ring-buffer: Updates for 6.12
Subsystems (5)
Steven Rostedt
maintainercover ring-buffer: Updates for 6.12
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
ring-buffer/for-next
Head SHA1: 2fcd5aff92aab479a9a89cfce2dbc9c6a9455b4f
Steven Rostedt (7):
ring-buffer: Don't reset persistent ring-buffer meta saved addresses
ring-buffer: Add magic and struct size to boot up meta data
tracing: Add "traceoff" flag to boot time tracing instances
tracing: Allow trace_printk() to go to other instance buffers
tracing: Have trace_printk not use binary prints if boot buffer
tracing: Add option to set an instance to be the trace_printk destination tracing/Documentation: Start a document on how to debug with tracing
Vincent Donnefort (1):
ring-buffer: Align meta-page to sub-buffers for improved TLB usage
----
Documentation/admin-guide/kernel-parameters.txt | 23 ++++ Documentation/trace/debugging.rst | 159 ++++++++++++++++++++++++ Documentation/trace/ftrace.rst | 12 ++ kernel/trace/ring_buffer.c | 79 ++++++++---- kernel/trace/trace.c | 127 ++++++++++++++++--- kernel/trace/trace.h | 4 +- kernel/trace/trace_output.c | 5 +- tools/testing/selftests/ring-buffer/map_test.c | 14 +++ 8 files changed, 385 insertions(+), 38 deletions(-) create mode 100644 Documentation/trace/debugging.rst
Steven Rostedt
maintainerPATCH 1/8 ring-buffer: Dont reset persistent ring-buffer meta saved addresses
From: Steven Rostedt <[email protected]>
The text and data address is saved in the meta data so that it can be used to know the delta of the text and data addresses of the last boot compared to the text and data addresses of the current boot. The delta is used to convert function pointer entries in the ring buffer to something that can be used by kallsyms (note this only works for built-in functions).
But the saved addresses get reset on boot up. If the buffer is not used and there's another reboot, then the saved text and data addresses will be of the last boot and not that of the boot that created the content in the ring buffer.
To get an idea of the issue:
# trace-cmd start -B boot_mapped -p function
# reboot
# trace-cmd show -B boot_mapped | tail
<...>-1 [000] d..1. 461.983243: native_apic_msr_write <-native_kick_ap
<...>-1 [000] d..1. 461.983244: __pfx_native_apic_msr_eoi <-native_kick_ap
<...>-1 [000] d..1. 461.983244: reserve_irq_vector_locked <-native_kick_ap
<...>-1 [000] d..1. 461.983262: branch_emulate_op <-native_kick_ap
<...>-1 [000] d..1. 461.983262: __ia32_sys_ia32_pread64 <-native_kick_ap
<...>-1 [000] d..1. 461.983263: native_kick_ap <-__smpboot_create_thread
<...>-1 [000] d..1. 461.983263: store_cache_disable <-native_kick_ap
<...>-1 [000] d..1. 461.983279: acpi_power_off_prepare <-native_kick_ap
<...>-1 [000] d..1. 461.983280: __pfx_acpi_ns_delete_node <-acpi_suspend_enter
<...>-1 [000] d..1. 461.983280: __pfx_acpi_os_release_lock <-acpi_suspend_enter
# reboot
# trace-cmd show -B boot_mapped |tail
<...>-1 [000] d..1. 461.983243: 0xffffffffa9669220 <-0xffffffffa965f3db
<...>-1 [000] d..1. 461.983244: 0xffffffffa96690f0 <-0xffffffffa965f3db
<...>-1 [000] d..1. 461.983244: 0xffffffffa9663fa0 <-0xffffffffa965f3db
<...>-1 [000] d..1. 461.983262: 0xffffffffa9672e80 <-0xffffffffa965f3e0
<...>-1 [000] d..1. 461.983262: 0xffffffffa962b940 <-0xffffffffa965f3ec
<...>-1 [000] d..1. 461.983263: 0xffffffffa965f540 <-0xffffffffa96e1362
<...>-1 [000] d..1. 461.983263: 0xffffffffa963c940 <-0xffffffffa965f55b
<...>-1 [000] d..1. 461.983279: 0xffffffffa9ee30c0 <-0xffffffffa965f59b
<...>-1 [000] d..1. 461.983280: 0xffffffffa9f16c10 <-0xffffffffa9ee3157
<...>-1 [000] d..1. 461.983280: 0xffffffffa9ee02e0 <-0xffffffffa9ee3157By not updating the saved text and data addresses in the meta data at every boot up and only updating them when the buffer is reset, it allows multiple boots to see the same data.
--- kernel/trace/ring_buffer.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
kernel/trace/ring_buffer.c +24 -8
@@ -1817,12 +1817,19 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)/* Used to calculate data delta */ static char rb_data_ptr[] ="" ; +#define THIS_TEXT_PTR ((unsigned long)rb_meta_init_text_addr) +#define THIS_DATA_PTR ((unsigned long)rb_data_ptr) + +static void rb_meta_init_text_addr (struct ring_buffer_meta *meta) +{ + meta->text_addr =THIS_TEXT_PTR ; + meta->data_addr =THIS_DATA_PTR ; +} +static void rb_range_meta_init (struct trace_buffer *buffer,int nr_pages) {struct ring_buffer_meta *meta;unsigned long delta; -unsigned long this_text = (unsigned long )rb_range_meta_init; -unsigned long this_data = (unsigned long )rb_data_ptr;void *subbuf;int cpu;int i;
@@ -1839,10 +1846,8 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages) meta->first_buffer += delta; meta->head_buffer += delta; meta->commit_buffer += delta; - buffer->last_text_delta = this_text - meta->text_addr; - buffer->last_data_delta = this_data - meta->data_addr; - meta->text_addr = this_text; - meta->data_addr = this_data; + buffer->last_text_delta =THIS_TEXT_PTR - meta->text_addr; + buffer->last_data_delta =THIS_DATA_PTR - meta->data_addr;continue ; }
@@ -1859,8 +1864,7 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages) subbuf =rb_subbufs_from_meta (meta); meta->first_buffer = (unsigned long )subbuf; - meta->text_addr = this_text; - meta->data_addr = this_data; +rb_meta_init_text_addr (meta);/* * The buffers[] array holds the order of the sub-buffers
@@ -5990,6 +5994,7 @@ static void reset_disabled_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)void ring_buffer_reset_cpu (struct trace_buffer *buffer,int cpu) {struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu]; +struct ring_buffer_meta *meta;if (!cpumask_test_cpu (cpu, buffer->cpumask))return ;
@@ -6008,6 +6013,11 @@ void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu)atomic_dec (&cpu_buffer->record_disabled);atomic_dec (&cpu_buffer->resize_disabled); +/* Make sure persistent meta now uses this buffer's addresses */ + meta =rb_range_meta (buffer,0 , cpu_buffer->cpu); +if (meta) +rb_meta_init_text_addr (meta); +mutex_unlock (&buffer->mutex); }EXPORT_SYMBOL_GPL (ring_buffer_reset_cpu);
@@ -6022,6 +6032,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);void ring_buffer_reset_online_cpus (struct trace_buffer *buffer) {struct ring_buffer_per_cpu *cpu_buffer; +struct ring_buffer_meta *meta;int cpu;/* prevent another thread from changing buffer sizes */
@@ -6049,6 +6060,11 @@ void ring_buffer_reset_online_cpus(struct trace_buffer *buffer)reset_disabled_cpu_buffer (cpu_buffer); +/* Make sure persistent meta now uses this buffer's addresses */ + meta =rb_range_meta (buffer,0 , cpu_buffer->cpu); +if (meta) +rb_meta_init_text_addr (meta); +atomic_dec (&cpu_buffer->record_disabled);atomic_sub (RESET_BIT , &cpu_buffer->resize_disabled); }
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 2/8 ring-buffer: Add magic and struct size to boot up meta data
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add a magic number as well as save the struct size of the ring_buffer_meta structure in the meta data to also use as validation. Updating the magic number could be used to force a invalidation between kernel versions, and saving the structure size is also a good method to make sure the content is what is expected.
--- kernel/trace/ring_buffer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
kernel/trace/ring_buffer.c +14 -0
@@ -44,7 +44,11 @@static void update_pages_handler (struct work_struct *work); +#define RING_BUFFER_META_MAGIC 0xBADFEED +struct ring_buffer_meta { +int magic; +int struct_size;unsigned long text_addr;unsigned long data_addr;unsigned long first_buffer;
@@ -1627,6 +1631,13 @@ static bool rb_meta_valid(struct ring_buffer_meta *meta, int cpu,unsigned long buffers_end;int i; +/* Check the meta magic and meta struct size */ +if (meta->magic !=RING_BUFFER_META_MAGIC || + meta->struct_size !=sizeof (*meta)) { +pr_info ("Ring buffer boot meta[%d] mismatch of magic or struct size\n" , cpu); +return false; + } +/* The subbuffer's size and number of subbuffers must match */ if (meta->subbuf_size != subbuf_size || meta->nr_subbufs != nr_pages +1 ) {
@@ -1858,6 +1869,9 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages)memset (meta,0 , next_meta - (void *)meta); + meta->magic =RING_BUFFER_META_MAGIC ; + meta->struct_size =sizeof (*meta); + meta->nr_subbufs = nr_pages +1 ; meta->subbuf_size =PAGE_SIZE ;
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 3/8 ring-buffer: Align meta-page to sub-buffers for improved TLB usage
In reply to Steven RostedtFrom: Vincent Donnefort <[email protected]>
Previously, the mapped ring-buffer layout caused misalignment between the meta-page and sub-buffers when the sub-buffer size was not a multiple of PAGE_SIZE. This prevented hardware with larger TLB entries from utilizing them effectively.
Add a padding with the zero-page between the meta-page and sub-buffers. Also update the ring-buffer map_test to verify that padding.
--- kernel/trace/ring_buffer.c | 33 +++++++++++-------- .../testing/selftests/ring-buffer/map_test.c | 14 ++++++++ 2 files changed, 34 insertions(+), 13 deletions(-)
kernel/trace/ring_buffer.c +20 -13
@@ -6852,10 +6852,10 @@ static void rb_setup_ids_meta_page(struct ring_buffer_per_cpu *cpu_buffer,/* install subbuf ID to kern VA translation */ cpu_buffer->subbuf_ids = subbuf_ids; - meta->meta_page_size =PAGE_SIZE ; meta->meta_struct_len =sizeof (*meta); meta->nr_subbufs = nr_subbufs; meta->subbuf_size = cpu_buffer->buffer->subbuf_size +BUF_PAGE_HDR_SIZE ; + meta->meta_page_size = meta->subbuf_size;rb_update_meta_page (cpu_buffer); }
@@ -6949,6 +6949,12 @@ static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer, !(vma->vm_flags & VM_MAYSHARE))return -EPERM ; + subbuf_order = cpu_buffer->buffer->subbuf_order; + subbuf_pages =1 << subbuf_order; + +if (subbuf_order && pgoff % subbuf_pages) +return -EINVAL ; +/* * Make sure the mapping cannot become writable later. Also tell the VM * to not touch these pages (VM_DONTCOPY | VM_DONTEXPAND).
@@ -6958,11 +6964,8 @@ static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer,lockdep_assert_held (&cpu_buffer->mapping_lock); - subbuf_order = cpu_buffer->buffer->subbuf_order; - subbuf_pages =1 << subbuf_order; - nr_subbufs = cpu_buffer->nr_pages +1 ;/* + reader-subbuf */ - nr_pages = ((nr_subbufs) << subbuf_order) - pgoff +1 ;/* + meta-page */ + nr_pages = ((nr_subbufs +1 ) << subbuf_order) - pgoff;/* + meta-page */ nr_vma_pages =vma_pages (vma);if (!nr_vma_pages || nr_vma_pages > nr_pages)
@@ -6975,20 +6978,24 @@ static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer,return -ENOMEM ;if (!pgoff) { +unsigned long meta_page_padding; + pages[p++] =virt_to_page (cpu_buffer->meta_page);/* -* TODO: Align sub-buffers on their size, once -* vm_insert_pages() supports the zero-page. +* Pad with the zero-page to align the meta-page with the +* sub-buffers. */ - }else { -/* Skip the meta-page */ - pgoff--; + meta_page_padding = subbuf_pages -1 ; +while (meta_page_padding-- && p < nr_pages) { +unsigned long __maybe_unused zero_addr = + vma->vm_start + (PAGE_SIZE * p); -if (pgoff % subbuf_pages) { - err = -EINVAL ; - goto out; + pages[p++] =ZERO_PAGE (zero_addr); } + }else { +/* Skip the meta-page */ + pgoff -= subbuf_pages; s += pgoff / subbuf_pages; }
tools/testing/selftests/ring-buffer/map_test.c +14 -0
@@ -228,6 +228,20 @@ TEST_F(map, data_mmap) data =mmap (NULL , data_len,PROT_READ ,MAP_SHARED , desc->cpu_fd, meta_len);ASSERT_EQ (data,MAP_FAILED ); + +/* Verify meta-page padding */ +if (desc->meta->meta_page_size >getpagesize ()) { +void *addr; + + data_len = desc->meta->meta_page_size; + data =mmap (NULL , data_len, +PROT_READ ,MAP_SHARED , desc->cpu_fd,0 ); +ASSERT_NE (data,MAP_FAILED ); + + addr = (void *)((unsigned long )data +getpagesize ()); +ASSERT_EQ (*((int *)addr),0 ); +munmap (data, data_len); + } }FIXTURE (snapshot) {
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 4/8 tracing: Add "traceoff" flag to boot time tracing instances
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add a "flags" delimiter (^) to the "trace_instance" kernel command line parameter, and add the "traceoff" flag. The format is:
trace_instance=<name>[^<flag1>[^<flag2>]][@<memory>][,<events>]
The code allows for more than one flag to be added, but currently only "traceoff" is done so.
The motivation for this change came from debugging with the persistent ring buffer and having trace_printk() writing to it. The trace_printk calls are always enabled, and the boot after the crash was having the unwanted trace_printks from the current boot inject into the ring buffer with the trace_printks of the crash kernel, making the output very confusing.
--- .../admin-guide/kernel-parameters.txt | 17 ++++++++++ kernel/trace/trace.c | 31 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +17 -0
@@ -6743,6 +6743,15 @@ the same thing would happen if it was left off). The irq_handler_entry event, and all events under the "initcall" system. + Flags can be added to the instance to modify its behavior when it is + created. The flags are separated by '^'. Currently there's only one flag + defined, and that's "traceoff", to have the tracing instance tracing + disabled after it is created. + + trace_instance=foo^traceoff,sched,irq + + The flags must come before the defined events. + If memory has been reserved (see memmap for x86), the instance can use that memory:
@@ -6765,6 +6774,14 @@ kernel versions where the validator will fail and reset the ring buffer if the layout is not the same as the previous kernel. + If the ring buffer is used for persistent bootups and has events enabled, + it is recommend to disable tracing so that events from a previous boot do not + mix with events of the current boot (unless you are debugging a random crash + at boot up). + + reserve_mem=12M:4096:trace trace_instance=boot_map^traceoff@trace,sched,irq + + trace_options=[option-list] [FTRACE] Enable or disable tracer options at boot. The option-list is a comma delimited list of options
kernel/trace/trace.c +30 -1
@@ -10468,10 +10468,36 @@ __init static void enable_instances(void)phys_addr_t start =0 ;phys_addr_t size =0 ;unsigned long addr =0 ; +bool traceoff = false; +char *flag_delim; +char *addr_delim; tok =strsep (&curr_str,"," ); - name =strsep (&tok,"@" ); + flag_delim =strchr (tok,'^' ); + addr_delim =strchr (tok,'@' ); + +if (addr_delim) + *addr_delim++ ='\0' ; + +if (flag_delim) + *flag_delim++ ='\0' ; + + name = tok; + +if (flag_delim) { +char *flag; + +while ((flag =strsep (&flag_delim,"^" ))) { +if (strcmp (flag,"traceoff" ) ==0 ) + traceoff = true; +else +pr_info ("Tracing: Invalid instance flag '%s' for %s\n" , + flag, name); + } + } + + tok = addr_delim;if (tok &&isdigit (*tok)) { start =memparse (tok, &tok);if (!start) {
@@ -10519,6 +10545,9 @@ __init static void enable_instances(void)continue ; } +if (traceoff) +tracer_tracing_off (tr); +/* Only allow non mapped buffers to be deleted */ if (!start)trace_array_put (tr);
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 5/8 tracing: Allow trace_printk() to go to other instance buffers
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Currently, trace_printk() just goes to the top level ring buffer. But there may be times that it should go to one of the instances created by the kernel command line.
Add a new trace_instance flag: traceprintk (also can use "printk" or "trace_printk" as people tend to forget the actual flag name).
trace_instance=foo^traceprintk
Will assign the trace_printk to this buffer at boot up.
--- .../admin-guide/kernel-parameters.txt | 14 ++++-- kernel/trace/trace.c | 46 ++++++++++++++----- 2 files changed, 45 insertions(+), 15 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +10 -4
@@ -6744,11 +6744,17 @@ event, and all events under the "initcall" system. Flags can be added to the instance to modify its behavior when it is - created. The flags are separated by '^'. Currently there's only one flag - defined, and that's "traceoff", to have the tracing instance tracing - disabled after it is created. + created. The flags are separated by '^'. - trace_instance=foo^traceoff,sched,irq + The available flags are: + + traceoff - Have the tracing instance tracing disabled after it is created. + traceprintk - Have trace_printk() write into this trace instance + (note, "printk" and "trace_printk" can also be used) + Currently, traceprintk flag cannot be used for memory + mapped ring buffers as described below. + + trace_instance=foo^traceoff^traceprintk,sched,irq The flags must come before the defined events.
kernel/trace/trace.c +35 -11
139 lines not on this page · raw message
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 6/8 tracing: Have trace_printk not use binary prints if boot buffer
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
If the persistent boot mapped ring buffer is used for trace_printk(), force it to not use the binary versions. trace_printk() by default uses bin_printf() that only saves the pointer to the format and not the format itself inside the ring buffer. But for a persistent buffer that is read after reboot, the pointers to the format strings may not be the same, or worse, not even exist! Instead, just force the more robust, but slower, version that does the formatting before saving into the ring buffer.
The boot mapped buffer can now be used for trace_printk and friends!
Using the trace_printk() and the persistent buffer was used to debug the issue with the osnoise tracer:
--- .../admin-guide/kernel-parameters.txt | 4 +- kernel/trace/trace.c | 44 ++++++++++++------- kernel/trace/trace.h | 3 +- kernel/trace/trace_output.c | 5 ++- 4 files changed, 36 insertions(+), 20 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -3
@@ -6751,8 +6751,6 @@ traceoff - Have the tracing instance tracing disabled after it is created. traceprintk - Have trace_printk() write into this trace instance (note, "printk" and "trace_printk" can also be used) - Currently, traceprintk flag cannot be used for memory - mapped ring buffers as described below. trace_instance=foo^traceoff^traceprintk,sched,irq
@@ -6785,7 +6783,7 @@ mix with events of the current boot (unless you are debugging a random crash at boot up). - reserve_mem=12M:4096:trace trace_instance=boot_map^traceoff@trace,sched,irq + reserve_mem=12M:4096:trace trace_instance=boot_map^traceoff^traceprintk@trace,sched,irq trace_options=[option-list]
kernel/trace/trace.c +29 -15
80 lines not on this page · raw message
kernel/trace/trace.h +2 -1
@@ -429,7 +429,8 @@ struct trace_array { };enum { -TRACE_ARRAY_FL_GLOBAL = (1 <<0 ) +TRACE_ARRAY_FL_GLOBAL =BIT (0 ), +TRACE_ARRAY_FL_BOOT =BIT (1 ), };extern struct list_head ftrace_trace_arrays;
kernel/trace/trace_output.c +4 -1
@@ -1591,10 +1591,13 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, {struct print_entry *field;struct trace_seq *s = &iter->seq; +unsigned long ip;trace_assign_type (field, iter->ent); -seq_print_ip_sym (s, field->ip, flags); + ip = field->ip + iter->tr->text_delta; + +seq_print_ip_sym (s, ip, flags);trace_seq_printf (s,": %s" , field->buf);return trace_handle_return (s);
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 7/8 tracing: Add option to set an instance to be the trace_printk destination
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add a option "trace_printk_dest" that will make the tracing instance the location that trace_printk() will go to. This is useful if the trace_printk or one of the top level tracers is too noisy and there's a need to separate the two. Then an instance can be created, the trace_printk can be set to go there instead, where it will not be lost in the noise of the top level tracer.
Note, only one instance can be the destination of trace_printk at a time. If an instance sets this flag, the instance that had it set will have it cleared. There is always one instance that has this set. By default, that is the top instance. This flag cannot be cleared from the top instance. Doing so will result in an -EINVAL. The only way this flag can be cleared from the top instance is by another instance setting it.
--- Documentation/trace/ftrace.rst | 12 ++++++++++ kernel/trace/trace.c | 40 +++++++++++++++++++++++++++++----- kernel/trace/trace.h | 1 + 3 files changed, 48 insertions(+), 5 deletions(-)
Documentation/trace/ftrace.rst +12 -0
@@ -1186,6 +1186,18 @@ Here are the available options: trace_printk Can disable trace_printk() from writing into the buffer. + trace_printk_dest + Set to have trace_printk() and similar internal tracing functions + write into this instance. Note, only one trace instance can have + this set. By setting this flag, it clears the trace_printk_dest flag + of the instance that had it set previously. By default, the top + level trace has this set, and will get it set again if another + instance has it set then clears it. + + This flag cannot be cleared by the top level instance, as it is the + default instance. The only way the top level instance has this flag + cleared, is by it being set in another instance. + annotate It is sometimes confusing when the CPU buffers are full and one CPU buffer had a lot of events recently, thus
kernel/trace/trace.c +35 -5
@@ -482,7 +482,7 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_export); TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | \ TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE | \ TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS | \ - TRACE_ITER_HASH_PTR) + TRACE_ITER_HASH_PTR | TRACE_ITER_TRACE_PRINTK)/* trace_options that are only supported by global_trace */ #define TOP_LEVEL_TRACE_FLAGS (TRACE_ITER_PRINTK | \
@@ -490,7 +490,7 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_export);/* trace_flags that are default zero for instances */ #define ZEROED_TRACE_FLAGS \ - (TRACE_ITER_EVENT_FORK | TRACE_ITER_FUNC_FORK) + (TRACE_ITER_EVENT_FORK | TRACE_ITER_FUNC_FORK | TRACE_ITER_TRACE_PRINTK)/* * The global_trace is the descriptor that holds the top-level tracing
@@ -513,6 +513,16 @@ static __always_inline bool printk_binsafe(struct trace_array *tr)return !(tr->flags &TRACE_ARRAY_FL_BOOT ); } +static void update_printk_trace (struct trace_array *tr) +{ +if (printk_trace == tr) +return ; + + printk_trace->trace_flags &= ~TRACE_ITER_TRACE_PRINTK ; + printk_trace = tr; + tr->trace_flags |=TRACE_ITER_TRACE_PRINTK ; +} +void trace_set_ring_buffer_expanded (struct trace_array *tr) {if (!tr)
@@ -5300,7 +5310,8 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)int set_tracer_flag (struct trace_array *tr,unsigned int mask,int enabled) {if ((mask ==TRACE_ITER_RECORD_TGID ) || - (mask ==TRACE_ITER_RECORD_CMD )) + (mask ==TRACE_ITER_RECORD_CMD ) || + (mask ==TRACE_ITER_TRACE_PRINTK ))lockdep_assert_held (&event_mutex);/* do nothing if flag is already set */
@@ -5312,6 +5323,25 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)if (tr->current_trace->flag_changed (tr, mask, !!enabled))return -EINVAL ; +if (mask ==TRACE_ITER_TRACE_PRINTK ) { +if (enabled) { +update_printk_trace (tr); + }else { +/* +* The global_trace cannot clear this. +* It's flag only gets cleared if another instance sets it. +*/ +if (printk_trace == &global_trace) +return -EINVAL ; +/* +* An instance must always have it set. +* by default, that's the global_trace instane. +*/ +if (printk_trace == tr) +update_printk_trace (&global_trace); + } + } +if (enabled) tr->trace_flags |= mask;else
@@ -9687,7 +9717,7 @@ static int __remove_instance(struct trace_array *tr) }if (printk_trace == tr) - printk_trace = &global_trace; +update_printk_trace (&global_trace);tracing_set_nop (tr);clear_ftrace_function_probes (tr);
@@ -10578,7 +10608,7 @@ __init static void enable_instances(void)tracer_tracing_off (tr);if (traceprintk) - printk_trace = tr; +update_printk_trace (tr);/* * If start is set, then this is a mapped buffer, and
kernel/trace/trace.h +1 -0
@@ -1321,6 +1321,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,C (IRQ_INFO ,"irq-info" ), \C (MARKERS ,"markers" ), \C (EVENT_FORK ,"event-fork" ), \ +C (TRACE_PRINTK ,"trace_printk_dest" ), \C (PAUSE_ON_TRACE ,"pause-on-trace" ), \C (HASH_PTR ,"hash-ptr" ),/* Print hashed pointer */ \FUNCTION_FLAGS \
Signature · 1 line
2.43.0
Steven Rostedt
maintainerPATCH 8/8 tracing/Documentation: Start a document on how to debug with tracing
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Add a new document Documentation/trace/debugging.rst that will hold various ways to debug tracing.
This initial version mentions trace_printk and how to create persistent buffers that can last across bootups.
--- .../admin-guide/kernel-parameters.txt | 2 + Documentation/trace/debugging.rst | 159 ++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 Documentation/trace/debugging.rst
Documentation/admin-guide/kernel-parameters.txt +2 -0
@@ -6785,6 +6785,8 @@ reserve_mem=12M:4096:trace trace_instance=boot_map^traceoff^traceprintk@trace,sched,irq + See also Documentation/trace/debugging.rst + trace_options=[option-list] [FTRACE] Enable or disable tracer options at boot.
Documentation/trace/debugging.rst new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.43.0