11 #include "../util/stat.h" 12 #include <subcmd/parse-options.h> 13 #include <linux/compiler.h> 14 #include <linux/kernel.h> 45 OPT_UINTEGER(
't',
"threads", &
nthreads,
"Specify amount of threads"),
46 OPT_UINTEGER(
'r',
"runtime", &
nsecs,
"Specify runtime (in seconds)"),
47 OPT_BOOLEAN(
'M',
"multi", &
multi,
"Use multiple futexes"),
48 OPT_BOOLEAN(
's',
"silent", &
silent,
"Silent mode: do not display data/details"),
49 OPT_BOOLEAN(
'S',
"shared", &
fshared,
"Use shared futexes instead of private ones"),
54 "perf bench futex lock-pi <options>",
63 printf(
"%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n",
69 siginfo_t *info __maybe_unused,
70 void *uc __maybe_unused)
74 gettimeofday(&end, NULL);
80 struct worker *w = (
struct worker *) arg;
81 unsigned long ops = w->
ops;
97 warn(
"thread %d: Could not lock pi-lock for %p (%d)",
108 warn(
"thread %d: Could not unlock pi-lock for %p (%d)",
129 worker[i].
futex = calloc(1,
sizeof(u_int32_t));
130 if (!worker[i].
futex)
131 err(EXIT_FAILURE,
"calloc");
136 CPU_SET(cpu->
map[i % cpu->
nr], &cpuset);
139 err(EXIT_FAILURE,
"pthread_attr_setaffinity_np");
141 if (pthread_create(&w[i].
thread, &thread_attr,
workerfn, &worker[i]))
142 err(EXIT_FAILURE,
"pthread_create");
150 struct sigaction act;
151 pthread_attr_t thread_attr;
160 err(EXIT_FAILURE,
"calloc");
162 sigfillset(&act.sa_mask);
164 sigaction(SIGINT, &act, NULL);
169 worker = calloc(
nthreads,
sizeof(*worker));
171 err(EXIT_FAILURE,
"calloc");
176 printf(
"Run summary [PID %d]: %d threads doing pi lock/unlock pairing for %d secs.\n\n",
185 pthread_attr_init(&thread_attr);
186 gettimeofday(&
start, NULL);
189 pthread_attr_destroy(&thread_attr);
201 ret = pthread_join(worker[i].
thread, NULL);
203 err(EXIT_FAILURE,
"pthread_join");
212 unsigned long t = worker[i].
ops/
runtime.tv_sec;
216 printf(
"[thread %3d] futex: %p [ %ld ops/sec ]\n",
220 free(worker[i].futex);
double avg_stats(struct stats *stats)
static struct stats throughput_stats
int bench_futex_lock_pi(int argc, const char **argv)
static pthread_mutex_t thread_lock
double stddev_stats(struct stats *stats)
static void init_stats(struct stats *stats)
static void create_threads(struct worker *w, pthread_attr_t thread_attr, struct cpu_map *cpu)
void update_stats(struct stats *stats, u64 val)
static void print_summary(void)
static const char *const bench_futex_lock_pi_usage[]
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 * workerfn(void *arg)
static pthread_cond_t thread_parent
static pthread_cond_t thread_worker
static int futex_lock_pi(u_int32_t *uaddr, struct timespec *timeout, int opflags)
static struct worker * worker
static unsigned int threads_starting
static u_int32_t global_futex
static void toggle_done(int sig __maybe_unused, siginfo_t *info __maybe_unused, void *uc __maybe_unused)
static unsigned int nthreads
struct cpu_map * cpu_map__new(const char *cpu_list)
static unsigned int nsecs
struct timeval start end runtime
static int futex_unlock_pi(u_int32_t *uaddr, int opflags)