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

127
inxi
View file

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