tracing: Account bottom half disabled sections.
PATCH 1/1 tracing: Account bottom half disabled sections.
Disabling only bottom halves via local_bh_disable() disables also preemption but this remains invisible to tracing. On a CONFIG_PREEMPT kernel one might wonder why there is no scheduling happening despite the N flag in the trace. The reason might be the a rcu_read_lock_bh() section.
Add a 'b' to the tracing output if in task context with disabled bottom halves.
--- include/linux/trace_events.h | 1 + kernel/trace/trace.c | 6 ++++-- kernel/trace/trace_output.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-)
include/linux/trace_events.h +1 -0
@@ -172,6 +172,7 @@ enum trace_flag_type {TRACE_FLAG_SOFTIRQ =0x10 ,TRACE_FLAG_PREEMPT_RESCHED =0x20 ,TRACE_FLAG_NMI =0x40 , + TRACE_FLAG_BH_OFF = 0x80, };#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
kernel/trace/trace.c +4 -2
@@ -2601,6 +2601,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) trace_flags |=TRACE_FLAG_HARDIRQ ;if (in_serving_softirq ()) trace_flags |=TRACE_FLAG_SOFTIRQ ; +if (softirq_count () >> (SOFTIRQ_SHIFT +1 )) + trace_flags |=TRACE_FLAG_BH_OFF ;if (tif_need_resched ()) trace_flags |=TRACE_FLAG_NEED_RESCHED ;
@@ -4185,7 +4187,7 @@ static void print_lat_help_header(struct seq_file *m)seq_puts (m,"# _------=> CPU# \n" "# / _-----=> irqs-off \n" "# | / _----=> need-resched \n" -"# || / _---=> hardirq/softirq \n" +"# || / _---=> hardirq/softirq/BH-disables\n" "# ||| / _--=> preempt-depth \n" "# |||| / _-=> migrate-disable \n" "# ||||| / delay \n"
@@ -4226,7 +4228,7 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_fileseq_printf (m,"# %.*s _-----=> irqs-off\n" , prec, space);seq_printf (m,"# %.*s / _----=> need-resched\n" , prec, space); -seq_printf (m,"# %.*s| / _---=> hardirq/softirq\n" , prec, space); +seq_printf (m,"# %.*s| / _---=> hardirq/softirq/BH-disabled\n" , prec, space);seq_printf (m,"# %.*s|| / _--=> preempt-depth\n" , prec, space);seq_printf (m,"# %.*s||| / _-=> migrate-disable\n" , prec, space);seq_printf (m,"# %.*s|||| / delay\n" , prec, space);
kernel/trace/trace_output.c +3 -0
@@ -445,11 +445,13 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)char irqs_off;int hardirq;int softirq; +int bh_off;int nmi; nmi = entry->flags &TRACE_FLAG_NMI ; hardirq = entry->flags &TRACE_FLAG_HARDIRQ ; softirq = entry->flags &TRACE_FLAG_SOFTIRQ ; + bh_off = entry->flags &TRACE_FLAG_BH_OFF ; irqs_off = (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
@@ -478,6 +480,7 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) (hardirq && softirq) ?'H' : hardirq ?'h' : softirq ?'s' : + bh_off ?'b' :'.' ; trace_seq_printf(s, "%c%c%c",
Signature · 1 line
2.34.1
Steven Rostedt
maintainerQuoted 51 lines · On Fri, 10 Dec 2021 21:31:27 +0100 Sebastian Andrzej Siewior…
Disabling only bottom halves via
local_bh_disable()disables also preemption but this remains invisible to tracing. On aCONFIG_PREEMPTkernel one might wonder why there is no scheduling happening despite the N flag in the trace. The reason might be the arcu_read_lock_bh()section.Add a 'b' to the tracing output if in task context with disabled bottom halves.
Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- include/linux/trace_events.h | 1 + kernel/trace/trace.c | 6 ++++-- kernel/trace/trace_output.c | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-)include/linux/trace_events.h +1
-0@@ -172,6 +172,7 @@ enum trace_flag_type {TRACE_FLAG_SOFTIRQ =0x10 ,TRACE_FLAG_PREEMPT_RESCHED =0x20 ,TRACE_FLAG_NMI =0x40 , + TRACE_FLAG_BH_OFF = 0x80, };#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT kernel/trace/trace.c +3
-1@@ -2601,6 +2601,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) trace_flags |=TRACE_FLAG_HARDIRQ ;if (in_serving_softirq ()) trace_flags |=TRACE_FLAG_SOFTIRQ ; +if (softirq_count () >> (SOFTIRQ_SHIFT +1 )) + trace_flags |=TRACE_FLAG_BH_OFF ;if (tif_need_resched ()) trace_flags |=TRACE_FLAG_NEED_RESCHED ;@@ -4185,7 +4187,7 @@ static void print_lat_help_header(struct seq_file *m)seq_puts (m,"# _------=> CPU# \n" "# / _-----=> irqs-off \n" "# | / _----=> need-resched \n" -"# || / _---=> hardirq/softirq \n" +"# || / _---=> hardirq/softirq/BH-disables\n" "# ||| / _--=> preempt-depth \n" "# |||| / _-=> migrate-disable \n" "# ||||| / delay \n"
kernel/trace/trace.c static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file · line 4231
Quoted 5 lines
kernel/trace/trace.c +1
-1@@ -4226,7 +4228,7 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_fileseq_printf (m,"# %.*s _-----=> irqs-off\n" , prec, space);seq_printf (m,"# %.*s / _----=> need-resched\n" , prec, space); -seq_printf (m,"# %.*s| / _---=> hardirq/softirq\n" , prec, space); +seq_printf (m,"# %.*s| / _---=> hardirq/softirq/BH-disabled\n" , prec, space);
So I went to update the documentation on this, and realized that this is wrong. Really, we want this in the irqs-off section probably.
Note, the above is to show we are running in a hardirq or softirq context. But BH-disabled does not match that. Should this be with irqs-off being:
d - irqs are disabled
b - BH is disabled?
D - irqs and BH is disabled?
-- Steve
Quoted 5 lines
kernel/trace/trace.c +0
-0seq_printf (m,"# %.*s|| / _--=> preempt-depth\n" , prec, space);seq_printf (m,"# %.*s||| / _-=> migrate-disable\n" , prec, space);seq_printf (m,"# %.*s|||| / delay\n" , prec, space);kernel/trace/trace_output.c +0
-0
Quoted 10 lines · Steven Rostedt
kernel/trace/trace.c static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file · line 4231
Quoted 6 lines
kernel/trace/trace.c +1
-1@@ -4226,7 +4228,7 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_fileseq_printf (m,"# %.*s _-----=> irqs-off\n" , prec, space);seq_printf (m,"# %.*s / _----=> need-resched\n" , prec, space); -seq_printf (m,"# %.*s| / _---=> hardirq/softirq\n" , prec, space); +seq_printf (m,"# %.*s| / _---=> hardirq/softirq/BH-disabled\n" , prec, space);So I went to update the documentation on this, and realized that this is wrong. Really, we want this in the irqs-off section probably.
Quoted 6 lines
Note, the above is to show we are running in a hardirq or softirq context. But BH-disabled does not match that. Should this be with irqs-off being:
d - irqs are disabled
b - BH is disabled?
D - irqs and BH is disabled?
We are not in hardirq/softirq/nmi but have simply BH disabled. Makes sense.
Quoted 1 line
-- Steve
Sebastian
PATCH v2 1/1 tracing: Account bottom half disabled sections.
Disabling only bottom halves via local_bh_disable() disables also preemption but this remains invisible to tracing. On a CONFIG_PREEMPT kernel one might wonder why there is no scheduling happening despite the N flag in the trace. The reason might be the a rcu_read_lock_bh() section.
Add a 'b' to the tracing output if in task context with disabled bottom halves.
---
v1…v2:
- Move output to the IRQ-off section.
include/linux/trace_events.h | 1 + kernel/trace/trace.c | 6 ++++-- kernel/trace/trace_output.c | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-)
include/linux/trace_events.h +1 -0
@@ -172,6 +172,7 @@ enum trace_flag_type {TRACE_FLAG_SOFTIRQ =0x10 ,TRACE_FLAG_PREEMPT_RESCHED =0x20 ,TRACE_FLAG_NMI =0x40 , + TRACE_FLAG_BH_OFF = 0x80, };#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
kernel/trace/trace.c +4 -2
@@ -2601,6 +2601,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status) trace_flags |=TRACE_FLAG_HARDIRQ ;if (in_serving_softirq ()) trace_flags |=TRACE_FLAG_SOFTIRQ ; +if (softirq_count () >> (SOFTIRQ_SHIFT +1 )) + trace_flags |=TRACE_FLAG_BH_OFF ;if (tif_need_resched ()) trace_flags |=TRACE_FLAG_NEED_RESCHED ;
@@ -4183,7 +4185,7 @@ unsigned long trace_total_entries(struct trace_array *tr)static void print_lat_help_header (struct seq_file *m) {seq_puts (m,"# _------=> CPU# \n" -"# / _-----=> irqs-off \n" +"# / _-----=> irqs-off/BH-disabled\n" "# | / _----=> need-resched \n" "# || / _---=> hardirq/softirq \n" "# ||| / _--=> preempt-depth \n"
@@ -4224,7 +4226,7 @@ static void print_func_help_header_irq(struct array_buffer *buf, struct seq_fileprint_event_info (buf, m); -seq_printf (m,"# %.*s _-----=> irqs-off\n" , prec, space); +seq_printf (m,"# %.*s _-----=> irqs-off/BH-disabled\n" , prec, space);seq_printf (m,"# %.*s / _----=> need-resched\n" , prec, space);seq_printf (m,"# %.*s| / _---=> hardirq/softirq\n" , prec, space);seq_printf (m,"# %.*s|| / _--=> preempt-depth\n" , prec, space);
kernel/trace/trace_output.c +4 -0
@@ -445,14 +445,18 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)char irqs_off;int hardirq;int softirq; +int bh_off;int nmi; nmi = entry->flags &TRACE_FLAG_NMI ; hardirq = entry->flags &TRACE_FLAG_HARDIRQ ; softirq = entry->flags &TRACE_FLAG_SOFTIRQ ; + bh_off = entry->flags &TRACE_FLAG_BH_OFF ; irqs_off = + (entry->flags &TRACE_FLAG_IRQS_OFF && bh_off) ?'D' : (entry->flags &TRACE_FLAG_IRQS_OFF ) ?'d' : + bh_off ?'b' : (entry->flags &TRACE_FLAG_IRQS_NOSUPPORT ) ?'X' :'.' ;
Signature · 1 line
2.34.1