Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp95827lqj; Thu, 11 Apr 2024 10:47:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXSRZ2lmGN06Fgh0UNvS2oEENqN6/SWdU0C3vc/HdFOBUFGLo3McimxqGMwykcHPvrjq1SQTeHGq+nsPC9qiSTrj+/n4oxWYVcSodb1OQ== X-Google-Smtp-Source: AGHT+IGxQcEgR9tUEzwKJX7/ctdqvaQ3HLNy5ctd+9hkAIf4DvWduTbRj3wkKyJSyXoe0ktX8CyI X-Received: by 2002:a05:6a20:3c9e:b0:1a3:6c9e:1e2b with SMTP id b30-20020a056a203c9e00b001a36c9e1e2bmr704111pzj.14.1712857677514; Thu, 11 Apr 2024 10:47:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712857677; cv=pass; d=google.com; s=arc-20160816; b=mVN1Dw74a4l3lF8DIQrVWVYbtMP4Fa/IVpfnTmgoS8dhyOqAkBPxM+H7FXrcCDyYCm 9H1PhwSQ/e5ed4yYa+8FElvQyiIr0ZOoClpZs6DKODSk1a2sIPKkOGx1PoU7UXSvSPMM IdTegNUVMIns54ecrlnV2WzREVLfajQfbl+NVC9vVHSXyREqZavtiuqJMrJVLznuOBqo O78NEei2afSku4AhPGIPprhKneOI4suyw6ruZwilCcyQ4ovs/kpoGBAdB1AiB3taZ++k NRjfPg5GRBkEi5eA2YbntNUNlb3fygMPMyVkt2EQ8G+LPFq4wHyf+RYmwdRyDzWoago5 1LPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VcZ0pKuDsoHogwdYuz9mbRdwS2176lXlA0vTIaXKs1g=; fh=ewgBhnTk/p8JaUcU5TGcX6KxGCOsgLg4R0EDsNnYHcU=; b=gtv54YzWvtcqNF9JCKbg+BbiBrUCkgWImvG6QyArNhVXo3ksTbyJccF5BYhX7GgDzL 9Xj+z+TVPg72W0RNGc0tSRCrB8DISpBKy8esratHK9ZHjFqlknkLqr17ERvuInf3MFe2 hK8nksWq4PJAHMkk2mi2y1rv+6fjLpvxYpXjYPTMr8H/wAkOvOzdFFfqNcOkScCxMv1+ Q3lFjjoFvvYLYmlpIjrUnVuUjPubmXWL5ZBd1QSOJbbMW8eBraLhLxudS5REYsjeAy0w yZ5nL2SwNe3wlnw1IUmJp+GCyDHuCixOa0kCnZ4oAPDhU0nh8fTiOfVGpgiXNQxN+w/C J11Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zMnH0ULc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i24-20020a63d458000000b005f066656fc1si1539748pgj.522.2024.04.11.10.47.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 10:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=zMnH0ULc; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141310-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141310-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F6EB2857C1 for ; Thu, 11 Apr 2024 17:47:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F6E4199E8B; Thu, 11 Apr 2024 16:21:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zMnH0ULc" Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EECF7199E8C for ; Thu, 11 Apr 2024 16:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712852517; cv=none; b=sadwpQe9226sm+x7m16TJk5Ji5Xi+9EUxlLicUWlfzDJDj/fMvd+X2jX92j1wfrr5WaS8m8ApNCMZjroDKl5Hht4uuMLJSb0XD1wMODaPBotS7SBRKKI9NmL3HJlZQ9UiNxSRkx5R/Rd+HYpLaxrOeDh6W+C9KNp0jwYnm8HPRY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712852517; c=relaxed/simple; bh=lf+0Ib0/SILN3w7/PCPazIMQblm1eMQjgq0Ng4XGKNQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ACYfgbw8tAcgiYL/GHcOTWnfZVE+QXoAz/h//ECtVksaddB2pNznAOsLNX063lksmIB+PDiWnHTRd4DUa7e+eiUK4ie4FOKvN1N3+uVmQGx2fQjKa3G4XjJMOJYcuSSeihzmg6MOsxGdhTUEb+2MgZaBnt3ZFtoNMDtp3/2eRHM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zMnH0ULc; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bbbc6e51d0so3385334b6e.3 for ; Thu, 11 Apr 2024 09:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712852515; x=1713457315; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VcZ0pKuDsoHogwdYuz9mbRdwS2176lXlA0vTIaXKs1g=; b=zMnH0ULcpk/KnxXzuQGSuJEzDwYXSJyiOjphfmUxivDi57fC0HuCsgLiXgtuqeS/ot boEr7tASYZ9++10beVcD8wK4s+hKPqntMoqOG9WMCQ1/H8VFy0ctro8n02DKqS1t/vcp iGW066n5TuiIGrP4ICG5g9huwn6jTecXvyZcTIYry4g+0iVxxBdXPn44uwzbu/FA3928 pPC5g63RzV1RqeMIdF0yTgecvsWtF9/2rV/QRnIFJf/2pe0xF6hP3ELgs/ChD/5HiqOW ghDdDy/5oiz9bX97l9aC+B9QFIKzYfKSdT/Aplg2WZrFB+yLk0wTYWtR1QbDDm05MK94 2QsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712852515; x=1713457315; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VcZ0pKuDsoHogwdYuz9mbRdwS2176lXlA0vTIaXKs1g=; b=kZSt1vrYGP0gMKKpleDtlT9qXCEDmSv1kRbn1rc2jKPzd8NvnRR/565p56skKS9CiH RS3ZlCzfaTO588LcTX2AnVwihCePRLGozQ447Cx3yjpem/CKOlMFizxfb79XPwqUe4Wj eHFpCwrs91o6EKL207sAw/g15jd+e6+qScEjRTUdsjNRGXI+ohRwixfGK6OqpgYytgqa EJGE5qPM1SnaoiePicZy/L7Wx8T3AJGZpl8nDGdozt55Fg96fvdEeZh2uSX1rOgaIT8y 8j97jQb3aZ8S0au/mpsIh9hUNhaiWHLMWfrqVE+ocxpO86J1uZ0j1m7rnTxlD44p8QZ0 D0FA== X-Forwarded-Encrypted: i=1; AJvYcCUt/uGnw/TLV562fGI3eezLP5E0zyljOy4P6ytYfwzmM+6Z6oNeZqjAgsCN/HzcBWtMa5WIih2mdnUrdPts2KIqR1h7Th+72WzHWdGw X-Gm-Message-State: AOJu0YxTcsuPQ7jYp2RKJjSr4Cs7Qg04MHvyfaLrv6c+NrCsINewN0FE xYu9OmHtzLBp52qVbGKwVL2qrfzSPxqIoBX3/7NPTlRqPfAZWn8nrcUsGlpXgck+esNEiXUcBaP vENxmC1RSnVIbKePxkdgsV+WWVvdXAoRb+KXA X-Received: by 2002:aca:100f:0:b0:3c5:fc80:56a with SMTP id 15-20020aca100f000000b003c5fc80056amr109433oiq.32.1712852514866; Thu, 11 Apr 2024 09:21:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240322-rust-ktime_ms_delta-v2-1-d98de1f7c282@google.com> In-Reply-To: From: Alice Ryhl Date: Thu, 11 Apr 2024 18:21:43 +0200 Message-ID: Subject: Re: [PATCH v2] rust: time: add Ktime To: Boqun Feng Cc: Miguel Ojeda , John Stultz , Thomas Gleixner , Stephen Boyd , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 11, 2024 at 5:57=E2=80=AFPM Boqun Feng w= rote: > > On Fri, Mar 22, 2024 at 08:59:38AM +0000, Alice Ryhl wrote: > > + /// Returns the number of milliseconds. > > + #[inline] > > + pub fn to_ms(self) -> i64 { > > + self.divns_constant::() > > + } > > +} > > + > > +/// Returns the number of milliseconds between two ktimes. > > +#[inline] > > +pub fn ktime_ms_delta(later: Ktime, earlier: Ktime) -> i64 { > > + (later - earlier).to_ms() > > +} > > + > > +impl core::ops::Sub for Ktime { > > + type Output =3D Ktime; > > + > > + #[inline] > > + fn sub(self, other: Ktime) -> Ktime { > > + Self { > > + inner: self.inner - other.inner, > > Nit: although we use "Release mode" to compile Rust code in kernel, so > i64 substraction behaves as 2's complement wrap, I think it's better we > use wrapping_sub here: > > self.inner.wrapping_sub(other.inner) > > however it's not a correctness issue for now, so with or without it, We enable overflow checks even on release mode right now. But I don't understand this nit because we only have an overflow condition if the two ktimes differ by more than 2^31, and if that happens then that's a *legitimate* overflow that we would want to catch. Or is there something I am missing? Alice