aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/annotate.c8
-rw-r--r--tools/perf/util/c++/clang.cpp2
-rw-r--r--tools/perf/util/callchain.c32
-rw-r--r--tools/perf/util/callchain.h1
-rw-r--r--tools/perf/util/cpumap.c11
-rw-r--r--tools/perf/util/find-map.c (renamed from tools/perf/util/find-vdso-map.c)7
-rw-r--r--tools/perf/util/machine.c2
-rw-r--r--tools/perf/util/mem-events.c2
-rw-r--r--tools/perf/util/ordered-events.c6
-rw-r--r--tools/perf/util/setup.py2
-rw-r--r--tools/perf/util/strbuf.c1
-rw-r--r--tools/perf/util/symbol-elf.c23
-rw-r--r--tools/perf/util/symbol.c1
-rw-r--r--tools/perf/util/vdso.c6
14 files changed, 72 insertions, 32 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index ac9805e0bc76..70de8f6b3aee 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1723,15 +1723,14 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
1723 err = asprintf(&command, 1723 err = asprintf(&command,
1724 "%s %s%s --start-address=0x%016" PRIx64 1724 "%s %s%s --start-address=0x%016" PRIx64
1725 " --stop-address=0x%016" PRIx64 1725 " --stop-address=0x%016" PRIx64
1726 " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand", 1726 " -l -d %s %s -C \"$1\" 2>/dev/null|grep -v \"$1:\"|expand",
1727 opts->objdump_path ?: "objdump", 1727 opts->objdump_path ?: "objdump",
1728 opts->disassembler_style ? "-M " : "", 1728 opts->disassembler_style ? "-M " : "",
1729 opts->disassembler_style ?: "", 1729 opts->disassembler_style ?: "",
1730 map__rip_2objdump(map, sym->start), 1730 map__rip_2objdump(map, sym->start),
1731 map__rip_2objdump(map, sym->end), 1731 map__rip_2objdump(map, sym->end),
1732 opts->show_asm_raw ? "" : "--no-show-raw", 1732 opts->show_asm_raw ? "" : "--no-show-raw",
1733 opts->annotate_src ? "-S" : "", 1733 opts->annotate_src ? "-S" : "");
1734 symfs_filename, symfs_filename);
1735 1734
1736 if (err < 0) { 1735 if (err < 0) {
1737 pr_err("Failure allocating memory for the command to run\n"); 1736 pr_err("Failure allocating memory for the command to run\n");
@@ -1756,7 +1755,8 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
1756 close(stdout_fd[0]); 1755 close(stdout_fd[0]);
1757 dup2(stdout_fd[1], 1); 1756 dup2(stdout_fd[1], 1);
1758 close(stdout_fd[1]); 1757 close(stdout_fd[1]);
1759 execl("/bin/sh", "sh", "-c", command, NULL); 1758 execl("/bin/sh", "sh", "-c", command, "--", symfs_filename,
1759 NULL);
1760 perror(command); 1760 perror(command);
1761 exit(-1); 1761 exit(-1);
1762 } 1762 }
diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
index 89512504551b..39c0004f2886 100644
--- a/tools/perf/util/c++/clang.cpp
+++ b/tools/perf/util/c++/clang.cpp
@@ -160,7 +160,7 @@ getBPFObjectFromModule(llvm::Module *Module)
160 } 160 }
161 PM.run(*Module); 161 PM.run(*Module);
162 162
163 return std::move(Buffer); 163 return Buffer;
164} 164}
165 165
166} 166}
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 32ef7bdca1cf..dc2212e12184 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -766,6 +766,7 @@ static enum match_result match_chain(struct callchain_cursor_node *node,
766 cnode->cycles_count += node->branch_flags.cycles; 766 cnode->cycles_count += node->branch_flags.cycles;
767 cnode->iter_count += node->nr_loop_iter; 767 cnode->iter_count += node->nr_loop_iter;
768 cnode->iter_cycles += node->iter_cycles; 768 cnode->iter_cycles += node->iter_cycles;
769 cnode->from_count++;
769 } 770 }
770 } 771 }
771 772
@@ -1345,10 +1346,10 @@ static int branch_to_str(char *bf, int bfsize,
1345static int branch_from_str(char *bf, int bfsize, 1346static int branch_from_str(char *bf, int bfsize,
1346 u64 branch_count, 1347 u64 branch_count,
1347 u64 cycles_count, u64 iter_count, 1348 u64 cycles_count, u64 iter_count,
1348 u64 iter_cycles) 1349 u64 iter_cycles, u64 from_count)
1349{ 1350{
1350 int printed = 0, i = 0; 1351 int printed = 0, i = 0;
1351 u64 cycles; 1352 u64 cycles, v = 0;
1352 1353
1353 cycles = cycles_count / branch_count; 1354 cycles = cycles_count / branch_count;
1354 if (cycles) { 1355 if (cycles) {
@@ -1357,14 +1358,16 @@ static int branch_from_str(char *bf, int bfsize,
1357 bf + printed, bfsize - printed); 1358 bf + printed, bfsize - printed);
1358 } 1359 }
1359 1360
1360 if (iter_count) { 1361 if (iter_count && from_count) {
1361 printed += count_pri64_printf(i++, "iter", 1362 v = iter_count / from_count;
1362 iter_count, 1363 if (v) {
1363 bf + printed, bfsize - printed); 1364 printed += count_pri64_printf(i++, "iter",
1365 v, bf + printed, bfsize - printed);
1364 1366
1365 printed += count_pri64_printf(i++, "avg_cycles", 1367 printed += count_pri64_printf(i++, "avg_cycles",
1366 iter_cycles / iter_count, 1368 iter_cycles / iter_count,
1367 bf + printed, bfsize - printed); 1369 bf + printed, bfsize - printed);
1370 }
1368 } 1371 }
1369 1372
1370 if (i) 1373 if (i)
@@ -1377,6 +1380,7 @@ static int counts_str_build(char *bf, int bfsize,
1377 u64 branch_count, u64 predicted_count, 1380 u64 branch_count, u64 predicted_count,
1378 u64 abort_count, u64 cycles_count, 1381 u64 abort_count, u64 cycles_count,
1379 u64 iter_count, u64 iter_cycles, 1382 u64 iter_count, u64 iter_cycles,
1383 u64 from_count,
1380 struct branch_type_stat *brtype_stat) 1384 struct branch_type_stat *brtype_stat)
1381{ 1385{
1382 int printed; 1386 int printed;
@@ -1389,7 +1393,8 @@ static int counts_str_build(char *bf, int bfsize,
1389 predicted_count, abort_count, brtype_stat); 1393 predicted_count, abort_count, brtype_stat);
1390 } else { 1394 } else {
1391 printed = branch_from_str(bf, bfsize, branch_count, 1395 printed = branch_from_str(bf, bfsize, branch_count,
1392 cycles_count, iter_count, iter_cycles); 1396 cycles_count, iter_count, iter_cycles,
1397 from_count);
1393 } 1398 }
1394 1399
1395 if (!printed) 1400 if (!printed)
@@ -1402,13 +1407,14 @@ static int callchain_counts_printf(FILE *fp, char *bf, int bfsize,
1402 u64 branch_count, u64 predicted_count, 1407 u64 branch_count, u64 predicted_count,
1403 u64 abort_count, u64 cycles_count, 1408 u64 abort_count, u64 cycles_count,
1404 u64 iter_count, u64 iter_cycles, 1409 u64 iter_count, u64 iter_cycles,
1410 u64 from_count,
1405 struct branch_type_stat *brtype_stat) 1411 struct branch_type_stat *brtype_stat)
1406{ 1412{
1407 char str[256]; 1413 char str[256];
1408 1414
1409 counts_str_build(str, sizeof(str), branch_count, 1415 counts_str_build(str, sizeof(str), branch_count,
1410 predicted_count, abort_count, cycles_count, 1416 predicted_count, abort_count, cycles_count,
1411 iter_count, iter_cycles, brtype_stat); 1417 iter_count, iter_cycles, from_count, brtype_stat);
1412 1418
1413 if (fp) 1419 if (fp)
1414 return fprintf(fp, "%s", str); 1420 return fprintf(fp, "%s", str);
@@ -1422,6 +1428,7 @@ int callchain_list_counts__printf_value(struct callchain_list *clist,
1422 u64 branch_count, predicted_count; 1428 u64 branch_count, predicted_count;
1423 u64 abort_count, cycles_count; 1429 u64 abort_count, cycles_count;
1424 u64 iter_count, iter_cycles; 1430 u64 iter_count, iter_cycles;
1431 u64 from_count;
1425 1432
1426 branch_count = clist->branch_count; 1433 branch_count = clist->branch_count;
1427 predicted_count = clist->predicted_count; 1434 predicted_count = clist->predicted_count;
@@ -1429,11 +1436,12 @@ int callchain_list_counts__printf_value(struct callchain_list *clist,
1429 cycles_count = clist->cycles_count; 1436 cycles_count = clist->cycles_count;
1430 iter_count = clist->iter_count; 1437 iter_count = clist->iter_count;
1431 iter_cycles = clist->iter_cycles; 1438 iter_cycles = clist->iter_cycles;
1439 from_count = clist->from_count;
1432 1440
1433 return callchain_counts_printf(fp, bf, bfsize, branch_count, 1441 return callchain_counts_printf(fp, bf, bfsize, branch_count,
1434 predicted_count, abort_count, 1442 predicted_count, abort_count,
1435 cycles_count, iter_count, iter_cycles, 1443 cycles_count, iter_count, iter_cycles,
1436 &clist->brtype_stat); 1444 from_count, &clist->brtype_stat);
1437} 1445}
1438 1446
1439static void free_callchain_node(struct callchain_node *node) 1447static void free_callchain_node(struct callchain_node *node)
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 154560b1eb65..99d38ac019b8 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -118,6 +118,7 @@ struct callchain_list {
118 bool has_children; 118 bool has_children;
119 }; 119 };
120 u64 branch_count; 120 u64 branch_count;
121 u64 from_count;
121 u64 predicted_count; 122 u64 predicted_count;
122 u64 abort_count; 123 u64 abort_count;
123 u64 cycles_count; 124 u64 cycles_count;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 1ccbd3342069..383674f448fc 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -134,7 +134,12 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
134 if (!cpu_list) 134 if (!cpu_list)
135 return cpu_map__read_all_cpu_map(); 135 return cpu_map__read_all_cpu_map();
136 136
137 if (!isdigit(*cpu_list)) 137 /*
138 * must handle the case of empty cpumap to cover
139 * TOPOLOGY header for NUMA nodes with no CPU
140 * ( e.g., because of CPU hotplug)
141 */
142 if (!isdigit(*cpu_list) && *cpu_list != '\0')
138 goto out; 143 goto out;
139 144
140 while (isdigit(*cpu_list)) { 145 while (isdigit(*cpu_list)) {
@@ -181,8 +186,10 @@ struct cpu_map *cpu_map__new(const char *cpu_list)
181 186
182 if (nr_cpus > 0) 187 if (nr_cpus > 0)
183 cpus = cpu_map__trim_new(nr_cpus, tmp_cpus); 188 cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
184 else 189 else if (*cpu_list != '\0')
185 cpus = cpu_map__default_new(); 190 cpus = cpu_map__default_new();
191 else
192 cpus = cpu_map__dummy_new();
186invalid: 193invalid:
187 free(tmp_cpus); 194 free(tmp_cpus);
188out: 195out:
diff --git a/tools/perf/util/find-vdso-map.c b/tools/perf/util/find-map.c
index d7823e3508fc..7b2300588ece 100644
--- a/tools/perf/util/find-vdso-map.c
+++ b/tools/perf/util/find-map.c
@@ -1,5 +1,5 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2static int find_vdso_map(void **start, void **end) 2static int find_map(void **start, void **end, const char *name)
3{ 3{
4 FILE *maps; 4 FILE *maps;
5 char line[128]; 5 char line[128];
@@ -7,7 +7,7 @@ static int find_vdso_map(void **start, void **end)
7 7
8 maps = fopen("/proc/self/maps", "r"); 8 maps = fopen("/proc/self/maps", "r");
9 if (!maps) { 9 if (!maps) {
10 fprintf(stderr, "vdso: cannot open maps\n"); 10 fprintf(stderr, "cannot open maps\n");
11 return -1; 11 return -1;
12 } 12 }
13 13
@@ -21,8 +21,7 @@ static int find_vdso_map(void **start, void **end)
21 if (m < 0) 21 if (m < 0)
22 continue; 22 continue;
23 23
24 if (!strncmp(&line[m], VDSO__MAP_NAME, 24 if (!strncmp(&line[m], name, strlen(name)))
25 sizeof(VDSO__MAP_NAME) - 1))
26 found = 1; 25 found = 1;
27 } 26 }
28 27
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 6fcb3bce0442..143f7057d581 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2005,7 +2005,7 @@ static void save_iterations(struct iterations *iter,
2005{ 2005{
2006 int i; 2006 int i;
2007 2007
2008 iter->nr_loop_iter = nr; 2008 iter->nr_loop_iter++;
2009 iter->cycles = 0; 2009 iter->cycles = 0;
2010 2010
2011 for (i = 0; i < nr; i++) 2011 for (i = 0; i < nr; i++)
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 93f74d8d3cdd..42c3e5a229d2 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -28,7 +28,7 @@ struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX] = {
28static char mem_loads_name[100]; 28static char mem_loads_name[100];
29static bool mem_loads_name__init; 29static bool mem_loads_name__init;
30 30
31char *perf_mem_events__name(int i) 31char * __weak perf_mem_events__name(int i)
32{ 32{
33 if (i == PERF_MEM_EVENTS__LOAD) { 33 if (i == PERF_MEM_EVENTS__LOAD) {
34 if (!mem_loads_name__init) { 34 if (!mem_loads_name__init) {
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index 897589507d97..ea523d3b248f 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -391,8 +391,10 @@ void ordered_events__free(struct ordered_events *oe)
391 * Current buffer might not have all the events allocated 391 * Current buffer might not have all the events allocated
392 * yet, we need to free only allocated ones ... 392 * yet, we need to free only allocated ones ...
393 */ 393 */
394 list_del(&oe->buffer->list); 394 if (oe->buffer) {
395 ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe); 395 list_del(&oe->buffer->list);
396 ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
397 }
396 398
397 /* ... and continue with the rest */ 399 /* ... and continue with the rest */
398 list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) { 400 list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) {
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 63f758c655d5..64d1f36dee99 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -17,6 +17,8 @@ if cc == "clang":
17 vars[var] = sub("-mcet", "", vars[var]) 17 vars[var] = sub("-mcet", "", vars[var])
18 if not clang_has_option("-fcf-protection"): 18 if not clang_has_option("-fcf-protection"):
19 vars[var] = sub("-fcf-protection", "", vars[var]) 19 vars[var] = sub("-fcf-protection", "", vars[var])
20 if not clang_has_option("-fstack-clash-protection"):
21 vars[var] = sub("-fstack-clash-protection", "", vars[var])
20 22
21from distutils.core import setup, Extension 23from distutils.core import setup, Extension
22 24
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 9005fbe0780e..23092fd6451d 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -109,7 +109,6 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
109 return ret; 109 return ret;
110 } 110 }
111 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved); 111 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
112 va_end(ap_saved);
113 if (len > strbuf_avail(sb)) { 112 if (len > strbuf_avail(sb)) {
114 pr_debug("this should not happen, your vsnprintf is broken"); 113 pr_debug("this should not happen, your vsnprintf is broken");
115 va_end(ap_saved); 114 va_end(ap_saved);
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 66a84d5846c8..dca7dfae69ad 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -19,6 +19,20 @@
19#define EM_AARCH64 183 /* ARM 64 bit */ 19#define EM_AARCH64 183 /* ARM 64 bit */
20#endif 20#endif
21 21
22#ifndef ELF32_ST_VISIBILITY
23#define ELF32_ST_VISIBILITY(o) ((o) & 0x03)
24#endif
25
26/* For ELF64 the definitions are the same. */
27#ifndef ELF64_ST_VISIBILITY
28#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o)
29#endif
30
31/* How to extract information held in the st_other field. */
32#ifndef GELF_ST_VISIBILITY
33#define GELF_ST_VISIBILITY(val) ELF64_ST_VISIBILITY (val)
34#endif
35
22typedef Elf64_Nhdr GElf_Nhdr; 36typedef Elf64_Nhdr GElf_Nhdr;
23 37
24#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT 38#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
@@ -87,6 +101,11 @@ static inline uint8_t elf_sym__type(const GElf_Sym *sym)
87 return GELF_ST_TYPE(sym->st_info); 101 return GELF_ST_TYPE(sym->st_info);
88} 102}
89 103
104static inline uint8_t elf_sym__visibility(const GElf_Sym *sym)
105{
106 return GELF_ST_VISIBILITY(sym->st_other);
107}
108
90#ifndef STT_GNU_IFUNC 109#ifndef STT_GNU_IFUNC
91#define STT_GNU_IFUNC 10 110#define STT_GNU_IFUNC 10
92#endif 111#endif
@@ -111,7 +130,9 @@ static inline int elf_sym__is_label(const GElf_Sym *sym)
111 return elf_sym__type(sym) == STT_NOTYPE && 130 return elf_sym__type(sym) == STT_NOTYPE &&
112 sym->st_name != 0 && 131 sym->st_name != 0 &&
113 sym->st_shndx != SHN_UNDEF && 132 sym->st_shndx != SHN_UNDEF &&
114 sym->st_shndx != SHN_ABS; 133 sym->st_shndx != SHN_ABS &&
134 elf_sym__visibility(sym) != STV_HIDDEN &&
135 elf_sym__visibility(sym) != STV_INTERNAL;
115} 136}
116 137
117static bool elf_sym__filter(GElf_Sym *sym) 138static bool elf_sym__filter(GElf_Sym *sym)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 01f2c7385e38..48efad6d0f90 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -614,6 +614,7 @@ out:
614static bool symbol__is_idle(const char *name) 614static bool symbol__is_idle(const char *name)
615{ 615{
616 const char * const idle_symbols[] = { 616 const char * const idle_symbols[] = {
617 "arch_cpu_idle",
617 "cpu_idle", 618 "cpu_idle",
618 "cpu_startup_entry", 619 "cpu_startup_entry",
619 "intel_idle", 620 "intel_idle",
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
index 741af209b19d..3702cba11d7d 100644
--- a/tools/perf/util/vdso.c
+++ b/tools/perf/util/vdso.c
@@ -18,10 +18,10 @@
18#include "debug.h" 18#include "debug.h"
19 19
20/* 20/*
21 * Include definition of find_vdso_map() also used in perf-read-vdso.c for 21 * Include definition of find_map() also used in perf-read-vdso.c for
22 * building perf-read-vdso32 and perf-read-vdsox32. 22 * building perf-read-vdso32 and perf-read-vdsox32.
23 */ 23 */
24#include "find-vdso-map.c" 24#include "find-map.c"
25 25
26#define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" 26#define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX"
27 27
@@ -76,7 +76,7 @@ static char *get_file(struct vdso_file *vdso_file)
76 if (vdso_file->found) 76 if (vdso_file->found)
77 return vdso_file->temp_file_name; 77 return vdso_file->temp_file_name;
78 78
79 if (vdso_file->error || find_vdso_map(&start, &end)) 79 if (vdso_file->error || find_map(&start, &end, VDSO__MAP_NAME))
80 return NULL; 80 return NULL;
81 81
82 size = end - start; 82 size = end - start;