Skip to content

Commit 2f7ebf2

Browse files
Andi KleenIngo Molnar
authored andcommitted
perf/x86/intel: Add support for PEBSv3 profiling
PEBSv3 is the same as the existing PEBSv2 used on Haswell, but it adds a new TSC field. Add support to the generic PEBS handler to handle the new format, and overwrite the perf time stamp using the new native_sched_clock_from_tsc(). Right now the time stamp is just slightly more accurate, as it is nearer the actual event trigger point. With the PEBS threshold > 1 patchkit it will be much more accurate, avoid the problems with MMAP mismatches earlier. The accurate time stamping is only implemented for the default trace clock for now. v2: Use _skl prefix. Check for default clock_id. Signed-off-by: Andi Kleen <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent a94cab2 commit 2f7ebf2

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

arch/x86/kernel/cpu/perf_event_intel_ds.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ union hsw_tsx_tuning {
224224

225225
#define PEBS_HSW_TSX_FLAGS 0xff00000000ULL
226226

227+
/* Same as HSW, plus TSC */
228+
229+
struct pebs_record_skl {
230+
u64 flags, ip;
231+
u64 ax, bx, cx, dx;
232+
u64 si, di, bp, sp;
233+
u64 r8, r9, r10, r11;
234+
u64 r12, r13, r14, r15;
235+
u64 status, dla, dse, lat;
236+
u64 real_ip, tsx_tuning;
237+
u64 tsc;
238+
};
239+
227240
void init_debug_store_on_cpu(int cpu)
228241
{
229242
struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
@@ -885,7 +898,7 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
885898
return 0;
886899
}
887900

888-
static inline u64 intel_hsw_weight(struct pebs_record_hsw *pebs)
901+
static inline u64 intel_hsw_weight(struct pebs_record_skl *pebs)
889902
{
890903
if (pebs->tsx_tuning) {
891904
union hsw_tsx_tuning tsx = { .value = pebs->tsx_tuning };
@@ -894,7 +907,7 @@ static inline u64 intel_hsw_weight(struct pebs_record_hsw *pebs)
894907
return 0;
895908
}
896909

897-
static inline u64 intel_hsw_transaction(struct pebs_record_hsw *pebs)
910+
static inline u64 intel_hsw_transaction(struct pebs_record_skl *pebs)
898911
{
899912
u64 txn = (pebs->tsx_tuning & PEBS_HSW_TSX_FLAGS) >> 32;
900913

@@ -918,7 +931,7 @@ static void setup_pebs_sample_data(struct perf_event *event,
918931
* unconditionally access the 'extra' entries.
919932
*/
920933
struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
921-
struct pebs_record_hsw *pebs = __pebs;
934+
struct pebs_record_skl *pebs = __pebs;
922935
u64 sample_type;
923936
int fll, fst, dsrc;
924937
int fl = event->hw.flags;
@@ -1016,6 +1029,16 @@ static void setup_pebs_sample_data(struct perf_event *event,
10161029
data->txn = intel_hsw_transaction(pebs);
10171030
}
10181031

1032+
/*
1033+
* v3 supplies an accurate time stamp, so we use that
1034+
* for the time stamp.
1035+
*
1036+
* We can only do this for the default trace clock.
1037+
*/
1038+
if (x86_pmu.intel_cap.pebs_format >= 3 &&
1039+
event->attr.use_clockid == 0)
1040+
data->time = native_sched_clock_from_tsc(pebs->tsc);
1041+
10191042
if (has_branch_stack(event))
10201043
data->br_stack = &cpuc->lbr_stack;
10211044
}
@@ -1245,6 +1268,13 @@ void __init intel_ds_init(void)
12451268
x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
12461269
break;
12471270

1271+
case 3:
1272+
pr_cont("PEBS fmt3%c, ", pebs_type);
1273+
x86_pmu.pebs_record_size =
1274+
sizeof(struct pebs_record_skl);
1275+
x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
1276+
break;
1277+
12481278
default:
12491279
printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type);
12501280
x86_pmu.pebs = 0;

0 commit comments

Comments
 (0)