Skip to content

Commit e2da783

Browse files
committed
Merge tag 'perf-tools-fixes-2021-01-17' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix 'CPU too large' error in Intel PT - Correct event attribute sizes in 'perf inject' - Sync build_bug.h and kvm.h kernel copies - Fix bpf.h header include directive in 5sec.c 'perf trace' bpf example - libbpf tests fixes - Fix shadow stat 'perf test' for non-bash shells - Take cgroups into account for shadow stats in 'perf stat' * tag 'perf-tools-fixes-2021-01-17' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf inject: Correct event attribute sizes perf intel-pt: Fix 'CPU too large' error perf stat: Take cgroups into account for shadow stats perf stat: Introduce struct runtime_stat_data libperf tests: Fail when failing to get a tracepoint id libperf tests: If a test fails return non-zero libperf tests: Avoid uninitialized variable warning perf test: Fix shadow stat test for non-bash shells tools headers: Syncronize linux/build_bug.h with the kernel sources tools headers UAPI: Sync kvm.h headers with the kernel sources perf bpf examples: Fix bpf.h header include directive in 5sec.c example
2 parents a1339d6 + 648b054 commit e2da783

File tree

12 files changed

+224
-208
lines changed

12 files changed

+224
-208
lines changed

tools/include/linux/build_bug.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,4 @@
7979
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
8080
#endif // static_assert
8181

82-
#ifdef __GENKSYMS__
83-
/* genksyms gets confused by _Static_assert */
84-
#define _Static_assert(expr, ...)
85-
#endif
86-
8782
#endif /* _LINUX_BUILD_BUG_H */

tools/include/uapi/linux/kvm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ struct kvm_hyperv_exit {
251251
#define KVM_EXIT_X86_RDMSR 29
252252
#define KVM_EXIT_X86_WRMSR 30
253253
#define KVM_EXIT_DIRTY_RING_FULL 31
254+
#define KVM_EXIT_AP_RESET_HOLD 32
254255

255256
/* For KVM_EXIT_INTERNAL_ERROR */
256257
/* Emulate instruction failed. */
@@ -573,6 +574,7 @@ struct kvm_vapic_addr {
573574
#define KVM_MP_STATE_CHECK_STOP 6
574575
#define KVM_MP_STATE_OPERATING 7
575576
#define KVM_MP_STATE_LOAD 8
577+
#define KVM_MP_STATE_AP_RESET_HOLD 9
576578

577579
struct kvm_mp_state {
578580
__u32 mp_state;

tools/lib/perf/tests/test-cpumap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ int main(int argc, char **argv)
2727
perf_cpu_map__put(cpus);
2828

2929
__T_END;
30-
return 0;
30+
return tests_failed == 0 ? 0 : -1;
3131
}

tools/lib/perf/tests/test-evlist.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ static int test_mmap_thread(void)
208208
char path[PATH_MAX];
209209
int id, err, pid, go_pipe[2];
210210
union perf_event *event;
211-
char bf;
212211
int count = 0;
213212

214213
snprintf(path, PATH_MAX, "%s/kernel/debug/tracing/events/syscalls/sys_enter_prctl/id",
215214
sysfs__mountpoint());
216215

217216
if (filename__read_int(path, &id)) {
217+
tests_failed++;
218218
fprintf(stderr, "error: failed to get tracepoint id: %s\n", path);
219219
return -1;
220220
}
@@ -229,6 +229,7 @@ static int test_mmap_thread(void)
229229
pid = fork();
230230
if (!pid) {
231231
int i;
232+
char bf;
232233

233234
read(go_pipe[0], &bf, 1);
234235

@@ -266,7 +267,7 @@ static int test_mmap_thread(void)
266267
perf_evlist__enable(evlist);
267268

268269
/* kick the child and wait for it to finish */
269-
write(go_pipe[1], &bf, 1);
270+
write(go_pipe[1], "A", 1);
270271
waitpid(pid, NULL, 0);
271272

272273
/*
@@ -409,5 +410,5 @@ int main(int argc, char **argv)
409410
test_mmap_cpus();
410411

411412
__T_END;
412-
return 0;
413+
return tests_failed == 0 ? 0 : -1;
413414
}

tools/lib/perf/tests/test-evsel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,5 @@ int main(int argc, char **argv)
131131
test_stat_thread_enable();
132132

133133
__T_END;
134-
return 0;
134+
return tests_failed == 0 ? 0 : -1;
135135
}

tools/lib/perf/tests/test-threadmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ int main(int argc, char **argv)
2727
perf_thread_map__put(threads);
2828

2929
__T_END;
30-
return 0;
30+
return tests_failed == 0 ? 0 : -1;
3131
}

tools/perf/examples/bpf/5sec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo <[email protected]>
4040
*/
4141

42-
#include <bpf/bpf.h>
42+
#include <bpf.h>
4343

4444
#define NSEC_PER_SEC 1000000000L
4545

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,29 @@ perf stat -a true > /dev/null 2>&1 || exit 2
99

1010
test_global_aggr()
1111
{
12-
local cyc
13-
1412
perf stat -a --no-big-num -e cycles,instructions sleep 1 2>&1 | \
1513
grep -e cycles -e instructions | \
1614
while read num evt hash ipc rest
1715
do
1816
# skip not counted events
19-
if [[ $num == "<not" ]]; then
17+
if [ "$num" = "<not" ]; then
2018
continue
2119
fi
2220

2321
# save cycles count
24-
if [[ $evt == "cycles" ]]; then
22+
if [ "$evt" = "cycles" ]; then
2523
cyc=$num
2624
continue
2725
fi
2826

2927
# skip if no cycles
30-
if [[ -z $cyc ]]; then
28+
if [ -z "$cyc" ]; then
3129
continue
3230
fi
3331

3432
# use printf for rounding and a leading zero
35-
local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
36-
if [[ $ipc != $res ]]; then
33+
res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
34+
if [ "$ipc" != "$res" ]; then
3735
echo "IPC is different: $res != $ipc ($num / $cyc)"
3836
exit 1
3937
fi
@@ -42,32 +40,32 @@ test_global_aggr()
4240

4341
test_no_aggr()
4442
{
45-
declare -A results
46-
4743
perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \
4844
grep ^CPU | \
4945
while read cpu num evt hash ipc rest
5046
do
5147
# skip not counted events
52-
if [[ $num == "<not" ]]; then
48+
if [ "$num" = "<not" ]; then
5349
continue
5450
fi
5551

5652
# save cycles count
57-
if [[ $evt == "cycles" ]]; then
58-
results[$cpu]=$num
53+
if [ "$evt" = "cycles" ]; then
54+
results="$results $cpu:$num"
5955
continue
6056
fi
6157

58+
cyc=${results##* $cpu:}
59+
cyc=${cyc%% *}
60+
6261
# skip if no cycles
63-
local cyc=${results[$cpu]}
64-
if [[ -z $cyc ]]; then
62+
if [ -z "$cyc" ]; then
6563
continue
6664
fi
6765

6866
# use printf for rounding and a leading zero
69-
local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
70-
if [[ $ipc != $res ]]; then
67+
res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
68+
if [ "$ipc" != "$res" ]; then
7169
echo "IPC is different for $cpu: $res != $ipc ($num / $cyc)"
7270
exit 1
7371
fi

tools/perf/util/header.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,14 @@ int perf_session__write_header(struct perf_session *session,
33233323
attr_offset = lseek(ff.fd, 0, SEEK_CUR);
33243324

33253325
evlist__for_each_entry(evlist, evsel) {
3326+
if (evsel->core.attr.size < sizeof(evsel->core.attr)) {
3327+
/*
3328+
* We are likely in "perf inject" and have read
3329+
* from an older file. Update attr size so that
3330+
* reader gets the right offset to the ids.
3331+
*/
3332+
evsel->core.attr.size = sizeof(evsel->core.attr);
3333+
}
33263334
f_attr = (struct perf_file_attr){
33273335
.attr = evsel->core.attr,
33283336
.ids = {

tools/perf/util/machine.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ int machines__for_each_thread(struct machines *machines,
29802980

29812981
pid_t machine__get_current_tid(struct machine *machine, int cpu)
29822982
{
2983-
int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);
2983+
int nr_cpus = min(machine->env->nr_cpus_avail, MAX_NR_CPUS);
29842984

29852985
if (cpu < 0 || cpu >= nr_cpus || !machine->current_tid)
29862986
return -1;
@@ -2992,7 +2992,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
29922992
pid_t tid)
29932993
{
29942994
struct thread *thread;
2995-
int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);
2995+
int nr_cpus = min(machine->env->nr_cpus_avail, MAX_NR_CPUS);
29962996

29972997
if (cpu < 0)
29982998
return -EINVAL;

0 commit comments

Comments
 (0)