From nobody Mon Jun 23 07:40:57 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bQg4B18Hvz5yw2Z; Mon, 23 Jun 2025 07:40:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bQg4B0D59z47kM; Mon, 23 Jun 2025 07:40:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750664458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cYUIP8riDWbQLIHaDYXnILtU18UUniNC8MweyB/1kpo=; b=i4HWZjT2dEEwJPj83XttqySHw2eIKq5g7HdpQDhbUEG19KwK+WhjfLmtp4sHxAvX632+fP +eFPw1SySceirxURBNvmbJXPW53V77y2LvXYeQ4fai20Djdpr4oJtN9KMtG7mqeVfJLkil fP2NJOTC0r3ztZNp9YObKQq4tfGII2OxHIY17CMMqyD8iQfvyafzsbk1op/QMJ+DCEfR0U 9XFYX26m3ZR8tZSRSDK76HGELnO6eMYjZ9J8GbR349beRA3xvDYGvBiGPJQCFIo8D0X3yt amSgt6nwcf2O0IeDvExdIEqCjKBUZtz/TKL7YzxZayU8Yap415fubXYp7wGk/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750664458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=cYUIP8riDWbQLIHaDYXnILtU18UUniNC8MweyB/1kpo=; b=wOCw25KmeEogE2Mv03gIXr+52WQMoZXN9qbTwPCvFSu740qEjam/RfB6xSkveoniWx2ucE zRKPXtO+qwsfQUPaW+2Cs7jtWZYBUlnQ3CQ/xEWzkKq+HggcBsX9zKSkArQMimE/0m0uJc FEqFdhR4m7Z0ZqINYMtjcE34nuo8MX//kcN+ykKOR6XiCr1txxw4Jxm3kb36dsMwGuV9q7 cil8uolBpueCtMzn8ZoLN4xx87dRLQisFiKYzAec+g0WT+8iqTiS2YlxtnuBDEm4eky0EN TeNuDzzA9cdZWkpx637t6TsTPrY4Q5y4N502Ts5ixZgj0BHbHcv31bZibJXZOA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750664458; a=rsa-sha256; cv=none; b=T+ty8x2UmR6+2BOiDrbKMQ2kzqdy+vBGW9OtNXjdGAHW7jJB+e4+srEM8yeE9HWVqQsVe5 a+kgujFmWFJG50gzVl14lpOwJB95FtGk4/1tJiogTz315wctzdRLJyWgXRTyW4FGgbbw+C HZop0gPBYsM/3wRABL3BQF6PrLwqZTnBZC/2oI0xQF6gllKntYaY6NqA7Rj9tm5TcV8PrR LeA0Fki5PAm1PWVzGa1euglrXBKYpJRgT0He1LsyEYnXvLzzUhfDB1K+kq5Gy943YqhCBz BWb/iwQzK4ouo3Kc0tCoH9PkB/B3w6vDsR3E2x1SmKHIQ9PjfD0K7waG1GLvNQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bQg496qsLztVl; Mon, 23 Jun 2025 07:40:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55N7evhW064868; Mon, 23 Jun 2025 07:40:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55N7evkY064865; Mon, 23 Jun 2025 07:40:57 GMT (envelope-from git) Date: Mon, 23 Jun 2025 07:40:57 GMT Message-Id: <202506230740.55N7evkY064865@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 884ca28b97e7 - stable/14 - libusb: use eventfd List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 884ca28b97e73f297b512aaf04deb6f951854c02 Auto-Submitted: auto-generated The branch stable/14 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=884ca28b97e73f297b512aaf04deb6f951854c02 commit 884ca28b97e73f297b512aaf04deb6f951854c02 Author: Baptiste Daroussin AuthorDate: 2025-05-15 13:21:50 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-23 07:40:33 +0000 libusb: use eventfd Simplify libusb code by replacing pipe(2) inter thread event mecanism with eventfd(2). MFC After: 3 weeks Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50360 (cherry picked from commit ae28929b7c78267815e994e0ad12e3cc7db361bc) --- lib/libusb/libusb10.c | 20 +++++++------------- lib/libusb/libusb10.h | 2 +- lib/libusb/libusb10_io.c | 5 ++--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 6d9c11910ea0..5564bfd8b499 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -118,15 +119,13 @@ libusb_set_nonblocking(int f) void libusb_interrupt_event_handler(libusb_context *ctx) { - uint8_t dummy; int err; if (ctx == NULL) return; - dummy = 0; - err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); - if (err < (int)sizeof(dummy)) { + err = eventfd_write(ctx->event, 1); + if (err < 0) { /* ignore error, if any */ DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!"); } @@ -145,7 +144,6 @@ libusb_init_context(libusb_context **context, struct libusb_context *ctx; pthread_condattr_t attr; char *debug, *ep; - int ret; if (num_options < 0) return (LIBUSB_ERROR_INVALID_PARAM); @@ -233,19 +231,16 @@ libusb_init_context(libusb_context **context, ctx->ctx_handler = NO_THREAD; ctx->hotplug_handler = NO_THREAD; - ret = pipe(ctx->ctrl_pipe); - if (ret < 0) { + ctx->event = eventfd(0, EFD_NONBLOCK); + if (ctx->event < 0) { pthread_mutex_destroy(&ctx->ctx_lock); pthread_mutex_destroy(&ctx->hotplug_lock); pthread_cond_destroy(&ctx->ctx_cond); free(ctx); return (LIBUSB_ERROR_OTHER); } - /* set non-blocking mode on the control pipe to avoid deadlock */ - libusb_set_nonblocking(ctx->ctrl_pipe[0]); - libusb_set_nonblocking(ctx->ctrl_pipe[1]); - libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->ctrl_pipe[0], POLLIN); + libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->event, POLLIN); pthread_mutex_lock(&default_context_lock); if (usbi_default_context == NULL) { @@ -288,8 +283,7 @@ libusb_exit(libusb_context *ctx) /* XXX cleanup devices */ libusb10_remove_pollfd(ctx, &ctx->ctx_poll); - close(ctx->ctrl_pipe[0]); - close(ctx->ctrl_pipe[1]); + close(ctx->event); pthread_mutex_destroy(&ctx->ctx_lock); pthread_mutex_destroy(&ctx->hotplug_lock); pthread_cond_destroy(&ctx->ctx_cond); diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index 544364386061..47d918959f63 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -93,7 +93,7 @@ TAILQ_HEAD(libusb_device_head, libusb_device); struct libusb_context { int debug; int debug_fixed; - int ctrl_pipe[2]; + int event; int tr_done_ref; int tr_done_gen; diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 2790142486ba..f1e31c2a7416 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #endif @@ -187,10 +188,8 @@ libusb10_handle_events_sub(struct libusb_context *ctx, struct timeval *tv) CTX_LOCK(ctx); } else { - uint8_t dummy; + eventfd_read(fds[i].fd, &(eventfd_t){0}); - while (read(fds[i].fd, &dummy, 1) == 1) - ; } }