Skip to contentSkip to conversation

rt-tests: determine_maximum_mpps.sh: Get frequency from timebase-frequency if cpuinfo fails

PATCH In review [email protected] 3 participants 3 messages Nov 11, 2024 – Nov 21, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rt-tests: determine_maximum_mpps.sh: Get frequency from timebase-frequency if cpuinfo fails

From: Tan En De <[email protected]>

If cpu MHz is not listed in /proc/cpuinfo (as in RISC-V Linux), get the frequency from /sys/firmware/devicetree/base/cpus/timebase-frequency.

---
 src/queuelat/determine_maximum_mpps.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/queuelat/determine_maximum_mpps.sh +9 -1
index 733b6b2..adfd809 100755
@@ -42,7 +42,15 @@ usage()
 
 get_cpuinfo_mhz()
 {
-	grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1
+	# Try to determine MHz from /proc/cpuinfo
+	FREQ_MHZ=$(grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1)
+
+	# Try to determine MHz from /sys/firmware/devicetree/base/cpus/timebase-frequency
+	if [ -z $FREQ_MHZ ]; then
+		FREQ_MHZ=$(($((16#$(hexdump -e '1/1 "%02X"' /sys/firmware/devicetree/base/cpus/timebase-frequency)))/1000000))
+	fi
+
+	echo "$FREQ_MHZ"
 }
 
 # Check that the scheduling policy hasn't already been set
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · On Mon, Nov 11, 2024 at 09:49:53AM +0800, [email protected] wrote:

From: Tan En De <[email protected]>

If cpu MHz is not listed in /proc/cpuinfo (as in RISC-V Linux), get the frequency from /sys/firmware/devicetree/base/cpus/timebase-frequency.

---
 src/queuelat/determine_maximum_mpps.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/queuelat/determine_maximum_mpps.sh +9 -1
index 733b6b2..adfd809 100755
@@ -42,7 +42,15 @@ usage()
 
 get_cpuinfo_mhz()
 {
-	grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1
+	# Try to determine MHz from /proc/cpuinfo
+	FREQ_MHZ=$(grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1)
+
+	# Try to determine MHz from /sys/firmware/devicetree/base/cpus/timebase-frequency
+	if [ -z $FREQ_MHZ ]; then
+		FREQ_MHZ=$(($((16#$(hexdump -e '1/1 "%02X"' /sys/firmware/devicetree/base/cpus/timebase-frequency)))/1000000))
+	fi
+
+	echo "$FREQ_MHZ"
 }
 
 # Check that the scheduling policy hasn't already been set
Signature · 1 line
2.34.1
#2 lore raw
In reply to [email protected]
Quoted 36 lines · On Mon, 11 Nov 2024, [email protected] wrote:

From: Tan En De <[email protected]>

If cpu MHz is not listed in /proc/cpuinfo (as in RISC-V Linux), get the frequency from /sys/firmware/devicetree/base/cpus/timebase-frequency.

---
 src/queuelat/determine_maximum_mpps.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/queuelat/determine_maximum_mpps.sh +9 -1
index 733b6b2..adfd809 100755
@@ -42,7 +42,15 @@ usage()
 
 get_cpuinfo_mhz()
 {
-	grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1
+	# Try to determine MHz from /proc/cpuinfo
+	FREQ_MHZ=$(grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1)
+
+	# Try to determine MHz from /sys/firmware/devicetree/base/cpus/timebase-frequency
+	if [ -z $FREQ_MHZ ]; then
+		FREQ_MHZ=$(($((16#$(hexdump -e '1/1 "%02X"' /sys/firmware/devicetree/base/cpus/timebase-frequency)))/1000000))
+	fi
+
+	echo "$FREQ_MHZ"
 }
 
 # Check that the scheduling policy hasn't already been set
Signature · 1 line
2.34.1