mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Dilger <adilger@clusterfs.com>
To: Tim Schmielau <tim@physik3.uni-rostock.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [patch] enable uptime display > 497 days on 32 bit (1/2)
Date: Fri, 1 Mar 2002 10:57:53 -0700	[thread overview]
Message-ID: <20020301105753.O22608@lynx.adilger.int> (raw)
In-Reply-To: <Pine.LNX.4.33.0203010339240.3946-100000@gans.physik3.uni-rostock.de>
In-Reply-To: <Pine.LNX.4.33.0203010339240.3946-100000@gans.physik3.uni-rostock.de>; from tim@physik3.uni-rostock.de on Fri, Mar 01, 2002 at 03:55:25AM +0100

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/


  parent reply	other threads:[~2002-03-01 17:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-01  2:55 Tim Schmielau
2002-03-01  2:57 ` [patch] enable uptime display > 497 days on 32 bit (2/2) Tim Schmielau
2002-03-01  9:04 ` [patch] enable uptime display > 497 days on 32 bit (1/2) george anzinger
2002-03-01 12:52 ` Rik van Riel
2002-03-01 15:48 ` george anzinger
2002-03-01 17:57 ` Andreas Dilger [this message]
2002-03-01 18:21   ` Tim Schmielau
2002-05-05 22:00 Tim Schmielau

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=20020301105753.O22608@lynx.adilger.int \
    --to=adilger@clusterfs.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tim@physik3.uni-rostock.de \
    /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

all inboxes | Powered by JetHome®