Skip to content

Commit eaea45f

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.18-2022-05-21' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix and validate CPU map inputs in synthetic PERF_RECORD_STAT events in 'perf stat'. - Fix x86's arch__intr_reg_mask() for the hybrid platform. - Address 'perf bench numa' compiler error on s390. - Fix check for btf__load_from_kernel_by_id() in libbpf. - Fix "all PMU test" 'perf test' to skip hv_24x7/hv_gpci tests on powerpc. - Fix session topology test to skip the test in guest environment. - Skip BPF 'perf test' if clang is not present. - Avoid shell test description infinite loop in 'perf test'. - Fix Intel LBR callstack entries and nr print message. * tag 'perf-tools-fixes-for-v5.18-2022-05-21' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf session: Fix Intel LBR callstack entries and nr print message perf test bpf: Skip test if clang is not present perf test session topology: Fix test to skip the test in guest environment perf bench numa: Address compiler error on s390 perf test: Avoid shell test description infinite loop perf regs x86: Fix arch__intr_reg_mask() for the hybrid platform perf test: Fix "all PMU test" to skip hv_24x7/hv_gpci tests on powerpc perf stat: Fix and validate CPU map inputs in synthetic PERF_RECORD_STAT events perf build: Fix check for btf__load_from_kernel_by_id() in libbpf
2 parents 4c493b1 + 51d0bf9 commit eaea45f

File tree

13 files changed

+103
-16
lines changed

13 files changed

+103
-16
lines changed

tools/build/Makefile.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ FEATURE_TESTS_EXTRA := \
9898
llvm-version \
9999
clang \
100100
libbpf \
101+
libbpf-btf__load_from_kernel_by_id \
101102
libpfm4 \
102103
libdebuginfod \
103104
clang-bpf-co-re

tools/build/feature/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ FILES= \
5757
test-lzma.bin \
5858
test-bpf.bin \
5959
test-libbpf.bin \
60+
test-libbpf-btf__load_from_kernel_by_id.bin \
6061
test-get_cpuid.bin \
6162
test-sdt.bin \
6263
test-cxx.bin \
@@ -287,6 +288,9 @@ $(OUTPUT)test-bpf.bin:
287288
$(OUTPUT)test-libbpf.bin:
288289
$(BUILD) -lbpf
289290

291+
$(OUTPUT)test-libbpf-btf__load_from_kernel_by_id.bin:
292+
$(BUILD) -lbpf
293+
290294
$(OUTPUT)test-sdt.bin:
291295
$(BUILD)
292296

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <bpf/libbpf.h>
3+
4+
int main(void)
5+
{
6+
return btf__load_from_kernel_by_id(20151128, NULL);
7+
}

tools/perf/Makefile.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,16 @@ ifndef NO_LIBELF
553553
ifeq ($(feature-libbpf), 1)
554554
EXTLIBS += -lbpf
555555
$(call detected,CONFIG_LIBBPF_DYNAMIC)
556+
557+
$(call feature_check,libbpf-btf__load_from_kernel_by_id)
558+
ifeq ($(feature-libbpf-btf__load_from_kernel_by_id), 1)
559+
CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
560+
endif
556561
else
557562
dummy := $(error Error: No libbpf devel library found, please install libbpf-devel);
558563
endif
564+
else
565+
CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
559566
endif
560567
endif
561568

tools/perf/arch/x86/util/perf_regs.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "../../../util/perf_regs.h"
1010
#include "../../../util/debug.h"
1111
#include "../../../util/event.h"
12+
#include "../../../util/pmu.h"
13+
#include "../../../util/pmu-hybrid.h"
1214

1315
const struct sample_reg sample_reg_masks[] = {
1416
SMPL_REG(AX, PERF_REG_X86_AX),
@@ -284,12 +286,22 @@ uint64_t arch__intr_reg_mask(void)
284286
.disabled = 1,
285287
.exclude_kernel = 1,
286288
};
289+
struct perf_pmu *pmu;
287290
int fd;
288291
/*
289292
* In an unnamed union, init it here to build on older gcc versions
290293
*/
291294
attr.sample_period = 1;
292295

296+
if (perf_pmu__has_hybrid()) {
297+
/*
298+
* The same register set is supported among different hybrid PMUs.
299+
* Only check the first available one.
300+
*/
301+
pmu = list_first_entry(&perf_pmu__hybrid_pmus, typeof(*pmu), hybrid_list);
302+
attr.config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT;
303+
}
304+
293305
event_attr_init(&attr);
294306

295307
fd = sys_perf_event_open(&attr, 0, -1, -1, 0);

tools/perf/bench/numa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ static int __bench_numa(const char *name)
17401740
"GB/sec,", "total-speed", "GB/sec total speed");
17411741

17421742
if (g->p.show_details >= 2) {
1743-
char tname[14 + 2 * 10 + 1];
1743+
char tname[14 + 2 * 11 + 1];
17441744
struct thread_data *td;
17451745
for (p = 0; p < g->p.nr_proc; p++) {
17461746
for (t = 0; t < g->p.nr_threads; t++) {

tools/perf/tests/bpf.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ static int __test__bpf(int idx)
222222

223223
ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,
224224
bpf_testcase_table[idx].prog_id,
225-
true, NULL);
225+
false, NULL);
226226
if (ret != TEST_OK || !obj_buf || !obj_buf_sz) {
227227
pr_debug("Unable to get BPF object, %s\n",
228228
bpf_testcase_table[idx].msg_compile_fail);
229-
if (idx == 0)
229+
if ((idx == 0) || (ret == TEST_SKIP))
230230
return TEST_SKIP;
231231
else
232232
return TEST_FAIL;
@@ -364,9 +364,11 @@ static int test__bpf_prologue_test(struct test_suite *test __maybe_unused,
364364
static struct test_case bpf_tests[] = {
365365
#ifdef HAVE_LIBBPF_SUPPORT
366366
TEST_CASE("Basic BPF filtering", basic_bpf_test),
367-
TEST_CASE("BPF pinning", bpf_pinning),
367+
TEST_CASE_REASON("BPF pinning", bpf_pinning,
368+
"clang isn't installed or environment missing BPF support"),
368369
#ifdef HAVE_BPF_PROLOGUE
369-
TEST_CASE("BPF prologue generation", bpf_prologue_test),
370+
TEST_CASE_REASON("BPF prologue generation", bpf_prologue_test,
371+
"clang isn't installed or environment missing BPF support"),
370372
#else
371373
TEST_CASE_REASON("BPF prologue generation", bpf_prologue_test, "not compiled in"),
372374
#endif

tools/perf/tests/builtin-test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,17 @@ static const char *shell_test__description(char *description, size_t size,
279279
{
280280
FILE *fp;
281281
char filename[PATH_MAX];
282+
int ch;
282283

283284
path__join(filename, sizeof(filename), path, name);
284285
fp = fopen(filename, "r");
285286
if (!fp)
286287
return NULL;
287288

288289
/* Skip shebang */
289-
while (fgetc(fp) != '\n');
290+
do {
291+
ch = fgetc(fp);
292+
} while (ch != EOF && ch != '\n');
290293

291294
description = fgets(description, size, fp);
292295
fclose(fp);
@@ -417,7 +420,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width,
417420
.priv = &st,
418421
};
419422

420-
if (!perf_test__matches(test_suite.desc, curr, argc, argv))
423+
if (test_suite.desc == NULL ||
424+
!perf_test__matches(test_suite.desc, curr, argc, argv))
421425
continue;
422426

423427
st.file = ent->d_name;

tools/perf/tests/shell/stat_all_pmu.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
set -e
66

77
for p in $(perf list --raw-dump pmu); do
8+
# In powerpc, skip the events for hv_24x7 and hv_gpci.
9+
# These events needs input values to be filled in for
10+
# core, chip, partition id based on system.
11+
# Example: hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
12+
# hv_gpci/event,partition_id=?/
13+
# Hence skip these events for ppc.
14+
if echo "$p" |grep -Eq 'hv_24x7|hv_gpci' ; then
15+
echo "Skipping: Event '$p' in powerpc"
16+
continue
17+
fi
818
echo "Testing $p"
919
result=$(perf stat -e "$p" true 2>&1)
1020
if ! echo "$result" | grep -q "$p" && ! echo "$result" | grep -q "<not supported>" ; then

tools/perf/tests/topology.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
109109
&& strncmp(session->header.env.arch, "aarch64", 7))
110110
return TEST_SKIP;
111111

112+
/*
113+
* In powerpc pSeries platform, not all the topology information
114+
* are exposed via sysfs. Due to restriction, detail like
115+
* physical_package_id will be set to -1. Hence skip this
116+
* test if physical_package_id returns -1 for cpu from perf_cpu_map.
117+
*/
118+
if (strncmp(session->header.env.arch, "powerpc", 7)) {
119+
if (cpu__get_socket_id(perf_cpu_map__cpu(map, 0)) == -1)
120+
return TEST_SKIP;
121+
}
122+
112123
TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu);
113124

114125
for (i = 0; i < session->header.env.nr_cpus_avail; i++) {

0 commit comments

Comments
 (0)