Spinlock backoff algorithm

From: Magne Mæhre <Magne(dot)Mahre(at)Sun(dot)COM>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Spinlock backoff algorithm
Date: 2007-11-14 09:34:51
Message-ID: 473AC13B.1060008@sun.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


I was playing with a Nevada server and noticed a rush on the FPU
(the Nevada has a single shared FPU for its 32 threads).
Looking at the spinlock code, I found :

cur_delay += (int) (cur_delay *
((double) random() / (double) MAX_RANDOM_VALUE) + 0.5);

I understand the reasoning for the backoff (as of the discussion on
2003-08-05), but is there any particular reason for using floating
point operations here ? Maybe a modulo would be just as good (or
better since it doesn't involve the FPU) ?

Something like:
cur_delay += random() % (cur_delay + 1) ;

--Magne

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zdenek Kotala 2007-11-14 10:48:58 Re: Spinlock backoff algorithm
Previous Message ITAGAKI Takahiro 2007-11-14 08:55:47 Re: LDC - Load Distributed Checkpoints with PG8.3b2 on Solaris