哪些perf事件可以使用PEBS?

时间:2017-02-10 19:04:41

标签: linux performance intel performancecounter perf

我想了解哪些事件可以使用我的精确修饰符 CPU(Sandy Bridge)。

英特尔软件开发人员手册(表18-32.PEBS性能 英特尔微体系架构代码名称Sandy Bridge的事件包含 仅限以下事件:INST_RETIREDUOPS_RETIREDBR_INST_RETIREDBR_MISP_RETIREDMEM_UOPS_RETIREDMEM_LOAD_UOPS_RETIREDMEM_LOAD_UOPS_LLC_HIT_RETIREDSandyBridge_core_V15.json列出了与PEBS相同的事件> 0

但是perf使用了some examples:pcycles添加到perf record -e cycles:p事件中。我可以在我的机器上成功运行perf record -e cycles:p -vv -- sleep 1

此外precise_ip 1打印CPU_CLK_UNHALTED。那么它是否意味着:p事件实际上使用了PEBS?

是否可以获取支持{{1}}的完整事件列表?

1 个答案:

答案 0 :(得分:3)

对于cycles:p没有PEBS的SandyBridge,有支持CPU_CLK_UNHALTED.*的黑客攻击。该hack在intel_pebs_aliases_snb()perf的内核部分实现。当用户使用非零-e cycles修饰符请PERF_COUNT_HW_CPU_CYCLES CPU_CLK_UNHALTED.CORE(转换为precise)时,此函数会使用PEBS将硬件事件更改为UOPS_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 }

intel_pebs_aliases_snb hack已在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;
pebs_aliases设置为非零时,intel_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    }

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

  

perf / x86:实施周期:p表示SNB / IVB

     

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

我认为,除了arch/x86/events/intel/core.c中的linux源代码,static void intel_pebs_aliases的grep(通常为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表示SKL,IVB,HSW,BDW上precise_ipINST_RETIRED.PREC_DIST (0x01c0)代替cycles:ppp的最高值