哪些性能事件可以使用 PEBS?

Ily*_*bin 6 linux performance intel performancecounter perf

我想了解哪些事件可以在我的 CPU(Sandy Bridge)上有精确的修改器。

英特尔软件开发人员手册(表 18-32.英特尔微架构代号 Sandy Bridge 的 PEBS 性能事件)仅包含以下事件:INST_RETIREDUOPS_RETIREDBR_INST_RETIREDBR_MISP_RETIREDMEM_UOPS_RETIREDMEM_LOAD_UOPS_RETIREDMEM_LOAD_UOPS_LLC_HIT_RETIRED。SandyBridge_core_V15.json列出了 PEBS > 0 的相同事件

然而,有一些使用 的例子perf,这增加:pcycles事件的发生。perf record -e cycles:p而且我可以在我的机器上成功运行。

perf record -e cycles:p -vv -- sleep 1打印precise_ip 1。那么这是否意味着该CPU_CLK_UNHALTED事件实际上使用了 PEBS?

是否可以获得支持的完整事件列表:p

osg*_*sgx 5

SandyBridge 上有 hack 支持cycles:p,但没有适用于CPU_CLK_UNHALTED.*. 该 hack 是perfintel_pebs_aliases_snb(). 当用户请求带有非零修饰符的-e cycleswhich PERF_COUNT_HW_CPU_CYCLES(转换为)时,该函数会将硬件事件更改为PEBS:CPU_CLK_UNHALTED.COREpreciseUOPS_RETIRED.ALL

  29    [PERF_COUNT_HW_CPU_CYCLES]      = 0x003c,

2739 static void intel_pebs_aliases_snb(struct perf_event *event)
2740 {
2741    if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
2742        /*
2743         * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
2744         * (0x003c) so that we can use it with PEBS.
2745         *
2746         * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
2747         * PEBS capable. However we can use UOPS_RETIRED.ALL
2748         * (0x01c2), which is a PEBS capable event, to get the same
2749         * count.
2750         *
2751         * UOPS_RETIRED.ALL counts the number of cycles that retires
2752         * CNTMASK micro-ops. By setting CNTMASK to a value (16)
2753         * larger than the maximum number of micro-ops that can be
2754         * retired per cycle (4) and then inverting the condition, we
2755         * count all cycles that retire 16 or less micro-ops, which
2756         * is every cycle.
2757         *
2758         * Thereby we gain a PEBS capable cycle counter.
2759         */
2760        u64 alt_config = X86_CONFIG(.event=0xc2, .umask=0x01, .inv=1, .cmask=16);
2761 
2762        alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
2763        event->hw.config = alt_config;
2764    }
2765 }
Run Code Online (Sandbox Code Playgroud)

该hack 已在for / asintel_pebs_aliases_snb中注册3557 __init int intel_pmu_init(void)case INTEL_FAM6_SANDYBRIDGE:case INTEL_FAM6_SANDYBRIDGE_X:

3772        x86_pmu.event_constraints = intel_snb_event_constraints;
3773        x86_pmu.pebs_constraints = intel_snb_pebs_event_constraints;
3774        x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
Run Code Online (Sandbox Code Playgroud)

pebs_aliasesintel_pmu_hw_config()precise_ip设置为非零时调用:

2814 static int intel_pmu_hw_config(struct perf_event *event)
2815 {

2821    if (event->attr.precise_ip) {

2828        if (x86_pmu.pebs_aliases)
2829            x86_pmu.pebs_aliases(event);
2830    }
Run Code Online (Sandbox Code Playgroud)

该黑客攻击于 2012 年实施,lkml 线程“[PATCH] perf,x86:使周期:p 在 SNB 上工作”,“[tip:perf / core] perf / x86:实现周期:p for SNB / IVB”,cccb9ba9e4ee0d750265f53de9258df69655c40b,http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?id=cccb9ba9e4ee0d750265f53de9258df69655c40b

perf/x86:为 SNB/IVB 实施周期:p

现在终于有了一个可以工作的 PEBS (IvyBridge) 的芯片,我们可以启用硬件并实现 SNB/IVB 的周期:p。

我认为,除了 中的 linux 源代码之外,没有此类“精确”转换 hack 的完整列表arch/x86/events/intel/core.c,grep for static void intel_pebs_aliases(通常cycles:p/CPU_CLK_UNHALTED 0x003c已实现)并检查intel_pmu_init实际模型和 x86_pmu.pebs_aliases所选的确切变体:

  • intel_pebs_aliases_core2,INST_RETIRED.ANY_P (0x00c0) CNTMASK=16而不是cycles:p
  • intel_pebs_aliases_snb,UOPS_RETIRED.ALL (0x01c2) CNTMASK=16而不是cycles:p
  • intel_pebs_aliases_precdist 表示 , 的最高值precise_ipINST_RETIRED.PREC_DIST (0x01c0)而不是cycles:pppSKL、IVB、HSW、BDW