哪些性能事件可以使用 PEBS?
Which perf events can use PEBS?
我想了解哪些事件可以对我的 precise 修饰符
CPU(沙桥)。
英特尔软件开发人员手册(Table 18-32.PEBS 性能
英特尔微体系结构代号 Sandy Bridge 的事件)包含
仅以下事件:INST_RETIRED
、UOPS_RETIRED
、
BR_INST_RETIRED
, BR_MISP_RETIRED
, MEM_UOPS_RETIRED
,
MEM_LOAD_UOPS_RETIRED
、MEM_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
的完整事件列表?
在 SandyBridge 上存在支持 cycles:p
的黑客攻击,它没有 CPU_CLK_UNHALTED.*
的 PEBS。该 hack 是在 intel_pebs_aliases_snb()
中的 perf
的内核部分实现的。当用户使用非零 precise
修饰符请求 -e cycles
即 PERF_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
黑客在 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
设置为 non-zero: 时,从 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 }
黑客攻击于 2012 年实施,lkml 线程“[PATCH] 性能,x86:使 cycles:p 在 SNB 上工作”,“[提示:perf/core] perf/x86:实施cycles:p 对于 SNB/IVB", cccb9ba9e4ee0d750265f53de9258df69655c40b, http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?id=cccb9ba9e4ee0d750265f53de9258df69655c40b:
perf/x86: Implement cycles:p for SNB/IVB
Now that there's finally a chip with working PEBS (IvyBridge), we can
enable the hardware and implement cycles:p for SNB/IVB.
而且我认为,除了 arch/x86/events/intel/core.c
中的 linux 源代码之外,没有此类 "precise" 转换黑客的完整列表,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_ip
,INST_RETIRED.PREC_DIST (0x01c0)
而不是 SKL、IVB、HSW、BDW 上的 cycles:ppp
我想了解哪些事件可以对我的 precise 修饰符 CPU(沙桥)。
英特尔软件开发人员手册(Table 18-32.PEBS 性能
英特尔微体系结构代号 Sandy Bridge 的事件)包含
仅以下事件:INST_RETIRED
、UOPS_RETIRED
、
BR_INST_RETIRED
, BR_MISP_RETIRED
, MEM_UOPS_RETIRED
,
MEM_LOAD_UOPS_RETIRED
、MEM_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
的完整事件列表?
在 SandyBridge 上存在支持 cycles:p
的黑客攻击,它没有 CPU_CLK_UNHALTED.*
的 PEBS。该 hack 是在 intel_pebs_aliases_snb()
中的 perf
的内核部分实现的。当用户使用非零 precise
修饰符请求 -e cycles
即 PERF_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
黑客在 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
设置为 non-zero: 时,从 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 }
黑客攻击于 2012 年实施,lkml 线程“[PATCH] 性能,x86:使 cycles:p 在 SNB 上工作”,“[提示:perf/core] perf/x86:实施cycles:p 对于 SNB/IVB", cccb9ba9e4ee0d750265f53de9258df69655c40b, http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?id=cccb9ba9e4ee0d750265f53de9258df69655c40b:
perf/x86: Implement cycles:p for SNB/IVB
Now that there's finally a chip with working PEBS (IvyBridge), we can enable the hardware and implement cycles:p for SNB/IVB.
而且我认为,除了 arch/x86/events/intel/core.c
中的 linux 源代码之外,没有此类 "precise" 转换黑客的完整列表,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_ip
,INST_RETIRED.PREC_DIST (0x01c0)
而不是 SKL、IVB、HSW、BDW 上的
cycles:ppp