[PATCH][RFC] unlikely spinlocks

Jake Moilanen moilanen at austin.ibm.com
Thu Mar 3 09:34:12 EST 2005


On our raw spinlocks, we currently have an attempt at the lock, and if
we do not get it we enter a spin loop.  This spinloop will likely
continue for awhile, and we pridict likely.  

Shouldn't we predict that we will get out of the loop so our next
instructions are already prefetched.  Even when we miss because the lock
is still held, it won't matter since we are waiting anyways.

I did a couple quick benchmarks, but the results are inconclusive.  

	16-way 690 running specjbb with original code
	# ./specjbb 3000 16 1 1 19 30 120
	    ...
	Valid run, Score is 59282

	16-way 690 running specjbb with unlikely code
	# ./specjbb 3000 16 1 1 19 30 120
	    ...
	Valid run, Score is 59541

I saw a smaller increase on a JS20 (~1.6%)

	JS20 specjbb w/ original code
	# ./specjbb 400 2 1 1 19 30 120
	   ...
	Valid run, Score is 20460


	JS20 specjbb w/ unlikely code
	# ./specjbb 400 2 1 1 19 30 120
	   ...
	Valid run, Score is 20803

Jake

Signed-off-by: Jake Moilanen <moilanen at austin.ibm.com>

---


diff -puN include/asm-ppc64/spinlock.h~unlikely-spinlocks include/asm-ppc64/spinlock.h
--- linux-2.6-bk/include/asm-ppc64/spinlock.h~unlikely-spinlocks	Wed Mar  2 13:55:39 2005
+++ linux-2.6-bk-moilanen/include/asm-ppc64/spinlock.h	Wed Mar  2 13:55:40 2005
@@ -110,7 +110,7 @@ static void __inline__ _raw_spin_lock(sp
 			HMT_low();
 			if (SHARED_PROCESSOR)
 				__spin_yield(lock);
-		} while (likely(lock->lock != 0));
+		} while (unlikely(lock->lock != 0));
 		HMT_medium();
 	}
 }
@@ -128,7 +128,7 @@ static void __inline__ _raw_spin_lock_fl
 			HMT_low();
 			if (SHARED_PROCESSOR)
 				__spin_yield(lock);
-		} while (likely(lock->lock != 0));
+		} while (unlikely(lock->lock != 0));
 		HMT_medium();
 		local_irq_restore(flags_dis);
 	}
@@ -194,7 +194,7 @@ static void __inline__ _raw_read_lock(rw
 			HMT_low();
 			if (SHARED_PROCESSOR)
 				__rw_yield(rw);
-		} while (likely(rw->lock < 0));
+		} while (unlikely(rw->lock < 0));
 		HMT_medium();
 	}
 }
@@ -251,7 +251,7 @@ static void __inline__ _raw_write_lock(r
 			HMT_low();
 			if (SHARED_PROCESSOR)
 				__rw_yield(rw);
-		} while (likely(rw->lock != 0));
+		} while (unlikely(rw->lock != 0));
 		HMT_medium();
 	}
 }

_




More information about the Linuxppc64-dev mailing list