linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: fix "gfp_t" format for synthetic events
@ 2019-10-17  8:38 Zhengjun Xing
  2019-10-17 14:27 ` Tom Zanussi
  0 siblings, 1 reply; 2+ messages in thread
From: Zhengjun Xing @ 2019-10-17  8:38 UTC (permalink / raw)
  To: rostedt, mingo, tom.zanussi; +Cc: linux-kernel, zhengjun.xing

In the format of synthetic events, the "gfp_t" is shown as "signed:1",
but in fact the "gfp_t" is "unsigned", should be shown as "signed:0".
The offset should be increased by the real size of each field, rather
than by the size of "u64".

The issue can be reproduced by the following commands:

echo 'memlatency u64 lat; unsigned int order; gfp_t gfp_flags; int migratetype' > /sys/kernel/debug/tracing/synthetic_events
cat  /sys/kernel/debug/tracing/events/synthetic/memlatency/format

name: memlatency
ID: 2233
format:
        field:unsigned short common_type;       offset:0;       size:2; signed:0;
        field:unsigned char common_flags;       offset:2;       size:1; signed:0;
        field:unsigned char common_preempt_count;       offset:3;       size:1; signed:0;
        field:int common_pid;   offset:4;       size:4; signed:1;

        field:u64 lat;  offset:8;       size:8; signed:0;
        field:unsigned int order;       offset:16;      size:4; signed:0;
        field:gfp_t gfp_flags;  offset:24;      size:4; signed:1;
        field:int migratetype;  offset:32;      size:4; signed:1;

print fmt: "lat=%llu, order=%u, gfp_flags=%x, migratetype=%d", REC->lat, REC->order, REC->gfp_flags, REC->migratetype

Signed-off-by: Zhengjun Xing <zhengjun.xing@linux.intel.com>
---
 kernel/trace/trace_events_hist.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 57648c5aa679..7d70321d03b1 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -665,7 +665,7 @@ static int synth_event_define_fields(struct trace_event_call *call)
 			offset += STR_VAR_LEN_MAX;
 			n_u64 += STR_VAR_LEN_MAX / sizeof(u64);
 		} else {
-			offset += sizeof(u64);
+			offset += size;
 			n_u64++;
 		}
 	}
@@ -679,6 +679,8 @@ static bool synth_field_signed(char *type)
 {
 	if (str_has_prefix(type, "u"))
 		return false;
+	if (strcmp(type, "gfp_t") == 0)
+		return false;
 
 	return true;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tracing: fix "gfp_t" format for synthetic events
  2019-10-17  8:38 [PATCH] tracing: fix "gfp_t" format for synthetic events Zhengjun Xing
@ 2019-10-17 14:27 ` Tom Zanussi
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Zanussi @ 2019-10-17 14:27 UTC (permalink / raw)
  To: Zhengjun Xing, rostedt, mingo, tom.zanussi; +Cc: linux-kernel

Hi Zhengjun,

On Thu, 2019-10-17 at 16:38 +0800, Zhengjun Xing wrote:
> In the format of synthetic events, the "gfp_t" is shown as
> "signed:1",
> but in fact the "gfp_t" is "unsigned", should be shown as "signed:0".
> The offset should be increased by the real size of each field, rather
> than by the size of "u64".
> 
> The issue can be reproduced by the following commands:
> 
> echo 'memlatency u64 lat; unsigned int order; gfp_t gfp_flags; int
> migratetype' > /sys/kernel/debug/tracing/synthetic_events
> cat  /sys/kernel/debug/tracing/events/synthetic/memlatency/format
> 
> name: memlatency
> ID: 2233
> format:
>         field:unsigned short
> common_type;       offset:0;       size:2; signed:0;
>         field:unsigned char
> common_flags;       offset:2;       size:1; signed:0;
>         field:unsigned char
> common_preempt_count;       offset:3;       size:1; signed:0;
>         field:int common_pid;   offset:4;       size:4; signed:1;
> 
>         field:u64 lat;  offset:8;       size:8; signed:0;
>         field:unsigned int order;       offset:16;      size:4;
> signed:0;
>         field:gfp_t gfp_flags;  offset:24;      size:4; signed:1;
>         field:int migratetype;  offset:32;      size:4; signed:1;
> 
> print fmt: "lat=%llu, order=%u, gfp_flags=%x, migratetype=%d", REC-
> >lat, REC->order, REC->gfp_flags, REC->migratetype
> 
> Signed-off-by: Zhengjun Xing <zhengjun.xing@linux.intel.com>
> ---
>  kernel/trace/trace_events_hist.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_events_hist.c
> b/kernel/trace/trace_events_hist.c
> index 57648c5aa679..7d70321d03b1 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -665,7 +665,7 @@ static int synth_event_define_fields(struct
> trace_event_call *call)
>  			offset += STR_VAR_LEN_MAX;
>  			n_u64 += STR_VAR_LEN_MAX / sizeof(u64);
>  		} else {
> -			offset += sizeof(u64);
> +			offset += size;
>  			n_u64++;
>  		}
>  	}

This part isn't correct - currently, all the synthetic event fields are
u64, so doing this alone will mess things up.  The synthetic fields
were defined to be u64 in order to simplify event generation - if we
want to use the actual sizes, it would take a more extensive patch
including the generation code as well.  Not sure the added complexity
is worth it to save a few bytes in the ring buffer.

> @@ -679,6 +679,8 @@ static bool synth_field_signed(char *type)
>  {
>  	if (str_has_prefix(type, "u"))
>  		return false;
> +	if (strcmp(type, "gfp_t") == 0)
> +		return false;
>  
>  	return true;
>  }


This part is fine and makes sense.

Thanks,

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-17 14:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17  8:38 [PATCH] tracing: fix "gfp_t" format for synthetic events Zhengjun Xing
2019-10-17 14:27 ` Tom Zanussi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).