Plasmoide CPU Frequency Control: governor, limiti, EPP, boost e profili per task
Widget KDE Plasma 6 (org.enne2.cpufreq) per pilotare il profilo energetico della CPU: governor, limiti min/max, energy_performance_preference, boost/turbo, quattro profili pronti (Silenzioso, Risparmio, Bilanciato, Performance) e task con profilo dedicato che ripristina lo stato precedente alla fine del comando. Privilegi separati: il widget resta non privilegiato e l'unica operazione root passa da un helper a interfaccia ristretta in /usr/local/libexec/enne2-cpufreq/ (comandi a elenco chiuso, argomenti validati su sysfs, rilettura di verifica), invocato via pkexec con l'azione polkit dedicata org.enne2.cpufreq.set. La regola in /etc/polkit-1/rules.d/ concede il consenso senza prompt a utenti locali in sessione attiva nel gruppo wheel; senza la regola la policy chiede la password. Dettagli verificati su frigate (Plasma 6.7.5, kernel 7.2, amd-pstate-epp): - con boost disattivato cpuinfo_max_freq scende alla frequenza nominale, quindi il tetto hardware si legge da amd_pstate_max_freq e i profili applicano il boost prima dei limiti; - scrittura dei limiti in ordine sicuro (mai min > max intermedio); - baseline e contatore di riferimento per i task paralleli; - syncControls protetto da uiReady e try/catch: un ReferenceError su un id della rappresentazione non deve interrompere l'aggiornamento dello stato; - implicitWidth/Height costanti, altrimenti il containment riduce il widget a 68x68. Include install.sh/uninstall.sh (widget, backend, dry-run), README con modello di sicurezza e diagnostica, screenshot docs/widget.png. Licenza MIT.
This commit is contained in:
Executable
+175
@@ -0,0 +1,175 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: MIT
|
||||
# enne2-cpufreq — lettore di stato NON privilegiato per il plasmoide.
|
||||
# Legge solo attributi world-readable di sysfs, /proc e hwmon; non scrive nulla.
|
||||
# Uscita: righe key=value (formato usato dagli altri widget org.enne2.*).
|
||||
set -u
|
||||
|
||||
SELF_DIR=$(dirname "$0")
|
||||
if [ -r "$SELF_DIR/profiles.sh" ]; then
|
||||
# shellcheck source=profiles.sh
|
||||
. "$SELF_DIR/profiles.sh"
|
||||
else
|
||||
printf 'helper=missing\nerror=profiles.sh mancante\n'
|
||||
exit 2
|
||||
fi
|
||||
|
||||
CPUFREQ=/sys/devices/system/cpu/cpufreq
|
||||
HELPER=/usr/local/libexec/enne2-cpufreq/cpufreq-helper
|
||||
POLICY_POLKIT=/usr/share/polkit-1/actions/org.enne2.cpufreq.set.policy
|
||||
RULE_POLKIT=/etc/polkit-1/rules.d/50-org.enne2.cpufreq.rules
|
||||
CONF_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/enne2-cpufreq
|
||||
TASKS=$CONF_DIR/tasks.json
|
||||
RUN=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/enne2-cpufreq
|
||||
|
||||
readf() {
|
||||
[ -r "$1" ] || return 1
|
||||
_val=
|
||||
IFS= read -r _val < "$1" 2>/dev/null || [ -n "$_val" ] || return 1
|
||||
printf '%s\n' "$_val"
|
||||
}
|
||||
|
||||
policies() {
|
||||
for _p in "$CPUFREQ"/policy[0-9]*; do
|
||||
[ -d "$_p" ] && printf '%s\n' "$_p"
|
||||
done
|
||||
}
|
||||
|
||||
attr_values() {
|
||||
for _p in $(policies); do
|
||||
readf "$_p/$1"
|
||||
done | sort -u | tr '\n' ' ' | sed 's/ *$//'
|
||||
}
|
||||
|
||||
p0=$(policies | head -n 1)
|
||||
if [ -z "$p0" ]; then
|
||||
printf 'helper=missing\nerror=nessuna policy cpufreq (driver non cpufreq?)\n'
|
||||
exit 2
|
||||
fi
|
||||
|
||||
driver=$(readf "$p0/scaling_driver" || echo unknown)
|
||||
hw_min=$(readf "$p0/cpuinfo_min_freq" || echo 0)
|
||||
hw_max=$(cf_hw_max_khz "$p0") # indipendente dallo stato del boost
|
||||
floor=$(readf "$p0/amd_pstate_lowest_nonlinear_freq" || echo "")
|
||||
[ -n "$floor" ] && [ "$floor" -gt "$hw_min" ] || floor=$hw_min
|
||||
min_khz=$(readf "$p0/scaling_min_freq" || echo 0)
|
||||
max_khz=$(readf "$p0/scaling_max_freq" || echo 0)
|
||||
governor=$(attr_values scaling_governor)
|
||||
governors=$(readf "$p0/scaling_available_governors" || echo "")
|
||||
epp=$(attr_values energy_performance_preference)
|
||||
epps=$(readf "$p0/energy_performance_available_preferences" || echo "")
|
||||
epp_supported=0
|
||||
[ -n "$epps" ] && epp_supported=1
|
||||
|
||||
# boost: per-policy (kernel recenti) → globale → intel_pstate/no_turbo invertito
|
||||
boost=$(readf "$p0/boost" || readf "$CPUFREQ/boost" || echo "")
|
||||
boost_supported=0
|
||||
[ -n "$boost" ] && boost_supported=1
|
||||
if [ "$boost_supported" -eq 0 ] && [ -r /sys/devices/system/cpu/intel_pstate/no_turbo ]; then
|
||||
_nt=$(readf /sys/devices/system/cpu/intel_pstate/no_turbo)
|
||||
[ "$_nt" = "1" ] && boost=0 || boost=1
|
||||
boost_supported=1
|
||||
fi
|
||||
|
||||
# frequenza istantanea: massima fra le policy (core più attivo) e media
|
||||
sum=0
|
||||
cnt=0
|
||||
curmax=0
|
||||
for _p in $(policies); do
|
||||
_f=$(readf "$_p/scaling_cur_freq") || continue
|
||||
case "$_f" in ''|*[!0-9]*) continue ;; esac
|
||||
sum=$((sum + _f))
|
||||
cnt=$((cnt + 1))
|
||||
[ "$_f" -gt "$curmax" ] && curmax=$_f
|
||||
done
|
||||
[ "$cnt" -gt 0 ] || cnt=1
|
||||
cur_avg=$((sum / cnt))
|
||||
|
||||
temp=$(readf /sys/class/hwmon/hwmon0/temp1_input 2>/dev/null || echo "")
|
||||
for _h in /sys/class/hwmon/hwmon*; do
|
||||
[ -r "$_h/name" ] || continue
|
||||
case "$(readf "$_h/name")" in
|
||||
k10temp|coretemp|zenpower)
|
||||
temp=$(readf "$_h/temp1_input" || echo "")
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
model=$(sed -n 's/^model name[[:space:]]*: //p' /proc/cpuinfo | head -n 1)
|
||||
load1=$(awk '{print $1}' /proc/loadavg)
|
||||
|
||||
helper_state=missing
|
||||
[ -x "$HELPER" ] && helper_state=ok
|
||||
polkit_state=missing
|
||||
if [ -r "$POLICY_POLKIT" ] && [ -r "$RULE_POLKIT" ]; then
|
||||
polkit_state=ok
|
||||
elif [ -r "$POLICY_POLKIT" ]; then
|
||||
polkit_state=ask
|
||||
fi
|
||||
|
||||
conflicts=""
|
||||
for _svc in tuned power-profiles-daemon tlp; do
|
||||
if systemctl is-active --quiet "$_svc" 2>/dev/null; then
|
||||
conflicts="$conflicts $_svc"
|
||||
fi
|
||||
done
|
||||
conflicts=${conflicts# }
|
||||
|
||||
profile=$(cf_detect_profile "${governor:-}" "${epp:-}" "${boost:-0}" "$max_khz" "$floor" "$hw_max")
|
||||
printf 'driver=%s\n' "$driver"
|
||||
printf 'mode=%s\n' "$(readf /sys/devices/system/cpu/amd_pstate/status || echo n/a)"
|
||||
printf 'model=%s\n' "$model"
|
||||
printf 'policies=%s\n' "$cnt"
|
||||
printf 'governor=%s\n' "$governor"
|
||||
printf 'governors=%s\n' "$governors"
|
||||
printf 'epp=%s\n' "$epp"
|
||||
printf 'epps=%s\n' "$epps"
|
||||
printf 'epp_supported=%s\n' "$epp_supported"
|
||||
printf 'boost=%s\n' "$boost"
|
||||
printf 'boost_supported=%s\n' "$boost_supported"
|
||||
printf 'hw_min_khz=%s\n' "$hw_min"
|
||||
printf 'hw_max_khz=%s\n' "$hw_max"
|
||||
printf 'floor_khz=%s\n' "$floor"
|
||||
printf 'min_khz=%s\n' "$min_khz"
|
||||
printf 'max_khz=%s\n' "$max_khz"
|
||||
printf 'cur_khz=%s\n' "$curmax"
|
||||
printf 'cur_avg_khz=%s\n' "$cur_avg"
|
||||
printf 'temp_mdegc=%s\n' "$temp"
|
||||
printf 'load1=%s\n' "$load1"
|
||||
printf 'profile=%s\n' "$profile"
|
||||
printf 'profile_label=%s\n' "$(cf_profile_label "$profile")"
|
||||
printf 'helper=%s\n' "$helper_state"
|
||||
printf 'polkit=%s\n' "$polkit_state"
|
||||
printf 'conflicts=%s\n' "$conflicts"
|
||||
[ -r /var/lib/enne2-cpufreq/baseline ] && printf 'baseline=present\n' || printf 'baseline=absent\n'
|
||||
|
||||
# ---- task configurati (un file JSON gestito da enne2-cpufreq-task) ----------
|
||||
# Formato di ogni riga: task=<indice> <TAB> <running 0|1> <TAB> <oggetto JSON>
|
||||
# Il JSON (jq -c, una riga) evita ogni ambiguità su spazi, tabulazioni e pipe
|
||||
# dentro i comandi definiti dall'utente.
|
||||
if command -v jq >/dev/null 2>&1 && [ -r "$TASKS" ]; then
|
||||
_count=$(jq -r '.tasks | length' "$TASKS" 2>/dev/null || echo 0)
|
||||
printf 'task_count=%s\n' "${_count:-0}"
|
||||
_i=0
|
||||
jq -c '.tasks[] | {name: .name, profile: .profile, command: .command, slug: .slug}' \
|
||||
"$TASKS" 2>/dev/null |
|
||||
while IFS= read -r _line; do
|
||||
[ -n "$_line" ] || continue
|
||||
_slug=$(printf '%s' "$_line" | jq -r '.slug // ""' 2>/dev/null)
|
||||
_running=0
|
||||
if [ -n "$_slug" ] && [ -r "$RUN/$_slug.pid" ]; then
|
||||
_pid=$(readf "$RUN/$_slug.pid")
|
||||
case "$_pid" in
|
||||
''|*[!0-9]*) _running=0 ;;
|
||||
*) kill -0 "$_pid" 2>/dev/null && _running=1 ;;
|
||||
esac
|
||||
fi
|
||||
printf 'task=%s\t%s\t%s\n' "$_i" "$_running" "$_line"
|
||||
_i=$((_i + 1))
|
||||
done
|
||||
else
|
||||
printf 'task_count=0\n'
|
||||
fi
|
||||
|
||||
printf 'ts=%s\n' "$(date +%s)"
|
||||
Executable
+274
@@ -0,0 +1,274 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: MIT
|
||||
# enne2-cpufreq-task — launcher di task con profilo CPU dedicato.
|
||||
#
|
||||
# Gira SEMPRE come utente: il comando del task non viene mai eseguito come root.
|
||||
# Solo il cambio di profilo passa dall'helper privilegiato via pkexec.
|
||||
#
|
||||
# Flusso di "run":
|
||||
# 1. helper task-begin <profilo> → salva la baseline (una sola volta) e applica
|
||||
# 2. il comando parte staccato (setsid) e scrive il proprio pid nel file di stato
|
||||
# 3. un watcher staccato attende l'uscita del pid e chiama helper task-end, che
|
||||
# ripristina la baseline quando non ci sono altri task attivi
|
||||
#
|
||||
# Il plasmoide invoca "add-hex" con gli argomenti codificati in esadecimale
|
||||
# (UTF-8): così nomi, comandi con spazi, virgolette o newline attraversano
|
||||
# l'exec engine di Plasma senza dipendere dal parsing delle virgolette.
|
||||
set -u
|
||||
|
||||
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
|
||||
export PATH
|
||||
|
||||
SELF_DIR=$(dirname "$0")
|
||||
HELPER=/usr/local/libexec/enne2-cpufreq/cpufreq-helper
|
||||
CONF_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/enne2-cpufreq
|
||||
TASKS=$CONF_DIR/tasks.json
|
||||
RUN=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/enne2-cpufreq
|
||||
|
||||
mkdir -p "$CONF_DIR" "$RUN" 2>/dev/null
|
||||
|
||||
fail() {
|
||||
printf 'ok=0\nerror=%s\n' "$*"
|
||||
exit 2
|
||||
}
|
||||
|
||||
readf() {
|
||||
[ -r "$1" ] || return 1
|
||||
_val=
|
||||
IFS= read -r _val < "$1" 2>/dev/null || [ -n "$_val" ] || return 1
|
||||
printf '%s\n' "$_val"
|
||||
}
|
||||
|
||||
# Decodifica esadecimale UTF-8 senza dipendenze (xxd/od non sempre presenti).
|
||||
hex_decode() {
|
||||
[ -n "${1:-}" ] || return 0
|
||||
case "$1" in *[!0-9a-fA-F]*) fail "payload esadecimale non valido" ;; esac
|
||||
_esc=$(printf '%s' "$1" | sed 's/\(..\)/\\x\1/g')
|
||||
printf '%b' "$_esc"
|
||||
}
|
||||
|
||||
need_jq() {
|
||||
command -v jq >/dev/null 2>&1 || fail "jq non installato (serve per gestire tasks.json)"
|
||||
}
|
||||
|
||||
init_tasks() {
|
||||
[ -r "$TASKS" ] && return 0
|
||||
printf '{"version":1,"tasks":[]}\n' > "$TASKS" || fail "impossibile creare $TASKS"
|
||||
}
|
||||
|
||||
slugify() {
|
||||
printf '%s' "$1" | tr 'A-Z' 'a-z' | tr -c 'A-Za-z0-9._-' '-' \
|
||||
| sed -e 's/--*/-/g' -e 's/^-//' -e 's/-$//'
|
||||
}
|
||||
|
||||
# Accetta indifferentemente il nome visualizzato o lo slug.
|
||||
resolve_slug() {
|
||||
jq -r --arg q "$1" '.tasks[] | select(.name == $q or .slug == $q) | .slug' \
|
||||
"$TASKS" 2>/dev/null | head -n 1
|
||||
}
|
||||
|
||||
field_of_slug() { # field_of_slug <slug> <campo>
|
||||
jq -r --arg s "$1" --arg f "$2" \
|
||||
'.tasks[] | select(.slug == $s) | .[$f] // empty' "$TASKS" 2>/dev/null | head -n 1
|
||||
}
|
||||
|
||||
is_running() { # is_running <slug>
|
||||
_pid=$(readf "$RUN/$1.pid") || return 1
|
||||
case "$_pid" in ''|*[!0-9]*) return 1 ;; esac
|
||||
kill -0 "$_pid" 2>/dev/null
|
||||
}
|
||||
|
||||
helper_ready() {
|
||||
[ -x "$HELPER" ] || fail "helper non installato in $HELPER (eseguire install.sh)"
|
||||
command -v pkexec >/dev/null 2>&1 || fail "pkexec non disponibile (installare polkit)"
|
||||
}
|
||||
|
||||
do_add() { # do_add <nome> <profilo> <comando>
|
||||
init_tasks
|
||||
need_jq
|
||||
_name=${1:-}
|
||||
_prof=${2:-}
|
||||
_cmd=${3:-}
|
||||
[ -n "$_name" ] || fail "nome del task mancante"
|
||||
[ -n "$_cmd" ] || fail "comando del task mancante"
|
||||
case $_prof in
|
||||
quiet|powersave|balanced|performance) ;;
|
||||
*) fail "profilo non valido: $_prof (quiet|powersave|balanced|performance)" ;;
|
||||
esac
|
||||
_slug=$(slugify "$_name")
|
||||
[ -n "$_slug" ] || fail "nome non utilizzabile come slug: $_name"
|
||||
if [ -n "$(resolve_slug "$_name")" ]; then
|
||||
fail "esiste già un task chiamato '$_name'"
|
||||
fi
|
||||
_tmp=$TASKS.tmp.$$
|
||||
jq --arg n "$_name" --arg p "$_prof" --arg c "$_cmd" --arg s "$_slug" \
|
||||
'.tasks += [{name: $n, profile: $p, command: $c, slug: $s}]' "$TASKS" > "$_tmp" \
|
||||
&& mv "$_tmp" "$TASKS" || { rm -f "$_tmp"; fail "scrittura tasks.json fallita"; }
|
||||
printf 'ok=1\nname=%s\nprofile=%s\nslug=%s\n' "$_name" "$_prof" "$_slug"
|
||||
}
|
||||
|
||||
cmd_add() { # add <nome> <profilo> <comando...>
|
||||
_name=${1:-}
|
||||
_prof=${2:-}
|
||||
[ "$#" -ge 3 ] || fail "servono nome, profilo e comando"
|
||||
shift 2
|
||||
do_add "$_name" "$_prof" "$*"
|
||||
}
|
||||
|
||||
cmd_add_hex() { # add-hex <nome_hex> <profilo_hex> <comando_hex>
|
||||
[ "$#" -ge 3 ] || fail "servono tre argomenti esadecimali"
|
||||
do_add "$(hex_decode "$1")" "$(hex_decode "$2")" "$(hex_decode "$3")"
|
||||
}
|
||||
|
||||
cmd_list() {
|
||||
init_tasks
|
||||
need_jq
|
||||
printf 'ok=1\n'
|
||||
[ -x "$HELPER" ] && printf 'helper=ok\n' || printf 'helper=missing\n'
|
||||
printf 'count=%s\n' "$(jq -r '.tasks | length' "$TASKS" 2>/dev/null || echo 0)"
|
||||
_i=0
|
||||
jq -c '.tasks[] | {name: .name, profile: .profile, command: .command, slug: .slug}' \
|
||||
"$TASKS" 2>/dev/null |
|
||||
while IFS= read -r _line; do
|
||||
[ -n "$_line" ] || continue
|
||||
_slug=$(printf '%s' "$_line" | jq -r '.slug')
|
||||
_run=0
|
||||
is_running "$_slug" && _run=1
|
||||
printf 'task=%s\t%s\t%s\n' "$_i" "$_run" "$_line"
|
||||
_i=$((_i + 1))
|
||||
done
|
||||
}
|
||||
|
||||
cmd_remove() { # remove <nome-o-slug>
|
||||
init_tasks
|
||||
need_jq
|
||||
_slug=$(resolve_slug "${1:-}")
|
||||
[ -n "$_slug" ] || fail "task '${1:-}' inesistente"
|
||||
is_running "$_slug" && fail "il task è in esecuzione: fermarlo prima di rimuoverlo"
|
||||
_tmp=$TASKS.tmp.$$
|
||||
jq --arg s "$_slug" '.tasks |= map(select(.slug != $s))' "$TASKS" > "$_tmp" \
|
||||
&& mv "$_tmp" "$TASKS" || { rm -f "$_tmp"; fail "scrittura tasks.json fallita"; }
|
||||
rm -f "$RUN/$_slug.pid" "$RUN/$_slug.info"
|
||||
printf 'ok=1\nremoved=%s\n' "$_slug"
|
||||
}
|
||||
|
||||
cmd_run() { # run <nome-o-slug>
|
||||
init_tasks
|
||||
need_jq
|
||||
helper_ready
|
||||
_slug=$(resolve_slug "${1:-}")
|
||||
[ -n "$_slug" ] || fail "task '${1:-}' inesistente"
|
||||
_name=$(field_of_slug "$_slug" name)
|
||||
_prof=$(field_of_slug "$_slug" profile)
|
||||
_cmd=$(field_of_slug "$_slug" command)
|
||||
[ -n "$_cmd" ] || fail "comando vuoto per '$_name'"
|
||||
is_running "$_slug" && fail "il task '$_name' è già in esecuzione"
|
||||
|
||||
_out=$(pkexec "$HELPER" task-begin "$_prof" 2>&1) \
|
||||
|| fail "profilo '$_prof' non applicato: $(printf '%s' "$_out" | tr '\n' ' ')"
|
||||
case "$_out" in
|
||||
*"ok=0"*) fail "profilo '$_prof' non applicato: $(printf '%s' "$_out" | tr '\n' ' ')" ;;
|
||||
esac
|
||||
|
||||
rm -f "$RUN/$_slug.pid" "$RUN/$_slug.info"
|
||||
# Il figlio scrive il proprio pid e poi exec il comando: il pid resta valido,
|
||||
# così il watcher può attenderne davvero la fine.
|
||||
setsid sh -c 'printf "%s\n" "$$" > "$1"; shift; exec sh -c "$1"' \
|
||||
sh "$RUN/$_slug.pid" "$_cmd" </dev/null >/dev/null 2>&1 &
|
||||
_launcher=$!
|
||||
|
||||
_n=0
|
||||
while [ ! -s "$RUN/$_slug.pid" ] && [ "$_n" -lt 25 ]; do
|
||||
sleep 0.1 2>/dev/null || sleep 1
|
||||
_n=$((_n + 1))
|
||||
kill -0 "$_launcher" 2>/dev/null || break
|
||||
done
|
||||
if [ ! -s "$RUN/$_slug.pid" ]; then
|
||||
pkexec "$HELPER" task-end >/dev/null 2>&1
|
||||
fail "avvio del comando fallito: $_cmd"
|
||||
fi
|
||||
_pid=$(readf "$RUN/$_slug.pid")
|
||||
printf 'name=%s\nprofile=%s\nslug=%s\nstarted=%s\n' \
|
||||
"$_name" "$_prof" "$_slug" "$(date +%s)" > "$RUN/$_slug.info"
|
||||
|
||||
setsid "$SELF_DIR/$(basename "$0")" watch "$_slug" </dev/null >/dev/null 2>&1 &
|
||||
|
||||
printf 'ok=1\nname=%s\nslug=%s\nprofile=%s\npid=%s\n' "$_name" "$_slug" "$_prof" "$_pid"
|
||||
}
|
||||
|
||||
cmd_stop() { # stop <nome-o-slug>
|
||||
init_tasks
|
||||
need_jq
|
||||
_slug=$(resolve_slug "${1:-}")
|
||||
[ -n "$_slug" ] || fail "task '${1:-}' inesistente"
|
||||
is_running "$_slug" || fail "il task '$_slug' non è in esecuzione"
|
||||
_pid=$(readf "$RUN/$_slug.pid")
|
||||
kill -TERM -- "-$_pid" 2>/dev/null || kill -TERM "$_pid" 2>/dev/null
|
||||
printf 'ok=1\nstopped=%s\npid=%s\n' "$_slug" "$_pid"
|
||||
}
|
||||
|
||||
cmd_watch() { # watch <slug> (interno)
|
||||
_slug=${1:-}
|
||||
[ -n "$_slug" ] || exit 2
|
||||
_pid=$(readf "$RUN/$_slug.pid" 2>/dev/null) || exit 0
|
||||
while kill -0 "$_pid" 2>/dev/null; do
|
||||
sleep 2
|
||||
done
|
||||
_name=$(sed -n 's/^name=//p' "$RUN/$_slug.info" 2>/dev/null)
|
||||
_prof=$(sed -n 's/^profile=//p' "$RUN/$_slug.info" 2>/dev/null)
|
||||
rm -f "$RUN/$_slug.pid" "$RUN/$_slug.info"
|
||||
if [ -x "$HELPER" ]; then
|
||||
pkexec "$HELPER" task-end >/dev/null 2>&1
|
||||
fi
|
||||
if command -v notify-send >/dev/null 2>&1; then
|
||||
notify-send -a "CPUFreq" -i cpu \
|
||||
"Task concluso: ${_name:-$_slug}" \
|
||||
"Profilo CPU '${_prof:-?}' chiuso, stato precedente ripristinato"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_active() {
|
||||
printf 'ok=1\n'
|
||||
_found=0
|
||||
for _f in "$RUN"/*.pid; do
|
||||
[ -r "$_f" ] || continue
|
||||
_pid=$(readf "$_f")
|
||||
case "$_pid" in ''|*[!0-9]*) continue ;; esac
|
||||
kill -0 "$_pid" 2>/dev/null || continue
|
||||
_slug=$(basename "$_f" .pid)
|
||||
_name=$(sed -n 's/^name=//p' "$RUN/$_slug.info" 2>/dev/null)
|
||||
_prof=$(sed -n 's/^profile=//p' "$RUN/$_slug.info" 2>/dev/null)
|
||||
printf 'act=%s\t%s\t%s\t%s\n' "$_slug" "${_name:-$_slug}" "${_prof:-?}" "$_pid"
|
||||
_found=$((_found + 1))
|
||||
done
|
||||
printf 'active=%s\n' "$_found"
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
uso: enne2-cpufreq-task <comando> [argomenti]
|
||||
list elenco dei task configurati
|
||||
add <nome> <profilo> <comando...>
|
||||
add-hex <nome> <profilo> <comando> argomenti in esadecimale UTF-8 (usato dal widget)
|
||||
remove <nome-o-slug>
|
||||
run <nome-o-slug> salva lo stato, applica il profilo, esegue, ripristina
|
||||
stop <nome-o-slug> termina il task (il watcher ripristina il profilo)
|
||||
active task attualmente in esecuzione
|
||||
EOF
|
||||
}
|
||||
|
||||
[ "$#" -gt 0 ] || { usage; exit 2; }
|
||||
_CMD=$1
|
||||
shift
|
||||
case "$_CMD" in
|
||||
list) cmd_list ;;
|
||||
add) cmd_add "$@" ;;
|
||||
add-hex) cmd_add_hex "$@" ;;
|
||||
remove|rm) cmd_remove "$@" ;;
|
||||
run|start) cmd_run "$@" ;;
|
||||
stop) cmd_stop "$@" ;;
|
||||
watch) cmd_watch "$@" ;;
|
||||
active) cmd_active ;;
|
||||
-h|--help|help) usage ;;
|
||||
*) printf 'ok=0\nerror=comando sconosciuto: %s\n' "$_CMD"; usage; exit 2 ;;
|
||||
esac
|
||||
Executable
+145
@@ -0,0 +1,145 @@
|
||||
# shellcheck shell=sh
|
||||
# Profili di frequenza condivisi fra helper privilegiato, lettore di stato e plasmoide.
|
||||
# Sorgente unica di verità: NON scrive nulla su sysfs, contiene solo la tabella dei
|
||||
# profili e l'aritmetica dei limiti (kHz). Copiato da install.sh accanto all'helper
|
||||
# in /usr/local/libexec/enne2-cpufreq/.
|
||||
#
|
||||
# Ogni profilo agisce su: governor, energy_performance_preference (EPP), boost e
|
||||
# tetto di frequenza espresso come percentuale dello span utile
|
||||
# (floor_khz .. cpuinfo_max_freq).
|
||||
|
||||
# Lettura minimale (il file è già stato validato dal chiamante dove serve).
|
||||
cf_read() {
|
||||
_cfout=
|
||||
[ -r "$1" ] || return 1
|
||||
IFS= read -r _cfout < "$1" 2>/dev/null || [ -n "$_cfout" ] || return 1
|
||||
printf '%s\n' "$_cfout"
|
||||
}
|
||||
|
||||
# Tetto hardware reale (kHz), indipendente dallo stato del boost:
|
||||
# con boost disattivato il kernel riporta in cpuinfo_max_freq la frequenza
|
||||
# nominale (es. 3.80 GHz invece di 4.97 GHz su amd-pstate). amd_pstate_max_freq
|
||||
# conserva il massimo effettivo; su altri driver cpuinfo_max_freq è già corretto.
|
||||
cf_hw_max_khz() {
|
||||
_cfp0=$1
|
||||
_cfmax=$(cf_read "$_cfp0/cpuinfo_max_freq" || echo 0)
|
||||
case "$_cfmax" in ''|*[!0-9]*) _cfmax=0 ;; esac
|
||||
_cfamd=$(cf_read "$_cfp0/amd_pstate_max_freq" || echo 0)
|
||||
case "$_cfamd" in ''|*[!0-9]*) _cfamd=0 ;; esac
|
||||
[ "$_cfamd" -gt "$_cfmax" ] && _cfmax=$_cfamd
|
||||
printf '%s\n' "$_cfmax"
|
||||
}
|
||||
|
||||
cf_profiles() {
|
||||
printf '%s\n' quiet powersave balanced performance
|
||||
}
|
||||
|
||||
cf_profile_known() {
|
||||
case "$1" in
|
||||
quiet|powersave|balanced|performance) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cf_profile_gov() {
|
||||
case "$1" in
|
||||
quiet|powersave|balanced) echo powersave ;;
|
||||
performance) echo performance ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cf_profile_epp() {
|
||||
case "$1" in
|
||||
quiet) echo power ;;
|
||||
powersave) echo balance_power ;;
|
||||
balanced) echo balance_performance ;;
|
||||
performance) echo performance ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cf_profile_boost() {
|
||||
case "$1" in
|
||||
quiet|powersave) echo 0 ;;
|
||||
balanced|performance) echo 1 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cf_profile_max_pct() {
|
||||
case "$1" in
|
||||
quiet) echo 35 ;;
|
||||
powersave) echo 60 ;;
|
||||
balanced|performance) echo 100 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cf_profile_label() {
|
||||
case "$1" in
|
||||
quiet) echo "Silenzioso" ;;
|
||||
powersave) echo "Risparmio" ;;
|
||||
balanced) echo "Bilanciato" ;;
|
||||
performance) echo "Performance" ;;
|
||||
custom) echo "Personalizzato" ;;
|
||||
*) echo "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
cf_profile_desc() {
|
||||
case "$1" in
|
||||
quiet) echo "EPP power, boost off, tetto 35% dello span" ;;
|
||||
powersave) echo "EPP balance_power, boost off, tetto 60%" ;;
|
||||
balanced) echo "EPP balance_performance, boost on, nessun tetto" ;;
|
||||
performance) echo "governor performance, EPP performance, boost on" ;;
|
||||
*) echo "" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# cf_profile_max_khz <profilo> <floor_khz> <hw_max_khz>
|
||||
cf_profile_max_khz() {
|
||||
_cfp=$(cf_profile_max_pct "$1") || return 1
|
||||
_cfl=$2
|
||||
_cfh=$3
|
||||
[ "$_cfh" -gt "$_cfl" ] || { echo "$_cfh"; return 0; }
|
||||
# un profilo al 100% non deve avere tetto: nessun arrotondamento
|
||||
[ "$_cfp" -ge 100 ] && { echo "$_cfh"; return 0; }
|
||||
cf_round50 $(( _cfl + (_cfh - _cfl) * _cfp / 100 ))
|
||||
}
|
||||
|
||||
# Arrotonda a 50 MHz: valori leggibili e stabili fra una lettura e l'altra.
|
||||
cf_round50() {
|
||||
echo $(( ($1 + 25000) / 50000 * 50000 ))
|
||||
}
|
||||
|
||||
# cf_detect_profile <governor> <epp> <boost> <max_khz> <floor_khz> <hw_max_khz>
|
||||
# Stampa il nome del profilo se lo stato coincide (tolleranza sul tetto) oppure "custom".
|
||||
cf_detect_profile() {
|
||||
_dg=$1
|
||||
_de=$2
|
||||
_db=$3
|
||||
_dmax=$4
|
||||
_dfloor=$5
|
||||
_dhwmax=$6
|
||||
_span=$(( _dhwmax - _dfloor ))
|
||||
[ "$_span" -gt 0 ] || _span=1
|
||||
_tol=$(( _span / 40 )) # 2.5% dello span
|
||||
[ "$_tol" -lt 80000 ] && _tol=80000
|
||||
for _dp in $(cf_profiles); do
|
||||
[ "$_dg" = "$(cf_profile_gov "$_dp")" ] || continue
|
||||
[ "$_db" = "$(cf_profile_boost "$_dp")" ] || continue
|
||||
_dp_max=$(cf_profile_max_khz "$_dp" "$_dfloor" "$_dhwmax")
|
||||
_diff=$(( _dmax - _dp_max ))
|
||||
[ "$_diff" -lt 0 ] && _diff=$(( -_diff ))
|
||||
[ "$_diff" -le "$_tol" ] || continue
|
||||
# L'EPP può non essere scrivibile con governor "performance": in quel caso
|
||||
# accettiamo il profilo anche se l'EPP letto non coincide.
|
||||
[ "$_de" = "$(cf_profile_epp "$_dp")" ] && { echo "$_dp"; return 0; }
|
||||
if [ "$_dg" = "performance" ] && [ "$_dp" = "performance" ]; then
|
||||
echo "$_dp"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
echo custom
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 enne2
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Pillola selezionabile usata per governor ed EPP: alternativa compatta a una
|
||||
* ComboBox, senza stato interno (attivo/inattivo derivano dalle proprietà).
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import org.kde.plasma.components 3.0 as PlasmaComponents
|
||||
import org.kde.kirigami as Kirigami
|
||||
|
||||
Rectangle {
|
||||
id: pill
|
||||
|
||||
property string text: ""
|
||||
property bool active: false
|
||||
property color accent: "#55c5c0"
|
||||
signal clicked()
|
||||
|
||||
implicitWidth: label.implicitWidth + 16
|
||||
implicitHeight: label.implicitHeight + 8
|
||||
radius: 4
|
||||
color: active
|
||||
? Qt.rgba(accent.r, accent.g, accent.b, 0.22)
|
||||
: (pillMouse.containsMouse ? Qt.rgba(1, 1, 1, 0.10) : Qt.rgba(1, 1, 1, 0.05))
|
||||
border.width: 1
|
||||
border.color: active
|
||||
? Qt.rgba(accent.r, accent.g, accent.b, 0.8)
|
||||
: Qt.rgba(1, 1, 1, 0.10)
|
||||
opacity: enabled ? 1.0 : 0.5
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation { duration: 120 }
|
||||
}
|
||||
|
||||
PlasmaComponents.Label {
|
||||
id: label
|
||||
anchors.centerIn: parent
|
||||
text: pill.text
|
||||
font.family: "monospace"
|
||||
font.pointSize: 8
|
||||
font.bold: pill.active
|
||||
color: pill.active ? pill.accent : Kirigami.Theme.textColor
|
||||
opacity: pill.active ? 1.0 : 0.78
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: pillMouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: pill.clicked()
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user