Reduce XBMC UI rendering CPU usage


14 posts
by rubenvb » Mon Feb 18, 2013 7:37 pm
Hi,

Is there any way to reduce XBMC's CPU usage when rendering the UI? It is near 100% even when idle.

I would like to keep xbmc active so that when I turn on my tv and set my receiver to its HDMI port, the XBMC UI pops up. I'd even bear waiting for XBMC to start up completely.

Right now, my only option is to keep XBMC running, but this means high CPU usage. I'd like to keep my owncloud webserver running in the background, which could be influenced negatively by the heavy XBMC process.

I think the best way I can handle this is by detecting if HDMI is connected, and if so: run
Code: Select all
systemctl start xbmc

Once HDMI is unconnected (i.e. the tv is turned off, or the receiver stops taking input (let's hope it works like that)), run
Code: Select all
systemctl stop xbmc


But if anyone has found a better way (like through XBMC itself), please let me know!

Ruben
Posts: 4
Joined: Mon Feb 18, 2013 7:22 pm
by yanglifu90 » Mon Feb 18, 2013 9:58 pm
Just curious, what is your setup then? Like which distribution, how is the owncloud server connected, etc..You could buy another RPi since it is cheap.
Posts: 8
Joined: Tue Nov 27, 2012 11:19 am
by worm » Tue Feb 19, 2013 12:04 pm
Slight health warning - though I'm far from an expert in this area - where are you getting the CPU usage figures?

My understanding is that the figures reported in the XBMC status screen are inaccurate. I'm sure someone in the know will be able to confirm either way
Posts: 32
Joined: Wed Jul 11, 2012 12:31 pm
by rubenvb » Tue Feb 19, 2013 12:14 pm
The current setup is:

Code: Select all
router --<ethernet>-- pi --<HDMI>--receiver--<HDMI>--TV
                      |
                    <USB>
                      |
                     HDD


But I don't quite see how this matters. A simple daemon or systemd thing to automatically shut off XBMC when there's no output connected to the HDMI port on the pi would be a large step in the right direction.

CPU usage is between 50-90% for an idle XBMC GUI. This is normal, or so I read on pretty much every place on the net.
Posts: 4
Joined: Mon Feb 18, 2013 7:22 pm
by nadnerb » Tue Feb 19, 2013 10:41 pm
Try running top via ssh for the true value.
The figures shown in the system info page of XBMC are incorrect. Hence why in Raspbmc they have been disabled.
User avatar
Posts: 175
Joined: Sun May 13, 2012 11:22 am
by rubenvb » Wed Feb 20, 2013 6:27 am
Top and htop is where I got my figures, I didn't even know xbmc showed CPU usage somewhere.
Posts: 4
Joined: Mon Feb 18, 2013 7:22 pm
by Egil » Wed Feb 20, 2013 7:12 am
That seems a bit excessive CPU usage. My Raspbmc idles at about 20%.
Posts: 4
Joined: Tue Feb 19, 2013 10:10 pm
by rubenvb » Wed Feb 20, 2013 8:11 am
Because it seems no one is willing to believe me, and just posting "works for me" instead of answering my question...

https://github.com/OpenELEC/OpenELEC.tv/issues/607
http://archlinuxarm.org/forum/viewtopic ... 4&start=70

The second one seems to contain a nice fix for the CPU usage, but even then I'd like to have the xbmc systemd unit to automatically start and stop when I need it.
Posts: 4
Joined: Mon Feb 18, 2013 7:22 pm
by naors » Sat May 04, 2013 3:55 am
Hi Rubenvb

I came across your post when I was searching for a solution to the same problem I have.
When XBMC is operational and idle, it takes 90% CPU on my RPi. Nothing helped me to resolve this problem, and even though you presented a "solution", it only reduces the CPU consumption. It doesn't produces a complete solution for this.

I thought of writing something of my own to detect the change in the HDMI signal but why work so hard when such a utility already exists. So here's what I did:
First, I used update-rc.d to disable xbmc starting up automatically at system boot.
Second thing, I wrote a small script and put it in a service I wrote (you can also put it in rc.local) so it will run at system boot instead of xbmc.
The script uses the tvservice binary to query the status of HDMI status in a resolution of 1 second.
I discovered that when you turn on the TV and put it into the channel of the RPi, the HDMI status retrieved by the tvservice shows a change for a couple of seconds. This was a good indication for me to know that I need to start the xbmc service as I only turn on the TV for using XBMC (all other operations are done through the ssh shell).
I didn't discover a change in the signal when the TV is turned off so I created a shortcut in XBMC to quit when I am done with it (I am too lazy to scroll the main menu for the Quit button :)).
And that's it, the XBMC is now operational only when I need it.
Here's the very simple BASH script I wrote:

#!/bin/bash
on_mode="0x120009"
while [ 1 ]
do
status=`tvservice -s | awk {'print $2'}`
if [ $status == $on_mode ]
then
echo "Detected hdmi signal - Starting xbmc . . ."
sudo service xbmc start
fi
sleep 1
done

I hope this helps you and all the others.

Naor
Posts: 3
Joined: Sat May 04, 2013 3:37 am
by peewee2 » Mon May 06, 2013 10:55 pm
I think you may find that the CPU usage depends on what you are doing.

I suspect that if you leave the XBMC outputting a program it will use more CPU than if the XBMC is just displaying the home screen.

I am not sure if using the tvservice command is useful, as far as I can see it will give the same output if the TV is using the HDMI port or displaying live TV.

I can echo an earlier post, my pi shows 25% CPU when the XBMC instance is idle with my TV using the SCART input.

My TV HDMI status :
xbian@xbian ~ $ tvservice -s
state 0x12000a [HDMI CEA (19) RGB lim 16:9], 1280x720 @ 50Hz, progressive

my pi is running 76 processes

xbian@xbian ~ $ top -b -n 1
top - 23:48:06 up 9:43, 1 user, load average: 0.37, 0.42, 0.41
Tasks: 77 total, 2 running, 75 sleeping, 0 stopped, 0 zombie
%Cpu(s): 27.8 us, 7.6 sy, 0.4 ni, 62.4 id, 1.2 wa, 0.0 hi, 0.6 si, 0.0 st
KiB Mem: 123536 total, 110348 used, 13188 free, 11368 buffers
KiB Swap: 127996 total, 0 used, 127996 free, 28820 cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2228 xbian 20 0 271m 46m 9.9m S 26.2 38.9 190:27.00 xbmc.bin
2839 xbian 20 0 6140 1240 968 R 10.5 1.0 0:00.06 top
41 root 20 0 0 0 0 R 5.2 0.0 8:45.28 mmcqd/0

As you can see, your situation is odd, and there must be something different about your set up.

Pete
Posts: 53
Joined: Sun Apr 14, 2013 7:04 pm
by peewee2 » Mon May 06, 2013 11:46 pm
Ah, just spotted what goes wrong.

If I navigate through the video menus ie

videos>add ons > BBC IPlayer>BBC1>Foyles War

The CPU jumps to 91% ( using top ) and stays at 91%

once I choose an episode and the video starts playing, CPU drops to 29%

if I bring up the on screen video controls, CPU jumps to 50%.

when I exit the movie CPU jumps back to 90%, coming back to the BBC1 program list CPU drops to 25%.

I guess ( have not tried it ) that when a movie completes, xbmc returns to the episode list which hammers the CPU.

If I put the TV to standby, the CPU usage remains high, even switching off the TV the CPU stays high.

I think there must be a bit of buggy code in the episode display logic.

unfortunately the tvservice command does not seem useful as it still shows the same data, this is with a Panasonic Viera TV

=================

This is wacky, having rebooted my xbian CPU usage is now around 2%

Pete
Posts: 53
Joined: Sun Apr 14, 2013 7:04 pm
by naors » Tue May 07, 2013 3:03 am
Hi peewee2,

You are probably right that my system is different than yours.
I am using Raspbian and installed Xbmc from cocooncrash repository. I tried compiling it myself but found it to be slower than receiving the updates from Michael's updated repository (thank you for that Michael Gorven!).
It seems that in my system Xbmc, when lying flat on the main menu without me moving a finger catches 90% CPU. I had to find a solution for that and using tvservice seemed faster than writing my own code. It is working wonderful for me.
I wonder why it didn't work for you. If you can post some more info, maybe I could take a look.

I also think I can improve this and query Xbmc for its current status and if the status is idle (playing nothing) for let's say 15-20 minutes, stop the service. I haven't got the time to investigate this yet.
I promise that I will keep you up to date with my latest discoveries.

Naor
Posts: 3
Joined: Sat May 04, 2013 3:37 am
by marcbres » Wed Jun 19, 2013 7:16 am
Hello naors,

I tried to use your script, but unfortunately the status does not change for me either.
I was thinking that maybe some hdmi parameter makes your raspberry do this change, please can you share with us the hdmi_* parameters of your /boot/config.txt?

Thank you very much!
Posts: 1
Joined: Wed Jun 19, 2013 7:12 am
by naors » Wed Jun 19, 2013 11:28 am
Hi Marcbres,

All my hdmi_* parameters are commented out so I guess I am using the defaults.
The only thing that is not commented out is my gpu_mem.

Naor
Posts: 3
Joined: Sat May 04, 2013 3:37 am