lkml.org 
[lkml]   [2013]   [May]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [tip:sched/urgent] sched: Avoid cputime scaling overflow
> +	for (;;) {
> + /* Make sure "rtime" is the bigger of stime/rtime */
> + if (stime > rtime) {
> + u64 tmp = rtime; rtime = stime; stime = tmp;

I keep forgetting to mention we have swap(rtime, stime); that does the above.

> + }
> +
> + /* Make sure 'total' fits in 32 bits */
> + if (total >> 32)
> + goto drop_precision;
> +
> + /* Does rtime (and thus stime) fit in 32 bits? */
> + if (!(rtime >> 32))
> + break;
> +
> + /* Can we just balance rtime/stime rather than dropping bits? */
> + if (stime >> 31)
> + goto drop_precision;
> +
> + /* We can grow stime and shrink rtime and try to make them both fit */
> + stime <<= 1;
> + rtime >>= 1;
> + continue;
> +
> +drop_precision:
> + /* We drop from rtime, it has more bits than stime */
> + rtime >>= 1;
> + total >>= 1;
> }
>
> + /*
> + * Make sure gcc understands that this is a 32x32->64 multiply,
> + * followed by a 64/32->64 divide.
> + */
> + scaled = div_u64((u64) (u32) stime * (u64) (u32) rtime, (u32)total);
> return (__force cputime_t) scaled;
> }
>


\
 
 \ /
  Last update: 2013-05-02 15:41    [W:0.075 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site