Skip to content

Commit df6e8e1

Browse files
committed
fix: Refactor cpu analysis to make dmidecode safer to use under win32
dmidecode Version when defined is better to use as cpu name with some cleaning Closes #898
1 parent f32e3ba commit df6e8e1

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ core:
77

88
inventory:
99
* Fix #897: Fix cpu analysis on win32 to support inventory of different cpus
10+
* Fix #898: Refactor cpu analysis to make dmidecode safer to use under win32
1011

1112
2.6 Thu, 26 Nov 2020
1213

lib/FusionInventory/Agent/Task/Inventory/Win32/CPU.pm

+16-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ sub _getCPUs {
6565
my $logicalId = 0;
6666
my @cpus;
6767

68+
# Be aware, a bug on OS side may have reversed the order of processors infos regarding
69+
# dmi table order, see https://github.com/fusioninventory/fusioninventory-agent/issues/898
70+
# so we use dmidecode infos in priority even if it is not totally accurate
6871
foreach my $object (getWMIObjects(
6972
class => 'Win32_Processor',
7073
properties => [ qw/
@@ -80,19 +83,25 @@ sub _getCPUs {
8083
my $wmi_threads = !$dmidecodeInfo->{THREAD} && $object->{NumberOfCores} ? $object->{NumberOfLogicalProcessors}/$object->{NumberOfCores} : undef;
8184

8285
# Split CPUID from its value inside registry
83-
my @splitted_identifier = split(/ |\n/, $registryInfo->{'/Identifier'} || $object->{Manufacturer});
86+
my @splitted_identifier = split(/ |\n/, $registryInfo->{'/Identifier'} || $object->{Description});
87+
88+
my $name = $dmidecodeInfo->{NAME};
89+
unless ($name) {
90+
$name = trimWhitespace($registryInfo->{'/ProcessorNameString'} || $object->{Name});
91+
$name =~ s/\((R|TM)\)//gi if $name;
92+
}
8493

8594
my $cpu = {
8695
CORE => $dmidecodeInfo->{CORE} || $object->{NumberOfCores},
8796
THREAD => $dmidecodeInfo->{THREAD} || $wmi_threads,
88-
DESCRIPTION => $registryInfo->{'/Identifier'} || $object->{Description},
89-
NAME => trimWhitespace($registryInfo->{'/ProcessorNameString'} || $object->{Name}),
90-
MANUFACTURER => getCanonicalManufacturer($registryInfo->{'/VendorIdentifier'} || $object->{Manufacturer}),
97+
DESCRIPTION => $dmidecodeInfo->{DESCRIPTION} || $registryInfo->{'/Identifier'} || $object->{Description},
98+
NAME => $name,
99+
MANUFACTURER => $dmidecodeInfo->{MANUFACTURER} || getCanonicalManufacturer($registryInfo->{'/VendorIdentifier'} || $object->{Manufacturer}),
91100
SERIAL => $dmidecodeInfo->{SERIAL} || $object->{SerialNumber},
92101
SPEED => $dmidecodeInfo->{SPEED} || $object->{MaxClockSpeed},
93-
FAMILYNUMBER => $splitted_identifier[2],
94-
MODEL => $splitted_identifier[4],
95-
STEPPING => $splitted_identifier[6],
102+
FAMILYNUMBER => $dmidecodeInfo->{FAMILYNUMBER} || $splitted_identifier[2],
103+
MODEL => $dmidecodeInfo->{MODEL} || $splitted_identifier[4],
104+
STEPPING => $dmidecodeInfo->{STEPPING} || $splitted_identifier[6],
96105
ID => $dmidecodeInfo->{ID} || $object->{ProcessorId}
97106
};
98107

lib/FusionInventory/Agent/Tools/Generic.pm

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ sub getCpusFromDmidecode {
126126
MANUFACTURER => $manufacturer
127127
};
128128
$cpu->{NAME} =
129-
($cpu->{MANUFACTURER} =~ /Intel/ ? $info->{'Family'} : undef) ||
130129
$info->{'Version'} ||
130+
$info->{'Family'} ||
131131
$info->{'Processor Family'} ||
132132
$info->{'Processor Version'};
133+
# Cleanup cpu NAME
134+
$cpu->{NAME} =~ s/\((R|TM)\)//gi if $cpu->{NAME};
133135

134136
if ($cpu->{ID}) {
135137

t/agent/tools/generic.t

+19-19
Original file line numberDiff line numberDiff line change
@@ -7154,7 +7154,7 @@ my %cpu_tests = (
71547154
'freebsd-8.1' => [
71557155
{
71567156
ID => '52 06 02 00 FF FB EB BF',
7157-
NAME => 'Core 2 Duo',
7157+
NAME => 'Intel Core i5 CPU M 430 @ 2.27GHz',
71587158
EXTERNAL_CLOCK => '1066',
71597159
SPEED => '2270',
71607160
THREAD => '4',
@@ -7170,7 +7170,7 @@ my %cpu_tests = (
71707170
'hp-dl180' => [
71717171
{
71727172
ID => 'A5 06 01 00 FF FB EB BF',
7173-
NAME => 'Xeon',
7173+
NAME => 'Intel Xeon CPU E5504 @ 2.00GHz',
71747174
EXTERNAL_CLOCK => '532',
71757175
SPEED => '2000',
71767176
THREAD => '4',
@@ -7197,7 +7197,7 @@ my %cpu_tests = (
71977197
'rhel-3.4' => [
71987198
{
71997199
ID => '41 0F 00 00 FF FB EB BF',
7200-
NAME => 'Xeon MP',
7200+
NAME => 'Intel Xeon CPU 2.80GHz',
72017201
EXTERNAL_CLOCK => '200',
72027202
SPEED => '2800',
72037203
THREAD => undef,
@@ -7211,7 +7211,7 @@ my %cpu_tests = (
72117211
},
72127212
{
72137213
ID => '41 0F 00 00 FF FB EB BF',
7214-
NAME => 'Xeon MP',
7214+
NAME => 'Intel Xeon CPU 2.80GHz',
72157215
EXTERNAL_CLOCK => '200',
72167216
SPEED => '2800',
72177217
THREAD => undef,
@@ -7229,7 +7229,7 @@ my %cpu_tests = (
72297229
'rhel-4.3' => [
72307230
{
72317231
ID => '29 0F 00 00 FF FB EB BF',
7232-
NAME => 'Xeon',
7232+
NAME => 'Intel Xeon',
72337233
EXTERNAL_CLOCK => '133',
72347234
SPEED => '2666',
72357235
THREAD => undef,
@@ -7243,7 +7243,7 @@ my %cpu_tests = (
72437243
},
72447244
{
72457245
ID => '29 0F 00 00 FF FB EB BF',
7246-
NAME => 'Xeon',
7246+
NAME => 'Intel Xeon',
72477247
EXTERNAL_CLOCK => '133',
72487248
SPEED => '2666',
72497249
THREAD => undef,
@@ -7275,7 +7275,7 @@ my %cpu_tests = (
72757275
'rhel-5.6' => [
72767276
{
72777277
ID => 'C2 06 02 00 FF FB EB BF',
7278-
NAME => 'Xeon',
7278+
NAME => 'Intel Xeon CPU E5620 @ 2.40GHz',
72797279
EXTERNAL_CLOCK => '5860',
72807280
SPEED => '2400',
72817281
THREAD => '8',
@@ -7289,7 +7289,7 @@ my %cpu_tests = (
72897289
},
72907290
{
72917291
ID => 'C2 06 02 00 FF FB EB BF',
7292-
NAME => 'Xeon',
7292+
NAME => 'Intel Xeon CPU E5620 @ 2.40GHz',
72937293
EXTERNAL_CLOCK => '5860',
72947294
SPEED => '2400',
72957295
THREAD => '8',
@@ -7305,7 +7305,7 @@ my %cpu_tests = (
73057305
'rhel-6.3-esx-1vcpu' => [
73067306
{
73077307
ID => 'A7 06 02 00 FF FB AB 0F',
7308-
NAME => 'Intel(R) Core(TM) i5-2500S CPU @ 2.70GHz',
7308+
NAME => 'Intel Core i5-2500S CPU @ 2.70GHz',
73097309
SPEED => '2700',
73107310
THREAD => undef,
73117311
SERIAL => undef,
@@ -7374,7 +7374,7 @@ my %cpu_tests = (
73747374
MODEL => 63,
73757375
MANUFACTURER => 'Intel',
73767376
ID => 'F2 06 03 00 FF FB EB BF',
7377-
NAME => 'Xeon',
7377+
NAME => 'Intel Xeon CPU E5-2699 v3 @ 2.30GHz',
73787378
FAMILYNUMBER => 6,
73797379
STEPPING => 2,
73807380
SERIAL => undef,
@@ -7386,7 +7386,7 @@ my %cpu_tests = (
73867386
ID => 'F2 06 03 00 FF FB EB BF',
73877387
STEPPING => 2,
73887388
FAMILYNUMBER => 6,
7389-
NAME => 'Xeon',
7389+
NAME => 'Intel Xeon CPU E5-2699 v3 @ 2.30GHz',
73907390
SERIAL => undef,
73917391
FAMILYNAME => 'Xeon',
73927392
THREAD => '36',
@@ -7398,7 +7398,7 @@ my %cpu_tests = (
73987398
'S3000AHLX' => [
73997399
{
74007400
ID => 'F6 06 00 00 FF FB EB BF',
7401-
NAME => 'Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz',
7401+
NAME => 'Intel Core2 CPU 6600 @ 2.40GHz',
74027402
EXTERNAL_CLOCK => '266',
74037403
SPEED => '2400',
74047404
THREAD => undef,
@@ -7414,7 +7414,7 @@ my %cpu_tests = (
74147414
'S5000VSA' => [
74157415
{
74167416
ID => 'F6 06 00 00 FF FB EB BF',
7417-
NAME => 'Xeon',
7417+
NAME => 'Intel Xeon CPU 5120 @ 1.86GHz',
74187418
EXTERNAL_CLOCK => '1066',
74197419
SPEED => '1860',
74207420
THREAD => '2',
@@ -7428,7 +7428,7 @@ my %cpu_tests = (
74287428
},
74297429
{
74307430
ID => 'F6 06 00 00 FF FB EB BF',
7431-
NAME => 'Xeon',
7431+
NAME => 'Intel Xeon CPU 5120 @ 1.86GHz',
74327432
EXTERNAL_CLOCK => '1066',
74337433
SPEED => '1860',
74347434
THREAD => '2',
@@ -7444,7 +7444,7 @@ my %cpu_tests = (
74447444
'linux-1' => [
74457445
{
74467446
ID => '7A 06 01 00 FF FB EB BF',
7447-
NAME => 'Core 2 Duo',
7447+
NAME => 'Intel Core2 Duo CPU E8400 @ 3.00GHz',
74487448
EXTERNAL_CLOCK => '333',
74497449
SPEED => '3000',
74507450
THREAD => '2',
@@ -7547,7 +7547,7 @@ my %cpu_tests = (
75477547
'windows-hyperV' => [
75487548
{
75497549
ID => '7A 06 01 00 FF FB 8B 1F',
7550-
NAME => 'Xeon',
7550+
NAME => 'Intel Xeon',
75517551
EXTERNAL_CLOCK => '266',
75527552
SPEED => '2500',
75537553
THREAD => undef,
@@ -7579,7 +7579,7 @@ my %cpu_tests = (
75797579
'windows-7' => [
75807580
{
75817581
ID => 'A7 06 02 00 FF FB EB BF',
7582-
NAME => 'Core 2 Duo',
7582+
NAME => 'Intel Core i5-2300 CPU @ 2.80GHz',
75837583
EXTERNAL_CLOCK => '100',
75847584
SPEED => '2800',
75857585
THREAD => undef,
@@ -7596,7 +7596,7 @@ my %cpu_tests = (
75967596
'windows-7.2' => [
75977597
{
75987598
ID => '62 0F 10 00 FF FB 8B 17',
7599-
NAME => 'AMD Athlon(tm) II X2 245 Processor',
7599+
NAME => 'AMD Athlon II X2 245 Processor',
76007600
EXTERNAL_CLOCK => '200',
76017601
SPEED => '2900',
76027602
THREAD => undef,
@@ -7618,7 +7618,7 @@ my %cpu_tests = (
76187618
ID => 'A7 06 02 00 FF FB EB BF',
76197619
MANUFACTURER => 'Intel(R) Corporation',
76207620
MODEL => '42',
7621-
NAME => 'Core i5',
7621+
NAME => 'Intel Core i5-2450M CPU @ 2.50GHz',
76227622
SERIAL => 'Not Supported by CPU',
76237623
SPEED => '2500',
76247624
STEPPING => '7',

t/tasks/inventory/windows/cpu.t

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ my %tests = (
3333
'7' => [
3434
{
3535
ID => 'A7 06 02 00 FF FB EB BF',
36-
NAME => 'Intel(R) Core(TM) i5-2300 CPU @ 2.80GHz',
36+
NAME => 'Intel Core i5-2300 CPU @ 2.80GHz',
3737
SERIAL => undef,
3838
MANUFACTURER => 'Intel',
3939
DESCRIPTION => 'x86 Family 6 Model 42 Stepping 7',
@@ -49,7 +49,7 @@ my %tests = (
4949
'2003' => [
5050
{
5151
ID => 'BFEBFBFF00000F29',
52-
NAME => 'Intel(R) Xeon(TM) CPU 3.06GHz',
52+
NAME => 'Intel Xeon CPU 3.06GHz',
5353
SERIAL => undef,
5454
MANUFACTURER => 'Intel',
5555
DESCRIPTION => 'x86 Family 15 Model 2 Stepping 9',
@@ -62,7 +62,7 @@ my %tests = (
6262
},
6363
{
6464
ID => '0000000000000000',
65-
NAME => 'Intel(R) Xeon(TM) CPU 3.06GHz',
65+
NAME => 'Intel Xeon CPU 3.06GHz',
6666
SERIAL => undef,
6767
MANUFACTURER => 'Intel',
6868
DESCRIPTION => 'x86 Family 15 Model 2 Stepping 9',
@@ -77,7 +77,7 @@ my %tests = (
7777
'2003SP2' => [
7878
{
7979
ID => '0FEBBBFF00010676',
80-
NAME => 'Intel(R) Xeon(R) CPU E5440 @ 2.83GHz',
80+
NAME => 'Intel Xeon CPU E5440 @ 2.83GHz',
8181
SERIAL => undef,
8282
MANUFACTURER => 'Intel',
8383
DESCRIPTION => 'x86 Family 6 Model 23 Stepping 6',
@@ -90,7 +90,7 @@ my %tests = (
9090
},
9191
{
9292
ID => '0FEBBBFF00000676',
93-
NAME => 'Intel(R) Xeon(R) CPU E5440 @ 2.83GHz',
93+
NAME => 'Intel Xeon CPU E5440 @ 2.83GHz',
9494
SERIAL => undef,
9595
MANUFACTURER => 'Intel',
9696
DESCRIPTION => 'x86 Family 6 Model 23 Stepping 6',
@@ -105,7 +105,7 @@ my %tests = (
105105
'xp' => [
106106
{
107107
ID => '76 06 01 00 FF FB EB BF',
108-
NAME => 'Intel(R) Core(TM)2 Duo CPU T9400 @ 2.53GHz',
108+
NAME => 'Core 2 Duo',
109109
SERIAL => undef,
110110
MANUFACTURER => 'Intel',
111111
DESCRIPTION => 'x86 Family 6 Model 23 Stepping 6',
@@ -148,7 +148,7 @@ my %tests = (
148148
'2008-with-2-different-cpus' => [
149149
{
150150
ID => 'A5 06 01 00 FF FB EB BF',
151-
NAME => 'Intel(R) Xeon(R) CPU E5506 @ 2.13GHz',
151+
NAME => 'Intel Xeon CPU E5504 @ 2.00GHz',
152152
SERIAL => undef,
153153
MANUFACTURER => 'Intel',
154154
DESCRIPTION => 'Intel64 Family 6 Model 26 Stepping 5',
@@ -161,7 +161,7 @@ my %tests = (
161161
},
162162
{
163163
ID => 'A5 06 01 00 FF FB EB BF',
164-
NAME => 'Intel(R) Xeon(R) CPU E5504 @ 2.00GHz',
164+
NAME => 'Intel Xeon CPU E5506 @ 2.13GHz',
165165
SERIAL => undef,
166166
MANUFACTURER => 'Intel',
167167
DESCRIPTION => 'Intel64 Family 6 Model 26 Stepping 5',

0 commit comments

Comments
 (0)