| | 2060 | # @cpu is a list of reference to hashes, one hash per CPU. |
| | 2061 | # Each entry has the following keys: vendor_id, cpu family, model, |
| | 2062 | # model name and stepping, directly taken from /proc/cpuinfo. |
| | 2063 | use vars qw(@cpu); |
| | 2064 | |
| | 2065 | sub initialize_cpu_list |
| | 2066 | { |
| | 2067 | open(local *INPUTFILE, "/proc/cpuinfo") or die "Can't access /proc/cpuinfo!"; |
| | 2068 | local $_; |
| | 2069 | my %entry; |
| | 2070 | while (<INPUTFILE>) { |
| | 2071 | if (m/^processor\s*:\s*(\d+)/) { |
| | 2072 | push @cpu, \%entry if scalar keys(%entry); # Previous entry |
| | 2073 | %entry = (); # New entry |
| | 2074 | next; |
| | 2075 | } |
| | 2076 | if (m/^(vendor_id|cpu family|model|model name|stepping)\s*:\s*(.+)$/) { |
| | 2077 | my $k = $1; |
| | 2078 | my $v = $2; |
| | 2079 | $v =~ s/\s+/ /g; # Merge multiple spaces |
| | 2080 | $v =~ s/ $//; # Trim trailing space |
| | 2081 | $entry{$k} = $v; |
| | 2082 | next; |
| | 2083 | } |
| | 2084 | } |
| | 2085 | push @cpu, \%entry if scalar keys(%entry); # Last entry |
| | 2086 | close INPUTFILE; |
| | 2087 | } |
| | 2088 | |