简体   繁体   中英

How to lower QT Gui thread priority?

I am designing an embedded QT application in linux. Part of my application is a real-time audio stream that is the top priority of the system and has to always meet it's real time deadlines. I have set this thread to be scheduled as FIFO with max priority:

schparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
pthread_setschedparam(pthread_self(),SCHED_FIFO, &schparam)

I need my QT GUI to always yield and let this real time process have priorty. So I tried setting QT GUI thread priorty as

QThread::currentThread()->setPriority(QThread::LowestPriority);

Yet this is still not working. If I interact with the GUI for too long my real-time audio stream is xflowing.

Is there some other priority parameter I need to set here? Unfortunately switching to a real-time kernel is not an option.

If you are running under linux, you can create a script and run the script after your application started.

The following sample script uses chrt to changes your Qt app threads priority.

To use the following script, you need to modify the script to change "your_qt_app" name. Also, in the script, I assigned the threads of your_qt_app to use FIFO real-time policy with priority of 10. You can adjust accordingly based on your needs.

Also the "ps" command in the script can help you analyze your system processes/threads priorities.

#!/bin/bash
threads_to_change_prio="
    your_qt_app
 "

 ps -Leo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm,args  > ./threads_prio.txt
 for i in $threads_to_change_prio; do
      tids=$(cat ./threads_prio.txt | grep $i | awk '{print $2}');
      for j in $tids; do        
          chrt -f -p 10 $j;
      done
 done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM