From 18e31433bd49dfb95c0c1c7e23765bde8cd3650a Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 15 Oct 2006 08:46:36 +0000 Subject: [PATCH] Parse /proc/cpuinfo and build a list of CPU from it. This will make it possible to suggest hardware monitoring drivers based of CPU ID. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@4209 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/detect/sensors-detect | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index e979496c..6eee1549 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2057,6 +2057,35 @@ sub kernel_version_at_least return 0; } +# @cpu is a list of reference to hashes, one hash per CPU. +# Each entry has the following keys: vendor_id, cpu family, model, +# model name and stepping, directly taken from /proc/cpuinfo. +use vars qw(@cpu); + +sub initialize_cpu_list +{ + open(local *INPUTFILE, "/proc/cpuinfo") or die "Can't access /proc/cpuinfo!"; + local $_; + my %entry; + while () { + if (m/^processor\s*:\s*(\d+)/) { + push @cpu, \%entry if scalar keys(%entry); # Previous entry + %entry = (); # New entry + next; + } + if (m/^(vendor_id|cpu family|model|model name|stepping)\s*:\s*(.+)$/) { + my $k = $1; + my $v = $2; + $v =~ s/\s+/ /g; # Merge multiple spaces + $v =~ s/ $//; # Trim trailing space + $entry{$k} = $v; + next; + } + } + push @cpu, \%entry if scalar keys(%entry); # Last entry + close INPUTFILE; +} + ########### # MODULES # ########### @@ -5282,6 +5311,7 @@ sub main initialize_modules_list; initialize_modules_supported; initialize_kernel_version; + initialize_cpu_list(); print "# sensors-detect revision $revision\n\n";