enigma2-4.2.1.17: add small patch
[opendreambox.git] / meta-opendreambox / recipes-dreambox / enigma2 / enigma2-4.2.1.17-dm7080 / 0001-set-priority-of-our-kernel-demux-threads-on-e2-start.patch
1 From 2c1f690796111bd369fccf2d39b3893f30e1870b Mon Sep 17 00:00:00 2001
2 From: ghost <andreas.monzner@dream-property.net>
3 Date: Sun, 8 Feb 2015 09:45:51 +0100
4 Subject: [PATCH] set priority of our kernel demux threads on e2 start (ask
5  the linux people why sched_setscheduler is only usable from
6  GPL kernel modules)
7
8 ---
9  mytest.py |   46 ++++++++++++++++++++++++++++++++++++++++++++++
10  1 file changed, 46 insertions(+)
11
12 diff --git a/usr/lib/enigma2/python/mytest.py b/usr/lib/enigma2/python/mytest.py
13 index 87bbf82..5886609 100644
14 --- a/usr/lib/enigma2/python/mytest.py
15 +++ b/usr/lib/enigma2/python/mytest.py
16 @@ -735,8 +735,54 @@ Screens.Ci.InitCiConfig()
17  #t_conn = t.timeout.connect(dump_malloc_stats)
18  #t.start(1000)
19  
20 +from threading import Thread
21 +class FixDemuxThread(Thread):
22 +       def __init__(self):
23 +               Thread.__init__(self)
24 +               self.start()
25 +
26 +       def process_num(self, name):
27 +               # this is a bad example... please dont use popen in enigma2
28 +               from os import popen
29 +               f = popen('pidof %s' % name, 'r')
30 +               if f is not None:
31 +                       stdin = f.read()
32 +                       ret = f.close()
33 +                       if ret is None:
34 +                               return int(stdin)
35 +               return None
36 +
37 +       def run(self):
38 +               # this fixes the infrequently broken recordings (missing ts packets in record file)
39 +               # when "rave record buffer overflow detected" messages are visible in kernel log
40 +               # (when multiple recordings are running at the same time)
41 +               #
42 +               # under normal circumstances i would prefer to do this in our kernel hardware drivers
43 +               # but the linux people only allow to call sched_setscheduler from GPL kernel modules
44 +               # so we must do it via userspace syscall
45 +               SCHED_FIFO = 1
46 +               import ctypes, ctypes.util
47 +               c = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))
48 +               class _SchedParams(ctypes.Structure):
49 +                       _fields_ = [('sched_priority', ctypes.c_int)]
50 +               # set prio of dmxX processes to same prio as linux threaded interrupts
51 +               prio = c.sched_get_priority_max(SCHED_FIFO) / 2 + 1
52 +               schedParams = _SchedParams(prio)
53 +               params = ctypes.byref(schedParams)
54 +               process_num = self.process_num
55 +               x = 0
56 +               while True:
57 +                       pid = process_num('dmx%d' %x)
58 +                       if pid is None:
59 +                               break
60 +                       if c.sched_setscheduler(pid, SCHED_FIFO, params) == -1:
61 +                               print "sched_setscheduler failed for dmx%d" %x
62 +                       x += 1
63 +
64  # first, setup a screen
65  try:
66 +       thread = FixDemuxThread()
67 +
68         runScreenTest()
69  
70         plugins.shutdown()
71 -- 
72 1.7.10.4
73