forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/tools/perf/arch/x86/util/intel-bts.c
....@@ -1,16 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * intel-bts.c: Intel Processor Trace support
34 * Copyright (c) 2013-2015, Intel Corporation.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
13
- *
145 */
156
167 #include <errno.h>
....@@ -18,17 +9,21 @@
189 #include <linux/types.h>
1910 #include <linux/bitops.h>
2011 #include <linux/log2.h>
12
+#include <linux/zalloc.h>
2113
22
-#include "../../util/cpumap.h"
23
-#include "../../util/evsel.h"
24
-#include "../../util/evlist.h"
25
-#include "../../util/session.h"
26
-#include "../../util/util.h"
27
-#include "../../util/pmu.h"
28
-#include "../../util/debug.h"
29
-#include "../../util/tsc.h"
30
-#include "../../util/auxtrace.h"
31
-#include "../../util/intel-bts.h"
14
+#include "../../../util/cpumap.h"
15
+#include "../../../util/event.h"
16
+#include "../../../util/evsel.h"
17
+#include "../../../util/evlist.h"
18
+#include "../../../util/mmap.h"
19
+#include "../../../util/session.h"
20
+#include "../../../util/pmu.h"
21
+#include "../../../util/debug.h"
22
+#include "../../../util/record.h"
23
+#include "../../../util/tsc.h"
24
+#include "../../../util/auxtrace.h"
25
+#include "../../../util/intel-bts.h"
26
+#include <internal/lib.h> // page_size
3227
3328 #define KiB(x) ((x) * 1024)
3429 #define MiB(x) ((x) * 1024 * 1024)
....@@ -44,7 +39,7 @@
4439 struct intel_bts_recording {
4540 struct auxtrace_record itr;
4641 struct perf_pmu *intel_bts_pmu;
47
- struct perf_evlist *evlist;
42
+ struct evlist *evlist;
4843 bool snapshot_mode;
4944 size_t snapshot_size;
5045 int snapshot_ref_cnt;
....@@ -59,14 +54,14 @@
5954
6055 static size_t
6156 intel_bts_info_priv_size(struct auxtrace_record *itr __maybe_unused,
62
- struct perf_evlist *evlist __maybe_unused)
57
+ struct evlist *evlist __maybe_unused)
6358 {
6459 return INTEL_BTS_AUXTRACE_PRIV_SIZE;
6560 }
6661
6762 static int intel_bts_info_fill(struct auxtrace_record *itr,
6863 struct perf_session *session,
69
- struct auxtrace_info_event *auxtrace_info,
64
+ struct perf_record_auxtrace_info *auxtrace_info,
7065 size_t priv_size)
7166 {
7267 struct intel_bts_recording *btsr =
....@@ -80,10 +75,10 @@
8075 if (priv_size != INTEL_BTS_AUXTRACE_PRIV_SIZE)
8176 return -EINVAL;
8277
83
- if (!session->evlist->nr_mmaps)
78
+ if (!session->evlist->core.nr_mmaps)
8479 return -EINVAL;
8580
86
- pc = session->evlist->mmap[0].base;
81
+ pc = session->evlist->mmap[0].core.base;
8782 if (pc) {
8883 err = perf_read_tsc_conversion(pc, &tc);
8984 if (err) {
....@@ -108,27 +103,32 @@
108103 }
109104
110105 static int intel_bts_recording_options(struct auxtrace_record *itr,
111
- struct perf_evlist *evlist,
106
+ struct evlist *evlist,
112107 struct record_opts *opts)
113108 {
114109 struct intel_bts_recording *btsr =
115110 container_of(itr, struct intel_bts_recording, itr);
116111 struct perf_pmu *intel_bts_pmu = btsr->intel_bts_pmu;
117
- struct perf_evsel *evsel, *intel_bts_evsel = NULL;
118
- const struct cpu_map *cpus = evlist->cpus;
119
- bool privileged = geteuid() == 0 || perf_event_paranoid() < 0;
112
+ struct evsel *evsel, *intel_bts_evsel = NULL;
113
+ const struct perf_cpu_map *cpus = evlist->core.cpus;
114
+ bool privileged = perf_event_paranoid_check(-1);
115
+
116
+ if (opts->auxtrace_sample_mode) {
117
+ pr_err("Intel BTS does not support AUX area sampling\n");
118
+ return -EINVAL;
119
+ }
120120
121121 btsr->evlist = evlist;
122122 btsr->snapshot_mode = opts->auxtrace_snapshot_mode;
123123
124124 evlist__for_each_entry(evlist, evsel) {
125
- if (evsel->attr.type == intel_bts_pmu->type) {
125
+ if (evsel->core.attr.type == intel_bts_pmu->type) {
126126 if (intel_bts_evsel) {
127127 pr_err("There may be only one " INTEL_BTS_PMU_NAME " event\n");
128128 return -EINVAL;
129129 }
130
- evsel->attr.freq = 0;
131
- evsel->attr.sample_period = 1;
130
+ evsel->core.attr.freq = 0;
131
+ evsel->core.attr.sample_period = 1;
132132 intel_bts_evsel = evsel;
133133 opts->full_auxtrace = true;
134134 }
....@@ -142,7 +142,7 @@
142142 if (!opts->full_auxtrace)
143143 return 0;
144144
145
- if (opts->full_auxtrace && !cpu_map__empty(cpus)) {
145
+ if (opts->full_auxtrace && !perf_cpu_map__empty(cpus)) {
146146 pr_err(INTEL_BTS_PMU_NAME " does not support per-cpu recording\n");
147147 return -EINVAL;
148148 }
....@@ -223,25 +223,25 @@
223223 * In the case of per-cpu mmaps, we need the CPU on the
224224 * AUX event.
225225 */
226
- if (!cpu_map__empty(cpus))
227
- perf_evsel__set_sample_bit(intel_bts_evsel, CPU);
226
+ if (!perf_cpu_map__empty(cpus))
227
+ evsel__set_sample_bit(intel_bts_evsel, CPU);
228228 }
229229
230230 /* Add dummy event to keep tracking */
231231 if (opts->full_auxtrace) {
232
- struct perf_evsel *tracking_evsel;
232
+ struct evsel *tracking_evsel;
233233 int err;
234234
235235 err = parse_events(evlist, "dummy:u", NULL);
236236 if (err)
237237 return err;
238238
239
- tracking_evsel = perf_evlist__last(evlist);
239
+ tracking_evsel = evlist__last(evlist);
240240
241241 perf_evlist__set_tracking_event(evlist, tracking_evsel);
242242
243
- tracking_evsel->attr.freq = 0;
244
- tracking_evsel->attr.sample_period = 1;
243
+ tracking_evsel->core.attr.freq = 0;
244
+ tracking_evsel->core.attr.sample_period = 1;
245245 }
246246
247247 return 0;
....@@ -322,11 +322,11 @@
322322 {
323323 struct intel_bts_recording *btsr =
324324 container_of(itr, struct intel_bts_recording, itr);
325
- struct perf_evsel *evsel;
325
+ struct evsel *evsel;
326326
327327 evlist__for_each_entry(btsr->evlist, evsel) {
328
- if (evsel->attr.type == btsr->intel_bts_pmu->type)
329
- return perf_evsel__disable(evsel);
328
+ if (evsel->core.attr.type == btsr->intel_bts_pmu->type)
329
+ return evsel__disable(evsel);
330330 }
331331 return -EINVAL;
332332 }
....@@ -335,11 +335,11 @@
335335 {
336336 struct intel_bts_recording *btsr =
337337 container_of(itr, struct intel_bts_recording, itr);
338
- struct perf_evsel *evsel;
338
+ struct evsel *evsel;
339339
340340 evlist__for_each_entry(btsr->evlist, evsel) {
341
- if (evsel->attr.type == btsr->intel_bts_pmu->type)
342
- return perf_evsel__enable(evsel);
341
+ if (evsel->core.attr.type == btsr->intel_bts_pmu->type)
342
+ return evsel__enable(evsel);
343343 }
344344 return -EINVAL;
345345 }
....@@ -413,20 +413,6 @@
413413 return err;
414414 }
415415
416
-static int intel_bts_read_finish(struct auxtrace_record *itr, int idx)
417
-{
418
- struct intel_bts_recording *btsr =
419
- container_of(itr, struct intel_bts_recording, itr);
420
- struct perf_evsel *evsel;
421
-
422
- evlist__for_each_entry(btsr->evlist, evsel) {
423
- if (evsel->attr.type == btsr->intel_bts_pmu->type)
424
- return perf_evlist__enable_event_idx(btsr->evlist,
425
- evsel, idx);
426
- }
427
- return -EINVAL;
428
-}
429
-
430416 struct auxtrace_record *intel_bts_recording_init(int *err)
431417 {
432418 struct perf_pmu *intel_bts_pmu = perf_pmu__find(INTEL_BTS_PMU_NAME);
....@@ -447,6 +433,7 @@
447433 }
448434
449435 btsr->intel_bts_pmu = intel_bts_pmu;
436
+ btsr->itr.pmu = intel_bts_pmu;
450437 btsr->itr.recording_options = intel_bts_recording_options;
451438 btsr->itr.info_priv_size = intel_bts_info_priv_size;
452439 btsr->itr.info_fill = intel_bts_info_fill;
....@@ -456,7 +443,7 @@
456443 btsr->itr.find_snapshot = intel_bts_find_snapshot;
457444 btsr->itr.parse_snapshot_options = intel_bts_parse_snapshot_options;
458445 btsr->itr.reference = intel_bts_reference;
459
- btsr->itr.read_finish = intel_bts_read_finish;
446
+ btsr->itr.read_finish = auxtrace_record__read_finish;
460447 btsr->itr.alignment = sizeof(struct branch);
461448 return &btsr->itr;
462449 }