Hi,
I tested my workaround the last days and it looks quite good.
With this workaround I am able to run external scripts before a subscription starts and after the last subscription ends. So I am able to change the powermanagement settings while tvheadend is running a subscription (e.g. a stream to kodi or while recording) and keep low power consumption if tvheaded is not streaming or recording.
The changes that I made can be found in the attachedtvheadend-3.4_patch.diff.
These changes do the following:
1. Add 2 fields in configuration in order to set one script to run before subscription starts and a second script to run after the last subscription ends
2. Run these script before and after subscription
This code might not be perfect since my c++ knowledge is poor (actually not existing). Also this is still a workaround for some other problems related to powermanagement or the linux kernel. In order to do these changes you need to checkout the project from github, build the project and deb-package the whole thing. Since this took most of my time I hope that the tvheadend-developers will add this workaround to the official version. I created a ticket (#2596) for this change.
I configured the following:
!config.png!
Before a new subscription starts the pre-shell script will be called by tvheadend (pre.sh):
#!/bin/bash
echo start `date` >> /home/hts/hts_events.txt
sleep 1
sudo cpufreq-set -c 0 -d 1.95GHz -g powersave
sudo cpufreq-set -c 1 -d 1.95GHz -g powersave
This scripts sets the minimal cpu frequency for all cpus to about 2GHz. I played with different frequencies. Since the recording and streaming over ethernet seems to need high-power I ended at 2GHz. The strategy for cpu frequency scaling is still "powersave" and not "performance" so that the frequency changes from 2GHz to 2.4GHz. Before changing the cpu frequency this script waits 1 second (sleep). I believe that I had problems when zapping between channels because zapping means that an unsubscription is done before a new subscription starts.
After the +last+ subscription ends the
post.sh-script will be called by tvheadend:
#!/bin/bash
echo stop `date` >> /home/hts/hts_events.txt
sudo cpufreq-set -c 0 -d 500MHz -g powersave
sudo cpufreq-set -c 1 -d 500MHz -g powersave
This script set the minimal cpu frequency back to 500MHz.
In order to manipulate the cpu frequency I use the "cpufreq-set" command. Since this command needs root priviledges I added the following lines to the "/etc/sudoers" file so that the
hts-user who runs tvheadend is able to execute this command:
# Allow hts to set the cpu frequency
User_Alias CPUFREQUA = hts
Cmnd_Alias CPUFREQ = /usr/bin/cpufreq-set
CPUFREQUA ALL = NOPASSWD: CPUFREQ
Be very careful since if there are any syntax errors in this file you won't be able tosudo anything!
For my setup this workaround works quite good. It is still a workaround and not the solution. I use this workaround in combination with KODI (former XBMC). I noticed that I still have "Continuity counter errors" when KODI is not runnig. I believe that this is because even if KODI is doing anything it takes about 30% cpu usage. It still seems to be important to hold the system busy.
But without this workaround I am not able to use tvheadend at all.