Skip to content

Commit 5b1dc0f

Browse files
ahunter6acmel
authored andcommitted
perf intel-pt: Add support for samples to contain IPC ratio
Copy the incremental instruction count and cycle count onto 'instructions' and 'branches' samples. Because Intel PT does not update the cycle count on every branch or instruction, the incremental values will often be zero. When there are values, they will be the number of instructions and number of cycles since the last update, and thus represent the average IPC since the last IPC value. Signed-off-by: Adrian Hunter <[email protected]> Cc: Jiri Olsa <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 61d276f commit 5b1dc0f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tools/perf/util/intel-pt.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ struct intel_pt_queue {
157157
u32 flags;
158158
u16 insn_len;
159159
u64 last_insn_cnt;
160+
u64 ipc_insn_cnt;
161+
u64 ipc_cyc_cnt;
162+
u64 last_in_insn_cnt;
163+
u64 last_in_cyc_cnt;
164+
u64 last_br_insn_cnt;
165+
u64 last_br_cyc_cnt;
160166
char insn[INTEL_PT_INSN_BUF_SZ];
161167
};
162168

@@ -1162,6 +1168,13 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq)
11621168
sample.branch_stack = (struct branch_stack *)&dummy_bs;
11631169
}
11641170

1171+
sample.cyc_cnt = ptq->ipc_cyc_cnt - ptq->last_br_cyc_cnt;
1172+
if (sample.cyc_cnt) {
1173+
sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_br_insn_cnt;
1174+
ptq->last_br_insn_cnt = ptq->ipc_insn_cnt;
1175+
ptq->last_br_cyc_cnt = ptq->ipc_cyc_cnt;
1176+
}
1177+
11651178
return intel_pt_deliver_synth_b_event(pt, event, &sample,
11661179
pt->branches_sample_type);
11671180
}
@@ -1217,6 +1230,13 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq)
12171230
sample.stream_id = ptq->pt->instructions_id;
12181231
sample.period = ptq->state->tot_insn_cnt - ptq->last_insn_cnt;
12191232

1233+
sample.cyc_cnt = ptq->ipc_cyc_cnt - ptq->last_in_cyc_cnt;
1234+
if (sample.cyc_cnt) {
1235+
sample.insn_cnt = ptq->ipc_insn_cnt - ptq->last_in_insn_cnt;
1236+
ptq->last_in_insn_cnt = ptq->ipc_insn_cnt;
1237+
ptq->last_in_cyc_cnt = ptq->ipc_cyc_cnt;
1238+
}
1239+
12201240
ptq->last_insn_cnt = ptq->state->tot_insn_cnt;
12211241

12221242
return intel_pt_deliver_synth_event(pt, ptq, event, &sample,
@@ -1488,6 +1508,15 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
14881508

14891509
ptq->have_sample = false;
14901510

1511+
if (ptq->state->tot_cyc_cnt > ptq->ipc_cyc_cnt) {
1512+
/*
1513+
* Cycle count and instruction count only go together to create
1514+
* a valid IPC ratio when the cycle count changes.
1515+
*/
1516+
ptq->ipc_insn_cnt = ptq->state->tot_insn_cnt;
1517+
ptq->ipc_cyc_cnt = ptq->state->tot_cyc_cnt;
1518+
}
1519+
14911520
if (pt->sample_pwr_events && (state->type & INTEL_PT_PWR_EVT)) {
14921521
if (state->type & INTEL_PT_CBR_CHG) {
14931522
err = intel_pt_synth_cbr_sample(ptq);

0 commit comments

Comments
 (0)