13
0

Use config variable to set IOTask thread policy

This commit is contained in:
Robin Gareus 2024-09-28 02:48:15 +02:00
parent dcd79f3135
commit d089f38481
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 23 additions and 34 deletions

View File

@ -223,6 +223,7 @@ CONFIG_VARIABLE (bool, allow_special_bus_removal, "allow-special-bus-removal", f
CONFIG_VARIABLE (int32_t, processor_usage, "processor-usage", -1) CONFIG_VARIABLE (int32_t, processor_usage, "processor-usage", -1)
CONFIG_VARIABLE (int32_t, cpu_dma_latency, "cpu-dma-latency", -1) /* >=0 to enable */ CONFIG_VARIABLE (int32_t, cpu_dma_latency, "cpu-dma-latency", -1) /* >=0 to enable */
CONFIG_VARIABLE (int32_t, io_thread_count, "io-thread-count", -2) CONFIG_VARIABLE (int32_t, io_thread_count, "io-thread-count", -2)
CONFIG_VARIABLE (int32_t, io_thread_policy, "io-thread-policy", 0)
CONFIG_VARIABLE (gain_t, max_gain, "max-gain", 2.0) /* +6.0dB */ CONFIG_VARIABLE (gain_t, max_gain, "max-gain", 2.0) /* +6.0dB */
CONFIG_VARIABLE (uint32_t, max_recent_sessions, "max-recent-sessions", 10) CONFIG_VARIABLE (uint32_t, max_recent_sessions, "max-recent-sessions", 10)
CONFIG_VARIABLE (uint32_t, max_recent_templates, "max-recent-templates", 10) CONFIG_VARIABLE (uint32_t, max_recent_templates, "max-recent-templates", 10)

View File

@ -32,6 +32,7 @@
#include "ardour/disk_reader.h" #include "ardour/disk_reader.h"
#include "ardour/io_tasklist.h" #include "ardour/io_tasklist.h"
#include "ardour/process_thread.h" #include "ardour/process_thread.h"
#include "ardour/rc_configuration.h"
#include "ardour/session_event.h" #include "ardour/session_event.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -50,54 +51,41 @@ IOTaskList::IOTaskList (uint32_t n_threads)
return; return;
} }
pthread_attr_t attr; bool use_rt;
struct sched_param parm; int policy;
pthread_attr_init (&attr); switch (Config->get_io_thread_policy ()) {
case 1:
bool use_sched_param = true; use_rt = true;
int policy = SCHED_RR;
const char* p = getenv ("ARDOUR_IO_SCHED");
if (p) {
int pi = atoi (p);
if (pi < 0) {
policy = SCHED_RR;
} else if (pi > 0) {
policy = SCHED_FIFO; policy = SCHED_FIFO;
} else { break;
use_sched_param = false; case 2:
} use_rt = true;
policy = SCHED_RR;
default:
use_rt = false;
policy = SCHED_OTHER;
break;
} }
if (use_sched_param) {
parm.sched_priority = pbd_absolute_rt_priority (SCHED_RR, pbd_pthread_priority (THREAD_IO));
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
pthread_attr_setschedpolicy (&attr, SCHED_OTHER); policy = SCHED_OTHER;
#else
pthread_attr_setschedpolicy (&attr, policy);
#endif #endif
pthread_attr_setschedparam (&attr, &parm);
pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM); DEBUG_TRACE (PBD::DEBUG::IOTaskList, string_compose ("IOTaskList starting %1 threads with sched policy = %2\n", _n_threads, policy));
pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
DEBUG_TRACE (PBD::DEBUG::IOTaskList, string_compose ("IOTaskList starting %1 threads with priority = %2, policy = %3\n", _n_threads, parm.sched_priority, policy));
} else {
DEBUG_TRACE (PBD::DEBUG::IOTaskList, string_compose ("IOTaskList starting %1 threads with default priority.\n", _n_threads));
}
_workers.resize (_n_threads); _workers.resize (_n_threads);
for (uint32_t i = 0; i < _n_threads; ++i) { for (uint32_t i = 0; i < _n_threads; ++i) {
if (pthread_create (&_workers[i], &attr, &_worker_thread, this)) { if (!use_rt || pbd_realtime_pthread_create (policy, THREAD_IO, 0, &_workers[i], &_worker_thread, this)) {
if (pthread_create (&_workers[i], NULL, &_worker_thread, this)) { if (use_rt && i == 0) {
PBD::warning << _("IOTaskList: cannot acquire realtime permissions.") << endmsg;
}
if (pbd_pthread_create (0, &_workers[i], &_worker_thread, this)) {
std::cerr << "Failed to start IOTaskList thread\n"; std::cerr << "Failed to start IOTaskList thread\n";
throw failed_constructor (); throw failed_constructor ();
} }
if (i == 0) {
PBD::warning << _("IOTaskList: cannot acquire realtime permissions.") << endmsg;
} }
} }
}
pthread_attr_destroy (&attr);
} }
IOTaskList::~IOTaskList () IOTaskList::~IOTaskList ()