Skip to content

Commit 7b10098

Browse files
captain5050acmel
authored andcommitted
perf evlist: Remove __evlist__add_default
__evlist__add_default adds a cycles event to a typically empty evlist and was extended for hybrid with evlist__add_default_hybrid, as more than 1 PMU was necessary. Rather than have dedicated logic for the cycles event, this change switches to parsing 'cycles:P' which will handle wildcarding the PMUs appropriately for hybrid. Reviewed-by: Kan Liang <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ali Saidi <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Dmitrii Dolgov <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jing Zhang <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kang Minchul <[email protected]> Cc: Leo Yan <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mike Leach <[email protected]> Cc: Ming Wang <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Rob Herring <[email protected]> Cc: Sandipan Das <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Suzuki Poulouse <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Will Deacon <[email protected]> Cc: Xing Zhengjun <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b4388df commit 7b10098

File tree

10 files changed

+25
-130
lines changed

10 files changed

+25
-130
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ void arch_evsel__set_sample_weight(struct evsel *evsel)
1616
evsel__set_sample_bit(evsel, WEIGHT_STRUCT);
1717
}
1818

19-
void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr)
20-
{
21-
struct perf_env env = { .total_mem = 0, } ;
22-
23-
if (!perf_env__cpuid(&env))
24-
return;
25-
26-
/*
27-
* On AMD, precise cycles event sampling internally uses IBS pmu.
28-
* But IBS does not have filtering capabilities and perf by default
29-
* sets exclude_guest = 1. This makes IBS pmu event init fail and
30-
* thus perf ends up doing non-precise sampling. Avoid it by clearing
31-
* exclude_guest.
32-
*/
33-
if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD"))
34-
attr->exclude_guest = 0;
35-
36-
free(env.cpuid);
37-
}
38-
3919
/* Check whether the evsel's PMU supports the perf metrics */
4020
bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
4121
{

tools/perf/builtin-record.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,18 +4161,11 @@ int cmd_record(int argc, const char **argv)
41614161
record.opts.tail_synthesize = true;
41624162

41634163
if (rec->evlist->core.nr_entries == 0) {
4164-
if (perf_pmu__has_hybrid()) {
4165-
err = evlist__add_default_hybrid(rec->evlist,
4166-
!record.opts.no_samples);
4167-
} else {
4168-
err = __evlist__add_default(rec->evlist,
4169-
!record.opts.no_samples);
4170-
}
4164+
bool can_profile_kernel = perf_event_paranoid_check(1);
41714165

4172-
if (err < 0) {
4173-
pr_err("Not enough memory for event selector list\n");
4166+
err = parse_event(rec->evlist, can_profile_kernel ? "cycles:P" : "cycles:Pu");
4167+
if (err)
41744168
goto out;
4175-
}
41764169
}
41774170

41784171
if (rec->opts.target.tid && !rec->opts.no_inherit_set)

tools/perf/builtin-top.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,10 +1653,12 @@ int cmd_top(int argc, const char **argv)
16531653
if (annotate_check_args(&top.annotation_opts) < 0)
16541654
goto out_delete_evlist;
16551655

1656-
if (!top.evlist->core.nr_entries &&
1657-
evlist__add_default(top.evlist) < 0) {
1658-
pr_err("Not enough memory for event selector list\n");
1659-
goto out_delete_evlist;
1656+
if (!top.evlist->core.nr_entries) {
1657+
bool can_profile_kernel = perf_event_paranoid_check(1);
1658+
int err = parse_event(top.evlist, can_profile_kernel ? "cycles:P" : "cycles:Pu");
1659+
1660+
if (err)
1661+
goto out_delete_evlist;
16601662
}
16611663

16621664
status = evswitch__init(&top.evswitch, top.evlist, stderr);

tools/perf/util/evlist-hybrid.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,6 @@
1616
#include <perf/evsel.h>
1717
#include <perf/cpumap.h>
1818

19-
int evlist__add_default_hybrid(struct evlist *evlist, bool precise)
20-
{
21-
struct evsel *evsel;
22-
struct perf_pmu *pmu;
23-
__u64 config;
24-
struct perf_cpu_map *cpus;
25-
26-
perf_pmu__for_each_hybrid_pmu(pmu) {
27-
config = PERF_COUNT_HW_CPU_CYCLES |
28-
((__u64)pmu->type << PERF_PMU_TYPE_SHIFT);
29-
evsel = evsel__new_cycles(precise, PERF_TYPE_HARDWARE,
30-
config);
31-
if (!evsel)
32-
return -ENOMEM;
33-
34-
cpus = perf_cpu_map__get(pmu->cpus);
35-
evsel->core.cpus = cpus;
36-
evsel->core.own_cpus = perf_cpu_map__get(cpus);
37-
evsel->pmu_name = strdup(pmu->name);
38-
evlist__add(evlist, evsel);
39-
}
40-
41-
return 0;
42-
}
43-
4419
bool evlist__has_hybrid(struct evlist *evlist)
4520
{
4621
struct evsel *evsel;

tools/perf/util/evlist-hybrid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "evlist.h"
88
#include <unistd.h>
99

10-
int evlist__add_default_hybrid(struct evlist *evlist, bool precise);
1110
bool evlist__has_hybrid(struct evlist *evlist);
1211

1312
#endif /* __PERF_EVLIST_HYBRID_H */

tools/perf/util/evlist.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@ struct evlist *evlist__new(void)
9393
struct evlist *evlist__new_default(void)
9494
{
9595
struct evlist *evlist = evlist__new();
96+
bool can_profile_kernel;
97+
int err;
98+
99+
if (!evlist)
100+
return NULL;
96101

97-
if (evlist && evlist__add_default(evlist)) {
102+
can_profile_kernel = perf_event_paranoid_check(1);
103+
err = parse_event(evlist, can_profile_kernel ? "cycles:P" : "cycles:Pu");
104+
if (err) {
98105
evlist__delete(evlist);
99106
evlist = NULL;
100107
}
@@ -237,19 +244,6 @@ static void evlist__set_leader(struct evlist *evlist)
237244
perf_evlist__set_leader(&evlist->core);
238245
}
239246

240-
int __evlist__add_default(struct evlist *evlist, bool precise)
241-
{
242-
struct evsel *evsel;
243-
244-
evsel = evsel__new_cycles(precise, PERF_TYPE_HARDWARE,
245-
PERF_COUNT_HW_CPU_CYCLES);
246-
if (evsel == NULL)
247-
return -ENOMEM;
248-
249-
evlist__add(evlist, evsel);
250-
return 0;
251-
}
252-
253247
static struct evsel *evlist__dummy_event(struct evlist *evlist)
254248
{
255249
struct perf_event_attr attr = {

tools/perf/util/evlist.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ void evlist__delete(struct evlist *evlist);
100100
void evlist__add(struct evlist *evlist, struct evsel *entry);
101101
void evlist__remove(struct evlist *evlist, struct evsel *evsel);
102102

103-
int __evlist__add_default(struct evlist *evlist, bool precise);
104-
105-
static inline int evlist__add_default(struct evlist *evlist)
106-
{
107-
return __evlist__add_default(evlist, true);
108-
}
109-
110103
int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs);
111104

112105
int __evlist__add_default_attrs(struct evlist *evlist,

tools/perf/util/evsel.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -316,48 +316,6 @@ struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx)
316316
return evsel;
317317
}
318318

319-
static bool perf_event_can_profile_kernel(void)
320-
{
321-
return perf_event_paranoid_check(1);
322-
}
323-
324-
struct evsel *evsel__new_cycles(bool precise __maybe_unused, __u32 type, __u64 config)
325-
{
326-
struct perf_event_attr attr = {
327-
.type = type,
328-
.config = config,
329-
.exclude_kernel = !perf_event_can_profile_kernel(),
330-
};
331-
struct evsel *evsel;
332-
333-
event_attr_init(&attr);
334-
335-
/*
336-
* Now let the usual logic to set up the perf_event_attr defaults
337-
* to kick in when we return and before perf_evsel__open() is called.
338-
*/
339-
evsel = evsel__new(&attr);
340-
if (evsel == NULL)
341-
goto out;
342-
343-
arch_evsel__fixup_new_cycles(&evsel->core.attr);
344-
345-
evsel->precise_max = true;
346-
347-
/* use asprintf() because free(evsel) assumes name is allocated */
348-
if (asprintf(&evsel->name, "cycles%s%s%.*s",
349-
(attr.precise_ip || attr.exclude_kernel) ? ":" : "",
350-
attr.exclude_kernel ? "u" : "",
351-
attr.precise_ip ? attr.precise_ip + 1 : 0, "ppp") < 0)
352-
goto error_free;
353-
out:
354-
return evsel;
355-
error_free:
356-
evsel__delete(evsel);
357-
evsel = NULL;
358-
goto out;
359-
}
360-
361319
int copy_config_terms(struct list_head *dst, struct list_head *src)
362320
{
363321
struct evsel_config_term *pos, *tmp;
@@ -1131,10 +1089,6 @@ void __weak arch_evsel__set_sample_weight(struct evsel *evsel)
11311089
evsel__set_sample_bit(evsel, WEIGHT);
11321090
}
11331091

1134-
void __weak arch_evsel__fixup_new_cycles(struct perf_event_attr *attr __maybe_unused)
1135-
{
1136-
}
1137-
11381092
void __weak arch__post_evsel_config(struct evsel *evsel __maybe_unused,
11391093
struct perf_event_attr *attr __maybe_unused)
11401094
{

tools/perf/util/evsel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ static inline struct evsel *evsel__newtp(const char *sys, const char *name)
243243
}
244244
#endif
245245

246-
struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config);
247-
248246
#ifdef HAVE_LIBTRACEEVENT
249247
struct tep_event *event_format__new(const char *sys, const char *name);
250248
#endif
@@ -312,7 +310,6 @@ void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_forma
312310
void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
313311

314312
void arch_evsel__set_sample_weight(struct evsel *evsel);
315-
void arch_evsel__fixup_new_cycles(struct perf_event_attr *attr);
316313
void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr);
317314

318315
int evsel__set_filter(struct evsel *evsel, const char *filter);

tools/perf/util/python.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
5050
#endif
5151

52+
/*
53+
* Avoid bringing in event parsing.
54+
*/
55+
int parse_event(struct evlist *evlist __maybe_unused, const char *str __maybe_unused)
56+
{
57+
return 0;
58+
}
59+
5260
/*
5361
* Provide these two so that we don't have to link against callchain.c and
5462
* start dragging hist.c, etc.

0 commit comments

Comments
 (0)