Lines Matching +full:sample +full:- +full:time

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2013-2015, Intel Corporation.
28 #include "thread-stack.h"
35 #include "intel-pt.h"
38 #include "util/synthetic-events.h"
39 #include "time-utils.h"
43 #include "intel-pt-decoder/intel-pt-log.h"
44 #include "intel-pt-decoder/intel-pt-decoder.h"
45 #include "intel-pt-decoder/intel-pt-insn-decoder.h"
46 #include "intel-pt-decoder/intel-pt-pkt-decoder.h"
172 /* applicable_counters is 64-bits */
210 u64 time; member
267 len -= pkt_len; in intel_pt_dump()
289 struct perf_sample *sample) in intel_pt_dump_sample() argument
291 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_dump_sample()
295 intel_pt_dump(pt, sample->aux_sample.data, sample->aux_sample.size); in intel_pt_dump_sample()
300 struct perf_time_interval *range = pt->synth_opts.ptime_range; in intel_pt_log_events()
301 int n = pt->synth_opts.range_num; in intel_pt_log_events()
303 if (pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_ALL_PERF_EVTS) in intel_pt_log_events()
306 if (pt->synth_opts.log_minus_flags & AUXTRACE_LOG_FLG_ALL_PERF_EVTS) in intel_pt_log_events()
309 /* perf_time__ranges_skip_sample does not work if time is zero */ in intel_pt_log_events()
320 struct rb_node **p = &rb_root->rb_node; in intel_pt_findnew_vmcs()
328 if (v->vmcs == vmcs) in intel_pt_findnew_vmcs()
331 if (vmcs < v->vmcs) in intel_pt_findnew_vmcs()
332 p = &(*p)->rb_left; in intel_pt_findnew_vmcs()
334 p = &(*p)->rb_right; in intel_pt_findnew_vmcs()
339 v->vmcs = vmcs; in intel_pt_findnew_vmcs()
340 v->tsc_offset = dflt_tsc_offset; in intel_pt_findnew_vmcs()
341 v->reliable = dflt_tsc_offset; in intel_pt_findnew_vmcs()
343 rb_link_node(&v->rb_node, parent, p); in intel_pt_findnew_vmcs()
344 rb_insert_color(&v->rb_node, rb_root); in intel_pt_findnew_vmcs()
353 struct intel_pt *pt = ptq->pt; in intel_pt_findnew_vmcs_info()
355 if (!vmcs && !pt->dflt_tsc_offset) in intel_pt_findnew_vmcs_info()
358 return intel_pt_findnew_vmcs(&pt->vmcs_info, vmcs, pt->dflt_tsc_offset); in intel_pt_findnew_vmcs_info()
366 n = rb_first(&pt->vmcs_info); in intel_pt_free_vmcs_info()
370 rb_erase(&v->rb_node, &pt->vmcs_info); in intel_pt_free_vmcs_info()
381 start = intel_pt_find_overlap(a->data, a->size, b->data, b->size, in intel_pt_do_fix_overlap()
382 pt->have_tsc, &consecutive, in intel_pt_do_fix_overlap()
383 pt->synth_opts.vm_time_correlation); in intel_pt_do_fix_overlap()
385 return -EINVAL; in intel_pt_do_fix_overlap()
391 if (pt->synth_opts.vm_time_correlation) in intel_pt_do_fix_overlap()
392 memset(b->data, 0, start - b->data); in intel_pt_do_fix_overlap()
393 b->use_size = b->data + b->size - start; in intel_pt_do_fix_overlap()
394 b->use_data = start; in intel_pt_do_fix_overlap()
395 if (b->use_size && consecutive) in intel_pt_do_fix_overlap()
396 b->consecutive = true; in intel_pt_do_fix_overlap()
407 if (!buffer->data) { in intel_pt_get_buffer()
408 int fd = perf_data__fd(ptq->pt->session->data); in intel_pt_get_buffer()
410 buffer->data = auxtrace_buffer__get_data(buffer, fd); in intel_pt_get_buffer()
411 if (!buffer->data) in intel_pt_get_buffer()
412 return -ENOMEM; in intel_pt_get_buffer()
415 might_overlap = ptq->pt->snapshot_mode || ptq->pt->sampling_mode; in intel_pt_get_buffer()
416 if (might_overlap && !buffer->consecutive && old_buffer && in intel_pt_get_buffer()
417 intel_pt_do_fix_overlap(ptq->pt, old_buffer, buffer)) in intel_pt_get_buffer()
418 return -ENOMEM; in intel_pt_get_buffer()
420 if (buffer->use_data) { in intel_pt_get_buffer()
421 b->len = buffer->use_size; in intel_pt_get_buffer()
422 b->buf = buffer->use_data; in intel_pt_get_buffer()
424 b->len = buffer->size; in intel_pt_get_buffer()
425 b->buf = buffer->data; in intel_pt_get_buffer()
427 b->ref_timestamp = buffer->reference; in intel_pt_get_buffer()
429 if (!old_buffer || (might_overlap && !buffer->consecutive)) { in intel_pt_get_buffer()
430 b->consecutive = false; in intel_pt_get_buffer()
431 b->trace_nr = buffer->buffer_nr + 1; in intel_pt_get_buffer()
433 b->consecutive = true; in intel_pt_get_buffer()
439 /* Do not drop buffers with references - refer intel_pt_get_trace() */
443 if (!buffer || buffer == ptq->buffer || buffer == ptq->old_buffer) in intel_pt_lookahead_drop_buffer()
454 struct auxtrace_buffer *buffer = ptq->buffer; in intel_pt_lookahead()
455 struct auxtrace_buffer *old_buffer = ptq->old_buffer; in intel_pt_lookahead()
459 queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; in intel_pt_lookahead()
499 struct auxtrace_buffer *buffer = ptq->buffer; in intel_pt_get_trace()
500 struct auxtrace_buffer *old_buffer = ptq->old_buffer; in intel_pt_get_trace()
504 if (ptq->stop) { in intel_pt_get_trace()
505 b->len = 0; in intel_pt_get_trace()
509 queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; in intel_pt_get_trace()
515 b->len = 0; in intel_pt_get_trace()
519 ptq->buffer = buffer; in intel_pt_get_trace()
525 if (ptq->step_through_buffers) in intel_pt_get_trace()
526 ptq->stop = true; in intel_pt_get_trace()
528 if (b->len) { in intel_pt_get_trace()
531 ptq->old_buffer = buffer; in intel_pt_get_trace()
557 if (!strcmp(var, "intel-pt.cache-divisor")) { in intel_pt_config_div()
592 return 32 - __builtin_clz(size); in intel_pt_cache_size()
623 return -ENOMEM; in intel_pt_cache_add()
627 return -ENOMEM; in intel_pt_cache_add()
629 e->insn_cnt = insn_cnt; in intel_pt_cache_add()
630 e->byte_cnt = byte_cnt; in intel_pt_cache_add()
631 e->op = intel_pt_insn->op; in intel_pt_cache_add()
632 e->branch = intel_pt_insn->branch; in intel_pt_cache_add()
633 e->emulated_ptwrite = intel_pt_insn->emulated_ptwrite; in intel_pt_cache_add()
634 e->length = intel_pt_insn->length; in intel_pt_cache_add()
635 e->rel = intel_pt_insn->rel; in intel_pt_cache_add()
636 memcpy(e->insn, intel_pt_insn->buf, INTEL_PT_INSN_BUF_SZ); in intel_pt_cache_add()
638 err = auxtrace_cache__add(c, offset, &e->entry); in intel_pt_cache_add()
669 /* Assumes 64-bit kernel */ in intel_pt_guest_kernel_ip()
681 return ip >= ptq->pt->kernel_start ? in intel_pt_nr_cpumode()
688 /* No support for non-zero CS base */ in intel_pt_cpumode()
690 return intel_pt_nr_cpumode(ptq, from_ip, ptq->state->from_nr); in intel_pt_cpumode()
691 return intel_pt_nr_cpumode(ptq, to_ip, ptq->state->to_nr); in intel_pt_cpumode()
696 struct machines *machines = &ptq->pt->session->machines; in intel_pt_get_guest()
698 pid_t pid = ptq->pid <= 0 ? DEFAULT_GUEST_KERNEL_ID : ptq->pid; in intel_pt_get_guest()
700 if (ptq->guest_machine && pid == ptq->guest_machine->pid) in intel_pt_get_guest()
703 ptq->guest_machine = NULL; in intel_pt_get_guest()
704 thread__zput(ptq->unknown_guest_thread); in intel_pt_get_guest()
707 thread__zput(ptq->guest_thread); in intel_pt_get_guest()
708 ptq->guest_thread = machines__findnew_guest_code(machines, pid); in intel_pt_get_guest()
713 return -1; in intel_pt_get_guest()
715 ptq->unknown_guest_thread = machine__idle_thread(machine); in intel_pt_get_guest()
716 if (!ptq->unknown_guest_thread) in intel_pt_get_guest()
717 return -1; in intel_pt_get_guest()
719 ptq->guest_machine = machine; in intel_pt_get_guest()
726 return intel_pt_insn->rel == 16 && intel_pt_insn->branch == INTEL_PT_BR_UNCONDITIONAL; in intel_pt_jmp_16()
752 struct machine *machine = ptq->pt->machine; in intel_pt_walk_next_insn()
766 intel_pt_insn->length = 0; in intel_pt_walk_next_insn()
767 intel_pt_insn->op = INTEL_PT_OP_OTHER; in intel_pt_walk_next_insn()
772 nr = ptq->state->to_nr; in intel_pt_walk_next_insn()
776 if (ptq->pt->have_guest_sideband) { in intel_pt_walk_next_insn()
777 if (!ptq->guest_machine || ptq->guest_machine_pid != ptq->pid) { in intel_pt_walk_next_insn()
779 ret = -EINVAL; in intel_pt_walk_next_insn()
785 ret = -EINVAL; in intel_pt_walk_next_insn()
788 machine = ptq->guest_machine; in intel_pt_walk_next_insn()
789 thread = ptq->guest_thread; in intel_pt_walk_next_insn()
793 ret = -EINVAL; in intel_pt_walk_next_insn()
796 thread = ptq->unknown_guest_thread; in intel_pt_walk_next_insn()
799 thread = ptq->thread; in intel_pt_walk_next_insn()
803 ret = -EINVAL; in intel_pt_walk_next_insn()
806 thread = ptq->pt->unknown_thread; in intel_pt_walk_next_insn()
819 ret = -EINVAL; in intel_pt_walk_next_insn()
824 if (dso__data(dso)->status == DSO_DATA_STATUS_ERROR && in intel_pt_walk_next_insn()
826 ret = -ENOENT; in intel_pt_walk_next_insn()
837 (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) { in intel_pt_walk_next_insn()
838 *insn_cnt_ptr = e->insn_cnt; in intel_pt_walk_next_insn()
839 *ip += e->byte_cnt; in intel_pt_walk_next_insn()
840 intel_pt_insn->op = e->op; in intel_pt_walk_next_insn()
841 intel_pt_insn->branch = e->branch; in intel_pt_walk_next_insn()
842 intel_pt_insn->emulated_ptwrite = e->emulated_ptwrite; in intel_pt_walk_next_insn()
843 intel_pt_insn->length = e->length; in intel_pt_walk_next_insn()
844 intel_pt_insn->rel = e->rel; in intel_pt_walk_next_insn()
845 memcpy(intel_pt_insn->buf, e->insn, INTEL_PT_INSN_BUF_SZ); in intel_pt_walk_next_insn()
855 /* Load maps to ensure dso->is_64_bit has been updated */ in intel_pt_walk_next_insn()
869 ret = -EINVAL; in intel_pt_walk_next_insn()
874 ret = -EINVAL; in intel_pt_walk_next_insn()
882 if (intel_pt_insn->branch != INTEL_PT_BR_NO_BRANCH) { in intel_pt_walk_next_insn()
889 offs = offset + intel_pt_insn->length; in intel_pt_walk_next_insn()
891 intel_pt_insn->emulated_ptwrite = eptw; in intel_pt_walk_next_insn()
898 *ip += intel_pt_insn->length; in intel_pt_walk_next_insn()
901 intel_pt_insn->length = 0; in intel_pt_walk_next_insn()
902 intel_pt_insn->op = INTEL_PT_OP_OTHER; in intel_pt_walk_next_insn()
909 offset += intel_pt_insn->length; in intel_pt_walk_next_insn()
933 *ip - start_ip, intel_pt_insn); in intel_pt_walk_next_insn()
953 list_for_each_entry(filt, &pt->filts.head, list) { in intel_pt_match_pgd_ip()
954 if (filt->start) in intel_pt_match_pgd_ip()
957 if ((filename && !filt->filename) || in intel_pt_match_pgd_ip()
958 (!filename && filt->filename) || in intel_pt_match_pgd_ip()
959 (filename && strcmp(filename, filt->filename))) in intel_pt_match_pgd_ip()
962 if (!(offset >= filt->addr && offset < filt->addr + filt->size)) in intel_pt_match_pgd_ip()
967 filt->start ? "filter" : "stop", in intel_pt_match_pgd_ip()
968 filt->addr, filt->size); in intel_pt_match_pgd_ip()
970 if (filt->start) in intel_pt_match_pgd_ip()
992 if (ptq->state->to_nr) { in __intel_pt_pgd_ip()
994 return intel_pt_match_pgd_ip(ptq->pt, ip, ip, NULL); in __intel_pt_pgd_ip()
996 return -EINVAL; in __intel_pt_pgd_ip()
997 } else if (ip >= ptq->pt->kernel_start) { in __intel_pt_pgd_ip()
998 return intel_pt_match_pgd_ip(ptq->pt, ip, ip, NULL); in __intel_pt_pgd_ip()
1003 thread = ptq->thread; in __intel_pt_pgd_ip()
1005 return -EINVAL; in __intel_pt_pgd_ip()
1009 return -EINVAL; in __intel_pt_pgd_ip()
1013 res = intel_pt_match_pgd_ip(ptq->pt, ip, offset, dso__long_name(map__dso(al.map))); in __intel_pt_pgd_ip()
1026 if (attr->type == pt->pmu_type) { in intel_pt_get_config()
1028 *config = attr->config; in intel_pt_get_config()
1039 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_exclude_kernel()
1040 if (intel_pt_get_config(pt, &evsel->core.attr, NULL) && in intel_pt_exclude_kernel()
1041 !evsel->core.attr.exclude_kernel) in intel_pt_exclude_kernel()
1052 if (!pt->noretcomp_bit) in intel_pt_return_compression()
1055 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_return_compression()
1056 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_return_compression()
1057 (config & pt->noretcomp_bit)) in intel_pt_return_compression()
1068 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_branch_enable()
1069 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_branch_enable()
1082 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_disabled_tnt()
1083 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_disabled_tnt()
1096 if (!pt->mtc_freq_bits) in intel_pt_mtc_period()
1099 for (shift = 0, config = pt->mtc_freq_bits; !(config & 1); shift++) in intel_pt_mtc_period()
1102 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_mtc_period()
1103 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) in intel_pt_mtc_period()
1104 return (config & pt->mtc_freq_bits) >> shift; in intel_pt_mtc_period()
1115 if (!pt->tsc_bit || !pt->cap_user_time_zero || pt->synth_opts.timeless_decoding) in intel_pt_timeless_decoding()
1118 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_timeless_decoding()
1119 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) in intel_pt_timeless_decoding()
1121 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) { in intel_pt_timeless_decoding()
1122 if (config & pt->tsc_bit) in intel_pt_timeless_decoding()
1135 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_tracing_kernel()
1136 if (intel_pt_get_config(pt, &evsel->core.attr, NULL) && in intel_pt_tracing_kernel()
1137 !evsel->core.attr.exclude_kernel) in intel_pt_tracing_kernel()
1149 if (!pt->tsc_bit) in intel_pt_have_tsc()
1152 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_have_tsc()
1153 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) { in intel_pt_have_tsc()
1154 if (config & pt->tsc_bit) in intel_pt_have_tsc()
1168 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_have_mtc()
1169 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_have_mtc()
1170 (config & pt->mtc_bit)) in intel_pt_have_mtc()
1180 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_sampling_mode()
1181 if ((evsel->core.attr.sample_type & PERF_SAMPLE_AUX) && in intel_pt_sampling_mode()
1182 evsel->core.attr.aux_sample_size) in intel_pt_sampling_mode()
1193 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_ctl()
1194 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) in intel_pt_ctl()
1204 quot = ns / pt->tc.time_mult; in intel_pt_ns_to_ticks()
1205 rem = ns % pt->tc.time_mult; in intel_pt_ns_to_ticks()
1206 return (quot << pt->tc.time_shift) + (rem << pt->tc.time_shift) / in intel_pt_ns_to_ticks()
1207 pt->tc.time_mult; in intel_pt_ns_to_ticks()
1215 sz += (pt->synth_opts.callchain_sz + 1) * sizeof(u64); in intel_pt_alloc_chain()
1223 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_callchain_init()
1224 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN)) in intel_pt_callchain_init()
1225 evsel->synth_sample_type |= PERF_SAMPLE_CALLCHAIN; in intel_pt_callchain_init()
1228 pt->chain = intel_pt_alloc_chain(pt); in intel_pt_callchain_init()
1229 if (!pt->chain) in intel_pt_callchain_init()
1230 return -ENOMEM; in intel_pt_callchain_init()
1236 struct perf_sample *sample) in intel_pt_add_callchain() argument
1238 struct thread *thread = machine__findnew_thread(pt->machine, in intel_pt_add_callchain()
1239 sample->pid, in intel_pt_add_callchain()
1240 sample->tid); in intel_pt_add_callchain()
1242 thread_stack__sample_late(thread, sample->cpu, pt->chain, in intel_pt_add_callchain()
1243 pt->synth_opts.callchain_sz + 1, sample->ip, in intel_pt_add_callchain()
1244 pt->kernel_start); in intel_pt_add_callchain()
1246 sample->callchain = pt->chain; in intel_pt_add_callchain()
1261 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_br_stack_init()
1262 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK)) in intel_pt_br_stack_init()
1263 evsel->synth_sample_type |= PERF_SAMPLE_BRANCH_STACK; in intel_pt_br_stack_init()
1266 pt->br_stack = intel_pt_alloc_br_stack(pt->br_stack_sz); in intel_pt_br_stack_init()
1267 if (!pt->br_stack) in intel_pt_br_stack_init()
1268 return -ENOMEM; in intel_pt_br_stack_init()
1274 struct perf_sample *sample) in intel_pt_add_br_stack() argument
1276 struct thread *thread = machine__findnew_thread(pt->machine, in intel_pt_add_br_stack()
1277 sample->pid, in intel_pt_add_br_stack()
1278 sample->tid); in intel_pt_add_br_stack()
1280 thread_stack__br_sample_late(thread, sample->cpu, pt->br_stack, in intel_pt_add_br_stack()
1281 pt->br_stack_sz, sample->ip, in intel_pt_add_br_stack()
1282 pt->kernel_start); in intel_pt_add_br_stack()
1284 sample->branch_stack = pt->br_stack; in intel_pt_add_br_stack()
1295 struct perf_env *env = pt->machine->env; in intel_pt_alloc_queue()
1302 if (pt->synth_opts.callchain) { in intel_pt_alloc_queue()
1303 ptq->chain = intel_pt_alloc_chain(pt); in intel_pt_alloc_queue()
1304 if (!ptq->chain) in intel_pt_alloc_queue()
1308 if (pt->synth_opts.last_branch || pt->synth_opts.other_events) { in intel_pt_alloc_queue()
1309 unsigned int entry_cnt = max(LBRS_MAX, pt->br_stack_sz); in intel_pt_alloc_queue()
1311 ptq->last_branch = intel_pt_alloc_br_stack(entry_cnt); in intel_pt_alloc_queue()
1312 if (!ptq->last_branch) in intel_pt_alloc_queue()
1316 ptq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); in intel_pt_alloc_queue()
1317 if (!ptq->event_buf) in intel_pt_alloc_queue()
1320 ptq->pt = pt; in intel_pt_alloc_queue()
1321 ptq->queue_nr = queue_nr; in intel_pt_alloc_queue()
1322 ptq->exclude_kernel = intel_pt_exclude_kernel(pt); in intel_pt_alloc_queue()
1323 ptq->pid = -1; in intel_pt_alloc_queue()
1324 ptq->tid = -1; in intel_pt_alloc_queue()
1325 ptq->cpu = -1; in intel_pt_alloc_queue()
1326 ptq->next_tid = -1; in intel_pt_alloc_queue()
1336 params.max_non_turbo_ratio = pt->max_non_turbo_ratio; in intel_pt_alloc_queue()
1338 params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n; in intel_pt_alloc_queue()
1339 params.tsc_ctc_ratio_d = pt->tsc_ctc_ratio_d; in intel_pt_alloc_queue()
1340 params.quick = pt->synth_opts.quick; in intel_pt_alloc_queue()
1341 params.vm_time_correlation = pt->synth_opts.vm_time_correlation; in intel_pt_alloc_queue()
1342 params.vm_tm_corr_dry_run = pt->synth_opts.vm_tm_corr_dry_run; in intel_pt_alloc_queue()
1343 params.first_timestamp = pt->first_timestamp; in intel_pt_alloc_queue()
1344 params.max_loops = pt->max_loops; in intel_pt_alloc_queue()
1350 if (pt->filts.cnt > 0) in intel_pt_alloc_queue()
1353 if (pt->synth_opts.instructions || pt->synth_opts.cycles) { in intel_pt_alloc_queue()
1354 if (pt->synth_opts.period) { in intel_pt_alloc_queue()
1355 switch (pt->synth_opts.period_type) { in intel_pt_alloc_queue()
1359 params.period = pt->synth_opts.period; in intel_pt_alloc_queue()
1363 params.period = pt->synth_opts.period; in intel_pt_alloc_queue()
1368 pt->synth_opts.period); in intel_pt_alloc_queue()
1381 if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18)) in intel_pt_alloc_queue()
1384 ptq->decoder = intel_pt_decoder_new(&params); in intel_pt_alloc_queue()
1385 if (!ptq->decoder) in intel_pt_alloc_queue()
1391 zfree(&ptq->event_buf); in intel_pt_alloc_queue()
1392 zfree(&ptq->last_branch); in intel_pt_alloc_queue()
1393 zfree(&ptq->chain); in intel_pt_alloc_queue()
1404 thread__zput(ptq->thread); in intel_pt_free_queue()
1405 thread__zput(ptq->guest_thread); in intel_pt_free_queue()
1406 thread__zput(ptq->unknown_guest_thread); in intel_pt_free_queue()
1407 intel_pt_decoder_free(ptq->decoder); in intel_pt_free_queue()
1408 zfree(&ptq->event_buf); in intel_pt_free_queue()
1409 zfree(&ptq->last_branch); in intel_pt_free_queue()
1410 zfree(&ptq->chain); in intel_pt_free_queue()
1418 pt->first_timestamp = timestamp; in intel_pt_first_timestamp()
1420 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_first_timestamp()
1421 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_first_timestamp()
1422 struct intel_pt_queue *ptq = queue->priv; in intel_pt_first_timestamp()
1424 if (ptq && ptq->decoder) in intel_pt_first_timestamp()
1425 intel_pt_set_first_timestamp(ptq->decoder, timestamp); in intel_pt_first_timestamp()
1431 struct machines *machines = &ptq->pt->session->machines; in intel_pt_get_guest_from_sideband()
1433 pid_t machine_pid = ptq->pid; in intel_pt_get_guest_from_sideband()
1444 if (ptq->guest_machine != machine) { in intel_pt_get_guest_from_sideband()
1445 ptq->guest_machine = NULL; in intel_pt_get_guest_from_sideband()
1446 thread__zput(ptq->guest_thread); in intel_pt_get_guest_from_sideband()
1447 thread__zput(ptq->unknown_guest_thread); in intel_pt_get_guest_from_sideband()
1449 ptq->unknown_guest_thread = machine__find_thread(machine, 0, 0); in intel_pt_get_guest_from_sideband()
1450 if (!ptq->unknown_guest_thread) in intel_pt_get_guest_from_sideband()
1451 return -1; in intel_pt_get_guest_from_sideband()
1452 ptq->guest_machine = machine; in intel_pt_get_guest_from_sideband()
1455 vcpu = ptq->thread ? thread__guest_cpu(ptq->thread) : -1; in intel_pt_get_guest_from_sideband()
1457 return -1; in intel_pt_get_guest_from_sideband()
1461 if (ptq->guest_thread && thread__tid(ptq->guest_thread) != tid) in intel_pt_get_guest_from_sideband()
1462 thread__zput(ptq->guest_thread); in intel_pt_get_guest_from_sideband()
1464 if (!ptq->guest_thread) { in intel_pt_get_guest_from_sideband()
1465 ptq->guest_thread = machine__find_thread(machine, -1, tid); in intel_pt_get_guest_from_sideband()
1466 if (!ptq->guest_thread) in intel_pt_get_guest_from_sideband()
1467 return -1; in intel_pt_get_guest_from_sideband()
1470 ptq->guest_machine_pid = machine_pid; in intel_pt_get_guest_from_sideband()
1471 ptq->guest_pid = thread__pid(ptq->guest_thread); in intel_pt_get_guest_from_sideband()
1472 ptq->guest_tid = tid; in intel_pt_get_guest_from_sideband()
1473 ptq->vcpu = vcpu; in intel_pt_get_guest_from_sideband()
1481 struct intel_pt_queue *ptq = queue->priv; in intel_pt_set_pid_tid_cpu()
1483 if (queue->tid == -1 || pt->have_sched_switch) { in intel_pt_set_pid_tid_cpu()
1484 ptq->tid = machine__get_current_tid(pt->machine, ptq->cpu); in intel_pt_set_pid_tid_cpu()
1485 if (ptq->tid == -1) in intel_pt_set_pid_tid_cpu()
1486 ptq->pid = -1; in intel_pt_set_pid_tid_cpu()
1487 thread__zput(ptq->thread); in intel_pt_set_pid_tid_cpu()
1490 if (!ptq->thread && ptq->tid != -1) in intel_pt_set_pid_tid_cpu()
1491 ptq->thread = machine__find_thread(pt->machine, -1, ptq->tid); in intel_pt_set_pid_tid_cpu()
1493 if (ptq->thread) { in intel_pt_set_pid_tid_cpu()
1494 ptq->pid = thread__pid(ptq->thread); in intel_pt_set_pid_tid_cpu()
1495 if (queue->cpu == -1) in intel_pt_set_pid_tid_cpu()
1496 ptq->cpu = thread__cpu(ptq->thread); in intel_pt_set_pid_tid_cpu()
1499 if (pt->have_guest_sideband && intel_pt_get_guest_from_sideband(ptq)) { in intel_pt_set_pid_tid_cpu()
1500 ptq->guest_machine_pid = 0; in intel_pt_set_pid_tid_cpu()
1501 ptq->guest_pid = -1; in intel_pt_set_pid_tid_cpu()
1502 ptq->guest_tid = -1; in intel_pt_set_pid_tid_cpu()
1503 ptq->vcpu = -1; in intel_pt_set_pid_tid_cpu()
1509 struct intel_pt *pt = ptq->pt; in intel_pt_sample_flags()
1511 ptq->insn_len = 0; in intel_pt_sample_flags()
1512 if (ptq->state->flags & INTEL_PT_ABORT_TX) { in intel_pt_sample_flags()
1513 ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT; in intel_pt_sample_flags()
1514 } else if (ptq->state->flags & INTEL_PT_ASYNC) { in intel_pt_sample_flags()
1515 if (!ptq->state->to_ip) in intel_pt_sample_flags()
1516 ptq->flags = PERF_IP_FLAG_BRANCH | in intel_pt_sample_flags()
1519 else if (ptq->state->from_nr && !ptq->state->to_nr) in intel_pt_sample_flags()
1520 ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | in intel_pt_sample_flags()
1524 ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | in intel_pt_sample_flags()
1528 if (ptq->state->from_ip) in intel_pt_sample_flags()
1529 ptq->flags = intel_pt_insn_type(ptq->state->insn_op); in intel_pt_sample_flags()
1531 ptq->flags = PERF_IP_FLAG_BRANCH | in intel_pt_sample_flags()
1533 if (ptq->state->flags & INTEL_PT_IN_TX) in intel_pt_sample_flags()
1534 ptq->flags |= PERF_IP_FLAG_IN_TX; in intel_pt_sample_flags()
1535 ptq->insn_len = ptq->state->insn_len; in intel_pt_sample_flags()
1536 memcpy(ptq->insn, ptq->state->insn, INTEL_PT_INSN_BUF_SZ); in intel_pt_sample_flags()
1539 if (ptq->state->type & INTEL_PT_TRACE_BEGIN) in intel_pt_sample_flags()
1540 ptq->flags |= PERF_IP_FLAG_TRACE_BEGIN; in intel_pt_sample_flags()
1541 if (ptq->state->type & INTEL_PT_TRACE_END) in intel_pt_sample_flags()
1542 ptq->flags |= PERF_IP_FLAG_TRACE_END; in intel_pt_sample_flags()
1544 if (pt->cap_event_trace) { in intel_pt_sample_flags()
1545 if (ptq->state->type & INTEL_PT_IFLAG_CHG) { in intel_pt_sample_flags()
1546 if (!ptq->state->from_iflag) in intel_pt_sample_flags()
1547 ptq->flags |= PERF_IP_FLAG_INTR_DISABLE; in intel_pt_sample_flags()
1548 if (ptq->state->from_iflag != ptq->state->to_iflag) in intel_pt_sample_flags()
1549 ptq->flags |= PERF_IP_FLAG_INTR_TOGGLE; in intel_pt_sample_flags()
1550 } else if (!ptq->state->to_iflag) { in intel_pt_sample_flags()
1551 ptq->flags |= PERF_IP_FLAG_INTR_DISABLE; in intel_pt_sample_flags()
1559 if (!pt->range_cnt) in intel_pt_setup_time_range()
1562 ptq->sel_timestamp = pt->time_ranges[0].start; in intel_pt_setup_time_range()
1563 ptq->sel_idx = 0; in intel_pt_setup_time_range()
1565 if (ptq->sel_timestamp) { in intel_pt_setup_time_range()
1566 ptq->sel_start = true; in intel_pt_setup_time_range()
1568 ptq->sel_timestamp = pt->time_ranges[0].end; in intel_pt_setup_time_range()
1569 ptq->sel_start = false; in intel_pt_setup_time_range()
1577 struct intel_pt_queue *ptq = queue->priv; in intel_pt_setup_queue()
1579 if (list_empty(&queue->head)) in intel_pt_setup_queue()
1585 return -ENOMEM; in intel_pt_setup_queue()
1586 queue->priv = ptq; in intel_pt_setup_queue()
1588 if (queue->cpu != -1) in intel_pt_setup_queue()
1589 ptq->cpu = queue->cpu; in intel_pt_setup_queue()
1590 ptq->tid = queue->tid; in intel_pt_setup_queue()
1592 ptq->cbr_seen = UINT_MAX; in intel_pt_setup_queue()
1594 if (pt->sampling_mode && !pt->snapshot_mode && in intel_pt_setup_queue()
1595 pt->timeless_decoding) in intel_pt_setup_queue()
1596 ptq->step_through_buffers = true; in intel_pt_setup_queue()
1598 ptq->sync_switch = pt->sync_switch; in intel_pt_setup_queue()
1603 if (!ptq->on_heap && in intel_pt_setup_queue()
1604 (!ptq->sync_switch || in intel_pt_setup_queue()
1605 ptq->switch_state != INTEL_PT_SS_EXPECTING_SWITCH_EVENT)) { in intel_pt_setup_queue()
1609 if (pt->timeless_decoding) in intel_pt_setup_queue()
1614 queue_nr, ptq->cpu, ptq->pid, ptq->tid); in intel_pt_setup_queue()
1616 if (ptq->sel_start && ptq->sel_timestamp) { in intel_pt_setup_queue()
1617 ret = intel_pt_fast_forward(ptq->decoder, in intel_pt_setup_queue()
1618 ptq->sel_timestamp); in intel_pt_setup_queue()
1624 state = intel_pt_decode(ptq->decoder); in intel_pt_setup_queue()
1625 if (state->err) { in intel_pt_setup_queue()
1626 if (state->err == INTEL_PT_ERR_NODATA) { in intel_pt_setup_queue()
1633 if (state->timestamp) in intel_pt_setup_queue()
1637 ptq->timestamp = state->timestamp; in intel_pt_setup_queue()
1639 queue_nr, ptq->timestamp); in intel_pt_setup_queue()
1640 ptq->state = state; in intel_pt_setup_queue()
1641 ptq->have_sample = true; in intel_pt_setup_queue()
1642 if (ptq->sel_start && ptq->sel_timestamp && in intel_pt_setup_queue()
1643 ptq->timestamp < ptq->sel_timestamp) in intel_pt_setup_queue()
1644 ptq->have_sample = false; in intel_pt_setup_queue()
1646 ret = auxtrace_heap__add(&pt->heap, queue_nr, ptq->timestamp); in intel_pt_setup_queue()
1649 ptq->on_heap = true; in intel_pt_setup_queue()
1660 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_setup_queues()
1661 ret = intel_pt_setup_queue(pt, &pt->queues.queue_array[i], i); in intel_pt_setup_queues()
1670 return pt->synth_opts.initial_skip && in intel_pt_skip_event()
1671 pt->num_events++ < pt->synth_opts.initial_skip; in intel_pt_skip_event()
1676 * Also ensure CBR is first non-skipped event by allowing for 4 more samples
1681 return pt->synth_opts.initial_skip && in intel_pt_skip_cbr_event()
1682 pt->num_events + 4 < pt->synth_opts.initial_skip; in intel_pt_skip_cbr_event()
1687 struct perf_sample *sample) in intel_pt_prep_a_sample() argument
1689 event->sample.header.type = PERF_RECORD_SAMPLE; in intel_pt_prep_a_sample()
1690 event->sample.header.size = sizeof(struct perf_event_header); in intel_pt_prep_a_sample()
1692 sample->pid = ptq->pid; in intel_pt_prep_a_sample()
1693 sample->tid = ptq->tid; in intel_pt_prep_a_sample()
1695 if (ptq->pt->have_guest_sideband) { in intel_pt_prep_a_sample()
1696 if ((ptq->state->from_ip && ptq->state->from_nr) || in intel_pt_prep_a_sample()
1697 (ptq->state->to_ip && ptq->state->to_nr)) { in intel_pt_prep_a_sample()
1698 sample->pid = ptq->guest_pid; in intel_pt_prep_a_sample()
1699 sample->tid = ptq->guest_tid; in intel_pt_prep_a_sample()
1700 sample->machine_pid = ptq->guest_machine_pid; in intel_pt_prep_a_sample()
1701 sample->vcpu = ptq->vcpu; in intel_pt_prep_a_sample()
1705 sample->cpu = ptq->cpu; in intel_pt_prep_a_sample()
1706 sample->insn_len = ptq->insn_len; in intel_pt_prep_a_sample()
1707 memcpy(sample->insn, ptq->insn, INTEL_PT_INSN_BUF_SZ); in intel_pt_prep_a_sample()
1713 struct perf_sample *sample) in intel_pt_prep_b_sample() argument
1715 intel_pt_prep_a_sample(ptq, event, sample); in intel_pt_prep_b_sample()
1717 if (!pt->timeless_decoding) in intel_pt_prep_b_sample()
1718 sample->time = tsc_to_perf_time(ptq->timestamp, &pt->tc); in intel_pt_prep_b_sample()
1720 sample->ip = ptq->state->from_ip; in intel_pt_prep_b_sample()
1721 sample->addr = ptq->state->to_ip; in intel_pt_prep_b_sample()
1722 sample->cpumode = intel_pt_cpumode(ptq, sample->ip, sample->addr); in intel_pt_prep_b_sample()
1723 sample->period = 1; in intel_pt_prep_b_sample()
1724 sample->flags = ptq->flags; in intel_pt_prep_b_sample()
1726 event->sample.header.misc = sample->cpumode; in intel_pt_prep_b_sample()
1730 struct perf_sample *sample, u64 type) in intel_pt_inject_event() argument
1732 event->header.size = perf_event__sample_event_size(sample, type, 0); in intel_pt_inject_event()
1733 return perf_event__synthesize_sample(event, type, 0, sample); in intel_pt_inject_event()
1738 struct perf_sample *sample, u64 type) in intel_pt_opt_inject() argument
1740 if (!pt->synth_opts.inject) in intel_pt_opt_inject()
1743 return intel_pt_inject_event(event, sample, type); in intel_pt_opt_inject()
1748 struct perf_sample *sample, u64 type) in intel_pt_deliver_synth_event() argument
1752 ret = intel_pt_opt_inject(pt, event, sample, type); in intel_pt_deliver_synth_event()
1756 ret = perf_session__deliver_synth_event(pt->session, event, sample); in intel_pt_deliver_synth_event()
1765 struct intel_pt *pt = ptq->pt; in intel_pt_synth_branch_sample()
1766 union perf_event *event = ptq->event_buf; in intel_pt_synth_branch_sample()
1767 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_branch_sample() local
1774 if (pt->branches_filter && !(pt->branches_filter & ptq->flags)) in intel_pt_synth_branch_sample()
1780 intel_pt_prep_b_sample(pt, ptq, event, &sample); in intel_pt_synth_branch_sample()
1782 sample.id = ptq->pt->branches_id; in intel_pt_synth_branch_sample()
1783 sample.stream_id = ptq->pt->branches_id; in intel_pt_synth_branch_sample()
1789 if (pt->synth_opts.last_branch && sort__mode == SORT_MODE__BRANCH) { in intel_pt_synth_branch_sample()
1792 .hw_idx = -1ULL, in intel_pt_synth_branch_sample()
1794 .from = sample.ip, in intel_pt_synth_branch_sample()
1795 .to = sample.addr, in intel_pt_synth_branch_sample()
1798 sample.branch_stack = (struct branch_stack *)&dummy_bs; in intel_pt_synth_branch_sample()
1801 if (ptq->sample_ipc) in intel_pt_synth_branch_sample()
1802 sample.cyc_cnt = ptq->ipc_cyc_cnt - ptq->last_br_cyc_cnt; in intel_pt_synth_branch_sample()
1803 if (sample.cyc_cnt) { in intel_pt_synth_branch_sample()
1804 sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_br_insn_cnt; in intel_pt_synth_branch_sample()
1805 ptq->last_br_insn_cnt = ptq->ipc_insn_cnt; in intel_pt_synth_branch_sample()
1806 ptq->last_br_cyc_cnt = ptq->ipc_cyc_cnt; in intel_pt_synth_branch_sample()
1809 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_branch_sample()
1810 pt->branches_sample_type); in intel_pt_synth_branch_sample()
1816 struct perf_sample *sample) in intel_pt_prep_sample() argument
1818 intel_pt_prep_b_sample(pt, ptq, event, sample); in intel_pt_prep_sample()
1820 if (pt->synth_opts.callchain) { in intel_pt_prep_sample()
1821 thread_stack__sample(ptq->thread, ptq->cpu, ptq->chain, in intel_pt_prep_sample()
1822 pt->synth_opts.callchain_sz + 1, in intel_pt_prep_sample()
1823 sample->ip, pt->kernel_start); in intel_pt_prep_sample()
1824 sample->callchain = ptq->chain; in intel_pt_prep_sample()
1827 if (pt->synth_opts.last_branch) { in intel_pt_prep_sample()
1828 thread_stack__br_sample(ptq->thread, ptq->cpu, ptq->last_branch, in intel_pt_prep_sample()
1829 pt->br_stack_sz); in intel_pt_prep_sample()
1830 sample->branch_stack = ptq->last_branch; in intel_pt_prep_sample()
1836 struct intel_pt *pt = ptq->pt; in intel_pt_synth_instruction_sample()
1837 union perf_event *event = ptq->event_buf; in intel_pt_synth_instruction_sample()
1838 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_instruction_sample() local
1843 intel_pt_prep_sample(pt, ptq, event, &sample); in intel_pt_synth_instruction_sample()
1845 sample.id = ptq->pt->instructions_id; in intel_pt_synth_instruction_sample()
1846 sample.stream_id = ptq->pt->instructions_id; in intel_pt_synth_instruction_sample()
1847 if (pt->synth_opts.quick) in intel_pt_synth_instruction_sample()
1848 sample.period = 1; in intel_pt_synth_instruction_sample()
1850 sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt; in intel_pt_synth_instruction_sample()
1852 if (ptq->sample_ipc) in intel_pt_synth_instruction_sample()
1853 sample.cyc_cnt = ptq->ipc_cyc_cnt - ptq->last_in_cyc_cnt; in intel_pt_synth_instruction_sample()
1854 if (sample.cyc_cnt) { in intel_pt_synth_instruction_sample()
1855 sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_in_insn_cnt; in intel_pt_synth_instruction_sample()
1856 ptq->last_in_insn_cnt = ptq->ipc_insn_cnt; in intel_pt_synth_instruction_sample()
1857 ptq->last_in_cyc_cnt = ptq->ipc_cyc_cnt; in intel_pt_synth_instruction_sample()
1860 ptq->last_insn_cnt = ptq->state->tot_insn_cnt; in intel_pt_synth_instruction_sample()
1862 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_instruction_sample()
1863 pt->instructions_sample_type); in intel_pt_synth_instruction_sample()
1868 struct intel_pt *pt = ptq->pt; in intel_pt_synth_cycle_sample()
1869 union perf_event *event = ptq->event_buf; in intel_pt_synth_cycle_sample()
1870 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_cycle_sample() local
1873 if (ptq->sample_ipc) in intel_pt_synth_cycle_sample()
1874 period = ptq->ipc_cyc_cnt - ptq->last_cy_cyc_cnt; in intel_pt_synth_cycle_sample()
1879 intel_pt_prep_sample(pt, ptq, event, &sample); in intel_pt_synth_cycle_sample()
1881 sample.id = ptq->pt->cycles_id; in intel_pt_synth_cycle_sample()
1882 sample.stream_id = ptq->pt->cycles_id; in intel_pt_synth_cycle_sample()
1883 sample.period = period; in intel_pt_synth_cycle_sample()
1885 sample.cyc_cnt = period; in intel_pt_synth_cycle_sample()
1886 sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_cy_insn_cnt; in intel_pt_synth_cycle_sample()
1887 ptq->last_cy_insn_cnt = ptq->ipc_insn_cnt; in intel_pt_synth_cycle_sample()
1888 ptq->last_cy_cyc_cnt = ptq->ipc_cyc_cnt; in intel_pt_synth_cycle_sample()
1890 return intel_pt_deliver_synth_event(pt, event, &sample, pt->cycles_sample_type); in intel_pt_synth_cycle_sample()
1895 struct intel_pt *pt = ptq->pt; in intel_pt_synth_transaction_sample()
1896 union perf_event *event = ptq->event_buf; in intel_pt_synth_transaction_sample()
1897 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_transaction_sample() local
1902 intel_pt_prep_sample(pt, ptq, event, &sample); in intel_pt_synth_transaction_sample()
1904 sample.id = ptq->pt->transactions_id; in intel_pt_synth_transaction_sample()
1905 sample.stream_id = ptq->pt->transactions_id; in intel_pt_synth_transaction_sample()
1907 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_transaction_sample()
1908 pt->transactions_sample_type); in intel_pt_synth_transaction_sample()
1914 struct perf_sample *sample) in intel_pt_prep_p_sample() argument
1916 intel_pt_prep_sample(pt, ptq, event, sample); in intel_pt_prep_p_sample()
1922 if (!sample->ip) in intel_pt_prep_p_sample()
1923 sample->flags = 0; in intel_pt_prep_p_sample()
1928 struct intel_pt *pt = ptq->pt; in intel_pt_synth_ptwrite_sample()
1929 union perf_event *event = ptq->event_buf; in intel_pt_synth_ptwrite_sample()
1930 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_ptwrite_sample() local
1936 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_ptwrite_sample()
1938 sample.id = ptq->pt->ptwrites_id; in intel_pt_synth_ptwrite_sample()
1939 sample.stream_id = ptq->pt->ptwrites_id; in intel_pt_synth_ptwrite_sample()
1942 raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP); in intel_pt_synth_ptwrite_sample()
1943 raw.payload = cpu_to_le64(ptq->state->ptw_payload); in intel_pt_synth_ptwrite_sample()
1945 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_ptwrite_sample()
1946 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_ptwrite_sample()
1948 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_ptwrite_sample()
1949 pt->ptwrites_sample_type); in intel_pt_synth_ptwrite_sample()
1954 struct intel_pt *pt = ptq->pt; in intel_pt_synth_cbr_sample()
1955 union perf_event *event = ptq->event_buf; in intel_pt_synth_cbr_sample()
1956 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_cbr_sample() local
1963 ptq->cbr_seen = ptq->state->cbr; in intel_pt_synth_cbr_sample()
1965 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_cbr_sample()
1967 sample.id = ptq->pt->cbr_id; in intel_pt_synth_cbr_sample()
1968 sample.stream_id = ptq->pt->cbr_id; in intel_pt_synth_cbr_sample()
1970 flags = (u16)ptq->state->cbr_payload | (pt->max_non_turbo_ratio << 16); in intel_pt_synth_cbr_sample()
1972 raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz); in intel_pt_synth_cbr_sample()
1975 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_cbr_sample()
1976 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_cbr_sample()
1978 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_cbr_sample()
1979 pt->pwr_events_sample_type); in intel_pt_synth_cbr_sample()
1984 struct intel_pt *pt = ptq->pt; in intel_pt_synth_psb_sample()
1985 union perf_event *event = ptq->event_buf; in intel_pt_synth_psb_sample()
1986 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_psb_sample() local
1992 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_psb_sample()
1994 sample.id = ptq->pt->psb_id; in intel_pt_synth_psb_sample()
1995 sample.stream_id = ptq->pt->psb_id; in intel_pt_synth_psb_sample()
1996 sample.flags = 0; in intel_pt_synth_psb_sample()
1999 raw.offset = ptq->state->psb_offset; in intel_pt_synth_psb_sample()
2001 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_psb_sample()
2002 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_psb_sample()
2004 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_psb_sample()
2005 pt->pwr_events_sample_type); in intel_pt_synth_psb_sample()
2010 struct intel_pt *pt = ptq->pt; in intel_pt_synth_mwait_sample()
2011 union perf_event *event = ptq->event_buf; in intel_pt_synth_mwait_sample()
2012 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_mwait_sample() local
2018 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_mwait_sample()
2020 sample.id = ptq->pt->mwait_id; in intel_pt_synth_mwait_sample()
2021 sample.stream_id = ptq->pt->mwait_id; in intel_pt_synth_mwait_sample()
2024 raw.payload = cpu_to_le64(ptq->state->mwait_payload); in intel_pt_synth_mwait_sample()
2026 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_mwait_sample()
2027 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_mwait_sample()
2029 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_mwait_sample()
2030 pt->pwr_events_sample_type); in intel_pt_synth_mwait_sample()
2035 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pwre_sample()
2036 union perf_event *event = ptq->event_buf; in intel_pt_synth_pwre_sample()
2037 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_pwre_sample() local
2043 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_pwre_sample()
2045 sample.id = ptq->pt->pwre_id; in intel_pt_synth_pwre_sample()
2046 sample.stream_id = ptq->pt->pwre_id; in intel_pt_synth_pwre_sample()
2049 raw.payload = cpu_to_le64(ptq->state->pwre_payload); in intel_pt_synth_pwre_sample()
2051 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_pwre_sample()
2052 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_pwre_sample()
2054 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_pwre_sample()
2055 pt->pwr_events_sample_type); in intel_pt_synth_pwre_sample()
2060 struct intel_pt *pt = ptq->pt; in intel_pt_synth_exstop_sample()
2061 union perf_event *event = ptq->event_buf; in intel_pt_synth_exstop_sample()
2062 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_exstop_sample() local
2068 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_exstop_sample()
2070 sample.id = ptq->pt->exstop_id; in intel_pt_synth_exstop_sample()
2071 sample.stream_id = ptq->pt->exstop_id; in intel_pt_synth_exstop_sample()
2074 raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP); in intel_pt_synth_exstop_sample()
2076 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_exstop_sample()
2077 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_exstop_sample()
2079 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_exstop_sample()
2080 pt->pwr_events_sample_type); in intel_pt_synth_exstop_sample()
2085 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pwrx_sample()
2086 union perf_event *event = ptq->event_buf; in intel_pt_synth_pwrx_sample()
2087 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_pwrx_sample() local
2093 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_pwrx_sample()
2095 sample.id = ptq->pt->pwrx_id; in intel_pt_synth_pwrx_sample()
2096 sample.stream_id = ptq->pt->pwrx_id; in intel_pt_synth_pwrx_sample()
2099 raw.payload = cpu_to_le64(ptq->state->pwrx_payload); in intel_pt_synth_pwrx_sample()
2101 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_pwrx_sample()
2102 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_pwrx_sample()
2104 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_pwrx_sample()
2105 pt->pwr_events_sample_type); in intel_pt_synth_pwrx_sample()
2137 const u64 *gp_regs = items->val[INTEL_PT_GP_REGS_POS]; in intel_pt_add_gp_regs()
2138 u32 mask = items->mask[INTEL_PT_GP_REGS_POS]; in intel_pt_add_gp_regs()
2144 int n = pebs_gp_regs[i] - 1; in intel_pt_add_gp_regs()
2151 * mask (i.e. 'intr_regs->mask') accordingly. in intel_pt_add_gp_regs()
2154 intr_regs->mask |= bit; in intel_pt_add_gp_regs()
2170 u32 mask = items->has_xmm & (regs_mask >> PERF_REG_X86_XMM0); in intel_pt_add_xmm()
2171 const u64 *xmm = items->xmm; in intel_pt_add_xmm()
2177 * and update the resulting mask (i.e. 'intr_regs->mask') accordingly. in intel_pt_add_xmm()
2179 intr_regs->mask |= (u64)mask << PERF_REG_X86_XMM0; in intel_pt_add_xmm()
2216 br_stack->nr = 0; in intel_pt_add_lbrs()
2218 to = &br_stack->entries[0].from; in intel_pt_add_lbrs()
2221 u32 mask = items->mask[i]; in intel_pt_add_lbrs()
2222 const u64 *from = items->val[i]; in intel_pt_add_lbrs()
2229 br_stack->nr += 1; in intel_pt_add_lbrs()
2237 const struct intel_pt_blk_items *items = &ptq->state->items; in intel_pt_do_synth_pebs_sample()
2238 struct perf_sample sample = { .ip = 0, }; in intel_pt_do_synth_pebs_sample() local
2239 union perf_event *event = ptq->event_buf; in intel_pt_do_synth_pebs_sample()
2240 struct intel_pt *pt = ptq->pt; in intel_pt_do_synth_pebs_sample()
2241 u64 sample_type = evsel->core.attr.sample_type; in intel_pt_do_synth_pebs_sample()
2243 u64 regs[8 * sizeof(sample.intr_regs.mask)]; in intel_pt_do_synth_pebs_sample()
2248 intel_pt_prep_a_sample(ptq, event, &sample); in intel_pt_do_synth_pebs_sample()
2250 sample.id = id; in intel_pt_do_synth_pebs_sample()
2251 sample.stream_id = id; in intel_pt_do_synth_pebs_sample()
2253 if (!evsel->core.attr.freq) in intel_pt_do_synth_pebs_sample()
2254 sample.period = evsel->core.attr.sample_period; in intel_pt_do_synth_pebs_sample()
2256 /* No support for non-zero CS base */ in intel_pt_do_synth_pebs_sample()
2257 if (items->has_ip) in intel_pt_do_synth_pebs_sample()
2258 sample.ip = items->ip; in intel_pt_do_synth_pebs_sample()
2259 else if (items->has_rip) in intel_pt_do_synth_pebs_sample()
2260 sample.ip = items->rip; in intel_pt_do_synth_pebs_sample()
2262 sample.ip = ptq->state->from_ip; in intel_pt_do_synth_pebs_sample()
2264 cpumode = intel_pt_cpumode(ptq, sample.ip, 0); in intel_pt_do_synth_pebs_sample()
2266 event->sample.header.misc = cpumode | PERF_RECORD_MISC_EXACT_IP; in intel_pt_do_synth_pebs_sample()
2268 sample.cpumode = cpumode; in intel_pt_do_synth_pebs_sample()
2273 if (items->has_timestamp) in intel_pt_do_synth_pebs_sample()
2274 timestamp = items->timestamp; in intel_pt_do_synth_pebs_sample()
2275 else if (!pt->timeless_decoding) in intel_pt_do_synth_pebs_sample()
2276 timestamp = ptq->timestamp; in intel_pt_do_synth_pebs_sample()
2278 sample.time = tsc_to_perf_time(timestamp, &pt->tc); in intel_pt_do_synth_pebs_sample()
2282 pt->synth_opts.callchain) { in intel_pt_do_synth_pebs_sample()
2283 thread_stack__sample(ptq->thread, ptq->cpu, ptq->chain, in intel_pt_do_synth_pebs_sample()
2284 pt->synth_opts.callchain_sz, sample.ip, in intel_pt_do_synth_pebs_sample()
2285 pt->kernel_start); in intel_pt_do_synth_pebs_sample()
2286 sample.callchain = ptq->chain; in intel_pt_do_synth_pebs_sample()
2290 (items->mask[INTEL_PT_GP_REGS_POS] || in intel_pt_do_synth_pebs_sample()
2291 items->mask[INTEL_PT_XMM_POS])) { in intel_pt_do_synth_pebs_sample()
2292 u64 regs_mask = evsel->core.attr.sample_regs_intr; in intel_pt_do_synth_pebs_sample()
2295 sample.intr_regs.abi = items->is_32_bit ? in intel_pt_do_synth_pebs_sample()
2298 sample.intr_regs.regs = regs; in intel_pt_do_synth_pebs_sample()
2300 pos = intel_pt_add_gp_regs(&sample.intr_regs, regs, items, regs_mask); in intel_pt_do_synth_pebs_sample()
2302 intel_pt_add_xmm(&sample.intr_regs, pos, items, regs_mask); in intel_pt_do_synth_pebs_sample()
2306 if (items->mask[INTEL_PT_LBR_0_POS] || in intel_pt_do_synth_pebs_sample()
2307 items->mask[INTEL_PT_LBR_1_POS] || in intel_pt_do_synth_pebs_sample()
2308 items->mask[INTEL_PT_LBR_2_POS]) { in intel_pt_do_synth_pebs_sample()
2309 intel_pt_add_lbrs(ptq->last_branch, items); in intel_pt_do_synth_pebs_sample()
2310 } else if (pt->synth_opts.last_branch) { in intel_pt_do_synth_pebs_sample()
2311 thread_stack__br_sample(ptq->thread, ptq->cpu, in intel_pt_do_synth_pebs_sample()
2312 ptq->last_branch, in intel_pt_do_synth_pebs_sample()
2313 pt->br_stack_sz); in intel_pt_do_synth_pebs_sample()
2315 ptq->last_branch->nr = 0; in intel_pt_do_synth_pebs_sample()
2317 sample.branch_stack = ptq->last_branch; in intel_pt_do_synth_pebs_sample()
2320 if (sample_type & PERF_SAMPLE_ADDR && items->has_mem_access_address) in intel_pt_do_synth_pebs_sample()
2321 sample.addr = items->mem_access_address; in intel_pt_do_synth_pebs_sample()
2328 if (items->has_mem_access_latency) { in intel_pt_do_synth_pebs_sample()
2329 u64 weight = items->mem_access_latency >> 32; in intel_pt_do_synth_pebs_sample()
2342 sample.weight = weight & 0xffff; in intel_pt_do_synth_pebs_sample()
2343 sample.ins_lat = items->mem_access_latency & 0xffff; in intel_pt_do_synth_pebs_sample()
2345 sample.weight = items->mem_access_latency; in intel_pt_do_synth_pebs_sample()
2347 if (!sample.weight && items->has_tsx_aux_info) { in intel_pt_do_synth_pebs_sample()
2349 sample.weight = (u32)items->tsx_aux_info; in intel_pt_do_synth_pebs_sample()
2353 if (sample_type & PERF_SAMPLE_TRANSACTION && items->has_tsx_aux_info) { in intel_pt_do_synth_pebs_sample()
2354 u64 ax = items->has_rax ? items->rax : 0; in intel_pt_do_synth_pebs_sample()
2356 u64 txn = (u8)(items->tsx_aux_info >> 32); in intel_pt_do_synth_pebs_sample()
2361 sample.transaction = txn; in intel_pt_do_synth_pebs_sample()
2364 return intel_pt_deliver_synth_event(pt, event, &sample, sample_type); in intel_pt_do_synth_pebs_sample()
2369 struct intel_pt *pt = ptq->pt; in intel_pt_synth_single_pebs_sample()
2370 struct evsel *evsel = pt->pebs_evsel; in intel_pt_synth_single_pebs_sample()
2371 u64 id = evsel->core.id[0]; in intel_pt_synth_single_pebs_sample()
2378 const struct intel_pt_blk_items *items = &ptq->state->items; in intel_pt_synth_pebs_sample()
2380 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pebs_sample()
2381 int err = -EINVAL; in intel_pt_synth_pebs_sample()
2384 if (!items->has_applicable_counters || !items->applicable_counters) { in intel_pt_synth_pebs_sample()
2385 if (!pt->single_pebs) in intel_pt_synth_pebs_sample()
2386 pr_err("PEBS-via-PT record with no applicable_counters\n"); in intel_pt_synth_pebs_sample()
2390 for_each_set_bit(hw_id, (unsigned long *)&items->applicable_counters, INTEL_PT_MAX_PEBS) { in intel_pt_synth_pebs_sample()
2391 pe = &ptq->pebs[hw_id]; in intel_pt_synth_pebs_sample()
2392 if (!pe->evsel) { in intel_pt_synth_pebs_sample()
2393 if (!pt->single_pebs) in intel_pt_synth_pebs_sample()
2394 pr_err("PEBS-via-PT record with no matching event, hw_id %d\n", in intel_pt_synth_pebs_sample()
2398 err = intel_pt_do_synth_pebs_sample(ptq, pe->evsel, pe->id); in intel_pt_synth_pebs_sample()
2408 struct intel_pt *pt = ptq->pt; in intel_pt_synth_events_sample()
2409 union perf_event *event = ptq->event_buf; in intel_pt_synth_events_sample()
2410 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_events_sample() local
2420 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_events_sample()
2422 sample.id = ptq->pt->evt_id; in intel_pt_synth_events_sample()
2423 sample.stream_id = ptq->pt->evt_id; in intel_pt_synth_events_sample()
2425 raw.cfe.type = ptq->state->cfe_type; in intel_pt_synth_events_sample()
2427 raw.cfe.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP); in intel_pt_synth_events_sample()
2428 raw.cfe.vector = ptq->state->cfe_vector; in intel_pt_synth_events_sample()
2429 raw.cfe.evd_cnt = ptq->state->evd_cnt; in intel_pt_synth_events_sample()
2431 for (i = 0; i < ptq->state->evd_cnt; i++) { in intel_pt_synth_events_sample()
2433 raw.evd[i].evd_type = ptq->state->evd[i].type; in intel_pt_synth_events_sample()
2434 raw.evd[i].payload = ptq->state->evd[i].payload; in intel_pt_synth_events_sample()
2437 sample.raw_size = perf_synth__raw_size(raw) + in intel_pt_synth_events_sample()
2438 ptq->state->evd_cnt * sizeof(struct perf_synth_intel_evd); in intel_pt_synth_events_sample()
2439 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_events_sample()
2441 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_events_sample()
2442 pt->evt_sample_type); in intel_pt_synth_events_sample()
2447 struct intel_pt *pt = ptq->pt; in intel_pt_synth_iflag_chg_sample()
2448 union perf_event *event = ptq->event_buf; in intel_pt_synth_iflag_chg_sample()
2449 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_iflag_chg_sample() local
2455 intel_pt_prep_p_sample(pt, ptq, event, &sample); in intel_pt_synth_iflag_chg_sample()
2457 sample.id = ptq->pt->iflag_chg_id; in intel_pt_synth_iflag_chg_sample()
2458 sample.stream_id = ptq->pt->iflag_chg_id; in intel_pt_synth_iflag_chg_sample()
2461 raw.iflag = ptq->state->to_iflag; in intel_pt_synth_iflag_chg_sample()
2463 if (ptq->state->type & INTEL_PT_BRANCH) { in intel_pt_synth_iflag_chg_sample()
2465 raw.branch_ip = ptq->state->to_ip; in intel_pt_synth_iflag_chg_sample()
2467 sample.addr = 0; in intel_pt_synth_iflag_chg_sample()
2469 sample.flags = ptq->flags; in intel_pt_synth_iflag_chg_sample()
2471 sample.raw_size = perf_synth__raw_size(raw); in intel_pt_synth_iflag_chg_sample()
2472 sample.raw_data = perf_synth__raw_data(&raw); in intel_pt_synth_iflag_chg_sample()
2474 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_iflag_chg_sample()
2475 pt->iflag_chg_sample_type); in intel_pt_synth_iflag_chg_sample()
2482 bool dump_log_on_error = pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_ON_ERROR; in intel_pt_synth_error()
2483 bool log_on_stdout = pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_USE_STDOUT; in intel_pt_synth_error()
2488 if (pt->synth_opts.error_minus_flags) { in intel_pt_synth_error()
2490 pt->synth_opts.error_minus_flags & AUXTRACE_ERR_FLG_OVERFLOW) in intel_pt_synth_error()
2493 pt->synth_opts.error_minus_flags & AUXTRACE_ERR_FLG_DATA_LOST) in intel_pt_synth_error()
2513 err = perf_session__deliver_synth_event(pt->session, &event, NULL); in intel_pt_synth_error()
2524 struct intel_pt *pt = ptq->pt; in intel_ptq_synth_error()
2525 u64 tm = ptq->timestamp; in intel_ptq_synth_error()
2527 pid_t pid = ptq->pid; in intel_ptq_synth_error()
2528 pid_t tid = ptq->tid; in intel_ptq_synth_error()
2529 int vcpu = -1; in intel_ptq_synth_error()
2531 tm = pt->timeless_decoding ? 0 : tsc_to_perf_time(tm, &pt->tc); in intel_ptq_synth_error()
2533 if (pt->have_guest_sideband && state->from_nr) { in intel_ptq_synth_error()
2534 machine_pid = ptq->guest_machine_pid; in intel_ptq_synth_error()
2535 vcpu = ptq->vcpu; in intel_ptq_synth_error()
2536 pid = ptq->guest_pid; in intel_ptq_synth_error()
2537 tid = ptq->guest_tid; in intel_ptq_synth_error()
2540 return intel_pt_synth_error(pt, state->err, ptq->cpu, pid, tid, in intel_ptq_synth_error()
2541 state->from_ip, tm, machine_pid, vcpu); in intel_ptq_synth_error()
2547 pid_t tid = ptq->next_tid; in intel_pt_next_tid()
2550 if (tid == -1) in intel_pt_next_tid()
2553 intel_pt_log("switch: cpu %d tid %d\n", ptq->cpu, tid); in intel_pt_next_tid()
2555 err = machine__set_current_tid(pt->machine, ptq->cpu, -1, tid); in intel_pt_next_tid()
2557 queue = &pt->queues.queue_array[ptq->queue_nr]; in intel_pt_next_tid()
2560 ptq->next_tid = -1; in intel_pt_next_tid()
2567 struct intel_pt *pt = ptq->pt; in intel_pt_is_switch_ip()
2569 return ip == pt->switch_ip && in intel_pt_is_switch_ip()
2570 (ptq->flags & PERF_IP_FLAG_BRANCH) && in intel_pt_is_switch_ip()
2571 !(ptq->flags & (PERF_IP_FLAG_CONDITIONAL | PERF_IP_FLAG_ASYNC | in intel_pt_is_switch_ip()
2580 const struct intel_pt_state *state = ptq->state; in intel_pt_sample()
2581 struct intel_pt *pt = ptq->pt; in intel_pt_sample()
2584 if (!ptq->have_sample) in intel_pt_sample()
2587 ptq->have_sample = false; in intel_pt_sample()
2589 if (pt->synth_opts.approx_ipc) { in intel_pt_sample()
2590 ptq->ipc_insn_cnt = ptq->state->tot_insn_cnt; in intel_pt_sample()
2591 ptq->ipc_cyc_cnt = ptq->state->cycles; in intel_pt_sample()
2592 ptq->sample_ipc = true; in intel_pt_sample()
2594 ptq->ipc_insn_cnt = ptq->state->tot_insn_cnt; in intel_pt_sample()
2595 ptq->ipc_cyc_cnt = ptq->state->tot_cyc_cnt; in intel_pt_sample()
2596 ptq->sample_ipc = ptq->state->flags & INTEL_PT_SAMPLE_IPC; in intel_pt_sample()
2600 if (symbol_conf.guest_code && (state->from_nr || state->to_nr)) in intel_pt_sample()
2607 if (pt->sample_pebs && state->type & INTEL_PT_BLK_ITEMS) { in intel_pt_sample()
2613 if (pt->synth_opts.intr_events) { in intel_pt_sample()
2614 if (state->type & INTEL_PT_EVT) { in intel_pt_sample()
2619 if (state->type & INTEL_PT_IFLAG_CHG) { in intel_pt_sample()
2626 if (pt->sample_pwr_events) { in intel_pt_sample()
2627 if (state->type & INTEL_PT_PSB_EVT) { in intel_pt_sample()
2632 if (ptq->state->cbr != ptq->cbr_seen) { in intel_pt_sample()
2637 if (state->type & INTEL_PT_PWR_EVT) { in intel_pt_sample()
2638 if (state->type & INTEL_PT_MWAIT_OP) { in intel_pt_sample()
2643 if (state->type & INTEL_PT_PWR_ENTRY) { in intel_pt_sample()
2648 if (state->type & INTEL_PT_EX_STOP) { in intel_pt_sample()
2653 if (state->type & INTEL_PT_PWR_EXIT) { in intel_pt_sample()
2661 if (state->type & INTEL_PT_INSTRUCTION) { in intel_pt_sample()
2662 if (pt->sample_instructions) { in intel_pt_sample()
2667 if (pt->sample_cycles) { in intel_pt_sample()
2674 if (pt->sample_transactions && (state->type & INTEL_PT_TRANSACTION)) { in intel_pt_sample()
2680 if (pt->sample_ptwrites && (state->type & INTEL_PT_PTW)) { in intel_pt_sample()
2686 if (!(state->type & INTEL_PT_BRANCH)) in intel_pt_sample()
2689 if (pt->use_thread_stack) { in intel_pt_sample()
2690 thread_stack__event(ptq->thread, ptq->cpu, ptq->flags, in intel_pt_sample()
2691 state->from_ip, state->to_ip, ptq->insn_len, in intel_pt_sample()
2692 state->trace_nr, pt->callstack, in intel_pt_sample()
2693 pt->br_stack_sz_plus, in intel_pt_sample()
2694 pt->mispred_all); in intel_pt_sample()
2696 thread_stack__set_trace_nr(ptq->thread, ptq->cpu, state->trace_nr); in intel_pt_sample()
2699 if (pt->sample_branches) { in intel_pt_sample()
2700 if (state->from_nr != state->to_nr && in intel_pt_sample()
2701 state->from_ip && state->to_ip) { in intel_pt_sample()
2703 u64 to_ip = st->to_ip; in intel_pt_sample()
2704 u64 from_ip = st->from_ip; in intel_pt_sample()
2710 st->to_ip = 0; in intel_pt_sample()
2714 st->from_ip = 0; in intel_pt_sample()
2715 st->to_ip = to_ip; in intel_pt_sample()
2717 st->from_ip = from_ip; in intel_pt_sample()
2725 if (!ptq->sync_switch) in intel_pt_sample()
2728 if (intel_pt_is_switch_ip(ptq, state->to_ip)) { in intel_pt_sample()
2729 switch (ptq->switch_state) { in intel_pt_sample()
2736 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_sample()
2739 ptq->switch_state = INTEL_PT_SS_EXPECTING_SWITCH_EVENT; in intel_pt_sample()
2742 } else if (!state->to_ip) { in intel_pt_sample()
2743 ptq->switch_state = INTEL_PT_SS_NOT_TRACING; in intel_pt_sample()
2744 } else if (ptq->switch_state == INTEL_PT_SS_NOT_TRACING) { in intel_pt_sample()
2745 ptq->switch_state = INTEL_PT_SS_UNKNOWN; in intel_pt_sample()
2746 } else if (ptq->switch_state == INTEL_PT_SS_UNKNOWN && in intel_pt_sample()
2747 state->to_ip == pt->ptss_ip && in intel_pt_sample()
2748 (ptq->flags & PERF_IP_FLAG_CALL)) { in intel_pt_sample()
2749 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_sample()
2757 struct machine *machine = pt->machine; in intel_pt_switch_ip()
2776 if (sym->binding == STB_GLOBAL && in intel_pt_switch_ip()
2777 !strcmp(sym->name, "__switch_to")) { in intel_pt_switch_ip()
2778 ip = map__unmap_ip(map, sym->start); in intel_pt_switch_ip()
2789 if (pt->have_sched_switch == 1) in intel_pt_switch_ip()
2795 if (!strcmp(sym->name, ptss)) { in intel_pt_switch_ip()
2796 ip = map__unmap_ip(map, sym->start); in intel_pt_switch_ip()
2811 if (pt->sync_switch_not_supported) in intel_pt_enable_sync_switch()
2814 pt->sync_switch = true; in intel_pt_enable_sync_switch()
2816 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_enable_sync_switch()
2817 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_enable_sync_switch()
2818 struct intel_pt_queue *ptq = queue->priv; in intel_pt_enable_sync_switch()
2821 ptq->sync_switch = true; in intel_pt_enable_sync_switch()
2829 pt->sync_switch = false; in intel_pt_disable_sync_switch()
2831 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_disable_sync_switch()
2832 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_disable_sync_switch()
2833 struct intel_pt_queue *ptq = queue->priv; in intel_pt_disable_sync_switch()
2836 ptq->sync_switch = false; in intel_pt_disable_sync_switch()
2843 * To filter against time ranges, it is only necessary to look at the next start
2844 * or end time.
2848 struct intel_pt *pt = ptq->pt; in intel_pt_next_time()
2850 if (ptq->sel_start) { in intel_pt_next_time()
2851 /* Next time is an end time */ in intel_pt_next_time()
2852 ptq->sel_start = false; in intel_pt_next_time()
2853 ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].end; in intel_pt_next_time()
2855 } else if (ptq->sel_idx + 1 < pt->range_cnt) { in intel_pt_next_time()
2856 /* Next time is a start time */ in intel_pt_next_time()
2857 ptq->sel_start = true; in intel_pt_next_time()
2858 ptq->sel_idx += 1; in intel_pt_next_time()
2859 ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].start; in intel_pt_next_time()
2863 /* No next time */ in intel_pt_next_time()
2872 if (ptq->sel_start) { in intel_pt_time_filter()
2873 if (ptq->timestamp >= ptq->sel_timestamp) { in intel_pt_time_filter()
2874 /* After start time, so consider next time */ in intel_pt_time_filter()
2876 if (!ptq->sel_timestamp) { in intel_pt_time_filter()
2877 /* No end time */ in intel_pt_time_filter()
2880 /* Check against end time */ in intel_pt_time_filter()
2883 /* Before start time, so fast forward */ in intel_pt_time_filter()
2884 ptq->have_sample = false; in intel_pt_time_filter()
2885 if (ptq->sel_timestamp > *ff_timestamp) { in intel_pt_time_filter()
2886 if (ptq->sync_switch) { in intel_pt_time_filter()
2887 intel_pt_next_tid(ptq->pt, ptq); in intel_pt_time_filter()
2888 ptq->switch_state = INTEL_PT_SS_UNKNOWN; in intel_pt_time_filter()
2890 *ff_timestamp = ptq->sel_timestamp; in intel_pt_time_filter()
2891 err = intel_pt_fast_forward(ptq->decoder, in intel_pt_time_filter()
2892 ptq->sel_timestamp); in intel_pt_time_filter()
2897 } else if (ptq->timestamp > ptq->sel_timestamp) { in intel_pt_time_filter()
2898 /* After end time, so consider next time */ in intel_pt_time_filter()
2900 /* No next time range, so stop decoding */ in intel_pt_time_filter()
2901 ptq->have_sample = false; in intel_pt_time_filter()
2902 ptq->switch_state = INTEL_PT_SS_NOT_TRACING; in intel_pt_time_filter()
2905 /* Check against next start time */ in intel_pt_time_filter()
2908 /* Before end time */ in intel_pt_time_filter()
2916 const struct intel_pt_state *state = ptq->state; in intel_pt_run_decoder()
2917 struct intel_pt *pt = ptq->pt; in intel_pt_run_decoder()
2921 if (!pt->kernel_start) { in intel_pt_run_decoder()
2922 pt->kernel_start = machine__kernel_start(pt->machine); in intel_pt_run_decoder()
2923 if (pt->per_cpu_mmaps && in intel_pt_run_decoder()
2924 (pt->have_sched_switch == 1 || pt->have_sched_switch == 3) && in intel_pt_run_decoder()
2925 !pt->timeless_decoding && intel_pt_tracing_kernel(pt) && in intel_pt_run_decoder()
2926 !pt->sampling_mode && !pt->synth_opts.vm_time_correlation) { in intel_pt_run_decoder()
2927 pt->switch_ip = intel_pt_switch_ip(pt, &pt->ptss_ip); in intel_pt_run_decoder()
2928 if (pt->switch_ip) { in intel_pt_run_decoder()
2930 pt->switch_ip, pt->ptss_ip); in intel_pt_run_decoder()
2937 ptq->queue_nr, ptq->cpu, ptq->pid, ptq->tid); in intel_pt_run_decoder()
2943 state = intel_pt_decode(ptq->decoder); in intel_pt_run_decoder()
2944 if (state->err) { in intel_pt_run_decoder()
2945 if (state->err == INTEL_PT_ERR_NODATA) in intel_pt_run_decoder()
2947 if (ptq->sync_switch && in intel_pt_run_decoder()
2948 state->from_ip >= pt->kernel_start) { in intel_pt_run_decoder()
2949 ptq->sync_switch = false; in intel_pt_run_decoder()
2952 ptq->timestamp = state->est_timestamp; in intel_pt_run_decoder()
2953 if (pt->synth_opts.errors) { in intel_pt_run_decoder()
2961 ptq->state = state; in intel_pt_run_decoder()
2962 ptq->have_sample = true; in intel_pt_run_decoder()
2966 if (pt->est_tsc && in intel_pt_run_decoder()
2967 (state->from_ip >= pt->kernel_start || !state->from_ip) && in intel_pt_run_decoder()
2968 state->to_ip && state->to_ip < pt->kernel_start) { in intel_pt_run_decoder()
2970 state->timestamp, state->est_timestamp); in intel_pt_run_decoder()
2971 ptq->timestamp = state->est_timestamp; in intel_pt_run_decoder()
2973 } else if (ptq->sync_switch && in intel_pt_run_decoder()
2974 ptq->switch_state == INTEL_PT_SS_UNKNOWN && in intel_pt_run_decoder()
2975 intel_pt_is_switch_ip(ptq, state->to_ip) && in intel_pt_run_decoder()
2976 ptq->next_tid == -1) { in intel_pt_run_decoder()
2978 state->timestamp, state->est_timestamp); in intel_pt_run_decoder()
2979 ptq->timestamp = state->est_timestamp; in intel_pt_run_decoder()
2980 } else if (state->timestamp > ptq->timestamp) { in intel_pt_run_decoder()
2981 ptq->timestamp = state->timestamp; in intel_pt_run_decoder()
2984 if (ptq->sel_timestamp) { in intel_pt_run_decoder()
2990 if (!pt->timeless_decoding && ptq->timestamp >= *timestamp) { in intel_pt_run_decoder()
2991 *timestamp = ptq->timestamp; in intel_pt_run_decoder()
3000 if (pt->queues.new_data) { in intel_pt_update_queues()
3001 pt->queues.new_data = false; in intel_pt_update_queues()
3017 if (!pt->heap.heap_cnt) in intel_pt_process_queues()
3020 if (pt->heap.heap_array[0].ordinal >= timestamp) in intel_pt_process_queues()
3023 queue_nr = pt->heap.heap_array[0].queue_nr; in intel_pt_process_queues()
3024 queue = &pt->queues.queue_array[queue_nr]; in intel_pt_process_queues()
3025 ptq = queue->priv; in intel_pt_process_queues()
3028 queue_nr, pt->heap.heap_array[0].ordinal, in intel_pt_process_queues()
3031 auxtrace_heap__pop(&pt->heap); in intel_pt_process_queues()
3033 if (pt->heap.heap_cnt) { in intel_pt_process_queues()
3034 ts = pt->heap.heap_array[0].ordinal + 1; in intel_pt_process_queues()
3046 auxtrace_heap__add(&pt->heap, queue_nr, ts); in intel_pt_process_queues()
3051 ret = auxtrace_heap__add(&pt->heap, queue_nr, ts); in intel_pt_process_queues()
3055 ptq->on_heap = false; in intel_pt_process_queues()
3065 struct auxtrace_queues *queues = &pt->queues; in intel_pt_process_timeless_queues()
3069 for (i = 0; i < queues->nr_queues; i++) { in intel_pt_process_timeless_queues()
3070 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_process_timeless_queues()
3071 struct intel_pt_queue *ptq = queue->priv; in intel_pt_process_timeless_queues()
3073 if (ptq && (tid == -1 || ptq->tid == tid)) { in intel_pt_process_timeless_queues()
3074 ptq->time = time_; in intel_pt_process_timeless_queues()
3084 struct perf_sample *sample) in intel_pt_sample_set_pid_tid_cpu() argument
3086 struct machine *m = ptq->pt->machine; in intel_pt_sample_set_pid_tid_cpu()
3088 ptq->pid = sample->pid; in intel_pt_sample_set_pid_tid_cpu()
3089 ptq->tid = sample->tid; in intel_pt_sample_set_pid_tid_cpu()
3090 ptq->cpu = queue->cpu; in intel_pt_sample_set_pid_tid_cpu()
3093 ptq->queue_nr, ptq->cpu, ptq->pid, ptq->tid); in intel_pt_sample_set_pid_tid_cpu()
3095 thread__zput(ptq->thread); in intel_pt_sample_set_pid_tid_cpu()
3097 if (ptq->tid == -1) in intel_pt_sample_set_pid_tid_cpu()
3100 if (ptq->pid == -1) { in intel_pt_sample_set_pid_tid_cpu()
3101 ptq->thread = machine__find_thread(m, -1, ptq->tid); in intel_pt_sample_set_pid_tid_cpu()
3102 if (ptq->thread) in intel_pt_sample_set_pid_tid_cpu()
3103 ptq->pid = thread__pid(ptq->thread); in intel_pt_sample_set_pid_tid_cpu()
3107 ptq->thread = machine__findnew_thread(m, ptq->pid, ptq->tid); in intel_pt_sample_set_pid_tid_cpu()
3111 struct perf_sample *sample) in intel_pt_process_timeless_sample() argument
3117 queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); in intel_pt_process_timeless_sample()
3119 return -EINVAL; in intel_pt_process_timeless_sample()
3121 ptq = queue->priv; in intel_pt_process_timeless_sample()
3125 ptq->stop = false; in intel_pt_process_timeless_sample()
3126 ptq->time = sample->time; in intel_pt_process_timeless_sample()
3127 intel_pt_sample_set_pid_tid_cpu(ptq, queue, sample); in intel_pt_process_timeless_sample()
3132 static int intel_pt_lost(struct intel_pt *pt, struct perf_sample *sample) in intel_pt_lost() argument
3134 return intel_pt_synth_error(pt, INTEL_PT_ERR_LOST, sample->cpu, in intel_pt_lost()
3135 sample->pid, sample->tid, 0, sample->time, in intel_pt_lost()
3136 sample->machine_pid, sample->vcpu); in intel_pt_lost()
3143 if (cpu < 0 || !pt->queues.nr_queues) in intel_pt_cpu_to_ptq()
3146 if ((unsigned)cpu >= pt->queues.nr_queues) in intel_pt_cpu_to_ptq()
3147 i = pt->queues.nr_queues - 1; in intel_pt_cpu_to_ptq()
3151 if (pt->queues.queue_array[i].cpu == cpu) in intel_pt_cpu_to_ptq()
3152 return pt->queues.queue_array[i].priv; in intel_pt_cpu_to_ptq()
3155 if (pt->queues.queue_array[--i].cpu == cpu) in intel_pt_cpu_to_ptq()
3156 return pt->queues.queue_array[i].priv; in intel_pt_cpu_to_ptq()
3159 for (; j < pt->queues.nr_queues; j++) { in intel_pt_cpu_to_ptq()
3160 if (pt->queues.queue_array[j].cpu == cpu) in intel_pt_cpu_to_ptq()
3161 return pt->queues.queue_array[j].priv; in intel_pt_cpu_to_ptq()
3173 if (!pt->sync_switch) in intel_pt_sync_switch()
3177 if (!ptq || !ptq->sync_switch) in intel_pt_sync_switch()
3180 switch (ptq->switch_state) { in intel_pt_sync_switch()
3185 ptq->next_tid = tid; in intel_pt_sync_switch()
3186 ptq->switch_state = INTEL_PT_SS_EXPECTING_SWITCH_IP; in intel_pt_sync_switch()
3189 if (!ptq->on_heap) { in intel_pt_sync_switch()
3190 ptq->timestamp = perf_time_to_tsc(timestamp, in intel_pt_sync_switch()
3191 &pt->tc); in intel_pt_sync_switch()
3192 err = auxtrace_heap__add(&pt->heap, ptq->queue_nr, in intel_pt_sync_switch()
3193 ptq->timestamp); in intel_pt_sync_switch()
3196 ptq->on_heap = true; in intel_pt_sync_switch()
3198 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_sync_switch()
3207 ptq->next_tid = -1; in intel_pt_sync_switch()
3214 struct perf_sample *sample) in intel_pt_process_switch() argument
3218 struct evsel *evsel = evlist__id2evsel(pt->session->evlist, sample->id); in intel_pt_process_switch()
3220 if (evsel != pt->switch_evsel) in intel_pt_process_switch()
3223 tid = evsel__intval(evsel, sample, "next_pid"); in intel_pt_process_switch()
3224 cpu = sample->cpu; in intel_pt_process_switch()
3226 intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n", in intel_pt_process_switch()
3227 cpu, tid, sample->time, perf_time_to_tsc(sample->time, in intel_pt_process_switch()
3228 &pt->tc)); in intel_pt_process_switch()
3230 ret = intel_pt_sync_switch(pt, cpu, tid, sample->time); in intel_pt_process_switch()
3234 return machine__set_current_tid(pt->machine, cpu, -1, tid); in intel_pt_process_switch()
3239 struct perf_sample *sample) in intel_pt_context_switch_in() argument
3241 pid_t pid = sample->pid; in intel_pt_context_switch_in()
3242 pid_t tid = sample->tid; in intel_pt_context_switch_in()
3243 int cpu = sample->cpu; in intel_pt_context_switch_in()
3245 if (pt->sync_switch) { in intel_pt_context_switch_in()
3249 if (ptq && ptq->sync_switch) { in intel_pt_context_switch_in()
3250 ptq->next_tid = -1; in intel_pt_context_switch_in()
3251 switch (ptq->switch_state) { in intel_pt_context_switch_in()
3258 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_context_switch_in()
3270 if (machine__get_current_tid(pt->machine, cpu) == tid) in intel_pt_context_switch_in()
3273 return machine__set_current_tid(pt->machine, cpu, pid, tid); in intel_pt_context_switch_in()
3278 struct perf_sample *sample) in intel_pt_guest_context_switch() argument
3280 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; in intel_pt_guest_context_switch()
3281 struct machines *machines = &pt->session->machines; in intel_pt_guest_context_switch()
3282 struct machine *machine = machines__find(machines, sample->machine_pid); in intel_pt_guest_context_switch()
3284 pt->have_guest_sideband = true; in intel_pt_guest_context_switch()
3290 pt->sync_switch_not_supported = true; in intel_pt_guest_context_switch()
3291 if (pt->sync_switch) in intel_pt_guest_context_switch()
3298 return -EINVAL; in intel_pt_guest_context_switch()
3300 return machine__set_current_tid(machine, sample->vcpu, sample->pid, sample->tid); in intel_pt_guest_context_switch()
3304 struct perf_sample *sample) in intel_pt_context_switch() argument
3306 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; in intel_pt_context_switch()
3311 return intel_pt_guest_context_switch(pt, event, sample); in intel_pt_context_switch()
3313 cpu = sample->cpu; in intel_pt_context_switch()
3315 if (pt->have_sched_switch == 3) { in intel_pt_context_switch()
3317 return intel_pt_context_switch_in(pt, sample); in intel_pt_context_switch()
3318 if (event->header.type != PERF_RECORD_SWITCH_CPU_WIDE) { in intel_pt_context_switch()
3319 pr_err("Expecting CPU-wide context switch event\n"); in intel_pt_context_switch()
3320 return -EINVAL; in intel_pt_context_switch()
3322 pid = event->context_switch.next_prev_pid; in intel_pt_context_switch()
3323 tid = event->context_switch.next_prev_tid; in intel_pt_context_switch()
3327 pid = sample->pid; in intel_pt_context_switch()
3328 tid = sample->tid; in intel_pt_context_switch()
3331 if (tid == -1) in intel_pt_context_switch()
3334 ret = intel_pt_sync_switch(pt, cpu, tid, sample->time); in intel_pt_context_switch()
3338 return machine__set_current_tid(pt->machine, cpu, pid, tid); in intel_pt_context_switch()
3343 struct perf_sample *sample) in intel_pt_process_itrace_start() argument
3345 if (!pt->per_cpu_mmaps) in intel_pt_process_itrace_start()
3348 intel_pt_log("itrace_start: cpu %d pid %d tid %d time %"PRIu64" tsc %#"PRIx64"\n", in intel_pt_process_itrace_start()
3349 sample->cpu, event->itrace_start.pid, in intel_pt_process_itrace_start()
3350 event->itrace_start.tid, sample->time, in intel_pt_process_itrace_start()
3351 perf_time_to_tsc(sample->time, &pt->tc)); in intel_pt_process_itrace_start()
3353 return machine__set_current_tid(pt->machine, sample->cpu, in intel_pt_process_itrace_start()
3354 event->itrace_start.pid, in intel_pt_process_itrace_start()
3355 event->itrace_start.tid); in intel_pt_process_itrace_start()
3360 struct perf_sample *sample) in intel_pt_process_aux_output_hw_id() argument
3362 u64 hw_id = event->aux_output_hw_id.hw_id; in intel_pt_process_aux_output_hw_id()
3367 queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); in intel_pt_process_aux_output_hw_id()
3368 evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id); in intel_pt_process_aux_output_hw_id()
3369 if (!queue || !queue->priv || !evsel || hw_id > INTEL_PT_MAX_PEBS) { in intel_pt_process_aux_output_hw_id()
3371 return -EINVAL; in intel_pt_process_aux_output_hw_id()
3374 ptq = queue->priv; in intel_pt_process_aux_output_hw_id()
3376 ptq->pebs[hw_id].evsel = evsel; in intel_pt_process_aux_output_hw_id()
3377 ptq->pebs[hw_id].id = sample->id; in intel_pt_process_aux_output_hw_id()
3385 if (!al->map || addr < map__start(al->map) || addr >= map__end(al->map)) { in intel_pt_find_map()
3387 return -1; in intel_pt_find_map()
3396 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; in intel_pt_text_poke()
3397 u64 addr = event->text_poke.addr + event->text_poke.new_len - 1; in intel_pt_text_poke()
3399 int cnt = 4096 + event->text_poke.new_len; in intel_pt_text_poke()
3400 struct thread *thread = pt->unknown_thread; in intel_pt_text_poke()
3402 struct machine *machine = pt->machine; in intel_pt_text_poke()
3408 if (!event->text_poke.new_len) in intel_pt_text_poke()
3411 for (; cnt; cnt--, addr--) { in intel_pt_text_poke()
3415 if (addr < event->text_poke.addr) in intel_pt_text_poke()
3430 if (addr + e->byte_cnt + e->length <= event->text_poke.addr) { in intel_pt_text_poke()
3436 if (e->branch != INTEL_PT_BR_NO_BRANCH) in intel_pt_text_poke()
3451 struct perf_sample *sample, in intel_pt_process_event() argument
3454 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_process_event()
3462 if (!tool->ordered_events) { in intel_pt_process_event()
3464 return -EINVAL; in intel_pt_process_event()
3467 if (sample->time && sample->time != (u64)-1) in intel_pt_process_event()
3468 timestamp = perf_time_to_tsc(sample->time, &pt->tc); in intel_pt_process_event()
3472 if (timestamp || pt->timeless_decoding) { in intel_pt_process_event()
3478 if (pt->timeless_decoding) { in intel_pt_process_event()
3479 if (pt->sampling_mode) { in intel_pt_process_event()
3480 if (sample->aux_sample.size) in intel_pt_process_event()
3482 sample); in intel_pt_process_event()
3483 } else if (event->header.type == PERF_RECORD_EXIT) { in intel_pt_process_event()
3485 event->fork.tid, in intel_pt_process_event()
3486 sample->time); in intel_pt_process_event()
3489 if (!pt->first_timestamp) in intel_pt_process_event()
3496 if (event->header.type == PERF_RECORD_SAMPLE) { in intel_pt_process_event()
3497 if (pt->synth_opts.add_callchain && !sample->callchain) in intel_pt_process_event()
3498 intel_pt_add_callchain(pt, sample); in intel_pt_process_event()
3499 if (pt->synth_opts.add_last_branch && !sample->branch_stack) in intel_pt_process_event()
3500 intel_pt_add_br_stack(pt, sample); in intel_pt_process_event()
3503 if (event->header.type == PERF_RECORD_AUX && in intel_pt_process_event()
3504 (event->aux.flags & PERF_AUX_FLAG_TRUNCATED) && in intel_pt_process_event()
3505 pt->synth_opts.errors) { in intel_pt_process_event()
3506 err = intel_pt_lost(pt, sample); in intel_pt_process_event()
3512 if (pt->switch_evsel && event->header.type == PERF_RECORD_SAMPLE) in intel_pt_process_event()
3513 err = intel_pt_process_switch(pt, sample); in intel_pt_process_event()
3516 if (event->header.type == PERF_RECORD_ITRACE_START) in intel_pt_process_event()
3517 err = intel_pt_process_itrace_start(pt, event, sample); in intel_pt_process_event()
3518 else if (event->header.type == PERF_RECORD_AUX_OUTPUT_HW_ID) in intel_pt_process_event()
3519 err = intel_pt_process_aux_output_hw_id(pt, event, sample); in intel_pt_process_event()
3520 else if (event->header.type == PERF_RECORD_SWITCH || in intel_pt_process_event()
3521 event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) in intel_pt_process_event()
3522 err = intel_pt_context_switch(pt, event, sample); in intel_pt_process_event()
3524 if (!err && event->header.type == PERF_RECORD_TEXT_POKE) in intel_pt_process_event()
3527 if (intel_pt_enable_logging && intel_pt_log_events(pt, sample->time)) { in intel_pt_process_event()
3528 intel_pt_log("event %u: cpu %d time %"PRIu64" tsc %#"PRIx64" ", in intel_pt_process_event()
3529 event->header.type, sample->cpu, sample->time, timestamp); in intel_pt_process_event()
3538 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_flush()
3545 if (!tool->ordered_events) in intel_pt_flush()
3546 return -EINVAL; in intel_pt_flush()
3552 if (pt->timeless_decoding) in intel_pt_flush()
3553 return intel_pt_process_timeless_queues(pt, -1, in intel_pt_flush()
3554 MAX_TIMESTAMP - 1); in intel_pt_flush()
3561 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_free_events()
3563 struct auxtrace_queues *queues = &pt->queues; in intel_pt_free_events()
3566 for (i = 0; i < queues->nr_queues; i++) { in intel_pt_free_events()
3567 intel_pt_free_queue(queues->queue_array[i].priv); in intel_pt_free_events()
3568 queues->queue_array[i].priv = NULL; in intel_pt_free_events()
3576 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_free()
3579 auxtrace_heap__free(&pt->heap); in intel_pt_free()
3581 session->auxtrace = NULL; in intel_pt_free()
3583 thread__put(pt->unknown_thread); in intel_pt_free()
3584 addr_filters__exit(&pt->filts); in intel_pt_free()
3585 zfree(&pt->chain); in intel_pt_free()
3586 zfree(&pt->filter); in intel_pt_free()
3587 zfree(&pt->time_ranges); in intel_pt_free()
3588 zfree(&pt->br_stack); in intel_pt_free()
3595 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_evsel_is_auxtrace()
3598 return evsel->core.attr.type == pt->pmu_type; in intel_pt_evsel_is_auxtrace()
3605 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_process_auxtrace_event()
3608 if (!pt->data_queued) { in intel_pt_process_auxtrace_event()
3611 int fd = perf_data__fd(session->data); in intel_pt_process_auxtrace_event()
3614 if (perf_data__is_pipe(session->data)) { in intel_pt_process_auxtrace_event()
3618 if (data_offset == -1) in intel_pt_process_auxtrace_event()
3619 return -errno; in intel_pt_process_auxtrace_event()
3622 err = auxtrace_queues__add_event(&pt->queues, session, event, in intel_pt_process_auxtrace_event()
3630 intel_pt_dump_event(pt, buffer->data, in intel_pt_process_auxtrace_event()
3631 buffer->size); in intel_pt_process_auxtrace_event()
3641 struct perf_sample *sample, in intel_pt_queue_data() argument
3644 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_queue_data()
3649 return auxtrace_queues__add_event(&pt->queues, session, event, in intel_pt_queue_data()
3653 if (sample->time && sample->time != (u64)-1) in intel_pt_queue_data()
3654 timestamp = perf_time_to_tsc(sample->time, &pt->tc); in intel_pt_queue_data()
3658 return auxtrace_queues__add_sample(&pt->queues, session, sample, in intel_pt_queue_data()
3667 pr_debug("Synthesizing '%s' event with id %" PRIu64 " sample type %#" PRIx64 "\n", in intel_pt_synth_event()
3668 name, id, (u64)attr->sample_type); in intel_pt_synth_event()
3684 if (evsel->core.id && evsel->core.id[0] == id) { in intel_pt_set_event_name()
3685 if (evsel->name) in intel_pt_set_event_name()
3686 zfree(&evsel->name); in intel_pt_set_event_name()
3687 evsel->name = strdup(name); in intel_pt_set_event_name()
3699 if (evsel->core.attr.type == pt->pmu_type && evsel->core.ids) in intel_pt_evsel()
3709 struct evlist *evlist = session->evlist; in intel_pt_synth_events()
3723 attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK; in intel_pt_synth_events()
3726 if (pt->timeless_decoding) in intel_pt_synth_events()
3730 if (!pt->per_cpu_mmaps) in intel_pt_synth_events()
3732 attr.exclude_user = evsel->core.attr.exclude_user; in intel_pt_synth_events()
3733 attr.exclude_kernel = evsel->core.attr.exclude_kernel; in intel_pt_synth_events()
3734 attr.exclude_hv = evsel->core.attr.exclude_hv; in intel_pt_synth_events()
3735 attr.exclude_host = evsel->core.attr.exclude_host; in intel_pt_synth_events()
3736 attr.exclude_guest = evsel->core.attr.exclude_guest; in intel_pt_synth_events()
3737 attr.sample_id_all = evsel->core.attr.sample_id_all; in intel_pt_synth_events()
3738 attr.read_format = evsel->core.attr.read_format; in intel_pt_synth_events()
3740 id = evsel->core.id[0] + 1000000000; in intel_pt_synth_events()
3744 if (pt->synth_opts.branches) { in intel_pt_synth_events()
3751 pt->sample_branches = true; in intel_pt_synth_events()
3752 pt->branches_sample_type = attr.sample_type; in intel_pt_synth_events()
3753 pt->branches_id = id; in intel_pt_synth_events()
3758 if (pt->synth_opts.callchain) in intel_pt_synth_events()
3760 if (pt->synth_opts.last_branch) { in intel_pt_synth_events()
3763 * We don't use the hardware index, but the sample generation in intel_pt_synth_events()
3770 if (pt->synth_opts.instructions) { in intel_pt_synth_events()
3772 if (pt->synth_opts.period_type == PERF_ITRACE_PERIOD_NANOSECS) in intel_pt_synth_events()
3774 intel_pt_ns_to_ticks(pt, pt->synth_opts.period); in intel_pt_synth_events()
3776 attr.sample_period = pt->synth_opts.period; in intel_pt_synth_events()
3780 pt->sample_instructions = true; in intel_pt_synth_events()
3781 pt->instructions_sample_type = attr.sample_type; in intel_pt_synth_events()
3782 pt->instructions_id = id; in intel_pt_synth_events()
3786 if (pt->synth_opts.cycles) { in intel_pt_synth_events()
3788 if (pt->synth_opts.period_type == PERF_ITRACE_PERIOD_NANOSECS) in intel_pt_synth_events()
3790 intel_pt_ns_to_ticks(pt, pt->synth_opts.period); in intel_pt_synth_events()
3792 attr.sample_period = pt->synth_opts.period; in intel_pt_synth_events()
3796 pt->sample_cycles = true; in intel_pt_synth_events()
3797 pt->cycles_sample_type = attr.sample_type; in intel_pt_synth_events()
3798 pt->cycles_id = id; in intel_pt_synth_events()
3805 if (pt->synth_opts.transactions) { in intel_pt_synth_events()
3810 pt->sample_transactions = true; in intel_pt_synth_events()
3811 pt->transactions_sample_type = attr.sample_type; in intel_pt_synth_events()
3812 pt->transactions_id = id; in intel_pt_synth_events()
3820 if (pt->synth_opts.ptwrites) { in intel_pt_synth_events()
3825 pt->sample_ptwrites = true; in intel_pt_synth_events()
3826 pt->ptwrites_sample_type = attr.sample_type; in intel_pt_synth_events()
3827 pt->ptwrites_id = id; in intel_pt_synth_events()
3832 if (pt->synth_opts.pwr_events) { in intel_pt_synth_events()
3833 pt->sample_pwr_events = true; in intel_pt_synth_events()
3834 pt->pwr_events_sample_type = attr.sample_type; in intel_pt_synth_events()
3840 pt->cbr_id = id; in intel_pt_synth_events()
3848 pt->psb_id = id; in intel_pt_synth_events()
3853 if (pt->synth_opts.pwr_events && (evsel->core.attr.config & INTEL_PT_CFG_PWR_EVT_EN)) { in intel_pt_synth_events()
3858 pt->mwait_id = id; in intel_pt_synth_events()
3866 pt->pwre_id = id; in intel_pt_synth_events()
3874 pt->exstop_id = id; in intel_pt_synth_events()
3882 pt->pwrx_id = id; in intel_pt_synth_events()
3887 if (pt->synth_opts.intr_events && (evsel->core.attr.config & INTEL_PT_CFG_EVT_EN)) { in intel_pt_synth_events()
3892 pt->evt_sample_type = attr.sample_type; in intel_pt_synth_events()
3893 pt->evt_id = id; in intel_pt_synth_events()
3898 if (pt->synth_opts.intr_events && pt->cap_event_trace) { in intel_pt_synth_events()
3903 pt->iflag_chg_sample_type = attr.sample_type; in intel_pt_synth_events()
3904 pt->iflag_chg_id = id; in intel_pt_synth_events()
3916 if (!pt->synth_opts.other_events) in intel_pt_setup_pebs_events()
3919 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_setup_pebs_events()
3920 if (evsel->core.attr.aux_output && evsel->core.id) { in intel_pt_setup_pebs_events()
3921 if (pt->single_pebs) { in intel_pt_setup_pebs_events()
3922 pt->single_pebs = false; in intel_pt_setup_pebs_events()
3925 pt->single_pebs = true; in intel_pt_setup_pebs_events()
3926 pt->sample_pebs = true; in intel_pt_setup_pebs_events()
3927 pt->pebs_evsel = evsel; in intel_pt_setup_pebs_events()
3951 if (evsel->core.attr.context_switch) in intel_pt_find_switch()
3962 if (!strcmp(var, "intel-pt.mispred-all")) in intel_pt_perf_config()
3963 pt->mispred_all = perf_config_bool(var, value); in intel_pt_perf_config()
3965 if (!strcmp(var, "intel-pt.max-loops")) in intel_pt_perf_config()
3966 perf_config_int(&pt->max_loops, var, value); in intel_pt_perf_config()
3976 tsc = perf_time_to_tsc(ns, &pt->tc); in intel_pt_tsc_start()
3979 tm = tsc_to_perf_time(tsc, &pt->tc); in intel_pt_tsc_start()
3982 tsc -= 1; in intel_pt_tsc_start()
3986 tm = tsc_to_perf_time(++tsc, &pt->tc); in intel_pt_tsc_start()
3996 tsc = perf_time_to_tsc(ns, &pt->tc); in intel_pt_tsc_end()
3999 tm = tsc_to_perf_time(tsc, &pt->tc); in intel_pt_tsc_end()
4006 tm = tsc_to_perf_time(--tsc, &pt->tc); in intel_pt_tsc_end()
4014 struct perf_time_interval *p = opts->ptime_range; in intel_pt_setup_time_ranges()
4015 int n = opts->range_num; in intel_pt_setup_time_ranges()
4018 if (!n || !p || pt->timeless_decoding) in intel_pt_setup_time_ranges()
4021 pt->time_ranges = calloc(n, sizeof(struct range)); in intel_pt_setup_time_ranges()
4022 if (!pt->time_ranges) in intel_pt_setup_time_ranges()
4023 return -ENOMEM; in intel_pt_setup_time_ranges()
4025 pt->range_cnt = n; in intel_pt_setup_time_ranges()
4030 struct range *r = &pt->time_ranges[i]; in intel_pt_setup_time_ranges()
4035 * Take care to ensure the TSC range matches the perf-time range in intel_pt_setup_time_ranges()
4036 * when converted back to perf-time. in intel_pt_setup_time_ranges()
4038 r->start = ts ? intel_pt_tsc_start(ts, pt) : 0; in intel_pt_setup_time_ranges()
4039 r->end = te ? intel_pt_tsc_end(te, pt) : 0; in intel_pt_setup_time_ranges()
4041 intel_pt_log("range %d: perf time interval: %"PRIu64" to %"PRIu64"\n", in intel_pt_setup_time_ranges()
4043 intel_pt_log("range %d: TSC time interval: %#"PRIx64" to %#"PRIx64"\n", in intel_pt_setup_time_ranges()
4044 i, r->start, r->end); in intel_pt_setup_time_ranges()
4064 return -errno; in intel_pt_parse_vm_tm_corr_arg()
4067 pt->dflt_tsc_offset = tsc_offset; in intel_pt_parse_vm_tm_corr_arg()
4075 return -errno; in intel_pt_parse_vm_tm_corr_arg()
4077 return -EINVAL; in intel_pt_parse_vm_tm_corr_arg()
4078 vmcs_info = intel_pt_findnew_vmcs(&pt->vmcs_info, vmcs, tsc_offset); in intel_pt_parse_vm_tm_corr_arg()
4080 return -ENOMEM; in intel_pt_parse_vm_tm_corr_arg()
4092 char *args = pt->synth_opts.vm_tm_corr_args; in intel_pt_parse_vm_tm_corr_args()
4103 pr_err("Failed to parse VM Time Correlation options\n"); in intel_pt_parse_vm_tm_corr_args()
4112 [INTEL_PT_TIME_SHIFT] = " Time Shift %"PRIu64"\n",
4113 [INTEL_PT_TIME_MULT] = " Time Muliplier %"PRIu64"\n",
4114 [INTEL_PT_TIME_ZERO] = " Time Zero %"PRIu64"\n",
4115 [INTEL_PT_CAP_USER_TIME_ZERO] = " Cap Time Zero %"PRId64"\n",
4120 [INTEL_PT_PER_CPU_MMAPS] = " Per-cpu maps %"PRId64"\n",
4126 [INTEL_PT_MAX_NONTURBO_RATIO] = " Max non-turbo ratio %"PRIu64"\n",
4150 fprintf(stdout, " %-20s%s\n", name, str ? str : ""); in intel_pt_print_info_str()
4155 return auxtrace_info->header.size >= in intel_pt_has()
4162 struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; in intel_pt_process_auxtrace_info()
4169 if (auxtrace_info->header.size < sizeof(struct perf_record_auxtrace_info) + in intel_pt_process_auxtrace_info()
4171 return -EINVAL; in intel_pt_process_auxtrace_info()
4175 return -ENOMEM; in intel_pt_process_auxtrace_info()
4177 pt->vmcs_info = RB_ROOT; in intel_pt_process_auxtrace_info()
4179 addr_filters__init(&pt->filts); in intel_pt_process_auxtrace_info()
4185 err = auxtrace_queues__init(&pt->queues); in intel_pt_process_auxtrace_info()
4189 if (session->itrace_synth_opts->set) { in intel_pt_process_auxtrace_info()
4190 pt->synth_opts = *session->itrace_synth_opts; in intel_pt_process_auxtrace_info()
4192 struct itrace_synth_opts *opts = session->itrace_synth_opts; in intel_pt_process_auxtrace_info()
4194 itrace_synth_opts__set_default(&pt->synth_opts, opts->default_no_sample); in intel_pt_process_auxtrace_info()
4195 if (!opts->default_no_sample && !opts->inject) { in intel_pt_process_auxtrace_info()
4196 pt->synth_opts.branches = false; in intel_pt_process_auxtrace_info()
4197 pt->synth_opts.callchain = true; in intel_pt_process_auxtrace_info()
4198 pt->synth_opts.add_callchain = true; in intel_pt_process_auxtrace_info()
4200 pt->synth_opts.thread_stack = opts->thread_stack; in intel_pt_process_auxtrace_info()
4203 if (!(pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_USE_STDOUT)) in intel_pt_process_auxtrace_info()
4206 pt->session = session; in intel_pt_process_auxtrace_info()
4207 pt->machine = &session->machines.host; /* No kvm support */ in intel_pt_process_auxtrace_info()
4208 pt->auxtrace_type = auxtrace_info->type; in intel_pt_process_auxtrace_info()
4209 pt->pmu_type = auxtrace_info->priv[INTEL_PT_PMU_TYPE]; in intel_pt_process_auxtrace_info()
4210 pt->tc.time_shift = auxtrace_info->priv[INTEL_PT_TIME_SHIFT]; in intel_pt_process_auxtrace_info()
4211 pt->tc.time_mult = auxtrace_info->priv[INTEL_PT_TIME_MULT]; in intel_pt_process_auxtrace_info()
4212 pt->tc.time_zero = auxtrace_info->priv[INTEL_PT_TIME_ZERO]; in intel_pt_process_auxtrace_info()
4213 pt->cap_user_time_zero = auxtrace_info->priv[INTEL_PT_CAP_USER_TIME_ZERO]; in intel_pt_process_auxtrace_info()
4214 pt->tsc_bit = auxtrace_info->priv[INTEL_PT_TSC_BIT]; in intel_pt_process_auxtrace_info()
4215 pt->noretcomp_bit = auxtrace_info->priv[INTEL_PT_NORETCOMP_BIT]; in intel_pt_process_auxtrace_info()
4216 pt->have_sched_switch = auxtrace_info->priv[INTEL_PT_HAVE_SCHED_SWITCH]; in intel_pt_process_auxtrace_info()
4217 pt->snapshot_mode = auxtrace_info->priv[INTEL_PT_SNAPSHOT_MODE]; in intel_pt_process_auxtrace_info()
4218 pt->per_cpu_mmaps = auxtrace_info->priv[INTEL_PT_PER_CPU_MMAPS]; in intel_pt_process_auxtrace_info()
4219 intel_pt_print_info(&auxtrace_info->priv[0], INTEL_PT_PMU_TYPE, in intel_pt_process_auxtrace_info()
4223 pt->mtc_bit = auxtrace_info->priv[INTEL_PT_MTC_BIT]; in intel_pt_process_auxtrace_info()
4224 pt->mtc_freq_bits = auxtrace_info->priv[INTEL_PT_MTC_FREQ_BITS]; in intel_pt_process_auxtrace_info()
4225 pt->tsc_ctc_ratio_n = auxtrace_info->priv[INTEL_PT_TSC_CTC_N]; in intel_pt_process_auxtrace_info()
4226 pt->tsc_ctc_ratio_d = auxtrace_info->priv[INTEL_PT_TSC_CTC_D]; in intel_pt_process_auxtrace_info()
4227 pt->cyc_bit = auxtrace_info->priv[INTEL_PT_CYC_BIT]; in intel_pt_process_auxtrace_info()
4228 intel_pt_print_info(&auxtrace_info->priv[0], INTEL_PT_MTC_BIT, in intel_pt_process_auxtrace_info()
4233 pt->max_non_turbo_ratio = in intel_pt_process_auxtrace_info()
4234 auxtrace_info->priv[INTEL_PT_MAX_NONTURBO_RATIO]; in intel_pt_process_auxtrace_info()
4235 intel_pt_print_info(&auxtrace_info->priv[0], in intel_pt_process_auxtrace_info()
4240 info = &auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN] + 1; in intel_pt_process_auxtrace_info()
4241 info_end = (void *)auxtrace_info + auxtrace_info->header.size; in intel_pt_process_auxtrace_info()
4246 len = auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN]; in intel_pt_process_auxtrace_info()
4247 intel_pt_print_info(&auxtrace_info->priv[0], in intel_pt_process_auxtrace_info()
4257 err = -EINVAL; in intel_pt_process_auxtrace_info()
4260 pt->filter = memdup(filter, len); in intel_pt_process_auxtrace_info()
4261 if (!pt->filter) { in intel_pt_process_auxtrace_info()
4262 err = -ENOMEM; in intel_pt_process_auxtrace_info()
4265 if (session->header.needs_swap) in intel_pt_process_auxtrace_info()
4266 mem_bswap_64(pt->filter, len); in intel_pt_process_auxtrace_info()
4267 if (pt->filter[len - 1]) { in intel_pt_process_auxtrace_info()
4269 err = -EINVAL; in intel_pt_process_auxtrace_info()
4272 err = addr_filters__parse_bare_filter(&pt->filts, in intel_pt_process_auxtrace_info()
4277 intel_pt_print_info_str("Filter string", pt->filter); in intel_pt_process_auxtrace_info()
4281 pt->cap_event_trace = *info++; in intel_pt_process_auxtrace_info()
4284 pt->cap_event_trace); in intel_pt_process_auxtrace_info()
4287 pt->timeless_decoding = intel_pt_timeless_decoding(pt); in intel_pt_process_auxtrace_info()
4288 if (pt->timeless_decoding && !pt->tc.time_mult) in intel_pt_process_auxtrace_info()
4289 pt->tc.time_mult = 1; in intel_pt_process_auxtrace_info()
4290 pt->have_tsc = intel_pt_have_tsc(pt); in intel_pt_process_auxtrace_info()
4291 pt->sampling_mode = intel_pt_sampling_mode(pt); in intel_pt_process_auxtrace_info()
4292 pt->est_tsc = !pt->timeless_decoding; in intel_pt_process_auxtrace_info()
4294 if (pt->synth_opts.vm_time_correlation) { in intel_pt_process_auxtrace_info()
4295 if (pt->timeless_decoding) { in intel_pt_process_auxtrace_info()
4296 pr_err("Intel PT has no time information for VM Time Correlation\n"); in intel_pt_process_auxtrace_info()
4297 err = -EINVAL; in intel_pt_process_auxtrace_info()
4300 if (session->itrace_synth_opts->ptime_range) { in intel_pt_process_auxtrace_info()
4301 pr_err("Time ranges cannot be specified with VM Time Correlation\n"); in intel_pt_process_auxtrace_info()
4302 err = -EINVAL; in intel_pt_process_auxtrace_info()
4307 pr_err("MTC packets must have been enabled for VM Time Correlation\n"); in intel_pt_process_auxtrace_info()
4308 err = -EINVAL; in intel_pt_process_auxtrace_info()
4316 pt->unknown_thread = thread__new(999999999, 999999999); in intel_pt_process_auxtrace_info()
4317 if (!pt->unknown_thread) { in intel_pt_process_auxtrace_info()
4318 err = -ENOMEM; in intel_pt_process_auxtrace_info()
4322 err = thread__set_comm(pt->unknown_thread, "unknown", 0); in intel_pt_process_auxtrace_info()
4325 if (thread__init_maps(pt->unknown_thread, pt->machine)) { in intel_pt_process_auxtrace_info()
4326 err = -ENOMEM; in intel_pt_process_auxtrace_info()
4330 pt->auxtrace.process_event = intel_pt_process_event; in intel_pt_process_auxtrace_info()
4331 pt->auxtrace.process_auxtrace_event = intel_pt_process_auxtrace_event; in intel_pt_process_auxtrace_info()
4332 pt->auxtrace.queue_data = intel_pt_queue_data; in intel_pt_process_auxtrace_info()
4333 pt->auxtrace.dump_auxtrace_sample = intel_pt_dump_sample; in intel_pt_process_auxtrace_info()
4334 pt->auxtrace.flush_events = intel_pt_flush; in intel_pt_process_auxtrace_info()
4335 pt->auxtrace.free_events = intel_pt_free_events; in intel_pt_process_auxtrace_info()
4336 pt->auxtrace.free = intel_pt_free; in intel_pt_process_auxtrace_info()
4337 pt->auxtrace.evsel_is_auxtrace = intel_pt_evsel_is_auxtrace; in intel_pt_process_auxtrace_info()
4338 session->auxtrace = &pt->auxtrace; in intel_pt_process_auxtrace_info()
4343 if (pt->have_sched_switch == 1) { in intel_pt_process_auxtrace_info()
4344 pt->switch_evsel = intel_pt_find_sched_switch(session->evlist); in intel_pt_process_auxtrace_info()
4345 if (!pt->switch_evsel) { in intel_pt_process_auxtrace_info()
4347 err = -EINVAL; in intel_pt_process_auxtrace_info()
4350 } else if (pt->have_sched_switch == 2 && in intel_pt_process_auxtrace_info()
4351 !intel_pt_find_switch(session->evlist)) { in intel_pt_process_auxtrace_info()
4353 err = -EINVAL; in intel_pt_process_auxtrace_info()
4357 if (pt->synth_opts.log) { in intel_pt_process_auxtrace_info()
4358 bool log_on_error = pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_ON_ERROR; in intel_pt_process_auxtrace_info()
4359 unsigned int log_on_error_size = pt->synth_opts.log_on_error_size; in intel_pt_process_auxtrace_info()
4364 /* Maximum non-turbo ratio is TSC freq / 100 MHz */ in intel_pt_process_auxtrace_info()
4365 if (pt->tc.time_mult) { in intel_pt_process_auxtrace_info()
4368 if (!pt->max_non_turbo_ratio) in intel_pt_process_auxtrace_info()
4369 pt->max_non_turbo_ratio = in intel_pt_process_auxtrace_info()
4372 intel_pt_log("Maximum non-turbo ratio %u\n", in intel_pt_process_auxtrace_info()
4373 pt->max_non_turbo_ratio); in intel_pt_process_auxtrace_info()
4374 pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000; in intel_pt_process_auxtrace_info()
4377 err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); in intel_pt_process_auxtrace_info()
4381 if (pt->synth_opts.calls) in intel_pt_process_auxtrace_info()
4382 pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | in intel_pt_process_auxtrace_info()
4384 if (pt->synth_opts.returns) in intel_pt_process_auxtrace_info()
4385 pt->branches_filter |= PERF_IP_FLAG_RETURN | in intel_pt_process_auxtrace_info()
4388 if ((pt->synth_opts.callchain || pt->synth_opts.add_callchain) && in intel_pt_process_auxtrace_info()
4393 pt->synth_opts.callchain = false; in intel_pt_process_auxtrace_info()
4394 pt->synth_opts.add_callchain = false; in intel_pt_process_auxtrace_info()
4398 if (pt->synth_opts.add_callchain) { in intel_pt_process_auxtrace_info()
4404 if (pt->synth_opts.last_branch || pt->synth_opts.add_last_branch) { in intel_pt_process_auxtrace_info()
4405 pt->br_stack_sz = pt->synth_opts.last_branch_sz; in intel_pt_process_auxtrace_info()
4406 pt->br_stack_sz_plus = pt->br_stack_sz; in intel_pt_process_auxtrace_info()
4409 if (pt->synth_opts.add_last_branch) { in intel_pt_process_auxtrace_info()
4415 * actual sample ip to where the sample time is recorded. in intel_pt_process_auxtrace_info()
4421 pt->br_stack_sz_plus += 1024; in intel_pt_process_auxtrace_info()
4423 pt->br_stack_sz_plus += 1; in intel_pt_process_auxtrace_info()
4426 pt->use_thread_stack = pt->synth_opts.callchain || in intel_pt_process_auxtrace_info()
4427 pt->synth_opts.add_callchain || in intel_pt_process_auxtrace_info()
4428 pt->synth_opts.thread_stack || in intel_pt_process_auxtrace_info()
4429 pt->synth_opts.last_branch || in intel_pt_process_auxtrace_info()
4430 pt->synth_opts.add_last_branch; in intel_pt_process_auxtrace_info()
4432 pt->callstack = pt->synth_opts.callchain || in intel_pt_process_auxtrace_info()
4433 pt->synth_opts.add_callchain || in intel_pt_process_auxtrace_info()
4434 pt->synth_opts.thread_stack; in intel_pt_process_auxtrace_info()
4442 if (perf_data__is_pipe(session->data)) { in intel_pt_process_auxtrace_info()
4448 if (pt->sampling_mode || list_empty(&session->auxtrace_index)) in intel_pt_process_auxtrace_info()
4451 err = auxtrace_queues__process_index(&pt->queues, session); in intel_pt_process_auxtrace_info()
4455 if (pt->queues.populated) in intel_pt_process_auxtrace_info()
4456 pt->data_queued = true; in intel_pt_process_auxtrace_info()
4458 if (pt->timeless_decoding) in intel_pt_process_auxtrace_info()
4464 zfree(&pt->chain); in intel_pt_process_auxtrace_info()
4465 thread__zput(pt->unknown_thread); in intel_pt_process_auxtrace_info()
4468 auxtrace_queues__free(&pt->queues); in intel_pt_process_auxtrace_info()
4469 session->auxtrace = NULL; in intel_pt_process_auxtrace_info()
4471 addr_filters__exit(&pt->filts); in intel_pt_process_auxtrace_info()
4472 zfree(&pt->filter); in intel_pt_process_auxtrace_info()
4473 zfree(&pt->time_ranges); in intel_pt_process_auxtrace_info()