History

perf bench: Fix epoll bench to correct usage of affinity for machines with #CPUs > 1K

The 'perf bench epoll' testcase fails on systems with more than 1K CPUs. Testcase: perf bench epoll all Result snippet: <<>> Run summary [PID 106497]: 1399 threads monitoring on 64 file-descriptors for 8 secs. perf: pthread_create: No such file or directory <<>> In epoll benchmarks (ctl, wait) pthread_create is invoked in do_threads from respective bench_epoll_* function. Though the logs shows direct failure from pthread_create, the actual failure is from "sched_setaffinity" returning EINVAL (invalid argument). This happens because the default mask size in glibc is 1024. To overcome this 1024 CPUs mask size limitation of cpu_set_t, change the mask size using the CPU_*_S macros. Patch addresses this by fixing all the epoll benchmarks to use CPU_ALLOC to allocate cpumask, CPU_ALLOC_SIZE for size, and CPU_SET_S to set the mask.

Athira Rajeev committed 4 years ago

Commit 299687e1 parent c9c2a422 files · +38 −12Browse files

Unified · Split

2 files
  1. tools/perf/bench/epoll-ctl.c +19 −6
  2. tools/perf/bench/epoll-wait.c +19 −6
tools/perf/bench/epoll-ctl.c+19−6
@@ -222,13 +222,20 @@ static void init_fdmaps(struct worker *w, int pct) · 221 unmodified lines
222222 static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)
223223 {
224224 pthread_attr_t thread_attr, *attrp = NULL;
225− cpu_set_t cpuset;
225+ cpu_set_t *cpuset;
226226 unsigned int i, j;
227227 int ret = 0;
228+ int nrcpus;
229+ size_t size;
228230
229231 if (!noaffinity)
230232 pthread_attr_init(&thread_attr);
231233
234+ nrcpus = perf_cpu_map__nr(cpu);
235+ cpuset = CPU_ALLOC(nrcpus);
236+ BUG_ON(!cpuset);
237+ size = CPU_ALLOC_SIZE(nrcpus);
238+
232239 for (i = 0; i < nthreads; i++) {
233240 struct worker *w = &worker[i];
234241
@@ -252,22 +259,28 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) · 17 unmodified lines
252259 init_fdmaps(w, 50);
253260
254261 if (!noaffinity) {
255− CPU_ZERO(&cpuset);
256− CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset);
262+ CPU_ZERO_S(size, cpuset);
263+ CPU_SET_S(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu,
264+ size, cpuset);
257265
258− ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset);
259− if (ret)
266+ ret = pthread_attr_setaffinity_np(&thread_attr, size, cpuset);
267+ if (ret) {
268+ CPU_FREE(cpuset);
260269 err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
270+ }
261271
262272 attrp = &thread_attr;
263273 }
264274
265275 ret = pthread_create(&w->thread, attrp, workerfn,
266276 (void *)(struct worker *) w);
267− if (ret)
277+ if (ret) {
278+ CPU_FREE(cpuset);
268279 err(EXIT_FAILURE, "pthread_create");
280+ }
269281 }
270282
283+ CPU_FREE(cpuset);
271284 if (!noaffinity)
272285 pthread_attr_destroy(&thread_attr);
273286
tools/perf/bench/epoll-wait.c+19−6
@@ -291,9 +291,11 @@ static void print_summary(void) · 290 unmodified lines
291291 static int do_threads(struct worker *worker, struct perf_cpu_map *cpu)
292292 {
293293 pthread_attr_t thread_attr, *attrp = NULL;
294− cpu_set_t cpuset;
294+ cpu_set_t *cpuset;
295295 unsigned int i, j;
296296 int ret = 0, events = EPOLLIN;
297+ int nrcpus;
298+ size_t size;
297299
298300 if (oneshot)
299301 events |= EPOLLONESHOT;
@@ -306,6 +308,11 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) · 6 unmodified lines
306308 if (!noaffinity)
307309 pthread_attr_init(&thread_attr);
308310
311+ nrcpus = perf_cpu_map__nr(cpu);
312+ cpuset = CPU_ALLOC(nrcpus);
313+ BUG_ON(!cpuset);
314+ size = CPU_ALLOC_SIZE(nrcpus);
315+
309316 for (i = 0; i < nthreads; i++) {
310317 struct worker *w = &worker[i];
311318
@@ -341,22 +348,28 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) · 29 unmodified lines
341348 }
342349
343350 if (!noaffinity) {
344− CPU_ZERO(&cpuset);
345− CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset);
351+ CPU_ZERO_S(size, cpuset);
352+ CPU_SET_S(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu,
353+ size, cpuset);
346354
347− ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset);
348− if (ret)
355+ ret = pthread_attr_setaffinity_np(&thread_attr, size, cpuset);
356+ if (ret) {
357+ CPU_FREE(cpuset);
349358 err(EXIT_FAILURE, "pthread_attr_setaffinity_np");
359+ }
350360
351361 attrp = &thread_attr;
352362 }
353363
354364 ret = pthread_create(&w->thread, attrp, workerfn,
355365 (void *)(struct worker *) w);
356− if (ret)
366+ if (ret) {
367+ CPU_FREE(cpuset);
357368 err(EXIT_FAILURE, "pthread_create");
369+ }
358370 }
359371
372+ CPU_FREE(cpuset);
360373 if (!noaffinity)
361374 pthread_attr_destroy(&thread_attr);
362375

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t