|
@@ -30,16 +30,18 @@ static u_int32_t futex1 = 0, futex2 = 0;
|
|
static unsigned int nrequeue = 1;
|
|
static unsigned int nrequeue = 1;
|
|
|
|
|
|
static pthread_t *worker;
|
|
static pthread_t *worker;
|
|
-static bool done = 0, silent = 0;
|
|
|
|
|
|
+static bool done = false, silent = false, fshared = false;
|
|
static pthread_mutex_t thread_lock;
|
|
static pthread_mutex_t thread_lock;
|
|
static pthread_cond_t thread_parent, thread_worker;
|
|
static pthread_cond_t thread_parent, thread_worker;
|
|
static struct stats requeuetime_stats, requeued_stats;
|
|
static struct stats requeuetime_stats, requeued_stats;
|
|
static unsigned int ncpus, threads_starting, nthreads = 0;
|
|
static unsigned int ncpus, threads_starting, nthreads = 0;
|
|
|
|
+static int futex_flag = 0;
|
|
|
|
|
|
static const struct option options[] = {
|
|
static const struct option options[] = {
|
|
OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
|
|
OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"),
|
|
OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"),
|
|
OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"),
|
|
OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
|
|
OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"),
|
|
|
|
+ OPT_BOOLEAN( 'S', "shared", &fshared, "Use shared futexes instead of private ones"),
|
|
OPT_END()
|
|
OPT_END()
|
|
};
|
|
};
|
|
|
|
|
|
@@ -70,7 +72,7 @@ static void *workerfn(void *arg __maybe_unused)
|
|
pthread_cond_wait(&thread_worker, &thread_lock);
|
|
pthread_cond_wait(&thread_worker, &thread_lock);
|
|
pthread_mutex_unlock(&thread_lock);
|
|
pthread_mutex_unlock(&thread_lock);
|
|
|
|
|
|
- futex_wait(&futex1, 0, NULL, FUTEX_PRIVATE_FLAG);
|
|
|
|
|
|
+ futex_wait(&futex1, 0, NULL, futex_flag);
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -127,9 +129,12 @@ int bench_futex_requeue(int argc, const char **argv,
|
|
if (!worker)
|
|
if (!worker)
|
|
err(EXIT_FAILURE, "calloc");
|
|
err(EXIT_FAILURE, "calloc");
|
|
|
|
|
|
- printf("Run summary [PID %d]: Requeuing %d threads (from %p to %p), "
|
|
|
|
- "%d at a time.\n\n",
|
|
|
|
- getpid(), nthreads, &futex1, &futex2, nrequeue);
|
|
|
|
|
|
+ if (!fshared)
|
|
|
|
+ futex_flag = FUTEX_PRIVATE_FLAG;
|
|
|
|
+
|
|
|
|
+ printf("Run summary [PID %d]: Requeuing %d threads (from [%s] %p to %p), "
|
|
|
|
+ "%d at a time.\n\n", getpid(), nthreads,
|
|
|
|
+ fshared ? "shared":"private", &futex1, &futex2, nrequeue);
|
|
|
|
|
|
init_stats(&requeued_stats);
|
|
init_stats(&requeued_stats);
|
|
init_stats(&requeuetime_stats);
|
|
init_stats(&requeuetime_stats);
|
|
@@ -156,13 +161,14 @@ int bench_futex_requeue(int argc, const char **argv,
|
|
|
|
|
|
/* Ok, all threads are patiently blocked, start requeueing */
|
|
/* Ok, all threads are patiently blocked, start requeueing */
|
|
gettimeofday(&start, NULL);
|
|
gettimeofday(&start, NULL);
|
|
- for (nrequeued = 0; nrequeued < nthreads; nrequeued += nrequeue)
|
|
|
|
|
|
+ for (nrequeued = 0; nrequeued < nthreads; nrequeued += nrequeue) {
|
|
/*
|
|
/*
|
|
* Do not wakeup any tasks blocked on futex1, allowing
|
|
* Do not wakeup any tasks blocked on futex1, allowing
|
|
* us to really measure futex_wait functionality.
|
|
* us to really measure futex_wait functionality.
|
|
*/
|
|
*/
|
|
- futex_cmp_requeue(&futex1, 0, &futex2, 0, nrequeue,
|
|
|
|
- FUTEX_PRIVATE_FLAG);
|
|
|
|
|
|
+ futex_cmp_requeue(&futex1, 0, &futex2, 0,
|
|
|
|
+ nrequeue, futex_flag);
|
|
|
|
+ }
|
|
gettimeofday(&end, NULL);
|
|
gettimeofday(&end, NULL);
|
|
timersub(&end, &start, &runtime);
|
|
timersub(&end, &start, &runtime);
|
|
|
|
|
|
@@ -175,7 +181,7 @@ int bench_futex_requeue(int argc, const char **argv,
|
|
}
|
|
}
|
|
|
|
|
|
/* everybody should be blocked on futex2, wake'em up */
|
|
/* everybody should be blocked on futex2, wake'em up */
|
|
- nrequeued = futex_wake(&futex2, nthreads, FUTEX_PRIVATE_FLAG);
|
|
|
|
|
|
+ nrequeued = futex_wake(&futex2, nthreads, futex_flag);
|
|
if (nthreads != nrequeued)
|
|
if (nthreads != nrequeued)
|
|
warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads);
|
|
warnx("couldn't wakeup all tasks (%d/%d)", nrequeued, nthreads);
|
|
|
|
|