Skip to contentSkip to conversation

tracing: Fix trace entry and trace common fields for preempt_lazy_count

PATCH In review Jiri Olsa 4 participants 15 messages Feb 21, 2020 – Mar 9, 2020 Tracing

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

PATCH 1/1 tracing: Fix trace entry and trace common fields for preempt_lazy_count

When commit 65fd07df3588 added preempt_lazy_count into 'struct trace_entry' it did not add 4 bytes padding. Also we need to update the common fields for tracepoint, otherwise some tools (bpftrace) stop working due to missing common fields.

Fixes 65fd07df3588 ("x86: Support for lazy preemption")
---
 include/linux/trace_events.h | 2 ++
 kernel/trace/trace_events.c  | 3 +++
 2 files changed, 5 insertions(+)
include/linux/trace_events.h +2 -0
index f3b1ef07e4a5..51a3f5188923 100644
@@ -65,6 +65,8 @@ struct trace_entry {
 	unsigned short		migrate_disable;
 	unsigned short		padding;
 	unsigned char		preempt_lazy_count;
+	unsigned char		padding1;
+	unsigned short		padding2;
 };
 
 #define TRACE_EVENT_TYPE_MAX						\
kernel/trace/trace_events.c +3 -0
index accaae59a762..1fe37b7aeaff 100644
@@ -183,6 +183,9 @@ static int trace_define_common_fields(void)
 	__common_field(int, pid);
 	__common_field(unsigned short, migrate_disable);
 	__common_field(unsigned short, padding);
+	__common_field(unsigned char,  preempt_lazy_count);
+	__common_field(unsigned char,  padding1);
+	__common_field(unsigned short, padding2);
 
 	return ret;
 }
Signature · 1 line
2.24.1
maintainer
#1 lore raw
Quoted 17 lines · On Fri, 21 Feb 2020 16:35:41 +0100 Jiri Olsa <[email protected]> wrote:

When commit 65fd07df3588 added preempt_lazy_count into 'struct trace_entry' it did not add 4 bytes padding. Also we need to update the common fields for tracepoint, otherwise some tools (bpftrace) stop working due to missing common fields.

Fixes 65fd07df3588 ("x86: Support for lazy preemption")
---
 include/linux/trace_events.h | 2 ++
 kernel/trace/trace_events.c  | 3 +++
 2 files changed, 5 insertions(+)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5..51a3f5188923 100644

include/linux/trace_events.h struct trace_entry { · line 69

Quoted 5 lines
include/linux/trace_events.h +2 -0
@@ -65,6 +65,8 @@ struct trace_entry {
 	unsigned short		migrate_disable;
 	unsigned short		padding;
 	unsigned char		preempt_lazy_count;
+	unsigned char		padding1;
+	unsigned short		padding2;

Wait! I don't have these changes in my tree, nor do I see them in Linus's. This really bloats the trace events! This header is very sensitive to size and just willy nilly adding to it is unacceptable. It's like adding to the page_struct. This gets added to *every* event, and a single byte added, causes 1M extra for a million events (very common in tracing). It causes 1G extra for a billion events.

Let's find a better way to handle this.

-- Steve

Quoted 17 lines
include/linux/trace_events.h +0 -0
 };
 
 #define TRACE_EVENT_TYPE_MAX						\
kernel/trace/trace_events.c +3 -0
index accaae59a762..1fe37b7aeaff 100644
@@ -183,6 +183,9 @@ static int trace_define_common_fields(void)
 	__common_field(int, pid);
 	__common_field(unsigned short, migrate_disable);
 	__common_field(unsigned short, padding);
+	__common_field(unsigned char,  preempt_lazy_count);
+	__common_field(unsigned char,  padding1);
+	__common_field(unsigned short, padding2);
 
 	return ret;
 }
#2 lore raw
Quoted 27 lines · Steven Rostedt
Quoted 17 lines · On Fri, 21 Feb 2020 16:35:41 +0100 Jiri Olsa <[email protected]> wrote:

When commit 65fd07df3588 added preempt_lazy_count into 'struct trace_entry' it did not add 4 bytes padding. Also we need to update the common fields for tracepoint, otherwise some tools (bpftrace) stop working due to missing common fields.

Fixes 65fd07df3588 ("x86: Support for lazy preemption")
---
 include/linux/trace_events.h | 2 ++
 kernel/trace/trace_events.c  | 3 +++
 2 files changed, 5 insertions(+)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5..51a3f5188923 100644

include/linux/trace_events.h struct trace_entry { · line 69

Quoted 5 lines
include/linux/trace_events.h +2 -0
@@ -65,6 +65,8 @@ struct trace_entry {
 	unsigned short		migrate_disable;
 	unsigned short		padding;
 	unsigned char		preempt_lazy_count;
+	unsigned char		padding1;
+	unsigned short		padding2;
Quoted 6 lines

Wait! I don't have these changes in my tree, nor do I see them in Linus's. This really bloats the trace events! This header is very sensitive to size and just willy nilly adding to it is unacceptable. It's like adding to the page_struct. This gets added to *every* event, and a single byte added, causes 1M extra for a million events (very common in tracing). It causes 1G extra for a billion events.

I'm on top of:
git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git
v5.4.19-rt11-rebase

Quoted 2 lines

Let's find a better way to handle this.

I can fix the bpftrace tool I guess, through it's not so convenient the way it's used in it

jirka

Quoted 22 lines

-- Steve

Quoted 17 lines
include/linux/trace_events.h +0 -0
 };
 
 #define TRACE_EVENT_TYPE_MAX						\
kernel/trace/trace_events.c +3 -0
index accaae59a762..1fe37b7aeaff 100644
@@ -183,6 +183,9 @@ static int trace_define_common_fields(void)
 	__common_field(int, pid);
 	__common_field(unsigned short, migrate_disable);
 	__common_field(unsigned short, padding);
+	__common_field(unsigned char,  preempt_lazy_count);
+	__common_field(unsigned char,  padding1);
+	__common_field(unsigned short, padding2);
 
 	return ret;
 }
maintainer
#3 lore raw
Quoted 35 lines · On Fri, 21 Feb 2020 17:10:30 +0100 Jiri Olsa <[email protected]> wrote:
Quoted 27 lines · Steven Rostedt
Quoted 17 lines · On Fri, 21 Feb 2020 16:35:41 +0100 Jiri Olsa <[email protected]> wrote:

When commit 65fd07df3588 added preempt_lazy_count into 'struct trace_entry' it did not add 4 bytes padding. Also we need to update the common fields for tracepoint, otherwise some tools (bpftrace) stop working due to missing common fields.

Fixes 65fd07df3588 ("x86: Support for lazy preemption")
---
 include/linux/trace_events.h | 2 ++
 kernel/trace/trace_events.c  | 3 +++
 2 files changed, 5 insertions(+)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5..51a3f5188923 100644

include/linux/trace_events.h struct trace_entry { · line 69

Quoted 5 lines
include/linux/trace_events.h +2 -0
@@ -65,6 +65,8 @@ struct trace_entry {
 	unsigned short		migrate_disable;
 	unsigned short		padding;
 	unsigned char		preempt_lazy_count;
+	unsigned char		padding1;
+	unsigned short		padding2;  
Quoted 6 lines

Wait! I don't have these changes in my tree, nor do I see them in Linus's. This really bloats the trace events! This header is very sensitive to size and just willy nilly adding to it is unacceptable. It's like adding to the page_struct. This gets added to *every* event, and a single byte added, causes 1M extra for a million events (very common in tracing). It causes 1G extra for a billion events.

Quoted 4 lines

I'm on top of:
git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git
v5.4.19-rt11-rebase

Ug, I now see it:

struct trace_entry {
	unsigned short		type;
	unsigned char		flags;
	unsigned char		preempt_count;
	int			pid;
	unsigned short		migrate_disable;
	unsigned short		padding;
	unsigned char		preempt_lazy_count;
};

Which adds a ton of bloat.

Quoted 5 lines
Quoted 2 lines

Let's find a better way to handle this.

I can fix the bpftrace tool I guess, through it's not so convenient the way it's used in it

Not as inconvenient as dropping events due to wasted space in the ring buffer. Note, this is attached to function tracing events. Any increase here will cause more function events to be dropped.

Why is migrate disable a short? Is there going to be more that 256 nesting?

-- Steve

#4 lore raw
Quoted 58 lines · Steven Rostedt
Quoted 35 lines · On Fri, 21 Feb 2020 17:10:30 +0100 Jiri Olsa <[email protected]> wrote:
Quoted 27 lines · Steven Rostedt
Quoted 17 lines · On Fri, 21 Feb 2020 16:35:41 +0100 Jiri Olsa <[email protected]> wrote:

When commit 65fd07df3588 added preempt_lazy_count into 'struct trace_entry' it did not add 4 bytes padding. Also we need to update the common fields for tracepoint, otherwise some tools (bpftrace) stop working due to missing common fields.

Fixes 65fd07df3588 ("x86: Support for lazy preemption")
---
 include/linux/trace_events.h | 2 ++
 kernel/trace/trace_events.c  | 3 +++
 2 files changed, 5 insertions(+)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5..51a3f5188923 100644

include/linux/trace_events.h struct trace_entry { · line 69

Quoted 5 lines
include/linux/trace_events.h +2 -0
@@ -65,6 +65,8 @@ struct trace_entry {
 	unsigned short		migrate_disable;
 	unsigned short		padding;
 	unsigned char		preempt_lazy_count;
+	unsigned char		padding1;
+	unsigned short		padding2;  
Quoted 6 lines

Wait! I don't have these changes in my tree, nor do I see them in Linus's. This really bloats the trace events! This header is very sensitive to size and just willy nilly adding to it is unacceptable. It's like adding to the page_struct. This gets added to *every* event, and a single byte added, causes 1M extra for a million events (very common in tracing). It causes 1G extra for a billion events.

Quoted 4 lines

I'm on top of:
git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git
v5.4.19-rt11-rebase

Ug, I now see it:

struct trace_entry {
	unsigned short		type;
	unsigned char		flags;
	unsigned char		preempt_count;
	int			pid;
	unsigned short		migrate_disable;
	unsigned short		padding;
	unsigned char		preempt_lazy_count;
};

Which adds a ton of bloat.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Let's find a better way to handle this.

I can fix the bpftrace tool I guess, through it's not so convenient the way it's used in it

Not as inconvenient as dropping events due to wasted space in the ring buffer. Note, this is attached to function tracing events. Any increase here will cause more function events to be dropped.

sure, I'll probably fix it anyway, but there might be other broken tools ;-)

libtraceevent/perf is actualy ok with this, probably following the offsets and sizes directly.. actualy bpftrace might be special case because it creates C struct out of the fields, so there's gap between common fields and the rest of the fields

jirka

Quoted 6 lines

Why is migrate disable a short? Is there going to be more that 256 nesting?

-- Steve

#6 lore raw
In reply to Steven Rostedt

On 2020-02-21 11:21:52 [-0500], Steven Rostedt wrote:
…

Quoted 11 lines
struct trace_entry {
	unsigned short		type;
	unsigned char		flags;
	unsigned char		preempt_count;
	int			pid;
	unsigned short		migrate_disable;
	unsigned short		padding;
	unsigned char		preempt_lazy_count;
};

Which adds a ton of bloat.

…

Quoted 2 lines

Why is migrate disable a short? Is there going to be more that 256 nesting?

I don't think so. We go now and then > 10 and the trace file shows only one digit. So I think that migrate_disable can use a byte field here.
So we make migrate_disable and preempt_lazy_count a char' type and keep the short' padding later on?

Quoted 1 line

-- Steve

Sebastian

maintainer
#5 lore raw
In reply to Jiri Olsa
Quoted 3 lines · On Fri, 21 Feb 2020 17:29:44 +0100 Jiri Olsa <[email protected]> wrote:

sure, I'll probably fix it anyway, but there might be other broken tools ;-)

libtraceevent/perf is actualy ok with this, probably following the

Which is the whole point of libtraceevent. Everything should be using it.

Quoted 3 lines

offsets and sizes directly.. actualy bpftrace might be special case because it creates C struct out of the fields, so there's gap between common fields and the rest of the fields

Hmm, hopefully this can be fixed, as I really don't want wasted space in the ring buffers.

-- Steve

#7 lore raw

PATCH 1/1 tracing: make preempt_lazy and migrate_disable counter smaller

In reply to Sebastian Andrzej Siewior

The migrate_disable counter should not exceed 255 so it is enough to store it in an 8bit field.
With this change we can move the `preempt_lazy_count' member into the gap so the whole struct shrinks by 4 bytes to 12 bytes in total.

---
 include/linux/trace_events.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/trace_events.h +2 -2
index f3b1ef07e4a5f..c8b3f06cb5ed7 100644
@@ -62,9 +62,9 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
+	unsigned short		padding;
 };
 
 #define TRACE_EVENT_TYPE_MAX						\
Signature · 1 line
2.25.0
maintainer
#8 lore raw

Re: [PATCH RT] tracing: make preempt_lazy and migrate_disable counter smaller

Quoted 5 lines · On Fri, 21 Feb 2020 18:44:19 +0100 Sebastian Andrzej Siewior…
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5f..c8b3f06cb5ed7 100644

include/linux/trace_events.h struct trace_entry { · line 68

Quoted 9 lines
include/linux/trace_events.h +2 -2
@@ -62,9 +62,9 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
+	unsigned short		padding;
 };

Do we really need the padding here?

-- Steve

#9 lore raw

Re: [PATCH RT] tracing: make preempt_lazy and migrate_disable counter smaller

Quoted 19 lines · Steven Rostedt
Quoted 5 lines · On Fri, 21 Feb 2020 18:44:19 +0100 Sebastian Andrzej Siewior…
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5f..c8b3f06cb5ed7 100644

include/linux/trace_events.h struct trace_entry { · line 68

Quoted 9 lines
include/linux/trace_events.h +2 -2
@@ -62,9 +62,9 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
+	unsigned short		padding;
 };

Do we really need the padding here?

Not really. The two bytes are consumed since there is __packed so that padding makes it just more obvious. However that padding wasn't used in the past. I can remove it if you want.
The struct can't be __packed to save additional two bytes, correct?

Quoted 1 line

-- Steve

Sebastian

#10 lore raw

Re: [PATCH RT] tracing: make preempt_lazy and migrate_disable counter smaller

In reply to Sebastian Andrzej Siewior
Quoted 15 lines · Sebastian Andrzej Siewior

The migrate_disable counter should not exceed 255 so it is enough to store it in an 8bit field.
With this change we can move the `preempt_lazy_count' member into the gap so the whole struct shrinks by 4 bytes to 12 bytes in total.

---
 include/linux/trace_events.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5f..c8b3f06cb5ed7 100644

include/linux/trace_events.h struct trace_entry { · line 67

Quoted 8 lines
include/linux/trace_events.h +2 -2
@@ -62,9 +62,9 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
+	unsigned short		padding;

also we still need to put preempt_lazy_count as common field:

	__common_field(unsigned char,  preempt_lazy_count);

jirka

#11 lore raw

Re: [PATCH RT] tracing: make preempt_lazy and migrate_disable counter smaller

Quoted 27 lines · Jiri Olsa
Quoted 15 lines · Sebastian Andrzej Siewior

The migrate_disable counter should not exceed 255 so it is enough to store it in an 8bit field.
With this change we can move the `preempt_lazy_count' member into the gap so the whole struct shrinks by 4 bytes to 12 bytes in total.

---
 include/linux/trace_events.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5f..c8b3f06cb5ed7 100644

include/linux/trace_events.h struct trace_entry { · line 67

Quoted 8 lines
include/linux/trace_events.h +2 -2
@@ -62,9 +62,9 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
+	unsigned short		padding;

also we still need to put preempt_lazy_count as common field:

Quoted 1 line
	__common_field(unsigned char,  preempt_lazy_count);

so I need to update the struct as I did (and drop the padding field like Steven suggested) and then do the "same" change to "trace_define_common_fields" ?

Quoted 2 lines

jirka

Sebastian

#12 lore raw

Re: [PATCH RT] tracing: make preempt_lazy and migrate_disable counter smaller

Quoted 28 lines · Sebastian Andrzej Siewior
Quoted 27 lines · Jiri Olsa
Quoted 15 lines · Sebastian Andrzej Siewior

The migrate_disable counter should not exceed 255 so it is enough to store it in an 8bit field.
With this change we can move the `preempt_lazy_count' member into the gap so the whole struct shrinks by 4 bytes to 12 bytes in total.

---
 include/linux/trace_events.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/trace_events.h +0 -0
index f3b1ef07e4a5f..c8b3f06cb5ed7 100644

include/linux/trace_events.h struct trace_entry { · line 67

Quoted 8 lines
include/linux/trace_events.h +2 -2
@@ -62,9 +62,9 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
+	unsigned short		padding;

also we still need to put preempt_lazy_count as common field:

Quoted 5 lines
Quoted 1 line
	__common_field(unsigned char,  preempt_lazy_count);

so I need to update the struct as I did (and drop the padding field like Steven suggested) and then do the "same" change to "trace_define_common_fields" ?

yep, AFAICS that's it

thanks,
jirka

#13 lore raw

PATCH v2 1/1 tracing: make preempt_lazy and migrate_disable counter smaller

The migrate_disable counter should not exceed 255 so it is enough to store it in an 8bit field.
With this change we can move the preempt_lazy_count' member into the gap so the whole struct shrinks by 4 bytes to 12 bytes in total. Remove the padding' field, it is not needed.
Update the tracing fields in trace_define_common_fields() (it was missing the preempt_lazy_count field).

---
v1…v2:
- drop the `padding' member
- update the members in trace_define_common_fields() to match struct trace_entry.

 include/linux/trace_events.h | 3 +--
 kernel/trace/trace_events.c  | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
include/linux/trace_events.h +1 -2
index f3b1ef07e4a5f..10bbf986bc1d5 100644
@@ -62,8 +62,7 @@ struct trace_entry {
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	unsigned short		migrate_disable;
-	unsigned short		padding;
+	unsigned char		migrate_disable;
 	unsigned char		preempt_lazy_count;
 };
 
kernel/trace/trace_events.c +2 -2
index accaae59a7626..8bfb187cce65a 100644
@@ -181,8 +181,8 @@ static int trace_define_common_fields(void)
 	__common_field(unsigned char, flags);
 	__common_field(unsigned char, preempt_count);
 	__common_field(int, pid);
-	__common_field(unsigned short, migrate_disable);
-	__common_field(unsigned short, padding);
+	__common_field(unsigned char, migrate_disable);
+	__common_field(unsigned char, preempt_lazy_count);
 
 	return ret;
 }
Signature · 1 line
2.25.1
#14 lore raw

Re: [PATCH RT v2] tracing: make preempt_lazy and migrate_disable counter smaller

Quoted 8 lines · Sebastian Andrzej Siewior

The migrate_disable counter should not exceed 255 so it is enough to store it in an 8bit field.
With this change we can move the preempt_lazy_count' member into the gap so the whole struct shrinks by 4 bytes to 12 bytes in total. Remove the padding' field, it is not needed.
Update the tracing fields in trace_define_common_fields() (it was missing the preempt_lazy_count field).

Quoted 6 lines

---
v1…v2:
- drop the `padding' member
- update the members in trace_define_common_fields() to match struct trace_entry.

seems ok to me.. not sure we care, but just wanted to point out that there's a 'not described gap' in the sched_wakeup's format file and probably in other formats as well:

	# cat /sys/kernel/debug/tracing/events/sched/sched_wakeup/format
	name: sched_wakeup
	ID: 310
	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:unsigned char common_migrate_disable;     offset:8;       size:1; signed:0;
		field:unsigned char common_preempt_lazy_count;  offset:9;       size:1; signed:0;
		field:char comm[16];    offset:12;      size:16;        signed:1;
		field:pid_t pid;        offset:28;      size:4; signed:1;
		field:int prio; offset:32;      size:4; signed:1;
		field:int success;      offset:36;      size:4; signed:1;
		field:int target_cpu;   offset:40;      size:4; signed:1;

there's "common_preempt_lazy_count" field on offset 9 with size 1:

	common_preempt_lazy_count;  offset:9;       size:1;

followed by "comm" field on offset 12:

	field:char comm[16];    offset:12;      size:16;        signed:1;

which makes 2 bytes gap in between, that might confuse some applications like bpftrace ;-) however there's still enough data to workaround that, so I'm ok with that

thanks,
jirka