Lines Matching +full:ip +full:- +full:core

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2013-2015, Intel Corporation.
27 #include "thread-stack.h"
34 #include "intel-pt.h"
37 #include "util/synthetic-events.h"
38 #include "time-utils.h"
42 #include "intel-pt-decoder/intel-pt-log.h"
43 #include "intel-pt-decoder/intel-pt-decoder.h"
44 #include "intel-pt-decoder/intel-pt-insn-decoder.h"
45 #include "intel-pt-decoder/intel-pt-pkt-decoder.h"
167 /* applicable_counters is 64-bits */
260 len -= pkt_len; in intel_pt_dump()
284 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_dump_sample()
288 intel_pt_dump(pt, sample->aux_sample.data, sample->aux_sample.size); in intel_pt_dump_sample()
293 struct perf_time_interval *range = pt->synth_opts.ptime_range; in intel_pt_log_events()
294 int n = pt->synth_opts.range_num; in intel_pt_log_events()
296 if (pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_ALL_PERF_EVTS) in intel_pt_log_events()
299 if (pt->synth_opts.log_minus_flags & AUXTRACE_LOG_FLG_ALL_PERF_EVTS) in intel_pt_log_events()
313 struct rb_node **p = &rb_root->rb_node; in intel_pt_findnew_vmcs()
321 if (v->vmcs == vmcs) in intel_pt_findnew_vmcs()
324 if (vmcs < v->vmcs) in intel_pt_findnew_vmcs()
325 p = &(*p)->rb_left; in intel_pt_findnew_vmcs()
327 p = &(*p)->rb_right; in intel_pt_findnew_vmcs()
332 v->vmcs = vmcs; in intel_pt_findnew_vmcs()
333 v->tsc_offset = dflt_tsc_offset; in intel_pt_findnew_vmcs()
334 v->reliable = dflt_tsc_offset; in intel_pt_findnew_vmcs()
336 rb_link_node(&v->rb_node, parent, p); in intel_pt_findnew_vmcs()
337 rb_insert_color(&v->rb_node, rb_root); in intel_pt_findnew_vmcs()
346 struct intel_pt *pt = ptq->pt; in intel_pt_findnew_vmcs_info()
348 if (!vmcs && !pt->dflt_tsc_offset) in intel_pt_findnew_vmcs_info()
351 return intel_pt_findnew_vmcs(&pt->vmcs_info, vmcs, pt->dflt_tsc_offset); in intel_pt_findnew_vmcs_info()
359 n = rb_first(&pt->vmcs_info); in intel_pt_free_vmcs_info()
363 rb_erase(&v->rb_node, &pt->vmcs_info); in intel_pt_free_vmcs_info()
374 start = intel_pt_find_overlap(a->data, a->size, b->data, b->size, in intel_pt_do_fix_overlap()
375 pt->have_tsc, &consecutive, in intel_pt_do_fix_overlap()
376 pt->synth_opts.vm_time_correlation); in intel_pt_do_fix_overlap()
378 return -EINVAL; in intel_pt_do_fix_overlap()
384 if (pt->synth_opts.vm_time_correlation) in intel_pt_do_fix_overlap()
385 memset(b->data, 0, start - b->data); in intel_pt_do_fix_overlap()
386 b->use_size = b->data + b->size - start; in intel_pt_do_fix_overlap()
387 b->use_data = start; in intel_pt_do_fix_overlap()
388 if (b->use_size && consecutive) in intel_pt_do_fix_overlap()
389 b->consecutive = true; in intel_pt_do_fix_overlap()
400 if (!buffer->data) { in intel_pt_get_buffer()
401 int fd = perf_data__fd(ptq->pt->session->data); in intel_pt_get_buffer()
403 buffer->data = auxtrace_buffer__get_data(buffer, fd); in intel_pt_get_buffer()
404 if (!buffer->data) in intel_pt_get_buffer()
405 return -ENOMEM; in intel_pt_get_buffer()
408 might_overlap = ptq->pt->snapshot_mode || ptq->pt->sampling_mode; in intel_pt_get_buffer()
409 if (might_overlap && !buffer->consecutive && old_buffer && in intel_pt_get_buffer()
410 intel_pt_do_fix_overlap(ptq->pt, old_buffer, buffer)) in intel_pt_get_buffer()
411 return -ENOMEM; in intel_pt_get_buffer()
413 if (buffer->use_data) { in intel_pt_get_buffer()
414 b->len = buffer->use_size; in intel_pt_get_buffer()
415 b->buf = buffer->use_data; in intel_pt_get_buffer()
417 b->len = buffer->size; in intel_pt_get_buffer()
418 b->buf = buffer->data; in intel_pt_get_buffer()
420 b->ref_timestamp = buffer->reference; in intel_pt_get_buffer()
422 if (!old_buffer || (might_overlap && !buffer->consecutive)) { in intel_pt_get_buffer()
423 b->consecutive = false; in intel_pt_get_buffer()
424 b->trace_nr = buffer->buffer_nr + 1; in intel_pt_get_buffer()
426 b->consecutive = true; in intel_pt_get_buffer()
432 /* Do not drop buffers with references - refer intel_pt_get_trace() */
436 if (!buffer || buffer == ptq->buffer || buffer == ptq->old_buffer) in intel_pt_lookahead_drop_buffer()
447 struct auxtrace_buffer *buffer = ptq->buffer; in intel_pt_lookahead()
448 struct auxtrace_buffer *old_buffer = ptq->old_buffer; in intel_pt_lookahead()
452 queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; in intel_pt_lookahead()
492 struct auxtrace_buffer *buffer = ptq->buffer; in intel_pt_get_trace()
493 struct auxtrace_buffer *old_buffer = ptq->old_buffer; in intel_pt_get_trace()
497 if (ptq->stop) { in intel_pt_get_trace()
498 b->len = 0; in intel_pt_get_trace()
502 queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; in intel_pt_get_trace()
508 b->len = 0; in intel_pt_get_trace()
512 ptq->buffer = buffer; in intel_pt_get_trace()
518 if (ptq->step_through_buffers) in intel_pt_get_trace()
519 ptq->stop = true; in intel_pt_get_trace()
521 if (b->len) { in intel_pt_get_trace()
524 ptq->old_buffer = buffer; in intel_pt_get_trace()
550 if (!strcmp(var, "intel-pt.cache-divisor")) { in intel_pt_config_div()
585 return 32 - __builtin_clz(size); in intel_pt_cache_size()
594 if (dso->auxtrace_cache) in intel_pt_cache()
595 return dso->auxtrace_cache; in intel_pt_cache()
602 dso->auxtrace_cache = c; in intel_pt_cache()
616 return -ENOMEM; in intel_pt_cache_add()
620 return -ENOMEM; in intel_pt_cache_add()
622 e->insn_cnt = insn_cnt; in intel_pt_cache_add()
623 e->byte_cnt = byte_cnt; in intel_pt_cache_add()
624 e->op = intel_pt_insn->op; in intel_pt_cache_add()
625 e->branch = intel_pt_insn->branch; in intel_pt_cache_add()
626 e->emulated_ptwrite = intel_pt_insn->emulated_ptwrite; in intel_pt_cache_add()
627 e->length = intel_pt_insn->length; in intel_pt_cache_add()
628 e->rel = intel_pt_insn->rel; in intel_pt_cache_add()
629 memcpy(e->insn, intel_pt_insn->buf, INTEL_PT_INSN_BUF_SZ); in intel_pt_cache_add()
631 err = auxtrace_cache__add(c, offset, &e->entry); in intel_pt_cache_add()
646 return auxtrace_cache__lookup(dso->auxtrace_cache, offset); in intel_pt_cache_lookup()
657 auxtrace_cache__remove(dso->auxtrace_cache, offset); in intel_pt_cache_invalidate()
660 static inline bool intel_pt_guest_kernel_ip(uint64_t ip) in intel_pt_guest_kernel_ip() argument
662 /* Assumes 64-bit kernel */ in intel_pt_guest_kernel_ip()
663 return ip & (1ULL << 63); in intel_pt_guest_kernel_ip()
666 static inline u8 intel_pt_nr_cpumode(struct intel_pt_queue *ptq, uint64_t ip, bool nr) in intel_pt_nr_cpumode() argument
669 return intel_pt_guest_kernel_ip(ip) ? in intel_pt_nr_cpumode()
674 return ip >= ptq->pt->kernel_start ? in intel_pt_nr_cpumode()
681 /* No support for non-zero CS base */ in intel_pt_cpumode()
683 return intel_pt_nr_cpumode(ptq, from_ip, ptq->state->from_nr); in intel_pt_cpumode()
684 return intel_pt_nr_cpumode(ptq, to_ip, ptq->state->to_nr); in intel_pt_cpumode()
689 struct machines *machines = &ptq->pt->session->machines; in intel_pt_get_guest()
691 pid_t pid = ptq->pid <= 0 ? DEFAULT_GUEST_KERNEL_ID : ptq->pid; in intel_pt_get_guest()
693 if (ptq->guest_machine && pid == ptq->guest_machine->pid) in intel_pt_get_guest()
696 ptq->guest_machine = NULL; in intel_pt_get_guest()
697 thread__zput(ptq->unknown_guest_thread); in intel_pt_get_guest()
700 thread__zput(ptq->guest_thread); in intel_pt_get_guest()
701 ptq->guest_thread = machines__findnew_guest_code(machines, pid); in intel_pt_get_guest()
706 return -1; in intel_pt_get_guest()
708 ptq->unknown_guest_thread = machine__idle_thread(machine); in intel_pt_get_guest()
709 if (!ptq->unknown_guest_thread) in intel_pt_get_guest()
710 return -1; in intel_pt_get_guest()
712 ptq->guest_machine = machine; in intel_pt_get_guest()
719 return intel_pt_insn->rel == 16 && intel_pt_insn->branch == INTEL_PT_BR_UNCONDITIONAL; in intel_pt_jmp_16()
740 uint64_t *insn_cnt_ptr, uint64_t *ip, in intel_pt_walk_next_insn() argument
745 struct machine *machine = ptq->pt->machine; in intel_pt_walk_next_insn()
757 intel_pt_insn->length = 0; in intel_pt_walk_next_insn()
759 if (to_ip && *ip == to_ip) in intel_pt_walk_next_insn()
762 nr = ptq->state->to_nr; in intel_pt_walk_next_insn()
763 cpumode = intel_pt_nr_cpumode(ptq, *ip, nr); in intel_pt_walk_next_insn()
766 if (ptq->pt->have_guest_sideband) { in intel_pt_walk_next_insn()
767 if (!ptq->guest_machine || ptq->guest_machine_pid != ptq->pid) { in intel_pt_walk_next_insn()
769 return -EINVAL; in intel_pt_walk_next_insn()
774 return -EINVAL; in intel_pt_walk_next_insn()
776 machine = ptq->guest_machine; in intel_pt_walk_next_insn()
777 thread = ptq->guest_thread; in intel_pt_walk_next_insn()
781 return -EINVAL; in intel_pt_walk_next_insn()
783 thread = ptq->unknown_guest_thread; in intel_pt_walk_next_insn()
786 thread = ptq->thread; in intel_pt_walk_next_insn()
790 return -EINVAL; in intel_pt_walk_next_insn()
792 thread = ptq->pt->unknown_thread; in intel_pt_walk_next_insn()
797 if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso) { in intel_pt_walk_next_insn()
799 intel_pt_log("ERROR: thread has no dso for %#" PRIx64 "\n", *ip); in intel_pt_walk_next_insn()
801 intel_pt_log("ERROR: thread has no map for %#" PRIx64 "\n", *ip); in intel_pt_walk_next_insn()
802 return -EINVAL; in intel_pt_walk_next_insn()
805 if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR && in intel_pt_walk_next_insn()
806 dso__data_status_seen(al.map->dso, in intel_pt_walk_next_insn()
808 return -ENOENT; in intel_pt_walk_next_insn()
810 offset = al.map->map_ip(al.map, *ip); in intel_pt_walk_next_insn()
815 e = intel_pt_cache_lookup(al.map->dso, machine, offset); in intel_pt_walk_next_insn()
817 (!max_insn_cnt || e->insn_cnt <= max_insn_cnt)) { in intel_pt_walk_next_insn()
818 *insn_cnt_ptr = e->insn_cnt; in intel_pt_walk_next_insn()
819 *ip += e->byte_cnt; in intel_pt_walk_next_insn()
820 intel_pt_insn->op = e->op; in intel_pt_walk_next_insn()
821 intel_pt_insn->branch = e->branch; in intel_pt_walk_next_insn()
822 intel_pt_insn->emulated_ptwrite = e->emulated_ptwrite; in intel_pt_walk_next_insn()
823 intel_pt_insn->length = e->length; in intel_pt_walk_next_insn()
824 intel_pt_insn->rel = e->rel; in intel_pt_walk_next_insn()
825 memcpy(intel_pt_insn->buf, e->insn, in intel_pt_walk_next_insn()
827 intel_pt_log_insn_no_data(intel_pt_insn, *ip); in intel_pt_walk_next_insn()
833 start_ip = *ip; in intel_pt_walk_next_insn()
835 /* Load maps to ensure dso->is_64_bit has been updated */ in intel_pt_walk_next_insn()
838 x86_64 = al.map->dso->is_64_bit; in intel_pt_walk_next_insn()
841 len = dso__data_read_offset(al.map->dso, machine, in intel_pt_walk_next_insn()
848 dso__fprintf(al.map->dso, intel_pt_log_fp()); in intel_pt_walk_next_insn()
849 return -EINVAL; in intel_pt_walk_next_insn()
853 return -EINVAL; in intel_pt_walk_next_insn()
855 intel_pt_log_insn(intel_pt_insn, *ip); in intel_pt_walk_next_insn()
859 if (intel_pt_insn->branch != INTEL_PT_BR_NO_BRANCH) { in intel_pt_walk_next_insn()
866 offs = offset + intel_pt_insn->length; in intel_pt_walk_next_insn()
867 eptw = intel_pt_emulated_ptwrite(al.map->dso, machine, offs); in intel_pt_walk_next_insn()
868 intel_pt_insn->emulated_ptwrite = eptw; in intel_pt_walk_next_insn()
875 *ip += intel_pt_insn->length; in intel_pt_walk_next_insn()
877 if (to_ip && *ip == to_ip) { in intel_pt_walk_next_insn()
878 intel_pt_insn->length = 0; in intel_pt_walk_next_insn()
882 if (*ip >= al.map->end) in intel_pt_walk_next_insn()
885 offset += intel_pt_insn->length; in intel_pt_walk_next_insn()
902 e = intel_pt_cache_lookup(al.map->dso, machine, start_offset); in intel_pt_walk_next_insn()
908 intel_pt_cache_add(al.map->dso, machine, start_offset, insn_cnt, in intel_pt_walk_next_insn()
909 *ip - start_ip, intel_pt_insn); in intel_pt_walk_next_insn()
918 static bool intel_pt_match_pgd_ip(struct intel_pt *pt, uint64_t ip, in intel_pt_match_pgd_ip() argument
926 list_for_each_entry(filt, &pt->filts.head, list) { in intel_pt_match_pgd_ip()
927 if (filt->start) in intel_pt_match_pgd_ip()
930 if ((filename && !filt->filename) || in intel_pt_match_pgd_ip()
931 (!filename && filt->filename) || in intel_pt_match_pgd_ip()
932 (filename && strcmp(filename, filt->filename))) in intel_pt_match_pgd_ip()
935 if (!(offset >= filt->addr && offset < filt->addr + filt->size)) in intel_pt_match_pgd_ip()
938 …intel_pt_log("TIP.PGD ip %#"PRIx64" offset %#"PRIx64" in %s hit filter: %s offset %#"PRIx64" size … in intel_pt_match_pgd_ip()
939 ip, offset, filename ? filename : "[kernel]", in intel_pt_match_pgd_ip()
940 filt->start ? "filter" : "stop", in intel_pt_match_pgd_ip()
941 filt->addr, filt->size); in intel_pt_match_pgd_ip()
943 if (filt->start) in intel_pt_match_pgd_ip()
950 intel_pt_log("TIP.PGD ip %#"PRIx64" offset %#"PRIx64" in %s is not in a filter region\n", in intel_pt_match_pgd_ip()
951 ip, offset, filename ? filename : "[kernel]"); in intel_pt_match_pgd_ip()
956 static int __intel_pt_pgd_ip(uint64_t ip, void *data) in __intel_pt_pgd_ip() argument
964 if (ptq->state->to_nr) { in __intel_pt_pgd_ip()
965 if (intel_pt_guest_kernel_ip(ip)) in __intel_pt_pgd_ip()
966 return intel_pt_match_pgd_ip(ptq->pt, ip, ip, NULL); in __intel_pt_pgd_ip()
968 return -EINVAL; in __intel_pt_pgd_ip()
969 } else if (ip >= ptq->pt->kernel_start) { in __intel_pt_pgd_ip()
970 return intel_pt_match_pgd_ip(ptq->pt, ip, ip, NULL); in __intel_pt_pgd_ip()
975 thread = ptq->thread; in __intel_pt_pgd_ip()
977 return -EINVAL; in __intel_pt_pgd_ip()
979 if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso) in __intel_pt_pgd_ip()
980 return -EINVAL; in __intel_pt_pgd_ip()
982 offset = al.map->map_ip(al.map, ip); in __intel_pt_pgd_ip()
984 return intel_pt_match_pgd_ip(ptq->pt, ip, offset, in __intel_pt_pgd_ip()
985 al.map->dso->long_name); in __intel_pt_pgd_ip()
988 static bool intel_pt_pgd_ip(uint64_t ip, void *data) in intel_pt_pgd_ip() argument
990 return __intel_pt_pgd_ip(ip, data) > 0; in intel_pt_pgd_ip()
996 if (attr->type == pt->pmu_type) { in intel_pt_get_config()
998 *config = attr->config; in intel_pt_get_config()
1009 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_exclude_kernel()
1010 if (intel_pt_get_config(pt, &evsel->core.attr, NULL) && in intel_pt_exclude_kernel()
1011 !evsel->core.attr.exclude_kernel) in intel_pt_exclude_kernel()
1022 if (!pt->noretcomp_bit) in intel_pt_return_compression()
1025 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_return_compression()
1026 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_return_compression()
1027 (config & pt->noretcomp_bit)) in intel_pt_return_compression()
1038 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_branch_enable()
1039 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_branch_enable()
1052 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_disabled_tnt()
1053 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_disabled_tnt()
1066 if (!pt->mtc_freq_bits) in intel_pt_mtc_period()
1069 for (shift = 0, config = pt->mtc_freq_bits; !(config & 1); shift++) in intel_pt_mtc_period()
1072 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_mtc_period()
1073 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) in intel_pt_mtc_period()
1074 return (config & pt->mtc_freq_bits) >> shift; in intel_pt_mtc_period()
1085 if (!pt->tsc_bit || !pt->cap_user_time_zero || pt->synth_opts.timeless_decoding) in intel_pt_timeless_decoding()
1088 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_timeless_decoding()
1089 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_TIME)) in intel_pt_timeless_decoding()
1091 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) { in intel_pt_timeless_decoding()
1092 if (config & pt->tsc_bit) in intel_pt_timeless_decoding()
1105 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_tracing_kernel()
1106 if (intel_pt_get_config(pt, &evsel->core.attr, NULL) && in intel_pt_tracing_kernel()
1107 !evsel->core.attr.exclude_kernel) in intel_pt_tracing_kernel()
1119 if (!pt->tsc_bit) in intel_pt_have_tsc()
1122 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_have_tsc()
1123 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) { in intel_pt_have_tsc()
1124 if (config & pt->tsc_bit) in intel_pt_have_tsc()
1138 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_have_mtc()
1139 if (intel_pt_get_config(pt, &evsel->core.attr, &config) && in intel_pt_have_mtc()
1140 (config & pt->mtc_bit)) in intel_pt_have_mtc()
1150 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_sampling_mode()
1151 if ((evsel->core.attr.sample_type & PERF_SAMPLE_AUX) && in intel_pt_sampling_mode()
1152 evsel->core.attr.aux_sample_size) in intel_pt_sampling_mode()
1163 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_ctl()
1164 if (intel_pt_get_config(pt, &evsel->core.attr, &config)) in intel_pt_ctl()
1174 quot = ns / pt->tc.time_mult; in intel_pt_ns_to_ticks()
1175 rem = ns % pt->tc.time_mult; in intel_pt_ns_to_ticks()
1176 return (quot << pt->tc.time_shift) + (rem << pt->tc.time_shift) / in intel_pt_ns_to_ticks()
1177 pt->tc.time_mult; in intel_pt_ns_to_ticks()
1185 sz += (pt->synth_opts.callchain_sz + 1) * sizeof(u64); in intel_pt_alloc_chain()
1193 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_callchain_init()
1194 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN)) in intel_pt_callchain_init()
1195 evsel->synth_sample_type |= PERF_SAMPLE_CALLCHAIN; in intel_pt_callchain_init()
1198 pt->chain = intel_pt_alloc_chain(pt); in intel_pt_callchain_init()
1199 if (!pt->chain) in intel_pt_callchain_init()
1200 return -ENOMEM; in intel_pt_callchain_init()
1208 struct thread *thread = machine__findnew_thread(pt->machine, in intel_pt_add_callchain()
1209 sample->pid, in intel_pt_add_callchain()
1210 sample->tid); in intel_pt_add_callchain()
1212 thread_stack__sample_late(thread, sample->cpu, pt->chain, in intel_pt_add_callchain()
1213 pt->synth_opts.callchain_sz + 1, sample->ip, in intel_pt_add_callchain()
1214 pt->kernel_start); in intel_pt_add_callchain()
1216 sample->callchain = pt->chain; in intel_pt_add_callchain()
1231 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_br_stack_init()
1232 if (!(evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK)) in intel_pt_br_stack_init()
1233 evsel->synth_sample_type |= PERF_SAMPLE_BRANCH_STACK; in intel_pt_br_stack_init()
1236 pt->br_stack = intel_pt_alloc_br_stack(pt->br_stack_sz); in intel_pt_br_stack_init()
1237 if (!pt->br_stack) in intel_pt_br_stack_init()
1238 return -ENOMEM; in intel_pt_br_stack_init()
1246 struct thread *thread = machine__findnew_thread(pt->machine, in intel_pt_add_br_stack()
1247 sample->pid, in intel_pt_add_br_stack()
1248 sample->tid); in intel_pt_add_br_stack()
1250 thread_stack__br_sample_late(thread, sample->cpu, pt->br_stack, in intel_pt_add_br_stack()
1251 pt->br_stack_sz, sample->ip, in intel_pt_add_br_stack()
1252 pt->kernel_start); in intel_pt_add_br_stack()
1254 sample->branch_stack = pt->br_stack; in intel_pt_add_br_stack()
1264 struct perf_env *env = pt->machine->env; in intel_pt_alloc_queue()
1271 if (pt->synth_opts.callchain) { in intel_pt_alloc_queue()
1272 ptq->chain = intel_pt_alloc_chain(pt); in intel_pt_alloc_queue()
1273 if (!ptq->chain) in intel_pt_alloc_queue()
1277 if (pt->synth_opts.last_branch || pt->synth_opts.other_events) { in intel_pt_alloc_queue()
1278 unsigned int entry_cnt = max(LBRS_MAX, pt->br_stack_sz); in intel_pt_alloc_queue()
1280 ptq->last_branch = intel_pt_alloc_br_stack(entry_cnt); in intel_pt_alloc_queue()
1281 if (!ptq->last_branch) in intel_pt_alloc_queue()
1285 ptq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); in intel_pt_alloc_queue()
1286 if (!ptq->event_buf) in intel_pt_alloc_queue()
1289 ptq->pt = pt; in intel_pt_alloc_queue()
1290 ptq->queue_nr = queue_nr; in intel_pt_alloc_queue()
1291 ptq->exclude_kernel = intel_pt_exclude_kernel(pt); in intel_pt_alloc_queue()
1292 ptq->pid = -1; in intel_pt_alloc_queue()
1293 ptq->tid = -1; in intel_pt_alloc_queue()
1294 ptq->cpu = -1; in intel_pt_alloc_queue()
1295 ptq->next_tid = -1; in intel_pt_alloc_queue()
1305 params.max_non_turbo_ratio = pt->max_non_turbo_ratio; in intel_pt_alloc_queue()
1307 params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n; in intel_pt_alloc_queue()
1308 params.tsc_ctc_ratio_d = pt->tsc_ctc_ratio_d; in intel_pt_alloc_queue()
1309 params.quick = pt->synth_opts.quick; in intel_pt_alloc_queue()
1310 params.vm_time_correlation = pt->synth_opts.vm_time_correlation; in intel_pt_alloc_queue()
1311 params.vm_tm_corr_dry_run = pt->synth_opts.vm_tm_corr_dry_run; in intel_pt_alloc_queue()
1312 params.first_timestamp = pt->first_timestamp; in intel_pt_alloc_queue()
1313 params.max_loops = pt->max_loops; in intel_pt_alloc_queue()
1319 if (pt->filts.cnt > 0) in intel_pt_alloc_queue()
1322 if (pt->synth_opts.instructions) { in intel_pt_alloc_queue()
1323 if (pt->synth_opts.period) { in intel_pt_alloc_queue()
1324 switch (pt->synth_opts.period_type) { in intel_pt_alloc_queue()
1328 params.period = pt->synth_opts.period; in intel_pt_alloc_queue()
1332 params.period = pt->synth_opts.period; in intel_pt_alloc_queue()
1337 pt->synth_opts.period); in intel_pt_alloc_queue()
1350 if (env->cpuid && !strncmp(env->cpuid, "GenuineIntel,6,92,", 18)) in intel_pt_alloc_queue()
1353 ptq->decoder = intel_pt_decoder_new(&params); in intel_pt_alloc_queue()
1354 if (!ptq->decoder) in intel_pt_alloc_queue()
1360 zfree(&ptq->event_buf); in intel_pt_alloc_queue()
1361 zfree(&ptq->last_branch); in intel_pt_alloc_queue()
1362 zfree(&ptq->chain); in intel_pt_alloc_queue()
1373 thread__zput(ptq->thread); in intel_pt_free_queue()
1374 thread__zput(ptq->guest_thread); in intel_pt_free_queue()
1375 thread__zput(ptq->unknown_guest_thread); in intel_pt_free_queue()
1376 intel_pt_decoder_free(ptq->decoder); in intel_pt_free_queue()
1377 zfree(&ptq->event_buf); in intel_pt_free_queue()
1378 zfree(&ptq->last_branch); in intel_pt_free_queue()
1379 zfree(&ptq->chain); in intel_pt_free_queue()
1387 pt->first_timestamp = timestamp; in intel_pt_first_timestamp()
1389 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_first_timestamp()
1390 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_first_timestamp()
1391 struct intel_pt_queue *ptq = queue->priv; in intel_pt_first_timestamp()
1393 if (ptq && ptq->decoder) in intel_pt_first_timestamp()
1394 intel_pt_set_first_timestamp(ptq->decoder, timestamp); in intel_pt_first_timestamp()
1400 struct machines *machines = &ptq->pt->session->machines; in intel_pt_get_guest_from_sideband()
1402 pid_t machine_pid = ptq->pid; in intel_pt_get_guest_from_sideband()
1413 if (ptq->guest_machine != machine) { in intel_pt_get_guest_from_sideband()
1414 ptq->guest_machine = NULL; in intel_pt_get_guest_from_sideband()
1415 thread__zput(ptq->guest_thread); in intel_pt_get_guest_from_sideband()
1416 thread__zput(ptq->unknown_guest_thread); in intel_pt_get_guest_from_sideband()
1418 ptq->unknown_guest_thread = machine__find_thread(machine, 0, 0); in intel_pt_get_guest_from_sideband()
1419 if (!ptq->unknown_guest_thread) in intel_pt_get_guest_from_sideband()
1420 return -1; in intel_pt_get_guest_from_sideband()
1421 ptq->guest_machine = machine; in intel_pt_get_guest_from_sideband()
1424 vcpu = ptq->thread ? ptq->thread->guest_cpu : -1; in intel_pt_get_guest_from_sideband()
1426 return -1; in intel_pt_get_guest_from_sideband()
1430 if (ptq->guest_thread && ptq->guest_thread->tid != tid) in intel_pt_get_guest_from_sideband()
1431 thread__zput(ptq->guest_thread); in intel_pt_get_guest_from_sideband()
1433 if (!ptq->guest_thread) { in intel_pt_get_guest_from_sideband()
1434 ptq->guest_thread = machine__find_thread(machine, -1, tid); in intel_pt_get_guest_from_sideband()
1435 if (!ptq->guest_thread) in intel_pt_get_guest_from_sideband()
1436 return -1; in intel_pt_get_guest_from_sideband()
1439 ptq->guest_machine_pid = machine_pid; in intel_pt_get_guest_from_sideband()
1440 ptq->guest_pid = ptq->guest_thread->pid_; in intel_pt_get_guest_from_sideband()
1441 ptq->guest_tid = tid; in intel_pt_get_guest_from_sideband()
1442 ptq->vcpu = vcpu; in intel_pt_get_guest_from_sideband()
1450 struct intel_pt_queue *ptq = queue->priv; in intel_pt_set_pid_tid_cpu()
1452 if (queue->tid == -1 || pt->have_sched_switch) { in intel_pt_set_pid_tid_cpu()
1453 ptq->tid = machine__get_current_tid(pt->machine, ptq->cpu); in intel_pt_set_pid_tid_cpu()
1454 if (ptq->tid == -1) in intel_pt_set_pid_tid_cpu()
1455 ptq->pid = -1; in intel_pt_set_pid_tid_cpu()
1456 thread__zput(ptq->thread); in intel_pt_set_pid_tid_cpu()
1459 if (!ptq->thread && ptq->tid != -1) in intel_pt_set_pid_tid_cpu()
1460 ptq->thread = machine__find_thread(pt->machine, -1, ptq->tid); in intel_pt_set_pid_tid_cpu()
1462 if (ptq->thread) { in intel_pt_set_pid_tid_cpu()
1463 ptq->pid = ptq->thread->pid_; in intel_pt_set_pid_tid_cpu()
1464 if (queue->cpu == -1) in intel_pt_set_pid_tid_cpu()
1465 ptq->cpu = ptq->thread->cpu; in intel_pt_set_pid_tid_cpu()
1468 if (pt->have_guest_sideband && intel_pt_get_guest_from_sideband(ptq)) { in intel_pt_set_pid_tid_cpu()
1469 ptq->guest_machine_pid = 0; in intel_pt_set_pid_tid_cpu()
1470 ptq->guest_pid = -1; in intel_pt_set_pid_tid_cpu()
1471 ptq->guest_tid = -1; in intel_pt_set_pid_tid_cpu()
1472 ptq->vcpu = -1; in intel_pt_set_pid_tid_cpu()
1478 struct intel_pt *pt = ptq->pt; in intel_pt_sample_flags()
1480 ptq->insn_len = 0; in intel_pt_sample_flags()
1481 if (ptq->state->flags & INTEL_PT_ABORT_TX) { in intel_pt_sample_flags()
1482 ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_TX_ABORT; in intel_pt_sample_flags()
1483 } else if (ptq->state->flags & INTEL_PT_ASYNC) { in intel_pt_sample_flags()
1484 if (!ptq->state->to_ip) in intel_pt_sample_flags()
1485 ptq->flags = PERF_IP_FLAG_BRANCH | in intel_pt_sample_flags()
1487 else if (ptq->state->from_nr && !ptq->state->to_nr) in intel_pt_sample_flags()
1488 ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | in intel_pt_sample_flags()
1491 ptq->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | in intel_pt_sample_flags()
1495 if (ptq->state->from_ip) in intel_pt_sample_flags()
1496 ptq->flags = intel_pt_insn_type(ptq->state->insn_op); in intel_pt_sample_flags()
1498 ptq->flags = PERF_IP_FLAG_BRANCH | in intel_pt_sample_flags()
1500 if (ptq->state->flags & INTEL_PT_IN_TX) in intel_pt_sample_flags()
1501 ptq->flags |= PERF_IP_FLAG_IN_TX; in intel_pt_sample_flags()
1502 ptq->insn_len = ptq->state->insn_len; in intel_pt_sample_flags()
1503 memcpy(ptq->insn, ptq->state->insn, INTEL_PT_INSN_BUF_SZ); in intel_pt_sample_flags()
1506 if (ptq->state->type & INTEL_PT_TRACE_BEGIN) in intel_pt_sample_flags()
1507 ptq->flags |= PERF_IP_FLAG_TRACE_BEGIN; in intel_pt_sample_flags()
1508 if (ptq->state->type & INTEL_PT_TRACE_END) in intel_pt_sample_flags()
1509 ptq->flags |= PERF_IP_FLAG_TRACE_END; in intel_pt_sample_flags()
1511 if (pt->cap_event_trace) { in intel_pt_sample_flags()
1512 if (ptq->state->type & INTEL_PT_IFLAG_CHG) { in intel_pt_sample_flags()
1513 if (!ptq->state->from_iflag) in intel_pt_sample_flags()
1514 ptq->flags |= PERF_IP_FLAG_INTR_DISABLE; in intel_pt_sample_flags()
1515 if (ptq->state->from_iflag != ptq->state->to_iflag) in intel_pt_sample_flags()
1516 ptq->flags |= PERF_IP_FLAG_INTR_TOGGLE; in intel_pt_sample_flags()
1517 } else if (!ptq->state->to_iflag) { in intel_pt_sample_flags()
1518 ptq->flags |= PERF_IP_FLAG_INTR_DISABLE; in intel_pt_sample_flags()
1526 if (!pt->range_cnt) in intel_pt_setup_time_range()
1529 ptq->sel_timestamp = pt->time_ranges[0].start; in intel_pt_setup_time_range()
1530 ptq->sel_idx = 0; in intel_pt_setup_time_range()
1532 if (ptq->sel_timestamp) { in intel_pt_setup_time_range()
1533 ptq->sel_start = true; in intel_pt_setup_time_range()
1535 ptq->sel_timestamp = pt->time_ranges[0].end; in intel_pt_setup_time_range()
1536 ptq->sel_start = false; in intel_pt_setup_time_range()
1544 struct intel_pt_queue *ptq = queue->priv; in intel_pt_setup_queue()
1546 if (list_empty(&queue->head)) in intel_pt_setup_queue()
1552 return -ENOMEM; in intel_pt_setup_queue()
1553 queue->priv = ptq; in intel_pt_setup_queue()
1555 if (queue->cpu != -1) in intel_pt_setup_queue()
1556 ptq->cpu = queue->cpu; in intel_pt_setup_queue()
1557 ptq->tid = queue->tid; in intel_pt_setup_queue()
1559 ptq->cbr_seen = UINT_MAX; in intel_pt_setup_queue()
1561 if (pt->sampling_mode && !pt->snapshot_mode && in intel_pt_setup_queue()
1562 pt->timeless_decoding) in intel_pt_setup_queue()
1563 ptq->step_through_buffers = true; in intel_pt_setup_queue()
1565 ptq->sync_switch = pt->sync_switch; in intel_pt_setup_queue()
1570 if (!ptq->on_heap && in intel_pt_setup_queue()
1571 (!ptq->sync_switch || in intel_pt_setup_queue()
1572 ptq->switch_state != INTEL_PT_SS_EXPECTING_SWITCH_EVENT)) { in intel_pt_setup_queue()
1576 if (pt->timeless_decoding) in intel_pt_setup_queue()
1581 queue_nr, ptq->cpu, ptq->pid, ptq->tid); in intel_pt_setup_queue()
1583 if (ptq->sel_start && ptq->sel_timestamp) { in intel_pt_setup_queue()
1584 ret = intel_pt_fast_forward(ptq->decoder, in intel_pt_setup_queue()
1585 ptq->sel_timestamp); in intel_pt_setup_queue()
1591 state = intel_pt_decode(ptq->decoder); in intel_pt_setup_queue()
1592 if (state->err) { in intel_pt_setup_queue()
1593 if (state->err == INTEL_PT_ERR_NODATA) { in intel_pt_setup_queue()
1600 if (state->timestamp) in intel_pt_setup_queue()
1604 ptq->timestamp = state->timestamp; in intel_pt_setup_queue()
1606 queue_nr, ptq->timestamp); in intel_pt_setup_queue()
1607 ptq->state = state; in intel_pt_setup_queue()
1608 ptq->have_sample = true; in intel_pt_setup_queue()
1609 if (ptq->sel_start && ptq->sel_timestamp && in intel_pt_setup_queue()
1610 ptq->timestamp < ptq->sel_timestamp) in intel_pt_setup_queue()
1611 ptq->have_sample = false; in intel_pt_setup_queue()
1613 ret = auxtrace_heap__add(&pt->heap, queue_nr, ptq->timestamp); in intel_pt_setup_queue()
1616 ptq->on_heap = true; in intel_pt_setup_queue()
1627 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_setup_queues()
1628 ret = intel_pt_setup_queue(pt, &pt->queues.queue_array[i], i); in intel_pt_setup_queues()
1637 return pt->synth_opts.initial_skip && in intel_pt_skip_event()
1638 pt->num_events++ < pt->synth_opts.initial_skip; in intel_pt_skip_event()
1643 * Also ensure CBR is first non-skipped event by allowing for 4 more samples
1648 return pt->synth_opts.initial_skip && in intel_pt_skip_cbr_event()
1649 pt->num_events + 4 < pt->synth_opts.initial_skip; in intel_pt_skip_cbr_event()
1656 event->sample.header.type = PERF_RECORD_SAMPLE; in intel_pt_prep_a_sample()
1657 event->sample.header.size = sizeof(struct perf_event_header); in intel_pt_prep_a_sample()
1659 sample->pid = ptq->pid; in intel_pt_prep_a_sample()
1660 sample->tid = ptq->tid; in intel_pt_prep_a_sample()
1662 if (ptq->pt->have_guest_sideband) { in intel_pt_prep_a_sample()
1663 if ((ptq->state->from_ip && ptq->state->from_nr) || in intel_pt_prep_a_sample()
1664 (ptq->state->to_ip && ptq->state->to_nr)) { in intel_pt_prep_a_sample()
1665 sample->pid = ptq->guest_pid; in intel_pt_prep_a_sample()
1666 sample->tid = ptq->guest_tid; in intel_pt_prep_a_sample()
1667 sample->machine_pid = ptq->guest_machine_pid; in intel_pt_prep_a_sample()
1668 sample->vcpu = ptq->vcpu; in intel_pt_prep_a_sample()
1672 sample->cpu = ptq->cpu; in intel_pt_prep_a_sample()
1673 sample->insn_len = ptq->insn_len; in intel_pt_prep_a_sample()
1674 memcpy(sample->insn, ptq->insn, INTEL_PT_INSN_BUF_SZ); in intel_pt_prep_a_sample()
1684 if (!pt->timeless_decoding) in intel_pt_prep_b_sample()
1685 sample->time = tsc_to_perf_time(ptq->timestamp, &pt->tc); in intel_pt_prep_b_sample()
1687 sample->ip = ptq->state->from_ip; in intel_pt_prep_b_sample()
1688 sample->addr = ptq->state->to_ip; in intel_pt_prep_b_sample()
1689 sample->cpumode = intel_pt_cpumode(ptq, sample->ip, sample->addr); in intel_pt_prep_b_sample()
1690 sample->period = 1; in intel_pt_prep_b_sample()
1691 sample->flags = ptq->flags; in intel_pt_prep_b_sample()
1693 event->sample.header.misc = sample->cpumode; in intel_pt_prep_b_sample()
1699 event->header.size = perf_event__sample_event_size(sample, type, 0); in intel_pt_inject_event()
1707 if (!pt->synth_opts.inject) in intel_pt_opt_inject()
1723 ret = perf_session__deliver_synth_event(pt->session, event, sample); in intel_pt_deliver_synth_event()
1732 struct intel_pt *pt = ptq->pt; in intel_pt_synth_branch_sample()
1733 union perf_event *event = ptq->event_buf; in intel_pt_synth_branch_sample()
1734 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_branch_sample()
1741 if (pt->branches_filter && !(pt->branches_filter & ptq->flags)) in intel_pt_synth_branch_sample()
1749 sample.id = ptq->pt->branches_id; in intel_pt_synth_branch_sample()
1750 sample.stream_id = ptq->pt->branches_id; in intel_pt_synth_branch_sample()
1756 if (pt->synth_opts.last_branch && sort__mode == SORT_MODE__BRANCH) { in intel_pt_synth_branch_sample()
1759 .hw_idx = -1ULL, in intel_pt_synth_branch_sample()
1761 .from = sample.ip, in intel_pt_synth_branch_sample()
1768 if (ptq->sample_ipc) in intel_pt_synth_branch_sample()
1769 sample.cyc_cnt = ptq->ipc_cyc_cnt - ptq->last_br_cyc_cnt; in intel_pt_synth_branch_sample()
1771 sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_br_insn_cnt; in intel_pt_synth_branch_sample()
1772 ptq->last_br_insn_cnt = ptq->ipc_insn_cnt; in intel_pt_synth_branch_sample()
1773 ptq->last_br_cyc_cnt = ptq->ipc_cyc_cnt; in intel_pt_synth_branch_sample()
1777 pt->branches_sample_type); in intel_pt_synth_branch_sample()
1787 if (pt->synth_opts.callchain) { in intel_pt_prep_sample()
1788 thread_stack__sample(ptq->thread, ptq->cpu, ptq->chain, in intel_pt_prep_sample()
1789 pt->synth_opts.callchain_sz + 1, in intel_pt_prep_sample()
1790 sample->ip, pt->kernel_start); in intel_pt_prep_sample()
1791 sample->callchain = ptq->chain; in intel_pt_prep_sample()
1794 if (pt->synth_opts.last_branch) { in intel_pt_prep_sample()
1795 thread_stack__br_sample(ptq->thread, ptq->cpu, ptq->last_branch, in intel_pt_prep_sample()
1796 pt->br_stack_sz); in intel_pt_prep_sample()
1797 sample->branch_stack = ptq->last_branch; in intel_pt_prep_sample()
1803 struct intel_pt *pt = ptq->pt; in intel_pt_synth_instruction_sample()
1804 union perf_event *event = ptq->event_buf; in intel_pt_synth_instruction_sample()
1805 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_instruction_sample()
1812 sample.id = ptq->pt->instructions_id; in intel_pt_synth_instruction_sample()
1813 sample.stream_id = ptq->pt->instructions_id; in intel_pt_synth_instruction_sample()
1814 if (pt->synth_opts.quick) in intel_pt_synth_instruction_sample()
1817 sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt; in intel_pt_synth_instruction_sample()
1819 if (ptq->sample_ipc) in intel_pt_synth_instruction_sample()
1820 sample.cyc_cnt = ptq->ipc_cyc_cnt - ptq->last_in_cyc_cnt; in intel_pt_synth_instruction_sample()
1822 sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_in_insn_cnt; in intel_pt_synth_instruction_sample()
1823 ptq->last_in_insn_cnt = ptq->ipc_insn_cnt; in intel_pt_synth_instruction_sample()
1824 ptq->last_in_cyc_cnt = ptq->ipc_cyc_cnt; in intel_pt_synth_instruction_sample()
1827 ptq->last_insn_cnt = ptq->state->tot_insn_cnt; in intel_pt_synth_instruction_sample()
1830 pt->instructions_sample_type); in intel_pt_synth_instruction_sample()
1835 struct intel_pt *pt = ptq->pt; in intel_pt_synth_transaction_sample()
1836 union perf_event *event = ptq->event_buf; in intel_pt_synth_transaction_sample()
1837 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_transaction_sample()
1844 sample.id = ptq->pt->transactions_id; in intel_pt_synth_transaction_sample()
1845 sample.stream_id = ptq->pt->transactions_id; in intel_pt_synth_transaction_sample()
1848 pt->transactions_sample_type); in intel_pt_synth_transaction_sample()
1859 * Zero IP is used to mean "trace start" but that is not the case for in intel_pt_prep_p_sample()
1860 * power or PTWRITE events with no IP, so clear the flags. in intel_pt_prep_p_sample()
1862 if (!sample->ip) in intel_pt_prep_p_sample()
1863 sample->flags = 0; in intel_pt_prep_p_sample()
1868 struct intel_pt *pt = ptq->pt; in intel_pt_synth_ptwrite_sample()
1869 union perf_event *event = ptq->event_buf; in intel_pt_synth_ptwrite_sample()
1870 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_ptwrite_sample()
1878 sample.id = ptq->pt->ptwrites_id; in intel_pt_synth_ptwrite_sample()
1879 sample.stream_id = ptq->pt->ptwrites_id; in intel_pt_synth_ptwrite_sample()
1882 raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP); in intel_pt_synth_ptwrite_sample()
1883 raw.payload = cpu_to_le64(ptq->state->ptw_payload); in intel_pt_synth_ptwrite_sample()
1889 pt->ptwrites_sample_type); in intel_pt_synth_ptwrite_sample()
1894 struct intel_pt *pt = ptq->pt; in intel_pt_synth_cbr_sample()
1895 union perf_event *event = ptq->event_buf; in intel_pt_synth_cbr_sample()
1896 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_cbr_sample()
1903 ptq->cbr_seen = ptq->state->cbr; in intel_pt_synth_cbr_sample()
1907 sample.id = ptq->pt->cbr_id; in intel_pt_synth_cbr_sample()
1908 sample.stream_id = ptq->pt->cbr_id; in intel_pt_synth_cbr_sample()
1910 flags = (u16)ptq->state->cbr_payload | (pt->max_non_turbo_ratio << 16); in intel_pt_synth_cbr_sample()
1912 raw.freq = cpu_to_le32(raw.cbr * pt->cbr2khz); in intel_pt_synth_cbr_sample()
1919 pt->pwr_events_sample_type); in intel_pt_synth_cbr_sample()
1924 struct intel_pt *pt = ptq->pt; in intel_pt_synth_psb_sample()
1925 union perf_event *event = ptq->event_buf; in intel_pt_synth_psb_sample()
1926 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_psb_sample()
1934 sample.id = ptq->pt->psb_id; in intel_pt_synth_psb_sample()
1935 sample.stream_id = ptq->pt->psb_id; in intel_pt_synth_psb_sample()
1939 raw.offset = ptq->state->psb_offset; in intel_pt_synth_psb_sample()
1945 pt->pwr_events_sample_type); in intel_pt_synth_psb_sample()
1950 struct intel_pt *pt = ptq->pt; in intel_pt_synth_mwait_sample()
1951 union perf_event *event = ptq->event_buf; in intel_pt_synth_mwait_sample()
1952 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_mwait_sample()
1960 sample.id = ptq->pt->mwait_id; in intel_pt_synth_mwait_sample()
1961 sample.stream_id = ptq->pt->mwait_id; in intel_pt_synth_mwait_sample()
1964 raw.payload = cpu_to_le64(ptq->state->mwait_payload); in intel_pt_synth_mwait_sample()
1970 pt->pwr_events_sample_type); in intel_pt_synth_mwait_sample()
1975 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pwre_sample()
1976 union perf_event *event = ptq->event_buf; in intel_pt_synth_pwre_sample()
1977 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_pwre_sample()
1985 sample.id = ptq->pt->pwre_id; in intel_pt_synth_pwre_sample()
1986 sample.stream_id = ptq->pt->pwre_id; in intel_pt_synth_pwre_sample()
1989 raw.payload = cpu_to_le64(ptq->state->pwre_payload); in intel_pt_synth_pwre_sample()
1995 pt->pwr_events_sample_type); in intel_pt_synth_pwre_sample()
2000 struct intel_pt *pt = ptq->pt; in intel_pt_synth_exstop_sample()
2001 union perf_event *event = ptq->event_buf; in intel_pt_synth_exstop_sample()
2002 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_exstop_sample()
2010 sample.id = ptq->pt->exstop_id; in intel_pt_synth_exstop_sample()
2011 sample.stream_id = ptq->pt->exstop_id; in intel_pt_synth_exstop_sample()
2014 raw.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP); in intel_pt_synth_exstop_sample()
2020 pt->pwr_events_sample_type); in intel_pt_synth_exstop_sample()
2025 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pwrx_sample()
2026 union perf_event *event = ptq->event_buf; in intel_pt_synth_pwrx_sample()
2027 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_pwrx_sample()
2035 sample.id = ptq->pt->pwrx_id; in intel_pt_synth_pwrx_sample()
2036 sample.stream_id = ptq->pt->pwrx_id; in intel_pt_synth_pwrx_sample()
2039 raw.payload = cpu_to_le64(ptq->state->pwrx_payload); in intel_pt_synth_pwrx_sample()
2045 pt->pwr_events_sample_type); in intel_pt_synth_pwrx_sample()
2077 const u64 *gp_regs = items->val[INTEL_PT_GP_REGS_POS]; in intel_pt_add_gp_regs()
2078 u32 mask = items->mask[INTEL_PT_GP_REGS_POS]; in intel_pt_add_gp_regs()
2084 int n = pebs_gp_regs[i] - 1; in intel_pt_add_gp_regs()
2091 * mask (i.e. 'intr_regs->mask') accordingly. in intel_pt_add_gp_regs()
2094 intr_regs->mask |= bit; in intel_pt_add_gp_regs()
2110 u32 mask = items->has_xmm & (regs_mask >> PERF_REG_X86_XMM0); in intel_pt_add_xmm()
2111 const u64 *xmm = items->xmm; in intel_pt_add_xmm()
2117 * and update the resulting mask (i.e. 'intr_regs->mask') accordingly. in intel_pt_add_xmm()
2119 intr_regs->mask |= (u64)mask << PERF_REG_X86_XMM0; in intel_pt_add_xmm()
2156 br_stack->nr = 0; in intel_pt_add_lbrs()
2158 to = &br_stack->entries[0].from; in intel_pt_add_lbrs()
2161 u32 mask = items->mask[i]; in intel_pt_add_lbrs()
2162 const u64 *from = items->val[i]; in intel_pt_add_lbrs()
2169 br_stack->nr += 1; in intel_pt_add_lbrs()
2177 const struct intel_pt_blk_items *items = &ptq->state->items; in intel_pt_do_synth_pebs_sample()
2178 struct perf_sample sample = { .ip = 0, }; in intel_pt_do_synth_pebs_sample()
2179 union perf_event *event = ptq->event_buf; in intel_pt_do_synth_pebs_sample()
2180 struct intel_pt *pt = ptq->pt; in intel_pt_do_synth_pebs_sample()
2181 u64 sample_type = evsel->core.attr.sample_type; in intel_pt_do_synth_pebs_sample()
2193 if (!evsel->core.attr.freq) in intel_pt_do_synth_pebs_sample()
2194 sample.period = evsel->core.attr.sample_period; in intel_pt_do_synth_pebs_sample()
2196 /* No support for non-zero CS base */ in intel_pt_do_synth_pebs_sample()
2197 if (items->has_ip) in intel_pt_do_synth_pebs_sample()
2198 sample.ip = items->ip; in intel_pt_do_synth_pebs_sample()
2199 else if (items->has_rip) in intel_pt_do_synth_pebs_sample()
2200 sample.ip = items->rip; in intel_pt_do_synth_pebs_sample()
2202 sample.ip = ptq->state->from_ip; in intel_pt_do_synth_pebs_sample()
2204 cpumode = intel_pt_cpumode(ptq, sample.ip, 0); in intel_pt_do_synth_pebs_sample()
2206 event->sample.header.misc = cpumode | PERF_RECORD_MISC_EXACT_IP; in intel_pt_do_synth_pebs_sample()
2213 if (items->has_timestamp) in intel_pt_do_synth_pebs_sample()
2214 timestamp = items->timestamp; in intel_pt_do_synth_pebs_sample()
2215 else if (!pt->timeless_decoding) in intel_pt_do_synth_pebs_sample()
2216 timestamp = ptq->timestamp; in intel_pt_do_synth_pebs_sample()
2218 sample.time = tsc_to_perf_time(timestamp, &pt->tc); in intel_pt_do_synth_pebs_sample()
2222 pt->synth_opts.callchain) { in intel_pt_do_synth_pebs_sample()
2223 thread_stack__sample(ptq->thread, ptq->cpu, ptq->chain, in intel_pt_do_synth_pebs_sample()
2224 pt->synth_opts.callchain_sz, sample.ip, in intel_pt_do_synth_pebs_sample()
2225 pt->kernel_start); in intel_pt_do_synth_pebs_sample()
2226 sample.callchain = ptq->chain; in intel_pt_do_synth_pebs_sample()
2230 (items->mask[INTEL_PT_GP_REGS_POS] || in intel_pt_do_synth_pebs_sample()
2231 items->mask[INTEL_PT_XMM_POS])) { in intel_pt_do_synth_pebs_sample()
2232 u64 regs_mask = evsel->core.attr.sample_regs_intr; in intel_pt_do_synth_pebs_sample()
2235 sample.intr_regs.abi = items->is_32_bit ? in intel_pt_do_synth_pebs_sample()
2246 if (items->mask[INTEL_PT_LBR_0_POS] || in intel_pt_do_synth_pebs_sample()
2247 items->mask[INTEL_PT_LBR_1_POS] || in intel_pt_do_synth_pebs_sample()
2248 items->mask[INTEL_PT_LBR_2_POS]) { in intel_pt_do_synth_pebs_sample()
2249 intel_pt_add_lbrs(ptq->last_branch, items); in intel_pt_do_synth_pebs_sample()
2250 } else if (pt->synth_opts.last_branch) { in intel_pt_do_synth_pebs_sample()
2251 thread_stack__br_sample(ptq->thread, ptq->cpu, in intel_pt_do_synth_pebs_sample()
2252 ptq->last_branch, in intel_pt_do_synth_pebs_sample()
2253 pt->br_stack_sz); in intel_pt_do_synth_pebs_sample()
2255 ptq->last_branch->nr = 0; in intel_pt_do_synth_pebs_sample()
2257 sample.branch_stack = ptq->last_branch; in intel_pt_do_synth_pebs_sample()
2260 if (sample_type & PERF_SAMPLE_ADDR && items->has_mem_access_address) in intel_pt_do_synth_pebs_sample()
2261 sample.addr = items->mem_access_address; in intel_pt_do_synth_pebs_sample()
2268 if (items->has_mem_access_latency) { in intel_pt_do_synth_pebs_sample()
2269 u64 weight = items->mem_access_latency >> 32; in intel_pt_do_synth_pebs_sample()
2283 sample.ins_lat = items->mem_access_latency & 0xffff; in intel_pt_do_synth_pebs_sample()
2285 sample.weight = items->mem_access_latency; in intel_pt_do_synth_pebs_sample()
2287 if (!sample.weight && items->has_tsx_aux_info) { in intel_pt_do_synth_pebs_sample()
2289 sample.weight = (u32)items->tsx_aux_info; in intel_pt_do_synth_pebs_sample()
2293 if (sample_type & PERF_SAMPLE_TRANSACTION && items->has_tsx_aux_info) { in intel_pt_do_synth_pebs_sample()
2294 u64 ax = items->has_rax ? items->rax : 0; in intel_pt_do_synth_pebs_sample()
2296 u64 txn = (u8)(items->tsx_aux_info >> 32); in intel_pt_do_synth_pebs_sample()
2309 struct intel_pt *pt = ptq->pt; in intel_pt_synth_single_pebs_sample()
2310 struct evsel *evsel = pt->pebs_evsel; in intel_pt_synth_single_pebs_sample()
2311 u64 id = evsel->core.id[0]; in intel_pt_synth_single_pebs_sample()
2318 const struct intel_pt_blk_items *items = &ptq->state->items; in intel_pt_synth_pebs_sample()
2320 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pebs_sample()
2321 int err = -EINVAL; in intel_pt_synth_pebs_sample()
2324 if (!items->has_applicable_counters || !items->applicable_counters) { in intel_pt_synth_pebs_sample()
2325 if (!pt->single_pebs) in intel_pt_synth_pebs_sample()
2326 pr_err("PEBS-via-PT record with no applicable_counters\n"); in intel_pt_synth_pebs_sample()
2330 for_each_set_bit(hw_id, (unsigned long *)&items->applicable_counters, INTEL_PT_MAX_PEBS) { in intel_pt_synth_pebs_sample()
2331 pe = &ptq->pebs[hw_id]; in intel_pt_synth_pebs_sample()
2332 if (!pe->evsel) { in intel_pt_synth_pebs_sample()
2333 if (!pt->single_pebs) in intel_pt_synth_pebs_sample()
2334 pr_err("PEBS-via-PT record with no matching event, hw_id %d\n", in intel_pt_synth_pebs_sample()
2338 err = intel_pt_do_synth_pebs_sample(ptq, pe->evsel, pe->id); in intel_pt_synth_pebs_sample()
2348 struct intel_pt *pt = ptq->pt; in intel_pt_synth_events_sample()
2349 union perf_event *event = ptq->event_buf; in intel_pt_synth_events_sample()
2350 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_events_sample()
2362 sample.id = ptq->pt->evt_id; in intel_pt_synth_events_sample()
2363 sample.stream_id = ptq->pt->evt_id; in intel_pt_synth_events_sample()
2365 raw.cfe.type = ptq->state->cfe_type; in intel_pt_synth_events_sample()
2367 raw.cfe.ip = !!(ptq->state->flags & INTEL_PT_FUP_IP); in intel_pt_synth_events_sample()
2368 raw.cfe.vector = ptq->state->cfe_vector; in intel_pt_synth_events_sample()
2369 raw.cfe.evd_cnt = ptq->state->evd_cnt; in intel_pt_synth_events_sample()
2371 for (i = 0; i < ptq->state->evd_cnt; i++) { in intel_pt_synth_events_sample()
2373 raw.evd[i].evd_type = ptq->state->evd[i].type; in intel_pt_synth_events_sample()
2374 raw.evd[i].payload = ptq->state->evd[i].payload; in intel_pt_synth_events_sample()
2378 ptq->state->evd_cnt * sizeof(struct perf_synth_intel_evd); in intel_pt_synth_events_sample()
2382 pt->evt_sample_type); in intel_pt_synth_events_sample()
2387 struct intel_pt *pt = ptq->pt; in intel_pt_synth_iflag_chg_sample()
2388 union perf_event *event = ptq->event_buf; in intel_pt_synth_iflag_chg_sample()
2389 struct perf_sample sample = { .ip = 0, }; in intel_pt_synth_iflag_chg_sample()
2397 sample.id = ptq->pt->iflag_chg_id; in intel_pt_synth_iflag_chg_sample()
2398 sample.stream_id = ptq->pt->iflag_chg_id; in intel_pt_synth_iflag_chg_sample()
2401 raw.iflag = ptq->state->to_iflag; in intel_pt_synth_iflag_chg_sample()
2403 if (ptq->state->type & INTEL_PT_BRANCH) { in intel_pt_synth_iflag_chg_sample()
2405 raw.branch_ip = ptq->state->to_ip; in intel_pt_synth_iflag_chg_sample()
2409 sample.flags = ptq->flags; in intel_pt_synth_iflag_chg_sample()
2415 pt->iflag_chg_sample_type); in intel_pt_synth_iflag_chg_sample()
2419 pid_t pid, pid_t tid, u64 ip, u64 timestamp, in intel_pt_synth_error() argument
2422 bool dump_log_on_error = pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_ON_ERROR; in intel_pt_synth_error()
2423 bool log_on_stdout = pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_USE_STDOUT; in intel_pt_synth_error()
2428 if (pt->synth_opts.error_minus_flags) { in intel_pt_synth_error()
2430 pt->synth_opts.error_minus_flags & AUXTRACE_ERR_FLG_OVERFLOW) in intel_pt_synth_error()
2433 pt->synth_opts.error_minus_flags & AUXTRACE_ERR_FLG_DATA_LOST) in intel_pt_synth_error()
2440 code, cpu, pid, tid, ip, msg, timestamp, in intel_pt_synth_error()
2453 err = perf_session__deliver_synth_event(pt->session, &event, NULL); in intel_pt_synth_error()
2464 struct intel_pt *pt = ptq->pt; in intel_ptq_synth_error()
2465 u64 tm = ptq->timestamp; in intel_ptq_synth_error()
2467 pid_t pid = ptq->pid; in intel_ptq_synth_error()
2468 pid_t tid = ptq->tid; in intel_ptq_synth_error()
2469 int vcpu = -1; in intel_ptq_synth_error()
2471 tm = pt->timeless_decoding ? 0 : tsc_to_perf_time(tm, &pt->tc); in intel_ptq_synth_error()
2473 if (pt->have_guest_sideband && state->from_nr) { in intel_ptq_synth_error()
2474 machine_pid = ptq->guest_machine_pid; in intel_ptq_synth_error()
2475 vcpu = ptq->vcpu; in intel_ptq_synth_error()
2476 pid = ptq->guest_pid; in intel_ptq_synth_error()
2477 tid = ptq->guest_tid; in intel_ptq_synth_error()
2480 return intel_pt_synth_error(pt, state->err, ptq->cpu, pid, tid, in intel_ptq_synth_error()
2481 state->from_ip, tm, machine_pid, vcpu); in intel_ptq_synth_error()
2487 pid_t tid = ptq->next_tid; in intel_pt_next_tid()
2490 if (tid == -1) in intel_pt_next_tid()
2493 intel_pt_log("switch: cpu %d tid %d\n", ptq->cpu, tid); in intel_pt_next_tid()
2495 err = machine__set_current_tid(pt->machine, ptq->cpu, -1, tid); in intel_pt_next_tid()
2497 queue = &pt->queues.queue_array[ptq->queue_nr]; in intel_pt_next_tid()
2500 ptq->next_tid = -1; in intel_pt_next_tid()
2505 static inline bool intel_pt_is_switch_ip(struct intel_pt_queue *ptq, u64 ip) in intel_pt_is_switch_ip() argument
2507 struct intel_pt *pt = ptq->pt; in intel_pt_is_switch_ip()
2509 return ip == pt->switch_ip && in intel_pt_is_switch_ip()
2510 (ptq->flags & PERF_IP_FLAG_BRANCH) && in intel_pt_is_switch_ip()
2511 !(ptq->flags & (PERF_IP_FLAG_CONDITIONAL | PERF_IP_FLAG_ASYNC | in intel_pt_is_switch_ip()
2520 const struct intel_pt_state *state = ptq->state; in intel_pt_sample()
2521 struct intel_pt *pt = ptq->pt; in intel_pt_sample()
2524 if (!ptq->have_sample) in intel_pt_sample()
2527 ptq->have_sample = false; in intel_pt_sample()
2529 if (pt->synth_opts.approx_ipc) { in intel_pt_sample()
2530 ptq->ipc_insn_cnt = ptq->state->tot_insn_cnt; in intel_pt_sample()
2531 ptq->ipc_cyc_cnt = ptq->state->cycles; in intel_pt_sample()
2532 ptq->sample_ipc = true; in intel_pt_sample()
2534 ptq->ipc_insn_cnt = ptq->state->tot_insn_cnt; in intel_pt_sample()
2535 ptq->ipc_cyc_cnt = ptq->state->tot_cyc_cnt; in intel_pt_sample()
2536 ptq->sample_ipc = ptq->state->flags & INTEL_PT_SAMPLE_IPC; in intel_pt_sample()
2540 if (symbol_conf.guest_code && (state->from_nr || state->to_nr)) in intel_pt_sample()
2547 if (pt->sample_pebs && state->type & INTEL_PT_BLK_ITEMS) { in intel_pt_sample()
2553 if (pt->synth_opts.intr_events) { in intel_pt_sample()
2554 if (state->type & INTEL_PT_EVT) { in intel_pt_sample()
2559 if (state->type & INTEL_PT_IFLAG_CHG) { in intel_pt_sample()
2566 if (pt->sample_pwr_events) { in intel_pt_sample()
2567 if (state->type & INTEL_PT_PSB_EVT) { in intel_pt_sample()
2572 if (ptq->state->cbr != ptq->cbr_seen) { in intel_pt_sample()
2577 if (state->type & INTEL_PT_PWR_EVT) { in intel_pt_sample()
2578 if (state->type & INTEL_PT_MWAIT_OP) { in intel_pt_sample()
2583 if (state->type & INTEL_PT_PWR_ENTRY) { in intel_pt_sample()
2588 if (state->type & INTEL_PT_EX_STOP) { in intel_pt_sample()
2593 if (state->type & INTEL_PT_PWR_EXIT) { in intel_pt_sample()
2601 if (pt->sample_instructions && (state->type & INTEL_PT_INSTRUCTION)) { in intel_pt_sample()
2607 if (pt->sample_transactions && (state->type & INTEL_PT_TRANSACTION)) { in intel_pt_sample()
2613 if (pt->sample_ptwrites && (state->type & INTEL_PT_PTW)) { in intel_pt_sample()
2619 if (!(state->type & INTEL_PT_BRANCH)) in intel_pt_sample()
2622 if (pt->use_thread_stack) { in intel_pt_sample()
2623 thread_stack__event(ptq->thread, ptq->cpu, ptq->flags, in intel_pt_sample()
2624 state->from_ip, state->to_ip, ptq->insn_len, in intel_pt_sample()
2625 state->trace_nr, pt->callstack, in intel_pt_sample()
2626 pt->br_stack_sz_plus, in intel_pt_sample()
2627 pt->mispred_all); in intel_pt_sample()
2629 thread_stack__set_trace_nr(ptq->thread, ptq->cpu, state->trace_nr); in intel_pt_sample()
2632 if (pt->sample_branches) { in intel_pt_sample()
2633 if (state->from_nr != state->to_nr && in intel_pt_sample()
2634 state->from_ip && state->to_ip) { in intel_pt_sample()
2636 u64 to_ip = st->to_ip; in intel_pt_sample()
2637 u64 from_ip = st->from_ip; in intel_pt_sample()
2640 * perf cannot handle having different machines for ip in intel_pt_sample()
2643 st->to_ip = 0; in intel_pt_sample()
2647 st->from_ip = 0; in intel_pt_sample()
2648 st->to_ip = to_ip; in intel_pt_sample()
2650 st->from_ip = from_ip; in intel_pt_sample()
2658 if (!ptq->sync_switch) in intel_pt_sample()
2661 if (intel_pt_is_switch_ip(ptq, state->to_ip)) { in intel_pt_sample()
2662 switch (ptq->switch_state) { in intel_pt_sample()
2669 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_sample()
2672 ptq->switch_state = INTEL_PT_SS_EXPECTING_SWITCH_EVENT; in intel_pt_sample()
2675 } else if (!state->to_ip) { in intel_pt_sample()
2676 ptq->switch_state = INTEL_PT_SS_NOT_TRACING; in intel_pt_sample()
2677 } else if (ptq->switch_state == INTEL_PT_SS_NOT_TRACING) { in intel_pt_sample()
2678 ptq->switch_state = INTEL_PT_SS_UNKNOWN; in intel_pt_sample()
2679 } else if (ptq->switch_state == INTEL_PT_SS_UNKNOWN && in intel_pt_sample()
2680 state->to_ip == pt->ptss_ip && in intel_pt_sample()
2681 (ptq->flags & PERF_IP_FLAG_CALL)) { in intel_pt_sample()
2682 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_sample()
2690 struct machine *machine = pt->machine; in intel_pt_switch_ip()
2693 u64 ip, switch_ip = 0; in intel_pt_switch_ip() local
2706 start = dso__first_symbol(map->dso); in intel_pt_switch_ip()
2709 if (sym->binding == STB_GLOBAL && in intel_pt_switch_ip()
2710 !strcmp(sym->name, "__switch_to")) { in intel_pt_switch_ip()
2711 ip = map->unmap_ip(map, sym->start); in intel_pt_switch_ip()
2712 if (ip >= map->start && ip < map->end) { in intel_pt_switch_ip()
2713 switch_ip = ip; in intel_pt_switch_ip()
2722 if (pt->have_sched_switch == 1) in intel_pt_switch_ip()
2728 if (!strcmp(sym->name, ptss)) { in intel_pt_switch_ip()
2729 ip = map->unmap_ip(map, sym->start); in intel_pt_switch_ip()
2730 if (ip >= map->start && ip < map->end) { in intel_pt_switch_ip()
2731 *ptss_ip = ip; in intel_pt_switch_ip()
2744 if (pt->sync_switch_not_supported) in intel_pt_enable_sync_switch()
2747 pt->sync_switch = true; in intel_pt_enable_sync_switch()
2749 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_enable_sync_switch()
2750 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_enable_sync_switch()
2751 struct intel_pt_queue *ptq = queue->priv; in intel_pt_enable_sync_switch()
2754 ptq->sync_switch = true; in intel_pt_enable_sync_switch()
2762 pt->sync_switch = false; in intel_pt_disable_sync_switch()
2764 for (i = 0; i < pt->queues.nr_queues; i++) { in intel_pt_disable_sync_switch()
2765 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_disable_sync_switch()
2766 struct intel_pt_queue *ptq = queue->priv; in intel_pt_disable_sync_switch()
2769 ptq->sync_switch = false; in intel_pt_disable_sync_switch()
2781 struct intel_pt *pt = ptq->pt; in intel_pt_next_time()
2783 if (ptq->sel_start) { in intel_pt_next_time()
2785 ptq->sel_start = false; in intel_pt_next_time()
2786 ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].end; in intel_pt_next_time()
2788 } else if (ptq->sel_idx + 1 < pt->range_cnt) { in intel_pt_next_time()
2790 ptq->sel_start = true; in intel_pt_next_time()
2791 ptq->sel_idx += 1; in intel_pt_next_time()
2792 ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].start; in intel_pt_next_time()
2805 if (ptq->sel_start) { in intel_pt_time_filter()
2806 if (ptq->timestamp >= ptq->sel_timestamp) { in intel_pt_time_filter()
2809 if (!ptq->sel_timestamp) { in intel_pt_time_filter()
2817 ptq->have_sample = false; in intel_pt_time_filter()
2818 if (ptq->sel_timestamp > *ff_timestamp) { in intel_pt_time_filter()
2819 if (ptq->sync_switch) { in intel_pt_time_filter()
2820 intel_pt_next_tid(ptq->pt, ptq); in intel_pt_time_filter()
2821 ptq->switch_state = INTEL_PT_SS_UNKNOWN; in intel_pt_time_filter()
2823 *ff_timestamp = ptq->sel_timestamp; in intel_pt_time_filter()
2824 err = intel_pt_fast_forward(ptq->decoder, in intel_pt_time_filter()
2825 ptq->sel_timestamp); in intel_pt_time_filter()
2830 } else if (ptq->timestamp > ptq->sel_timestamp) { in intel_pt_time_filter()
2834 ptq->have_sample = false; in intel_pt_time_filter()
2835 ptq->switch_state = INTEL_PT_SS_NOT_TRACING; in intel_pt_time_filter()
2849 const struct intel_pt_state *state = ptq->state; in intel_pt_run_decoder()
2850 struct intel_pt *pt = ptq->pt; in intel_pt_run_decoder()
2854 if (!pt->kernel_start) { in intel_pt_run_decoder()
2855 pt->kernel_start = machine__kernel_start(pt->machine); in intel_pt_run_decoder()
2856 if (pt->per_cpu_mmaps && in intel_pt_run_decoder()
2857 (pt->have_sched_switch == 1 || pt->have_sched_switch == 3) && in intel_pt_run_decoder()
2858 !pt->timeless_decoding && intel_pt_tracing_kernel(pt) && in intel_pt_run_decoder()
2859 !pt->sampling_mode && !pt->synth_opts.vm_time_correlation) { in intel_pt_run_decoder()
2860 pt->switch_ip = intel_pt_switch_ip(pt, &pt->ptss_ip); in intel_pt_run_decoder()
2861 if (pt->switch_ip) { in intel_pt_run_decoder()
2863 pt->switch_ip, pt->ptss_ip); in intel_pt_run_decoder()
2870 ptq->queue_nr, ptq->cpu, ptq->pid, ptq->tid); in intel_pt_run_decoder()
2876 state = intel_pt_decode(ptq->decoder); in intel_pt_run_decoder()
2877 if (state->err) { in intel_pt_run_decoder()
2878 if (state->err == INTEL_PT_ERR_NODATA) in intel_pt_run_decoder()
2880 if (ptq->sync_switch && in intel_pt_run_decoder()
2881 state->from_ip >= pt->kernel_start) { in intel_pt_run_decoder()
2882 ptq->sync_switch = false; in intel_pt_run_decoder()
2885 ptq->timestamp = state->est_timestamp; in intel_pt_run_decoder()
2886 if (pt->synth_opts.errors) { in intel_pt_run_decoder()
2894 ptq->state = state; in intel_pt_run_decoder()
2895 ptq->have_sample = true; in intel_pt_run_decoder()
2899 if (pt->est_tsc && in intel_pt_run_decoder()
2900 (state->from_ip >= pt->kernel_start || !state->from_ip) && in intel_pt_run_decoder()
2901 state->to_ip && state->to_ip < pt->kernel_start) { in intel_pt_run_decoder()
2903 state->timestamp, state->est_timestamp); in intel_pt_run_decoder()
2904 ptq->timestamp = state->est_timestamp; in intel_pt_run_decoder()
2906 } else if (ptq->sync_switch && in intel_pt_run_decoder()
2907 ptq->switch_state == INTEL_PT_SS_UNKNOWN && in intel_pt_run_decoder()
2908 intel_pt_is_switch_ip(ptq, state->to_ip) && in intel_pt_run_decoder()
2909 ptq->next_tid == -1) { in intel_pt_run_decoder()
2911 state->timestamp, state->est_timestamp); in intel_pt_run_decoder()
2912 ptq->timestamp = state->est_timestamp; in intel_pt_run_decoder()
2913 } else if (state->timestamp > ptq->timestamp) { in intel_pt_run_decoder()
2914 ptq->timestamp = state->timestamp; in intel_pt_run_decoder()
2917 if (ptq->sel_timestamp) { in intel_pt_run_decoder()
2923 if (!pt->timeless_decoding && ptq->timestamp >= *timestamp) { in intel_pt_run_decoder()
2924 *timestamp = ptq->timestamp; in intel_pt_run_decoder()
2933 if (pt->queues.new_data) { in intel_pt_update_queues()
2934 pt->queues.new_data = false; in intel_pt_update_queues()
2950 if (!pt->heap.heap_cnt) in intel_pt_process_queues()
2953 if (pt->heap.heap_array[0].ordinal >= timestamp) in intel_pt_process_queues()
2956 queue_nr = pt->heap.heap_array[0].queue_nr; in intel_pt_process_queues()
2957 queue = &pt->queues.queue_array[queue_nr]; in intel_pt_process_queues()
2958 ptq = queue->priv; in intel_pt_process_queues()
2961 queue_nr, pt->heap.heap_array[0].ordinal, in intel_pt_process_queues()
2964 auxtrace_heap__pop(&pt->heap); in intel_pt_process_queues()
2966 if (pt->heap.heap_cnt) { in intel_pt_process_queues()
2967 ts = pt->heap.heap_array[0].ordinal + 1; in intel_pt_process_queues()
2979 auxtrace_heap__add(&pt->heap, queue_nr, ts); in intel_pt_process_queues()
2984 ret = auxtrace_heap__add(&pt->heap, queue_nr, ts); in intel_pt_process_queues()
2988 ptq->on_heap = false; in intel_pt_process_queues()
2998 struct auxtrace_queues *queues = &pt->queues; in intel_pt_process_timeless_queues()
3002 for (i = 0; i < queues->nr_queues; i++) { in intel_pt_process_timeless_queues()
3003 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_process_timeless_queues()
3004 struct intel_pt_queue *ptq = queue->priv; in intel_pt_process_timeless_queues()
3006 if (ptq && (tid == -1 || ptq->tid == tid)) { in intel_pt_process_timeless_queues()
3007 ptq->time = time_; in intel_pt_process_timeless_queues()
3019 struct machine *m = ptq->pt->machine; in intel_pt_sample_set_pid_tid_cpu()
3021 ptq->pid = sample->pid; in intel_pt_sample_set_pid_tid_cpu()
3022 ptq->tid = sample->tid; in intel_pt_sample_set_pid_tid_cpu()
3023 ptq->cpu = queue->cpu; in intel_pt_sample_set_pid_tid_cpu()
3026 ptq->queue_nr, ptq->cpu, ptq->pid, ptq->tid); in intel_pt_sample_set_pid_tid_cpu()
3028 thread__zput(ptq->thread); in intel_pt_sample_set_pid_tid_cpu()
3030 if (ptq->tid == -1) in intel_pt_sample_set_pid_tid_cpu()
3033 if (ptq->pid == -1) { in intel_pt_sample_set_pid_tid_cpu()
3034 ptq->thread = machine__find_thread(m, -1, ptq->tid); in intel_pt_sample_set_pid_tid_cpu()
3035 if (ptq->thread) in intel_pt_sample_set_pid_tid_cpu()
3036 ptq->pid = ptq->thread->pid_; in intel_pt_sample_set_pid_tid_cpu()
3040 ptq->thread = machine__findnew_thread(m, ptq->pid, ptq->tid); in intel_pt_sample_set_pid_tid_cpu()
3050 queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); in intel_pt_process_timeless_sample()
3052 return -EINVAL; in intel_pt_process_timeless_sample()
3054 ptq = queue->priv; in intel_pt_process_timeless_sample()
3058 ptq->stop = false; in intel_pt_process_timeless_sample()
3059 ptq->time = sample->time; in intel_pt_process_timeless_sample()
3067 return intel_pt_synth_error(pt, INTEL_PT_ERR_LOST, sample->cpu, in intel_pt_lost()
3068 sample->pid, sample->tid, 0, sample->time, in intel_pt_lost()
3069 sample->machine_pid, sample->vcpu); in intel_pt_lost()
3076 if (cpu < 0 || !pt->queues.nr_queues) in intel_pt_cpu_to_ptq()
3079 if ((unsigned)cpu >= pt->queues.nr_queues) in intel_pt_cpu_to_ptq()
3080 i = pt->queues.nr_queues - 1; in intel_pt_cpu_to_ptq()
3084 if (pt->queues.queue_array[i].cpu == cpu) in intel_pt_cpu_to_ptq()
3085 return pt->queues.queue_array[i].priv; in intel_pt_cpu_to_ptq()
3088 if (pt->queues.queue_array[--i].cpu == cpu) in intel_pt_cpu_to_ptq()
3089 return pt->queues.queue_array[i].priv; in intel_pt_cpu_to_ptq()
3092 for (; j < pt->queues.nr_queues; j++) { in intel_pt_cpu_to_ptq()
3093 if (pt->queues.queue_array[j].cpu == cpu) in intel_pt_cpu_to_ptq()
3094 return pt->queues.queue_array[j].priv; in intel_pt_cpu_to_ptq()
3106 if (!pt->sync_switch) in intel_pt_sync_switch()
3110 if (!ptq || !ptq->sync_switch) in intel_pt_sync_switch()
3113 switch (ptq->switch_state) { in intel_pt_sync_switch()
3118 ptq->next_tid = tid; in intel_pt_sync_switch()
3119 ptq->switch_state = INTEL_PT_SS_EXPECTING_SWITCH_IP; in intel_pt_sync_switch()
3122 if (!ptq->on_heap) { in intel_pt_sync_switch()
3123 ptq->timestamp = perf_time_to_tsc(timestamp, in intel_pt_sync_switch()
3124 &pt->tc); in intel_pt_sync_switch()
3125 err = auxtrace_heap__add(&pt->heap, ptq->queue_nr, in intel_pt_sync_switch()
3126 ptq->timestamp); in intel_pt_sync_switch()
3129 ptq->on_heap = true; in intel_pt_sync_switch()
3131 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_sync_switch()
3134 intel_pt_log("ERROR: cpu %d expecting switch ip\n", cpu); in intel_pt_sync_switch()
3140 ptq->next_tid = -1; in intel_pt_sync_switch()
3150 struct evsel *evsel = evlist__id2evsel(pt->session->evlist, sample->id); in intel_pt_process_switch()
3152 if (evsel != pt->switch_evsel) in intel_pt_process_switch()
3156 cpu = sample->cpu; in intel_pt_process_switch()
3159 cpu, tid, sample->time, perf_time_to_tsc(sample->time, in intel_pt_process_switch()
3160 &pt->tc)); in intel_pt_process_switch()
3162 ret = intel_pt_sync_switch(pt, cpu, tid, sample->time); in intel_pt_process_switch()
3166 return machine__set_current_tid(pt->machine, cpu, -1, tid); in intel_pt_process_switch()
3172 pid_t pid = sample->pid; in intel_pt_context_switch_in()
3173 pid_t tid = sample->tid; in intel_pt_context_switch_in()
3174 int cpu = sample->cpu; in intel_pt_context_switch_in()
3176 if (pt->sync_switch) { in intel_pt_context_switch_in()
3180 if (ptq && ptq->sync_switch) { in intel_pt_context_switch_in()
3181 ptq->next_tid = -1; in intel_pt_context_switch_in()
3182 switch (ptq->switch_state) { in intel_pt_context_switch_in()
3189 ptq->switch_state = INTEL_PT_SS_TRACING; in intel_pt_context_switch_in()
3201 if (machine__get_current_tid(pt->machine, cpu) == tid) in intel_pt_context_switch_in()
3204 return machine__set_current_tid(pt->machine, cpu, pid, tid); in intel_pt_context_switch_in()
3211 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; in intel_pt_guest_context_switch()
3212 struct machines *machines = &pt->session->machines; in intel_pt_guest_context_switch()
3213 struct machine *machine = machines__find(machines, sample->machine_pid); in intel_pt_guest_context_switch()
3215 pt->have_guest_sideband = true; in intel_pt_guest_context_switch()
3221 pt->sync_switch_not_supported = true; in intel_pt_guest_context_switch()
3222 if (pt->sync_switch) in intel_pt_guest_context_switch()
3229 return -EINVAL; in intel_pt_guest_context_switch()
3231 return machine__set_current_tid(machine, sample->vcpu, sample->pid, sample->tid); in intel_pt_guest_context_switch()
3237 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; in intel_pt_context_switch()
3244 cpu = sample->cpu; in intel_pt_context_switch()
3246 if (pt->have_sched_switch == 3) { in intel_pt_context_switch()
3249 if (event->header.type != PERF_RECORD_SWITCH_CPU_WIDE) { in intel_pt_context_switch()
3250 pr_err("Expecting CPU-wide context switch event\n"); in intel_pt_context_switch()
3251 return -EINVAL; in intel_pt_context_switch()
3253 pid = event->context_switch.next_prev_pid; in intel_pt_context_switch()
3254 tid = event->context_switch.next_prev_tid; in intel_pt_context_switch()
3258 pid = sample->pid; in intel_pt_context_switch()
3259 tid = sample->tid; in intel_pt_context_switch()
3262 if (tid == -1) in intel_pt_context_switch()
3265 ret = intel_pt_sync_switch(pt, cpu, tid, sample->time); in intel_pt_context_switch()
3269 return machine__set_current_tid(pt->machine, cpu, pid, tid); in intel_pt_context_switch()
3276 if (!pt->per_cpu_mmaps) in intel_pt_process_itrace_start()
3280 sample->cpu, event->itrace_start.pid, in intel_pt_process_itrace_start()
3281 event->itrace_start.tid, sample->time, in intel_pt_process_itrace_start()
3282 perf_time_to_tsc(sample->time, &pt->tc)); in intel_pt_process_itrace_start()
3284 return machine__set_current_tid(pt->machine, sample->cpu, in intel_pt_process_itrace_start()
3285 event->itrace_start.pid, in intel_pt_process_itrace_start()
3286 event->itrace_start.tid); in intel_pt_process_itrace_start()
3293 u64 hw_id = event->aux_output_hw_id.hw_id; in intel_pt_process_aux_output_hw_id()
3298 queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); in intel_pt_process_aux_output_hw_id()
3299 evsel = evlist__id2evsel_strict(pt->session->evlist, sample->id); in intel_pt_process_aux_output_hw_id()
3300 if (!queue || !queue->priv || !evsel || hw_id > INTEL_PT_MAX_PEBS) { in intel_pt_process_aux_output_hw_id()
3302 return -EINVAL; in intel_pt_process_aux_output_hw_id()
3305 ptq = queue->priv; in intel_pt_process_aux_output_hw_id()
3307 ptq->pebs[hw_id].evsel = evsel; in intel_pt_process_aux_output_hw_id()
3308 ptq->pebs[hw_id].id = sample->id; in intel_pt_process_aux_output_hw_id()
3316 if (!al->map || addr < al->map->start || addr >= al->map->end) { in intel_pt_find_map()
3318 return -1; in intel_pt_find_map()
3327 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; in intel_pt_text_poke()
3328 u64 addr = event->text_poke.addr + event->text_poke.new_len - 1; in intel_pt_text_poke()
3330 int cnt = 4096 + event->text_poke.new_len; in intel_pt_text_poke()
3331 struct thread *thread = pt->unknown_thread; in intel_pt_text_poke()
3333 struct machine *machine = pt->machine; in intel_pt_text_poke()
3337 if (!event->text_poke.new_len) in intel_pt_text_poke()
3340 for (; cnt; cnt--, addr--) { in intel_pt_text_poke()
3342 if (addr < event->text_poke.addr) in intel_pt_text_poke()
3347 if (!al.map->dso || !al.map->dso->auxtrace_cache) in intel_pt_text_poke()
3350 offset = al.map->map_ip(al.map, addr); in intel_pt_text_poke()
3352 e = intel_pt_cache_lookup(al.map->dso, machine, offset); in intel_pt_text_poke()
3356 if (addr + e->byte_cnt + e->length <= event->text_poke.addr) { in intel_pt_text_poke()
3362 if (e->branch != INTEL_PT_BR_NO_BRANCH) in intel_pt_text_poke()
3365 intel_pt_cache_invalidate(al.map->dso, machine, offset); in intel_pt_text_poke()
3367 al.map->dso->long_name, addr); in intel_pt_text_poke()
3379 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_process_event()
3387 if (!tool->ordered_events) { in intel_pt_process_event()
3389 return -EINVAL; in intel_pt_process_event()
3392 if (sample->time && sample->time != (u64)-1) in intel_pt_process_event()
3393 timestamp = perf_time_to_tsc(sample->time, &pt->tc); in intel_pt_process_event()
3397 if (timestamp || pt->timeless_decoding) { in intel_pt_process_event()
3403 if (pt->timeless_decoding) { in intel_pt_process_event()
3404 if (pt->sampling_mode) { in intel_pt_process_event()
3405 if (sample->aux_sample.size) in intel_pt_process_event()
3408 } else if (event->header.type == PERF_RECORD_EXIT) { in intel_pt_process_event()
3410 event->fork.tid, in intel_pt_process_event()
3411 sample->time); in intel_pt_process_event()
3414 if (!pt->first_timestamp) in intel_pt_process_event()
3421 if (event->header.type == PERF_RECORD_SAMPLE) { in intel_pt_process_event()
3422 if (pt->synth_opts.add_callchain && !sample->callchain) in intel_pt_process_event()
3424 if (pt->synth_opts.add_last_branch && !sample->branch_stack) in intel_pt_process_event()
3428 if (event->header.type == PERF_RECORD_AUX && in intel_pt_process_event()
3429 (event->aux.flags & PERF_AUX_FLAG_TRUNCATED) && in intel_pt_process_event()
3430 pt->synth_opts.errors) { in intel_pt_process_event()
3436 if (pt->switch_evsel && event->header.type == PERF_RECORD_SAMPLE) in intel_pt_process_event()
3438 else if (event->header.type == PERF_RECORD_ITRACE_START) in intel_pt_process_event()
3440 else if (event->header.type == PERF_RECORD_AUX_OUTPUT_HW_ID) in intel_pt_process_event()
3442 else if (event->header.type == PERF_RECORD_SWITCH || in intel_pt_process_event()
3443 event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) in intel_pt_process_event()
3446 if (!err && event->header.type == PERF_RECORD_TEXT_POKE) in intel_pt_process_event()
3449 if (intel_pt_enable_logging && intel_pt_log_events(pt, sample->time)) { in intel_pt_process_event()
3451 event->header.type, sample->cpu, sample->time, timestamp); in intel_pt_process_event()
3460 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_flush()
3467 if (!tool->ordered_events) in intel_pt_flush()
3468 return -EINVAL; in intel_pt_flush()
3474 if (pt->timeless_decoding) in intel_pt_flush()
3475 return intel_pt_process_timeless_queues(pt, -1, in intel_pt_flush()
3476 MAX_TIMESTAMP - 1); in intel_pt_flush()
3483 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_free_events()
3485 struct auxtrace_queues *queues = &pt->queues; in intel_pt_free_events()
3488 for (i = 0; i < queues->nr_queues; i++) { in intel_pt_free_events()
3489 intel_pt_free_queue(queues->queue_array[i].priv); in intel_pt_free_events()
3490 queues->queue_array[i].priv = NULL; in intel_pt_free_events()
3498 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_free()
3501 auxtrace_heap__free(&pt->heap); in intel_pt_free()
3503 session->auxtrace = NULL; in intel_pt_free()
3505 thread__put(pt->unknown_thread); in intel_pt_free()
3506 addr_filters__exit(&pt->filts); in intel_pt_free()
3507 zfree(&pt->chain); in intel_pt_free()
3508 zfree(&pt->filter); in intel_pt_free()
3509 zfree(&pt->time_ranges); in intel_pt_free()
3516 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_evsel_is_auxtrace()
3519 return evsel->core.attr.type == pt->pmu_type; in intel_pt_evsel_is_auxtrace()
3526 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_process_auxtrace_event()
3529 if (!pt->data_queued) { in intel_pt_process_auxtrace_event()
3532 int fd = perf_data__fd(session->data); in intel_pt_process_auxtrace_event()
3535 if (perf_data__is_pipe(session->data)) { in intel_pt_process_auxtrace_event()
3539 if (data_offset == -1) in intel_pt_process_auxtrace_event()
3540 return -errno; in intel_pt_process_auxtrace_event()
3543 err = auxtrace_queues__add_event(&pt->queues, session, event, in intel_pt_process_auxtrace_event()
3551 intel_pt_dump_event(pt, buffer->data, in intel_pt_process_auxtrace_event()
3552 buffer->size); in intel_pt_process_auxtrace_event()
3565 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_queue_data()
3570 return auxtrace_queues__add_event(&pt->queues, session, event, in intel_pt_queue_data()
3574 if (sample->time && sample->time != (u64)-1) in intel_pt_queue_data()
3575 timestamp = perf_time_to_tsc(sample->time, &pt->tc); in intel_pt_queue_data()
3579 return auxtrace_queues__add_sample(&pt->queues, session, sample, in intel_pt_queue_data()
3596 return perf_session__deliver_synth_event(intel_pt_synth->session, event, in intel_pt_event_synth()
3607 name, id, (u64)attr->sample_type); in intel_pt_synth_event()
3627 if (evsel->core.id && evsel->core.id[0] == id) { in intel_pt_set_event_name()
3628 if (evsel->name) in intel_pt_set_event_name()
3629 zfree(&evsel->name); in intel_pt_set_event_name()
3630 evsel->name = strdup(name); in intel_pt_set_event_name()
3642 if (evsel->core.attr.type == pt->pmu_type && evsel->core.ids) in intel_pt_evsel()
3652 struct evlist *evlist = session->evlist; in intel_pt_synth_events()
3666 attr.sample_type = evsel->core.attr.sample_type & PERF_SAMPLE_MASK; in intel_pt_synth_events()
3669 if (pt->timeless_decoding) in intel_pt_synth_events()
3673 if (!pt->per_cpu_mmaps) in intel_pt_synth_events()
3675 attr.exclude_user = evsel->core.attr.exclude_user; in intel_pt_synth_events()
3676 attr.exclude_kernel = evsel->core.attr.exclude_kernel; in intel_pt_synth_events()
3677 attr.exclude_hv = evsel->core.attr.exclude_hv; in intel_pt_synth_events()
3678 attr.exclude_host = evsel->core.attr.exclude_host; in intel_pt_synth_events()
3679 attr.exclude_guest = evsel->core.attr.exclude_guest; in intel_pt_synth_events()
3680 attr.sample_id_all = evsel->core.attr.sample_id_all; in intel_pt_synth_events()
3681 attr.read_format = evsel->core.attr.read_format; in intel_pt_synth_events()
3683 id = evsel->core.id[0] + 1000000000; in intel_pt_synth_events()
3687 if (pt->synth_opts.branches) { in intel_pt_synth_events()
3694 pt->sample_branches = true; in intel_pt_synth_events()
3695 pt->branches_sample_type = attr.sample_type; in intel_pt_synth_events()
3696 pt->branches_id = id; in intel_pt_synth_events()
3701 if (pt->synth_opts.callchain) in intel_pt_synth_events()
3703 if (pt->synth_opts.last_branch) { in intel_pt_synth_events()
3713 if (pt->synth_opts.instructions) { in intel_pt_synth_events()
3715 if (pt->synth_opts.period_type == PERF_ITRACE_PERIOD_NANOSECS) in intel_pt_synth_events()
3717 intel_pt_ns_to_ticks(pt, pt->synth_opts.period); in intel_pt_synth_events()
3719 attr.sample_period = pt->synth_opts.period; in intel_pt_synth_events()
3723 pt->sample_instructions = true; in intel_pt_synth_events()
3724 pt->instructions_sample_type = attr.sample_type; in intel_pt_synth_events()
3725 pt->instructions_id = id; in intel_pt_synth_events()
3732 if (pt->synth_opts.transactions) { in intel_pt_synth_events()
3737 pt->sample_transactions = true; in intel_pt_synth_events()
3738 pt->transactions_sample_type = attr.sample_type; in intel_pt_synth_events()
3739 pt->transactions_id = id; in intel_pt_synth_events()
3747 if (pt->synth_opts.ptwrites) { in intel_pt_synth_events()
3752 pt->sample_ptwrites = true; in intel_pt_synth_events()
3753 pt->ptwrites_sample_type = attr.sample_type; in intel_pt_synth_events()
3754 pt->ptwrites_id = id; in intel_pt_synth_events()
3759 if (pt->synth_opts.pwr_events) { in intel_pt_synth_events()
3760 pt->sample_pwr_events = true; in intel_pt_synth_events()
3761 pt->pwr_events_sample_type = attr.sample_type; in intel_pt_synth_events()
3767 pt->cbr_id = id; in intel_pt_synth_events()
3775 pt->psb_id = id; in intel_pt_synth_events()
3780 if (pt->synth_opts.pwr_events && (evsel->core.attr.config & INTEL_PT_CFG_PWR_EVT_EN)) { in intel_pt_synth_events()
3785 pt->mwait_id = id; in intel_pt_synth_events()
3793 pt->pwre_id = id; in intel_pt_synth_events()
3801 pt->exstop_id = id; in intel_pt_synth_events()
3809 pt->pwrx_id = id; in intel_pt_synth_events()
3814 if (pt->synth_opts.intr_events && (evsel->core.attr.config & INTEL_PT_CFG_EVT_EN)) { in intel_pt_synth_events()
3819 pt->evt_sample_type = attr.sample_type; in intel_pt_synth_events()
3820 pt->evt_id = id; in intel_pt_synth_events()
3825 if (pt->synth_opts.intr_events && pt->cap_event_trace) { in intel_pt_synth_events()
3830 pt->iflag_chg_sample_type = attr.sample_type; in intel_pt_synth_events()
3831 pt->iflag_chg_id = id; in intel_pt_synth_events()
3843 if (!pt->synth_opts.other_events) in intel_pt_setup_pebs_events()
3846 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_setup_pebs_events()
3847 if (evsel->core.attr.aux_output && evsel->core.id) { in intel_pt_setup_pebs_events()
3848 if (pt->single_pebs) { in intel_pt_setup_pebs_events()
3849 pt->single_pebs = false; in intel_pt_setup_pebs_events()
3852 pt->single_pebs = true; in intel_pt_setup_pebs_events()
3853 pt->sample_pebs = true; in intel_pt_setup_pebs_events()
3854 pt->pebs_evsel = evsel; in intel_pt_setup_pebs_events()
3878 if (evsel->core.attr.context_switch) in intel_pt_find_switch()
3889 if (!strcmp(var, "intel-pt.mispred-all")) in intel_pt_perf_config()
3890 pt->mispred_all = perf_config_bool(var, value); in intel_pt_perf_config()
3892 if (!strcmp(var, "intel-pt.max-loops")) in intel_pt_perf_config()
3893 perf_config_int(&pt->max_loops, var, value); in intel_pt_perf_config()
3903 tsc = perf_time_to_tsc(ns, &pt->tc); in intel_pt_tsc_start()
3906 tm = tsc_to_perf_time(tsc, &pt->tc); in intel_pt_tsc_start()
3909 tsc -= 1; in intel_pt_tsc_start()
3913 tm = tsc_to_perf_time(++tsc, &pt->tc); in intel_pt_tsc_start()
3923 tsc = perf_time_to_tsc(ns, &pt->tc); in intel_pt_tsc_end()
3926 tm = tsc_to_perf_time(tsc, &pt->tc); in intel_pt_tsc_end()
3933 tm = tsc_to_perf_time(--tsc, &pt->tc); in intel_pt_tsc_end()
3941 struct perf_time_interval *p = opts->ptime_range; in intel_pt_setup_time_ranges()
3942 int n = opts->range_num; in intel_pt_setup_time_ranges()
3945 if (!n || !p || pt->timeless_decoding) in intel_pt_setup_time_ranges()
3948 pt->time_ranges = calloc(n, sizeof(struct range)); in intel_pt_setup_time_ranges()
3949 if (!pt->time_ranges) in intel_pt_setup_time_ranges()
3950 return -ENOMEM; in intel_pt_setup_time_ranges()
3952 pt->range_cnt = n; in intel_pt_setup_time_ranges()
3957 struct range *r = &pt->time_ranges[i]; in intel_pt_setup_time_ranges()
3962 * Take care to ensure the TSC range matches the perf-time range in intel_pt_setup_time_ranges()
3963 * when converted back to perf-time. in intel_pt_setup_time_ranges()
3965 r->start = ts ? intel_pt_tsc_start(ts, pt) : 0; in intel_pt_setup_time_ranges()
3966 r->end = te ? intel_pt_tsc_end(te, pt) : 0; in intel_pt_setup_time_ranges()
3971 i, r->start, r->end); in intel_pt_setup_time_ranges()
3991 return -errno; in intel_pt_parse_vm_tm_corr_arg()
3994 pt->dflt_tsc_offset = tsc_offset; in intel_pt_parse_vm_tm_corr_arg()
4002 return -errno; in intel_pt_parse_vm_tm_corr_arg()
4004 return -EINVAL; in intel_pt_parse_vm_tm_corr_arg()
4005 vmcs_info = intel_pt_findnew_vmcs(&pt->vmcs_info, vmcs, tsc_offset); in intel_pt_parse_vm_tm_corr_arg()
4007 return -ENOMEM; in intel_pt_parse_vm_tm_corr_arg()
4019 char *args = pt->synth_opts.vm_tm_corr_args; in intel_pt_parse_vm_tm_corr_args()
4047 [INTEL_PT_PER_CPU_MMAPS] = " Per-cpu maps %"PRId64"\n",
4053 [INTEL_PT_MAX_NONTURBO_RATIO] = " Max non-turbo ratio %"PRIu64"\n",
4077 fprintf(stdout, " %-20s%s\n", name, str ? str : ""); in intel_pt_print_info_str()
4082 return auxtrace_info->header.size >= in intel_pt_has()
4089 struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; in intel_pt_process_auxtrace_info()
4096 if (auxtrace_info->header.size < sizeof(struct perf_record_auxtrace_info) + in intel_pt_process_auxtrace_info()
4098 return -EINVAL; in intel_pt_process_auxtrace_info()
4102 return -ENOMEM; in intel_pt_process_auxtrace_info()
4104 pt->vmcs_info = RB_ROOT; in intel_pt_process_auxtrace_info()
4106 addr_filters__init(&pt->filts); in intel_pt_process_auxtrace_info()
4112 err = auxtrace_queues__init(&pt->queues); in intel_pt_process_auxtrace_info()
4116 if (session->itrace_synth_opts->set) { in intel_pt_process_auxtrace_info()
4117 pt->synth_opts = *session->itrace_synth_opts; in intel_pt_process_auxtrace_info()
4119 struct itrace_synth_opts *opts = session->itrace_synth_opts; in intel_pt_process_auxtrace_info()
4121 itrace_synth_opts__set_default(&pt->synth_opts, opts->default_no_sample); in intel_pt_process_auxtrace_info()
4122 if (!opts->default_no_sample && !opts->inject) { in intel_pt_process_auxtrace_info()
4123 pt->synth_opts.branches = false; in intel_pt_process_auxtrace_info()
4124 pt->synth_opts.callchain = true; in intel_pt_process_auxtrace_info()
4125 pt->synth_opts.add_callchain = true; in intel_pt_process_auxtrace_info()
4127 pt->synth_opts.thread_stack = opts->thread_stack; in intel_pt_process_auxtrace_info()
4130 if (!(pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_USE_STDOUT)) in intel_pt_process_auxtrace_info()
4133 pt->session = session; in intel_pt_process_auxtrace_info()
4134 pt->machine = &session->machines.host; /* No kvm support */ in intel_pt_process_auxtrace_info()
4135 pt->auxtrace_type = auxtrace_info->type; in intel_pt_process_auxtrace_info()
4136 pt->pmu_type = auxtrace_info->priv[INTEL_PT_PMU_TYPE]; in intel_pt_process_auxtrace_info()
4137 pt->tc.time_shift = auxtrace_info->priv[INTEL_PT_TIME_SHIFT]; in intel_pt_process_auxtrace_info()
4138 pt->tc.time_mult = auxtrace_info->priv[INTEL_PT_TIME_MULT]; in intel_pt_process_auxtrace_info()
4139 pt->tc.time_zero = auxtrace_info->priv[INTEL_PT_TIME_ZERO]; in intel_pt_process_auxtrace_info()
4140 pt->cap_user_time_zero = auxtrace_info->priv[INTEL_PT_CAP_USER_TIME_ZERO]; in intel_pt_process_auxtrace_info()
4141 pt->tsc_bit = auxtrace_info->priv[INTEL_PT_TSC_BIT]; in intel_pt_process_auxtrace_info()
4142 pt->noretcomp_bit = auxtrace_info->priv[INTEL_PT_NORETCOMP_BIT]; in intel_pt_process_auxtrace_info()
4143 pt->have_sched_switch = auxtrace_info->priv[INTEL_PT_HAVE_SCHED_SWITCH]; in intel_pt_process_auxtrace_info()
4144 pt->snapshot_mode = auxtrace_info->priv[INTEL_PT_SNAPSHOT_MODE]; in intel_pt_process_auxtrace_info()
4145 pt->per_cpu_mmaps = auxtrace_info->priv[INTEL_PT_PER_CPU_MMAPS]; in intel_pt_process_auxtrace_info()
4146 intel_pt_print_info(&auxtrace_info->priv[0], INTEL_PT_PMU_TYPE, in intel_pt_process_auxtrace_info()
4150 pt->mtc_bit = auxtrace_info->priv[INTEL_PT_MTC_BIT]; in intel_pt_process_auxtrace_info()
4151 pt->mtc_freq_bits = auxtrace_info->priv[INTEL_PT_MTC_FREQ_BITS]; in intel_pt_process_auxtrace_info()
4152 pt->tsc_ctc_ratio_n = auxtrace_info->priv[INTEL_PT_TSC_CTC_N]; in intel_pt_process_auxtrace_info()
4153 pt->tsc_ctc_ratio_d = auxtrace_info->priv[INTEL_PT_TSC_CTC_D]; in intel_pt_process_auxtrace_info()
4154 pt->cyc_bit = auxtrace_info->priv[INTEL_PT_CYC_BIT]; in intel_pt_process_auxtrace_info()
4155 intel_pt_print_info(&auxtrace_info->priv[0], INTEL_PT_MTC_BIT, in intel_pt_process_auxtrace_info()
4160 pt->max_non_turbo_ratio = in intel_pt_process_auxtrace_info()
4161 auxtrace_info->priv[INTEL_PT_MAX_NONTURBO_RATIO]; in intel_pt_process_auxtrace_info()
4162 intel_pt_print_info(&auxtrace_info->priv[0], in intel_pt_process_auxtrace_info()
4167 info = &auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN] + 1; in intel_pt_process_auxtrace_info()
4168 info_end = (void *)auxtrace_info + auxtrace_info->header.size; in intel_pt_process_auxtrace_info()
4173 len = auxtrace_info->priv[INTEL_PT_FILTER_STR_LEN]; in intel_pt_process_auxtrace_info()
4174 intel_pt_print_info(&auxtrace_info->priv[0], in intel_pt_process_auxtrace_info()
4184 err = -EINVAL; in intel_pt_process_auxtrace_info()
4187 pt->filter = memdup(filter, len); in intel_pt_process_auxtrace_info()
4188 if (!pt->filter) { in intel_pt_process_auxtrace_info()
4189 err = -ENOMEM; in intel_pt_process_auxtrace_info()
4192 if (session->header.needs_swap) in intel_pt_process_auxtrace_info()
4193 mem_bswap_64(pt->filter, len); in intel_pt_process_auxtrace_info()
4194 if (pt->filter[len - 1]) { in intel_pt_process_auxtrace_info()
4196 err = -EINVAL; in intel_pt_process_auxtrace_info()
4199 err = addr_filters__parse_bare_filter(&pt->filts, in intel_pt_process_auxtrace_info()
4204 intel_pt_print_info_str("Filter string", pt->filter); in intel_pt_process_auxtrace_info()
4208 pt->cap_event_trace = *info++; in intel_pt_process_auxtrace_info()
4211 pt->cap_event_trace); in intel_pt_process_auxtrace_info()
4214 pt->timeless_decoding = intel_pt_timeless_decoding(pt); in intel_pt_process_auxtrace_info()
4215 if (pt->timeless_decoding && !pt->tc.time_mult) in intel_pt_process_auxtrace_info()
4216 pt->tc.time_mult = 1; in intel_pt_process_auxtrace_info()
4217 pt->have_tsc = intel_pt_have_tsc(pt); in intel_pt_process_auxtrace_info()
4218 pt->sampling_mode = intel_pt_sampling_mode(pt); in intel_pt_process_auxtrace_info()
4219 pt->est_tsc = !pt->timeless_decoding; in intel_pt_process_auxtrace_info()
4221 if (pt->synth_opts.vm_time_correlation) { in intel_pt_process_auxtrace_info()
4222 if (pt->timeless_decoding) { in intel_pt_process_auxtrace_info()
4224 err = -EINVAL; in intel_pt_process_auxtrace_info()
4227 if (session->itrace_synth_opts->ptime_range) { in intel_pt_process_auxtrace_info()
4229 err = -EINVAL; in intel_pt_process_auxtrace_info()
4235 err = -EINVAL; in intel_pt_process_auxtrace_info()
4243 pt->unknown_thread = thread__new(999999999, 999999999); in intel_pt_process_auxtrace_info()
4244 if (!pt->unknown_thread) { in intel_pt_process_auxtrace_info()
4245 err = -ENOMEM; in intel_pt_process_auxtrace_info()
4255 INIT_LIST_HEAD(&pt->unknown_thread->node); in intel_pt_process_auxtrace_info()
4257 err = thread__set_comm(pt->unknown_thread, "unknown", 0); in intel_pt_process_auxtrace_info()
4260 if (thread__init_maps(pt->unknown_thread, pt->machine)) { in intel_pt_process_auxtrace_info()
4261 err = -ENOMEM; in intel_pt_process_auxtrace_info()
4265 pt->auxtrace.process_event = intel_pt_process_event; in intel_pt_process_auxtrace_info()
4266 pt->auxtrace.process_auxtrace_event = intel_pt_process_auxtrace_event; in intel_pt_process_auxtrace_info()
4267 pt->auxtrace.queue_data = intel_pt_queue_data; in intel_pt_process_auxtrace_info()
4268 pt->auxtrace.dump_auxtrace_sample = intel_pt_dump_sample; in intel_pt_process_auxtrace_info()
4269 pt->auxtrace.flush_events = intel_pt_flush; in intel_pt_process_auxtrace_info()
4270 pt->auxtrace.free_events = intel_pt_free_events; in intel_pt_process_auxtrace_info()
4271 pt->auxtrace.free = intel_pt_free; in intel_pt_process_auxtrace_info()
4272 pt->auxtrace.evsel_is_auxtrace = intel_pt_evsel_is_auxtrace; in intel_pt_process_auxtrace_info()
4273 session->auxtrace = &pt->auxtrace; in intel_pt_process_auxtrace_info()
4278 if (pt->have_sched_switch == 1) { in intel_pt_process_auxtrace_info()
4279 pt->switch_evsel = intel_pt_find_sched_switch(session->evlist); in intel_pt_process_auxtrace_info()
4280 if (!pt->switch_evsel) { in intel_pt_process_auxtrace_info()
4282 err = -EINVAL; in intel_pt_process_auxtrace_info()
4285 } else if (pt->have_sched_switch == 2 && in intel_pt_process_auxtrace_info()
4286 !intel_pt_find_switch(session->evlist)) { in intel_pt_process_auxtrace_info()
4288 err = -EINVAL; in intel_pt_process_auxtrace_info()
4292 if (pt->synth_opts.log) { in intel_pt_process_auxtrace_info()
4293 bool log_on_error = pt->synth_opts.log_plus_flags & AUXTRACE_LOG_FLG_ON_ERROR; in intel_pt_process_auxtrace_info()
4294 unsigned int log_on_error_size = pt->synth_opts.log_on_error_size; in intel_pt_process_auxtrace_info()
4299 /* Maximum non-turbo ratio is TSC freq / 100 MHz */ in intel_pt_process_auxtrace_info()
4300 if (pt->tc.time_mult) { in intel_pt_process_auxtrace_info()
4303 if (!pt->max_non_turbo_ratio) in intel_pt_process_auxtrace_info()
4304 pt->max_non_turbo_ratio = in intel_pt_process_auxtrace_info()
4307 intel_pt_log("Maximum non-turbo ratio %u\n", in intel_pt_process_auxtrace_info()
4308 pt->max_non_turbo_ratio); in intel_pt_process_auxtrace_info()
4309 pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000; in intel_pt_process_auxtrace_info()
4312 err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); in intel_pt_process_auxtrace_info()
4316 if (pt->synth_opts.calls) in intel_pt_process_auxtrace_info()
4317 pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | in intel_pt_process_auxtrace_info()
4319 if (pt->synth_opts.returns) in intel_pt_process_auxtrace_info()
4320 pt->branches_filter |= PERF_IP_FLAG_RETURN | in intel_pt_process_auxtrace_info()
4323 if ((pt->synth_opts.callchain || pt->synth_opts.add_callchain) && in intel_pt_process_auxtrace_info()
4328 pt->synth_opts.callchain = false; in intel_pt_process_auxtrace_info()
4329 pt->synth_opts.add_callchain = false; in intel_pt_process_auxtrace_info()
4333 if (pt->synth_opts.add_callchain) { in intel_pt_process_auxtrace_info()
4339 if (pt->synth_opts.last_branch || pt->synth_opts.add_last_branch) { in intel_pt_process_auxtrace_info()
4340 pt->br_stack_sz = pt->synth_opts.last_branch_sz; in intel_pt_process_auxtrace_info()
4341 pt->br_stack_sz_plus = pt->br_stack_sz; in intel_pt_process_auxtrace_info()
4344 if (pt->synth_opts.add_last_branch) { in intel_pt_process_auxtrace_info()
4350 * actual sample ip to where the sample time is recorded. in intel_pt_process_auxtrace_info()
4356 pt->br_stack_sz_plus += 1024; in intel_pt_process_auxtrace_info()
4358 pt->br_stack_sz_plus += 1; in intel_pt_process_auxtrace_info()
4361 pt->use_thread_stack = pt->synth_opts.callchain || in intel_pt_process_auxtrace_info()
4362 pt->synth_opts.add_callchain || in intel_pt_process_auxtrace_info()
4363 pt->synth_opts.thread_stack || in intel_pt_process_auxtrace_info()
4364 pt->synth_opts.last_branch || in intel_pt_process_auxtrace_info()
4365 pt->synth_opts.add_last_branch; in intel_pt_process_auxtrace_info()
4367 pt->callstack = pt->synth_opts.callchain || in intel_pt_process_auxtrace_info()
4368 pt->synth_opts.add_callchain || in intel_pt_process_auxtrace_info()
4369 pt->synth_opts.thread_stack; in intel_pt_process_auxtrace_info()
4377 if (pt->sampling_mode || list_empty(&session->auxtrace_index)) in intel_pt_process_auxtrace_info()
4380 err = auxtrace_queues__process_index(&pt->queues, session); in intel_pt_process_auxtrace_info()
4384 if (pt->queues.populated) in intel_pt_process_auxtrace_info()
4385 pt->data_queued = true; in intel_pt_process_auxtrace_info()
4387 if (pt->timeless_decoding) in intel_pt_process_auxtrace_info()
4393 zfree(&pt->chain); in intel_pt_process_auxtrace_info()
4394 thread__zput(pt->unknown_thread); in intel_pt_process_auxtrace_info()
4397 auxtrace_queues__free(&pt->queues); in intel_pt_process_auxtrace_info()
4398 session->auxtrace = NULL; in intel_pt_process_auxtrace_info()
4400 addr_filters__exit(&pt->filts); in intel_pt_process_auxtrace_info()
4401 zfree(&pt->filter); in intel_pt_process_auxtrace_info()
4402 zfree(&pt->time_ranges); in intel_pt_process_auxtrace_info()