From e154b38327c29a769b2cc46f8a83c228939ee773 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 27 Nov 2020 23:04:41 -0500 Subject: [PATCH] Qt Timing config window bug fixes for cases when OS does not have proper permissions. --- src/drivers/Qt/ConsoleWindow.cpp | 5 +-- src/drivers/Qt/TimingConf.cpp | 55 +++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 1078b838..4cd8a8f6 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -109,9 +109,8 @@ consoleWin_t::consoleWin_t(QWidget *parent) gameTimer->start( 8 ); // 120hz emulatorThread->start(); - //emulatorThread->setPriority( QThread::TimeCriticalPriority ); - setPriority( QThread::TimeCriticalPriority ); + //setPriority( QThread::TimeCriticalPriority ); } consoleWin_t::~consoleWin_t(void) @@ -2107,8 +2106,6 @@ void emulatorThread_t::run(void) init(); - //setPriority( QThread::TimeCriticalPriority ); - while ( nes_shm->runEmulator ) { fceuWrapperUpdate(); diff --git a/src/drivers/Qt/TimingConf.cpp b/src/drivers/Qt/TimingConf.cpp index 96cdaa9a..fa039e31 100644 --- a/src/drivers/Qt/TimingConf.cpp +++ b/src/drivers/Qt/TimingConf.cpp @@ -23,7 +23,7 @@ TimingConfDialog_t::TimingConfDialog_t(QWidget *parent) : QDialog( parent ) { QVBoxLayout *mainLayout, *vbox; - QHBoxLayout *hbox; + //QHBoxLayout *hbox; QGridLayout *grid; QGroupBox *emuPrioBox; @@ -93,10 +93,25 @@ void TimingConfDialog_t::emuSchedNiceChange(int val) { return; } + fceuWrapperLock(); if ( consoleWindow->emulatorThread->setNicePriority( -val ) ) { - printf("Set Nice Failed\n"); + char msg[1024]; + + sprintf( msg, "Error: system call setPriority Failed\nReason: %s\n", strerror(errno) ); +#ifdef __linux__ + strcat( msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); + strcat( msg, " /etc/security/limits.conf \n\n"); + strcat( msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); + strcat( msg, "* - priority 99 \n"); + strcat( msg, "* - rtprio 99 \n"); + strcat( msg, "* - nice -20 \n"); +#endif + printf("%s\n", msg ); + consoleWindow->QueueErrorMsgWindow( msg ); + updateSliderValues(); } + fceuWrapperUnLock(); } //---------------------------------------------------------------------------- void TimingConfDialog_t::emuSchedPrioChange(int val) @@ -107,12 +122,27 @@ void TimingConfDialog_t::emuSchedPrioChange(int val) { return; } + fceuWrapperLock(); consoleWindow->emulatorThread->getSchedParam( policy, prio ); if ( consoleWindow->emulatorThread->setSchedParam( policy, val ) ) { - printf("Set setSchedParam Failed\n"); + char msg[1024]; + + sprintf( msg, "Error: system call pthread_setschedparam Failed\nReason: %s\n", strerror(errno) ); +#ifdef __linux__ + strcat( msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); + strcat( msg, " /etc/security/limits.conf \n\n"); + strcat( msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); + strcat( msg, "* - priority 99 \n"); + strcat( msg, "* - rtprio 99 \n"); + strcat( msg, "* - nice -20 \n"); +#endif + printf("%s\n", msg ); + consoleWindow->QueueErrorMsgWindow( msg ); + updateSliderValues(); } + fceuWrapperUnLock(); } //---------------------------------------------------------------------------- void TimingConfDialog_t::emuSchedPolicyChange( int index ) @@ -123,15 +153,32 @@ void TimingConfDialog_t::emuSchedPolicyChange( int index ) { return; } + fceuWrapperLock(); consoleWindow->emulatorThread->getSchedParam( policy, prio ); policy = emuSchedPolicyBox->itemData( index ).toInt(); - consoleWindow->emulatorThread->setSchedParam( policy, prio ); + if ( consoleWindow->emulatorThread->setSchedParam( policy, prio ) ) + { + char msg[1024]; + + sprintf( msg, "Error: system call pthread_setschedparam Failed\nReason: %s\n", strerror(errno) ); +#ifdef __linux__ + strcat( msg, "Ensure that your system has the proper resource permissions set in the file:\n\n"); + strcat( msg, " /etc/security/limits.conf \n\n"); + strcat( msg, "Adding the following lines to that file and rebooting will usually fix the issue:\n\n"); + strcat( msg, "* - priority 99 \n"); + strcat( msg, "* - rtprio 99 \n"); + strcat( msg, "* - nice -20 \n"); +#endif + printf("%s\n", msg ); + consoleWindow->QueueErrorMsgWindow( msg ); + } updatePolicyBox(); updateSliderLimits(); updateSliderValues(); + fceuWrapperUnLock(); } //---------------------------------------------------------------------------- void TimingConfDialog_t::updatePolicyBox(void)