Skip to contentSkip to conversation

cpu_relax(): use in ACPI lock

PATCH In review [email protected] 1 participant 1 message Jun 24, 2006 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 18/18 cpu_relax(): use in ACPI lock

From: Andreas Mohr <[email protected]>

Use cpu_relax() in __acpi_acquire_global_lock() etc.

---

 include/asm-i386/acpi.h   |   14 ++++++++++----
 include/asm-x86_64/acpi.h |   14 ++++++++++----
 2 files changed, 20 insertions(+), 8 deletions(-)
include/asm-i386/acpi.h renamed from include/asm-i386/acpi.h~cpu_relax-use-in-acpi-lock +10 -4
diff -puN include/asm-i386/acpi.h~cpu_relax-use-in-acpi-lock include/asm-i386/acpi.h
@@ -61,11 +61,14 @@ static inline int
 __acpi_acquire_global_lock (unsigned int *lock)
 {
 	unsigned int old, new, val;
-	do {
+	while (1) {
 		old = *lock;
 		new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
 		val = cmpxchg(lock, old, new);
-	} while (unlikely (val != old));
+		if (likely(val == old))
+			break;
+		cpu_relax();
+	}
 	return (new < 3) ? -1 : 0;
 }
 
@@ -73,11 +76,14 @@ static inline int
 __acpi_release_global_lock (unsigned int *lock)
 {
 	unsigned int old, new, val;
-	do {
+	while (1) {
 		old = *lock;
 		new = old & ~0x3;
 		val = cmpxchg(lock, old, new);
-	} while (unlikely (val != old));
+		if (likely(val == old))
+			break;
+		cpu_relax();
+	}
 	return old & 0x1;
 }
 
include/asm-x86_64/acpi.h renamed from include/asm-x86_64/acpi.h~cpu_relax-use-in-acpi-lock +10 -4
diff -puN include/asm-x86_64/acpi.h~cpu_relax-use-in-acpi-lock include/asm-x86_64/acpi.h
@@ -59,11 +59,14 @@ static inline int
 __acpi_acquire_global_lock (unsigned int *lock)
 {
 	unsigned int old, new, val;
-	do {
+	while (1) {
 		old = *lock;
 		new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
 		val = cmpxchg(lock, old, new);
-	} while (unlikely (val != old));
+		if (likely(val == old))
+			break;
+		cpu_relax();
+	}
 	return (new < 3) ? -1 : 0;
 }
 
@@ -71,11 +74,14 @@ static inline int
 __acpi_release_global_lock (unsigned int *lock)
 {
 	unsigned int old, new, val;
-	do {
+	while (1) {
 		old = *lock;
 		new = old & ~0x3;
 		val = cmpxchg(lock, old, new);
-	} while (unlikely (val != old));
+		if (likely(val == old))
+			break;
+		cpu_relax();
+	}
 	return old & 0x1;
 }
 

_