Skip to content

Commit 2f7d460

Browse files
ahunter6gregkh
authored andcommitted
perf intel-pt: Fix IPC with CYC threshold
[ Upstream commit 6af4b60 ] The code assumed every CYC-eligible packet has a CYC packet, which is not the case when CYC thresholds are used. Fix by checking if a CYC packet is actually present in that case. Fixes: 5b1dc0f ("perf intel-pt: Add support for samples to contain IPC ratio") Signed-off-by: Adrian Hunter <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Cc: Jiri Olsa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 4616d95 commit 2f7d460

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
#include "intel-pt-decoder.h"
2525
#include "intel-pt-log.h"
2626

27+
#define BITULL(x) (1ULL << (x))
28+
29+
/* IA32_RTIT_CTL MSR bits */
30+
#define INTEL_PT_CYC_ENABLE BITULL(1)
31+
#define INTEL_PT_CYC_THRESHOLD (BITULL(22) | BITULL(21) | BITULL(20) | BITULL(19))
32+
#define INTEL_PT_CYC_THRESHOLD_SHIFT 19
33+
2734
#define INTEL_PT_BLK_SIZE 1024
2835

2936
#define BIT63 (((uint64_t)1 << 63))
@@ -167,6 +174,8 @@ struct intel_pt_decoder {
167174
uint64_t sample_tot_cyc_cnt;
168175
uint64_t base_cyc_cnt;
169176
uint64_t cyc_cnt_timestamp;
177+
uint64_t ctl;
178+
uint64_t cyc_threshold;
170179
double tsc_to_cyc;
171180
bool continuous_period;
172181
bool overflow;
@@ -204,6 +213,14 @@ static uint64_t intel_pt_lower_power_of_2(uint64_t x)
204213
return x << i;
205214
}
206215

216+
static uint64_t intel_pt_cyc_threshold(uint64_t ctl)
217+
{
218+
if (!(ctl & INTEL_PT_CYC_ENABLE))
219+
return 0;
220+
221+
return (ctl & INTEL_PT_CYC_THRESHOLD) >> INTEL_PT_CYC_THRESHOLD_SHIFT;
222+
}
223+
207224
static void intel_pt_setup_period(struct intel_pt_decoder *decoder)
208225
{
209226
if (decoder->period_type == INTEL_PT_PERIOD_TICKS) {
@@ -245,12 +262,15 @@ struct intel_pt_decoder *intel_pt_decoder_new(struct intel_pt_params *params)
245262

246263
decoder->flags = params->flags;
247264

265+
decoder->ctl = params->ctl;
248266
decoder->period = params->period;
249267
decoder->period_type = params->period_type;
250268

251269
decoder->max_non_turbo_ratio = params->max_non_turbo_ratio;
252270
decoder->max_non_turbo_ratio_fp = params->max_non_turbo_ratio;
253271

272+
decoder->cyc_threshold = intel_pt_cyc_threshold(decoder->ctl);
273+
254274
intel_pt_setup_period(decoder);
255275

256276
decoder->mtc_shift = params->mtc_period;
@@ -2017,6 +2037,7 @@ static int intel_pt_hop_trace(struct intel_pt_decoder *decoder, bool *no_tip, in
20172037

20182038
static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
20192039
{
2040+
int last_packet_type = INTEL_PT_PAD;
20202041
bool no_tip = false;
20212042
int err;
20222043

@@ -2025,6 +2046,12 @@ static int intel_pt_walk_trace(struct intel_pt_decoder *decoder)
20252046
if (err)
20262047
return err;
20272048
next:
2049+
if (decoder->cyc_threshold) {
2050+
if (decoder->sample_cyc && last_packet_type != INTEL_PT_CYC)
2051+
decoder->sample_cyc = false;
2052+
last_packet_type = decoder->packet.type;
2053+
}
2054+
20282055
if (decoder->hop) {
20292056
switch (intel_pt_hop_trace(decoder, &no_tip, &err)) {
20302057
case HOP_IGNORE:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ struct intel_pt_params {
244244
void *data;
245245
bool return_compression;
246246
bool branch_enable;
247+
uint64_t ctl;
247248
uint64_t period;
248249
enum intel_pt_period_type period_type;
249250
unsigned max_non_turbo_ratio;

tools/perf/util/intel-pt.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,18 @@ static bool intel_pt_sampling_mode(struct intel_pt *pt)
893893
return false;
894894
}
895895

896+
static u64 intel_pt_ctl(struct intel_pt *pt)
897+
{
898+
struct evsel *evsel;
899+
u64 config;
900+
901+
evlist__for_each_entry(pt->session->evlist, evsel) {
902+
if (intel_pt_get_config(pt, &evsel->core.attr, &config))
903+
return config;
904+
}
905+
return 0;
906+
}
907+
896908
static u64 intel_pt_ns_to_ticks(const struct intel_pt *pt, u64 ns)
897909
{
898910
u64 quot, rem;
@@ -1026,6 +1038,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt,
10261038
params.data = ptq;
10271039
params.return_compression = intel_pt_return_compression(pt);
10281040
params.branch_enable = intel_pt_branch_enable(pt);
1041+
params.ctl = intel_pt_ctl(pt);
10291042
params.max_non_turbo_ratio = pt->max_non_turbo_ratio;
10301043
params.mtc_period = intel_pt_mtc_period(pt);
10311044
params.tsc_ctc_ratio_n = pt->tsc_ctc_ratio_n;

0 commit comments

Comments
 (0)