i5 1240p使用perf避坑指南

新入手了一台小米迷你主机,CPU是英特尔的十二代i5 1240p,intel i5 1240p微架构属于alder lake,有4个大核,8个小核,每个大核有两个线程,因此,该CPU多线程能力为12核16线程。最近在研究性能剖析相关的知识,没想到遇到了不少坑,记于此。

Perf on WSL(cycles:u not supported)

首先尝试了在windows wsl中使用perf

$ sudo apt install linux-tools-generic

安装的可执行程序位于/usr/lib/linux-tools/\<kernel version>/perf

$ perf stat ls
Performance counter stats for 'ls':

              0.76 msec task-clock:u              #    0.706 CPUs utilized
                 0      context-switches:u        #    0.000 /sec
                 0      cpu-migrations:u          #    0.000 /sec
               113      page-faults:u             #  149.431 K/sec
   <not supported>      cycles:u
   <not supported>      instructions:u
   <not supported>      branches:u
   <not supported>      branch-misses:u

       0.001070439 seconds time elapsed

       0.001058000 seconds user
       0.000000000 seconds sys

查看pmu驱动,结果是这样的

$ dmesg | grep PMU

$ dmesg | grep PMU
[    0.094674] Performance Events: unsupported p6 CPU model 154 no PMU driver, software events only.
$ lscpu
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   39 bits physical, 48 bits virtual
CPU(s):                          16
On-line CPU(s) list:             0-15
Thread(s) per core:              2
Core(s) per socket:              8
Socket(s):                       1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           154
Model name:                      12th Gen Intel(R) Core(TM) i5-1240P
Stepping:                        3
CPU MHz:                         2112.007
BogoMIPS:                        4224.01
Virtualization:                  VT-x
Hypervisor vendor:               Microsoft
Virtualization type:             full
L1d cache:                       384 KiB
L1i cache:                       256 KiB
L2 cache:                        10 MiB
L3 cache:                        12 MiB
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Mitigation; Enhanced IBRS
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxs
                                 r sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_
                                 reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic m
                                 ovbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowpr
                                 efetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_a
                                 d fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb
                                 sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni umip waitpkg gfni vaes vpclmulqdq rdpid
                                 movdiri movdir64b fsrm serialize flush_l1d arch_capabilities

Flags中没有看到arch_perfmon,也就是说Hardware Performance Monitor没有使能

Perf On Hyper-V

再试一下通过Hyper-V行不行,我已经使能了Hyper-V,然后通过微软这篇官方[1]文档使能pmu

$ # Enable IPT
Set-VMProcessor MyVMName -Perfmon @("ipt", "pmu")

再启动Hyper-V虚拟机,直接报错找不到系统监视器,启动失败

小米迷你主机安装Ubuntu

一开始安装的20.04,发现wifi驱动没有适配,为了省事,直接安装22.04。装完之后,pmu能正常使用了。

 Performance counter stats for 'ls':

              0.78 msec task-clock                #    0.548 CPUs utilized          
                 0      context-switches          #    0.000 /sec                   
                 0      cpu-migrations            #    0.000 /sec                   
                91      page-faults               #  116.387 K/sec                  
         1,448,050      cpu_core/cycles/          #    1.852 G/sec                  
     <not counted>      cpu_atom/cycles/                                              (0.00%)
         1,749,783      cpu_core/instructions/    #    2.238 G/sec                  
     <not counted>      cpu_atom/instructions/                                        (0.00%)
           325,300      cpu_core/branches/        #  416.052 M/sec                  
     <not counted>      cpu_atom/branches/                                            (0.00%)
             9,590      cpu_core/branch-misses/   #   12.265 M/sec                  
     <not counted>      cpu_atom/branch-misses/                                       (0.00%)

       0.001426852 seconds time elapsed

       0.001447000 seconds user
       0.000000000 seconds sys

推荐一个烧录镜像工具,Rufus,功能简单清晰
在这里插入图片描述

参考文献

[1]: https://learn.microsoft.com/zh-cn/windows-server/virtualization/hyper-v/manage/performance-monitoring-hardware

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶玄青

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值