[Interest] Poor QMethod::invoke performance across threads on i.MX53

Thiago Macieira thiago.macieira at intel.com
Mon May 18 09:46:34 CEST 2015


On Thursday 14 May 2015 18:18:52 Robert Daniels wrote:
> I'm working on a project that uses a QThread to process communication over a
> TCP connection. In trying to improve performance I've tracked down an odd
> slow-down when we use QMethod::invoke to force a method to be called on the
> correct thread.

You don't need threads to get acceptable performance of TCP. The networking is 
usually much slower than the processing itself.

> This is an embedded project running on a Freescale i.MX53.  On this board,
> I've measured the time to make this call and it is on average around 400000
> ns. I've measured this on our i.MX6 board as well (with only one core
> enabled) and it takes only 60000 ns. This doesn't look right to me. I would
> expect the difference to be at most 2x, not 6x.

Can you benchmark this in any way? What is consuming CPU time here? Is it in 
kernel mode? Is it waiting? Is it the QSemaphore inside the blocking queued 
connection>

> Is there something I'm missing here in my expectations or is there something
> fundamentally wrong causing this slow-down?

There are problems, but not related to the issue you're reporting.

> class WorkerThread : public QThread
> {
>     Q_OBJECT
> 
> public:
>     WorkerThread()
>     {
>         moveToThread(this);

This is wrong. Never do "moveToThread(this)", since it's very difficult to then 
destroy the QThread object. This is unrelated to the problem and it's probably 
only for simplicity of your testcase.

> private slots:
>     void onTimer()
>     {
>         qDebug() << "Begin test.";
>         QElapsedTimer timer;
>         qint64 total = 0;
>         const int cnt = 100000;
> 
>         for (int i = 0; i < cnt; i++) {
>             timer.start();
>             worker.myMethod(i);
>             total += timer.nsecsElapsed();

nsecsElapsed may not have enough resolution on your board. The problem might 
not be slowness, but simply that the clock isn't good enough.

Move the timer.start() and timer.elapsed() calls outside of the loop.

And please check with your admins if they can remove this message in emails 
you send to the public, which are archived and distributed all over the 
Internet:

> Ce message, ainsi que tous les fichiers joints à ce message, peuvent
> contenir des informations sensibles et/ ou confidentielles ne devant pas
> être divulguées. Si vous n'êtes pas le destinataire de ce message (ou que
> vous recevez ce message par erreur), nous vous remercions de le notifier
> immédiatement à son expéditeur, et de détruire ce message. Toute copie,
> divulgation, modification, utilisation ou diffusion, non autorisée, directe
> ou indirecte, de tout ou partie de ce message, est strictement interdite.
> Se désabonner: Si vous souhaitez être retiré de notre liste de diffusion,
> s'il vous plaît envoyer vos coordonnées à
> CASL.unsubscribe at legrand.ca<mailto:casl.unsubscribe at legrand.ca> et indiquer
> quels sont les messages que vous ne souhaitez plus recevoir.
> 
> 
> This e-mail, and any document attached hereby, may contain confidential

PS: "hereto", not "hereby".

> and/or privileged information. If you are not the intended recipient (or
> have received this e-mail in error) please notify the sender immediately
> and destroy this e-mail. Any unauthorized, direct or indirect, copying,
> disclosure, distribution or other use of the material or parts thereof is
> strictly forbidden. Unsubscribe: If you would like to be removed from our
> mailing list, please send your contact information to
> CASL.unsubscribe at legrand.ca<mailto:casl.unsubscribe at legrand.ca> and
> indicate what messages you no longer wish to receive.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list