Skip to content

Commit 48f38aa

Browse files
Andi KleenIngo Molnar
authored andcommitted
perf/x86/intel: Extract memory code PEBS parser for reuse
Extract some code related to memory profiling from the PEBS record parser into separate functions. It can be reused by the upcoming adaptive PEBS parser. No functional changes. Rename intel_hsw_weight to intel_get_tsx_weight, and intel_hsw_transaction to intel_get_tsx_transaction. Because the input is not the hsw pebs format anymore. Signed-off-by: Andi Kleen <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vince Weaver <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 878068e commit 48f38aa

File tree

1 file changed

+34
-29
lines changed
  • arch/x86/events/intel

1 file changed

+34
-29
lines changed

arch/x86/events/intel/ds.c

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,52 +1125,64 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
11251125
return 0;
11261126
}
11271127

1128-
static inline u64 intel_hsw_weight(struct pebs_record_skl *pebs)
1128+
static inline u64 intel_get_tsx_weight(u64 tsx_tuning)
11291129
{
1130-
if (pebs->tsx_tuning) {
1131-
union hsw_tsx_tuning tsx = { .value = pebs->tsx_tuning };
1130+
if (tsx_tuning) {
1131+
union hsw_tsx_tuning tsx = { .value = tsx_tuning };
11321132
return tsx.cycles_last_block;
11331133
}
11341134
return 0;
11351135
}
11361136

1137-
static inline u64 intel_hsw_transaction(struct pebs_record_skl *pebs)
1137+
static inline u64 intel_get_tsx_transaction(u64 tsx_tuning, u64 ax)
11381138
{
1139-
u64 txn = (pebs->tsx_tuning & PEBS_HSW_TSX_FLAGS) >> 32;
1139+
u64 txn = (tsx_tuning & PEBS_HSW_TSX_FLAGS) >> 32;
11401140

11411141
/* For RTM XABORTs also log the abort code from AX */
1142-
if ((txn & PERF_TXN_TRANSACTION) && (pebs->ax & 1))
1143-
txn |= ((pebs->ax >> 24) & 0xff) << PERF_TXN_ABORT_SHIFT;
1142+
if ((txn & PERF_TXN_TRANSACTION) && (ax & 1))
1143+
txn |= ((ax >> 24) & 0xff) << PERF_TXN_ABORT_SHIFT;
11441144
return txn;
11451145
}
11461146

1147+
#define PERF_X86_EVENT_PEBS_HSW_PREC \
1148+
(PERF_X86_EVENT_PEBS_ST_HSW | \
1149+
PERF_X86_EVENT_PEBS_LD_HSW | \
1150+
PERF_X86_EVENT_PEBS_NA_HSW)
1151+
1152+
static u64 get_data_src(struct perf_event *event, u64 aux)
1153+
{
1154+
u64 val = PERF_MEM_NA;
1155+
int fl = event->hw.flags;
1156+
bool fst = fl & (PERF_X86_EVENT_PEBS_ST | PERF_X86_EVENT_PEBS_HSW_PREC);
1157+
1158+
if (fl & PERF_X86_EVENT_PEBS_LDLAT)
1159+
val = load_latency_data(aux);
1160+
else if (fst && (fl & PERF_X86_EVENT_PEBS_HSW_PREC))
1161+
val = precise_datala_hsw(event, aux);
1162+
else if (fst)
1163+
val = precise_store_data(aux);
1164+
return val;
1165+
}
1166+
11471167
static void setup_pebs_sample_data(struct perf_event *event,
11481168
struct pt_regs *iregs, void *__pebs,
11491169
struct perf_sample_data *data,
11501170
struct pt_regs *regs)
11511171
{
1152-
#define PERF_X86_EVENT_PEBS_HSW_PREC \
1153-
(PERF_X86_EVENT_PEBS_ST_HSW | \
1154-
PERF_X86_EVENT_PEBS_LD_HSW | \
1155-
PERF_X86_EVENT_PEBS_NA_HSW)
11561172
/*
11571173
* We cast to the biggest pebs_record but are careful not to
11581174
* unconditionally access the 'extra' entries.
11591175
*/
11601176
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
11611177
struct pebs_record_skl *pebs = __pebs;
11621178
u64 sample_type;
1163-
int fll, fst, dsrc;
1164-
int fl = event->hw.flags;
1179+
int fll;
11651180

11661181
if (pebs == NULL)
11671182
return;
11681183

11691184
sample_type = event->attr.sample_type;
1170-
dsrc = sample_type & PERF_SAMPLE_DATA_SRC;
1171-
1172-
fll = fl & PERF_X86_EVENT_PEBS_LDLAT;
1173-
fst = fl & (PERF_X86_EVENT_PEBS_ST | PERF_X86_EVENT_PEBS_HSW_PREC);
1185+
fll = event->hw.flags & PERF_X86_EVENT_PEBS_LDLAT;
11741186

11751187
perf_sample_data_init(data, 0, event->hw.last_period);
11761188

@@ -1185,16 +1197,8 @@ static void setup_pebs_sample_data(struct perf_event *event,
11851197
/*
11861198
* data.data_src encodes the data source
11871199
*/
1188-
if (dsrc) {
1189-
u64 val = PERF_MEM_NA;
1190-
if (fll)
1191-
val = load_latency_data(pebs->dse);
1192-
else if (fst && (fl & PERF_X86_EVENT_PEBS_HSW_PREC))
1193-
val = precise_datala_hsw(event, pebs->dse);
1194-
else if (fst)
1195-
val = precise_store_data(pebs->dse);
1196-
data->data_src.val = val;
1197-
}
1200+
if (sample_type & PERF_SAMPLE_DATA_SRC)
1201+
data->data_src.val = get_data_src(event, pebs->dse);
11981202

11991203
/*
12001204
* We must however always use iregs for the unwinder to stay sane; the
@@ -1281,10 +1285,11 @@ static void setup_pebs_sample_data(struct perf_event *event,
12811285
if (x86_pmu.intel_cap.pebs_format >= 2) {
12821286
/* Only set the TSX weight when no memory weight. */
12831287
if ((sample_type & PERF_SAMPLE_WEIGHT) && !fll)
1284-
data->weight = intel_hsw_weight(pebs);
1288+
data->weight = intel_get_tsx_weight(pebs->tsx_tuning);
12851289

12861290
if (sample_type & PERF_SAMPLE_TRANSACTION)
1287-
data->txn = intel_hsw_transaction(pebs);
1291+
data->txn = intel_get_tsx_transaction(pebs->tsx_tuning,
1292+
pebs->ax);
12881293
}
12891294

12901295
/*

0 commit comments

Comments
 (0)