gogoWebsite

Check CPU power consumption under Linux system, and check CPU information under Linux system

Updated to 2 hours ago

View CPU information under Linux system

View CPU information (model):

# cat /proc/cpuinfo| grep name | cut -f2 -d: | uniq -c

8 Intel(R) Xeon(R) CPU           E5410   @ 2.33GHz

(I saw that there are 8 logical CPUs, and I also knew the CPU model)

Check the number of logical CPUs:

#cat /proc/cpuinfo|grep "processor"|sort -u|wc -l

24

Check the number of physical CPUs:

#grep"physical id" /proc/cpuinfo|sort -u|wc-l

2

#grep"physical id" /proc/cpuinfo|sort-u

physical id     : 0

physical id     : 1

Check the number of cores per physical CPU:

#grep "cpucores" /proc/cpuinfo|uniq

cpu cores       : 6

Number of logical CPUs on each physical CPU:

#grep"siblings" /proc/cpuinfo|uniq

siblings        : 12

Determine whether the hyper-copy thread is enabled:

If the "physical id" and "core id" of multiple logical CPUs are the same, it means that hyperthreading is enabled

Or in other words

Number of logical CPUs > Number of physical CPUs * Number of CPU cores enabled Hyperthreading

Number of logical CPUs = Number of physical CPUs * Number of CPU cores not enabled hyperthreading

Query all information at once: 1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19#!/bin/bash

physicalNumber=0

coreNumber=0

logicalNumber=0

HTNumber=0

logicalNumber=$(grep  "processor" /proc/cpuinfo|sort -u|wc -l)

physicalNumber=$(grep  "physical id" /proc/cpuinfo|sort -u|wc -l)

coreNumber=$(grep  "cpu cores" /proc/cpuinfo|uniq|awk -F':' '{print $2}'|xargs)

HTNumber=$((logicalNumber  / (physicalNumber * coreNumber)))

echo "******  CPU Information ******"

echo "Logical  CPU Number  : ${logicalNumber}"

echo "Physical  CPU Number : ${physicalNumber}"

echo "CPU  Core Number     : ${coreNumber}"

echo "HT  Number           :  ${HTNumber}"

echo "*****************************"

Execution results:

#./cpuinfo

****** CPU Information ******

Logical CPU Number  : 24

Physical CPU Number : 2

CPU Core Number     : 6

HT Number           : 2

*****************************