Allow to override rt priority for internal backends

This commit is contained in:
Robin Gareus 2021-06-10 03:16:35 +02:00
parent 2c8916310a
commit 89a0040f1b
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
2 changed files with 50 additions and 13 deletions

View file

@ -54,15 +54,9 @@
/* these are relative to sched_get_priority_max()
* see pbd_absolute_rt_priority()
*/
#ifdef PLATFORM_WINDOWS
# define PBD_RT_PRI_MAIN -1
# define PBD_RT_PRI_MIDI -2
# define PBD_RT_PRI_PROC -2
#else
# define PBD_RT_PRI_MAIN -20
# define PBD_RT_PRI_MIDI -21
# define PBD_RT_PRI_PROC -22
#endif
# define PBD_RT_PRI_MAIN pbd_pthread_priority (THREAD_MAIN)
# define PBD_RT_PRI_MIDI pbd_pthread_priority (THREAD_MIDI)
# define PBD_RT_PRI_PROC pbd_pthread_priority (THREAD_PROC)
LIBPBD_API int pthread_create_and_store (std::string name, pthread_t *thread, void * (*start_routine)(void *), void * arg);
LIBPBD_API void pthread_cancel_one (pthread_t thread);
@ -71,6 +65,14 @@ LIBPBD_API void pthread_kill_all (int signum);
LIBPBD_API const char* pthread_name ();
LIBPBD_API void pthread_set_name (const char* name);
enum PBDThreadClass {
THREAD_MAIN, // main audio I/O thread
THREAD_MIDI, // MIDI I/O threads
THREAD_PROC // realtime worker
};
LIBPBD_API int pbd_pthread_priority (PBDThreadClass);
LIBPBD_API int pbd_pthread_create (
const size_t stacksize,
pthread_t *thread,

View file

@ -277,6 +277,42 @@ pbd_pthread_create (
return rv;
}
int
pbd_pthread_priority (PBDThreadClass which)
{
/* fall back to use values relative to max */
#ifdef PLATFORM_WINDOWS
switch (which) {
case THREAD_MAIN:
return -1;
case THREAD_MIDI:
return -2;
default:
case THREAD_PROC:
return -2;
}
#else
int base = -20;
const char* p = getenv ("ARDOUR_SCHED_PRI");
if (p && *p) {
base = atoi (p);
if (base > -5 && base < 5) {
base = -20;
}
}
switch (which) {
case THREAD_MAIN:
return base;
case THREAD_MIDI:
return base - 1;
default:
case THREAD_PROC:
return base - 2;
}
#endif
}
int
pbd_absolute_rt_priority (int policy, int priority)
{
@ -285,13 +321,12 @@ pbd_absolute_rt_priority (int policy, int priority)
const int p_max = sched_get_priority_max (policy); // Linux: 99
if (priority == 0) {
/* use default. XXX this should be relative to audio (JACK) thread,
* internal backends use -20 (Audio), -21 (MIDI), -22 (compuation)
*/
priority = (p_min + p_max) / 2;
} else if (priority > 0) {
priority += p_min;
/* value relative to minium */
priority += p_min - 1;
} else {
/* value relative maximum */
priority += p_max + 1;
}