Re: [PATCH 1/2] procfs: add seq_put_hex_ll to speed up /proc/pid/maps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 12 Jan 2018 10:58:11 -0800 Andrei Vagin <avagin@xxxxxxxxxx> wrote:

> seq_put_hex_ll() prints a number in hexadecimal notation and works
> faster than seq_printf().
> 
> ...
>
> --- a/fs/seq_file.c
> +++ b/fs/seq_file.c
> @@ -670,6 +670,26 @@ void seq_puts(struct seq_file *m, const char *s)
>  }
>  EXPORT_SYMBOL(seq_puts);
>  
> +static inline void seq_put_delimeter(struct seq_file *m, const char *delimiter)
> +{
> +	int len;
> +
> +	if (!delimiter || !delimiter[0])
> +		return;
> +
> +	if (delimiter[1] == 0)
> +		return seq_putc(m, delimiter[0]);
> +
> +	len = strlen(delimiter);
> +	if (m->count + len >= m->size) {
> +		seq_set_overflow(m);
> +		return;
> +	}
> +
> +	memcpy(m->buf + m->count, delimiter, len);
> +	m->count += len;
> +}

Can we please have a nice comment describing this function's role and
behaviour?

I don't think the `inline' is needed or desirable - gcc can figure that
out, and with three callsites a `noinline' would be more justified!

That `return seq_putc(...)' will generate a warning in some situations
- seq_putc() returns void.  Let's split it into 'seq_putc(...);
return;' please.

> +/**
> + * seq_put_hex_ll - put a number in hexadecimal notation
> + * @m: seq_file identifying the buffer to which data should be written
> + * @delimiter: a string which is printed before the number
> + * @v: the number
> + * @width: a minimum field width
> + *
> + * seq_put_hex_ll(m, "", v, 8) is equal to seq_printf(m, "0x08llx", v)
> + *
> + * This routine is very quick when you show lots of numbers.
> + * In usual cases, it will be better to use seq_printf(). It's easier to read.
> + */
> +void seq_put_hex_ll(struct seq_file *m, const char *delimiter,
> +				unsigned long long v, int width)
> +{
> +	int i, len;
> +
> +	seq_put_delimeter(m, delimiter);
> +
> +	len = (sizeof(v) * 8 - __builtin_clzll(v) + 3) / 4;
> +
> +	if (unlikely(len == 0))
> +		len = 1;
> +
> +	if (len < width)
> +		len = width;
> +
> +	if (m->count + len > m->size)
> +		goto overflow;
> +
> +	for (i = len - 1; i >= 0; i--) {
> +		m->buf[m->count + i] = hex_asc[0xf & v];
> +		v = v >> 4;
> +	}
> +	m->count += len;
> +	return;
> +overflow:
> +	seq_set_overflow(m);
> +}

I don't think we need the goto.  Just do "seq_set_overflow(m); return;".




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux