public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Andrew Morton <akpm@osdl.org>
Cc: Ingo Molnar <mingo@elte.hu>, Linus Torvalds <torvalds@osdl.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] remove volatile from x86 cmos_lock
Date: Fri, 14 Jul 2006 10:48:43 -0400	[thread overview]
Message-ID: <1152888523.27135.2.camel@localhost.localdomain> (raw)

Here's another exercise to understand barriers. Once again, please
review to see if this is indeed correct.

This patch removes the volatile keyword for cmos_lock and tries to make
the code correct using barriers.

-- Steve

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Index: linux-2.6.18-rc1/include/asm-i386/mc146818rtc.h
===================================================================
--- linux-2.6.18-rc1.orig/include/asm-i386/mc146818rtc.h	2006-07-14 09:09:14.000000000 -0400
+++ linux-2.6.18-rc1/include/asm-i386/mc146818rtc.h	2006-07-14 09:22:50.000000000 -0400
@@ -31,7 +31,7 @@
  * atomically claim the lock and set the owner.
  */
 #include <linux/smp.h>
-extern volatile unsigned long cmos_lock;
+extern unsigned long cmos_lock;
 
 /*
  * All of these below must be called with interrupts off, preempt
@@ -43,8 +43,10 @@ static inline void lock_cmos(unsigned ch
 	unsigned long new;
 	new = ((smp_processor_id()+1) << 8) | reg;
 	for (;;) {
-		if (cmos_lock)
+		if (cmos_lock) {
+			cpu_relax();
 			continue;
+		}
 		if (__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)) == 0)
 			return;
 	}
@@ -52,14 +54,16 @@ static inline void lock_cmos(unsigned ch
 
 static inline void unlock_cmos(void)
 {
-	cmos_lock = 0;
+	set_wmb(cmos_lock, 0);
 }
 static inline int do_i_have_lock_cmos(void)
 {
+	barrier();
 	return (cmos_lock >> 8) == (smp_processor_id()+1);
 }
 static inline unsigned char current_lock_cmos_reg(void)
 {
+	barrier();
 	return cmos_lock & 0xff;
 }
 #define lock_cmos_prefix(reg) \
Index: linux-2.6.18-rc1/arch/i386/kernel/time.c
===================================================================
--- linux-2.6.18-rc1.orig/arch/i386/kernel/time.c	2006-07-14 09:08:56.000000000 -0400
+++ linux-2.6.18-rc1/arch/i386/kernel/time.c	2006-07-14 09:24:06.000000000 -0400
@@ -86,7 +86,7 @@ EXPORT_SYMBOL(rtc_lock);
  * register we are working with.  It is required for NMI access to the
  * CMOS/RTC registers.  See include/asm-i386/mc146818rtc.h for details.
  */
-volatile unsigned long cmos_lock = 0;
+unsigned long cmos_lock = 0;
 EXPORT_SYMBOL(cmos_lock);
 
 /* Routines for accessing the CMOS RAM/RTC. */



             reply	other threads:[~2006-07-14 14:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-14 14:48 Steven Rostedt [this message]
     [not found] ` <200607141653.35011.oliver@neukum.org>
2006-07-14 15:09   ` [PATCH] remove volatile from x86 cmos_lock Steven Rostedt
2006-07-14 21:50     ` Dave Jones
2006-07-15  2:04       ` Steven Rostedt

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=1152888523.27135.2.camel@localhost.localdomain \
    --to=rostedt@goodmis.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@osdl.org \
    /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