Skip to content

Commit

Permalink
plugins/cpuspeed: fix for Linux kernels with SMT disabled
Browse files Browse the repository at this point in the history
If SMT is disabled there can be 16 cpuXX directories but only first 8 of
them have statistic files. Fix config and fetch to check cpuNN's files
instead of cpu0's files.
  • Loading branch information
kimheino authored and steveschnepp committed Sep 18, 2023
1 parent 435e12a commit 47517b3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions plugins/node.d.linux/cpuspeed
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ if [ "$1" = "config" ]; then
echo "graph_info $graph_info"

for c in /sys/devices/system/cpu/cpu[0-9]*; do
if [ ! -r "$c/cpufreq/stats/time_in_state" ] && [ ! -r "$c/cpufreq/scaling_cur_freq" ]; then
continue
fi

N=${c##*/cpu}

echo "cpu$N.label CPU $N"
Expand Down Expand Up @@ -163,14 +167,14 @@ fi

for c in /sys/devices/system/cpu/cpu[0-9]*; do
N=${c##*/cpu}
if [ IS_RYZEN ] && [ -r "$INTEL_PSTATE_INDICATOR_FILENAME" ]; then
if [ IS_RYZEN ] && [ -r "$c/cpufreq/scaling_cur_freq" ]; then
value=$(cat "$c/cpufreq/scaling_cur_freq")
elif [ -r "$ACPI_CPUFREQ_INDICATOR_FILENAME" ]; then
elif [ -r "$c/cpufreq/stats/time_in_state" ]; then
value=$(awk '{ cycles += $1 * $2 } END { printf("%.0f", cycles / 100); }' "$c/cpufreq/stats/time_in_state")
elif [ -r "$INTEL_PSTATE_INDICATOR_FILENAME" ]; then
elif [ -r "$c/cpufreq/scaling_cur_freq" ]; then
value=$(cat "$c/cpufreq/scaling_cur_freq")
else
value="U"
continue
fi
printf 'cpu%d.value %s\n' "$N" "$value"
done

0 comments on commit 47517b3

Please sign in to comment.