PDA

View Full Version : QThread 100% cpu usage on linux only



essial
25th April 2010, 23:32
I have an app that runs several threads in the background. On windows and mac, it doesn't use any CPU usage when 'idle', but in linux it always sits at 100% all the time. Most of the threads are sitting on tryAcquire mutex locks with 250ms timeouts, and also have 250ms sleeps in the loops in the run function. Any ideas what could cause the CPU usage only on the linux host and any ideas on how to fix it?

Thanks!

wysota
25th April 2010, 23:54
We'd have to see the code. As far as I remember on some systems the time spent in the sleep() call is treated as active cpu usage but I doubt this is what is causing the effect in your case. You'd have to see which threads are actually active.

essial
26th April 2010, 00:07
http://gitorious.org/nesicide/nesicide2-master/blobs/master/emulator/nesemulatorthread.cpp
and
http://gitorious.org/nesicide/nesicide2-master/blobs/master/debugger/breakpointwatcherthread.cpp

wysota
26th April 2010, 00:18
Please run your application under callgrind and see where your application spends all the time (you can use kcachegrind to display the data in more user-friendly format).

By the way, why (in the first file) are you using tryAcquire() without even checking if you managed to acquire the semaphore or not? And also I see you intend to operate on some dialog from a worker thread - don't do it, it's forbidden, it will crash or deadlock your application.

essial
26th April 2010, 01:13
Weird...
http://img42.imageshack.us/img42/6273/callmap.png
Seems like LibSDL is the offender, or am I mis-reading something?

wysota
26th April 2010, 09:43
More likely libasound. Just make sure you are tracing the proper thread.

essial
26th April 2010, 15:33
OK apparently this wasn't a Qt problem, sorry! Basically the issue is Ubuntu related. For some bizarre reason the libsdl package in linux decided to include the alsa based libsdl subsystem instead of the pulseaudio one. Switching from the alsa libsdl package to the pulseaudio one (libsdl1.2debian-pulseaudio) instantly fixed the problem and now it works perfectly. Whodathunkit..