/* Not supported in etmv3 */ if (cs_etm_get_version(cs_etm_pmu, cpu) == CS_ETMV3) {
pr_err("%s: contextid not supported in ETMv3, disable with %s/contextid=0/\n",
CORESIGHT_ETM_PMU_NAME, CORESIGHT_ETM_PMU_NAME); return -EINVAL;
}
/* Get a handle on TRCIDR2 */
err = cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2], &val); if (err) return err;
if (contextid &
perf_pmu__format_bits(cs_etm_pmu, "contextid1")) { /* * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID * tracing is supported: * 0b00000 Context ID tracing is not supported. * 0b00100 Maximum of 32-bit Context ID size. * All other values are reserved.
*/ if (BMVAL(val, 5, 9) != 0x4) {
pr_err("%s: CONTEXTIDR_EL1 isn't supported, disable with %s/contextid1=0/\n",
CORESIGHT_ETM_PMU_NAME, CORESIGHT_ETM_PMU_NAME); return -EINVAL;
}
}
if (contextid &
perf_pmu__format_bits(cs_etm_pmu, "contextid2")) { /* * TRCIDR2.VMIDOPT[30:29] != 0 and * TRCIDR2.VMIDSIZE[14:10] == 0b00100 (32bit virtual contextid) * We can't support CONTEXTIDR in VMID if the size of the * virtual context id is < 32bit. * Any value of VMIDSIZE >= 4 (i.e, > 32bit) is fine for us.
*/ if (!BMVAL(val, 29, 30) || BMVAL(val, 10, 14) < 4) {
pr_err("%s: CONTEXTIDR_EL2 isn't supported, disable with %s/contextid2=0/\n",
CORESIGHT_ETM_PMU_NAME, CORESIGHT_ETM_PMU_NAME); return -EINVAL;
}
}
if (!(evsel->core.attr.config &
perf_pmu__format_bits(cs_etm_pmu, "timestamp"))) return 0;
if (cs_etm_get_version(cs_etm_pmu, cpu) == CS_ETMV3) {
pr_err("%s: timestamp not supported in ETMv3, disable with %s/timestamp=0/\n",
CORESIGHT_ETM_PMU_NAME, CORESIGHT_ETM_PMU_NAME); return -EINVAL;
}
/* Get a handle on TRCIRD0 */
err = cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0], &val); if (err) return err;
/* * TRCIDR0.TSSIZE, bit [28-24], indicates whether global timestamping * is supported: * 0b00000 Global timestamping is not implemented * 0b00110 Implementation supports a maximum timestamp of 48bits. * 0b01000 Implementation supports a maximum timestamp of 64bits.
*/
val &= GENMASK(28, 24); if (!val) { return -EINVAL;
}
/* * Check whether the requested timestamp and contextid options should be * available on all requested CPUs and if not, tell the user how to override. * The kernel will silently disable any unavailable options so a warning here * first is better. In theory the kernel could still disable the option for * some other reason so this is best effort only.
*/ staticint cs_etm_validate_config(struct perf_pmu *cs_etm_pmu, struct evsel *evsel)
{ int idx, err = 0; struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; struct perf_cpu_map *intersect_cpus; struct perf_cpu cpu;
/* * Set option of each CPU we have. In per-cpu case, do the validation * for CPUs to work with. In per-thread case, the CPU map has the "any" * CPU value. Since the traced program can run on any CPUs in this case, * thus don't skip validation.
*/ if (!perf_cpu_map__has_any_cpu(event_cpus)) { struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus();
perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { if (cs_etm_get_version(cs_etm_pmu, cpu) == CS_NOT_PRESENT) {
pr_err("%s: Not found on CPU %d. Check hardware and firmware support and that all Coresight drivers are loaded\n",
CORESIGHT_ETM_PMU_NAME, cpu.cpu); return -EINVAL;
}
err = cs_etm_validate_context_id(cs_etm_pmu, evsel, cpu); if (err) break;
err = cs_etm_validate_timestamp(cs_etm_pmu, evsel, cpu); if (err) break;
}
ret = perf_pmu__scan_file(pmu, path, "%x", &hash); if (ret != 1) { if (errno == ENOENT)
pr_err("Couldn't find sink \"%s\" on event %s\n" "Missing kernel or device support?\n\n" "Hint: An appropriate sink will be picked automatically if one isn't specified.\n",
sink, evsel__name(evsel)); else
pr_err("Failed to set sink \"%s\" on event %s with %d (%s)\n",
sink, evsel__name(evsel), errno,
str_error_r(errno, msg, sizeof(msg))); return ret;
}
evsel->core.attr.config2 |= hash; return 0;
}
/* * No sink was provided on the command line - allow the CoreSight * system to look for a default
*/ return 0;
}
evlist__for_each_entry(evlist, evsel) { if (evsel->core.attr.type == cs_etm_pmu->type) { if (cs_etm_evsel) {
pr_err("There may be only one %s event\n",
CORESIGHT_ETM_PMU_NAME); return -EINVAL;
}
cs_etm_evsel = evsel;
}
}
/* no need to continue if at least one event of interest was found */ if (!cs_etm_evsel) return 0;
ret = cs_etm_set_sink_attr(cs_etm_pmu, cs_etm_evsel); if (ret) return ret;
if (opts->use_clockid) {
pr_err("Cannot use clockid (-k option) with %s\n",
CORESIGHT_ETM_PMU_NAME); return -EINVAL;
}
/* we are in snapshot mode */ if (opts->auxtrace_snapshot_mode) { /* * No size were given to '-S' or '-m,', so go with * the default
*/ if (!opts->auxtrace_snapshot_size &&
!opts->auxtrace_mmap_pages) { if (privileged) {
opts->auxtrace_mmap_pages = MiB(4) / page_size;
} else {
opts->auxtrace_mmap_pages =
KiB(128) / page_size; if (opts->mmap_pages == UINT_MAX)
opts->mmap_pages = KiB(256) / page_size;
}
} elseif (!opts->auxtrace_mmap_pages && !privileged &&
opts->mmap_pages == UINT_MAX) {
opts->mmap_pages = KiB(256) / page_size;
}
/* * '-m,xyz' was specified but no snapshot size, so make the * snapshot size as big as the auxtrace mmap area.
*/ if (!opts->auxtrace_snapshot_size) {
opts->auxtrace_snapshot_size =
opts->auxtrace_mmap_pages * (size_t)page_size;
}
/* * -Sxyz was specified but no auxtrace mmap area, so make the * auxtrace mmap area big enough to fit the requested snapshot * size.
*/ if (!opts->auxtrace_mmap_pages) {
size_t sz = opts->auxtrace_snapshot_size;
/* Snapshot size can't be bigger than the auxtrace area */ if (opts->auxtrace_snapshot_size >
opts->auxtrace_mmap_pages * (size_t)page_size) {
pr_err("Snapshot size %zu must not be greater than AUX area tracing mmap size %zu\n",
opts->auxtrace_snapshot_size,
opts->auxtrace_mmap_pages * (size_t)page_size); return -EINVAL;
}
/* Something went wrong somewhere - this shouldn't happen */ if (!opts->auxtrace_snapshot_size ||
!opts->auxtrace_mmap_pages) {
pr_err("Failed to calculate default snapshot size and/or AUX area tracing mmap pages\n"); return -EINVAL;
}
}
/* Buffer sizes weren't specified with '-m,xyz' so give some defaults */ if (!opts->auxtrace_mmap_pages) { if (privileged) {
opts->auxtrace_mmap_pages = MiB(4) / page_size;
} else {
opts->auxtrace_mmap_pages = KiB(128) / page_size; if (opts->mmap_pages == UINT_MAX)
opts->mmap_pages = KiB(256) / page_size;
}
}
if (opts->auxtrace_snapshot_mode)
pr_debug2("%s snapshot size: %zu\n", CORESIGHT_ETM_PMU_NAME,
opts->auxtrace_snapshot_size);
/* * To obtain the auxtrace buffer file descriptor, the auxtrace * event must come first.
*/
evlist__to_front(evlist, cs_etm_evsel);
/* * get the CPU on the sample - need it to associate trace ID in the * AUX_OUTPUT_HW_ID event, and the AUX event for per-cpu mmaps.
*/
evsel__set_sample_bit(cs_etm_evsel, CPU);
/* * Also the case of per-cpu mmaps, need the contextID in order to be notified * when a context switch happened.
*/ if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) {
evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, "timestamp", 1);
evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, "contextid", 1);
}
/* * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME * bit is set for all events. In this case, always enable Arm CoreSight * timestamp tracing.
*/ if (opts->sample_time_set)
evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, "timestamp", 1);
evlist__for_each_entry(evlist, evsel) { if (evsel->core.attr.type == cs_etm_pmu->type) { /* * Variable perf_event_attr::config is assigned to * ETMv3/PTM. The bit fields have been made to match * the ETMv3.5 ETRMCR register specification. See the * PMU_FORMAT_ATTR() declarations in * drivers/hwtracing/coresight/coresight-perf.c for * details.
*/
config = evsel->core.attr.config; break;
}
}
/* * The perf event variable config bits represent both * the command line options and register programming * bits in ETMv3/PTM. For ETMv4 we must remap options * to real bits
*/
config_opts = cs_etm_get_config(itr); if (config_opts & BIT(ETM_OPT_CYCACC))
config |= BIT(ETM4_CFG_BIT_CYCACC); if (config_opts & BIT(ETM_OPT_CTXTID))
config |= BIT(ETM4_CFG_BIT_CTXTID); if (config_opts & BIT(ETM_OPT_TS))
config |= BIT(ETM4_CFG_BIT_TS); if (config_opts & BIT(ETM_OPT_RETSTK))
config |= BIT(ETM4_CFG_BIT_RETSTK); if (config_opts & BIT(ETM_OPT_CTXTID2))
config |= BIT(ETM4_CFG_BIT_VMID) |
BIT(ETM4_CFG_BIT_VMID_OPT); if (config_opts & BIT(ETM_OPT_BRANCH_BROADCAST))
config |= BIT(ETM4_CFG_BIT_BB);
if (!perf_cpu_map__has_any_cpu(event_cpus)) { /* cpu map is not "any" CPU , we have specific CPUs to work with */ struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus();
intersect_cpus = perf_cpu_map__intersect(event_cpus, online_cpus);
perf_cpu_map__put(online_cpus);
} else { /* Event can be "any" CPU so count all online CPUs. */
intersect_cpus = perf_cpu_map__new_online_cpus();
} /* Count number of each type of ETM. Don't count if that CPU has CS_NOT_PRESENT. */
perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { enum cs_etm_version v = cs_etm_get_version(cs_etm_pmu, cpu);
ete += v == CS_ETE;
etmv4 += v == CS_ETMV4;
etmv3 += v == CS_ETMV3;
}
perf_cpu_map__put(intersect_cpus);
if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH])) returnfalse;
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH], &trcdevarch); /* * ETE if ARCHVER is 5 (ARCHVER is 4 for ETM) and ARCHPART is 0xA13. * See ETM_DEVARCH_ETE_ARCH in coresight-etm4x.h
*/ return TRCDEVARCH_ARCHVER(trcdevarch) == 5 && TRCDEVARCH_ARCHPART(trcdevarch) == 0xA13;
}
static __u64 cs_etm_get_legacy_trace_id(struct perf_cpu cpu)
{ /* Wrap at 48 so that invalid trace IDs aren't saved into files. */ return CORESIGHT_LEGACY_CPU_TRACE_ID(cpu.cpu % 48);
}
/* Get trace configuration register */
data[CS_ETMV4_TRCCONFIGR] = cs_etmv4_get_config(itr); /* traceID set to legacy version, in case new perf running on older system */
data[CS_ETMV4_TRCTRACEIDR] = cs_etm_get_legacy_trace_id(cpu);
/* Get read-only information from sysFS */
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0],
&data[CS_ETMV4_TRCIDR0]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR1],
&data[CS_ETMV4_TRCIDR1]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2],
&data[CS_ETMV4_TRCIDR2]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR8],
&data[CS_ETMV4_TRCIDR8]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCAUTHSTATUS],
&data[CS_ETMV4_TRCAUTHSTATUS]);
/* Kernels older than 5.19 may not expose ts_source */ if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TS_SOURCE]) ||
cs_etm_get_ro_signed(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TS_SOURCE],
&data[CS_ETMV4_TS_SOURCE])) {
pr_debug3("[%03d] pmu file 'ts_source' not found. Fallback to safe value (-1)\n",
cpu.cpu);
data[CS_ETMV4_TS_SOURCE] = (__u64) -1;
}
}
/* Get trace configuration register */
data[CS_ETE_TRCCONFIGR] = cs_etmv4_get_config(itr); /* traceID set to legacy version, in case new perf running on older system */
data[CS_ETE_TRCTRACEIDR] = cs_etm_get_legacy_trace_id(cpu);
/* Get read-only information from sysFS */
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR0], &data[CS_ETE_TRCIDR0]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR1], &data[CS_ETE_TRCIDR1]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR2], &data[CS_ETE_TRCIDR2]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR8], &data[CS_ETE_TRCIDR8]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCAUTHSTATUS],
&data[CS_ETE_TRCAUTHSTATUS]); /* ETE uses the same registers as ETMv4 plus TRCDEVARCH */
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH],
&data[CS_ETE_TRCDEVARCH]);
/* Kernels older than 5.19 may not expose ts_source */ if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TS_SOURCE]) ||
cs_etm_get_ro_signed(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TS_SOURCE],
&data[CS_ETE_TS_SOURCE])) {
pr_debug3("[%03d] pmu file 'ts_source' not found. Fallback to safe value (-1)\n",
cpu.cpu);
data[CS_ETE_TS_SOURCE] = (__u64) -1;
}
}
/* first see what kind of tracer this cpu is affined to */ switch (cs_etm_get_version(cs_etm_pmu, cpu)) { case CS_ETE:
magic = __perf_cs_ete_magic;
cs_etm_save_ete_header(&info->priv[*offset], itr, cpu);
/* How much space was used */
increment = CS_ETE_PRIV_MAX;
nr_trc_params = CS_ETE_PRIV_MAX - CS_ETM_COMMON_BLK_MAX_V1; break;
case CS_ETMV4:
magic = __perf_cs_etmv4_magic;
cs_etm_save_etmv4_header(&info->priv[*offset], itr, cpu);
/* How much space was used */
increment = CS_ETMV4_PRIV_MAX;
nr_trc_params = CS_ETMV4_PRIV_MAX - CS_ETMV4_TRCCONFIGR; break;
case CS_ETMV3:
magic = __perf_cs_etmv3_magic; /* Get configuration register */
info->priv[*offset + CS_ETM_ETMCR] = cs_etm_get_config(itr); /* traceID set to legacy value in case new perf running on old system */
info->priv[*offset + CS_ETM_ETMTRACEIDR] = cs_etm_get_legacy_trace_id(cpu); /* Get read-only information from sysFS */
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMCCER],
&info->priv[*offset + CS_ETM_ETMCCER]);
cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMIDR],
&info->priv[*offset + CS_ETM_ETMIDR]);
/* How much space was used */
increment = CS_ETM_PRIV_MAX;
nr_trc_params = CS_ETM_PRIV_MAX - CS_ETM_ETMCR; break;
default: case CS_NOT_PRESENT: /* Unreachable, CPUs already validated in cs_etm_validate_config() */
assert(true); return;
}
/* Build generic header portion */
info->priv[*offset + CS_ETM_MAGIC] = magic;
info->priv[*offset + CS_ETM_CPU] = cpu.cpu;
info->priv[*offset + CS_ETM_NR_TRC_PARAMS] = nr_trc_params; /* Where the next CPU entry should start from */
*offset += increment;
}
if (priv_size != cs_etm_info_priv_size(itr, session->evlist)) return -EINVAL;
if (!session->evlist->core.nr_mmaps) return -EINVAL;
/* If the cpu_map has the "any" CPU all online CPUs are involved */ if (perf_cpu_map__has_any_cpu(event_cpus)) {
cpu_map = online_cpus;
} else { /* Make sure all specified CPUs are online */
perf_cpu_map__for_each_cpu(cpu, i, event_cpus) { if (!perf_cpu_map__has(online_cpus, cpu)) return -EINVAL;
}
cpu_map = event_cpus;
}
nr_cpu = perf_cpu_map__nr(cpu_map); /* Get PMU type as dynamically assigned by the core */
type = cs_etm_pmu->type;
/* First fill out the session header */
info->type = PERF_AUXTRACE_CS_ETM;
info->priv[CS_HEADER_VERSION] = CS_HEADER_CURRENT_VERSION;
info->priv[CS_PMU_TYPE_CPUS] = type << 32;
info->priv[CS_PMU_TYPE_CPUS] |= nr_cpu;
info->priv[CS_ETM_SNAPSHOT] = ptr->snapshot_mode;
/* * Set a default config to enable the user changed config tracking mechanism * (CFG_CHG and evsel__set_config_if_unset()). If no default is set then user * changes aren't tracked.
*/ void
cs_etm_get_default_config(conststruct perf_pmu *pmu __maybe_unused, struct perf_event_attr *attr)
{
attr->sample_period = 1;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.