Skip to content

Commit 7b4b4f8

Browse files
ahunter6acmel
authored andcommitted
perf intel-pt: Accumulate cycle count from CYC packets
In preparation for providing instructions-per-cycle (IPC) information, accumulate cycle count from CYC packets. Although CYC packets are optional (requires config term 'cyc' to enable cycle-accurate mode when recording), the simplest way to count cycles is with CYC packets. The first complication is that cycles must be counted only when also counting instructions. That means when control flow packet generation is enabled i.e. between TIP.PGE and TIP.PGD packets. Also, sampling the cycle count follows the same rules as sampling the timestamp, that is, not before the instruction to which the decoder is walking is reached. In addition, the cycle count is not accurate for any but the first branch of a TNT packet. 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 948e9dc commit 7b4b4f8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tools/perf/util/intel-pt-decoder/intel-pt-decoder.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,16 @@ struct intel_pt_decoder {
160160
uint64_t period_mask;
161161
uint64_t period_ticks;
162162
uint64_t last_masked_timestamp;
163+
uint64_t tot_cyc_cnt;
164+
uint64_t sample_tot_cyc_cnt;
163165
bool continuous_period;
164166
bool overflow;
165167
bool set_fup_tx_flags;
166168
bool set_fup_ptw;
167169
bool set_fup_mwait;
168170
bool set_fup_pwre;
169171
bool set_fup_exstop;
172+
bool sample_cyc;
170173
unsigned int fup_tx_flags;
171174
unsigned int tx_flags;
172175
uint64_t fup_ptw_payload;
@@ -1323,6 +1326,7 @@ static int intel_pt_walk_tnt(struct intel_pt_decoder *decoder)
13231326
decoder->ip += intel_pt_insn.length;
13241327
return 0;
13251328
}
1329+
decoder->sample_cyc = false;
13261330
decoder->ip += intel_pt_insn.length;
13271331
if (!decoder->tnt.count) {
13281332
intel_pt_update_sample_time(decoder);
@@ -1515,6 +1519,9 @@ static void intel_pt_calc_cyc_timestamp(struct intel_pt_decoder *decoder)
15151519
decoder->have_cyc = true;
15161520

15171521
decoder->cycle_cnt += decoder->packet.payload;
1522+
if (decoder->pge)
1523+
decoder->tot_cyc_cnt += decoder->packet.payload;
1524+
decoder->sample_cyc = true;
15181525

15191526
if (!decoder->cyc_ref_timestamp)
15201527
return;
@@ -2419,21 +2426,26 @@ const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder)
24192426
decoder->state.err = intel_pt_ext_err(err);
24202427
decoder->state.from_ip = decoder->ip;
24212428
intel_pt_update_sample_time(decoder);
2429+
decoder->sample_tot_cyc_cnt = decoder->tot_cyc_cnt;
24222430
} else {
24232431
decoder->state.err = 0;
24242432
if (decoder->cbr != decoder->cbr_seen && decoder->state.type) {
24252433
decoder->cbr_seen = decoder->cbr;
24262434
decoder->state.type |= INTEL_PT_CBR_CHG;
24272435
decoder->state.cbr_payload = decoder->cbr_payload;
24282436
}
2429-
if (intel_pt_sample_time(decoder->pkt_state))
2437+
if (intel_pt_sample_time(decoder->pkt_state)) {
24302438
intel_pt_update_sample_time(decoder);
2439+
if (decoder->sample_cyc)
2440+
decoder->sample_tot_cyc_cnt = decoder->tot_cyc_cnt;
2441+
}
24312442
}
24322443

24332444
decoder->state.timestamp = decoder->sample_timestamp;
24342445
decoder->state.est_timestamp = intel_pt_est_timestamp(decoder);
24352446
decoder->state.cr3 = decoder->cr3;
24362447
decoder->state.tot_insn_cnt = decoder->tot_insn_cnt;
2448+
decoder->state.tot_cyc_cnt = decoder->sample_tot_cyc_cnt;
24372449

24382450
return &decoder->state;
24392451
}

tools/perf/util/intel-pt-decoder/intel-pt-decoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct intel_pt_state {
7777
uint64_t to_ip;
7878
uint64_t cr3;
7979
uint64_t tot_insn_cnt;
80+
uint64_t tot_cyc_cnt;
8081
uint64_t timestamp;
8182
uint64_t est_timestamp;
8283
uint64_t trace_nr;

0 commit comments

Comments
 (0)