Re: [PATCH 4/4] taskstats: use div_u64() for the elapsed time in tgid_stats_add_task()
From: Balbir Singh
Date: Sun Nov 01 2026 - 21:53:18 EST
On 11/1/26 11:57 AM, Bradley Morgan wrote:
> 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);
Thanks!
Reviewed-by: Balbir Singh <balbirs@xxxxxxxxxx>