Skip to contentSkip to conversation

queuelat: fix get_cpuinfo_mhz.sh script on SMP systems

PATCH In review Marcelo Tosatti 3 participants 3 messages Jun 20, 2018 – Jun 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 queuelat: fix get_cpuinfo_mhz.sh script on SMP systems

get_cpuinfo_mhz.sh fails on SMP systems because /proc/cpuinfo returns multiple "cpu MHz" containing lines.

Get only the first one.

src/queuelat/get_cpuinfo_mhz.sh +1 -1
index fb5158f..46f94c4 100755
@@ -1,5 +1,5 @@
 #!/bin/bash
 
-mhz=`cat /proc/cpuinfo  | grep "cpu MHz" | uniq | cut -f 3 -d " "`
+mhz=`cat /proc/cpuinfo  | grep "cpu MHz" | uniq | cut -f 3 -d " " | head -1`
 echo $mhz
 
#1 lore raw
Quoted 13 lines · Marcelo Tosatti

get_cpuinfo_mhz.sh fails on SMP systems because /proc/cpuinfo returns multiple "cpu MHz" containing lines.

Get only the first one.

src/queuelat/get_cpuinfo_mhz.sh +0 -0
index fb5158f..46f94c4 100755

src/queuelat/get_cpuinfo_mhz.sh line 3

Quoted 4 lines
src/queuelat/get_cpuinfo_mhz.sh +1 -1
@@ -1,5 +1,5 @@
 #!/bin/bash
 
-mhz=`cat /proc/cpuinfo  | grep "cpu MHz" | uniq | cut -f 3 -d " "`
+mhz=`cat /proc/cpuinfo  | grep "cpu MHz" | uniq | cut -f 3 -d " " | head -1`

Not sure how much it matters here but you can make this more compact by using the '-m' grep option to stop the search after one match, something like:

mhz = cat /proc/cpuinfo | grep -m 1 "cpu MHz" | cut -f 3 -d " "

-Gratian

#2 lore raw
Quoted 16 lines · Gratian Crisan
Quoted 15 lines · Marcelo Tosatti

get_cpuinfo_mhz.sh fails on SMP systems because /proc/cpuinfo returns multiple "cpu MHz" containing lines.

Get only the first one.

src/queuelat/get_cpuinfo_mhz.sh +0 -0
index fb5158f..46f94c4 100755
@@ -1,5 +1,5 @@
 #!/bin/bash
 
Quoted 8 lines

src/queuelat/get_cpuinfo_mhz.sh line 3

Quoted 2 lines
src/queuelat/get_cpuinfo_mhz.sh +1 -1
-mhz=`cat /proc/cpuinfo  | grep "cpu MHz" | uniq | cut -f 3 -d " "`
+mhz=`cat /proc/cpuinfo  | grep "cpu MHz" | uniq | cut -f 3 -d " " | head -1`

Not sure how much it matters here but you can make this more compact by using the '-m' grep option to stop the search after one match, something like:

mhz = cat /proc/cpuinfo | grep -m 1 "cpu MHz" | cut -f 3 -d " "

Want to make it even shorter? Then skip the cat command and grep /proc/cpuinfo directly:
-mhz = `cat /proc/cpuinfo | grep -m 1 "cpu MHz" | cut -f 3 -d " "
+mhz = grep -m 1 "cpu MHz" /proc/cpuinfo | cut -f 3 -d " "

-Carsten