Skip to content

Commit

Permalink
check for rlimits on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Jul 2, 2013
1 parent 737a063 commit aa2f6bf
Show file tree
Hide file tree
Showing 5 changed files with 73 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
35 changes: 35 additions & 0 deletions src/util/rlimit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "rlimit.h"

#ifdef __LINUX__

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

// 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__
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 aa2f6bf

Please sign in to comment.