Re: [PATCH] process cputimer is moving faster than itscorresponding clock

From: Peter Zijlstra
Date: Wed Apr 10 2013 - 07:35:29 EST


On Fri, 2013-04-05 at 13:59 -0400, Olivier Langlois wrote:
> Process timers are moving fasters than their corresponding
> cpu clock for various reasons:
>
> 1. There is a race condition when getting a timer sample that makes the sample
> be smaller than it should leading to setting the timer expiration to soon.
> 2. When initializing the cputimer, by including tasks deltas in the initial
> timer value, it makes them be counted twice.
> 3. When a thread autoreap itself when exiting, the last context switch update
> will update the cputimer and not the overall process values stored in
> signal.

Please explain these races. Things like task_sched_runtime() on which
most of this stuff is build read both sum_exec_runtime and compute the
delta while holding the rq->lock; this should avoid any and all races
against update_curr() and the sort.

All this fiddling with conditional deltas seems very ugly, esp. since
no attempt is made to explain why it would be impossible to tighten the
synchronization to avoid the races.

> I have also removed to erractic cputimer start/stop. I am guessing that it
> was done to 'resync' once in a while the cputimer with the clock but
> you could start the cputimer by calling timer_settimer that finally
> do not end up by arming a new posix timer so you could have the cputimer
> running with 0 armed timers or have 1 periodic process timer.

No keeping a process wide (over all threads) cputime aggregate running
is _expensive_, so its important to stop doing this once there's nobody
who cares about it anymore.


--
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/