Lines Matching +full:cpu +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/coresight-pmu.h>
18 #include "cs-etm.h"
29 #include "../../../util/cs-etm.h"
71 static bool cs_etm_is_ete(struct perf_pmu *cs_etm_pmu, struct perf_cpu cpu);
72 static int cs_etm_get_ro(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path, __u64 *val);
73 static bool cs_etm_pmu_path_exists(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path);
76 struct perf_cpu cpu) in cs_etm_get_version() argument
78 if (cs_etm_is_ete(cs_etm_pmu, cpu)) in cs_etm_get_version()
80 else if (cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0])) in cs_etm_get_version()
82 else if (cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMCCER])) in cs_etm_get_version()
89 struct perf_cpu cpu) in cs_etm_validate_context_id() argument
93 u64 contextid = evsel->core.attr.config & in cs_etm_validate_context_id()
102 if (cs_etm_get_version(cs_etm_pmu, cpu) == CS_ETMV3) { in cs_etm_validate_context_id()
105 return -EINVAL; in cs_etm_validate_context_id()
109 err = cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2], &val); in cs_etm_validate_context_id()
116 * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID in cs_etm_validate_context_id()
119 * 0b00100 Maximum of 32-bit Context ID size. in cs_etm_validate_context_id()
125 return -EINVAL; in cs_etm_validate_context_id()
141 return -EINVAL; in cs_etm_validate_context_id()
149 struct perf_cpu cpu) in cs_etm_validate_timestamp() argument
154 if (!(evsel->core.attr.config & in cs_etm_validate_timestamp()
158 if (cs_etm_get_version(cs_etm_pmu, cpu) == CS_ETMV3) { in cs_etm_validate_timestamp()
161 return -EINVAL; in cs_etm_validate_timestamp()
165 err = cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0], &val); in cs_etm_validate_timestamp()
170 * TRCIDR0.TSSIZE, bit [28-24], indicates whether global timestamping in cs_etm_validate_timestamp()
178 return -EINVAL; in cs_etm_validate_timestamp()
188 return ptr->cs_etm_pmu; in cs_etm_get_pmu()
202 struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; in cs_etm_validate_config()
204 struct perf_cpu cpu; in cs_etm_validate_config() local
207 * Set option of each CPU we have. In per-cpu case, do the validation in cs_etm_validate_config()
208 * for CPUs to work with. In per-thread case, the CPU map has the "any" in cs_etm_validate_config()
209 * CPU value. Since the traced program can run on any CPUs in this case, in cs_etm_validate_config()
221 perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { in cs_etm_validate_config()
222 if (cs_etm_get_version(cs_etm_pmu, cpu) == CS_NOT_PRESENT) { in cs_etm_validate_config()
223 …pr_err("%s: Not found on CPU %d. Check hardware and firmware support and that all Coresight driver… in cs_etm_validate_config()
224 CORESIGHT_ETM_PMU_NAME, cpu.cpu); in cs_etm_validate_config()
225 return -EINVAL; in cs_etm_validate_config()
227 err = cs_etm_validate_context_id(cs_etm_pmu, evsel, cpu); in cs_etm_validate_config()
231 err = cs_etm_validate_timestamp(cs_etm_pmu, evsel, cpu); in cs_etm_validate_config()
252 return -1; in cs_etm_parse_snapshot_options()
255 opts->auxtrace_snapshot_mode = true; in cs_etm_parse_snapshot_options()
256 opts->auxtrace_snapshot_size = snapshot_size; in cs_etm_parse_snapshot_options()
257 ptr->snapshot_size = snapshot_size; in cs_etm_parse_snapshot_options()
267 int ret = -EINVAL; in cs_etm_set_sink_attr()
270 if (evsel->core.attr.config2 & GENMASK(31, 0)) in cs_etm_set_sink_attr()
273 list_for_each_entry(term, &evsel->config_terms, list) { in cs_etm_set_sink_attr()
274 if (term->type != EVSEL__CONFIG_TERM_DRV_CFG) in cs_etm_set_sink_attr()
277 sink = term->val.str; in cs_etm_set_sink_attr()
294 evsel->core.attr.config2 |= hash; in cs_etm_set_sink_attr()
299 * No sink was provided on the command line - allow the CoreSight in cs_etm_set_sink_attr()
312 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_recording_options()
314 struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; in cs_etm_recording_options()
315 bool privileged = perf_event_paranoid_check(-1); in cs_etm_recording_options()
319 if (evsel->core.attr.type == cs_etm_pmu->type) { in cs_etm_recording_options()
323 return -EINVAL; in cs_etm_recording_options()
333 ptr->evlist = evlist; in cs_etm_recording_options()
334 ptr->snapshot_mode = opts->auxtrace_snapshot_mode; in cs_etm_recording_options()
338 opts->record_switch_events = true; in cs_etm_recording_options()
340 cs_etm_evsel->needs_auxtrace_mmap = true; in cs_etm_recording_options()
341 opts->full_auxtrace = true; in cs_etm_recording_options()
347 if (opts->use_clockid) { in cs_etm_recording_options()
348 pr_err("Cannot use clockid (-k option) with %s\n", in cs_etm_recording_options()
350 return -EINVAL; in cs_etm_recording_options()
354 if (opts->auxtrace_snapshot_mode) { in cs_etm_recording_options()
356 * No size were given to '-S' or '-m,', so go with in cs_etm_recording_options()
359 if (!opts->auxtrace_snapshot_size && in cs_etm_recording_options()
360 !opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
362 opts->auxtrace_mmap_pages = MiB(4) / page_size; in cs_etm_recording_options()
364 opts->auxtrace_mmap_pages = in cs_etm_recording_options()
366 if (opts->mmap_pages == UINT_MAX) in cs_etm_recording_options()
367 opts->mmap_pages = KiB(256) / page_size; in cs_etm_recording_options()
369 } else if (!opts->auxtrace_mmap_pages && !privileged && in cs_etm_recording_options()
370 opts->mmap_pages == UINT_MAX) { in cs_etm_recording_options()
371 opts->mmap_pages = KiB(256) / page_size; in cs_etm_recording_options()
375 * '-m,xyz' was specified but no snapshot size, so make the in cs_etm_recording_options()
378 if (!opts->auxtrace_snapshot_size) { in cs_etm_recording_options()
379 opts->auxtrace_snapshot_size = in cs_etm_recording_options()
380 opts->auxtrace_mmap_pages * (size_t)page_size; in cs_etm_recording_options()
384 * -Sxyz was specified but no auxtrace mmap area, so make the in cs_etm_recording_options()
388 if (!opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
389 size_t sz = opts->auxtrace_snapshot_size; in cs_etm_recording_options()
392 opts->auxtrace_mmap_pages = roundup_pow_of_two(sz); in cs_etm_recording_options()
396 if (opts->auxtrace_snapshot_size > in cs_etm_recording_options()
397 opts->auxtrace_mmap_pages * (size_t)page_size) { in cs_etm_recording_options()
399 opts->auxtrace_snapshot_size, in cs_etm_recording_options()
400 opts->auxtrace_mmap_pages * (size_t)page_size); in cs_etm_recording_options()
401 return -EINVAL; in cs_etm_recording_options()
404 /* Something went wrong somewhere - this shouldn't happen */ in cs_etm_recording_options()
405 if (!opts->auxtrace_snapshot_size || in cs_etm_recording_options()
406 !opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
408 return -EINVAL; in cs_etm_recording_options()
412 /* Buffer sizes weren't specified with '-m,xyz' so give some defaults */ in cs_etm_recording_options()
413 if (!opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
415 opts->auxtrace_mmap_pages = MiB(4) / page_size; in cs_etm_recording_options()
417 opts->auxtrace_mmap_pages = KiB(128) / page_size; in cs_etm_recording_options()
418 if (opts->mmap_pages == UINT_MAX) in cs_etm_recording_options()
419 opts->mmap_pages = KiB(256) / page_size; in cs_etm_recording_options()
423 if (opts->auxtrace_snapshot_mode) in cs_etm_recording_options()
425 opts->auxtrace_snapshot_size); in cs_etm_recording_options()
434 * get the CPU on the sample - need it to associate trace ID in the in cs_etm_recording_options()
435 * AUX_OUTPUT_HW_ID event, and the AUX event for per-cpu mmaps. in cs_etm_recording_options()
437 evsel__set_sample_bit(cs_etm_evsel, CPU); in cs_etm_recording_options()
440 * Also the case of per-cpu mmaps, need the contextID in order to be notified in cs_etm_recording_options()
451 * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME in cs_etm_recording_options()
455 if (opts->sample_time_set) in cs_etm_recording_options()
465 evsel->core.attr.freq = 0; in cs_etm_recording_options()
466 evsel->core.attr.sample_period = 1; in cs_etm_recording_options()
468 /* In per-cpu case, always need the time of mmap events etc */ in cs_etm_recording_options()
482 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_get_config()
483 struct evlist *evlist = ptr->evlist; in cs_etm_get_config()
487 if (evsel->core.attr.type == cs_etm_pmu->type) { in cs_etm_get_config()
493 * drivers/hwtracing/coresight/coresight-perf.c for in cs_etm_get_config()
496 config = evsel->core.attr.config; in cs_etm_get_config()
543 struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; in cs_etm_info_priv_size()
545 struct perf_cpu cpu; in cs_etm_info_priv_size() local
549 /* cpu map is not "any" CPU , we have specific CPUs to work with */ in cs_etm_info_priv_size()
555 /* Event can be "any" CPU so count all online CPUs. */ in cs_etm_info_priv_size()
558 /* Count number of each type of ETM. Don't count if that CPU has CS_NOT_PRESENT. */ in cs_etm_info_priv_size()
559 perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { in cs_etm_info_priv_size()
560 enum cs_etm_version v = cs_etm_get_version(cs_etm_pmu, cpu); in cs_etm_info_priv_size()
574 static int cs_etm_get_ro(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path, __u64 *val) in cs_etm_get_ro() argument
580 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu.cpu, path); in cs_etm_get_ro()
585 return -EINVAL; in cs_etm_get_ro()
591 static int cs_etm_get_ro_signed(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path, in cs_etm_get_ro_signed() argument
599 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu.cpu, path); in cs_etm_get_ro_signed()
604 return -EINVAL; in cs_etm_get_ro_signed()
611 static bool cs_etm_pmu_path_exists(struct perf_pmu *pmu, struct perf_cpu cpu, const char *path) in cs_etm_pmu_path_exists() argument
616 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu.cpu, path); in cs_etm_pmu_path_exists()
629 static bool cs_etm_is_ete(struct perf_pmu *cs_etm_pmu, struct perf_cpu cpu) in cs_etm_is_ete() argument
633 if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH])) in cs_etm_is_ete()
636 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH], &trcdevarch); in cs_etm_is_ete()
639 * See ETM_DEVARCH_ETE_ARCH in coresight-etm4x.h in cs_etm_is_ete()
644 static __u64 cs_etm_get_legacy_trace_id(struct perf_cpu cpu) in cs_etm_get_legacy_trace_id() argument
647 return CORESIGHT_LEGACY_CPU_TRACE_ID(cpu.cpu % 48); in cs_etm_get_legacy_trace_id()
650 static void cs_etm_save_etmv4_header(__u64 data[], struct auxtrace_record *itr, struct perf_cpu cpu) in cs_etm_save_etmv4_header() argument
653 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_save_etmv4_header()
658 data[CS_ETMV4_TRCTRACEIDR] = cs_etm_get_legacy_trace_id(cpu); in cs_etm_save_etmv4_header()
660 /* Get read-only information from sysFS */ in cs_etm_save_etmv4_header()
661 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0], in cs_etm_save_etmv4_header()
663 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR1], in cs_etm_save_etmv4_header()
665 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2], in cs_etm_save_etmv4_header()
667 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR8], in cs_etm_save_etmv4_header()
669 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TRCAUTHSTATUS], in cs_etm_save_etmv4_header()
673 if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TS_SOURCE]) || in cs_etm_save_etmv4_header()
674 cs_etm_get_ro_signed(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TS_SOURCE], in cs_etm_save_etmv4_header()
676 pr_debug3("[%03d] pmu file 'ts_source' not found. Fallback to safe value (-1)\n", in cs_etm_save_etmv4_header()
677 cpu.cpu); in cs_etm_save_etmv4_header()
678 data[CS_ETMV4_TS_SOURCE] = (__u64) -1; in cs_etm_save_etmv4_header()
682 static void cs_etm_save_ete_header(__u64 data[], struct auxtrace_record *itr, struct perf_cpu cpu) in cs_etm_save_ete_header() argument
685 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_save_ete_header()
690 data[CS_ETE_TRCTRACEIDR] = cs_etm_get_legacy_trace_id(cpu); in cs_etm_save_ete_header()
692 /* Get read-only information from sysFS */ in cs_etm_save_ete_header()
693 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR0], &data[CS_ETE_TRCIDR0]); in cs_etm_save_ete_header()
694 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR1], &data[CS_ETE_TRCIDR1]); in cs_etm_save_ete_header()
695 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR2], &data[CS_ETE_TRCIDR2]); in cs_etm_save_ete_header()
696 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCIDR8], &data[CS_ETE_TRCIDR8]); in cs_etm_save_ete_header()
697 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCAUTHSTATUS], in cs_etm_save_ete_header()
700 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH], in cs_etm_save_ete_header()
704 if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TS_SOURCE]) || in cs_etm_save_ete_header()
705 cs_etm_get_ro_signed(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TS_SOURCE], in cs_etm_save_ete_header()
707 pr_debug3("[%03d] pmu file 'ts_source' not found. Fallback to safe value (-1)\n", in cs_etm_save_ete_header()
708 cpu.cpu); in cs_etm_save_ete_header()
709 data[CS_ETE_TS_SOURCE] = (__u64) -1; in cs_etm_save_ete_header()
713 static void cs_etm_get_metadata(struct perf_cpu cpu, u32 *offset, in cs_etm_get_metadata() argument
721 /* first see what kind of tracer this cpu is affined to */ in cs_etm_get_metadata()
722 switch (cs_etm_get_version(cs_etm_pmu, cpu)) { in cs_etm_get_metadata()
725 cs_etm_save_ete_header(&info->priv[*offset], itr, cpu); in cs_etm_get_metadata()
729 nr_trc_params = CS_ETE_PRIV_MAX - CS_ETM_COMMON_BLK_MAX_V1; in cs_etm_get_metadata()
734 cs_etm_save_etmv4_header(&info->priv[*offset], itr, cpu); in cs_etm_get_metadata()
738 nr_trc_params = CS_ETMV4_PRIV_MAX - CS_ETMV4_TRCCONFIGR; in cs_etm_get_metadata()
744 info->priv[*offset + CS_ETM_ETMCR] = cs_etm_get_config(itr); in cs_etm_get_metadata()
746 info->priv[*offset + CS_ETM_ETMTRACEIDR] = cs_etm_get_legacy_trace_id(cpu); in cs_etm_get_metadata()
747 /* Get read-only information from sysFS */ in cs_etm_get_metadata()
748 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMCCER], in cs_etm_get_metadata()
749 &info->priv[*offset + CS_ETM_ETMCCER]); in cs_etm_get_metadata()
750 cs_etm_get_ro(cs_etm_pmu, cpu, metadata_etmv3_ro[CS_ETM_ETMIDR], in cs_etm_get_metadata()
751 &info->priv[*offset + CS_ETM_ETMIDR]); in cs_etm_get_metadata()
755 nr_trc_params = CS_ETM_PRIV_MAX - CS_ETM_ETMCR; in cs_etm_get_metadata()
766 info->priv[*offset + CS_ETM_MAGIC] = magic; in cs_etm_get_metadata()
767 info->priv[*offset + CS_ETM_CPU] = cpu.cpu; in cs_etm_get_metadata()
768 info->priv[*offset + CS_ETM_NR_TRC_PARAMS] = nr_trc_params; in cs_etm_get_metadata()
769 /* Where the next CPU entry should start from */ in cs_etm_get_metadata()
770 *offset += increment; in cs_etm_get_metadata()
779 u32 offset; in cs_etm_info_fill() local
782 struct perf_cpu_map *event_cpus = session->evlist->core.user_requested_cpus; in cs_etm_info_fill()
786 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_info_fill()
787 struct perf_cpu cpu; in cs_etm_info_fill() local
789 if (priv_size != cs_etm_info_priv_size(itr, session->evlist)) in cs_etm_info_fill()
790 return -EINVAL; in cs_etm_info_fill()
792 if (!session->evlist->core.nr_mmaps) in cs_etm_info_fill()
793 return -EINVAL; in cs_etm_info_fill()
795 /* If the cpu_map has the "any" CPU all online CPUs are involved */ in cs_etm_info_fill()
800 perf_cpu_map__for_each_cpu(cpu, i, event_cpus) { in cs_etm_info_fill()
801 if (!perf_cpu_map__has(online_cpus, cpu)) in cs_etm_info_fill()
802 return -EINVAL; in cs_etm_info_fill()
810 type = cs_etm_pmu->type; in cs_etm_info_fill()
813 info->type = PERF_AUXTRACE_CS_ETM; in cs_etm_info_fill()
814 info->priv[CS_HEADER_VERSION] = CS_HEADER_CURRENT_VERSION; in cs_etm_info_fill()
815 info->priv[CS_PMU_TYPE_CPUS] = type << 32; in cs_etm_info_fill()
816 info->priv[CS_PMU_TYPE_CPUS] |= nr_cpu; in cs_etm_info_fill()
817 info->priv[CS_ETM_SNAPSHOT] = ptr->snapshot_mode; in cs_etm_info_fill()
819 offset = CS_ETM_SNAPSHOT + 1; in cs_etm_info_fill()
821 perf_cpu_map__for_each_cpu(cpu, i, cpu_map) { in cs_etm_info_fill()
822 assert(offset < priv_size); in cs_etm_info_fill()
823 cs_etm_get_metadata(cpu, &offset, itr, info); in cs_etm_info_fill()
837 evlist__for_each_entry(ptr->evlist, evsel) { in cs_etm_snapshot_start()
838 if (evsel->core.attr.type == ptr->cs_etm_pmu->type) in cs_etm_snapshot_start()
841 return -EINVAL; in cs_etm_snapshot_start()
850 evlist__for_each_entry(ptr->evlist, evsel) { in cs_etm_snapshot_finish()
851 if (evsel->core.attr.type == ptr->cs_etm_pmu->type) in cs_etm_snapshot_finish()
854 return -EINVAL; in cs_etm_snapshot_finish()
879 *err = -EINVAL; in cs_etm_record_init()
885 *err = -ENOMEM; in cs_etm_record_init()
889 ptr->cs_etm_pmu = cs_etm_pmu; in cs_etm_record_init()
890 ptr->itr.parse_snapshot_options = cs_etm_parse_snapshot_options; in cs_etm_record_init()
891 ptr->itr.recording_options = cs_etm_recording_options; in cs_etm_record_init()
892 ptr->itr.info_priv_size = cs_etm_info_priv_size; in cs_etm_record_init()
893 ptr->itr.info_fill = cs_etm_info_fill; in cs_etm_record_init()
894 ptr->itr.snapshot_start = cs_etm_snapshot_start; in cs_etm_record_init()
895 ptr->itr.snapshot_finish = cs_etm_snapshot_finish; in cs_etm_record_init()
896 ptr->itr.reference = cs_etm_reference; in cs_etm_record_init()
897 ptr->itr.free = cs_etm_recording_free; in cs_etm_record_init()
898 ptr->itr.read_finish = auxtrace_record__read_finish; in cs_etm_record_init()
901 return &ptr->itr; in cs_etm_record_init()
915 attr->sample_period = 1; in cs_etm_get_default_config()