1 // SPDX-License-Identifier: GPL-2.0
3 * Arm Statistical Profiling Extensions (SPE) support
4 * Copyright (c) 2017-2018, Arm Ltd.
11 #include <linux/bitops.h>
12 #include <linux/kernel.h>
13 #include <linux/log2.h>
14 #include <linux/types.h>
15 #include <linux/zalloc.h>
28 #include "thread-stack.h"
31 #include "util/synthetic-events.h"
34 #include "arm-spe-decoder/arm-spe-decoder.h"
35 #include "arm-spe-decoder/arm-spe-pkt-decoder.h"
37 #define MAX_TIMESTAMP (~0ULL)
40 struct auxtrace auxtrace;
41 struct auxtrace_queues queues;
42 struct auxtrace_heap heap;
43 struct itrace_synth_opts synth_opts;
45 struct perf_session *session;
46 struct machine *machine;
49 struct perf_tsc_conversion tc;
58 u8 sample_remote_access;
73 unsigned long num_events;
76 struct arm_spe_queue {
78 unsigned int queue_nr;
79 struct auxtrace_buffer *buffer;
80 struct auxtrace_buffer *old_buffer;
81 union perf_event *event_buf;
87 struct arm_spe_decoder *decoder;
90 struct thread *thread;
93 static void arm_spe_dump(struct arm_spe *spe __maybe_unused,
94 unsigned char *buf, size_t len)
96 struct arm_spe_pkt packet;
99 char desc[ARM_SPE_PKT_DESC_MAX];
100 const char *color = PERF_COLOR_BLUE;
102 color_fprintf(stdout, color,
103 ". ... ARM SPE data: size %zu bytes\n",
107 ret = arm_spe_get_packet(buf, len, &packet);
113 color_fprintf(stdout, color, " %08x: ", pos);
114 for (i = 0; i < pkt_len; i++)
115 color_fprintf(stdout, color, " %02x", buf[i]);
117 color_fprintf(stdout, color, " ");
119 ret = arm_spe_pkt_desc(&packet, desc,
120 ARM_SPE_PKT_DESC_MAX);
122 color_fprintf(stdout, color, " %s\n", desc);
124 color_fprintf(stdout, color, " Bad packet!\n");
132 static void arm_spe_dump_event(struct arm_spe *spe, unsigned char *buf,
136 arm_spe_dump(spe, buf, len);
139 static int arm_spe_get_trace(struct arm_spe_buffer *b, void *data)
141 struct arm_spe_queue *speq = data;
142 struct auxtrace_buffer *buffer = speq->buffer;
143 struct auxtrace_buffer *old_buffer = speq->old_buffer;
144 struct auxtrace_queue *queue;
146 queue = &speq->spe->queues.queue_array[speq->queue_nr];
148 buffer = auxtrace_buffer__next(queue, buffer);
149 /* If no more data, drop the previous auxtrace_buffer and return */
152 auxtrace_buffer__drop_data(old_buffer);
157 speq->buffer = buffer;
159 /* If the aux_buffer doesn't have data associated, try to load it */
161 /* get the file desc associated with the perf data file */
162 int fd = perf_data__fd(speq->spe->session->data);
164 buffer->data = auxtrace_buffer__get_data(buffer, fd);
169 b->len = buffer->size;
170 b->buf = buffer->data;
174 auxtrace_buffer__drop_data(old_buffer);
175 speq->old_buffer = buffer;
177 auxtrace_buffer__drop_data(buffer);
178 return arm_spe_get_trace(b, data);
184 static struct arm_spe_queue *arm_spe__alloc_queue(struct arm_spe *spe,
185 unsigned int queue_nr)
187 struct arm_spe_params params = { .get_trace = 0, };
188 struct arm_spe_queue *speq;
190 speq = zalloc(sizeof(*speq));
194 speq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE);
195 if (!speq->event_buf)
199 speq->queue_nr = queue_nr;
205 params.get_trace = arm_spe_get_trace;
208 /* create new decoder */
209 speq->decoder = arm_spe_decoder_new(¶ms);
216 zfree(&speq->event_buf);
222 static inline u8 arm_spe_cpumode(struct arm_spe *spe, u64 ip)
224 return ip >= spe->kernel_start ?
225 PERF_RECORD_MISC_KERNEL :
226 PERF_RECORD_MISC_USER;
229 static void arm_spe_prep_sample(struct arm_spe *spe,
230 struct arm_spe_queue *speq,
231 union perf_event *event,
232 struct perf_sample *sample)
234 struct arm_spe_record *record = &speq->decoder->record;
236 if (!spe->timeless_decoding)
237 sample->time = tsc_to_perf_time(record->timestamp, &spe->tc);
239 sample->ip = record->from_ip;
240 sample->cpumode = arm_spe_cpumode(spe, sample->ip);
241 sample->pid = speq->pid;
242 sample->tid = speq->tid;
244 sample->cpu = speq->cpu;
246 event->sample.header.type = PERF_RECORD_SAMPLE;
247 event->sample.header.misc = sample->cpumode;
248 event->sample.header.size = sizeof(struct perf_event_header);
252 arm_spe_deliver_synth_event(struct arm_spe *spe,
253 struct arm_spe_queue *speq __maybe_unused,
254 union perf_event *event,
255 struct perf_sample *sample)
259 ret = perf_session__deliver_synth_event(spe->session, event, sample);
261 pr_err("ARM SPE: failed to deliver event, error %d\n", ret);
266 static int arm_spe__synth_mem_sample(struct arm_spe_queue *speq,
267 u64 spe_events_id, u64 data_src)
269 struct arm_spe *spe = speq->spe;
270 struct arm_spe_record *record = &speq->decoder->record;
271 union perf_event *event = speq->event_buf;
272 struct perf_sample sample = { .ip = 0, };
274 arm_spe_prep_sample(spe, speq, event, &sample);
276 sample.id = spe_events_id;
277 sample.stream_id = spe_events_id;
278 sample.addr = record->virt_addr;
279 sample.phys_addr = record->phys_addr;
280 sample.data_src = data_src;
282 return arm_spe_deliver_synth_event(spe, speq, event, &sample);
285 static int arm_spe__synth_branch_sample(struct arm_spe_queue *speq,
288 struct arm_spe *spe = speq->spe;
289 struct arm_spe_record *record = &speq->decoder->record;
290 union perf_event *event = speq->event_buf;
291 struct perf_sample sample = { .ip = 0, };
293 arm_spe_prep_sample(spe, speq, event, &sample);
295 sample.id = spe_events_id;
296 sample.stream_id = spe_events_id;
297 sample.addr = record->to_ip;
299 return arm_spe_deliver_synth_event(spe, speq, event, &sample);
302 #define SPE_MEM_TYPE (ARM_SPE_L1D_ACCESS | ARM_SPE_L1D_MISS | \
303 ARM_SPE_LLC_ACCESS | ARM_SPE_LLC_MISS | \
304 ARM_SPE_REMOTE_ACCESS)
306 static bool arm_spe__is_memory_event(enum arm_spe_sample_type type)
308 if (type & SPE_MEM_TYPE)
314 static u64 arm_spe__synth_data_source(const struct arm_spe_record *record)
316 union perf_mem_data_src data_src = { 0 };
318 if (record->op == ARM_SPE_LD)
319 data_src.mem_op = PERF_MEM_OP_LOAD;
321 data_src.mem_op = PERF_MEM_OP_STORE;
323 if (record->type & (ARM_SPE_LLC_ACCESS | ARM_SPE_LLC_MISS)) {
324 data_src.mem_lvl = PERF_MEM_LVL_L3;
326 if (record->type & ARM_SPE_LLC_MISS)
327 data_src.mem_lvl |= PERF_MEM_LVL_MISS;
329 data_src.mem_lvl |= PERF_MEM_LVL_HIT;
330 } else if (record->type & (ARM_SPE_L1D_ACCESS | ARM_SPE_L1D_MISS)) {
331 data_src.mem_lvl = PERF_MEM_LVL_L1;
333 if (record->type & ARM_SPE_L1D_MISS)
334 data_src.mem_lvl |= PERF_MEM_LVL_MISS;
336 data_src.mem_lvl |= PERF_MEM_LVL_HIT;
339 if (record->type & ARM_SPE_REMOTE_ACCESS)
340 data_src.mem_lvl |= PERF_MEM_LVL_REM_CCE1;
342 if (record->type & (ARM_SPE_TLB_ACCESS | ARM_SPE_TLB_MISS)) {
343 data_src.mem_dtlb = PERF_MEM_TLB_WK;
345 if (record->type & ARM_SPE_TLB_MISS)
346 data_src.mem_dtlb |= PERF_MEM_TLB_MISS;
348 data_src.mem_dtlb |= PERF_MEM_TLB_HIT;
354 static int arm_spe_sample(struct arm_spe_queue *speq)
356 const struct arm_spe_record *record = &speq->decoder->record;
357 struct arm_spe *spe = speq->spe;
361 data_src = arm_spe__synth_data_source(record);
363 if (spe->sample_flc) {
364 if (record->type & ARM_SPE_L1D_MISS) {
365 err = arm_spe__synth_mem_sample(speq, spe->l1d_miss_id,
371 if (record->type & ARM_SPE_L1D_ACCESS) {
372 err = arm_spe__synth_mem_sample(speq, spe->l1d_access_id,
379 if (spe->sample_llc) {
380 if (record->type & ARM_SPE_LLC_MISS) {
381 err = arm_spe__synth_mem_sample(speq, spe->llc_miss_id,
387 if (record->type & ARM_SPE_LLC_ACCESS) {
388 err = arm_spe__synth_mem_sample(speq, spe->llc_access_id,
395 if (spe->sample_tlb) {
396 if (record->type & ARM_SPE_TLB_MISS) {
397 err = arm_spe__synth_mem_sample(speq, spe->tlb_miss_id,
403 if (record->type & ARM_SPE_TLB_ACCESS) {
404 err = arm_spe__synth_mem_sample(speq, spe->tlb_access_id,
411 if (spe->sample_branch && (record->type & ARM_SPE_BRANCH_MISS)) {
412 err = arm_spe__synth_branch_sample(speq, spe->branch_miss_id);
417 if (spe->sample_remote_access &&
418 (record->type & ARM_SPE_REMOTE_ACCESS)) {
419 err = arm_spe__synth_mem_sample(speq, spe->remote_access_id,
425 if (spe->sample_memory && arm_spe__is_memory_event(record->type)) {
426 err = arm_spe__synth_mem_sample(speq, spe->memory_id, data_src);
434 static int arm_spe_run_decoder(struct arm_spe_queue *speq, u64 *timestamp)
436 struct arm_spe *spe = speq->spe;
437 struct arm_spe_record *record;
440 if (!spe->kernel_start)
441 spe->kernel_start = machine__kernel_start(spe->machine);
445 * The usual logic is firstly to decode the packets, and then
446 * based the record to synthesize sample; but here the flow is
447 * reversed: it calls arm_spe_sample() for synthesizing samples
448 * prior to arm_spe_decode().
450 * Two reasons for this code logic:
451 * 1. Firstly, when setup queue in arm_spe__setup_queue(), it
452 * has decoded trace data and generated a record, but the record
453 * is left to generate sample until run to here, so it's correct
454 * to synthesize sample for the left record.
455 * 2. After decoding trace data, it needs to compare the record
456 * timestamp with the coming perf event, if the record timestamp
457 * is later than the perf event, it needs bail out and pushs the
458 * record into auxtrace heap, thus the record can be deferred to
459 * synthesize sample until run to here at the next time; so this
460 * can correlate samples between Arm SPE trace data and other
461 * perf events with correct time ordering.
463 ret = arm_spe_sample(speq);
467 ret = arm_spe_decode(speq->decoder);
469 pr_debug("No data or all data has been processed.\n");
474 * Error is detected when decode SPE trace data, continue to
475 * the next trace data and find out more records.
480 record = &speq->decoder->record;
482 /* Update timestamp for the last record */
483 if (record->timestamp > speq->timestamp)
484 speq->timestamp = record->timestamp;
487 * If the timestamp of the queue is later than timestamp of the
488 * coming perf event, bail out so can allow the perf event to
489 * be processed ahead.
491 if (!spe->timeless_decoding && speq->timestamp >= *timestamp) {
492 *timestamp = speq->timestamp;
500 static int arm_spe__setup_queue(struct arm_spe *spe,
501 struct auxtrace_queue *queue,
502 unsigned int queue_nr)
504 struct arm_spe_queue *speq = queue->priv;
505 struct arm_spe_record *record;
507 if (list_empty(&queue->head) || speq)
510 speq = arm_spe__alloc_queue(spe, queue_nr);
517 if (queue->cpu != -1)
518 speq->cpu = queue->cpu;
520 if (!speq->on_heap) {
523 if (spe->timeless_decoding)
527 ret = arm_spe_decode(speq->decoder);
535 record = &speq->decoder->record;
537 speq->timestamp = record->timestamp;
538 ret = auxtrace_heap__add(&spe->heap, queue_nr, speq->timestamp);
541 speq->on_heap = true;
547 static int arm_spe__setup_queues(struct arm_spe *spe)
552 for (i = 0; i < spe->queues.nr_queues; i++) {
553 ret = arm_spe__setup_queue(spe, &spe->queues.queue_array[i], i);
561 static int arm_spe__update_queues(struct arm_spe *spe)
563 if (spe->queues.new_data) {
564 spe->queues.new_data = false;
565 return arm_spe__setup_queues(spe);
571 static bool arm_spe__is_timeless_decoding(struct arm_spe *spe)
574 struct evlist *evlist = spe->session->evlist;
575 bool timeless_decoding = true;
578 * Circle through the list of event and complain if we find one
579 * with the time bit set.
581 evlist__for_each_entry(evlist, evsel) {
582 if ((evsel->core.attr.sample_type & PERF_SAMPLE_TIME))
583 timeless_decoding = false;
586 return timeless_decoding;
589 static void arm_spe_set_pid_tid_cpu(struct arm_spe *spe,
590 struct auxtrace_queue *queue)
592 struct arm_spe_queue *speq = queue->priv;
595 tid = machine__get_current_tid(spe->machine, speq->cpu);
598 thread__zput(speq->thread);
600 speq->tid = queue->tid;
602 if ((!speq->thread) && (speq->tid != -1)) {
603 speq->thread = machine__find_thread(spe->machine, -1,
608 speq->pid = speq->thread->pid_;
609 if (queue->cpu == -1)
610 speq->cpu = speq->thread->cpu;
614 static int arm_spe_process_queues(struct arm_spe *spe, u64 timestamp)
616 unsigned int queue_nr;
621 struct auxtrace_queue *queue;
622 struct arm_spe_queue *speq;
624 if (!spe->heap.heap_cnt)
627 if (spe->heap.heap_array[0].ordinal >= timestamp)
630 queue_nr = spe->heap.heap_array[0].queue_nr;
631 queue = &spe->queues.queue_array[queue_nr];
634 auxtrace_heap__pop(&spe->heap);
636 if (spe->heap.heap_cnt) {
637 ts = spe->heap.heap_array[0].ordinal + 1;
644 arm_spe_set_pid_tid_cpu(spe, queue);
646 ret = arm_spe_run_decoder(speq, &ts);
648 auxtrace_heap__add(&spe->heap, queue_nr, ts);
653 ret = auxtrace_heap__add(&spe->heap, queue_nr, ts);
657 speq->on_heap = false;
664 static int arm_spe_process_timeless_queues(struct arm_spe *spe, pid_t tid,
667 struct auxtrace_queues *queues = &spe->queues;
671 for (i = 0; i < queues->nr_queues; i++) {
672 struct auxtrace_queue *queue = &spe->queues.queue_array[i];
673 struct arm_spe_queue *speq = queue->priv;
675 if (speq && (tid == -1 || speq->tid == tid)) {
677 arm_spe_set_pid_tid_cpu(spe, queue);
678 arm_spe_run_decoder(speq, &ts);
684 static int arm_spe_process_event(struct perf_session *session,
685 union perf_event *event,
686 struct perf_sample *sample,
687 struct perf_tool *tool)
691 struct arm_spe *spe = container_of(session->auxtrace,
692 struct arm_spe, auxtrace);
697 if (!tool->ordered_events) {
698 pr_err("SPE trace requires ordered events\n");
702 if (sample->time && (sample->time != (u64) -1))
703 timestamp = perf_time_to_tsc(sample->time, &spe->tc);
707 if (timestamp || spe->timeless_decoding) {
708 err = arm_spe__update_queues(spe);
713 if (spe->timeless_decoding) {
714 if (event->header.type == PERF_RECORD_EXIT) {
715 err = arm_spe_process_timeless_queues(spe,
719 } else if (timestamp) {
720 err = arm_spe_process_queues(spe, timestamp);
726 static int arm_spe_process_auxtrace_event(struct perf_session *session,
727 union perf_event *event,
728 struct perf_tool *tool __maybe_unused)
730 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe,
733 if (!spe->data_queued) {
734 struct auxtrace_buffer *buffer;
736 int fd = perf_data__fd(session->data);
739 if (perf_data__is_pipe(session->data)) {
742 data_offset = lseek(fd, 0, SEEK_CUR);
743 if (data_offset == -1)
747 err = auxtrace_queues__add_event(&spe->queues, session, event,
748 data_offset, &buffer);
752 /* Dump here now we have copied a piped trace out of the pipe */
754 if (auxtrace_buffer__get_data(buffer, fd)) {
755 arm_spe_dump_event(spe, buffer->data,
757 auxtrace_buffer__put_data(buffer);
765 static int arm_spe_flush(struct perf_session *session __maybe_unused,
766 struct perf_tool *tool __maybe_unused)
768 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe,
775 if (!tool->ordered_events)
778 ret = arm_spe__update_queues(spe);
782 if (spe->timeless_decoding)
783 return arm_spe_process_timeless_queues(spe, -1,
786 return arm_spe_process_queues(spe, MAX_TIMESTAMP);
789 static void arm_spe_free_queue(void *priv)
791 struct arm_spe_queue *speq = priv;
795 thread__zput(speq->thread);
796 arm_spe_decoder_free(speq->decoder);
797 zfree(&speq->event_buf);
801 static void arm_spe_free_events(struct perf_session *session)
803 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe,
805 struct auxtrace_queues *queues = &spe->queues;
808 for (i = 0; i < queues->nr_queues; i++) {
809 arm_spe_free_queue(queues->queue_array[i].priv);
810 queues->queue_array[i].priv = NULL;
812 auxtrace_queues__free(queues);
815 static void arm_spe_free(struct perf_session *session)
817 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe,
820 auxtrace_heap__free(&spe->heap);
821 arm_spe_free_events(session);
822 session->auxtrace = NULL;
826 static bool arm_spe_evsel_is_auxtrace(struct perf_session *session,
829 struct arm_spe *spe = container_of(session->auxtrace, struct arm_spe, auxtrace);
831 return evsel->core.attr.type == spe->pmu_type;
834 static const char * const arm_spe_info_fmts[] = {
835 [ARM_SPE_PMU_TYPE] = " PMU Type %"PRId64"\n",
838 static void arm_spe_print_info(__u64 *arr)
843 fprintf(stdout, arm_spe_info_fmts[ARM_SPE_PMU_TYPE], arr[ARM_SPE_PMU_TYPE]);
846 struct arm_spe_synth {
847 struct perf_tool dummy_tool;
848 struct perf_session *session;
851 static int arm_spe_event_synth(struct perf_tool *tool,
852 union perf_event *event,
853 struct perf_sample *sample __maybe_unused,
854 struct machine *machine __maybe_unused)
856 struct arm_spe_synth *arm_spe_synth =
857 container_of(tool, struct arm_spe_synth, dummy_tool);
859 return perf_session__deliver_synth_event(arm_spe_synth->session,
863 static int arm_spe_synth_event(struct perf_session *session,
864 struct perf_event_attr *attr, u64 id)
866 struct arm_spe_synth arm_spe_synth;
868 memset(&arm_spe_synth, 0, sizeof(struct arm_spe_synth));
869 arm_spe_synth.session = session;
871 return perf_event__synthesize_attr(&arm_spe_synth.dummy_tool, attr, 1,
872 &id, arm_spe_event_synth);
875 static void arm_spe_set_event_name(struct evlist *evlist, u64 id,
880 evlist__for_each_entry(evlist, evsel) {
881 if (evsel->core.id && evsel->core.id[0] == id) {
884 evsel->name = strdup(name);
891 arm_spe_synth_events(struct arm_spe *spe, struct perf_session *session)
893 struct evlist *evlist = session->evlist;
895 struct perf_event_attr attr;
900 evlist__for_each_entry(evlist, evsel) {
901 if (evsel->core.attr.type == spe->pmu_type) {
908 pr_debug("No selected events with SPE trace data\n");
912 memset(&attr, 0, sizeof(struct perf_event_attr));
913 attr.size = sizeof(struct perf_event_attr);
914 attr.type = PERF_TYPE_HARDWARE;
915 attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK;
916 attr.sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID |
917 PERF_SAMPLE_PERIOD | PERF_SAMPLE_DATA_SRC;
918 if (spe->timeless_decoding)
919 attr.sample_type &= ~(u64)PERF_SAMPLE_TIME;
921 attr.sample_type |= PERF_SAMPLE_TIME;
923 attr.exclude_user = evsel->core.attr.exclude_user;
924 attr.exclude_kernel = evsel->core.attr.exclude_kernel;
925 attr.exclude_hv = evsel->core.attr.exclude_hv;
926 attr.exclude_host = evsel->core.attr.exclude_host;
927 attr.exclude_guest = evsel->core.attr.exclude_guest;
928 attr.sample_id_all = evsel->core.attr.sample_id_all;
929 attr.read_format = evsel->core.attr.read_format;
931 /* create new id val to be a fixed offset from evsel id */
932 id = evsel->core.id[0] + 1000000000;
937 if (spe->synth_opts.flc) {
938 spe->sample_flc = true;
940 /* Level 1 data cache miss */
941 err = arm_spe_synth_event(session, &attr, id);
944 spe->l1d_miss_id = id;
945 arm_spe_set_event_name(evlist, id, "l1d-miss");
948 /* Level 1 data cache access */
949 err = arm_spe_synth_event(session, &attr, id);
952 spe->l1d_access_id = id;
953 arm_spe_set_event_name(evlist, id, "l1d-access");
957 if (spe->synth_opts.llc) {
958 spe->sample_llc = true;
960 /* Last level cache miss */
961 err = arm_spe_synth_event(session, &attr, id);
964 spe->llc_miss_id = id;
965 arm_spe_set_event_name(evlist, id, "llc-miss");
968 /* Last level cache access */
969 err = arm_spe_synth_event(session, &attr, id);
972 spe->llc_access_id = id;
973 arm_spe_set_event_name(evlist, id, "llc-access");
977 if (spe->synth_opts.tlb) {
978 spe->sample_tlb = true;
981 err = arm_spe_synth_event(session, &attr, id);
984 spe->tlb_miss_id = id;
985 arm_spe_set_event_name(evlist, id, "tlb-miss");
989 err = arm_spe_synth_event(session, &attr, id);
992 spe->tlb_access_id = id;
993 arm_spe_set_event_name(evlist, id, "tlb-access");
997 if (spe->synth_opts.branches) {
998 spe->sample_branch = true;
1001 err = arm_spe_synth_event(session, &attr, id);
1004 spe->branch_miss_id = id;
1005 arm_spe_set_event_name(evlist, id, "branch-miss");
1009 if (spe->synth_opts.remote_access) {
1010 spe->sample_remote_access = true;
1013 err = arm_spe_synth_event(session, &attr, id);
1016 spe->remote_access_id = id;
1017 arm_spe_set_event_name(evlist, id, "remote-access");
1021 if (spe->synth_opts.mem) {
1022 spe->sample_memory = true;
1024 err = arm_spe_synth_event(session, &attr, id);
1027 spe->memory_id = id;
1028 arm_spe_set_event_name(evlist, id, "memory");
1034 int arm_spe_process_auxtrace_info(union perf_event *event,
1035 struct perf_session *session)
1037 struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info;
1038 size_t min_sz = sizeof(u64) * ARM_SPE_AUXTRACE_PRIV_MAX;
1039 struct perf_record_time_conv *tc = &session->time_conv;
1040 struct arm_spe *spe;
1043 if (auxtrace_info->header.size < sizeof(struct perf_record_auxtrace_info) +
1047 spe = zalloc(sizeof(struct arm_spe));
1051 err = auxtrace_queues__init(&spe->queues);
1055 spe->session = session;
1056 spe->machine = &session->machines.host; /* No kvm support */
1057 spe->auxtrace_type = auxtrace_info->type;
1058 spe->pmu_type = auxtrace_info->priv[ARM_SPE_PMU_TYPE];
1060 spe->timeless_decoding = arm_spe__is_timeless_decoding(spe);
1063 * The synthesized event PERF_RECORD_TIME_CONV has been handled ahead
1064 * and the parameters for hardware clock are stored in the session
1065 * context. Passes these parameters to the struct perf_tsc_conversion
1066 * in "spe->tc", which is used for later conversion between clock
1067 * counter and timestamp.
1069 * For backward compatibility, copies the fields starting from
1070 * "time_cycles" only if they are contained in the event.
1072 spe->tc.time_shift = tc->time_shift;
1073 spe->tc.time_mult = tc->time_mult;
1074 spe->tc.time_zero = tc->time_zero;
1076 if (event_contains(*tc, time_cycles)) {
1077 spe->tc.time_cycles = tc->time_cycles;
1078 spe->tc.time_mask = tc->time_mask;
1079 spe->tc.cap_user_time_zero = tc->cap_user_time_zero;
1080 spe->tc.cap_user_time_short = tc->cap_user_time_short;
1083 spe->auxtrace.process_event = arm_spe_process_event;
1084 spe->auxtrace.process_auxtrace_event = arm_spe_process_auxtrace_event;
1085 spe->auxtrace.flush_events = arm_spe_flush;
1086 spe->auxtrace.free_events = arm_spe_free_events;
1087 spe->auxtrace.free = arm_spe_free;
1088 spe->auxtrace.evsel_is_auxtrace = arm_spe_evsel_is_auxtrace;
1089 session->auxtrace = &spe->auxtrace;
1091 arm_spe_print_info(&auxtrace_info->priv[0]);
1096 if (session->itrace_synth_opts && session->itrace_synth_opts->set)
1097 spe->synth_opts = *session->itrace_synth_opts;
1099 itrace_synth_opts__set_default(&spe->synth_opts, false);
1101 err = arm_spe_synth_events(spe, session);
1103 goto err_free_queues;
1105 err = auxtrace_queues__process_index(&spe->queues, session);
1107 goto err_free_queues;
1109 if (spe->queues.populated)
1110 spe->data_queued = true;
1115 auxtrace_queues__free(&spe->queues);
1116 session->auxtrace = NULL;