mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
Benchtests: Add bench for pthread_spin_{try}lock and mutex_trylock
Reuses infrastructure from previous pthread_mutex_lock benchmarks to test other performance sensitive functions.
This commit is contained in:
parent
114e299ca6
commit
10c779f44a
@ -103,11 +103,19 @@ endif
|
||||
|
||||
bench-pthread := \
|
||||
pthread-locks \
|
||||
pthread-mutex-locks \
|
||||
pthread-mutex-lock \
|
||||
pthread-mutex-trylock \
|
||||
pthread-spin-lock \
|
||||
pthread-spin-trylock \
|
||||
pthread_once \
|
||||
thread_create \
|
||||
# bench-pthread
|
||||
|
||||
LDLIBS-bench-pthread-mutex-lock += -lm
|
||||
LDLIBS-bench-pthread-mutex-trylock += -lm
|
||||
LDLIBS-bench-pthread-spin-lock += -lm
|
||||
LDLIBS-bench-pthread-spin-trylock += -lm
|
||||
|
||||
bench-string := \
|
||||
ffs \
|
||||
ffsll \
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Measure mutex_lock for different threads and critical sections.
|
||||
/* Measure lock functions for different threads and critical sections.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
@ -17,7 +17,6 @@
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define TEST_MAIN
|
||||
#define TEST_NAME "pthread-mutex-locks"
|
||||
#define TIMEOUT (20 * 60)
|
||||
|
||||
#include <stdio.h>
|
||||
@ -31,8 +30,8 @@
|
||||
#include "bench-timing.h"
|
||||
#include "json-lib.h"
|
||||
|
||||
static pthread_mutex_t lock;
|
||||
static pthread_mutexattr_t attr;
|
||||
static bench_lock_t lock;
|
||||
static bench_lock_attr_t attr;
|
||||
static pthread_barrier_t barrier;
|
||||
|
||||
#define START_ITERS 1000
|
||||
@ -104,9 +103,9 @@ worker (void *v)
|
||||
TIMING_NOW (start);
|
||||
while (iters--)
|
||||
{
|
||||
pthread_mutex_lock (&lock);
|
||||
LOCK (&lock);
|
||||
critical_section (crt_len);
|
||||
pthread_mutex_unlock (&lock);
|
||||
UNLOCK (&lock);
|
||||
non_critical_section (non_crt_len);
|
||||
}
|
||||
TIMING_NOW (stop);
|
||||
@ -123,7 +122,7 @@ do_one_test (int num_threads, int crt_len, int non_crt_len, long iters)
|
||||
Worker_Params *p, params[num_threads];
|
||||
pthread_t threads[num_threads];
|
||||
|
||||
pthread_mutex_init (&lock, &attr);
|
||||
LOCK_INIT (&lock, &attr);
|
||||
pthread_barrier_init (&barrier, NULL, num_threads);
|
||||
|
||||
for (i = 0; i < num_threads; i++)
|
||||
@ -137,7 +136,7 @@ do_one_test (int num_threads, int crt_len, int non_crt_len, long iters)
|
||||
for (i = 0; i < num_threads; i++)
|
||||
pthread_join (threads[i], NULL);
|
||||
|
||||
pthread_mutex_destroy (&lock);
|
||||
LOCK_DESTROY (&lock);
|
||||
pthread_barrier_destroy (&barrier);
|
||||
|
||||
mean = 0;
|
||||
@ -246,7 +245,7 @@ do_bench (void)
|
||||
char name[128];
|
||||
|
||||
json_init (&json_ctx, 2, stdout);
|
||||
json_attr_object_begin (&json_ctx, "pthread_mutex_locks");
|
||||
json_attr_object_begin (&json_ctx, TEST_NAME);
|
||||
|
||||
/* The thread config begins from 1, and increases by 2x until nprocs.
|
||||
We also wants to test over-saturation case (1.25*nprocs). */
|
||||
@ -260,8 +259,7 @@ do_bench (void)
|
||||
threads[th_conf++] = nprocs;
|
||||
threads[th_conf++] = nprocs + nprocs / 4;
|
||||
|
||||
pthread_mutexattr_init (&attr);
|
||||
pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
|
||||
LOCK_ATTR_INIT (&attr);
|
||||
snprintf (name, sizeof name, "type=adaptive");
|
||||
|
||||
for (k = 0; k < (sizeof (non_crt_lens) / sizeof (int)); k++)
|
32
benchtests/bench-pthread-mutex-lock.c
Normal file
32
benchtests/bench-pthread-mutex-lock.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* Measure mutex_lock for different threads and critical sections.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define LOCK(lock) pthread_mutex_lock (lock)
|
||||
#define UNLOCK(lock) pthread_mutex_unlock (lock)
|
||||
#define LOCK_INIT(lock, attr) pthread_mutex_init (lock, attr)
|
||||
#define LOCK_DESTROY(lock) pthread_mutex_destroy (lock)
|
||||
#define LOCK_ATTR_INIT(attr) \
|
||||
pthread_mutexattr_init (attr); \
|
||||
pthread_mutexattr_settype (attr, PTHREAD_MUTEX_ADAPTIVE_NP);
|
||||
|
||||
#define bench_lock_t pthread_mutex_t
|
||||
#define bench_lock_attr_t pthread_mutexattr_t
|
||||
|
||||
#define TEST_NAME "pthread-mutex-lock"
|
||||
|
||||
#include "bench-pthread-lock-base.c"
|
37
benchtests/bench-pthread-mutex-trylock.c
Normal file
37
benchtests/bench-pthread-mutex-trylock.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* Measure mutex_trylock for different threads and critical sections.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define LOCK(lock) \
|
||||
while (pthread_mutex_trylock (lock) != 0) \
|
||||
{ \
|
||||
non_critical_section (non_crt_len); \
|
||||
}
|
||||
|
||||
#define UNLOCK(lock) pthread_mutex_unlock (lock)
|
||||
#define LOCK_INIT(lock, attr) pthread_mutex_init (lock, attr)
|
||||
#define LOCK_DESTROY(lock) pthread_mutex_destroy (lock)
|
||||
#define LOCK_ATTR_INIT(attr) \
|
||||
pthread_mutexattr_init (attr); \
|
||||
pthread_mutexattr_settype (attr, PTHREAD_MUTEX_ADAPTIVE_NP);
|
||||
|
||||
#define bench_lock_t pthread_mutex_t
|
||||
#define bench_lock_attr_t pthread_mutexattr_t
|
||||
|
||||
#define TEST_NAME "pthread-mutex-trylock"
|
||||
|
||||
#include "bench-pthread-lock-base.c"
|
30
benchtests/bench-pthread-spin-lock.c
Normal file
30
benchtests/bench-pthread-spin-lock.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* Measure mutex_trylock for different threads and critical sections.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define LOCK(lock) pthread_spin_lock (lock)
|
||||
#define UNLOCK(lock) pthread_spin_unlock (lock)
|
||||
#define LOCK_INIT(lock, attr) pthread_spin_init (lock, *(attr))
|
||||
#define LOCK_DESTROY(lock) pthread_spin_destroy (lock)
|
||||
#define LOCK_ATTR_INIT(attr) *(attr) = 0
|
||||
|
||||
#define bench_lock_t pthread_spinlock_t
|
||||
#define bench_lock_attr_t int
|
||||
|
||||
#define TEST_NAME "pthread-spin-lock"
|
||||
|
||||
#include "bench-pthread-lock-base.c"
|
34
benchtests/bench-pthread-spin-trylock.c
Normal file
34
benchtests/bench-pthread-spin-trylock.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* Measure spin_trylock for different threads and critical sections.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define LOCK(lock) \
|
||||
while (pthread_spin_lock (lock) != 0) \
|
||||
{ \
|
||||
non_critical_section (non_crt_len); \
|
||||
}
|
||||
#define UNLOCK(lock) pthread_spin_unlock (lock)
|
||||
#define LOCK_INIT(lock, attr) pthread_spin_init (lock, *(attr))
|
||||
#define LOCK_DESTROY(lock) pthread_spin_destroy (lock)
|
||||
#define LOCK_ATTR_INIT(attr) *(attr) = 0
|
||||
|
||||
#define bench_lock_t pthread_spinlock_t
|
||||
#define bench_lock_attr_t int
|
||||
|
||||
#define TEST_NAME "pthread-spin-trylock"
|
||||
|
||||
#include "bench-pthread-lock-base.c"
|
Loading…
Reference in New Issue
Block a user