From patchwork Wed Nov 23 17:06:23 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: 25090 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2912998wrr; Wed, 23 Nov 2022 09:10:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf76gE3ADGor33Tq6N/uW7Hv5YJcUqnjLOk2kGw7njxjs0VaVVv3ZQtKRQvew/on2ZE3W1Qb X-Received: by 2002:a05:6402:1f14:b0:461:c7ef:b09e with SMTP id b20-20020a0564021f1400b00461c7efb09emr12997801edb.58.1669223459745; Wed, 23 Nov 2022 09:10:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669223459; cv=none; d=google.com; s=arc-20160816; b=WbSQxIKkzKMhRJKyTbjYMLKyJPPRkV30v51sVoJi/Iog6GsXcuVgBS/M9fQM4b9KsX p4obvczjnUS7lGaEFOwYykxb2wO+tFa7QURV+aXQxq4AItYvXwo/w8db6LeU3tYWtmZ0 7BJeIjHypDDSATs7R4wKjKDFB17sp9MedY024g/29pOdwamHrofhBFXcQ2Ws/Mtwk+pT E3dlB3s33ZYXulWBR1zp0xlI3PKWIJtmF+bx0jO2/HBHLUQPG6/IBRFx0IsXm8nTByTn vGcuyTbInhuxaPLy1TowTci5++4xATF3/FAjSq091XQeZsyu47D1WVYFHbg5TgaqJoj0 qJ4g== 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=BbJAr2W841bCQMfMDNDfW8CBKpQGPCwQ5RICHeDwUP4=; b=DLRE+MNmV52fYkzDzpnCE9TsGSLXkoX5iWreSi7NvKJMANWQuI+20Y2D9MyqOyM4gn i1qtDQ0Yf55ZXW5e2IPG+r5yWZBCXKunoFg8+YCtdnj+KZOBCSU1OBTReONb1Msi3QFR mMeFcUNjnJYedVuZVK0FbxlhuPEylTfR/ruzN2eqUOvhGkZWNCNB9Micy459WNRCIpmr jIG/a1zZcW+QRHQ8Psn7V8BzEmjPtdzXjDtZOS2LmhjKz3IF4/yUZoaDOHgniLkZcTpD 6J3/Ma6Rsu/WwR97rfMbT5XzOTJ8/nEz6sGkBVj9TdgaBoO4SuDNx8clbcTnRY0Pch7N J/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Cy9qvLxY; 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 bb13-20020a1709070a0d00b007ae6e307f60si11377001ejc.323.2022.11.23.09.10.30; Wed, 23 Nov 2022 09:10:59 -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=Cy9qvLxY; 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 S238851AbiKWRHb (ORCPT + 99 others); Wed, 23 Nov 2022 12:07:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239020AbiKWRGp (ORCPT ); Wed, 23 Nov 2022 12:06:45 -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 A66EAC4B69; Wed, 23 Nov 2022 09:06:42 -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 456EB61DF7; Wed, 23 Nov 2022 17:06:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2C2EC433D6; Wed, 23 Nov 2022 17:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669223201; bh=572LKrFlwGTVNo7fZjQcd1sMaO3bjlC22vJvxTRspSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cy9qvLxY59+KxQyUyH+9sCX6HVEFqQVPPLH787k/5aUI4w1y1iVKXLv7gJ8lV/FjH JIKLuGm+rugW5eK2RiWgfAzaVnleYP75YhnvLYK4Wym80AmihlZsAyQbgA6dtIYXcl JAHvAmWGY9Iq+DHgsG5n3AQa1CIWCxbzDZbgvxwRyYp5uhtPxNSTY69EKgGEOQFwkB VtTM+spQyjkNlT6lhHs1lW/EGcpYIMt7mpRFiKRBG3niH0UdlQFjglDtcUUD7r5ROG 1dlZQwBRVpqHMsq/XWzc9g3LjLmBf2nnavqQp+Vj74LmaKa0UpKHtvpRdL9STbz6P2 Q9bM3V3r2BdAA== From: Daniel Bristot de Oliveira To: Daniel Bristot de Oliveira , Steven Rostedt Cc: Masami Hiramatsu , Jonathan Corbet , Juri Lelli , Clark Williams , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 5/6] tracing/osnoise: Add preempt and/or irq disabled options Date: Wed, 23 Nov 2022 18:06:23 +0100 Message-Id: <78ab591cbda81b833578ee69e34c90f16438102a.1669115208.git.bristot@kernel.org> 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?1750307658245186096?= X-GMAIL-MSGID: =?utf-8?q?1750307658245186096?= 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 | 40 +++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 801eba0b5cf8..14b7f4092982 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,6 +1315,8 @@ static void notify_new_max_latency(u64 latency) */ static int run_osnoise(void) { + bool preempt_disable = test_bit(OSN_PREEMPT_DISABLE, &osnoise_options); + bool irq_disable = 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; @@ -1335,6 +1344,14 @@ static int run_osnoise(void) */ threshold = tracing_thresh ? : 5000; + /* + * IRQ disable also implies in preempt disable. + */ + if (irq_disable) + local_irq_disable(); + else if (preempt_disable) + preempt_disable(); + /* * Make sure NMIs see sampling first */ @@ -1422,16 +1439,21 @@ static int run_osnoise(void) * cond_resched() */ if (IS_ENABLED(CONFIG_PREEMPT_RCU)) { - local_irq_disable(); + if (!irq_disable) + local_irq_disable(); + rcu_momentary_dyntick_idle(); - local_irq_enable(); + + if (!irq_disable) + 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 (!irq_disable && !preempt_disable) + cond_resched(); last_sample = sample; last_int_count = int_count; @@ -1450,6 +1472,14 @@ static int run_osnoise(void) */ barrier(); + /* + * Return to the preemptive state. + */ + if (irq_disable) + local_irq_enable(); + else if (preempt_disable) + preempt_enable(); + /* * Save noise info. */