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> 49 OPT_UINTEGER(
't',
"threads", &
nthreads,
"Specify amount of threads"),
50 OPT_UINTEGER(
'w',
"nwakes", &
nwakes,
"Specify amount of threads to wake at once"),
51 OPT_BOOLEAN(
's',
"silent", &
silent,
"Silent mode: do not display data/details"),
52 OPT_BOOLEAN(
'S',
"shared", &
fshared,
"Use shared futexes instead of private ones"),
57 "perf bench futex wake <options>",
61 static void *
workerfn(
void *arg __maybe_unused)
81 double waketime_avg =
avg_stats(&waketime_stats);
85 printf(
"Wokeup %d of %d threads in %.4f ms (+-%.2f%%)\n",
88 waketime_avg / USEC_PER_MSEC,
93 pthread_attr_t thread_attr,
struct cpu_map *cpu)
103 CPU_SET(cpu->
map[i % cpu->
nr], &cpuset);
106 err(EXIT_FAILURE,
"pthread_attr_setaffinity_np");
108 if (pthread_create(&w[i], &thread_attr,
workerfn, NULL))
109 err(EXIT_FAILURE,
"pthread_create");
114 siginfo_t *info __maybe_unused,
115 void *uc __maybe_unused)
124 struct sigaction act;
125 pthread_attr_t thread_attr;
136 err(EXIT_FAILURE,
"calloc");
138 sigfillset(&act.sa_mask);
140 sigaction(SIGINT, &act, NULL);
147 err(EXIT_FAILURE,
"calloc");
152 printf(
"Run summary [PID %d]: blocking on %d threads (at [%s] futex %p), " 153 "waking up %d at a time.\n\n",
158 pthread_attr_init(&thread_attr);
164 unsigned int nwoken = 0;
165 struct timeval start, end, runtime;
180 gettimeofday(&start, NULL);
183 gettimeofday(&end, NULL);
184 timersub(&end, &start, &runtime);
190 printf(
"[Run %d]: Wokeup %d of %d threads in %.4f ms\n",
191 j + 1, nwoken,
nthreads, runtime.tv_usec / (
double)USEC_PER_MSEC);
195 ret = pthread_join(
worker[i], NULL);
197 err(EXIT_FAILURE,
"pthread_join");
206 pthread_attr_destroy(&thread_attr);
static void block_threads(pthread_t *w, pthread_attr_t thread_attr, struct cpu_map *cpu)
int bench_futex_wake(int argc, const char **argv)
double avg_stats(struct stats *stats)
static struct stats waketime_stats wakeup_stats
static const char *const bench_futex_wake_usage[]
double stddev_stats(struct stats *stats)
static void init_stats(struct stats *stats)
void update_stats(struct stats *stats, u64 val)
static void * workerfn(void *arg __maybe_unused)
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 unsigned int threads_starting
static unsigned int nwakes
static pthread_mutex_t thread_lock
static pthread_cond_t thread_parent
static int futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
static unsigned int ncpus
struct cpu_map * cpu_map__new(const char *cpu_list)
static void toggle_done(int sig __maybe_unused, siginfo_t *info __maybe_unused, void *uc __maybe_unused)
unsigned int bench_repeat
static int futex_wake(u_int32_t *uaddr, int nr_wake, int opflags)
static void print_summary(void)
static unsigned int nthreads
static pthread_cond_t thread_worker