Skip to content

Commit b1bf72d

Browse files
virtuosoIngo Molnar
authored andcommitted
perf/x86/intel/pt: Add new timing packet enables
Intel PT chapter in the new Intel Architecture SDM adds several packets corresponding enable bits and registers that control packet generation. Also, additional bits in the Intel PT CPUID leaf were added to enumerate presence and parameters of these new packets and features. The packets and enables are: * CYC: cycle accurate mode, provides the number of cycles elapsed since previous CYC packet; its presence and available threshold values are enumerated via CPUID; * MTC: mini time counter packets, used for tracking TSC time between full TSC packets; its presence and available resolution options are enumerated via CPUID; * PSB packet period is now configurable, available period values are enumerated via CPUID. This patch adds corresponding bit and register definitions, pmu driver capabilities based on CPUID enumeration, new attribute format bits for the new featurens and extends event configuration validation function to take these into account. Signed-off-by: Alexander Shishkin <[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] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/1438262131-12725-1-git-send-email-alexander.shishkin@linux.intel.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent 9a6694c commit b1bf72d

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,21 @@
8080

8181
#define MSR_IA32_RTIT_CTL 0x00000570
8282
#define RTIT_CTL_TRACEEN BIT(0)
83+
#define RTIT_CTL_CYCLEACC BIT(1)
8384
#define RTIT_CTL_OS BIT(2)
8485
#define RTIT_CTL_USR BIT(3)
8586
#define RTIT_CTL_CR3EN BIT(7)
8687
#define RTIT_CTL_TOPA BIT(8)
88+
#define RTIT_CTL_MTC_EN BIT(9)
8789
#define RTIT_CTL_TSC_EN BIT(10)
8890
#define RTIT_CTL_DISRETC BIT(11)
8991
#define RTIT_CTL_BRANCH_EN BIT(13)
92+
#define RTIT_CTL_MTC_RANGE_OFFSET 14
93+
#define RTIT_CTL_MTC_RANGE (0x0full << RTIT_CTL_MTC_RANGE_OFFSET)
94+
#define RTIT_CTL_CYC_THRESH_OFFSET 19
95+
#define RTIT_CTL_CYC_THRESH (0x0full << RTIT_CTL_CYC_THRESH_OFFSET)
96+
#define RTIT_CTL_PSB_FREQ_OFFSET 24
97+
#define RTIT_CTL_PSB_FREQ (0x0full << RTIT_CTL_PSB_FREQ_OFFSET)
9098
#define MSR_IA32_RTIT_STATUS 0x00000571
9199
#define RTIT_STATUS_CONTEXTEN BIT(1)
92100
#define RTIT_STATUS_TRIGGEREN BIT(2)

arch/x86/kernel/cpu/intel_pt.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ struct topa_entry {
7272
enum pt_capabilities {
7373
PT_CAP_max_subleaf = 0,
7474
PT_CAP_cr3_filtering,
75+
PT_CAP_psb_cyc,
76+
PT_CAP_mtc,
7577
PT_CAP_topa_output,
7678
PT_CAP_topa_multiple_entries,
79+
PT_CAP_single_range_output,
7780
PT_CAP_payloads_lip,
81+
PT_CAP_mtc_periods,
82+
PT_CAP_cycle_thresholds,
83+
PT_CAP_psb_periods,
7884
};
7985

8086
struct pt_pmu {

arch/x86/kernel/cpu/perf_event_intel_pt.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ static struct pt_cap_desc {
6565
} pt_caps[] = {
6666
PT_CAP(max_subleaf, 0, CR_EAX, 0xffffffff),
6767
PT_CAP(cr3_filtering, 0, CR_EBX, BIT(0)),
68+
PT_CAP(psb_cyc, 0, CR_EBX, BIT(1)),
69+
PT_CAP(mtc, 0, CR_EBX, BIT(3)),
6870
PT_CAP(topa_output, 0, CR_ECX, BIT(0)),
6971
PT_CAP(topa_multiple_entries, 0, CR_ECX, BIT(1)),
72+
PT_CAP(single_range_output, 0, CR_ECX, BIT(2)),
7073
PT_CAP(payloads_lip, 0, CR_ECX, BIT(31)),
74+
PT_CAP(mtc_periods, 1, CR_EAX, 0xffff0000),
75+
PT_CAP(cycle_thresholds, 1, CR_EBX, 0xffff),
76+
PT_CAP(psb_periods, 1, CR_EBX, 0xffff0000),
7177
};
7278

7379
static u32 pt_cap_get(enum pt_capabilities cap)
@@ -94,12 +100,22 @@ static struct attribute_group pt_cap_group = {
94100
.name = "caps",
95101
};
96102

103+
PMU_FORMAT_ATTR(cyc, "config:1" );
104+
PMU_FORMAT_ATTR(mtc, "config:9" );
97105
PMU_FORMAT_ATTR(tsc, "config:10" );
98106
PMU_FORMAT_ATTR(noretcomp, "config:11" );
107+
PMU_FORMAT_ATTR(mtc_period, "config:14-17" );
108+
PMU_FORMAT_ATTR(cyc_thresh, "config:19-22" );
109+
PMU_FORMAT_ATTR(psb_period, "config:24-27" );
99110

100111
static struct attribute *pt_formats_attr[] = {
112+
&format_attr_cyc.attr,
113+
&format_attr_mtc.attr,
101114
&format_attr_tsc.attr,
102115
&format_attr_noretcomp.attr,
116+
&format_attr_mtc_period.attr,
117+
&format_attr_cyc_thresh.attr,
118+
&format_attr_psb_period.attr,
103119
NULL,
104120
};
105121

@@ -170,15 +186,65 @@ static int __init pt_pmu_hw_init(void)
170186
return ret;
171187
}
172188

173-
#define PT_CONFIG_MASK (RTIT_CTL_TSC_EN | RTIT_CTL_DISRETC)
189+
#define RTIT_CTL_CYC_PSB (RTIT_CTL_CYCLEACC | \
190+
RTIT_CTL_CYC_THRESH | \
191+
RTIT_CTL_PSB_FREQ)
192+
193+
#define RTIT_CTL_MTC (RTIT_CTL_MTC_EN | \
194+
RTIT_CTL_MTC_RANGE)
195+
196+
#define PT_CONFIG_MASK (RTIT_CTL_TSC_EN | \
197+
RTIT_CTL_DISRETC | \
198+
RTIT_CTL_CYC_PSB | \
199+
RTIT_CTL_MTC)
174200

175201
static bool pt_event_valid(struct perf_event *event)
176202
{
177203
u64 config = event->attr.config;
204+
u64 allowed, requested;
178205

179206
if ((config & PT_CONFIG_MASK) != config)
180207
return false;
181208

209+
if (config & RTIT_CTL_CYC_PSB) {
210+
if (!pt_cap_get(PT_CAP_psb_cyc))
211+
return false;
212+
213+
allowed = pt_cap_get(PT_CAP_psb_periods);
214+
requested = (config & RTIT_CTL_PSB_FREQ) >>
215+
RTIT_CTL_PSB_FREQ_OFFSET;
216+
if (requested && (!(allowed & BIT(requested))))
217+
return false;
218+
219+
allowed = pt_cap_get(PT_CAP_cycle_thresholds);
220+
requested = (config & RTIT_CTL_CYC_THRESH) >>
221+
RTIT_CTL_CYC_THRESH_OFFSET;
222+
if (requested && (!(allowed & BIT(requested))))
223+
return false;
224+
}
225+
226+
if (config & RTIT_CTL_MTC) {
227+
/*
228+
* In the unlikely case that CPUID lists valid mtc periods,
229+
* but not the mtc capability, drop out here.
230+
*
231+
* Spec says that setting mtc period bits while mtc bit in
232+
* CPUID is 0 will #GP, so better safe than sorry.
233+
*/
234+
if (!pt_cap_get(PT_CAP_mtc))
235+
return false;
236+
237+
allowed = pt_cap_get(PT_CAP_mtc_periods);
238+
if (!allowed)
239+
return false;
240+
241+
requested = (config & RTIT_CTL_MTC_RANGE) >>
242+
RTIT_CTL_MTC_RANGE_OFFSET;
243+
244+
if (!(allowed & BIT(requested)))
245+
return false;
246+
}
247+
182248
return true;
183249
}
184250

0 commit comments

Comments
 (0)