public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ihar 'Philips' Filipau" <filia@softhome.net>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [Q] jiffies overflow & timers.
Date: Mon, 17 Nov 2003 19:36:23 +0100	[thread overview]
Message-ID: <3FB91527.50007@softhome.net> (raw)

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


             reply	other threads:[~2003-11-17 18:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-17 18:36 Ihar 'Philips' Filipau [this message]
2003-11-17 19:01 ` [Q] jiffies overflow & timers 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FB91527.50007@softhome.net \
    --to=filia@softhome.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox