From nobody Fri Dec 19 15:50:13 2025 Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (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 3919747768; Thu, 11 Apr 2024 23:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876892; cv=none; b=QHhvzXfF5k+lAWcSHPEFZPbbOKchJi5qXBC8ml+Rxv9icfOwrESfpDs+aw94noyvk7zHRgWz+EUYe3++Tk5RG5yQxndTvLRrHz+R9PSI5WN2Sf7hb0Eq6M180LYErtHDmvGxJLodBrgQlItcbMm5Pgq1X3/jXn/AA4TJdyt8J74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876892; c=relaxed/simple; bh=qDhteLf50yECMlgCo5DdnnD4LXN20q1SIVpQkLp52YA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9QJoXwv61wOSY71qyuRDBrWSeL7k+M6imVtQeYh/aBQyjoCIvw48agU9A/qG2HsfFiElkFk8xfpOvDCtzU9w/iVmzhxdRygJMoOTWF/FV38ehwApgX4+nIr5JBrDQdCYbxR9GuTxvcGO4SQkiRaQjv3bcFM5nx8/aSwqbsy09g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FVGKuMVg; arc=none smtp.client-ip=209.85.219.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FVGKuMVg" Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-dcd9e34430cso367531276.1; Thu, 11 Apr 2024 16:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712876890; x=1713481690; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=BQI2TKoyu8BDgVRKtOJlJn6MKKOUFwvO4itwrjVwbqA=; b=FVGKuMVg84Eh+NQpoEQo2OKPiV9Yjfd9mydZGv1MmA+SXEAWNBXvpv9fTeJY+yGae3 yq5l1SUe9FCBIfbTrtwMdGgVTT9t0PozxS05HNrfuXoKM1qIUXUYl40rDS/szuMzkiO2 CxAPg/MVHrDQzJOlAOYkircb6Hp3K+65j1axLts4szS/hekv/tsl+zWMyApADFJM1a0F J1vhL7lzlCByM0k5bE3arj9llp1N1T7GDMyu3aPiwABXVBGxyoc9/dvM+WEj4rAgOBlf 3dCF0xsKGKFk8WlpozdDe38l7e5LbT54b9BU2VhIuTPnpb9gwzUgVMmJ8r9KWQptxsw9 H7Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712876890; x=1713481690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=BQI2TKoyu8BDgVRKtOJlJn6MKKOUFwvO4itwrjVwbqA=; b=WoaC8n+rnD4GX61Dlw17ntCP8g3LKQN/xaMGB7gYqdwu9xbp18oCY9+Hx9ssU9J4dM Isvd0buAWlvzcwh+RtLP3f5qq4d0TQ7w+KzkuJQ3wD7h0sO0i2k1SxfQ+jz9RESjgrG4 +5t3/k5edlpMJAPxvoqqnYAsdmLATa+3zVV31khWEPq230FmbIMd2giBx77IBnSUPfe0 0inwZKctuBZVSMH1JNTYijG21NMlfscxXmrTyj7UOtJ8avYC1tZFq2KPSM83tBpoYbKg /fELq9RXSuhJEWrdc3QGVN6xIV1xeMn2fAn/KAbxew9nwaYqpkNVS14Sp0KkMwkX0P9n XBcA== X-Forwarded-Encrypted: i=1; AJvYcCW0XYkMTKHBMeB2xBNDN2MmM51uynfsrmVj+FmLgO4C5PHaRVx5GsLi9jpcgXjgsryquAMLdl4uKE/b1nr74r6XdUpQkG+lmGN64qBFYOPxu4sf0T2X0C3yu6VKhNTwTZoOAlDY33diuMVj2a0= X-Gm-Message-State: AOJu0YwL7a9VVj27RJM7/d5yqhhNBDFdbqapiXicunjp3JIJ/tkrb1jt oVRyG00+pDyzfGSzSvxfmNLNt/i6/EdMiVZrA3jDlwpp4pSMz8/e X-Google-Smtp-Source: AGHT+IG7487kc7xE3+S4pw61eQvvVZEg83y20evmhUXciSVxn+dwp3BL3crRYPocXeomCfDD5CZkAw== X-Received: by 2002:a25:8c10:0:b0:dc7:443d:d9da with SMTP id k16-20020a258c10000000b00dc7443dd9damr1056841ybl.4.1712876890082; Thu, 11 Apr 2024 16:08:10 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id u7-20020a0cdd07000000b00690c9256676sm1526056qvk.49.2024.04.11.16.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 16:08:09 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 2B0C11200066; Thu, 11 Apr 2024 19:08:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 11 Apr 2024 19:08:09 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehledgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeegleejiedthedvheeggfejveefjeejkefgveffieeujefhueeigfegueeh geeggfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 11 Apr 2024 19:08:08 -0400 (EDT) From: Boqun Feng To: Thomas Gleixner , Miguel Ojeda Cc: John Stultz , Stephen Boyd , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] rust: time: doc: Add missing C header links Date: Thu, 11 Apr 2024 16:08:00 -0700 Message-ID: <20240411230801.1504496-2-boqun.feng@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411230801.1504496-1-boqun.feng@gmail.com> References: <20240411230801.1504496-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The definitions related to jiffies are at linux/jiffies.h, and the definitions related to ktime_t are at linux/ktime.h, since `kernel::time` provides the functionality dealing with jiffies and ktime_t, it makes sense to add links to them from Rust's time module. Signed-off-by: Boqun Feng Acked-by: Miguel Ojeda Reviewed-by: Alice Ryhl --- rust/kernel/time.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 6811d5cadbd4..e3bb5e89f88d 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -4,6 +4,9 @@ //! //! This module contains the kernel APIs related to time and timers that //! have been ported or wrapped for usage by Rust code in the kernel. +//! +//! C header: [`include/linux/jiffies.h`](srctree/include/linux/jiffies.h). +//! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h). =20 /// The number of nanoseconds per millisecond. pub const NSEC_PER_MSEC: i64 =3D bindings::NSEC_PER_MSEC as i64; --=20 2.44.0 From nobody Fri Dec 19 15:50:13 2025 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 B328D47F51; Thu, 11 Apr 2024 23:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876894; cv=none; b=DQUTwoZdPq4Q/pl5tYqKDZ2d2zvbUe5/H+WSJHI8xWpqwCDYR9n74dMVGND9qQx/wnQXnf/hLxjmsfxdkka7LCYj/eCkEROFIDanVSPTAXdtc3gThOi5EaF9JRN9CpvSdHrKKTsUiBOZN38El9aUebTGKTMXw5Ey+eRnClXjYzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876894; c=relaxed/simple; bh=YGi08gU0thy2xo5L/Jd2ML51rJYD3cHypCbeOJyorH8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GtTHJL4IZ/mMEQiR1w9O8wDt3p+JK2B0ysnkonvbNEv2etGUzE1l0GVA0VSfCOqLCqM+V3NmRHQCHLHPC5K9k6CEW2bCAr3JKIGMBdrdmlo2eIXUnrv05HKyhtNGqPFmk8DUzaNHgU4hp1FpZycinH6azm8ovaz4iUvnTx4nIl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gc0LHZjH; arc=none smtp.client-ip=209.85.160.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gc0LHZjH" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-434832aa162so1246851cf.1; Thu, 11 Apr 2024 16:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712876891; x=1713481691; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=1cp6Y65O98WYlbmp5ogw9D72luMzjnNhAIcpF72RIPQ=; b=gc0LHZjHgdfkz3zXH1No0O7X+blRnls3JAsJtxUo8cHZGuOTjQSbnVp5x5Xz6oHbRV 0NVmKrgf8s567991xYwlQXrHR2EO0AAQWlgLc3RIjea2ndIcy8sQ06f2M+srnNIDabtQ KmVkhm0qKIHiAXcY7Gg7DdTF7OItpkuP/ZzOtbInB22LCZC0LRyZEysEIniCcS5CW3x0 8tzLkdDWnnfBbiRYdU4pOyaGMMZNepk7AkFlSy2s9kFXxk1JBQbpGp04d8LK9SZtfloz 7y2yg0eZIVt8AgZF6mSbjQbst1wyVuFOZ7PHwRmSsbDg/tCBta8pLlQ5O0ReJUE+6kkA Gt6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712876891; x=1713481691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1cp6Y65O98WYlbmp5ogw9D72luMzjnNhAIcpF72RIPQ=; b=Q0iM5PXTqbEM5vePQW4Lm6pjsXzciKDmydxs9ad/BfXpyq8vbsihB6r5VSuZfXouvT Wyl3svPLQoOVN6h3RUjf1ASNvLX6CtxUur6tdoTO4nwtnsU6rBT/Y9uRIpj07V32HkY0 +DlQbifEULsITgEQdi7md5AOLzBUJgmUZD+nphNQEVR5AbVb7riy5od5NaFQBDepIP1e uKaZScZNug+K/uKqHrMMsWvaD3nTCO2y+cceNBMckbt3BdHL0i8XZRSxywhHxxHQ75bC Z/QuGeZrtQgg4jizRQj6aV6eqnTo4Rt1q8F4M+BRATNJDAx7pEVdzVjXaQ0HX7TMAOyy KXGw== X-Forwarded-Encrypted: i=1; AJvYcCV//Hda/nqd2bW0n/IBgvwky3f6GQRcrrTmhveIhcI+91m+GIevINds7dUoF1uS/+L19GsUZVm6bQvoqFZ5M4BGw27p1i2LD/smMqUhZylLIFk1Vi/LIrOCj2hE81G1A6S/YrZleW+WTX/J1gs= X-Gm-Message-State: AOJu0YyPwH94mARV4qvQOXX6+GgsERF0PXkAHLej0bAbwwHSihhfnM9A /F9iR2PEbiDqEhgMd9bIU25ebmKpbqLlgeGRybSNNfXRMl8XgNZjlf9fmg== X-Google-Smtp-Source: AGHT+IGxLwz69pNIBHeq2xD+Wt5oG7jqgryyLf/L1g+Szbe4KnmD14+MAzru6+M0Tgl9TXZF5pTcDw== X-Received: by 2002:a05:622a:11d3:b0:434:3c23:d84b with SMTP id n19-20020a05622a11d300b004343c23d84bmr1201401qtk.31.1712876891595; Thu, 11 Apr 2024 16:08:11 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d19-20020ac86693000000b00434f6c1458bsm1477812qtp.17.2024.04.11.16.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 16:08:11 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfauth.nyi.internal (Postfix) with ESMTP id 8CD801200066; Thu, 11 Apr 2024 19:08:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 11 Apr 2024 19:08:10 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehledgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpefghfffvefhhfdvgfejgfekvdelgfekgeevueehlefhiedvgeffjefgteeu gfehieenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 11 Apr 2024 19:08:10 -0400 (EDT) From: Boqun Feng To: Thomas Gleixner , Miguel Ojeda Cc: John Stultz , Stephen Boyd , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , bjorn3_gh@protonmail.com, Benno Lossin , Andreas Hindborg , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] rust: time: Use wrapping_sub() for Ktime::sub() Date: Thu, 11 Apr 2024 16:08:01 -0700 Message-ID: <20240411230801.1504496-3-boqun.feng@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411230801.1504496-1-boqun.feng@gmail.com> References: <20240411230801.1504496-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently since Rust code is compiled with "-Coverflow-checks=3Dy", so a normal substraction may be compiled as an overflow checking and panic if overflow happens: subq %rsi, %rdi jo .LBB0_2 movq %rdi, %rax retq .LBB0_2: pushq %rax leaq str.0(%rip), %rdi leaq .L__unnamed_1(%rip), %rdx movl $33, %esi callq *core::panicking::panic::h59297120e85ea178@GOTPCREL(%rip) although overflow detection is nice to have, however this makes `Ktime::sub()` behave differently than `ktime_sub()`, moreover it's not clear that the overflow checking is helpful, since for example, the current binder usage[1] doesn't have the checking. Therefore make `Ktime::sub()` have the same semantics as `ktime_sub()`: overflow behaves like 2s-complement wrapping sub. Link: https://lore.kernel.org/lkml/5ac8c0d09392290be789423f0dd78a520b830fab= .1682333709.git.zhangchuang3@xiaomi.com/ [1] Signed-off-by: Boqun Feng --- rust/kernel/time.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index e3bb5e89f88d..3cb15d3079f4 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -77,7 +77,9 @@ impl core::ops::Sub for Ktime { #[inline] fn sub(self, other: Ktime) -> Ktime { Self { - inner: self.inner - other.inner, + // Mirrors `ktime_sub()`, kernel defines signed overflow to be= have like 2s-complement, + // hence `wrapping_sub()` is used. + inner: self.inner.wrapping_sub(other.inner), } } } --=20 2.44.0