rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/2] rust: Add read_poll_timeout
@ 2025-08-11  4:10 FUJITA Tomonori
  2025-08-11  4:10 ` [PATCH v1 1/2] rust: Add cpu_relax() helper FUJITA Tomonori
  2025-08-11  4:10 ` [PATCH v1 2/2] rust: Add read_poll_timeout functions FUJITA Tomonori
  0 siblings, 2 replies; 16+ messages in thread
From: FUJITA Tomonori @ 2025-08-11  4:10 UTC (permalink / raw)
  To: a.hindborg, alex.gaynor, ojeda
  Cc: aliceryhl, anna-maria, bjorn3_gh, boqun.feng, dakr, frederic,
	gary, jstultz, linux-kernel, lossin, lyude, rust-for-linux, sboyd,
	tglx, tmgross, acourbot, daniel.almeida

Add a helper function to poll periodically until a condition is met or
a timeout is reached.

This patch was previously reviewed as part of another patchset [1] but
was removed to expedite merging into the mainline. Now that all the
features it depends on have been merged into the mainline, it is being
reposted as a new independent patchset.

I put this function kernel/time/poll.rs. If we follow the C
implementation, it might go under kernel/iopoll, but since this
function is not necessarily related to I/O, I think it is more
appropriate to maintain it as part of the timekeeping abstraction.

As Andreas pointed out [3], the test to call this function in an
atomic context doesn't work nicely; we can see might_sleep() throws a
warning in an atomic context. If such cases cannot be caught by the
test infra, it would be better to either remove the test or change it
to norun with a TODO, I think. Also, it might be better to move it
next to might_sleep() if we keep it.

After we agree on this patchset, I'll work on
read_poll_timeout_atomic().

v1 (the changes since the last posting [2])
- removed might_sleep() change since it was already merged separately.
- split out cpu_relax() in a separate patch
- make the example code compilable
- update the code to use Clocksource (MONOTONIC)
- call might_sleep() always (even when the function doesn't sleep)
- cosmetic changes to the doc

[1] https://lore.kernel.org/lkml/20250207132623.168854-1-fujita.tomonori@gmail.com/
[2] https://lore.kernel.org/lkml/20250220070611.214262-8-fujita.tomonori@gmail.com/
[3] https://lore.kernel.org/lkml/87y0wx9hpk.fsf@kernel.org/

FUJITA Tomonori (2):
  rust: Add cpu_relax() helper
  rust: Add read_poll_timeout functions

 rust/helpers/helpers.c   |   1 +
 rust/helpers/processor.c |   8 +++
 rust/kernel/lib.rs       |   1 +
 rust/kernel/processor.rs |  13 +++++
 rust/kernel/time.rs      |   1 +
 rust/kernel/time/poll.rs | 104 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 128 insertions(+)
 create mode 100644 rust/helpers/processor.c
 create mode 100644 rust/kernel/processor.rs
 create mode 100644 rust/kernel/time/poll.rs


base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
-- 
2.43.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-08-17  4:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11  4:10 [PATCH v1 0/2] rust: Add read_poll_timeout FUJITA Tomonori
2025-08-11  4:10 ` [PATCH v1 1/2] rust: Add cpu_relax() helper FUJITA Tomonori
2025-08-11  9:39   ` Alice Ryhl
2025-08-14  6:12     ` FUJITA Tomonori
2025-08-11 10:45   ` Andreas Hindborg
2025-08-11  4:10 ` [PATCH v1 2/2] rust: Add read_poll_timeout functions FUJITA Tomonori
2025-08-11  9:50   ` Alice Ryhl
2025-08-14  6:11     ` FUJITA Tomonori
2025-08-14  8:26       ` Alice Ryhl
2025-08-17  4:21       ` FUJITA Tomonori
2025-08-11  9:55   ` Danilo Krummrich
2025-08-11 10:32     ` Andreas Hindborg
2025-08-14  6:29     ` FUJITA Tomonori
2025-08-11 10:47   ` Andreas Hindborg
2025-08-13  2:56   ` Alexandre Courbot
2025-08-14  6:39     ` FUJITA Tomonori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).