ACC SHELL

Path : /usr/lib/pm-profiler/
File Upload :
Current File : //usr/lib/pm-profiler/get-current-settings

#!/bin/bash
#
# script to read out the current values which can be set by pm-profiler.
#

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

function pm_profile_name {
    Value=`cat /etc/pm-profiler.conf |grep PM_PROFILER_PROFILE| \
                 sed -e 's/PM_PROFILER_PROFILE=\"\(.*\)\"/\1/g'`
    echo "NAME=$Value"
}

function get_cpufreq_governor {
    Option="CPUFREQ_GOVERNOR"
    Value=`dbus-send --system --print-reply --dest=org.freedesktop.Hal\
                   $HAL_COMPUTER_PATH \
                   org.freedesktop.Hal.Device.CPUFreq.GetCPUFreqGovernor \
                   | grep string | sed -e 's/\s*string //g' \
                   | sed -e 's/"//g' 2> /dev/null`
    if [ ! $? ]; then
        echo "Warning: Bad return Value of dbus-send." >&2
    fi
    Governor=$Value
    echo $Option"="$Value
}

function get_cpufreq_ondemand_up_threshold {
    Option="CPUFREQ_UP_THRESHOLD"
    Value=`cat /sys/devices/system/cpu/cpu0/cpufreq/$Governor/up_threshold`

    for I in /sys/devices/system/cpu/cpu[[:digit:]]*; do
        if [ -d $I/cpufreq/$Governor ]; then
            Next_Value=`cat $I/cpufreq/$Governor/up_threshold`
            if [[ $Next_Value != $Value ]]; then
                echo "Warning: different values: "$Option >&2
            fi
        else
            echo "Warning: different governor on "$I >&2
        fi
    done
    echo $Option"="$Value
}

function get_cpufreq_ondemand_sampling_rate {
    Option="CPUFREQ_UP_CPUFREQ_SAMPLING_RATE"
    Value=`cat /sys/devices/system/cpu/cpu0/cpufreq/$Governor/sampling_rate`

    for I in /sys/devices/system/cpu/cpu[[:digit:]]*; do
        if [ -d $I/cpufreq/$Governor ]; then
            if [ `cat $I/cpufreq/$Governor/sampling_rate` != $Value ]; then
                echo "Warning: different values: "$Option >&2
            fi
        else
            echo "Warning: different governor on "$I >&2
        fi
    done
    echo $Option"="$Value
}

function get_cpufreq_ondemand_powersave_bias {
    Option="CPUFREQ_ONDEMAND_POWERSAVE_BIAS"
    Value=`cat /sys/devices/system/cpu/cpu0/cpufreq/$Governor/powersave_bias`

    for I in /sys/devices/system/cpu/cpu[[:digit:]]*; do
        if [ -d $I/cpufreq/$Governor ]; then
            if [ `cat $I/cpufreq/$Governor/powersave_bias` != $Value ]; then
                echo "Warning: different values: "$Option >&2
            fi
        else
            echo "Warning: different governor on "$I >&2
        fi
    done
    echo $Option"="$Value
}

function get_cpufreq_sched_mc_power_savings {
    path_mc="/sys/devices/system/cpu/sched_mc_power_savings"
    path_smp="/sys/devices/system/cpu/sched_smp_power_savings"

    if [ -f "$path_mc" ] ; then
        Option="CPUFREQ_SCHED_MC_POWER_SAVINGS"
        Value=`cat $path_mc`
        echo $Option"="$Value
    fi
    if [ -f "$path_smp" ] ; then
        Option="CPUFREQ_SCHED_MC_POWER_SAVINGS"
        Value=`cat $path_smp`
        echo $Option"="$Value
    fi
}

function get_sata_alpm {
    Option="SATA_ALPM"
    Value=

    if [ -f /sys/class/scsi_host/host0/link_power_management_policy ]; then
        Value=`cat /sys/class/scsi_host/host0/link_power_management_policy`

        for I in /sys/class/scsi_host/host[[:digit:]]*/link_power_management_policy; do
            if [ `cat /sys/class/scsi_host/host0/link_power_management_policy` != $Value ] ; then
                echo "Warning: different values: "$Option >&2
            fi
        done
    fi
    echo $Option"="$Value
}

function get_dirty_writeback_centisecs {
    Value=`cat /proc/sys/vm/dirty_writeback_centisecs`
    echo "DIRTY_WRITEBACK_CENTISECS="$Value >&2
}

function get_read_ahead_kb {
    Option="READ_AHEAD_KB"
    Value=`cat /sys/block/sda/queue/read_ahead_kb`
    cd /dev
    for I in sd?; do
        if [[ `cat /sys/block/$I/queue/read_ahead_kb` != $Value ]]; then
            echo "Warning: different values: "$Option >&2
        fi
    done
    cd - > /dev/null
    echo $Option"="$Value
}

get_cpufreq_governor
get_cpufreq_sched_mc_power_savings
get_sata_alpm
#get_external_hook
#get_hal_disable_polling
get_dirty_writeback_centisecs
get_read_ahead_kb

if [ -d /sys/devices/system/cpu/cpu0/cpufreq ]; then
    get_cpufreq_governor
    if [ $Governor == conservative -o $Governor == ondemand ]; then
	get_cpufreq_ondemand_sampling_rate
	get_cpufreq_ondemand_up_threshold
        if [ $Governor == ondemand ]; then
	    get_cpufreq_ondemand_powersave_bias
        fi
    fi
    exit 0
else
    echo "Error: unable to read settings." \
         "Please check if your system supports power management." >&2
    exit 126
fi

exit 0



ACC SHELL 2018