[LTP] [PATCH v1] Correctly handle user time in setitimer01
Martin Doucha
mdoucha@suse.cz
Fri Nov 4 16:33:28 CET 2022
On 04. 11. 22 15:13, Cyril Hrubis wrote:
> Hi!
>> Since ITIMER_VIRTUAL and ITIMER_PROF are counting down in user time, we
>> need to take in consideration CLOCK_MONOTONIC_COARSE resolution. This is
>> requested by the syscall, since it's considering context switch from
>> user to kernel mode by using a higher clock resolution.
>
> What exactly do you mean by this? I do not think that there is "user"
> and "kernel" time, just different in-kernel timers/counters with
> different precisions.
>
> As ITIMER_VIRTUAL and ITIMER_PROF counts CPU time the precision would be
> the same as the COARSE clocks which depends on jiffies and on the
> compile time option CONFIG_HZ. That is because in the scheduller the CPU
> time is quantized into chunks based on CONFIG_HZ.
>
> And the ITIMER_REAL runs on hrtimers which would be the same precision
> as CLOCK_REALTIME or CLOCK_MONOTONIC.
The kernel mangles the new timer values for ITIMER_PROF and
ITIMER_VIRTUAL. It'll always add one extra jiffy to the actual timer
value you've passed. For ITIMER_REAL, the timer value gets set as is.
From set_cpu_itimer() in kernel/time/itimer.c:
if (oval || nval) {
if (nval > 0)
nval += TICK_NSEC;
set_process_cpu_timer(tsk, clock_id, &nval, &oval);
}
nval = new timer value passed to setitimer() converted to nanoseconds
TICK_NSEC = 1 jiffy in nanoseconds
--
Martin Doucha mdoucha@suse.cz
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
More information about the ltp
mailing list