stream: only warn about mlock when in RT mode

Only warn about mlock failure when the stream is configured to
operate in REALTIME mode.
This commit is contained in:
Wim Taymans 2020-03-20 11:21:44 +01:00
parent 0d3aa1fd30
commit 67eb89689d
3 changed files with 29 additions and 8 deletions

View file

@ -79,6 +79,7 @@ struct node_data {
unsigned int do_free:1;
unsigned int have_transport:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
struct pw_client_node *client_node;
struct spa_hook client_node_listener;
@ -632,7 +633,8 @@ client_node_port_use_buffers(void *object,
bid->mem = mm;
if (data->allow_mlock && mlock(mm->ptr, mm->size) < 0)
pw_log_warn("Failed to mlock memory %p %u: %s",
pw_log(data->warn_mlock ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
"Failed to mlock memory %p %u: %s",
mm->ptr, mm->size,
errno == ENOMEM ?
"This is not a problem but for best performance, "
@ -1145,6 +1147,7 @@ static struct pw_proxy *node_export(struct pw_core *core, void *object, bool do_
struct pw_impl_node *node = object;
struct pw_proxy *client_node;
struct node_data *data;
const char *str;
int i;
client_node = pw_core_create_object(core,
@ -1163,7 +1166,14 @@ static struct pw_proxy *node_export(struct pw_core *core, void *object, bool do_
data->context = pw_impl_node_get_context(node);
data->client_node = (struct pw_client_node *)client_node;
data->remote_id = SPA_ID_INVALID;
data->allow_mlock = data->context->defaults.mem_allow_mlock;
if ((str = pw_properties_get(node->properties, "mem.allow-mlock")) != NULL)
data->allow_mlock = pw_properties_parse_bool(str);
data->warn_mlock = true;
if ((str = pw_properties_get(node->properties, "mem.warn-mlock")) != NULL)
data->warn_mlock = pw_properties_parse_bool(str);
node->exported = true;

View file

@ -141,6 +141,7 @@ struct filter {
unsigned int subscribe:1;
unsigned int draining:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
};
static int get_param_index(uint32_t id)
@ -535,7 +536,8 @@ static int map_data(struct filter *impl, struct spa_data *data, int prot)
range.offset, range.size, data->data);
if (impl->allow_mlock && mlock(data->data, data->maxsize) < 0) {
pw_log_warn(NAME" %p: Failed to mlock memory %p %u: %s", impl,
pw_log(impl->warn_mlock ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
NAME" %p: Failed to mlock memory %p %u: %s", impl,
data->data, data->maxsize,
errno == ENOMEM ?
"This is not a problem but for best performance, "
@ -1164,6 +1166,10 @@ pw_filter_connect(struct pw_filter *filter,
pw_log_debug(NAME" %p: connect", filter);
impl->flags = flags;
impl->warn_mlock = SPA_FLAG_IS_SET(flags, PW_FILTER_FLAG_RT_PROCESS);
pw_properties_set(filter->properties, "mem.warn-mlock",
impl->warn_mlock ? "true" : "false");
impl->impl_node.iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
@ -1177,7 +1183,7 @@ pw_filter_connect(struct pw_filter *filter,
impl->info = SPA_NODE_INFO_INIT();
impl->info.max_input_ports = MAX_PORTS;
impl->info.max_output_ports = MAX_PORTS;
impl->info.flags = SPA_NODE_FLAG_RT;
impl->info.flags = impl->warn_mlock ? SPA_NODE_FLAG_RT : 0;
impl->info.props = &filter->properties->dict;
impl->params[0] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, 0);
impl->params[1] = SPA_PARAM_INFO(SPA_PARAM_Meta, 0);

View file

@ -130,6 +130,7 @@ struct stream {
unsigned int free_proxy:1;
unsigned int draining:1;
unsigned int allow_mlock:1;
unsigned int warn_mlock:1;
};
static int get_param_index(uint32_t id)
@ -533,11 +534,12 @@ static int map_data(struct stream *impl, struct spa_data *data, int prot)
range.offset, range.size, data->data);
if (impl->allow_mlock && mlock(data->data, data->maxsize) < 0) {
pw_log_warn(NAME" %p: Failed to mlock memory %p %u: %s", impl,
data->data, data->maxsize,
errno == ENOMEM ?
"This is not a problem but for best performance, "
"consider increasing RLIMIT_MEMLOCK" : strerror(errno));
pw_log(impl->warn_mlock ? SPA_LOG_LEVEL_WARN : SPA_LOG_LEVEL_DEBUG,
NAME" %p: Failed to mlock memory %p %u: %s", impl,
data->data, data->maxsize,
errno == ENOMEM ?
"This is not a problem but for best performance, "
"consider increasing RLIMIT_MEMLOCK" : strerror(errno));
}
return 0;
}
@ -1423,6 +1425,9 @@ pw_stream_connect(struct pw_stream *stream,
if (flags & PW_STREAM_FLAG_DONT_RECONNECT)
pw_properties_set(stream->properties, PW_KEY_NODE_DONT_RECONNECT, "true");
impl->warn_mlock = SPA_FLAG_IS_SET(flags, PW_STREAM_FLAG_RT_PROCESS);
pw_properties_set(stream->properties, "mem.warn-mlock", impl->warn_mlock ? "true" : "false");
if ((pw_properties_get(stream->properties, PW_KEY_MEDIA_CLASS) == NULL)) {
pw_properties_setf(stream->properties, PW_KEY_MEDIA_CLASS, "Stream/%s/%s",
direction == PW_DIRECTION_INPUT ? "Input" : "Output",