lkml.org 
[lkml]   [1996]   [Oct]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: sys_getitimer() question


On Thu, 31 Oct 1996, Ingo Molnar wrote:
>
> from kernel/itimer.c:sys_getitimer():
>
> static int _getitimer(int which, struct itimerval *value)
> {
> register unsigned long val, interval;
>
> switch (which) {
> case ITIMER_REAL:
> interval = current->it_real_incr;
> ---> val = 0;
> ---> if (del_timer(&current->real_timer)) {
> ---> unsigned long now = jiffies;
> ---> val = current->real_timer.expires;
> ---> add_timer(&current->real_timer);
> ---> /* look out for negative/zero itimer.. */
> ---> if (val <= now)
> ---> val = now+1;
> ---> val -= now;
> ---> }
>
> Why is the timer deleted and added when we are querying the value only? Or
> is there some usage pattern performance reason?

The main reasons is that the timer code doesn't guarantee that the "expires"
value is valid when the timer is active. The original timer code used
relative expires, and when the timer was on the active queue the "expires"
field couldn't be used directly (because it was only a "ticks from previous
timer" value).

With the current timer implementation I guess the above is not exactly the
most intelligent way to handle this all, and your example replacement should
be fine.

The timer code will be eventually rewritten to use a heap to store the
timers, but I suspect that your code would continue to work.

Linus

\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.032 / U:0.792 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site