Skip to content

Commit c5b3a09

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.19-2022-06-19' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tool fixes from Arnaldo Carvalho de Melo: - Don't set data source if it's not a memory operation in ARM SPE (Statistical Profiling Extensions). - Fix handling of exponent floating point values in perf stat expressions. - Don't leak fd on failure on libperf open. - Fix 'perf test' CPU topology test for PPC guest systems. - Fix undefined behaviour on breakpoint account 'perf test' entry. - Record only user callchains on the "Check ARM64 callgraphs are complete in FP mode" 'perf test' entry. - Fix "perf stat CSV output linter" test on s390. - Sync batch of kernel headers with tools/perf/. * tag 'perf-tools-fixes-for-v5.19-2022-06-19' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: tools headers UAPI: Sync linux/prctl.h with the kernel sources perf metrics: Ensure at least 1 id per metric tools headers arm64: Sync arm64's cputype.h with the kernel sources tools headers UAPI: Sync x86's asm/kvm.h with the kernel sources perf arm-spe: Don't set data source if it's not a memory operation perf expr: Allow exponents on floating point values perf test topology: Use !strncmp(right platform) to fix guest PPC comparision check perf test: Record only user callchains on the "Check Arm64 callgraphs are complete in fp mode" test perf beauty: Update copy of linux/socket.h with the kernel sources perf test: Fix variable length array undefined behavior in bp_account libperf evsel: Open shouldn't leak fd on failure perf test: Fix "perf stat CSV output linter" test on s390 perf unwind: Fix uninitialized variable
2 parents 59b785f + 140cd9e commit c5b3a09

File tree

15 files changed

+125
-105
lines changed

15 files changed

+125
-105
lines changed

tools/arch/arm64/include/asm/cputype.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#define MIDR_VARIANT(midr) \
3737
(((midr) & MIDR_VARIANT_MASK) >> MIDR_VARIANT_SHIFT)
3838
#define MIDR_IMPLEMENTOR_SHIFT 24
39-
#define MIDR_IMPLEMENTOR_MASK (0xff << MIDR_IMPLEMENTOR_SHIFT)
39+
#define MIDR_IMPLEMENTOR_MASK (0xffU << MIDR_IMPLEMENTOR_SHIFT)
4040
#define MIDR_IMPLEMENTOR(midr) \
4141
(((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT)
4242

@@ -118,6 +118,10 @@
118118

119119
#define APPLE_CPU_PART_M1_ICESTORM 0x022
120120
#define APPLE_CPU_PART_M1_FIRESTORM 0x023
121+
#define APPLE_CPU_PART_M1_ICESTORM_PRO 0x024
122+
#define APPLE_CPU_PART_M1_FIRESTORM_PRO 0x025
123+
#define APPLE_CPU_PART_M1_ICESTORM_MAX 0x028
124+
#define APPLE_CPU_PART_M1_FIRESTORM_MAX 0x029
121125

122126
#define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
123127
#define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
@@ -164,6 +168,10 @@
164168
#define MIDR_HISI_TSV110 MIDR_CPU_MODEL(ARM_CPU_IMP_HISI, HISI_CPU_PART_TSV110)
165169
#define MIDR_APPLE_M1_ICESTORM MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_ICESTORM)
166170
#define MIDR_APPLE_M1_FIRESTORM MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM)
171+
#define MIDR_APPLE_M1_ICESTORM_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_ICESTORM_PRO)
172+
#define MIDR_APPLE_M1_FIRESTORM_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM_PRO)
173+
#define MIDR_APPLE_M1_ICESTORM_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_ICESTORM_MAX)
174+
#define MIDR_APPLE_M1_FIRESTORM_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M1_FIRESTORM_MAX)
167175

168176
/* Fujitsu Erratum 010001 affects A64FX 1.0 and 1.1, (v0r0 and v1r0) */
169177
#define MIDR_FUJITSU_ERRATUM_010001 MIDR_FUJITSU_A64FX
@@ -172,7 +180,7 @@
172180

173181
#ifndef __ASSEMBLY__
174182

175-
#include "sysreg.h"
183+
#include <asm/sysreg.h>
176184

177185
#define read_cpuid(reg) read_sysreg_s(SYS_ ## reg)
178186

tools/arch/x86/include/uapi/asm/kvm.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,12 @@ struct kvm_sync_regs {
428428
struct kvm_vcpu_events events;
429429
};
430430

431-
#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0)
432-
#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1)
433-
#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2)
434-
#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3)
435-
#define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT (1 << 4)
431+
#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0)
432+
#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1)
433+
#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2)
434+
#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3)
435+
#define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT (1 << 4)
436+
#define KVM_X86_QUIRK_FIX_HYPERCALL_INSN (1 << 5)
436437

437438
#define KVM_STATE_NESTED_FORMAT_VMX 0
438439
#define KVM_STATE_NESTED_FORMAT_SVM 1

tools/include/uapi/linux/prctl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ struct prctl_mm_map {
272272
# define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1
273273
# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2
274274

275+
/* arm64 Scalable Matrix Extension controls */
276+
/* Flag values must be in sync with SVE versions */
277+
#define PR_SME_SET_VL 63 /* set task vector length */
278+
# define PR_SME_SET_VL_ONEXEC (1 << 18) /* defer effect until exec */
279+
#define PR_SME_GET_VL 64 /* get task vector length */
280+
/* Bits common to PR_SME_SET_VL and PR_SME_GET_VL */
281+
# define PR_SME_VL_LEN_MASK 0xffff
282+
# define PR_SME_VL_INHERIT (1 << 17) /* inherit across exec */
283+
275284
#define PR_SET_VMA 0x53564d41
276285
# define PR_SET_VMA_ANON_NAME 0
277286

tools/lib/perf/evsel.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,30 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
149149
int fd, group_fd, *evsel_fd;
150150

151151
evsel_fd = FD(evsel, idx, thread);
152-
if (evsel_fd == NULL)
153-
return -EINVAL;
152+
if (evsel_fd == NULL) {
153+
err = -EINVAL;
154+
goto out;
155+
}
154156

155157
err = get_group_fd(evsel, idx, thread, &group_fd);
156158
if (err < 0)
157-
return err;
159+
goto out;
158160

159161
fd = sys_perf_event_open(&evsel->attr,
160162
threads->map[thread].pid,
161163
cpu, group_fd, 0);
162164

163-
if (fd < 0)
164-
return -errno;
165+
if (fd < 0) {
166+
err = -errno;
167+
goto out;
168+
}
165169

166170
*evsel_fd = fd;
167171
}
168172
}
173+
out:
174+
if (err)
175+
perf_evsel__close(evsel);
169176

170177
return err;
171178
}

tools/perf/tests/bp_account.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,21 @@ static int detect_ioctl(void)
151151
static int detect_share(int wp_cnt, int bp_cnt)
152152
{
153153
struct perf_event_attr attr;
154-
int i, fd[wp_cnt + bp_cnt], ret;
154+
int i, *fd = NULL, ret = -1;
155+
156+
if (wp_cnt + bp_cnt == 0)
157+
return 0;
158+
159+
fd = malloc(sizeof(int) * (wp_cnt + bp_cnt));
160+
if (!fd)
161+
return -1;
155162

156163
for (i = 0; i < wp_cnt; i++) {
157164
fd[i] = wp_event((void *)&the_var, &attr);
158-
TEST_ASSERT_VAL("failed to create wp\n", fd[i] != -1);
165+
if (fd[i] == -1) {
166+
pr_err("failed to create wp\n");
167+
goto out;
168+
}
159169
}
160170

161171
for (; i < (bp_cnt + wp_cnt); i++) {
@@ -166,9 +176,11 @@ static int detect_share(int wp_cnt, int bp_cnt)
166176

167177
ret = i != (bp_cnt + wp_cnt);
168178

179+
out:
169180
while (i--)
170181
close(fd[i]);
171182

183+
free(fd);
172184
return ret;
173185
}
174186

tools/perf/tests/expr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
9797
ret |= test(ctx, "2.2 > 2.2", 0);
9898
ret |= test(ctx, "2.2 < 1.1", 0);
9999
ret |= test(ctx, "1.1 > 2.2", 0);
100+
ret |= test(ctx, "1.1e10 < 1.1e100", 1);
101+
ret |= test(ctx, "1.1e2 > 1.1e-2", 1);
100102

101103
if (ret) {
102104
expr__ctx_free(ctx);

tools/perf/tests/shell/lib/perf_csv_output_lint.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

tools/perf/tests/shell/stat+csv_output.sh

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,41 @@
66

77
set -e
88

9-
pythonchecker=$(dirname $0)/lib/perf_csv_output_lint.py
10-
if [ "x$PYTHON" == "x" ]
11-
then
12-
if which python3 > /dev/null
13-
then
14-
PYTHON=python3
15-
elif which python > /dev/null
16-
then
17-
PYTHON=python
18-
else
19-
echo Skipping test, python not detected please set environment variable PYTHON.
20-
exit 2
21-
fi
22-
fi
9+
function commachecker()
10+
{
11+
local -i cnt=0 exp=0
12+
13+
case "$1"
14+
in "--no-args") exp=6
15+
;; "--system-wide") exp=6
16+
;; "--event") exp=6
17+
;; "--interval") exp=7
18+
;; "--per-thread") exp=7
19+
;; "--system-wide-no-aggr") exp=7
20+
[ $(uname -m) = "s390x" ] && exp=6
21+
;; "--per-core") exp=8
22+
;; "--per-socket") exp=8
23+
;; "--per-node") exp=8
24+
;; "--per-die") exp=8
25+
esac
26+
27+
while read line
28+
do
29+
# Check for lines beginning with Failed
30+
x=${line:0:6}
31+
[ "$x" = "Failed" ] && continue
32+
33+
# Count the number of commas
34+
x=$(echo $line | tr -d -c ',')
35+
cnt="${#x}"
36+
# echo $line $cnt
37+
[ "$cnt" -ne "$exp" ] && {
38+
echo "wrong number of fields. expected $exp in $line" 1>&2
39+
exit 1;
40+
}
41+
done
42+
return 0
43+
}
2344

2445
# Return true if perf_event_paranoid is > $1 and not running as root.
2546
function ParanoidAndNotRoot()
@@ -30,7 +51,7 @@ function ParanoidAndNotRoot()
3051
check_no_args()
3152
{
3253
echo -n "Checking CSV output: no args "
33-
perf stat -x, true 2>&1 | $PYTHON $pythonchecker --no-args
54+
perf stat -x, true 2>&1 | commachecker --no-args
3455
echo "[Success]"
3556
}
3657

@@ -42,7 +63,7 @@ check_system_wide()
4263
echo "[Skip] paranoid and not root"
4364
return
4465
fi
45-
perf stat -x, -a true 2>&1 | $PYTHON $pythonchecker --system-wide
66+
perf stat -x, -a true 2>&1 | commachecker --system-wide
4667
echo "[Success]"
4768
}
4869

@@ -55,22 +76,22 @@ check_system_wide_no_aggr()
5576
return
5677
fi
5778
echo -n "Checking CSV output: system wide no aggregation "
58-
perf stat -x, -A -a --no-merge true 2>&1 | $PYTHON $pythonchecker --system-wide-no-aggr
79+
perf stat -x, -A -a --no-merge true 2>&1 | commachecker --system-wide-no-aggr
5980
echo "[Success]"
6081
}
6182

6283
check_interval()
6384
{
6485
echo -n "Checking CSV output: interval "
65-
perf stat -x, -I 1000 true 2>&1 | $PYTHON $pythonchecker --interval
86+
perf stat -x, -I 1000 true 2>&1 | commachecker --interval
6687
echo "[Success]"
6788
}
6889

6990

7091
check_event()
7192
{
7293
echo -n "Checking CSV output: event "
73-
perf stat -x, -e cpu-clock true 2>&1 | $PYTHON $pythonchecker --event
94+
perf stat -x, -e cpu-clock true 2>&1 | commachecker --event
7495
echo "[Success]"
7596
}
7697

@@ -82,7 +103,7 @@ check_per_core()
82103
echo "[Skip] paranoid and not root"
83104
return
84105
fi
85-
perf stat -x, --per-core -a true 2>&1 | $PYTHON $pythonchecker --per-core
106+
perf stat -x, --per-core -a true 2>&1 | commachecker --per-core
86107
echo "[Success]"
87108
}
88109

@@ -94,7 +115,7 @@ check_per_thread()
94115
echo "[Skip] paranoid and not root"
95116
return
96117
fi
97-
perf stat -x, --per-thread -a true 2>&1 | $PYTHON $pythonchecker --per-thread
118+
perf stat -x, --per-thread -a true 2>&1 | commachecker --per-thread
98119
echo "[Success]"
99120
}
100121

@@ -106,7 +127,7 @@ check_per_die()
106127
echo "[Skip] paranoid and not root"
107128
return
108129
fi
109-
perf stat -x, --per-die -a true 2>&1 | $PYTHON $pythonchecker --per-die
130+
perf stat -x, --per-die -a true 2>&1 | commachecker --per-die
110131
echo "[Success]"
111132
}
112133

@@ -118,7 +139,7 @@ check_per_node()
118139
echo "[Skip] paranoid and not root"
119140
return
120141
fi
121-
perf stat -x, --per-node -a true 2>&1 | $PYTHON $pythonchecker --per-node
142+
perf stat -x, --per-node -a true 2>&1 | commachecker --per-node
122143
echo "[Success]"
123144
}
124145

@@ -130,7 +151,7 @@ check_per_socket()
130151
echo "[Skip] paranoid and not root"
131152
return
132153
fi
133-
perf stat -x, --per-socket -a true 2>&1 | $PYTHON $pythonchecker --per-socket
154+
perf stat -x, --per-socket -a true 2>&1 | commachecker --per-socket
134155
echo "[Success]"
135156
}
136157

tools/perf/tests/shell/test_arm_callgraph_fp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ CFLAGS="-g -O0 -fno-inline -fno-omit-frame-pointer"
4343
cc $CFLAGS $TEST_PROGRAM_SOURCE -o $TEST_PROGRAM || exit 1
4444

4545
# Add a 1 second delay to skip samples that are not in the leaf() function
46-
perf record -o $PERF_DATA --call-graph fp -e cycles//u -D 1000 -- $TEST_PROGRAM 2> /dev/null &
46+
perf record -o $PERF_DATA --call-graph fp -e cycles//u -D 1000 --user-callchains -- $TEST_PROGRAM 2> /dev/null &
4747
PID=$!
4848

4949
echo " + Recording (PID=$PID)..."

tools/perf/tests/topology.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
115115
* physical_package_id will be set to -1. Hence skip this
116116
* test if physical_package_id returns -1 for cpu from perf_cpu_map.
117117
*/
118-
if (strncmp(session->header.env.arch, "powerpc", 7)) {
118+
if (!strncmp(session->header.env.arch, "ppc64le", 7)) {
119119
if (cpu__get_socket_id(perf_cpu_map__cpu(map, 0)) == -1)
120120
return TEST_SKIP;
121121
}

0 commit comments

Comments
 (0)