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"
69 static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu);
70 static bool cs_etm_is_ete(struct auxtrace_record *itr, int cpu);
73 struct evsel *evsel, int cpu) in cs_etm_validate_context_id() argument
77 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_validate_context_id()
81 u64 contextid = evsel->core.attr.config & in cs_etm_validate_context_id()
90 if (!cs_etm_is_etmv4(itr, cpu)) { in cs_etm_validate_context_id()
93 return -EINVAL; in cs_etm_validate_context_id()
97 snprintf(path, PATH_MAX, "cpu%d/%s", in cs_etm_validate_context_id()
98 cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2]); in cs_etm_validate_context_id()
111 * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID in cs_etm_validate_context_id()
114 * 0b00100 Maximum of 32-bit Context ID size. in cs_etm_validate_context_id()
120 return -EINVAL; in cs_etm_validate_context_id()
136 return -EINVAL; in cs_etm_validate_context_id()
144 struct evsel *evsel, int cpu) in cs_etm_validate_timestamp() argument
148 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_validate_timestamp()
153 if (!(evsel->core.attr.config & in cs_etm_validate_timestamp()
157 if (!cs_etm_is_etmv4(itr, cpu)) { in cs_etm_validate_timestamp()
160 return -EINVAL; in cs_etm_validate_timestamp()
164 snprintf(path, PATH_MAX, "cpu%d/%s", in cs_etm_validate_timestamp()
165 cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]); in cs_etm_validate_timestamp()
176 * TRCIDR0.TSSIZE, bit [28-24], indicates whether global timestamping in cs_etm_validate_timestamp()
184 return -EINVAL; in cs_etm_validate_timestamp()
200 int i, err = -EINVAL; in cs_etm_validate_config()
201 struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; in cs_etm_validate_config()
204 /* Set option of each CPU we have */ in cs_etm_validate_config()
205 for (i = 0; i < cpu__max_cpu().cpu; i++) { in cs_etm_validate_config()
206 struct perf_cpu cpu = { .cpu = i, }; in cs_etm_validate_config() local
209 * In per-cpu case, do the validation for CPUs to work with. in cs_etm_validate_config()
210 * In per-thread case, the CPU map is empty. Since the traced in cs_etm_validate_config()
215 !perf_cpu_map__has(event_cpus, cpu)) in cs_etm_validate_config()
218 if (!perf_cpu_map__has(online_cpus, cpu)) in cs_etm_validate_config()
247 return -1; in cs_etm_parse_snapshot_options()
250 opts->auxtrace_snapshot_mode = true; in cs_etm_parse_snapshot_options()
251 opts->auxtrace_snapshot_size = snapshot_size; in cs_etm_parse_snapshot_options()
252 ptr->snapshot_size = snapshot_size; in cs_etm_parse_snapshot_options()
262 int ret = -EINVAL; in cs_etm_set_sink_attr()
265 if (evsel->core.attr.config2 & GENMASK(31, 0)) in cs_etm_set_sink_attr()
268 list_for_each_entry(term, &evsel->config_terms, list) { in cs_etm_set_sink_attr()
269 if (term->type != EVSEL__CONFIG_TERM_DRV_CFG) in cs_etm_set_sink_attr()
272 sink = term->val.str; in cs_etm_set_sink_attr()
289 evsel->core.attr.config2 |= hash; in cs_etm_set_sink_attr()
294 * No sink was provided on the command line - allow the CoreSight in cs_etm_set_sink_attr()
307 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_recording_options()
309 struct perf_cpu_map *cpus = evlist->core.user_requested_cpus; in cs_etm_recording_options()
310 bool privileged = perf_event_paranoid_check(-1); in cs_etm_recording_options()
314 if (evsel->core.attr.type == cs_etm_pmu->type) { in cs_etm_recording_options()
318 return -EINVAL; in cs_etm_recording_options()
328 ptr->evlist = evlist; in cs_etm_recording_options()
329 ptr->snapshot_mode = opts->auxtrace_snapshot_mode; in cs_etm_recording_options()
333 opts->record_switch_events = true; in cs_etm_recording_options()
335 cs_etm_evsel->needs_auxtrace_mmap = true; in cs_etm_recording_options()
336 opts->full_auxtrace = true; in cs_etm_recording_options()
342 if (opts->use_clockid) { in cs_etm_recording_options()
343 pr_err("Cannot use clockid (-k option) with %s\n", in cs_etm_recording_options()
345 return -EINVAL; in cs_etm_recording_options()
349 if (opts->auxtrace_snapshot_mode) { in cs_etm_recording_options()
351 * No size were given to '-S' or '-m,', so go with in cs_etm_recording_options()
354 if (!opts->auxtrace_snapshot_size && in cs_etm_recording_options()
355 !opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
357 opts->auxtrace_mmap_pages = MiB(4) / page_size; in cs_etm_recording_options()
359 opts->auxtrace_mmap_pages = in cs_etm_recording_options()
361 if (opts->mmap_pages == UINT_MAX) in cs_etm_recording_options()
362 opts->mmap_pages = KiB(256) / page_size; in cs_etm_recording_options()
364 } else if (!opts->auxtrace_mmap_pages && !privileged && in cs_etm_recording_options()
365 opts->mmap_pages == UINT_MAX) { in cs_etm_recording_options()
366 opts->mmap_pages = KiB(256) / page_size; in cs_etm_recording_options()
370 * '-m,xyz' was specified but no snapshot size, so make the in cs_etm_recording_options()
373 if (!opts->auxtrace_snapshot_size) { in cs_etm_recording_options()
374 opts->auxtrace_snapshot_size = in cs_etm_recording_options()
375 opts->auxtrace_mmap_pages * (size_t)page_size; in cs_etm_recording_options()
379 * -Sxyz was specified but no auxtrace mmap area, so make the in cs_etm_recording_options()
383 if (!opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
384 size_t sz = opts->auxtrace_snapshot_size; in cs_etm_recording_options()
387 opts->auxtrace_mmap_pages = roundup_pow_of_two(sz); in cs_etm_recording_options()
391 if (opts->auxtrace_snapshot_size > in cs_etm_recording_options()
392 opts->auxtrace_mmap_pages * (size_t)page_size) { in cs_etm_recording_options()
394 opts->auxtrace_snapshot_size, in cs_etm_recording_options()
395 opts->auxtrace_mmap_pages * (size_t)page_size); in cs_etm_recording_options()
396 return -EINVAL; in cs_etm_recording_options()
399 /* Something went wrong somewhere - this shouldn't happen */ in cs_etm_recording_options()
400 if (!opts->auxtrace_snapshot_size || in cs_etm_recording_options()
401 !opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
403 return -EINVAL; in cs_etm_recording_options()
407 /* Buffer sizes weren't specified with '-m,xyz' so give some defaults */ in cs_etm_recording_options()
408 if (!opts->auxtrace_mmap_pages) { in cs_etm_recording_options()
410 opts->auxtrace_mmap_pages = MiB(4) / page_size; in cs_etm_recording_options()
412 opts->auxtrace_mmap_pages = KiB(128) / page_size; in cs_etm_recording_options()
413 if (opts->mmap_pages == UINT_MAX) in cs_etm_recording_options()
414 opts->mmap_pages = KiB(256) / page_size; in cs_etm_recording_options()
418 if (opts->auxtrace_snapshot_mode) in cs_etm_recording_options()
420 opts->auxtrace_snapshot_size); in cs_etm_recording_options()
429 * get the CPU on the sample - need it to associate trace ID in the in cs_etm_recording_options()
430 * AUX_OUTPUT_HW_ID event, and the AUX event for per-cpu mmaps. in cs_etm_recording_options()
432 evsel__set_sample_bit(cs_etm_evsel, CPU); in cs_etm_recording_options()
435 * Also the case of per-cpu mmaps, need the contextID in order to be notified in cs_etm_recording_options()
446 * When the option '--timestamp' or '-T' is enabled, the PERF_SAMPLE_TIME in cs_etm_recording_options()
450 if (opts->sample_time_set) in cs_etm_recording_options()
460 evsel->core.attr.freq = 0; in cs_etm_recording_options()
461 evsel->core.attr.sample_period = 1; in cs_etm_recording_options()
463 /* In per-cpu case, always need the time of mmap events etc */ in cs_etm_recording_options()
477 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_get_config()
478 struct evlist *evlist = ptr->evlist; in cs_etm_get_config()
482 if (evsel->core.attr.type == cs_etm_pmu->type) { in cs_etm_get_config()
488 * drivers/hwtracing/coresight/coresight-perf.c for in cs_etm_get_config()
491 config = evsel->core.attr.config; in cs_etm_get_config()
538 struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; in cs_etm_info_priv_size()
541 /* cpu map is not empty, we have specific CPUs to work with */ in cs_etm_info_priv_size()
543 for (i = 0; i < cpu__max_cpu().cpu; i++) { in cs_etm_info_priv_size()
544 struct perf_cpu cpu = { .cpu = i, }; in cs_etm_info_priv_size() local
546 if (!perf_cpu_map__has(event_cpus, cpu) || in cs_etm_info_priv_size()
547 !perf_cpu_map__has(online_cpus, cpu)) in cs_etm_info_priv_size()
559 for (i = 0; i < cpu__max_cpu().cpu; i++) { in cs_etm_info_priv_size()
560 struct perf_cpu cpu = { .cpu = i, }; in cs_etm_info_priv_size() local
562 if (!perf_cpu_map__has(online_cpus, cpu)) in cs_etm_info_priv_size()
582 static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu) in cs_etm_is_etmv4() argument
590 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_is_etmv4()
593 snprintf(path, PATH_MAX, "cpu%d/%s", in cs_etm_is_etmv4()
594 cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]); in cs_etm_is_etmv4()
604 static int cs_etm_get_ro(struct perf_pmu *pmu, int cpu, const char *path) in cs_etm_get_ro() argument
611 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu, path); in cs_etm_get_ro()
620 static int cs_etm_get_ro_signed(struct perf_pmu *pmu, int cpu, const char *path) in cs_etm_get_ro_signed() argument
627 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu, path); in cs_etm_get_ro_signed()
636 static bool cs_etm_pmu_path_exists(struct perf_pmu *pmu, int cpu, const char *path) in cs_etm_pmu_path_exists() argument
641 snprintf(pmu_path, PATH_MAX, "cpu%d/%s", cpu, path); in cs_etm_pmu_path_exists()
654 static bool cs_etm_is_ete(struct auxtrace_record *itr, int cpu) in cs_etm_is_ete() argument
657 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_is_ete()
660 if (!cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH])) in cs_etm_is_ete()
663 trcdevarch = cs_etm_get_ro(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TRCDEVARCH]); in cs_etm_is_ete()
666 * See ETM_DEVARCH_ETE_ARCH in coresight-etm4x.h in cs_etm_is_ete()
671 static void cs_etm_save_etmv4_header(__u64 data[], struct auxtrace_record *itr, int cpu) in cs_etm_save_etmv4_header() argument
674 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_save_etmv4_header()
680 CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) | CORESIGHT_TRACE_ID_UNUSED_FLAG; in cs_etm_save_etmv4_header()
682 /* Get read-only information from sysFS */ in cs_etm_save_etmv4_header()
683 data[CS_ETMV4_TRCIDR0] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_etmv4_header()
685 data[CS_ETMV4_TRCIDR1] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_etmv4_header()
687 data[CS_ETMV4_TRCIDR2] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_etmv4_header()
689 data[CS_ETMV4_TRCIDR8] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_etmv4_header()
691 data[CS_ETMV4_TRCAUTHSTATUS] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_etmv4_header()
695 if (cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_etmv4_ro[CS_ETMV4_TS_SOURCE])) in cs_etm_save_etmv4_header()
696 data[CS_ETMV4_TS_SOURCE] = (__u64) cs_etm_get_ro_signed(cs_etm_pmu, cpu, in cs_etm_save_etmv4_header()
699 pr_debug3("[%03d] pmu file 'ts_source' not found. Fallback to safe value (-1)\n", in cs_etm_save_etmv4_header()
700 cpu); in cs_etm_save_etmv4_header()
701 data[CS_ETMV4_TS_SOURCE] = (__u64) -1; in cs_etm_save_etmv4_header()
705 static void cs_etm_save_ete_header(__u64 data[], struct auxtrace_record *itr, int cpu) in cs_etm_save_ete_header() argument
708 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_save_ete_header()
714 CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) | CORESIGHT_TRACE_ID_UNUSED_FLAG; in cs_etm_save_ete_header()
716 /* Get read-only information from sysFS */ in cs_etm_save_ete_header()
717 data[CS_ETE_TRCIDR0] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
719 data[CS_ETE_TRCIDR1] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
721 data[CS_ETE_TRCIDR2] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
723 data[CS_ETE_TRCIDR8] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
725 data[CS_ETE_TRCAUTHSTATUS] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
728 data[CS_ETE_TRCDEVARCH] = cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
732 if (cs_etm_pmu_path_exists(cs_etm_pmu, cpu, metadata_ete_ro[CS_ETE_TS_SOURCE])) in cs_etm_save_ete_header()
733 data[CS_ETE_TS_SOURCE] = (__u64) cs_etm_get_ro_signed(cs_etm_pmu, cpu, in cs_etm_save_ete_header()
736 pr_debug3("[%03d] pmu file 'ts_source' not found. Fallback to safe value (-1)\n", in cs_etm_save_ete_header()
737 cpu); in cs_etm_save_ete_header()
738 data[CS_ETE_TS_SOURCE] = (__u64) -1; in cs_etm_save_ete_header()
742 static void cs_etm_get_metadata(int cpu, u32 *offset, in cs_etm_get_metadata() argument
750 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_get_metadata()
752 /* first see what kind of tracer this cpu is affined to */ in cs_etm_get_metadata()
753 if (cs_etm_is_ete(itr, cpu)) { in cs_etm_get_metadata()
755 cs_etm_save_ete_header(&info->priv[*offset], itr, cpu); in cs_etm_get_metadata()
759 nr_trc_params = CS_ETE_PRIV_MAX - CS_ETM_COMMON_BLK_MAX_V1; in cs_etm_get_metadata()
760 } else if (cs_etm_is_etmv4(itr, cpu)) { in cs_etm_get_metadata()
762 cs_etm_save_etmv4_header(&info->priv[*offset], itr, cpu); in cs_etm_get_metadata()
766 nr_trc_params = CS_ETMV4_PRIV_MAX - CS_ETMV4_TRCCONFIGR; in cs_etm_get_metadata()
770 info->priv[*offset + CS_ETM_ETMCR] = cs_etm_get_config(itr); in cs_etm_get_metadata()
772 info->priv[*offset + CS_ETM_ETMTRACEIDR] = in cs_etm_get_metadata()
773 CORESIGHT_LEGACY_CPU_TRACE_ID(cpu) | CORESIGHT_TRACE_ID_UNUSED_FLAG; in cs_etm_get_metadata()
774 /* Get read-only information from sysFS */ in cs_etm_get_metadata()
775 info->priv[*offset + CS_ETM_ETMCCER] = in cs_etm_get_metadata()
776 cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_get_metadata()
778 info->priv[*offset + CS_ETM_ETMIDR] = in cs_etm_get_metadata()
779 cs_etm_get_ro(cs_etm_pmu, cpu, in cs_etm_get_metadata()
784 nr_trc_params = CS_ETM_PRIV_MAX - CS_ETM_ETMCR; in cs_etm_get_metadata()
788 info->priv[*offset + CS_ETM_MAGIC] = magic; in cs_etm_get_metadata()
789 info->priv[*offset + CS_ETM_CPU] = cpu; in cs_etm_get_metadata()
790 info->priv[*offset + CS_ETM_NR_TRC_PARAMS] = nr_trc_params; in cs_etm_get_metadata()
791 /* Where the next CPU entry should start from */ in cs_etm_get_metadata()
792 *offset += increment; in cs_etm_get_metadata()
801 u32 offset; in cs_etm_info_fill() local
804 struct perf_cpu_map *event_cpus = session->evlist->core.user_requested_cpus; in cs_etm_info_fill()
808 struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; in cs_etm_info_fill()
810 if (priv_size != cs_etm_info_priv_size(itr, session->evlist)) in cs_etm_info_fill()
811 return -EINVAL; in cs_etm_info_fill()
813 if (!session->evlist->core.nr_mmaps) in cs_etm_info_fill()
814 return -EINVAL; in cs_etm_info_fill()
822 struct perf_cpu cpu = { .cpu = i, }; in cs_etm_info_fill() local
824 if (perf_cpu_map__has(event_cpus, cpu) && in cs_etm_info_fill()
825 !perf_cpu_map__has(online_cpus, cpu)) in cs_etm_info_fill()
826 return -EINVAL; in cs_etm_info_fill()
834 type = cs_etm_pmu->type; in cs_etm_info_fill()
837 info->type = PERF_AUXTRACE_CS_ETM; in cs_etm_info_fill()
838 info->priv[CS_HEADER_VERSION] = CS_HEADER_CURRENT_VERSION; in cs_etm_info_fill()
839 info->priv[CS_PMU_TYPE_CPUS] = type << 32; in cs_etm_info_fill()
840 info->priv[CS_PMU_TYPE_CPUS] |= nr_cpu; in cs_etm_info_fill()
841 info->priv[CS_ETM_SNAPSHOT] = ptr->snapshot_mode; in cs_etm_info_fill()
843 offset = CS_ETM_SNAPSHOT + 1; in cs_etm_info_fill()
845 for (i = 0; i < cpu__max_cpu().cpu && offset < priv_size; i++) { in cs_etm_info_fill()
846 struct perf_cpu cpu = { .cpu = i, }; in cs_etm_info_fill() local
848 if (perf_cpu_map__has(cpu_map, cpu)) in cs_etm_info_fill()
849 cs_etm_get_metadata(i, &offset, itr, info); in cs_etm_info_fill()
863 evlist__for_each_entry(ptr->evlist, evsel) { in cs_etm_snapshot_start()
864 if (evsel->core.attr.type == ptr->cs_etm_pmu->type) in cs_etm_snapshot_start()
867 return -EINVAL; in cs_etm_snapshot_start()
876 evlist__for_each_entry(ptr->evlist, evsel) { in cs_etm_snapshot_finish()
877 if (evsel->core.attr.type == ptr->cs_etm_pmu->type) in cs_etm_snapshot_finish()
880 return -EINVAL; in cs_etm_snapshot_finish()
905 *err = -EINVAL; in cs_etm_record_init()
911 *err = -ENOMEM; in cs_etm_record_init()
915 ptr->cs_etm_pmu = cs_etm_pmu; in cs_etm_record_init()
916 ptr->itr.pmu = cs_etm_pmu; in cs_etm_record_init()
917 ptr->itr.parse_snapshot_options = cs_etm_parse_snapshot_options; in cs_etm_record_init()
918 ptr->itr.recording_options = cs_etm_recording_options; in cs_etm_record_init()
919 ptr->itr.info_priv_size = cs_etm_info_priv_size; in cs_etm_record_init()
920 ptr->itr.info_fill = cs_etm_info_fill; in cs_etm_record_init()
921 ptr->itr.snapshot_start = cs_etm_snapshot_start; in cs_etm_record_init()
922 ptr->itr.snapshot_finish = cs_etm_snapshot_finish; in cs_etm_record_init()
923 ptr->itr.reference = cs_etm_reference; in cs_etm_record_init()
924 ptr->itr.free = cs_etm_recording_free; in cs_etm_record_init()
925 ptr->itr.read_finish = auxtrace_record__read_finish; in cs_etm_record_init()
928 return &ptr->itr; in cs_etm_record_init()
942 attr->sample_period = 1; in cs_etm_get_default_config()