All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Li Zefan <lizf@cn.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>,
	Johannes Berg <johannes@sipsolutions.net>,
	LKML <linux-kernel@vger.kernel.org>,
	Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: Re: [PATCH 2/2] tracing/events: record the size of dynamic arrays
Date: Fri, 17 Jul 2009 01:14:18 -0400	[thread overview]
Message-ID: <20090717051357.GE4977@nowhere> (raw)
In-Reply-To: <4A5E964A.9000403@cn.fujitsu.com>

On Thu, Jul 16, 2009 at 10:54:02AM +0800, Li Zefan wrote:
> When a dynamic array is defined, we add __data_loc_foo in
> trace_entry to record the offset of the array, but the
> size of the array is not recorded, which causes 2 problems:
> 
> - the event filter just compares the first 2 chars of the strings.
> 
> - parsers can't parse dynamic arrays.
> 
> So we encode the size of each dynamic array in the higher 16 bits
> of __data_loc_foo, while the offset is in lower 16 bits.
> 
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> ---
>  include/trace/ftrace.h             |   14 ++++++++------
>  kernel/trace/trace_events_filter.c |    6 ++++--
>  2 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
> index cc78943..3cbb96e 100644
> --- a/include/trace/ftrace.h
> +++ b/include/trace/ftrace.h
> @@ -25,7 +25,7 @@
>  #define __array(type, item, len)	type	item[len];
>  
>  #undef __dynamic_array
> -#define __dynamic_array(type, item, len) unsigned short __data_loc_##item;
> +#define __dynamic_array(type, item, len) u32 __data_loc_##item;
>  
>  #undef __string
>  #define __string(item, src) __dynamic_array(char, item, -1)
> @@ -51,13 +51,14 @@
>   * Include the following:
>   *
>   * struct ftrace_data_offsets_<call> {
> - *	int				<item1>;
> - *	int				<item2>;
> + *	u32				<item1>;
> + *	u32				<item2>;
>   *	[...]
>   * };
>   *
> - * The __dynamic_array() macro will create each int <item>, this is
> + * The __dynamic_array() macro will create each u32 <item>, this is
>   * to keep the offset of each array from the beginning of the event.
> + * The size of an array is also encoded, in the higher 16 bits of <item>.
>   */
>  
>  #undef __field
> @@ -67,7 +68,7 @@
>  #define __array(type, item, len)
>  
>  #undef __dynamic_array
> -#define __dynamic_array(type, item, len)	int item;
> +#define __dynamic_array(type, item, len)	u32 item;
>  
>  #undef __string
>  #define __string(item, src) __dynamic_array(char, item, -1)
> @@ -207,7 +208,7 @@ ftrace_format_##call(struct trace_seq *s)				\
>  
>  #undef __get_dynamic_array
>  #define __get_dynamic_array(field)	\
> -		((void *)__entry + __entry->__data_loc_##field)
> +		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
>  
>  #undef __get_str
>  #define __get_str(field) (char *)__get_dynamic_array(field)
> @@ -325,6 +326,7 @@ ftrace_define_fields_##call(void)					\
>  #define __dynamic_array(type, item, len)				\
>  	__data_offsets->item = __data_size +				\
>  			       offsetof(typeof(*entry), __data);	\
> +	__data_offsets->item |= (len * sizeof(type)) << 16;		\
>  	__data_size += (len) * sizeof(type);
>  
>  #undef __string
> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> index b9aae72..1c80ef7 100644
> --- a/kernel/trace/trace_events_filter.c
> +++ b/kernel/trace/trace_events_filter.c
> @@ -176,11 +176,13 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
>  static int filter_pred_strloc(struct filter_pred *pred, void *event,
>  			      int val1, int val2)
>  {
> -	unsigned short str_loc = *(unsigned short *)(event + pred->offset);
> +	u32 str_item = *(u32 *)(event + pred->offset);
> +	int str_loc = str_item & 0xffff;
> +	int str_len = str_item >> 16;
>  	char *addr = (char *)(event + str_loc);
>  	int cmp, match;
>  
> -	cmp = strncmp(addr, pred->str_val, pred->str_len);
> +	cmp = strncmp(addr, pred->str_val, str_len);
>  
>  	match = (!cmp) ^ pred->not;
>  
> -- 1.6.3 


Looks good.
Like the previous one, I prefer to wait for an Ack from Steve though.


  reply	other threads:[~2009-07-17  5:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-16  2:52 [PATCH 0/2] tracing/events: 2 fixes for dynamic arrays Li Zefan
2009-07-16  2:53 ` [PATCH 1/2] tracing/events: add missing type info of " Li Zefan
2009-07-17  4:44   ` Frederic Weisbecker
2009-08-05  8:19   ` [tip:tracing/core] " tip-bot for Lai Jiangshan
2009-07-16  2:54 ` [PATCH 2/2] tracing/events: record the size " Li Zefan
2009-07-17  5:14   ` Frederic Weisbecker [this message]
2009-08-05  8:19   ` [tip:tracing/core] " tip-bot for Li Zefan
2009-07-20  1:18 ` [PATCH 0/2] tracing/events: 2 fixes for " Li Zefan
2009-07-20 15:38   ` Steven Rostedt

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=20090717051357.GE4977@nowhere \
    --to=fweisbec@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --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.