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 73D8BC433EF for ; Sun, 5 Jun 2022 13:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350684AbiFEN4A (ORCPT ); Sun, 5 Jun 2022 09:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344712AbiFENzZ (ORCPT ); Sun, 5 Jun 2022 09:55:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E486D6349; Sun, 5 Jun 2022 06:55:10 -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 1000360FAC; Sun, 5 Jun 2022 13:55:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4AEBC385A5; Sun, 5 Jun 2022 13:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654437309; bh=H6IuwmJUYnY4Pzfom1jIayZM3c3TnXdFIIFUSwgyIpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLF2JqKctVXjVpPWFJmGgBRBndWj65Y+rZdGNSLsPirUiit0EQOiEkyHe3M/LB2oM Ip2WPiJ5G4dtcH7R4luIEI/7gvzd4hf4s1vuu7DpElrpVWt5Dcif70Vci1c3dv0fmE yNmzNktJNU/BPK67JO7mVlaiaOu7hdilmEimeF2aD5b35FdPk4pz6FOAuRYdcldhkc Hzn4KBmYXEwhmXSZJ2qFn+o526HbCMkcKP6JKhZV3TEnB8FeDVc/obTRqkT76rLEyA fF4nuUlIadXTWinX00F/4uNuF1HxSJU4+JEoUrVmxolUKHwRraPyI8bntwKu7BTNjY +zXDm2c9x4OXg== 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.4 2/4] time/sched_clock: Round the frequency reported to nearest rather than down Date: Sun, 5 Jun 2022 09:54:58 -0400 Message-Id: <20220605135503.61690-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220605135503.61690-1-sashal@kernel.org> References: <20220605135503.61690-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 a5538dd76a81..c586b66da0d3 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -213,11 +214,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