Skip to content

Instantly share code, notes, and snippets.

@stesie
Created October 3, 2012 14:50
Show Gist options
  • Save stesie/3827328 to your computer and use it in GitHub Desktop.
Save stesie/3827328 to your computer and use it in GitHub Desktop.
N900 DBus monitory to increase CPU speed during VoIP calls
#! /usr/bin/python
import gobject
import dbus
import pyinotify
from dbus.mainloop.glib import DBusGMainLoop
class CpufreqController(pyinotify.ProcessEvent):
minfreq = 125000
def getMinfreq(self):
return self.minfreq
def setMinfreq(self, v):
self.minfreq = v;
if self.getSystemMinfreq() != v:
self.setSystemMinfreq(v)
def getSystemMinfreq(self):
f = open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq', 'r')
return int(f.read(), 10)
def setSystemMinfreq(self, newFreq):
f = open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq', 'w')
f.write(str(newFreq))
def process_IN_MODIFY(self, event):
if self.getSystemMinfreq() < self.minfreq:
self.setSystemMinfreq(self.minfreq)
class DbusHandler:
def __init__(self, cpufreq):
self.cpufreq = cpufreq;
def call_request(self, _bus, msg):
if not (msg.get_type() == 1 and msg.get_member() == 'call_request') and \
not (msg.get_type() == 4 and msg.get_member() == 'call_ended'):
return
args = msg.get_args_list()
if args[0].find("sip") < 0:
return # don't care for non-sip connections
if msg.get_member() == 'call_request':
self.cpufreq.setMinfreq(600000)
else:
self.cpufreq.setMinfreq(125000)
if __name__ == '__main__':
gobject.threads_init()
DBusGMainLoop(set_as_default = True)
freq = CpufreqController()
wm = pyinotify.WatchManager()
wm.add_watch('/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq', pyinotify.IN_MODIFY)
notifier = pyinotify.ThreadedNotifier(wm, freq)
notifier.start()
bus = dbus.SessionBus()
bus.add_match_string("interface='com.nokia.policy.telephony'")
dbh = DbusHandler(freq)
bus.add_message_filter(dbh.call_request)
gobject.MainLoop().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment