Skip to content

Commit 33cad28

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/intel/lbr: Create kmem_cache for the LBR context data
A new kmem_cache method is introduced to allocate the PMU specific data task_ctx_data, which requires the PMU specific code to create a kmem_cache. Currently, the task_ctx_data is only used by the Intel LBR call stack feature, which is introduced since Haswell. The kmem_cache should be only created for Haswell and later platforms. There is no alignment requirement for the existing platforms. Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 217c2a6 commit 33cad28

File tree

1 file changed

+19
-2
lines changed
  • arch/x86/events/intel

1 file changed

+19
-2
lines changed

arch/x86/events/intel/lbr.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,9 +1531,17 @@ void __init intel_pmu_lbr_init_snb(void)
15311531
*/
15321532
}
15331533

1534+
static inline struct kmem_cache *
1535+
create_lbr_kmem_cache(size_t size, size_t align)
1536+
{
1537+
return kmem_cache_create("x86_lbr", size, align, 0, NULL);
1538+
}
1539+
15341540
/* haswell */
15351541
void intel_pmu_lbr_init_hsw(void)
15361542
{
1543+
size_t size = sizeof(struct x86_perf_task_context);
1544+
15371545
x86_pmu.lbr_nr = 16;
15381546
x86_pmu.lbr_tos = MSR_LBR_TOS;
15391547
x86_pmu.lbr_from = MSR_LBR_NHM_FROM;
@@ -1542,13 +1550,17 @@ void intel_pmu_lbr_init_hsw(void)
15421550
x86_pmu.lbr_sel_mask = LBR_SEL_MASK;
15431551
x86_pmu.lbr_sel_map = hsw_lbr_sel_map;
15441552

1553+
x86_get_pmu()->task_ctx_cache = create_lbr_kmem_cache(size, 0);
1554+
15451555
if (lbr_from_signext_quirk_needed())
15461556
static_branch_enable(&lbr_from_quirk_key);
15471557
}
15481558

15491559
/* skylake */
15501560
__init void intel_pmu_lbr_init_skl(void)
15511561
{
1562+
size_t size = sizeof(struct x86_perf_task_context);
1563+
15521564
x86_pmu.lbr_nr = 32;
15531565
x86_pmu.lbr_tos = MSR_LBR_TOS;
15541566
x86_pmu.lbr_from = MSR_LBR_NHM_FROM;
@@ -1558,6 +1570,8 @@ __init void intel_pmu_lbr_init_skl(void)
15581570
x86_pmu.lbr_sel_mask = LBR_SEL_MASK;
15591571
x86_pmu.lbr_sel_map = hsw_lbr_sel_map;
15601572

1573+
x86_get_pmu()->task_ctx_cache = create_lbr_kmem_cache(size, 0);
1574+
15611575
/*
15621576
* SW branch filter usage:
15631577
* - support syscall, sysret capture.
@@ -1631,6 +1645,7 @@ void __init intel_pmu_arch_lbr_init(void)
16311645
union cpuid28_ebx ebx;
16321646
union cpuid28_ecx ecx;
16331647
unsigned int unused_edx;
1648+
size_t size;
16341649
u64 lbr_nr;
16351650

16361651
/* Arch LBR Capabilities */
@@ -1655,8 +1670,10 @@ void __init intel_pmu_arch_lbr_init(void)
16551670
x86_pmu.lbr_br_type = ecx.split.lbr_br_type;
16561671
x86_pmu.lbr_nr = lbr_nr;
16571672

1658-
x86_get_pmu()->task_ctx_size = sizeof(struct x86_perf_task_context_arch_lbr) +
1659-
lbr_nr * sizeof(struct lbr_entry);
1673+
size = sizeof(struct x86_perf_task_context_arch_lbr) +
1674+
lbr_nr * sizeof(struct lbr_entry);
1675+
x86_get_pmu()->task_ctx_size = size;
1676+
x86_get_pmu()->task_ctx_cache = create_lbr_kmem_cache(size, 0);
16601677

16611678
x86_pmu.lbr_from = MSR_ARCH_LBR_FROM_0;
16621679
x86_pmu.lbr_to = MSR_ARCH_LBR_TO_0;

0 commit comments

Comments
 (0)