From nobody Mon Feb 9 17:58:40 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B53211DDA20; Tue, 28 Jan 2025 17:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738084390; cv=none; b=DH4Dno/T6AfbFBf5mB3lOCQkmd9+hqkTLk1k0i2pXu8hoqGheZg5qO4CJ0T5+N4cpl9d0HmK3aWdRCKf3YL6M50zWqwYnOvMa725bHGuxDWXN+Ze5EpezBgSwkdlDbuVaJMhgg86tX6fp48WtOQ0xeLjGpo6djf7JUJFABQ6YsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738084390; c=relaxed/simple; bh=LOkV48DJCXqr4s3ewnL2P85KpGcwsy7PCabCFOjlXyA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=nqq1WppZzQ+bxjdnay2OsKsE8vmaq44XnVbCgo+uMoouYmBjf9ErdZbbxK3mn2QebxNHA7g1xW+u3tZsBhtvraHO8s0MXY+B9i9FrZxB5Dq1Od4L0RFfk+JOMa18lFDSmOFnKQikZpqGnVB3HSwROs2lpLDDCxPFVjaYhZjO4o8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hd8ObKRv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hd8ObKRv" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7E180C4CED3; Tue, 28 Jan 2025 17:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738084390; bh=LOkV48DJCXqr4s3ewnL2P85KpGcwsy7PCabCFOjlXyA=; h=From:Date:Subject:To:Cc:Reply-To:From; b=hd8ObKRviK+4OPCMt2cswEIv4eoBHSC4TTacQnK7J5Ht+w5X0S/phW/2CBEBxHw9p yTt/9z4zKlhVy3Ho0D7Hw+xa3KjH1x2XFnflVrh+Fe6z+UI/jSms7aRgRy/qXqp+xp fUDZrj4x7y8sx05XN/P1L85Kr6IsGCBpQZ7jX6Orb77JffukOlu1k1Vk9rvMxivbWx CWs98+e45oARq352NoXEFcLAo1sdnSaBtCkuUhZ6F4jFh3mvt/D6sKxW0vuwzJY6E8 V4MKtMQXUWC/TtWDT4Pdk/ZAwxcEOuPNyEKujCtVtddPhiUiwyyyYB7lF3drDh7Plw PsZKdtejhEtsw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66945C0218A; Tue, 28 Jan 2025 17:13:10 +0000 (UTC) From: Timothy Garwood via B4 Relay Date: Tue, 28 Jan 2025 18:12:49 +0100 Subject: [PATCH RFC] rust: HrTimerMode replacement with bitfield_options macro Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250128-bitfield-option-hrtimer-v1-1-31033d8e727f@protonmail.com> X-B4-Tracking: v=1; b=H4sIABAQmWcC/12OzW4CMQyEX2Xlc13FYUlIrpV4AK6IQ368JVKXp UmIkBDv3rRFqOpx7Jlv5gaFc+ICdrhB5pZKWk5d0MsA4ehO74wpdg1SyLUgqdGnOiX+iLica/f iMdc0c0bNgc1E2niK0NPnzFO6/pD3sNu+weH3mPnz0lvq4/MssUOvGEmQfiLbCptCkpiDREnrG JQnZfxkm4K/Ax9ZEht0Mf6fWHB2IS/oNqP2K2NIOGeb/CZ4VxjDMs+p2iFfSkX1SiMc7vcvzvu GsBkBAAA= X-Change-ID: 20250127-bitfield-option-hrtimer-7ece9f179b1d To: Miguel Ojeda , Alex Gaynor Cc: Andreas Hindborg , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Timothy Garwood X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1738084388; l=6528; i=gtimothy-dev@protonmail.com; s=20250123; h=from:subject:message-id; bh=affPqQwr4VVR21U7swKhRZpKaHYPLTxharXdiQNSgC4=; b=VJ/iKV8Q7wRnm7BTJCbWaD+dOCiWMaHQBFzn3IiVRplfKSyfdc1W7v0PRK83cr8pkmGddh526 ow4r8fFvaR2CHyBD/up985X30u/D+RhJLdzVUpA+1jvbKIpZYizMhzy X-Developer-Key: i=gtimothy-dev@protonmail.com; a=ed25519; pk=4MkQh/a3f6vfOYMYyJPEDyETzhXD/Sa4ZNZ/kAKxOOs= X-Endpoint-Received: by B4 Relay for gtimothy-dev@protonmail.com/20250123 with auth_id=330 X-Original-From: Timothy Garwood Reply-To: gtimothy-dev@protonmail.com From: Timothy Garwood replace the HrTimerMode enum with a bitfield wrapper built using the bitfield_options macro --- This patch provides an example of usage of the bitfield_options macro proposed in [1] as a replacement for the HrTimerMode enum introduced in [2]. [1] is a RFC. This patch depends on both [1] and [2] Link: https://lore.kernel.org/rust-for-linux/20250128-add-bitfield-options-macro-= v2-1-d65349b389fc@protonmail.com Link: https://lore.kernel.org/rust-for-linux/20250110-hrtimer-v3-v6-12-rc2-v6-0-f= 71d50f16482@kernel.org [2] Signed-off-by: Timothy Garwood --- rust/kernel/time/hrtimer.rs | 82 ++++++++++-------------------------------= ---- 1 file changed, 17 insertions(+), 65 deletions(-) diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs index f759e4b1aa9f9fa6d55d5c144deedccc5d0590ae..ecbd7ebd7bf319291fec5bc5de3= 1fe4a36d03c24 100644 --- a/rust/kernel/time/hrtimer.rs +++ b/rust/kernel/time/hrtimer.rs @@ -364,75 +364,27 @@ fn from(value: HrTimerRestart) -> Self { } } =20 -/// Operational mode of [`HrTimer`]. -#[derive(Clone, Copy)] -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, +kernel::bitfield_options! { + name: HrTimerMode, + type: bindings::hrtimer_mode, + options: [ + {name: relative, + true: bindings::hrtimer_mode_HRTIMER_MODE_REL, + false: bindings::hrtimer_mode_HRTIMER_MODE_ABS + }, + {name: pinned, + true: bindings::hrtimer_mode_HRTIMER_MODE_PINNED, + false: 0}, + {name: hard, + true: bindings::hrtimer_mode_HRTIMER_MODE_HARD, + false: bindings::hrtimer_mode_HRTIMER_MODE_SOFT} + ] } =20 impl From for bindings::hrtimer_mode { fn from(value: HrTimerMode) -> Self { - use bindings::*; - match value { - 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, - } + use kernel::bitfield::BitField; + value.bits() } } =20 --- base-commit: b9a6cbc3bad5eaf0e413c9487d8a0f2d3309bf0c change-id: 20250127-bitfield-option-hrtimer-7ece9f179b1d prerequisite-change-id: 20241017-hrtimer-v3-v6-12-rc2-215dc6b169bf:v6 prerequisite-patch-id: 23d01479b2ab6b48af65eb681817c753f2b36874 prerequisite-patch-id: 407fc78a43b558f7c6d9cde9a7bf211a06185afb prerequisite-patch-id: d8f3138d942b3ebfa3549cf54f6bb1c522401ba9 prerequisite-patch-id: 11beab205013c97d7e9a686352b1359910b5938b prerequisite-patch-id: 84bfb19dfd05dba3aac82b4f2b0031cf6aee8566 prerequisite-patch-id: fada7846a89465ac08b4ab049f9bc626abc27589 prerequisite-patch-id: 526e62d0d80535f4c1b2edb62ee8b7a0f6d86f78 prerequisite-patch-id: 201342b1c7635b147218cefdeded3bc326f59503 prerequisite-patch-id: 271bb7aa324adcf71bdc3c8fcfaefa269ed8ab74 prerequisite-patch-id: 75c30cfa3e81a8d4895567c16aa0b279616d0bdd prerequisite-patch-id: 68c2afbd51b25083614b2d963b6d32cbb3c3bb9a prerequisite-patch-id: 37d31228bd445445dbb1baa23ea83ab1e5c7a47b prerequisite-patch-id: fa49bf80231519c5397367f2d9467f3c28868620 prerequisite-patch-id: d1c5ffd588712325a3372dd4f582ace4debd594d prerequisite-change-id: 20241108-add-bitfield-options-macro-a847b39910aa:v2 prerequisite-patch-id: 7db40a5cde7387419cd346305da28e2c4932eca1 Best regards, --=20 Timothy Garwood