tracing: Updates for 5.10
Subsystems (8)
Steven Rostedt
maintainerPATCH 9/26 tracing: Delete repeated words in comments
In reply to Steven RostedtFrom: Randy Dunlap <[email protected]>
Drop repeated words in kernel/trace/.
{and, the, not}
--- kernel/trace/ftrace.c | 2 +- kernel/trace/trace.c | 2 +- kernel/trace/trace_dynevent.c | 2 +- kernel/trace/trace_events_synth.c | 2 +- kernel/trace/tracing_map.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
kernel/trace/ftrace.c +1 -1
@@ -2402,7 +2402,7 @@ struct ftrace_ops direct_ops = {* * If the record has the FTRACE_FL_REGS set, that means that it * wants to convert to a callback that saves all regs. If FTRACE_FL_REGS -* is not not set, then it wants to convert to the normal callback. +* is not set, then it wants to convert to the normal callback. * * Returns the address of the trampoline to set to */
kernel/trace/trace.c +1 -1
@@ -9287,7 +9287,7 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) }/* -* We need to stop all tracing on all CPUS to read the +* We need to stop all tracing on all CPUS to read * the next buffer. This is a bit expensive, but is * not done often. We fill all what we can read, * and then release the locks again.
kernel/trace/trace_dynevent.c +1 -1
@@ -402,7 +402,7 @@ void dynevent_arg_init(struct dynevent_arg *arg,* whitespace, all followed by a separator, if applicable. After the * first arg string is successfully appended to the command string, * the optional @operator is appended, followed by the second arg and -* and optional @separator. If no separator was specified when +* optional @separator. If no separator was specified when * initializing the arg, a space will be appended. */ void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair,
kernel/trace/trace_events_synth.c +1 -1
@@ -1211,7 +1211,7 @@ __synth_event_trace_start(struct trace_event_file *file,* ENABLED bit is set (which attaches the probe thus allowing * this code to be called, etc). Because this is called * directly by the user, we don't have that but we still need -* to honor not logging when disabled. For the the iterated +* to honor not logging when disabled. For the iterated * trace case, we save the enabed state upon start and just * ignore the following data calls. */
kernel/trace/tracing_map.c +1 -1
@@ -260,7 +260,7 @@ int tracing_map_add_var(struct tracing_map *map)* to use cmp_fn. * * A key can be a subset of a compound key; for that purpose, the -* offset param is used to describe where within the the compound key +* offset param is used to describe where within the compound key * the key referenced by this key field resides. * * Return: The index identifying the field in the map and associated
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 11/26 kprobes: Use module_name() macro
In reply to Steven RostedtFrom: Jarkko Sakkinen <[email protected]>
It is advised to use module_name() macro instead of dereferencing mod->name directly. This makes sense for consistencys sake and also it prevents a hard dependency to CONFIG_MODULES.
--- kernel/trace/trace_kprobe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/trace/trace_kprobe.c +4 -3
@@ -106,9 +106,10 @@ static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk) static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,struct module *mod) { -int len =strlen (mod->name); +int len =strlen (module_name (mod));const char *name =trace_kprobe_symbol (tk); -return strncmp (mod->name, name, len) ==0 && name[len] ==':' ; + +return strncmp (module_name (mod), name, len) ==0 && name[len] ==':' ; } static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
@@ -688,7 +689,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb,if (ret)pr_warn ("Failed to re-register probe %s on %s: %d\n" ,trace_probe_name (&tk->tp), - mod->name, ret); +module_name (mod), ret); } }mutex_unlock (&event_mutex);
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 23/26 tracing: Enable adding dynamic events early stage
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Split the event fields initialization from creating new event directory. This allows the boot-time tracing to define dynamic events before initializing events directory on tracefs.
--- kernel/trace/trace_events.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/trace/trace_events.c +8 -1
@@ -38,6 +38,7 @@ DEFINE_MUTEX(event_mutex);LIST_HEAD (ftrace_events);static LIST_HEAD (ftrace_generic_fields);static LIST_HEAD (ftrace_common_fields); +static bool eventdir_initialized;#define GFP_TRACE (GFP_KERNEL | __GFP_ZERO)
@@ -2486,7 +2487,10 @@ __trace_add_new_event(struct trace_event_call *call, struct trace_array *tr)if (!file)return -ENOMEM ; -return event_create_dir (tr->event_dir, file); +if (eventdir_initialized) +return event_create_dir (tr->event_dir, file); +else +return event_define_fields (call); }/*
@@ -3478,6 +3482,9 @@ __init int event_trace_init(void)if (ret)pr_warn ("Failed to register trace events module notifier\n" );#endif + + eventdir_initialized = true; +return 0 ; }
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 21/26 kprobes: Init kprobes in early_initcall
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Init kprobes feature in early_initcall as same as jump_label and dynamic_debug does, so that we can use kprobes events in earlier boot stage.
--- kernel/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
@@ -2529,7 +2529,7 @@ static int __init init_kprobes(void)init_test_probes ();return err; } -subsys_initcall (init_kprobes); +early_initcall (init_kprobes);#ifdef CONFIG_DEBUG_FS static void report_probe(struct seq_file *pi, struct kprobe *p,
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 22/26 tracing: Define event fields early stage
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Define event fields at early stage so that boot-time tracing can access the event fields (like per-event filter setting).
--- kernel/trace/trace_events.c | 92 ++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 37 deletions(-)
kernel/trace/trace_events.c +55 -37
@@ -2123,12 +2123,48 @@ event_subsystem_dir(struct trace_array *tr, const char *name,return NULL ; } +static int +event_define_fields (struct trace_event_call *call) +{ +struct list_head *head; +int ret =0 ; + +/* +* Other events may have the same class. Only update +* the fields if they are not already defined. +*/ + head =trace_get_fields (call); +if (list_empty (head)) { +struct trace_event_fields *field = call->class->fields_array; +unsigned int offset =sizeof (struct trace_entry ); + +for (; field->type; field++) { +if (field->type ==TRACE_FUNCTION_TYPE ) { + field->define_fields (call); +break ; + } + + offset =ALIGN (offset, field->align); + ret =trace_define_field (call, field->type, field->name, + offset, field->size, + field->is_signed, field->filter_type); +if (WARN_ON_ONCE (ret)) { +pr_err ("error code is %d\n" , ret); +break ; + } + + offset += field->size; + } + } + +return ret; +} +static int event_create_dir (struct dentry *parent,struct trace_event_file *file) {struct trace_event_call *call = file->event_call;struct trace_array *tr = file->tr; -struct list_head *head;struct dentry *d_events;const char *name;int ret;
@@ -2162,35 +2198,10 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file) &ftrace_event_id_fops);#endif -/* -* Other events may have the same class. Only update -* the fields if they are not already defined. -*/ - head =trace_get_fields (call); -if (list_empty (head)) { -struct trace_event_fields *field = call->class->fields_array; -unsigned int offset =sizeof (struct trace_entry ); - -for (; field->type; field++) { -if (field->type ==TRACE_FUNCTION_TYPE ) { - ret = field->define_fields (call); -break ; - } - - offset =ALIGN (offset, field->align); - ret =trace_define_field (call, field->type, field->name, - offset, field->size, - field->is_signed, field->filter_type); -if (ret) -break ; - - offset += field->size; - } -if (ret <0 ) { -pr_warn ("Could not initialize trace point events/%s\n" , - name); -return -1 ; - } + ret =event_define_fields (call); +if (ret <0 ) { +pr_warn ("Could not initialize trace point events/%s\n" , name); +return ret; }/*
@@ -2493,7 +2504,7 @@ __trace_early_add_new_event(struct trace_event_call *call,if (!file)return -ENOMEM ; -return 0 ; +return event_define_fields (call); }struct ftrace_module_file_ops ;
@@ -3431,6 +3442,18 @@ static __init int event_trace_enable_again(void)early_initcall (event_trace_enable_again); +/* Init fields which doesn't related to the tracefs */ +static __init int event_trace_init_fields (void ) +{ +if (trace_define_generic_fields ()) +pr_warn ("tracing: Failed to allocated generic fields" ); + +if (trace_define_common_fields ()) +pr_warn ("tracing: Failed to allocate common fields" ); + +return 0 ; +} +__init int event_trace_init (void ) {struct trace_array *tr;
@@ -3446,12 +3469,6 @@ __init int event_trace_init(void)if (!entry)pr_warn ("Could not create tracefs 'available_events' entry\n" ); -if (trace_define_generic_fields ()) -pr_warn ("tracing: Failed to allocated generic fields" ); - -if (trace_define_common_fields ()) -pr_warn ("tracing: Failed to allocate common fields" ); - ret =early_event_add_tracer (NULL , tr);if (ret)return ret;
@@ -3469,6 +3486,7 @@ void __init trace_event_init(void)event_trace_memsetup ();init_ftrace_syscalls ();event_trace_enable (); +event_trace_init_fields (); }#ifdef CONFIG_EVENT_TRACE_STARTUP_TEST
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 20/26 selftests/ftrace: Add %return suffix tests
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add kprobe %return suffix testcase and syntax error tests for %return suffix.
--- .../test.d/kprobe/kprobe_syntax_errors.tc | 6 ++++++ .../test.d/kprobe/kretprobe_return_suffix.tc | 21 +++++++++++++++++++ .../test.d/kprobe/uprobe_syntax_errors.tc | 6 ++++++ 3 files changed, 33 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +6 -0
@@ -97,4 +97,10 @@ check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE check_error '^p:kprobes/testevent _do_fork abcd=\1' # SAME_PROBE fi +# %return suffix errors +if grep -q "place (kretprobe): .*%return.*" README; then +check_error 'p vfs_read^%hoge' # BAD_ADDR_SUFFIX +check_error 'p ^vfs_read+10%return' # BAD_RETPROBE +fi + exit 0
tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Kretprobe %%return suffix test +# requires: kprobe_events '<symbol>[+<offset>]%return':README + +# Test for kretprobe by "r" +echo 'r:myprobeaccept vfs_read' > kprobe_events +RESULT1=`cat kprobe_events` + +# Test for kretprobe by "%return" +echo 'p:myprobeaccept vfs_read%return' > kprobe_events +RESULT2=`cat kprobe_events` + +if [ "$RESULT1" != "$RESULT2" ]; then + echo "Error: %return suffix didn't make a return probe." + echo "r-command: $RESULT1" + echo "%return: $RESULT2" + exit_fail +fi + +echo > kprobe_events
tools/testing/selftests/ftrace/test.d/kprobe/uprobe_syntax_errors.tc +6 -0
@@ -17,4 +17,10 @@ check_error 'p /bin/sh:10(10)^a' # BAD_REFCNT_SUFFIX check_error 'p /bin/sh:10 ^@+ab' # BAD_FILE_OFFS check_error 'p /bin/sh:10 ^@symbol' # SYM_ON_UPROBE +# %return suffix error +if grep -q "place (uprobe): .*%return.*" README; then +check_error 'p /bin/sh:10^%hoge' # BAD_ADDR_SUFFIX +check_error 'p /bin/sh:10(10)^%return' # BAD_REFCNT_SUFFIX +fi + exit 0
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 24/26 tracing: Enable creating new instance early boot
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Enable creating new trace_array instance in early boot stage. If the instances directory is not created, postpone it until the tracefs is initialized.
--- kernel/trace/trace.c | 53 +++++++++++++++++++++++++++------- kernel/trace/trace.h | 7 +++++ kernel/trace/trace_functions.c | 22 +++++++++----- 3 files changed, 63 insertions(+), 19 deletions(-)
kernel/trace/trace.c +42 -11
@@ -8636,6 +8636,24 @@ struct trace_array *trace_array_find_get(const char *instance)return tr; } +static int trace_array_create_dir (struct trace_array *tr) +{ +int ret; + + tr->dir =tracefs_create_dir (tr->name, trace_instance_dir); +if (!tr->dir) +return -EINVAL ; + + ret =event_trace_add_tracer (tr->dir, tr); +if (ret) +tracefs_remove (tr->dir); + +init_tracer_tracefs (tr, tr->dir); +__update_tracer_options (tr); + +return ret; +} +static struct trace_array *trace_array_create (const char *name) {struct trace_array *tr;
@@ -8671,30 +8689,27 @@ static struct trace_array *trace_array_create(const char *name)if (allocate_trace_buffers (tr, trace_buf_size) <0 ) goto out_free_tr; - tr->dir =tracefs_create_dir (name, trace_instance_dir); -if (!tr->dir) - goto out_free_tr; - - ret =event_trace_add_tracer (tr->dir, tr); -if (ret) { -tracefs_remove (tr->dir); +if (ftrace_allocate_ftrace_ops (tr) <0 ) goto out_free_tr; - }ftrace_init_trace_array (tr); -init_tracer_tracefs (tr, tr->dir);init_trace_flags_index (tr); -__update_tracer_options (tr); + +if (trace_instance_dir) { + ret =trace_array_create_dir (tr); +if (ret) + goto out_free_tr; + }list_add (&tr->list, &ftrace_trace_arrays); tr->ref++; -return tr; out_free_tr: +ftrace_free_ftrace_ops (tr);free_trace_buffers (tr);free_cpumask_var (tr->tracing_cpumask);kfree (tr->name);
@@ -8852,11 +8867,27 @@ static int instance_rmdir(const char *name)static __init void create_trace_instances (struct dentry *d_tracer) { +struct trace_array *tr; + trace_instance_dir =tracefs_create_instance_dir ("instances" , d_tracer, instance_mkdir, instance_rmdir);if (MEM_FAIL (!trace_instance_dir,"Failed to create instances directory\n" ))return ; + +mutex_lock (&event_mutex); +mutex_lock (&trace_types_lock); + +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (!tr->name) +continue ; +if (MEM_FAIL (trace_array_create_dir (tr) <0 , +"Failed to create instance directory\n" )) +break ; + } + +mutex_unlock (&trace_types_lock); +mutex_unlock (&event_mutex); } static void
kernel/trace/trace.h +7 -0
@@ -1125,6 +1125,8 @@ extern int ftrace_is_dead(void);int ftrace_create_function_files (struct trace_array *tr,struct dentry *parent);void ftrace_destroy_function_files (struct trace_array *tr); +int ftrace_allocate_ftrace_ops (struct trace_array *tr); +void ftrace_free_ftrace_ops (struct trace_array *tr);void ftrace_init_global_array_ops (struct trace_array *tr);void ftrace_init_array_ops (struct trace_array *tr,ftrace_func_t func);void ftrace_reset_array_ops (struct trace_array *tr);
@@ -1146,6 +1148,11 @@ ftrace_create_function_files(struct trace_array *tr, {return 0 ; } +static inline int ftrace_allocate_ftrace_ops (struct trace_array *tr) +{ +return 0 ; +} +static inline void ftrace_free_ftrace_ops (struct trace_array *tr) { }static inline void ftrace_destroy_function_files (struct trace_array *tr) { }static inline __init void ftrace_init_global_array_ops (struct trace_array *tr) { }
kernel/trace/trace_functions.c +14 -8
@@ -34,10 +34,14 @@ enum { TRACE_FUNC_OPT_STACK = 0x1, }; -static int allocate_ftrace_ops (struct trace_array *tr) +int ftrace_allocate_ftrace_ops (struct trace_array *tr) {struct ftrace_ops *ops; +/* The top level array uses the "global_ops" */ +if (tr->flags &TRACE_ARRAY_FL_GLOBAL ) +return 0 ; + ops =kzalloc (sizeof (*ops),GFP_KERNEL );if (!ops)return -ENOMEM ;
@@ -48,15 +52,19 @@ static int allocate_ftrace_ops(struct trace_array *tr) tr->ops = ops; ops->private = tr; +return 0 ; } +void ftrace_free_ftrace_ops (struct trace_array *tr) +{ +kfree (tr->ops); + tr->ops =NULL ; +}int ftrace_create_function_files (struct trace_array *tr,struct dentry *parent) { -int ret; -/* * The top level array uses the "global_ops", and the files are * created on boot up.
@@ -64,9 +72,8 @@ int ftrace_create_function_files(struct trace_array *tr,if (tr->flags &TRACE_ARRAY_FL_GLOBAL )return 0 ; - ret =allocate_ftrace_ops (tr); -if (ret) -return ret; +if (!tr->ops) +return -EINVAL ;ftrace_create_filter_files (tr->ops, parent);
@@ -76,8 +83,7 @@ int ftrace_create_function_files(struct trace_array *tr,void ftrace_destroy_function_files (struct trace_array *tr) {ftrace_destroy_filter_files (tr->ops); -kfree (tr->ops); - tr->ops =NULL ; +ftrace_free_ftrace_ops (tr); }static int function_trace_init (struct trace_array *tr)
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 26/26 Documentation: tracing: Add the startup timing of boot-time tracing
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add the note about when to start the boot-time tracing. This will be needed for the people who wants to trace earlier boot sequence.
--- Documentation/trace/boottime-trace.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/trace/boottime-trace.rst +14 -0
@@ -120,6 +120,20 @@ instance node, but those are also visible from other instances. So please take care for event name conflict. +When to Start +============= + +All boot-time tracing options starting with ``ftrace`` will be enabled at the +end of core_initcall. This means you can trace the events from postcore_initcall. +Most of the subsystems and architecture dependent drivers will be initialized +after that (arch_initcall or subsys_initcall). Thus, you can trace those with +boot-time tracing. +If you want to trace events before core_initcall, you can use the options +starting with ``kernel``. Some of them will be enabled eariler than the initcall +processing (for example,. ``kernel.ftrace=function`` and ``kernel.trace_event`` +will start before the initcall.) + + Examples ========
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 25/26 tracing/boot, kprobe, synth: Initialize boot-time tracing earlier
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Initialize boot-time tracing in core_initcall_sync instead of fs_initcall, and initialize required tracers (kprobes and synth) in core_initcall. This will allow the boot-time tracing to trace __init code from the beginning of postcore_initcall stage.
--- kernel/trace/trace_boot.c | 7 +++++-- kernel/trace/trace_events_synth.c | 19 ++++++++++++++----- kernel/trace/trace_kprobe.c | 6 +++--- 3 files changed, 22 insertions(+), 10 deletions(-)
kernel/trace/trace_boot.c +5 -2
@@ -340,5 +340,8 @@ static int __init trace_boot_init(void)return 0 ; } - -fs_initcall (trace_boot_init); +/* +* Start tracing at the end of core-initcall, so that it starts tracing +* from the beginning of postcore_initcall. +*/ +core_initcall_sync (trace_boot_init);
kernel/trace/trace_events_synth.c +14 -5
@@ -1754,17 +1754,26 @@ static const struct file_operations synth_events_fops = { .release = seq_release, }; -static __init int trace_events_synth_init (void ) +/* +* Register dynevent at core_initcall. This allows kernel to setup kprobe +* events in postcore_initcall without tracefs. +*/ +static __init int trace_events_synth_init_early (void ) { -struct dentry *entry =NULL ;int err =0 ; err =dyn_event_register (&synth_event_ops); -if (err) { +if (err)pr_warn ("Could not register synth_event_ops\n" ); -return err; - } +return err; +} +core_initcall (trace_events_synth_init_early); + +static __init int trace_events_synth_init (void ) +{ +struct dentry *entry =NULL ; +int err =0 ; err =tracing_init_dentry ();if (err) goto err;
kernel/trace/trace_kprobe.c +3 -3
@@ -1897,8 +1897,8 @@ static __init void setup_boot_kprobe_events(void) }/* -* Register dynevent at subsys_initcall. This allows kernel to setup kprobe -* events in fs_initcall without tracefs. +* Register dynevent at core_initcall. This allows kernel to setup kprobe +* events in postcore_initcall without tracefs. */ static __init int init_kprobe_trace_early (void ) {
@@ -1913,7 +1913,7 @@ static __init int init_kprobe_trace_early(void)return 0 ; } -subsys_initcall (init_kprobe_trace_early); +core_initcall (init_kprobe_trace_early);/* Make a tracefs interface for controlling probe points */ static __init int init_kprobe_trace (void )
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 18/26 Documentation: tracing: Add %return suffix description
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add a description of the %return suffix option for kprobe event and uprobe event.
--- Documentation/trace/kprobetrace.rst | 2 ++ Documentation/trace/uprobetracer.rst | 2 ++ 2 files changed, 4 insertions(+)
Documentation/trace/kprobetrace.rst +2 -0
@@ -30,6 +30,7 @@ Synopsis of kprobe_events p[:[GRP/]EVENT] [MOD:]SYM[+offs]|MEMADDR [FETCHARGS] : Set a probe r[MAXACTIVE][:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe + p:[GRP/]EVENT] [MOD:]SYM[+0]%return [FETCHARGS] : Set a return probe -:[GRP/]EVENT : Clear a probe GRP : Group name. If omitted, use "kprobes" for it.
@@ -37,6 +38,7 @@ Synopsis of kprobe_events based on SYM+offs or MEMADDR. MOD : Module name which has given SYM. SYM[+offs] : Symbol+offset where the probe is inserted. + SYM%return : Return address of the symbol MEMADDR : Address where the probe is inserted. MAXACTIVE : Maximum number of instances of the specified function that can be probed simultaneously, or 0 for the default value
Documentation/trace/uprobetracer.rst +2 -0
@@ -28,6 +28,7 @@ Synopsis of uprobe_tracer p[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] : Set a uprobe r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] : Set a return uprobe (uretprobe) + p[:[GRP/]EVENT] PATH:OFFSET%return [FETCHARGS] : Set a return uprobe (uretprobe) -:[GRP/]EVENT : Clear uprobe or uretprobe event GRP : Group name. If omitted, "uprobes" is the default value.
@@ -35,6 +36,7 @@ Synopsis of uprobe_tracer on PATH+OFFSET. PATH : Path to an executable or a library. OFFSET : Offset where the probe is inserted. + OFFSET%return : Offset where the return probe is inserted. FETCHARGS : Arguments. Each probe can have up to 128 args. %REG : Fetch register REG
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 17/26 tracing/uprobes: Support perf-style return probe
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Support perf-style return probe ("SYMBOL%return") for uprobe events as same as kprobe events does.
--- kernel/trace/trace.c | 2 +- kernel/trace/trace_uprobe.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-)
kernel/trace/trace.c +1 -1
@@ -5125,7 +5125,7 @@ static const char readme_msg[] = "place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"#endif #ifdef CONFIG_UPROBE_EVENTS - " place (uprobe): <path>:<offset>[(ref_ctr_offset)]\n" + " place (uprobe): <path>:<offset>[%return][(ref_ctr_offset)]\n"#endif "\t args: <name>=fetcharg[:type]\n" "\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n"
kernel/trace/trace_uprobe.c +14 -1
@@ -528,7 +528,7 @@ static int register_trace_uprobe(struct trace_uprobe *tu)/* * Argument syntax: -* - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] +* - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET[%return][(REF)] [FETCHARGS] */ static int trace_uprobe_create (int argc,const char **argv) {
@@ -617,6 +617,19 @@ static int trace_uprobe_create(int argc, const char **argv) } } +/* Check if there is %return suffix */ + tmp =strchr (arg,'%' ); +if (tmp) { +if (!strcmp (tmp,"%return" )) { + *tmp ='\0' ; + is_return = true; + }else { +trace_probe_log_err (tmp - filename,BAD_ADDR_SUFFIX ); + ret = -EINVAL ; + goto fail_address_parse; + } + } +/* Parse uprobe offset. */ ret =kstrtoul (arg,0 , &offset);if (ret) {
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 19/26 Documentation: tracing: boot: Add an example of tracing function-calls
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add an example of tracing function calls on a specific function.
--- Documentation/trace/boottime-trace.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Documentation/trace/boottime-trace.rst +20 -0
@@ -168,6 +168,26 @@ is for tracing functions starting with "user\_", and others tracing The instance node also accepts event nodes so that each instance can customize its event tracing. +With the trigger action and kprobes, you can trace function-graph while +a function is called. For example, this will trace all function calls in +the pci_proc_init():: + + ftrace { + tracing_on = 0 + tracer = function_graph + event.kprobes { + start_event { + probes = "pci_proc_init" + actions = "traceon" + } + end_event { + probes = "pci_proc_init%return" + actions = "traceoff" + } + } + } + + This boot-time tracing also supports ftrace kernel parameters via boot config. For example, following kernel parameters::
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 2/26 tools/bootconfig: Add list option
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add list option (-l) to show the bootconfig in the list style. This is same output of /proc/bootconfig. So users can check how their bootconfig will be shown in procfs. This will help them to write a user-space script to parse the /proc/bootconfig.
--- tools/bootconfig/main.c | 52 +++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-)
tools/bootconfig/main.c +40 -12
@@ -14,18 +14,19 @@#include <linux/kernel.h> #include <linux/bootconfig.h> -static int xbc_show_value (struct xbc_node *node) +static int xbc_show_value (struct xbc_node *node,bool semicolon) { -const char *val; +const char *val, *eol;char q;int i =0 ; + eol = semicolon ?";\n" :"\n" ;xbc_array_for_each_value (node, val) {if (strchr (val,'"' )) q ='\'' ;else q ='"' ; -printf ("%c%s%c%s" , q, val, q, node->next ?", " :";\n" ); +printf ("%c%s%c%s" , q, val, q, node->next ?", " : eol); i++; }return i;
@@ -53,7 +54,7 @@ static void xbc_show_compact_tree(void)continue ; }else if (cnode &&xbc_node_is_value (cnode)) {printf ("%s = " ,xbc_node_get_data (node)); -xbc_show_value (cnode); +xbc_show_value (cnode, true); }else {printf ("%s;\n" ,xbc_node_get_data (node)); }
@@ -77,6 +78,26 @@ static void xbc_show_compact_tree(void) } } +static void xbc_show_list (void ) +{ +char key[XBC_KEYLEN_MAX ]; +struct xbc_node *leaf; +const char *val; +int ret =0 ; + +xbc_for_each_key_value (leaf, val) { + ret =xbc_node_compose_key (leaf, key,XBC_KEYLEN_MAX ); +if (ret <0 ) +break ; +printf ("%s = " , key); +if (!val || val[0 ] =='\0' ) { +printf ("\"\"\n" ); +continue ; + } +xbc_show_value (xbc_node_get_child (leaf), false); + } +} +/* Simple real checksum */ int checksum (unsigned char *buf,int len) {
@@ -233,7 +254,7 @@ static int init_xbc_with_error(char *buf, int len)return ret; } -int show_xbc (const char *path) +int show_xbc (const char *path,bool list) {int ret, fd;char *buf =NULL ;
@@ -267,7 +288,10 @@ int show_xbc(const char *path)if (init_xbc_with_error (buf, ret) <0 ) goto out; } -xbc_show_compact_tree (); +if (list) +xbc_show_list (); +else +xbc_show_compact_tree (); ret =0 ; out:free (buf);
@@ -390,7 +414,8 @@ int usage(void)" Apply, delete or show boot config to initrd.\n" " Options:\n" " -a <config>: Apply boot config to initrd\n" -" -d : Delete boot config file from initrd\n\n" +" -d : Delete boot config file from initrd\n" +" -l : list boot config in initrd or file\n\n" " If no option is given, show the bootconfig in the given file.\n");return -1 ; }
@@ -399,10 +424,10 @@ int main(int argc, char **argv) {char *path =NULL ;char *apply =NULL ; -bool delete = false; +bool delete = false, list = false;int opt; -while ((opt =getopt (argc, argv,"hda:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"hda:l" )) !=-1 ) {switch (opt) {case 'd' : delete = true;
@@ -410,14 +435,17 @@ int main(int argc, char **argv)case 'a' : apply = optarg;break ; +case 'l' : + list = true; +break ;case 'h' :default :return usage (); } } -if (apply && delete) { -pr_err ("Error: You can not specify both -a and -d at once.\n" ); +if ((apply && delete) || (delete && list) || (apply && list)) { +pr_err ("Error: You can give one of -a, -d or -l at once.\n" );return usage (); }
@@ -433,5 +461,5 @@ int main(int argc, char **argv)else if (delete)return delete_xbc (path); -return show_xbc (path); +return show_xbc (path, list); }
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 16/26 tracing/kprobes: Support perf-style return probe
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Support perf-style return probe ("SYMBOL%return") for kprobe events. This will allow boot-time tracing user to define a return probe event.
--- kernel/trace/trace.c | 2 +- kernel/trace/trace_kprobe.c | 18 +++++++++++++++++- kernel/trace/trace_probe.h | 1 + 3 files changed, 19 insertions(+), 2 deletions(-)
kernel/trace/trace.c +1 -1
@@ -5122,7 +5122,7 @@ static const char readme_msg[] = "\t -:[<group>/]<event>\n" #ifdef CONFIG_KPROBE_EVENTS "\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n" - "place (kretprobe): [<module>:]<symbol>[+<offset>]|<memaddr>\n" + "place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n" #endif#ifdef CONFIG_UPROBE_EVENTS " place (uprobe): <path>:<offset>[(ref_ctr_offset)]\n"
kernel/trace/trace_kprobe.c +17 -1
@@ -718,6 +718,9 @@ static int trace_kprobe_create(int argc, const char *argv[])* p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS] * - Add kretprobe: * r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS] +* Or +* p:[GRP/]EVENT] [MOD:]KSYM[+0]%return [FETCHARGS] +* * Fetch args: * $retval : fetch return value * $stack : fetch stack address
@@ -747,7 +750,6 @@ static int trace_kprobe_create(int argc, const char *argv[])switch (argv[0 ][0 ]) {case 'r' : is_return = true; - flags |=TPARG_FL_RETURN ;break ;case 'p' :break ;
@@ -805,12 +807,26 @@ static int trace_kprobe_create(int argc, const char *argv[]) symbol =kstrdup (argv[1 ],GFP_KERNEL );if (!symbol)return -ENOMEM ; + + tmp =strchr (symbol,'%' ); +if (tmp) { +if (!strcmp (tmp,"%return" )) { + *tmp ='\0' ; + is_return = true; + }else { +trace_probe_log_err (tmp - symbol,BAD_ADDR_SUFFIX ); + goto parse_error; + } + } +/* TODO: support .init module functions */ ret =traceprobe_split_symbol_offset (symbol, &offset);if (ret || offset <0 || offset >UINT_MAX ) {trace_probe_log_err (0 ,BAD_PROBE_ADDR ); goto parse_error; } +if (is_return) + flags |=TPARG_FL_RETURN ;if (kprobe_on_func_entry (NULL , symbol, offset)) flags |=TPARG_FL_FENTRY ;if (offset && is_return && !(flags &TPARG_FL_FENTRY )) {
kernel/trace/trace_probe.h +1 -0
@@ -404,6 +404,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,C (MAXACT_TOO_BIG ,"Maxactive is too big" ), \C (BAD_PROBE_ADDR ,"Invalid probed address or symbol" ), \C (BAD_RETPROBE ,"Retprobe address must be an function entry" ), \ +C (BAD_ADDR_SUFFIX ,"Invalid probed address suffix" ), \C (NO_GROUP_NAME ,"Group name is not specified" ), \C (GROUP_TOO_LONG ,"Group name is too long" ), \ C(BAD_GROUP_NAME, "Group name must follow the same rules as C identifiers"), \
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 8/26 tracing: make tracing_init_dentry() returns an integer instead of a d_entry pointer
In reply to Steven RostedtFrom: Wei Yang <[email protected]>
Current tracing_init_dentry() return a d_entry pointer, while is not necessary. This function returns NULL on success or error on failure, which means there is no valid d_entry pointer return.
Let's return 0 on success and negative value for error.
--- kernel/trace/trace.c | 36 ++++++++++++++-------------- kernel/trace/trace.h | 2 +- kernel/trace/trace_dynevent.c | 8 +++---- kernel/trace/trace_events_synth.c | 9 +++---- kernel/trace/trace_functions_graph.c | 8 +++---- kernel/trace/trace_hwlat.c | 8 +++---- kernel/trace/trace_kprobe.c | 10 ++++---- kernel/trace/trace_printk.c | 8 +++---- kernel/trace/trace_stack.c | 12 +++++----- kernel/trace/trace_stat.c | 8 +++---- kernel/trace/trace_uprobe.c | 9 ++++--- 11 files changed, 57 insertions(+), 61 deletions(-)
kernel/trace/trace.c +18 -18
@@ -8971,21 +8971,21 @@ static struct vfsmount *trace_automount(struct dentry *mntpt, void *ingore)* directory. It is called via fs_initcall() by any of the boot up code * and expects to return the dentry of the top level tracing directory. */ -struct dentry *tracing_init_dentry (void ) +int tracing_init_dentry (void ) {struct trace_array *tr = &global_trace;if (security_locked_down (LOCKDOWN_TRACEFS )) {pr_warn ("Tracing disabled due to lockdown\n" ); -return ERR_PTR (-EPERM ); +return -EPERM ; }/* The top level trace array uses NULL as parent */ if (tr->dir) -return NULL ; +return 0 ;if (WARN_ON (!tracefs_initialized ())) -return ERR_PTR (-ENODEV ); +return -ENODEV ;/* * As there may still be users that expect the tracing
@@ -8996,7 +8996,7 @@ struct dentry *tracing_init_dentry(void) tr->dir =debugfs_create_automount ("tracing" ,NULL , trace_automount,NULL ); -return NULL ; +return 0 ; }extern struct trace_eval_map *__start_ftrace_eval_maps[];
@@ -9083,48 +9083,48 @@ static struct notifier_block trace_module_nb = {static __init int tracer_init_tracefs (void ) { -struct dentry *d_tracer; +int ret;trace_access_lock_init (); - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ;event_trace_init (); -init_tracer_tracefs (&global_trace, d_tracer); -ftrace_init_tracefs_toplevel (&global_trace, d_tracer); +init_tracer_tracefs (&global_trace,NULL ); +ftrace_init_tracefs_toplevel (&global_trace,NULL ); -trace_create_file ("tracing_thresh" ,0644 , d_tracer, +trace_create_file ("tracing_thresh" ,0644 ,NULL , &global_trace, &tracing_thresh_fops); -trace_create_file ("README" ,0444 , d_tracer, +trace_create_file ("README" ,0444 ,NULL ,NULL , &tracing_readme_fops); -trace_create_file ("saved_cmdlines" ,0444 , d_tracer, +trace_create_file ("saved_cmdlines" ,0444 ,NULL ,NULL , &tracing_saved_cmdlines_fops); -trace_create_file ("saved_cmdlines_size" ,0644 , d_tracer, +trace_create_file ("saved_cmdlines_size" ,0644 ,NULL ,NULL , &tracing_saved_cmdlines_size_fops); -trace_create_file ("saved_tgids" ,0444 , d_tracer, +trace_create_file ("saved_tgids" ,0444 ,NULL ,NULL , &tracing_saved_tgids_fops);trace_eval_init (); -trace_create_eval_file (d_tracer); +trace_create_eval_file (NULL );#ifdef CONFIG_MODULES register_module_notifier (&trace_module_nb);#endif #ifdef CONFIG_DYNAMIC_FTRACE -trace_create_file ("dyn_ftrace_total_info" ,0444 , d_tracer, +trace_create_file ("dyn_ftrace_total_info" ,0444 ,NULL ,NULL , &tracing_dyn_info_fops);#endif -create_trace_instances (d_tracer); +create_trace_instances (NULL );update_tracer_options (&global_trace);
kernel/trace/trace.h +1 -1
@@ -737,7 +737,7 @@ struct dentry *trace_create_file(const char *name,void *data, const struct file_operations *fops); -struct dentry *tracing_init_dentry (void ); +int tracing_init_dentry (void );struct ring_buffer_event ;
kernel/trace/trace_dynevent.c +4 -4
@@ -206,14 +206,14 @@ static const struct file_operations dynamic_events_ops = {/* Make a tracefs interface for controlling dynamic events */ static __init int init_dynamic_event (void ) { -struct dentry *d_tracer;struct dentry *entry; +int ret; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ; - entry =tracefs_create_file ("dynamic_events" ,0644 , d_tracer, + entry =tracefs_create_file ("dynamic_events" ,0644 ,NULL ,NULL , &dynamic_events_ops);/* Event list interface */
kernel/trace/trace_events_synth.c +3 -6
@@ -1757,7 +1757,6 @@ static const struct file_operations synth_events_fops = {static __init int trace_events_synth_init (void ) {struct dentry *entry =NULL ; -struct dentry *d_tracer;int err =0 ; err =dyn_event_register (&synth_event_ops);
@@ -1766,13 +1765,11 @@ static __init int trace_events_synth_init(void)return err; } - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) { - err =PTR_ERR (d_tracer); + err =tracing_init_dentry (); +if (err) goto err; - } - entry =tracefs_create_file ("synthetic_events" ,0644 , d_tracer, + entry =tracefs_create_file ("synthetic_events" ,0644 ,NULL ,NULL , &synth_events_fops);if (!entry) { err = -ENODEV ;
kernel/trace/trace_functions_graph.c +4 -4
@@ -1336,13 +1336,13 @@ static const struct file_operations graph_depth_fops = {static __init int init_graph_tracefs (void ) { -struct dentry *d_tracer; +int ret; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ; -trace_create_file ("max_graph_depth" ,0644 , d_tracer, +trace_create_file ("max_graph_depth" ,0644 ,NULL ,NULL , &graph_depth_fops);return 0 ;
kernel/trace/trace_hwlat.c +4 -4
@@ -538,14 +538,14 @@ static const struct file_operations window_fops = {*/ static int init_tracefs (void ) { -struct dentry *d_tracer; +int ret;struct dentry *top_dir; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return -ENOMEM ; - top_dir =tracefs_create_dir ("hwlat_detector" , d_tracer); + top_dir =tracefs_create_dir ("hwlat_detector" ,NULL );if (!top_dir)return -ENOMEM ;
kernel/trace/trace_kprobe.c +5 -5
@@ -1901,14 +1901,14 @@ subsys_initcall(init_kprobe_trace_early);/* Make a tracefs interface for controlling probe points */ static __init int init_kprobe_trace (void ) { -struct dentry *d_tracer; +int ret;struct dentry *entry; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ; - entry =tracefs_create_file ("kprobe_events" ,0644 , d_tracer, + entry =tracefs_create_file ("kprobe_events" ,0644 ,NULL ,NULL , &kprobe_events_ops);/* Event list interface */
@@ -1916,7 +1916,7 @@ static __init int init_kprobe_trace(void)pr_warn ("Could not create tracefs 'kprobe_events' entry\n" );/* Profile interface */ - entry =tracefs_create_file ("kprobe_profile" ,0444 , d_tracer, + entry =tracefs_create_file ("kprobe_profile" ,0444 ,NULL ,NULL , &kprobe_profile_ops);if (!entry)
kernel/trace/trace_printk.c +4 -4
@@ -367,13 +367,13 @@ static const struct file_operations ftrace_formats_fops = {static __init int init_trace_printk_function_export (void ) { -struct dentry *d_tracer; +int ret; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ; -trace_create_file ("printk_formats" ,0444 , d_tracer, +trace_create_file ("printk_formats" ,0444 ,NULL ,NULL , &ftrace_formats_fops);return 0 ;
kernel/trace/trace_stack.c +6 -6
@@ -554,20 +554,20 @@ __setup("stacktrace", enable_stacktrace);static __init int stack_trace_init (void ) { -struct dentry *d_tracer; +int ret; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ; -trace_create_file ("stack_max_size" ,0644 , d_tracer, +trace_create_file ("stack_max_size" ,0644 ,NULL , &stack_trace_max_size, &stack_max_size_fops); -trace_create_file ("stack_trace" ,0444 , d_tracer, +trace_create_file ("stack_trace" ,0444 ,NULL ,NULL , &stack_trace_fops);#ifdef CONFIG_DYNAMIC_FTRACE -trace_create_file ("stack_trace_filter" ,0644 , d_tracer, +trace_create_file ("stack_trace_filter" ,0644 ,NULL , &trace_ops, &stack_trace_filter_fops);#endif
kernel/trace/trace_stat.c +4 -4
@@ -276,13 +276,13 @@ static const struct file_operations tracing_stat_fops = {static int tracing_stat_init (void ) { -struct dentry *d_tracing; +int ret; - d_tracing =tracing_init_dentry (); -if (IS_ERR (d_tracing)) + ret =tracing_init_dentry (); +if (ret)return -ENODEV ; - stat_dir =tracefs_create_dir ("trace_stat" , d_tracing); + stat_dir =tracefs_create_dir ("trace_stat" ,NULL );if (!stat_dir) {pr_warn ("Could not create tracefs 'trace_stat' entry\n" );return -ENOMEM ;
kernel/trace/trace_uprobe.c +4 -5
@@ -1625,21 +1625,20 @@ void destroy_local_trace_uprobe(struct trace_event_call *event_call)/* Make a trace interface for controling probe points */ static __init int init_uprobe_trace (void ) { -struct dentry *d_tracer;int ret; ret =dyn_event_register (&trace_uprobe_ops);if (ret)return ret; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) + ret =tracing_init_dentry (); +if (ret)return 0 ; -trace_create_file ("uprobe_events" ,0644 , d_tracer, +trace_create_file ("uprobe_events" ,0644 ,NULL ,NULL , &uprobe_events_ops);/* Profile interface */ -trace_create_file ("uprobe_profile" ,0444 , d_tracer, +trace_create_file ("uprobe_profile" ,0444 ,NULL ,NULL , &uprobe_profile_ops);return 0 ; }
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 1/26 tools/bootconfig: Show bootconfig compact tree from bootconfig file
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Show the bootconfig compact tree from the bootconfig file instead of an initrd if the given file has no magic number and is smaller than 32KB.
User can use this for checking the syntax error or output checking before applying the bootconfig to initrd.
--- tools/bootconfig/main.c | 81 +++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 23 deletions(-)
tools/bootconfig/main.c +58 -23
@@ -195,10 +195,55 @@ int load_xbc_from_initrd(int fd, char **buf)return size; } +static void show_xbc_error (const char *data,const char *msg,int pos) +{ +int lin =1 , col, i; + +if (pos <0 ) { +pr_err ("Error: %s.\n" , msg); +return ; + } + +/* Note that pos starts from 0 but lin and col should start from 1. */ + col = pos +1 ; +for (i =0 ; i < pos; i++) { +if (data[i] =='\n' ) { + lin++; + col = pos - i; + } + } +pr_err ("Parse Error: %s at %d:%d\n" , msg, lin, col); + +} + +static int init_xbc_with_error (char *buf,int len) +{ +char *copy =strdup (buf); +const char *msg; +int ret, pos; + +if (!copy) +return -ENOMEM ; + + ret =xbc_init (buf, &msg, &pos); +if (ret <0 ) +show_xbc_error (copy, msg, pos); +free (copy); + +return ret; +} +int show_xbc (const char *path) {int ret, fd;char *buf =NULL ; +struct stat st; + + ret =stat (path, &st); +if (ret <0 ) { +pr_err ("Failed to stat %s: %d\n" , path, -errno); +return -errno; + } fd =open (path,O_RDONLY );if (fd <0 ) {
@@ -207,14 +252,24 @@ int show_xbc(const char *path) } ret =load_xbc_from_initrd (fd, &buf); +close (fd);if (ret <0 ) {pr_err ("Failed to load a boot config from initrd: %d\n" , ret); goto out; } +/* Assume a bootconfig file if it is enough small */ +if (ret ==0 && st.st_size <=XBC_DATA_MAX ) { + ret =load_xbc_file (path, &buf); +if (ret <0 ) { +pr_err ("Failed to load a boot config: %d\n" , ret); + goto out; + } +if (init_xbc_with_error (buf, ret) <0 ) + goto out; + }xbc_show_compact_tree (); ret =0 ; out: -close (fd);free (buf);return ret;
@@ -251,27 +306,6 @@ int delete_xbc(const char *path)return ret; } -static void show_xbc_error (const char *data,const char *msg,int pos) -{ -int lin =1 , col, i; - -if (pos <0 ) { -pr_err ("Error: %s.\n" , msg); -return ; - } - -/* Note that pos starts from 0 but lin and col should start from 1. */ - col = pos +1 ; -for (i =0 ; i < pos; i++) { -if (data[i] =='\n' ) { - lin++; - col = pos - i; - } - } -pr_err ("Parse Error: %s at %d:%d\n" , msg, lin, col); - -} -int apply_xbc (const char *path,const char *xbc_path) {u32 size, csum;
@@ -352,11 +386,12 @@ int apply_xbc(const char *path, const char *xbc_path)int usage (void ) {printf ("Usage: bootconfig [OPTIONS] <INITRD>\n" +"Or bootconfig <CONFIG>\n" " Apply, delete or show boot config to initrd.\n" " Options:\n" " -a <config>: Apply boot config to initrd\n" " -d : Delete boot config file from initrd\n\n" -" If no option is given, show current applied boot config.\n" ); +" If no option is given, show the bootconfig in the given file.\n" );return -1 ; }
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 13/26 fgraph: Convert ret_stack tasklist scanning to rcu
In reply to Steven RostedtFrom: Davidlohr Bueso <[email protected]>
It seems that alloc_retstack_tasklist() can also take a lockless approach for scanning the tasklist, instead of using the big global tasklist_lock. For this we also kill another deprecated and rcu-unsafe tsk->thread_group user replacing it with for_each_process_thread(), maintaining semantics.
Here tasklist_lock does not protect anything other than the list against concurrent fork/exit. And considering that the whole thing is capped by FTRACE_RETSTACK_ALLOC_SIZE (32), it should not be a problem to have a pontentially stale, yet stable, list. The task cannot go away either, so we don't risk racing with ftrace_graph_exit_task() which clears the retstack.
The tsk->ret_stack management is not protected by tasklist_lock, being serialized with the corresponding publish/subscribe barriers against concurrent ftrace_push_return_trace(). In addition this plays nicer with cachelines by avoiding two atomic ops in the uncontended case.
--- kernel/trace/fgraph.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/trace/fgraph.c +4 -4
@@ -387,8 +387,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) } } -read_lock (&tasklist_lock); - do_each_thread(g, t) { +rcu_read_lock (); +for_each_process_thread (g, t) {if (start == end) { ret = -EAGAIN ; goto unlock;
@@ -403,10 +403,10 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)smp_wmb (); t->ret_stack = ret_stack_list[start++]; } - }while_each_thread (g, t); + } unlock: -read_unlock (&tasklist_lock); +rcu_read_unlock (); free:for (i = start; i < end; i++)kfree (ret_stack_list[i]);
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 15/26 Documentation: tracing: Add tracing_on option to boot-time tracer
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add tracing_on option description to the boot-time tracer.
--- Documentation/trace/boottime-trace.rst | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/trace/boottime-trace.rst +4 -0
@@ -61,6 +61,10 @@ These options can be used for each instance including global ftrace node. ftrace.[instance.INSTANCE.]options = OPT1[, OPT2[...]] Enable given ftrace options. +ftrace.[instance.INSTANCE.]tracing_on = 0|1 + Enable/Disable tracing on this instance when starting boot-time tracing. + (you can enable it by the "traceon" event trigger action) + ftrace.[instance.INSTANCE.]trace_clock = CLOCK Set given CLOCK to ftrace's trace_clock.
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 14/26 tracing/boot: Add per-instance tracing_on option support
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add per-instance tracing_on option, which will be useful with traceon/traceoff event trigger actions. For example, if we disable tracing_on by default and set traceon and traceoff on a pair of events, we can trace functions between the pair of events.
--- kernel/trace/trace_boot.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
kernel/trace/trace_boot.c +10 -0
@@ -40,6 +40,16 @@ trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node)pr_err ("Failed to set option: %s\n" , buf); } + p =xbc_node_find_value (node,"tracing_on" ,NULL ); +if (p && *p !='\0' ) { +if (kstrtoul (p,10 , &v)) +pr_err ("Failed to set tracing on: %s\n" , p); +if (v) +tracer_tracing_on (tr); +else +tracer_tracing_off (tr); + } + p =xbc_node_find_value (node,"trace_clock" ,NULL );if (p && *p !='\0' ) {if (tracing_set_clock (tr, p) <0 )
Signature · 1 line
2.28.0
Steven Rostedt
maintainercover tracing: Updates for 5.10
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: fd264ce96c382bc2e36eb1f49ac45c5980650244
Dan Carpenter (1):
tracing: remove a pointless assignment
Davidlohr Bueso (1):
fgraph: Convert ret_stack tasklist scanning to rcu
Jarkko Sakkinen (1):
kprobes: Use module_name() macro
Masami Hiramatsu (19):
tools/bootconfig: Show bootconfig compact tree from bootconfig file tools/bootconfig: Add list option
tools/bootconfig: Make all functions static
tools/bootconfig: Add a script to generate ftrace shell-command from bootconfig tools/bootconfig: Add a script to generates bootconfig from ftrace tools/bootconfig: Add --init option for bconf2ftrace.sh tracing/boot: Add per-instance tracing_on option support
Documentation: tracing: Add tracing_on option to boot-time tracer tracing/kprobes: Support perf-style return probe
tracing/uprobes: Support perf-style return probe
Documentation: tracing: Add %return suffix description
Documentation: tracing: boot: Add an example of tracing function-calls selftests/ftrace: Add %return suffix tests
kprobes: Init kprobes in early_initcall
tracing: Define event fields early stage
tracing: Enable adding dynamic events early stage
tracing: Enable creating new instance early boot
tracing/boot, kprobe, synth: Initialize boot-time tracing earlier
Documentation: tracing: Add the startup timing of boot-time tracing
Randy Dunlap (1):
tracing: Delete repeated words in comments
Wei Yang (2):
tracing: toplevel d_entry already initialized
tracing: make tracing_init_dentry() returns an integer instead of a d_entry pointer
Xianting Tian (1):
tracing: Use __this_cpu_read() in trace_buffered_event_enable()
----
Documentation/trace/boottime-trace.rst | 38 ++++ Documentation/trace/kprobetrace.rst | 2 + Documentation/trace/uprobetracer.rst | 2 + MAINTAINERS | 1 + kernel/kprobes.c | 2 +- kernel/trace/fgraph.c | 8 +- kernel/trace/ftrace.c | 2 +- kernel/trace/trace.c | 98 ++++++--- kernel/trace/trace.h | 9 +- kernel/trace/trace_boot.c | 17 +- kernel/trace/trace_dynevent.c | 10 +- kernel/trace/trace_events.c | 110 ++++++---- kernel/trace/trace_events_synth.c | 30 ++- kernel/trace/trace_functions.c | 22 +- kernel/trace/trace_functions_graph.c | 8 +- kernel/trace/trace_hwlat.c | 8 +- kernel/trace/trace_kprobe.c | 41 +++- kernel/trace/trace_printk.c | 8 +- kernel/trace/trace_probe.h | 1 + kernel/trace/trace_stack.c | 12 +- kernel/trace/trace_stat.c | 8 +- kernel/trace/trace_uprobe.c | 24 +- kernel/trace/tracing_map.c | 2 +- tools/bootconfig/main.c | 147 +++++++++---- tools/bootconfig/scripts/bconf2ftrace.sh | 199 +++++++++++++++++ tools/bootconfig/scripts/ftrace.sh | 109 +++++++++ tools/bootconfig/scripts/ftrace2bconf.sh | 244 +++++++++++++++++++++ tools/bootconfig/scripts/xbc.sh | 56 +++++ .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 6 + .../test.d/kprobe/kretprobe_return_suffix.tc | 21 ++ .../ftrace/test.d/kprobe/uprobe_syntax_errors.tc | 6 + 31 files changed, 1055 insertions(+), 196 deletions(-) create mode 100755 tools/bootconfig/scripts/bconf2ftrace.sh create mode 100644 tools/bootconfig/scripts/ftrace.sh create mode 100755 tools/bootconfig/scripts/ftrace2bconf.sh create mode 100644 tools/bootconfig/scripts/xbc.sh create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kretprobe_return_suffix.tc
Steven Rostedt
maintainerPATCH 12/26 tracing: remove a pointless assignment
From: Dan Carpenter <[email protected]>
The "tr" is a stack variable so setting it to NULL before a return is a no-op. Delete the assignment.
--- kernel/trace/trace.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace.c +0 -1
@@ -8799,7 +8799,6 @@ static int __remove_instance(struct trace_array *tr)free_cpumask_var (tr->tracing_cpumask);kfree (tr->name);kfree (tr); - tr =NULL ;return 0 ; }
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 5/26 tools/bootconfig: Add a script to generates bootconfig from ftrace
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add a ftrace2bconf.sh under tools/bootconfig/scripts which generates a bootconfig file from the current ftrace settings.
To read the ftrace settings, ftrace2bconf.sh requires the root privilege (or sudo). The ftrace2bconf.sh will output the bootconfig to stdout and error messages to stderr, so usually you'll run it as
# ftrace2bconf.sh > ftrace.bconf
Note that some ftrace configurations are not supported. For example, function-call/callgraph trace/notrace settings are not supported because the wildcard has been expanded and lost in the ftrace anymore.
--- tools/bootconfig/scripts/ftrace2bconf.sh | 244 +++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100755 tools/bootconfig/scripts/ftrace2bconf.sh
tools/bootconfig/scripts/ftrace2bconf.sh new file +244 -0
@@ -0,0 +1,244 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only + +usage() { + echo "Dump boot-time tracing bootconfig from ftrace" + echo "Usage: $0 [--debug] [ > BOOTCONFIG-FILE]" + exit 1 +} + +DEBUG= +while [ x"$1" != x ]; do + case "$1" in + "--debug") + DEBUG=$1;; + -*) + usage + ;; + esac + shift 1 +done + +if [ x"$DEBUG" != x ]; then + set -x +fi + +TRACEFS=`grep -m 1 -w tracefs /proc/mounts | cut -f 2 -d " "` +if [ -z "$TRACEFS" ]; then + if ! grep -wq debugfs /proc/mounts; then + echo "Error: No tracefs/debugfs was mounted." + exit 1 + fi + TRACEFS=`grep -m 1 -w debugfs /proc/mounts | cut -f 2 -d " "`/tracing + if [ ! -d $TRACEFS ]; then + echo "Error: ftrace is not enabled on this kernel." 1>&2 + exit 1 + fi +fi + +######## main ######### + +set -e + +emit_kv() { # key =|+= value + echo "$@" +} + +global_options() { + val=`cat $TRACEFS/max_graph_depth` + [ $val != 0 ] && emit_kv kernel.fgraph_max_depth = $val + if grep -qv "^#" $TRACEFS/set_graph_function $TRACEFS/set_graph_notrace ; then + cat 1>&2 << EOF +# WARN: kernel.fgraph_filters and kernel.fgraph_notrace are not supported, since the wild card expression was expanded and lost from memory. +EOF + fi +} + +kprobe_event_options() { + cat $TRACEFS/kprobe_events | while read p args; do + case $p in + r*) + cat 1>&2 << EOF +# WARN: A return probe found but it is not supported by bootconfig. Skip it. +EOF + continue;; + esac + p=${p#*:} + event=${p#*/} + group=${p%/*} + if [ $group != "kprobes" ]; then + cat 1>&2 << EOF +# WARN: kprobes group name $group is changed to "kprobes" for bootconfig. +EOF + fi + emit_kv $PREFIX.event.kprobes.$event.probes += $args + done +} + +synth_event_options() { + cat $TRACEFS/synthetic_events | while read event fields; do + emit_kv $PREFIX.event.synthetic.$event.fields = `echo $fields | sed "s/;/,/g"` + done +} + +# Variables resolver +DEFINED_VARS= +UNRESOLVED_EVENTS= + +defined_vars() { # event-dir + grep "^hist" $1/trigger | grep -o ':[a-zA-Z0-9]*=' +} +referred_vars() { + grep "^hist" $1/trigger | grep -o '$[a-zA-Z0-9]*' +} + +per_event_options() { # event-dir + evdir=$1 + # Check the special event which has no filter and no trigger + [ ! -f $evdir/filter ] && return + + if grep -q "^hist:" $evdir/trigger; then + # hist action can refer the undefined variables + __vars=`defined_vars $evdir` + for v in `referred_vars $evdir`; do + if echo $DEFINED_VARS $__vars | grep -vqw ${v#$}; then + # $v is not defined yet, defer it + UNRESOLVED_EVENTS="$UNRESOLVED_EVENTS $evdir" + return; + fi + done + DEFINED_VARS="$DEFINED_VARS "`defined_vars $evdir` + fi + grep -v "^#" $evdir/trigger | while read action active; do + emit_kv $PREFIX.event.$group.$event.actions += \'$action\' + done + + # enable is not checked; this is done by set_event in the instance. + val=`cat $evdir/filter` + if [ "$val" != "none" ]; then + emit_kv $PREFIX.event.$group.$event.filter = "$val" + fi +} + +retry_unresolved() { + unresolved=$UNRESOLVED_EVENTS + UNRESOLVED_EVENTS= + for evdir in $unresolved; do + event=${evdir##*/} + group=${evdir%/*}; group=${group##*/} + per_event_options $evdir + done +} + +event_options() { + # PREFIX and INSTANCE must be set + if [ $PREFIX = "ftrace" ]; then + # define the dynamic events + kprobe_event_options + synth_event_options + fi + for group in `ls $INSTANCE/events/` ; do + [ ! -d $INSTANCE/events/$group ] && continue + for event in `ls $INSTANCE/events/$group/` ;do + [ ! -d $INSTANCE/events/$group/$event ] && continue + per_event_options $INSTANCE/events/$group/$event + done + done + retry=0 + while [ $retry -lt 3 ]; do + retry_unresolved + retry=$((retry + 1)) + done + if [ "$UNRESOLVED_EVENTS" ]; then + cat 1>&2 << EOF +! ERROR: hist triggers in $UNRESOLVED_EVENTS use some undefined variables. +EOF + fi +} + +is_default_trace_option() { # option +grep -qw $1 << EOF +print-parent +nosym-offset +nosym-addr +noverbose +noraw +nohex +nobin +noblock +trace_printk +annotate +nouserstacktrace +nosym-userobj +noprintk-msg-only +context-info +nolatency-format +record-cmd +norecord-tgid +overwrite +nodisable_on_free +irq-info +markers +noevent-fork +nopause-on-trace +function-trace +nofunction-fork +nodisplay-graph +nostacktrace +notest_nop_accept +notest_nop_refuse +EOF +} + +instance_options() { # [instance-name] + if [ $# -eq 0 ]; then + PREFIX="ftrace" + INSTANCE=$TRACEFS + else + PREFIX="ftrace.instance.$1" + INSTANCE=$TRACEFS/instances/$1 + fi + val= + for i in `cat $INSTANCE/trace_options`; do + is_default_trace_option $i && continue + val="$val, $i" + done + [ "$val" ] && emit_kv $PREFIX.options = "${val#,}" + val="local" + for i in `cat $INSTANCE/trace_clock` ; do + [ "${i#*]}" ] && continue + i=${i%]}; val=${i#[} + done + [ $val != "local" ] && emit_kv $PREFIX.trace_clock = $val + val=`cat $INSTANCE/buffer_size_kb` + if echo $val | grep -vq "expanded" ; then + emit_kv $PREFIX.buffer_size = $val"KB" + fi + if grep -q "is allocated" $INSTANCE/snapshot ; then + emit_kv $PREFIX.alloc_snapshot + fi + val=`cat $INSTANCE/tracing_cpumask` + if [ `echo $val | sed -e s/f//g`x != x ]; then + emit_kv $PREFIX.cpumask = $val + fi + + val= + for i in `cat $INSTANCE/set_event`; do + val="$val, $i" + done + [ "$val" ] && emit_kv $PREFIX.events = "${val#,}" + val=`cat $INSTANCE/current_tracer` + [ $val != nop ] && emit_kv $PREFIX.tracer = $val + if grep -qv "^#" $INSTANCE/set_ftrace_filter $INSTANCE/set_ftrace_notrace; then + cat 1>&2 << EOF +# WARN: kernel.ftrace.filters and kernel.ftrace.notrace are not supported, since the wild card expression was expanded and lost from memory. +EOF + fi + event_options +} + +global_options +instance_options +for i in `ls $TRACEFS/instances` ; do + instance_options $i +done
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 6/26 tools/bootconfig: Add --init option for bconf2ftrace.sh
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Since the ftrace current setting may conflict with the new setting from bootconfig, add the --init option to initialize ftrace before setting for bconf2ftrace.sh.
E.g.
$ bconf2ftrace.sh --init boottrace.bconf
This initialization method copied from selftests/ftrace.
--- tools/bootconfig/scripts/bconf2ftrace.sh | 12 ++- tools/bootconfig/scripts/ftrace.sh | 109 +++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 tools/bootconfig/scripts/ftrace.sh
tools/bootconfig/scripts/bconf2ftrace.sh +11 -1
@@ -3,8 +3,9 @@ usage() { echo "Ftrace boottime trace test tool" - echo "Usage: $0 [--apply] [--debug] BOOTCONFIG-FILE" + echo "Usage: $0 [--apply|--init] [--debug] BOOTCONFIG-FILE" echo " --apply: Test actual apply to tracefs (need sudo)" + echo " --init: Initialize ftrace before applying (imply --apply)" exit 1 }
@@ -13,12 +14,16 @@ usage() { BCONF= DEBUG= APPLY= +INIT= while [ x"$1" != x ]; do case "$1" in "--debug") DEBUG=$1;; "--apply") APPLY=$1;; + "--init") + APPLY=$1 + INIT=$1;; *) [ ! -f $1 ] && usage BCONF=$1;;
@@ -57,6 +62,11 @@ if [ -z "$TRACEFS" ]; then fi fi +if [ x"$INIT" != x ]; then + . `dirname $0`/ftrace.sh + (cd $TRACEFS; initialize_ftrace) +fi + . `dirname $0`/xbc.sh ######## main #########
tools/bootconfig/scripts/ftrace.sh new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 10/26 tracing: Use __this_cpu_read() in trace_buffered_event_enable()
In reply to Steven RostedtFrom: Xianting Tian <[email protected]>
The code is executed with preemption disabled, so it's safe to use __this_cpu_read().
--- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
@@ -2511,7 +2511,7 @@ void trace_buffered_event_enable(void)preempt_disable ();if (cpu ==smp_processor_id () && -this_cpu_read (trace_buffered_event) != +__this_cpu_read (trace_buffered_event) !=per_cpu (trace_buffered_event, cpu))WARN_ON_ONCE (1 );preempt_enable ();
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 3/26 tools/bootconfig: Make all functions static
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Make all functions static except for main(). This is just a cleanup.
--- tools/bootconfig/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
tools/bootconfig/main.c +8 -8
@@ -99,7 +99,7 @@ static void xbc_show_list(void) }/* Simple real checksum */ -int checksum (unsigned char *buf,int len) +static int checksum (unsigned char *buf,int len) {int i, sum =0 ;
@@ -111,7 +111,7 @@ int checksum(unsigned char *buf, int len)#define PAGE_SIZE 4096 -int load_xbc_fd (int fd,char **buf,int size) +static int load_xbc_fd (int fd,char **buf,int size) {int ret;
@@ -128,7 +128,7 @@ int load_xbc_fd(int fd, char **buf, int size) }/* Return the read size or -errno */ -int load_xbc_file (const char *path,char **buf) +static int load_xbc_file (const char *path,char **buf) {struct stat stat;int fd, ret;
@@ -147,7 +147,7 @@ int load_xbc_file(const char *path, char **buf)return ret; } -int load_xbc_from_initrd (int fd,char **buf) +static int load_xbc_from_initrd (int fd,char **buf) {struct stat stat;int ret;
@@ -254,7 +254,7 @@ static int init_xbc_with_error(char *buf, int len)return ret; } -int show_xbc (const char *path,bool list) +static int show_xbc (const char *path,bool list) {int ret, fd;char *buf =NULL ;
@@ -299,7 +299,7 @@ int show_xbc(const char *path, bool list)return ret; } -int delete_xbc (const char *path) +static int delete_xbc (const char *path) {struct stat stat;int ret =0 , fd, size;
@@ -330,7 +330,7 @@ int delete_xbc(const char *path)return ret; } -int apply_xbc (const char *path,const char *xbc_path) +static int apply_xbc (const char *path,const char *xbc_path) {u32 size, csum;char *buf, *data;
@@ -407,7 +407,7 @@ int apply_xbc(const char *path, const char *xbc_path)return ret; } -int usage (void ) +static int usage (void ) {printf ("Usage: bootconfig [OPTIONS] <INITRD>\n" "Or bootconfig <CONFIG>\n"
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 7/26 tracing: toplevel d_entry already initialized
In reply to Steven RostedtFrom: Wei Yang <[email protected]>
Currently we have following call flow:
tracer_init_tracefs()
tracing_init_dentry()
event_trace_init()
tracing_init_dentry()
This shows tracing_init_dentry() is called twice in this flow and this is not necessary.
Let's remove the second one when it is for sure be properly initialized.
--- kernel/trace/trace_events.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
kernel/trace/trace_events.c +2 -7
@@ -3434,7 +3434,6 @@ early_initcall(event_trace_enable_again);__init int event_trace_init (void ) {struct trace_array *tr; -struct dentry *d_tracer;struct dentry *entry;int ret;
@@ -3442,11 +3441,7 @@ __init int event_trace_init(void)if (!tr)return -ENODEV ; - d_tracer =tracing_init_dentry (); -if (IS_ERR (d_tracer)) -return 0 ; - - entry =tracefs_create_file ("available_events" ,0444 , d_tracer, + entry =tracefs_create_file ("available_events" ,0444 ,NULL , tr, &ftrace_avail_fops);if (!entry)pr_warn ("Could not create tracefs 'available_events' entry\n" );
@@ -3457,7 +3452,7 @@ __init int event_trace_init(void)if (trace_define_common_fields ())pr_warn ("tracing: Failed to allocate common fields" ); - ret =early_event_add_tracer (d_tracer, tr); + ret =early_event_add_tracer (NULL , tr);if (ret)return ret;
Signature · 1 line
2.28.0
Steven Rostedt
maintainerPATCH 4/26 tools/bootconfig: Add a script to generate ftrace shell-command from bootconfig
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add a bconf2ftrace.sh under tools/bootconfig/scripts which generates a shell script to setup boot-time trace from bootconfig file for testing the bootconfig.
bconf2ftrace.sh will take a bootconfig file (includes boot-time tracing) and convert it into a shell-script which is almost same as the boot-time tracer does.
If --apply option is given, it also tries to apply those command to the running kernel, which requires the root privilege (or sudo).
For example, if you just want to confirm the shell commands, save the output as below.
# bconf2ftrace.sh ftrace.bconf > ftrace.sh
Or, you can apply it directly.
# bconf2ftrace.sh --apply ftrace.bconf
Note that some boot-time tracing parameters under kernel.* are not able to set via tracefs nor procfs (e.g. tp_printk, traceoff_on_warning.), so those are ignored.
--- MAINTAINERS | 1 + tools/bootconfig/scripts/bconf2ftrace.sh | 189 +++++++++++++++++++++++ tools/bootconfig/scripts/xbc.sh | 56 +++++++ 3 files changed, 246 insertions(+) create mode 100755 tools/bootconfig/scripts/bconf2ftrace.sh create mode 100644 tools/bootconfig/scripts/xbc.sh
MAINTAINERS +1 -0
@@ -6601,6 +6601,7 @@ F: fs/proc/bootconfig.c F: include/linux/bootconfig.h F: lib/bootconfig.c F: tools/bootconfig/* +F: tools/bootconfig/scripts/* EXYNOS DP DRIVER M: Jingoo Han <[email protected]>
tools/bootconfig/scripts/bconf2ftrace.sh new file +189 -0
189 lines not on this page · raw message
tools/bootconfig/scripts/xbc.sh new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.28.0
Masami Hiramatsu
maintainerRe: [for-next][PATCH 24/26] tracing: Enable creating new instance early boot
In reply to Steven RostedtHi Steve,
Sorry, I found that this is not enough for setting up the instance. It seems that an instance is created but the events of the instance are not created (and maybe reset when initializing the tracefs). Let me fix it.
Thank you,
Quoted 205 lines · On Mon, 21 Sep 2020 21:24:38 -0400 Steven Rostedt <[email protected]> wrote:
From: Masami Hiramatsu <[email protected]>
Enable creating new
trace_arrayinstance in early boot stage. If the instances directory is not created, postpone it until the tracefs is initialized.Signed-off-by Masami Hiramatsu <[email protected]>Signed-off-by Steven Rostedt (VMware) <[email protected]>--- kernel/trace/trace.c | 53 +++++++++++++++++++++++++++------- kernel/trace/trace.h | 7 +++++ kernel/trace/trace_functions.c | 22 +++++++++----- 3 files changed, 63 insertions(+), 19 deletions(-)kernel/trace/trace.c +42
-11@@ -8636,6 +8636,24 @@ struct trace_array *trace_array_find_get(const char *instance)return tr; } +static int trace_array_create_dir (struct trace_array *tr) +{ +int ret; + + tr->dir =tracefs_create_dir (tr->name, trace_instance_dir); +if (!tr->dir) +return -EINVAL ; + + ret =event_trace_add_tracer (tr->dir, tr); +if (ret) +tracefs_remove (tr->dir); + +init_tracer_tracefs (tr, tr->dir); +__update_tracer_options (tr); + +return ret; +} +static struct trace_array *trace_array_create (const char *name) {struct trace_array *tr;@@ -8671,30 +8689,27 @@ static struct trace_array *trace_array_create(const char *name)if (allocate_trace_buffers (tr, trace_buf_size) <0 ) goto out_free_tr; - tr->dir =tracefs_create_dir (name, trace_instance_dir); -if (!tr->dir) - goto out_free_tr; - - ret =event_trace_add_tracer (tr->dir, tr); -if (ret) { -tracefs_remove (tr->dir); +if (ftrace_allocate_ftrace_ops (tr) <0 ) goto out_free_tr; - }ftrace_init_trace_array (tr); -init_tracer_tracefs (tr, tr->dir);init_trace_flags_index (tr); -__update_tracer_options (tr); + +if (trace_instance_dir) { + ret =trace_array_create_dir (tr); +if (ret) + goto out_free_tr; + }list_add (&tr->list, &ftrace_trace_arrays); tr->ref++; -return tr; out_free_tr: +ftrace_free_ftrace_ops (tr);free_trace_buffers (tr);free_cpumask_var (tr->tracing_cpumask);kfree (tr->name);@@ -8852,11 +8867,27 @@ static int instance_rmdir(const char *name)static __init void create_trace_instances (struct dentry *d_tracer) { +struct trace_array *tr; + trace_instance_dir =tracefs_create_instance_dir ("instances" , d_tracer, instance_mkdir, instance_rmdir);if (MEM_FAIL (!trace_instance_dir,"Failed to create instances directory\n" ))return ; + +mutex_lock (&event_mutex); +mutex_lock (&trace_types_lock); + +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (!tr->name) +continue ; +if (MEM_FAIL (trace_array_create_dir (tr) <0 , +"Failed to create instance directory\n" )) +break ; + } + +mutex_unlock (&trace_types_lock); +mutex_unlock (&event_mutex); } static voidkernel/trace/trace.h +7
-0@@ -1125,6 +1125,8 @@ extern int ftrace_is_dead(void);int ftrace_create_function_files (struct trace_array *tr,struct dentry *parent);void ftrace_destroy_function_files (struct trace_array *tr); +int ftrace_allocate_ftrace_ops (struct trace_array *tr); +void ftrace_free_ftrace_ops (struct trace_array *tr);void ftrace_init_global_array_ops (struct trace_array *tr);void ftrace_init_array_ops (struct trace_array *tr,ftrace_func_t func);void ftrace_reset_array_ops (struct trace_array *tr);@@ -1146,6 +1148,11 @@ ftrace_create_function_files(struct trace_array *tr, {return 0 ; } +static inline int ftrace_allocate_ftrace_ops (struct trace_array *tr) +{ +return 0 ; +} +static inline void ftrace_free_ftrace_ops (struct trace_array *tr) { }static inline void ftrace_destroy_function_files (struct trace_array *tr) { }static inline __init void ftrace_init_global_array_ops (struct trace_array *tr) { }kernel/trace/trace_functions.c +14
-8@@ -34,10 +34,14 @@ enum { TRACE_FUNC_OPT_STACK = 0x1, }; -static int allocate_ftrace_ops (struct trace_array *tr) +int ftrace_allocate_ftrace_ops (struct trace_array *tr) {struct ftrace_ops *ops; +/* The top level array uses the "global_ops" */ +if (tr->flags &TRACE_ARRAY_FL_GLOBAL ) +return 0 ; + ops =kzalloc (sizeof (*ops),GFP_KERNEL );if (!ops)return -ENOMEM ;@@ -48,15 +52,19 @@ static int allocate_ftrace_ops(struct trace_array *tr) tr->ops = ops; ops->private = tr; +return 0 ; } +void ftrace_free_ftrace_ops (struct trace_array *tr) +{ +kfree (tr->ops); + tr->ops =NULL ; +}int ftrace_create_function_files (struct trace_array *tr,struct dentry *parent) { -int ret; -/* * The top level array uses the "global_ops", and the files are * created on boot up. @@ -64,9 +72,8 @@ int ftrace_create_function_files(struct trace_array *tr,if (tr->flags &TRACE_ARRAY_FL_GLOBAL )return 0 ; - ret =allocate_ftrace_ops (tr); -if (ret) -return ret; +if (!tr->ops) +return -EINVAL ;ftrace_create_filter_files (tr->ops, parent);@@ -76,8 +83,7 @@ int ftrace_create_function_files(struct trace_array *tr,void ftrace_destroy_function_files (struct trace_array *tr) {ftrace_destroy_filter_files (tr->ops); -kfree (tr->ops); - tr->ops =NULL ; +ftrace_free_ftrace_ops (tr); }static int function_trace_init (struct trace_array *tr)Signature · 1 line
2.28.0
Signature · 1 line
Masami Hiramatsu <[email protected]>
Masami Hiramatsu
maintainerPATCH 1/1 tracing/boot: Initialize per-instance event list in early boot
Initialize per-instance event list in early boot time (before initializing instance directory on tracefs). This fixes boot-time tracing to correctly handle the boot-time per-instance settings.
--- kernel/trace/trace.c | 3 ++- kernel/trace/trace.h | 1 + kernel/trace/trace_events.c | 30 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 15 deletions(-)
kernel/trace/trace.c +2 -1
@@ -8700,7 +8700,8 @@ static struct trace_array *trace_array_create(const char *name) ret =trace_array_create_dir (tr);if (ret) goto out_free_tr; - } + }else +__trace_early_add_events (tr);list_add (&tr->list, &ftrace_trace_arrays);
kernel/trace/trace.h +1 -0
@@ -1658,6 +1658,7 @@ extern void trace_event_enable_tgid_record(bool enable);extern int event_trace_init (void );extern int event_trace_add_tracer (struct dentry *parent,struct trace_array *tr);extern int event_trace_del_tracer (struct trace_array *tr); +extern void __trace_early_add_events (struct trace_array *tr); extern struct trace_event_file *__find_event_file(struct trace_array *tr, const char *system,
kernel/trace/trace_events.c +16 -14
@@ -3131,14 +3131,13 @@ static inline int register_event_cmds(void) { return 0; }#endif /* CONFIG_DYNAMIC_FTRACE */ /* -* The top level array has already had its trace_event_file -* descriptors created in order to allow for early events to -* be recorded. This function is called after the tracefs has been -* initialized, and we now have to create the files associated -* to the events. +* The top level array and trace arrays created by boot-time tracing +* have already had its trace_event_file descriptors created in order +* to allow for early events to be recorded. +* This function is called after the tracefs has been initialized, +* and we now have to create the files associated to the events. */ -static __init void -__trace_early_add_event_dirs (struct trace_array *tr) +static void __trace_early_add_event_dirs (struct trace_array *tr) {struct trace_event_file *file;int ret;
@@ -3153,13 +3152,12 @@ __trace_early_add_event_dirs(struct trace_array *tr) }/* -* For early boot up, the top trace array requires to have -* a list of events that can be enabled. This must be done before -* the filesystem is set up in order to allow events to be traced -* early. +* For early boot up, the top trace array and the trace arrays created +* by boot-time tracing require to have a list of events that can be +* enabled. This must be done before the filesystem is set up in order +* to allow events to be traced early. */ -static __init void -__trace_early_add_events (struct trace_array *tr) +void __trace_early_add_events (struct trace_array *tr) {struct trace_event_call *call;int ret;
@@ -3290,7 +3288,11 @@ int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr) goto out;down_write (&trace_event_sem); -__trace_add_event_dirs (tr); +/* If tr already has the event list, it is initialized in early boot. */ +if (unlikely (!list_empty (&tr->events))) +__trace_early_add_event_dirs (tr); +else +__trace_add_event_dirs (tr);up_write (&trace_event_sem); out:
Steven Rostedt
maintainerRe: [PATCH] tracing/boot: Initialize per-instance event list in early boot
Quoted 4 lines · On Fri, 25 Sep 2020 01:40:08 +0900 Masami Hiramatsu <[email protected]> wrote:
Initialize per-instance event list in early boot time (before initializing instance directory on tracefs). This fixes boot-time tracing to correctly handle the boot-time per-instance settings.
I added:
-- Steve
Quoted 90 lines
Signed-off-by Masami Hiramatsu <[email protected]>--- kernel/trace/trace.c | 3 ++- kernel/trace/trace.h | 1 + kernel/trace/trace_events.c | 30 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 15 deletions(-)kernel/trace/trace.c +2
-1@@ -8700,7 +8700,8 @@ static struct trace_array *trace_array_create(const char *name) ret =trace_array_create_dir (tr);if (ret) goto out_free_tr; - } + }else +__trace_early_add_events (tr);list_add (&tr->list, &ftrace_trace_arrays);kernel/trace/trace.h +1
-0@@ -1658,6 +1658,7 @@ extern void trace_event_enable_tgid_record(bool enable);extern int event_trace_init (void );extern int event_trace_add_tracer (struct dentry *parent,struct trace_array *tr);extern int event_trace_del_tracer (struct trace_array *tr); +extern void __trace_early_add_events (struct trace_array *tr); extern struct trace_event_file *__find_event_file(struct trace_array *tr, const char *system,kernel/trace/trace_events.c +16
-14@@ -3131,14 +3131,13 @@ static inline int register_event_cmds(void) { return 0; }#endif /* CONFIG_DYNAMIC_FTRACE */ /* -* The top level array has already had its trace_event_file -* descriptors created in order to allow for early events to -* be recorded. This function is called after the tracefs has been -* initialized, and we now have to create the files associated -* to the events. +* The top level array and trace arrays created by boot-time tracing +* have already had its trace_event_file descriptors created in order +* to allow for early events to be recorded. +* This function is called after the tracefs has been initialized, +* and we now have to create the files associated to the events. */ -static __init void -__trace_early_add_event_dirs (struct trace_array *tr) +static void __trace_early_add_event_dirs (struct trace_array *tr) {struct trace_event_file *file;int ret;@@ -3153,13 +3152,12 @@ __trace_early_add_event_dirs(struct trace_array *tr) }/* -* For early boot up, the top trace array requires to have -* a list of events that can be enabled. This must be done before -* the filesystem is set up in order to allow events to be traced -* early. +* For early boot up, the top trace array and the trace arrays created +* by boot-time tracing require to have a list of events that can be +* enabled. This must be done before the filesystem is set up in order +* to allow events to be traced early. */ -static __init void -__trace_early_add_events (struct trace_array *tr) +void __trace_early_add_events (struct trace_array *tr) {struct trace_event_call *call;int ret;@@ -3290,7 +3288,11 @@ int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr) goto out;down_write (&trace_event_sem); -__trace_add_event_dirs (tr); +/* If tr already has the event list, it is initialized in early boot. */ +if (unlikely (!list_empty (&tr->events))) +__trace_early_add_event_dirs (tr); +else +__trace_add_event_dirs (tr);up_write (&trace_event_sem); out: