update i386 spinlock for hyperthreading

From: Manfred Spraul <manfred(at)colorfullife(dot)com>
To: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: update i386 spinlock for hyperthreading
Date: 2003-12-26 22:26:48
Message-ID: 3FECB5A8.50708@colorfullife.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers pgsql-patches

Hi,

Intel recommends to add a special pause instruction into spinlock busy
loops. It's necessary for hyperthreading - without it, the cpu can't
figure out that a logical thread does no useful work and incorrectly
awards lots of execution resources to that thread. Additionally, it's
supposed to reduce the time the cpu needs to recover from the
(mispredicted) branch after the spinlock was obtained.
The attached patch adds a new platform hook and implements it for i386.
The new instruction is backward compatible, thus no cpu detection is
necessary.
Additionally I've increased the number of loops from 100 to 1000 - a 3
GHz Pentium 4 might execute 100 loops faster than a single bus
transaction. I don't know if this change is appropriate for all
platforms, or if SPINS_PER_DELAY should be made platform specific.

Mark did a test run with his dbt-2 benchmark on a 4-way Xeon with HT
enabled, and the patch resulted in a 10% performance increase:
Before:
http://developer.osdl.org/markw/dbt2-pgsql/284/
After:
http://developer.osdl.org/markw/dbt2-pgsql/300/

--
Manfred

Attachment Content-Type Size
patch-spinlock-i386 text/plain 2.7 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Randal L. Schwartz 2003-12-26 23:10:17 Re: between
Previous Message Mike Nolan 2003-12-26 22:10:21 Re: between

Browse pgsql-hackers by date

  From Date Subject
Next Message A E 2003-12-26 22:32:55 REPOST from SQL List: Use of Setof Record Dynamically
Previous Message Tom Lane 2003-12-26 22:10:04 Re: fulltext searching via a custom index type

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2003-12-26 23:22:11 Re: update i386 spinlock for hyperthreading
Previous Message Tom Lane 2003-12-26 17:09:11 Re: fork/exec patch: pre-CreateProcess finalization