Messages in this thread | | | Date | Fri, 1 Mar 2002 10:57:53 -0700 | From | Andreas Dilger <> | Subject | Re: [patch] enable uptime display > 497 days on 32 bit (1/2) |
| |
On Mar 01, 2002 03:55 +0100, Tim Schmielau wrote: > rediffed to 2.4.19-pre2 and three micro-optimizations: > > move jiffies_hi etc. to same cacheline as jiffies > (suggested by George Anzinger) > avoid turning off interrupts (suggested by Andreas Dilger) > use unlikely() (suggested by Andreas Dilger) > > As no other comments turned up, this will go to Marcelo RSN. > (wondered why noone vetoed this as overkill...)
Minor nit - the indenting of #ifdefs is not really used in the kernel.
> +u64 get_jiffies64(void) > +{ > + unsigned long jiffies_tmp, jiffies_hi_tmp; > + > + spin_lock(&jiffies64_lock); > + jiffies_tmp = jiffies; /* avoid races */ > + jiffies_hi_tmp = jiffies_hi; > + if (unlikely(jiffies_tmp < jiffies_last)) /* We have a wrap */ > + jiffies_hi++; > + jiffies_last = jiffies_tmp; > + spin_unlock(&jiffies64_lock); > + > + return (jiffies_tmp | ((u64)jiffies_hi_tmp) << BITS_PER_LONG); > +}
If jiffies_hi is incremented, then jiffies_hi_tmp will be wrong on return.
> +static void check_jiffieswrap(unsigned long data) > +{ > + unsigned long jiffies_tmp; > + mod_timer(&jiffieswrap_timer, jiffies + CHECK_JIFFIESWRAP_INTERVAL); > + > + if (spin_trylock(&jiffies64_lock)) { > + /* If we don't get the lock, we can just give up. > + The current holder of the lock will check for wraps */ > + jiffies_tmp = jiffies; /* avoid races */ > + if (jiffies_tmp < jiffies_last) /* We have a wrap */ > + jiffies_hi++; > + jiffies_last = jiffies_tmp; > + spin_unlock(&jiffies64_lock); > + } } note:----------------------------------------------------------------------^
Since check_jiffieswrap() and get_jiffies64() are substantially the same, you may want to define a function _inc_jiffies64() which does:
+#ifdef NEEDS_JIFFIES64 +/* jiffies_hi and jiffies_last are protected by jiffies64_lock */ +static unsigned long jiffies_hi, jiffies_last; +static spinlock_t jiffies64_lock = SPIN_LOCK_UNLOCKED; +#endif
static inline void _inc_jiffies64(unsigned long jiffies_tmp) { jiffies_tmp = jiffies; /* avoid races */ if (jiffies_tmp < jiffies_last) /* We have a wrap */ jiffies_hi++; jiffies_last = jiffies_tmp; }
static void get_jiffies64() { unsigned long jiffies_tmp, jiffies_hi_tmp;
spin_lock(&jiffies64_lock); _inc_jiffies64(jiffies_tmp); jiffies_hi_tmp = jiffies_hi; spin_unlock(&jiffies64_lock);
return (jiffies_tmp | ((u64)jiffies_hi_tmp) << BITS_PER_LONG); }
static void check_jiffieswrap(unsigned long data) { unsigned long jiffies_tmp; mod_timer(&jiffieswrap_timer, jiffies + CHECK_JIFFIESWRAP_INTERVAL);
/* * If we don't get the lock, we can just give up. * The current holder of the lock will check for wraps */ if (spin_trylock(&jiffies64_lock)) { _inc_jiffies64(jiffies_tmp); spin_unlock(&jiffies64_lock); } }
Cheers, Andreas -- Andreas Dilger http://sourceforge.net/projects/ext2resize/ http://www-mddsp.enel.ucalgary.ca/People/adilger/
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |