mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Li,Rongqing" <lirongqing@baidu.com>
To: "mingo@redhat.com" <mingo@redhat.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"juri.lelli@redhat.com" <juri.lelli@redhat.com>,
	"vincent.guittot@linaro.org" <vincent.guittot@linaro.org>,
	"dietmar.eggemann@arm.com" <dietmar.eggemann@arm.com>,
	"rostedt@goodmis.org" <rostedt@goodmis.org>,
	"bsegall@google.com" <bsegall@google.com>,
	"mgorman@suse.de" <mgorman@suse.de>,
	"vschneid@redhat.com" <vschneid@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: 答复: [PATCH] sched/cputime: Fix a mostly theoretical divide by zero
Date: Mon, 16 Jun 2025 11:46:25 +0000	[thread overview]
Message-ID: <54c4aa198131420d9c77542bad5d27e7@baidu.com> (raw)
In-Reply-To: <20250604110442.8251-1-lirongqing@baidu.com>

> 
> Sum of utime and stime can overflow to 0, when a process with many threads
> run over total 2^64 ns
> 
> Signed-off-by: Li RongQing <lirongqing@baidu.com>


Ping

Thanks

-Li

> ---
>  kernel/sched/cputime.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index
> 6dab4854..c35fc4c 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -579,7 +579,8 @@ void cputime_adjust(struct task_cputime *curr, struct
> prev_cputime *prev,
>  		goto update;
>  	}
> 
> -	stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
> +	if (likely(stime + utime))
> +		stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
>  	/*
>  	 * Because mul_u64_u64_div_u64() can approximate on some
>  	 * achitectures; enforce the constraint that: a*b/(b+c) <= a.
> --
> 2.9.4


  reply	other threads:[~2025-06-16 11:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04 11:04 lirongqing
2025-06-16 11:46 ` Li,Rongqing [this message]
2025-06-16 12:51   ` Vincent Guittot
2025-06-16 14:48     ` David Laight
2025-06-17  6:36     ` 答复: [外部邮件] " Li,Rongqing

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=54c4aa198131420d9c77542bad5d27e7@baidu.com \
    --to=lirongqing@baidu.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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®