From mboxrd@z Thu Jan 1 00:00:00 1970 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 CD0A7C433EF for ; Sun, 5 Jun 2022 13:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344208AbiFENxl (ORCPT ); Sun, 5 Jun 2022 09:53:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243995AbiFENx3 (ORCPT ); Sun, 5 Jun 2022 09:53:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C23F270E; Sun, 5 Jun 2022 06:53:28 -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 ABF4D60F9C; Sun, 5 Jun 2022 13:53:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80EC9C385A5; Sun, 5 Jun 2022 13:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654437207; bh=AU8d+kJilhAOhDFwChzPGNMoONnIHkfPe6ac7uyzwz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQthc7djJ/GZqGWprn++T8ltJBz1Dq08c2wn/OV+UQmHug0MjLI/yS+nqjbg6z+oj T2oXQp9AkdbwgLn0YWQOqmEJUVSAXCmm8n7Js1h17ggFvfesd1CdtWAEkE3w1fD3J4 uCESmPeN+dWtP+E9tPPMP/MbVqHPzLtL/AEE7XzgOBIctKYaLKi3itkVKC367LQEGe w5390aWuYcFy/tsnNVLd03eQvFQRHZv/2WUj24JtK+5rt2OmDMZuPyvlS5SDxLQkRw emKdxS8LbCJeQcr9DPHIla9WDtbtHXPI4gRhxzcKzvKEFDpituZDAlFoT5erW2lYMD XWgQzjNFINmWg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Maciej W. Rozycki" , Thomas Gleixner , John Stultz , Sasha Levin Subject: [PATCH MANUALSEL 5.18 3/7] time/sched_clock: Round the frequency reported to nearest rather than down Date: Sun, 5 Jun 2022 09:53:11 -0400 Message-Id: <20220605135320.61247-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220605135320.61247-1-sashal@kernel.org> References: <20220605135320.61247-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Maciej W. Rozycki" [ Upstream commit 92067440f1311dfa4d77b57a9da6b3706f5da32e ] The frequency reported for clock sources are rounded down, which gives misleading figures, e.g.: I/O ASIC clock frequency 24999480Hz sched_clock: 32 bits at 24MHz, resolution 40ns, wraps every 85901132779ns MIPS counter frequency 59998512Hz sched_clock: 32 bits at 59MHz, resolution 16ns, wraps every 35792281591ns Rounding to nearest is more adequate: I/O ASIC clock frequency 24999664Hz sched_clock: 32 bits at 25MHz, resolution 40ns, wraps every 85900499947ns MIPS counter frequency 59999728Hz sched_clock: 32 bits at 60MHz, resolution 16ns, wraps every 35791556599ns Signed-off-by: Maciej W. Rozycki Signed-off-by: Thomas Gleixner Acked-by: John Stultz Link: https://lore.kernel.org/r/alpine.DEB.2.21.2204240055590.9383@angie.orcam.me.uk Signed-off-by: Sasha Levin --- kernel/time/sched_clock.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index b1b9b12899f5..ee07f3ac1e5b 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -199,11 +200,11 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate) r = rate; if (r >= 4000000) { - r /= 1000000; + r = DIV_ROUND_CLOSEST(r, 1000000); r_unit = 'M'; } else { if (r >= 1000) { - r /= 1000; + r = DIV_ROUND_CLOSEST(r, 1000); r_unit = 'k'; } else { r_unit = ' '; -- 2.35.1