Skip to content

Commit

Permalink
Merge pull request #31 from daschuer/limits
Browse files Browse the repository at this point in the history
check for rlimits on Linux
  • Loading branch information
daschuer committed Jul 3, 2013
2 parents c8f4af9 + abfba17 commit 9f1d25e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
1 change: 1 addition & 0 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
11 changes: 11 additions & 0 deletions src/dlgprefsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
17 changes: 12 additions & 5 deletions src/dlgprefsounddlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>729</width>
<height>363</height>
<width>743</width>
<height>369</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -106,9 +106,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="underflowHLayout"/>
</item>
</layout>
</item>
<item>
Expand All @@ -127,6 +124,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="limitsHint">
<property name="text">
<string>&lt;ul&gt;&lt;li&gt;Enable Real-Time scheduling (currently disabled) see the &lt;a href=&quot;http://www.mixxx.org/wiki/doku.php/troubleshooting?s[]=limits&quot;&gt;Mixxx Wiki&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
39 changes: 39 additions & 0 deletions src/util/rlimit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "util/rlimit.h"

#ifdef __LINUX__

extern "C" {
#include <sys/time.h>
#include <sys/resource.h>
}

// 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;
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() >= PA_RTPRIO); // PA sets RtPrio = 82
}

#endif // __LINUX__
14 changes: 14 additions & 0 deletions src/util/rlimit.h
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit 9f1d25e

Please sign in to comment.