line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Solaris::CPU; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
89023801
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
66
|
|
4
|
1
|
|
|
1
|
|
12
|
use warnings; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
78
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
32
|
|
|
1
|
|
|
|
|
23
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1413
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
282
|
|
9
|
1
|
|
|
1
|
|
639
|
use FusionInventory::Agent::Tools::Solaris; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1320
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub isEnabled { |
12
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
13
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{cpu}; |
14
|
0
|
|
|
|
|
|
return 1; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub doInventory { |
18
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
foreach my $cpu (_getCPUs()) { |
23
|
0
|
|
|
|
|
|
$inventory->addEntry( |
24
|
|
|
|
|
|
|
section => 'CPUS', |
25
|
|
|
|
|
|
|
entry => $cpu |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _getCPUs { |
32
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# get virtual CPUs from psrinfo -v |
35
|
0
|
|
|
|
|
|
my @all_virtual_cpus = _getVirtualCPUs(logger => $params{logger}); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# get physical CPUs from psrinfo -vp |
38
|
0
|
|
|
|
|
|
my @all_physical_cpus = _getPhysicalCPUs(logger => $params{logger}); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# count the different speed values |
41
|
|
|
|
|
|
|
# undef is temporarily mapped to 0, to avoid warnings |
42
|
0
|
0
|
|
|
|
|
my @physical_speeds = |
43
|
0
|
|
|
|
|
|
map { $_ ? $_ : undef } |
44
|
0
|
0
|
|
|
|
|
sort { $a <=> $b } |
45
|
|
|
|
|
|
|
uniq |
46
|
0
|
|
|
|
|
|
map { $_->{speed} || 0 } |
47
|
|
|
|
|
|
|
@all_physical_cpus; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
my @virtual_speeds = |
50
|
0
|
|
|
|
|
|
map { $_ ? $_ : undef } |
51
|
0
|
0
|
|
|
|
|
sort { $a <=> $b } |
52
|
|
|
|
|
|
|
uniq |
53
|
0
|
|
|
|
|
|
map { $_->{speed} || 0 } |
54
|
|
|
|
|
|
|
@all_virtual_cpus; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my @cpus; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# process CPUs by groups, according to their speed |
59
|
0
|
|
|
|
|
|
while (@physical_speeds) { |
60
|
0
|
|
|
|
|
|
my $physical_speed = shift @physical_speeds; |
61
|
0
|
|
|
|
|
|
my $virtual_speed = shift @virtual_speeds; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my @physical_cpus = $physical_speed ? |
64
|
0
|
|
|
|
|
|
grep { $_->{speed} eq $physical_speed } @all_physical_cpus: |
65
|
0
|
0
|
|
|
|
|
grep { ! defined $_->{speed} } @all_physical_cpus; |
66
|
0
|
|
|
|
|
|
my @virtual_cpus = $virtual_speed ? |
67
|
0
|
|
|
|
|
|
grep { $_->{speed} eq $virtual_speed } @all_virtual_cpus: |
68
|
0
|
0
|
|
|
|
|
grep { ! defined $_->{speed} } @all_virtual_cpus; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
|
my $speed = $physical_cpus[0]->{speed} || $virtual_cpus[0]->{speed}; |
71
|
0
|
|
0
|
|
|
|
my $type = $physical_cpus[0]->{type} || $virtual_cpus[0]->{type}; |
72
|
0
|
0
|
|
|
|
|
my $manufacturer = |
|
|
0
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$type =~ /SPARC/ ? 'SPARC' : |
74
|
|
|
|
|
|
|
$type =~ /Xeon/ ? 'Intel' : |
75
|
|
|
|
|
|
|
undef ; |
76
|
0
|
|
|
|
|
|
my $cpus = scalar @physical_cpus; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
my ($cores, $threads) = |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$type eq 'UltraSPARC-IV' ? (2, 1) : # US-IV & US-IV+ |
80
|
|
|
|
|
|
|
$type eq 'UltraSPARC-T1' ? (undef, 4) : # Niagara |
81
|
|
|
|
|
|
|
$type eq 'UltraSPARC-T2' ? (undef, 8) : # Niagara-II |
82
|
|
|
|
|
|
|
$type eq 'UltraSPARC-T2+' ? (undef, 8) : # Victoria Falls |
83
|
|
|
|
|
|
|
$type eq 'SPARC-T3' ? (undef, 8) : # Rainbow Falls |
84
|
|
|
|
|
|
|
$type eq 'SPARC64-VI' ? (2, 2) : # Olympus-C SPARC64-VI |
85
|
|
|
|
|
|
|
$type eq 'SPARC64-VII' ? (4, 2) : # Jupiter SPARC64-VII |
86
|
|
|
|
|
|
|
$type eq 'SPARC64-VII+' ? (4, 2) : # Jupiter+ SPARC64-VII+ |
87
|
|
|
|
|
|
|
$type eq 'SPARC64-VII++' ? (4, 2) : # Jupiter++ SPARC64-VII++ |
88
|
|
|
|
|
|
|
$type eq 'SPARC64-VIII' ? (8, 2) : # Venus SPARC64-VIII |
89
|
|
|
|
|
|
|
(1, 1) ; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ($type =~ /MB86907/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$type = "TurboSPARC-II $type"; |
93
|
|
|
|
|
|
|
} elsif ($type =~ /MB86904|390S10/) { |
94
|
0
|
0
|
|
|
|
|
$type = ($speed > 70) ? "microSPARC-II $type" : "microSPARC $type"; |
95
|
|
|
|
|
|
|
} elsif ($type =~ /,RT62[56]/) { |
96
|
0
|
|
|
|
|
|
$type = "hyperSPARC $type"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# deduce core numbers from number of virtual cpus if needed |
100
|
0
|
0
|
|
|
|
|
if (!$cores) { |
101
|
|
|
|
|
|
|
# cores may be < 1 in case of virtualisation |
102
|
0
|
|
|
|
|
|
$cores = (scalar @virtual_cpus) / $threads / $cpus; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
for my $i (1 .. $cpus) { |
106
|
0
|
|
|
|
|
|
push @cpus, |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
MANUFACTURER => $manufacturer, |
109
|
|
|
|
|
|
|
NAME => $type, |
110
|
|
|
|
|
|
|
SPEED => $speed, |
111
|
|
|
|
|
|
|
CORE => $cores, |
112
|
|
|
|
|
|
|
THREAD => $threads |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return @cpus; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _getVirtualCPUs { |
121
|
0
|
|
|
0
|
|
|
my %params = ( |
122
|
|
|
|
|
|
|
command => '/usr/sbin/psrinfo -v', |
123
|
|
|
|
|
|
|
@_ |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
127
|
0
|
0
|
|
|
|
|
return unless $handle; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my @cpus; |
130
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
131
|
0
|
0
|
|
|
|
|
if ($line =~ /The (\S+) processor operates at (\d+) MHz/) { |
132
|
0
|
|
|
|
|
|
push @cpus, { |
133
|
|
|
|
|
|
|
type => $1, |
134
|
|
|
|
|
|
|
speed => $2, |
135
|
|
|
|
|
|
|
}; |
136
|
0
|
|
|
|
|
|
next; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
close $handle; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return @cpus; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _getPhysicalCPUs { |
145
|
0
|
|
|
0
|
|
|
my %params = ( |
146
|
|
|
|
|
|
|
command => '/usr/sbin/psrinfo -vp', |
147
|
|
|
|
|
|
|
@_ |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
151
|
0
|
0
|
|
|
|
|
return unless $handle; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my @cpus; |
154
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
if ($line =~ /^The physical processor has (\d+) virtual/) { |
157
|
0
|
|
|
|
|
|
push @cpus, { |
158
|
|
|
|
|
|
|
count => $1 |
159
|
|
|
|
|
|
|
}; |
160
|
0
|
|
|
|
|
|
next; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
if ($line =~ /^The physical processor has (\d+) cores and (\d+) virtual/) { |
164
|
0
|
|
|
|
|
|
push @cpus, { |
165
|
|
|
|
|
|
|
count => $2 |
166
|
|
|
|
|
|
|
}; |
167
|
0
|
|
|
|
|
|
next; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
if ($line =~ /^The (\S+) physical processor has (\d+) virtual/) { |
171
|
0
|
|
|
|
|
|
push @cpus, { |
172
|
|
|
|
|
|
|
type => $1, |
173
|
|
|
|
|
|
|
count => $2 |
174
|
|
|
|
|
|
|
}; |
175
|
0
|
|
|
|
|
|
next; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
0
|
0
|
|
|
|
|
if ($line =~ /(\S+) \(.* clock (\d+) MHz\)/) { |
179
|
0
|
|
|
|
|
|
my $cpu = $cpus[-1]; |
180
|
0
|
|
|
|
|
|
$cpu->{type} = $1; |
181
|
0
|
|
|
|
|
|
$cpu->{speed} = $2; |
182
|
0
|
|
|
|
|
|
next; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
0
|
0
|
|
|
|
|
if ($line =~ /Intel\(r\) Xeon\(r\) CPU +(\S+)/) { |
186
|
0
|
|
|
|
|
|
my $cpu = $cpus[-1]; |
187
|
0
|
|
|
|
|
|
$cpu->{type} = "Xeon $1"; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
|
close $handle; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return @cpus; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |