From: Steven Rostedt <rostedt@goodmis.org>
To: jolsa@redhat.com
Cc: mingo@elte.hu, linux-kernel@vger.kernel.org,
Frederic Weisbecker <fweisbec@gmail.com>
Subject: Re: [PATCHv2 1/3] tracing - buf iterator definition, parsing function
Date: Thu, 10 Sep 2009 16:29:59 -0400 [thread overview]
Message-ID: <1252614599.18996.24.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <1252113181-3325-2-git-send-email-jolsa@redhat.com>
Ah, after working with my old patches, I think I like yours better ;-)
But I still have some issues. I'll comment on them, and if you can send
out a v3 with the updates, I'll apply them.
On Sat, 2009-09-05 at 03:12 +0200, jolsa@redhat.com wrote:
> Defined 'trace_biter' structure to carry the properties of the input,
> through the multiple writes.
>
> The 'trace_get_user' reads the user incput string separated by space
> (matched by isspace(ch). For each string found the 'struct trace_biter'
> iterator is updated, and the function returns.
>
> wbr,
> jirka
>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
>
> ---
> kernel/trace/trace.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
> kernel/trace/trace.h | 48 +++++++++++++++++++++++++++++
> 2 files changed, 131 insertions(+), 0 deletions(-)
>
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index af15008..8cf8f99 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -335,6 +335,89 @@ static struct {
>
> int trace_clock_id;
>
> +/*
> + * trace_get_user - reads the user incput string separated by space
typo - incput
> + * (matched by isspace(ch))
> + *
> + * For each string found the 'struct trace_biter' iterator is updated,
Call it trace_parser, I hate the sound of trace_biter (I keep
pronouncing it as bitter).
> + * and the function returns.
> + *
> + * Returns number of bytes read.
> + *
> + * see kernel/trace/trace.h for 'struct trace_biter' details.
> + */
> +int trace_get_user(struct trace_biter *biter, const char __user *ubuf,
s/biter/parser/g
> + size_t cnt, loff_t *ppos)
> +{
> + char ch;
> + size_t read = 0;
> + ssize_t ret;
> +
> + if (!*ppos)
> + TRACE_BITER_CLEAR(biter);
Don't do this with macros (explained below)
> +
> + ret = get_user(ch, ubuf++);
> + if (ret)
> + goto out;
> +
> + read++;
> + cnt--;
> +
> + /*
> + * If the parser haven't finished with the last write,
grammar nit - "If the parser is not finished ..."
> + * continue reading the user input without skipping spaces.
> + */
> + if (!biter->cont) {
> + /* skip white space */
> + while (cnt && isspace(ch)) {
> + ret = get_user(ch, ubuf++);
> + if (ret)
> + goto out;
> + read++;
> + cnt--;
> + }
> +
> + /* only spaces were written */
> + if (isspace(ch)) {
> + *ppos += read;
> + ret = read;
> + goto out;
> + }
> +
> + biter->idx = 0;
> + }
> +
> + /* read the non-space input */
> + while (cnt && !isspace(ch)) {
> + if (biter->idx < biter->size)
> + biter->buffer[biter->idx++] = ch;
> + else {
> + ret = -EINVAL;
> + goto out;
> + }
> + ret = get_user(ch, ubuf++);
> + if (ret)
> + goto out;
> + read++;
> + cnt--;
> + }
> +
> + /* We either got finished input or we have to wait for another call. */
> + if (isspace(ch)) {
> + biter->buffer[biter->idx] = 0;
> + biter->cont = 0;
> + } else {
> + biter->cont = 1;
> + biter->buffer[biter->idx++] = ch;
> + }
> +
> + *ppos += read;
> + ret = read;
> +
> +out:
> + return ret;
> +}
> +
> ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)
> {
> int len;
> diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
> index d881015..d4e38e8 100644
> --- a/kernel/trace/trace.h
> +++ b/kernel/trace/trace.h
> @@ -652,6 +652,54 @@ static inline int ftrace_trace_task(struct task_struct *task)
> #endif
>
> /*
> + * struct trace_biter - servers for reading the user input separated by spaces
Again, rename to trace_parser.
> + * @cont: set if the input is not complete - no final space char was found
> + * @buffer: holds the parsed user input
> + * @idx: user input lenght
> + * @size: buffer size
> + */
> +struct trace_biter {
> + bool cont;
> + char *buffer;
> + unsigned idx;
> + unsigned size;
> +};
> +
> +#define TRACE_BITER_LOADED(biter) (biter->idx)
> +#define TRACE_BITER_CONT(biter) (biter->cont)
> +#define TRACE_BITER_CLEAR(biter) \
> +do { \
> + biter->cont = false; \
> + biter->idx = 0; \
> +} while(0)
Ug, just use parser->idx directly. No need for macros. Or if you want to
encapsulate this, then use static inline functions. Avoid MACROS, they
just make the code ugly.
> +
> +/*
> + * trace_biter_alloc - allocates the buffer for trace buffer iterator
> + */
> +static inline int trace_biter_alloc(struct trace_biter *biter, int size)
Using alloc as the name here is confusing because you are passing in a
struct trace_parser already, so you are not allocating one. Rename it to
trace_parser_get_init().
> +{
> + memset(biter, 0, sizeof(*biter));
> +
> + biter->buffer = kmalloc(size, GFP_KERNEL);
> + if (!biter->buffer)
> + return 1;
> +
> + biter->size = size;
> + return 0;
> +}
> +
> +/*
> + * trace_biter_free - frees the buffer for trace buffer iterator
> + */
> +static inline void trace_biter_free(struct trace_biter *biter)
And again, you are not freeing the trace_parser. Lets rename this to
trace_parser_put(). This way we have a get/put pair that developers can
relate to. Maybe another name pair may be more appropriate, but when you
call something x_alloc/x_free, it refers to allocating and freeing x,
not a part of x.
-- Steve
> +{
> + kfree(biter->buffer);
> +}
> +
> +extern int trace_get_user(struct trace_biter *biter, const char __user *ubuf,
> + size_t cnt, loff_t *ppos);
> +
> +/*
> * trace_iterator_flags is an enumeration that defines bit
> * positions into trace_flags that controls the output.
> *
next prev parent reply other threads:[~2009-09-10 20:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-05 1:12 [PATCHv2 0/3] tracing - adding common method for reading/parsing user input jolsa
2009-09-05 1:12 ` [PATCHv2 1/3] tracing - buf iterator definition, parsing function jolsa
2009-09-08 13:47 ` Steven Rostedt
2009-09-10 20:29 ` Steven Rostedt [this message]
2009-09-05 1:13 ` [PATCHv2 2/3] tracing - buf iterator support for set_event jolsa
2009-09-10 20:35 ` Steven Rostedt
2009-09-05 1:13 ` [PATCHv2 3/3] tracing - buf iterator support for set_graph_function set_ftrace_filter set_ftrace_notrace jolsa
2009-09-10 20:43 ` Steven Rostedt
2009-09-05 2:41 ` [PATCHv2 0/3] tracing - adding common method for reading/parsing user input Daniel Walker
2009-09-05 6:40 ` Jiri Olsa
2009-09-05 13:02 ` Steven Rostedt
2009-09-08 14:01 ` Steven Rostedt
2009-09-08 14:37 ` Jiri Olsa
2009-09-08 14:44 ` Steven Rostedt
2009-09-08 14:46 ` Jiri Olsa
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=1252614599.18996.24.camel@gandalf.stny.rr.com \
--to=rostedt@goodmis.org \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®