Skip to content

Commit 4543e1b

Browse files
committed
Add automatic pstate boot configuration
1 parent 5372b03 commit 4543e1b

3 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
# Select a low-latency pstate mode early in boot when the user did not choose
4+
# one explicitly on the kernel command line.
5+
6+
proc_cmdline="${BIGLINUX_PROC_CMDLINE:-/proc/cmdline}"
7+
proc_cpuinfo="${BIGLINUX_PROC_CPUINFO:-/proc/cpuinfo}"
8+
sys_cpu="${BIGLINUX_SYS_CPU:-/sys/devices/system/cpu}"
9+
10+
log() {
11+
if command -v logger >/dev/null 2>&1; then
12+
logger -t biglinux-auto-pstate "$*" 2>/dev/null || true
13+
fi
14+
}
15+
16+
manual_pstate_is_configured() {
17+
[ -r "$proc_cmdline" ] || return 1
18+
tr ' ' '\n' < "$proc_cmdline" | grep -Eq '^(amd_pstate|intel_pstate)([.=]|$)'
19+
}
20+
21+
cpu_vendor() {
22+
[ -r "$proc_cpuinfo" ] || return 1
23+
awk -F ': *' '/^vendor_id[[:space:]]*:/{ print $2; exit }' "$proc_cpuinfo"
24+
}
25+
26+
set_pstate_status() {
27+
local driver="$1"
28+
local desired_status="$2"
29+
local status_file="$sys_cpu/$driver/status"
30+
local current_status
31+
32+
[ -r "$status_file" ] || return 0
33+
34+
current_status="$(cat "$status_file" 2>/dev/null || true)"
35+
[ "$current_status" = "$desired_status" ] && return 0
36+
37+
if ! [ -w "$status_file" ]; then
38+
log "Cannot set $driver to $desired_status: $status_file is not writable"
39+
return 0
40+
fi
41+
42+
if printf '%s\n' "$desired_status" > "$status_file" 2>/dev/null; then
43+
log "Configured $driver status=$desired_status"
44+
else
45+
log "Failed to configure $driver status=$desired_status"
46+
fi
47+
}
48+
49+
main() {
50+
local vendor
51+
52+
if manual_pstate_is_configured; then
53+
log "Keeping pstate mode from kernel command line"
54+
return 0
55+
fi
56+
57+
vendor="$(cpu_vendor || true)"
58+
case "$vendor" in
59+
GenuineIntel)
60+
set_pstate_status intel_pstate passive
61+
;;
62+
AuthenticAMD)
63+
set_pstate_status amd_pstate guided
64+
;;
65+
esac
66+
}
67+
68+
main "$@"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Configure automatic CPU pstate mode
3+
DefaultDependencies=no
4+
After=sysinit.target local-fs.target
5+
Before=multi-user.target graphical.target display-manager.service
6+
ConditionPathExists=/sys/devices/system/cpu
7+
8+
[Service]
9+
Type=oneshot
10+
ExecStart=/usr/bin/biglinux-auto-pstate
11+
12+
[Install]
13+
WantedBy=multi-user.target

pkgbuild/biglinux-improve-compatibility.install

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
post_install() {
2+
systemctl enable biglinux-auto-pstate.service || true
3+
systemctl start biglinux-auto-pstate.service || true
24
systemctl enable biglinux-improve-compatibility.service || true
35
systemctl start biglinux-improve-compatibility.service || true
46
systemctl enable suspend-bluetooth-fix.service || true
@@ -18,6 +20,7 @@ ProcessSizeMax=0' > /etc/systemd/coredump.conf.d/custom.conf
1820
}
1921

2022
pre_remove() {
23+
systemctl disable biglinux-auto-pstate.service || true
2124
systemctl disable biglinux-improve-compatibility.service || true
2225
systemctl disable suspend-bluetooth-fix.service || true
2326
systemctl disable glibc2-41-fix.path || true
@@ -37,6 +40,8 @@ pre_upgrade() {
3740

3841

3942
post_upgrade() {
43+
systemctl enable biglinux-auto-pstate.service || true
44+
systemctl start biglinux-auto-pstate.service || true
4045
systemctl --global enable jamesdsp-autostart.service || true
4146
systemctl enable suspend-bluetooth-fix.service || true
4247
systemctl start suspend-bluetooth-fix.service || true

0 commit comments

Comments
 (0)