diff options
Diffstat (limited to 'tools/perf/util/intel-pt.c')
-rw-r--r-- | tools/perf/util/intel-pt.c | 110 |
1 files changed, 47 insertions, 63 deletions
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 3773d9c54f45..0effaff57020 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -132,6 +132,7 @@ struct intel_pt_queue { struct intel_pt *pt; unsigned int queue_nr; struct auxtrace_buffer *buffer; + struct auxtrace_buffer *old_buffer; void *decoder; const struct intel_pt_state *state; struct ip_callchain *chain; @@ -143,6 +144,7 @@ struct intel_pt_queue { bool stop; bool step_through_buffers; bool use_buffer_pid_tid; + bool sync_switch; pid_t pid, tid; int cpu; int switch_state; @@ -207,49 +209,28 @@ static void intel_pt_dump_event(struct intel_pt *pt, unsigned char *buf, static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *a, struct auxtrace_buffer *b) { + bool consecutive = false; void *start; start = intel_pt_find_overlap(a->data, a->size, b->data, b->size, - pt->have_tsc); + pt->have_tsc, &consecutive); if (!start) return -EINVAL; b->use_size = b->data + b->size - start; b->use_data = start; + if (b->use_size && consecutive) + b->consecutive = true; return 0; } -static void intel_pt_use_buffer_pid_tid(struct intel_pt_queue *ptq, - struct auxtrace_queue *queue, - struct auxtrace_buffer *buffer) -{ - if (queue->cpu == -1 && buffer->cpu != -1) - ptq->cpu = buffer->cpu; - - ptq->pid = buffer->pid; - ptq->tid = buffer->tid; - - intel_pt_log("queue %u cpu %d pid %d tid %d\n", - ptq->queue_nr, ptq->cpu, ptq->pid, ptq->tid); - - thread__zput(ptq->thread); - - if (ptq->tid != -1) { - if (ptq->pid != -1) - ptq->thread = machine__findnew_thread(ptq->pt->machine, - ptq->pid, - ptq->tid); - else - ptq->thread = machine__find_thread(ptq->pt->machine, -1, - ptq->tid); - } -} - /* This function assumes data is processed sequentially only */ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) { struct intel_pt_queue *ptq = data; - struct auxtrace_buffer *buffer = ptq->buffer, *old_buffer = buffer; + struct auxtrace_buffer *buffer = ptq->buffer; + struct auxtrace_buffer *old_buffer = ptq->old_buffer; struct auxtrace_queue *queue; + bool might_overlap; if (ptq->stop) { b->len = 0; @@ -257,7 +238,7 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data) } queue = &ptq->pt->queues.queue_array[ptq->queue_nr]; -next: + buffer = auxtrace_buffer__next(queue, buffer); if (!buffer) { if (old_buffer) @@ -276,7 +257,8 @@ next: return -ENOMEM; } - if (ptq->pt->snapshot_mode && !buffer->consecutive && old_buffer && + might_overlap = ptq->pt->snapshot_mode || ptq->pt->sampling_mode; + if (might_overlap && !buffer->consecutive && old_buffer && intel_pt_do_fix_overlap(ptq->pt, old_buffer, buffer)) return -ENOMEM; @@ -289,33 +271,24 @@ next: } b->ref_timestamp = buffer->reference; - /* - * If in snapshot mode and the buffer has no usable data, get next - * buffer and again check overlap against old_buffer. - */ - if (ptq->pt->snapshot_mode && !b->len) - goto next; - - if (old_buffer) - auxtrace_buffer__drop_data(old_buffer); - - if (!old_buffer || ptq->pt->sampling_mode || (ptq->pt->snapshot_mode && - !buffer->consecutive)) { + if (!old_buffer || (might_overlap && !buffer->consecutive)) { b->consecutive = false; b->trace_nr = buffer->buffer_nr + 1; } else { b->consecutive = true; } - if (ptq->use_buffer_pid_tid && (ptq->pid != buffer->pid || - ptq->tid != buffer->tid)) - intel_pt_use_buffer_pid_tid(ptq, queue, buffer); - if (ptq->step_through_buffers) ptq->stop = true; - if (!b->len) + if (b->len) { + if (old_buffer) + auxtrace_buffer__drop_data(old_buffer); + ptq->old_buffer = buffer; + } else { + auxtrace_buffer__drop_data(buffer); return intel_pt_get_trace(b, data); + } return 0; } @@ -954,16 +927,15 @@ static int intel_pt_setup_queue(struct intel_pt *pt, ptq->cpu = queue->cpu; ptq->tid = queue->tid; - if (pt->sampling_mode) { - if (pt->timeless_decoding) - ptq->step_through_buffers = true; - if (pt->timeless_decoding || !pt->have_sched_switch) - ptq->use_buffer_pid_tid = true; - } + if (pt->sampling_mode && !pt->snapshot_mode && + pt->timeless_decoding) + ptq->step_through_buffers = true; + + ptq->sync_switch = pt->sync_switch; } if (!ptq->on_heap && - (!pt->sync_switch || + (!ptq->sync_switch || ptq->switch_state != INTEL_PT_SS_EXPECTING_SWITCH_EVENT)) { const struct intel_pt_state *state; int ret; @@ -1546,7 +1518,7 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) if (pt->synth_opts.last_branch) intel_pt_update_last_branch_rb(ptq); - if (!pt->sync_switch) + if (!ptq->sync_switch) return 0; if (intel_pt_is_switch_ip(ptq, state->to_ip)) { @@ -1627,6 +1599,21 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip) return switch_ip; } +static void intel_pt_enable_sync_switch(struct intel_pt *pt) +{ + unsigned int i; + + pt->sync_switch = true; + + for (i = 0; i < pt->queues.nr_queues; i++) { + struct auxtrace_queue *queue = &pt->queues.queue_array[i]; + struct intel_pt_queue *ptq = queue->priv; + + if (ptq) + ptq->sync_switch = true; + } +} + static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) { const struct intel_pt_state *state = ptq->state; @@ -1643,7 +1630,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) if (pt->switch_ip) { intel_pt_log("switch_ip: %"PRIx64" ptss_ip: %"PRIx64"\n", pt->switch_ip, pt->ptss_ip); - pt->sync_switch = true; + intel_pt_enable_sync_switch(pt); } } } @@ -1659,9 +1646,9 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) if (state->err) { if (state->err == INTEL_PT_ERR_NODATA) return 1; - if (pt->sync_switch && + if (ptq->sync_switch && state->from_ip >= pt->kernel_start) { - pt->sync_switch = false; + ptq->sync_switch = false; intel_pt_next_tid(pt, ptq); } if (pt->synth_opts.errors) { @@ -1687,7 +1674,7 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) state->timestamp, state->est_timestamp); ptq->timestamp = state->est_timestamp; /* Use estimated TSC in unknown switch state */ - } else if (pt->sync_switch && + } else if (ptq->sync_switch && ptq->switch_state == INTEL_PT_SS_UNKNOWN && intel_pt_is_switch_ip(ptq, state->to_ip) && ptq->next_tid == -1) { @@ -1834,7 +1821,7 @@ static int intel_pt_sync_switch(struct intel_pt *pt, int cpu, pid_t tid, return 1; ptq = intel_pt_cpu_to_ptq(pt, cpu); - if (!ptq) + if (!ptq || !ptq->sync_switch) return 1; switch (ptq->switch_state) { @@ -2075,9 +2062,6 @@ static int intel_pt_process_auxtrace_event(struct perf_session *session, struct intel_pt *pt = container_of(session->auxtrace, struct intel_pt, auxtrace); - if (pt->sampling_mode) - return 0; - if (!pt->data_queued) { struct auxtrace_buffer *buffer; off_t data_offset; |