File: i386.pm

package info (click to toggle)
fusioninventory-agent 1%3A2.3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,636 kB
  • ctags: 1,451
  • sloc: perl: 89,223; xml: 422; sh: 83; python: 26; makefile: 22
file content (129 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download | duplicates (2)
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
package FusionInventory::Agent::Task::Inventory::Linux::Archs::i386;

use strict;
use warnings;

use Config;

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Linux;
use FusionInventory::Agent::Tools::Generic;

sub isEnabled {
    return
        $Config{archname} =~ /^(i\d86|x86_64)/ &&
        (
            -r '/proc/cpuinfo'
        );
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};
    my $logger    = $params{logger};

    foreach my $cpu (_getCPUs(logger => $logger)) {
        $inventory->addEntry(
            section => 'CPUS',
            entry   => $cpu
        );
    }
}

sub _getCPUs {
    my (%params) = @_;

    my @cpusFromDmidecode = $params{dmidecode} ?
        getCpusFromDmidecode(file => $params{dmidecode}) :
        getCpusFromDmidecode();
    my @cpusFromProc      = $params{cpuinfo} ?
        getCPUsFromProc(file => $params{cpuinfo}) :
        getCPUsFromProc();

    my @physicalCPUs = _getPhysicalCPUs(@cpusFromProc);
    my @baseCPUs = @cpusFromDmidecode ?
        @cpusFromDmidecode : @physicalCPUs;

    my $info = $cpusFromProc[-1];

    my $cpt = 0;
    my @cpus;

    foreach my $cpu (@baseCPUs) {

        if ($info->{vendor_id}) {
            $info->{vendor_id} =~ s/Genuine//;
            $info->{vendor_id} =~ s/(TMx86|TransmetaCPU)/Transmeta/;
            $info->{vendor_id} =~ s/CyrixInstead/Cyrix/;
            $info->{vendor_id} =~ s/CentaurHauls/VIA/;
            $info->{vendor_id} =~ s/AuthenticAMD/AMD/;

            $cpu->{MANUFACTURER} = $info->{vendor_id};
        }

        if ($info->{'model name'}) {
            $cpu->{NAME} = $info->{'model name'};
        }

        # Get directly informations from cpuinfo if not already processed
        # in dmidecode
        $cpu->{CORE} = $cpusFromProc[$cpt]{CORE}
            unless $cpu->{CORE};
        $cpu->{THREAD} = $cpusFromProc[$cpt]{THREAD}
            unless $cpu->{THREAD};
        $cpu->{STEPPING} = $cpusFromProc[$cpt]{STEPPING}
            unless $cpu->{STEPPING} ;
        $cpu->{FAMILYNUMBER} = $cpusFromProc[$cpt]{FAMILYNUMBER}
            unless $cpu->{FAMILYNUMBER};
        $cpu->{MODEL} = $cpusFromProc[$cpt]{MODEL}
            unless $cpu->{MODEL};

        if ($cpu->{NAME} =~ /([\d\.]+)s*(GHZ)/i) {
            $cpu->{SPEED} = {
               ghz => 1000,
               mhz => 1,
            }->{lc($2)} * $1;
        }

        $cpu->{ARCH} = 'i386';

        push @cpus, $cpu;
        $cpt++;
    }

    return @cpus;
}

sub _getPhysicalCPUs {
    my (@cpus) = @_;

    my @physical_cpus;
    my %cpus;

    foreach my $cpu (@cpus) {
        my $id = $cpu->{'physical id'};
        if (defined $id) {
            $cpus{$id}{STEPPING}     = $cpu->{'stepping'};
            $cpus{$id}{FAMILYNUMBER} = $cpu->{'cpu family'};
            $cpus{$id}{MODEL}        = $cpu->{'model'};
            $cpus{$id}{CORE}         = $cpu->{'cpu cores'};
            $cpus{$id}{THREAD}       = $cpu->{'siblings'} / ($cpu->{'cpu cores'} || 1);
        } else {
            push @physical_cpus, {
                STEPPING     => $cpu->{'stepping'},
                FAMILYNUMBER => $cpu->{'cpu family'},
                MODEL        => $cpu->{'model'},
                CORE         => 1,
                THREAD       => 1
            }
        }
    }

    # physical id may not start at 0!
    push @physical_cpus, values %cpus if %cpus;

    return @physical_cpus;
}

1;