linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/cputime: Fix a mostly theoretical divide by zero
@ 2025-06-04 11:04 lirongqing
  2025-06-16 11:46 ` 答复: " Li,Rongqing
  0 siblings, 1 reply; 5+ messages in thread
From: lirongqing @ 2025-06-04 11:04 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, linux-kernel
  Cc: Li RongQing

From: Li RongQing <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>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-06-17  6:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04 11:04 [PATCH] sched/cputime: Fix a mostly theoretical divide by zero lirongqing
2025-06-16 11:46 ` 答复: " Li,Rongqing
2025-06-16 12:51   ` Vincent Guittot
2025-06-16 14:48     ` David Laight
2025-06-17  6:36     ` 答复: [外部邮件] " Li,Rongqing

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).