Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp899439pxp; Wed, 16 Mar 2022 20:36:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrZ6FrZhaBKUymBACVNo1uoG/9iFM+2jB0c3ta/Y6vZ/+LeSrCgvMq+4ALABg03RBTLJZ5 X-Received: by 2002:a05:6a00:1349:b0:4f7:68db:5e3a with SMTP id k9-20020a056a00134900b004f768db5e3amr2777089pfu.51.1647488198718; Wed, 16 Mar 2022 20:36:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647488198; cv=none; d=google.com; s=arc-20160816; b=lvcp5JiCBa06jVqrdEiEeGfo8gdXZrgjD0WX6hY6Ye3Hq1oNb2518rLTO66+Yg4mt4 ZKf+mV7uekuO25o8FcyTZ5q8+tjel/hFFwvhIlz3/HKZ21iu0HavDypuVy69gMdSr+N0 j5ydEfnCE076pWOjNk3us4RqHFNnPCslREkI/WvrGRaML6YXTwIi2fErgSEwpW+WUEQ6 TNju+y4Vmzvp4AfDCE5fYXDwdqeXOxIokBrM1sn9Z68rnPLpb5DlDgNBQyCU1DHgA66H mFnGUIxlrojCDPFMzPMV+EhINsdFX2Do4pqMOQjsuk0+7vLpHsQjSxeNjr8UDaHwDxhI oX3g== 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=CA6RqyFpGEDSCkeuRCljch94Yn0N/wuDfDFxEJtHYYQ=; b=A5D6N1p+p09wFTe+wfAza0SGx9Nhd010nulJq9VkYMHiffdezgPl7HnJjsTa536Ll+ zK/cLeJ1OnQX1eliu8qPBiVHEO65H+dbfFSC03Nn4m8yBoFfElHHFG0mq0rziCZ3B5ZA tRhEFKcsOsW81vERMz3UEaai9RH9naqbOeWf3g3xh5qJuXhO16/2VVsAov2e0kJDOrOv BHEo1OBU6zWvLT8odAlLPXn40HlBBlSew+BKX8zEzM5TTYu0ttKhyqf4gR8ZYy2t3Foh myUCn/5i3MDQumGWlSWiC6arSCPV6bLSs91g4gvQ2FxIytuQOEazkjDdQBXGfjFa0DdX XT2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NtiqJ63s; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k1-20020a637b41000000b003816043f0b4si891939pgn.681.2022.03.16.20.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:36:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NtiqJ63s; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF18553B5B; Wed, 16 Mar 2022 20:32:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242033AbiCNM2q (ORCPT + 99 others); Mon, 14 Mar 2022 08:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243626AbiCNMVF (ORCPT ); Mon, 14 Mar 2022 08:21:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B5F54FA5; Mon, 14 Mar 2022 05:16:30 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 86EF7608C4; Mon, 14 Mar 2022 12:16:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90AF8C340E9; Mon, 14 Mar 2022 12:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647260190; bh=dVGoPrrWRTVHA4L6rhMCbLqZZdospTvDe05WnMPVvFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NtiqJ63sYxe1yOsuMCUs1nSeZ8aGGyhCuZn+BK99bTn6IxYJ8Yo9q2PZo8sd5xTNG 9o82BkcBav8kZ9REmriEmfrXwP6m+KZXkV1mPu3kdel+OFBBgyiNOaihbUDFaPAVYi XPRNYFs/gwxnL+V4295A0KMozaXsS/nPdrUQr4uE= 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.16 082/121] tracing/osnoise: Make osnoise_main to sleep for microseconds Date: Mon, 14 Mar 2022 12:54:25 +0100 Message-Id: <20220314112746.409684021@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112744.120491875@linuxfoundation.org> References: <20220314112744.120491875@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=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 b58674e8644a..58c788b0ca27 100644 --- a/kernel/trace/trace_osnoise.c +++ b/kernel/trace/trace_osnoise.c @@ -1437,6 +1437,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 * @@ -1445,30 +1476,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