Skip to content

Commit 299687e

Browse files
athira-rajeevacmel
authored andcommitted
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. Reported-by: Disha Goel <disgoel@linux.vnet.ibm.com> Signed-off-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com> Tested-by: Disha Goel <disgoel@linux.vnet.ibm.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nageswara R Sastry <rnsastry@linux.ibm.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: linuxppc-dev@lists.ozlabs.org Link: https://lore.kernel.org/r/20220406175113.87881-3-atrajeev@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent c9c2a42 commit 299687e

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

tools/perf/bench/epoll-ctl.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,20 @@ static void init_fdmaps(struct worker *w, int pct)
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)
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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,11 @@ static void print_summary(void)
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)
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)
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

0 commit comments

Comments
 (0)