From aa2f6bf92b4bc911ec726381e7e5579d7399b376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 3 Jul 2013 00:30:47 +0200 Subject: [PATCH 1/2] check for rlimits on Linux --- build/depends.py | 1 + src/dlgprefsound.cpp | 11 +++++++++++ src/dlgprefsounddlg.ui | 17 ++++++++++++----- src/util/rlimit.cpp | 35 +++++++++++++++++++++++++++++++++++ src/util/rlimit.h | 14 ++++++++++++++ 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/util/rlimit.cpp create mode 100644 src/util/rlimit.h diff --git a/build/depends.py b/build/depends.py index bb89ca6c478..40918539803 100644 --- a/build/depends.py +++ b/build/depends.py @@ -736,6 +736,7 @@ def sources(self, build): "util/timer.cpp", "util/performancetimer.cpp", "util/version.cpp", + "util/rlimit.cpp", # Add the QRC file which compiles in some extra resources # (prefs icons, etc.) diff --git a/src/dlgprefsound.cpp b/src/dlgprefsound.cpp index 5578bd4af41..920c6a6282f 100644 --- a/src/dlgprefsound.cpp +++ b/src/dlgprefsound.cpp @@ -21,6 +21,7 @@ #include "playermanager.h" #include "soundmanager.h" #include "sounddevice.h" +#include "util/rlimit.h" /** * Construct a new sound preferences pane. Initializes and populates all the @@ -100,6 +101,16 @@ DlgPrefSound::DlgPrefSound(QWidget *pParent, SoundManager *pSoundManager, new ControlObjectThreadMain("[Master]", "latency"); connect(m_pMasterLatency, SIGNAL(valueChanged(double)), this, SLOT(masterLatencyChanged(double))); + + qDebug() << "RLimit Cur " << RLimit::getCurRtPrio(); + qDebug() << "RLimit Max " << RLimit::getMaxRtPrio(); + +#ifdef __LINUX__ + if (RLimit::isRtPrioAllowed()) +#endif // __LINUX__ + { + limitsHint->hide(); + } } DlgPrefSound::~DlgPrefSound() { diff --git a/src/dlgprefsounddlg.ui b/src/dlgprefsounddlg.ui index d5eb133de77..910d8cf4dee 100644 --- a/src/dlgprefsounddlg.ui +++ b/src/dlgprefsounddlg.ui @@ -6,8 +6,8 @@ 0 0 - 729 - 363 + 743 + 369 @@ -106,9 +106,6 @@ - - - @@ -127,6 +124,16 @@ + + + + <ul><li>Enable Real-Time scheduling (currently disabled) see the <a href="http://www.mixxx.org/wiki/doku.php/troubleshooting?s[]=limits">Mixxx Wiki</a></li></ul> + + + true + + + diff --git a/src/util/rlimit.cpp b/src/util/rlimit.cpp new file mode 100644 index 00000000000..ed53ae68083 --- /dev/null +++ b/src/util/rlimit.cpp @@ -0,0 +1,35 @@ +#include "rlimit.h" + +#ifdef __LINUX__ + +extern "C" { + #include + #include +} + +// static +unsigned int RLimit::getCurRtPrio() { + struct rlimit limits; + if(getrlimit(RLIMIT_RTPRIO, &limits)) { + // Error + return 100; + } + return limits.rlim_cur; +} + +// static +unsigned int RLimit::getMaxRtPrio() { + struct rlimit limits; + if(getrlimit(RLIMIT_RTPRIO, &limits)) { + // Error + return 0; + } + return limits.rlim_max; +} + +// static +bool RLimit::isRtPrioAllowed() { + return (getCurRtPrio() >= 82); // PA sets RtPrio = 82 +} + +#endif // __LINUX__ diff --git a/src/util/rlimit.h b/src/util/rlimit.h new file mode 100644 index 00000000000..d96fc88e4e8 --- /dev/null +++ b/src/util/rlimit.h @@ -0,0 +1,14 @@ +#ifndef RLIMIT_H +#define RLIMIT_H + +#ifdef __LINUX__ + +class RLimit { + public: + static unsigned int getCurRtPrio(); + static unsigned int getMaxRtPrio(); + static bool isRtPrioAllowed(); +}; + +#endif // __LINUX__ +#endif // RLIMIT_H_ From abfba17b80b5d8bc23d3681b7edd541909ce071e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 3 Jul 2013 19:56:48 +0200 Subject: [PATCH 2/2] minor fixes according to review comments --- src/util/rlimit.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/rlimit.cpp b/src/util/rlimit.cpp index ed53ae68083..088f9157046 100644 --- a/src/util/rlimit.cpp +++ b/src/util/rlimit.cpp @@ -1,4 +1,4 @@ -#include "rlimit.h" +#include "util/rlimit.h" #ifdef __LINUX__ @@ -7,6 +7,10 @@ extern "C" { #include } +// TODO(xxx) this is the result from a calculation inside PortAudio +// We should query the value from PA or do the same calculations +const rlim_t PA_RTPRIO = 82; // PA sets RtPrio = 82 + // static unsigned int RLimit::getCurRtPrio() { struct rlimit limits; @@ -29,7 +33,7 @@ unsigned int RLimit::getMaxRtPrio() { // static bool RLimit::isRtPrioAllowed() { - return (getCurRtPrio() >= 82); // PA sets RtPrio = 82 + return (getCurRtPrio() >= PA_RTPRIO); // PA sets RtPrio = 82 } #endif // __LINUX__