[PATCH 4/4] taskstats: use div_u64() for the elapsed time in tgid_stats_add_task()

From: Bradley Morgan

Date: Sat Oct 31 2026 - 20:58:08 EST


tgid_stats_add_task() converts utime and stime with div_u64() and the
elapsed time with do_div(), two ways of doing the same 64-bit divide four
lines apart. do_div() clobbers its first argument, which is the only
reason delta needs a statement of its own. Both end up at a native
divide on 64-bit and at __div64_32() on 32-bit, so this is only about
picking one.

Signed-off-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
---
kernel/taskstats.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 9e11f92216861..2d4ecb9a89a91 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -226,8 +226,7 @@ static void tgid_stats_add_task(struct taskstats *stats,
/* calculate task elapsed time in nsec */
delta = now_ns - tsk->start_time;
/* Convert to micro seconds */
- do_div(delta, NSEC_PER_USEC);
- stats->ac_etime += delta;
+ stats->ac_etime += div_u64(delta, NSEC_PER_USEC);

task_cputime(tsk, &utime, &stime);
stats->ac_utime += div_u64(utime, NSEC_PER_USEC);
--
2.53.0