Skip to content

Commit 90bc12c

Browse files
Maximilian Sanders9105947
Maximilian Sander
authored andcommittedMar 18, 2024
Fix .type for perf invocation
The old perf invocation used a non-sensical value for .type. It seems like it worked by accident. This fix copies the invocation from the kernel documentation. The now non-required PMU type lookup is removed.
1 parent 6180651 commit 90bc12c

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed
 

‎include/perf_util.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,4 @@ class perf_tmam_handle {
116116

117117
/// trigger perf readout, but discard results
118118
void nullread();
119-
120-
/// helper: retrieve perf event type for P-core PMU
121-
static unsigned int get_pmu_type();
122119
};

‎src/perf_util.cpp

+3-19
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,6 @@ perf_tmam_data_t perf_tmam_data_t::read_from_perf(int perf_leader_fd) {
134134
return data;
135135
}
136136

137-
unsigned int perf_tmam_handle::get_pmu_type() {
138-
const std::string fname = "/sys/devices/cpu_core/type";
139-
unsigned int type;
140-
std::ifstream typefile(fname);
141-
142-
if (!typefile.is_open()) {
143-
throw std::system_error(errno, std::generic_category(), "could not open " + fname);
144-
}
145-
146-
typefile >> type;
147-
148-
if (0 == type) {
149-
throw std::system_error(EINVAL, std::generic_category(), "perf PMU type must not be zero");
150-
}
151-
152-
return type;
153-
}
154137

155138
perf_tmam_handle::perf_tmam_handle(bool use_rdpmc, pid_t pid, int cpu) : use_rdpmc(use_rdpmc) {
156139
// phase 1: open leader
@@ -159,14 +142,15 @@ perf_tmam_handle::perf_tmam_handle(bool use_rdpmc, pid_t pid, int cpu) : use_rdp
159142
// Note that "config" is using hardcoded values throughout.
160143
// This is because a) the documentation notes these numbers,
161144
// so they are assumed to be stable and b) they are hardcoded in the kernel as well.
145+
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/Documentation/topdown.txt
162146

163147
// Also, the perf_event_attr struct is huged and designed to no be specified for many fields.
164148
// Therefore the pragma to supress the warnings.
165149

166150
#pragma GCC diagnostic push
167151
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
168152
struct perf_event_attr leader_perf_attr = {
169-
.type = get_pmu_type(),
153+
.type = PERF_TYPE_RAW,
170154
.size = sizeof(struct perf_event_attr),
171155
.config = 0x400,
172156
.read_format = PERF_FORMAT_GROUP,
@@ -186,7 +170,7 @@ perf_tmam_handle::perf_tmam_handle(bool use_rdpmc, pid_t pid, int cpu) : use_rdp
186170
#pragma GCC diagnostic push
187171
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
188172
struct perf_event_attr perf_attr = {
189-
.type = get_pmu_type(),
173+
.type = PERF_TYPE_RAW,
190174
.size = sizeof(struct perf_event_attr),
191175
.config = config,
192176
.read_format = PERF_FORMAT_GROUP,

0 commit comments

Comments
 (0)
Please sign in to comment.