Re: [REGRESSION] [Linux 3.2] top/htop and all other CPU usage
From: Michal Hocko
Date: Fri Dec 02 2011 - 05:39:26 EST
On Thu 01-12-11 15:07:49, Michal Hocko wrote:
[...]
> While implementation is not race free (we better not use locks in that
> path...) so we might race:
>
> E.g.
>
> CPU1 CPU2
> now = ktime_get
> tick_nohz_start_idle
> ts->idle_entrytime = now;
> if (ts->idle_active)
> ts->idle_active = 1
> [...]
> return idle_sleeptime
>
> But this is OK because sleeptime will be more or less accurate. We just
> skip few ticks.
>
> It would be worse if we had a race like:
> CPU1 CPU2
> now = ktime_get
> tick_nohz_start_idle
> now = ktime_get
> update_ts_time_stats()
> ts->idle_entrytime = now;
> ts->idle_active = 1
> if (ts->idle_active)
> delta = ktime_sub(now, idle_entrytime)
> ktime_add(idle_sleeptime, delta)
>
> In this case we might get an overflow from ktime_sub but AFAIU the
> ktime_* magic the overflow should cause to get smaller idle_sleeptime
> in the end after ktime_add (we do not add a small number but rather
> subtract it), right?
Scratch that. Dunno why but I thought that ktime_t has unsigned values
but it is apparently not true (tv64 is s64). Anyway the above races should
be safe.
--
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9
Czech Republic
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/