Set thread priority relative to backend
This also removed direct calls to backend real_time_priority for good measure.
This commit is contained in:
parent
72deb74c58
commit
dd4a1a6d73
@ -164,7 +164,7 @@ public:
|
||||
/** Return true if the backed is JACK */
|
||||
virtual bool is_jack () const { return false; }
|
||||
|
||||
virtual int client_real_time_priority () { return PBD_RT_PRI_PROC; }
|
||||
virtual int client_real_time_priority () { return 0; }
|
||||
|
||||
/* Discovering devices and parameters */
|
||||
|
||||
|
@ -115,9 +115,6 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
|
||||
void request_device_list_update();
|
||||
void launch_device_control_app();
|
||||
|
||||
int client_real_time_priority ();
|
||||
bool is_realtime() const;
|
||||
|
||||
// for the user which hold state_lock to check if reset operation is pending
|
||||
bool is_reset_requested() const { return _hw_reset_request_count.load(); }
|
||||
|
||||
|
@ -1067,6 +1067,12 @@ AudioEngine::start (bool for_latency)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_backend->is_realtime ()) {
|
||||
pbd_set_engine_rt_priority (_backend->client_real_time_priority ());
|
||||
} else {
|
||||
pbd_set_engine_rt_priority (0);
|
||||
}
|
||||
|
||||
_running = true;
|
||||
|
||||
if (_session) {
|
||||
@ -1190,38 +1196,6 @@ AudioEngine::get_dsp_load() const
|
||||
return _backend->dsp_load ();
|
||||
}
|
||||
|
||||
bool
|
||||
AudioEngine::is_realtime() const
|
||||
{
|
||||
if (!_backend) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return _backend->is_realtime();
|
||||
}
|
||||
|
||||
int
|
||||
AudioEngine::client_real_time_priority ()
|
||||
{
|
||||
if (!_backend) {
|
||||
assert (0);
|
||||
return PBD_RT_PRI_PROC;
|
||||
}
|
||||
if (!_backend->is_realtime ()) {
|
||||
/* this is only an issue with the Dummy backend.
|
||||
* - with JACK, we require rt permissions.
|
||||
* - with ALSA/PulseAudio this can only happen if rt permissions
|
||||
* are n/a. Other attempts to get rt will fail likewise.
|
||||
*
|
||||
* perhaps:
|
||||
* TODO: use is_realtime () ? PBD_SCHED_FIFO : PBD_SCHED_OTHER
|
||||
*/
|
||||
return PBD_RT_PRI_PROC; // XXX
|
||||
}
|
||||
|
||||
return _backend->client_real_time_priority();
|
||||
}
|
||||
|
||||
void
|
||||
AudioEngine::transport_start ()
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ typedef std::map<pthread_t, std::string> ThreadMap;
|
||||
static ThreadMap all_threads;
|
||||
static pthread_mutex_t thread_map_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static Glib::Threads::Private<char> thread_name (free);
|
||||
static int base_priority_relative_to_max = -20;
|
||||
|
||||
namespace PBD
|
||||
{
|
||||
@ -272,6 +273,19 @@ pbd_pthread_create (
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
pbd_set_engine_rt_priority (int p)
|
||||
{
|
||||
/* this is mainly for JACK's benefit */
|
||||
const int p_max = sched_get_priority_max (SCHED_FIFO);
|
||||
const int p_min = sched_get_priority_min (SCHED_FIFO);
|
||||
if (p <= 0 || p <= p_min + 10 || p > p_max) {
|
||||
base_priority_relative_to_max = -20;
|
||||
} else {
|
||||
base_priority_relative_to_max = p - p_max;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
pbd_pthread_priority (PBDThreadClass which)
|
||||
{
|
||||
@ -292,11 +306,11 @@ pbd_pthread_priority (PBDThreadClass which)
|
||||
return -13;
|
||||
}
|
||||
#else
|
||||
int base = -20;
|
||||
int base = base_priority_relative_to_max;
|
||||
const char* p = getenv ("ARDOUR_SCHED_PRI");
|
||||
if (p && *p) {
|
||||
base = atoi (p);
|
||||
if (base > -5 && base < 5) {
|
||||
if (base > -5 || base < -85) {
|
||||
base = -20;
|
||||
}
|
||||
}
|
||||
@ -309,6 +323,8 @@ pbd_pthread_priority (PBDThreadClass which)
|
||||
default:
|
||||
case THREAD_PROC:
|
||||
return base - 2;
|
||||
case THREAD_CTRL:
|
||||
return base - 3;
|
||||
case THREAD_IO:
|
||||
return base - 10;
|
||||
}
|
||||
@ -322,23 +338,12 @@ pbd_absolute_rt_priority (int policy, int priority)
|
||||
const int p_min = sched_get_priority_min (policy); // Linux: 1
|
||||
const int p_max = sched_get_priority_max (policy); // Linux: 99
|
||||
|
||||
if (priority == 0) {
|
||||
assert (0);
|
||||
priority = (p_min + p_max) / 2;
|
||||
} else if (priority > 0) {
|
||||
/* value relative to minium */
|
||||
priority += p_min - 1;
|
||||
} else {
|
||||
/* value relative maximum */
|
||||
/* priority is relative to the max */
|
||||
assert (priority < 0);
|
||||
priority += p_max + 1;
|
||||
}
|
||||
|
||||
if (priority > p_max) {
|
||||
priority = p_max;
|
||||
}
|
||||
if (priority < p_min) {
|
||||
priority = p_min;
|
||||
}
|
||||
priority = std::min (p_max, priority);
|
||||
priority = std::max (p_min, priority);
|
||||
return priority;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user