#!/usr/bin/perl # CheckProcs.pl - a script to verify that the system is running a # kernel which matches the installed CPUs and that hyperthreading is # turned off. Only for Linux. # # Phil Hollenback (philiph_at_pobox_dot_com) # Telemetry Investments # 6/18/04 `id -u` == 0 || die "must be run as root"; open(DmiFh, "/usr/sbin/dmidecode |") or die "problem running dmidecode"; $DmiNumProcs = 0; $DmiNumSockets = 0; while() { next unless /Central Processor/; # We've found a processor (or at least a socket), keep going while() { # Keep walking the dmidecode output to find out if # the socket has a processor in it. last if /^Handle/; next unless /Status/; $DmiNumSockets += 1; /Populated/ and $DmiNumProcs += 1; last; } } close DmiFh; # Redirect x86info stderr to stdout because it always tries # to use /dev/cpu/0/cpuid device, which doesn't work unless you load # the cpuid driver. We don't need that because we don't care about # cpuid putput. open(x86Fh, "/usr/sbin/x86info 2>&1 |") or die "problem running x86info"; $x86NumProcs = 0; $x86NumHyper = 0; while() { /Found.*CPU/ and ($x86NumProcs) = (/Found (\d+) CPU/); /The physical package/ and ($x86NumHyper) = (/The physical package supports (\d+) logical processors/); } open(CpuInfoFh, "/proc/cpuinfo") || die "failed to open /proc/cpuinfo!"; $CpuInfoNumProcs = 0; while() { next unless /^processor.*:/; ($CpuInfoNumProcs) += (/^processor.*: (\d+)/); } close CpuInfoFh; if ( $DmiNumProcs != $x86NumProcs ) { print "Warning: dmidecode reports $DmiNumProcs processors, x86info reports $x86NumProcs processors.\n"; } if ( $DmiNumProcs != $CpuInfoNumProcs ) { print "Warning: dmidecode reports $DmiNumProcs processors, kernel reports $CpuInfoNumProcs processors.\n"; } if ( $DmiNumProcs != $DmiNumSockets ) { print "Info: dmidecode reports $DmiNumSockets cpu sockets, but only $DmiNumProcs processors.\n"; } if ( $x86NumHyper > 1 ) { print "Warning: hyperthreading is enabled.\n"; }