public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Fawzi Mohamed <fmohamed@me.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	Thomas Dargel <td@chemie.hu-berlin.de>,
	Hillf Danton <dhillf@gmail.com>, Paul Turner <pjt@google.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: Re: [PATCH] fix oops in updating thread cputime and task time
Date: Wed, 25 Apr 2012 14:10:27 +0200	[thread overview]
Message-ID: <1335355827.28150.263.camel@twins> (raw)
In-Reply-To: <301628B7-B058-4C01-9A65-F2A4AAF05EE6@me.com>

On Sat, 2012-04-21 at 09:23 +0200, Fawzi Mohamed wrote:
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 4603b9d..03a2d89 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2966,7 +2966,7 @@ void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
>                 u64 temp = (__force u64) rtime;
>  
>                 temp *= (__force u64) utime;
> -               do_div(temp, (__force u32) total);
> +               temp = div64_u64(temp, total);
>                 utime = (__force cputime_t) temp;
>         } else
>                 utime = rtime;
> @@ -2999,7 +2999,7 @@ void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
>                 u64 temp = (__force u64) rtime;
>  
>                 temp *= (__force u64) cputime.utime;
> -               do_div(temp, (__force u32) total);
> +               temp = div64_u64(temp, total);
>                 utime = (__force cputime_t) temp;
>         } else
>                 utime = rtime; 

I'm not entirely sure why it takes 19 days, suppose we have HZ=1000 and
your app never idles, it still takes 2^32/1000 seconds ~50 days to
overflow that u32.

Anyway, yes your patch avoids the /0 issue, but it leaves the other
problem with that code..

  rtime * utime / total

The multiplication can overflow the u64 at which point you're staring at
complete rubbish, this happens at about that same point.

So I figure we need to use the shiny new mult_frac() primitive.

32bit platforms are going to be staring at crap either way though, since
their entire time accounting (cputime_t) will start warping at that
point,.. not sure what if anything we should do about that though..
anybody?

      reply	other threads:[~2012-04-25 12:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-16 16:29 [PATCH] fix oops in updating thread cputime and task time Fawzi Mohamed
2012-04-21  7:23 ` Fawzi Mohamed
2012-04-25 12:10   ` Peter Zijlstra [this message]

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=1335355827.28150.263.camel@twins \
    --to=peterz@infradead.org \
    --cc=dhillf@gmail.com \
    --cc=fmohamed@me.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=pjt@google.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=td@chemie.hu-berlin.de \
    /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