From mboxrd@z Thu Jan 1 00:00:00 1970 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 7E45F192D80; Tue, 17 Sep 2024 22:28:29 +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=1726612109; cv=none; b=TMbspRrOoAe4w8zrCPIVwRpGav4SC6mxAcrtIq/2hiPAX6QYRjCi9MqhxU5SIn9UUxxqOns7iz9nHjki8W4c0QxOCIhaAUp8PH6jxqXPlmqroVCNyG1t5hm59BYYFPnmLNMNkjhN7j+oPQ/4CKlcH9EC7SZeDsqoBOucPj5QQLA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726612109; c=relaxed/simple; bh=v8a0nJ/rc+OK18Wxq94GBNtOb5DtDJoxXv1oZUTW0wM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YhAQ7SCE5PSV0b9Mc/x92PWNB5FHsNFNu9R6XVeAtn/YeljxhgPNIaTGRLOlIdGLqvqG2R+XzJSHCpSHt8kR4/RpH1ZDSkL9r0dfuY4UXCA+NNTPtj8c++GeQPCAyPiPB9Q2VpjMu57WIaJbAyJ3ooZc/p/qPtpx+YTuX79M9L0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h6cE/FRm; 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="h6cE/FRm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8B91C4CECE; Tue, 17 Sep 2024 22:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726612109; bh=v8a0nJ/rc+OK18Wxq94GBNtOb5DtDJoxXv1oZUTW0wM=; h=From:To:Cc:Subject:Date:From; b=h6cE/FRmA24GKvvdS6JAFjorlADzEj2zyVDWQt9tvLr3hFb/pwTudioJRgT/KO112 37f0VMsgpNSkkgPSHXDuyeuXqLRaISxt/GqFZdVdUl9osNjKN0Z30ZxIrK+loC/fpz i7h2ll+G2V+JuevpD/Xc14gkbJgiNQc8T4Zx5q6q2n/t0yoDkctCKYPeCU25uziEVr B07hWx78oqRWyXXI7hDwNuugVxGAWK9Gn8eEi1YOyh7Hv6hb3uJwfriJxQbfoTftM2 a2K6R+jg8HgpSo3vETLJZOUWSoYfCd+Z3sYWhD53Ee+WHa5Nhp9Q3ATm+UKxN+hXaQ P4/sHvtTFOBrA== From: Andreas Hindborg To: Miguel Ojeda , Alex Gaynor , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner Cc: Andreas Hindborg , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 00/14] hrtimer Rust API Date: Wed, 18 Sep 2024 00:27:24 +0200 Message-ID: <20240917222739.1298275-1-a.hindborg@kernel.org> X-Mailer: git-send-email 2.46.0 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3771; i=a.hindborg@kernel.org; h=from:subject; bh=v8a0nJ/rc+OK18Wxq94GBNtOb5DtDJoxXv1oZUTW0wM=; b=LS0tLS1CRUdJTiBQR1AgTUVTU0FHRS0tLS0tCgpvd0o0bkFGdEFwTDlrQTBEQUFvQjRiZ2FQb mtvWTNjQnl5WmlBR2JxQWZHWExSeWNmQ3ZHR0Z6RS9XTFY4NmkwCjliRH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1FTkQgUEdQIE1FU1NBR0UtLS0tLQo= X-Developer-Key: i=a.hindborg@kernel.org; a=openpgp; fpr=3108C10F46872E248D1FB221376EB100563EF7A7 Content-Transfer-Encoding: 8bit Hi! This series adds support for using the `hrtimer` subsystem from Rust code. I tried breaking up the code in some smaller patches, hopefully that will ease the review process a bit. The major change in this series is the use of a handle to carry ownership of the callback target. In v1, we used the armed timer to carry ownership of the callback target. This caused issues when the live timer became the last owner of the callback target, because the target would be dropped in timer callback context. That is solved by using a handle instead. A request from Thomas on v1 was to add a more complete API. While I did add more features, we are still missing some. In the interest of getting the patches on list prior to LPC 2024, I am leaving out the following planned features: - hrtimer_sleeper, schedule_hrtimeout, hrtimer_nanosleep and friends - introspection functions: - try_cancel - get_remaining - active - queued - callback_running - hrtimer_forward - access to timer callback target through timer handle I plan to add these features in the comming months. Adding the above features should not cause much churn, and pending positive review, I see no reason to not pick up this series first. To make it absolutely clear that I am willing to maintain the code I submit, I added a mantainer entry in the last patch. Feel free to drop it, if you want to make other arrangements. --- Changes from v1: - use a handle to own the timer callback target - add ability to for callback to reschedule timer - improve `impl_has_timer` to allow generics - add support for stack allocated timers - add support for scheduling closures - use `Ktime` for setting expiration - use `CondVar` instead of `AtomicBool` in examples - rebase on 6.11 - improve documentation This series is a dependency for unmerged features of the Rust null block driver [1], and for rkvms [2]. Link: https://git.kernel.org/pub/scm/linux/kernel/git/a.hindborg/linux.git/log/?h=rnull-v6.11-rc2 [1] Link: https://gitlab.freedesktop.org/lyudess/linux/-/tree/rvkms-wip [2] --- Andreas Hindborg (13): rust: hrtimer: introduce hrtimer support rust: sync: add `Arc::as_ptr` rust: sync: add `Arc::clone_from_raw` rust: hrtimer: implement `TimerPointer` for `Arc` rust: hrtimer: allow timer restart from timer handler rust: hrtimer: add `UnsafeTimerPointer` rust: hrtimer: implement `UnsafeTimerPointer` for `Pin<&T>` rust: hrtimer: implement `UnsafeTimerPointer` for `Pin<&mut T>` rust: hrtimer: add `hrtimer::ScopedTimerPointer` rust: hrtimer: allow specifying a distinct callback parameter rust: hrtimer: implement `TimerPointer` for `Pin>` rust: hrtimer: add `schedule_function` to schedule closures rust: hrtimer: add maintainer entry Lyude Paul (1): rust: time: Add Ktime::from_ns() MAINTAINERS | 10 + rust/kernel/hrtimer.rs | 550 +++++++++++++++++++++++++++++++++ rust/kernel/hrtimer/arc.rs | 86 ++++++ rust/kernel/hrtimer/closure.rs | 72 +++++ rust/kernel/hrtimer/pin.rs | 97 ++++++ rust/kernel/hrtimer/pin_mut.rs | 99 ++++++ rust/kernel/hrtimer/tbox.rs | 95 ++++++ rust/kernel/lib.rs | 1 + rust/kernel/sync/arc.rs | 28 ++ rust/kernel/time.rs | 8 + 10 files changed, 1046 insertions(+) create mode 100644 rust/kernel/hrtimer.rs create mode 100644 rust/kernel/hrtimer/arc.rs create mode 100644 rust/kernel/hrtimer/closure.rs create mode 100644 rust/kernel/hrtimer/pin.rs create mode 100644 rust/kernel/hrtimer/pin_mut.rs create mode 100644 rust/kernel/hrtimer/tbox.rs base-commit: 98f7e32f20d28ec452afb208f9cffc08448a2652 -- 2.46.0