Lines Matching +full:is +full:- +full:decoded +full:- +full:cs
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
63 * which CPU it ran on. It also implies no context IDs so the TID is
128 * work with. One option is to modify to auxtrace_heap_XYZ() API or simply
154 return -EINVAL; in cs_etm__get_magic()
156 metadata = inode->priv; in cs_etm__get_magic()
168 return -EINVAL; in cs_etm__get_cpu()
170 metadata = inode->priv; in cs_etm__get_cpu()
176 * The returned PID format is presented as an enum:
178 * CS_ETM_PIDFMT_CTXTID: CONTEXTIDR or CONTEXTIDR_EL1 is traced.
179 * CS_ETM_PIDFMT_CTXTID2: CONTEXTIDR_EL2 is traced.
188 * The result is cached in etm->pid_fmt so this function only needs to be called
197 /* CONTEXTIDR is traced */ in cs_etm__init_pid_fmt()
202 /* CONTEXTIDR_EL2 is traced */ in cs_etm__init_pid_fmt()
205 /* CONTEXTIDR_EL1 is traced */ in cs_etm__init_pid_fmt()
215 return etmq->etm->pid_fmt; in cs_etm__get_pid_fmt()
227 return -ENOMEM; in cs_etm__map_trace_id()
233 if (inode->priv) in cs_etm__map_trace_id()
234 return -EINVAL; in cs_etm__map_trace_id()
237 inode->priv = cpu_metadata; in cs_etm__map_trace_id()
257 return -EINVAL; in cs_etm__metadata_get_trace_id()
280 return -EINVAL; in cs_etm__metadata_set_trace_id()
293 for (i = 0; i < etm->num_cpu; i++) { in get_cpu_data_idx()
294 if (etm->metadata[i][CS_ETM_CPU] == (u64)cpu) { in get_cpu_data_idx()
299 return -1; in get_cpu_data_idx()
310 return (idx != -1) ? etm->metadata[idx] : NULL; in get_cpu_data()
317 * The routine is tolerant of seeing multiple packets with the same association,
318 * but a CPU / Trace ID association changing during a session is an error.
333 hw_id = event->aux_output_hw_id.hw_id; in cs_etm__process_aux_output_hw_id()
339 return -EINVAL; in cs_etm__process_aux_output_hw_id()
342 etm = container_of(session->auxtrace, struct cs_etm_auxtrace, auxtrace); in cs_etm__process_aux_output_hw_id()
343 if (!etm || !etm->metadata) in cs_etm__process_aux_output_hw_id()
344 return -EINVAL; in cs_etm__process_aux_output_hw_id()
347 evsel = evlist__event2evsel(session->evlist, event); in cs_etm__process_aux_output_hw_id()
349 return -EINVAL; in cs_etm__process_aux_output_hw_id()
354 if (cpu == -1) { in cs_etm__process_aux_output_hw_id()
355 /* no CPU in the sample - possibly recorded with an old version of perf */ in cs_etm__process_aux_output_hw_id()
357 return -EINVAL; in cs_etm__process_aux_output_hw_id()
360 /* See if the ID is mapped to a CPU, and it matches the current CPU */ in cs_etm__process_aux_output_hw_id()
363 cpu_data = inode->priv; in cs_etm__process_aux_output_hw_id()
366 return -EINVAL; in cs_etm__process_aux_output_hw_id()
375 return -EINVAL; in cs_etm__process_aux_output_hw_id()
378 /* mapped and matched - return OK */ in cs_etm__process_aux_output_hw_id()
386 /* not one we've seen before - lets map it */ in cs_etm__process_aux_output_hw_id()
403 * When a timestamp packet is encountered the backend code in cs_etm__etmq_set_traceid_queue_timestamp()
404 * is stopped so that the front end has time to process packets in cs_etm__etmq_set_traceid_queue_timestamp()
409 etmq->pending_timestamp_chan_id = trace_chan_id; in cs_etm__etmq_set_traceid_queue_timestamp()
417 if (!etmq->pending_timestamp_chan_id) in cs_etm__etmq_get_timestamp()
421 *trace_chan_id = etmq->pending_timestamp_chan_id; in cs_etm__etmq_get_timestamp()
424 etmq->pending_timestamp_chan_id); in cs_etm__etmq_get_timestamp()
429 etmq->pending_timestamp_chan_id = 0; in cs_etm__etmq_get_timestamp()
432 return packet_queue->cs_timestamp; in cs_etm__etmq_get_timestamp()
439 queue->head = 0; in cs_etm__clear_packet_queue()
440 queue->tail = 0; in cs_etm__clear_packet_queue()
441 queue->packet_count = 0; in cs_etm__clear_packet_queue()
443 queue->packet_buffer[i].isa = CS_ETM_ISA_UNKNOWN; in cs_etm__clear_packet_queue()
444 queue->packet_buffer[i].start_addr = CS_ETM_INVAL_ADDR; in cs_etm__clear_packet_queue()
445 queue->packet_buffer[i].end_addr = CS_ETM_INVAL_ADDR; in cs_etm__clear_packet_queue()
446 queue->packet_buffer[i].instr_count = 0; in cs_etm__clear_packet_queue()
447 queue->packet_buffer[i].last_instr_taken_branch = false; in cs_etm__clear_packet_queue()
448 queue->packet_buffer[i].last_instr_size = 0; in cs_etm__clear_packet_queue()
449 queue->packet_buffer[i].last_instr_type = 0; in cs_etm__clear_packet_queue()
450 queue->packet_buffer[i].last_instr_subtype = 0; in cs_etm__clear_packet_queue()
451 queue->packet_buffer[i].last_instr_cond = 0; in cs_etm__clear_packet_queue()
452 queue->packet_buffer[i].flags = 0; in cs_etm__clear_packet_queue()
453 queue->packet_buffer[i].exception_number = UINT32_MAX; in cs_etm__clear_packet_queue()
454 queue->packet_buffer[i].trace_chan_id = UINT8_MAX; in cs_etm__clear_packet_queue()
455 queue->packet_buffer[i].cpu = INT_MIN; in cs_etm__clear_packet_queue()
464 struct intlist *traceid_queues_list = etmq->traceid_queues_list; in cs_etm__clear_all_packet_queues()
467 idx = (int)(intptr_t)inode->priv; in cs_etm__clear_all_packet_queues()
468 tidq = etmq->traceid_queues[idx]; in cs_etm__clear_all_packet_queues()
469 cs_etm__clear_packet_queue(&tidq->packet_queue); in cs_etm__clear_all_packet_queues()
477 int rc = -ENOMEM; in cs_etm__init_traceid_queue()
479 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__init_traceid_queue()
481 cs_etm__clear_packet_queue(&tidq->packet_queue); in cs_etm__init_traceid_queue()
483 queue = &etmq->etm->queues.queue_array[etmq->queue_nr]; in cs_etm__init_traceid_queue()
484 tidq->trace_chan_id = trace_chan_id; in cs_etm__init_traceid_queue()
485 tidq->el = tidq->prev_packet_el = ocsd_EL_unknown; in cs_etm__init_traceid_queue()
486 tidq->thread = machine__findnew_thread(&etm->session->machines.host, -1, in cs_etm__init_traceid_queue()
487 queue->tid); in cs_etm__init_traceid_queue()
488 tidq->prev_packet_thread = machine__idle_thread(&etm->session->machines.host); in cs_etm__init_traceid_queue()
490 tidq->packet = zalloc(sizeof(struct cs_etm_packet)); in cs_etm__init_traceid_queue()
491 if (!tidq->packet) in cs_etm__init_traceid_queue()
494 tidq->prev_packet = zalloc(sizeof(struct cs_etm_packet)); in cs_etm__init_traceid_queue()
495 if (!tidq->prev_packet) in cs_etm__init_traceid_queue()
498 if (etm->synth_opts.last_branch) { in cs_etm__init_traceid_queue()
501 sz += etm->synth_opts.last_branch_sz * in cs_etm__init_traceid_queue()
503 tidq->last_branch = zalloc(sz); in cs_etm__init_traceid_queue()
504 if (!tidq->last_branch) in cs_etm__init_traceid_queue()
506 tidq->last_branch_rb = zalloc(sz); in cs_etm__init_traceid_queue()
507 if (!tidq->last_branch_rb) in cs_etm__init_traceid_queue()
511 tidq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); in cs_etm__init_traceid_queue()
512 if (!tidq->event_buf) in cs_etm__init_traceid_queue()
518 zfree(&tidq->last_branch_rb); in cs_etm__init_traceid_queue()
519 zfree(&tidq->last_branch); in cs_etm__init_traceid_queue()
520 zfree(&tidq->prev_packet); in cs_etm__init_traceid_queue()
521 zfree(&tidq->packet); in cs_etm__init_traceid_queue()
533 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__etmq_get_traceid_queue()
535 if (etm->per_thread_decoding) in cs_etm__etmq_get_traceid_queue()
538 traceid_queues_list = etmq->traceid_queues_list; in cs_etm__etmq_get_traceid_queue()
546 idx = (int)(intptr_t)inode->priv; in cs_etm__etmq_get_traceid_queue()
547 return etmq->traceid_queues[idx]; in cs_etm__etmq_get_traceid_queue()
559 /* Memory for the inode is free'ed in cs_etm_free_traceid_queues () */ in cs_etm__etmq_get_traceid_queue()
565 inode->priv = (void *)(intptr_t)idx; in cs_etm__etmq_get_traceid_queue()
571 traceid_queues = etmq->traceid_queues; in cs_etm__etmq_get_traceid_queue()
578 * memory is left untouched. in cs_etm__etmq_get_traceid_queue()
584 etmq->traceid_queues = traceid_queues; in cs_etm__etmq_get_traceid_queue()
586 return etmq->traceid_queues[idx]; in cs_etm__etmq_get_traceid_queue()
606 return &tidq->packet_queue; in cs_etm__etmq_get_packet_queue()
616 if (etm->synth_opts.branches || etm->synth_opts.last_branch || in cs_etm__packet_swap()
617 etm->synth_opts.instructions) { in cs_etm__packet_swap()
623 * previous and current packets. This is because the previous in cs_etm__packet_swap()
624 * packet is used for the 'from' IP for branch samples, so the in cs_etm__packet_swap()
630 tmp = tidq->packet; in cs_etm__packet_swap()
631 tidq->packet = tidq->prev_packet; in cs_etm__packet_swap()
632 tidq->prev_packet = tmp; in cs_etm__packet_swap()
633 tidq->prev_packet_el = tidq->el; in cs_etm__packet_swap()
634 thread__put(tidq->prev_packet_thread); in cs_etm__packet_swap()
635 tidq->prev_packet_thread = thread__get(tidq->thread); in cs_etm__packet_swap()
644 if (len && (pkt_string[len-1] == '\n')) in cs_etm__packet_dump()
656 u64 **metadata = etm->metadata; in cs_etm__set_trace_param_etmv3()
667 u64 **metadata = etm->metadata; in cs_etm__set_trace_param_etmv4()
682 u64 **metadata = etm->metadata; in cs_etm__set_trace_param_ete()
709 if (m_idx == -1) { in cs_etm__init_trace_params()
715 architecture = etm->metadata[m_idx][CS_ETM_MAGIC]; in cs_etm__init_trace_params()
719 etmidr = etm->metadata[m_idx][CS_ETM_ETMIDR]; in cs_etm__init_trace_params()
729 return -EINVAL; in cs_etm__init_trace_params()
741 int ret = -EINVAL; in cs_etm__init_decoder_params()
746 d_params->packet_printer = cs_etm__packet_dump; in cs_etm__init_decoder_params()
747 d_params->operation = mode; in cs_etm__init_decoder_params()
748 d_params->data = etmq; in cs_etm__init_decoder_params()
749 d_params->formatted = formatted; in cs_etm__init_decoder_params()
750 d_params->fsyncs = false; in cs_etm__init_decoder_params()
751 d_params->hsyncs = false; in cs_etm__init_decoder_params()
752 d_params->frame_aligned = true; in cs_etm__init_decoder_params()
769 cs_etm_decoder__get_name(etmq->decoder), buffer->size); in cs_etm__dump_event()
775 etmq->decoder, buffer->offset, in cs_etm__dump_event()
776 &((u8 *)buffer->data)[buffer_used], in cs_etm__dump_event()
777 buffer->size - buffer_used, &consumed); in cs_etm__dump_event()
782 } while (buffer_used < buffer->size); in cs_etm__dump_event()
784 cs_etm_decoder__reset(etmq->decoder); in cs_etm__dump_event()
790 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__flush_events()
796 if (!tool->ordered_events) in cs_etm__flush_events()
797 return -EINVAL; in cs_etm__flush_events()
799 if (etm->timeless_decoding) { in cs_etm__flush_events()
801 * Pass tid = -1 to process all queues. But likely they will have in cs_etm__flush_events()
804 return cs_etm__process_timeless_queues(etm, -1); in cs_etm__flush_events()
816 struct intlist *traceid_queues_list = etmq->traceid_queues_list; in cs_etm__free_traceid_queues()
819 priv = (uintptr_t)inode->priv; in cs_etm__free_traceid_queues()
823 tidq = etmq->traceid_queues[idx]; in cs_etm__free_traceid_queues()
824 thread__zput(tidq->thread); in cs_etm__free_traceid_queues()
825 thread__zput(tidq->prev_packet_thread); in cs_etm__free_traceid_queues()
826 zfree(&tidq->event_buf); in cs_etm__free_traceid_queues()
827 zfree(&tidq->last_branch); in cs_etm__free_traceid_queues()
828 zfree(&tidq->last_branch_rb); in cs_etm__free_traceid_queues()
829 zfree(&tidq->prev_packet); in cs_etm__free_traceid_queues()
830 zfree(&tidq->packet); in cs_etm__free_traceid_queues()
842 etmq->traceid_queues_list = NULL; in cs_etm__free_traceid_queues()
845 zfree(&etmq->traceid_queues); in cs_etm__free_traceid_queues()
855 cs_etm_decoder__free(etmq->decoder); in cs_etm__free_queue()
863 struct cs_etm_auxtrace *aux = container_of(session->auxtrace, in cs_etm__free_events()
866 struct auxtrace_queues *queues = &aux->queues; in cs_etm__free_events()
868 for (i = 0; i < queues->nr_queues; i++) { in cs_etm__free_events()
869 cs_etm__free_queue(queues->queue_array[i].priv); in cs_etm__free_events()
870 queues->queue_array[i].priv = NULL; in cs_etm__free_events()
880 struct cs_etm_auxtrace *aux = container_of(session->auxtrace, in cs_etm__free()
884 session->auxtrace = NULL; in cs_etm__free()
892 for (i = 0; i < aux->num_cpu; i++) in cs_etm__free()
893 zfree(&aux->metadata[i]); in cs_etm__free()
895 zfree(&aux->metadata); in cs_etm__free()
902 struct cs_etm_auxtrace *aux = container_of(session->auxtrace, in cs_etm__evsel_is_auxtrace()
906 return evsel->core.attr.type == aux->pmu_type; in cs_etm__evsel_is_auxtrace()
916 * running at EL1 assume everything is the host. in cs_etm__get_machine()
919 return &etmq->etm->session->machines.host; in cs_etm__get_machine()
922 * Not perfect, but otherwise assume anything in EL1 is the default in cs_etm__get_machine()
923 * guest, and everything else is the host. Distinguishing between guest in cs_etm__get_machine()
924 * and host userspaces isn't currently supported either. Neither is in cs_etm__get_machine()
925 * multiple guest support. All this does is reduce the likeliness of in cs_etm__get_machine()
931 return machines__find_guest(&etmq->etm->session->machines, in cs_etm__get_machine()
938 return &etmq->etm->session->machines.host; in cs_etm__get_machine()
997 assert(tidq->el == ocsd_EL1 || tidq->el == ocsd_EL0); in cs_etm__mem_access()
999 assert(tidq->el == ocsd_EL2); in cs_etm__mem_access()
1001 assert(tidq->el == ocsd_EL3); in cs_etm__mem_access()
1004 cpumode = cs_etm__cpu_mode(etmq, address, tidq->el); in cs_etm__mem_access()
1006 if (!thread__find_map(tidq->thread, cpumode, address, &al)) in cs_etm__mem_access()
1013 if (dso->data.status == DSO_DATA_STATUS_ERROR && in cs_etm__mem_access()
1021 len = dso__data_read_offset(dso, maps__machine(thread__maps(tidq->thread)), in cs_etm__mem_access()
1025 …ui__warning_once("CS ETM Trace: Missing DSO. Use 'perf archive' or debuginfod to export data from … in cs_etm__mem_access()
1026 …" Enable CONFIG_PROC_KCORE or use option '-k /path/to/vmlinux' for kernel symbols.\n"… in cs_etm__mem_access()
1027 if (!dso->auxtrace_warned) { in cs_etm__mem_access()
1028 pr_err("CS ETM Trace: Debug data not found for address %#"PRIx64" in %s\n", in cs_etm__mem_access()
1030 dso->long_name ? dso->long_name : "Unknown"); in cs_etm__mem_access()
1031 dso->auxtrace_warned = true; in cs_etm__mem_access()
1048 * Each queue can only contain data from one CPU when unformatted, so only one decoder is in cs_etm__alloc_queue()
1051 int decoders = formatted ? etm->num_cpu : 1; in cs_etm__alloc_queue()
1057 etmq->traceid_queues_list = intlist__new(NULL); in cs_etm__alloc_queue()
1058 if (!etmq->traceid_queues_list) in cs_etm__alloc_queue()
1077 etmq->decoder = cs_etm_decoder__new(decoders, &d_params, in cs_etm__alloc_queue()
1080 if (!etmq->decoder) in cs_etm__alloc_queue()
1087 if (cs_etm_decoder__add_mem_access_cb(etmq->decoder, in cs_etm__alloc_queue()
1088 0x0L, ((u64) -1L), in cs_etm__alloc_queue()
1096 cs_etm_decoder__free(etmq->decoder); in cs_etm__alloc_queue()
1098 intlist__delete(etmq->traceid_queues_list); in cs_etm__alloc_queue()
1110 struct cs_etm_queue *etmq = queue->priv; in cs_etm__setup_queue()
1112 if (list_empty(&queue->head) || etmq) in cs_etm__setup_queue()
1118 return -ENOMEM; in cs_etm__setup_queue()
1120 queue->priv = etmq; in cs_etm__setup_queue()
1121 etmq->etm = etm; in cs_etm__setup_queue()
1122 etmq->queue_nr = queue_nr; in cs_etm__setup_queue()
1123 etmq->offset = 0; in cs_etm__setup_queue()
1138 * We are under a CPU-wide trace scenario. As such we need to know in cs_etm__queue_first_cs_timestamp()
1142 * timestamp. The timestamp is then added to the auxtrace min heap in cs_etm__queue_first_cs_timestamp()
1156 * encountering a CS timestamp, a full packet queue or the end of in cs_etm__queue_first_cs_timestamp()
1177 * just decoded are useless since no timestamp has been in cs_etm__queue_first_cs_timestamp()
1190 * Note that packets decoded above are still in the traceID's packet in cs_etm__queue_first_cs_timestamp()
1194 ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); in cs_etm__queue_first_cs_timestamp()
1203 struct branch_stack *bs_src = tidq->last_branch_rb; in cs_etm__copy_last_branch_rb()
1204 struct branch_stack *bs_dst = tidq->last_branch; in cs_etm__copy_last_branch_rb()
1208 * Set the number of records before early exit: ->nr is used to in cs_etm__copy_last_branch_rb()
1209 * determine how many branches to copy from ->entries. in cs_etm__copy_last_branch_rb()
1211 bs_dst->nr = bs_src->nr; in cs_etm__copy_last_branch_rb()
1214 * Early exit when there is nothing to copy. in cs_etm__copy_last_branch_rb()
1216 if (!bs_src->nr) in cs_etm__copy_last_branch_rb()
1220 * As bs_src->entries is a circular buffer, we need to copy from it in in cs_etm__copy_last_branch_rb()
1222 * branch ->last_branch_pos until the end of bs_src->entries buffer. in cs_etm__copy_last_branch_rb()
1224 nr = etmq->etm->synth_opts.last_branch_sz - tidq->last_branch_pos; in cs_etm__copy_last_branch_rb()
1225 memcpy(&bs_dst->entries[0], in cs_etm__copy_last_branch_rb()
1226 &bs_src->entries[tidq->last_branch_pos], in cs_etm__copy_last_branch_rb()
1231 * of the bs_src->entries buffer and until the ->last_branch_pos element in cs_etm__copy_last_branch_rb()
1236 if (bs_src->nr >= etmq->etm->synth_opts.last_branch_sz) { in cs_etm__copy_last_branch_rb()
1237 memcpy(&bs_dst->entries[nr], in cs_etm__copy_last_branch_rb()
1238 &bs_src->entries[0], in cs_etm__copy_last_branch_rb()
1239 sizeof(struct branch_entry) * tidq->last_branch_pos); in cs_etm__copy_last_branch_rb()
1246 tidq->last_branch_pos = 0; in cs_etm__reset_last_branch_rb()
1247 tidq->last_branch_rb->nr = 0; in cs_etm__reset_last_branch_rb()
1258 * T32 instruction size is indicated by bits[15:11] of the first in cs_etm__t32_instr_size()
1259 * 16-bit word of the instruction: 0b11101, 0b11110 and 0b11111 in cs_etm__t32_instr_size()
1260 * denote a 32-bit instruction. in cs_etm__t32_instr_size()
1268 if (packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__first_executed_instr()
1271 return packet->start_addr; in cs_etm__first_executed_instr()
1278 if (packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__last_executed_instr()
1281 return packet->end_addr - packet->last_instr_size; in cs_etm__last_executed_instr()
1289 if (packet->isa == CS_ETM_ISA_T32) { in cs_etm__instr_addr()
1290 u64 addr = packet->start_addr; in cs_etm__instr_addr()
1295 offset--; in cs_etm__instr_addr()
1301 return packet->start_addr + offset * 4; in cs_etm__instr_addr()
1307 struct branch_stack *bs = tidq->last_branch_rb; in cs_etm__update_last_branch_rb()
1316 if (!tidq->last_branch_pos) in cs_etm__update_last_branch_rb()
1317 tidq->last_branch_pos = etmq->etm->synth_opts.last_branch_sz; in cs_etm__update_last_branch_rb()
1319 tidq->last_branch_pos -= 1; in cs_etm__update_last_branch_rb()
1321 be = &bs->entries[tidq->last_branch_pos]; in cs_etm__update_last_branch_rb()
1322 be->from = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__update_last_branch_rb()
1323 be->to = cs_etm__first_executed_instr(tidq->packet); in cs_etm__update_last_branch_rb()
1325 be->flags.mispred = 0; in cs_etm__update_last_branch_rb()
1326 be->flags.predicted = 1; in cs_etm__update_last_branch_rb()
1329 * Increment bs->nr until reaching the number of last branches asked by in cs_etm__update_last_branch_rb()
1332 if (bs->nr < etmq->etm->synth_opts.last_branch_sz) in cs_etm__update_last_branch_rb()
1333 bs->nr += 1; in cs_etm__update_last_branch_rb()
1339 event->header.size = perf_event__sample_event_size(sample, type, 0); in cs_etm__inject_event()
1347 struct auxtrace_buffer *aux_buffer = etmq->buffer; in cs_etm__get_trace()
1351 queue = &etmq->etm->queues.queue_array[etmq->queue_nr]; in cs_etm__get_trace()
1359 etmq->buf_len = 0; in cs_etm__get_trace()
1363 etmq->buffer = aux_buffer; in cs_etm__get_trace()
1366 if (!aux_buffer->data) { in cs_etm__get_trace()
1368 int fd = perf_data__fd(etmq->etm->session->data); in cs_etm__get_trace()
1370 aux_buffer->data = auxtrace_buffer__get_data(aux_buffer, fd); in cs_etm__get_trace()
1371 if (!aux_buffer->data) in cs_etm__get_trace()
1372 return -ENOMEM; in cs_etm__get_trace()
1379 etmq->buf_used = 0; in cs_etm__get_trace()
1380 etmq->buf_len = aux_buffer->size; in cs_etm__get_trace()
1381 etmq->buf = aux_buffer->data; in cs_etm__get_trace()
1383 return etmq->buf_len; in cs_etm__get_trace()
1392 if (tid != -1) { in cs_etm__set_thread()
1393 thread__zput(tidq->thread); in cs_etm__set_thread()
1394 tidq->thread = machine__find_thread(machine, -1, tid); in cs_etm__set_thread()
1398 if (!tidq->thread) in cs_etm__set_thread()
1399 tidq->thread = machine__idle_thread(machine); in cs_etm__set_thread()
1401 tidq->el = el; in cs_etm__set_thread()
1411 return -EINVAL; in cs_etm__etmq_set_tid_el()
1419 return !!etmq->etm->timeless_decoding; in cs_etm__etmq_is_timeless()
1431 if (packet->sample_type == CS_ETM_DISCONTINUITY) { in cs_etm__copy_insn()
1432 sample->insn_len = 0; in cs_etm__copy_insn()
1437 * T32 instruction size might be 32-bit or 16-bit, decide by calling in cs_etm__copy_insn()
1440 if (packet->isa == CS_ETM_ISA_T32) in cs_etm__copy_insn()
1441 sample->insn_len = cs_etm__t32_instr_size(etmq, trace_chan_id, in cs_etm__copy_insn()
1442 sample->ip); in cs_etm__copy_insn()
1443 /* Otherwise, A64 and A32 instruction size are always 32-bit. */ in cs_etm__copy_insn()
1445 sample->insn_len = 4; in cs_etm__copy_insn()
1447 cs_etm__mem_access(etmq, trace_chan_id, sample->ip, sample->insn_len, in cs_etm__copy_insn()
1448 (void *)sample->insn, 0); in cs_etm__copy_insn()
1453 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__convert_sample_time()
1455 if (etm->has_virtual_ts) in cs_etm__convert_sample_time()
1456 return tsc_to_perf_time(cs_timestamp, &etm->tc); in cs_etm__convert_sample_time()
1464 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__resolve_sample_time()
1465 struct cs_etm_packet_queue *packet_queue = &tidq->packet_queue; in cs_etm__resolve_sample_time()
1467 if (!etm->timeless_decoding && etm->has_virtual_ts) in cs_etm__resolve_sample_time()
1468 return packet_queue->cs_timestamp; in cs_etm__resolve_sample_time()
1470 return etm->latest_kernel_timestamp; in cs_etm__resolve_sample_time()
1478 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__synth_instruction_sample()
1479 union perf_event *event = tidq->event_buf; in cs_etm__synth_instruction_sample()
1482 event->sample.header.type = PERF_RECORD_SAMPLE; in cs_etm__synth_instruction_sample()
1483 event->sample.header.misc = cs_etm__cpu_mode(etmq, addr, tidq->el); in cs_etm__synth_instruction_sample()
1484 event->sample.header.size = sizeof(struct perf_event_header); in cs_etm__synth_instruction_sample()
1490 sample.pid = thread__pid(tidq->thread); in cs_etm__synth_instruction_sample()
1491 sample.tid = thread__tid(tidq->thread); in cs_etm__synth_instruction_sample()
1492 sample.id = etmq->etm->instructions_id; in cs_etm__synth_instruction_sample()
1493 sample.stream_id = etmq->etm->instructions_id; in cs_etm__synth_instruction_sample()
1495 sample.cpu = tidq->packet->cpu; in cs_etm__synth_instruction_sample()
1496 sample.flags = tidq->prev_packet->flags; in cs_etm__synth_instruction_sample()
1497 sample.cpumode = event->sample.header.misc; in cs_etm__synth_instruction_sample()
1499 cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample); in cs_etm__synth_instruction_sample()
1501 if (etm->synth_opts.last_branch) in cs_etm__synth_instruction_sample()
1502 sample.branch_stack = tidq->last_branch; in cs_etm__synth_instruction_sample()
1504 if (etm->synth_opts.inject) { in cs_etm__synth_instruction_sample()
1506 etm->instructions_sample_type); in cs_etm__synth_instruction_sample()
1511 ret = perf_session__deliver_synth_event(etm->session, event, &sample); in cs_etm__synth_instruction_sample()
1515 "CS ETM Trace: failed to deliver instruction event, error %d\n", in cs_etm__synth_instruction_sample()
1522 * The cs etm packet encodes an instruction range between a branch target
1529 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__synth_branch_sample()
1531 union perf_event *event = tidq->event_buf; in cs_etm__synth_branch_sample()
1539 ip = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__synth_branch_sample()
1541 event->sample.header.type = PERF_RECORD_SAMPLE; in cs_etm__synth_branch_sample()
1542 event->sample.header.misc = cs_etm__cpu_mode(etmq, ip, in cs_etm__synth_branch_sample()
1543 tidq->prev_packet_el); in cs_etm__synth_branch_sample()
1544 event->sample.header.size = sizeof(struct perf_event_header); in cs_etm__synth_branch_sample()
1550 sample.pid = thread__pid(tidq->prev_packet_thread); in cs_etm__synth_branch_sample()
1551 sample.tid = thread__tid(tidq->prev_packet_thread); in cs_etm__synth_branch_sample()
1552 sample.addr = cs_etm__first_executed_instr(tidq->packet); in cs_etm__synth_branch_sample()
1553 sample.id = etmq->etm->branches_id; in cs_etm__synth_branch_sample()
1554 sample.stream_id = etmq->etm->branches_id; in cs_etm__synth_branch_sample()
1556 sample.cpu = tidq->packet->cpu; in cs_etm__synth_branch_sample()
1557 sample.flags = tidq->prev_packet->flags; in cs_etm__synth_branch_sample()
1558 sample.cpumode = event->sample.header.misc; in cs_etm__synth_branch_sample()
1560 cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->prev_packet, in cs_etm__synth_branch_sample()
1566 if (etm->synth_opts.last_branch) { in cs_etm__synth_branch_sample()
1569 .hw_idx = -1ULL, in cs_etm__synth_branch_sample()
1578 if (etm->synth_opts.inject) { in cs_etm__synth_branch_sample()
1580 etm->branches_sample_type); in cs_etm__synth_branch_sample()
1585 ret = perf_session__deliver_synth_event(etm->session, event, &sample); in cs_etm__synth_branch_sample()
1589 "CS ETM Trace: failed to deliver instruction event, error %d\n", in cs_etm__synth_branch_sample()
1608 return perf_session__deliver_synth_event(cs_etm_synth->session, in cs_etm__event_synth()
1627 struct evlist *evlist = session->evlist; in cs_etm__synth_events()
1635 if (evsel->core.attr.type == etm->pmu_type) { in cs_etm__synth_events()
1649 attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK; in cs_etm__synth_events()
1652 if (etm->timeless_decoding) in cs_etm__synth_events()
1657 attr.exclude_user = evsel->core.attr.exclude_user; in cs_etm__synth_events()
1658 attr.exclude_kernel = evsel->core.attr.exclude_kernel; in cs_etm__synth_events()
1659 attr.exclude_hv = evsel->core.attr.exclude_hv; in cs_etm__synth_events()
1660 attr.exclude_host = evsel->core.attr.exclude_host; in cs_etm__synth_events()
1661 attr.exclude_guest = evsel->core.attr.exclude_guest; in cs_etm__synth_events()
1662 attr.sample_id_all = evsel->core.attr.sample_id_all; in cs_etm__synth_events()
1663 attr.read_format = evsel->core.attr.read_format; in cs_etm__synth_events()
1666 id = evsel->core.id[0] + 1000000000; in cs_etm__synth_events()
1671 if (etm->synth_opts.branches) { in cs_etm__synth_events()
1678 etm->branches_sample_type = attr.sample_type; in cs_etm__synth_events()
1679 etm->branches_id = id; in cs_etm__synth_events()
1684 if (etm->synth_opts.last_branch) { in cs_etm__synth_events()
1694 if (etm->synth_opts.instructions) { in cs_etm__synth_events()
1696 attr.sample_period = etm->synth_opts.period; in cs_etm__synth_events()
1697 etm->instructions_sample_period = attr.sample_period; in cs_etm__synth_events()
1701 etm->instructions_sample_type = attr.sample_type; in cs_etm__synth_events()
1702 etm->instructions_id = id; in cs_etm__synth_events()
1712 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__sample()
1714 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__sample()
1718 instrs_prev = tidq->period_instructions; in cs_etm__sample()
1720 tidq->period_instructions += tidq->packet->instr_count; in cs_etm__sample()
1724 * PREV_PACKET is a branch. in cs_etm__sample()
1726 if (etm->synth_opts.last_branch && in cs_etm__sample()
1727 tidq->prev_packet->sample_type == CS_ETM_RANGE && in cs_etm__sample()
1728 tidq->prev_packet->last_instr_taken_branch) in cs_etm__sample()
1731 if (etm->synth_opts.instructions && in cs_etm__sample()
1732 tidq->period_instructions >= etm->instructions_sample_period) { in cs_etm__sample()
1746 * -------------------------------------------------- in cs_etm__sample()
1753 * \---------------- -----------------/ in cs_etm__sample()
1755 * tidq->packet->instr_count in cs_etm__sample()
1758 * every etm->instructions_sample_period instructions - as in cs_etm__sample()
1759 * defined on the perf command line. Sample(n) is being the in cs_etm__sample()
1763 * tidq->packet->instr_count represents the number of in cs_etm__sample()
1769 * etm->instructions_sample_period. in cs_etm__sample()
1772 * instructions, one is the tail of the old packet and another in cs_etm__sample()
1773 * is the head of the new coming packet, to generate in cs_etm__sample()
1776 * instructions will be used by later packet and it is assigned in cs_etm__sample()
1777 * to tidq->period_instructions for next round calculation. in cs_etm__sample()
1782 * entry conditions ensure that instrs_prev is less than in cs_etm__sample()
1783 * etm->instructions_sample_period. in cs_etm__sample()
1785 u64 offset = etm->instructions_sample_period - instrs_prev; in cs_etm__sample()
1789 if (etm->synth_opts.last_branch) in cs_etm__sample()
1792 while (tidq->period_instructions >= in cs_etm__sample()
1793 etm->instructions_sample_period) { in cs_etm__sample()
1795 * Calculate the address of the sampled instruction (-1 in cs_etm__sample()
1796 * as sample is reported as though instruction has just in cs_etm__sample()
1801 tidq->packet, offset - 1); in cs_etm__sample()
1804 etm->instructions_sample_period); in cs_etm__sample()
1808 offset += etm->instructions_sample_period; in cs_etm__sample()
1809 tidq->period_instructions -= in cs_etm__sample()
1810 etm->instructions_sample_period; in cs_etm__sample()
1814 if (etm->synth_opts.branches) { in cs_etm__sample()
1818 if (tidq->prev_packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__sample()
1822 if (tidq->prev_packet->sample_type == CS_ETM_RANGE && in cs_etm__sample()
1823 tidq->prev_packet->last_instr_taken_branch) in cs_etm__sample()
1841 * When the exception packet is inserted, whether the last instruction in cs_etm__exception()
1842 * in previous range packet is taken branch or not, we need to force in cs_etm__exception()
1843 * to set 'prev_packet->last_instr_taken_branch' to true. This ensures in cs_etm__exception()
1845 * exception is trapped to kernel or before the exception returning. in cs_etm__exception()
1851 if (tidq->prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__exception()
1852 tidq->prev_packet->last_instr_taken_branch = true; in cs_etm__exception()
1861 struct cs_etm_auxtrace *etm = etmq->etm; in cs_etm__flush()
1864 if (tidq->prev_packet->sample_type == CS_ETM_EMPTY) in cs_etm__flush()
1867 if (etmq->etm->synth_opts.last_branch && in cs_etm__flush()
1868 etmq->etm->synth_opts.instructions && in cs_etm__flush()
1869 tidq->prev_packet->sample_type == CS_ETM_RANGE) { in cs_etm__flush()
1882 addr = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__flush()
1886 tidq->period_instructions); in cs_etm__flush()
1890 tidq->period_instructions = 0; in cs_etm__flush()
1894 if (etm->synth_opts.branches && in cs_etm__flush()
1895 tidq->prev_packet->sample_type == CS_ETM_RANGE) { in cs_etm__flush()
1905 if (etm->synth_opts.last_branch) in cs_etm__flush()
1917 * It has no new packet coming and 'etmq->packet' contains the stale in cs_etm__end_block()
1925 if (etmq->etm->synth_opts.last_branch && in cs_etm__end_block()
1926 etmq->etm->synth_opts.instructions && in cs_etm__end_block()
1927 tidq->prev_packet->sample_type == CS_ETM_RANGE) { in cs_etm__end_block()
1937 addr = cs_etm__last_executed_instr(tidq->prev_packet); in cs_etm__end_block()
1941 tidq->period_instructions); in cs_etm__end_block()
1945 tidq->period_instructions = 0; in cs_etm__end_block()
1961 if (!etmq->buf_len) { in cs_etm__get_data_block()
1967 * are contiguous, reset the decoder to force re-sync. in cs_etm__get_data_block()
1969 ret = cs_etm_decoder__reset(etmq->decoder); in cs_etm__get_data_block()
1974 return etmq->buf_len; in cs_etm__get_data_block()
1986 switch (packet->isa) { in cs_etm__is_svc_instr()
1989 * The SVC of T32 is defined in ARM DDI 0487D.a, F5.1.247: in cs_etm__is_svc_instr()
1992 * +-----------------+--------+ in cs_etm__is_svc_instr()
1994 * +-----------------+--------+ in cs_etm__is_svc_instr()
2000 addr = end_addr - 2; in cs_etm__is_svc_instr()
2009 * The SVC of A32 is defined in ARM DDI 0487D.a, F5.1.247: in cs_etm__is_svc_instr()
2012 * +---------+---------+-------------------------+ in cs_etm__is_svc_instr()
2014 * +---------+---------+-------------------------+ in cs_etm__is_svc_instr()
2016 addr = end_addr - 4; in cs_etm__is_svc_instr()
2026 * The SVC of A64 is defined in ARM DDI 0487D.a, C6.2.294: in cs_etm__is_svc_instr()
2029 * +-----------------------+---------+-----------+ in cs_etm__is_svc_instr()
2031 * +-----------------------+---------+-----------+ in cs_etm__is_svc_instr()
2033 addr = end_addr - 4; in cs_etm__is_svc_instr()
2051 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__is_syscall()
2052 struct cs_etm_packet *packet = tidq->packet; in cs_etm__is_syscall()
2053 struct cs_etm_packet *prev_packet = tidq->prev_packet; in cs_etm__is_syscall()
2056 if (packet->exception_number == CS_ETMV3_EXC_SVC) in cs_etm__is_syscall()
2065 if (packet->exception_number == CS_ETMV4_EXC_CALL && in cs_etm__is_syscall()
2067 prev_packet->end_addr)) in cs_etm__is_syscall()
2077 struct cs_etm_packet *packet = tidq->packet; in cs_etm__is_async_exception()
2080 if (packet->exception_number == CS_ETMV3_EXC_DEBUG_HALT || in cs_etm__is_async_exception()
2081 packet->exception_number == CS_ETMV3_EXC_ASYNC_DATA_ABORT || in cs_etm__is_async_exception()
2082 packet->exception_number == CS_ETMV3_EXC_PE_RESET || in cs_etm__is_async_exception()
2083 packet->exception_number == CS_ETMV3_EXC_IRQ || in cs_etm__is_async_exception()
2084 packet->exception_number == CS_ETMV3_EXC_FIQ) in cs_etm__is_async_exception()
2088 if (packet->exception_number == CS_ETMV4_EXC_RESET || in cs_etm__is_async_exception()
2089 packet->exception_number == CS_ETMV4_EXC_DEBUG_HALT || in cs_etm__is_async_exception()
2090 packet->exception_number == CS_ETMV4_EXC_SYSTEM_ERROR || in cs_etm__is_async_exception()
2091 packet->exception_number == CS_ETMV4_EXC_INST_DEBUG || in cs_etm__is_async_exception()
2092 packet->exception_number == CS_ETMV4_EXC_DATA_DEBUG || in cs_etm__is_async_exception()
2093 packet->exception_number == CS_ETMV4_EXC_IRQ || in cs_etm__is_async_exception()
2094 packet->exception_number == CS_ETMV4_EXC_FIQ) in cs_etm__is_async_exception()
2104 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__is_sync_exception()
2105 struct cs_etm_packet *packet = tidq->packet; in cs_etm__is_sync_exception()
2106 struct cs_etm_packet *prev_packet = tidq->prev_packet; in cs_etm__is_sync_exception()
2109 if (packet->exception_number == CS_ETMV3_EXC_SMC || in cs_etm__is_sync_exception()
2110 packet->exception_number == CS_ETMV3_EXC_HYP || in cs_etm__is_sync_exception()
2111 packet->exception_number == CS_ETMV3_EXC_JAZELLE_THUMBEE || in cs_etm__is_sync_exception()
2112 packet->exception_number == CS_ETMV3_EXC_UNDEFINED_INSTR || in cs_etm__is_sync_exception()
2113 packet->exception_number == CS_ETMV3_EXC_PREFETCH_ABORT || in cs_etm__is_sync_exception()
2114 packet->exception_number == CS_ETMV3_EXC_DATA_FAULT || in cs_etm__is_sync_exception()
2115 packet->exception_number == CS_ETMV3_EXC_GENERIC) in cs_etm__is_sync_exception()
2119 if (packet->exception_number == CS_ETMV4_EXC_TRAP || in cs_etm__is_sync_exception()
2120 packet->exception_number == CS_ETMV4_EXC_ALIGNMENT || in cs_etm__is_sync_exception()
2121 packet->exception_number == CS_ETMV4_EXC_INST_FAULT || in cs_etm__is_sync_exception()
2122 packet->exception_number == CS_ETMV4_EXC_DATA_FAULT) in cs_etm__is_sync_exception()
2129 if (packet->exception_number == CS_ETMV4_EXC_CALL && in cs_etm__is_sync_exception()
2131 prev_packet->end_addr)) in cs_etm__is_sync_exception()
2141 if (packet->exception_number > CS_ETMV4_EXC_FIQ && in cs_etm__is_sync_exception()
2142 packet->exception_number <= CS_ETMV4_EXC_END) in cs_etm__is_sync_exception()
2152 struct cs_etm_packet *packet = tidq->packet; in cs_etm__set_sample_flags()
2153 struct cs_etm_packet *prev_packet = tidq->prev_packet; in cs_etm__set_sample_flags()
2154 u8 trace_chan_id = tidq->trace_chan_id; in cs_etm__set_sample_flags()
2158 switch (packet->sample_type) { in cs_etm__set_sample_flags()
2165 if (packet->last_instr_type == OCSD_INSTR_BR && in cs_etm__set_sample_flags()
2166 packet->last_instr_subtype == OCSD_S_INSTR_NONE) { in cs_etm__set_sample_flags()
2167 packet->flags = PERF_IP_FLAG_BRANCH; in cs_etm__set_sample_flags()
2169 if (packet->last_instr_cond) in cs_etm__set_sample_flags()
2170 packet->flags |= PERF_IP_FLAG_CONDITIONAL; in cs_etm__set_sample_flags()
2174 * Immediate branch instruction with link (e.g. BL), this is in cs_etm__set_sample_flags()
2177 if (packet->last_instr_type == OCSD_INSTR_BR && in cs_etm__set_sample_flags()
2178 packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK) in cs_etm__set_sample_flags()
2179 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2183 * Indirect branch instruction with link (e.g. BLR), this is in cs_etm__set_sample_flags()
2186 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2187 packet->last_instr_subtype == OCSD_S_INSTR_BR_LINK) in cs_etm__set_sample_flags()
2188 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2193 * OCSD_S_INSTR_V7_IMPLIED_RET, this is explicit hint for in cs_etm__set_sample_flags()
2196 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2197 packet->last_instr_subtype == OCSD_S_INSTR_V7_IMPLIED_RET) in cs_etm__set_sample_flags()
2198 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2203 * this is used for function return, especially for functions in cs_etm__set_sample_flags()
2206 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2207 packet->last_instr_subtype == OCSD_S_INSTR_NONE) in cs_etm__set_sample_flags()
2208 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2212 if (packet->last_instr_type == OCSD_INSTR_BR_INDIRECT && in cs_etm__set_sample_flags()
2213 packet->last_instr_subtype == OCSD_S_INSTR_V8_RET) in cs_etm__set_sample_flags()
2214 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2222 if (prev_packet->sample_type == CS_ETM_DISCONTINUITY) in cs_etm__set_sample_flags()
2223 prev_packet->flags |= PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2227 * If the previous packet is an exception return packet in cs_etm__set_sample_flags()
2232 if (prev_packet->flags == (PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2236 packet, packet->start_addr)) in cs_etm__set_sample_flags()
2237 prev_packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2243 * The trace is discontinuous, if the previous packet is in cs_etm__set_sample_flags()
2247 if (prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__set_sample_flags()
2248 prev_packet->flags |= PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2252 ret = cs_etm__get_magic(packet->trace_chan_id, &magic); in cs_etm__set_sample_flags()
2256 /* The exception is for system call. */ in cs_etm__set_sample_flags()
2258 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2266 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2271 * Otherwise, exception is caused by trap, instruction & in cs_etm__set_sample_flags()
2275 packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2280 * When the exception packet is inserted, since exception in cs_etm__set_sample_flags()
2281 * packet is not used standalone for generating samples in cs_etm__set_sample_flags()
2284 * it is an exception taken branch. in cs_etm__set_sample_flags()
2286 if (prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__set_sample_flags()
2287 prev_packet->flags = packet->flags; in cs_etm__set_sample_flags()
2291 * When the exception return packet is inserted, since in cs_etm__set_sample_flags()
2292 * exception return packet is not used standalone for in cs_etm__set_sample_flags()
2295 * flags to tell perf it is an exception return branch. in cs_etm__set_sample_flags()
2302 * reuse it for exception return packet, this is not reliable in cs_etm__set_sample_flags()
2308 * packet is for system call or for other types. Thus the in cs_etm__set_sample_flags()
2315 if (prev_packet->sample_type == CS_ETM_RANGE) in cs_etm__set_sample_flags()
2316 prev_packet->flags = PERF_IP_FLAG_BRANCH | in cs_etm__set_sample_flags()
2334 * Packets are decoded and added to the decoder's packet queue in cs_etm__decode_data_block()
2336 * processing stops or there is nothing left in the buffer. Normal in cs_etm__decode_data_block()
2340 ret = cs_etm_decoder__process_data_block(etmq->decoder, in cs_etm__decode_data_block()
2341 etmq->offset, in cs_etm__decode_data_block()
2342 &etmq->buf[etmq->buf_used], in cs_etm__decode_data_block()
2343 etmq->buf_len, in cs_etm__decode_data_block()
2348 etmq->offset += processed; in cs_etm__decode_data_block()
2349 etmq->buf_used += processed; in cs_etm__decode_data_block()
2350 etmq->buf_len -= processed; in cs_etm__decode_data_block()
2362 packet_queue = &tidq->packet_queue; in cs_etm__process_traceid_queue()
2367 tidq->packet); in cs_etm__process_traceid_queue()
2386 switch (tidq->packet->sample_type) { in cs_etm__process_traceid_queue()
2398 * If the exception packet is coming, in cs_etm__process_traceid_queue()
2416 pr_err("CS ETM Trace: empty packet\n"); in cs_etm__process_traceid_queue()
2417 return -EINVAL; in cs_etm__process_traceid_queue()
2431 struct intlist *traceid_queues_list = etmq->traceid_queues_list; in cs_etm__clear_all_traceid_queues()
2434 idx = (int)(intptr_t)inode->priv; in cs_etm__clear_all_traceid_queues()
2435 tidq = etmq->traceid_queues[idx]; in cs_etm__clear_all_traceid_queues()
2455 return -EINVAL; in cs_etm__run_per_thread_timeless_decoder()
2476 } while (etmq->buf_len); in cs_etm__run_per_thread_timeless_decoder()
2507 * buffer. But here in per-cpu mode we need to iterate in cs_etm__run_per_cpu_timeless_decoder()
2511 etmq->traceid_queues_list) { in cs_etm__run_per_cpu_timeless_decoder()
2512 idx = (int)(intptr_t)inode->priv; in cs_etm__run_per_cpu_timeless_decoder()
2513 tidq = etmq->traceid_queues[idx]; in cs_etm__run_per_cpu_timeless_decoder()
2516 } while (etmq->buf_len); in cs_etm__run_per_cpu_timeless_decoder()
2518 intlist__for_each_entry(inode, etmq->traceid_queues_list) { in cs_etm__run_per_cpu_timeless_decoder()
2519 idx = (int)(intptr_t)inode->priv; in cs_etm__run_per_cpu_timeless_decoder()
2520 tidq = etmq->traceid_queues[idx]; in cs_etm__run_per_cpu_timeless_decoder()
2535 struct auxtrace_queues *queues = &etm->queues; in cs_etm__process_timeless_queues()
2537 for (i = 0; i < queues->nr_queues; i++) { in cs_etm__process_timeless_queues()
2538 struct auxtrace_queue *queue = &etm->queues.queue_array[i]; in cs_etm__process_timeless_queues()
2539 struct cs_etm_queue *etmq = queue->priv; in cs_etm__process_timeless_queues()
2545 if (etm->per_thread_decoding) { in cs_etm__process_timeless_queues()
2552 if (tid == -1 || thread__tid(tidq->thread) == tid) in cs_etm__process_timeless_queues()
2572 * Pre-populate the heap with one entry from each queue so that we can in cs_etm__process_timestamped_queues()
2575 for (i = 0; i < etm->queues.nr_queues; i++) { in cs_etm__process_timestamped_queues()
2576 etmq = etm->queues.queue_array[i].priv; in cs_etm__process_timestamped_queues()
2586 if (!etm->heap.heap_cnt) in cs_etm__process_timestamped_queues()
2590 cs_queue_nr = etm->heap.heap_array[0].queue_nr; in cs_etm__process_timestamped_queues()
2593 queue = &etm->queues.queue_array[queue_nr]; in cs_etm__process_timestamped_queues()
2594 etmq = queue->priv; in cs_etm__process_timestamped_queues()
2600 auxtrace_heap__pop(&etm->heap); in cs_etm__process_timestamped_queues()
2609 ret = -EINVAL; in cs_etm__process_timestamped_queues()
2647 * there is no more traces to decode in the current in cs_etm__process_timestamped_queues()
2650 * did not get a timestamp, there is no more traces to in cs_etm__process_timestamped_queues()
2662 * just been decoded. They will be processed and synthesized in cs_etm__process_timestamped_queues()
2667 ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, cs_timestamp); in cs_etm__process_timestamped_queues()
2679 if (etm->timeless_decoding) in cs_etm__process_itrace_start()
2685 * trace is supported for guests which wouldn't need pids so this should in cs_etm__process_itrace_start()
2688 th = machine__findnew_thread(&etm->session->machines.host, in cs_etm__process_itrace_start()
2689 event->itrace_start.pid, in cs_etm__process_itrace_start()
2690 event->itrace_start.tid); in cs_etm__process_itrace_start()
2692 return -ENOMEM; in cs_etm__process_itrace_start()
2703 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; in cs_etm__process_switch_cpu_wide()
2706 * Context switch in per-thread mode are irrelevant since perf in cs_etm__process_switch_cpu_wide()
2707 * will start/stop tracing as the process is scheduled. in cs_etm__process_switch_cpu_wide()
2709 if (etm->timeless_decoding) in cs_etm__process_switch_cpu_wide()
2723 * trace is supported for guests which wouldn't need pids so this should in cs_etm__process_switch_cpu_wide()
2726 th = machine__findnew_thread(&etm->session->machines.host, in cs_etm__process_switch_cpu_wide()
2727 event->context_switch.next_prev_pid, in cs_etm__process_switch_cpu_wide()
2728 event->context_switch.next_prev_tid); in cs_etm__process_switch_cpu_wide()
2730 return -ENOMEM; in cs_etm__process_switch_cpu_wide()
2742 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__process_event()
2749 if (!tool->ordered_events) { in cs_etm__process_event()
2751 return -EINVAL; in cs_etm__process_event()
2754 switch (event->header.type) { in cs_etm__process_event()
2757 * Don't need to wait for cs_etm__flush_events() in per-thread mode to in cs_etm__process_event()
2759 * this thread. All this does is emit samples earlier than waiting for in cs_etm__process_event()
2764 if (etm->per_thread_decoding && etm->timeless_decoding) in cs_etm__process_event()
2766 event->fork.tid); in cs_etm__process_event()
2781 if (sample->time && (sample->time != (u64)-1)) in cs_etm__process_event()
2782 etm->latest_kernel_timestamp = sample->time; in cs_etm__process_event()
2799 * This is because the queues can contain multiple entries of the same in dump_queued_data()
2802 for (i = 0; i < etm->queues.nr_queues; ++i) in dump_queued_data()
2803 list_for_each_entry(buf, &etm->queues.queue_array[i].head, list) in dump_queued_data()
2804 if (buf->reference == event->reference) in dump_queued_data()
2805 cs_etm__dump_event(etm->queues.queue_array[i].priv, buf); in dump_queued_data()
2812 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__process_auxtrace_event()
2815 if (!etm->data_queued) { in cs_etm__process_auxtrace_event()
2818 int fd = perf_data__fd(session->data); in cs_etm__process_auxtrace_event()
2819 bool is_pipe = perf_data__is_pipe(session->data); in cs_etm__process_auxtrace_event()
2821 int idx = event->auxtrace.idx; in cs_etm__process_auxtrace_event()
2827 if (data_offset == -1) in cs_etm__process_auxtrace_event()
2828 return -errno; in cs_etm__process_auxtrace_event()
2831 err = auxtrace_queues__add_event(&etm->queues, session, in cs_etm__process_auxtrace_event()
2837 * Knowing if the trace is formatted or not requires a lookup of in cs_etm__process_auxtrace_event()
2838 * the aux record so only works in non-piped mode where data is in cs_etm__process_auxtrace_event()
2842 err = cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], in cs_etm__process_auxtrace_event()
2843 idx, true, -1); in cs_etm__process_auxtrace_event()
2849 cs_etm__dump_event(etm->queues.queue_array[idx].priv, buffer); in cs_etm__process_auxtrace_event()
2853 dump_queued_data(etm, &event->auxtrace); in cs_etm__process_auxtrace_event()
2861 struct evlist *evlist = etm->session->evlist; in cs_etm__setup_timeless_decoding()
2863 /* Override timeless mode with user input from --itrace=Z */ in cs_etm__setup_timeless_decoding()
2864 if (etm->synth_opts.timeless_decoding) { in cs_etm__setup_timeless_decoding()
2865 etm->timeless_decoding = true; in cs_etm__setup_timeless_decoding()
2873 if (cs_etm__evsel_is_auxtrace(etm->session, evsel)) { in cs_etm__setup_timeless_decoding()
2874 etm->timeless_decoding = in cs_etm__setup_timeless_decoding()
2875 !(evsel->core.attr.config & BIT(ETM_OPT_TS)); in cs_etm__setup_timeless_decoding()
2879 pr_err("CS ETM: Couldn't find ETM evsel\n"); in cs_etm__setup_timeless_decoding()
2880 return -EINVAL; in cs_etm__setup_timeless_decoding()
2886 * For version 1 there is a per cpu nr_params entry. If we are handling
2916 for (k = CS_ETM_COMMON_BLK_MAX_V1 - 1; k < nr_in_params; k++) in cs_etm__create_meta_blk()
2921 /* read version 1 info block - input and output nr_params may differ */ in cs_etm__create_meta_blk()
2926 /* if input has more params than output - skip excess */ in cs_etm__create_meta_blk()
2935 metadata[CS_ETM_NR_TRC_PARAMS] = nr_out_params - nr_cmn_params; in cs_etm__create_meta_blk()
2951 * is reset across each buffer, so splitting the buffers up in advance has
2966 struct cs_etm_auxtrace *etm = container_of(session->auxtrace, in cs_etm__queue_aux_fragment()
2978 auxtrace_event = &auxtrace_event_union->auxtrace; in cs_etm__queue_aux_fragment()
2979 if (auxtrace_event->header.type != PERF_RECORD_AUXTRACE) in cs_etm__queue_aux_fragment()
2980 return -EINVAL; in cs_etm__queue_aux_fragment()
2982 if (auxtrace_event->header.size < sizeof(struct perf_record_auxtrace) || in cs_etm__queue_aux_fragment()
2983 auxtrace_event->header.size != sz) { in cs_etm__queue_aux_fragment()
2984 return -EINVAL; in cs_etm__queue_aux_fragment()
2988 * In per-thread mode, auxtrace CPU is set to -1, but TID will be set instead. See in cs_etm__queue_aux_fragment()
2991 * So now compare only TIDs if auxtrace CPU is -1, and CPUs if auxtrace CPU is not -1. in cs_etm__queue_aux_fragment()
2994 if (auxtrace_event->cpu == (__u32) -1) { in cs_etm__queue_aux_fragment()
2995 etm->per_thread_decoding = true; in cs_etm__queue_aux_fragment()
2996 if (auxtrace_event->tid != sample->tid) in cs_etm__queue_aux_fragment()
2998 } else if (auxtrace_event->cpu != sample->cpu) { in cs_etm__queue_aux_fragment()
2999 if (etm->per_thread_decoding) { in cs_etm__queue_aux_fragment()
3001 * Found a per-cpu buffer after a per-thread one was in cs_etm__queue_aux_fragment()
3004 pr_err("CS ETM: Inconsistent per-thread/per-cpu mode.\n"); in cs_etm__queue_aux_fragment()
3005 return -EINVAL; in cs_etm__queue_aux_fragment()
3010 if (aux_event->flags & PERF_AUX_FLAG_OVERWRITE) { in cs_etm__queue_aux_fragment()
3012 * Clamp size in snapshot mode. The buffer size is clamped in in cs_etm__queue_aux_fragment()
3016 aux_size = min(aux_event->aux_size, auxtrace_event->size); in cs_etm__queue_aux_fragment()
3022 aux_offset = aux_event->aux_offset - aux_size; in cs_etm__queue_aux_fragment()
3024 aux_size = aux_event->aux_size; in cs_etm__queue_aux_fragment()
3025 aux_offset = aux_event->aux_offset; in cs_etm__queue_aux_fragment()
3028 if (aux_offset >= auxtrace_event->offset && in cs_etm__queue_aux_fragment()
3029 aux_offset + aux_size <= auxtrace_event->offset + auxtrace_event->size) { in cs_etm__queue_aux_fragment()
3037 file_offset += aux_offset - auxtrace_event->offset + auxtrace_event->header.size; in cs_etm__queue_aux_fragment()
3039 pr_debug3("CS ETM: Queue buffer size: %#"PRI_lx64" offset: %#"PRI_lx64 in cs_etm__queue_aux_fragment()
3040 " tid: %d cpu: %d\n", aux_size, aux_offset, sample->tid, sample->cpu); in cs_etm__queue_aux_fragment()
3041 err = auxtrace_queues__add_event(&etm->queues, session, &auxtrace_fragment, in cs_etm__queue_aux_fragment()
3046 idx = auxtrace_event->idx; in cs_etm__queue_aux_fragment()
3047 formatted = !(aux_event->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW); in cs_etm__queue_aux_fragment()
3048 return cs_etm__setup_queue(etm, &etm->queues.queue_array[idx], in cs_etm__queue_aux_fragment()
3049 idx, formatted, sample->cpu); in cs_etm__queue_aux_fragment()
3060 if (event->header.type == PERF_RECORD_AUX_OUTPUT_HW_ID) { in cs_etm__process_aux_hw_id_cb()
3078 if (event->header.type != PERF_RECORD_AUX) in cs_etm__queue_aux_records_cb()
3081 if (event->header.size < sizeof(struct perf_record_aux)) in cs_etm__queue_aux_records_cb()
3082 return -EINVAL; in cs_etm__queue_aux_records_cb()
3085 if (!event->aux.aux_size) in cs_etm__queue_aux_records_cb()
3092 evsel = evlist__event2evsel(session->evlist, event); in cs_etm__queue_aux_records_cb()
3094 return -EINVAL; in cs_etm__queue_aux_records_cb()
3102 list_for_each_entry(auxtrace_index, &session->auxtrace_index, list) { in cs_etm__queue_aux_records_cb()
3103 for (i = 0; i < auxtrace_index->nr; i++) { in cs_etm__queue_aux_records_cb()
3104 ent = &auxtrace_index->entries[i]; in cs_etm__queue_aux_records_cb()
3105 ret = cs_etm__queue_aux_fragment(session, ent->file_offset, in cs_etm__queue_aux_records_cb()
3106 ent->sz, &event->aux, &sample); in cs_etm__queue_aux_records_cb()
3120 pr_err("CS ETM: Couldn't find auxtrace buffer for aux_offset: %#"PRI_lx64 in cs_etm__queue_aux_records_cb()
3121 " tid: %d cpu: %d\n", event->aux.aux_offset, sample.tid, sample.cpu); in cs_etm__queue_aux_records_cb()
3127 struct auxtrace_index *index = list_first_entry_or_null(&session->auxtrace_index, in cs_etm__queue_aux_records()
3129 if (index && index->nr > 0) in cs_etm__queue_aux_records()
3130 return perf_session__peek_events(session, session->header.data_offset, in cs_etm__queue_aux_records()
3131 session->header.data_size, in cs_etm__queue_aux_records()
3136 * buffers or no index at all). Fail silently as there is the possibility of in cs_etm__queue_aux_records()
3137 * queueing them in cs_etm__process_auxtrace_event() if etm->data_queued is still in cs_etm__queue_aux_records()
3146 (CS_##type##_##param - CS_ETM_COMMON_BLK_MAX_V1))
3195 return -EINVAL; in cs_etm__map_trace_ids_metadata()
3227 return -EINVAL; in cs_etm__clear_unused_trace_ids_metadata()
3236 struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; in cs_etm__process_auxtrace_info_full()
3238 struct perf_record_time_conv *tc = &session->time_conv; in cs_etm__process_auxtrace_info_full()
3240 int total_size = auxtrace_info->header.size; in cs_etm__process_auxtrace_info_full()
3250 * Create an RB tree for traceID-metadata tuple. Since the conversion in cs_etm__process_auxtrace_info_full()
3251 * has to be made for each packet that gets decoded, optimizing access in cs_etm__process_auxtrace_info_full()
3252 * in anything other than a sequential array is worth doing. in cs_etm__process_auxtrace_info_full()
3256 return -ENOMEM; in cs_etm__process_auxtrace_info_full()
3259 ptr = (u64 *) auxtrace_info->priv; in cs_etm__process_auxtrace_info_full()
3263 err = -ENOMEM; in cs_etm__process_auxtrace_info_full()
3271 * The metadata is stored in the auxtrace_info section and encodes in cs_etm__process_auxtrace_info_full()
3272 * the configuration of the ARM embedded trace macrocell which is in cs_etm__process_auxtrace_info_full()
3288 metadata[j] = cs_etm__create_meta_blk(ptr, &i, CS_ETE_PRIV_MAX, -1); in cs_etm__process_auxtrace_info_full()
3290 …ui__error("CS ETM Trace: Unrecognised magic number %#"PRIx64". File could be from a newer version … in cs_etm__process_auxtrace_info_full()
3292 err = -EINVAL; in cs_etm__process_auxtrace_info_full()
3297 err = -ENOMEM; in cs_etm__process_auxtrace_info_full()
3309 priv_size = total_size - event_header_size - INFO_HEADER_SIZE; in cs_etm__process_auxtrace_info_full()
3311 err = -EINVAL; in cs_etm__process_auxtrace_info_full()
3318 err = -ENOMEM; in cs_etm__process_auxtrace_info_full()
3327 etm->pid_fmt = cs_etm__init_pid_fmt(metadata[0]); in cs_etm__process_auxtrace_info_full()
3329 err = auxtrace_queues__init(&etm->queues); in cs_etm__process_auxtrace_info_full()
3333 if (session->itrace_synth_opts->set) { in cs_etm__process_auxtrace_info_full()
3334 etm->synth_opts = *session->itrace_synth_opts; in cs_etm__process_auxtrace_info_full()
3336 itrace_synth_opts__set_default(&etm->synth_opts, in cs_etm__process_auxtrace_info_full()
3337 session->itrace_synth_opts->default_no_sample); in cs_etm__process_auxtrace_info_full()
3338 etm->synth_opts.callchain = false; in cs_etm__process_auxtrace_info_full()
3341 etm->session = session; in cs_etm__process_auxtrace_info_full()
3343 etm->num_cpu = num_cpu; in cs_etm__process_auxtrace_info_full()
3344 etm->pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); in cs_etm__process_auxtrace_info_full()
3345 etm->snapshot_mode = (ptr[CS_ETM_SNAPSHOT] != 0); in cs_etm__process_auxtrace_info_full()
3346 etm->metadata = metadata; in cs_etm__process_auxtrace_info_full()
3347 etm->auxtrace_type = auxtrace_info->type; in cs_etm__process_auxtrace_info_full()
3349 if (etm->synth_opts.use_timestamp) in cs_etm__process_auxtrace_info_full()
3352 * therefore the decoder cannot know if the timestamp trace is in cs_etm__process_auxtrace_info_full()
3359 etm->has_virtual_ts = true; in cs_etm__process_auxtrace_info_full()
3362 etm->has_virtual_ts = cs_etm__has_virtual_ts(metadata, num_cpu); in cs_etm__process_auxtrace_info_full()
3364 if (!etm->has_virtual_ts) in cs_etm__process_auxtrace_info_full()
3369 "if the Coresight timestamp on the platform is same with the kernel time.\n\n"); in cs_etm__process_auxtrace_info_full()
3371 etm->auxtrace.process_event = cs_etm__process_event; in cs_etm__process_auxtrace_info_full()
3372 etm->auxtrace.process_auxtrace_event = cs_etm__process_auxtrace_event; in cs_etm__process_auxtrace_info_full()
3373 etm->auxtrace.flush_events = cs_etm__flush_events; in cs_etm__process_auxtrace_info_full()
3374 etm->auxtrace.free_events = cs_etm__free_events; in cs_etm__process_auxtrace_info_full()
3375 etm->auxtrace.free = cs_etm__free; in cs_etm__process_auxtrace_info_full()
3376 etm->auxtrace.evsel_is_auxtrace = cs_etm__evsel_is_auxtrace; in cs_etm__process_auxtrace_info_full()
3377 session->auxtrace = &etm->auxtrace; in cs_etm__process_auxtrace_info_full()
3383 etm->tc.time_shift = tc->time_shift; in cs_etm__process_auxtrace_info_full()
3384 etm->tc.time_mult = tc->time_mult; in cs_etm__process_auxtrace_info_full()
3385 etm->tc.time_zero = tc->time_zero; in cs_etm__process_auxtrace_info_full()
3387 etm->tc.time_cycles = tc->time_cycles; in cs_etm__process_auxtrace_info_full()
3388 etm->tc.time_mask = tc->time_mask; in cs_etm__process_auxtrace_info_full()
3389 etm->tc.cap_user_time_zero = tc->cap_user_time_zero; in cs_etm__process_auxtrace_info_full()
3390 etm->tc.cap_user_time_short = tc->cap_user_time_short; in cs_etm__process_auxtrace_info_full()
3404 * the same IDs as the old algorithm as far as is possible, unless there are clashes in cs_etm__process_auxtrace_info_full()
3411 * value CORESIGHT_TRACE_ID_UNUSED_VAL - which indicates no decoder is required. in cs_etm__process_auxtrace_info_full()
3413 * If no AUX_HW_ID packets are present - which means a file recorded on an old kernel in cs_etm__process_auxtrace_info_full()
3414 * then we map Trace ID values to CPU directly from the metadata - clearing any unused in cs_etm__process_auxtrace_info_full()
3420 err = perf_session__peek_events(session, session->header.data_offset, in cs_etm__process_auxtrace_info_full()
3421 session->header.data_size, in cs_etm__process_auxtrace_info_full()
3429 /* otherwise, this is a file with metadata values only, map from metadata */ in cs_etm__process_auxtrace_info_full()
3440 etm->data_queued = etm->queues.populated; in cs_etm__process_auxtrace_info_full()
3444 auxtrace_queues__free(&etm->queues); in cs_etm__process_auxtrace_info_full()
3445 session->auxtrace = NULL; in cs_etm__process_auxtrace_info_full()
3449 /* No need to check @metadata[j], free(NULL) is supported */ in cs_etm__process_auxtrace_info_full()