All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>,
	LKML <linux-kernel@vger.kernel.org>, Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH 01/17] tools lib traceevent: Add state member to struct trace_seq
Date: Wed, 15 Jan 2014 11:15:19 -0300	[thread overview]
Message-ID: <20140115141519.GB16016@ghostprotocols.net> (raw)
In-Reply-To: <87fvopalbb.fsf@sejong.aot.lge.com>

Em Wed, Jan 15, 2014 at 02:03:20PM +0900, Namhyung Kim escreveu:
> On Tue, 14 Jan 2014 21:56:55 -0500, Steven Rostedt wrote:
> > On Wed, 15 Jan 2014 11:49:28 +0900
> > Namhyung Kim <namhyung@kernel.org> wrote:
> >> Oh, it looks better.  But I'd like to TRACE_SEQ_CHECK() as is for some
> >> cases.  How about this?
> >
> > Looks good to me.
> >
> > Acked-by: Steven Rostedt <rostedt@goodmis.org>
> >
> > I'll try to look at the rest of the patches tomorrow.

Hi Steven, can I keep your ackd-by?
 
> Thanks, and I found that trace_seq_destroy() should use
> TRACE_SEQ_TRACE_RET instead.  Here's an updated patch.
> 
> Thanks,
> Namhyung
> 
> 
> From 539a5dd1cb3ba4cb03c283115a9a84f8e345514e Mon Sep 17 00:00:00 2001
> From: Namhyung Kim <namhyung@kernel.org>
> Date: Thu, 19 Dec 2013 18:17:44 +0900
> Subject: [PATCH] tools lib traceevent: Add state member to struct trace_seq
> 
> The trace_seq->state is for tracking errors during the use of
> trace_seq APIs and getting rid of die() in it.
> 
> Acked-by: Steven Rostedt <rostedt@goodmis.org>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
>  tools/lib/traceevent/Makefile      |  2 +-
>  tools/lib/traceevent/event-parse.h |  7 +++++
>  tools/lib/traceevent/trace-seq.c   | 55 +++++++++++++++++++++++++++++---------
>  3 files changed, 50 insertions(+), 14 deletions(-)
> 
> diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
> index f778d48ac609..56d52a33a3df 100644
> --- a/tools/lib/traceevent/Makefile
> +++ b/tools/lib/traceevent/Makefile
> @@ -136,7 +136,7 @@ export Q VERBOSE
>  
>  EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
>  
> -INCLUDES = -I. $(CONFIG_INCLUDES)
> +INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
>  
>  # Set compile option CFLAGS if not set elsewhere
>  CFLAGS ?= -g -Wall
> diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
> index cf5db9013f2c..3c890cb28db7 100644
> --- a/tools/lib/traceevent/event-parse.h
> +++ b/tools/lib/traceevent/event-parse.h
> @@ -58,6 +58,12 @@ struct pevent_record {
>  #endif
>  };
>  
> +enum trace_seq_fail {
> +	TRACE_SEQ__GOOD,
> +	TRACE_SEQ__BUFFER_POISONED,
> +	TRACE_SEQ__MEM_ALLOC_FAILED,
> +};
> +
>  /*
>   * Trace sequences are used to allow a function to call several other functions
>   * to create a string of data to use (up to a max of PAGE_SIZE).
> @@ -68,6 +74,7 @@ struct trace_seq {
>  	unsigned int		buffer_size;
>  	unsigned int		len;
>  	unsigned int		readpos;
> +	enum trace_seq_fail	state;
>  };
>  
>  void trace_seq_init(struct trace_seq *s);
> diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
> index d7f2e68bc5b9..f7112138e6af 100644
> --- a/tools/lib/traceevent/trace-seq.c
> +++ b/tools/lib/traceevent/trace-seq.c
> @@ -22,6 +22,7 @@
>  #include <string.h>
>  #include <stdarg.h>
>  
> +#include <asm/bug.h>
>  #include "event-parse.h"
>  #include "event-utils.h"
>  
> @@ -32,10 +33,21 @@
>  #define TRACE_SEQ_POISON	((void *)0xdeadbeef)
>  #define TRACE_SEQ_CHECK(s)						\
>  do {									\
> -	if ((s)->buffer == TRACE_SEQ_POISON)			\
> -		die("Usage of trace_seq after it was destroyed");	\
> +	if (WARN_ONCE((s)->buffer == TRACE_SEQ_POISON,			\
> +		      "Usage of trace_seq after it was destroyed"))	\
> +		(s)->state = TRACE_SEQ__BUFFER_POISONED;		\
>  } while (0)
>  
> +#define TRACE_SEQ_CHECK_RET_N(s, n)		\
> +do {						\
> +	TRACE_SEQ_CHECK(s);			\
> +	if ((s)->state != TRACE_SEQ__GOOD)	\
> +		return n; 			\
> +} while (0)
> +
> +#define TRACE_SEQ_CHECK_RET(s)   TRACE_SEQ_CHECK_RET_N(s, )
> +#define TRACE_SEQ_CHECK_RET0(s)  TRACE_SEQ_CHECK_RET_N(s, 0)
> +
>  /**
>   * trace_seq_init - initialize the trace_seq structure
>   * @s: a pointer to the trace_seq structure to initialize
> @@ -46,6 +58,7 @@ void trace_seq_init(struct trace_seq *s)
>  	s->readpos = 0;
>  	s->buffer_size = TRACE_SEQ_BUF_SIZE;
>  	s->buffer = malloc_or_die(s->buffer_size);
> +	s->state = TRACE_SEQ__GOOD;
>  }
>  
>  /**
> @@ -71,7 +84,7 @@ void trace_seq_destroy(struct trace_seq *s)
>  {
>  	if (!s)
>  		return;
> -	TRACE_SEQ_CHECK(s);
> +	TRACE_SEQ_CHECK_RET(s);
>  	free(s->buffer);
>  	s->buffer = TRACE_SEQ_POISON;
>  }
> @@ -80,8 +93,9 @@ static void expand_buffer(struct trace_seq *s)
>  {
>  	s->buffer_size += TRACE_SEQ_BUF_SIZE;
>  	s->buffer = realloc(s->buffer, s->buffer_size);
> -	if (!s->buffer)
> -		die("Can't allocate trace_seq buffer memory");
> +	if (WARN_ONCE(!s->buffer,
> +		      "Can't allocate trace_seq buffer memory"))
> +		s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
>  }
>  
>  /**
> @@ -105,9 +119,9 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
>  	int len;
>  	int ret;
>  
> -	TRACE_SEQ_CHECK(s);
> -
>   try_again:
> +	TRACE_SEQ_CHECK_RET0(s);
> +
>  	len = (s->buffer_size - 1) - s->len;
>  
>  	va_start(ap, fmt);
> @@ -141,9 +155,9 @@ trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
>  	int len;
>  	int ret;
>  
> -	TRACE_SEQ_CHECK(s);
> -
>   try_again:
> +	TRACE_SEQ_CHECK_RET0(s);
> +
>  	len = (s->buffer_size - 1) - s->len;
>  
>  	ret = vsnprintf(s->buffer + s->len, len, fmt, args);
> @@ -172,13 +186,15 @@ int trace_seq_puts(struct trace_seq *s, const char *str)
>  {
>  	int len;
>  
> -	TRACE_SEQ_CHECK(s);
> +	TRACE_SEQ_CHECK_RET0(s);
>  
>  	len = strlen(str);
>  
>  	while (len > ((s->buffer_size - 1) - s->len))
>  		expand_buffer(s);
>  
> +	TRACE_SEQ_CHECK_RET0(s);
> +
>  	memcpy(s->buffer + s->len, str, len);
>  	s->len += len;
>  
> @@ -187,11 +203,13 @@ int trace_seq_puts(struct trace_seq *s, const char *str)
>  
>  int trace_seq_putc(struct trace_seq *s, unsigned char c)
>  {
> -	TRACE_SEQ_CHECK(s);
> +	TRACE_SEQ_CHECK_RET0(s);
>  
>  	while (s->len >= (s->buffer_size - 1))
>  		expand_buffer(s);
>  
> +	TRACE_SEQ_CHECK_RET0(s);
> +
>  	s->buffer[s->len++] = c;
>  
>  	return 1;
> @@ -199,7 +217,7 @@ int trace_seq_putc(struct trace_seq *s, unsigned char c)
>  
>  void trace_seq_terminate(struct trace_seq *s)
>  {
> -	TRACE_SEQ_CHECK(s);
> +	TRACE_SEQ_CHECK_RET(s);
>  
>  	/* There's always one character left on the buffer */
>  	s->buffer[s->len] = 0;
> @@ -208,5 +226,16 @@ void trace_seq_terminate(struct trace_seq *s)
>  int trace_seq_do_printf(struct trace_seq *s)
>  {
>  	TRACE_SEQ_CHECK(s);
> -	return printf("%.*s", s->len, s->buffer);
> +
> +	switch (s->state) {
> +	case TRACE_SEQ__GOOD:
> +		return printf("%.*s", s->len, s->buffer);
> +	case TRACE_SEQ__BUFFER_POISONED:
> +		puts("Usage of trace_seq after it was destroyed");
> +		break;
> +	case TRACE_SEQ__MEM_ALLOC_FAILED:
> +		puts("Can't allocate trace_seq buffer memory");
> +		break;
> +	}
> +	return -1;
>  }
> -- 
> 1.7.11.7

  reply	other threads:[~2014-01-15 14:21 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15  1:45 [PATCHSET 00/17] tools lib traceevent: Plugin unload enhancement Namhyung Kim
2014-01-15  1:45 ` [PATCH 01/17] tools lib traceevent: Add state member to struct trace_seq Namhyung Kim
2014-01-15  2:00   ` Steven Rostedt
2014-01-15  2:49     ` Namhyung Kim
2014-01-15  2:56       ` Steven Rostedt
2014-01-15  5:03         ` Namhyung Kim
2014-01-15 14:15           ` Arnaldo Carvalho de Melo [this message]
2014-01-15 14:25             ` Steven Rostedt
2014-01-16 13:37           ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-15  1:45 ` [PATCH 02/17] tools lib traceevent: Check return value of realloc() Namhyung Kim
2014-01-15  2:03   ` Steven Rostedt
2014-01-16 13:37   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-15  1:45 ` [PATCH 03/17] tools lib traceevent: Get rid of malloc_or_die() in trace_seq_init() Namhyung Kim
2014-01-15  2:05   ` Steven Rostedt
2014-01-16 13:37   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-15  1:45 ` [PATCH 04/17] tools lib traceevent: Get rid of die() finally!! Namhyung Kim
2014-01-16 13:38   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-15  1:45 ` [PATCH 05/17] tools lib traceevent: Make plugin unload function receive pevent Namhyung Kim
2014-01-15  2:24   ` Steven Rostedt
2014-01-16 13:38   ` [tip:perf/core] " tip-bot for Namhyung Kim
2014-01-15  1:45 ` [PATCH 06/17] tools lib traceevent: Add pevent_unregister_event_handler() Namhyung Kim
2014-01-15 16:18   ` Steven Rostedt
2014-01-15 18:12     ` Arnaldo Carvalho de Melo
2014-01-16  0:00     ` Namhyung Kim
2014-01-16  1:52       ` Steven Rostedt
2014-01-16  1:58         ` Namhyung Kim
2014-01-16  2:05           ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 07/17] tools lib traceevent: Add pevent_unregister_print_function() Namhyung Kim
2014-01-15 16:19   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 08/17] tools lib traceevent: Unregister handler when function plugin unloaded Namhyung Kim
2014-01-15 16:21   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 09/17] tools lib traceevent: Unregister handler when hrtimer " Namhyung Kim
2014-01-15 16:21   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 10/17] tools lib traceevent: Unregister handler when kmem " Namhyung Kim
2014-01-15  1:45 ` [PATCH 11/17] tools lib traceevent: Unregister handler when kvm " Namhyung Kim
2014-01-15  1:45 ` [PATCH 12/17] tools lib traceevent: Unregister handler when sched_switch " Namhyung Kim
2014-01-15  1:45 ` [PATCH 13/17] tools lib traceevent: Unregister handler when mac80211 " Namhyung Kim
2014-01-15 20:32   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 14/17] tools lib traceevent: Unregister handler when cfg80211 " Namhyung Kim
2014-01-15 20:34   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 15/17] tools lib traceevent: Unregister handler when jbd2 " Namhyung Kim
2014-01-15 20:35   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 16/17] tools lib traceevent: Unregister handler when scsi " Namhyung Kim
2014-01-15 20:36   ` Steven Rostedt
2014-01-15  1:45 ` [PATCH 17/17] tools lib traceevent: Unregister handler when xen " Namhyung Kim
2014-01-15 13:39 ` [PATCHSET 00/17] tools lib traceevent: Plugin unload enhancement 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=20140115141519.GB16016@ghostprotocols.net \
    --to=acme@ghostprotocols.net \
    --cc=a.p.zijlstra@chello.nl \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.