Daniel Bişar
Daniel Bişar

Reputation: 2773

Get processor frequencies

Basically I would like to know a good way to display Informations like CPU frequencies etc. in a nice and easy way. I don't know a good program for linux which shows it in the way i want. So i decided to write a script. But it seems even this is not so easy (my bash knowledge is not very good).

So i would like to get an output like:

Core 1: 800 MHz, Temp: 30 C
Core 2: 1500 MHz, Temp: ...
...

for the first step the MHz would be enough.

How do I get this done the easiest way?

What I have until now:

CpuInfoOutput="$(cat /proc/cpuinfo)"
ProcessorCount="$(echo "${CpuInfoOutput}" | grep processor | tail -1 | grep -o ":.*" | cut -f2- -d: | xargs)"

ProcessorCount=$(expr $ProcessorCount + 1)

echo "CPU Count: ${ProcessorCount}"

for i in $(seq $ProcessorCount)
do
    $ProcessorId = $(expr $i - 1)

    TODO

    echo ${CpuInfoOutput} | grep processor | 
done

Output of cat /proc/cpuinfo

processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 16
model       : 4
model name  : AMD Phenom(tm) II X4 965 Processor
stepping    : 3
microcode   : 0x10000c8
cpu MHz     : 800.000
cache size  : 512 KB
physical id : 0
siblings    : 4
core id     : 0
cpu cores   : 4
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 5
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs        : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips    : 6837.89
TLB size    : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

processor   : 1
vendor_id   : AuthenticAMD
cpu family  : 16
model       : 4
model name  : AMD Phenom(tm) II X4 965 Processor
stepping    : 3
microcode   : 0x10000c8
cpu MHz     : 2200.000
cache size  : 512 KB
physical id : 0
siblings    : 4
core id     : 1
cpu cores   : 4
apicid      : 1
initial apicid  : 1
fpu     : yes
fpu_exception   : yes
cpuid level : 5
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs        : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips    : 6837.89
TLB size    : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

processor   : 2
vendor_id   : AuthenticAMD
cpu family  : 16
model       : 4
model name  : AMD Phenom(tm) II X4 965 Processor
stepping    : 3
microcode   : 0x10000c8
cpu MHz     : 800.000
cache size  : 512 KB
physical id : 0
siblings    : 4
core id     : 2
cpu cores   : 4
apicid      : 2
initial apicid  : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 5
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs        : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips    : 6837.89
TLB size    : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

processor   : 3
vendor_id   : AuthenticAMD
cpu family  : 16
model       : 4
model name  : AMD Phenom(tm) II X4 965 Processor
stepping    : 3
microcode   : 0x10000c8
cpu MHz     : 2200.000
cache size  : 512 KB
physical id : 0
siblings    : 4
core id     : 3
cpu cores   : 4
apicid      : 3
initial apicid  : 3
fpu     : yes
fpu_exception   : yes
cpuid level : 5
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs        : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips    : 6837.89
TLB size    : 1024 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate

EDIT: My solution for now:

#! 

# print processor MHz values
awk -F":" '$1~"processor"{processor=$2+1} $1~"cpu MHz"{print "Processor " processor ":\t" $2 " MHz"}' /proc/cpuinfo

# print GPU clock value
GPU_FREQ=$(awk -F":" '$1~"current engine" {print $2}' /sys/kernel/debug/dri/64/radeon_pm_info)
echo -e "Graphics card:\t$GPU_FREQ"

# print temperatures

CPU_TEMP=$(cat /sys/class/hwmon/hwmon1/device/temp2_input)
GFX_TEMP=$(cat /sys/class/graphics/fb0/device/hwmon/hwmon0/temp1_input)


echo
echo -e "CPU temp:\t$(expr $CPU_TEMP / 1000)" °C
echo -e "Graphics temp:\t$(expr $GFX_TEMP / 1000)" °C

Sample output

Processor 1:     800.000 MHz
Processor 2:     800.000 MHz
Processor 3:     800.000 MHz
Processor 4:     800.000 MHz
Graphics card:   675000 kHz

CPU temp:   35 °C
Graphics temp:  46 °C

Currently really not nice the way i read the GPU frequency. But i did not find any other solution then to use the debug thing from Linux. So i will need root access for the script...

Upvotes: 0

Views: 1160

Answers (2)

buqing
buqing

Reputation: 995

You can try the following commend

grep -w 'processor\|MHz' /proc/cpuinfo | sed 'N;s/\n/,/;s/[\t|:]//g'

In my system, it print out as

processor 0,cpu MHz 2593.993
processor 1,cpu MHz 2593.993
processor 2,cpu MHz 2593.993
processor 3,cpu MHz 2593.993

Upvotes: 1

JNevill
JNevill

Reputation: 50034

I think you'll find awk a better solution for this:

awk -F":" '$1~"processor"{processor=$2+1} $1~"cpu MHz"{print "Processor #" processor " is running at " $2 "mhz"}' /proc/cpuinfo

awk here is splitting the output from /proc/cpuinfo by colon :. If it finds the word "processor" in the first field it stores the value of the second field $2 into variable processor. If it finds the words "cpu MHz` in the first field later on it then prints out the processor from the variable as well as the speed.

On my system:

$ awk -F":" '$1~"processor"{processor=$2+1} $1~"cpu MHz"{print "Processor #" processor " is running at " $2 "mhz"}' /proc/cpuinfo
Processor #1 is running at  2794.500mhz
Processor #2 is running at  1354.500mhz

Upvotes: 2

Related Questions