2007-06-14 20:29:11

by Andreas Mohr

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

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 <[email protected]>


--- 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;
}