Lines Matching +full:coresight +full:- +full:dummy +full:- +full:source
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(C) 2015-2018 Linaro Limited.
12 #include <linux/coresight-pmu.h>
22 #include "cs-etm.h"
23 #include "cs-etm-decoder/cs-etm-decoder.h"
37 #include "thread-stack.h"
40 #include "util/synthetic-events.h"
61 * Per-thread ignores the trace channel ID and instead assumes that
151 #define SINK_UNSET ((u32) -1)
168 inode = intlist__find(etmq->traceid_list, trace_chan_id); in cs_etm__get_magic()
170 return -EINVAL; in cs_etm__get_magic()
172 metadata = inode->priv; in cs_etm__get_magic()
182 inode = intlist__find(etmq->traceid_list, trace_chan_id); in cs_etm__get_cpu()
184 return -EINVAL; in cs_etm__get_cpu()
186 metadata = inode->priv; in cs_etm__get_cpu()
204 * The result is cached in etm->pid_fmt so this function only needs to be called
231 return etmq->etm->pid_fmt; in cs_etm__get_pid_fmt()
238 struct int_node *inode = intlist__findnew(etmq->traceid_list, trace_chan_id); in cs_etm__insert_trace_id_node()
242 return -ENOMEM; in cs_etm__insert_trace_id_node()
244 /* Disallow re-mapping a different traceID to metadata pair. */ in cs_etm__insert_trace_id_node()
245 if (inode->priv) { in cs_etm__insert_trace_id_node()
246 u64 *curr_cpu_data = inode->priv; in cs_etm__insert_trace_id_node()
253 * are expected (but not supported) in per-thread mode, in cs_etm__insert_trace_id_node()
256 if (etmq->etm->per_thread_decoding) in cs_etm__insert_trace_id_node()
257 pr_err("CS_ETM: overlapping Trace IDs aren't currently supported in per-thread mode\n"); in cs_etm__insert_trace_id_node()
261 return -EINVAL; in cs_etm__insert_trace_id_node()
271 return -EINVAL; in cs_etm__insert_trace_id_node()
274 /* Skip re-adding the same mappings if everything matched */ in cs_etm__insert_trace_id_node()
279 inode->priv = cpu_metadata; in cs_etm__insert_trace_id_node()
286 if (etm->per_thread_decoding) in cs_etm__get_queue()
287 return etm->queues.queue_array[0].priv; in cs_etm__get_queue()
289 return etm->queues.queue_array[cpu].priv; in cs_etm__get_queue()
302 if (etmq->format == UNFORMATTED) in cs_etm__map_trace_id_v0()
310 for (unsigned int i = 0; i < etm->queues.nr_queues; ++i) { in cs_etm__map_trace_id_v0()
313 etmq = etm->queues.queue_array[i].priv; in cs_etm__map_trace_id_v0()
332 return -EINVAL; in cs_etm__process_trace_id_v0()
355 * Check sink id hasn't changed in per-cpu mode. In per-thread mode, in cs_etm__process_trace_id_v0_1()
359 if (!etmq->etm->per_thread_decoding && etmq->sink_id != SINK_UNSET && in cs_etm__process_trace_id_v0_1()
360 etmq->sink_id != sink_id) { in cs_etm__process_trace_id_v0_1()
362 return -EINVAL; in cs_etm__process_trace_id_v0_1()
365 etmq->sink_id = sink_id; in cs_etm__process_trace_id_v0_1()
368 for (unsigned int i = 0; i < etm->queues.nr_queues; ++i) { in cs_etm__process_trace_id_v0_1()
369 struct cs_etm_queue *other_etmq = etm->queues.queue_array[i].priv; in cs_etm__process_trace_id_v0_1()
372 if (other_etmq->sink_id != etmq->sink_id) in cs_etm__process_trace_id_v0_1()
376 if (other_etmq->traceid_list == etmq->traceid_list) in cs_etm__process_trace_id_v0_1()
380 if (!intlist__empty(etmq->traceid_list)) { in cs_etm__process_trace_id_v0_1()
382 return -EINVAL; in cs_etm__process_trace_id_v0_1()
385 etmq->own_traceid_list = NULL; in cs_etm__process_trace_id_v0_1()
386 intlist__delete(etmq->traceid_list); in cs_etm__process_trace_id_v0_1()
387 etmq->traceid_list = other_etmq->traceid_list; in cs_etm__process_trace_id_v0_1()
418 return -EINVAL; in cs_etm__metadata_get_trace_id()
440 return -EINVAL; in cs_etm__metadata_set_trace_id()
453 for (i = 0; i < etm->num_cpu; i++) { in get_cpu_data_idx()
454 if (etm->metadata[i][CS_ETM_CPU] == (u64)cpu) { in get_cpu_data_idx()
459 return -1; in get_cpu_data_idx()
470 return (idx != -1) ? etm->metadata[idx] : NULL; in get_cpu_data()
490 hw_id = event->aux_output_hw_id.hw_id; in cs_etm__process_aux_output_hw_id()
497 return -EINVAL; in cs_etm__process_aux_output_hw_id()
501 etm = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace); in cs_etm__process_aux_output_hw_id()
502 if (!etm || !etm->metadata) in cs_etm__process_aux_output_hw_id()
503 return -EINVAL; in cs_etm__process_aux_output_hw_id()
506 evsel = evlist__event2evsel(session->evlist, event); in cs_etm__process_aux_output_hw_id()
508 return -EINVAL; in cs_etm__process_aux_output_hw_id()
513 if (cpu == -1) { in cs_etm__process_aux_output_hw_id()
514 /* no CPU in the sample - possibly recorded with an old version of perf */ in cs_etm__process_aux_output_hw_id()
516 return -EINVAL; in cs_etm__process_aux_output_hw_id()
535 etmq->pending_timestamp_chan_id = trace_chan_id; in cs_etm__etmq_set_traceid_queue_timestamp()
543 if (!etmq->pending_timestamp_chan_id) in cs_etm__etmq_get_timestamp()
547 *trace_chan_id = etmq->pending_timestamp_chan_id; in cs_etm__etmq_get_timestamp()
550 etmq->pending_timestamp_chan_id); in cs_etm__etmq_get_timestamp()
555 etmq->pending_timestamp_chan_id = 0; in cs_etm__etmq_get_timestamp()
558 return packet_queue->cs_timestamp; in cs_etm__etmq_get_timestamp()
565 queue->head = 0; in cs_etm__clear_packet_queue()
566 queue->tail = 0; in cs_etm__clear_packet_queue()
567 queue->packet_count = 0; in cs_etm__clear_packet_queue()
569 queue->packet_buffer[i].isa = CS_ETM_ISA_UNKNOWN; in cs_etm__clear_packet_queue()
570 queue->packet_buffer[i].start_addr = CS_ETM_INVAL_ADDR; in cs_etm__clear_packet_queue()
571 queue->packet_buffer[i].end_addr = CS_ETM_INVAL_ADDR; in cs_etm__clear_packet_queue()
572 queue->packet_buffer[i].instr_count = 0; in cs_etm__clear_packet_queue()
573 queue->packet_buffer[i].last_instr_taken_branch = false; in cs_etm__clear_packet_queue()
574 queue->packet_buffer[i].last_instr_size = 0; in cs_etm__clear_packet_queue()
575 queue->packet_buffer[i].last_instr_type = 0; in cs_etm__clear_packet_queue()
576 queue->packet_buffer[i].last_instr_subtype = 0; in cs_etm__clear_packet_queue()
577 queue->packet_buffer[i].last_instr_cond = 0; in cs_etm__clear_packet_queue()
578 queue->packet_buffer[i].flags = 0; in cs_etm__clear_packet_queue()
579 queue->packet_buffer[i].exception_number = UINT32_MAX; in cs_etm__clear_packet_queue()
580 queue->packet_buffer[i].trace_chan_id = UINT8_MAX; in cs_etm__clear_packet_queue()
581 queue->packet_buffer[i].cpu = INT_MIN; in cs_etm__clear_packet_queue()
590 struct intlist *traceid_queues_list = etmq->traceid_queues_list; in cs_etm__clear_all_packet_queues()
593 idx = (int)(intptr_t)inode->priv; in cs_etm__clear_all_packet_queues()
594 tidq = etmq->traceid_queues[idx]; in cs_etm__clear_all_packet_queues()
595 cs_etm__clear_packet_queue(&tidq->packet_queue); in cs_etm__clear_all_packet_queues()
603 int rc = -ENOMEM; in cs_etm__init_traceid_queue()
605 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__init_traceid_queue()
607 cs_etm__clear_packet_queue(&tidq->packet_queue); in cs_etm__init_traceid_queue()
609 queue = &etmq->etm->queues.queue_array[etmq->queue_nr]; in cs_etm__init_traceid_queue()
610 tidq->trace_chan_id = trace_chan_id; in cs_etm__init_traceid_queue()
611 tidq->el = tidq->prev_packet_el = ocsd_EL_unknown; in cs_etm__init_traceid_queue()
612 tidq->thread = machine__findnew_thread(&etm->session->machines.host, -1, in cs_etm__init_traceid_queue()
613 queue->tid); in cs_etm__init_traceid_queue()
614 tidq->prev_packet_thread = machine__idle_thread(&etm->session->machines.host); in cs_etm__init_traceid_queue()
616 tidq->packet = zalloc(sizeof(struct cs_etm_packet)); in cs_etm__init_traceid_queue()
617 if (!tidq->packet) in cs_etm__init_traceid_queue()
620 tidq->prev_packet = zalloc(sizeof(struct cs_etm_packet)); in cs_etm__init_traceid_queue()
621 if (!tidq->prev_packet) in cs_etm__init_traceid_queue()
624 if (etm->synth_opts.last_branch) { in cs_etm__init_traceid_queue()
627 sz += etm->synth_opts.last_branch_sz * in cs_etm__init_traceid_queue()
629 tidq->last_branch = zalloc(sz); in cs_etm__init_traceid_queue()
630 if (!tidq->last_branch) in cs_etm__init_traceid_queue()
632 tidq->last_branch_rb = zalloc(sz); in cs_etm__init_traceid_queue()
633 if (!tidq->last_branch_rb) in cs_etm__init_traceid_queue()
637 tidq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); in cs_etm__init_traceid_queue()
638 if (!tidq->event_buf) in cs_etm__init_traceid_queue()
644 zfree(&tidq->last_branch_rb); in cs_etm__init_traceid_queue()
645 zfree(&tidq->last_branch); in cs_etm__init_traceid_queue()
646 zfree(&tidq->prev_packet); in cs_etm__init_traceid_queue()
647 zfree(&tidq->packet); in cs_etm__init_traceid_queue()
659 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__etmq_get_traceid_queue()
661 if (etm->per_thread_decoding) in cs_etm__etmq_get_traceid_queue()
664 traceid_queues_list = etmq->traceid_queues_list; in cs_etm__etmq_get_traceid_queue()
672 idx = (int)(intptr_t)inode->priv; in cs_etm__etmq_get_traceid_queue()
673 return etmq->traceid_queues[idx]; in cs_etm__etmq_get_traceid_queue()
691 inode->priv = (void *)(intptr_t)idx; in cs_etm__etmq_get_traceid_queue()
697 traceid_queues = etmq->traceid_queues; in cs_etm__etmq_get_traceid_queue()
710 etmq->traceid_queues = traceid_queues; in cs_etm__etmq_get_traceid_queue()
712 return etmq->traceid_queues[idx]; in cs_etm__etmq_get_traceid_queue()
732 return &tidq->packet_queue; in cs_etm__etmq_get_packet_queue()
742 if (etm->synth_opts.branches || etm->synth_opts.last_branch || in cs_etm__packet_swap()
743 etm->synth_opts.instructions) { in cs_etm__packet_swap()
756 tmp = tidq->packet; in cs_etm__packet_swap()
757 tidq->packet = tidq->prev_packet; in cs_etm__packet_swap()
758 tidq->prev_packet = tmp; in cs_etm__packet_swap()
759 tidq->prev_packet_el = tidq->el; in cs_etm__packet_swap()
760 thread__put(tidq->prev_packet_thread); in cs_etm__packet_swap()
761 tidq->prev_packet_thread = thread__get(tidq->thread); in cs_etm__packet_swap()
773 snprintf(queue_nr, sizeof(queue_nr), "Qnr:%d; ", etmq->queue_nr); in cs_etm__packet_dump()
777 if (len && (pkt_string[len-1] == '\n')) in cs_etm__packet_dump()
788 t_params->protocol = cs_etm__get_v7_protocol_version(etmidr); in cs_etm__set_trace_param_etmv3()
789 t_params->etmv3.reg_ctrl = metadata[CS_ETM_ETMCR]; in cs_etm__set_trace_param_etmv3()
790 t_params->etmv3.reg_trc_id = metadata[CS_ETM_ETMTRACEIDR]; in cs_etm__set_trace_param_etmv3()
796 t_params->protocol = CS_ETM_PROTO_ETMV4i; in cs_etm__set_trace_param_etmv4()
797 t_params->etmv4.reg_idr0 = metadata[CS_ETMV4_TRCIDR0]; in cs_etm__set_trace_param_etmv4()
798 t_params->etmv4.reg_idr1 = metadata[CS_ETMV4_TRCIDR1]; in cs_etm__set_trace_param_etmv4()
799 t_params->etmv4.reg_idr2 = metadata[CS_ETMV4_TRCIDR2]; in cs_etm__set_trace_param_etmv4()
800 t_params->etmv4.reg_idr8 = metadata[CS_ETMV4_TRCIDR8]; in cs_etm__set_trace_param_etmv4()
801 t_params->etmv4.reg_configr = metadata[CS_ETMV4_TRCCONFIGR]; in cs_etm__set_trace_param_etmv4()
802 t_params->etmv4.reg_traceidr = metadata[CS_ETMV4_TRCTRACEIDR]; in cs_etm__set_trace_param_etmv4()
808 t_params->protocol = CS_ETM_PROTO_ETE; in cs_etm__set_trace_param_ete()
809 t_params->ete.reg_idr0 = metadata[CS_ETE_TRCIDR0]; in cs_etm__set_trace_param_ete()
810 t_params->ete.reg_idr1 = metadata[CS_ETE_TRCIDR1]; in cs_etm__set_trace_param_ete()
811 t_params->ete.reg_idr2 = metadata[CS_ETE_TRCIDR2]; in cs_etm__set_trace_param_ete()
812 t_params->ete.reg_idr8 = metadata[CS_ETE_TRCIDR8]; in cs_etm__set_trace_param_ete()
813 t_params->ete.reg_configr = metadata[CS_ETE_TRCCONFIGR]; in cs_etm__set_trace_param_ete()
814 t_params->ete.reg_traceidr = metadata[CS_ETE_TRCTRACEIDR]; in cs_etm__set_trace_param_ete()
815 t_params->ete.reg_devarch = metadata[CS_ETE_TRCDEVARCH]; in cs_etm__set_trace_param_ete()
823 intlist__for_each_entry(inode, etmq->traceid_list) { in cs_etm__init_trace_params()
824 u64 *metadata = inode->priv; in cs_etm__init_trace_params()
840 return -EINVAL; in cs_etm__init_trace_params()
851 int ret = -EINVAL; in cs_etm__init_decoder_params()
856 d_params->packet_printer = cs_etm__packet_dump; in cs_etm__init_decoder_params()
857 d_params->operation = mode; in cs_etm__init_decoder_params()
858 d_params->data = etmq; in cs_etm__init_decoder_params()
859 d_params->formatted = etmq->format == FORMATTED; in cs_etm__init_decoder_params()
860 d_params->fsyncs = false; in cs_etm__init_decoder_params()
861 d_params->hsyncs = false; in cs_etm__init_decoder_params()
862 d_params->frame_aligned = true; in cs_etm__init_decoder_params()
878 ". ... CoreSight %s Trace data: size %#zx bytes\n", in cs_etm__dump_event()
879 cs_etm_decoder__get_name(etmq->decoder), buffer->size); in cs_etm__dump_event()
885 etmq->decoder, buffer->offset, in cs_etm__dump_event()
886 &((u8 *)buffer->data)[buffer_used], in cs_etm__dump_event()
887 buffer->size - buffer_used, &consumed); in cs_etm__dump_event()
892 } while (buffer_used < buffer->size); in cs_etm__dump_event()
894 cs_etm_decoder__reset(etmq->decoder); in cs_etm__dump_event()
900 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__flush_events()
906 if (!tool->ordered_events) in cs_etm__flush_events()
907 return -EINVAL; in cs_etm__flush_events()
909 if (etm->timeless_decoding) { in cs_etm__flush_events()
911 * Pass tid = -1 to process all queues. But likely they will have in cs_etm__flush_events()
914 return cs_etm__process_timeless_queues(etm, -1); in cs_etm__flush_events()
926 struct intlist *traceid_queues_list = etmq->traceid_queues_list; in cs_etm__free_traceid_queues()
929 priv = (uintptr_t)inode->priv; in cs_etm__free_traceid_queues()
933 tidq = etmq->traceid_queues[idx]; in cs_etm__free_traceid_queues()
934 thread__zput(tidq->thread); in cs_etm__free_traceid_queues()
935 thread__zput(tidq->prev_packet_thread); in cs_etm__free_traceid_queues()
936 zfree(&tidq->event_buf); in cs_etm__free_traceid_queues()
937 zfree(&tidq->last_branch); in cs_etm__free_traceid_queues()
938 zfree(&tidq->last_branch_rb); in cs_etm__free_traceid_queues()
939 zfree(&tidq->prev_packet); in cs_etm__free_traceid_queues()
940 zfree(&tidq->packet); in cs_etm__free_traceid_queues()
952 etmq->traceid_queues_list = NULL; in cs_etm__free_traceid_queues()
955 zfree(&etmq->traceid_queues); in cs_etm__free_traceid_queues()
966 cs_etm_decoder__free(etmq->decoder); in cs_etm__free_queue()
969 if (etmq->own_traceid_list) { in cs_etm__free_queue()
971 intlist__for_each_entry_safe(inode, tmp, etmq->own_traceid_list) in cs_etm__free_queue()
972 intlist__remove(etmq->own_traceid_list, inode); in cs_etm__free_queue()
975 intlist__delete(etmq->own_traceid_list); in cs_etm__free_queue()
984 struct cs_etm_auxtrace *aux = container_of(session->auxtrace, in cs_etm__free_events()
987 struct auxtrace_queues *queues = &aux->queues; in cs_etm__free_events()
989 for (i = 0; i < queues->nr_queues; i++) { in cs_etm__free_events()
990 cs_etm__free_queue(queues->queue_array[i].priv); in cs_etm__free_events()
991 queues->queue_array[i].priv = NULL; in cs_etm__free_events()
1000 struct cs_etm_auxtrace *aux = container_of(session->auxtrace, in cs_etm__free()
1004 session->auxtrace = NULL; in cs_etm__free()
1006 for (i = 0; i < aux->num_cpu; i++) in cs_etm__free()
1007 zfree(&aux->metadata[i]); in cs_etm__free()
1009 zfree(&aux->metadata); in cs_etm__free()
1016 struct cs_etm_auxtrace *aux = container_of(session->auxtrace, in cs_etm__evsel_is_auxtrace()
1020 return evsel->core.attr.type == aux->pmu_type; in cs_etm__evsel_is_auxtrace()
1033 return &etmq->etm->session->machines.host; in cs_etm__get_machine()
1045 return machines__find_guest(&etmq->etm->session->machines, in cs_etm__get_machine()
1052 return &etmq->etm->session->machines.host; in cs_etm__get_machine()
1111 assert(tidq->el == ocsd_EL1 || tidq->el == ocsd_EL0); in cs_etm__mem_access()
1113 assert(tidq->el == ocsd_EL2); in cs_etm__mem_access()
1115 assert(tidq->el == ocsd_EL3); in cs_etm__mem_access()
1118 cpumode = cs_etm__cpu_mode(etmq, address, tidq->el); in cs_etm__mem_access()
1120 if (!thread__find_map(tidq->thread, cpumode, address, &al)) in cs_etm__mem_access()
1127 if (dso__data(dso)->status == DSO_DATA_STATUS_ERROR && in cs_etm__mem_access()
1135 len = dso__data_read_offset(dso, maps__machine(thread__maps(tidq->thread)), in cs_etm__mem_access()
1140 …" Enable CONFIG_PROC_KCORE or use option '-k /path/to/vmlinux' for kernel symbols.\n"… in cs_etm__mem_access()
1161 etmq->traceid_queues_list = intlist__new(NULL); in cs_etm__alloc_queue()
1162 if (!etmq->traceid_queues_list) in cs_etm__alloc_queue()
1166 * Create an RB tree for traceID-metadata tuple. Since the conversion in cs_etm__alloc_queue()
1170 etmq->traceid_list = etmq->own_traceid_list = intlist__new(NULL); in cs_etm__alloc_queue()
1171 if (!etmq->traceid_list) in cs_etm__alloc_queue()
1177 intlist__delete(etmq->traceid_queues_list); in cs_etm__alloc_queue()
1187 struct cs_etm_queue *etmq = queue->priv; in cs_etm__setup_queue()
1195 return -ENOMEM; in cs_etm__setup_queue()
1197 queue->priv = etmq; in cs_etm__setup_queue()
1198 etmq->etm = etm; in cs_etm__setup_queue()
1199 etmq->queue_nr = queue_nr; in cs_etm__setup_queue()
1200 queue->cpu = queue_nr; /* Placeholder, may be reset to -1 in per-thread mode */ in cs_etm__setup_queue()
1201 etmq->offset = 0; in cs_etm__setup_queue()
1202 etmq->sink_id = SINK_UNSET; in cs_etm__setup_queue()
1217 * We are under a CPU-wide trace scenario. As such we need to know in cs_etm__queue_first_cs_timestamp()
1273 ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); in cs_etm__queue_first_cs_timestamp()
1282 struct branch_stack *bs_src = tidq->last_branch_rb; in cs_etm__copy_last_branch_rb()
1283 struct branch_stack *bs_dst = tidq->last_branch; in cs_etm__copy_last_branch_rb()
1287 * Set the number of records before early exit: ->nr is used to in cs_etm__copy_last_branch_rb()
1288 * determine how many branches to copy from ->entries. in cs_etm__copy_last_branch_rb()
1290 bs_dst->nr = bs_src->nr; in cs_etm__copy_last_branch_rb()
1295 if (!bs_src->nr) in cs_etm__copy_last_branch_rb()
1299 * As bs_src->entries is a circular buffer, we need to copy from it in in cs_etm__copy_last_branch_rb()
1301 * branch ->last_branch_pos until the end of bs_src->entries buffer. in cs_etm__copy_last_branch_rb()
1303 nr = etmq->etm->synth_opts.last_branch_sz - tidq->last_branch_pos; in cs_etm__copy_last_branch_rb()
1304 memcpy(&bs_dst->entries[0], in cs_etm__copy_last_branch_rb()
1305 &bs_src->entries[tidq->last_branch_pos], in cs_etm__copy_last_branch_rb()
1310 * of the bs_src->entries buffer and until the ->last_branch_pos element in cs_etm__copy_last_branch_rb()
1315 if (bs_src->nr >= etmq->etm->synth_opts.last_branch_sz) { in cs_etm__copy_last_branch_rb()
1316 memcpy(&bs_dst->entries[nr], in cs_etm__copy_last_branch_rb()
1317 &bs_src->entries[0], in cs_etm__copy_last_branch_rb()
1318 sizeof(struct branch_entry) * tidq->last_branch_pos); in cs_etm__copy_last_branch_rb()
1325 tidq->last_branch_pos = 0; in cs_etm__reset_last_branch_rb()
1326 tidq->last_branch_rb->nr = 0; in cs_etm__reset_last_branch_rb()
1338 * 16-bit word of the instruction: 0b11101, 0b11110 and 0b11111 in cs_etm__t32_instr_size()
1339 * denote a 32-bit instruction. in cs_etm__t32_instr_size()
1350 if (packet->sample_type == CS_ETM_DISCONTINUITY || in cs_etm__first_executed_instr()
1351 packet->sample_type == CS_ETM_EXCEPTION) in cs_etm__first_executed_instr()
1354 return packet->start_addr; in cs_etm__first_executed_instr()
1361 if (packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__last_executed_instr()
1364 return packet->end_addr - packet->last_instr_size; in cs_etm__last_executed_instr()
1372 if (packet->isa == CS_ETM_ISA_T32) { in cs_etm__instr_addr()
1373 u64 addr = packet->start_addr; in cs_etm__instr_addr()
1378 offset--; in cs_etm__instr_addr()
1384 return packet->start_addr + offset * 4; in cs_etm__instr_addr()
1390 struct branch_stack *bs = tidq->last_branch_rb; in cs_etm__update_last_branch_rb()
1399 if (!tidq->last_branch_pos) in cs_etm__update_last_branch_rb()
1400 tidq->last_branch_pos = etmq->etm->synth_opts.last_branch_sz; in cs_etm__update_last_branch_rb()
1402 tidq->last_branch_pos -= 1; in cs_etm__update_last_branch_rb()
1404 be = &bs->entries[tidq->last_branch_pos]; in cs_etm__update_last_branch_rb()
1405 be->from = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__update_last_branch_rb()
1406 be->to = cs_etm__first_executed_instr(tidq->packet); in cs_etm__update_last_branch_rb()
1408 be->flags.mispred = 0; in cs_etm__update_last_branch_rb()
1409 be->flags.predicted = 1; in cs_etm__update_last_branch_rb()
1412 * Increment bs->nr until reaching the number of last branches asked by in cs_etm__update_last_branch_rb()
1415 if (bs->nr < etmq->etm->synth_opts.last_branch_sz) in cs_etm__update_last_branch_rb()
1416 bs->nr += 1; in cs_etm__update_last_branch_rb()
1422 event->header.size = perf_event__sample_event_size(sample, type, 0); in cs_etm__inject_event()
1430 struct auxtrace_buffer *aux_buffer = etmq->buffer; in cs_etm__get_trace()
1434 queue = &etmq->etm->queues.queue_array[etmq->queue_nr]; in cs_etm__get_trace()
1442 etmq->buf_len = 0; in cs_etm__get_trace()
1446 etmq->buffer = aux_buffer; in cs_etm__get_trace()
1449 if (!aux_buffer->data) { in cs_etm__get_trace()
1451 int fd = perf_data__fd(etmq->etm->session->data); in cs_etm__get_trace()
1453 aux_buffer->data = auxtrace_buffer__get_data(aux_buffer, fd); in cs_etm__get_trace()
1454 if (!aux_buffer->data) in cs_etm__get_trace()
1455 return -ENOMEM; in cs_etm__get_trace()
1462 etmq->buf_used = 0; in cs_etm__get_trace()
1463 etmq->buf_len = aux_buffer->size; in cs_etm__get_trace()
1464 etmq->buf = aux_buffer->data; in cs_etm__get_trace()
1466 return etmq->buf_len; in cs_etm__get_trace()
1475 if (tid != -1) { in cs_etm__set_thread()
1476 thread__zput(tidq->thread); in cs_etm__set_thread()
1477 tidq->thread = machine__find_thread(machine, -1, tid); in cs_etm__set_thread()
1481 if (!tidq->thread) in cs_etm__set_thread()
1482 tidq->thread = machine__idle_thread(machine); in cs_etm__set_thread()
1484 tidq->el = el; in cs_etm__set_thread()
1494 return -EINVAL; in cs_etm__etmq_set_tid_el()
1502 return !!etmq->etm->timeless_decoding; in cs_etm__etmq_is_timeless()
1514 if (packet->sample_type == CS_ETM_DISCONTINUITY) { in cs_etm__copy_insn()
1515 sample->insn_len = 0; in cs_etm__copy_insn()
1520 * T32 instruction size might be 32-bit or 16-bit, decide by calling in cs_etm__copy_insn()
1523 if (packet->isa == CS_ETM_ISA_T32) in cs_etm__copy_insn()
1524 sample->insn_len = cs_etm__t32_instr_size(etmq, trace_chan_id, in cs_etm__copy_insn()
1525 sample->ip); in cs_etm__copy_insn()
1526 /* Otherwise, A64 and A32 instruction size are always 32-bit. */ in cs_etm__copy_insn()
1528 sample->insn_len = 4; in cs_etm__copy_insn()
1530 cs_etm__mem_access(etmq, trace_chan_id, sample->ip, sample->insn_len, in cs_etm__copy_insn()
1531 (void *)sample->insn, 0); in cs_etm__copy_insn()
1536 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__convert_sample_time()
1538 if (etm->has_virtual_ts) in cs_etm__convert_sample_time()
1539 return tsc_to_perf_time(cs_timestamp, &etm->tc); in cs_etm__convert_sample_time()
1547 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__resolve_sample_time()
1548 struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue; in cs_etm__resolve_sample_time()
1550 if (!etm->timeless_decoding && etm->has_virtual_ts) in cs_etm__resolve_sample_time()
1551 return packet_queue->cs_timestamp; in cs_etm__resolve_sample_time()
1553 return etm->latest_kernel_timestamp; in cs_etm__resolve_sample_time()
1561 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__synth_instruction_sample()
1562 union perf_event *event = tidq->event_buf; in cs_etm__synth_instruction_sample()
1565 event->sample.header.type = PERF_RECORD_SAMPLE; in cs_etm__synth_instruction_sample()
1566 event->sample.header.misc = cs_etm__cpu_mode(etmq, addr, tidq->el); in cs_etm__synth_instruction_sample()
1567 event->sample.header.size = sizeof(struct perf_event_header); in cs_etm__synth_instruction_sample()
1573 sample.pid = thread__pid(tidq->thread); in cs_etm__synth_instruction_sample()
1574 sample.tid = thread__tid(tidq->thread); in cs_etm__synth_instruction_sample()
1575 sample.id = etmq->etm->instructions_id; in cs_etm__synth_instruction_sample()
1576 sample.stream_id = etmq->etm->instructions_id; in cs_etm__synth_instruction_sample()
1578 sample.cpu = tidq->packet->cpu; in cs_etm__synth_instruction_sample()
1579 sample.flags = tidq->prev_packet->flags; in cs_etm__synth_instruction_sample()
1580 sample.cpumode = event->sample.header.misc; in cs_etm__synth_instruction_sample()
1582 cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample); in cs_etm__synth_instruction_sample()
1584 if (etm->synth_opts.last_branch) in cs_etm__synth_instruction_sample()
1585 sample.branch_stack = tidq->last_branch; in cs_etm__synth_instruction_sample()
1587 if (etm->synth_opts.inject) { in cs_etm__synth_instruction_sample()
1589 etm->instructions_sample_type); in cs_etm__synth_instruction_sample()
1594 ret = perf_session__deliver_synth_event(etm->session, event, &sample); in cs_etm__synth_instruction_sample()
1612 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__synth_branch_sample()
1614 union perf_event *event = tidq->event_buf; in cs_etm__synth_branch_sample()
1622 ip = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__synth_branch_sample()
1624 event->sample.header.type = PERF_RECORD_SAMPLE; in cs_etm__synth_branch_sample()
1625 event->sample.header.misc = cs_etm__cpu_mode(etmq, ip, in cs_etm__synth_branch_sample()
1626 tidq->prev_packet_el); in cs_etm__synth_branch_sample()
1627 event->sample.header.size = sizeof(struct perf_event_header); in cs_etm__synth_branch_sample()
1633 sample.pid = thread__pid(tidq->prev_packet_thread); in cs_etm__synth_branch_sample()
1634 sample.tid = thread__tid(tidq->prev_packet_thread); in cs_etm__synth_branch_sample()
1635 sample.addr = cs_etm__first_executed_instr(tidq->packet); in cs_etm__synth_branch_sample()
1636 sample.id = etmq->etm->branches_id; in cs_etm__synth_branch_sample()
1637 sample.stream_id = etmq->etm->branches_id; in cs_etm__synth_branch_sample()
1639 sample.cpu = tidq->packet->cpu; in cs_etm__synth_branch_sample()
1640 sample.flags = tidq->prev_packet->flags; in cs_etm__synth_branch_sample()
1641 sample.cpumode = event->sample.header.misc; in cs_etm__synth_branch_sample()
1643 cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->prev_packet, in cs_etm__synth_branch_sample()
1649 if (etm->synth_opts.last_branch) { in cs_etm__synth_branch_sample()
1652 .hw_idx = -1ULL, in cs_etm__synth_branch_sample()
1661 if (etm->synth_opts.inject) { in cs_etm__synth_branch_sample()
1663 etm->branches_sample_type); in cs_etm__synth_branch_sample()
1668 ret = perf_session__deliver_synth_event(etm->session, event, &sample); in cs_etm__synth_branch_sample()
1681 struct evlist *evlist = session->evlist; in cs_etm__synth_events()
1689 if (evsel->core.attr.type == etm->pmu_type) { in cs_etm__synth_events()
1696 pr_debug("No selected events with CoreSight Trace data\n"); in cs_etm__synth_events()
1703 attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK; in cs_etm__synth_events()
1706 if (etm->timeless_decoding) in cs_etm__synth_events()
1711 attr.exclude_user = evsel->core.attr.exclude_user; in cs_etm__synth_events()
1712 attr.exclude_kernel = evsel->core.attr.exclude_kernel; in cs_etm__synth_events()
1713 attr.exclude_hv = evsel->core.attr.exclude_hv; in cs_etm__synth_events()
1714 attr.exclude_host = evsel->core.attr.exclude_host; in cs_etm__synth_events()
1715 attr.exclude_guest = evsel->core.attr.exclude_guest; in cs_etm__synth_events()
1716 attr.sample_id_all = evsel->core.attr.sample_id_all; in cs_etm__synth_events()
1717 attr.read_format = evsel->core.attr.read_format; in cs_etm__synth_events()
1720 id = evsel->core.id[0] + 1000000000; in cs_etm__synth_events()
1725 if (etm->synth_opts.branches) { in cs_etm__synth_events()
1732 etm->branches_sample_type = attr.sample_type; in cs_etm__synth_events()
1733 etm->branches_id = id; in cs_etm__synth_events()
1738 if (etm->synth_opts.last_branch) { in cs_etm__synth_events()
1748 if (etm->synth_opts.instructions) { in cs_etm__synth_events()
1750 attr.sample_period = etm->synth_opts.period; in cs_etm__synth_events()
1751 etm->instructions_sample_period = attr.sample_period; in cs_etm__synth_events()
1755 etm->instructions_sample_type = attr.sample_type; in cs_etm__synth_events()
1756 etm->instructions_id = id; in cs_etm__synth_events()
1766 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__sample()
1768 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__sample()
1772 instrs_prev = tidq->period_instructions; in cs_etm__sample()
1774 tidq->period_instructions += tidq->packet->instr_count; in cs_etm__sample()
1780 if (etm->synth_opts.last_branch && in cs_etm__sample()
1781 tidq->prev_packet->sample_type == CS_ETM_RANGE && in cs_etm__sample()
1782 tidq->prev_packet->last_instr_taken_branch) in cs_etm__sample()
1785 if (etm->synth_opts.instructions && in cs_etm__sample()
1786 tidq->period_instructions >= etm->instructions_sample_period) { in cs_etm__sample()
1800 * -------------------------------------------------- in cs_etm__sample()
1807 * \---------------- -----------------/ in cs_etm__sample()
1809 * tidq->packet->instr_count in cs_etm__sample()
1812 * every etm->instructions_sample_period instructions - as in cs_etm__sample()
1817 * tidq->packet->instr_count represents the number of in cs_etm__sample()
1823 * etm->instructions_sample_period. in cs_etm__sample()
1831 * to tidq->period_instructions for next round calculation. in cs_etm__sample()
1837 * etm->instructions_sample_period. in cs_etm__sample()
1839 u64 offset = etm->instructions_sample_period - instrs_prev; in cs_etm__sample()
1843 if (etm->synth_opts.last_branch) in cs_etm__sample()
1846 while (tidq->period_instructions >= in cs_etm__sample()
1847 etm->instructions_sample_period) { in cs_etm__sample()
1849 * Calculate the address of the sampled instruction (-1 in cs_etm__sample()
1855 tidq->packet, offset - 1); in cs_etm__sample()
1858 etm->instructions_sample_period); in cs_etm__sample()
1862 offset += etm->instructions_sample_period; in cs_etm__sample()
1863 tidq->period_instructions -= in cs_etm__sample()
1864 etm->instructions_sample_period; in cs_etm__sample()
1868 if (etm->synth_opts.branches) { in cs_etm__sample()
1872 if (tidq->prev_packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__sample()
1876 if (tidq->prev_packet->sample_type == CS_ETM_RANGE && in cs_etm__sample()
1877 tidq->prev_packet->last_instr_taken_branch) in cs_etm__sample()
1897 * to set 'prev_packet->last_instr_taken_branch' to true. This ensures in cs_etm__exception()
1901 * The exception packet includes the dummy address values, so don't in cs_etm__exception()
1905 if (tidq->prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__exception()
1906 tidq->prev_packet->last_instr_taken_branch = true; in cs_etm__exception()
1915 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__flush()
1918 if (tidq->prev_packet->sample_type == CS_ETM_EMPTY) in cs_etm__flush()
1921 if (etmq->etm->synth_opts.last_branch && in cs_etm__flush()
1922 etmq->etm->synth_opts.instructions && in cs_etm__flush()
1923 tidq->prev_packet->sample_type == CS_ETM_RANGE) { in cs_etm__flush()
1936 addr = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__flush()
1940 tidq->period_instructions); in cs_etm__flush()
1944 tidq->period_instructions = 0; in cs_etm__flush()
1948 if (etm->synth_opts.branches && in cs_etm__flush()
1949 tidq->prev_packet->sample_type == CS_ETM_RANGE) { in cs_etm__flush()
1959 if (etm->synth_opts.last_branch) in cs_etm__flush()
1971 * It has no new packet coming and 'etmq->packet' contains the stale in cs_etm__end_block()
1979 if (etmq->etm->synth_opts.last_branch && in cs_etm__end_block()
1980 etmq->etm->synth_opts.instructions && in cs_etm__end_block()
1981 tidq->prev_packet->sample_type == CS_ETM_RANGE) { in cs_etm__end_block()
1991 addr = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__end_block()
1995 tidq->period_instructions); in cs_etm__end_block()
1999 tidq->period_instructions = 0; in cs_etm__end_block()
2015 if (!etmq->buf_len) { in cs_etm__get_data_block()
2021 * are contiguous, reset the decoder to force re-sync. in cs_etm__get_data_block()
2023 ret = cs_etm_decoder__reset(etmq->decoder); in cs_etm__get_data_block()
2028 return etmq->buf_len; in cs_etm__get_data_block()
2040 switch (packet->isa) { in cs_etm__is_svc_instr()
2046 * +-----------------+--------+ in cs_etm__is_svc_instr()
2048 * +-----------------+--------+ in cs_etm__is_svc_instr()
2054 addr = end_addr - 2; in cs_etm__is_svc_instr()
2066 * +---------+---------+-------------------------+ in cs_etm__is_svc_instr()
2068 * +---------+---------+-------------------------+ in cs_etm__is_svc_instr()
2070 addr = end_addr - 4; in cs_etm__is_svc_instr()
2083 * +-----------------------+---------+-----------+ in cs_etm__is_svc_instr()
2085 * +-----------------------+---------+-----------+ in cs_etm__is_svc_instr()
2087 addr = end_addr - 4; in cs_etm__is_svc_instr()
2105 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__is_syscall()
2106 struct cs_etm_packet *packet = tidq->packet; in cs_etm__is_syscall()
2107 struct cs_etm_packet *prev_packet = tidq->prev_packet; in cs_etm__is_syscall()
2110 if (packet->exception_number == CS_ETMV3_EXC_SVC) in cs_etm__is_syscall()
2119 if (packet->exception_number == CS_ETMV4_EXC_CALL && in cs_etm__is_syscall()
2121 prev_packet->end_addr)) in cs_etm__is_syscall()
2131 struct cs_etm_packet *packet = tidq->packet; in cs_etm__is_async_exception()
2134 if (packet->exception_number == CS_ETMV3_EXC_DEBUG_HALT || in cs_etm__is_async_exception()
2135 packet->exception_number == CS_ETMV3_EXC_ASYNC_DATA_ABORT || in cs_etm__is_async_exception()
2136 packet->exception_number == CS_ETMV3_EXC_PE_RESET || in cs_etm__is_async_exception()
2137 packet->exception_number == CS_ETMV3_EXC_IRQ || in cs_etm__is_async_exception()
2138 packet->exception_number == CS_ETMV3_EXC_FIQ) in cs_etm__is_async_exception()
2142 if (packet->exception_number == CS_ETMV4_EXC_RESET || in cs_etm__is_async_exception()
2143 packet->exception_number == CS_ETMV4_EXC_DEBUG_HALT || in cs_etm__is_async_exception()
2144 packet->exception_number == CS_ETMV4_EXC_SYSTEM_ERROR || in cs_etm__is_async_exception()
2145 packet->exception_number == CS_ETMV4_EXC_INST_DEBUG || in cs_etm__is_async_exception()
2146 packet->exception_number == CS_ETMV4_EXC_DATA_DEBUG || in cs_etm__is_async_exception()
2147 packet->exception_number == CS_ETMV4_EXC_IRQ || in cs_etm__is_async_exception()
2148 packet->exception_number == CS_ETMV4_EXC_FIQ) in cs_etm__is_async_exception()
2158 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__is_sync_exception()
2159 struct cs_etm_packet *packet = tidq->packet; in cs_etm__is_sync_exception()
2160 struct cs_etm_packet *prev_packet = tidq->prev_packet; in cs_etm__is_sync_exception()
2163 if (packet->exception_number == CS_ETMV3_EXC_SMC || in cs_etm__is_sync_exception()
2164 packet->exception_number == CS_ETMV3_EXC_HYP || in cs_etm__is_sync_exception()
2165 packet->exception_number == CS_ETMV3_EXC_JAZELLE_THUMBEE || in cs_etm__is_sync_exception()
2166 packet->exception_number == CS_ETMV3_EXC_UNDEFINED_INSTR || in cs_etm__is_sync_exception()
2167 packet->exception_number == CS_ETMV3_EXC_PREFETCH_ABORT || in cs_etm__is_sync_exception()
2168 packet->exception_number == CS_ETMV3_EXC_DATA_FAULT || in cs_etm__is_sync_exception()
2169 packet->exception_number == CS_ETMV3_EXC_GENERIC) in cs_etm__is_sync_exception()
2173 if (packet->exception_number == CS_ETMV4_EXC_TRAP || in cs_etm__is_sync_exception()
2174 packet->exception_number == CS_ETMV4_EXC_ALIGNMENT || in cs_etm__is_sync_exception()
2175 packet->exception_number == CS_ETMV4_EXC_INST_FAULT || in cs_etm__is_sync_exception()
2176 packet->exception_number == CS_ETMV4_EXC_DATA_FAULT) in cs_etm__is_sync_exception()
2183 if (packet->exception_number == CS_ETMV4_EXC_CALL && in cs_etm__is_sync_exception()
2185 prev_packet->end_addr)) in cs_etm__is_sync_exception()
2195 if (packet->exception_number > CS_ETMV4_EXC_FIQ && in cs_etm__is_sync_exception()
2196 packet->exception_number <= CS_ETMV4_EXC_END) in cs_etm__is_sync_exception()
2206 struct cs_etm_packet *packet = tidq->packet; in cs_etm__set_sample_flags()
2207 struct cs_etm_packet *prev_packet = tidq->prev_packet; in cs_etm__set_sample_flags()
2208 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__set_sample_flags()
2212 switch (packet->sample_type) { in cs_etm__set_sample_flags()
2219 if (packet->last_instr_type == OCSD_INSTR_BR && in cs_etm__set_sample_flags()
2220 packet->last_instr_subtype == OCSD_S_INSTR_NONE) { in cs_etm__set_sample_flags()
2221 packet->flags = PERF_IP_FLAG_BRANCH; in cs_etm__set_sample_flags()
2223 if (packet->last_instr_cond) in cs_etm__set_sample_flags()
2224 packet->flags |= PERF_IP_FLAG_CONDITIONAL; in cs_etm__set_sample_flags()
2231 if (packet->last_instr_type == OCSD_INSTR_BR && in cs_etm__set_sample_flags()
2232 packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK) in cs_etm__set_sample_flags()
2233 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2240 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2241 packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK) in cs_etm__set_sample_flags()
2242 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2250 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2251 packet->last_instr_subtype == OCSD_S_INSTR_V7_IMPLIED_RET) in cs_etm__set_sample_flags()
2252 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2260 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2261 packet->last_instr_subtype == OCSD_S_INSTR_NONE) in cs_etm__set_sample_flags()
2262 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2266 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2267 packet->last_instr_subtype == OCSD_S_INSTR_V8_RET) in cs_etm__set_sample_flags()
2268 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2276 if (prev_packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__set_sample_flags()
2277 prev_packet->flags |= PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2286 if (prev_packet->flags == (PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2290 packet, packet->start_addr)) in cs_etm__set_sample_flags()
2291 prev_packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2301 if (prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__set_sample_flags()
2302 prev_packet->flags |= PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2306 ret = cs_etm__get_magic(etmq, packet->trace_chan_id, &magic); in cs_etm__set_sample_flags()
2312 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2320 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2329 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2340 if (prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__set_sample_flags()
2341 prev_packet->flags = packet->flags; in cs_etm__set_sample_flags()
2369 if (prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__set_sample_flags()
2370 prev_packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2394 ret = cs_etm_decoder__process_data_block(etmq->decoder, in cs_etm__decode_data_block()
2395 etmq->offset, in cs_etm__decode_data_block()
2396 &etmq->buf[etmq->buf_used], in cs_etm__decode_data_block()
2397 etmq->buf_len, in cs_etm__decode_data_block()
2402 etmq->offset += processed; in cs_etm__decode_data_block()
2403 etmq->buf_used += processed; in cs_etm__decode_data_block()
2404 etmq->buf_len -= processed; in cs_etm__decode_data_block()
2416 packet_queue = &tidq->packet_queue; in cs_etm__process_traceid_queue()
2421 tidq->packet); in cs_etm__process_traceid_queue()
2440 switch (tidq->packet->sample_type) { in cs_etm__process_traceid_queue()
2471 return -EINVAL; in cs_etm__process_traceid_queue()
2485 struct intlist *traceid_queues_list = etmq->traceid_queues_list; in cs_etm__clear_all_traceid_queues()
2488 idx = (int)(intptr_t)inode->priv; in cs_etm__clear_all_traceid_queues()
2489 tidq = etmq->traceid_queues[idx]; in cs_etm__clear_all_traceid_queues()
2503 return -EINVAL; in cs_etm__run_per_thread_timeless_decoder()
2524 } while (etmq->buf_len); in cs_etm__run_per_thread_timeless_decoder()
2555 * buffer. But here in per-cpu mode we need to iterate in cs_etm__run_per_cpu_timeless_decoder()
2559 etmq->traceid_queues_list) { in cs_etm__run_per_cpu_timeless_decoder()
2560 idx = (int)(intptr_t)inode->priv; in cs_etm__run_per_cpu_timeless_decoder()
2561 tidq = etmq->traceid_queues[idx]; in cs_etm__run_per_cpu_timeless_decoder()
2564 } while (etmq->buf_len); in cs_etm__run_per_cpu_timeless_decoder()
2566 intlist__for_each_entry(inode, etmq->traceid_queues_list) { in cs_etm__run_per_cpu_timeless_decoder()
2567 idx = (int)(intptr_t)inode->priv; in cs_etm__run_per_cpu_timeless_decoder()
2568 tidq = etmq->traceid_queues[idx]; in cs_etm__run_per_cpu_timeless_decoder()
2583 struct auxtrace_queues *queues = &etm->queues; in cs_etm__process_timeless_queues()
2585 for (i = 0; i < queues->nr_queues; i++) { in cs_etm__process_timeless_queues()
2586 struct auxtrace_queue *queue = &etm->queues.queue_array[i]; in cs_etm__process_timeless_queues()
2587 struct cs_etm_queue *etmq = queue->priv; in cs_etm__process_timeless_queues()
2593 if (etm->per_thread_decoding) { in cs_etm__process_timeless_queues()
2600 if (tid == -1 || thread__tid(tidq->thread) == tid) in cs_etm__process_timeless_queues()
2620 * Pre-populate the heap with one entry from each queue so that we can in cs_etm__process_timestamped_queues()
2623 for (i = 0; i < etm->queues.nr_queues; i++) { in cs_etm__process_timestamped_queues()
2624 etmq = etm->queues.queue_array[i].priv; in cs_etm__process_timestamped_queues()
2634 if (!etm->heap.heap_cnt) in cs_etm__process_timestamped_queues()
2638 cs_queue_nr = etm->heap.heap_array[0].queue_nr; in cs_etm__process_timestamped_queues()
2641 queue = &etm->queues.queue_array[queue_nr]; in cs_etm__process_timestamped_queues()
2642 etmq = queue->priv; in cs_etm__process_timestamped_queues()
2648 auxtrace_heap__pop(&etm->heap); in cs_etm__process_timestamped_queues()
2657 ret = -EINVAL; in cs_etm__process_timestamped_queues()
2715 ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); in cs_etm__process_timestamped_queues()
2718 for (i = 0; i < etm->queues.nr_queues; i++) { in cs_etm__process_timestamped_queues()
2721 etmq = etm->queues.queue_array[i].priv; in cs_etm__process_timestamped_queues()
2725 intlist__for_each_entry(inode, etmq->traceid_queues_list) { in cs_etm__process_timestamped_queues()
2726 int idx = (int)(intptr_t)inode->priv; in cs_etm__process_timestamped_queues()
2729 tidq = etmq->traceid_queues[idx]; in cs_etm__process_timestamped_queues()
2744 if (etm->timeless_decoding) in cs_etm__process_itrace_start()
2753 th = machine__findnew_thread(&etm->session->machines.host, in cs_etm__process_itrace_start()
2754 event->itrace_start.pid, in cs_etm__process_itrace_start()
2755 event->itrace_start.tid); in cs_etm__process_itrace_start()
2757 return -ENOMEM; in cs_etm__process_itrace_start()
2768 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; in cs_etm__process_switch_cpu_wide()
2771 * Context switch in per-thread mode are irrelevant since perf in cs_etm__process_switch_cpu_wide()
2774 if (etm->timeless_decoding) in cs_etm__process_switch_cpu_wide()
2791 th = machine__findnew_thread(&etm->session->machines.host, in cs_etm__process_switch_cpu_wide()
2792 event->context_switch.next_prev_pid, in cs_etm__process_switch_cpu_wide()
2793 event->context_switch.next_prev_tid); in cs_etm__process_switch_cpu_wide()
2795 return -ENOMEM; in cs_etm__process_switch_cpu_wide()
2807 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__process_event()
2814 if (!tool->ordered_events) { in cs_etm__process_event()
2815 pr_err("CoreSight ETM Trace requires ordered events\n"); in cs_etm__process_event()
2816 return -EINVAL; in cs_etm__process_event()
2819 switch (event->header.type) { in cs_etm__process_event()
2822 * Don't need to wait for cs_etm__flush_events() in per-thread mode to in cs_etm__process_event()
2829 if (etm->per_thread_decoding && etm->timeless_decoding) in cs_etm__process_event()
2831 event->fork.tid); in cs_etm__process_event()
2846 if (sample->time && (sample->time != (u64)-1)) in cs_etm__process_event()
2847 etm->latest_kernel_timestamp = sample->time; in cs_etm__process_event()
2867 for (i = 0; i < etm->queues.nr_queues; ++i) in dump_queued_data()
2868 list_for_each_entry(buf, &etm->queues.queue_array[i].head, list) in dump_queued_data()
2869 if (buf->reference == event->reference) in dump_queued_data()
2870 cs_etm__dump_event(etm->queues.queue_array[i].priv, buf); in dump_queued_data()
2877 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__process_auxtrace_event()
2880 if (!etm->data_queued) { in cs_etm__process_auxtrace_event()
2883 int fd = perf_data__fd(session->data); in cs_etm__process_auxtrace_event()
2884 bool is_pipe = perf_data__is_pipe(session->data); in cs_etm__process_auxtrace_event()
2886 int idx = event->auxtrace.idx; in cs_etm__process_auxtrace_event()
2892 if (data_offset == -1) in cs_etm__process_auxtrace_event()
2893 return -errno; in cs_etm__process_auxtrace_event()
2896 err = auxtrace_queues__add_event(&etm->queues, session, in cs_etm__process_auxtrace_event()
2903 cs_etm__dump_event(etm->queues.queue_array[idx].priv, buffer); in cs_etm__process_auxtrace_event()
2907 dump_queued_data(etm, &event->auxtrace); in cs_etm__process_auxtrace_event()
2915 struct evlist *evlist = etm->session->evlist; in cs_etm__setup_timeless_decoding()
2917 /* Override timeless mode with user input from --itrace=Z */ in cs_etm__setup_timeless_decoding()
2918 if (etm->synth_opts.timeless_decoding) { in cs_etm__setup_timeless_decoding()
2919 etm->timeless_decoding = true; in cs_etm__setup_timeless_decoding()
2927 if (cs_etm__evsel_is_auxtrace(etm->session, evsel)) { in cs_etm__setup_timeless_decoding()
2928 etm->timeless_decoding = in cs_etm__setup_timeless_decoding()
2929 !(evsel->core.attr.config & BIT(ETM_OPT_TS)); in cs_etm__setup_timeless_decoding()
2934 return -EINVAL; in cs_etm__setup_timeless_decoding()
2969 /* remaining block params at offset +1 from source */ in cs_etm__create_meta_blk()
2970 for (k = CS_ETM_COMMON_BLK_MAX_V1 - 1; k < nr_in_params; k++) in cs_etm__create_meta_blk()
2975 /* read version 1 info block - input and output nr_params may differ */ in cs_etm__create_meta_blk()
2980 /* if input has more params than output - skip excess */ in cs_etm__create_meta_blk()
2989 metadata[CS_ETM_NR_TRC_PARAMS] = nr_out_params - nr_cmn_params; in cs_etm__create_meta_blk()
3019 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__queue_aux_fragment()
3031 auxtrace_event = &auxtrace_event_union->auxtrace; in cs_etm__queue_aux_fragment()
3032 if (auxtrace_event->header.type != PERF_RECORD_AUXTRACE) in cs_etm__queue_aux_fragment()
3033 return -EINVAL; in cs_etm__queue_aux_fragment()
3035 if (auxtrace_event->header.size < sizeof(struct perf_record_auxtrace) || in cs_etm__queue_aux_fragment()
3036 auxtrace_event->header.size != sz) { in cs_etm__queue_aux_fragment()
3037 return -EINVAL; in cs_etm__queue_aux_fragment()
3041 * In per-thread mode, auxtrace CPU is set to -1, but TID will be set instead. See in cs_etm__queue_aux_fragment()
3044 * So now compare only TIDs if auxtrace CPU is -1, and CPUs if auxtrace CPU is not -1. in cs_etm__queue_aux_fragment()
3047 if (auxtrace_event->cpu == (__u32) -1) { in cs_etm__queue_aux_fragment()
3048 etm->per_thread_decoding = true; in cs_etm__queue_aux_fragment()
3049 if (auxtrace_event->tid != sample->tid) in cs_etm__queue_aux_fragment()
3051 } else if (auxtrace_event->cpu != sample->cpu) { in cs_etm__queue_aux_fragment()
3052 if (etm->per_thread_decoding) { in cs_etm__queue_aux_fragment()
3054 * Found a per-cpu buffer after a per-thread one was in cs_etm__queue_aux_fragment()
3057 pr_err("CS ETM: Inconsistent per-thread/per-cpu mode.\n"); in cs_etm__queue_aux_fragment()
3058 return -EINVAL; in cs_etm__queue_aux_fragment()
3063 if (aux_event->flags & PERF_AUX_FLAG_OVERWRITE) { in cs_etm__queue_aux_fragment()
3069 aux_size = min(aux_event->aux_size, auxtrace_event->size); in cs_etm__queue_aux_fragment()
3075 aux_offset = aux_event->aux_offset - aux_size; in cs_etm__queue_aux_fragment()
3077 aux_size = aux_event->aux_size; in cs_etm__queue_aux_fragment()
3078 aux_offset = aux_event->aux_offset; in cs_etm__queue_aux_fragment()
3081 if (aux_offset >= auxtrace_event->offset && in cs_etm__queue_aux_fragment()
3082 aux_offset + aux_size <= auxtrace_event->offset + auxtrace_event->size) { in cs_etm__queue_aux_fragment()
3083 struct cs_etm_queue *etmq = etm->queues.queue_array[auxtrace_event->idx].priv; in cs_etm__queue_aux_fragment()
3092 file_offset += aux_offset - auxtrace_event->offset + auxtrace_event->header.size; in cs_etm__queue_aux_fragment()
3095 " tid: %d cpu: %d\n", aux_size, aux_offset, sample->tid, sample->cpu); in cs_etm__queue_aux_fragment()
3096 err = auxtrace_queues__add_event(&etm->queues, session, &auxtrace_fragment, in cs_etm__queue_aux_fragment()
3101 format = (aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW) ? in cs_etm__queue_aux_fragment()
3103 if (etmq->format != UNSET && format != etmq->format) { in cs_etm__queue_aux_fragment()
3105 return -EINVAL; in cs_etm__queue_aux_fragment()
3107 etmq->format = format; in cs_etm__queue_aux_fragment()
3119 if (event->header.type == PERF_RECORD_AUX_OUTPUT_HW_ID) { in cs_etm__process_aux_hw_id_cb()
3137 if (event->header.type != PERF_RECORD_AUX) in cs_etm__queue_aux_records_cb()
3140 if (event->header.size < sizeof(struct perf_record_aux)) in cs_etm__queue_aux_records_cb()
3141 return -EINVAL; in cs_etm__queue_aux_records_cb()
3144 if (!event->aux.aux_size) in cs_etm__queue_aux_records_cb()
3151 evsel = evlist__event2evsel(session->evlist, event); in cs_etm__queue_aux_records_cb()
3153 return -EINVAL; in cs_etm__queue_aux_records_cb()
3161 list_for_each_entry(auxtrace_index, &session->auxtrace_index, list) { in cs_etm__queue_aux_records_cb()
3162 for (i = 0; i < auxtrace_index->nr; i++) { in cs_etm__queue_aux_records_cb()
3163 ent = &auxtrace_index->entries[i]; in cs_etm__queue_aux_records_cb()
3164 ret = cs_etm__queue_aux_fragment(session, ent->file_offset, in cs_etm__queue_aux_records_cb()
3165 ent->sz, &event->aux, &sample); in cs_etm__queue_aux_records_cb()
3180 " tid: %d cpu: %d\n", event->aux.aux_offset, sample.tid, sample.cpu); in cs_etm__queue_aux_records_cb()
3186 struct auxtrace_index *index = list_first_entry_or_null(&session->auxtrace_index, in cs_etm__queue_aux_records()
3188 if (index && index->nr > 0) in cs_etm__queue_aux_records()
3189 return perf_session__peek_events(session, session->header.data_offset, in cs_etm__queue_aux_records()
3190 session->header.data_size, in cs_etm__queue_aux_records()
3196 * queueing them in cs_etm__process_auxtrace_event() if etm->data_queued is still in cs_etm__queue_aux_records()
3205 (CS_##type##_##param - CS_ETM_COMMON_BLK_MAX_V1))
3255 return -EINVAL; in cs_etm__map_trace_ids_metadata()
3272 int decoders = intlist__nr_entries(etmq->traceid_list); in cs_etm__create_queue_decoders()
3281 if (etmq->format == UNFORMATTED) in cs_etm__create_queue_decoders()
3299 etmq->decoder = cs_etm_decoder__new(decoders, &d_params, in cs_etm__create_queue_decoders()
3302 if (!etmq->decoder) in cs_etm__create_queue_decoders()
3309 if (cs_etm_decoder__add_mem_access_cb(etmq->decoder, in cs_etm__create_queue_decoders()
3310 0x0L, ((u64) -1L), in cs_etm__create_queue_decoders()
3318 cs_etm_decoder__free(etmq->decoder); in cs_etm__create_queue_decoders()
3321 return -EINVAL; in cs_etm__create_queue_decoders()
3326 struct auxtrace_queues *queues = &etm->queues; in cs_etm__create_decoders()
3328 for (unsigned int i = 0; i < queues->nr_queues; i++) { in cs_etm__create_decoders()
3329 bool empty = list_empty(&queues->queue_array[i].head); in cs_etm__create_decoders()
3330 struct cs_etm_queue *etmq = queues->queue_array[i].priv; in cs_etm__create_decoders()
3335 * etmq->format is unknown for empty queues. in cs_etm__create_decoders()
3337 assert(empty || etmq->format != UNSET); in cs_etm__create_decoders()
3351 struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; in cs_etm__process_auxtrace_info_full()
3353 struct perf_record_time_conv *tc = &session->time_conv; in cs_etm__process_auxtrace_info_full()
3355 int total_size = auxtrace_info->header.size; in cs_etm__process_auxtrace_info_full()
3365 ptr = (u64 *) auxtrace_info->priv; in cs_etm__process_auxtrace_info_full()
3369 return -ENOMEM; in cs_etm__process_auxtrace_info_full()
3392 metadata[j] = cs_etm__create_meta_blk(ptr, &i, CS_ETE_PRIV_MAX, -1); in cs_etm__process_auxtrace_info_full()
3396 err = -EINVAL; in cs_etm__process_auxtrace_info_full()
3401 err = -ENOMEM; in cs_etm__process_auxtrace_info_full()
3416 priv_size = total_size - event_header_size - INFO_HEADER_SIZE; in cs_etm__process_auxtrace_info_full()
3418 err = -EINVAL; in cs_etm__process_auxtrace_info_full()
3425 err = -ENOMEM; in cs_etm__process_auxtrace_info_full()
3434 etm->pid_fmt = cs_etm__init_pid_fmt(metadata[0]); in cs_etm__process_auxtrace_info_full()
3436 err = auxtrace_queues__init_nr(&etm->queues, max_cpu + 1); in cs_etm__process_auxtrace_info_full()
3440 for (unsigned int j = 0; j < etm->queues.nr_queues; ++j) { in cs_etm__process_auxtrace_info_full()
3441 err = cs_etm__setup_queue(etm, &etm->queues.queue_array[j], j); in cs_etm__process_auxtrace_info_full()
3446 if (session->itrace_synth_opts->set) { in cs_etm__process_auxtrace_info_full()
3447 etm->synth_opts = *session->itrace_synth_opts; in cs_etm__process_auxtrace_info_full()
3449 itrace_synth_opts__set_default(&etm->synth_opts, in cs_etm__process_auxtrace_info_full()
3450 session->itrace_synth_opts->default_no_sample); in cs_etm__process_auxtrace_info_full()
3451 etm->synth_opts.callchain = false; in cs_etm__process_auxtrace_info_full()
3454 etm->session = session; in cs_etm__process_auxtrace_info_full()
3456 etm->num_cpu = num_cpu; in cs_etm__process_auxtrace_info_full()
3457 etm->pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); in cs_etm__process_auxtrace_info_full()
3458 etm->snapshot_mode = (ptr[CS_ETM_SNAPSHOT] != 0); in cs_etm__process_auxtrace_info_full()
3459 etm->metadata = metadata; in cs_etm__process_auxtrace_info_full()
3460 etm->auxtrace_type = auxtrace_info->type; in cs_etm__process_auxtrace_info_full()
3462 if (etm->synth_opts.use_timestamp) in cs_etm__process_auxtrace_info_full()
3472 etm->has_virtual_ts = true; in cs_etm__process_auxtrace_info_full()
3475 etm->has_virtual_ts = cs_etm__has_virtual_ts(metadata, num_cpu); in cs_etm__process_auxtrace_info_full()
3477 if (!etm->has_virtual_ts) in cs_etm__process_auxtrace_info_full()
3482 "if the Coresight timestamp on the platform is same with the kernel time.\n\n"); in cs_etm__process_auxtrace_info_full()
3484 etm->auxtrace.process_event = cs_etm__process_event; in cs_etm__process_auxtrace_info_full()
3485 etm->auxtrace.process_auxtrace_event = cs_etm__process_auxtrace_event; in cs_etm__process_auxtrace_info_full()
3486 etm->auxtrace.flush_events = cs_etm__flush_events; in cs_etm__process_auxtrace_info_full()
3487 etm->auxtrace.free_events = cs_etm__free_events; in cs_etm__process_auxtrace_info_full()
3488 etm->auxtrace.free = cs_etm__free; in cs_etm__process_auxtrace_info_full()
3489 etm->auxtrace.evsel_is_auxtrace = cs_etm__evsel_is_auxtrace; in cs_etm__process_auxtrace_info_full()
3490 session->auxtrace = &etm->auxtrace; in cs_etm__process_auxtrace_info_full()
3496 etm->tc.time_shift = tc->time_shift; in cs_etm__process_auxtrace_info_full()
3497 etm->tc.time_mult = tc->time_mult; in cs_etm__process_auxtrace_info_full()
3498 etm->tc.time_zero = tc->time_zero; in cs_etm__process_auxtrace_info_full()
3500 etm->tc.time_cycles = tc->time_cycles; in cs_etm__process_auxtrace_info_full()
3501 etm->tc.time_mask = tc->time_mask; in cs_etm__process_auxtrace_info_full()
3502 etm->tc.cap_user_time_zero = tc->cap_user_time_zero; in cs_etm__process_auxtrace_info_full()
3503 etm->tc.cap_user_time_short = tc->cap_user_time_short; in cs_etm__process_auxtrace_info_full()
3529 * If no AUX_HW_ID packets are present - which means a file recorded on an old kernel in cs_etm__process_auxtrace_info_full()
3536 err = perf_session__peek_events(session, session->header.data_offset, in cs_etm__process_auxtrace_info_full()
3537 session->header.data_size, in cs_etm__process_auxtrace_info_full()
3553 etm->data_queued = etm->queues.populated; in cs_etm__process_auxtrace_info_full()
3557 auxtrace_queues__free(&etm->queues); in cs_etm__process_auxtrace_info_full()
3558 session->auxtrace = NULL; in cs_etm__process_auxtrace_info_full()