Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3853937pxp; Tue, 15 Mar 2022 07:34:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfUeDizgnn0dr27sLnbgFgVGXdSGh2X4LuZekAH8PpBPlUgNefdPpI/FrwHhQedTb9IFGM X-Received: by 2002:a17:902:e848:b0:151:e3a5:b609 with SMTP id t8-20020a170902e84800b00151e3a5b609mr28224257plg.137.1647354842259; Tue, 15 Mar 2022 07:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647354842; cv=none; d=google.com; s=arc-20160816; b=jlmvtrLcS1PDa/t3MY9orvAgvajP5g5xmfEuoeYphbVHSy7HpDjzdX0CprklUfI97d 2CvIME6K3dspBYi0xPkXLUGFZvLnhZMTsTjqa7cibeJmNQZfsOU6Z2d9C0jH07P4XPzo 58Bzl1fGWbX+ALqtZ1W6G7iAJHdpj5YpQ9NraDqmz7GDwDrrMecaHqx69i+vsk4NzfC7 zGv1zf5/fVI5vQEFpykF1Jaljr5YSi++8vbOu2AK4vKT3rqprXrq5K3HbMb4xfWDUw14 4xuVhcazR+SGSggtPhJNIsqRYRTnFdcX2/PgABqJL8I7FiAGKHMXz+do4jUULZrX/atw vAbg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2kAF+z2SAC+J5LJd+gZ0/ycsf1zb2mYK8ONmihN7Qys=; b=irFgHL+GmJqHcaP7n9NNgFj72h6i9kg8oAh1zN7zKkKKxGjdqQ+27VaXE3ue+WFKux 30o5GTik4xD/SUhYqoXa/zms2XqYVhuF63h9JDOT3SjLzF6tGov1+aqSQQWtPdO/0ubu w0NgfQfdUUDywXoySveGeYquvg2ORN+dqRUjxgR0FQUEdi3v+N6DjMRCKNHsOg3pE2oQ 97/t5tMuLwnDeDu2ikGgiofm+4Aw4uEAf8KKAp2a9AhwpA5cQDXd269a/DbEXI4dLjWC hgCTHyM2s9GZoSYryHX4xFgg3uC4J3bfLfS2lt+hEch2omYV0JzlT7ipzAhpOZBNgxuk c71A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hQNJMXYk; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r204-20020a632bd5000000b003804720138fsi17176698pgr.227.2022.03.15.07.33.48; Tue, 15 Mar 2022 07:34:02 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=hQNJMXYk; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241262AbiCNMNH (ORCPT + 99 others); Mon, 14 Mar 2022 08:13:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242484AbiCNMKD (ORCPT ); Mon, 14 Mar 2022 08:10:03 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D4EC2018A; Mon, 14 Mar 2022 05:08:37 -0700 (PDT) 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 sin.source.kernel.org (Postfix) with ESMTPS id 7A0FDCE1268; Mon, 14 Mar 2022 12:08:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFB24C340EC; Mon, 14 Mar 2022 12:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259713; bh=vIPXqAjDyhWI4A6J1UsnGGCoO+/UCR49RtAaOfr2sCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQNJMXYk3pmXMOo2MDQawVqGY0V7xiWkAXA0S10EC56zwqoa1P4d9E3xBEU1DtKru 5aUOHPH8deDZsnTpWZHvIxCQULdplPic/uooXOgrkkE3bR+TXCtgBmztBh6puSWi6c dSo+xHRq1n2pp+UaE57RXI6Lhle03BEmmizYEuhg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Daniel Bristot de Oliveira , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.15 071/110] tracing/osnoise: Make osnoise_main to sleep for microseconds Date: Mon, 14 Mar 2022 12:54:13 +0100 Message-Id: <20220314112745.017200899@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112743.029192918@linuxfoundation.org> References: <20220314112743.029192918@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 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,T_SCC_BODY_TEXT_LINE 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 From: Daniel Bristot de Oliveira [ Upstream commit dd990352f01ee9a6c6eee152e5d11c021caccfe4 ] osnoise's runtime and period are in the microseconds scale, but it is currently sleeping in the millisecond's scale. This behavior roots in the usage of hwlat as the skeleton for osnoise. Make osnoise to sleep in the microseconds scale. Also, move the sleep to a specialized function. Link: https://lkml.kernel.org/r/302aa6c7bdf2d131719b22901905e9da122a11b2.1645197336.git.bristot@kernel.org Cc: Ingo Molnar Signed-off-by: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- kernel/trace/trace_osnoise.c | 53 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c index 65a518649997..fc491d0aee5a 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -1249,6 +1249,37 @@ static int run_osnoise(void) static struct cpumask osnoise_cpumask; static struct cpumask save_cpumask; +/* + * osnoise_sleep - sleep until the next period + */ +static void osnoise_sleep(void) +{ + u64 interval; + ktime_t wake_time; + + mutex_lock(&interface_lock); + interval = osnoise_data.sample_period - osnoise_data.sample_runtime; + mutex_unlock(&interface_lock); + + /* + * differently from hwlat_detector, the osnoise tracer can run + * without a pause because preemption is on. + */ + if (!interval) { + /* Let synchronize_rcu_tasks() make progress */ + cond_resched_tasks_rcu_qs(); + return; + } + + wake_time = ktime_add_us(ktime_get(), interval); + __set_current_state(TASK_INTERRUPTIBLE); + + while (schedule_hrtimeout_range(&wake_time, 0, HRTIMER_MODE_ABS)) { + if (kthread_should_stop()) + break; + } +} + /* * osnoise_main - The osnoise detection kernel thread * @@ -1257,30 +1288,10 @@ static struct cpumask save_cpumask; */ static int osnoise_main(void *data) { - u64 interval; while (!kthread_should_stop()) { - run_osnoise(); - - mutex_lock(&interface_lock); - interval = osnoise_data.sample_period - osnoise_data.sample_runtime; - mutex_unlock(&interface_lock); - - do_div(interval, USEC_PER_MSEC); - - /* - * differently from hwlat_detector, the osnoise tracer can run - * without a pause because preemption is on. - */ - if (interval < 1) { - /* Let synchronize_rcu_tasks() make progress */ - cond_resched_tasks_rcu_qs(); - continue; - } - - if (msleep_interruptible(interval)) - break; + osnoise_sleep(); } return 0; -- 2.34.1