Skip to content

Commit 5e9b35a

Browse files
Fix lscpu cpu frequency parsing
1 parent 64b3d85 commit 5e9b35a

File tree

4 files changed

+935
-2
lines changed

4 files changed

+935
-2
lines changed

BenchmarkDotNet.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
<s:Boolean x:Key="/Default/UserDictionary/Words/=Redstone/@EntryIndexedValue">True</s:Boolean>
178178
<s:Boolean x:Key="/Default/UserDictionary/Words/=reimplement/@EntryIndexedValue">True</s:Boolean>
179179
<s:Boolean x:Key="/Default/UserDictionary/Words/=runtimes/@EntryIndexedValue">True</s:Boolean>
180+
<s:Boolean x:Key="/Default/UserDictionary/Words/=ryzen/@EntryIndexedValue">True</s:Boolean>
180181
<s:Boolean x:Key="/Default/UserDictionary/Words/=sgen/@EntryIndexedValue">True</s:Boolean>
181182
<s:Boolean x:Key="/Default/UserDictionary/Words/=SHADOWCOPY/@EntryIndexedValue">True</s:Boolean>
182183
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shortified/@EntryIndexedValue">True</s:Boolean>

src/BenchmarkDotNet/Portability/Cpu/Linux/LinuxCpuInfoParser.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ internal static CpuInfo Parse(string? cpuInfo, string? lscpu)
6868
string value = lscpuParts[i + 1].Trim();
6969

7070
if (name.EqualsWithIgnoreCase(Lscpu.MaxFrequency) &&
71-
Frequency.TryParseMHz(value.Replace(',', '.'), out var maxFrequencyMHz)) // Example: `CPU max MHz: 3200,0000`
72-
maxFrequency = Frequency.FromMHz(maxFrequencyMHz);
71+
Frequency.TryParseMHz(value.Replace(',', '.'), out var maxFrequencyParsed)) // Example: `CPU max MHz: 3200,0000`
72+
maxFrequency = maxFrequencyParsed;
7373

7474
if (name.EqualsWithIgnoreCase(Lscpu.ModelName))
7575
processorModelNames.Add(value);

tests/BenchmarkDotNet.Tests/Portability/Cpu/LinuxCpuInfoParserTests.cs

+36
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,42 @@ public void Issue2577Test()
9898
Output.AssertEqual(expected, actual);
9999
}
100100

101+
[Fact]
102+
public void AmdRyzen9_7950X()
103+
{
104+
string cpuInfo = TestHelper.ReadTestFile("ryzen9-cpuinfo.txt");
105+
const string lscpu =
106+
"""
107+
Architecture: x86_64
108+
CPU op-mode(s): 32-bit, 64-bit
109+
Address sizes: 48 bits physical, 48 bits virtual
110+
Byte Order: Little Endian
111+
CPU(s): 32
112+
On-line CPU(s) list: 0-31
113+
Vendor ID: AuthenticAMD
114+
Model name: AMD Ryzen 9 7950X 16-Core Processor
115+
CPU family: 25
116+
Model: 97
117+
Thread(s) per core: 2
118+
Core(s) per socket: 16
119+
Socket(s): 1
120+
Stepping: 2
121+
CPU(s) scaling MHz: 41%
122+
CPU max MHz: 5881.0000
123+
CPU min MHz: 400.0000
124+
BogoMIPS: 8983.23
125+
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl
126+
pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb
127+
bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512
128+
cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean
129+
flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succo
130+
r smca fsrm flush_l1d
131+
""";
132+
var actual = LinuxCpuInfoParser.Parse(cpuInfo, lscpu);
133+
var expected = new CpuInfo("AMD Ryzen 9 7950X 16-Core Processor", 1, 16, 32, 5881 * MHz, 5881 * MHz);
134+
Output.AssertEqual(expected, actual);
135+
}
136+
101137
[Theory]
102138
[InlineData("Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz", 2.50)]
103139
[InlineData("Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz", 2.30)]

0 commit comments

Comments
 (0)