Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit acb6515

Browse files
Kan Liangacmel
authored andcommitted
perf record: Support sample-read topdown metric group
With the hardware TopDown metrics feature, sample-read feature should be supported for a topdown group, e.g., sample a non-topdown event and read a topdown metric group. But the current perf record code errors out. For a topdown metric group, the slots event must be the leader of the group, but the leader slots event doesn't support sampling. To support sample-read the topdown metric group, use the 2nd event of the group as the "leader" for the purposes of sampling. Only the platform with Topdown metic feature supports sample-read the topdown group. Add arch_topdown_sample_read() to indicate whether the topdown group supports sample-read. Signed-off-by: Kan Liang <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 687986b commit acb6515

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <stdio.h>
33
#include "api/fs/fs.h"
4+
#include "util/pmu.h"
45
#include "util/topdown.h"
56

67
/*
@@ -26,3 +27,37 @@ void arch_topdown_group_warn(void)
2627
"nmi_watchdog enabled with topdown. May give wrong results.\n"
2728
"Disable with echo 0 > /proc/sys/kernel/nmi_watchdog\n");
2829
}
30+
31+
#define TOPDOWN_SLOTS 0x0400
32+
33+
static bool is_topdown_slots_event(struct evsel *counter)
34+
{
35+
if (!counter->pmu_name)
36+
return false;
37+
38+
if (strcmp(counter->pmu_name, "cpu"))
39+
return false;
40+
41+
if (counter->core.attr.config == TOPDOWN_SLOTS)
42+
return true;
43+
44+
return false;
45+
}
46+
47+
/*
48+
* Check whether a topdown group supports sample-read.
49+
*
50+
* Only Topdown metic supports sample-read. The slots
51+
* event must be the leader of the topdown group.
52+
*/
53+
54+
bool arch_topdown_sample_read(struct evsel *leader)
55+
{
56+
if (!pmu_have_event("cpu", "slots"))
57+
return false;
58+
59+
if (is_topdown_slots_event(leader))
60+
return true;
61+
62+
return false;
63+
}

tools/perf/util/record.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "util/perf_api_probe.h"
1515
#include "record.h"
1616
#include "../perf-sys.h"
17+
#include "topdown.h"
1718

1819
/*
1920
* evsel__config_leader_sampling() uses special rules for leader sampling.
@@ -24,7 +25,7 @@ static struct evsel *evsel__read_sampler(struct evsel *evsel, struct evlist *evl
2425
{
2526
struct evsel *leader = evsel->leader;
2627

27-
if (evsel__is_aux_event(leader)) {
28+
if (evsel__is_aux_event(leader) || arch_topdown_sample_read(leader)) {
2829
evlist__for_each_entry(evlist, evsel) {
2930
if (evsel->leader == leader && evsel != evsel->leader)
3031
return evsel;

tools/perf/util/topdown.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ __weak bool arch_topdown_check_group(bool *warn)
5151
__weak void arch_topdown_group_warn(void)
5252
{
5353
}
54+
55+
__weak bool arch_topdown_sample_read(struct evsel *leader __maybe_unused)
56+
{
57+
return false;
58+
}

tools/perf/util/topdown.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#ifndef TOPDOWN_H
33
#define TOPDOWN_H 1
4+
#include "evsel.h"
45

56
bool arch_topdown_check_group(bool *warn);
67
void arch_topdown_group_warn(void);
8+
bool arch_topdown_sample_read(struct evsel *leader);
79

810
int topdown_filter_events(const char **attr, char **str, bool use_group);
911

0 commit comments

Comments
 (0)