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 6D2C2C43334 for ; Sun, 5 Jun 2022 13:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344811AbiFENzh (ORCPT ); Sun, 5 Jun 2022 09:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348954AbiFENzV (ORCPT ); Sun, 5 Jun 2022 09:55:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 303F3EE3F; Sun, 5 Jun 2022 06:55:04 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7C1D5B80DA6; Sun, 5 Jun 2022 13:54:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66A4BC385A5; Sun, 5 Jun 2022 13:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654437295; bh=AU8d+kJilhAOhDFwChzPGNMoONnIHkfPe6ac7uyzwz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/cBv2kBQMpuXXoAZVIrWpJOSNzDUckypBnRgP/5xRACxLcCAlIJGbq5JWqzygMQK 1Gn2l/9f1LErOW48hYKb9Lxm9bJFGB4KIFKsJVtuHczrlfzSeiveLV3zQj2AOlkcNk V3HibJiji3NUKo+PoRbqB6y+NRhAN33t9P67E+UsGbLVWaw1qouq8lwPm/NudtAwqe seWDmCqQnO1+sqZK8QNBpi+9hqELkl/ouYxiiNwV1Lxn2bnY6kqQ/GRGk1Ou+rA8oI /ershiIuMPexbbBV6GrU4K8dM/8Tue60ZbYIdyYMpgEeP6ETr9kHtJvTpsAc/zWX3d BAzRuGCrD6TQw== 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.10 3/5] time/sched_clock: Round the frequency reported to nearest rather than down Date: Sun, 5 Jun 2022 09:54:42 -0400 Message-Id: <20220605135447.61611-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220605135447.61611-1-sashal@kernel.org> References: <20220605135447.61611-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: stable@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