17 #include "../util/stat.h" 18 #include <subcmd/parse-options.h> 19 #include <linux/compiler.h> 20 #include <linux/kernel.h> 21 #include <linux/time64.h> 48 OPT_UINTEGER(
't',
"threads", &
nthreads,
"Specify amount of threads"),
49 OPT_UINTEGER(
'q',
"nrequeue", &
nrequeue,
"Specify amount of threads to requeue at once"),
50 OPT_BOOLEAN(
's',
"silent", &
silent,
"Silent mode: do not display data/details"),
51 OPT_BOOLEAN(
'S',
"shared", &
fshared,
"Use shared futexes instead of private ones"),
56 "perf bench futex requeue <options>",
62 double requeuetime_avg =
avg_stats(&requeuetime_stats);
63 double requeuetime_stddev =
stddev_stats(&requeuetime_stats);
66 printf(
"Requeued %d of %d threads in %.4f ms (+-%.2f%%)\n",
69 requeuetime_avg / USEC_PER_MSEC,
73 static void *
workerfn(
void *arg __maybe_unused)
87 pthread_attr_t thread_attr,
struct cpu_map *cpu)
97 CPU_SET(cpu->
map[i % cpu->
nr], &cpuset);
100 err(EXIT_FAILURE,
"pthread_attr_setaffinity_np");
102 if (pthread_create(&w[i], &thread_attr,
workerfn, NULL))
103 err(EXIT_FAILURE,
"pthread_create");
108 siginfo_t *info __maybe_unused,
109 void *uc __maybe_unused)
118 struct sigaction act;
119 pthread_attr_t thread_attr;
128 err(EXIT_FAILURE,
"cpu_map__new");
130 sigfillset(&act.sa_mask);
132 sigaction(SIGINT, &act, NULL);
139 err(EXIT_FAILURE,
"calloc");
147 printf(
"Run summary [PID %d]: Requeuing %d threads (from [%s] %p to %p), " 148 "%d at a time.\n\n", getpid(),
nthreads,
153 pthread_attr_init(&thread_attr);
159 unsigned int nrequeued = 0;
160 struct timeval start, end, runtime;
175 gettimeofday(&start, NULL);
185 gettimeofday(&end, NULL);
186 timersub(&end, &start, &runtime);
192 printf(
"[Run %d]: Requeued %d of %d threads in %.4f ms\n",
193 j + 1, nrequeued,
nthreads, runtime.tv_usec / (
double)USEC_PER_MSEC);
199 warnx(
"couldn't wakeup all tasks (%d/%d)", nrequeued,
nthreads);
202 ret = pthread_join(
worker[i], NULL);
204 err(EXIT_FAILURE,
"pthread_join");
212 pthread_attr_destroy(&thread_attr);
static void toggle_done(int sig __maybe_unused, siginfo_t *info __maybe_unused, void *uc __maybe_unused)
static pthread_cond_t thread_parent
double avg_stats(struct stats *stats)
static pthread_cond_t thread_worker
static pthread_t * worker
static int futex_cmp_requeue(u_int32_t *uaddr, u_int32_t val, u_int32_t *uaddr2, int nr_wake, int nr_requeue, int opflags)
static struct stats requeuetime_stats requeued_stats
double stddev_stats(struct stats *stats)
static unsigned int nrequeue
static unsigned int nthreads
static const char *const bench_futex_requeue_usage[]
static unsigned int threads_starting
static void init_stats(struct stats *stats)
static void print_summary(void)
static void * workerfn(void *arg __maybe_unused)
void update_stats(struct stats *stats, u64 val)
static int pthread_attr_setaffinity_np(pthread_attr_t *attr __maybe_unused, size_t cpusetsize __maybe_unused, cpu_set_t *cpuset __maybe_unused)
double rel_stddev_stats(double stddev, double avg)
static void block_threads(pthread_t *w, pthread_attr_t thread_attr, struct cpu_map *cpu)
static int futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
int bench_futex_requeue(int argc, const char **argv)
static pthread_mutex_t thread_lock
struct cpu_map * cpu_map__new(const char *cpu_list)
unsigned int bench_repeat
static int futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)