tracing: Updates for v6.16
Subsystems (9)
Steven Rostedt
maintainercover tracing: Updates for v6.16
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/for-next
Head SHA1: 2632a2013f58f0aab4b9fd042e67d78740ba0996
Masami Hiramatsu (Google) (1):
tracing: Record trace_clock and recover when reboot
Steven Rostedt (2):
tracepoint: Have tracepoints created with DECLARE_TRACE() have _tp suffix tracing/sched: Use __string() instead of fixed lengths for task->comm
Yury Norov (1):
tracing: Cleanup upper_empty() in pid_list
----
Documentation/trace/tracepoints.rst | 17 ++- include/linux/tracepoint.h | 38 +++++-- include/trace/bpf_probe.h | 8 +- include/trace/define_trace.h | 17 ++- include/trace/events/sched.h | 124 ++++++++++----------- include/trace/events/tcp.h | 2 +- kernel/trace/pid_list.c | 8 +- kernel/trace/trace.c | 17 +++ tools/testing/selftests/bpf/progs/raw_tp_null.c | 2 +- .../testing/selftests/bpf/progs/raw_tp_null_fail.c | 2 +- .../selftests/bpf/progs/test_module_attach.c | 4 +- .../selftests/bpf/progs/test_tp_btf_nullable.c | 4 +- .../testing/selftests/bpf/test_kmods/bpf_testmod.c | 8 +- 13 files changed, 149 insertions(+), 102 deletions(-)
Steven Rostedt
maintainerPATCH 1/4 tracing: Cleanup upper_empty() in pid_list
From: Yury Norov <[email protected]>
Instead of find_first_bit() use the dedicated bitmap_empty(), and make upper_empty() a nice one-liner.
While there, fix opencoded BITS_PER_TYPE().
--- kernel/trace/pid_list.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
kernel/trace/pid_list.c +2 -6
@@ -81,13 +81,9 @@ static inline bool upper_empty(union upper_chunk *chunk) {/* * If chunk->data has no lower chunks, it will be the same -* as a zeroed bitmask. Use find_first_bit() to test it -* and if it doesn't find any bits set, then the array -* is empty. +* as a zeroed bitmask. */ -int bit =find_first_bit ((unsigned long *)chunk->data, -sizeof (chunk->data) *8 ); -return bit >=sizeof (chunk->data) *8 ; +return bitmap_empty ((unsigned long *)chunk->data,BITS_PER_TYPE (chunk->data)); } static inline int pid_split(unsigned int pid, unsigned int *upper1,
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH 2/4 tracepoint: Have tracepoints created with DECLARE_TRACE() have _tp suffix
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Most tracepoints in the kernel are created with TRACE_EVENT(). The TRACE_EVENT() macro (and DECLARE_EVENT_CLASS() and DEFINE_EVENT() where in reality, TRACE_EVENT() is just a helper macro that calls those other two macros), will create not only a tracepoint (the function trace_<event>() used in the kernel), it also exposes the tracepoint to user space along with defining what fields will be saved by that tracepoint.
There are a few places that tracepoints are created in the kernel that are not exposed to userspace via tracefs. They can only be accessed from code within the kernel. These tracepoints are created with DEFINE_TRACE()
Most of these tracepoints end with "_tp". This is useful as when the developer sees that, they know that the tracepoint is for in-kernel only (meaning it can only be accessed inside the kernel, either directly by the kernel or indirectly via modules and BPF programs) and is not exposed to user space.
Instead of making this only a process to add "_tp", enforce it by making the DECLARE_TRACE() append the "_tp" suffix to the tracepoint. This requires adding DECLARE_TRACE_EVENT() macros for the TRACE_EVENT() macro to use that keeps the original name.
--- Documentation/trace/tracepoints.rst | 17 ++++++--- include/linux/tracepoint.h | 38 +++++++++++++------ include/trace/bpf_probe.h | 8 ++-- include/trace/define_trace.h | 17 ++++++++- include/trace/events/sched.h | 30 +++++++-------- include/trace/events/tcp.h | 2 +- .../testing/selftests/bpf/progs/raw_tp_null.c | 2 +- .../selftests/bpf/progs/raw_tp_null_fail.c | 2 +- .../selftests/bpf/progs/test_module_attach.c | 4 +- .../bpf/progs/test_tp_btf_nullable.c | 4 +- .../selftests/bpf/test_kmods/bpf_testmod.c | 8 ++-- 11 files changed, 83 insertions(+), 49 deletions(-)
Documentation/trace/tracepoints.rst +11 -6
@@ -71,7 +71,7 @@ In subsys/file.c (where the tracing statement must be added):: void somefct(void) { ... - trace_subsys_eventname(arg, task); + trace_subsys_eventname_tp(arg, task); ... }
@@ -129,12 +129,12 @@ within an if statement with the following:: for (i = 0; i < count; i++) tot += calculate_nuggets(); - trace_foo_bar(tot); + trace_foo_bar_tp(tot); } -All trace_<tracepoint>() calls have a matching trace_<tracepoint>_enabled() +All trace_<tracepoint>_tp() calls have a matching trace_<tracepoint>_enabled() function defined that returns true if the tracepoint is enabled and -false otherwise. The trace_<tracepoint>() should always be within the +false otherwise. The trace_<tracepoint>_tp() should always be within the block of the if (trace_<tracepoint>_enabled()) to prevent races between the tracepoint being enabled and the check being seen.
@@ -143,7 +143,10 @@ the static_key of the tracepoint to allow the if statement to be implemented with jump labels and avoid conditional branches. .. note:: The convenience macro TRACE_EVENT provides an alternative way to - define tracepoints. Check http://lwn.net/Articles/379903, + define tracepoints. Note, DECLARE_TRACE(foo) creates a function + "trace_foo_tp()" whereas TRACE_EVENT(foo) creates a function + "trace_foo()", and also exposes the tracepoint as a trace event in + /sys/kernel/tracing/events directory. Check http://lwn.net/Articles/379903, http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362 for a series of articles with more details.
@@ -159,7 +162,9 @@ In a C file:: void do_trace_foo_bar_wrapper(args) { - trace_foo_bar(args); + trace_foo_bar_tp(args); // for tracepoints created via DECLARE_TRACE + // or + trace_foo_bar(args); // for tracepoints created via TRACE_EVENT } In the header file::
include/linux/tracepoint.h +26 -12
@@ -464,16 +464,30 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)#endif #define DECLARE_TRACE (name, proto, args) \ - __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ + __DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \ cpu_online(raw_smp_processor_id()), \ PARAMS(void *__data, proto))#define DECLARE_TRACE_CONDITION (name, proto, args, cond) \ - __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ + __DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \ cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \ PARAMS(void *__data, proto))#define DECLARE_TRACE_SYSCALL (name, proto, args) \ + __DECLARE_TRACE_SYSCALL(name##_tp, PARAMS(proto), PARAMS(args), \ + PARAMS(void *__data, proto)) + +#define DECLARE_TRACE_EVENT (name, proto, args) \ + __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ + cpu_online(raw_smp_processor_id()), \ + PARAMS(void *__data, proto)) + +#define DECLARE_TRACE_EVENT_CONDITION (name, proto, args, cond) \ + __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ + cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \ + PARAMS(void *__data, proto)) + +#define DECLARE_TRACE_EVENT_SYSCALL (name, proto, args) \ __DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args), \ PARAMS(void *__data, proto))
@@ -591,32 +605,32 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)#define DECLARE_EVENT_CLASS (name, proto, args, tstruct, assign, print)#define DEFINE_EVENT (template, name, proto, args) \ - DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) + DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))#define DEFINE_EVENT_FN (template, name, proto, args, reg, unreg)\ - DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) + DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))#define DEFINE_EVENT_PRINT (template, name, proto, args, print) \ - DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) + DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))#define DEFINE_EVENT_CONDITION (template, name, proto, \ args, cond) \ - DECLARE_TRACE_CONDITION(name, PARAMS(proto), \ + DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \ PARAMS(args), PARAMS(cond))#define TRACE_EVENT (name, proto, args, struct, assign, print) \ - DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) + DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))#define TRACE_EVENT_FN (name, proto, args, struct, \ assign, print, reg, unreg) \ - DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) -#define TRACE_EVENT_FN_COND (name, proto, args, cond, struct, \ + DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args)) +#define TRACE_EVENT_FN_COND (name, proto, args, cond, struct, \ assign, print, reg, unreg) \ - DECLARE_TRACE_CONDITION(name, PARAMS(proto), \ + DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \ PARAMS(args), PARAMS(cond))#define TRACE_EVENT_CONDITION (name, proto, args, cond, \ struct, assign, print) \ - DECLARE_TRACE_CONDITION(name, PARAMS(proto), \ + DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \ PARAMS(args), PARAMS(cond))#define TRACE_EVENT_SYSCALL (name, proto, args, struct, assign, \ print, reg, unreg) \ - DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args)) + DECLARE_TRACE_EVENT_SYSCALL(name, PARAMS(proto), PARAMS(args))#define TRACE_EVENT_FLAGS (event, flag)
include/trace/bpf_probe.h +4 -4
@@ -119,14 +119,14 @@ static inline void bpf_test_buffer_##call(void) \#undef DECLARE_TRACE#define DECLARE_TRACE (call, proto, args) \ - __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \ - __DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), 0) + __BPF_DECLARE_TRACE(call##_tp, PARAMS(proto), PARAMS(args)) \ + __DEFINE_EVENT(call##_tp, call##_tp, PARAMS(proto), PARAMS(args), 0)#undef DECLARE_TRACE_WRITABLE#define DECLARE_TRACE_WRITABLE (call, proto, args, size) \ __CHECK_WRITABLE_BUF_SIZE(call, PARAMS(proto), PARAMS(args), size) \ - __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \ - __DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), size) + __BPF_DECLARE_TRACE(call##_tp, PARAMS(proto), PARAMS(args)) \ + __DEFINE_EVENT(call##_tp, call##_tp, PARAMS(proto), PARAMS(args), size)#include TRACE_INCLUDE (TRACE_INCLUDE_FILE )
include/trace/define_trace.h +16 -1
@@ -74,10 +74,18 @@#undef DECLARE_TRACE#define DECLARE_TRACE (name, proto, args) \ - DEFINE_TRACE(name, PARAMS(proto), PARAMS(args)) + DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))#undef DECLARE_TRACE_CONDITION#define DECLARE_TRACE_CONDITION (name, proto, args, cond) \ + DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args)) + +#undef DECLARE_TRACE_EVENT +#define DECLARE_TRACE_EVENT (name, proto, args) \ + DEFINE_TRACE(name, PARAMS(proto), PARAMS(args)) + +#undef DECLARE_TRACE_EVENT_CONDITION +#define DECLARE_TRACE_EVENT_CONDITION (name, proto, args, cond) \ DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))/* If requested, create helpers for calling these tracepoints from Rust. */
@@ -115,6 +123,11 @@#undef DECLARE_TRACE_CONDITION#define DECLARE_TRACE_CONDITION (name, proto, args, cond) +#undef DECLARE_TRACE_EVENT +#define DECLARE_TRACE_EVENT (name, proto, args) +#undef DECLARE_TRACE_EVENT_CONDITION +#define DECLARE_TRACE_EVENT_CONDITION (name, proto, args, cond) +#ifdef TRACEPOINTS_ENABLED #include <trace/trace_events.h> #include <trace/perf.h>
@@ -136,6 +149,8 @@#undef TRACE_HEADER_MULTI_READ#undef DECLARE_TRACE#undef DECLARE_TRACE_CONDITION +#undef DECLARE_TRACE_EVENT +#undef DECLARE_TRACE_EVENT_CONDITION/* Only undef what we defined in this file */ #ifdef UNDEF_TRACE_INCLUDE_FILE
include/trace/events/sched.h +15 -15
@@ -773,64 +773,64 @@ TRACE_EVENT(sched_wake_idle_without_ipi,* * Postfixed with _tp to make them easily identifiable in the code. */ -DECLARE_TRACE (pelt_cfs_tp, +DECLARE_TRACE (pelt_cfs, TP_PROTO(struct cfs_rq *cfs_rq),TP_ARGS (cfs_rq)); -DECLARE_TRACE (pelt_rt_tp, +DECLARE_TRACE (pelt_rt, TP_PROTO(struct rq *rq),TP_ARGS (rq)); -DECLARE_TRACE (pelt_dl_tp, +DECLARE_TRACE (pelt_dl, TP_PROTO(struct rq *rq),TP_ARGS (rq)); -DECLARE_TRACE (pelt_hw_tp, +DECLARE_TRACE (pelt_hw, TP_PROTO(struct rq *rq),TP_ARGS (rq)); -DECLARE_TRACE (pelt_irq_tp, +DECLARE_TRACE (pelt_irq, TP_PROTO(struct rq *rq),TP_ARGS (rq)); -DECLARE_TRACE (pelt_se_tp, +DECLARE_TRACE (pelt_se, TP_PROTO(struct sched_entity *se),TP_ARGS (se)); -DECLARE_TRACE (sched_cpu_capacity_tp, +DECLARE_TRACE (sched_cpu_capacity, TP_PROTO(struct rq *rq),TP_ARGS (rq)); -DECLARE_TRACE (sched_overutilized_tp, +DECLARE_TRACE (sched_overutilized, TP_PROTO(struct root_domain *rd, bool overutilized),TP_ARGS (rd, overutilized)); -DECLARE_TRACE (sched_util_est_cfs_tp, +DECLARE_TRACE (sched_util_est_cfs, TP_PROTO(struct cfs_rq *cfs_rq),TP_ARGS (cfs_rq)); -DECLARE_TRACE (sched_util_est_se_tp, +DECLARE_TRACE (sched_util_est_se, TP_PROTO(struct sched_entity *se),TP_ARGS (se)); -DECLARE_TRACE (sched_update_nr_running_tp, +DECLARE_TRACE (sched_update_nr_running, TP_PROTO(struct rq *rq, int change),TP_ARGS (rq, change)); -DECLARE_TRACE (sched_compute_energy_tp, +DECLARE_TRACE (sched_compute_energy, TP_PROTO(struct task_struct *p, int dst_cpu, unsigned long energy, unsigned long max_util, unsigned long busy_time),TP_ARGS (p, dst_cpu, energy, max_util, busy_time)); -DECLARE_TRACE (sched_entry_tp, +DECLARE_TRACE (sched_entry, TP_PROTO(bool preempt, unsigned long ip),TP_ARGS (preempt, ip)); -DECLARE_TRACE (sched_exit_tp, +DECLARE_TRACE (sched_exit, TP_PROTO(bool is_switch, unsigned long ip),TP_ARGS (is_switch, ip)); -DECLARE_TRACE_CONDITION (sched_set_state_tp, +DECLARE_TRACE_CONDITION (sched_set_state, TP_PROTO(struct task_struct *tsk, int state),TP_ARGS (tsk, state),TP_CONDITION (!!(tsk->__state) != !!state));
include/trace/events/tcp.h +1 -1
@@ -259,7 +259,7 @@ TRACE_EVENT(tcp_retransmit_synack, __entry->saddr_v6, __entry->daddr_v6) ); -DECLARE_TRACE (tcp_cwnd_reduction_tp, +DECLARE_TRACE (tcp_cwnd_reduction, TP_PROTO(const struct sock *sk, int newly_acked_sacked, int newly_lost, int flag), TP_ARGS(sk, newly_acked_sacked, newly_lost, flag)
tools/testing/selftests/bpf/progs/raw_tp_null.c +1 -1
@@ -10,7 +10,7 @@ char _license[] SEC("license") = "GPL";int tid;int i; -SEC("tp_btf/bpf_testmod_test_raw_tp_null") +SEC("tp_btf/bpf_testmod_test_raw_tp_null_tp")int BPF_PROG (test_raw_tp_null ,struct sk_buff *skb) {struct task_struct *task =bpf_get_current_task_btf ();
tools/testing/selftests/bpf/progs/raw_tp_null_fail.c +1 -1
@@ -8,7 +8,7 @@ char _license[] SEC("license") = "GPL";/* Ensure module parameter has PTR_MAYBE_NULL */ -SEC("tp_btf/bpf_testmod_test_raw_tp_null") +SEC("tp_btf/bpf_testmod_test_raw_tp_null_tp") __failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'") int test_raw_tp_null_bpf_testmod_test_raw_tp_null_arg_1(void *ctx) { asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);
tools/testing/selftests/bpf/progs/test_module_attach.c +2 -2
@@ -19,7 +19,7 @@ int BPF_PROG(handle_raw_tp,__u32 raw_tp_bare_write_sz =0 ; -SEC("raw_tp/bpf_testmod_test_write_bare") +SEC("raw_tp/bpf_testmod_test_write_bare_tp")int BPF_PROG (handle_raw_tp_bare ,struct task_struct *task,struct bpf_testmod_test_write_ctx *write_ctx) {
@@ -31,7 +31,7 @@ int raw_tp_writable_bare_in_val = 0;int raw_tp_writable_bare_early_ret =0 ;int raw_tp_writable_bare_out_val =0 ; -SEC("raw_tp.w/bpf_testmod_test_writable_bare") +SEC("raw_tp.w/bpf_testmod_test_writable_bare_tp")int BPF_PROG (handle_raw_tp_writable_bare ,struct bpf_testmod_test_writable_ctx *writable) {
tools/testing/selftests/bpf/progs/test_tp_btf_nullable.c +2 -2
@@ -6,14 +6,14 @@#include "../test_kmods/bpf_testmod.h" #include "bpf_misc.h" -SEC("tp_btf/bpf_testmod_test_nullable_bare") +SEC("tp_btf/bpf_testmod_test_nullable_bare_tp") __failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'") int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx) {return nullable_ctx->len; } -SEC("tp_btf/bpf_testmod_test_nullable_bare") +SEC("tp_btf/bpf_testmod_test_nullable_bare_tp")int BPF_PROG (handle_tp_btf_nullable_bare2 ,struct bpf_testmod_test_read_ctx *nullable_ctx) {if (nullable_ctx)
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c +4 -4
@@ -413,7 +413,7 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj, (void )bpf_testmod_test_arg_ptr_to_struct (&struct_arg1_2); - (void )trace_bpf_testmod_test_raw_tp_null (NULL ); + (void )trace_bpf_testmod_test_raw_tp_null_tp (NULL );bpf_testmod_test_struct_ops3 ();
@@ -431,14 +431,14 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,if (bpf_testmod_loop_test (101 ) >100 )trace_bpf_testmod_test_read (current, &ctx); -trace_bpf_testmod_test_nullable_bare (NULL ); +trace_bpf_testmod_test_nullable_bare_tp (NULL );/* Magic number to enable writable tp */ if (len ==64 ) {struct bpf_testmod_test_writable_ctx writable = { .val =1024 , }; -trace_bpf_testmod_test_writable_bare (&writable); +trace_bpf_testmod_test_writable_bare_tp (&writable);if (writable.early_ret)return snprintf (buf, len,"%d\n" , writable.val); }
@@ -470,7 +470,7 @@ bpf_testmod_test_write(struct file *file, struct kobject *kobj, .len = len, }; -trace_bpf_testmod_test_write_bare (current, &ctx); +trace_bpf_testmod_test_write_bare_tp (current, &ctx);return -EIO ;/* always fail */ }
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH 3/4 tracing/sched: Use __string() instead of fixed lengths for task->comm
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The sched_switch and sched_waking events hardcoded the length of the comm it recorded because these events were created before the dynamic strings were implemented. Unfortunately, several other events copied this method.
As the size of the comm may change in the future, make the string dynamic. The dynamic string requires a 4 byte meta data to hold the size and offset of the string. The amount stored in the ring buffer will then be the strlen(comm) + 5 (for the \n), and aligned to 4 bytes if there's no other strings. This means that a task comm can have up to 10 characters before it requires another 4 bytes in the ring buffer. Most tasks are usually less than that, so this should not be a problem, and it also allows the name to be extended over the TASK_COMM_LEN [1]
Note, sched_switch and the sched_waking trace events still hardcode the length, as there is tooling that still requires that. An effort to update the tooling will be made to allow this to change in the future.
[1] https://lore.kernel.org/all/[email protected]/
--- include/trace/events/sched.h | 94 ++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 47 deletions(-)
include/trace/events/sched.h +47 -47
@@ -20,16 +20,16 @@ TRACE_EVENT(sched_kthread_stop,TP_ARGS (t),TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) -__field ( pid_t, pid ) + __string( comm, t->comm ) +__field ( pid_t, pid ) ),TP_fast_assign ( - memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = t->pid; ), -TP_printk ("comm=%s pid=%d" , __entry->comm, __entry->pid) +TP_printk ("comm=%s pid=%d" ,__get_str (comm), __entry->pid) );/*
@@ -276,15 +276,15 @@ TRACE_EVENT(sched_migrate_task,TP_ARGS (p, dest_cpu),TP_STRUCT__entry ( -__array (char ,comm ,TASK_COMM_LEN ) -__field ( pid_t, pid ) -__field ( int, prio ) -__field ( int, orig_cpu ) -__field ( int, dest_cpu ) + __string( comm, p->comm ) + __field( pid_t, pid ) + __field( int, prio ) + __field( int, orig_cpu ) +__field ( int, dest_cpu ) ),TP_fast_assign ( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = p->pid; __entry->prio = p->prio;/* XXX SCHED_DEADLINE */ __entry->orig_cpu =task_cpu (p);
@@ -292,7 +292,7 @@ TRACE_EVENT(sched_migrate_task, ),TP_printk ("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d" , - __entry->comm, __entry->pid, __entry->prio, +__get_str (comm), __entry->pid, __entry->prio, __entry->orig_cpu, __entry->dest_cpu) );
@@ -303,19 +303,19 @@ DECLARE_EVENT_CLASS(sched_process_template,TP_ARGS (p),TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) -__field (pid_t ,pid ) -__field ( int, prio ) + __string( comm, p->comm ) +__field (pid_t ,pid ) +__field ( int, prio ) ),TP_fast_assign ( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = p->pid; __entry->prio = p->prio;/* XXX SCHED_DEADLINE */ ),TP_printk ("comm=%s pid=%d prio=%d" , - __entry->comm, __entry->pid, __entry->prio) +__get_str (comm), __entry->pid, __entry->prio) );/*
@@ -349,19 +349,19 @@ TRACE_EVENT(sched_process_wait,TP_ARGS (pid),TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) + __string( comm, current->comm )__field (pid_t ,pid )__field ( int, prio ) ),TP_fast_assign ( - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid =pid_nr (pid); __entry->prio = current->prio;/* XXX SCHED_DEADLINE */ ),TP_printk ("comm=%s pid=%d prio=%d" , - __entry->comm, __entry->pid, __entry->prio) +__get_str (comm), __entry->pid, __entry->prio) );/*
@@ -374,22 +374,22 @@ TRACE_EVENT(sched_process_fork,TP_ARGS (parent, child),TP_STRUCT__entry ( -__array (char ,parent_comm ,TASK_COMM_LEN ) -__field ( pid_t, parent_pid ) -__array ( char, child_comm,TASK_COMM_LEN ) -__field ( pid_t, child_pid ) + __string( parent_comm, parent->comm ) + __field( pid_t, parent_pid ) + __string( child_comm, child->comm ) +__field ( pid_t, child_pid ) ),TP_fast_assign ( - memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN); + __assign_str(parent_comm); __entry->parent_pid = parent->pid; -memcpy (__entry->child_comm, child->comm,TASK_COMM_LEN ); +__assign_str (child_comm); __entry->child_pid = child->pid; ),TP_printk ("comm=%s pid=%d child_comm=%s child_pid=%d" , - __entry->parent_comm, __entry->parent_pid, - __entry->child_comm, __entry->child_pid) +__get_str (parent_comm), __entry->parent_pid, +__get_str (child_comm), __entry->child_pid) );/*
@@ -473,19 +473,19 @@ DECLARE_EVENT_CLASS_SCHEDSTAT(sched_stat_template,TP_ARGS (__perf_task (tsk),__perf_count (delay)),TP_STRUCT__entry ( -__array (char ,comm ,TASK_COMM_LEN ) -__field ( pid_t, pid ) -__field ( u64, delay ) + __string( comm, tsk->comm ) + __field( pid_t, pid ) +__field ( u64, delay ) ),TP_fast_assign ( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = tsk->pid; __entry->delay = delay; ),TP_printk ("comm=%s pid=%d delay=%Lu [ns]" , - __entry->comm, __entry->pid, +__get_str (comm), __entry->pid, (unsigned long long )__entry->delay) );
@@ -531,19 +531,19 @@ DECLARE_EVENT_CLASS(sched_stat_runtime,TP_ARGS (tsk,__perf_count (runtime)),TP_STRUCT__entry ( -__array (char ,comm ,TASK_COMM_LEN ) -__field ( pid_t, pid ) -__field ( u64, runtime ) + __string( comm, tsk->comm ) + __field( pid_t, pid ) +__field ( u64, runtime ) ),TP_fast_assign ( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = tsk->pid; __entry->runtime = runtime; ),TP_printk ("comm=%s pid=%d runtime=%Lu [ns]" , - __entry->comm, __entry->pid, +__get_str (comm), __entry->pid, (unsigned long long )__entry->runtime) );
@@ -562,14 +562,14 @@ TRACE_EVENT(sched_pi_setprio,TP_ARGS (tsk, pi_task),TP_STRUCT__entry ( -__array (char ,comm ,TASK_COMM_LEN ) -__field ( pid_t, pid ) -__field ( int, oldprio ) -__field ( int, newprio ) + __string( comm, tsk->comm ) + __field( pid_t, pid ) + __field( int, oldprio ) +__field ( int, newprio ) ),TP_fast_assign ( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = tsk->pid; __entry->oldprio = tsk->prio; __entry->newprio = pi_task ?
@@ -579,7 +579,7 @@ TRACE_EVENT(sched_pi_setprio, ),TP_printk ("comm=%s pid=%d oldprio=%d newprio=%d" , - __entry->comm, __entry->pid, +__get_str (comm), __entry->pid, __entry->oldprio, __entry->newprio) );
@@ -589,16 +589,16 @@ TRACE_EVENT(sched_process_hang,TP_ARGS (tsk),TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) -__field ( pid_t, pid ) + __string( comm, tsk->comm ) +__field ( pid_t, pid ) ),TP_fast_assign ( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __assign_str(comm); __entry->pid = tsk->pid; ), -TP_printk ("comm=%s pid=%d" , __entry->comm, __entry->pid) +TP_printk ("comm=%s pid=%d" ,__get_str (comm), __entry->pid) );#endif /* CONFIG_DETECT_HUNG_TASK */
Signature · 1 line
2.47.2
Steven Rostedt
maintainerPATCH 4/4 tracing: Record trace_clock and recover when reboot
In reply to Steven RostedtFrom: "Masami Hiramatsu (Google)" <[email protected]>
Record trace_clock information in the trace_scratch area and recover the trace_clock when boot, so that reader can docode the timestamp correctly.
Note that since most trace_clocks records the timestamp in nano- seconds, this is not a bug. But some trace_clock, like counter and tsc will record the counter value. Only for those trace_clock user needs this information.
--- kernel/trace/trace.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
kernel/trace/trace.c +17 -0
@@ -6066,6 +6066,7 @@ struct trace_mod_entry { };struct trace_scratch { +unsigned int clock_id;unsigned long text_addr;unsigned long nr_entries;struct trace_mod_entry entries[];
@@ -6181,6 +6182,7 @@ static void update_last_data(struct trace_array *tr)if (tr->scratch) {struct trace_scratch *tscratch = tr->scratch; + tscratch->clock_id = tr->clock_id;memset (tscratch->entries,0 ,flex_array_size (tscratch, entries, tscratch->nr_entries)); tscratch->nr_entries =0 ;
@@ -7403,6 +7405,12 @@ int tracing_set_clock(struct trace_array *tr, const char *clockstr)tracing_reset_online_cpus (&tr->max_buffer);#endif +if (tr->scratch && !(tr->flags &TRACE_ARRAY_FL_LAST_BOOT )) { +struct trace_scratch *tscratch = tr->scratch; + + tscratch->clock_id = i; + } +mutex_unlock (&trace_types_lock);return 0 ;
@@ -9628,6 +9636,15 @@ static void setup_trace_scratch(struct trace_array *tr,/* Scan modules to make text delta for modules. */ module_for_each_mod (make_mod_delta, tr); + +/* Set trace_clock as the same of the previous boot. */ +if (tscratch->clock_id != tr->clock_id) { +if (tscratch->clock_id >=ARRAY_SIZE (trace_clocks) || +tracing_set_clock (tr, trace_clocks[tscratch->clock_id].name) <0 ) { +pr_info ("the previous trace_clock info is not valid." ); + goto reset; + } + }return ; reset:/* Invalid trace modules */
Signature · 1 line
2.47.2