From: Waiman Long <longman@redhat.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: Filipe Xavier <felipe_life@live.com>,
aliceryhl@google.com, ojeda@kernel.org, gary@garyguo.net,
benno.lossin@proton.me, will@kernel.org,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH v2] rust: add trylock method support for lock backend
Date: Tue, 24 Sep 2024 21:27:19 -0400 [thread overview]
Message-ID: <9a6f0d8b-7ccb-42f4-a6aa-3e38f08eeb86@redhat.com> (raw)
In-Reply-To: <ZvM-46lb_CSPr19h@boqun-archlinux>
On 9/24/24 18:36, Boqun Feng wrote:
> On Tue, Sep 24, 2024 at 02:31:43PM -0400, Waiman Long wrote:
>> On 9/24/24 03:02, Boqun Feng wrote:
>>>> +
>>>> +int rust_helper_spin_trylock(spinlock_t *lock)
>>>> +{
>>>> + return spin_trylock(lock);
>>>> +}
>>>> diff --git a/rust/kernel/sync/lock.rs b/rust/kernel/sync/lock.rs
>>>> index f6c34ca4d819..f4e51a5a1f23 100644
>>>> --- a/rust/kernel/sync/lock.rs
>>>> +++ b/rust/kernel/sync/lock.rs
>>>> @@ -58,6 +58,13 @@ unsafe fn init(
>>>> #[must_use]
>>>> unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState;
>>>> + /// Tries to acquire the lock without blocking.
>>> As I suggested in v1, "without blocking" is not accurate here because
>>> a lock can be a spinlock. So you can just remove it. I think the word
>>> "Tries" itself implies "neither busy waiting nor blocking".
>> Actually a spinlock in a PREEMPT_RT kernel is a sleeping lock. Not all
> I don't see why a spinlock sometimes being a sleeping lock can justify
> the inaccurate phrase "without blocking", it's still a spinning lock
> when PREEMPT_RT=n, and function document should cover all the cases.
>
>> people will associate "Tries" with not blocking. Anyway, I don't think it is
>> a problem with the "without blocking" phrase.
>>
> The problem is that for a generic Lock which includes spinlock and
> mutex, "without blocking" is really inaccurate or redundant. For
> spinlock, raw_spin_lock() also doesn't block, but it's not a valid
> try_lock implementaiton. The phrase "without blocking" doesn't provide
> useful or correct information to the users IMO. It should really be
> something like "without waiting for the owner infinitely when
> contention" if "Tries" is not an enough sign.
Right, if your focus is about no waiting, the phrase "without blocking"
is insufficient. It should be "without blocking/waiting" or something
similar. In that sense, just saying "without blocking" can be misleading.
Cheers,
Longman
next prev parent reply other threads:[~2024-09-25 1:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-15 15:23 [PATCH v2] rust: add trylock method support for lock backend Filipe Xavier
2024-09-24 7:02 ` Boqun Feng
2024-09-24 18:31 ` Waiman Long
2024-09-24 22:36 ` Boqun Feng
2024-09-25 1:27 ` Waiman Long [this message]
2024-09-24 20:24 ` Gary Guo
2024-09-24 23:33 ` Boqun Feng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9a6f0d8b-7ccb-42f4-a6aa-3e38f08eeb86@redhat.com \
--to=longman@redhat.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=boqun.feng@gmail.com \
--cc=felipe_life@live.com \
--cc=gary@garyguo.net \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox