[lkml]   [2001]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: How should we do a 64-bit jiffies?
Linus Torvalds wrote:
> In article <>,
> george anzinger <> wrote:
> >
> >I am beginning to think that defining a u64 and casting, i.e.:
> >
> >#define jiffies (unsigned long volitial)jiffies_u64
> >
> >is the way to go.
> ..except for gcc being bad at even 64->32-bit casts like the above. It
> will usually still load the full 64-bit value, and then only use the low
> bits.
> The efficient and sane way to do it is:
> /*
> * The 64-bit value is not volatile - you MUST NOT read it
> * without holding the spinlock
> */
Given that the spinlock would have to be spin_lock_irq (jiffies is
updated in clock interrupt code), is there a way to avoid the lock? The
following code does it for UP systems, given it is not rearranged. Is
there something like this that will work for
SMP systems?

(assumeing the defines below):

do {
jiffies_f = jiffies;
jiffies_64_f = jiffies_64;
while ( jiffies_f != jiffies);

If all things are in order, this will work on UP. Order could be
enforced by using locked instructions for the jiffies access...


> u64 jiffies_64;
> /*
> * Most people don't necessarily care about the full 64-bit
> * value, so we can just get the "unstable" low bits without
> * holding the lock. For historical reasons we also mark
> * it volatile so that busy-waiting doesn't get optimized
> * away in old drivers.
> */
> #if defined(__LITTLE_ENDIAN) || (BITS_PER_LONG > 32)
> #define jiffies (((volatile unsigned long *)&jiffies_64)[0])
> #else
> #define jiffies (((volatile unsigned long *)&jiffies_64)[1])
> #endif
> which looks ugly, but the ugliness is confined to that one place, and
> none of the users will ever have to care..
> Linus
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

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