You are not logged in.
I am trying to create a phc service which would undervolt my cpu after migrating from rc.d-based system to systemd.
This is how I used to run it:
rc.d start phc-intel
At first, I tried writing this from scratch, like so:
- bin file
1 #!/bin/sh
2
3 . /etc/sysconfig/phc
4
5 [ -z "$VIDS" -o -z "$1" ] && exit 1
6
7 set_vids()
8 {
9 for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
10 if [ -f "$i" ]; then
11 echo "$1" > "$i"
12 [ "$?" -ne "0" ] && exit 1
13 fi
14 done
15 true
16 }
17
18 case $1 in
19 set)
20 set_vids "$VIDS"
21 ;;
22 reset)
23 [ -f "/sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids" ] || exit 1
24 set_vids "$(< /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids)"
25 ;;
26 esac
- service file:
1 [Unit]
2 Description=Apply phc configuration
3 After=cpupower.service
4
5 [Service]
6 ExecStart=/usr/sbin/phc.sh set
7 ExecStop=/usr/sbin/phc.sh reset
8 Type=oneshot
9 StandardOutput=syslog
10 RemainAfterExit=yes
11
12 [Install]
13 WantedBy=multi-user.target
but it did not work, so I took another approach by taking an existing service file. So I copied the content of /etc/rc.d/phc-intel and created an executable like that:
#!/bin/bash
shopt -s nullglob
if [ "$1" = set ]; then
. /etc/conf.d/phc-intel
[ -n "$VIDS" ] || exit
for i in $(< /proc/cmdline); do
[ $i = nophc ] && exit
done
for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
echo $VIDS > "$i"
done
exit
fi
. /etc/rc.conf
. /etc/rc.d/functions
case "$1" in
start)
. /etc/conf.d/phc-intel
if [ -z "$VIDS" ]; then
printhl 'Please edit /etc/conf.d/phc-intel'
exit 1
fi
stat_busy 'Setting PHC VIDs'
for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
echo $VIDS > "$i"
done && stat_done || stat_fail
;;
stop)
stat_busy 'Resetting default PHC VIDs'
for i in /sys/devices/system/cpu/cpu*/cpufreq; do
[ -e "$i/phc_default_vids" -a -e "$i/phc_vids" ] && cp "$i"/phc_{default_,}vids
done && stat_done || stat_fail
;;
status)
check_off () {
for i in /sys/devices/system/cpu/cpu*/cpufreq; do
[ "$(< $i/phc_vids)" = "$(< $i/phc_default_vids)" ] || return;
done
}
check_on () {
for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
[[ "$(< $i)" =~ "$VIDS" ]] || return;
done
}
stat_busy 'PHC status'
. /etc/conf.d/phc-intel
if check_off; then
status_stopped
elif check_on; then
status_started
else
stat_fail
fi
;;
setup)
LOG='/var/log/phc-intel.log'
fail () {
stat_fail
printhl "Look at $LOG to find out what went wrong"
exit 1
}
stat_busy 'Removing old phc-intel modules'
for i in /lib/modules/*; do
if [ -f "$i/phc-intel.ko" -a ! -f "$i/version" ]; then
rm -f "$i/phc-intel.ko"
rmdir --ignore-fail-on-non-empty "$i"
elif [ -f "$i/extra/phc-intel.ko" -a ! -d "$i/kernel" ]; then
rm -f "$i/extra/phc-intel.ko"
rmdir -p --ignore-fail-on-non-empty "$i/extra"
fi
done
stat_done
stat_busy 'Compiling new phc-intel module'
cd /usr/src/phc-intel/
make &>$LOG && stat_done || fail
stat_busy 'Installing new phc-intel module'
make install &>>$LOG && stat_done || fail
stat_busy 'Cleaning up'
make clean &>>$LOG && stat_done || fail
;;
*)
echo "usage: $0 {start|stop|status|setup|set}"
esac
and the service file:
[Unit]
Description=CPU undervolting
After=cpupower.service[Service]
ExecStart=/usr/sbin/phc.sh start
ExecStop=/usr/sbin/phc.sh restart
Type=oneshot
StandardOutput=syslog
RemainAfterExit=yes[Install]
WantedBy=multi-user.target
However, when I try to run the service, I get this:
$ systemctl status phc.service
phc.service - CPU undervolting
Loaded: loaded (/etc/systemd/system/phc.service; enabled)
Active: failed (Result: exit-code) since Sat, 2012-10-27 18:33:54 CEST; 39s ago
Process: 7379 ExecStart=/usr/sbin/phc.sh start (code=exited, status=127)
CGroup: name=systemd:/system/phc.service
How can I make this work?
PS
I also want to have this service restart automatically if it crashes.
Last edited by impact (2012-10-28 20:02:08)
Offline
Following this with interest, did you get anywhere?
Hardware: 2016 Dell XPS15 - matte FullHD - i5-6300HQ - 32GB DDR4 - Nvidia GTX960M - Samsung 840EVO 250GB SSD - 56Wh
Software: Plasma 5 - rEFInd - linux-ck - preload - prelink - verynice - psd - bumblebee
Offline
I didn't get anywhere with the service, but I did got around it by writing a phc script which runs on every boot and upon every resume (it quits or crashes upon hibernation/suspend).
Offline
I didn't get anywhere with the service, but I did got around it by writing a phc script which runs on every boot and upon every resume (it quits or crashes upon hibernation/suspend).
Care to share please? I've also been trying to set phc up but did not find a way to overcome the fact that I don't have the rc.d command anymore.
Hardware: 2016 Dell XPS15 - matte FullHD - i5-6300HQ - 32GB DDR4 - Nvidia GTX960M - Samsung 840EVO 250GB SSD - 56Wh
Software: Plasma 5 - rEFInd - linux-ck - preload - prelink - verynice - psd - bumblebee
Offline
Sure. It goes like that:
/usr/sbin/phc.sh
#!/bin/sh
. /etc/sysconfig/phc
[[ -z "$VIDS" ]] && exit 1
set_vids() {
for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids ; do
echo "$1" > "$i"
done
}
case "$1" in
set)
set_vids "$VIDS"
;;
reset)
[ -f "/sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids" ] || exit 1
set_vids "$(< /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids)"
;;
*)
exit 1
;;
esac
where /etc/sysconfig/phc contains your undervolted VIDs in this form:
VIDS="23 0 0 0 0"
Offline
Sure. It goes like that:
/usr/sbin/phc.sh
#!/bin/sh . /etc/sysconfig/phc [[ -z "$VIDS" ]] && exit 1 set_vids() { for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids ; do echo "$1" > "$i" done } case "$1" in set) set_vids "$VIDS" ;; reset) [ -f "/sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids" ] || exit 1 set_vids "$(< /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids)" ;; *) exit 1 ;; esac
where /etc/sysconfig/phc contains your undervolted VIDs in this form:
VIDS="23 0 0 0 0"
Thanks.
Sorry, how do you make that run at every boot?
Hardware: 2016 Dell XPS15 - matte FullHD - i5-6300HQ - 32GB DDR4 - Nvidia GTX960M - Samsung 840EVO 250GB SSD - 56Wh
Software: Plasma 5 - rEFInd - linux-ck - preload - prelink - verynice - psd - bumblebee
Offline
Sure. It goes like that:
/usr/sbin/phc.sh
#!/bin/sh . /etc/sysconfig/phc [[ -z "$VIDS" ]] && exit 1 set_vids() { for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids ; do echo "$1" > "$i" done } case "$1" in set) set_vids "$VIDS" ;; reset) [ -f "/sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids" ] || exit 1 set_vids "$(< /sys/devices/system/cpu/cpu0/cpufreq/phc_default_vids)" ;; *) exit 1 ;; esac
where /etc/sysconfig/phc contains your undervolted VIDs in this form:
VIDS="23 0 0 0 0"
Lockheed, I have no idea why but your script does absolutely nothing on my computer
Seems like it works only by doing
su
echo 28 27 4 0 > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids
With
sudo echo 28 27 4 0 > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids
It gives me Permission denied...
EDIT:
Putting the vids into /etc/conf.d/phc-intel doesn't seem to work either ???
Last edited by OdinEidolon (2012-12-29 20:13:14)
Hardware: 2016 Dell XPS15 - matte FullHD - i5-6300HQ - 32GB DDR4 - Nvidia GTX960M - Samsung 840EVO 250GB SSD - 56Wh
Software: Plasma 5 - rEFInd - linux-ck - preload - prelink - verynice - psd - bumblebee
Offline
It gives me Permission denied...
The problem is that the command gets run under sudo, but the redirect gets run under your user.
try using:
sudo sh -c "echo 28 27 4 0 > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids"
Offline
OdinEidolon wrote:It gives me Permission denied...
The problem is that the command gets run under sudo, but the redirect gets run under your user.
try using:sudo sh -c "echo 28 27 4 0 > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids"
Thank you for the explanation.
Hardware: 2016 Dell XPS15 - matte FullHD - i5-6300HQ - 32GB DDR4 - Nvidia GTX960M - Samsung 840EVO 250GB SSD - 56Wh
Software: Plasma 5 - rEFInd - linux-ck - preload - prelink - verynice - psd - bumblebee
Offline