Skip to content

Commit 24a0b22

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.16-2022-01-02' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix TUI exit screen refresh race condition in 'perf top'. - Fix parsing of Intel PT VM time correlation arguments. - Honour CPU filtering command line request of a script's switch events in 'perf script'. - Fix printing of switch events in Intel PT python script. - Fix duplicate alias events list printing in 'perf list', noticed on heterogeneous arm64 systems. - Fix return value of ids__new(), users expect NULL for failure, not ERR_PTR(-ENOMEM). * tag 'perf-tools-fixes-for-v5.16-2022-01-02' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf top: Fix TUI exit screen refresh race condition perf pmu: Fix alias events list perf scripts python: intel-pt-events.py: Fix printing of switch events perf script: Fix CPU filtering of a script's switch events perf intel-pt: Fix parsing of VM time correlation arguments perf expr: Fix return value of ids__new()
2 parents 859431a + 64f18d2 commit 24a0b22

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

tools/perf/builtin-script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ static int process_switch_event(struct perf_tool *tool,
24732473
if (perf_event__process_switch(tool, event, sample, machine) < 0)
24742474
return -1;
24752475

2476-
if (scripting_ops && scripting_ops->process_switch)
2476+
if (scripting_ops && scripting_ops->process_switch && !filter_cpu(sample))
24772477
scripting_ops->process_switch(event, sample, machine);
24782478

24792479
if (!script->show_switch_events)

tools/perf/scripts/python/intel-pt-events.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
except:
3333
broken_pipe_exception = IOError
3434

35-
glb_switch_str = None
36-
glb_switch_printed = True
35+
glb_switch_str = {}
3736
glb_insn = False
3837
glb_disassembler = None
3938
glb_src = False
@@ -70,6 +69,7 @@ def trace_begin():
7069
ap = argparse.ArgumentParser(usage = "", add_help = False)
7170
ap.add_argument("--insn-trace", action='store_true')
7271
ap.add_argument("--src-trace", action='store_true')
72+
ap.add_argument("--all-switch-events", action='store_true')
7373
global glb_args
7474
global glb_insn
7575
global glb_src
@@ -256,10 +256,6 @@ def print_srccode(comm, param_dict, sample, symbol, dso, with_insn):
256256
print(start_str, src_str)
257257

258258
def do_process_event(param_dict):
259-
global glb_switch_printed
260-
if not glb_switch_printed:
261-
print(glb_switch_str)
262-
glb_switch_printed = True
263259
event_attr = param_dict["attr"]
264260
sample = param_dict["sample"]
265261
raw_buf = param_dict["raw_buf"]
@@ -274,6 +270,11 @@ def do_process_event(param_dict):
274270
dso = get_optional(param_dict, "dso")
275271
symbol = get_optional(param_dict, "symbol")
276272

273+
cpu = sample["cpu"]
274+
if cpu in glb_switch_str:
275+
print(glb_switch_str[cpu])
276+
del glb_switch_str[cpu]
277+
277278
if name[0:12] == "instructions":
278279
if glb_src:
279280
print_srccode(comm, param_dict, sample, symbol, dso, True)
@@ -336,8 +337,6 @@ def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x):
336337
sys.exit(1)
337338

338339
def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_preempt, *x):
339-
global glb_switch_printed
340-
global glb_switch_str
341340
if out:
342341
out_str = "Switch out "
343342
else:
@@ -350,6 +349,10 @@ def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_pree
350349
machine_str = ""
351350
else:
352351
machine_str = "machine PID %d" % machine_pid
353-
glb_switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \
352+
switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \
354353
(out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str)
355-
glb_switch_printed = False
354+
if glb_args.all_switch_events:
355+
print(switch_str);
356+
else:
357+
global glb_switch_str
358+
glb_switch_str[cpu] = switch_str

tools/perf/ui/tui/setup.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ void ui__exit(bool wait_for_ok)
170170
"Press any key...", 0);
171171

172172
SLtt_set_cursor_visibility(1);
173-
SLsmg_refresh();
174-
SLsmg_reset_smg();
173+
if (!pthread_mutex_trylock(&ui__lock)) {
174+
SLsmg_refresh();
175+
SLsmg_reset_smg();
176+
pthread_mutex_unlock(&ui__lock);
177+
}
175178
SLang_reset_tty();
176-
177179
perf_error__unregister(&perf_tui_eops);
178180
}

tools/perf/util/expr.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ static bool key_equal(const void *key1, const void *key2,
6666

6767
struct hashmap *ids__new(void)
6868
{
69-
return hashmap__new(key_hash, key_equal, NULL);
69+
struct hashmap *hash;
70+
71+
hash = hashmap__new(key_hash, key_equal, NULL);
72+
if (IS_ERR(hash))
73+
return NULL;
74+
return hash;
7075
}
7176

7277
void ids__free(struct hashmap *ids)

tools/perf/util/intel-pt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,6 +3625,7 @@ static int intel_pt_parse_vm_tm_corr_arg(struct intel_pt *pt, char **args)
36253625
*args = p;
36263626
return 0;
36273627
}
3628+
p += 1;
36283629
while (1) {
36293630
vmcs = strtoull(p, &p, 0);
36303631
if (errno)

tools/perf/util/pmu.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,21 @@ bool is_pmu_core(const char *name)
16591659
return !strcmp(name, "cpu") || is_arm_pmu_core(name);
16601660
}
16611661

1662+
static bool pmu_alias_is_duplicate(struct sevent *alias_a,
1663+
struct sevent *alias_b)
1664+
{
1665+
/* Different names -> never duplicates */
1666+
if (strcmp(alias_a->name, alias_b->name))
1667+
return false;
1668+
1669+
/* Don't remove duplicates for hybrid PMUs */
1670+
if (perf_pmu__is_hybrid(alias_a->pmu) &&
1671+
perf_pmu__is_hybrid(alias_b->pmu))
1672+
return false;
1673+
1674+
return true;
1675+
}
1676+
16621677
void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
16631678
bool long_desc, bool details_flag, bool deprecated,
16641679
const char *pmu_name)
@@ -1744,12 +1759,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
17441759
qsort(aliases, len, sizeof(struct sevent), cmp_sevent);
17451760
for (j = 0; j < len; j++) {
17461761
/* Skip duplicates */
1747-
if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name)) {
1748-
if (!aliases[j].pmu || !aliases[j - 1].pmu ||
1749-
!strcmp(aliases[j].pmu, aliases[j - 1].pmu)) {
1750-
continue;
1751-
}
1752-
}
1762+
if (j > 0 && pmu_alias_is_duplicate(&aliases[j], &aliases[j - 1]))
1763+
continue;
17531764

17541765
if (name_only) {
17551766
printf("%s ", aliases[j].name);

0 commit comments

Comments
 (0)