From: Linus Torvalds <torvalds@linuxfoundation.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Jonathan Cameron <jic23@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Eric Biederman <ebiederm@xmission.com>
Subject: Re: [PATCH 1/2] cleanup: Add conditional guard support
Date: Fri, 3 Nov 2023 08:17:01 -1000 [thread overview]
Message-ID: <CAHk-=wiGpX9+ajuRZeeX48C9ChwS0qNGj+Gkg_kDiuo6KJV00Q@mail.gmail.com> (raw)
In-Reply-To: <20231103093023.GA8262@noisy.programming.kicks-ass.net>
On Thu, 2 Nov 2023 at 23:30, Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, Nov 02, 2023 at 03:40:11PM +0100, Oleg Nesterov wrote:
> >
> > To me
> >
> > guard(rcu);
> > guard(spinlock, &lock);
> >
> > looks better than
> >
> > guard(rcu)();
> > // doesn't match scoped_guard(spinlock, &lock)
> > guard(spinlock)(&lock);
> >
> > And this will make guard() consistent with scoped_guard().
[...]
> That said; if we were to do this, then something like:
>
> #define __cond_guard(_name, _inst, _fail, args...) \
> CLASS(_name, _inst)(args); \
> if (!__guard_ptr(_name)(&_inst)) _fail
>
> #define cond_guard(_name, _fail, args...) \
> __cond_guard(_name, __UNIQUE_ID(guard), _fail, args)
>
> cond_guard(spinlock_try, return -EBUSY, &my_lock);
>
> Becomes possible.
>
> Linus, do you like that enough to suffer a flag day patch as proposed by
> Oleg?
I don't find myself caring too much whether we have that "double
grouping" of the guard type-vs-arguments or the "(type, arg...)"
syntax.
I honestly think that "guard(spinlock)(&lock)" makes it more visually
obvious that the first argument is the "type of guard", while
"guard(spinlock, &lock)" makes it look like the two arguments are
somehow at the same level, which they most definitely aren't.
But I also can't find it in myself to care too much about something
that is so purely syntactic, and that I suspect should be abstracted
away anyway to just become "guard_spinlock(&lock)" with a trivial
helper macro.
Linus
next prev parent reply other threads:[~2023-11-03 18:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-02 10:44 [PATCH 0/2] cleanup: Conditional locking support Peter Zijlstra
2023-11-02 10:44 ` [PATCH 1/2] cleanup: Add conditional guard support Peter Zijlstra
2023-11-02 14:40 ` Oleg Nesterov
2023-11-02 15:55 ` Oleg Nesterov
2023-11-03 9:30 ` Peter Zijlstra
2023-11-03 18:17 ` Linus Torvalds [this message]
2023-11-03 18:51 ` Oleg Nesterov
2023-11-02 10:44 ` [PATCH 2/2] ptrace: Convert ptrace_attach() to use lock guards Peter Zijlstra
2023-11-02 15:17 ` Oleg Nesterov
2023-11-02 15:34 ` [PATCH 0/2] cleanup: Conditional locking support Peter Zijlstra
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='CAHk-=wiGpX9+ajuRZeeX48C9ChwS0qNGj+Gkg_kDiuo6KJV00Q@mail.gmail.com' \
--to=torvalds@linuxfoundation.org \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).