feat: dynamic CPU governor (performance during tasks, powersave at idle)
Switch to performance governor when task queue starts processing, back to powersave when queue drains. Removes bee-cpuperf.service. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -179,6 +181,7 @@ func (q *taskQueue) startWorker(opts *HandlerOptions) {
|
|||||||
func (q *taskQueue) worker() {
|
func (q *taskQueue) worker() {
|
||||||
for {
|
for {
|
||||||
<-q.trigger
|
<-q.trigger
|
||||||
|
setCPUGovernor("performance")
|
||||||
for {
|
for {
|
||||||
q.mu.Lock()
|
q.mu.Lock()
|
||||||
t := q.nextPending()
|
t := q.nextPending()
|
||||||
@@ -211,6 +214,19 @@ func (q *taskQueue) worker() {
|
|||||||
q.prune()
|
q.prune()
|
||||||
q.mu.Unlock()
|
q.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
setCPUGovernor("powersave")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setCPUGovernor writes the given governor to all CPU scaling_governor sysfs files.
|
||||||
|
// Silently ignores errors (e.g. when cpufreq is not available).
|
||||||
|
func setCPUGovernor(governor string) {
|
||||||
|
matches, err := filepath.Glob("/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor")
|
||||||
|
if err != nil || len(matches) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, path := range matches {
|
||||||
|
_ = os.WriteFile(path, []byte(governor), 0644)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Set CPU governor to performance
|
|
||||||
DefaultDependencies=no
|
|
||||||
After=sysinit.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/bin/sh -c 'for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do [ -f "$f" ] && echo performance > "$f"; done'
|
|
||||||
RemainAfterExit=yes
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
/etc/systemd/system/bee-cpuperf.service
|
|
||||||
Reference in New Issue
Block a user