[PATCH -mm] i386: add cpu_relax() to cmos_lock()

From: Andreas Mohr
Date: Thu Jun 14 2007 - 16:29:12 EST


Add cpu_relax() to cmos_lock() inline function
for faster operation on SMT CPUs and less power consumption
on others in case of lock contention (which probably doesn't
happen too often, so admittedly this patch is not too exciting).

This is a small followup to my cpu_relax() patch series last year.

A different, possibly more readable and efficient way to write this loop
would be something like:

while ((cmos_lock) ||
(__cmpxchg(&cmos_lock, 0, new, sizeof(cmos_lock)))) {
cpu_relax();
}

Compiled and runtime-tested on linux-2.6.22-rc4-mm2, Athlon.

Signed-off-by: Andreas Mohr <andi@xxxxxxxx>


--- linux-2.6.22-rc4-mm2.orig/include/asm-i386/mc146818rtc.h 2007-06-10 22:00:53.000000000 +0200
+++ linux-2.6.22-rc4-mm2/include/asm-i386/mc146818rtc.h 2007-06-09 21:40:21.000000000 +0200
@@ -43,8 +43,10 @@
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;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/