From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Michael Jeanson <mjeanson@efficios.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Alexei Starovoitov <ast@kernel.org>, Yonghong Song <yhs@fb.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Namhyung Kim <namhyung@kernel.org>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
bpf@vger.kernel.org, Joel Fernandes <joel@joelfernandes.org>,
Jordan Rife <jrife@google.com>,
linux-trace-kernel@vger.kernel.org,
Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: [RFC PATCH 4/5] tracing: Remove conditional locking from __DO_TRACE()
Date: Tue, 26 Nov 2024 09:45:56 +0100 [thread overview]
Message-ID: <20241126084556.GI38837@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAHk-=wjcCQ4-0f68bWMLuFnj9r9Hwg4YnXDBg8-K7z6ygq=iEQ@mail.gmail.com>
On Mon, Nov 25, 2024 at 09:51:43AM -0800, Linus Torvalds wrote:
> That said, I have a "lovely" suggestion. Instead of the "if(0)+goto"
> games, I think you can just do this:
>
> #define scoped_guard(_name, args...) \
> for (CLASS(_name, scope)(args), *_once = (void *)1; _once && \
> (__guard_ptr(_name)(&scope) || !__is_cond_ptr(_name)); \
> _once = NULL)
>
Right, so that's more or less what we used to have:
#define scoped_guard(_name, args...) \
for (CLASS(_name, scope)(args), *done = NULL; \
__guard_ptr(_name)(&scope) && !done; done = (void *)1)
But it turns out the compilers have a hard time dealing with this. From
commit fcc22ac5baf0 ("cleanup: Adjust scoped_guard() macros to avoid
potential warning"):
int foo(struct my_drv *adapter)
{
scoped_guard(spinlock, &adapter->some_spinlock)
return adapter->spinlock_protected_var;
}
Using that (old) form results in:
error: control reaches end of non-void function [-Werror=return-type]
Now obviously the above can also be written like:
int foo(struct my_drv *adapter)
{
guard(spinlock)(&adapter->some_spinlock);
return adapter->spinlock_protected_var;
}
But the point is to show the compilers get confused. Additionally Dan
Carpenter noted that smatch has a much easier time dealing with the new
form.
And the commit notes the generated code is actually slighly smaller with
e new form too (probably because the compiler is less confused about
control flow).
Except of course, now we get that dangling-else warning, there is no
winning this :-/
So I merged that patch because of the compilers getting less confused
and better code-gen, but if you prefer the old one we can definitely go
back. In which case we should go talk to compiler folks to figure out
how to make it not so confused.
next prev parent reply other threads:[~2024-11-26 8:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-23 15:30 [RFC PATCH 0/5] tracing: Remove conditional locking from tracepoints Mathieu Desnoyers
2024-11-23 15:30 ` [RFC PATCH 1/5] tracing: Move it_func[0] comment to the relevant context Mathieu Desnoyers
2024-11-23 15:30 ` [RFC PATCH 2/5] tracing: Remove __idx variable from __DO_TRACE Mathieu Desnoyers
2024-11-23 15:30 ` [RFC PATCH 3/5] rcupdate_trace: Define rcu_tasks_trace lock guard Mathieu Desnoyers
2024-11-23 15:30 ` [RFC PATCH 4/5] tracing: Remove conditional locking from __DO_TRACE() Mathieu Desnoyers
2024-11-23 17:38 ` Linus Torvalds
2024-11-25 1:50 ` Mathieu Desnoyers
2024-11-25 3:22 ` Steven Rostedt
2024-11-25 14:18 ` Mathieu Desnoyers
2024-11-25 14:26 ` Peter Zijlstra
2024-11-25 15:35 ` Przemek Kitszel
2024-11-25 17:51 ` Linus Torvalds
2024-11-26 8:45 ` Peter Zijlstra [this message]
2024-11-26 18:13 ` Linus Torvalds
2024-11-26 20:47 ` Dmitry Torokhov
2024-11-26 22:32 ` Przemek Kitszel
2024-11-26 22:40 ` Linus Torvalds
2024-11-23 15:30 ` [RFC PATCH 5/5] tracing: Remove cond argument from __DECLARE_TRACE_SYSCALL Mathieu Desnoyers
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=20241126084556.GI38837@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=joel@joelfernandes.org \
--cc=jrife@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=mjeanson@efficios.com \
--cc=namhyung@kernel.org \
--cc=ndesaulniers@google.com \
--cc=paulmck@kernel.org \
--cc=przemyslaw.kitszel@intel.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=yhs@fb.com \
/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