public inbox for linux-trace-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Qian-Yu Lin <tiffany019230@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	mhiramat@kernel.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] trace_printk: replace _______STR with __UNIQUE_ID(STR)
Date: Fri, 1 May 2026 22:13:15 +0100	[thread overview]
Message-ID: <20260501221315.1f709d6d@pumpkin> (raw)
In-Reply-To: <afS7UUAfzgiSzEHv@nova>

On Fri, 1 May 2026 22:40:17 +0800
Qian-Yu Lin <tiffany019230@gmail.com> wrote:

...
> Yes. I measured compile time of kernel/trace/ring_buffer_benchmark.o
> after make clean on an x86_64 machine running Ubuntu 24.04 LTS:
> 
>   - Original _______STR:                 49.8s
>   - v1 with __UNIQUE_ID (compiler.h):    53.5s
>   - compound literal (no extra include): 33.2s

That difference looks far to big to me.
And the times are far too large to be measuring the actual compile time.

> 
> I propose using a compound literal in v2, which eliminates the local
> variable entirely and requires no extra include:
> 
> #define trace_printk(fmt, ...)                          \
> do {                                                    \
>     if (sizeof((char[])                             \
>         {__stringify((__VA_ARGS__))}) > 3)      \
>         do_trace_printk(fmt, ##__VA_ARGS__);    \

There has to be a better way to align that code.
Although you should be able to use:
	if (sizeof __stringify((__VA_ARGS__)) > 3)
(I've omitted one set of parenthesis for clarity)

You could change __stringify() to work with __VA_ARGS__ the you don't need
the extra (); this works fine:
#define _x(...) #__VA_ARGS__
#define x(...) _x(__VA_ARGS__)
#define z abcd
int a = sizeof x(z, v); /* 8 */
See: https://godbolt.org/z/zo4h4nr9b

-- David

>     else                                            \
>         trace_puts(fmt);                        \
> } while (0)
> 
> This fully eliminates the shadowing risk without any compile overhead.
> 
> Qian-Yu
> 
> > 
> >   
> > >  #include <linux/compiler_attributes.h>
> > >  #include <linux/instruction_pointer.h>
> > >  #include <linux/stddef.h>
> > > @@ -84,15 +85,18 @@ do {									\
> > >   * let gcc optimize the rest.
> > >   */
> > >  
> > > -#define trace_printk(fmt, ...)				\
> > > +#define ___trace_printk(fmt, str, ...)				\
> > >  do {							\
> > > -	char _______STR[] = __stringify((__VA_ARGS__));	\
> > > -	if (sizeof(_______STR) > 3)			\
> > > +	char str[] = __stringify((__VA_ARGS__));	\
> > > +	if (sizeof(str) > 3)			\
> > >  		do_trace_printk(fmt, ##__VA_ARGS__);	\
> > >  	else						\
> > >  		trace_puts(fmt);			\
> > >  } while (0)
> > >  
> > > +#define trace_printk(fmt, ...) \
> > > +	___trace_printk(fmt, __UNIQUE_ID(str), ##__VA_ARGS__)
> > > +
> > >  #define do_trace_printk(fmt, args...)					\
> > >  do {									\
> > >  	static const char *trace_printk_fmt __used			\  
> >   


  parent reply	other threads:[~2026-05-01 21:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 16:57 [PATCH] trace_printk: replace _______STR with __UNIQUE_ID(STR) Qian-Yu Lin
2026-04-29 17:42 ` Steven Rostedt
2026-04-29 21:47   ` David Laight
2026-05-01 14:51     ` Qian-Yu Lin
2026-05-01 14:40   ` Qian-Yu Lin
2026-05-01 15:19     ` Steven Rostedt
2026-05-01 16:17       ` Qian-Yu Lin
2026-05-01 16:21         ` Steven Rostedt
2026-05-01 21:13     ` David Laight [this message]
2026-05-02  7:37       ` Qian-Yu Lin
2026-05-01 16:28 ` [PATCH v2] trace_printk: replace ___STR with compound literal Qian-Yu Lin
2026-05-02  7:55 ` [PATCH v3] trace_printk: remove local variable for argument detection Qian-Yu Lin

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=20260501221315.1f709d6d@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tiffany019230@gmail.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