/
CPU.pm
141 lines (115 loc) · 3.61 KB
/
CPU.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package FusionInventory::Agent::Task::Inventory::Input::Solaris::CPU;
use strict;
use warnings;
use English qw(-no_match_vars);
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Solaris;
sub isEnabled {
return 1;
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
my $logger = $params{logger};
# get virtual cpus from psrinfo -v
my @vcpus = _getVirtualCPUs(logger => $logger);
# get physical cpus from psrinfo -vp
my @pcpus = _getPhysicalCPUs(logger => $logger);
# consider all cpus as identical
my $type = $pcpus[0]->{type} || $vcpus[0]->{type};
my $speed = $pcpus[0]->{speed} || $vcpus[0]->{speed};
my $cpus = scalar @pcpus;
my ($cores, $threads) =
$type eq 'UltraSPARC-IV' ? (2, 1) : # US-IV & US-IV+
$type eq 'UltraSPARC-T1' ? (undef, 4) : # Niagara
$type eq 'UltraSPARC-T2' ? (undef, 8) : # Niagara-II
$type eq 'UltraSPARC-T2+' ? (undef, 8) : # Victoria Falls
$type eq 'SPARC-T3' ? (undef, 8) : # Rainbow Falls
$type eq 'SPARC64-VI' ? (2, 2) : # Olympus-C SPARC64-VI
$type eq 'SPARC64-VII' ? (4, 2) : # Jupiter SPARC64-VII
$type eq 'SPARC64-VII+' ? (4, 2) : # Jupiter+ SPARC64-VII+
$type eq 'SPARC64-VII++' ? (4, 2) : # Jupiter++ SPARC64-VII++
$type eq 'SPARC64-VIII' ? (8, 2) : # Venus SPARC64-VIII
(1, 1) ;
if ($type =~ /MB86907/) {
$type = "TurboSPARC-II $type";
} elsif ($type =~ /MB86904|390S10/) {
$type = ($speed > 70) ? "microSPARC-II $type" : "microSPARC $type";
} elsif ($type =~ /,RT62[56]/) {
$type = "hyperSPARC $type";
}
# deduce core numbers from number of virtual cpus if needed
if (!$cores) {
# todo: solaris zone
$cores = (scalar @vcpus) / $threads / $cpus;
}
while ($cpus--) {
$inventory->addEntry(
section => 'CPUS',
entry => {
MANUFACTURER => 'SPARC',
NAME => $type,
SPEED => $speed,
CORE => $cores,
THREAD => $threads
}
);
}
}
sub _getVirtualCPUs {
my %params = (
command => '/usr/sbin/psrinfo -v',
@_
);
my $handle = getFileHandle(%params);
return unless $handle;
my @cpus;
while (my $line = <$handle>) {
if ($line =~ /The (\S+) processor operates at (\d+) MHz/) {
push @cpus, {
type => $1,
speed => $2,
};
next;
}
}
close $handle;
return @cpus;
}
sub _getPhysicalCPUs {
my %params = (
command => '/usr/sbin/psrinfo -vp',
@_
);
my $handle = getFileHandle(%params);
return unless $handle;
my @cpus;
while (my $line = <$handle>) {
if ($line =~ /^The physical processor has (\d+) virtual/) {
push @cpus, {
count => $1
};
next;
}
if ($line =~ /^The (\S+) physical processor has (\d+) virtual/) {
push @cpus, {
type => $1,
count => $2
};
next;
}
if ($line =~ /(\S+) \(.* clock (\d+) MHz\)/) {
my $cpu = $cpus[-1];
$cpu->{type} = $1;
$cpu->{speed} = $2;
next;
}
if ($line =~ /Intel\(r\) Xeon\(r\) CPU +(\S+)/) {
my $cpu = $cpus[-1];
$cpu->{type} = "Xeon $1";
}
}
close $handle;
return @cpus;
}
1;