【问题标题】:Which perf events can use PEBS?哪些 perf 事件可以使用 PEBS?
【发布时间】:2017-06-29 05:48:42
【问题描述】:

我想了解哪些事件可以在我的 CPU(沙桥)。

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

但是有some examples 使用perf,将:p 添加到cycles 事件。我可以在我的机器上成功运行perf record -e cycles:p

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

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

【问题讨论】:

标签: linux performance intel performancecounter perf


【解决方案1】:

在没有CPU_CLK_UNHALTED.* 的 PEBS 的 SandyBridge 上有支持 cycles:p 的 hack。 hack 在intel_pebs_aliases_snb()perf 的内核部分中实现。当用户使用非零 precise 修饰符请求 -e cyclesPERF_COUNT_HW_CPU_CYCLES(转换为 CPU_CLK_UNHALTED.CORE)时,此函数将使用 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;

precise_ip 设置为非零时,从intel_pmu_hw_config() 调用pebs_aliases

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    }

该 hack 于 2012 年实施,lkml 线程“[PATCH] perf, x86: Make cycles:p working on SNB”, “[tip:perf/core] perf/x86: Implement cycles:p for 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)并检查 @987654349 之外,没有这种“精确”转换 hack 的完整列表@ 用于实际模型和精确的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) 而不是 SKL、IVB、HSW、BDW 上的 cycles:ppp

【讨论】:

  • perf stat -e cycles,cycles:p,instructions,task-clock ./program 进行的实验表明,使用hack 时cycles 并不完全等于cycles:p。但相差不到 0.1%。
猜你喜欢
  • 2012-07-11
  • 1970-01-01
  • 2018-08-08
  • 2019-09-15
  • 1970-01-01
  • 2020-12-18
  • 1970-01-01
  • 2010-11-15
  • 2019-06-10
相关资源
最近更新 更多