From nobody Mon Feb 9 13:59:18 2026 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 20FE181E; Sun, 4 May 2025 05:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334819; cv=none; b=qUmmfm1fjTtxbo/2x++wDmTDYDFQpnvjs4zMKs5y2uaZ5ikTF4Eav2EoipPHd++h7oRPAdq6FLsX7mB7vAeiQIMTu1062ksSoq+MkQh2ldpGAJkfDNFTETkQoWDQJsKWylO/AWhLv4mxVTqeCyRmt+qVm5LraxqFw9JuNSG6wic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334819; c=relaxed/simple; bh=zl4sJNGthzZLZ1+4crX6Vr7P7kWOAx7JN+qu+L3ObPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f+bCJG7CGgneOfhEyA7cM2Rg64ntFKcWek82op3zV8xmmewwjFZ/ro7DlYRFYFrLrTbBumNPHGRmEWp0uWwCMhXTxhRJvLQhv5CzVwSLUxBtH4Nbj3IqqPrlQiiw3MdHLNuiH4lJY+wLtbRIPNDEXg08ZUvE3YqMWfGlG7LYsZo= 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=JoBjkgva; arc=none smtp.client-ip=209.85.210.173 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="JoBjkgva" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-739be717eddso2761022b3a.2; Sat, 03 May 2025 22:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746334815; x=1746939615; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VrDG74rIW86O9duGthjeZHPVikMtq3eKNAk/Yr/Vgpo=; b=JoBjkgvaYFeyu4tovblkTsx7skubhjAILoEa1SV2AiIc1t57iuxUdNUEm+sDUWHi7v wyIeAjR8xXqcc6wpeZxYzPDCkquxc4OTyT1LF91BScxZz3xH71gN2J47h0hL/Qd8ihmU VXEB6VcmyrMgD2kt9UlId+VDqnY1bUTIFlQpbWp67B9K4lH8tZKH6mK0zGA/G1RhOrkq 1lhmLMcjLy36Cvf7VyIptnulCBdbByRWx3AE7f+kOJ3LwkHjDoTq9n7g+2NKBoTrQJQb x+oBzp3/M7hI2soTXUloUl6H3bP9ZwLPSYGKI6FHmvefzRtLZZDzLagXFuKItn7lRur9 fOsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746334815; x=1746939615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VrDG74rIW86O9duGthjeZHPVikMtq3eKNAk/Yr/Vgpo=; b=Ljz2EgZWQQOPT76xd1zxB8g8wsY0lkeMHtWQkZlX5a/UzIOuu2pYcH2XErF8J6xCpB pN/Nf1k7uuVZqGSSLOcHax1tSjFJE0IZewl5RTdu8MY7Ig3bUpmem0f8vGQtGvQm2FBV ck2Ge5F3vmtA0EsfAMEqiTBBFXpmSpBY8ht9PAD3vAsS8aQ2ekH7FRqwc3vpYrUMTERm /KjQCaGVeJ1DxADZYLi7tE2xvz/XgRvVa/iSxLmRsv+xI4/Ywf3lD3YY/9lIVagNoc81 i+tyqAISbiHTLsBBb9JBxGKmAv8q0p72rLOqL3ETc5y50f+FBWhoN3LKZRFp1uRrOKos hx/w== X-Forwarded-Encrypted: i=1; AJvYcCUgHqPvwSPnuEl4tFji3Fjh9Padv/8hDY16Ba24mN/b4ly3ZZIaEB02X24cMjOYIKmoxG1dlf/q1W2VU+c=@vger.kernel.org X-Gm-Message-State: AOJu0YzGUa1xnbxO5BqTDWvyUA5K4hTDN4IDjncwbgrO5/s2o/6Ra/Vx IoUaOIMqw3TZ7IQvqLKM/8OpkLz6QzrSnsBb2bTmkR4D/tBEBsUiaRs7Dd+U X-Gm-Gg: ASbGncvsWEnTasdFSajrtAaAzSj3P6wORVTmnEAssVW3+U6y34LJZeX4N9L8paJwMwT MAskxmreOn24S1NZuqZWXtJ3G6sHuHKIMaKeX3nHiSUxD5zMWqhFoxTQ+uWz4pEXa6GJP9rDGom l+In5lxZlSPFwlVUFB3v+34aCgWTVTvZDZDaZuAnk76OHG64fIWI6/LX1UeT/G9JSRDg4TB9THx nfEu+d93JVonC/Ql6PxbVGVUmb6aArXMSqC1ZEZyw2YMoxqo+MO6QGGpdjtxbgj3gqUQskVRUYu AYs/RR7gSx4hZynwM7FCaB9rZN/6u7Cyuq+EJhAUuPwA/J775rdZAncaSSkNEfLd2d+W6+gagxK QAtHcVIVt4PQvbkshsg== X-Google-Smtp-Source: AGHT+IH4jNL6htGTVVoOTPK7QPxTV+BiuViU95N8q7vXthKpI86LxyXaxii2C4yvkMYaIAviI/qHOw== X-Received: by 2002:a05:6a00:e17:b0:736:a8db:93bb with SMTP id d2e1a72fcca58-7406729ed39mr6310921b3a.5.1746334814961; Sat, 03 May 2025 22:00:14 -0700 (PDT) Received: from mew.. (p4138183-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.129.206.183]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058db91dasm4225756b3a.44.2025.05.03.22.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 May 2025 22:00:14 -0700 (PDT) From: FUJITA Tomonori To: rust-for-linux@vger.kernel.org Cc: a.hindborg@kernel.org, boqun.feng@gmail.com, frederic@kernel.org, lyude@redhat.com, tglx@linutronix.de, anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/5] rust: time: Change Delta methods to take &self instead of self Date: Sun, 4 May 2025 13:59:54 +0900 Message-ID: <20250504045959.238068-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250504045959.238068-1-fujita.tomonori@gmail.com> References: <20250504045959.238068-1-fujita.tomonori@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" Change several methods of the `Delta` type in Rust to take `&self` instead of `self`. These methods do not mutate or consume the `Delta` value and are more idiomatically expressed as taking a shared reference. This change improves consistency with common Rust practice and allows calling these methods on references without requiring an explicit copy or move of the value. Signed-off-by: FUJITA Tomonori --- rust/kernel/time.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 1be5ecd814d3..deca2999ced6 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -260,26 +260,26 @@ pub const fn from_secs(secs: i64) -> Self { =20 /// Return `true` if the [`Delta`] spans no time. #[inline] - pub fn is_zero(self) -> bool { + pub fn is_zero(&self) -> bool { self.as_nanos() =3D=3D 0 } =20 /// Return `true` if the [`Delta`] spans a negative amount of time. #[inline] - pub fn is_negative(self) -> bool { + pub fn is_negative(&self) -> bool { self.as_nanos() < 0 } =20 /// Return the number of nanoseconds in the [`Delta`]. #[inline] - pub const fn as_nanos(self) -> i64 { + pub const fn as_nanos(&self) -> i64 { self.nanos } =20 /// Return the smallest number of microseconds greater than or equal /// to the value in the [`Delta`]. #[inline] - pub fn as_micros_ceil(self) -> i64 { + pub fn as_micros_ceil(&self) -> i64 { #[cfg(CONFIG_64BIT)] { self.as_nanos().saturating_add(NSEC_PER_USEC - 1) / NSEC_PER_U= SEC @@ -294,7 +294,7 @@ pub fn as_micros_ceil(self) -> i64 { =20 /// Return the number of milliseconds in the [`Delta`]. #[inline] - pub fn as_millis(self) -> i64 { + pub fn as_millis(&self) -> i64 { #[cfg(CONFIG_64BIT)] { self.as_nanos() / NSEC_PER_MSEC --=20 2.43.0 From nobody Mon Feb 9 13:59:18 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 78F8E17A31C; Sun, 4 May 2025 05:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334824; cv=none; b=a/h+iA47v+F/DG1xMImhA09kCpMA1s29OhvclKNdd45nPiFwzW/6s23KruEQZWI6tYFfZtKgyV78SQZjLXFTisWBQHqPFgerSOfPZorcnrqL345TLiToHtEhsfdyGLQOpXh1NWuxGgjkQQMq+mYehBLrn5GghMyNaysDASiKJ5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334824; c=relaxed/simple; bh=U3DM6lQPbqJ6rCjoJ36SG9EAj2Vpil7SfdTr2c8DC+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O9DWJpNNZre2iFQwyW7dhXWVuSditcrn9ozX1xYpVRKS+DQ050d55WYRYb4Hfeklf1ebx3UlgoJi+Kh7EYWA2Dr0FPC8Sw0lG7fehlTBfxsz/n6NrE/LPNJT3G3ffP6dUMOI0M3go1qk0/ivVEDVBW5b/fagIuT1WnTVON+w7Tg= 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=jOfWjNWI; arc=none smtp.client-ip=209.85.210.171 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="jOfWjNWI" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-736aa9d0f2aso4652748b3a.0; Sat, 03 May 2025 22:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746334819; x=1746939619; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/fqidDXq0kr00V4UH5PYapGK6UsK8iPCy8jxg2+xVp8=; b=jOfWjNWIzTBAIs7/yu3sKE0Qo87sF+OCQGnlXc79mb/Tx5PxLMfhnzzVsQhge0LGNa GUCgDI8SowHVda6t4ldh0Cn4F95jU/PEyp5w72vFGZey9Y/nP43RKmiXeaJKGrKxj5g/ 98pLWV2/1Eosvfl6YY4NlqJ5GFR+x8hLujJ5O/MoKt61ZZDlOHsGAjz/Xp4md0045Q0e UCVHOU4FQ1fhCZRrgM7gdsYm6dCvvTF57xJ7la4Vk4jcun/Y3t3m9VjRT4+igPBq/goA ZNOj6lMfmbr2JuY4rEKdmMG6lwCbaiKiD4DExMGSDI9sysoZhEujIUuk7tYwEha0x2Lu GNdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746334819; x=1746939619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/fqidDXq0kr00V4UH5PYapGK6UsK8iPCy8jxg2+xVp8=; b=QwTDrRqo+2vZAKzNMyJO4/B5MkjbhgNUvIde5wfOsnVCC+L2+Wh2dZ8eOOGmZOfUIR g7vXmOuCjKtTC83EQGMTlEX2olP751QrX4tMqGaa2AQurCFCb19N/pq+zx+aFh5xxJBk pBI7VLwTYupGS3tjdy82OMJluL6EJUaBZkZ0GtgGFUutCifY3X62AmceTr0liiXwBZQx hXdNdduoKpVMcK3L/YipJcvDUNttwEiS/+T++BldHL2dLWKhBAPXNKeT06s0LWMS4jgk hAURgZbVFB2fyjmnOWS84AD9C4gzfHt/EoRhs9SyA/v4Ejm2EsUXTM8b4nEuDal+D0ev Vrog== X-Forwarded-Encrypted: i=1; AJvYcCVD/6Bq9rUwJkQMTzPi0TAhr+THTn/JuQYUHPUYpI0apInbEqxucAbKhvzLPOxh6dH6tvw0rk+hgvPAZbM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxhv46lxc6o8+G1tOxXteyLn+FG47XFjGvpAl5RyMBKBg20NnjN yq68Eejz+RhaX/Y1BEldNe8jN7fYfhPSVWXTrOoYNzYXAMT7njoGdIe4xoxx X-Gm-Gg: ASbGncuUJwZ2iP8UEyJ12guS++0dfd286Qrsz1JUbUTvTydfdBOkvUXNJvU5WXNIdt3 RxNovSyzsJhjO3js49oRRiOjwsL4y/tHTZadtzLFrKh9zt9R6J2YiZWc348DhoYC679u99rSRDs pFu7eBA7ow+GVD6DvPShiBPFty9umTgtnEQI1l4cU+orwK9XE++5fDNMO0/wmKRDkrwVImPO0xa JvnQnKqS7jkDYGVdRETSa7rS181iikbg32RDL2UXaRHYxbnABF258FKQE+QnET0ULZPWwPFW1Cb GJyVtdEd7dI2tWqKZy90xZqGIDRzabNBt7yyBhm/ktg99qeQRxfH9ETE79Mg9BBTcHqHjqcrMoz 7pT4tARPCXncB2JI1mw== X-Google-Smtp-Source: AGHT+IGbR+X/XCX7yvRNACmxnQX6hpeszflRUO/N06xDw0HBKwL+UCyJuF2NqSqOECgXdY7GNILAug== X-Received: by 2002:a05:6a00:2985:b0:736:3c2b:c38e with SMTP id d2e1a72fcca58-7406735b5a1mr6972772b3a.13.1746334819445; Sat, 03 May 2025 22:00:19 -0700 (PDT) Received: from mew.. (p4138183-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.129.206.183]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058db91dasm4225756b3a.44.2025.05.03.22.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 May 2025 22:00:19 -0700 (PDT) From: FUJITA Tomonori To: rust-for-linux@vger.kernel.org Cc: a.hindborg@kernel.org, boqun.feng@gmail.com, frederic@kernel.org, lyude@redhat.com, tglx@linutronix.de, anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/5] rust: timer: Replace HrTimerMode enum with trait-based mode types Date: Sun, 4 May 2025 13:59:55 +0900 Message-ID: <20250504045959.238068-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250504045959.238068-1-fujita.tomonori@gmail.com> References: <20250504045959.238068-1-fujita.tomonori@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" Replace the `HrTimerMode` enum with a trait-based approach that uses zero-sized types to represent each mode of operation. Each mode now implements the `HrTimerMode` trait. This refactoring is a preparation for replacing raw `Ktime` in HrTimer with the `Instant` and `Delta` types, and for making `HrTimer` generic over a `ClockSource`. Signed-off-by: FUJITA Tomonori Reviewed-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 164 ++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 74 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 380712d4302a..24d013e47c7b 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -98,7 +98,7 @@ pub fn to_ns(self) -> i64 { pub struct HrTimer { #[pin] timer: Opaque, - mode: HrTimerMode, + mode: bindings::hrtimer_mode, _t: PhantomData, } =20 @@ -112,7 +112,7 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new(mode: HrTimerMode) -> impl PinInit + pub fn new() -> impl PinInit where T: HrTimerCallback, { @@ -127,11 +127,11 @@ pub fn new(mode: HrTimerMode) -> impl= PinInit place, Some(T::Pointer::run), U::ID, - mode.into_c(), + M::C_MODE, ); } }), - mode: mode, + mode: M::C_MODE, _t: PhantomData, }) } @@ -389,7 +389,7 @@ unsafe fn start(this: *const Self, expires: Ktime) { Self::c_timer_ptr(this).cast_mut(), expires.to_ns(), 0, - (*Self::raw_get_timer(this)).mode.into_c(), + (*Self::raw_get_timer(this)).mode, ); } } @@ -414,77 +414,93 @@ fn into_c(self) -> bindings::hrtimer_restart { } =20 /// Operational mode of [`HrTimer`]. -// NOTE: Some of these have the same encoding on the C side, so we keep -// `repr(Rust)` and convert elsewhere. -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum HrTimerMode { - /// Timer expires at the given expiration time. - Absolute, - /// Timer expires after the given expiration time interpreted as a dur= ation from now. - Relative, - /// Timer does not move between CPU cores. - Pinned, - /// Timer handler is executed in soft irq context. - Soft, - /// Timer handler is executed in hard irq context. - Hard, - /// Timer expires at the given expiration time. - /// Timer does not move between CPU cores. - AbsolutePinned, - /// Timer expires after the given expiration time interpreted as a dur= ation from now. - /// Timer does not move between CPU cores. - RelativePinned, - /// Timer expires at the given expiration time. - /// Timer handler is executed in soft irq context. - AbsoluteSoft, - /// Timer expires after the given expiration time interpreted as a dur= ation from now. - /// Timer handler is executed in soft irq context. - RelativeSoft, - /// Timer expires at the given expiration time. - /// Timer does not move between CPU cores. - /// Timer handler is executed in soft irq context. - AbsolutePinnedSoft, - /// Timer expires after the given expiration time interpreted as a dur= ation from now. - /// Timer does not move between CPU cores. - /// Timer handler is executed in soft irq context. - RelativePinnedSoft, - /// Timer expires at the given expiration time. - /// Timer handler is executed in hard irq context. - AbsoluteHard, - /// Timer expires after the given expiration time interpreted as a dur= ation from now. - /// Timer handler is executed in hard irq context. - RelativeHard, - /// Timer expires at the given expiration time. - /// Timer does not move between CPU cores. - /// Timer handler is executed in hard irq context. - AbsolutePinnedHard, - /// Timer expires after the given expiration time interpreted as a dur= ation from now. - /// Timer does not move between CPU cores. - /// Timer handler is executed in hard irq context. - RelativePinnedHard, +pub trait HrTimerMode { + /// The C representation of hrtimer mode. + const C_MODE: bindings::hrtimer_mode; } =20 -impl HrTimerMode { - fn into_c(self) -> bindings::hrtimer_mode { - use bindings::*; - match self { - HrTimerMode::Absolute =3D> hrtimer_mode_HRTIMER_MODE_ABS, - HrTimerMode::Relative =3D> hrtimer_mode_HRTIMER_MODE_REL, - HrTimerMode::Pinned =3D> hrtimer_mode_HRTIMER_MODE_PINNED, - HrTimerMode::Soft =3D> hrtimer_mode_HRTIMER_MODE_SOFT, - HrTimerMode::Hard =3D> hrtimer_mode_HRTIMER_MODE_HARD, - HrTimerMode::AbsolutePinned =3D> hrtimer_mode_HRTIMER_MODE_ABS= _PINNED, - HrTimerMode::RelativePinned =3D> hrtimer_mode_HRTIMER_MODE_REL= _PINNED, - HrTimerMode::AbsoluteSoft =3D> hrtimer_mode_HRTIMER_MODE_ABS_S= OFT, - HrTimerMode::RelativeSoft =3D> hrtimer_mode_HRTIMER_MODE_REL_S= OFT, - HrTimerMode::AbsolutePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE= _ABS_PINNED_SOFT, - HrTimerMode::RelativePinnedSoft =3D> hrtimer_mode_HRTIMER_MODE= _REL_PINNED_SOFT, - HrTimerMode::AbsoluteHard =3D> hrtimer_mode_HRTIMER_MODE_ABS_H= ARD, - HrTimerMode::RelativeHard =3D> hrtimer_mode_HRTIMER_MODE_REL_H= ARD, - HrTimerMode::AbsolutePinnedHard =3D> hrtimer_mode_HRTIMER_MODE= _ABS_PINNED_HARD, - HrTimerMode::RelativePinnedHard =3D> hrtimer_mode_HRTIMER_MODE= _REL_PINNED_HARD, - } - } +/// Timer that expires at a fixed point in time. +pub struct AbsoluteMode; + +impl HrTimerMode for AbsoluteMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS; +} + +/// Timer that expires after a delay from now. +pub struct RelativeMode; + +impl HrTimerMode for RelativeMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL; +} + +/// Timer with absolute expiration time, pinned to its current CPU. +pub struct AbsolutePinnedMode; + +impl HrTimerMode for AbsolutePinnedMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED; +} + +/// Timer with relative expiration time, pinned to its current CPU. +pub struct RelativePinnedMode; + +impl HrTimerMode for RelativePinnedMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED; +} + +/// Timer with absolute expiration, handled in soft irq context. +pub struct AbsoluteSoftMode; + +impl HrTimerMode for AbsoluteSoftMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_SOFT; +} + +/// Timer with relative expiration, handled in soft irq context. +pub struct RelativeSoftMode; + +impl HrTimerMode for RelativeSoftMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_SOFT; +} + +/// Timer with absolute expiration, pinned to CPU and handled in soft irq = context. +pub struct AbsolutePinnedSoftMode; + +impl HrTimerMode for AbsolutePinnedSoftMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED_SOFT; +} + +/// Timer with relative expiration, pinned to CPU and handled in soft irq = context. +pub struct RelativePinnedSoftMode; + +impl HrTimerMode for RelativePinnedSoftMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED_SOFT; +} + +/// Timer with absolute expiration, handled in hard irq context. +pub struct AbsoluteHardMode; + +impl HrTimerMode for AbsoluteHardMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_HARD; +} + +/// Timer with relative expiration, handled in hard irq context. +pub struct RelativeHardMode; + +impl HrTimerMode for RelativeHardMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_HARD; +} + +/// Timer with absolute expiration, pinned to CPU and handled in hard irq = context. +pub struct AbsolutePinnedHardMode; + +impl HrTimerMode for AbsolutePinnedHardMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED_HARD; +} + +/// Timer with relative expiration, pinned to CPU and handled in hard irq = context. +pub struct RelativePinnedHardMode; + +impl HrTimerMode for RelativePinnedHardMode { + const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED_HARD; } =20 /// Use to implement the [`HasHrTimer`] trait. --=20 2.43.0 From nobody Mon Feb 9 13:59:18 2026 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 AC9101624EA; Sun, 4 May 2025 05:00:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334826; cv=none; b=J7wju+HVXunhg7CCMY0bv2Sbcg/IwTyz4b90DSVljKSvzClzmb3w4vsvAMvGfUyLLcb6zPh0YECMLDC8c06VRtIipWH7k0WwsbfMrWF+MvLYGXwUeUiZ+8yB5J/UymQfqriUA4JSaQ0aay6v14YmKmwmF5r4aQELlDfzZtAIxXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334826; c=relaxed/simple; bh=sQSpKCM4nRT8s/biIXq9ewwRy0TRGc+mLHnMW7AnnJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lQWpzyuPk7UNA2cJePRxY4PWJdXszJZATCk8Fial0tzh74S9zqduEUkgFSm9fkMC+beHlEudGwm/CHsL2ns0f8AynZVnZJ26aGmLh2aAXLFJE9YpFvm11wgp5T4oPtg6d5ZZEca1XL57/i/oj2CMVHh6uVN5NJgSQ3JhBgS07Ek= 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=TmGWGTYa; arc=none smtp.client-ip=209.85.210.172 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="TmGWGTYa" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7376dd56eccso3856864b3a.0; Sat, 03 May 2025 22:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746334823; x=1746939623; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=agUh2e8B8oeY+1DKKBDray7XNmeFmBpkHwJwg0QmBUI=; b=TmGWGTYa/QVAnE/RLtKEEb9mdkbwiLsh5qQXwaGMAIOvCQemT5S2b+HSdpgsX6EP+8 w2oUgLB1boUA1yOXM0xZonGrUaa1vIr+bTJDPaubEZR+PtwoE+kzTAMv5n4x4TAXEA6b U3TQVrB3I4VVWJbmgCj2C686UOpVqhRPow0DTWZGoWfZx/WOY+nULeF5zGWl1vC5xL1h Qotk5Dkl0j0sCJ3VvcSHA8XgP62LvC3uTNaZitnWjcd55IwUKMXI+Uy44flJ5KCKkhEI 6CBF9jOv07rYEnfB2knPPNLTZmVhfA55ZQizFH+ujz2FAJoCKTt/bJlWmZ4j298IxXUQ ALXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746334823; x=1746939623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=agUh2e8B8oeY+1DKKBDray7XNmeFmBpkHwJwg0QmBUI=; b=R19MLyOKdr0V8MS53yqq2JoOeSK2juMZRKvfva2EkKu5I4bqI0jp/nxYMJD6ba+dXw ltad0LMNTh+Ql0MTOaUaPHtophP6tzKse10oEqFhH4BTH93hVCLLANaCPaYUUkToJtnH SfrlFQsr+K6xoT+yZwE2Y2Jb1VxT1dR3UsAspas8icbR7LXkrbRdDAr6volJwmfYL3ya P0Wu9auaSitRTcVBmk3TwaEoI8Wo2F/2M2sm3zk+j58IFT1/fAkbf1Hvi18GdV+p2TBN 6nJC6wj9XXiu4a1VyUzPM0nMdT50r1Pv6Pp8XBzbY/KzVwE6nUZXqFw+Hs+dwlBFZH3I 2AsQ== X-Forwarded-Encrypted: i=1; AJvYcCWCu3LDhUTWbZE3LWAJ1JhPrjp/yHo+xIun7iLkKeHn4ZsysY++d756n61y2TfmyLRSNR9DEek/A9TCrgw=@vger.kernel.org X-Gm-Message-State: AOJu0YxTh0yYyf6US8QNy+7Ls5SKx5BMy8DrYTYsIuJ6wNisTfj4fZDy 51LeUwNaXVY8rvnZHeM1T60wKNQudJLhsvwj2/mqfFuHIcitLPnwQxk22MWF X-Gm-Gg: ASbGnctWpzut9DyXAUfBsNFHuDeqeoZlGdND75+SmCpAm27yGA4v/0sI7vRF6zM1DmW 2s3os69iTfXhNfW5PHMZiYT8rXwJI1OVQllf0xo+1tFrI2Ulr4VwwMcGcprrgD9FzxXOPhVY/Jn 4T0frt6wynfn7zZFNrfYO1JWrgbRGu8SCF68eggzanDAFqPUPl7Xhj6GHGQK4+uk408BcbbJyaF rdp195LUH9VtTcuj/k952/E4JoT5NvTRRf/Q6kCmVRCmtnZE9jYhAiBEH7yqDDH0LZ3354tKm6/ vsw3MvRsuGb4u9p9lv5XddQS6lec1TZGEs0yOZT8eDGnK6lfTG9vp0OUX3FkHKZpw3sLNgSsuCc CxLlNJO1W4Z/jNL94Fw== X-Google-Smtp-Source: AGHT+IHdHowyMjgIUsJKcsoDOA0kOb5VVCmXkLZKvPXbu8T3Qjq2h/R3o3kD4F6iSYhnchKTZxVKFw== X-Received: by 2002:a05:6a00:3012:b0:736:4704:d5da with SMTP id d2e1a72fcca58-7406f1b442emr3939398b3a.22.1746334823561; Sat, 03 May 2025 22:00:23 -0700 (PDT) Received: from mew.. (p4138183-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.129.206.183]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058db91dasm4225756b3a.44.2025.05.03.22.00.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 May 2025 22:00:23 -0700 (PDT) From: FUJITA Tomonori To: rust-for-linux@vger.kernel.org Cc: a.hindborg@kernel.org, boqun.feng@gmail.com, frederic@kernel.org, lyude@redhat.com, tglx@linutronix.de, anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/5] rust: time: Add HrTimerExpires trait Date: Sun, 4 May 2025 13:59:56 +0900 Message-ID: <20250504045959.238068-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250504045959.238068-1-fujita.tomonori@gmail.com> References: <20250504045959.238068-1-fujita.tomonori@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" Introduce the `HrTimerExpires` trait to represent types that can be used as expiration values for high-resolution timers. Define a required method, `as_nanos()`, which returns the expiration time as a raw nanosecond value suitable for use with C's hrtimer APIs. Also extend the `HrTimerMode` to use the `HrTimerExpires` trait. This refactoring is a preparation for enabling hrtimer code to work uniformly with both absolute and relative expiration modes. Signed-off-by: FUJITA Tomonori --- rust/kernel/time.rs | 5 + rust/kernel/time/hrtimer.rs | 181 ++++++++++++++++++++++++------------ 2 files changed, 128 insertions(+), 58 deletions(-) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index deca2999ced6..ac9551fca14f 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -194,6 +194,11 @@ pub fn now() -> Self { pub fn elapsed(&self) -> Delta { Self::now() - *self } + + #[inline] + pub(crate) fn as_nanos(&self) -> i64 { + self.inner + } } =20 impl core::ops::Sub for Instant { diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 24d013e47c7b..55e1825425b6 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -67,7 +67,7 @@ //! A `restart` operation on a timer in the **stopped** state is equivalen= t to a //! `start` operation. =20 -use super::ClockSource; +use super::{ClockSource, Delta, Instant}; use crate::{prelude::*, types::Opaque}; use core::marker::PhantomData; use pin_init::PinInit; @@ -413,94 +413,159 @@ fn into_c(self) -> bindings::hrtimer_restart { } } =20 +/// Time representations that can be used as expiration values in [`HrTime= r`]. +pub trait HrTimerExpires { + /// Converts the expiration time into a nanosecond representation. + /// + /// This value corresponds to a raw ktime_t value, suitable for passin= g to kernel + /// timer functions. The interpretation (absolute vs relative) depends= on the + /// associated [HrTimerMode] in use. + fn as_nanos(&self) -> i64; +} + +impl HrTimerExpires for Instant { + fn as_nanos(&self) -> i64 { + Instant::::as_nanos(self) + } +} + +impl HrTimerExpires for Delta { + fn as_nanos(&self) -> i64 { + Delta::as_nanos(self) + } +} + /// Operational mode of [`HrTimer`]. pub trait HrTimerMode { /// The C representation of hrtimer mode. const C_MODE: bindings::hrtimer_mode; -} =20 -/// Timer that expires at a fixed point in time. -pub struct AbsoluteMode; + /// Type representing the clock source. + type Clock: ClockSource; =20 -impl HrTimerMode for AbsoluteMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS; + /// Type representing the expiration specification (absolute or relati= ve time). + type Expires: HrTimerExpires; } =20 -/// Timer that expires after a delay from now. -pub struct RelativeMode; - -impl HrTimerMode for RelativeMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL; -} +/// Defines a new `HrTimerMode` implementation with a given expiration typ= e and C mode. +#[doc(hidden)] +macro_rules! define_hrtimer_mode { + ( + $(#[$meta:meta])* + $vis:vis struct $name:ident<$clock:ident> { + c =3D $mode:ident, + expires =3D $expires:ty + } + ) =3D> { + $(#[$meta])* + $vis struct $name<$clock: $crate::time::ClockSource>( + ::core::marker::PhantomData<$clock> + ); =20 -/// Timer with absolute expiration time, pinned to its current CPU. -pub struct AbsolutePinnedMode; + impl<$clock: $crate::time::ClockSource> $crate::time::hrtimer::HrT= imerMode for $name<$clock> { + const C_MODE: $crate::bindings::hrtimer_mode =3D + $crate::macros::paste! {$crate::bindings::[]}; =20 -impl HrTimerMode for AbsolutePinnedMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED; + type Clock =3D $clock; + type Expires =3D $expires; + } + }; } =20 -/// Timer with relative expiration time, pinned to its current CPU. -pub struct RelativePinnedMode; - -impl HrTimerMode for RelativePinnedMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED; +define_hrtimer_mode! { + /// Timer that expires at a fixed point in time. + pub struct AbsoluteMode { + c =3D HRTIMER_MODE_ABS, + expires =3D Instant + } } =20 -/// Timer with absolute expiration, handled in soft irq context. -pub struct AbsoluteSoftMode; - -impl HrTimerMode for AbsoluteSoftMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_SOFT; +define_hrtimer_mode! { + /// Timer that expires after a delay from now. + pub struct RelativeMode { + c =3D HRTIMER_MODE_REL, + expires =3D Delta + } } =20 -/// Timer with relative expiration, handled in soft irq context. -pub struct RelativeSoftMode; - -impl HrTimerMode for RelativeSoftMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_SOFT; +define_hrtimer_mode! { + /// Timer with absolute expiration time, pinned to its current CPU. + pub struct AbsolutePinnedMode { + c =3D HRTIMER_MODE_ABS_PINNED, + expires =3D Instant + } } =20 -/// Timer with absolute expiration, pinned to CPU and handled in soft irq = context. -pub struct AbsolutePinnedSoftMode; - -impl HrTimerMode for AbsolutePinnedSoftMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED_SOFT; +define_hrtimer_mode! { + /// Timer with relative expiration time, pinned to its current CPU. + pub struct RelativePinnedMode { + c =3D HRTIMER_MODE_REL_PINNED, + expires =3D Delta + } } =20 -/// Timer with relative expiration, pinned to CPU and handled in soft irq = context. -pub struct RelativePinnedSoftMode; - -impl HrTimerMode for RelativePinnedSoftMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED_SOFT; +define_hrtimer_mode! { + /// Timer with absolute expiration, handled in soft irq context. + pub struct AbsoluteSoftMode { + c =3D HRTIMER_MODE_ABS_SOFT, + expires =3D Instant + } } =20 -/// Timer with absolute expiration, handled in hard irq context. -pub struct AbsoluteHardMode; - -impl HrTimerMode for AbsoluteHardMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_HARD; +define_hrtimer_mode! { + /// Timer with relative expiration, handled in soft irq context. + pub struct RelativeSoftMode { + c =3D HRTIMER_MODE_REL_SOFT, + expires =3D Delta + } } =20 -/// Timer with relative expiration, handled in hard irq context. -pub struct RelativeHardMode; +define_hrtimer_mode! { + /// Timer with absolute expiration, pinned to CPU and handled in soft = irq context. + pub struct AbsolutePinnedSoftMode { + c =3D HRTIMER_MODE_ABS_PINNED_SOFT, + expires =3D Instant + } +} =20 -impl HrTimerMode for RelativeHardMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_HARD; +define_hrtimer_mode! { + /// Timer with absolute expiration, pinned to CPU and handled in soft = irq context. + pub struct RelativePinnedSoftMode { + c =3D HRTIMER_MODE_REL_PINNED_SOFT, + expires =3D Delta + } } =20 -/// Timer with absolute expiration, pinned to CPU and handled in hard irq = context. -pub struct AbsolutePinnedHardMode; +define_hrtimer_mode! { + /// Timer with absolute expiration, handled in hard irq context. + pub struct AbsoluteHardMode { + c =3D HRTIMER_MODE_ABS_HARD, + expires =3D Instant + } +} =20 -impl HrTimerMode for AbsolutePinnedHardMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED_HARD; +define_hrtimer_mode! { + /// Timer with relative expiration, handled in hard irq context. + pub struct RelativeHardMode { + c =3D HRTIMER_MODE_REL_HARD, + expires =3D Delta + } } =20 -/// Timer with relative expiration, pinned to CPU and handled in hard irq = context. -pub struct RelativePinnedHardMode; +define_hrtimer_mode! { + /// Timer with absolute expiration, pinned to CPU and handled in hard = irq context. + pub struct AbsolutePinnedHardMode { + c =3D HRTIMER_MODE_ABS_PINNED_HARD, + expires =3D Instant + } +} =20 -impl HrTimerMode for RelativePinnedHardMode { - const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED_HARD; +define_hrtimer_mode! { + /// Timer with relative expiration, pinned to CPU and handled in hard = irq context. + pub struct RelativePinnedHardMode { + c =3D HRTIMER_MODE_REL_PINNED_HARD, + expires =3D Delta + } } =20 /// Use to implement the [`HasHrTimer`] trait. --=20 2.43.0 From nobody Mon Feb 9 13:59:18 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 0306917A31C; Sun, 4 May 2025 05:00:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334830; cv=none; b=uscj4hIf9MC1hJltqr4BtOmBVhzjkdfJj0X6BobdvtHgy61NDttwS/00HwKvwJY4nngzrwuoZ9FSWilc1E25ZB04AmkiXsY2GLTUOmrbfvxzOvwn24R0LwJlFQDz8VfCS9HK02L5rcA8XAXhW3zKXaYSLzGpc27r8yXd4cBsdR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334830; c=relaxed/simple; bh=FlPQ9iXVFrxRTyfeW2IF8MHi0vTPl/cxV5k8adyJ8P0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lx/GSIyn4M2K7x7afIlhYsbBH1LJDhGZfCPb1gBQKcYMu4FxHec0WAPNrvUGxQ+eheaHs8yx3zE1xzpIzpxWZOko1MSSlk0FRdLYkSnnqi06qGwy8qX+CJTTMQSlAC4gGeiJrsUH3pkt9lmqEDx+fMCoQNJlWTPLZIxytvNM8gQ= 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=ESmDqW51; arc=none smtp.client-ip=209.85.210.182 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="ESmDqW51" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-736c277331eso4145467b3a.1; Sat, 03 May 2025 22:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746334828; x=1746939628; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cjbGYG+8x4M0bAgJSxWznYro2eOFp8zdnX+tDzzFfAQ=; b=ESmDqW51O5WFETChONWteLCfF9eKAJFwkxradMo//MWxacIhBOUGDv6zXFSjTT9MET Yyc77hL4FSAOlTgi/ndka2n8mZlUzVUhazH5l3eOOQccojbKEkqC6K/5bMcxnOZtfRLI UI+iL0lPu2DXfBZpoDFbPalrLj8hkNTLRqbZWrdlyhQ7eLphwBtbgSo7Bu5QqBRFRwOP aQm5p3t3nvVI0uZKKkZZboqs7PA6xyn1CLYd9Io9p7CSPkFtklsb7IAvsQ9AGDQriDQ2 mvDNLioBIY3P1kmJgwSZf9b4d4nGiDmX7WX86DqGJku8/w7yY3Vav1dW9+HfWOO2uZho lkbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746334828; x=1746939628; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cjbGYG+8x4M0bAgJSxWznYro2eOFp8zdnX+tDzzFfAQ=; b=Hij9egLEBqj1PK3K4PIKHR4VEXbGVmblesLH9FOJd7mqMLOZyJgPT5aUXpU21hhpLO 9vm7iXz/652LuaE6bkU+6mA4ixobK4BUrPMBhE75+0BFfb5KJmzp9B+vvX68GXVrhYjq 3b8Bc7H+m409RqfFlVrg0XAjK3A5OY7Tv/MCo5cdMpEcp2gAR+h7pKr97OQRC0PRnLLC l+M/TOsfo6ivAgcb08tR5NnMG/b9n/qNWm7GPrII6vGaQWUspRe9X9DjALRw46TzPHAq 69eYhWaCYDSo+ydYDy8s+WtKiGYRlCH5AAFSPdaBCybu+3eA3dFrZQK8d4kc7W2joA9Z 4CUw== X-Forwarded-Encrypted: i=1; AJvYcCU+tt5UU7y4rcVRSw9/fMLRtbMppm2I9Zr4UpAsP2Y8NGqqkD9S7Iz2F5Juz8k+CsKHoKmMbiSnA8ZzYBw=@vger.kernel.org X-Gm-Message-State: AOJu0YzCbpTUms4mntjsBzZboIz470ttUThH8/VuyAbbBw2pxZgWZLoA c7Vu/Ua51tO17PATlSAtg69dI6LD+ZEHbHa9SrRFThM+XHDKQ2SJNi9JU2d7 X-Gm-Gg: ASbGncs9/XRk6wEjo1btKWSmvMBmLzvFD+pYngymYPnAo2dbyINOPdCLzPKUOHIsvoh YfLbeKiHMpJGz3nHe4vKUr71hIEWxzABkSkXJ26JCab67SAd1jDYNp7DvRWIMPpMndRcT+ZUGGw QPle1LYqYV4A1bqjszuGLwp7CsWuHJO5F7CjOjiFMiHCN7HxU1DjlGNMaH6dl+5r3/okQuO/9Lx yWwBdJrvabqHyIppC9Xns/Wu8zTribGO7x1MkB45e/Z0DYTQgQXcFdjDI0JI4932xN60+4jPGq7 cY0d/3YxU0R49ebkj28xPoizf8y6Gx8uI/adT8SJtXAmSZUuhzIgph+7zp3kMf1dDiXQyWUezJ8 jJskyYH7GUtpvQM0yTw== X-Google-Smtp-Source: AGHT+IHVEpj3wb5RIgV9GVVQVJSdQwzAt+7ryU19fwFo/E9To3S8UZg3OFb90oJBkv6j17Y/8Zc1YQ== X-Received: by 2002:a05:6a20:ce48:b0:1f5:9cdc:54bb with SMTP id adf61e73a8af0-20bd766234bmr16163940637.11.1746334827679; Sat, 03 May 2025 22:00:27 -0700 (PDT) Received: from mew.. (p4138183-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.129.206.183]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058db91dasm4225756b3a.44.2025.05.03.22.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 May 2025 22:00:27 -0700 (PDT) From: FUJITA Tomonori To: rust-for-linux@vger.kernel.org Cc: a.hindborg@kernel.org, boqun.feng@gmail.com, frederic@kernel.org, lyude@redhat.com, tglx@linutronix.de, anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/5] rust: time: Make HasHrTimer generic over HrTimerMode Date: Sun, 4 May 2025 13:59:57 +0900 Message-ID: <20250504045959.238068-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250504045959.238068-1-fujita.tomonori@gmail.com> References: <20250504045959.238068-1-fujita.tomonori@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" Add a `TimerMode` associated type to the `HasHrTimer` trait to represent the operational mode of the timer, such as absolute or relative expiration. This new type must implement the `HrTimerMode` trait, which defines how expiration values are interpreted. Update the `start()` method to accept an `expires` parameter of type `::Expires` instead of the fixed `Ktime`. This enables different timer modes to provide strongly typed expiration values, such as `Instant` or `Delta`. The `impl_has_hr_timer` macro is also extended to allow specifying the `HrTimerMode`. In the following example, it guarantees that the `start()` method for `Foo` only accepts `Instant`. Using a `Delta` or an `Instant` with a different clock source will result in a compile-time error: struct Foo { #[pin] timer: HrTimer, } impl_has_hr_timer! { impl HasHrTimer for Foo { mode =3D AbsoluteMode, self.timer } } This design eliminates runtime mismatches between expires types and clock sources, and enables stronger type-level guarantees throughout hrtimer. Signed-off-by: FUJITA Tomonori --- rust/kernel/time/hrtimer.rs | 55 ++++++++++++++++++++++------- rust/kernel/time/hrtimer/arc.rs | 8 +++-- rust/kernel/time/hrtimer/pin.rs | 8 +++-- rust/kernel/time/hrtimer/pin_mut.rs | 8 +++-- rust/kernel/time/hrtimer/tbox.rs | 8 +++-- 5 files changed, 66 insertions(+), 21 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 55e1825425b6..3355ae6fe76d 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -98,7 +98,6 @@ pub fn to_ns(self) -> i64 { pub struct HrTimer { #[pin] timer: Opaque, - mode: bindings::hrtimer_mode, _t: PhantomData, } =20 @@ -112,9 +111,10 @@ unsafe impl Sync for HrTimer {} =20 impl HrTimer { /// Return an initializer for a new timer instance. - pub fn new() -> impl PinInit + pub fn new() -> impl PinInit where T: HrTimerCallback, + T: HasHrTimer, { pin_init!(Self { // INVARIANT: We initialize `timer` with `hrtimer_setup` below. @@ -126,12 +126,11 @@ pub fn new() -> impl = PinInit bindings::hrtimer_setup( place, Some(T::Pointer::run), - U::ID, - M::C_MODE, + <>::TimerMode as HrTimerMode>::= Clock::ID, + >::TimerMode::C_MODE, ); } }), - mode: M::C_MODE, _t: PhantomData, }) } @@ -193,6 +192,11 @@ pub(crate) unsafe fn raw_cancel(this: *const Self) -> = bool { /// exist. A timer can be manipulated through any of the handles, and a ha= ndle /// may represent a cancelled timer. pub trait HrTimerPointer: Sync + Sized { + /// The operational mode associated with this timer. + /// + /// This defines how the expiration value is interpreted. + type TimerMode: HrTimerMode; + /// A handle representing a started or restarted timer. /// /// If the timer is running or if the timer callback is executing when= the @@ -205,7 +209,7 @@ pub trait HrTimerPointer: Sync + Sized { =20 /// Start the timer with expiry after `expires` time units. If the tim= er was /// already running, it is restarted with the new expiry time. - fn start(self, expires: Ktime) -> Self::TimerHandle; + fn start(self, expires: ::Expires) -> = Self::TimerHandle; } =20 /// Unsafe version of [`HrTimerPointer`] for situations where leaking the @@ -220,6 +224,11 @@ pub trait HrTimerPointer: Sync + Sized { /// [`UnsafeHrTimerPointer`] outlives any associated [`HrTimerPointer::Tim= erHandle`] /// instances. pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { + /// The operational mode associated with this timer. + /// + /// This defines how the expiration value is interpreted. + type TimerMode: HrTimerMode; + /// A handle representing a running timer. /// /// # Safety @@ -236,7 +245,7 @@ pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { /// /// Caller promises keep the timer structure alive until the timer is = dead. /// Caller can ensure this by not leaking the returned [`Self::TimerHa= ndle`]. - unsafe fn start(self, expires: Ktime) -> Self::TimerHandle; + unsafe fn start(self, expires: ::Expir= es) -> Self::TimerHandle; } =20 /// A trait for stack allocated timers. @@ -246,9 +255,14 @@ pub unsafe trait UnsafeHrTimerPointer: Sync + Sized { /// Implementers must ensure that `start_scoped` does not return until the /// timer is dead and the timer handler is not running. pub unsafe trait ScopedHrTimerPointer { + /// The operational mode associated with this timer. + /// + /// This defines how the expiration value is interpreted. + type TimerMode: HrTimerMode; + /// Start the timer to run after `expires` time units and immediately /// after call `f`. When `f` returns, the timer is cancelled. - fn start_scoped(self, expires: Ktime, f: F) -> T + fn start_scoped(self, expires: := :Expires, f: F) -> T where F: FnOnce() -> T; } @@ -260,7 +274,13 @@ unsafe impl ScopedHrTimerPointer for T where T: UnsafeHrTimerPointer, { - fn start_scoped(self, expires: Ktime, f: F) -> U + type TimerMode =3D T::TimerMode; + + fn start_scoped( + self, + expires: <::TimerMode as HrTimerMode>::= Expires, + f: F, + ) -> U where F: FnOnce() -> U, { @@ -335,6 +355,11 @@ pub unsafe trait HrTimerHandle { /// their documentation. All the methods of this trait must operate on the= same /// field. pub unsafe trait HasHrTimer { + /// The operational mode associated with this timer. + /// + /// This defines how the expiration value is interpreted. + type TimerMode: HrTimerMode; + /// Return a pointer to the [`HrTimer`] within `Self`. /// /// This function is useful to get access to the value without creating @@ -382,14 +407,14 @@ unsafe fn c_timer_ptr(this: *const Self) -> *const bi= ndings::hrtimer { /// - `this` must point to a valid `Self`. /// - Caller must ensure that the pointee of `this` lives until the ti= mer /// fires or is canceled. - unsafe fn start(this: *const Self, expires: Ktime) { + unsafe fn start(this: *const Self, expires: ::Expires) { // SAFETY: By function safety requirement, `this` is a valid `Self= `. unsafe { bindings::hrtimer_start_range_ns( Self::c_timer_ptr(this).cast_mut(), - expires.to_ns(), + expires.as_nanos(), 0, - (*Self::raw_get_timer(this)).mode, + ::Clock::ID as u32, ); } } @@ -579,12 +604,16 @@ macro_rules! impl_has_hr_timer { impl$({$($generics:tt)*})? HasHrTimer<$timer_type:ty> for $self:ty - { self.$field:ident } + { + mode =3D $mode:ty, + self.$field:ident + } $($rest:tt)* ) =3D> { // SAFETY: This implementation of `raw_get_timer` only compiles if= the // field has the right type. unsafe impl$(<$($generics)*>)? $crate::time::hrtimer::HasHrTimer<$= timer_type> for $self { + type TimerMode =3D $mode; =20 #[inline] unsafe fn raw_get_timer( diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc= .rs index ccf1e66e5b2d..ed490a7a8950 100644 --- a/rust/kernel/time/hrtimer/arc.rs +++ b/rust/kernel/time/hrtimer/arc.rs @@ -4,8 +4,8 @@ use super::HrTimer; use super::HrTimerCallback; use super::HrTimerHandle; +use super::HrTimerMode; use super::HrTimerPointer; -use super::Ktime; use super::RawHrTimerCallback; use crate::sync::Arc; use crate::sync::ArcBorrow; @@ -54,9 +54,13 @@ impl HrTimerPointer for Arc T: HasHrTimer, T: for<'a> HrTimerCallback =3D Self>, { + type TimerMode =3D >::TimerMode; type TimerHandle =3D ArcHrTimerHandle; =20 - fn start(self, expires: Ktime) -> ArcHrTimerHandle { + fn start( + self, + expires: <>::TimerMode as HrTimerMode>::Expires, + ) -> ArcHrTimerHandle { // SAFETY: // - We keep `self` alive by wrapping it in a handle below. // - Since we generate the pointer passed to `start` from a valid diff --git a/rust/kernel/time/hrtimer/pin.rs b/rust/kernel/time/hrtimer/pin= .rs index 293ca9cf058c..550aad28d987 100644 --- a/rust/kernel/time/hrtimer/pin.rs +++ b/rust/kernel/time/hrtimer/pin.rs @@ -4,7 +4,7 @@ use super::HrTimer; use super::HrTimerCallback; use super::HrTimerHandle; -use super::Ktime; +use super::HrTimerMode; use super::RawHrTimerCallback; use super::UnsafeHrTimerPointer; use core::pin::Pin; @@ -54,9 +54,13 @@ unsafe impl<'a, T> UnsafeHrTimerPointer for Pin<&'a T> T: HasHrTimer, T: HrTimerCallback =3D Self>, { + type TimerMode =3D >::TimerMode; type TimerHandle =3D PinHrTimerHandle<'a, T>; =20 - unsafe fn start(self, expires: Ktime) -> Self::TimerHandle { + unsafe fn start( + self, + expires: <>::TimerMode as HrTimerMode>::Expires, + ) -> Self::TimerHandle { // Cast to pointer let self_ptr: *const T =3D self.get_ref(); =20 diff --git a/rust/kernel/time/hrtimer/pin_mut.rs b/rust/kernel/time/hrtimer= /pin_mut.rs index 6033572d35ad..bacd3d5d972a 100644 --- a/rust/kernel/time/hrtimer/pin_mut.rs +++ b/rust/kernel/time/hrtimer/pin_mut.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 =20 use super::{ - HasHrTimer, HrTimer, HrTimerCallback, HrTimerHandle, Ktime, RawHrTimer= Callback, + HasHrTimer, HrTimer, HrTimerCallback, HrTimerHandle, HrTimerMode, RawH= rTimerCallback, UnsafeHrTimerPointer, }; use core::{marker::PhantomData, pin::Pin, ptr::NonNull}; @@ -52,9 +52,13 @@ unsafe impl<'a, T> UnsafeHrTimerPointer for Pin<&'a mut = T> T: HasHrTimer, T: HrTimerCallback =3D Self>, { + type TimerMode =3D >::TimerMode; type TimerHandle =3D PinMutHrTimerHandle<'a, T>; =20 - unsafe fn start(mut self, expires: Ktime) -> Self::TimerHandle { + unsafe fn start( + mut self, + expires: <>::TimerMode as HrTimerMode>::Expires, + ) -> Self::TimerHandle { // SAFETY: // - We promise not to move out of `self`. We only pass `self` // back to the caller as a `Pin<&mut self>`. diff --git a/rust/kernel/time/hrtimer/tbox.rs b/rust/kernel/time/hrtimer/tb= ox.rs index 29526a5da203..ec08303315f2 100644 --- a/rust/kernel/time/hrtimer/tbox.rs +++ b/rust/kernel/time/hrtimer/tbox.rs @@ -4,8 +4,8 @@ use super::HrTimer; use super::HrTimerCallback; use super::HrTimerHandle; +use super::HrTimerMode; use super::HrTimerPointer; -use super::Ktime; use super::RawHrTimerCallback; use crate::prelude::*; use core::ptr::NonNull; @@ -64,9 +64,13 @@ impl HrTimerPointer for Pin> T: for<'a> HrTimerCallback =3D Pin>>, A: crate::alloc::Allocator, { + type TimerMode =3D >::TimerMode; type TimerHandle =3D BoxHrTimerHandle; =20 - fn start(self, expires: Ktime) -> Self::TimerHandle { + fn start( + self, + expires: <>::TimerMode as HrTimerMode>::Expires, + ) -> Self::TimerHandle { // SAFETY: // - We will not move out of this box during timer callback (we p= ass an // immutable reference to the callback). --=20 2.43.0 From nobody Mon Feb 9 13:59:18 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 D98CB18DB18; Sun, 4 May 2025 05:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334834; cv=none; b=ue1duRjAp1Rc4TZglIXaLhIa4YNVNkZgh4xtIj/Ao/nC6TSG8yoDnZZsK2rzUTB/g91/O4x80jKPV7ouWaY3eKf+XMw5NgDhz5GzStg4tKsQIKQH5RbQpphsM6bPQVgWiB6SsGwSuYzwimpws+slEQey4mGHh97zJ8BwA66UDSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746334834; c=relaxed/simple; bh=BKYFylhCTXnSJ3PMuuaK85GfBtfvO9sTwbjzfzDc6KA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t2Mnd69DPokARNeyME0s+/i3aS15F7OlTaqnx0JeERLIiNy7GiF1WclYu4k7jYKu17N8lO7dxIz0QBqmhMqR/PB11EKB3xnvyt3/g0hDpSGp6pMzzEYspQNAsGGRQ3VUPL8p7wZ7fOMcGpisZcZXoCpjwiV53UlAz0urjrKij6Q= 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=XdrBK9q6; arc=none smtp.client-ip=209.85.210.178 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="XdrBK9q6" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-736c3e7b390so3881866b3a.2; Sat, 03 May 2025 22:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746334832; x=1746939632; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BAtLYBrIM9/ajJYtasF5l8HBHfz0+HezoBSoeR9Mong=; b=XdrBK9q6VDwJBJAhkAfomiqV/NOQsFF3arnGSZU+3iuvHXdRijpO8+0RjuWNzALT6A eY31LsrDfhngA0dP6kYPbqSipRJZAUxHf6qAAKXfUHJqoLpoEv2MXK33ePzjG0Fatcd1 2mD2DaAlY2MKyARQTpwltqi28HMkxYgXktIaAdP/HkZ+Iq3C1LvKipvEJSmcHXZ9hAJC LUfIdERg4uCpAIg2FEjYu0xHr+pgVsDuZhPgQeHXxahEmo6vwlqibIvDpK+5m7Si2XSl yaSoYPZo+Bk/PpOEbuebeALC3vzinWgjDDweFSXpVhbXL/PTK8qQLJgt8/Kj9PZMLFEc +Jcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746334832; x=1746939632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BAtLYBrIM9/ajJYtasF5l8HBHfz0+HezoBSoeR9Mong=; b=brZQIDC47beNaJ88eN9t2Cci+vqbY6T0QFjCfTsnCvCm77e7oGDAi4tu+065YjrPaW aEG+qfcIm1sjTGkcDsL3d3/Q/7j+n8sPefSz9CDzPVL4lyEXCFF6e4SduYlCXw25p4Sj CP+S++lsKtabh1M/nmYyoIp8+wQUUaYm8kVaCMeE7UVyxIm7M3MUCh1XsgmiTwii9HrK QDMkQrq5VWXeMSfhe6+69qf+MoGUMWwGz0Ry4rRdeHbnunoaepd9BjdPWGZwdlhH/mnI zh4im41N75SXrT+fMLzRq4odbyxaApzMKF8RRN5h9lqTETl7R3P/EQ5oOwJNsn6lGFj6 pt2A== X-Forwarded-Encrypted: i=1; AJvYcCXrN6FetYRWj/mp1V2q4n6ac7qr9Z/ATl9t9LFkxMLD40OHq7aFlqaC3QztWG0ihdwl+I08+QFlmfHC/SM=@vger.kernel.org X-Gm-Message-State: AOJu0YxEoHjgyJt14DODcsqEGJg1PZGuZpCveYPXK5HlStXOEm1nFPfF +sXdQi54LEK45YlCpHK/8GYiv/J51XVOopcmkVPi+kKWSSkRQKWKsFRIslFP X-Gm-Gg: ASbGnctioz1IHiHKdWxRCXPotXXoL/suXDrDfM+TfcvM9w2BRKbCjf/yjaO1VFg7vMs WH8gAJ1mcK4p+izPgBBVRmh/YHwo3HCBIR4L1caEnfkxodWoFLhDFlhgMVfbXKE2qqZPfHJMPDw 4DYKRLR0HmWrF1sTT8PXxfZfEPyBukgLQiEaa3aUg6h7Hp3RRAnkU1DxNFDirV1wZp211Ri99PQ AXoQb9SpE61TxaPk4hjMj640JRvLkGkPfnMk1pl4U/n5BYkVaI9hL05SFAc0/FxrdHncU6WQd4Z 0He+FckBYjimr/8nQzyK6dbrfYO8D/qnTZW987BE0Fb62maB8qrluAsInoluL4NulMHXa6te0bT 2N8nO7TQDoQ69xDN9nyptytqvyIK2 X-Google-Smtp-Source: AGHT+IFdxQJB/suLSC5KY0vhzDnmqJVYahHZj/LCDVtudCFG+nUAOQBEjr7DDKNM+n+NKmrbYxKhcQ== X-Received: by 2002:a05:6a00:32cb:b0:736:450c:fa54 with SMTP id d2e1a72fcca58-7406f0adf7cmr3670436b3a.6.1746334831893; Sat, 03 May 2025 22:00:31 -0700 (PDT) Received: from mew.. (p4138183-ipxg22701hodogaya.kanagawa.ocn.ne.jp. [153.129.206.183]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058db91dasm4225756b3a.44.2025.05.03.22.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 May 2025 22:00:31 -0700 (PDT) From: FUJITA Tomonori To: rust-for-linux@vger.kernel.org Cc: a.hindborg@kernel.org, boqun.feng@gmail.com, frederic@kernel.org, lyude@redhat.com, tglx@linutronix.de, anna-maria@linutronix.de, jstultz@google.com, sboyd@kernel.org, ojeda@kernel.org, alex.gaynor@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/5] rust: time: Remove Ktime in hrtimer Date: Sun, 4 May 2025 13:59:58 +0900 Message-ID: <20250504045959.238068-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250504045959.238068-1-fujita.tomonori@gmail.com> References: <20250504045959.238068-1-fujita.tomonori@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" Remove the use of `Ktime` from the hrtimer code, which was originally introduced as a temporary workaround. The hrtimer has now been fully converted to use the `Instant` and `Delta` types instead. Signed-off-by: FUJITA Tomonori Reviewed-by: Andreas Hindborg --- rust/kernel/time/hrtimer.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index 3355ae6fe76d..e396c27e0e1a 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -72,22 +72,6 @@ use core::marker::PhantomData; use pin_init::PinInit; =20 -/// A Rust wrapper around a `ktime_t`. -// NOTE: Ktime is going to be removed when hrtimer is converted to Instant= /Delta. -#[repr(transparent)] -#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord)] -pub struct Ktime { - inner: bindings::ktime_t, -} - -impl Ktime { - /// Returns the number of nanoseconds. - #[inline] - pub fn to_ns(self) -> i64 { - self.inner - } -} - /// A timer backed by a C `struct hrtimer`. /// /// # Invariants --=20 2.43.0