From nobody Thu Sep 18 04:16:34 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 8D58CC04FDE for ; Fri, 9 Dec 2022 22:07:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbiLIWHD (ORCPT ); Fri, 9 Dec 2022 17:07:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbiLIWGi (ORCPT ); Fri, 9 Dec 2022 17:06:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A80AA5DE8; Fri, 9 Dec 2022 14:06:07 -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 2024FB8293F; Fri, 9 Dec 2022 22:06:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E5C5C433F0; Fri, 9 Dec 2022 22:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670623564; bh=UofQ2Om5TKKPZw19SG+8wKH8TntN+ojXWrOiFhpkAis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ObcHETnV404P8FdK6dcZ3k8cwnJHWj53iKrb8qBFv+KV9vFx/MNCY2VlnIl83fRKX GkKtSBij7bMDEosyNGwu6dQD9rFbWG8/zfZ9xnYxm3uSF+DjZ1AimX5Pf1ABAConF9 uoaqG0+vlQqK37Vmywu34eMmUPsWdgcX6EBf3ZK/DWcZu1niXdTyKMeSB6pkrCsbNj yC2M4FAI3ea5riv5qgcHam52q6lcjNFL0KfpZ8zTUH9mzcz5duwFKhmmkj7nIorpZL O/rDF/8H8ALoiCLsi17zMbOPm/R9IV5fXqIOu11020UPUk6hylNouVg7cHsdsLim3t 0yLa1Eot8ov1w== From: Daniel Bristot de Oliveira To: Daniel Bristot de Oliveira , Steven Rostedt Cc: Masami Hiramatsu , Jonathan Corbet , Juri Lelli , Clark Williams , Bagas Sanjaya , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V5 1/3] tracing/osnoise: Add PANIC_ON_STOP option Date: Fri, 9 Dec 2022 23:05:52 +0100 Message-Id: <249ce4287c6725543e6db845a6e0df621dc67db5.1670623111.git.bristot@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Often the latency observed in a CPU is not caused by the work being done in the CPU itself, but by work done on another CPU that causes the hardware to stall all CPUs. In this case, it is interesting to know what is happening on ALL CPUs, and the best way to do this is via crash dump analysis. Add the PANIC_ON_STOP option to osnoise/timerlat tracers. The default behavior is having this option off. When enabled by the user, the system will panic after hitting a stop tracing condition. This option was motivated by a real scenario that Juri Lelli and I were debugging. Cc: Juri Lelli Cc: Daniel Bristot de Oliveira Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira --- kernel/trace/trace_osnoise.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 3f10dd1f2f1c..801eba0b5cf8 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -54,10 +54,11 @@ enum osnoise_options_index { OSN_DEFAULTS =3D 0, OSN_WORKLOAD, + OSN_PANIC_ON_STOP, OSN_MAX }; =20 -static const char * const osnoise_options_str[OSN_MAX] =3D { "DEFAULTS", "= OSNOISE_WORKLOAD" }; +static const char * const osnoise_options_str[OSN_MAX] =3D { "DEFAULTS", "= OSNOISE_WORKLOAD", "PANIC_ON_STOP" }; =20 #define OSN_DEFAULT_OPTIONS 0x2 unsigned long osnoise_options =3D OSN_DEFAULT_OPTIONS; @@ -1270,6 +1271,9 @@ static __always_inline void osnoise_stop_tracing(void) trace_array_printk_buf(tr->array_buffer.buffer, _THIS_IP_, "stop tracing hit on cpu %d\n", smp_processor_id()); =20 + if (test_bit(OSN_PANIC_ON_STOP, &osnoise_options)) + panic("tracer hit stop condition on CPU %d\n", smp_processor_id()); + tracer_tracing_off(tr); } rcu_read_unlock(); --=20 2.32.0 From nobody Thu Sep 18 04:16:34 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 8650EC4332F for ; Fri, 9 Dec 2022 22:07:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229478AbiLIWHI (ORCPT ); Fri, 9 Dec 2022 17:07:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbiLIWGi (ORCPT ); Fri, 9 Dec 2022 17:06:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4083AACB27; Fri, 9 Dec 2022 14:06:08 -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 D131A6235D; Fri, 9 Dec 2022 22:06:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 310D2C433EF; Fri, 9 Dec 2022 22:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670623567; bh=bcPgIdyubZd9xGJuhapfIfVeZ0xI08zpb8W1mTeeYmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MrSjF7YEMuyND1um5ybz00sDB6QdM+Cs1oZfOT68LmdDw8gNzmWWQTwF4gmhZk61m 1ZKmO7UpoBt7QITZ4qDC+JyMKEvkz9DOTkt+lIkYbamtVnTIL4eu545MOht3+iG739 8cLz6kU++5PvQwHm75WioSHx6KIfQVNHICERq/oJAFurOcql1RpzZm7mgM/+pi7Sg+ jtWipNnaWKduj3NUHkhN3A1j6cLhiDl4w4/cQOLShiiZAYDjBKURKRvilwbtfqT+pD QRaW4NzIz+vg/QdApjK8pSc5oqlG6OoF9yzawav8J59az0nn7XEgNWobokxRN4j/D6 ybP6chddlwziQ== From: Daniel Bristot de Oliveira To: Daniel Bristot de Oliveira , Steven Rostedt Cc: Masami Hiramatsu , Jonathan Corbet , Juri Lelli , Clark Williams , Bagas Sanjaya , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V5 2/3] tracing/osnoise: Add preempt and/or irq disabled options Date: Fri, 9 Dec 2022 23:05:53 +0100 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The osnoise workload runs with preemption and IRQs enabled in such a way as to allow all sorts of noise to disturb osnoise's execution. hwlat tracer has a similar workload but works with irq disabled, allowing only NMIs and the hardware to generate noise. While thinking about adding an options file to hwlat tracer to allow the system to panic, and other features I was thinking to add, like having a tracepoint at each noise detection, it came to my mind that is easier to make osnoise and also do hardware latency detection than making hwlat "feature compatible" with osnoise. Other points are: - osnoise already has an independent cpu file. - osnoise has a more intuitive interface, e.g., runtime/period vs. window/width (and people often need help remembering what it is). - osnoise: tracepoints - osnoise stop options - osnoise options file itself Moreover, the user-space side (in rtla) is simplified by reusing the existing osnoise code. Finally, people have been asking me about using osnoise for hw latency detection, and I have to explain that it was sufficient but not necessary. These options make it sufficient and necessary. Adding a Suggested-by Clark, as he often asked me about this possibility. Cc: Suggested-by: Clark Williams Cc: Daniel Bristot de Oliveira Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira --- kernel/trace/trace_osnoise.c | 48 ++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 801eba0b5cf8..4da021d9629c 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -55,10 +55,17 @@ enum osnoise_options_index { OSN_DEFAULTS =3D 0, OSN_WORKLOAD, OSN_PANIC_ON_STOP, + OSN_PREEMPT_DISABLE, + OSN_IRQ_DISABLE, OSN_MAX }; =20 -static const char * const osnoise_options_str[OSN_MAX] =3D { "DEFAULTS", "= OSNOISE_WORKLOAD", "PANIC_ON_STOP" }; +static const char * const osnoise_options_str[OSN_MAX] =3D { + "DEFAULTS", + "OSNOISE_WORKLOAD", + "PANIC_ON_STOP", + "OSNOISE_PREEMPT_DISABLE", + "OSNOISE_IRQ_DISABLE" }; =20 #define OSN_DEFAULT_OPTIONS 0x2 unsigned long osnoise_options =3D OSN_DEFAULT_OPTIONS; @@ -1308,18 +1315,26 @@ static void notify_new_max_latency(u64 latency) */ static int run_osnoise(void) { + bool disable_irq =3D test_bit(OSN_IRQ_DISABLE, &osnoise_options); struct osnoise_variables *osn_var =3D this_cpu_osn_var(); u64 start, sample, last_sample; u64 last_int_count, int_count; s64 noise =3D 0, max_noise =3D 0; s64 total, last_total =3D 0; struct osnoise_sample s; + bool disable_preemption; unsigned int threshold; u64 runtime, stop_in; u64 sum_noise =3D 0; int hw_count =3D 0; int ret =3D -1; =20 + /* + * Disabling preemption is only required if IRQs are enabled, + * and the options is set on. + */ + disable_preemption =3D !disable_irq && test_bit(OSN_PREEMPT_DISABLE, &osn= oise_options); + /* * Considers the current thread as the workload. */ @@ -1335,6 +1350,15 @@ static int run_osnoise(void) */ threshold =3D tracing_thresh ? : 5000; =20 + /* + * Apply PREEMPT and IRQ disabled options. + */ + if (disable_irq) + local_irq_disable(); + + if (disable_preemption) + preempt_disable(); + /* * Make sure NMIs see sampling first */ @@ -1422,16 +1446,21 @@ static int run_osnoise(void) * cond_resched() */ if (IS_ENABLED(CONFIG_PREEMPT_RCU)) { - local_irq_disable(); + if (!disable_irq) + local_irq_disable(); + rcu_momentary_dyntick_idle(); - local_irq_enable(); + + if (!disable_irq) + local_irq_enable(); } =20 /* * For the non-preemptive kernel config: let threads runs, if - * they so wish. + * they so wish, unless set not do to so. */ - cond_resched(); + if (!disable_irq && !disable_preemption) + cond_resched(); =20 last_sample =3D sample; last_int_count =3D int_count; @@ -1450,6 +1479,15 @@ static int run_osnoise(void) */ barrier(); =20 + /* + * Return to the preemptive state. + */ + if (disable_preemption) + preempt_enable(); + + if (disable_irq) + local_irq_enable(); + /* * Save noise info. */ --=20 2.32.0 From nobody Thu Sep 18 04:16:34 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 556AEC4332F for ; Fri, 9 Dec 2022 22:07:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229568AbiLIWHN (ORCPT ); Fri, 9 Dec 2022 17:07:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbiLIWGi (ORCPT ); Fri, 9 Dec 2022 17:06:38 -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 CEA72BB0ED; Fri, 9 Dec 2022 14:06:10 -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 68A4B62370; Fri, 9 Dec 2022 22:06:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6F0FC433D2; Fri, 9 Dec 2022 22:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670623569; bh=13oCDAnt7f3rlE9DpU68cvHeHJUi8m64xEllotvf6ZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gmQSdEO+0XTok1DL97OAd+O33z9ldHg0Mc3wdZy6DDVpRFbmqa2P+Lu3LrpZRF5y2 30Fcj1wrkIWjSnBh/PEe0JUjzfmGCI0FSITsU7X+JZMP4bRrGcceUxSFHFTIrzX6oO aTZ6CEiTwHDWq+Vjl243S/0Ux84N1EizjhNKWzpKh2zERTBfwGEhj4+JVoZA7qyMt5 CD58o4vnOvf68dGlvcgMKm39NuoigakSmuJsCVKIYv5b/Z8Bl6a+GZqZz6MQ0hGYGE OFD+bt9nq4BaWHcbNav/ytZqSqJmpHnCjSpJShJYcNT3CEpBgnI4/+5u9o8rjzz0BO 7YemLWYNj1OAg== From: Daniel Bristot de Oliveira To: Daniel Bristot de Oliveira , Steven Rostedt Cc: Masami Hiramatsu , Jonathan Corbet , Juri Lelli , Clark Williams , Bagas Sanjaya , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V5 3/3] Documentation/osnoise: Add osnoise/options documentation Date: Fri, 9 Dec 2022 23:05:54 +0100 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add the documentation about the osnoise/options file, the options, and some additional explanation about the OSNOISE_WORKLOAD option. Cc: Daniel Bristot de Oliveira Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Jonathan Corbet Cc: Bagas Sanjaya Signed-off-by: Daniel Bristot de Oliveira Reviewed-by: Bagas Sanjaya --- Documentation/trace/osnoise-tracer.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/trace/osnoise-tracer.rst b/Documentation/trace/o= snoise-tracer.rst index 3c675ed82b27..f2008e317223 100644 --- a/Documentation/trace/osnoise-tracer.rst +++ b/Documentation/trace/osnoise-tracer.rst @@ -92,8 +92,8 @@ Note that the example above shows a high number of HW noi= se samples. The reason being is that this sample was taken on a virtual machine, and the host interference is detected as a hardware interference. =20 -Tracer options ---------------------- +Tracer Configuration +-------------------- =20 The tracer has a set of options inside the osnoise directory, they are: =20 @@ -115,6 +115,22 @@ The tracer has a set of options inside the osnoise dir= ectory, they are: NO_OSNOISE_WORKLOAD disables the OSNOISE_WORKLOAD option. The special DEAFAULTS option resets all options to the default value. =20 +Tracer Options +-------------- + +The osnoise/options file exposes a set of on/off configuration options for +the osnoise tracer. These options are: + + - DEFAULTS: reset the options to the default value. + - OSNOISE_WORKLOAD: do not dispatch osnoise workload (see dedicated + section below). + - PANIC_ON_STOP: call panic() if the tracer stops. This option serves to + capture a vmcore. + - OSNOISE_PREEMPT_DISABLE: disable preemption while running the osnoise + workload, allowing only IRQ and hardware-related noise. + - OSNOISE_IRQ_DISABLE: disable IRQs while running the osnoise workload, + allowing only NMIs and hardware-related noise, like hwlat tracer. + Additional Tracing ------------------ =20 --=20 2.32.0