From patchwork Tue Apr 8 20:42:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 879084 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBE3D24C081 for ; Tue, 8 Apr 2025 20:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744144978; cv=pass; b=AVWGMwevSFlpNSnDBeO4wfHVnjCMsaet6vi2QqC8AWqXmKFOYGdzAoWdSsbu5ATzQ3y9HFkXY/wMF6CNkc/HIv++a3Hz9YVB9JowcoZQaUjSXrHpfo7+/HpPsGoZIWTZADB6frOEchh+F/fgZ1DXkENwdWFNDTwbsbm/h9FsCfU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744144978; c=relaxed/simple; bh=Sct0SAeR/w295KtiXZ/VZVHGEUQ8WFB2OPk9MPKS3uc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BoH/+5yAPEFlyvmqA7MGm/vJDMPXXizG2kXIRXvcph8Pyp52kAPUiQmw88SDssM5nl7CksFPYxPE65hhxWcA6569R3Bvs9a5tOex8TkTaaHargcfHD/4Ku2SOuoW5Gxs1N/dDZjZCvMULl79PnYFpRi4Tuk/Ex89TuyhdGBcbtI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=XtwN60wc; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="XtwN60wc" Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4ZXJ1L0l0fzySN; Tue, 8 Apr 2025 23:42:45 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1744144966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qEy1wdTVki0Wy7XlS6KXfSl3ypZ3qqjQhXUL8k+Zirk=; b=XtwN60wcNkPHcsNGNrhCyRK3jEa0rfrcXpRGw0wdPjNTrv/orU6oXdBs01iy2QJE9EN/Kh +Ic/zgGhd1SUCyFOn3yMfIH3xZ68x6FHBx8G4o2n8c0RluT++neJgvpAGZL9B+6zx4C/P+ 3GEeEZQcC42y71C90Oc3BUoOnl+M0ig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1744144966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qEy1wdTVki0Wy7XlS6KXfSl3ypZ3qqjQhXUL8k+Zirk=; b=iMm2f1Kioj+qcBP5hvIHV0lTp652OaxH0LKJkJZayTRIWjzHkl0A669bsqbru5NX+TdgA/ pJ2mjKWCaM/7CXnAvvgEQ3IUY0rHNOpXMHKTR7j7zS/tvBoREASyY7a+6IviA4kJZXhjVY zF/aVu2APAIEFpfB00XffZdbsI4UubU= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1744144966; a=rsa-sha256; cv=none; b=nD0p8ZlGc5tuVhrNJjM+mMUx3wzVfjIxEP6nJrYeBnoY+MAkqtW46w69Iu7SyeDgVkUrvC 2xxzOAZcKicZbPQkawDLeb8usNXT/gK/xmMXKLuvj9FjR9p47cAxkItgCbK4rMpGtMIgIL AK5Guq7lMnPES1a/xclY7hHbI1OGgo8= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 1/3] shared/io: add watcher to be used with TX timestamping Date: Tue, 8 Apr 2025 23:42:38 +0300 Message-ID: X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add special implementation of fd watcher GSource for audio use. For audio use cases, sound server may turn on TX timestamping on a socket that we are watching. In this case, we shall not consider the TX timestamping POLLERR as a socket error condition, nor read the TX timestamps. When TX timestamps appear in errqueue, switch from fd poll wait to polling the fd at regular intervals. This is because unread errqueue causes poll() to wake up immediately, so the mainloop cannot block on that, and we have to use a timer instead with some reasonable timeout for the use case. This rate limits wakeups on new TX timestamps we aren't going to read, and also avoids the busy looping if timestamping was left on but errqueue is not flushed. Kernel does not provide any way for user applications to disable wakeup on POLLERR currently. Note that even with epoll() POLLET it still wakes up on every timestamp. Implement this only for io-glib; it is only needed for audio use cases that anyway are using glib, so add a glib-specific API for it in addition to the 'struct io *' one. Uses features from GLib 2.36 (from 2013) so update configure.ac also. --- Notes: v2: - Remove io-glib.h. Pass void * for GIOChannel *, which is how it needs to be if it's in io.h as requested. - Adjust API a bit In theory avdtp/bap could be changed to use a 'struct io *' instead, but it's mostly additional complication with no gain since they are using GLib anyway, and in theory 'struct io *' users shall use the io_set_ignore_errqueue API instead. acinclude.m4 | 4 +- configure.ac | 2 +- src/shared/io-ell.c | 12 +++ src/shared/io-glib.c | 185 ++++++++++++++++++++++++++++++++++++++- src/shared/io-mainloop.c | 12 +++ src/shared/io.h | 5 ++ 6 files changed, 216 insertions(+), 4 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 168117840..8046c9a7d 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -63,8 +63,8 @@ AC_DEFUN([COMPILER_FLAGS], [ with_cflags="$with_cflags -Wformat -Wformat-security" with_cflags="$with_cflags -Wstringop-overflow" with_cflags="$with_cflags -DG_DISABLE_DEPRECATED" - with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28" - with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32" + with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36" + with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36" fi AC_SUBST([WARNING_CFLAGS], $with_cflags) ]) diff --git a/configure.ac b/configure.ac index 2ea727256..1e089aaa7 100644 --- a/configure.ac +++ b/configure.ac @@ -81,7 +81,7 @@ AC_CHECK_DECLS([basename], [], ]) -PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28) +PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.36) if (test "${enable_threads}" = "yes"); then AC_DEFINE(NEED_THREADS, 1, [Define if threading support is required]) diff --git a/src/shared/io-ell.c b/src/shared/io-ell.c index 35dc38e2e..4d64cf3c5 100644 --- a/src/shared/io-ell.c +++ b/src/shared/io-ell.c @@ -175,6 +175,12 @@ bool io_set_close_on_destroy(struct io *io, bool do_close) return l_io_set_close_on_destroy(io->l_io, do_close); } +bool io_set_ignore_errqueue(struct io *io, bool do_ignore) +{ + /* TODO: unimplemented */ + return false; +} + bool io_set_read_handler(struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy) { @@ -303,3 +309,9 @@ bool io_shutdown(struct io *io) return shutdown(fd, SHUT_RDWR) == 0; } + +unsigned int io_glib_add_err_watch(void *giochannel, io_glib_err_func_t func, + void *user_data) +{ + return 0; +} diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c index 754043db1..81cd1122b 100644 --- a/src/shared/io-glib.c +++ b/src/shared/io-glib.c @@ -13,11 +13,14 @@ #endif #include +#include #include #include "src/shared/io.h" +#define IO_ERR_WATCH_RATELIMIT (500 * G_TIME_SPAN_MILLISECOND) + struct io_watch { struct io *io; guint id; @@ -29,11 +32,24 @@ struct io_watch { struct io { int ref_count; GIOChannel *channel; + bool err_watch; struct io_watch *read_watch; struct io_watch *write_watch; struct io_watch *disconnect_watch; }; +struct io_err_watch { + GSource source; + GIOChannel *io; + GIOCondition events; + gpointer tag; +}; + +static guint io_glib_add_err_watch_full(GIOChannel *io, gint priority, + GIOCondition events, + GIOFunc func, gpointer user_data, + GDestroyNotify notify); + static struct io *io_ref(struct io *io) { if (!io) @@ -179,10 +195,17 @@ static struct io_watch *watch_new(struct io *io, GIOCondition cond, prio = cond == G_IO_HUP ? G_PRIORITY_DEFAULT_IDLE : G_PRIORITY_DEFAULT; - watch->id = g_io_add_watch_full(io->channel, prio, + if (!io->err_watch) + watch->id = g_io_add_watch_full(io->channel, prio, cond | G_IO_ERR | G_IO_NVAL, watch_callback, watch, watch_destroy); + else + watch->id = io_glib_add_err_watch_full(io->channel, prio, + cond | G_IO_ERR | G_IO_NVAL, + watch_callback, watch, + watch_destroy); + if (watch->id == 0) { watch_destroy(watch); return NULL; @@ -250,6 +273,15 @@ bool io_set_disconnect_handler(struct io *io, io_callback_func_t callback, return io_set_handler(io, G_IO_HUP, callback, user_data, destroy); } +bool io_set_ignore_errqueue(struct io *io, bool do_ignore) +{ + if (!io) + return false; + + io->err_watch = do_ignore; + return true; +} + ssize_t io_send(struct io *io, const struct iovec *iov, int iovcnt) { int fd; @@ -278,3 +310,154 @@ bool io_shutdown(struct io *io) return g_io_channel_shutdown(io->channel, TRUE, NULL) == G_IO_STATUS_NORMAL; } + +/* + * GSource implementation that tolerates non-empty MSG_ERRQUEUE, without + * attempting to flush it. This is intended for use with TX timestamping in + * cases where someone else is reading the timestamps and we are only interested + * in POLLHUP or socket errors. + */ + +static gint64 io_err_watch_wakeup; + +static gboolean io_err_watch_dispatch(GSource *source, + GSourceFunc callback, gpointer user_data) +{ + struct io_err_watch *watch = (void *)source; + const GIOFunc func = (void *)callback; + const gint64 timeout = IO_ERR_WATCH_RATELIMIT; + GIOCondition cond; + int fd; + + if (!func) + return FALSE; + + fd = g_io_channel_unix_get_fd(watch->io); + + /* + * If woken up by POLLERR only, and SO_ERROR is not set, ignore this + * event. Also disable polling for some time so that we don't consume + * too much CPU on events we are not interested in, or busy loop if + * nobody is flushing the errqueue. + */ + + if (watch->tag) + cond = g_source_query_unix_fd(&watch->source, watch->tag); + else + cond = 0; + + if (cond == G_IO_ERR) { + int err, ret; + socklen_t len = sizeof(err); + + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len); + if (ret == 0 && err == 0) { + g_source_remove_unix_fd(&watch->source, watch->tag); + watch->tag = NULL; + + /* io_err watches all wake up at the same time */ + if (!io_err_watch_wakeup) + io_err_watch_wakeup = g_get_monotonic_time() + + timeout; + + g_source_set_ready_time(&watch->source, + io_err_watch_wakeup); + return TRUE; + } + } + + if (g_source_get_ready_time(&watch->source) != -1) { + g_assert(!watch->tag); + io_err_watch_wakeup = 0; + watch->tag = g_source_add_unix_fd(&watch->source, fd, + watch->events); + g_source_set_ready_time(&watch->source, -1); + } + + cond &= watch->events; + + if (cond) + return func(watch->io, cond, user_data); + else + return TRUE; +} + +static void io_err_watch_finalize(GSource *source) +{ + struct io_err_watch *watch = (void *)source; + + if (watch->tag) + g_source_remove_unix_fd(&watch->source, watch->tag); + + g_io_channel_unref(watch->io); +} + +static guint io_glib_add_err_watch_full(GIOChannel *io, gint priority, + GIOCondition events, + GIOFunc func, gpointer user_data, + GDestroyNotify notify) +{ + static GSourceFuncs source_funcs = { + .dispatch = io_err_watch_dispatch, + .finalize = io_err_watch_finalize, + }; + GSourceFunc callback = (void *)func; + struct io_err_watch *watch; + gint fd; + guint id; + + g_return_val_if_fail(!(events & (G_IO_IN | G_IO_OUT)), 0); + g_return_val_if_fail(events, 0); + g_return_val_if_fail(func, 0); + + fd = g_io_channel_unix_get_fd(io); + + watch = (void *)g_source_new(&source_funcs, + sizeof(struct io_err_watch)); + + watch->io = g_io_channel_ref(io); + watch->events = events; + watch->tag = g_source_add_unix_fd(&watch->source, fd, events); + + g_source_set_name((void *)watch, "io_glib_err_watch"); + g_source_set_callback(&watch->source, callback, user_data, notify); + + if (priority != G_PRIORITY_DEFAULT) + g_source_set_priority(&watch->source, priority); + + id = g_source_attach(&watch->source, NULL); + g_source_unref(&watch->source); + + return id; +} + +struct err_watch_cb_data { + io_glib_err_func_t func; + void *data; +}; + +static gboolean err_watch_callback(GIOChannel *channel, GIOCondition cond, + gpointer user_data) +{ + struct err_watch_cb_data *data = user_data; + + data->func(cond, data->data); + return FALSE; +} + +unsigned int io_glib_add_err_watch(void *giochannel, + io_glib_err_func_t func, + void *user_data) +{ + struct err_watch_cb_data *data; + + data = g_try_new0(struct err_watch_cb_data, 1); + if (!data) + return 0; + + data->func = func; + data->data = user_data; + return io_glib_add_err_watch_full(giochannel, G_PRIORITY_DEFAULT, + G_IO_ERR | G_IO_HUP | G_IO_NVAL, + err_watch_callback, data, g_free); +} diff --git a/src/shared/io-mainloop.c b/src/shared/io-mainloop.c index ad461843c..8fd49935e 100644 --- a/src/shared/io-mainloop.c +++ b/src/shared/io-mainloop.c @@ -192,6 +192,12 @@ bool io_set_close_on_destroy(struct io *io, bool do_close) return true; } +bool io_set_ignore_errqueue(struct io *io, bool do_ignore) +{ + /* TODO: unimplemented */ + return false; +} + bool io_set_read_handler(struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy) { @@ -309,3 +315,9 @@ bool io_shutdown(struct io *io) return shutdown(io->fd, SHUT_RDWR) == 0; } + +unsigned int io_glib_add_err_watch(void *giochannel, io_glib_err_func_t func, + void *user_data) +{ + return 0; +} diff --git a/src/shared/io.h b/src/shared/io.h index bad899ff7..87c3c001c 100644 --- a/src/shared/io.h +++ b/src/shared/io.h @@ -20,6 +20,7 @@ void io_destroy(struct io *io); int io_get_fd(struct io *io); bool io_set_close_on_destroy(struct io *io, bool do_close); +bool io_set_ignore_errqueue(struct io *io, bool do_ignore); ssize_t io_send(struct io *io, const struct iovec *iov, int iovcnt); bool io_shutdown(struct io *io); @@ -32,3 +33,7 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy); bool io_set_disconnect_handler(struct io *io, io_callback_func_t callback, void *user_data, io_destroy_func_t destroy); + +typedef void (*io_glib_err_func_t)(int cond, void *user_data); +unsigned int io_glib_add_err_watch(void *giochannel, io_glib_err_func_t func, + void *user_data); From patchwork Tue Apr 8 20:42:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 879085 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBEA3250BE7 for ; Tue, 8 Apr 2025 20:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744144977; cv=pass; b=t8MW0LSaZqM6wRELwwAR7/EGPRlBZ0rQ+0GHMrVbHSUTPOrnB21Ca/jvvFKijZpKlnGK+PD/ub9T7aiB7B3nuhclCSdviSe3OsQ3kr98H8FCH/ZpG8civNmWNShbuA1a9WUoVF/5U12TjYPXSTZK0Whq5e9DjfDShZTkHctcuNA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744144977; c=relaxed/simple; bh=fMvUP25PriLsV9+aCuDd5y694dqefdolpNVewj/zbco=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZyljGpIoTgUe11vihQJsLPVGDqq/U89rnQ4AVfOmDrJdi2lF20mtUs/kkHL419b32OA60081uDhrFx63ZYuTLvJ5hD0p8mKnR5+pWIc1L7HGoYS59yu8l6x+5EAELe8V2D8d1vZIR4hipYTbvSjjbvqGZbbqHZEHFeqV78dfSjs= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=ozz59z3b; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="ozz59z3b" Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4ZXJ1M0dG2zydx; Tue, 8 Apr 2025 23:42:46 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1744144967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zRJf8/2VSDM3HcxUiHsf23mu1Y4fcm8+VPKqW8PASPc=; b=ozz59z3bzZ/zVsqaMxv9WFsB8I/cdHSH+aSbtNaSwft/YMGKjwI8EES4mfGTPvUcFu0WE8 6zJAXSTOBomlQkuTmwVwF/mLONESTux6jqssPf9X9UY7/H+vIY28le/JtYfKHYgsomSf/J hWisCEd9Iydu95uepPjnIGzjI+3IBFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1744144967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zRJf8/2VSDM3HcxUiHsf23mu1Y4fcm8+VPKqW8PASPc=; b=YqUTRWj1eyO+aRDPjlhCLzO6dBn+8RdpZF8PF3NFucgMRMZyKgdESfGJpPm26bc9PMhn+/ qZiiMaB7/gzGxgJLsj5mzmcI9nWRO/ovGplVAaKgQKHeoPDgn0E44FZDXOKWfPd6gnYIh1 VK16jBanYRjL5xH6ydltLKwLAyroyoc= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1744144967; a=rsa-sha256; cv=none; b=G0l3tLK2J8quFEJepw3UdoiRJgz4vBYnsAalOLgMjt9nQAvTAoeyih5SAjKRYMHpzmdNdA Od1GB+pw8SGnoy1Uk6dxy292hI9smbSSwSjoAeHFoPlvQLfeTWPKuBeV5S+SdHcwqeyv9b EFTJ4ozp3pviiLTS31GbfP3+Ed+T4So= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 2/3] avdtp: don't consider TX timestamps as errors Date: Tue, 8 Apr 2025 23:42:39 +0300 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use io_add_err_watch to avoid considering TX timestamps as errors in the transport io channel. --- Notes: v2: - use new API profiles/audio/avdtp.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/profiles/audio/avdtp.c b/profiles/audio/avdtp.c index dd8458f20..17b8850ea 100644 --- a/profiles/audio/avdtp.c +++ b/profiles/audio/avdtp.c @@ -31,6 +31,7 @@ #include "btio/btio.h" #include "src/btd.h" #include "src/log.h" +#include "src/shared/io.h" #include "src/shared/timeout.h" #include "src/shared/util.h" #include "src/shared/queue.h" @@ -749,8 +750,7 @@ static void stream_free(void *data) g_free(stream); } -static gboolean transport_cb(GIOChannel *chan, GIOCondition cond, - gpointer data) +static void transport_cb(int cond, void *data) { struct avdtp_stream *stream = data; struct avdtp_local_sep *sep = stream->lsep; @@ -766,8 +766,6 @@ static gboolean transport_cb(GIOChannel *chan, GIOCondition cond, if (!stream->abort_int) avdtp_sep_set_state(stream->session, sep, AVDTP_STATE_IDLE); - - return FALSE; } static int get_send_buffer_size(int sk) @@ -866,8 +864,7 @@ proceed: avdtp_sep_set_state(session, sep, AVDTP_STATE_OPEN); - stream->io_id = g_io_add_watch(io, G_IO_ERR | G_IO_HUP | G_IO_NVAL, - (GIOFunc) transport_cb, stream); + stream->io_id = io_glib_add_err_watch(io, transport_cb, stream); /* Release pending IO */ if (session->pending_open_io) { From patchwork Tue Apr 8 20:42:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 879791 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E00F225779 for ; Tue, 8 Apr 2025 20:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744144977; cv=pass; b=fsiqpud1AFaRSBN5Ns+LlxiC2y9E0pivIqJQIXei2ew1ozMo5kiSlmIbXlriQWVlKE5ddE9BDgKcbHagdEVh9Q2BbM+1pvP5+Q4cbJ1/OEGtSRSfeXw3Y8iDdidv804mtnDGfcHKBSVCosUQsaUeIKvff8dupz6uaZl8RWlnolk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744144977; c=relaxed/simple; bh=AoxfMHSZt/lut6XytkIvX5bb20CC4p8leeeDqzeyNzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RfwSJ+Z+POgTbCWD+2wwDztqRr6UsRauWjvryWY2N3rHmuZGUvNHl5XPf+IoUjZD3pYpOlJbL9RVZbMpyRCAgS+CODfpcjyC2LSemeMKMHv1tF1ND97oF6ZGUhHdWUZj6yOE1C8Gln9Hzs23Y7a20Sx5UcI2uC1GHuvhXLUqB+A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=sSFownO3; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="sSFownO3" Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4ZXJ1M5kQCz102q; Tue, 8 Apr 2025 23:42:47 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1744144968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=07j0uBUXC9xY+bAVxH0TMPWFk6pgsec3qqCCg7J7KVQ=; b=sSFownO3/9YqHZbquEuEpxEZGhFkYihKoxhIpOJaUJgIk2RyOnEKkB9/uM/vA7uBJJUGsG lESfc0f2sUhPdthNVKRW/Wn64x3hJZcb9x/Dn66tfc+fWfH9rNNRt2g9ZUaXT8omcHwxn+ t2BT0NvFrFE1GHRk4fBDl3Y2wc5D1AU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1744144968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=07j0uBUXC9xY+bAVxH0TMPWFk6pgsec3qqCCg7J7KVQ=; b=ke5jR8zN2CUFBW9x3p0fZ3buxrDQcdV2Pd+ha/MKfx4B9r/Hv8NsfQ+Q1KQaBtfEVX3Lsl V4hK1asdkyvr3Y7Jus9rrv+DdmMsXauCir3VUDERnV5hBt+Z06ywBO0y3HkaEsM2xVAtc9 0kApdc7Q+SUHhjXCMlmS80KlJkgCTeQ= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1744144968; a=rsa-sha256; cv=none; b=yVuITsw4yV3LWCHE8pb8LzNgvXU8prD3sXqybdd6Ke7sQYRYD9Oz5T1LoXkKl/3j+qvXQE l/69T8CL5DQF2ABb9LW1877BxiGT5M69oBSqCQJCt/KG3m1NS2wLXxjZ2vyVkBl/S+kKj+ NJQ3CdGwzS+4okoeNemK/YBsvm/P0YQ= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 3/3] bap: don't consider TX timestamps as errors Date: Tue, 8 Apr 2025 23:42:40 +0300 Message-ID: <9b5dc8ea2e6727e9b83e10cc7bd76c85b5a13c54.1744144760.git.pav@iki.fi> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use io_add_err_watch to avoid considering TX timestamps as errors in the transport io channel. --- Notes: v2: - use new API profiles/audio/bap.c | 22 ++++++++-------------- src/shared/bap.c | 2 ++ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index a37e62f76..fd9b751cc 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -39,6 +39,7 @@ #include "src/btd.h" #include "src/dbus-common.h" #include "src/shared/util.h" +#include "src/shared/io.h" #include "src/shared/att.h" #include "src/shared/queue.h" #include "src/shared/gatt-db.h" @@ -1868,8 +1869,7 @@ static void recreate_cig(struct bap_setup *setup) queue_foreach(sessions, recreate_cig_session, &info); } -static gboolean setup_io_disconnected(GIOChannel *io, GIOCondition cond, - gpointer user_data) +static void setup_io_disconnected(int cond, void *user_data) { struct bap_setup *setup = user_data; @@ -1882,8 +1882,6 @@ static gboolean setup_io_disconnected(GIOChannel *io, GIOCondition cond, /* Check if connecting recreate IO */ if (!is_cig_busy(setup->ep->data, setup->qos.ucast.cig_id)) recreate_cig(setup); - - return FALSE; } static void bap_connect_bcast_io_cb(GIOChannel *chan, GError *err, @@ -1964,8 +1962,7 @@ static void setup_connect_io(struct bap_data *data, struct bap_setup *setup, return; } - setup->io_id = g_io_add_watch(io, G_IO_HUP | G_IO_ERR | G_IO_NVAL, - setup_io_disconnected, setup); + setup->io_id = io_glib_add_err_watch(io, setup_io_disconnected, setup); setup->io = io; setup->cig_active = !defer; @@ -2024,8 +2021,7 @@ static void setup_connect_io_broadcast(struct bap_data *data, return; } - setup->io_id = g_io_add_watch(io, G_IO_HUP | G_IO_ERR | G_IO_NVAL, - setup_io_disconnected, setup); + setup->io_id = io_glib_add_err_watch(io, setup_io_disconnected, setup); setup->io = io; @@ -2691,9 +2687,8 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd, if (!setup->io) { io = g_io_channel_unix_new(fd); - setup->io_id = g_io_add_watch(io, - G_IO_HUP | G_IO_ERR | G_IO_NVAL, - setup_io_disconnected, setup); + setup->io_id = io_glib_add_err_watch(io, setup_io_disconnected, + setup); setup->io = io; } else io = setup->io; @@ -2736,9 +2731,8 @@ static void bap_connecting_bcast(struct bt_bap_stream *stream, bool state, if (!setup->io) { io = g_io_channel_unix_new(fd); - setup->io_id = g_io_add_watch(io, - G_IO_HUP | G_IO_ERR | G_IO_NVAL, - setup_io_disconnected, setup); + setup->io_id = io_glib_add_err_watch(io, setup_io_disconnected, + setup); setup->io = io; } else io = setup->io; diff --git a/src/shared/bap.c b/src/shared/bap.c index be35c2e60..3758aa000 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -2779,6 +2779,8 @@ static struct bt_bap_stream_io *stream_io_new(struct bt_bap *bap, int fd) DBG(bap, "fd %d", fd); + io_set_ignore_errqueue(io, true); + sio = new0(struct bt_bap_stream_io, 1); sio->bap = bap; sio->io = io;