context: drop RT when freewheeling

When we are freewheeling, drop the RT priority so that we don't
lock up the system too much.
This commit is contained in:
Wim Taymans 2021-07-05 10:41:57 +02:00
parent 9ceb728dec
commit 5e0c9199bd
2 changed files with 35 additions and 0 deletions

View file

@ -41,6 +41,7 @@
#include <pipewire/impl.h>
#include <pipewire/private.h>
#include <pipewire/thread.h>
#include <pipewire/conf.h>
#include <pipewire/extensions/protocol-native.h>
@ -183,6 +184,30 @@ static int try_load_conf(struct pw_context *this, const char *conf_prefix,
return res;
}
static int context_set_freewheel(struct pw_context *context, bool freewheel)
{
struct pw_thread *thr;
int res;
if ((thr = pw_data_loop_get_thread(context->data_loop_impl)) == NULL)
return -EIO;
if (freewheel) {
pw_log_info(NAME" %p: enter freewheel", context);
res = pw_thread_utils_drop_rt(thr);
} else {
pw_log_info(NAME" %p: exit freewheel", context);
res = pw_thread_utils_acquire_rt(thr, 88);
}
if (res < 0)
pw_log_info(NAME" %p: freewheel error:%s", context, spa_strerror(res));
context->freewheeling = freewheel;
return res;
}
/** Create a new context object
*
* \param main_loop the main loop to use
@ -385,6 +410,8 @@ struct pw_context *pw_context_new(struct pw_loop *main_loop,
if ((res = pw_data_loop_start(this->data_loop_impl)) < 0)
goto error_free;
context_set_freewheel(this, false);
pw_settings_init(this);
pw_log_debug(NAME" %p: created", this);
@ -982,6 +1009,7 @@ int pw_context_recalc_graph(struct pw_context *context, const char *reason)
struct impl *impl = SPA_CONTAINER_OF(context, struct impl, this);
struct pw_impl_node *n, *s, *target, *fallback;
uint32_t max_quantum, min_quantum, def_quantum, def_rate;
bool freewheel = false;
pw_log_info(NAME" %p: busy:%d reason:%s", context, impl->recalc, reason);
@ -1029,6 +1057,8 @@ again:
* is a target for our unassigned nodes */
if (target == NULL)
target = n;
if (n->freewheel)
freewheel = true;
break;
}
}
@ -1037,6 +1067,10 @@ again:
if (target == NULL)
target = fallback;
/* update the freewheel status */
if (context->freewheeling != freewheel)
context_set_freewheel(context, freewheel);
/* now go through all available nodes. The ones we didn't visit
* in collect_nodes() are not linked to any driver. We assign them
* to either an active driver of the first driver */

View file

@ -450,6 +450,7 @@ struct pw_context {
struct pw_impl_client *current_client; /**< client currently executing code in mainloop */
long sc_pagesize;
unsigned int freewheeling:1;
void *user_data; /**< extra user data */
};