From patchwork Fri Dec 9 22:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Bristot de Oliveira X-Patchwork-Id: 31942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1015028wrr; Fri, 9 Dec 2022 14:11:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf509IsuQspCtjeImxuhIFDFMgKxOQFt4JPGfdT689FCfViM4M62Jo043lZ4Yi2sVtV7cWz/ X-Received: by 2002:a05:6a20:9f4a:b0:9d:efbf:6618 with SMTP id ml10-20020a056a209f4a00b0009defbf6618mr10291151pzb.38.1670623918384; Fri, 09 Dec 2022 14:11:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670623918; cv=none; d=google.com; s=arc-20160816; b=oiQJQHeoGUeva5H1NOJ6TmYKhDKnlYqVW7CJp5KpbiEzvzqZFpuZpQMHi9Kgd5P23w 2y/n/iyWu1AdypYrAkC6AtPtF6psD/gxZWIzyKumAHFfmEEZuuucWTqH4DJKr8+lFgcc 3ylOAKYaSXC4BvxkMaESuBOm83FGLO4/qbooMPHujMheCM/7AaZsdgCPwHTxoNEzcvfg NodGWRHroX8YLV/e+5gumRHjbGQys3LRp7D8Rt9qaVsGrFW5cxgmKe5sova+HjSL4Vz/ rHoTAuldJ8xMh3QDLPVa475vB2q78S5aczT1e9J/E4fq9F6wpDfdmY8ULEh59/WlPd49 1zqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7W9hR3TwLnFizMpkGOUUXjdVHfl1mur5UhYGtIvGECQ=; b=y3ob8rSIjffbz/HQrA9WhndbULB3PNxRAKJM5Su6SX05s2uRi+plwBZGFF/vsgC8oz 2vjqOuCQiL0h5nnXs1m0VIMBbbtnA+QOODQ977OXNrjn4S6STCgMKTzSo4axnm5OPnir R2umgPIlyb0mkC3iENJyzEKKZH5ZGNfwfp3tkh5mr9w+wOM2XXDo+NZa2mxcpCRa3YsG t/i6VOX7xOw/rIQoAkJSEnpbjurxuQfHgqM4N1uBYc1JpgdQaGOW4FQmIdm/a7VG2c/o 3MVB/joy/b3FGCoZlSMdj3BuGszGfX8HCNpE8o4Ncx+MYBoLkWwB5KYyQEDpws8gkHHn rUfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MrSjF7YE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x70-20020a638649000000b0046f6afe556bsi2552213pgd.651.2022.12.09.14.11.41; Fri, 09 Dec 2022 14:11:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MrSjF7YE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbiLIWHH (ORCPT + 99 others); Fri, 9 Dec 2022 17:07:07 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751776145555593906?= X-GMAIL-MSGID: =?utf-8?q?1751776145555593906?= 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 = 0, OSN_WORKLOAD, OSN_PANIC_ON_STOP, + OSN_PREEMPT_DISABLE, + OSN_IRQ_DISABLE, OSN_MAX }; -static const char * const osnoise_options_str[OSN_MAX] = { "DEFAULTS", "OSNOISE_WORKLOAD", "PANIC_ON_STOP" }; +static const char * const osnoise_options_str[OSN_MAX] = { + "DEFAULTS", + "OSNOISE_WORKLOAD", + "PANIC_ON_STOP", + "OSNOISE_PREEMPT_DISABLE", + "OSNOISE_IRQ_DISABLE" }; #define OSN_DEFAULT_OPTIONS 0x2 unsigned long osnoise_options = OSN_DEFAULT_OPTIONS; @@ -1308,18 +1315,26 @@ static void notify_new_max_latency(u64 latency) */ static int run_osnoise(void) { + bool disable_irq = test_bit(OSN_IRQ_DISABLE, &osnoise_options); struct osnoise_variables *osn_var = this_cpu_osn_var(); u64 start, sample, last_sample; u64 last_int_count, int_count; s64 noise = 0, max_noise = 0; s64 total, last_total = 0; struct osnoise_sample s; + bool disable_preemption; unsigned int threshold; u64 runtime, stop_in; u64 sum_noise = 0; int hw_count = 0; int ret = -1; + /* + * Disabling preemption is only required if IRQs are enabled, + * and the options is set on. + */ + disable_preemption = !disable_irq && test_bit(OSN_PREEMPT_DISABLE, &osnoise_options); + /* * Considers the current thread as the workload. */ @@ -1335,6 +1350,15 @@ static int run_osnoise(void) */ threshold = tracing_thresh ? : 5000; + /* + * 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(); } /* * 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(); last_sample = sample; last_int_count = int_count; @@ -1450,6 +1479,15 @@ static int run_osnoise(void) */ barrier(); + /* + * Return to the preemptive state. + */ + if (disable_preemption) + preempt_enable(); + + if (disable_irq) + local_irq_enable(); + /* * Save noise info. */