From: Steven Rostedt <rostedt@goodmis.org>
To: "Li,Rongqing" <lirongqing@baidu.com>
Cc: Oleg Nesterov <oleg@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
David Laight <david.laight.linux@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"vschneid@redhat.com" <vschneid@redhat.com>,
"mgorman@suse.de" <mgorman@suse.de>,
"bsegall@google.com" <bsegall@google.com>,
"dietmar.eggemann@arm.com" <dietmar.eggemann@arm.com>,
"vincent.guittot@linaro.org" <vincent.guittot@linaro.org>,
"juri.lelli@redhat.com" <juri.lelli@redhat.com>,
"mingo@redhat.com" <mingo@redhat.com>
Subject: Re: [????] Re: divide error in x86 and cputime
Date: Mon, 7 Jul 2025 19:53:18 -0400 [thread overview]
Message-ID: <20250707195318.0c7f401d@gandalf.local.home> (raw)
In-Reply-To: <2ef88def90634827bac1874d90e0e329@baidu.com>
On Mon, 7 Jul 2025 23:41:14 +0000
"Li,Rongqing" <lirongqing@baidu.com> wrote:
> > On a second thought, this
> >
> > mul_u64_u64_div_u64(0x69f98da9ba980c00, 0xfffd213aabd74626,
> > 0x09e00900);
> > stime rtime
> > stime + utime
> >
> > looks suspicious:
> >
> > - stime > stime + utime
> >
> > - rtime = 0xfffd213aabd74626 is absurdly huge
> >
> > so perhaps there is another problem?
> >
>
> it happened when a process with 236 busy polling threads , run about 904 days, the total time will overflow the 64bit
>
> non-x86 system maybe has same issue, once (stime + utime) overflows 64bit, mul_u64_u64_div_u64 from lib/math/div64.c maybe cause division by 0
>
> so to cputime, could cputime_adjust() return stime if stime if stime + utime is overflow
>
> diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
> index 6dab4854..db0c273 100644
> --- a/kernel/sched/cputime.c
> +++ b/kernel/sched/cputime.c
> @@ -579,6 +579,10 @@ void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
> goto update;
> }
>
> + if (stime > (stime + utime)) {
> + goto update;
> + }
> +
> stime = mul_u64_u64_div_u64(stime, rtime, stime + utime);
> /*
> * Because mul_u64_u64_div_u64() can approximate on some
>
Are you running 5.10.0? Because a diff of 5.10.238 from 5.10.0 gives:
@@ -579,6 +579,12 @@ void cputime_adjust(struct task_cputime *curr, struct prev_cputime *prev,
}
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.
+ */
+ if (unlikely(stime > rtime))
+ stime = rtime;
update:
Thus the result is what's getting screwed up.
-- Steve
next prev parent reply other threads:[~2025-07-07 23:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 8:14 divide error in x86 and cputime Li,Rongqing
2025-07-07 15:11 ` Steven Rostedt
2025-07-07 22:09 ` Oleg Nesterov
2025-07-07 22:20 ` Steven Rostedt
2025-07-07 22:33 ` Steven Rostedt
2025-07-07 23:00 ` Oleg Nesterov
2025-07-08 11:00 ` David Laight
2025-07-08 1:40 ` 答复: [????] " Li,Rongqing
2025-07-08 1:53 ` Steven Rostedt
2025-07-08 1:58 ` 答复: [????] " Li,Rongqing
2025-07-08 2:05 ` Steven Rostedt
2025-07-08 2:17 ` Oleg Nesterov
2025-07-08 9:58 ` David Laight
2025-07-07 22:30 ` Oleg Nesterov
2025-07-07 23:41 ` 答复: [????] " Li,Rongqing
2025-07-07 23:53 ` Steven Rostedt [this message]
2025-07-08 0:10 ` 答复: [????] " Li,Rongqing
2025-07-08 0:30 ` Steven Rostedt
2025-07-08 1:17 ` 答复: [????] " Li,Rongqing
2025-07-08 1:41 ` Steven Rostedt
2025-07-08 10:35 ` [????] Re: [????] " David Laight
2025-07-08 11:12 ` 答复: [????] " Li,Rongqing
2025-07-08 0:23 ` 答复: " 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=20250707195318.0c7f401d@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=bsegall@google.com \
--cc=david.laight.linux@gmail.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lirongqing@baidu.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).