19 #include <linux/compiler.h> 20 #include <linux/kernel.h> 23 #include "../util/stat.h" 24 #include <subcmd/parse-options.h> 52 OPT_UINTEGER(
't',
"threads", &
nthreads,
"Specify amount of threads"),
53 OPT_UINTEGER(
'r',
"runtime", &
nsecs,
"Specify runtime (in seconds)"),
54 OPT_UINTEGER(
'f',
"futexes", &
nfutexes,
"Specify amount of futexes per threads"),
55 OPT_BOOLEAN(
's',
"silent", &
silent,
"Silent mode: do not display data/details"),
56 OPT_BOOLEAN(
'S',
"shared", &
fshared,
"Use shared futexes instead of private ones"),
61 "perf bench futex hash <options>",
70 unsigned long ops = w->
ops;
80 for (i = 0; i <
nfutexes; i++, ops++) {
89 (!ret || errno != EAGAIN || errno != EWOULDBLOCK))
90 warn(
"Non-expected futex return call");
99 siginfo_t *info __maybe_unused,
100 void *uc __maybe_unused)
104 gettimeofday(&end, NULL);
113 printf(
"%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
122 struct sigaction act;
124 pthread_attr_t thread_attr;
138 sigfillset(&act.sa_mask);
140 sigaction(SIGINT, &act, NULL);
145 worker = calloc(
nthreads,
sizeof(*worker));
152 printf(
"Run summary [PID %d]: %d threads, each operating on %d [%s] futexes for %d secs.\n\n",
161 pthread_attr_init(&thread_attr);
162 gettimeofday(&
start, NULL);
166 if (!worker[i].futex)
170 CPU_SET(cpu->
map[i % cpu->
nr], &cpuset);
174 err(EXIT_FAILURE,
"pthread_attr_setaffinity_np");
177 (
void *)(
struct worker *) &worker[i]);
179 err(EXIT_FAILURE,
"pthread_create");
182 pthread_attr_destroy(&thread_attr);
194 ret = pthread_join(worker[i].
thread, NULL);
196 err(EXIT_FAILURE,
"pthread_join");
205 unsigned long t = worker[i].
ops/
runtime.tv_sec;
209 printf(
"[thread %2d] futex: %p [ %ld ops/sec ]\n",
210 worker[i].
tid, &worker[i].
futex[0], t);
212 printf(
"[thread %2d] futexes: %p ... %p [ %ld ops/sec ]\n",
213 worker[i].tid, &worker[i].futex[0],
226 err(EXIT_FAILURE,
"calloc");
static unsigned int nfutexes
double avg_stats(struct stats *stats)
static pthread_mutex_t thread_lock
double stddev_stats(struct stats *stats)
static void init_stats(struct stats *stats)
static void * workerfn(void *arg)
void update_stats(struct stats *stats, u64 val)
static unsigned int nthreads
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 pthread_cond_t thread_parent
static const char *const bench_futex_hash_usage[]
static void print_summary(void)
static void toggle_done(int sig __maybe_unused, siginfo_t *info __maybe_unused, void *uc __maybe_unused)
static int futex_wait(u_int32_t *uaddr, u_int32_t val, struct timespec *timeout, int opflags)
static unsigned int threads_starting
static unsigned int nsecs
static struct stats throughput_stats
struct cpu_map * cpu_map__new(const char *cpu_list)
static pthread_cond_t thread_worker
int bench_futex_hash(int argc, const char **argv)
struct timeval start end runtime