How to find the highest clocked CPU core under linux in bash? [closed]

I wonder what clock speed my CPU cores are boosting to. How do I find out under Linux in BASH?

In today’s dynamically boosting CPUs, the clock speed depends on the current workload. Modern games for example are relatively multithreaded, using 6 or 8 cores is common in AAA titles. When I can decide if I use more cores in my own applications, I need to consider how much single-core clock speed I am trading for the extra parallelism.

I can produce arbitrarily multithreaded CPU load like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>stress-ng --cpu 1
</code>
<code>stress-ng --cpu 1 </code>
stress-ng --cpu 1

There is information about the CPU clock in sysfs:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 23
model : 1
model name : AMD Ryzen Threadripper 1950X 16-Core Processor
stepping : 1
microcode : 0x8001137
cpu MHz : 2200.000
cache size : 512 KB
physical id : 0
siblings : 16
core id : 0
cpu cores : 16
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
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 constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid amd_dcm aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev
bugs : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass retbleed smt_rsb srso div0
bogomips : 6799.35
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate eff_freq_ro [13] [14]
[...]
</code>
<code>$ cat /proc/cpuinfo processor : 0 vendor_id : AuthenticAMD cpu family : 23 model : 1 model name : AMD Ryzen Threadripper 1950X 16-Core Processor stepping : 1 microcode : 0x8001137 cpu MHz : 2200.000 cache size : 512 KB physical id : 0 siblings : 16 core id : 0 cpu cores : 16 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 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 constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid amd_dcm aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev bugs : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass retbleed smt_rsb srso div0 bogomips : 6799.35 TLB size : 2560 4K pages clflush size : 64 cache_alignment : 64 address sizes : 43 bits physical, 48 bits virtual power management: ts ttp tm hwpstate eff_freq_ro [13] [14] [...] </code>
$ cat /proc/cpuinfo
processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 23
model       : 1
model name  : AMD Ryzen Threadripper 1950X 16-Core Processor
stepping    : 1
microcode   : 0x8001137
cpu MHz     : 2200.000
cache size  : 512 KB
physical id : 0
siblings    : 16
core id     : 0
cpu cores   : 16
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
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 constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid amd_dcm aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev
bugs        : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass retbleed smt_rsb srso div0
bogomips    : 6799.35
TLB size    : 2560 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate eff_freq_ro [13] [14]
[...]

2

Monitoring cpu frequences:

As a function:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>monitCpuFreq() {
local top=0 lowest freqs init bgcolor delay=${1:-0.1} strtop nl
local -i cRose=217 cPeach=209 cBrYellow=229 cBrGreen=151 cPaleBlue=110 i
while ! read -sn 1 -t $delay _; do
mapfile -t freqs < <(sed -ne '/^cpu .Hz/s/.*: //p' < /proc/cpuinfo |
sort -rn)
(( ${freqs[0]/.} > ${top/.} )) && top=${freqs[0]}
! [[ $lowest ]] || (( ${freqs[-1]/.} < ${lowest/.} )) &&
lowest=${freqs[-1]}
if ! [[ -n $init ]]; then
printf '%.0sn' ${freqs[@]:1}
printf 'e[%dAe7' $(( ${#freqs[@]} -1 ))
init='done'
fi
printf 'e8'
printf -v strtop 'Top: %8.3f Mhz' $top
for i in ${!freqs[@]}; do
(( i == ${#freqs[@]} -1 )) && nl=\r || nl=\n
bgcolor=$(( ${freqs[i]/.*} >= 3675 ? cRose :
${freqs[i]/.*} >= 3275 ? cPeach :
${freqs[i]/.*} >= 2175 ? cBrYellow :
${freqs[i]/.*} >= 1975 ? cBrGreen : cPaleBlue ))
printf 'e[48;5;%dme[30m%s MHze[0m re[16C%s %b'
"$bgcolor" "${freqs[i]}" "$strtop" $nl
strtop=''
done
printf 'e[16CLowest: %8.3f Mhz ' $lowest
done
echo
}
</code>
<code>monitCpuFreq() { local top=0 lowest freqs init bgcolor delay=${1:-0.1} strtop nl local -i cRose=217 cPeach=209 cBrYellow=229 cBrGreen=151 cPaleBlue=110 i while ! read -sn 1 -t $delay _; do mapfile -t freqs < <(sed -ne '/^cpu .Hz/s/.*: //p' < /proc/cpuinfo | sort -rn) (( ${freqs[0]/.} > ${top/.} )) && top=${freqs[0]} ! [[ $lowest ]] || (( ${freqs[-1]/.} < ${lowest/.} )) && lowest=${freqs[-1]} if ! [[ -n $init ]]; then printf '%.0sn' ${freqs[@]:1} printf 'e[%dAe7' $(( ${#freqs[@]} -1 )) init='done' fi printf 'e8' printf -v strtop 'Top: %8.3f Mhz' $top for i in ${!freqs[@]}; do (( i == ${#freqs[@]} -1 )) && nl=\r || nl=\n bgcolor=$(( ${freqs[i]/.*} >= 3675 ? cRose : ${freqs[i]/.*} >= 3275 ? cPeach : ${freqs[i]/.*} >= 2175 ? cBrYellow : ${freqs[i]/.*} >= 1975 ? cBrGreen : cPaleBlue )) printf 'e[48;5;%dme[30m%s MHze[0m re[16C%s %b' "$bgcolor" "${freqs[i]}" "$strtop" $nl strtop='' done printf 'e[16CLowest: %8.3f Mhz ' $lowest done echo } </code>
monitCpuFreq() {
    local top=0 lowest freqs init bgcolor delay=${1:-0.1} strtop nl
    local -i cRose=217 cPeach=209 cBrYellow=229 cBrGreen=151 cPaleBlue=110 i
    while ! read -sn 1 -t $delay _; do
        mapfile -t freqs < <(sed -ne '/^cpu .Hz/s/.*: //p' < /proc/cpuinfo |
                                 sort -rn)
        (( ${freqs[0]/.} > ${top/.} )) && top=${freqs[0]}
        ! [[ $lowest ]] || (( ${freqs[-1]/.} < ${lowest/.} )) &&
            lowest=${freqs[-1]}
        if ! [[ -n $init ]]; then
            printf '%.0sn' ${freqs[@]:1}
            printf 'e[%dAe7' $(( ${#freqs[@]} -1 ))
            init='done'
        fi
        printf 'e8'
        printf -v strtop 'Top:    %8.3f Mhz' $top
        for i in ${!freqs[@]}; do
            (( i == ${#freqs[@]} -1 )) && nl=\r || nl=\n
            bgcolor=$(( ${freqs[i]/.*} >= 3675 ? cRose :
                        ${freqs[i]/.*} >= 3275 ? cPeach :
                        ${freqs[i]/.*} >= 2175 ? cBrYellow :
                        ${freqs[i]/.*} >= 1975 ? cBrGreen : cPaleBlue ))
            printf 'e[48;5;%dme[30m%s MHze[0m re[16C%s %b' 
                   "$bgcolor" "${freqs[i]}" "$strtop" $nl
            strtop=''
        done
        printf 'e[16CLowest: %8.3f Mhz ' $lowest
    done
    echo
}

Will keep lowest and highest frequences:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>2011.592 MHz Top: 3192.718 Mhz
2000.754 MHz
...
1999.129 MHz
1995.587 MHz Lowest: 1197.234 Mhz
</code>
<code>2011.592 MHz Top: 3192.718 Mhz 2000.754 MHz ... 1999.129 MHz 1995.587 MHz Lowest: 1197.234 Mhz </code>
2011.592 MHz    Top:    3192.718 Mhz 
2000.754 MHz     
...
1999.129 MHz     
1995.587 MHz    Lowest: 1197.234 Mhz 

Hit Any key to exit loop!

3

To get a nice list of current CPU speeds, you can filter the content of sysfs using grep and order it using sort get an ordered list of your CPU clock speeds using grep

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>watch 'cat /proc/cpuinfo | grep MHz | sort -rnk 4'
</code>
<code>watch 'cat /proc/cpuinfo | grep MHz | sort -rnk 4' </code>
watch 'cat /proc/cpuinfo | grep MHz | sort -rnk 4'

This creates real-time lists like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>cpu MHz : 3729.014
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2200.000
cpu MHz : 2199.772
cpu MHz : 2199.756
cpu MHz : 2182.517
cpu MHz : 2109.182
</code>
<code>cpu MHz : 3729.014 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2200.000 cpu MHz : 2199.772 cpu MHz : 2199.756 cpu MHz : 2182.517 cpu MHz : 2109.182 </code>
cpu MHz         : 3729.014
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2200.000
cpu MHz         : 2199.772
cpu MHz         : 2199.756
cpu MHz         : 2182.517
cpu MHz         : 2109.182

1

If you are okay with using a script, you can get a color coded list:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/bin/bash
clear
while true; do
line=1
grep 'MHz' /proc/cpuinfo | awk '{printf "%.0fn", $4}'
| sort -rn | while read freq; do
if [ "$freq" -ge 3675 ]; then
bgcolor=217 # Rose (very high)
elif [ "$freq" -ge 3275 ]; then
bgcolor=209 # Peach (high)
elif [ "$freq" -ge 2175 ]; then
bgcolor=229 # bright yellow (medium)
elif [ "$freq" -ge 1975 ]; then
bgcolor=151 # Bright green (medium low)
else
bgcolor=110 # Pale blue (low)
fi
# Move cursor to correct line and print clock
printf "e[%d;1He[48;5;%dme[30m%4d MHze[0m" "$line" "$bgcolor" "$freq"
((line++))
done
# Move cursor below last line
printf "e[%d;1H" "$line"
sleep 0.1
done
</code>
<code>#!/bin/bash clear while true; do line=1 grep 'MHz' /proc/cpuinfo | awk '{printf "%.0fn", $4}' | sort -rn | while read freq; do if [ "$freq" -ge 3675 ]; then bgcolor=217 # Rose (very high) elif [ "$freq" -ge 3275 ]; then bgcolor=209 # Peach (high) elif [ "$freq" -ge 2175 ]; then bgcolor=229 # bright yellow (medium) elif [ "$freq" -ge 1975 ]; then bgcolor=151 # Bright green (medium low) else bgcolor=110 # Pale blue (low) fi # Move cursor to correct line and print clock printf "e[%d;1He[48;5;%dme[30m%4d MHze[0m" "$line" "$bgcolor" "$freq" ((line++)) done # Move cursor below last line printf "e[%d;1H" "$line" sleep 0.1 done </code>
#!/bin/bash

clear
while true; do
    line=1
    grep 'MHz' /proc/cpuinfo | awk '{printf "%.0fn", $4}'
      | sort -rn | while read freq; do
        if [ "$freq" -ge 3675 ]; then
            bgcolor=217  # Rose (very high)
        elif [ "$freq" -ge 3275 ]; then
            bgcolor=209  # Peach (high)
        elif [ "$freq" -ge 2175 ]; then
            bgcolor=229  # bright yellow (medium)
        elif [ "$freq" -ge 1975 ]; then
            bgcolor=151  # Bright green (medium low)
        else
            bgcolor=110  # Pale blue (low)
        fi
        # Move cursor to correct line and print clock
        printf "e[%d;1He[48;5;%dme[30m%4d MHze[0m" "$line" "$bgcolor" "$freq"
        ((line++))
    done
    # Move cursor below last line
    printf "e[%d;1H" "$line"
    sleep 0.1
done

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật