Lines Matching refs:pt

176 	struct intel_pt *pt;  member
224 static void intel_pt_dump(struct intel_pt *pt __maybe_unused, in intel_pt_dump()
264 static void intel_pt_dump_event(struct intel_pt *pt, unsigned char *buf, in intel_pt_dump_event() argument
268 intel_pt_dump(pt, buf, len); in intel_pt_dump_event()
284 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_dump_sample() local
288 intel_pt_dump(pt, sample->aux_sample.data, sample->aux_sample.size); in intel_pt_dump_sample()
291 static bool intel_pt_log_events(struct intel_pt *pt, u64 tm) in intel_pt_log_events() argument
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()
346 struct intel_pt *pt = ptq->pt; in intel_pt_findnew_vmcs_info() local
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()
354 static void intel_pt_free_vmcs_info(struct intel_pt *pt) in intel_pt_free_vmcs_info() argument
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()
368 static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *a, in intel_pt_do_fix_overlap() argument
375 pt->have_tsc, &consecutive, in intel_pt_do_fix_overlap()
376 pt->synth_opts.vm_time_correlation); in intel_pt_do_fix_overlap()
384 if (pt->synth_opts.vm_time_correlation) in intel_pt_do_fix_overlap()
401 int fd = perf_data__fd(ptq->pt->session->data); in intel_pt_get_buffer()
408 might_overlap = ptq->pt->snapshot_mode || ptq->pt->sampling_mode; in intel_pt_get_buffer()
410 intel_pt_do_fix_overlap(ptq->pt, old_buffer, buffer)) in intel_pt_get_buffer()
452 queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; in intel_pt_lookahead()
502 queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; in intel_pt_get_trace()
674 return ip >= ptq->pt->kernel_start ? in intel_pt_nr_cpumode()
689 struct machines *machines = &ptq->pt->session->machines; in intel_pt_get_guest()
745 struct machine *machine = ptq->pt->machine; in intel_pt_walk_next_insn()
766 if (ptq->pt->have_guest_sideband) { in intel_pt_walk_next_insn()
792 thread = ptq->pt->unknown_thread; 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()
966 return intel_pt_match_pgd_ip(ptq->pt, ip, ip, NULL); 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()
984 return intel_pt_match_pgd_ip(ptq->pt, ip, offset, in __intel_pt_pgd_ip()
993 static bool intel_pt_get_config(struct intel_pt *pt, in intel_pt_get_config() argument
996 if (attr->type == pt->pmu_type) { in intel_pt_get_config()
1005 static bool intel_pt_exclude_kernel(struct intel_pt *pt) in intel_pt_exclude_kernel() argument
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()
1017 static bool intel_pt_return_compression(struct intel_pt *pt) in intel_pt_return_compression() argument
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()
1033 static bool intel_pt_branch_enable(struct intel_pt *pt) in intel_pt_branch_enable() argument
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()
1047 static bool intel_pt_disabled_tnt(struct intel_pt *pt) in intel_pt_disabled_tnt() argument
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()
1060 static unsigned int intel_pt_mtc_period(struct intel_pt *pt) in intel_pt_mtc_period() argument
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()
1079 static bool intel_pt_timeless_decoding(struct intel_pt *pt) in intel_pt_timeless_decoding() argument
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()
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()
1101 static bool intel_pt_tracing_kernel(struct intel_pt *pt) in intel_pt_tracing_kernel() argument
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()
1113 static bool intel_pt_have_tsc(struct intel_pt *pt) in intel_pt_have_tsc() argument
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()
1133 static bool intel_pt_have_mtc(struct intel_pt *pt) in intel_pt_have_mtc() argument
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()
1146 static bool intel_pt_sampling_mode(struct intel_pt *pt) in intel_pt_sampling_mode() argument
1150 evlist__for_each_entry(pt->session->evlist, evsel) { in intel_pt_sampling_mode()
1158 static u64 intel_pt_ctl(struct intel_pt *pt) in intel_pt_ctl() argument
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()
1170 static u64 intel_pt_ns_to_ticks(const struct intel_pt *pt, u64 ns) in intel_pt_ns_to_ticks() argument
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()
1180 static struct ip_callchain *intel_pt_alloc_chain(struct intel_pt *pt) in intel_pt_alloc_chain() argument
1185 sz += (pt->synth_opts.callchain_sz + 1) * sizeof(u64); in intel_pt_alloc_chain()
1189 static int intel_pt_callchain_init(struct intel_pt *pt) in intel_pt_callchain_init() argument
1193 evlist__for_each_entry(pt->session->evlist, evsel) { 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()
1205 static void intel_pt_add_callchain(struct intel_pt *pt, in intel_pt_add_callchain() argument
1208 struct thread *thread = machine__findnew_thread(pt->machine, 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()
1227 static int intel_pt_br_stack_init(struct intel_pt *pt) in intel_pt_br_stack_init() argument
1231 evlist__for_each_entry(pt->session->evlist, evsel) { 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()
1243 static void intel_pt_add_br_stack(struct intel_pt *pt, in intel_pt_add_br_stack() argument
1246 struct thread *thread = machine__findnew_thread(pt->machine, 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()
1260 static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, in intel_pt_alloc_queue() argument
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()
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()
1289 ptq->pt = pt; in intel_pt_alloc_queue()
1291 ptq->exclude_kernel = intel_pt_exclude_kernel(pt); in intel_pt_alloc_queue()
1302 params.return_compression = intel_pt_return_compression(pt); in intel_pt_alloc_queue()
1303 params.branch_enable = intel_pt_branch_enable(pt); in intel_pt_alloc_queue()
1304 params.ctl = intel_pt_ctl(pt); in intel_pt_alloc_queue()
1305 params.max_non_turbo_ratio = pt->max_non_turbo_ratio; in intel_pt_alloc_queue()
1306 params.mtc_period = intel_pt_mtc_period(pt); 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()
1316 if (params.branch_enable && intel_pt_disabled_tnt(pt) && !params.quick) 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()
1336 params.period = intel_pt_ns_to_ticks(pt, in intel_pt_alloc_queue()
1337 pt->synth_opts.period); in intel_pt_alloc_queue()
1383 static void intel_pt_first_timestamp(struct intel_pt *pt, u64 timestamp) in intel_pt_first_timestamp() argument
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()
1400 struct machines *machines = &ptq->pt->session->machines; in intel_pt_get_guest_from_sideband()
1447 static void intel_pt_set_pid_tid_cpu(struct intel_pt *pt, in intel_pt_set_pid_tid_cpu() argument
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()
1460 ptq->thread = machine__find_thread(pt->machine, -1, ptq->tid); 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()
1478 struct intel_pt *pt = ptq->pt; in intel_pt_sample_flags() local
1511 if (pt->cap_event_trace) { in intel_pt_sample_flags()
1523 static void intel_pt_setup_time_range(struct intel_pt *pt, in intel_pt_setup_time_range() argument
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()
1535 ptq->sel_timestamp = pt->time_ranges[0].end; in intel_pt_setup_time_range()
1540 static int intel_pt_setup_queue(struct intel_pt *pt, in intel_pt_setup_queue() argument
1550 ptq = intel_pt_alloc_queue(pt, queue_nr); 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()
1565 ptq->sync_switch = pt->sync_switch; in intel_pt_setup_queue()
1567 intel_pt_setup_time_range(pt, ptq); in intel_pt_setup_queue()
1576 if (pt->timeless_decoding) in intel_pt_setup_queue()
1613 ret = auxtrace_heap__add(&pt->heap, queue_nr, ptq->timestamp); in intel_pt_setup_queue()
1622 static int intel_pt_setup_queues(struct intel_pt *pt) in intel_pt_setup_queues() argument
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()
1635 static inline bool intel_pt_skip_event(struct intel_pt *pt) in intel_pt_skip_event() argument
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()
1646 static inline bool intel_pt_skip_cbr_event(struct intel_pt *pt) in intel_pt_skip_cbr_event() argument
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()
1662 if (ptq->pt->have_guest_sideband) { in intel_pt_prep_a_sample()
1677 static void intel_pt_prep_b_sample(struct intel_pt *pt, in intel_pt_prep_b_sample() argument
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()
1703 static inline int intel_pt_opt_inject(struct intel_pt *pt, in intel_pt_opt_inject() argument
1707 if (!pt->synth_opts.inject) in intel_pt_opt_inject()
1713 static int intel_pt_deliver_synth_event(struct intel_pt *pt, in intel_pt_deliver_synth_event() argument
1719 ret = intel_pt_opt_inject(pt, event, sample, type); in intel_pt_deliver_synth_event()
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() local
1741 if (pt->branches_filter && !(pt->branches_filter & ptq->flags)) in intel_pt_synth_branch_sample()
1744 if (intel_pt_skip_event(pt)) in intel_pt_synth_branch_sample()
1747 intel_pt_prep_b_sample(pt, ptq, event, &sample); 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()
1776 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_branch_sample()
1777 pt->branches_sample_type); in intel_pt_synth_branch_sample()
1780 static void intel_pt_prep_sample(struct intel_pt *pt, in intel_pt_prep_sample() argument
1785 intel_pt_prep_b_sample(pt, ptq, event, sample); in intel_pt_prep_sample()
1787 if (pt->synth_opts.callchain) { 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()
1794 if (pt->synth_opts.last_branch) { in intel_pt_prep_sample()
1796 pt->br_stack_sz); in intel_pt_prep_sample()
1803 struct intel_pt *pt = ptq->pt; in intel_pt_synth_instruction_sample() local
1807 if (intel_pt_skip_event(pt)) in intel_pt_synth_instruction_sample()
1810 intel_pt_prep_sample(pt, ptq, event, &sample); 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()
1829 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
1839 if (intel_pt_skip_event(pt)) in intel_pt_synth_transaction_sample()
1842 intel_pt_prep_sample(pt, ptq, event, &sample); 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()
1847 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_transaction_sample()
1848 pt->transactions_sample_type); in intel_pt_synth_transaction_sample()
1851 static void intel_pt_prep_p_sample(struct intel_pt *pt, in intel_pt_prep_p_sample() argument
1856 intel_pt_prep_sample(pt, ptq, event, sample); in intel_pt_prep_p_sample()
1868 struct intel_pt *pt = ptq->pt; in intel_pt_synth_ptwrite_sample() local
1873 if (intel_pt_skip_event(pt)) in intel_pt_synth_ptwrite_sample()
1876 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
1888 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
1900 if (intel_pt_skip_cbr_event(pt)) in intel_pt_synth_cbr_sample()
1905 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
1918 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
1929 if (intel_pt_skip_event(pt)) in intel_pt_synth_psb_sample()
1932 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
1944 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
1955 if (intel_pt_skip_event(pt)) in intel_pt_synth_mwait_sample()
1958 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
1969 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
1980 if (intel_pt_skip_event(pt)) in intel_pt_synth_pwre_sample()
1983 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
1994 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
2005 if (intel_pt_skip_event(pt)) in intel_pt_synth_exstop_sample()
2008 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
2019 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
2030 if (intel_pt_skip_event(pt)) in intel_pt_synth_pwrx_sample()
2033 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
2044 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_pwrx_sample()
2045 pt->pwr_events_sample_type); in intel_pt_synth_pwrx_sample()
2180 struct intel_pt *pt = ptq->pt; in intel_pt_do_synth_pebs_sample() local
2185 if (intel_pt_skip_event(pt)) in intel_pt_do_synth_pebs_sample()
2215 else if (!pt->timeless_decoding) 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()
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()
2250 } else if (pt->synth_opts.last_branch) { in intel_pt_do_synth_pebs_sample()
2253 pt->br_stack_sz); in intel_pt_do_synth_pebs_sample()
2304 return intel_pt_deliver_synth_event(pt, event, &sample, sample_type); in intel_pt_do_synth_pebs_sample()
2309 struct intel_pt *pt = ptq->pt; in intel_pt_synth_single_pebs_sample() local
2310 struct evsel *evsel = pt->pebs_evsel; in intel_pt_synth_single_pebs_sample()
2320 struct intel_pt *pt = ptq->pt; in intel_pt_synth_pebs_sample() local
2325 if (!pt->single_pebs) in intel_pt_synth_pebs_sample()
2333 if (!pt->single_pebs) in intel_pt_synth_pebs_sample()
2348 struct intel_pt *pt = ptq->pt; in intel_pt_synth_events_sample() local
2357 if (intel_pt_skip_event(pt)) in intel_pt_synth_events_sample()
2360 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
2381 return intel_pt_deliver_synth_event(pt, event, &sample, 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() local
2392 if (intel_pt_skip_event(pt)) in intel_pt_synth_iflag_chg_sample()
2395 intel_pt_prep_p_sample(pt, ptq, event, &sample); 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()
2414 return intel_pt_deliver_synth_event(pt, event, &sample, in intel_pt_synth_iflag_chg_sample()
2415 pt->iflag_chg_sample_type); in intel_pt_synth_iflag_chg_sample()
2418 static int intel_pt_synth_error(struct intel_pt *pt, int code, int cpu, 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()
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() local
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()
2480 return intel_pt_synth_error(pt, state->err, ptq->cpu, pid, tid, in intel_ptq_synth_error()
2484 static int intel_pt_next_tid(struct intel_pt *pt, struct intel_pt_queue *ptq) in intel_pt_next_tid() argument
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()
2498 intel_pt_set_pid_tid_cpu(pt, queue); in intel_pt_next_tid()
2507 struct intel_pt *pt = ptq->pt; in intel_pt_is_switch_ip() local
2509 return ip == pt->switch_ip && in intel_pt_is_switch_ip()
2521 struct intel_pt *pt = ptq->pt; in intel_pt_sample() local
2529 if (pt->synth_opts.approx_ipc) { 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()
2566 if (pt->sample_pwr_events) { 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()
2622 if (pt->use_thread_stack) { 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()
2632 if (pt->sample_branches) { in intel_pt_sample()
2666 err = intel_pt_next_tid(pt, ptq); in intel_pt_sample()
2680 state->to_ip == pt->ptss_ip && in intel_pt_sample()
2688 static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip) in intel_pt_switch_ip() argument
2690 struct machine *machine = pt->machine; in intel_pt_switch_ip()
2722 if (pt->have_sched_switch == 1) in intel_pt_switch_ip()
2740 static void intel_pt_enable_sync_switch(struct intel_pt *pt) in intel_pt_enable_sync_switch() argument
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()
2758 static void intel_pt_disable_sync_switch(struct intel_pt *pt) in intel_pt_disable_sync_switch() argument
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()
2770 intel_pt_next_tid(pt, ptq); in intel_pt_disable_sync_switch()
2781 struct intel_pt *pt = ptq->pt; in intel_pt_next_time() local
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()
2792 ptq->sel_timestamp = pt->time_ranges[ptq->sel_idx].start; in intel_pt_next_time()
2820 intel_pt_next_tid(ptq->pt, ptq); in intel_pt_time_filter()
2850 struct intel_pt *pt = ptq->pt; in intel_pt_run_decoder() local
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()
2864 intel_pt_enable_sync_switch(pt); in intel_pt_run_decoder()
2881 state->from_ip >= pt->kernel_start) { in intel_pt_run_decoder()
2883 intel_pt_next_tid(pt, ptq); in intel_pt_run_decoder()
2886 if (pt->synth_opts.errors) { 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()
2923 if (!pt->timeless_decoding && ptq->timestamp >= *timestamp) { in intel_pt_run_decoder()
2931 static inline int intel_pt_update_queues(struct intel_pt *pt) in intel_pt_update_queues() argument
2933 if (pt->queues.new_data) { in intel_pt_update_queues()
2934 pt->queues.new_data = false; in intel_pt_update_queues()
2935 return intel_pt_setup_queues(pt); in intel_pt_update_queues()
2940 static int intel_pt_process_queues(struct intel_pt *pt, u64 timestamp) in intel_pt_process_queues() argument
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()
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()
2974 intel_pt_set_pid_tid_cpu(pt, queue); 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()
2995 static int intel_pt_process_timeless_queues(struct intel_pt *pt, pid_t tid, in intel_pt_process_timeless_queues() argument
2998 struct auxtrace_queues *queues = &pt->queues; in intel_pt_process_timeless_queues()
3003 struct auxtrace_queue *queue = &pt->queues.queue_array[i]; in intel_pt_process_timeless_queues()
3008 intel_pt_set_pid_tid_cpu(pt, queue); in intel_pt_process_timeless_queues()
3019 struct machine *m = ptq->pt->machine; in intel_pt_sample_set_pid_tid_cpu()
3043 static int intel_pt_process_timeless_sample(struct intel_pt *pt, in intel_pt_process_timeless_sample() argument
3050 queue = auxtrace_queues__sample_queue(&pt->queues, sample, pt->session); in intel_pt_process_timeless_sample()
3065 static int intel_pt_lost(struct intel_pt *pt, struct perf_sample *sample) in intel_pt_lost() argument
3067 return intel_pt_synth_error(pt, INTEL_PT_ERR_LOST, sample->cpu, in intel_pt_lost()
3072 static struct intel_pt_queue *intel_pt_cpu_to_ptq(struct intel_pt *pt, int cpu) in intel_pt_cpu_to_ptq() argument
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()
3100 static int intel_pt_sync_switch(struct intel_pt *pt, int cpu, pid_t tid, in intel_pt_sync_switch() argument
3106 if (!pt->sync_switch) in intel_pt_sync_switch()
3109 ptq = intel_pt_cpu_to_ptq(pt, cpu); 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()
3145 static int intel_pt_process_switch(struct intel_pt *pt, in intel_pt_process_switch() argument
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()
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()
3169 static int intel_pt_context_switch_in(struct intel_pt *pt, in intel_pt_context_switch_in() argument
3176 if (pt->sync_switch) { in intel_pt_context_switch_in()
3179 ptq = intel_pt_cpu_to_ptq(pt, cpu); 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()
3207 static int intel_pt_guest_context_switch(struct intel_pt *pt, in intel_pt_guest_context_switch() argument
3212 struct machines *machines = &pt->session->machines; 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()
3223 intel_pt_disable_sync_switch(pt); in intel_pt_guest_context_switch()
3234 static int intel_pt_context_switch(struct intel_pt *pt, union perf_event *event, in intel_pt_context_switch() argument
3242 return intel_pt_guest_context_switch(pt, event, sample); in intel_pt_context_switch()
3246 if (pt->have_sched_switch == 3) { in intel_pt_context_switch()
3248 return intel_pt_context_switch_in(pt, sample); 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()
3272 static int intel_pt_process_itrace_start(struct intel_pt *pt, in intel_pt_process_itrace_start() argument
3276 if (!pt->per_cpu_mmaps) 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()
3289 static int intel_pt_process_aux_output_hw_id(struct intel_pt *pt, in intel_pt_process_aux_output_hw_id() argument
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()
3325 static int intel_pt_text_poke(struct intel_pt *pt, union perf_event *event) in intel_pt_text_poke() argument
3331 struct thread *thread = pt->unknown_thread; in intel_pt_text_poke()
3333 struct machine *machine = pt->machine; in intel_pt_text_poke()
3379 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_process_event() local
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()
3398 err = intel_pt_update_queues(pt); 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()
3406 err = intel_pt_process_timeless_sample(pt, in intel_pt_process_event()
3409 err = intel_pt_process_timeless_queues(pt, in intel_pt_process_event()
3414 if (!pt->first_timestamp) in intel_pt_process_event()
3415 intel_pt_first_timestamp(pt, timestamp); in intel_pt_process_event()
3416 err = intel_pt_process_queues(pt, timestamp); in intel_pt_process_event()
3422 if (pt->synth_opts.add_callchain && !sample->callchain) in intel_pt_process_event()
3423 intel_pt_add_callchain(pt, sample); in intel_pt_process_event()
3424 if (pt->synth_opts.add_last_branch && !sample->branch_stack) in intel_pt_process_event()
3425 intel_pt_add_br_stack(pt, sample); in intel_pt_process_event()
3430 pt->synth_opts.errors) { in intel_pt_process_event()
3431 err = intel_pt_lost(pt, sample); in intel_pt_process_event()
3436 if (pt->switch_evsel && event->header.type == PERF_RECORD_SAMPLE) in intel_pt_process_event()
3437 err = intel_pt_process_switch(pt, sample); in intel_pt_process_event()
3439 err = intel_pt_process_itrace_start(pt, event, sample); in intel_pt_process_event()
3441 err = intel_pt_process_aux_output_hw_id(pt, event, sample); in intel_pt_process_event()
3444 err = intel_pt_context_switch(pt, event, sample); in intel_pt_process_event()
3447 err = intel_pt_text_poke(pt, event); in intel_pt_process_event()
3449 if (intel_pt_enable_logging && intel_pt_log_events(pt, sample->time)) { in intel_pt_process_event()
3460 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_flush() local
3470 ret = intel_pt_update_queues(pt); 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()
3478 return intel_pt_process_queues(pt, MAX_TIMESTAMP); in intel_pt_flush()
3483 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_free_events() local
3485 struct auxtrace_queues *queues = &pt->queues; in intel_pt_free_events()
3498 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_free() local
3501 auxtrace_heap__free(&pt->heap); in intel_pt_free()
3504 intel_pt_free_vmcs_info(pt); 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()
3510 free(pt); in intel_pt_free()
3516 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_evsel_is_auxtrace() local
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() local
3529 if (!pt->data_queued) { 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()
3565 struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, in intel_pt_queue_data() local
3570 return auxtrace_queues__add_event(&pt->queues, session, event, 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()
3636 static struct evsel *intel_pt_evsel(struct intel_pt *pt, in intel_pt_evsel() argument
3642 if (evsel->core.attr.type == pt->pmu_type && evsel->core.ids) in intel_pt_evsel()
3649 static int intel_pt_synth_events(struct intel_pt *pt, in intel_pt_synth_events() argument
3653 struct evsel *evsel = intel_pt_evsel(pt, evlist); 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()
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()
3839 static void intel_pt_setup_pebs_events(struct intel_pt *pt) in intel_pt_setup_pebs_events() argument
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()
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()
3887 struct intel_pt *pt = data; in intel_pt_perf_config() local
3890 pt->mispred_all = perf_config_bool(var, value); in intel_pt_perf_config()
3893 perf_config_int(&pt->max_loops, var, value); in intel_pt_perf_config()
3899 static u64 intel_pt_tsc_start(u64 ns, struct intel_pt *pt) in intel_pt_tsc_start() argument
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()
3913 tm = tsc_to_perf_time(++tsc, &pt->tc); in intel_pt_tsc_start()
3919 static u64 intel_pt_tsc_end(u64 ns, struct intel_pt *pt) in intel_pt_tsc_end() argument
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()
3938 static int intel_pt_setup_time_ranges(struct intel_pt *pt, in intel_pt_setup_time_ranges() argument
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()
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()
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()
3977 static int intel_pt_parse_vm_tm_corr_arg(struct intel_pt *pt, char **args) in intel_pt_parse_vm_tm_corr_arg() argument
3994 pt->dflt_tsc_offset = tsc_offset; 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()
4017 static int intel_pt_parse_vm_tm_corr_args(struct intel_pt *pt) in intel_pt_parse_vm_tm_corr_args() argument
4019 char *args = pt->synth_opts.vm_tm_corr_args; in intel_pt_parse_vm_tm_corr_args()
4026 ret = intel_pt_parse_vm_tm_corr_arg(pt, &args); in intel_pt_parse_vm_tm_corr_args()
4091 struct intel_pt *pt; in intel_pt_process_auxtrace_info() local
4100 pt = zalloc(sizeof(struct intel_pt)); in intel_pt_process_auxtrace_info()
4101 if (!pt) 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()
4108 err = perf_config(intel_pt_perf_config, pt); in intel_pt_process_auxtrace_info()
4112 err = auxtrace_queues__init(&pt->queues); in intel_pt_process_auxtrace_info()
4117 pt->synth_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()
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()
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()
4160 pt->max_non_turbo_ratio = 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()
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()
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()
4233 if (!intel_pt_have_mtc(pt)) { in intel_pt_process_auxtrace_info()
4238 err = intel_pt_parse_vm_tm_corr_args(pt); 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()
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()
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()
4285 } else if (pt->have_sched_switch == 2 && 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()
4300 if (pt->tc.time_mult) { in intel_pt_process_auxtrace_info()
4301 u64 tsc_freq = intel_pt_ns_to_ticks(pt, 1000000000); 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()
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()
4334 err = intel_pt_callchain_init(pt); 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()
4345 err = intel_pt_br_stack_init(pt); in intel_pt_process_auxtrace_info()
4355 if (intel_pt_tracing_kernel(pt)) 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()
4371 err = intel_pt_synth_events(pt, session); in intel_pt_process_auxtrace_info()
4375 intel_pt_setup_pebs_events(pt); 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()
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()
4403 free(pt); in intel_pt_process_auxtrace_info()