From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>,
torvalds@linux-foundation.org, keescook@chromium.org,
gregkh@linuxfoundation.org, pbonzini@redhat.com
Cc: linux-kernel@vger.kernel.org, ojeda@kernel.org,
ndesaulniers@google.com, mingo@redhat.com, will@kernel.org,
boqun.feng@gmail.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
bristot@redhat.com, vschneid@redhat.com, paulmck@kernel.org,
frederic@kernel.org, quic_neeraju@quicinc.com,
joel@joelfernandes.org, josh@joshtriplett.org,
mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com,
qiang1.zhang@intel.com, rcu@vger.kernel.org, tj@kernel.org,
tglx@linutronix.de
Subject: Re: [RFC][PATCH 1/2] locking: Introduce __cleanup__ based guards
Date: Fri, 26 May 2023 14:49:33 -0400 [thread overview]
Message-ID: <cf20bbbc-c435-326d-f31a-86b1f4ce927a@redhat.com> (raw)
In-Reply-To: <20230526151946.960406324@infradead.org>
On 5/26/23 11:05, Peter Zijlstra wrote:
> Use __attribute__((__cleanup__(func))) to buid various guards:
>
> - ptr_guard()
> - void_guard() / void_scope()
> - lock_guard() / lock_scope()
> - double_lock_guard() / double_lock_scope()
>
> Where the _guard thingies are variables with scope-based cleanup and
> the _scope thingies are basically do-once for-loops with the same.
>
> The CPP is rather impenetrable -- but I'll attempt to write proper
> comments if/when people think this is worth pursuing.
>
> Actual usage in the next patch
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> include/linux/compiler_attributes.h | 2
> include/linux/irqflags.h | 7 ++
> include/linux/guards.h | 118 ++++++++++++++++++++++++++++++++++++
> include/linux/mutex.h | 5 +
> include/linux/preempt.h | 4 +
> include/linux/rcupdate.h | 3
> include/linux/sched/task.h | 2
> include/linux/spinlock.h | 23 +++++++
> 8 files changed, 164 insertions(+)
That is an interesting idea and may help to simplify some of the common
code patterns that we have in the kernel. The macros are a bit hard to
read and understand though I thought I got a rough idea of what they are
trying to do.
BTW, do we have a use case for double_lock_guard/double_lock_scope? I
can envision a nested lock_scope inside a lock_scope, but taking 2 auto
locks of the same type at init time and then unlock them at exit just
doesn't make sense to me.
Cheers,
Longman
next prev parent reply other threads:[~2023-05-26 18:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 15:05 [RFC][PATCH 0/2] Lock and Pointer guards Peter Zijlstra
2023-05-26 15:05 ` [RFC][PATCH 1/2] locking: Introduce __cleanup__ based guards Peter Zijlstra
2023-05-26 17:05 ` Kees Cook
2023-05-26 18:39 ` Miguel Ojeda
2023-05-26 18:22 ` Linus Torvalds
2023-05-26 19:10 ` Peter Zijlstra
2023-05-26 18:49 ` Waiman Long [this message]
2023-05-26 18:58 ` Mathieu Desnoyers
2023-05-26 19:04 ` Waiman Long
2023-05-26 15:05 ` [RFC][PATCH 2/2] sched: Use fancy new guards Peter Zijlstra
2023-05-26 16:25 ` Greg KH
2023-05-26 16:27 ` Mathieu Desnoyers
2023-05-26 16:43 ` Peter Zijlstra
2023-05-26 17:08 ` Kees Cook
2023-05-26 17:41 ` Miguel Ojeda
2023-05-26 16:41 ` Peter Zijlstra
2023-05-29 11:29 ` [RFC][PATCH 0/2] Lock and Pointer guards Paolo Bonzini
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=cf20bbbc-c435-326d-f31a-86b1f4ce927a@redhat.com \
--to=longman@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=juri.lelli@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=ndesaulniers@google.com \
--cc=ojeda@kernel.org \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=qiang1.zhang@intel.com \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--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
all inboxes | Powered by JetHome®