Commit 3da2fe13 authored by Tim Schmielau's avatar Tim Schmielau Committed by Linus Torvalds

[PATCH] use 64 bit jiffies: infrastructure

Provide a sane way to avoid unneccessary locking on 64 bit platforms,
and a 64 bit analogous to "jiffies_to_clock_t()".
parent 81c0cfcc
...@@ -2,15 +2,35 @@ ...@@ -2,15 +2,35 @@
#define _LINUX_JIFFIES_H #define _LINUX_JIFFIES_H
#include <linux/types.h> #include <linux/types.h>
#include <linux/spinlock.h>
#include <asm/system.h>
#include <asm/param.h> /* for HZ */ #include <asm/param.h> /* for HZ */
/* /*
* The 64-bit value is not volatile - you MUST NOT read it * The 64-bit value is not volatile - you MUST NOT read it
* without holding read_lock_irq(&xtime_lock) * without holding read_lock_irq(&xtime_lock).
* get_jiffies_64() will do this for you as appropriate.
*/ */
extern u64 jiffies_64; extern u64 jiffies_64;
extern unsigned long volatile jiffies; extern unsigned long volatile jiffies;
static inline u64 get_jiffies_64(void)
{
#if BITS_PER_LONG < 64
extern rwlock_t xtime_lock;
unsigned long flags;
u64 tmp;
read_lock_irqsave(&xtime_lock, flags);
tmp = jiffies_64;
read_unlock_irqrestore(&xtime_lock, flags);
return tmp;
#else
return (u64)jiffies;
#endif
}
/* /*
* These inlines deal with timer wrapping correctly. You are * These inlines deal with timer wrapping correctly. You are
* strongly encouraged to use them * strongly encouraged to use them
......
...@@ -2,7 +2,30 @@ ...@@ -2,7 +2,30 @@
#define _LINUX_TIMES_H #define _LINUX_TIMES_H
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <asm/div64.h>
#include <asm/types.h>
#if (HZ % USER_HZ)==0
# define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ)) # define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
#else
# define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x))
#endif
static inline u64 jiffies_64_to_clock_t(u64 x)
{
#if (HZ % USER_HZ)==0
do_div(x, HZ / USER_HZ);
#else
/*
* There are better ways that don't overflow early,
* but even this doesn't overflow in hundreds of years
* in 64 bits, so..
*/
x *= USER_HZ;
do_div(x, HZ);
#endif
return x;
}
#endif #endif
struct tms { struct tms {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment