From: vda <vda@port.imtp.ilyichevsk.odessa.ua>
To: Tim Schmielau <tim@physik3.uni-rostock.de>
Cc: Andreas Dilger <adilger@turbolabs.com>,
"Richard B. Johnson" <root@chaos.analogic.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [Patch] Re: Nasty suprise with uptime
Date: Thu, 1 Nov 2001 16:09:08 +0000 [thread overview]
Message-ID: <01110116090800.01137@nemo> (raw)
In-Reply-To: <Pine.LNX.4.30.0110312138040.30038-100000@gans.physik3.uni-rostock.de>
In-Reply-To: <Pine.LNX.4.30.0110312138040.30038-100000@gans.physik3.uni-rostock.de>
On Wednesday 31 October 2001 20:47, Tim Schmielau wrote:
> btw.: can someone please explain to me why do_timer uses
> (*(unsigned long *)&jiffies)++;
> instead of just doing jiffies++ ?
This casts away volatile -> gcc generates potentially faster code
> -unsigned long volatile jiffies;
> +unsigned long volatile jiffies = INITIAL_JIFFIES;
> +unsigned long volatile jiffies_hi, jiffies_hi_shadow;
Grepped your patch for uses of jiffies_hi_shadow, found none
except for stores. Seems to be unused?
> void do_timer(struct pt_regs *regs)
> {
> - (*(unsigned long *)&jiffies)++;
> + /* we assume that two calls to do_timer can never overlap
> + * since they are one jiffie apart in time */
> + if (jiffies != (unsigned long)(-1)) {
> + jiffies++;
> + } else {
> + /* We still need to care about the race with readers of
> + * jiffies_hi. Readers have to discard the values if
> + * jiffies_hi != jiffies_hi_shadow when read with
> + * proper barriers in between. */
> + jiffies_hi++;
> + barrier();
> + jiffies++;
> + barrier();
> + jiffies_hi_shadow = jiffies_hi;
> + barrier();
> + }
Looks like gross overkill for 64bit i++. I see no flaw in much simpler:
+ if(++jiffies == 0) {
+ /* barrier(); --vda: needed? I have some doubts... */
+ jiffies_hi++;
+ }
To avoid races 64bit readers must read in reverse order: hi,lo,check hi;
your patch already does this just right:
> +static inline u64 get_jiffies64() {
> + unsigned long hi,lo;
> + /* We need to make sure jiffies_hi does not change while
> + * reading jiffies and jiffies_hi */
> + do {
> + hi = jiffies_hi;
> + barrier();
> + lo = jiffies;
> + barrier();
> + } while (hi != jiffies_hi);
> + return lo + (((u64)hi) << BITS_PER_LONG);
> +}
> +
> +#define INITIAL_JIFFIES 0xFFFFD000ul
> +extern unsigned long volatile jiffies, jiffies_hi, jiffies_hi_shadow;
This belongs to some .h file, not .c (most likely include/linux/sched.h)
Also consider
+#if defined(CONFIG_DEBUG_KERNEL)
+/* Rollover in 1000 secs */
+#define INITIAL_JIFFIES ((unsigned long) -1000*HZ)
+#else
+#define INITIAL_JIFFIES 0
+#endif
Hope your patch will go into mainline soon!
--
vda
next prev parent reply other threads:[~2001-11-01 14:11 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <01103121070200.01262@nemo>
2001-10-31 19:26 ` [Patch] Re: Nasty suprise with uptime Tim Schmielau
2001-10-31 19:52 ` Richard B. Johnson
2001-10-31 20:00 ` J Sloan
2001-10-31 20:20 ` Charles Cazabon
2001-10-31 20:33 ` Kurt Roeckx
2001-10-31 20:47 ` Tim Schmielau
2001-10-31 21:07 ` Andreas Dilger
2001-10-31 21:11 ` Richard B. Johnson
2001-11-01 16:09 ` vda [this message]
2001-11-01 9:02 Petr Vandrovec
-- strict thread matches above, loose matches on Subject: below --
2001-10-31 22:11 Petr Vandrovec
2001-10-31 21:45 ` Andreas Dilger
2001-10-31 22:58 ` Tim Schmielau
2001-10-31 23:56 ` Andreas Dilger
2001-11-01 0:23 ` Tim Schmielau
2001-11-01 0:52 ` Tim Schmielau
2001-11-01 11:21 ` george anzinger
2001-11-01 11:40 ` Tim Schmielau
2001-11-02 0:28 ` Tim Schmielau
2001-11-02 1:23 ` Andreas Dilger
2001-11-02 9:10 ` Miquel van Smoorenburg
2001-11-02 17:18 ` Tim Schmielau
2001-11-02 18:48 ` Andreas Dilger
2001-11-01 16:35 ` vda
2001-11-01 15:34 ` Richard B. Johnson
2001-11-01 17:02 ` Benjamin LaHaise
2001-11-01 18:03 ` Richard B. Johnson
2001-11-01 18:34 ` Benjamin LaHaise
2001-11-02 14:46 ` vda
2001-11-01 17:29 ` george anzinger
2001-10-31 11:35 Tim Schmielau
2001-10-31 15:39 ` vda
2001-10-31 14:31 ` Richard B. Johnson
2001-10-31 18:16 ` Tim Schmielau
2001-10-31 18:35 ` Tim Schmielau
2001-10-31 18:59 ` Andreas Dilger
2001-10-31 18:40 ` Andreas Dilger
2001-10-31 18:58 ` Gerhard Mack
2001-10-31 19:14 ` Richard B. Johnson
2001-10-31 20:11 ` Gerhard Mack
2001-10-31 20:39 ` Richard B. Johnson
2001-10-31 20:52 ` Andreas Dilger
2001-10-31 21:05 ` Tim Schmielau
2001-10-31 21:39 ` Andreas Dilger
2001-10-31 21:17 ` Richard B. Johnson
2001-11-01 7:45 ` Ville Herva
2001-10-31 19:06 ` george anzinger
2001-10-31 22:54 ` george anzinger
2001-11-04 18:31 ` Ton Hospel
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=01110116090800.01137@nemo \
--to=vda@port.imtp.ilyichevsk.odessa.ua \
--cc=adilger@turbolabs.com \
--cc=linux-kernel@vger.kernel.org \
--cc=root@chaos.analogic.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.