Re: [RFC][PATCH 03/12 v3] tracing: Create seq_buf layer in trace_seq

Joe Perches
2014-11-07T18:59:32Z

On Fri, 2014-11-07 at 13:30 -0500, Steven Rostedt wrote:
> I'm not going to waist bandwidth reposting the entire series. Here's a
> new version of this patch. I'm getting ready to pull it into my next
> queue.

All this seems sensible enough though I think it'd
be nicer if all the touch-ups were compressed into
a single patch.

and some trivia:

> Create a seq_buf layer that trace_seq sits on. The seq_buf will not
> be limited to page size. This will allow other usages of seq_buf
> instead of a hard set PAGE_SIZE one that trace_seq has.
>
> Link: http://lkml.kernel.org/r/20141104160221.864997179@goodmis.org
[]
> diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
[]
> +extern __printf(2, 3)
> +int seq_buf_printf(struct seq_buf *s, const char *fmt, ...);
> +extern __printf(2, 0)
> +int seq_buf_vprintf(struct seq_buf *s, const char *fmt, va_list args);
> +extern int
> +seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
> +extern int seq_buf_print_seq(struct seq_file *m, struct seq_buf *s);
> +extern int seq_buf_to_user(struct seq_buf *s, char __user *ubuf,
> + int cnt);
> +extern int seq_buf_puts(struct seq_buf *s, const char *str);
> +extern int seq_buf_putc(struct seq_buf *s, unsigned char c);
> +extern int seq_buf_putmem(struct seq_buf *s, const void *mem, unsigned int len);
> +extern int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
> + unsigned int len);
> +extern int seq_buf_path(struct seq_buf *s, const struct path *path);
> +
> +extern int seq_buf_bitmask(struct seq_buf *s, const unsigned long *maskp,
> + int nmaskbits);

Maybe remove the extern bits from the function definitions?
And maybe the unsigned int len/cnt could be size_t

> diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h
[]
> @@ -12,16 +12,14 @@
>
> struct trace_seq {
> unsigned char buffer[PAGE_SIZE];
> - unsigned int len;
> - unsigned int readpos;
> + struct seq_buf seq;
> int full;
> };
>
> static inline void
> trace_seq_init(struct trace_seq *s)
> {
> - s->len = 0;
> - s->readpos = 0;
> + seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);

Maybe the PAGE_SIZE uses could be ARRAY_SIZE(s->buffer)

> diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
[]
> /* How much buffer is written? */
> -#define TRACE_SEQ_BUF_USED(s) min((s)->len, (unsigned int)(PAGE_SIZE - 1))
> +#define TRACE_SEQ_BUF_USED(s) min((s)->seq.len, (unsigned int)(PAGE_SIZE - 1))

min_t?
maybe this should be FIELD_SIZEOF(struct trace_seq, buffer) - 1