#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/phc-k8.conf
case "$1" in
start)
stat_busy 'Setting PHC-K8 rules'
if [ ! -d /sys/module/phc_k8 ]; then
echo "'phc_k8' module is not loaded."
stat_fail
elif [ -z "$FIDS" ] && [ -z "$VIDS"]; then
echo "Nothing to do, please change the config in /etc/conf.d/phc-k8.conf"
stat_fail
else
if [ ! -e /sys/devices/system/cpu/cpu0/cpufreq/phc_fids ] && [ ! -e /sys/devides/system/cpu/cpu0/cpufreq/phc_vids ]; then
echo "Can not set rules, devices did not exist."
stat_fail
exit 0
fi
for CPU in /sys/devices/system/cpu/cpu?; do
[ -n "$FIDS" ] && echo $FIDS > $CPU/cpufreq/phc_fids 2> /dev/null
[ -n "$VIDS" ] && echo $VIDS > $CPU/cpufreq/phc_vids 2> /dev/null
done
add_daemon phc-k8
stat_done
fi
;;
stop)
stat_busy 'Resetting PHC-K8 rules to default'
if [ ! -d /sys/module/phc_k8 ]; then
echo "'phc_k8' module is not loaded."
stat_fail
else
for CPU in /sys/devices/system/cpu/cpu?; do
cat $CPU/cpufreq/phc_default_fids > $CPU/cpufreq/phc_fids 2>/dev/null
cat $CPU/cpufreq/phc_default_vids > $CPU/cpufreq/phc_vids 2>/dev/null
done
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon phc-k8
stat_done
fi
fi
;;
restart)
$0 start
;;
setup)
if [ ! -n "$INSTALL_DIR" ]; then
echo "\$INSTALL_DIR is not defined!"
else
TMPDIR="/tmp/phc-k8"
LOG="/var/log/phc-k8.log"
if ! mkdir -m 0755 -p $TMPDIR 2>/dev/null; then
echo "Can not create temp dir!"
stat_fail
exit 0
fi
cp $INSTALL_DIR/* $TMPDIR && cd $TMPDIR
if find /lib/modules/`uname -r` -name "phc_k8\.*" 2>/dev/null|grep -q phc_k8; then
stat_busy "Removing old phc-k8 kernel module"
find /lib/modules/`uname -r` -name "phc_k8\.*" 2>/dev/null|xargs rm -f 2>/dev/null
stat_done
fi
stat_busy "Recompiling phc-k8 kernel modules"
if ! make install >> $LOG 2>&1;then
echo "Look at $LOG to find out what went wrong"
stat_fail
exit 0
fi
stat_done
fi
;;
*)
echo "usage: $0 {start|stop|restart|setup}"
esac
exit 0