Skip to contentSkip to conversation

rt-tests: determine_maximum_mpps.sh: Add a menu to get user settings.

PATCH In review John Kacur 3 participants 6 messages Dec 9, 2020 – Dec 16, 2020 Kbuild

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/3 rt-tests: determine_maximum_mpps.sh: Add a menu to get user settings.

Incorporate the functionality of the get_cpuinfo_mhz.sh script into determine_maximum_mpps.sh so that get_cpuinfo_mhz.sh can be removed.

Currently determine_maximum_mpps.sh (part of queuelat) asks the user to edit the PREAMBLE in the script to set the environment.

Get rid of this by creating a menu that allows the user the set these variables from a menu when running the script.

Here is the output from running the script with the -h option

./src/queuelat/determine_maximum_mpps.sh -h
Usage:
determine_maximum_mpps.sh [OPTIONS]

-c cpulist
List of processors to run on. The default is processor 0 Numbers are separated by commas and may include ranges. Eg. 0,3,7-11
-m maxlat
maximum latency in nanoseconds. The default is 20000
if the maximum is exceeded, that run of queuelat quits
-n cycles
Estimated number of cycles it takes to process one packet The default is 300
-f
Set the scheduling policy to SCHED_FIFO.
This is the default if not specified
-r
Set the scheduling policy to SCHED_RR.
-p priority
default priority = 1. Valid numbers are from 1 to 99
-h
help
print this help message and exit

src/queuelat/determine_maximum_mpps.sh +81 -9
index f785147f1bbd..fdede472728c 100755
@@ -6,12 +6,84 @@
 #  A script to determine the maximum mpps. Logic:
 #  Increase mpps in 0.5 units 
 # 
-# NOTE: please set "PREAMBLE" to the command line you use for 
-# 
-PREAMBLE="taskset -c 2 chrt -f 1"
 MAXLAT="20000"
 CYCLES_PER_PACKET="300"
 OUTFILE=/usr/tmp/outfile
+PRIO=1
+CPULIST=0
+SCHED=""
+
+usage()
+{
+	echo "Usage:"
+	echo "$(basename $0) [OPTIONS]"
+	echo
+	echo "-c cpulist"
+	echo "	List of processors to run on. The default is processor 0"
+	echo "	Numbers are separated by commas and may include ranges. Eg. 0,3,7-11"
+	echo "-m maxlat"
+	echo "	maximum latency in nanoseconds. The default is 20000"
+	echo "	if the maximum is exceeded, that run of queuelat quits"
+	echo "-n cycles"
+	echo "	Estimated number of cycles it takes to process one packet"
+	echo "	The default is 300"
+	echo "-f"
+	echo "	Set the scheduling policy to SCHED_FIFO."
+	echo "	This is the default if not specified"
+	echo "-r"
+	echo "	Set the scheduling policy to SCHED_RR".
+	echo "-p priority"
+	echo "	default priority = 1. Valid numbers are from 1 to 99"
+	echo "-h"
+	echo "	help"
+	echo "	print this help message and exit"
+	exit
+}
+
+get_cpuinfo_mhz()
+{
+	grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1
+}
+
+# Check that the scheduling policy hasn't already been set
+# Exit with an error message if it has
+check_sched()
+{
+	if [ "${SCHED}" != "" ]; then
+		echo "Specify -f or -r, but not both"
+		usage
+	fi
+}
+
+# Process command line options
+while getopts ":c:frp:m:n:h" opt; do
+	case ${opt} in
+		c ) CPULIST="${OPTARG}" ;;
+		m ) MAXLAT="${OPTARG}" ;;
+		n ) CYCLES_PER_PACKET="${OPTARG}" ;;
+		f ) check_sched; SCHED="-f" ;;
+		r ) check_sched; SCHED="-r" ;;
+		p ) PRIO="${OPTARG}" ;;
+		h ) usage ;;
+		* ) echo "no such option"; usage ;;
+	esac
+done
+
+shift $((OPTIND -1 ))
+
+# If the user hasn't specified a scheduling policy
+# then set it to the default SCHED_FIFO
+if [ "${SCHED}" == "" ]; then
+	SCHED="-f"
+fi
+
+# Error checking that the user entered a priority between 1 and 99
+if [[ "${PRIO}" -lt "1" ]] || [[ "${PRIO}" -gt "99" ]]; then
+	echo "PRIO must be a number between 1 and 99"
+	usage
+fi
+
+PREAMBLE="taskset -c ${CPULIST} chrt ${SCHED} ${PRIO}"
 
 echo "Determining maximum mpps the machine can handle"
 echo "Will take a few minutes to determine mpps value"
@@ -21,7 +93,7 @@ for mpps in $(seq 3 3 50); do
 	echo testing "$mpps" Mpps
 
 	OUTFILE=$(mktemp)
-	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(sh get_cpuinfo_mhz.sh)" -p "$mpps" -t 30 > "$OUTFILE"
+	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
 
 	exceeded=$(grep exceeded "$OUTFILE")
 	if [ ! -z "$exceeded" ]; then
@@ -37,7 +109,7 @@ for mpps in $(seq $first_mpps -1 3); do
 	echo testing "$mpps" Mpps
 
 	OUTFILE=$(mktemp)
-	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(sh get_cpuinfo_mhz.sh)" -p "$mpps" -t 30 > "$OUTFILE"
+	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
 
 	exceeded=$(grep exceeded "$OUTFILE")
 	if [ -z "$exceeded" ]; then
@@ -54,7 +126,7 @@ for mpps in $(seq "$second_mpps" 0.3 $first_mpps); do
 	echo testing "$mpps" Mpps
 
 	OUTFILE=$(mktemp)
-	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(sh get_cpuinfo_mhz.sh)" -p "$mpps" -t 30 > "$OUTFILE"
+	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
 
 	exceeded=$(grep exceeded "$OUTFILE")
 	if [ ! -z "$exceeded" ]; then
@@ -71,7 +143,7 @@ for mpps in $(seq "$third_mpps" -0.1 3); do
 	echo testing "$mpps" Mpps
 
 	OUTFILE=$(mktemp)
-	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(sh get_cpuinfo_mhz.sh)" -p "$mpps" -t 30 > "$OUTFILE"
+	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
 
 	exceeded=$(grep exceeded "$OUTFILE")
 	if [ -z "$exceeded" ]; then
@@ -90,7 +162,7 @@ while [ $queuelat_failure == 1 ]; do
 	echo "$mpps Mpps"
 
 	for i in $(seq 1 10); do
-		$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz.sh)" -p "$mpps" -t 30 > "$OUTFILE"
+		$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 30 > "$OUTFILE"
 		exceeded=$(grep exceeded "$OUTFILE")
 
 		if [ ! -z "$exceeded" ]; then
@@ -113,7 +185,7 @@ while [ $queuelat_failure == 1 ]; do
 	echo -n "Starting 10 minutes run with "
 	echo "$mpps Mpps"
 
-	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz.sh)" -p "$mpps" -t 600 > "$OUTFILE"
+	$PREAMBLE queuelat -m $MAXLAT -c $CYCLES_PER_PACKET -f "$(get_cpuinfo_mhz)" -p "$mpps" -t 600 > "$OUTFILE"
 	exceeded=$(grep exceeded "$OUTFILE")
 
 	if [ ! -z "$exceeded" ]; then
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH 2/3 rt-tests: queuelat: Remove get_cpuinfo_mhz.sh and old Makefile

The functionality in get_cpuinfo_mhz.sh has been incorporated into determine_maximum_mpps.sh, so it can safely be removed.

The queuelat is built from the rt-tests suite Makefile, and the old Makefile in the queuelat directory can be removed.

Makefile +0 -1
index 3b38d21afb3a..d5b14991032d 100644
@@ -209,7 +209,6 @@ rebuild:
 install: all install_manpages install_hwlatdetect install_get_cyclictest_snapshot
 	mkdir -p "$(DESTDIR)$(bindir)"
 	cp $(TARGETS) "$(DESTDIR)$(bindir)"
-	install src/queuelat/get_cpuinfo_mhz.sh "$(DESTDIR)$(bindir)"
 	install src/queuelat/determine_maximum_mpps.sh "${DESTDIR}${bindir}"
 
 .PHONY: install_hwlatdetect
src/queuelat/Makefile deleted +0 -9
deleted file mode 100644
index b4d327829b17..000000000000
@@ -1,9 +0,0 @@
-queuelat: queuelat.o
-	cc -o queuelat queuelat.o
-
-queuelat.o: queuelat.c
-	cc -c -Wall queuelat.c
-
-clean:
-	rm queuelat queuelat.o
-          
src/queuelat/get_cpuinfo_mhz.sh deleted +0 -7
deleted file mode 100755
index 14a2c12c478f..000000000000
@@ -1,7 +0,0 @@
-#!/bin/bash
-
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (C) 2018 Marcelo Tosatti <[email protected]>
-
-mhz=$(grep "cpu MHz" /proc/cpuinfo | cut -f 3 -d " " | sort -rn | head -n1)
-echo "$mhz"
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH 3/3 rt-tests: queuelat: Add a manpage for determine_maximum_mpps.sh

In reply to John Kacur

Add a manpage for determine_maximum_mpps.sh

Makefile +1 -0
index d5b14991032d..fba4546ac50a 100644
@@ -52,6 +52,7 @@ MANPAGES = src/cyclictest/cyclictest.8 \
 	   src/signaltest/signaltest.8 \
 	   src/pi_tests/pip_stress.8 \
 	   src/queuelat/queuelat.8 \
+	   src/queuelat/determine_maximum_mpps.8 \
 	   src/sched_deadline/deadline_test.8 \
 	   src/ssdd/ssdd.8 \
 	   src/sched_deadline/cyclicdeadline.8 \
src/queuelat/determine_maximum_mpps.8 new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
2.26.2
#3 lore raw
In reply to John Kacur

Hi John,

Quoted 11 lines · John Kacur

Incorporate the functionality of the get_cpuinfo_mhz.sh script into determine_maximum_mpps.sh so that get_cpuinfo_mhz.sh can be removed.

Currently determine_maximum_mpps.sh (part of queuelat) asks the user to edit the PREAMBLE in the script to set the environment.

Get rid of this by creating a menu that allows the user the set these variables from a menu when running the script.

Here is the output from running the script with the -h option

Quoted 7 lines

./src/queuelat/determine_maximum_mpps.sh -h
Usage:
determine_maximum_mpps.sh [OPTIONS]

-c cpulist
List of processors to run on. The default is processor 0 Numbers are separated by commas and may include ranges. Eg. 0,3,7-11

Does the option also do CPU affinity. In this case I would suggest to use '-a' to go with the pattern.

What about long options? Long options are propably a bit harder to implement in shell but it would be good in my opinion to keep all those tests commands as close as possible.

Thanks,
Daniel

author
#4 lore raw
Quoted 25 lines · Daniel Wagner

Hi John,

Quoted 11 lines · John Kacur

Incorporate the functionality of the get_cpuinfo_mhz.sh script into determine_maximum_mpps.sh so that get_cpuinfo_mhz.sh can be removed.

Currently determine_maximum_mpps.sh (part of queuelat) asks the user to edit the PREAMBLE in the script to set the environment.

Get rid of this by creating a menu that allows the user the set these variables from a menu when running the script.

Here is the output from running the script with the -h option

Quoted 7 lines

./src/queuelat/determine_maximum_mpps.sh -h
Usage:
determine_maximum_mpps.sh [OPTIONS]

-c cpulist
List of processors to run on. The default is processor 0 Numbers are separated by commas and may include ranges. Eg. 0,3,7-11

Does the option also do CPU affinity. In this case I would suggest to use '-a' to go with the pattern.

Quoted 8 lines

What about long options? Long options are propably a bit harder to implement in shell but it would be good in my opinion to keep all those tests commands as close as possible.

Thanks,
Daniel

The script is using taskset to set the cpu affinity, and so it uses -c to match the option in taskset. However the script also uses taskset to run queuelat which uses -c to mean cycles-per-packet.

I am fine with changing this option to -a to match cyclictest and other tests in the suite. I'll send a patch to do that.

Yeah, long options are a PITA in shell script, I think I might just convert the script to python where command line options are a breeze.

That will come in a later patch.

John

#5 lore raw
Quoted 1 line · John Kacur

On Mon, 14 Dec 2020, Daniel Wagner wrote:

...

Quoted 5 lines
Quoted 5 lines

What about long options? Long options are propably a bit harder to implement in shell but it would be good in my opinion to keep all those tests commands as close as possible.

...

Quoted 4 lines

Yeah, long options are a PITA in shell script, I think I might just convert the script to python where command line options are a breeze.

Just a FYI, it's quite O.K. when using util-linux getopt(1) instead of bash's getopts builtin.

thanks,

--
Ahmed S. Darwish
Linutronix GmbH