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.
Unified · Split
| @@ -222,13 +222,20 @@ static void init_fdmaps(struct worker *w, int pct) · 221 unmodified lines | ||
| 222 | 222 | static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) |
| 223 | 223 | { |
| 224 | 224 | pthread_attr_t thread_attr, *attrp = NULL; |
| 225 | − cpu_set_t cpuset; | |
| 225 | + cpu_set_t *cpuset; | |
| 226 | 226 | unsigned int i, j; |
| 227 | 227 | int ret = 0; |
| 228 | + int nrcpus; | |
| 229 | + size_t size; | |
| 228 | 230 | |
| 229 | 231 | if (!noaffinity) |
| 230 | 232 | pthread_attr_init(&thread_attr); |
| 231 | 233 | |
| 234 | + nrcpus = perf_cpu_map__nr(cpu); | |
| 235 | + cpuset = CPU_ALLOC(nrcpus); | |
| 236 | + BUG_ON(!cpuset); | |
| 237 | + size = CPU_ALLOC_SIZE(nrcpus); | |
| 238 | + | |
| 232 | 239 | for (i = 0; i < nthreads; i++) { |
| 233 | 240 | struct worker *w = &worker[i]; |
| 234 | 241 | |
| @@ -252,22 +259,28 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) · 17 unmodified lines | ||
| 252 | 259 | init_fdmaps(w, 50); |
| 253 | 260 | |
| 254 | 261 | 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); | |
| 257 | 265 | |
| 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); | |
| 260 | 269 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); |
| 270 | + } | |
| 261 | 271 | |
| 262 | 272 | attrp = &thread_attr; |
| 263 | 273 | } |
| 264 | 274 | |
| 265 | 275 | ret = pthread_create(&w->thread, attrp, workerfn, |
| 266 | 276 | (void *)(struct worker *) w); |
| 267 | − if (ret) | |
| 277 | + if (ret) { | |
| 278 | + CPU_FREE(cpuset); | |
| 268 | 279 | err(EXIT_FAILURE, "pthread_create"); |
| 280 | + } | |
| 269 | 281 | } |
| 270 | 282 | |
| 283 | + CPU_FREE(cpuset); | |
| 271 | 284 | if (!noaffinity) |
| 272 | 285 | pthread_attr_destroy(&thread_attr); |
| 273 | 286 | |
| @@ -291,9 +291,11 @@ static void print_summary(void) · 290 unmodified lines | ||
| 291 | 291 | static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) |
| 292 | 292 | { |
| 293 | 293 | pthread_attr_t thread_attr, *attrp = NULL; |
| 294 | − cpu_set_t cpuset; | |
| 294 | + cpu_set_t *cpuset; | |
| 295 | 295 | unsigned int i, j; |
| 296 | 296 | int ret = 0, events = EPOLLIN; |
| 297 | + int nrcpus; | |
| 298 | + size_t size; | |
| 297 | 299 | |
| 298 | 300 | if (oneshot) |
| 299 | 301 | events |= EPOLLONESHOT; |
| @@ -306,6 +308,11 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) · 6 unmodified lines | ||
| 306 | 308 | if (!noaffinity) |
| 307 | 309 | pthread_attr_init(&thread_attr); |
| 308 | 310 | |
| 311 | + nrcpus = perf_cpu_map__nr(cpu); | |
| 312 | + cpuset = CPU_ALLOC(nrcpus); | |
| 313 | + BUG_ON(!cpuset); | |
| 314 | + size = CPU_ALLOC_SIZE(nrcpus); | |
| 315 | + | |
| 309 | 316 | for (i = 0; i < nthreads; i++) { |
| 310 | 317 | struct worker *w = &worker[i]; |
| 311 | 318 | |
| @@ -341,22 +348,28 @@ static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) · 29 unmodified lines | ||
| 341 | 348 | } |
| 342 | 349 | |
| 343 | 350 | 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); | |
| 346 | 354 | |
| 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); | |
| 349 | 358 | err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); |
| 359 | + } | |
| 350 | 360 | |
| 351 | 361 | attrp = &thread_attr; |
| 352 | 362 | } |
| 353 | 363 | |
| 354 | 364 | ret = pthread_create(&w->thread, attrp, workerfn, |
| 355 | 365 | (void *)(struct worker *) w); |
| 356 | − if (ret) | |
| 366 | + if (ret) { | |
| 367 | + CPU_FREE(cpuset); | |
| 357 | 368 | err(EXIT_FAILURE, "pthread_create"); |
| 369 | + } | |
| 358 | 370 | } |
| 359 | 371 | |
| 372 | + CPU_FREE(cpuset); | |
| 360 | 373 | if (!noaffinity) |
| 361 | 374 | pthread_attr_destroy(&thread_attr); |
| 362 | 375 | |