From nobody Sat Oct 11 12:12:43 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.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 14F2C23AB8D; Tue, 10 Jun 2025 13:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562120; cv=none; b=NDa83U7sM2JVx3HJvIRdfkZhFPthgp6qWW30KMiGh24SlsEYWmI6Besvk7zz3MjlHnnGdmjuo714vFpH9uBMZJFsTXhTbRZ1fqZLyjks3ENPhiUp3A9O76NukCobpe3Sz9bmwtupqj2zYVNeOzfwDNGJYRuJLOtBEJH5OKZ7wMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562120; c=relaxed/simple; bh=4hyk0K8UbeOWdvX5D5fgy3eh4gAR9L/juUd7uhWoWKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZIn9hEi7K981Oolmp/J8TA062SFaJahsgXsSm2uvTSwfMsLIzk+KIGuuAvHaED1w3G/9cZeEWMhPNlRLgJTtXYvcOk08WKCK7FlXSTTQJ7W79vhMws2kfsTXn4qGosPjqY+3Sm7pa6a6lkpjAErWb1p7VlI6q/kCFh/p00wiKM= 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=Qx7IqIEB; arc=none smtp.client-ip=209.85.214.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="Qx7IqIEB" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-235e1d710d8so66581045ad.1; Tue, 10 Jun 2025 06:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749562118; x=1750166918; 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=omwJ5JP66L/+9sD/AxglLPlZQ7EGc6XcrGECQtUSke0=; b=Qx7IqIEBfRmSWTGbrrs8JvpnyT/gD9sh7vtyRVHK7GbpUTYJ+RwG7YfDOxbbd7Ne8u /7FRZ4AOsqJc+eqxgOFMHlpwSXakewxyuxwkDVhG77S5TtlYe4Y2RuVP73uuOZQBvujH X+M6n7hmccVIUSKL/x1baJvDFBhNuRsV/10wnn8u2cpJNOOmMZ5PMsOVpalxf8BvxMDA MQWc5W+n89sLi1+25JQd/FsP2vkNHDBHDG5LcvBBGXYNAtYEFLiM2vMGz1Tgn3JRc5ov ESY3eSteSokXSqK//M+LOrZwLTNnxali/lPLZBbbMpfj35hCqXdGF9BvlqYK2vJ5pjLl 0Ybg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749562118; x=1750166918; 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=omwJ5JP66L/+9sD/AxglLPlZQ7EGc6XcrGECQtUSke0=; b=uCPlBvcw65epdJBVTfoj0K36vJs/GJx6KUZWpO/iHTNQQl6iandn+yKdZ5jb4lbPeb bmoRb/TjfpMw4WrONCMW9m7PoPlDPISAkgvvdTC/Vm52pNwkH5OIxCmDz9poVoldReQv UhJsjFubSB/cPndfEcqKSJ2kEntpQHLJaPGkLN+jqKc01JllmEho4BmGjpGHgGvXORDC CBStt83JV7YODGsamEbmyBXUdcGNwoM3+8FYI8TxkQFh0M6BXew7y2IT1KHOCekb7qJI y+2Kc6ebNEVNFINP1o0xdhMXoSslbns9SX/wT4cJziMMN00Lz7UlqBdTRJJ1A3tE/h+j IClA== X-Forwarded-Encrypted: i=1; AJvYcCUtDxtIVMgK7lJeGIWmLDkNuMYCUBxs46muDs883mlGum1RBDTz7MS7+0TAvpbd8pYmH8W/+OTPBd0WNYI=@vger.kernel.org, AJvYcCXm8e78F4GBcDJVISYh/S31CS8pFWealYXGbaQDf0mzNkDvB0+rkkJhvEDIWfcHQ5VUtRqk5qYnhh7MIxc229I=@vger.kernel.org X-Gm-Message-State: AOJu0YwaS2Ty/TFFStOUSjMk1ISx/Zm9fV8PSzTBgcP37Kz7SDJVaAgv ygIw9aUknhN8ZCzYTghEnCgJgnu8N7EbGqfOKdi4fDra8O4+RFP3z6Lu X-Gm-Gg: ASbGncuxyW9z9kHUrxNtM7cXCs0a2mf+AIPSt1T4iBgsKHzq3SAt/kR8HNHQ+M9YdCj X9p5vE8Ur3Tosql+70QyXnkKjbs6mFhTgwL+v113X58KX9YWt8JIwZrEXFdhT5W3bPKsT2jaAMK 9FJVaV2H4iaIqWliL9904ElAQl2ZQ6Bnb+aJdzphGgUFbTnfESoUkMCsS1AcL84iTaD1A73YNUe 0L7s8Eg1GGBwomgevyTo92IJzdv7/UkBuFzmOAjVPfSKQ/Vak1hSFXz1/rFlL2jlRsZdkUQJa+P +3R1xgPRNUj6z30QDqOG75PW8ueH4P5D3fwvjoWrRrK+AGB5IyCamH7UnRBiCb4rKK9uv6VYl7d ZEyCK69JBsw2mlWI2v7Kle35LPn4uDBRJgLo= X-Google-Smtp-Source: AGHT+IHFo4Hj568NXhmQHnRzk5hYOvgTrZaZ+Gt8La/fb87IINto/aqaIIaswE7l9do8CcalpsDslw== X-Received: by 2002:a17:902:ea04:b0:224:24d3:6103 with SMTP id d9443c01a7336-23638342d1cmr40756195ad.35.1749562118258; Tue, 10 Jun 2025 06:28:38 -0700 (PDT) Received: from bee.. (p5332007-ipxg23901hodogaya.kanagawa.ocn.ne.jp. [180.34.120.7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3134b128050sm7969276a91.25.2025.06.10.06.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 06:28:37 -0700 (PDT) From: FUJITA Tomonori To: a.hindborg@kernel.org, alex.gaynor@gmail.com, ojeda@kernel.org Cc: aliceryhl@google.com, anna-maria@linutronix.de, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, frederic@kernel.org, gary@garyguo.net, jstultz@google.com, linux-kernel@vger.kernel.org, lossin@kernel.org, lyude@redhat.com, rust-for-linux@vger.kernel.org, sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu Subject: [PATCH v3 1/5] rust: time: Rename Delta's methods from as_* to into_* Date: Tue, 10 Jun 2025 22:28:19 +0900 Message-ID: <20250610132823.3457263-2-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610132823.3457263-1-fujita.tomonori@gmail.com> References: <20250610132823.3457263-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" Rename Delta's methods that take self from as_* to into_* to align with Rust naming conventions. Using `self` is more common Rust practice for small values that can be freely copied [1]. Clippy warns against using as_* names for trait methods that take self as follows: warning: methods called as_* usually take self by reference or self by muta= ble reference --> ~/linux/rust/kernel/time/hrtimer.rs:421:17 | 421 | fn as_nanos(self) -> i64; Rename the `Delta` struct's methods from as_nanos(), as_micros_ceil(), and as_millis() to into_nanos(), into_micros_ceil(), and into_millis(), respectively to maintain consistency with the other function names. Link: https://lore.kernel.org/lkml/aD1fgizC4FPT07vt@google.com/ [1] Reviewed-by: Andreas Hindborg Signed-off-by: FUJITA Tomonori --- rust/kernel/time.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 9fd487276457..2a231c321afa 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -261,31 +261,31 @@ pub const fn from_secs(secs: i64) -> Self { /// Return `true` if the [`Delta`] spans no time. #[inline] pub fn is_zero(self) -> bool { - self.as_nanos() =3D=3D 0 + self.into_nanos() =3D=3D 0 } =20 /// Return `true` if the [`Delta`] spans a negative amount of time. #[inline] pub fn is_negative(self) -> bool { - self.as_nanos() < 0 + self.into_nanos() < 0 } =20 /// Return the number of nanoseconds in the [`Delta`]. #[inline] - pub const fn as_nanos(self) -> i64 { + pub const fn into_nanos(self) -> i64 { self.nanos } =20 /// Return the smallest number of microseconds greater than or equal /// to the value in the [`Delta`]. #[inline] - pub const fn as_micros_ceil(self) -> i64 { - self.as_nanos().saturating_add(NSEC_PER_USEC - 1) / NSEC_PER_USEC + pub const fn into_micros_ceil(self) -> i64 { + self.into_nanos().saturating_add(NSEC_PER_USEC - 1) / NSEC_PER_USEC } =20 /// Return the number of milliseconds in the [`Delta`]. #[inline] - pub const fn as_millis(self) -> i64 { - self.as_nanos() / NSEC_PER_MSEC + pub const fn into_millis(self) -> i64 { + self.into_nanos() / NSEC_PER_MSEC } } --=20 2.43.0 From nobody Sat Oct 11 12:12:43 2025 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 5A46323ABAA; Tue, 10 Jun 2025 13:28:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562125; cv=none; b=NJ+alBCui79n1T/x7o7SJK314YUBG4X111Tsub3Xq4sBx61/Y/fpm+Akx8R2ZxTydugIKUnsIkgiA1cfoL7hv4j0jYO3jn5K/HQdqAd9IMhNU3FAM6WuuAGHjRxsEz7fwIBf1QAP9QNwEhslPzT3oqbgg+ckhqyP5hDkt6fTxR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562125; c=relaxed/simple; bh=NRoPuLsRJOm5rC5ZB155G6bpOMGKHlkV77L8xCoa4OE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=De2Qv4xgoNFzYLkUHCnChQFXYKKtOefUui5wgbB/OYjGv/EWONbDk7GzRXVSBCgpmjQCufVSiUoAmXOZGDcBlcwZLRDpJUbdQXHUmv6uI3VZIGLjd2T1E6HnB4matcf3svvYXE1QQfywz27wB6+4SuX4m0izCQ11elipGUa+glA= 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=HYLVuPZr; arc=none smtp.client-ip=209.85.215.174 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="HYLVuPZr" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-b0b2d0b2843so3636365a12.2; Tue, 10 Jun 2025 06:28:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749562122; x=1750166922; 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=1mvvzlMbDdYmXYPtcaFob3b+rqUp5cEbqhNbwJWVQeI=; b=HYLVuPZrmQPGHKmGKhFoHGLhufytZoDTd//edxU+7OJgkHsZkBJO+/WGke32uf4Ydh zLWOAUSr4Yj7FFsPFoP6ESlmPHf/eE+/Jgk2TSpchMFFVXZ/k2v0Pii9/G0KolxdfXIg Sl7p0qUxgbQs/t9Th8YjLw17gmDKKWu1gkdi8QPNuj22NTGXd+xXi+9pzFbLUL45Ml6D VwIvWpNjEsPR8qITEpcvZtC4or5h8efb5Z91ins/dZcrLwGhm/NL6g4TVZuCZaRqmHXN 9T4CGsbq5pz2vKEu3GcdfoNbgFprE8ZAZDaScgJ5597gz/7zKHwvLFigGE8dkWupLHE4 4rBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749562122; x=1750166922; 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=1mvvzlMbDdYmXYPtcaFob3b+rqUp5cEbqhNbwJWVQeI=; b=hp4a1lMMXlqqlTPdSZGKvmq9iJnp0zUUUvBp1VAq+RWTJmVJp09pbAF1SwEMEN74vR HG/VM2sioiNDrdLLuIZ5shA+50LCwDvf4qx8rwWcphf003UoOXwagQBbPtokipml8Fyg 621wDz1F1Fojjy8/7lS/NzRgPU79sfbUJZaL9mERU/N0ZoB8jO+hMtNk3IF7YeZGext3 9J8kF0NjGxCxQ535DqSVDslumWmt7xqoMVnivpdG6rggPEvf5jTVdDmr1FX1E6s5eZrC Xk3nsW2s8F8N9wnRC4fupClbcOQFwjV3ltj+YQKYDc0PXD8zrNtG1QY35RPtV3uW7mfv zG/w== X-Forwarded-Encrypted: i=1; AJvYcCUzX5OMapcW6KJtTcg3ZOVn7qm75epkiMKpGdhvzYNxZPnPx49sT5c8C9UDOdmsnV2Z2w30c6PhWVSkBVjLuRg=@vger.kernel.org, AJvYcCXMuv4Cb0gTcbniq1vtRZ1sg0+mC0RtXYwFXm8daKZPQ12Y8neA/jpWCooBdYh19hKZynA0xbdSuqQF6YY=@vger.kernel.org X-Gm-Message-State: AOJu0YzPHGmyLzEAl+ewD7oG1ogDgjUavVbqZPjZQ2KcC6Bel1JEAZ8n R1zD3//+GGu9cmbcmX42r+oZicZANawusEy6Qi4TT5BsmnB5D9bN2+pP X-Gm-Gg: ASbGnctA4UY/KvkIHkO2j2HuHYFn0obNyZBdeoRluv4MBALyOMLz5FAYzt7IXf3CRyS fLoxRWnJ2WB4UjT5UYqUL5RWwZQL3LfoVDISqjx8kvjTDhIzmh3PLf7RcQlFUE22Qh10ZclPlsP H3uz1F2UE8EbuJomU+7xnPK9JMFRu5g4eg22KjDzZD5frXYO9lRChwtYnuGmiSu3YjTWN6XHH/e 55VXnPkK03LryaYXrEF2gq0IXfGuqwwt/Ilk0WFHYuBZyqSSHwgRORGdfMVjzP5Z3qboQNAVrk6 gzmy7Oj3+ojIUXQYI5sCJsVuU3Z0e9np9+RB/FZ2Hh9Jb+hof3gRQsETLGjDa61NyoAhxGjxZP+ A1E19YtAerHB9UyB/YAJyC7GHesCPbMSbaZ7zKoCOxBohGg== X-Google-Smtp-Source: AGHT+IFUfcGHUGTZuh8PBG3hJykgcW5tGM6RfatDYfdHDl9OEZ/cbEfIi2zoXQjK/bGAVEtGOGHpjQ== X-Received: by 2002:a17:90b:52c6:b0:311:b5ac:6f5d with SMTP id 98e67ed59e1d1-3134769e684mr24557616a91.29.1749562122490; Tue, 10 Jun 2025 06:28:42 -0700 (PDT) Received: from bee.. (p5332007-ipxg23901hodogaya.kanagawa.ocn.ne.jp. [180.34.120.7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3134b128050sm7969276a91.25.2025.06.10.06.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 06:28:42 -0700 (PDT) From: FUJITA Tomonori To: a.hindborg@kernel.org, alex.gaynor@gmail.com, ojeda@kernel.org Cc: aliceryhl@google.com, anna-maria@linutronix.de, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, frederic@kernel.org, gary@garyguo.net, jstultz@google.com, linux-kernel@vger.kernel.org, lossin@kernel.org, lyude@redhat.com, rust-for-linux@vger.kernel.org, sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu Subject: [PATCH v3 2/5] rust: time: Replace HrTimerMode enum with trait-based mode types Date: Tue, 10 Jun 2025 22:28:20 +0900 Message-ID: <20250610132823.3457263-3-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610132823.3457263-1-fujita.tomonori@gmail.com> References: <20250610132823.3457263-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`. Reviewed-by: Andreas Hindborg Signed-off-by: FUJITA Tomonori --- 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 280128d7e982..23f9f1ba8607 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, ); } } @@ -412,77 +412,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 Sat Oct 11 12:12:43 2025 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 BBCB317A305; Tue, 10 Jun 2025 13:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562129; cv=none; b=qPKgOvrUJWd9bDLSzXs4W7w2kDh1DHjwHGNldIDwDGT6PP1ieGMIKhjfLe+PGh1zynKgyk+91z3e9OjY5Ed1dYxUOwyk8qJeR3fbsAbeK4G2ICQeoNKIcqvY8gpTf0EGZZ+79z6JzUOsAnX33PLAXyQ4agQCk0fPexb9vW4Gk8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562129; c=relaxed/simple; bh=2HKkeS+D/53hmI7d01xFjBfZF8ViSPG4/bm7I3oKskA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p7y+gtYViauM2tD+nG2Kym6nt3YtjQGCSH7+A8rYiKmOMswiEoOo/2Ef4I0vhrH0iWeuCjEIX7DK8TvKQscgRmZBO/oPMiOIhXVzbQwoxClHqEkEFPEKfGRix2Sml5vv/PZOa+pGl1ufDpjMxCHSraWFIAUrjZ6Vs/u6Wzq2+88= 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=iJY8KG5H; arc=none smtp.client-ip=209.85.216.53 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="iJY8KG5H" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3109f106867so6556852a91.1; Tue, 10 Jun 2025 06:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749562127; x=1750166927; 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=li/TEVC1pHmYwJ7Qq6x5hEv02gsKC/iDeTYpmuevE7o=; b=iJY8KG5HMZghLhicSoVNv/AbAItUfrcYoiG6ePtXA/UkKLV7XjAo8GNcZPUxSIgxY9 fIxG92LC83keCYRrC5L+cgi/ayQ6kNDFQWmXQG2HaEbFvQlBHV9L4TyuKV1o6VwBqxNr HMNQvdgPmqo5/JJEAjmtMkuKbPrbVjPqMKyATuLkyINdHnrJIQ0tbXlPUY10jYoHIfOP kvO7O2abvJtr1EKflXLKOU73gq6YL6LBA1ZH74sQ0CoV/mAQhhVrQuYp9W/vg413mfXk EB2ZWP80+ZBR6781ZxCiyvsasm122LUUS3mo5KmVRCwuzzYZLt8hF9gvsuAX3ZIF6xG3 wroQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749562127; x=1750166927; 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=li/TEVC1pHmYwJ7Qq6x5hEv02gsKC/iDeTYpmuevE7o=; b=Vp/7II/L3lm+rjC9Q9i4+Aq73iH9PlTWVZlpwSUSvxN3CzUZ5dfoqY7HbGHfzspzuF ElqXXiSORHjQn7xv1fp+e0P0kgsufRYhkDB1HXEupswRHn18sn2+z4G95mDWmbLbuHEo 41Nz6EEDSwD98IvXMU3ty83t/+djjC9ghfxM5F+2gTdYHEkC8BWmnT3JmHP5gGmAvgLP UOpotteCD5/WlaeJGavnMzNLmIyIBCR0AX0jtxEkzgtPOec7IQ4gEUdbulD44EFy2t8S Zps7cLTHOjqPGDXFgDA3VGwLFyMKYnZSJy5lMBAK4/q25sgksNgIFTKbOQFKJSXtDMUe NKUg== X-Forwarded-Encrypted: i=1; AJvYcCUA8i375xiUjHLIfIB70uGAufQBEi2Awm305Sve4uHAbWUlibUQYahCIq4Ta6lUdFHDzwgErH+tBXqtzpo=@vger.kernel.org, AJvYcCUE6hH9/Hj57VFhDT3BeISbbZ483H9c9wbtOLicbwZvZlSHQ1W6N1fxJ3j8nsGPsJGWEwdFnsaPtsVr1VjKCzg=@vger.kernel.org X-Gm-Message-State: AOJu0YwYEHsKqjTC7gZ5FmgTu5qnTsBucStx41CQX/OkFb/AQBtjfrA7 3XNZ93Xb5WIoj757g3+u1pZpLOpWDSJ3kSEj+Y9R+Q17o1QHagkm7WKJ X-Gm-Gg: ASbGncu2WwjmLgWoi62ECXHRqzhNOA9w6oTlxEG5uEEkrdiQjDNweZekKp1eNC7U/np J5oOcO/OqWlh4UYoi2Enp1zqiZplnqxsRXe6vbsWK2V+/z8spW7/ElBrZ3jt68RSD6syzLV4pVs 5EX8V9zNjoL0+Z+28ixtbH9qqwZk9Uw501gMaYsWC6H9J4I9ANHufxZkmRdG+L580luuO4DlBGw ExJI+RpoWLo/qo5nukBs05yIzKfSvku7CsH9dbo50NXFfuKvkohGD8TecfPZrE5FPuPLC4WVPLz wTl6OcJWh2TTAVaIww/8wG+9SDnesl4LfgYOL7sqQiL8WPBdfD/AyJTTSshN7oHHe9VFiSfn6tA lHuNJR00hk9Mo6qmc5Jq7mrhtvQUwKKSenWw= X-Google-Smtp-Source: AGHT+IFclABCfX/IC3J/vArRt3KWJm5NyGdrbWqQlZNl1/xizi1DEqwHkxrPFPW2RF8ZN0wSsLIZpg== X-Received: by 2002:a17:90b:1b09:b0:311:ff18:b83e with SMTP id 98e67ed59e1d1-313a1542b4dmr3834471a91.9.1749562126839; Tue, 10 Jun 2025 06:28:46 -0700 (PDT) Received: from bee.. (p5332007-ipxg23901hodogaya.kanagawa.ocn.ne.jp. [180.34.120.7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3134b128050sm7969276a91.25.2025.06.10.06.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 06:28:46 -0700 (PDT) From: FUJITA Tomonori To: a.hindborg@kernel.org, alex.gaynor@gmail.com, ojeda@kernel.org Cc: aliceryhl@google.com, anna-maria@linutronix.de, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, frederic@kernel.org, gary@garyguo.net, jstultz@google.com, linux-kernel@vger.kernel.org, lossin@kernel.org, lyude@redhat.com, rust-for-linux@vger.kernel.org, sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu Subject: [PATCH v3 3/5] rust: time: Add HrTimerExpires trait Date: Tue, 10 Jun 2025 22:28:21 +0900 Message-ID: <20250610132823.3457263-4-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610132823.3457263-1-fujita.tomonori@gmail.com> References: <20250610132823.3457263-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, `into_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. Reviewed-by: Andreas Hindborg Signed-off-by: FUJITA Tomonori --- rust/kernel/time.rs | 5 ++ rust/kernel/time/hrtimer.rs | 126 +++++++++++++++++++++++++----------- 2 files changed, 95 insertions(+), 36 deletions(-) diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 2a231c321afa..70bd3be0facc 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 into_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 23f9f1ba8607..0ba87f1233cd 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; @@ -411,94 +411,148 @@ 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 into_nanos(self) -> i64; +} + +impl HrTimerExpires for Instant { + fn into_nanos(self) -> i64 { + Instant::::into_nanos(self) + } +} + +impl HrTimerExpires for Delta { + fn into_nanos(self) -> i64 { + Delta::into_nanos(self) + } +} + /// Operational mode of [`HrTimer`]. pub trait HrTimerMode { /// The C representation of hrtimer mode. const C_MODE: bindings::hrtimer_mode; + + /// Type representing the clock source. + type Clock: ClockSource; + + /// Type representing the expiration specification (absolute or relati= ve time). + type Expires: HrTimerExpires; } =20 /// Timer that expires at a fixed point in time. -pub struct AbsoluteMode; +pub struct AbsoluteMode(PhantomData); =20 -impl HrTimerMode for AbsoluteMode { +impl HrTimerMode for AbsoluteMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS; + + type Clock =3D C; + type Expires =3D Instant; } =20 /// Timer that expires after a delay from now. -pub struct RelativeMode; +pub struct RelativeMode(PhantomData); =20 -impl HrTimerMode for RelativeMode { +impl HrTimerMode for RelativeMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL; + + type Clock =3D C; + type Expires =3D Delta; } =20 /// Timer with absolute expiration time, pinned to its current CPU. -pub struct AbsolutePinnedMode; - -impl HrTimerMode for AbsolutePinnedMode { +pub struct AbsolutePinnedMode(PhantomData); +impl HrTimerMode for AbsolutePinnedMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED; + + type Clock =3D C; + type Expires =3D Instant; } =20 /// Timer with relative expiration time, pinned to its current CPU. -pub struct RelativePinnedMode; - -impl HrTimerMode for RelativePinnedMode { +pub struct RelativePinnedMode(PhantomData); +impl HrTimerMode for RelativePinnedMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED; + + type Clock =3D C; + type Expires =3D Delta; } =20 /// Timer with absolute expiration, handled in soft irq context. -pub struct AbsoluteSoftMode; - -impl HrTimerMode for AbsoluteSoftMode { +pub struct AbsoluteSoftMode(PhantomData); +impl HrTimerMode for AbsoluteSoftMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_SOFT; + + type Clock =3D C; + type Expires =3D Instant; } =20 /// Timer with relative expiration, handled in soft irq context. -pub struct RelativeSoftMode; - -impl HrTimerMode for RelativeSoftMode { +pub struct RelativeSoftMode(PhantomData); +impl HrTimerMode for RelativeSoftMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_SOFT; + + type Clock =3D C; + type Expires =3D Delta; } =20 /// Timer with absolute expiration, pinned to CPU and handled in soft irq = context. -pub struct AbsolutePinnedSoftMode; - -impl HrTimerMode for AbsolutePinnedSoftMode { +pub struct AbsolutePinnedSoftMode(PhantomData); +impl HrTimerMode for AbsolutePinnedSoftMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED_SOFT; -} =20 -/// Timer with relative expiration, pinned to CPU and handled in soft irq = context. -pub struct RelativePinnedSoftMode; + type Clock =3D C; + type Expires =3D Instant; +} =20 -impl HrTimerMode for RelativePinnedSoftMode { +/// Timer with absolute expiration, pinned to CPU and handled in soft irq = context. +pub struct RelativePinnedSoftMode(PhantomData); +impl HrTimerMode for RelativePinnedSoftMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED_SOFT; + + type Clock =3D C; + type Expires =3D Delta; } =20 /// Timer with absolute expiration, handled in hard irq context. -pub struct AbsoluteHardMode; - -impl HrTimerMode for AbsoluteHardMode { +pub struct AbsoluteHardMode(PhantomData); +impl HrTimerMode for AbsoluteHardMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_HARD; + + type Clock =3D C; + type Expires =3D Instant; } =20 /// Timer with relative expiration, handled in hard irq context. -pub struct RelativeHardMode; - -impl HrTimerMode for RelativeHardMode { +pub struct RelativeHardMode(PhantomData); +impl HrTimerMode for RelativeHardMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_HARD; + + type Clock =3D C; + type Expires =3D Delta; } =20 /// Timer with absolute expiration, pinned to CPU and handled in hard irq = context. -pub struct AbsolutePinnedHardMode; - -impl HrTimerMode for AbsolutePinnedHardMode { +pub struct AbsolutePinnedHardMode(PhantomData); +impl HrTimerMode for AbsolutePinnedHardMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_ABS_PINNED_HARD; + + type Clock =3D C; + type Expires =3D Instant; } =20 /// Timer with relative expiration, pinned to CPU and handled in hard irq = context. -pub struct RelativePinnedHardMode; - -impl HrTimerMode for RelativePinnedHardMode { +pub struct RelativePinnedHardMode(PhantomData); +impl HrTimerMode for RelativePinnedHardMode { const C_MODE: bindings::hrtimer_mode =3D bindings::hrtimer_mode_HRTIME= R_MODE_REL_PINNED_HARD; + + type Clock =3D C; + type Expires =3D Delta; } =20 /// Use to implement the [`HasHrTimer`] trait. --=20 2.43.0 From nobody Sat Oct 11 12:12:43 2025 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.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 DF2012980DF; Tue, 10 Jun 2025 13:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562133; cv=none; b=RVx7YrWDKsxUtIW/jaJcCKwicW1kQuku0wIreTUAGgFiQPPdFMb2GlYt40xXhlP0RUq3awlCh45cXuHUTAqKnhxJ95wrjLXaM28MFeKM54B+27y1+fm2xNqC/tIk6vCe+YhddvWxRBPSdkZ6PRuKbXfZO05KLAJn8JvRp/Hff04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562133; c=relaxed/simple; bh=NsDN6N5m8MLoqfwZQ1UsrDsIfxcdH6PywnNvCFwq4V8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dtwmyXxmOs0Wzk9+rMKF0NA4wxg/ISZExJxGIxIf17QrSDEIsSSsr9to01eVDcL+Z92PyF28Zrk1Jbs0dMLA2H7Evltbl2vSgg30B3/6cGcIJL5s8IzXX/HNQJNhOLKX7BO/T4B3sinjXAP3ZjDkUdamz5Awdruhmz0nnI8Ga40= 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=TkVJIM4O; arc=none smtp.client-ip=209.85.215.176 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="TkVJIM4O" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-b2f62bbb5d6so2753670a12.0; Tue, 10 Jun 2025 06:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749562131; x=1750166931; 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=jAHrmjESoEljqSEnck1mvwJh+eVSbJGX3azoeF8reFc=; b=TkVJIM4Ou7MO7Mi141wHi5IBoR+e8ayIP9KGKmDAOxFE7IYzuSGGATb9QMuCETltwF KIeUBkOhyLX2/ezPpIgb43GJ/IdI/bSTt8WjqAoIFfsopAoLDhG0RccoFT7mOQzImzKJ mld/J//7oHjyOpE/StYuEwJ+s7q0uWTPBkMihn145WvY+ixbtDz1NFDFKBAYth12dTrK Y8MF6o/mENgx6UH0JsvsFaWMEa7QM6xnqgeLCCkLlmapytpqOseai0sD8t7REotMPTgr 47K16kUf3rdG5UyuSULJ+lGAlFRRhk+ho99SbdO2mBVP/ufUf5miD4WlepekK0ohPVI7 8LNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749562131; x=1750166931; 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=jAHrmjESoEljqSEnck1mvwJh+eVSbJGX3azoeF8reFc=; b=vb2Ok5o1kLQnGbibnm1TVGo6QLWOc1vaq8jIcEfbUOfrYXlr/YMvGB9mrIGjSZ/VW5 R92eqraWz5qNLieV96X5x/buujhKaCY8+g99L76kkOPraTE8Gix7HJmITMCuOq1lRJ6P gY7ZQSRoEzPxpZlx/jEi+vnO0EaLR1KS04ID5D/kXyfwYnmoH+lJImabrEXWCTjvBC7X qcYwM3GPZArkuu8g+DohgY1uRD/bOB2ogN6HLRCTys4Ru/jgxMB5aG/uK5/l1OVhJoKR qTQqTgpgGOsgGiczIYUHwbnB9p1859iyTs1XJuhpXF8cME7iAO2mgi1IsLCFm0CXwAJY uEkA== X-Forwarded-Encrypted: i=1; AJvYcCUtNs2EGNbIQ0GoKsXZFMM86LGkQUB9QTfIH5NBbEiVMuxPG4HIT2BIDacfkzMEjUmosBWi6asiLqXfInMGLDc=@vger.kernel.org, AJvYcCUzG4107FVux/Yg9ETNdkmpFwAZ7OgqyQVHSFfmjspxi6lflY9ROxPxA2OjzOK596ImVo+jVQIN1zFoOh8=@vger.kernel.org X-Gm-Message-State: AOJu0YyLh8WWuNpd57vyXin/AgI3/3D2phqxrB2inImgSBttQVj2OcHF S9LvErVacdbJ4XM/c/nOEtwrKLT/NhQnkkVeeR+rlXGVOVquM6rKhNWr X-Gm-Gg: ASbGncv0V8SIF7+SDiLnzyJksDmbKq2vf9ChFR3r1yviG5MZX+2Z4X8EPX1kDMJdG2H DfHnfVWBcgs2wYPCnzLZ31QhFWQXbatfQENnaIwLwgC3ohMuludxhhrZ9JxqbcSox3QqzyYcjN5 CWeD8O0X8PdiMXtxoQISa9RqlfU5P9Mm7wryT/eH+dV3Cn9+yy6Pcte0VX0rEGPcu8vgre3DR08 sduAAkuDlrGKzZA0hEoS1UL2WhLvxlZAfZOAFa4QadTKre5UK0qmAK5GFOklnj7SScqO+CPIHfI fygXUby7bWW0sD3G8SUNgFwaoBWBhaZukPruelzYLCqA6vROglSYvIGT3pmDRj8GIW2xhHfjw2/ V9UBenWOsio0Zj5KWEAHBn917o4XqVNANBNU= X-Google-Smtp-Source: AGHT+IFnzXjSN8oZARyuqmWkK94Q2uxrqTrZ3SFevLP0LIiobO2sgsFCBz1T+Mmwh+vgfl/ETf8Ldg== X-Received: by 2002:a17:90b:3dd0:b0:311:ea13:2e6e with SMTP id 98e67ed59e1d1-31347678ba4mr26824372a91.28.1749562131034; Tue, 10 Jun 2025 06:28:51 -0700 (PDT) Received: from bee.. (p5332007-ipxg23901hodogaya.kanagawa.ocn.ne.jp. [180.34.120.7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3134b128050sm7969276a91.25.2025.06.10.06.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 06:28:50 -0700 (PDT) From: FUJITA Tomonori To: a.hindborg@kernel.org, alex.gaynor@gmail.com, ojeda@kernel.org Cc: aliceryhl@google.com, anna-maria@linutronix.de, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, frederic@kernel.org, gary@garyguo.net, jstultz@google.com, linux-kernel@vger.kernel.org, lossin@kernel.org, lyude@redhat.com, rust-for-linux@vger.kernel.org, sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu Subject: [PATCH v3 4/5] rust: time: Make HasHrTimer generic over HrTimerMode Date: Tue, 10 Jun 2025 22:28:22 +0900 Message-ID: <20250610132823.3457263-5-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610132823.3457263-1-fujita.tomonori@gmail.com> References: <20250610132823.3457263-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 : AbsoluteMode, field : 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 Reviewed-by: Andreas Hindborg --- 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 0ba87f1233cd..4ca153f8fce6 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.into_nanos(), 0, - (*Self::raw_get_timer(this)).mode, + ::Clock::ID as u32, ); } } @@ -566,12 +591,16 @@ macro_rules! impl_has_hr_timer { impl$({$($generics:tt)*})? HasHrTimer<$timer_type:ty> for $self:ty - { self.$field:ident } + { + mode : $mode:ty, + field : 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 Sat Oct 11 12:12:43 2025 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 DDE2B29A308; Tue, 10 Jun 2025 13:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562137; cv=none; b=NwQXY1MyLNkPvlDAgFsuTd6ASBuTdBr4AR4WpVd2xBRFkpnMSOLszSyG+bjgnsPy5T77czfcXVtz/9sD3nPjYFPsmmjTaUPPcwerIwmahul+4XbZGs2L0hZ3VeEJKPm6ppGzaSDb8ci5Eq8M56opk2AbZ/NedDKvVYmZsaDuHxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749562137; c=relaxed/simple; bh=Pbs46PP7pCs0MPmMt4GjuzpYwD4EEpd9XRag3zkhwz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kWCxCIH/PawYXqrG80xThsuwhjRSm1bRNSt7XVhtR/wMsbNZ18CKtitHjO7ec71x6JOGCgrGUwHffSVxKMgeUd2fOHuvaD4IuSsJMkgbabcXfS1p4HUbeqJATomxxecTK+74P9s/u+kjjYPsDCpHb8urmu62juyai/9ls/v9AOU= 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=IHkasFH8; arc=none smtp.client-ip=209.85.216.45 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="IHkasFH8" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-311ef4fb43dso4091982a91.3; Tue, 10 Jun 2025 06:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749562135; x=1750166935; 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=Rc7nHsumEdn2KQbBdNMRcYljio2yurEvUWZ/Mli9glE=; b=IHkasFH8EeqMqaMk9qtkC8fFMRek7KSbLdLFPSbhoOmyHub+WFDToi02bZGKxiLH2j xQZv36QpgkITrOmrrkdWjhKGNjb21M5NkAiU25+rQi/YrVVixDZDnaqD+jUzKSZtnggs LfCcd6muj8nHqr9iSa2S67rcCDN1hEpAFxDomKOHT9Mv5f8rV7vvhXx7N2qompXDob0r td7iV24xLcbiqKK7wT13XAIOLbnz9m1e2Q/f9iyaO38C+HWwU43oWdnChE2ABtAo+wqF PT50Whrw5QZBOqo6GWul4lTnZSxwnXvIXrJ9yOzwHkljzEdFjzWSpyyv+RtJnK3hER6h Gnag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749562135; x=1750166935; 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=Rc7nHsumEdn2KQbBdNMRcYljio2yurEvUWZ/Mli9glE=; b=iWUbJpb7/ksvMXh8yTuCMHOqjxkXdVAVbfT0K7aM55WDoicB+UhskoCEF4tljT1ldt UAwnWL4+n9CRsuf/P4mMt4oO5q7OodFBU1fv6Gv9+Qg/6vhN88Q3VABBhFsKNDJ2Ke59 qVlg8QaYIUkfSxl3EJCDB5kF8L/vYTbVNmx4zV+FezXLWzOkmR5Lg1iIazIQoO/yjs0y qItpY4Ee5XViWtGuFUHy36+HV2Fe9pUsSlnmwSbWYFNHbv46dzQiFOK5N++0/4PaIWNX vikdWiT3SvyZHM8Gifby+owoGyHbz97hWLw3CiQBWGomXgjbuinlqF0i1q9kAg7fitV4 /EPw== X-Forwarded-Encrypted: i=1; AJvYcCVubI/PQqVTHHlv4/RFb97ln1xA5+FjmZkQivqWMTOfJ2mBa2aK05PdKviS5B0eg64J9Y+TUy3rQyRjAR7RjDQ=@vger.kernel.org, AJvYcCW0L26esseLGlnMNNV3OreMK0Xx0gaa3XvfXRsnJptwj5mLhIQe2zISiBrx+1j61GYC3/vE4z/NU1LgLzA=@vger.kernel.org X-Gm-Message-State: AOJu0YzE6PXrQgll4YeZIoUeSGph8JUvmOMcLNmCLNBE3RozqkORoSxl SS+QvCcpq06d/Ed7S5zFO5VYAlzDatG6Li/+4E1Z5SQJ8Nu56Hnlqw/E X-Gm-Gg: ASbGncvcpY7QjZEGSVIOn2W/6/nZRwGR8kQTfVn8LDtRydRWu1t68ammxNTOG8VVgP0 R2XskMwruSR0hdWscEaEHR6q5elROfsDquzSle9CzRV2OaCKR9o++yb1vHq3FD7h8GkWp9aNF46 yT0zs7AXdD49wlNvHGfYlOmrPzV/DpOMvK/0DVMhNFzOCiCUXZJ44I+Y30UNoHYPUK7oXX/NCbt bT7DtkwnPvopu5zEyB1gaOFgjPL9KoU3mUuOkeo0DK6m8SMuEXGTITz5v2Zg2xLbc1DccyfPw/H japmnWzbN7oRXCF9gEw87nVRUUCajSFTIy8jFcugzeLx44SCoJWHQc4lOfESnakwa03yPfIkqoa 19ySUbmcRBpIuH8hRAKyRpaeYmYCVBgsfM8E= X-Google-Smtp-Source: AGHT+IH05u7IrcuH6+zYZ6wKHxWG1GUKhxIN/0VozpeD8CoD4qo2bsTIZEoKXL8TztGrvj2P8iY7Zw== X-Received: by 2002:a17:90b:3d90:b0:312:ffdc:42b2 with SMTP id 98e67ed59e1d1-3134767f220mr20724915a91.23.1749562135168; Tue, 10 Jun 2025 06:28:55 -0700 (PDT) Received: from bee.. (p5332007-ipxg23901hodogaya.kanagawa.ocn.ne.jp. [180.34.120.7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3134b128050sm7969276a91.25.2025.06.10.06.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 06:28:54 -0700 (PDT) From: FUJITA Tomonori To: a.hindborg@kernel.org, alex.gaynor@gmail.com, ojeda@kernel.org Cc: aliceryhl@google.com, anna-maria@linutronix.de, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, frederic@kernel.org, gary@garyguo.net, jstultz@google.com, linux-kernel@vger.kernel.org, lossin@kernel.org, lyude@redhat.com, rust-for-linux@vger.kernel.org, sboyd@kernel.org, tglx@linutronix.de, tmgross@umich.edu Subject: [PATCH v3 5/5] rust: time: Remove Ktime in hrtimer Date: Tue, 10 Jun 2025 22:28:23 +0900 Message-ID: <20250610132823.3457263-6-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250610132823.3457263-1-fujita.tomonori@gmail.com> References: <20250610132823.3457263-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. Reviewed-by: Andreas Hindborg Signed-off-by: FUJITA Tomonori --- 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 4ca153f8fce6..3980a7c5f7db 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