#! /bin/sh ### BEGIN INIT INFO # Provides: ondemand # Required-Start: $remote_fs $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: Set the CPU Frequency Scaling governor to "ondemand" ### END INIT INFO # Don't run if we're going to start an Android LXC container: test ! -f /etc/init/lxc-android-config.conf || exit 0 global PATH := '/sbin:/usr/sbin:/bin:/usr/bin' source /lib/init/vars.sh source /lib/lsb/init-functions global AVAILABLE := '"/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors'" global DOWN_FACTOR := '"/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor'" matchstr $1 { start { start-stop-daemon --start --background --exec /etc/init.d/ondemand -- background } background { sleep 60 # probably enough time for desktop login test -f $AVAILABLE || exit 0 read governors < $AVAILABLE matchstr $governors { *interactive* { global GOVERNOR := '"interactive'" break } *ondemand* { global GOVERNOR := '"ondemand'" matchstr $[uname -m] { ppc64* { global SAMPLING := '100' } } break } *powersave* { global GOVERNOR := '"powersave'" break } * { exit 0 } } for CPUFREQ in [/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor] { test -f $CPUFREQ || continue echo -n $GOVERNOR > $CPUFREQ } if test -n $SAMPLING && test -f $DOWN_FACTOR { echo -n $SAMPLING > $DOWN_FACTOR } } restart|reload|force-reload { echo "Error: argument '$1' not supported" > !2 exit 3 } stop { } * { echo "Usage: $0 start|stop" > !2 exit 3 } } (CommandList children: [ (AndOr children: [ (C {(Lit_Other "[")} {(KW_Bang "!")} {(-f)} {(/etc/init/lxc-android-config.conf)} {(Lit_Other "]")} ) (C {(exit)} {(0)}) ] op_id: Op_DPipe ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: {(/sbin) (Lit_Other ":") (/usr/sbin) (Lit_Other ":") (/bin) (Lit_Other ":") (/usr/bin)} spids: [48] ) ] spids: [48] ) (C {(.)} {(/lib/init/vars.sh)}) (C {(.)} {(/lib/lsb/init-functions)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:AVAILABLE) op: Equal rhs: {(DQ (/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors))} spids: [67] ) ] spids: [67] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DOWN_FACTOR) op: Equal rhs: {(DQ (/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor))} spids: [72] ) ] spids: [72] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list: [{(start)}] action: [ (C {(start-stop-daemon)} {(--start)} {(--background)} {(--exec)} {(/etc/init.d/ondemand)} {(--)} {(background)} ) ] spids: [87 88 106 -1] ) (case_arm pat_list: [{(background)}] action: [ (C {(sleep)} {(60)}) (AndOr children: [ (C {(Lit_Other "[")} {(-f)} {($ VSub_Name "$AVAILABLE")} {(Lit_Other "]")}) (C {(exit)} {(0)}) ] op_id: Op_DPipe ) (SimpleCommand words: [{(read)} {(governors)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {($ VSub_Name "$AVAILABLE")} spids: [141] ) ] ) (Case to_match: {($ VSub_Name "$governors")} arms: [ (case_arm pat_list: [{(Lit_Other "*") (interactive) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GOVERNOR) op: Equal rhs: {(DQ (interactive))} spids: [159] ) ] spids: [159] ) (ControlFlow token:) ] spids: [153 156 168 -1] ) (case_arm pat_list: [{(Lit_Other "*") (ondemand) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GOVERNOR) op: Equal rhs: {(DQ (ondemand))} spids: [177] ) ] spids: [177] ) (Case to_match: { (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-m)})]) left_token: spids: [185 189] ) } arms: [ (case_arm pat_list: [{(ppc64) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SAMPLING) op: Equal rhs: {(100)} spids: [199] ) ] spids: [199] ) ] spids: [194 196 203 -1] ) ] spids: [183 191 206] ) (ControlFlow token:) ] spids: [171 174 212 -1] ) (case_arm pat_list: [{(Lit_Other "*") (powersave) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GOVERNOR) op: Equal rhs: {(DQ (powersave))} spids: [221] ) ] spids: [221] ) (ControlFlow token:) ] spids: [215 218 230 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(C {(exit)} {(0)})] spids: [233 234 242 -1] ) ] spids: [146 150 245] ) (ForEach iter_name: CPUFREQ iter_words: [{(/sys/devices/system/cpu/cpu) (Lit_Other "*") (/cpufreq/scaling_governor)}] do_arg_iter: False body: (DoGroup children: [ (AndOr children: [ (C {(Lit_Other "[")} {(-f)} {($ VSub_Name "$CPUFREQ")} {(Lit_Other "]")}) (ControlFlow token:) ] op_id: Op_DPipe ) (SimpleCommand words: [{(echo)} {(-n)} {($ VSub_Name "$GOVERNOR")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$CPUFREQ")} spids: [282] ) ] ) ] spids: [260 287] ) spids: [254 -1] ) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$SAMPLING"))} {(Lit_Other "]")} ) (C {(Lit_Other "[")} {(-f)} {($ VSub_Name "$DOWN_FACTOR")} {(Lit_Other "]")}) ] op_id: Op_DAmp ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(-n)} {($ VSub_Name "$SAMPLING")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$DOWN_FACTOR")} spids: [322] ) ] ) ] spids: [-1 313] ) ] spids: [-1 327] ) ] spids: [109 110 330 -1] ) (case_arm pat_list: [{(restart)} {(reload)} {(force-reload)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: argument '") ($ VSub_Number "$1") ("' not supported"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[349])] ) (C {(exit)} {(3)}) ] spids: [333 338 358 -1] ) (case_arm pat_list:[{(stop)}] spids:[361362365-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Usage: ") ($ VSub_Number "$0") (" start|stop"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[380])] ) (C {(exit)} {(3)}) ] spids: [368 369 389 -1] ) ] spids: [78 84 391] ) ] )