From ebdc657fa166466d40b6d90f9cf4d4e41f6f7afc Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 2 Sep 2024 16:13:55 -0300 Subject: [PATCH 1/3] benchmark,doc: add CPU scaling governor to perf --- benchmark/cpu.sh | 21 +++++++++++++++++++ .../writing-and-running-benchmarks.md | 10 +++++++++ 2 files changed, 31 insertions(+) create mode 100755 benchmark/cpu.sh diff --git a/benchmark/cpu.sh b/benchmark/cpu.sh new file mode 100755 index 00000000000000..a642c77e567f33 --- /dev/null +++ b/benchmark/cpu.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +CPUPATH=/sys/devices/system/cpu + +MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}') + +set_governor() { + echo "Setting CPU frequency governor to \"$1\"" + for (( i=0; i<=$MAXID; i++ )); do + echo "$1" > $CPUPATH/cpu$i/cpufreq/scaling_governor + done +} + +case "$1" in + fast | performance) + set_governor "performance" + ;; + echo "Usage: $0 fast" + exit 1 + ;; +esac diff --git a/doc/contributing/writing-and-running-benchmarks.md b/doc/contributing/writing-and-running-benchmarks.md index f70ff965a8d7d1..b291e09098990e 100644 --- a/doc/contributing/writing-and-running-benchmarks.md +++ b/doc/contributing/writing-and-running-benchmarks.md @@ -94,6 +94,16 @@ A list of mirrors is [located here](https://cran.r-project.org/mirrors.html). ## Running benchmarks +### Setting CPU Frequency scaling governor to "performance" + +It is recommended to set the CPU frequency to 'performance' before running +benchmarks. This ensures that each benchmark run can achieve peak performance +according to the hardware. Therefore, run: + +```console +$ ./benchmarks/cpu.sh fast +``` + ### Running individual benchmarks This can be useful for debugging a benchmark or doing a quick performance From 036de84a270a397ef7d409de05c86d08c5987a6a Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Mon, 2 Sep 2024 16:27:02 -0300 Subject: [PATCH 2/3] fixup! rewrite from bash to sh --- benchmark/cpu.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/benchmark/cpu.sh b/benchmark/cpu.sh index a642c77e567f33..9c9dd7fa4ddc58 100755 --- a/benchmark/cpu.sh +++ b/benchmark/cpu.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh CPUPATH=/sys/devices/system/cpu @@ -6,8 +6,10 @@ MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}') set_governor() { echo "Setting CPU frequency governor to \"$1\"" - for (( i=0; i<=$MAXID; i++ )); do - echo "$1" > $CPUPATH/cpu$i/cpufreq/scaling_governor + i=0 + while [ "$i" -le "$MAXID" ]; do + echo "$1" > "$CPUPATH/cpu$i/cpufreq/scaling_governor" + i=$((i + 1)) done } @@ -15,6 +17,7 @@ case "$1" in fast | performance) set_governor "performance" ;; + *) echo "Usage: $0 fast" exit 1 ;; From 5b00162c07ea83493b9bf3fce58c82f872630364 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Mon, 2 Sep 2024 18:36:12 -0300 Subject: [PATCH 3/3] Update doc/contributing/writing-and-running-benchmarks.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Nießen --- doc/contributing/writing-and-running-benchmarks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing/writing-and-running-benchmarks.md b/doc/contributing/writing-and-running-benchmarks.md index b291e09098990e..0988480bd98735 100644 --- a/doc/contributing/writing-and-running-benchmarks.md +++ b/doc/contributing/writing-and-running-benchmarks.md @@ -96,8 +96,8 @@ A list of mirrors is [located here](https://cran.r-project.org/mirrors.html). ### Setting CPU Frequency scaling governor to "performance" -It is recommended to set the CPU frequency to 'performance' before running -benchmarks. This ensures that each benchmark run can achieve peak performance +It is recommended to set the CPU frequency to `performance` before running +benchmarks. This increases the likelihood of each benchmark achieving peak performance according to the hardware. Therefore, run: ```console