Updated rwlock-in-C patchkit
Andi Kleen
andi@firstfloor.org
Wed Apr 16 13:35:00 GMT 2014
"Carlos O'Donell" <carlos@redhat.com> writes:
>
> That's right. I'd like to see the whatever code was used to benchmark
> the performance submitted as a microbenchmark so I can run it myself
> and verify. Again, it's not that I don't trust Andi, but an objective
> evaluation is always going to be the best defense for these changes.
Here is the code I used:
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
#define ITER 100
main()
{
int i, j;
for (j = 0; j < 50; j++) {
pthread_rwlock_rdlock(&rwlock);
pthread_rwlock_unlock(&rwlock);
pthread_rwlock_wrlock(&rwlock);
pthread_rwlock_unlock(&rwlock);
uint64_t start = __builtin_ia32_rdtsc();
for (i = 0; i < ITER; i++) {
pthread_rwlock_rdlock(&rwlock);
pthread_rwlock_unlock(&rwlock);
}
uint64_t end = __builtin_ia32_rdtsc();
if (j > 0)
printf("rdlock avg %.f\n", (end-start)/(float)ITER);
start = __builtin_ia32_rdtsc();
for (i = 0; i < ITER; i++) {
pthread_rwlock_wrlock(&rwlock);
pthread_rwlock_unlock(&rwlock);
}
end = __builtin_ia32_rdtsc();
if (j > 0)
printf("wrlock avg %.f\n", (end-start)/(float)ITER);
}
return 0;
}
More information about the Libc-alpha
mailing list