This patch adds a comment that describes what the "rep; no" sequence in
spin_delay() does, in src/include/storage/s_lock.h. I think fully
describing what this code sequence is intended to due is worth the
space, but speak up if you think I've added too large a comment...
Barring any objections, I intend to apply this tomorrow.
-Neil
Index: src/include/storage/s_lock.h
===
RCS file: /home/neilc/private-cvsroot/pgsql-server/src/include/storage/s_lock.h,v
retrieving revision 1.131
diff -c -r1.131 s_lock.h
*** src/include/storage/s_lock.h 24 Sep 2004 01:48:43 - 1.131
--- src/include/storage/s_lock.h 6 Oct 2004 06:48:42 -
***
*** 138,143
--- 138,166
static __inline__ void
spin_delay(void)
{
+ /*
+ * This sequence is equivalent to the PAUSE instruction ("rep" is
+ * ignored by old IA32 processors if the following instruction is
+ * not a string operation); the IA-32 Architecture Software
+ * Developer's Manual, Vol. 3, Section 7.7.2 describes why using
+ * PAUSE in the inner loop of a spin lock is necessary for good
+ * performance:
+ *
+ * The PAUSE instruction improves the performance of IA-32
+ * processors supporting Hyper-Threading Technology when
+ * executing spin-wait loops and other routines where one
+ * thread is accessing a shared lock or semaphore in a tight
+ * polling loop. When executing a spin-wait loop, the
+ * processor can suffer a severe performance penalty when
+ * exiting the loop because it detects a possible memory order
+ * violation and flushes the core processor's pipeline. The
+ * PAUSE instruction provides a hint to the processor that the
+ * code sequence is a spin-wait loop. The processor uses this
+ * hint to avoid the memory order violation and prevent the
+ * pipeline flush. In addition, the PAUSE instruction
+ * de-pipelines the spin-wait loop to prevent it from
+ * consuming execution resources excessively.
+ */
__asm__ __volatile__(
" rep; nop \n");
}
---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html