Updated and hopefully simplified the get_cpu<data>. We no longer care what the numbers are, all we do is count unique ids. Now we ignore the id identifier number, since the new i series from Intel either kills a logical processor or ships flawed quad cores as dual or dual HT, maybe even tri-core sometime. The new logic only cares about the number of cores, the number of physical processors, and the number of virtual processors.

This commit is contained in:
trash80.v2.0 2010-07-24 18:04:14 +00:00
parent 7df3311080
commit a97f8d6b54

133
inxi
View file

@ -1,8 +1,8 @@
#!/bin/bash
########################################################################
#### Script Name: inxi
#### version: 1.4.10
#### Date: June 10 2010
#### version: 1.4.11
#### Date: Jule 24 2010
########################################################################
#### SPECIAL THANKS
########################################################################
@ -2018,11 +2018,7 @@ get_cpu_ht_multicore_smp_data()
{
eval $LOGFS
# in /proc/cpuinfo
# algorithm
# if > 1 processor && processor id (physical id) == core id then Hyperthreaded (HT)
# if > 1 processor && different processor ids then Multiple Processors (SMP)
# if > 1 processor && processor id != core id then Multi-Core Processors (MCP)
# if = 1 processor then single core/processor Uni-Processor (UP)
if [[ $B_CPUINFO_FILE == 'true' ]]; then
A_CPU_TYPE_PCNT_CCNT=( $(
@ -2030,83 +2026,86 @@ get_cpu_ht_multicore_smp_data()
BEGIN {
FS=": "
IGNORECASE = 1
core_count = 0
holder = 0
i = 0
index_temp = ""
num_of_cores = 0
physical_cpu_count = 0
processor_logical_count = 0
processors = 1
type = "UP"
num_of_processors = 0
num_of_cpus = 0
core_id[0]
processor_id[0]
cpu_id[0]
type = "-"
iter = 0
}
# counts logical processors, both HT and physical
# array of logical processors, both HT and physical
/^processor/ {
processor_logical_count = $NF + 1
}
# counts physical cores (not used currently)
/^cpu cores/ {
num_of_cores = $NF
processor_id[iter] = $NF
}
# array of physical cpus ids
/^physical/ {
a_physical_id[i] = $NF
cpu_id[iter] = $NF
}
# array of core ids
/^core id/ {
a_core_id[i] = $NF
i++
core_id[iter] = $NF
iter++
}
END {
# look for the largest id number, and assign it (dumped this method due intel)
# note that there are some cases, intel i5 core 2 HT where core_id shows
# as 0/2, not 0/1. this triggers a 3 core output, erroneously.
# Sorting the data solves this, since the counter now is mechanical, not
# trusting the data from the proc/cpuinfo at all re what the core id is
asort(a_core_id)
# awk increments j++ counter BEFORE the loop?
for ( j = 0; j <= processor_logical_count; j++ ) {
# if ( j in a_core_id && a_core_id[j] > core_count ) {
if ( j in a_core_id ) {
#core_count = a_core_id[j]
if ( a_core_id[j] != holder ){
core_count++
holder = a_core_id[j]
}
}
}
core_count = core_count + 1
## Look thru the array and filter same numbers.
## only unique numbers required
## this is to get an accurate count
## we are only concerned with array length
# trick, set the index equal to value, if the same, it will overwrite
# this lets us create the actual array of true cpu physical ids
for ( j in a_physical_id ) {
index_temp = a_physical_id[j]
a_cpu_physical_working[index_temp] = a_physical_id[j]
i = 0
## count unique processors ##
for ( i in processor_id ) {
procHolder[processor_id[i]] = 1
}
# note that length() is a gawk >= 3.1.5 only method, better to do it manually
for ( j in a_cpu_physical_working ) {
++physical_cpu_count
for ( i in procHolder ) {
num_of_processors++
}
# looking at logical processor counts over 1, which means either HT, SMP or MCP
# http://en.wikipedia.org/wiki/Symmetric_multiprocessing
if ( processor_logical_count > 1 && core_count > 1 ) {
if ( processor_logical_count > core_count && physical_cpu_count > 1 ) {
type = "SMP-HT" # could be Xeon/P4 HT dual cpu
}
else if ( processor_logical_count > core_count ) {
type = "HT" # this is more than likely a P4 w/HT or an Atom 270
}
else {
type = "SMP"
}
i = 0
## count unique physical cpus ##
for ( i in cpu_id ) {
cpuHolder[cpu_id[i]] = 1
}
# make sure to handle up cpus too
else {
core_count = 1
physical_cpu_count = 1
for ( i in cpuHolder ) {
num_of_cpus++
}
print type " " physical_cpu_count " " core_count
i = 0
## count unique cores ##
for ( i in core_id ) {
coreHolder[core_id[i]] = 1
}
for ( i in coreHolder ) {
num_of_cores++
}
####################################################################
# algorithm
# if > 1 processor && processor id (physical id) == core id then Hyperthreaded (HT)
# if > 1 processor && processor id (physical id) != core id then Multi-Core Processors (MCP)
# if > 1 processor && processor ids (physical id) > 1 then Multiple Processors (SMP)
# if = 1 processor then single core/processor Uni-Processor (UP)
if ( num_of_processors > 1 )
{
if ( num_of_processors == (num_of_cores * 2 ))
{
type = type "HT-"
}
if ( num_of_processors >= num_of_cores )
{
type = type "MCP-"
}
if ( num_of_cpus > 1 )
{
type = type "SMP-"
}
} else {
type = type "UP-"
}
print type " " num_of_cpus " " num_of_cores
}
' $FILE_CPUINFO
) )