ACC SHELL

Path : /usr/lib/pm-profiler/
File Upload :
Current File : //usr/lib/pm-profiler/enable-profile

#!/bin/bash
#
# trigger script to enable a profile. Part of the pm-profiler
#
# Copyright (C) 2008 Holger Macht <hmacht@suse.de>
#
# This file is released under the GPLv2.
#

# where are the profiles?
PROFILE_PATH="/etc/pm-profiler"

STATEFILE="/var/run/pm-profiler.profile"

ERROR_GENERAL_ERROR=1
ERROR_INVALID_ARGUMENTS=2
ERROR_INVALID_PROFILE=3
ERROR_CONFIG_OPTION=4

LOGGER="logger -s -t pm-profiler"

HAL_COMPUTER_PATH="/org/freedesktop/Hal/devices/computer"

if [ -z "$1" ]; then
    $LOGGER "missing profile name"
    exit $ERROR_INVALID_ARGUMENTS
else
    PROFILE="$1"
fi

. $PROFILE_PATH/$PROFILE/config >/dev/null 2>&1
if [ "$?" != "0" ]; then
    $LOGGER "the requested profile $PROFILE does not exist"
    exit $ERROR_INVALID_PROFILE
fi

function cpufreq_governor {
    dbus-send --system --print-reply --dest=org.freedesktop.Hal \
	$HAL_COMPUTER_PATH \
	org.freedesktop.Hal.Device.CPUFreq.SetCPUFreqGovernor \
	string:$CPUFREQ_GOVERNOR >/dev/null 2>&1 | $LOGGER
}

function cpufreq_ondemand_up_threshold {
    for I in /sys/devices/system/cpu/cpu*/cpufreq/ondemand/up_threshold; do
        echo $CPUFREQ_ONDEMAND_UP_THRESHOLD > $I
    done
}

function cpufreq_ondemand_sampling_rate {
    local SAMPLE_RATE
    for I in /sys/devices/system/cpu/cpu*/cpufreq; do
        if [ -e $I/cpuinfo_transition_latency ] && \
	    [ -w $I/ondemand/sampling_rate ]; then
	    SAMPLE_RATE=$(($(cat $I/cpuinfo_transition_latency) \
		* $CPUFREQ_ONDEMAND_SAMPLING_RATE / 1000))
	    echo $SAMPLE_RATE > $I/ondemand/sampling_rate
	fi
    done
}

function cpufreq_ondemand_powersave_bias {
    for I in /sys/devices/system/cpu/cpu*/cpufreq/ondemand/powersave_bias; do
	echo $CPUFREQ_ONDEMAND_POWERSAVE_BIAS > $I
    done
}

function cpufreq_sched_mc_power_savings {
    path_mc="/sys/devices/system/cpu/sched_mc_power_savings"
    path_smt="/sys/devices/system/cpu/sched_smt_power_savings"

    if [ -w "$path_mc" ] ; then
        echo $CPUFREQ_SCHED_MC_POWER_SAVINGS > $path_mc
    fi
    if [ -w "$path_smt" ] ; then
        echo $CPUFREQ_SCHED_MC_POWER_SAVINGS > $path_smt
    fi
}

function sata_alpm {
    for I in /sys/class/scsi_host/host*/link_power_management_policy; do
	[ -e $I ] && echo $SATA_ALPM > $I
    done
}

function external_hook {
    $EXTERNAL_HOOK 2>&1 | $LOGGER &
}

function hal_disable_polling {
    for I in /dev/scd*; do
	hal-disable-polling --device $I >/dev/null 2>&1 | $LOGGER
    done
}

function dirty_writeback_centisecs {
    echo $DIRTY_WRITEBACK_CENTISECS > /proc/sys/vm/dirty_writeback_centisecs
}

function read_ahead_kb {
    echo $READ_AHEAD_KB > /sys/block/sd*/queue/read_ahead_kb
}

[ -n "$CPUFREQ_GOVERNOR" ] && cpufreq_governor
[ -n "$CPUFREQ_ONDEMAND_UP_THRESHOLD" ] && cpufreq_ondemand_up_threshold
[ -n "$CPUFREQ_ONDEMAND_SAMPLING_RATE" ] && cpufreq_ondemand_sampling_rate
[ -n "$CPUFREQ_ONDEMAND_POWERSAVE_BIAS" ] && cpufreq_ondemand_powersave_bias
[ -n "$CPUFREQ_SCHED_MC_POWER_SAVINGS" ] && cpufreq_sched_mc_power_savings
[ -n "$SATA_ALPM" ] && sata_alpm
[ -n "$EXTERNAL_HOOK" ] && external_hook
[ -n "$HAL_DISABLE_POLLING" ] && hal_disable_polling
[ -n "$DIRTY_WRITEBACK_CENTISECS" ] && dirty_writeback_centisecs
[ -n "$READ_AHEAD_KB" ] && read_ahead_kb

echo $PROFILE > $STATEFILE


exit 0

#sed -e "s/CURRENT_PROFILE=\".*\"/CURRENT_PROFILE=\"$PROFILE\"/g" -i /etc/pm-profiler.conf

ACC SHELL 2018