lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240415210035.GW2118490@ZenIV>
Date: Mon, 15 Apr 2024 22:00:35 +0100
From: Al Viro <viro@...iv.linux.org.uk>
To: Christophe JAILLET <christophe.jaillet@...adoo.fr>
Cc: Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
	linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
	linux-fsdevel@...r.kernel.org
Subject: Re: [PATCH] seq_file: Optimize seq_puts()

On Mon, Apr 15, 2024 at 10:47:59PM +0200, Christophe JAILLET wrote:
> Le 04/01/2024 à 14:29, Christophe JAILLET a écrit :
> > Most of seq_puts() usages are done with a string literal. In such cases,
> > the length of the string car be computed at compile time in order to save
> > a strlen() call at run-time. seq_write() can then be used instead.
> > 
> > This saves a few cycles.
> > 
> > To have an estimation of how often this optimization triggers:
> >     $ git grep seq_puts.*\" | wc -l
> >     3391
> > 
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
> 
> Hi,
> 
> any feed-back on this small optimisation of seq_puts()?

> > +#define seq_puts(m, s)						\
> > +do {								\
> > +	if (__builtin_constant_p(s))				\
> > +		seq_write(m, s, __builtin_strlen(s));		\
> > +	else							\
> > +		__seq_puts(m, s);				\
> > +} while (0)
> > +

No need to make it a macro, actually.  And I would suggest going
a bit further:

static inline void seq_puts(struct seq_file *m, const char *s)
{
        if (!__builtin_constant_p(*s))
		__seq_puts(m, s);
	else if (s[0] && !s[1])
		seq_putc(m, s[0]);
	else
		seq_write(m, s, __builtin_strlen(s));
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ