Lines Matching full:spe
3 * Arm Statistical Profiling Extensions (SPE) support
33 #include "arm-spe.h"
34 #include "arm-spe-decoder/arm-spe-decoder.h"
35 #include "arm-spe-decoder/arm-spe-pkt-decoder.h"
86 struct arm_spe *spe; member
103 static void arm_spe_dump(struct arm_spe *spe __maybe_unused, in arm_spe_dump()
113 ". ... ARM SPE data: size %#zx bytes\n", in arm_spe_dump()
142 static void arm_spe_dump_event(struct arm_spe *spe, unsigned char *buf, in arm_spe_dump_event() argument
146 arm_spe_dump(spe, buf, len); in arm_spe_dump_event()
156 queue = &speq->spe->queues.queue_array[speq->queue_nr]; in arm_spe_get_trace()
172 int fd = perf_data__fd(speq->spe->session->data); in arm_spe_get_trace()
194 static struct arm_spe_queue *arm_spe__alloc_queue(struct arm_spe *spe, in arm_spe__alloc_queue() argument
208 speq->spe = spe; in arm_spe__alloc_queue()
233 static inline u8 arm_spe_cpumode(struct arm_spe *spe, u64 ip) in arm_spe_cpumode() argument
235 return ip >= spe->kernel_start ? in arm_spe_cpumode()
240 static void arm_spe_set_pid_tid_cpu(struct arm_spe *spe, in arm_spe_set_pid_tid_cpu() argument
246 tid = machine__get_current_tid(spe->machine, speq->cpu); in arm_spe_set_pid_tid_cpu()
254 speq->thread = machine__find_thread(spe->machine, -1, in arm_spe_set_pid_tid_cpu()
267 struct arm_spe *spe = speq->spe; in arm_spe_set_tid() local
268 int err = machine__set_current_tid(spe->machine, speq->cpu, -1, tid); in arm_spe_set_tid()
273 arm_spe_set_pid_tid_cpu(spe, &spe->queues.queue_array[speq->queue_nr]); in arm_spe_set_tid()
297 static void arm_spe_prep_sample(struct arm_spe *spe, in arm_spe_prep_sample() argument
304 if (!spe->timeless_decoding) in arm_spe_prep_sample()
305 sample->time = tsc_to_perf_time(record->timestamp, &spe->tc); in arm_spe_prep_sample()
308 sample->cpumode = arm_spe_cpumode(spe, sample->ip); in arm_spe_prep_sample()
327 arm_spe_deliver_synth_event(struct arm_spe *spe, in arm_spe_deliver_synth_event() argument
334 if (spe->synth_opts.inject) { in arm_spe_deliver_synth_event()
335 ret = arm_spe__inject_event(event, sample, spe->sample_type); in arm_spe_deliver_synth_event()
340 ret = perf_session__deliver_synth_event(spe->session, event, sample); in arm_spe_deliver_synth_event()
342 pr_err("ARM SPE: failed to deliver event, error %d\n", ret); in arm_spe_deliver_synth_event()
350 struct arm_spe *spe = speq->spe; in arm_spe__synth_mem_sample() local
355 arm_spe_prep_sample(spe, speq, event, &sample); in arm_spe__synth_mem_sample()
364 return arm_spe_deliver_synth_event(spe, speq, event, &sample); in arm_spe__synth_mem_sample()
370 struct arm_spe *spe = speq->spe; in arm_spe__synth_branch_sample() local
375 arm_spe_prep_sample(spe, speq, event, &sample); in arm_spe__synth_branch_sample()
382 return arm_spe_deliver_synth_event(spe, speq, event, &sample); in arm_spe__synth_branch_sample()
388 struct arm_spe *spe = speq->spe; in arm_spe__synth_instruction_sample() local
397 if (speq->period_instructions < spe->instructions_sample_period) in arm_spe__synth_instruction_sample()
401 arm_spe_prep_sample(spe, speq, event, &sample); in arm_spe__synth_instruction_sample()
408 sample.period = spe->instructions_sample_period; in arm_spe__synth_instruction_sample()
411 return arm_spe_deliver_synth_event(spe, speq, event, &sample); in arm_spe__synth_instruction_sample()
434 * Neoverse SPE records. in arm_spe__synth_data_source_neoverse()
556 struct arm_spe *spe = speq->spe; in arm_spe_sample() local
560 data_src = arm_spe__synth_data_source(record, spe->midr); in arm_spe_sample()
562 if (spe->sample_flc) { in arm_spe_sample()
564 err = arm_spe__synth_mem_sample(speq, spe->l1d_miss_id, in arm_spe_sample()
571 err = arm_spe__synth_mem_sample(speq, spe->l1d_access_id, in arm_spe_sample()
578 if (spe->sample_llc) { in arm_spe_sample()
580 err = arm_spe__synth_mem_sample(speq, spe->llc_miss_id, in arm_spe_sample()
587 err = arm_spe__synth_mem_sample(speq, spe->llc_access_id, in arm_spe_sample()
594 if (spe->sample_tlb) { in arm_spe_sample()
596 err = arm_spe__synth_mem_sample(speq, spe->tlb_miss_id, in arm_spe_sample()
603 err = arm_spe__synth_mem_sample(speq, spe->tlb_access_id, in arm_spe_sample()
610 if (spe->sample_branch && (record->type & ARM_SPE_BRANCH_MISS)) { in arm_spe_sample()
611 err = arm_spe__synth_branch_sample(speq, spe->branch_miss_id); in arm_spe_sample()
616 if (spe->sample_remote_access && in arm_spe_sample()
618 err = arm_spe__synth_mem_sample(speq, spe->remote_access_id, in arm_spe_sample()
628 if (spe->sample_memory && is_ldst_op(record->op)) { in arm_spe_sample()
629 err = arm_spe__synth_mem_sample(speq, spe->memory_id, data_src); in arm_spe_sample()
634 if (spe->sample_instructions) { in arm_spe_sample()
635 err = arm_spe__synth_instruction_sample(speq, spe->instructions_id, data_src); in arm_spe_sample()
645 struct arm_spe *spe = speq->spe; in arm_spe_run_decoder() local
649 if (!spe->kernel_start) in arm_spe_run_decoder()
650 spe->kernel_start = machine__kernel_start(spe->machine); in arm_spe_run_decoder()
669 * can correlate samples between Arm SPE trace data and other in arm_spe_run_decoder()
677 if (!spe->timeless_decoding && record->context_id != (u64)-1) { in arm_spe_run_decoder()
682 spe->use_ctx_pkt_for_pid = true; in arm_spe_run_decoder()
696 * Error is detected when decode SPE trace data, continue to in arm_spe_run_decoder()
713 if (!spe->timeless_decoding && speq->timestamp >= *timestamp) { in arm_spe_run_decoder()
722 static int arm_spe__setup_queue(struct arm_spe *spe, in arm_spe__setup_queue() argument
732 speq = arm_spe__alloc_queue(spe, queue_nr); in arm_spe__setup_queue()
745 if (spe->timeless_decoding) in arm_spe__setup_queue()
760 ret = auxtrace_heap__add(&spe->heap, queue_nr, speq->timestamp); in arm_spe__setup_queue()
769 static int arm_spe__setup_queues(struct arm_spe *spe) in arm_spe__setup_queues() argument
774 for (i = 0; i < spe->queues.nr_queues; i++) { in arm_spe__setup_queues()
775 ret = arm_spe__setup_queue(spe, &spe->queues.queue_array[i], i); in arm_spe__setup_queues()
783 static int arm_spe__update_queues(struct arm_spe *spe) in arm_spe__update_queues() argument
785 if (spe->queues.new_data) { in arm_spe__update_queues()
786 spe->queues.new_data = false; in arm_spe__update_queues()
787 return arm_spe__setup_queues(spe); in arm_spe__update_queues()
793 static bool arm_spe__is_timeless_decoding(struct arm_spe *spe) in arm_spe__is_timeless_decoding() argument
796 struct evlist *evlist = spe->session->evlist; in arm_spe__is_timeless_decoding()
811 static int arm_spe_process_queues(struct arm_spe *spe, u64 timestamp) in arm_spe_process_queues() argument
821 if (!spe->heap.heap_cnt) in arm_spe_process_queues()
824 if (spe->heap.heap_array[0].ordinal >= timestamp) in arm_spe_process_queues()
827 queue_nr = spe->heap.heap_array[0].queue_nr; in arm_spe_process_queues()
828 queue = &spe->queues.queue_array[queue_nr]; in arm_spe_process_queues()
831 auxtrace_heap__pop(&spe->heap); in arm_spe_process_queues()
833 if (spe->heap.heap_cnt) { in arm_spe_process_queues()
834 ts = spe->heap.heap_array[0].ordinal + 1; in arm_spe_process_queues()
843 * here we need to update the pid/tid in the thread and SPE queue. in arm_spe_process_queues()
845 if (!spe->use_ctx_pkt_for_pid) in arm_spe_process_queues()
846 arm_spe_set_pid_tid_cpu(spe, queue); in arm_spe_process_queues()
850 auxtrace_heap__add(&spe->heap, queue_nr, ts); in arm_spe_process_queues()
855 ret = auxtrace_heap__add(&spe->heap, queue_nr, ts); in arm_spe_process_queues()
866 static int arm_spe_process_timeless_queues(struct arm_spe *spe, pid_t tid, in arm_spe_process_timeless_queues() argument
869 struct auxtrace_queues *queues = &spe->queues; in arm_spe_process_timeless_queues()
874 struct auxtrace_queue *queue = &spe->queues.queue_array[i]; in arm_spe_process_timeless_queues()
879 arm_spe_set_pid_tid_cpu(spe, queue); in arm_spe_process_timeless_queues()
886 static int arm_spe_context_switch(struct arm_spe *spe, union perf_event *event, in arm_spe_context_switch() argument
902 return machine__set_current_tid(spe->machine, cpu, pid, tid); in arm_spe_context_switch()
912 struct arm_spe *spe = container_of(session->auxtrace, in arm_spe_process_event() local
919 pr_err("SPE trace requires ordered events\n"); in arm_spe_process_event()
924 timestamp = perf_time_to_tsc(sample->time, &spe->tc); in arm_spe_process_event()
928 if (timestamp || spe->timeless_decoding) { in arm_spe_process_event()
929 err = arm_spe__update_queues(spe); in arm_spe_process_event()
934 if (spe->timeless_decoding) { in arm_spe_process_event()
936 err = arm_spe_process_timeless_queues(spe, in arm_spe_process_event()
941 err = arm_spe_process_queues(spe, timestamp); in arm_spe_process_event()
945 if (!spe->use_ctx_pkt_for_pid && in arm_spe_process_event()
948 err = arm_spe_context_switch(spe, event, sample); in arm_spe_process_event()
958 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe, in arm_spe_process_auxtrace_event() local
961 if (!spe->data_queued) { in arm_spe_process_auxtrace_event()
975 err = auxtrace_queues__add_event(&spe->queues, session, event, in arm_spe_process_auxtrace_event()
983 arm_spe_dump_event(spe, buffer->data, in arm_spe_process_auxtrace_event()
996 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe, in arm_spe_flush() local
1006 ret = arm_spe__update_queues(spe); in arm_spe_flush()
1010 if (spe->timeless_decoding) in arm_spe_flush()
1011 return arm_spe_process_timeless_queues(spe, -1, in arm_spe_flush()
1014 ret = arm_spe_process_queues(spe, MAX_TIMESTAMP); in arm_spe_flush()
1018 if (!spe->use_ctx_pkt_for_pid) in arm_spe_flush()
1019 ui__warning("Arm SPE CONTEXT packets not found in the traces.\n" in arm_spe_flush()
1020 "Matching of TIDs to SPE events could be inaccurate.\n"); in arm_spe_flush()
1039 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe, in arm_spe_free_events() local
1041 struct auxtrace_queues *queues = &spe->queues; in arm_spe_free_events()
1053 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe, in arm_spe_free() local
1056 auxtrace_heap__free(&spe->heap); in arm_spe_free()
1059 free(spe); in arm_spe_free()
1065 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe, auxtrace); in arm_spe_evsel_is_auxtrace() local
1067 return evsel->core.attr.type == spe->pmu_type; in arm_spe_evsel_is_auxtrace()
1127 arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session) in arm_spe_synth_events() argument
1137 if (evsel->core.attr.type == spe->pmu_type) { in arm_spe_synth_events()
1144 pr_debug("No selected events with SPE trace data\n"); in arm_spe_synth_events()
1156 if (spe->timeless_decoding) in arm_spe_synth_events()
1161 spe->sample_type = attr.sample_type; in arm_spe_synth_events()
1177 if (spe->synth_opts.flc) { in arm_spe_synth_events()
1178 spe->sample_flc = true; in arm_spe_synth_events()
1184 spe->l1d_miss_id = id; in arm_spe_synth_events()
1192 spe->l1d_access_id = id; in arm_spe_synth_events()
1197 if (spe->synth_opts.llc) { in arm_spe_synth_events()
1198 spe->sample_llc = true; in arm_spe_synth_events()
1204 spe->llc_miss_id = id; in arm_spe_synth_events()
1212 spe->llc_access_id = id; in arm_spe_synth_events()
1217 if (spe->synth_opts.tlb) { in arm_spe_synth_events()
1218 spe->sample_tlb = true; in arm_spe_synth_events()
1224 spe->tlb_miss_id = id; in arm_spe_synth_events()
1232 spe->tlb_access_id = id; in arm_spe_synth_events()
1237 if (spe->synth_opts.branches) { in arm_spe_synth_events()
1238 spe->sample_branch = true; in arm_spe_synth_events()
1244 spe->branch_miss_id = id; in arm_spe_synth_events()
1249 if (spe->synth_opts.remote_access) { in arm_spe_synth_events()
1250 spe->sample_remote_access = true; in arm_spe_synth_events()
1256 spe->remote_access_id = id; in arm_spe_synth_events()
1261 if (spe->synth_opts.mem) { in arm_spe_synth_events()
1262 spe->sample_memory = true; in arm_spe_synth_events()
1267 spe->memory_id = id; in arm_spe_synth_events()
1272 if (spe->synth_opts.instructions) { in arm_spe_synth_events()
1273 if (spe->synth_opts.period_type != PERF_ITRACE_PERIOD_INSTRUCTIONS) { in arm_spe_synth_events()
1274 pr_warning("Only instruction-based sampling period is currently supported by Arm SPE.\n"); in arm_spe_synth_events()
1277 if (spe->synth_opts.period > 1) in arm_spe_synth_events()
1278 pr_warning("Arm SPE has a hardware-based sample period.\n" in arm_spe_synth_events()
1281 spe->sample_instructions = true; in arm_spe_synth_events()
1283 attr.sample_period = spe->synth_opts.period; in arm_spe_synth_events()
1284 spe->instructions_sample_period = attr.sample_period; in arm_spe_synth_events()
1288 spe->instructions_id = id; in arm_spe_synth_events()
1304 struct arm_spe *spe; in arm_spe_process_auxtrace_info() local
1311 spe = zalloc(sizeof(struct arm_spe)); in arm_spe_process_auxtrace_info()
1312 if (!spe) in arm_spe_process_auxtrace_info()
1315 err = auxtrace_queues__init(&spe->queues); in arm_spe_process_auxtrace_info()
1319 spe->session = session; in arm_spe_process_auxtrace_info()
1320 spe->machine = &session->machines.host; /* No kvm support */ in arm_spe_process_auxtrace_info()
1321 spe->auxtrace_type = auxtrace_info->type; in arm_spe_process_auxtrace_info()
1322 spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE]; in arm_spe_process_auxtrace_info()
1323 spe->midr = midr; in arm_spe_process_auxtrace_info()
1325 spe->timeless_decoding = arm_spe__is_timeless_decoding(spe); in arm_spe_process_auxtrace_info()
1331 * in "spe->tc", which is used for later conversion between clock in arm_spe_process_auxtrace_info()
1337 spe->tc.time_shift = tc->time_shift; in arm_spe_process_auxtrace_info()
1338 spe->tc.time_mult = tc->time_mult; in arm_spe_process_auxtrace_info()
1339 spe->tc.time_zero = tc->time_zero; in arm_spe_process_auxtrace_info()
1342 spe->tc.time_cycles = tc->time_cycles; in arm_spe_process_auxtrace_info()
1343 spe->tc.time_mask = tc->time_mask; in arm_spe_process_auxtrace_info()
1344 spe->tc.cap_user_time_zero = tc->cap_user_time_zero; in arm_spe_process_auxtrace_info()
1345 spe->tc.cap_user_time_short = tc->cap_user_time_short; in arm_spe_process_auxtrace_info()
1348 spe->auxtrace.process_event = arm_spe_process_event; in arm_spe_process_auxtrace_info()
1349 spe->auxtrace.process_auxtrace_event = arm_spe_process_auxtrace_event; in arm_spe_process_auxtrace_info()
1350 spe->auxtrace.flush_events = arm_spe_flush; in arm_spe_process_auxtrace_info()
1351 spe->auxtrace.free_events = arm_spe_free_events; in arm_spe_process_auxtrace_info()
1352 spe->auxtrace.free = arm_spe_free; in arm_spe_process_auxtrace_info()
1353 spe->auxtrace.evsel_is_auxtrace = arm_spe_evsel_is_auxtrace; in arm_spe_process_auxtrace_info()
1354 session->auxtrace = &spe->auxtrace; in arm_spe_process_auxtrace_info()
1362 spe->synth_opts = *session->itrace_synth_opts; in arm_spe_process_auxtrace_info()
1364 itrace_synth_opts__set_default(&spe->synth_opts, false); in arm_spe_process_auxtrace_info()
1366 err = arm_spe_synth_events(spe, session); in arm_spe_process_auxtrace_info()
1370 err = auxtrace_queues__process_index(&spe->queues, session); in arm_spe_process_auxtrace_info()
1374 if (spe->queues.populated) in arm_spe_process_auxtrace_info()
1375 spe->data_queued = true; in arm_spe_process_auxtrace_info()
1380 auxtrace_queues__free(&spe->queues); in arm_spe_process_auxtrace_info()
1383 free(spe); in arm_spe_process_auxtrace_info()