// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2013 Davidlohr Bueso <davidlohr@hp.com> * * futex-wake: Block a bunch of threads on a futex and wake'em up, N at a time. * * This program is particularly useful to measure the latency of nthread wakeups * in non-error situations: all waiters are queued and all wake calls wakeup * one or more tasks, and thus the waitqueue is never empty.
*/
/* For the CLR_() macros */ #include <string.h> #include <pthread.h>
staticstruct bench_futex_parameters params = {
.nbuckets = -1, /* * How many wakeups to do at a time. * Default to 1 in order to make the kernel work more.
*/
.nwakes = 1,
};
staticconststruct option options[] = {
OPT_INTEGER( 'b', "buckets", ¶ms.nbuckets, "Specify amount of hash buckets"),
OPT_UINTEGER('t', "threads", ¶ms.nthreads, "Specify amount of threads"),
OPT_UINTEGER('w', "nwakes", ¶ms.nwakes, "Specify amount of threads to wake at once"),
OPT_BOOLEAN( 's', "silent", ¶ms.silent, "Silent mode: do not display data/details"),
OPT_BOOLEAN( 'S', "shared", ¶ms.fshared, "Use shared futexes instead of private ones"),
OPT_BOOLEAN( 'm', "mlockall", ¶ms.mlockall, "Lock all current and future memory"),
/* create, launch & block all threads */
block_threads(worker, cpu);
/* make sure all threads are already blocked */
mutex_lock(&thread_lock); while (threads_starting)
cond_wait(&thread_parent, &thread_lock);
cond_broadcast(&thread_worker);
mutex_unlock(&thread_lock);
usleep(100000);
/* Ok, all threads are patiently blocked, start waking folks up */
gettimeofday(&start, NULL); while (nwoken != params.nthreads)
nwoken += futex_wake(&futex1,
params.nwakes, futex_flag);
gettimeofday(&end, NULL);
timersub(&end, &start, &runtime);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.