Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Fix build on older glibcs

Where we don't have CPU_ALLOC & friends. As the tools are being used in older
distros where the only allowed change are to replace the kernel, like RHEL4 and
5.

Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Stephane Eranian <eranian@google.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+19 -14
+19 -14
tools/perf/builtin-test.c
··· 332 332 struct perf_evsel *evsel; 333 333 struct perf_event_attr attr; 334 334 unsigned int nr_open_calls = 111, i; 335 - cpu_set_t *cpu_set; 336 - size_t cpu_set_size; 335 + cpu_set_t cpu_set; 337 336 int id = trace_event__id("sys_enter_open"); 338 337 339 338 if (id < 0) { ··· 352 353 return -1; 353 354 } 354 355 355 - cpu_set = CPU_ALLOC(cpus->nr); 356 356 357 - if (cpu_set == NULL) 358 - goto out_thread_map_delete; 359 - 360 - cpu_set_size = CPU_ALLOC_SIZE(cpus->nr); 361 - CPU_ZERO_S(cpu_set_size, cpu_set); 357 + CPU_ZERO(&cpu_set); 362 358 363 359 memset(&attr, 0, sizeof(attr)); 364 360 attr.type = PERF_TYPE_TRACEPOINT; ··· 361 367 evsel = perf_evsel__new(&attr, 0); 362 368 if (evsel == NULL) { 363 369 pr_debug("perf_evsel__new\n"); 364 - goto out_cpu_free; 370 + goto out_thread_map_delete; 365 371 } 366 372 367 373 if (perf_evsel__open(evsel, cpus, threads) < 0) { ··· 373 379 374 380 for (cpu = 0; cpu < cpus->nr; ++cpu) { 375 381 unsigned int ncalls = nr_open_calls + cpu; 382 + /* 383 + * XXX eventually lift this restriction in a way that 384 + * keeps perf building on older glibc installations 385 + * without CPU_ALLOC. 1024 cpus in 2010 still seems 386 + * a reasonable upper limit tho :-) 387 + */ 388 + if (cpus->map[cpu] >= CPU_SETSIZE) { 389 + pr_debug("Ignoring CPU %d\n", cpus->map[cpu]); 390 + continue; 391 + } 376 392 377 - CPU_SET_S(cpus->map[cpu], cpu_set_size, cpu_set); 378 - if (sched_setaffinity(0, cpu_set_size, cpu_set) < 0) { 393 + CPU_SET(cpus->map[cpu], &cpu_set); 394 + if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { 379 395 pr_debug("sched_setaffinity() failed on CPU %d: %s ", 380 396 cpus->map[cpu], 381 397 strerror(errno)); ··· 395 391 fd = open("/etc/passwd", O_RDONLY); 396 392 close(fd); 397 393 } 398 - CPU_CLR_S(cpus->map[cpu], cpu_set_size, cpu_set); 394 + CPU_CLR(cpus->map[cpu], &cpu_set); 399 395 } 400 396 401 397 /* ··· 410 406 411 407 for (cpu = 0; cpu < cpus->nr; ++cpu) { 412 408 unsigned int expected; 409 + 410 + if (cpus->map[cpu] >= CPU_SETSIZE) 411 + continue; 413 412 414 413 if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) { 415 414 pr_debug("perf_evsel__open_read_on_cpu\n"); ··· 432 425 perf_evsel__close_fd(evsel, 1, threads->nr); 433 426 out_evsel_delete: 434 427 perf_evsel__delete(evsel); 435 - out_cpu_free: 436 - CPU_FREE(cpu_set); 437 428 out_thread_map_delete: 438 429 thread_map__delete(threads); 439 430 return err;