Skip to content

Commit 3c3b41e

Browse files
james-c-linaroacmel
authored andcommitted
perf cs-etm: Finish removal of ETM_OPT_*
These #defines have been removed from the kernel headers in favour of the string based PMU format attributes. Usages were previously removed from the recording side of cs-etm in Perf. Finish the removal by removing usages from the decode side too. It's a straight replacement of the old #defines with the new register bit definitions. Except cs_etm__setup_timeless_decoding() which wasn't looking at the saved metadata and was instead hard coding an access to 'attr.config'. This was vulnerable to the same issue of .config being moved to .config2 etc that the original removal of ETM_OPT_* tried to fix. So fix that too. Signed-off-by: James Clark <james.clark@linaro.org> Tested-by: Leo Yan <leo.yan@arm.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Leo Yan <leo.yan@linux.dev> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Suzuki Poulouse <suzuki.poulose@arm.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0693907 commit 3c3b41e

4 files changed

Lines changed: 29 additions & 38 deletions

File tree

tools/perf/arch/arm/util/cs-etm.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,6 @@ static const char * const metadata_ete_ro[] = {
6868

6969
enum cs_etm_version { CS_NOT_PRESENT, CS_ETMV3, CS_ETMV4, CS_ETE };
7070

71-
/* ETMv4 CONFIGR register bits */
72-
#define TRCCONFIGR_BB BIT(3)
73-
#define TRCCONFIGR_CCI BIT(4)
74-
#define TRCCONFIGR_CID BIT(6)
75-
#define TRCCONFIGR_VMID BIT(7)
76-
#define TRCCONFIGR_TS BIT(11)
77-
#define TRCCONFIGR_RS BIT(12)
78-
#define TRCCONFIGR_VMIDOPT BIT(15)
79-
80-
/* ETMv3 ETMCR register bits */
81-
#define ETMCR_CYC_ACC BIT(12)
82-
#define ETMCR_TIMESTAMP_EN BIT(28)
83-
#define ETMCR_RETURN_STACK BIT(29)
84-
8571
static bool cs_etm_is_ete(struct perf_pmu *cs_etm_pmu, struct perf_cpu cpu);
8672
static int cs_etm_get_ro(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path, __u64 *val);
8773
static bool cs_etm_pmu_path_exists(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path);

tools/perf/util/cs-etm-decoder/cs-etm-decoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq,
549549
/*
550550
* Process the PE_CONTEXT packets if we have a valid contextID or VMID.
551551
* If the kernel is running at EL2, the PID is traced in CONTEXTIDR_EL2
552-
* as VMID, Bit ETM_OPT_CTXTID2 is set in this case.
552+
* as VMID, Format attribute 'contextid2' is set in this case.
553553
*/
554554
switch (cs_etm__get_pid_fmt(etmq)) {
555555
case CS_ETM_PIDFMT_CTXTID:

tools/perf/util/cs-etm.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int cs_etm__get_cpu(struct cs_etm_queue *etmq, u8 trace_chan_id, int *cpu)
194194
* CS_ETM_PIDFMT_CTXTID2: CONTEXTIDR_EL2 is traced.
195195
* CS_ETM_PIDFMT_NONE: No context IDs
196196
*
197-
* It's possible that the two bits ETM_OPT_CTXTID and ETM_OPT_CTXTID2
197+
* It's possible that the two format attributes 'contextid1' and 'contextid2'
198198
* are enabled at the same time when the session runs on an EL2 kernel.
199199
* This means the CONTEXTIDR_EL1 and CONTEXTIDR_EL2 both will be
200200
* recorded in the trace data, the tool will selectively use
@@ -210,15 +210,15 @@ static enum cs_etm_pid_fmt cs_etm__init_pid_fmt(u64 *metadata)
210210
if (metadata[CS_ETM_MAGIC] == __perf_cs_etmv3_magic) {
211211
val = metadata[CS_ETM_ETMCR];
212212
/* CONTEXTIDR is traced */
213-
if (val & BIT(ETM_OPT_CTXTID))
213+
if (val & ETMCR_CTXTID)
214214
return CS_ETM_PIDFMT_CTXTID;
215215
} else {
216216
val = metadata[CS_ETMV4_TRCCONFIGR];
217217
/* CONTEXTIDR_EL2 is traced */
218-
if (val & (BIT(ETM4_CFG_BIT_VMID) | BIT(ETM4_CFG_BIT_VMID_OPT)))
218+
if (val & (TRCCONFIGR_VMID | TRCCONFIGR_VMIDOPT))
219219
return CS_ETM_PIDFMT_CTXTID2;
220220
/* CONTEXTIDR_EL1 is traced */
221-
else if (val & BIT(ETM4_CFG_BIT_CTXTID))
221+
else if (val & TRCCONFIGR_CID)
222222
return CS_ETM_PIDFMT_CTXTID;
223223
}
224224

@@ -2914,29 +2914,21 @@ static int cs_etm__process_auxtrace_event(struct perf_session *session,
29142914
return 0;
29152915
}
29162916

2917-
static int cs_etm__setup_timeless_decoding(struct cs_etm_auxtrace *etm)
2917+
static void cs_etm__setup_timeless_decoding(struct cs_etm_auxtrace *etm)
29182918
{
2919-
struct evsel *evsel;
2920-
struct evlist *evlist = etm->session->evlist;
2919+
/* Take first ETM as all options will be the same for all ETMs */
2920+
u64 *metadata = etm->metadata[0];
29212921

29222922
/* Override timeless mode with user input from --itrace=Z */
29232923
if (etm->synth_opts.timeless_decoding) {
29242924
etm->timeless_decoding = true;
2925-
return 0;
2925+
return;
29262926
}
29272927

2928-
/*
2929-
* Find the cs_etm evsel and look at what its timestamp setting was
2930-
*/
2931-
evlist__for_each_entry(evlist, evsel)
2932-
if (cs_etm__evsel_is_auxtrace(etm->session, evsel)) {
2933-
etm->timeless_decoding =
2934-
!(evsel->core.attr.config & BIT(ETM_OPT_TS));
2935-
return 0;
2936-
}
2937-
2938-
pr_err("CS ETM: Couldn't find ETM evsel\n");
2939-
return -EINVAL;
2928+
if (metadata[CS_ETM_MAGIC] == __perf_cs_etmv3_magic)
2929+
etm->timeless_decoding = !(metadata[CS_ETM_ETMCR] & ETMCR_TIMESTAMP_EN);
2930+
else
2931+
etm->timeless_decoding = !(metadata[CS_ETMV4_TRCCONFIGR] & TRCCONFIGR_TS);
29402932
}
29412933

29422934
/*
@@ -3499,9 +3491,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event,
34993491
etm->auxtrace.evsel_is_auxtrace = cs_etm__evsel_is_auxtrace;
35003492
session->auxtrace = &etm->auxtrace;
35013493

3502-
err = cs_etm__setup_timeless_decoding(etm);
3503-
if (err)
3504-
return err;
3494+
cs_etm__setup_timeless_decoding(etm);
35053495

35063496
etm->tc.time_shift = tc->time_shift;
35073497
etm->tc.time_mult = tc->time_mult;

tools/perf/util/cs-etm.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ struct cs_etm_packet_queue {
230230
/* CoreSight trace ID is currently the bottom 7 bits of the value */
231231
#define CORESIGHT_TRACE_ID_VAL_MASK GENMASK(6, 0)
232232

233+
/* ETMv4 CONFIGR register bits */
234+
#define TRCCONFIGR_BB BIT(3)
235+
#define TRCCONFIGR_CCI BIT(4)
236+
#define TRCCONFIGR_CID BIT(6)
237+
#define TRCCONFIGR_VMID BIT(7)
238+
#define TRCCONFIGR_TS BIT(11)
239+
#define TRCCONFIGR_RS BIT(12)
240+
#define TRCCONFIGR_VMIDOPT BIT(15)
241+
242+
/* ETMv3 ETMCR register bits */
243+
#define ETMCR_CYC_ACC BIT(12)
244+
#define ETMCR_CTXTID BIT(14)
245+
#define ETMCR_TIMESTAMP_EN BIT(28)
246+
#define ETMCR_RETURN_STACK BIT(29)
247+
233248
int cs_etm__process_auxtrace_info(union perf_event *event,
234249
struct perf_session *session);
235250
void cs_etm_get_default_config(const struct perf_pmu *pmu, struct perf_event_attr *attr);

0 commit comments

Comments
 (0)