public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [Q] jiffies overflow & timers.
@ 2003-11-17 18:36 Ihar 'Philips' Filipau
  2003-11-17 19:01 ` Richard B. Johnson
  0 siblings, 1 reply; 7+ messages in thread
From: Ihar 'Philips' Filipau @ 2003-11-17 18:36 UTC (permalink / raw)
  To: Linux Kernel Mailing List

Hello!

    [ ver 2.4.18/22 ]

    [ I feel strongly that is FAQ - so any ptr(RTFM)!=0 apreciated. ]

    [ ldd2 covers this very sparsely - overflow case is not covered at 
all - just mentioned. Google - looks like I cannot find right keywords 
for this ... ]

    I'm trying to find correct solution for case of jiffies overflow and 
standard kernel timers (./kernel/timer.c).

    My module has to maintain list of timers. I cannot reuse directly 
struct timer_list - since it uses jiffies and jiffies do wrap on overflow.

    I decided to use struct timeval & do_gettimeofday(). But still I 
have to handle case when next timer to expire will happend after jiffies 
will overflow.

   So my question - how to detect that jiffies had overflown?

   Is the following code is sufficient?
   (Assuming that I will not try to set timer longer than (~0UL/(HZ)) 
seconds)

unsigned long
tv_get_next_expiring_jiffies( struct timeval *target_tv )
{
   struct timeval curr_tv, timeout;
   ulong dif_jif;

   do_gettimeofday( &curr_tv );

   /* timeout = curr_tv - target_tv */
   tv_sub( &timeout, &curr_tv, target_tv );

   dif_jif = tv_to_jiffies( &timeout );   /* assumption above. */

   if (jiffies > ~0UL - dif_jif) {
       /* will overflow
        * so wait for overflow, then just reschedule
        */
       return ~0UL;
   } else {
       /* will not */
       return jiffies + dif_jif;
   }
}

Is (~0UL) "safe harbour"? in other words - will this value reached? /me 
cannot find where jiffies is incremented... Dumd grep -r jiffies gives 
no results (no assignment, no taking of pointer, literally no matches in 
.S files - what I'm missing?) Because if this value will be reached and 
I will detect that jiffies == ~0UL I will have to "while(jiffies == 
~0UL);" wait for overflow.

-- 
Ihar 'Philips' Filipau  / with best regards from Saarbruecken.
--                                                           _ _ _
  "... and for $64000 question, could you get yourself       |_|*|_|
    vaguely familiar with the notion of on-topic posting?"   |_|_|*|
                                 -- Al Viro @ LKML           |*|*|*|


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-11-18 14:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-17 18:36 [Q] jiffies overflow & timers Ihar 'Philips' Filipau
2003-11-17 19:01 ` Richard B. Johnson
2003-11-17 21:01   ` Ihar 'Philips' Filipau
2003-11-17 21:28     ` Richard B. Johnson
2003-11-18  9:53       ` Ihar 'Philips' Filipau
2003-11-18 13:24         ` Richard B. Johnson
2003-11-18 14:11           ` Ihar 'Philips' Filipau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox