Merge tag 'perf-urgent-2020-03-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf fixes from Thomas Gleixner:
"A pile of perf fixes:

Kernel side:

- AMD uncore driver: Replace the open coded sanity check with the
core variant, which provides the correct error code and also leaves
a hint in dmesg

Tooling:

- Fix the stdio input handling with glibc versions >= 2.28

- Unbreak the futex-wake benchmark which was reduced to 0 test
threads due to the conversion to cpumaps

- Initialize sigaction structs before invoking sys_sigactio()

- Plug the mapfile memory leak in perf jevents

- Fix off by one relative directory includes

- Fix an undefined string comparison in perf diff"

* tag 'perf-urgent-2020-03-15' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/amd/uncore: Replace manual sampling check with CAP_NO_INTERRUPT flag
tools: Fix off-by 1 relative directory includes
perf jevents: Fix leak of mapfile memory
perf bench: Clear struct sigaction before sigaction() syscall
perf bench futex-wake: Restore thread count default to online CPU count
perf top: Fix stdio interface input handling with glibc 2.28+
perf diff: Fix undefined string comparision spotted by clang's -Wstring-compare
perf symbols: Don't try to find a vmlinux file when looking for kernel modules
perf bench: Share some global variables to fix build with gcc 10
perf parse-events: Use asprintf() instead of strncpy() to read tracepoint files
perf env: Do not return pointers to local variables
perf tests bp_account: Make global variable static

+7 -10
arch/x86/events/amd/uncore.c
··· 190 191 /* 192 * NB and Last level cache counters (MSRs) are shared across all cores 193 - * that share the same NB / Last level cache. Interrupts can be directed 194 - * to a single target core, however, event counts generated by processes 195 - * running on other cores cannot be masked out. So we do not support 196 - * sampling and per-thread events. 197 */ 198 - if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK) 199 - return -EINVAL; 200 - 201 - /* and we do not enable counter overflow interrupts */ 202 hwc->config = event->attr.config & AMD64_RAW_EVENT_MASK_NB; 203 hwc->idx = -1; 204 ··· 303 .start = amd_uncore_start, 304 .stop = amd_uncore_stop, 305 .read = amd_uncore_read, 306 - .capabilities = PERF_PMU_CAP_NO_EXCLUDE, 307 }; 308 309 static struct pmu amd_llc_pmu = { ··· 314 .start = amd_uncore_start, 315 .stop = amd_uncore_stop, 316 .read = amd_uncore_read, 317 - .capabilities = PERF_PMU_CAP_NO_EXCLUDE, 318 }; 319 320 static struct amd_uncore *amd_uncore_alloc(unsigned int cpu)
··· 190 191 /* 192 * NB and Last level cache counters (MSRs) are shared across all cores 193 + * that share the same NB / Last level cache. On family 16h and below, 194 + * Interrupts can be directed to a single target core, however, event 195 + * counts generated by processes running on other cores cannot be masked 196 + * out. So we do not support sampling and per-thread events via 197 + * CAP_NO_INTERRUPT, and we do not enable counter overflow interrupts: 198 */ 199 hwc->config = event->attr.config & AMD64_RAW_EVENT_MASK_NB; 200 hwc->idx = -1; 201 ··· 306 .start = amd_uncore_start, 307 .stop = amd_uncore_stop, 308 .read = amd_uncore_read, 309 + .capabilities = PERF_PMU_CAP_NO_EXCLUDE | PERF_PMU_CAP_NO_INTERRUPT, 310 }; 311 312 static struct pmu amd_llc_pmu = { ··· 317 .start = amd_uncore_start, 318 .stop = amd_uncore_stop, 319 .read = amd_uncore_read, 320 + .capabilities = PERF_PMU_CAP_NO_EXCLUDE | PERF_PMU_CAP_NO_INTERRUPT, 321 }; 322 323 static struct amd_uncore *amd_uncore_alloc(unsigned int cpu)
+7 -7
tools/include/uapi/asm/errno.h
··· 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #if defined(__i386__) || defined(__x86_64__) 3 - #include "../../arch/x86/include/uapi/asm/errno.h" 4 #elif defined(__powerpc__) 5 - #include "../../arch/powerpc/include/uapi/asm/errno.h" 6 #elif defined(__sparc__) 7 - #include "../../arch/sparc/include/uapi/asm/errno.h" 8 #elif defined(__alpha__) 9 - #include "../../arch/alpha/include/uapi/asm/errno.h" 10 #elif defined(__mips__) 11 - #include "../../arch/mips/include/uapi/asm/errno.h" 12 #elif defined(__ia64__) 13 - #include "../../arch/ia64/include/uapi/asm/errno.h" 14 #elif defined(__xtensa__) 15 - #include "../../arch/xtensa/include/uapi/asm/errno.h" 16 #else 17 #include <asm-generic/errno.h> 18 #endif
··· 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #if defined(__i386__) || defined(__x86_64__) 3 + #include "../../../arch/x86/include/uapi/asm/errno.h" 4 #elif defined(__powerpc__) 5 + #include "../../../arch/powerpc/include/uapi/asm/errno.h" 6 #elif defined(__sparc__) 7 + #include "../../../arch/sparc/include/uapi/asm/errno.h" 8 #elif defined(__alpha__) 9 + #include "../../../arch/alpha/include/uapi/asm/errno.h" 10 #elif defined(__mips__) 11 + #include "../../../arch/mips/include/uapi/asm/errno.h" 12 #elif defined(__ia64__) 13 + #include "../../../arch/ia64/include/uapi/asm/errno.h" 14 #elif defined(__xtensa__) 15 + #include "../../../arch/xtensa/include/uapi/asm/errno.h" 16 #else 17 #include <asm-generic/errno.h> 18 #endif
+10 -10
tools/perf/arch/arm64/util/arm-spe.c
··· 11 #include <linux/zalloc.h> 12 #include <time.h> 13 14 - #include "../../util/cpumap.h" 15 - #include "../../util/event.h" 16 - #include "../../util/evsel.h" 17 - #include "../../util/evlist.h" 18 - #include "../../util/session.h" 19 #include <internal/lib.h> // page_size 20 - #include "../../util/pmu.h" 21 - #include "../../util/debug.h" 22 - #include "../../util/auxtrace.h" 23 - #include "../../util/record.h" 24 - #include "../../util/arm-spe.h" 25 26 #define KiB(x) ((x) * 1024) 27 #define MiB(x) ((x) * 1024 * 1024)
··· 11 #include <linux/zalloc.h> 12 #include <time.h> 13 14 + #include "../../../util/cpumap.h" 15 + #include "../../../util/event.h" 16 + #include "../../../util/evsel.h" 17 + #include "../../../util/evlist.h" 18 + #include "../../../util/session.h" 19 #include <internal/lib.h> // page_size 20 + #include "../../../util/pmu.h" 21 + #include "../../../util/debug.h" 22 + #include "../../../util/auxtrace.h" 23 + #include "../../../util/record.h" 24 + #include "../../../util/arm-spe.h" 25 26 #define KiB(x) ((x) * 1024) 27 #define MiB(x) ((x) * 1024 * 1024)
+1 -1
tools/perf/arch/arm64/util/perf_regs.c
··· 1 // SPDX-License-Identifier: GPL-2.0 2 - #include "../../util/perf_regs.h" 3 4 const struct sample_reg sample_reg_masks[] = { 5 SMPL_REG_END
··· 1 // SPDX-License-Identifier: GPL-2.0 2 + #include "../../../util/perf_regs.h" 3 4 const struct sample_reg sample_reg_masks[] = { 5 SMPL_REG_END
+2 -2
tools/perf/arch/powerpc/util/perf_regs.c
··· 4 #include <regex.h> 5 #include <linux/zalloc.h> 6 7 - #include "../../util/perf_regs.h" 8 - #include "../../util/debug.h" 9 10 #include <linux/kernel.h> 11
··· 4 #include <regex.h> 5 #include <linux/zalloc.h> 6 7 + #include "../../../util/perf_regs.h" 8 + #include "../../../util/debug.h" 9 10 #include <linux/kernel.h> 11
+7 -7
tools/perf/arch/x86/util/auxtrace.c
··· 7 #include <errno.h> 8 #include <stdbool.h> 9 10 - #include "../../util/header.h" 11 - #include "../../util/debug.h" 12 - #include "../../util/pmu.h" 13 - #include "../../util/auxtrace.h" 14 - #include "../../util/intel-pt.h" 15 - #include "../../util/intel-bts.h" 16 - #include "../../util/evlist.h" 17 18 static 19 struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
··· 7 #include <errno.h> 8 #include <stdbool.h> 9 10 + #include "../../../util/header.h" 11 + #include "../../../util/debug.h" 12 + #include "../../../util/pmu.h" 13 + #include "../../../util/auxtrace.h" 14 + #include "../../../util/intel-pt.h" 15 + #include "../../../util/intel-bts.h" 16 + #include "../../../util/evlist.h" 17 18 static 19 struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist,
+6 -6
tools/perf/arch/x86/util/event.c
··· 3 #include <linux/string.h> 4 #include <linux/zalloc.h> 5 6 - #include "../../util/event.h" 7 - #include "../../util/synthetic-events.h" 8 - #include "../../util/machine.h" 9 - #include "../../util/tool.h" 10 - #include "../../util/map.h" 11 - #include "../../util/debug.h" 12 13 #if defined(__x86_64__) 14
··· 3 #include <linux/string.h> 4 #include <linux/zalloc.h> 5 6 + #include "../../../util/event.h" 7 + #include "../../../util/synthetic-events.h" 8 + #include "../../../util/machine.h" 9 + #include "../../../util/tool.h" 10 + #include "../../../util/map.h" 11 + #include "../../../util/debug.h" 12 13 #if defined(__x86_64__) 14
+2 -2
tools/perf/arch/x86/util/header.c
··· 7 #include <string.h> 8 #include <regex.h> 9 10 - #include "../../util/debug.h" 11 - #include "../../util/header.h" 12 13 static inline void 14 cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c,
··· 7 #include <string.h> 8 #include <regex.h> 9 10 + #include "../../../util/debug.h" 11 + #include "../../../util/header.h" 12 13 static inline void 14 cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c,
+12 -12
tools/perf/arch/x86/util/intel-bts.c
··· 11 #include <linux/log2.h> 12 #include <linux/zalloc.h> 13 14 - #include "../../util/cpumap.h" 15 - #include "../../util/event.h" 16 - #include "../../util/evsel.h" 17 - #include "../../util/evlist.h" 18 - #include "../../util/mmap.h" 19 - #include "../../util/session.h" 20 - #include "../../util/pmu.h" 21 - #include "../../util/debug.h" 22 - #include "../../util/record.h" 23 - #include "../../util/tsc.h" 24 - #include "../../util/auxtrace.h" 25 - #include "../../util/intel-bts.h" 26 #include <internal/lib.h> // page_size 27 28 #define KiB(x) ((x) * 1024)
··· 11 #include <linux/log2.h> 12 #include <linux/zalloc.h> 13 14 + #include "../../../util/cpumap.h" 15 + #include "../../../util/event.h" 16 + #include "../../../util/evsel.h" 17 + #include "../../../util/evlist.h" 18 + #include "../../../util/mmap.h" 19 + #include "../../../util/session.h" 20 + #include "../../../util/pmu.h" 21 + #include "../../../util/debug.h" 22 + #include "../../../util/record.h" 23 + #include "../../../util/tsc.h" 24 + #include "../../../util/auxtrace.h" 25 + #include "../../../util/intel-bts.h" 26 #include <internal/lib.h> // page_size 27 28 #define KiB(x) ((x) * 1024)
+15 -15
tools/perf/arch/x86/util/intel-pt.c
··· 13 #include <linux/zalloc.h> 14 #include <cpuid.h> 15 16 - #include "../../util/session.h" 17 - #include "../../util/event.h" 18 - #include "../../util/evlist.h" 19 - #include "../../util/evsel.h" 20 - #include "../../util/evsel_config.h" 21 - #include "../../util/cpumap.h" 22 - #include "../../util/mmap.h" 23 #include <subcmd/parse-options.h> 24 - #include "../../util/parse-events.h" 25 - #include "../../util/pmu.h" 26 - #include "../../util/debug.h" 27 - #include "../../util/auxtrace.h" 28 - #include "../../util/record.h" 29 - #include "../../util/target.h" 30 - #include "../../util/tsc.h" 31 #include <internal/lib.h> // page_size 32 - #include "../../util/intel-pt.h" 33 34 #define KiB(x) ((x) * 1024) 35 #define MiB(x) ((x) * 1024 * 1024)
··· 13 #include <linux/zalloc.h> 14 #include <cpuid.h> 15 16 + #include "../../../util/session.h" 17 + #include "../../../util/event.h" 18 + #include "../../../util/evlist.h" 19 + #include "../../../util/evsel.h" 20 + #include "../../../util/evsel_config.h" 21 + #include "../../../util/cpumap.h" 22 + #include "../../../util/mmap.h" 23 #include <subcmd/parse-options.h> 24 + #include "../../../util/parse-events.h" 25 + #include "../../../util/pmu.h" 26 + #include "../../../util/debug.h" 27 + #include "../../../util/auxtrace.h" 28 + #include "../../../util/record.h" 29 + #include "../../../util/target.h" 30 + #include "../../../util/tsc.h" 31 #include <internal/lib.h> // page_size 32 + #include "../../../util/intel-pt.h" 33 34 #define KiB(x) ((x) * 1024) 35 #define MiB(x) ((x) * 1024 * 1024)
+3 -3
tools/perf/arch/x86/util/machine.c
··· 5 #include <stdlib.h> 6 7 #include <internal/lib.h> // page_size 8 - #include "../../util/machine.h" 9 - #include "../../util/map.h" 10 - #include "../../util/symbol.h" 11 #include <linux/ctype.h> 12 13 #include <symbol/kallsyms.h>
··· 5 #include <stdlib.h> 6 7 #include <internal/lib.h> // page_size 8 + #include "../../../util/machine.h" 9 + #include "../../../util/map.h" 10 + #include "../../../util/symbol.h" 11 #include <linux/ctype.h> 12 13 #include <symbol/kallsyms.h>
+4 -4
tools/perf/arch/x86/util/perf_regs.c
··· 5 #include <linux/kernel.h> 6 #include <linux/zalloc.h> 7 8 - #include "../../perf-sys.h" 9 - #include "../../util/perf_regs.h" 10 - #include "../../util/debug.h" 11 - #include "../../util/event.h" 12 13 const struct sample_reg sample_reg_masks[] = { 14 SMPL_REG(AX, PERF_REG_X86_AX),
··· 5 #include <linux/kernel.h> 6 #include <linux/zalloc.h> 7 8 + #include "../../../perf-sys.h" 9 + #include "../../../util/perf_regs.h" 10 + #include "../../../util/debug.h" 11 + #include "../../../util/event.h" 12 13 const struct sample_reg sample_reg_masks[] = { 14 SMPL_REG(AX, PERF_REG_X86_AX),
+3 -3
tools/perf/arch/x86/util/pmu.c
··· 4 #include <linux/stddef.h> 5 #include <linux/perf_event.h> 6 7 - #include "../../util/intel-pt.h" 8 - #include "../../util/intel-bts.h" 9 - #include "../../util/pmu.h" 10 11 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) 12 {
··· 4 #include <linux/stddef.h> 5 #include <linux/perf_event.h> 6 7 + #include "../../../util/intel-pt.h" 8 + #include "../../../util/intel-bts.h" 9 + #include "../../../util/pmu.h" 10 11 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) 12 {
+4
tools/perf/bench/bench.h
··· 2 #ifndef BENCH_H 3 #define BENCH_H 4 5 /* 6 * The madvise transparent hugepage constants were added in glibc 7 * 2.13. For compatibility with older versions of glibc, define these
··· 2 #ifndef BENCH_H 3 #define BENCH_H 4 5 + #include <sys/time.h> 6 + 7 + extern struct timeval bench__start, bench__end, bench__runtime; 8 + 9 /* 10 * The madvise transparent hugepage constants were added in glibc 11 * 2.13. For compatibility with older versions of glibc, define these
+4 -4
tools/perf/bench/epoll-ctl.c
··· 35 36 static unsigned int nthreads = 0; 37 static unsigned int nsecs = 8; 38 - struct timeval start, end, runtime; 39 static bool done, __verbose, randomize; 40 41 /* ··· 93 { 94 /* inform all threads that we're done for the day */ 95 done = true; 96 - gettimeofday(&end, NULL); 97 - timersub(&end, &start, &runtime); 98 } 99 100 static void nest_epollfd(void) ··· 312 exit(EXIT_FAILURE); 313 } 314 315 sigfillset(&act.sa_mask); 316 act.sa_sigaction = toggle_done; 317 sigaction(SIGINT, &act, NULL); ··· 361 362 threads_starting = nthreads; 363 364 - gettimeofday(&start, NULL); 365 366 do_threads(worker, cpu); 367
··· 35 36 static unsigned int nthreads = 0; 37 static unsigned int nsecs = 8; 38 static bool done, __verbose, randomize; 39 40 /* ··· 94 { 95 /* inform all threads that we're done for the day */ 96 done = true; 97 + gettimeofday(&bench__end, NULL); 98 + timersub(&bench__end, &bench__start, &bench__runtime); 99 } 100 101 static void nest_epollfd(void) ··· 313 exit(EXIT_FAILURE); 314 } 315 316 + memset(&act, 0, sizeof(act)); 317 sigfillset(&act.sa_mask); 318 act.sa_sigaction = toggle_done; 319 sigaction(SIGINT, &act, NULL); ··· 361 362 threads_starting = nthreads; 363 364 + gettimeofday(&bench__start, NULL); 365 366 do_threads(worker, cpu); 367
+6 -6
tools/perf/bench/epoll-wait.c
··· 90 91 static unsigned int nthreads = 0; 92 static unsigned int nsecs = 8; 93 - struct timeval start, end, runtime; 94 static bool wdone, done, __verbose, randomize, nonblocking; 95 96 /* ··· 275 { 276 /* inform all threads that we're done for the day */ 277 done = true; 278 - gettimeofday(&end, NULL); 279 - timersub(&end, &start, &runtime); 280 } 281 282 static void print_summary(void) ··· 286 287 printf("\nAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", 288 avg, rel_stddev_stats(stddev, avg), 289 - (int) runtime.tv_sec); 290 } 291 292 static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) ··· 426 exit(EXIT_FAILURE); 427 } 428 429 sigfillset(&act.sa_mask); 430 act.sa_sigaction = toggle_done; 431 sigaction(SIGINT, &act, NULL); ··· 479 480 threads_starting = nthreads; 481 482 - gettimeofday(&start, NULL); 483 484 do_threads(worker, cpu); 485 ··· 519 qsort(worker, nthreads, sizeof(struct worker), cmpworker); 520 521 for (i = 0; i < nthreads; i++) { 522 - unsigned long t = worker[i].ops/runtime.tv_sec; 523 524 update_stats(&throughput_stats, t); 525
··· 90 91 static unsigned int nthreads = 0; 92 static unsigned int nsecs = 8; 93 static bool wdone, done, __verbose, randomize, nonblocking; 94 95 /* ··· 276 { 277 /* inform all threads that we're done for the day */ 278 done = true; 279 + gettimeofday(&bench__end, NULL); 280 + timersub(&bench__end, &bench__start, &bench__runtime); 281 } 282 283 static void print_summary(void) ··· 287 288 printf("\nAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", 289 avg, rel_stddev_stats(stddev, avg), 290 + (int)bench__runtime.tv_sec); 291 } 292 293 static int do_threads(struct worker *worker, struct perf_cpu_map *cpu) ··· 427 exit(EXIT_FAILURE); 428 } 429 430 + memset(&act, 0, sizeof(act)); 431 sigfillset(&act.sa_mask); 432 act.sa_sigaction = toggle_done; 433 sigaction(SIGINT, &act, NULL); ··· 479 480 threads_starting = nthreads; 481 482 + gettimeofday(&bench__start, NULL); 483 484 do_threads(worker, cpu); 485 ··· 519 qsort(worker, nthreads, sizeof(struct worker), cmpworker); 520 521 for (i = 0; i < nthreads; i++) { 522 + unsigned long t = worker[i].ops / bench__runtime.tv_sec; 523 524 update_stats(&throughput_stats, t); 525
+7 -6
tools/perf/bench/futex-hash.c
··· 37 static bool fshared = false, done = false, silent = false; 38 static int futex_flag = 0; 39 40 - struct timeval start, end, runtime; 41 static pthread_mutex_t thread_lock; 42 static unsigned int threads_starting; 43 static struct stats throughput_stats; ··· 103 { 104 /* inform all threads that we're done for the day */ 105 done = true; 106 - gettimeofday(&end, NULL); 107 - timersub(&end, &start, &runtime); 108 } 109 110 static void print_summary(void) ··· 114 115 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", 116 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), 117 - (int) runtime.tv_sec); 118 } 119 120 int bench_futex_hash(int argc, const char **argv) ··· 137 if (!cpu) 138 goto errmem; 139 140 sigfillset(&act.sa_mask); 141 act.sa_sigaction = toggle_done; 142 sigaction(SIGINT, &act, NULL); ··· 162 163 threads_starting = nthreads; 164 pthread_attr_init(&thread_attr); 165 - gettimeofday(&start, NULL); 166 for (i = 0; i < nthreads; i++) { 167 worker[i].tid = i; 168 worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex)); ··· 205 pthread_mutex_destroy(&thread_lock); 206 207 for (i = 0; i < nthreads; i++) { 208 - unsigned long t = worker[i].ops/runtime.tv_sec; 209 update_stats(&throughput_stats, t); 210 if (!silent) { 211 if (nfutexes == 1)
··· 37 static bool fshared = false, done = false, silent = false; 38 static int futex_flag = 0; 39 40 + struct timeval bench__start, bench__end, bench__runtime; 41 static pthread_mutex_t thread_lock; 42 static unsigned int threads_starting; 43 static struct stats throughput_stats; ··· 103 { 104 /* inform all threads that we're done for the day */ 105 done = true; 106 + gettimeofday(&bench__end, NULL); 107 + timersub(&bench__end, &bench__start, &bench__runtime); 108 } 109 110 static void print_summary(void) ··· 114 115 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", 116 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), 117 + (int)bench__runtime.tv_sec); 118 } 119 120 int bench_futex_hash(int argc, const char **argv) ··· 137 if (!cpu) 138 goto errmem; 139 140 + memset(&act, 0, sizeof(act)); 141 sigfillset(&act.sa_mask); 142 act.sa_sigaction = toggle_done; 143 sigaction(SIGINT, &act, NULL); ··· 161 162 threads_starting = nthreads; 163 pthread_attr_init(&thread_attr); 164 + gettimeofday(&bench__start, NULL); 165 for (i = 0; i < nthreads; i++) { 166 worker[i].tid = i; 167 worker[i].futex = calloc(nfutexes, sizeof(*worker[i].futex)); ··· 204 pthread_mutex_destroy(&thread_lock); 205 206 for (i = 0; i < nthreads; i++) { 207 + unsigned long t = worker[i].ops / bench__runtime.tv_sec; 208 update_stats(&throughput_stats, t); 209 if (!silent) { 210 if (nfutexes == 1)
+6 -6
tools/perf/bench/futex-lock-pi.c
··· 37 static bool done = false, fshared = false; 38 static unsigned int nthreads = 0; 39 static int futex_flag = 0; 40 - struct timeval start, end, runtime; 41 static pthread_mutex_t thread_lock; 42 static unsigned int threads_starting; 43 static struct stats throughput_stats; ··· 63 64 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", 65 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), 66 - (int) runtime.tv_sec); 67 } 68 69 static void toggle_done(int sig __maybe_unused, ··· 72 { 73 /* inform all threads that we're done for the day */ 74 done = true; 75 - gettimeofday(&end, NULL); 76 - timersub(&end, &start, &runtime); 77 } 78 79 static void *workerfn(void *arg) ··· 160 if (!cpu) 161 err(EXIT_FAILURE, "calloc"); 162 163 sigfillset(&act.sa_mask); 164 act.sa_sigaction = toggle_done; 165 sigaction(SIGINT, &act, NULL); ··· 185 186 threads_starting = nthreads; 187 pthread_attr_init(&thread_attr); 188 - gettimeofday(&start, NULL); 189 190 create_threads(worker, thread_attr, cpu); 191 pthread_attr_destroy(&thread_attr); ··· 211 pthread_mutex_destroy(&thread_lock); 212 213 for (i = 0; i < nthreads; i++) { 214 - unsigned long t = worker[i].ops/runtime.tv_sec; 215 216 update_stats(&throughput_stats, t); 217 if (!silent)
··· 37 static bool done = false, fshared = false; 38 static unsigned int nthreads = 0; 39 static int futex_flag = 0; 40 static pthread_mutex_t thread_lock; 41 static unsigned int threads_starting; 42 static struct stats throughput_stats; ··· 64 65 printf("%sAveraged %ld operations/sec (+- %.2f%%), total secs = %d\n", 66 !silent ? "\n" : "", avg, rel_stddev_stats(stddev, avg), 67 + (int)bench__runtime.tv_sec); 68 } 69 70 static void toggle_done(int sig __maybe_unused, ··· 73 { 74 /* inform all threads that we're done for the day */ 75 done = true; 76 + gettimeofday(&bench__end, NULL); 77 + timersub(&bench__end, &bench__start, &bench__runtime); 78 } 79 80 static void *workerfn(void *arg) ··· 161 if (!cpu) 162 err(EXIT_FAILURE, "calloc"); 163 164 + memset(&act, 0, sizeof(act)); 165 sigfillset(&act.sa_mask); 166 act.sa_sigaction = toggle_done; 167 sigaction(SIGINT, &act, NULL); ··· 185 186 threads_starting = nthreads; 187 pthread_attr_init(&thread_attr); 188 + gettimeofday(&bench__start, NULL); 189 190 create_threads(worker, thread_attr, cpu); 191 pthread_attr_destroy(&thread_attr); ··· 211 pthread_mutex_destroy(&thread_lock); 212 213 for (i = 0; i < nthreads; i++) { 214 + unsigned long t = worker[i].ops / bench__runtime.tv_sec; 215 216 update_stats(&throughput_stats, t); 217 if (!silent)
+1
tools/perf/bench/futex-requeue.c
··· 128 if (!cpu) 129 err(EXIT_FAILURE, "cpu_map__new"); 130 131 sigfillset(&act.sa_mask); 132 act.sa_sigaction = toggle_done; 133 sigaction(SIGINT, &act, NULL);
··· 128 if (!cpu) 129 err(EXIT_FAILURE, "cpu_map__new"); 130 131 + memset(&act, 0, sizeof(act)); 132 sigfillset(&act.sa_mask); 133 act.sa_sigaction = toggle_done; 134 sigaction(SIGINT, &act, NULL);
+1
tools/perf/bench/futex-wake-parallel.c
··· 234 exit(EXIT_FAILURE); 235 } 236 237 sigfillset(&act.sa_mask); 238 act.sa_sigaction = toggle_done; 239 sigaction(SIGINT, &act, NULL);
··· 234 exit(EXIT_FAILURE); 235 } 236 237 + memset(&act, 0, sizeof(act)); 238 sigfillset(&act.sa_mask); 239 act.sa_sigaction = toggle_done; 240 sigaction(SIGINT, &act, NULL);
+3 -2
tools/perf/bench/futex-wake.c
··· 43 static pthread_mutex_t thread_lock; 44 static pthread_cond_t thread_parent, thread_worker; 45 static struct stats waketime_stats, wakeup_stats; 46 - static unsigned int ncpus, threads_starting, nthreads = 0; 47 static int futex_flag = 0; 48 49 static const struct option options[] = { ··· 136 if (!cpu) 137 err(EXIT_FAILURE, "calloc"); 138 139 sigfillset(&act.sa_mask); 140 act.sa_sigaction = toggle_done; 141 sigaction(SIGINT, &act, NULL); 142 143 if (!nthreads) 144 - nthreads = ncpus; 145 146 worker = calloc(nthreads, sizeof(*worker)); 147 if (!worker)
··· 43 static pthread_mutex_t thread_lock; 44 static pthread_cond_t thread_parent, thread_worker; 45 static struct stats waketime_stats, wakeup_stats; 46 + static unsigned int threads_starting, nthreads = 0; 47 static int futex_flag = 0; 48 49 static const struct option options[] = { ··· 136 if (!cpu) 137 err(EXIT_FAILURE, "calloc"); 138 139 + memset(&act, 0, sizeof(act)); 140 sigfillset(&act.sa_mask); 141 act.sa_sigaction = toggle_done; 142 sigaction(SIGINT, &act, NULL); 143 144 if (!nthreads) 145 + nthreads = cpu->nr; 146 147 worker = calloc(nthreads, sizeof(*worker)); 148 if (!worker)
+2 -1
tools/perf/builtin-diff.c
··· 1312 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, 1313 he->ms.sym); 1314 1315 - if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) { 1316 scnprintf(buf, sizeof(buf), "[%s -> %s] %4ld", 1317 start_line, end_line, block_he->diff.cycles); 1318 } else {
··· 1312 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, 1313 he->ms.sym); 1314 1315 + if ((strncmp(start_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) && 1316 + (strncmp(end_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)) { 1317 scnprintf(buf, sizeof(buf), "[%s -> %s] %4ld", 1318 start_line, end_line, block_he->diff.cycles); 1319 } else {
+3 -1
tools/perf/builtin-top.c
··· 684 delay_msecs = top->delay_secs * MSEC_PER_SEC; 685 set_term_quiet_input(&save); 686 /* trash return*/ 687 - getc(stdin); 688 689 while (!done) { 690 perf_top__print_sym_table(top);
··· 684 delay_msecs = top->delay_secs * MSEC_PER_SEC; 685 set_term_quiet_input(&save); 686 /* trash return*/ 687 + clearerr(stdin); 688 + if (poll(&stdin_poll, 1, 0) > 0) 689 + getc(stdin); 690 691 while (!done) { 692 perf_top__print_sym_table(top);
+9 -6
tools/perf/pmu-events/jevents.c
··· 1082 */ 1083 int main(int argc, char *argv[]) 1084 { 1085 - int rc; 1086 int maxfds; 1087 char ldirname[PATH_MAX]; 1088 - 1089 const char *arch; 1090 const char *output_file; 1091 const char *start_dirname; ··· 1155 /* Make build fail */ 1156 fclose(eventsfp); 1157 free_arch_std_events(); 1158 - return 1; 1159 } else if (rc) { 1160 goto empty_map; 1161 } ··· 1174 /* Make build fail */ 1175 fclose(eventsfp); 1176 free_arch_std_events(); 1177 - return 1; 1178 } 1179 1180 - return 0; 1181 1182 empty_map: 1183 fclose(eventsfp); 1184 create_empty_mapping(output_file); 1185 free_arch_std_events(); 1186 - return 0; 1187 }
··· 1082 */ 1083 int main(int argc, char *argv[]) 1084 { 1085 + int rc, ret = 0; 1086 int maxfds; 1087 char ldirname[PATH_MAX]; 1088 const char *arch; 1089 const char *output_file; 1090 const char *start_dirname; ··· 1156 /* Make build fail */ 1157 fclose(eventsfp); 1158 free_arch_std_events(); 1159 + ret = 1; 1160 + goto out_free_mapfile; 1161 } else if (rc) { 1162 goto empty_map; 1163 } ··· 1174 /* Make build fail */ 1175 fclose(eventsfp); 1176 free_arch_std_events(); 1177 + ret = 1; 1178 } 1179 1180 + 1181 + goto out_free_mapfile; 1182 1183 empty_map: 1184 fclose(eventsfp); 1185 create_empty_mapping(output_file); 1186 free_arch_std_events(); 1187 + out_free_mapfile: 1188 + free(mapfile); 1189 + return ret; 1190 }
+1 -1
tools/perf/tests/bp_account.c
··· 19 #include "../perf-sys.h" 20 #include "cloexec.h" 21 22 - volatile long the_var; 23 24 static noinline int test_function(void) 25 {
··· 19 #include "../perf-sys.h" 20 #include "cloexec.h" 21 22 + static volatile long the_var; 23 24 static noinline int test_function(void) 25 {
+2 -1
tools/perf/util/block-info.c
··· 295 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, 296 he->ms.sym); 297 298 - if ((start_line != SRCLINE_UNKNOWN) && (end_line != SRCLINE_UNKNOWN)) { 299 scnprintf(buf, sizeof(buf), "[%s -> %s]", 300 start_line, end_line); 301 } else {
··· 295 end_line = map__srcline(he->ms.map, bi->sym->start + bi->end, 296 he->ms.sym); 297 298 + if ((strncmp(start_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) && 299 + (strncmp(end_line, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)) { 300 scnprintf(buf, sizeof(buf), "[%s -> %s]", 301 start_line, end_line); 302 } else {
+2 -2
tools/perf/util/env.c
··· 343 344 const char *perf_env__arch(struct perf_env *env) 345 { 346 - struct utsname uts; 347 char *arch_name; 348 349 if (!env || !env->arch) { /* Assume local operation */ 350 - if (uname(&uts) < 0) 351 return NULL; 352 arch_name = uts.machine; 353 } else
··· 343 344 const char *perf_env__arch(struct perf_env *env) 345 { 346 char *arch_name; 347 348 if (!env || !env->arch) { /* Assume local operation */ 349 + static struct utsname uts = { .machine[0] = '\0', }; 350 + if (uts.machine[0] == '\0' && uname(&uts) < 0) 351 return NULL; 352 arch_name = uts.machine; 353 } else
+1 -1
tools/perf/util/map.c
··· 431 432 if (map && map->dso) { 433 char *srcline = map__srcline(map, addr, NULL); 434 - if (srcline != SRCLINE_UNKNOWN) 435 ret = fprintf(fp, "%s%s", prefix, srcline); 436 free_srcline(srcline); 437 }
··· 431 432 if (map && map->dso) { 433 char *srcline = map__srcline(map, addr, NULL); 434 + if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) 435 ret = fprintf(fp, "%s%s", prefix, srcline); 436 free_srcline(srcline); 437 }
+2 -8
tools/perf/util/parse-events.c
··· 257 path = zalloc(sizeof(*path)); 258 if (!path) 259 return NULL; 260 - path->system = malloc(MAX_EVENT_LENGTH); 261 - if (!path->system) { 262 free(path); 263 return NULL; 264 } 265 - path->name = malloc(MAX_EVENT_LENGTH); 266 - if (!path->name) { 267 zfree(&path->system); 268 free(path); 269 return NULL; 270 } 271 - strncpy(path->system, sys_dirent->d_name, 272 - MAX_EVENT_LENGTH); 273 - strncpy(path->name, evt_dirent->d_name, 274 - MAX_EVENT_LENGTH); 275 return path; 276 } 277 }
··· 257 path = zalloc(sizeof(*path)); 258 if (!path) 259 return NULL; 260 + if (asprintf(&path->system, "%.*s", MAX_EVENT_LENGTH, sys_dirent->d_name) < 0) { 261 free(path); 262 return NULL; 263 } 264 + if (asprintf(&path->name, "%.*s", MAX_EVENT_LENGTH, evt_dirent->d_name) < 0) { 265 zfree(&path->system); 266 free(path); 267 return NULL; 268 } 269 return path; 270 } 271 }
+6 -7
tools/perf/util/symbol.c
··· 1622 goto out; 1623 } 1624 1625 - if (dso->kernel) { 1626 if (dso->kernel == DSO_TYPE_KERNEL) 1627 ret = dso__load_kernel_sym(dso, map); 1628 else if (dso->kernel == DSO_TYPE_GUEST_KERNEL) ··· 1654 name = malloc(PATH_MAX); 1655 if (!name) 1656 goto out; 1657 - 1658 - kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || 1659 - dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP || 1660 - dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE || 1661 - dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP; 1662 - 1663 1664 /* 1665 * Read the build id if possible. This is required for
··· 1622 goto out; 1623 } 1624 1625 + kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || 1626 + dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP || 1627 + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE || 1628 + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP; 1629 + 1630 + if (dso->kernel && !kmod) { 1631 if (dso->kernel == DSO_TYPE_KERNEL) 1632 ret = dso__load_kernel_sym(dso, map); 1633 else if (dso->kernel == DSO_TYPE_GUEST_KERNEL) ··· 1649 name = malloc(PATH_MAX); 1650 if (!name) 1651 goto out; 1652 1653 /* 1654 * Read the build id if possible. This is required for