新入手了一台小米迷你主机,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,功能简单清晰
文章来源:https://www.toymoban.com/news/detail-436128.html
参考文献
[1]: https://learn.microsoft.com/zh-cn/windows-server/virtualization/hyper-v/manage/performance-monitoring-hardware文章来源地址https://www.toymoban.com/news/detail-436128.html
到了这里,关于i5 1240p使用perf避坑指南的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!