1#!/bin/sh /etc/rc.common
2
3START=99
4
5# ipq806x_power_auto()
6#   Changes the governor to ondemand and sets the default parameters for cpu ondemand governor.
7#   The parameters are tuned for best performance than for power.
8#   Also, the up_thresholds have been set to low value, to workaround the cpu
9#   utilization anamolies we are seeing with kcpustat with tickless kernel.
10ipq806x_power_auto() {
11	echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
12	echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
13
14	# Change the minimum operating frequency for CPU0.
15	# This is required for cases where large amount of network traffic is sent
16	# instantaneously  without any ramp-up time , when CPU is at minimum perf level.
17	# At 384 MHz, CPU0 stays fully busy in softirq context and doesn't move to ksoftirqd, and
18	# doesn't give any other thread including cpufreq thread a chance to run.
19	# Hence, the CPU frequency is locked up at 384MHz till the traffic is stopped.
20	# Increasing the min frequency for CPU0 to 800 MHz (L2=1GHz), allows 4 Gbps instantaneous
21	# traffic without any hangs/lockups.
22	#
23	# CPU1 min frequency also has to be increased because there is a hardware constraint
24	# kraits cannot operate at 384MHz when L2 is at 1GHz.
25	#
26	# The impact on idle-state power with this change is about ~40-45mW.
27	echo "800000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
28	echo "800000" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
29
30	# Change sampling rate for frequency scaling decisions to 1s, from 10 ms
31	echo "1000000" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
32
33	# Change sampling rate for frequency down scaling decision to 10s
34	echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
35
36	# Change the CPU load threshold above which frequency is up-scaled to
37	# turbo frequency,to 50%
38	echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
39	echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_any_cpu_load
40	echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_multi_core
41
42	# Change the CPU load threshold below which frequency is down-scaled to
43	# 10% (down_threshold = up_threshold - down_differential)
44	echo 40 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential
45
46	# Set sync_freq and optimal_freq used for multicore scenarios to max
47	# freq
48	echo "1000000" > /sys/devices/system/cpu/cpufreq/ondemand/optimal_freq
49	echo "1000000" > /sys/devices/system/cpu/cpufreq/ondemand/sync_freq
50}
51
52# ipq806x_power_turbo()
53#   Sets the Krait CPU/L2 and NSS NetAP core clock frequencies to fixed Turbo frequencies
54#   No frequency scaling is done in this profile
55ipq806x_power_turbo() {
56	echo "userspace" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
57	echo "userspace" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
58
59	echo "1400000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
60	echo "1400000" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_setspeed
61
62	echo 733000000 > /proc/sys/dev/nss/clock/current_freq
63}
64
65
66start() {
67	config_load system
68	config_get mode powerctl mode "auto"
69
70	if eval "type ipq806x_power_${mode}" 2>/dev/null >/dev/null; then
71		eval ipq806x_power_${mode}
72	else
73		echo "\"${mode}\" power mode not supported"
74	fi
75}
76
77