Increased CPU load while running a custom screensaver
#1
I've written a simple Python screensaver for H3-based boards (using it on a NanoPI M1 with OpenElec and Kodi 16.1) to disable the video while idle, allowing the attached monitor to power down. It works perfectly except that the CPU load as seen with 'top' rises significantly when it kicks in.
I'm using the reFocus skin and while having 'top' running on a SSH session I can see that, with some music file playing, the normal load is under 8% but as soon as the screensaver kicks in it rises to around 25%. This causes the CPU clocks to speed up and the temperature on the CPU to rise quite a bit.
I've read somewhere that one/several screensavers disable the renderer when they kick in to lower the CPU / GPU load. My questions are:

1. Is there API support for this when using Python ?
2. Is there another possible cause for this behaviour ? That can be fixed on the Python side ?

Below is the code for the screensaver.

Code:
import xbmcaddon
import xbmcgui
import xbmc
import os
import struct
import fcntl

addon = xbmcaddon.Addon()
addon_name = addon.getAddonInfo('name')
addon_path = addon.getAddonInfo('path')

class Screensaver(xbmcgui.WindowXMLDialog):

    class ExitMonitor(xbmc.Monitor):

        def __init__(self, exit_callback):
            self.exit_callback = exit_callback

        def onScreensaverDeactivated(self):
            self.exit_callback()

    def onInit(self):
        self.log('onInit')
        buffer = struct.pack('LLLL',0,1,0,0)
        dev = os.open('/dev/disp', os.O_RDWR)
        try:
            fcntl.ioctl(dev, 0x0C, buffer)
        finally:
            os.close(dev)
        self.exit_monitor = self.ExitMonitor(self.exit)

    def exit(self):
        self.abort_requested = True
        self.exit_monitor = None
        buffer = struct.pack('LLLL',0,0,0,0)
        dev = os.open('/dev/disp', os.O_RDWR)
        try:
            fcntl.ioctl(dev, 0x0C, buffer)
        finally:
            os.close(dev)
        self.log('exit')
        self.close()

    def log(self, msg):
        xbmc.log(u'H3Blank hdmi screensaver: %s' % msg)


if __name__ == '__main__':
    screensaver = Screensaver(
        'script-%s-main.xml' % addon_name,
        addon_path,
        'default',
    )
    screensaver.doModal()
    del screensaver
    sys.modules.clear()
Reply

Logout Mark Read Team Forum Stats Members Help
Increased CPU load while running a custom screensaver0