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