From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 271DFC636CC for ; Wed, 8 Feb 2023 01:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229519AbjBHB5h (ORCPT ); Tue, 7 Feb 2023 20:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjBHB5d (ORCPT ); Tue, 7 Feb 2023 20:57:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4A983D901 for ; Tue, 7 Feb 2023 17:57:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 414776147D for ; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E4E2C4339B; Wed, 8 Feb 2023 01:57:31 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiE-006dMV-20; Tue, 07 Feb 2023 20:57:30 -0500 Message-ID: <20230208015730.437670637@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:34 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Davidlohr Bueso , Daniel Bristot de Oliveira Subject: [for-next][PATCH 01/11] tracing/osnoise: No need for schedule_hrtimeout range References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Davidlohr Bueso No slack time is being passed, just use schedule_hrtimeout(). Link: https://lore.kernel.org/linux-trace-kernel/20230123234649.17968-1-dav= e@stgolabs.net Signed-off-by: Davidlohr Bueso Acked-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_osnoise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 210e1f168392..04f0fdae19a1 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -1539,7 +1539,7 @@ static void osnoise_sleep(void) wake_time =3D ktime_add_us(ktime_get(), interval); __set_current_state(TASK_INTERRUPTIBLE); =20 - while (schedule_hrtimeout_range(&wake_time, 0, HRTIMER_MODE_ABS)) { + while (schedule_hrtimeout(&wake_time, HRTIMER_MODE_ABS)) { if (kthread_should_stop()) break; } --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FEC9C636CC for ; Wed, 8 Feb 2023 01:57:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbjBHB5n (ORCPT ); Tue, 7 Feb 2023 20:57:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBHB5e (ORCPT ); Tue, 7 Feb 2023 20:57:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6DCF1968F for ; Tue, 7 Feb 2023 17:57:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7F49B61485 for ; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D167EC433A4; Wed, 8 Feb 2023 01:57:31 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiE-006dN4-2f; Tue, 07 Feb 2023 20:57:30 -0500 Message-ID: <20230208015730.639442891@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:35 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Jonathan Corbet , kernel test robot , Bagas Sanjaya Subject: [for-next][PATCH 02/11] tracing/histogram: Wrap remaining shell snippets in code blocks References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Bagas Sanjaya Most shell command snippets (echo/cat) and their output are already in literal code blocks. However a few still isn't wrapped, in which the htmldocs output is ugly. Wrap the remaining unwrapped snippets, while also fix recent kernel test robot warnings. Link: https://lore.kernel.org/linux-trace-kernel/20230129031402.47420-1-bag= asdotme@gmail.com Cc: Masami Hiramatsu Cc: Jonathan Corbet Link: https://lore.kernel.org/linux-doc/202301290253.LU5yIxcJ-lkp@intel.com/ Fixes: 88238513bb2671 ("tracing/histogram: Document variable stacktrace") Reported-by: kernel test robot Signed-off-by: Bagas Sanjaya Signed-off-by: Steven Rostedt (Google) --- Documentation/trace/histogram.rst | 93 ++++++++++++++++--------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/Documentation/trace/histogram.rst b/Documentation/trace/histog= ram.rst index 5c391328b9bb..8e95295e39b6 100644 --- a/Documentation/trace/histogram.rst +++ b/Documentation/trace/histogram.rst @@ -1864,7 +1864,7 @@ A histogram can now be defined for the new synthetic = event:: The above shows the latency "lat" in a power of 2 grouping. =20 Like any other event, once a histogram is enabled for the event, the -output can be displayed by reading the event's 'hist' file. +output can be displayed by reading the event's 'hist' file:: =20 # cat /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/hist =20 @@ -1911,7 +1911,7 @@ output can be displayed by reading the event's 'hist'= file. =20 =20 The latency values can also be grouped linearly by a given size with -the ".buckets" modifier and specify a size (in this case groups of 10). +the ".buckets" modifier and specify a size (in this case groups of 10):: =20 # echo 'hist:keys=3Dpid,prio,lat.buckets=3D10:sort=3Dlat' >> \ /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/trigger @@ -1945,7 +1945,7 @@ the ".buckets" modifier and specify a size (in this c= ase groups of 10). =20 To save stacktraces, create a synthetic event with a field of type "unsign= ed long[]" or even just "long[]". For example, to see how long a task is blocked in an -uninterruptible state: +uninterruptible state:: =20 # cd /sys/kernel/tracing # echo 's:block_lat pid_t pid; u64 delta; unsigned long[] stack;' > dyna= mic_events @@ -1990,7 +1990,8 @@ uninterruptible state: =3D> kthread+0xe9/0x110 =3D> ret_from_fork+0x2c/0x50 =20 -A synthetic event that has a stacktrace field may use it as a key in histo= gram: +A synthetic event that has a stacktrace field may use it as a key in +histogram:: =20 # echo 'hist:delta.buckets=3D100,stack.stacktrace:sort=3Ddelta' > events= /synthetic/block_lat/trigger # cat events/synthetic/block_lat/hist @@ -2183,11 +2184,11 @@ The following commonly-used handler.action pairs ar= e available: wakeup_new_test($testpid) if comm=3D=3D"cyclictest"' >> \ /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/trig= ger =20 - Or, equivalently, using the 'trace' keyword syntax: + Or, equivalently, using the 'trace' keyword syntax:: =20 - # echo 'hist:keys=3D$testpid:testpid=3Dpid:onmatch(sched.sched_wakeup_= new).\ - trace(wakeup_new_test,$testpid) if comm=3D=3D"cyclictest"' >> \ - /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/trigger + # echo 'hist:keys=3D$testpid:testpid=3Dpid:onmatch(sched.sched_wakeu= p_new).\ + trace(wakeup_new_test,$testpid) if comm=3D=3D"cyclictest"' >= > \ + /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/trig= ger =20 Creating and displaying a histogram based on those events is now just a matter of using the fields and new synthetic event in the @@ -2320,48 +2321,48 @@ The following commonly-used handler.action pairs ar= e available: resulting latency, stored in wakeup_lat, exceeds the current maximum latency, a snapshot is taken. As part of the setup, all the scheduler events are also enabled, which are the events that - will show up in the snapshot when it is taken at some point: + will show up in the snapshot when it is taken at some point:: =20 - # echo 1 > /sys/kernel/debug/tracing/events/sched/enable + # echo 1 > /sys/kernel/debug/tracing/events/sched/enable =20 - # echo 'hist:keys=3Dpid:ts0=3Dcommon_timestamp.usecs \ - if comm=3D=3D"cyclictest"' >> \ - /sys/kernel/debug/tracing/events/sched/sched_waking/trigger + # echo 'hist:keys=3Dpid:ts0=3Dcommon_timestamp.usecs \ + if comm=3D=3D"cyclictest"' >> \ + /sys/kernel/debug/tracing/events/sched/sched_waking/trigger =20 - # echo 'hist:keys=3Dnext_pid:wakeup_lat=3Dcommon_timestamp.usecs-$ts0:= \ - onmax($wakeup_lat).save(next_prio,next_comm,prev_pid,prev_prio= , \ - prev_comm):onmax($wakeup_lat).snapshot() \ - if next_comm=3D=3D"cyclictest"' >> \ - /sys/kernel/debug/tracing/events/sched/sched_switch/trigger + # echo 'hist:keys=3Dnext_pid:wakeup_lat=3Dcommon_timestamp.usecs-$ts= 0: \ + onmax($wakeup_lat).save(next_prio,next_comm,prev_pid,prev_pr= io, \ + prev_comm):onmax($wakeup_lat).snapshot() \ + if next_comm=3D=3D"cyclictest"' >> \ + /sys/kernel/debug/tracing/events/sched/sched_switch/trigger =20 When the histogram is displayed, for each bucket the max value and the saved values corresponding to the max are displayed following the rest of the fields. =20 If a snapshot was taken, there is also a message indicating that, - along with the value and event that triggered the global maximum: + along with the value and event that triggered the global maximum:: =20 - # cat /sys/kernel/debug/tracing/events/sched/sched_switch/hist - { next_pid: 2101 } hitcount: 200 - max: 52 next_prio: 120 next_comm: cyclictest \ - prev_pid: 0 prev_prio: 120 prev_comm: swapper/6 + # cat /sys/kernel/debug/tracing/events/sched/sched_switch/hist + { next_pid: 2101 } hitcount: 200 + max: 52 next_prio: 120 next_comm: cyclictest \ + prev_pid: 0 prev_prio: 120 prev_comm: swapper/6 =20 - { next_pid: 2103 } hitcount: 1326 - max: 572 next_prio: 19 next_comm: cyclictest \ - prev_pid: 0 prev_prio: 120 prev_comm: swapper/1 + { next_pid: 2103 } hitcount: 1326 + max: 572 next_prio: 19 next_comm: cyclictest \ + prev_pid: 0 prev_prio: 120 prev_comm: swapper/1 =20 - { next_pid: 2102 } hitcount: 1982 \ - max: 74 next_prio: 19 next_comm: cyclictest \ - prev_pid: 0 prev_prio: 120 prev_comm: swapper/5 + { next_pid: 2102 } hitcount: 1982 \ + max: 74 next_prio: 19 next_comm: cyclictest \ + prev_pid: 0 prev_prio: 120 prev_comm: swapper/5 =20 - Snapshot taken (see tracing/snapshot). Details: - triggering value { onmax($wakeup_lat) }: 572 \ - triggered by event with key: { next_pid: 2103 } + Snapshot taken (see tracing/snapshot). Details: + triggering value { onmax($wakeup_lat) }: 572 \ + triggered by event with key: { next_pid: 2103 } =20 - Totals: - Hits: 3508 - Entries: 3 - Dropped: 0 + Totals: + Hits: 3508 + Entries: 3 + Dropped: 0 =20 In the above case, the event that triggered the global maximum has the key with next_pid =3D=3D 2103. If you look at the bucket that has @@ -2439,15 +2440,15 @@ The following commonly-used handler.action pairs ar= e available: $cwnd variable. If the value has changed, a snapshot is taken. As part of the setup, all the scheduler and tcp events are also enabled, which are the events that will show up in the snapshot - when it is taken at some point: + when it is taken at some point:: =20 - # echo 1 > /sys/kernel/debug/tracing/events/sched/enable - # echo 1 > /sys/kernel/debug/tracing/events/tcp/enable + # echo 1 > /sys/kernel/debug/tracing/events/sched/enable + # echo 1 > /sys/kernel/debug/tracing/events/tcp/enable =20 - # echo 'hist:keys=3Ddport:cwnd=3Dsnd_cwnd: \ - onchange($cwnd).save(snd_wnd,srtt,rcv_wnd): \ - onchange($cwnd).snapshot()' >> \ - /sys/kernel/debug/tracing/events/tcp/tcp_probe/trigger + # echo 'hist:keys=3Ddport:cwnd=3Dsnd_cwnd: \ + onchange($cwnd).save(snd_wnd,srtt,rcv_wnd): \ + onchange($cwnd).snapshot()' >> \ + /sys/kernel/debug/tracing/events/tcp/tcp_probe/trigger =20 When the histogram is displayed, for each bucket the tracked value and the saved values corresponding to that value are displayed @@ -2470,10 +2471,10 @@ The following commonly-used handler.action pairs ar= e available: { dport: 443 } hitcount: 211 changed: 10 snd_wnd: 26960 srtt: 17379 rcv_wnd: = 28800 =20 - Snapshot taken (see tracing/snapshot). Details:: + Snapshot taken (see tracing/snapshot). Details: =20 - triggering value { onchange($cwnd) }: 10 - triggered by event with key: { dport: 80 } + triggering value { onchange($cwnd) }: 10 + triggered by event with key: { dport: 80 } =20 Totals: Hits: 414 --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C75EC636CC for ; Wed, 8 Feb 2023 01:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbjBHB54 (ORCPT ); Tue, 7 Feb 2023 20:57:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbjBHB5g (ORCPT ); Tue, 7 Feb 2023 20:57:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AFCF23675 for ; Tue, 7 Feb 2023 17:57:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4F807B81B9E for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05A5AC433A7; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiF-006dNc-07; Tue, 07 Feb 2023 20:57:31 -0500 Message-ID: <20230208015730.847877889@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:36 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Linyu Yuan Subject: [for-next][PATCH 03/11] tracing: Acquire buffer from temparary trace sequence References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Linyu Yuan there is one dwc3 trace event declare as below, DECLARE_EVENT_CLASS(dwc3_log_event, TP_PROTO(u32 event, struct dwc3 *dwc), TP_ARGS(event, dwc), TP_STRUCT__entry( __field(u32, event) __field(u32, ep0state) __dynamic_array(char, str, DWC3_MSG_MAX) ), TP_fast_assign( __entry->event =3D event; __entry->ep0state =3D dwc->ep0state; ), TP_printk("event (%08x): %s", __entry->event, dwc3_decode_event(__get_str(str), DWC3_MSG_MAX, __entry->event, __entry->ep0state)) ); the problem is when trace function called, it will allocate up to DWC3_MSG_MAX bytes from trace event buffer, but never fill the buffer during fast assignment, it only fill the buffer when output function are called, so this means if output function are not called, the buffer will never used. add __get_buf(len) which acquiree buffer from iter->tmp_seq when trace output function called, it allow user write string to acquired buffer. the mentioned dwc3 trace event will changed as below, DECLARE_EVENT_CLASS(dwc3_log_event, TP_PROTO(u32 event, struct dwc3 *dwc), TP_ARGS(event, dwc), TP_STRUCT__entry( __field(u32, event) __field(u32, ep0state) ), TP_fast_assign( __entry->event =3D event; __entry->ep0state =3D dwc->ep0state; ), TP_printk("event (%08x): %s", __entry->event, dwc3_decode_event(__get_buf(DWC3_MSG_MAX), DWC3_MSG_MAX, __entry->event, __entry->ep0state)) );. Link: https://lore.kernel.org/linux-trace-kernel/1675065249-23368-1-git-sen= d-email-quic_linyyuan@quicinc.com Cc: Masami Hiramatsu Signed-off-by: Linyu Yuan Signed-off-by: Steven Rostedt (Google) --- include/linux/trace_seq.h | 5 +++++ include/trace/stages/stage3_trace_output.h | 3 +++ include/trace/stages/stage7_class_define.h | 1 + kernel/trace/trace_seq.c | 23 ++++++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/include/linux/trace_seq.h b/include/linux/trace_seq.h index 0c4c7587d6c3..6be92bf559fe 100644 --- a/include/linux/trace_seq.h +++ b/include/linux/trace_seq.h @@ -95,6 +95,7 @@ extern void trace_seq_bitmask(struct trace_seq *s, const = unsigned long *maskp, extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, bool ascii); +char *trace_seq_acquire(struct trace_seq *s, unsigned int len); =20 #else /* CONFIG_TRACING */ static inline __printf(2, 3) @@ -139,6 +140,10 @@ static inline int trace_seq_path(struct trace_seq *s, = const struct path *path) { return 0; } +static inline char *trace_seq_acquire(struct trace_seq *s, unsigned int le= n) +{ + return NULL; +} #endif /* CONFIG_TRACING */ =20 #endif /* _LINUX_TRACE_SEQ_H */ diff --git a/include/trace/stages/stage3_trace_output.h b/include/trace/sta= ges/stage3_trace_output.h index 66374df61ed3..c1fb1355d309 100644 --- a/include/trace/stages/stage3_trace_output.h +++ b/include/trace/stages/stage3_trace_output.h @@ -139,3 +139,6 @@ u64 ____val =3D (u64)(value); \ (u32) do_div(____val, NSEC_PER_SEC); \ }) + +#undef __get_buf +#define __get_buf(len) trace_seq_acquire(p, (len)) diff --git a/include/trace/stages/stage7_class_define.h b/include/trace/sta= ges/stage7_class_define.h index 8795429f388b..bcb960d16fc0 100644 --- a/include/trace/stages/stage7_class_define.h +++ b/include/trace/stages/stage7_class_define.h @@ -23,6 +23,7 @@ #undef __get_rel_sockaddr #undef __print_array #undef __print_hex_dump +#undef __get_buf =20 /* * The below is not executed in the kernel. It is only what is diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c index 9c90b3a7dce2..e5e299260d0c 100644 --- a/kernel/trace/trace_seq.c +++ b/kernel/trace/trace_seq.c @@ -403,3 +403,26 @@ int trace_seq_hex_dump(struct trace_seq *s, const char= *prefix_str, return 1; } EXPORT_SYMBOL(trace_seq_hex_dump); + +/* + * trace_seq_acquire - acquire seq buffer with size len + * @s: trace sequence descriptor + * @len: size of buffer to be acquired + * + * acquire buffer with size of @len from trace_seq for output usage, + * user can fill string into that buffer. + * + * Returns start address of acquired buffer. + * + * it allow multiple usage in one trace output function call. + */ +char *trace_seq_acquire(struct trace_seq *s, unsigned int len) +{ + char *ret =3D trace_seq_buffer_ptr(s); + + if (!WARN_ON_ONCE(seq_buf_buffer_left(&s->seq) < len)) + seq_buf_commit(&s->seq, len); + + return ret; +} +EXPORT_SYMBOL(trace_seq_acquire); --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AC9EC636CD for ; Wed, 8 Feb 2023 01:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230223AbjBHB6B (ORCPT ); Tue, 7 Feb 2023 20:58:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjBHB5g (ORCPT ); Tue, 7 Feb 2023 20:57:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7F4E3EFF7 for ; Tue, 7 Feb 2023 17:57:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 78A57B81BA0 for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34269C433A8; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiF-006dOA-0l; Tue, 07 Feb 2023 20:57:31 -0500 Message-ID: <20230208015731.055452222@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:37 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Song Shuai Subject: [for-next][PATCH 04/11] samples: ftrace: Include the nospec-branch.h only for x86 References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Song Shuai When other architectures without the nospec functionality write their direct-call functions of samples/ftrace/*.c, the including of asm/nospec-branch.h must be taken care to fix the no header file found error in building process. This commit (ee3e2469b346 "x86/ftrace: Make it call depth tracking aware") file-globally includes asm/nospec-branch.h providing CALL_DEPTH_ACCOUNT for only x86 direct-call functions. It seems better to move the including to `#ifdef CONFIG_X86_64`. Link: https://lore.kernel.org/linux-trace-kernel/20230130085954.647845-1-su= agrfillet@gmail.com Signed-off-by: Song Shuai Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- samples/ftrace/ftrace-direct-modify.c | 2 +- samples/ftrace/ftrace-direct-multi-modify.c | 2 +- samples/ftrace/ftrace-direct-multi.c | 2 +- samples/ftrace/ftrace-direct-too.c | 2 +- samples/ftrace/ftrace-direct.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/ftrace/ftrace-direct-modify.c b/samples/ftrace/ftrace-= direct-modify.c index de5a0f67f320..d93abbcb1f4c 100644 --- a/samples/ftrace/ftrace-direct-modify.c +++ b/samples/ftrace/ftrace-direct-modify.c @@ -3,7 +3,6 @@ #include #include #include -#include =20 extern void my_direct_func1(void); extern void my_direct_func2(void); @@ -26,6 +25,7 @@ static unsigned long my_ip =3D (unsigned long)schedule; #ifdef CONFIG_X86_64 =20 #include +#include =20 asm ( " .pushsection .text, \"ax\", @progbits\n" diff --git a/samples/ftrace/ftrace-direct-multi-modify.c b/samples/ftrace/f= trace-direct-multi-modify.c index a825dbd2c9cf..b58c594efb51 100644 --- a/samples/ftrace/ftrace-direct-multi-modify.c +++ b/samples/ftrace/ftrace-direct-multi-modify.c @@ -3,7 +3,6 @@ #include #include #include -#include =20 extern void my_direct_func1(unsigned long ip); extern void my_direct_func2(unsigned long ip); @@ -24,6 +23,7 @@ extern void my_tramp2(void *); #ifdef CONFIG_X86_64 =20 #include +#include =20 asm ( " .pushsection .text, \"ax\", @progbits\n" diff --git a/samples/ftrace/ftrace-direct-multi.c b/samples/ftrace/ftrace-d= irect-multi.c index d955a2650605..c27cf130c319 100644 --- a/samples/ftrace/ftrace-direct-multi.c +++ b/samples/ftrace/ftrace-direct-multi.c @@ -5,7 +5,6 @@ #include #include #include -#include =20 extern void my_direct_func(unsigned long ip); =20 @@ -19,6 +18,7 @@ extern void my_tramp(void *); #ifdef CONFIG_X86_64 =20 #include +#include =20 asm ( " .pushsection .text, \"ax\", @progbits\n" diff --git a/samples/ftrace/ftrace-direct-too.c b/samples/ftrace/ftrace-dir= ect-too.c index e13fb59a2b47..8139dce2a31c 100644 --- a/samples/ftrace/ftrace-direct-too.c +++ b/samples/ftrace/ftrace-direct-too.c @@ -4,7 +4,6 @@ #include /* for handle_mm_fault() */ #include #include -#include =20 extern void my_direct_func(struct vm_area_struct *vma, unsigned long address, unsigned int flags); @@ -21,6 +20,7 @@ extern void my_tramp(void *); #ifdef CONFIG_X86_64 =20 #include +#include =20 asm ( " .pushsection .text, \"ax\", @progbits\n" diff --git a/samples/ftrace/ftrace-direct.c b/samples/ftrace/ftrace-direct.c index 1f769d0db20f..1d3d307ca33d 100644 --- a/samples/ftrace/ftrace-direct.c +++ b/samples/ftrace/ftrace-direct.c @@ -4,7 +4,6 @@ #include /* for wake_up_process() */ #include #include -#include =20 extern void my_direct_func(struct task_struct *p); =20 @@ -18,6 +17,7 @@ extern void my_tramp(void *); #ifdef CONFIG_X86_64 =20 #include +#include =20 asm ( " .pushsection .text, \"ax\", @progbits\n" --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 348EFC636CD for ; Wed, 8 Feb 2023 01:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229775AbjBHB6K (ORCPT ); Tue, 7 Feb 2023 20:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbjBHB5g (ORCPT ); Tue, 7 Feb 2023 20:57:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FAC93F283 for ; Tue, 7 Feb 2023 17:57:35 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B47DCB81B9C for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DE81C4339E; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiF-006dOi-1P; Tue, 07 Feb 2023 20:57:31 -0500 Message-ID: <20230208015731.258171441@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:38 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Arnd Bergmann , Mark Rutland Subject: [for-next][PATCH 05/11] ftrace: sample: avoid open-coded 64-bit division References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnd Bergmann Calculating the average period requires a 64-bit division that leads to a link failure on 32-bit architectures: x86_64-linux-ld: samples/ftrace/ftrace-ops.o: in function `ftrace_ops_sampl= e_init': ftrace-ops.c:(.init.text+0x23b): undefined reference to `__udivdi3' Use the div_u64() helper to do this instead. Since this is an init function= that is not called frequently, the runtime overhead is going to be acceptable. Link: https://lore.kernel.org/linux-trace-kernel/20230130130246.247537-1-ar= nd@kernel.org Cc: Masami Hiramatsu Fixes: b56c68f705ca ("ftrace: Add sample with custom ops") Signed-off-by: Arnd Bergmann Acked-by: Mark Rutland Signed-off-by: Steven Rostedt (Google) --- samples/ftrace/ftrace-ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/ftrace/ftrace-ops.c b/samples/ftrace/ftrace-ops.c index 24deb51c7261..0c8da87ff5c3 100644 --- a/samples/ftrace/ftrace-ops.c +++ b/samples/ftrace/ftrace-ops.c @@ -223,7 +223,7 @@ static int __init ftrace_ops_sample_init(void) =20 pr_info("Attempted %u calls to %ps in %lluns (%lluns / call)\n", nr_function_calls, tracee_relevant, - period, period / nr_function_calls); + period, div_u64(period, nr_function_calls)); =20 if (persist) return 0; --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 884E3C636CC for ; Wed, 8 Feb 2023 01:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbjBHB5j (ORCPT ); Tue, 7 Feb 2023 20:57:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbjBHB5e (ORCPT ); Tue, 7 Feb 2023 20:57:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D5B3E601 for ; Tue, 7 Feb 2023 17:57:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D02B6147F for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B27DC433D2; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiF-006dPG-25; Tue, 07 Feb 2023 20:57:31 -0500 Message-ID: <20230208015731.460057881@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:39 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Tom Rix , Mark Rutland Subject: [for-next][PATCH 06/11] samples: ftrace: Make some global variables static References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tom Rix smatch reports this representative issue samples/ftrace/ftrace-ops.c:15:14: warning: symbol 'nr_function_calls' was = not declared. Should it be static? The nr_functions_calls and several other global variables are only used in ftrace-ops.c, so they should be static. Remove the instances of initializing static int to 0. Link: https://lore.kernel.org/linux-trace-kernel/20230130193708.1378108-1-t= rix@redhat.com Signed-off-by: Tom Rix Acked-by: Mark Rutland Signed-off-by: Steven Rostedt (Google) --- samples/ftrace/ftrace-ops.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/ftrace/ftrace-ops.c b/samples/ftrace/ftrace-ops.c index 0c8da87ff5c3..68d6685c80bd 100644 --- a/samples/ftrace/ftrace-ops.c +++ b/samples/ftrace/ftrace-ops.c @@ -12,7 +12,7 @@ * Arbitrary large value chosen to be sufficiently large to minimize noise= but * sufficiently small to complete quickly. */ -unsigned int nr_function_calls =3D 100000; +static unsigned int nr_function_calls =3D 100000; module_param(nr_function_calls, uint, 0); MODULE_PARM_DESC(nr_function_calls, "How many times to call the relevant t= racee"); =20 @@ -21,7 +21,7 @@ MODULE_PARM_DESC(nr_function_calls, "How many times to ca= ll the relevant tracee" * be called directly or whether it's necessary to go via the list func, w= hich * can be significantly more expensive. */ -unsigned int nr_ops_relevant =3D 1; +static unsigned int nr_ops_relevant =3D 1; module_param(nr_ops_relevant, uint, 0); MODULE_PARM_DESC(nr_ops_relevant, "How many ftrace_ops to associate with t= he relevant tracee"); =20 @@ -30,7 +30,7 @@ MODULE_PARM_DESC(nr_ops_relevant, "How many ftrace_ops to= associate with the rel * tracers enabled for distinct functions can force the use of the list fu= nc * and incur overhead for all call sites. */ -unsigned int nr_ops_irrelevant =3D 0; +static unsigned int nr_ops_irrelevant; module_param(nr_ops_irrelevant, uint, 0); MODULE_PARM_DESC(nr_ops_irrelevant, "How many ftrace_ops to associate with= the irrelevant tracee"); =20 @@ -38,15 +38,15 @@ MODULE_PARM_DESC(nr_ops_irrelevant, "How many ftrace_op= s to associate with the i * On architectures with DYNAMIC_FTRACE_WITH_REGS, saving the full pt_regs= can * be more expensive than only saving the minimal necessary regs. */ -bool save_regs =3D false; +static bool save_regs; module_param(save_regs, bool, 0); MODULE_PARM_DESC(save_regs, "Register ops with FTRACE_OPS_FL_SAVE_REGS (sa= ve all registers in the trampoline)"); =20 -bool assist_recursion =3D false; +static bool assist_recursion; module_param(assist_recursion, bool, 0); MODULE_PARM_DESC(assist_reursion, "Register ops with FTRACE_OPS_FL_RECURSI= ON"); =20 -bool assist_rcu =3D false; +static bool assist_rcu; module_param(assist_rcu, bool, 0); MODULE_PARM_DESC(assist_reursion, "Register ops with FTRACE_OPS_FL_RCU"); =20 @@ -55,7 +55,7 @@ MODULE_PARM_DESC(assist_reursion, "Register ops with FTRA= CE_OPS_FL_RCU"); * overhead. Sometimes a consistency check using a more expensive tracer is * desireable. */ -bool check_count =3D false; +static bool check_count; module_param(check_count, bool, 0); MODULE_PARM_DESC(check_count, "Check that tracers are called the expected = number of times\n"); =20 @@ -64,7 +64,7 @@ MODULE_PARM_DESC(check_count, "Check that tracers are cal= led the expected number * runs, but sometimes it can be useful to leave them registered so that t= hey * can be inspected through the tracefs 'enabled_functions' file. */ -bool persist =3D false; +static bool persist; module_param(persist, bool, 0); MODULE_PARM_DESC(persist, "Successfully load module and leave ftrace ops r= egistered after test completes\n"); =20 @@ -114,8 +114,8 @@ static void ops_func_count(unsigned long ip, unsigned l= ong parent_ip, self->count++; } =20 -struct sample_ops *ops_relevant; -struct sample_ops *ops_irrelevant; +static struct sample_ops *ops_relevant; +static struct sample_ops *ops_irrelevant; =20 static struct sample_ops *ops_alloc_init(void *tracee, ftrace_func_t func, unsigned long flags, int nr) @@ -163,8 +163,8 @@ static void ops_check(struct sample_ops *ops, int nr, } } =20 -ftrace_func_t tracer_relevant =3D ops_func_nop; -ftrace_func_t tracer_irrelevant =3D ops_func_nop; +static ftrace_func_t tracer_relevant =3D ops_func_nop; +static ftrace_func_t tracer_irrelevant =3D ops_func_nop; =20 static int __init ftrace_ops_sample_init(void) { --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47FD7C636CC for ; Wed, 8 Feb 2023 01:58:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229699AbjBHB6H (ORCPT ); Tue, 7 Feb 2023 20:58:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbjBHB5h (ORCPT ); Tue, 7 Feb 2023 20:57:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C2A33F28C for ; Tue, 7 Feb 2023 17:57:35 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 24BCEB81B9B for ; Wed, 8 Feb 2023 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF49CC433A0; Wed, 8 Feb 2023 01:57:32 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiF-006dPq-2l; Tue, 07 Feb 2023 20:57:31 -0500 Message-ID: <20230208015731.669243610@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:40 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Tom Zanussi , kernel test robot Subject: [for-next][PATCH 07/11] tracing: Fix trace_event_raw_event_synth() if else statement References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" The test to check if the field is a stack is to be done if it is not a string. But the code had: } if (event->fields[i]->is_stack) { and not } else if (event->fields[i]->is_stack) { which would cause it to always be tested. Worse yet, this also included an "else" statement that was only to be called if the field was not a string and a stack, but this code allows it to be called if it was a string (and not a stack). Also fixed some whitespace issues. Link: https://lore.kernel.org/all/202301302110.mEtNwkBD-lkp@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20230131095237.63e3ca8d@ga= ndalf.local.home Cc: Tom Zanussi Fixes: 00cf3d672a9d ("tracing: Allow synthetic events to pass around stackt= races") Reported-by: kernel test robot Signed-off-by: Steven Rostedt (Google) Acked-by: Masami Hiramatsu (Google) --- kernel/trace/trace_events_synth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_= synth.c index adb630633f31..306c89e0ce55 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -564,8 +564,8 @@ static notrace void trace_event_raw_event_synth(void *_= _data, event->fields[i]->is_dynamic, data_size, &n_u64); data_size +=3D len; /* only dynamic string increments */ - } if (event->fields[i]->is_stack) { - long *stack =3D (long *)(long)var_ref_vals[val_idx]; + } else if (event->fields[i]->is_stack) { + long *stack =3D (long *)(long)var_ref_vals[val_idx]; =20 len =3D trace_stack(entry, event, stack, data_size, &n_u64); --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D9E3C636CC for ; Wed, 8 Feb 2023 01:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbjBHB5y (ORCPT ); Tue, 7 Feb 2023 20:57:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjBHB5f (ORCPT ); Tue, 7 Feb 2023 20:57:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FCF13EFE5 for ; Tue, 7 Feb 2023 17:57:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 96BDD61460 for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 105C7C433AC; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiG-006dQO-0D; Tue, 07 Feb 2023 20:57:32 -0500 Message-ID: <20230208015731.877487562@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:41 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Randy Dunlap , Ross Zwisler Subject: [for-next][PATCH 08/11] tracing: Add creation of instances at boot command line References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" Add kernel command line to add tracing instances. This only creates instances at boot but still does not enable any events to them. Later changes will extend this command line to add enabling of events, filters, and triggers. As well as possibly redirecting trace_printk()! Link: https://lkml.kernel.org/r/20230207173026.186210158@goodmis.org Cc: Randy Dunlap Cc: Masami Hiramatsu Cc: Andrew Morton Reviewed-by: Ross Zwisler Signed-off-by: Steven Rostedt (Google) --- .../admin-guide/kernel-parameters.txt | 6 +++ kernel/trace/trace.c | 50 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 6cfa6e3996cf..9545da5ed849 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6272,6 +6272,12 @@ comma-separated list of trace events to enable. See also Documentation/trace/events.rst =20 + trace_instance=3D[instance-info] + [FTRACE] Create a ring buffer instance early in boot up. + This will be listed in: + + /sys/kernel/tracing/instances + trace_options=3D[option-list] [FTRACE] Enable or disable tracer options at boot. The option-list is a comma delimited list of options diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b90eecd27dfc..863716fcca49 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -49,6 +49,8 @@ #include #include =20 +#include /* COMMAND_LINE_SIZE */ + #include "trace.h" #include "trace_output.h" =20 @@ -186,6 +188,9 @@ static char *default_bootup_tracer; static bool allocate_snapshot; static bool snapshot_at_boot; =20 +static char boot_instance_info[COMMAND_LINE_SIZE] __initdata; +static int boot_instance_index; + static int __init set_cmdline_ftrace(char *str) { strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); @@ -239,6 +244,23 @@ static int __init boot_snapshot(char *str) __setup("ftrace_boot_snapshot", boot_snapshot); =20 =20 +static int __init boot_instance(char *str) +{ + char *slot =3D boot_instance_info + boot_instance_index; + int left =3D sizeof(boot_instance_info) - boot_instance_index; + int ret; + + if (strlen(str) >=3D left) + return -1; + + ret =3D snprintf(slot, left, "%s\t", str); + boot_instance_index +=3D ret; + + return 1; +} +__setup("trace_instance=3D", boot_instance); + + static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; =20 static int __init set_trace_boot_options(char *str) @@ -10144,6 +10166,31 @@ ssize_t trace_parse_run_command(struct file *file,= const char __user *buffer, return ret; } =20 +__init static void enable_instances(void) +{ + struct trace_array *tr; + char *curr_str; + char *str; + char *tok; + + /* A tab is always appended */ + boot_instance_info[boot_instance_index - 1] =3D '\0'; + str =3D boot_instance_info; + + while ((curr_str =3D strsep(&str, "\t"))) { + + tok =3D strsep(&curr_str, ","); + + tr =3D trace_array_get_by_name(tok); + if (!tr) { + pr_warn("Failed to create instance buffer %s\n", curr_str); + continue; + } + /* Allow user space to delete it */ + trace_array_put(tr); + } +} + __init static int tracer_alloc_buffers(void) { int ring_buf_size; @@ -10302,6 +10349,9 @@ void __init early_trace_init(void) void __init trace_init(void) { trace_event_init(); + + if (boot_instance_index) + enable_instances(); } =20 __init static void clear_boot_tracer(void) --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03DE3C636CD for ; Wed, 8 Feb 2023 01:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjBHB5u (ORCPT ); Tue, 7 Feb 2023 20:57:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229774AbjBHB5f (ORCPT ); Tue, 7 Feb 2023 20:57:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6F263E606 for ; Tue, 7 Feb 2023 17:57:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 63DE66148D for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EB8BC433EF; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiG-006dQy-0s; Tue, 07 Feb 2023 20:57:32 -0500 Message-ID: <20230208015732.087113146@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:42 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Ross Zwisler Subject: [for-next][PATCH 09/11] tracing: Add enabling of events to boot instances References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" Add the format of: trace_instance=3Dfoo,sched:sched_switch,irq_handler_entry,initcall That will create the "foo" instance and enable the sched_switch event (here were the "sched" system is explicitly specified), the irq_handler_entry event, and all events under the system initcall. Link: https://lkml.kernel.org/r/20230207173026.386114535@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Reviewed-by: Ross Zwisler Signed-off-by: Steven Rostedt (Google) --- Documentation/admin-guide/kernel-parameters.txt | 14 ++++++++++++++ kernel/trace/trace.c | 4 ++++ kernel/trace/trace.h | 2 ++ kernel/trace/trace_events.c | 9 ++++----- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 9545da5ed849..40304dc3d319 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6278,6 +6278,20 @@ =20 /sys/kernel/tracing/instances =20 + Events can be enabled at the time the instance is created + via: + + trace_instance=3D,:,: + + Note, the ":" portion is optional if the event is + unique. + + trace_instance=3Dfoo,sched:sched_switch,irq_handler_entry,initcall + + will enable the "sched_switch" event (note, the "sched:" is optional, a= nd + the same thing would happen if it was left off). The irq_handler_entry + event, and all events under the "initcall" system. + trace_options=3D[option-list] [FTRACE] Enable or disable tracer options at boot. The option-list is a comma delimited list of options diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 863716fcca49..5b16af9e7d30 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -10188,6 +10188,10 @@ __init static void enable_instances(void) } /* Allow user space to delete it */ trace_array_put(tr); + + while ((tok =3D strsep(&curr_str, ","))) { + early_enable_events(tr, tok, true); + } } } =20 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index d16929dd0f08..f10bf804dd2b 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1334,6 +1334,8 @@ DECLARE_PER_CPU(int, trace_buffered_event_cnt); void trace_buffered_event_disable(void); void trace_buffered_event_enable(void); =20 +void early_enable_events(struct trace_array *tr, char *buf, bool disable_f= irst); + static inline void __trace_event_discard_commit(struct trace_buffer *buffer, struct ring_buffer_event *event) diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index b07931ad97de..cf3fd74fa675 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -3750,10 +3750,9 @@ static __init int event_trace_memsetup(void) return 0; } =20 -static __init void -early_enable_events(struct trace_array *tr, bool disable_first) +__init void +early_enable_events(struct trace_array *tr, char *buf, bool disable_first) { - char *buf =3D bootup_event_buf; char *token; int ret; =20 @@ -3806,7 +3805,7 @@ static __init int event_trace_enable(void) */ __trace_early_add_events(tr); =20 - early_enable_events(tr, false); + early_enable_events(tr, bootup_event_buf, false); =20 trace_printk_start_comm(); =20 @@ -3834,7 +3833,7 @@ static __init int event_trace_enable_again(void) if (!tr) return -ENODEV; =20 - early_enable_events(tr, true); + early_enable_events(tr, bootup_event_buf, true); =20 return 0; } --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F35DC636CC for ; Wed, 8 Feb 2023 01:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjBHB6O (ORCPT ); Tue, 7 Feb 2023 20:58:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbjBHB5h (ORCPT ); Tue, 7 Feb 2023 20:57:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04E433E601 for ; Tue, 7 Feb 2023 17:57:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A00ECB81BA2 for ; Wed, 8 Feb 2023 01:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54AE9C433D2; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiG-006dRX-1X; Tue, 07 Feb 2023 20:57:32 -0500 Message-ID: <20230208015732.290763896@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:43 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Ross Zwisler Subject: [for-next][PATCH 10/11] tracing: Add trace_array_puts() to write into instance References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" Add a generic trace_array_puts() that can be used to "trace_puts()" into an allocated trace_array instance. This is just another variant of trace_array_printk(). Link: https://lkml.kernel.org/r/20230207173026.584717290@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Reviewed-by: Ross Zwisler Signed-off-by: Steven Rostedt (Google) --- include/linux/trace.h | 12 ++++++++++++ kernel/trace/trace.c | 27 +++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/include/linux/trace.h b/include/linux/trace.h index 80ffda871749..2a70a447184c 100644 --- a/include/linux/trace.h +++ b/include/linux/trace.h @@ -33,6 +33,18 @@ struct trace_array; int register_ftrace_export(struct trace_export *export); int unregister_ftrace_export(struct trace_export *export); =20 +/** + * trace_array_puts - write a constant string into the trace buffer. + * @tr: The trace array to write to + * @str: The constant string to write + */ +#define trace_array_puts(tr, str) \ + ({ \ + str ? __trace_array_puts(tr, _THIS_IP_, str, strlen(str)) : -1; \ + }) +int __trace_array_puts(struct trace_array *tr, unsigned long ip, + const char *str, int size); + void trace_printk_init_buffers(void); __printf(3, 4) int trace_array_printk(struct trace_array *tr, unsigned long ip, diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 5b16af9e7d30..9918bf7441ed 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1023,13 +1023,8 @@ __buffer_unlock_commit(struct trace_buffer *buffer, = struct ring_buffer_event *ev ring_buffer_unlock_commit(buffer); } =20 -/** - * __trace_puts - write a constant string into the trace buffer. - * @ip: The address of the caller - * @str: The constant string to write - * @size: The size of the string. - */ -int __trace_puts(unsigned long ip, const char *str, int size) +int __trace_array_puts(struct trace_array *tr, unsigned long ip, + const char *str, int size) { struct ring_buffer_event *event; struct trace_buffer *buffer; @@ -1037,7 +1032,7 @@ int __trace_puts(unsigned long ip, const char *str, i= nt size) unsigned int trace_ctx; int alloc; =20 - if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) + if (!(tr->trace_flags & TRACE_ITER_PRINTK)) return 0; =20 if (unlikely(tracing_selftest_running || tracing_disabled)) @@ -1046,7 +1041,7 @@ int __trace_puts(unsigned long ip, const char *str, i= nt size) alloc =3D sizeof(*entry) + size + 2; /* possible \n added */ =20 trace_ctx =3D tracing_gen_ctx(); - buffer =3D global_trace.array_buffer.buffer; + buffer =3D tr->array_buffer.buffer; ring_buffer_nest_start(buffer); event =3D __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, trace_ctx); @@ -1068,11 +1063,23 @@ int __trace_puts(unsigned long ip, const char *str,= int size) entry->buf[size] =3D '\0'; =20 __buffer_unlock_commit(buffer, event); - ftrace_trace_stack(&global_trace, buffer, trace_ctx, 4, NULL); + ftrace_trace_stack(tr, buffer, trace_ctx, 4, NULL); out: ring_buffer_nest_end(buffer); return size; } +EXPORT_SYMBOL_GPL(__trace_array_puts); + +/** + * __trace_puts - write a constant string into the trace buffer. + * @ip: The address of the caller + * @str: The constant string to write + * @size: The size of the string. + */ +int __trace_puts(unsigned long ip, const char *str, int size) +{ + return __trace_array_puts(&global_trace, ip, str, size); +} EXPORT_SYMBOL_GPL(__trace_puts); =20 /** --=20 2.39.1 From nobody Fri Sep 12 18:19:42 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85107C636CD for ; Wed, 8 Feb 2023 01:57:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbjBHB5q (ORCPT ); Tue, 7 Feb 2023 20:57:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbjBHB5f (ORCPT ); Tue, 7 Feb 2023 20:57:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1DF3D901 for ; Tue, 7 Feb 2023 17:57:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C052F60DD1 for ; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0139C433EF; Wed, 8 Feb 2023 01:57:33 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1pPZiG-006dS6-2C; Tue, 07 Feb 2023 20:57:32 -0500 Message-ID: <20230208015732.497961665@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 07 Feb 2023 20:56:44 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Andrew Morton , Ross Zwisler Subject: [for-next][PATCH 11/11] tracing: Allow boot instances to have snapshot buffers References: <20230208015633.791198913@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" Add to ftrace_boot_snapshot, "=3D" name, where the instance will get a snapshot buffer, and will take a snapshot at the end of boot (which will save the boot traces). Link: https://lkml.kernel.org/r/20230207173026.792774721@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Reviewed-by: Ross Zwisler Signed-off-by: Steven Rostedt (Google) --- .../admin-guide/kernel-parameters.txt | 9 +++ kernel/trace/trace.c | 79 +++++++++++++++++-- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 40304dc3d319..7fa1ee4ba910 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1532,6 +1532,15 @@ boot up that is likely to be overridden by user space start up functionality. =20 + Optionally, the snapshot can also be defined for a tracing + instance that was created by the trace_instance=3D command + line parameter. + + trace_instance=3Dfoo,sched_switch ftrace_boot_snapshot=3Dfoo + + The above will cause the "foo" tracing instance to trigger + a snapshot at the end of boot up. + ftrace_dump_on_oops[=3Dorig_cpu] [FTRACE] will dump the trace buffers on oops. If no parameter is passed, ftrace will dump diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 9918bf7441ed..97c88711f270 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -191,6 +191,9 @@ static bool snapshot_at_boot; static char boot_instance_info[COMMAND_LINE_SIZE] __initdata; static int boot_instance_index; =20 +static char boot_snapshot_info[COMMAND_LINE_SIZE] __initdata; +static int boot_snapshot_index; + static int __init set_cmdline_ftrace(char *str) { strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE); @@ -227,9 +230,22 @@ __setup("traceoff_on_warning", stop_trace_on_warning); =20 static int __init boot_alloc_snapshot(char *str) { - allocate_snapshot =3D true; - /* We also need the main ring buffer expanded */ - ring_buffer_expanded =3D true; + char *slot =3D boot_snapshot_info + boot_snapshot_index; + int left =3D sizeof(boot_snapshot_info) - boot_snapshot_index; + int ret; + + if (str[0] =3D=3D '=3D') { + str++; + if (strlen(str) >=3D left) + return -1; + + ret =3D snprintf(slot, left, "%s\t", str); + boot_snapshot_index +=3D ret; + } else { + allocate_snapshot =3D true; + /* We also need the main ring buffer expanded */ + ring_buffer_expanded =3D true; + } return 1; } __setup("alloc_snapshot", boot_alloc_snapshot); @@ -9254,10 +9270,6 @@ static int allocate_trace_buffers(struct trace_array= *tr, int size) } tr->allocated_snapshot =3D allocate_snapshot; =20 - /* - * Only the top level trace array gets its snapshot allocated - * from the kernel command line. - */ allocate_snapshot =3D false; #endif =20 @@ -10173,6 +10185,47 @@ ssize_t trace_parse_run_command(struct file *file,= const char __user *buffer, return ret; } =20 +#ifdef CONFIG_TRACER_MAX_TRACE +__init static bool tr_needs_alloc_snapshot(const char *name) +{ + char *test; + int len =3D strlen(name); + bool ret; + + if (!boot_snapshot_index) + return false; + + if (strncmp(name, boot_snapshot_info, len) =3D=3D 0 && + boot_snapshot_info[len] =3D=3D '\t') + return true; + + test =3D kmalloc(strlen(name) + 3, GFP_KERNEL); + if (!test) + return false; + + sprintf(test, "\t%s\t", name); + ret =3D strstr(boot_snapshot_info, test) =3D=3D NULL; + kfree(test); + return ret; +} + +__init static void do_allocate_snapshot(const char *name) +{ + if (!tr_needs_alloc_snapshot(name)) + return; + + /* + * When allocate_snapshot is set, the next call to + * allocate_trace_buffers() (called by trace_array_get_by_name()) + * will allocate the snapshot buffer. That will alse clear + * this flag. + */ + allocate_snapshot =3D true; +} +#else +static inline void do_allocate_snapshot(const char *name) { } +#endif + __init static void enable_instances(void) { struct trace_array *tr; @@ -10188,6 +10241,9 @@ __init static void enable_instances(void) =20 tok =3D strsep(&curr_str, ","); =20 + if (IS_ENABLED(CONFIG_TRACER_MAX_TRACE)) + do_allocate_snapshot(tok); + tr =3D trace_array_get_by_name(tok); if (!tr) { pr_warn("Failed to create instance buffer %s\n", curr_str); @@ -10335,10 +10391,19 @@ __init static int tracer_alloc_buffers(void) =20 void __init ftrace_boot_snapshot(void) { + struct trace_array *tr; + if (snapshot_at_boot) { tracing_snapshot(); internal_trace_puts("** Boot snapshot taken **\n"); } + + list_for_each_entry(tr, &ftrace_trace_arrays, list) { + if (tr =3D=3D &global_trace) + continue; + trace_array_puts(tr, "** Boot snapshot taken **\n"); + tracing_snapshot_instance(tr); + } } =20 void __init early_trace_init(void) --=20 2.39.1