From: Thorsten Blum <blum@kernel.org>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Thorsten Blum <blum@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] powerpc/sysfs: Use NSEC_PER_USEC for wait time conversions
Date: Fri, 18 Sep 2026 23:43:41 +0200 [thread overview]
Message-ID: <20260918214341.271211-3-blum@kernel.org> (raw)
Replace the hard-coded conversion factor 1000 with NSEC_PER_USEC to
clarify the units. Fix the comments describing the conversion from
time-base ticks to nanoseconds. Also rename rem_us to rem_ticks since
the remainder is measured in ticks.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
arch/powerpc/kernel/sysfs.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 329c1690b5ed..2e3ef6df8837 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -6,6 +6,7 @@
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/sysfs.h>
+#include <linux/time64.h>
#include <linux/export.h>
#include <linux/nodemask.h>
#include <linux/cpumask.h>
@@ -245,10 +246,10 @@ static unsigned int get_idle_ticks_bit(u64 ns)
{
u64 cycle;
- if (ns >= 10000)
- cycle = div_u64(ns + 500, 1000) * tb_ticks_per_usec;
+ if (ns >= 10 * NSEC_PER_USEC)
+ cycle = div_u64(ns + NSEC_PER_USEC / 2, NSEC_PER_USEC) * tb_ticks_per_usec;
else
- cycle = div_u64(ns * tb_ticks_per_usec, 1000);
+ cycle = div_u64(ns * tb_ticks_per_usec, NSEC_PER_USEC);
if (!cycle)
return 0;
@@ -324,15 +325,15 @@ static ssize_t show_pw20_wait_time(struct device *dev,
PWRMGTCR0_PW20_ENT_SHIFT;
tb_cycle = (tb_cycle << (MAX_BIT - value + 1));
- /* convert ms to ns */
- if (tb_ticks_per_usec > 1000) {
- time = div_u64(tb_cycle, tb_ticks_per_usec / 1000);
+ /* Convert time-base ticks to ns */
+ if (tb_ticks_per_usec > NSEC_PER_USEC) {
+ time = div_u64(tb_cycle, tb_ticks_per_usec / NSEC_PER_USEC);
} else {
- u32 rem_us;
+ u32 rem_ticks;
- time = div_u64_rem(tb_cycle, tb_ticks_per_usec,
- &rem_us);
- time = time * 1000 + rem_us * 1000 / tb_ticks_per_usec;
+ time = div_u64_rem(tb_cycle, tb_ticks_per_usec, &rem_ticks);
+ time *= NSEC_PER_USEC;
+ time += rem_ticks * NSEC_PER_USEC / tb_ticks_per_usec;
}
} else {
time = pw20_wt;
@@ -446,15 +447,15 @@ static ssize_t show_altivec_idle_wait_time(struct device *dev,
PWRMGTCR0_AV_IDLE_CNT_SHIFT;
tb_cycle = (tb_cycle << (MAX_BIT - value + 1));
- /* convert ms to ns */
- if (tb_ticks_per_usec > 1000) {
- time = div_u64(tb_cycle, tb_ticks_per_usec / 1000);
+ /* Convert time-base ticks to ns */
+ if (tb_ticks_per_usec > NSEC_PER_USEC) {
+ time = div_u64(tb_cycle, tb_ticks_per_usec / NSEC_PER_USEC);
} else {
- u32 rem_us;
+ u32 rem_ticks;
- time = div_u64_rem(tb_cycle, tb_ticks_per_usec,
- &rem_us);
- time = time * 1000 + rem_us * 1000 / tb_ticks_per_usec;
+ time = div_u64_rem(tb_cycle, tb_ticks_per_usec, &rem_ticks);
+ time *= NSEC_PER_USEC;
+ time += rem_ticks * NSEC_PER_USEC / tb_ticks_per_usec;
}
} else {
time = altivec_idle_wt;
reply other threads:[~2026-09-18 21:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260918214341.271211-3-blum@kernel.org \
--to=blum@kernel.org \
--cc=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=sshegde@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®