Re: gprof SELECT COUNT(*) results

From: Qingqing Zhou <zhouqq(at)cs(dot)toronto(dot)edu>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: gprof SELECT COUNT(*) results
Date: 2005-11-25 04:58:57
Message-ID: Pine.LNX.4.58.0511242354580.13944@eon.cs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 24 Nov 2005, Qingqing Zhou wrote:
>
> I may need to write some separate tests to see if this is what we should
> pay for bus lock instruction.
>

Here I come up with a test program to see how spinlock costs:

$/pgsql/src/backend/storage/lmgr#./a.out
Spinlock pair(2648542) duration: 143.134 ms
$/pgsql/src/backend/storage/lmgr#./a.out
Spinlock pair(2648542) duration: 143.107 ms
$/pgsql/src/backend/storage/lmgr#./a.out
Spinlock pair(2648542) duration: 143.104 ms

So seems lock instruction really costs ...

Regards,
Qingqing

---

/*
* spintest.c -
* Test spinlock acquire/release without concurrency.
*
* To compile (the -pg is to match the gprof make I used):
* backend/storage/lmgr#gcc -O2 -pg -Wall -I ../../../include/ spintest.c
*/

#include "postgres.h"
#include "storage/lwlock.h"
#include "storage/spin.h"
#include <sys/time.h>

#define TIMES 2648542

int NumLocks = 0;

void
s_lock(volatile slock_t *lock, const char *file, int line)
{
fprintf(stderr, "should never be here\n");
abort();
}

int
main(void)
{
int i;
slock_t lock = 0;
struct timeval start_t, stop_t;
long usecs;

gettimeofday(&start_t, NULL);
for (i = 0; i < TIMES; i ++)
{
SpinLockAcquire_NoHoldoff(&lock);

/* pretend to do something */
NumLocks ++;

SpinLockRelease_NoHoldoff(&lock);
}
gettimeofday(&stop_t, NULL);

if (stop_t.tv_usec < start_t.tv_usec)
{
stop_t.tv_sec--;
stop_t.tv_usec += 1000000;
}

usecs = (long) (stop_t.tv_sec - start_t.tv_sec) * 1000000
+ (long) (stop_t.tv_usec - start_t.tv_usec);

fprintf (stdout, "Spinlock pair(%u) duration: %ld.%03ld ms\n",
TIMES,
(long) ((stop_t.tv_sec - start_t.tv_sec) * 1000 +
(stop_t.tv_usec - start_t.tv_usec) / 1000),
(long) (stop_t.tv_usec - start_t.tv_usec) % 1000);

return 0;
}

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Olivier Thauvin 2005-11-25 05:11:21 Re: PL/php in pg_pltemplate
Previous Message Tom Lane 2005-11-25 04:48:33 Re: gprof SELECT COUNT(*) results