From nobody Thu May 15 14:24:53 2025 X-Original-To: dev-commits-src-main@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 4ZystG033Cz5wQSg; Thu, 15 May 2025 14:24:54 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZystF5Xfgz3clQ; Thu, 15 May 2025 14:24:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747319093; 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=gS4MOaY7LRLE1dZwC0mLrHj0JzTRIe3EWubj8gl6iW4=; b=sf2t0aLRicCFi4/fJ9jhHVyx5uXx+4WtgrX4uXj4BMfulIJbdTo0far2p3pyhfJ67ChHhu NxVy+AK8BznKKFjqdcVSTzksldHMZiejuGJjInYtrW6iFLbaRPwZZA95jwapFXgs4sHkO+ hAwLa10Elf01WnsgzFpmR9sQW7nkiqrwuN3nGHef0h8LRC3/HCbxfTp6g3y42Cm03BCnBt xALj9X4uRMCyCp4p6qViPSR/SfMydzdJMiF1ASsslID7x2MIlkY2ocq8HAkXOtCnKdG9Cs IONXdE4qfpLwsB175RM8RM5f8hya0pKpmvqsXgrmFwPOElveTli1IPYih7M2nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747319093; 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=gS4MOaY7LRLE1dZwC0mLrHj0JzTRIe3EWubj8gl6iW4=; b=bW90CzPB/9u4OwYKtCr2V5xJUTBep/TzbkQMbyusQj9cZ/z/QYHfyPMeTRyrTo0zVxICMm ShHzjD9ka9OAXgnuzel4Im29K797gQ4JM6ozQgCEMYKRVj2rPdXXxlL9afh8ZZvKttmC1s 2FVUtg4ixe9GZeMZllklKF+rC/qKODq2PCiBSWaOBgNwrlNPQHu0s1vscLVV5jEh7KsU84 fglBZc/LcLyGLAwq/5Y1+ogA6vQ5rVJd4AiZeU8x/tH72DPyfeGy9egQIXfYzktn+kPdvG 0bW3vpvFjccprJGIWXGcd7QAS2Q4UgynnB6kYFSSI69ub2qL1OFO18rpBBUu/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747319093; a=rsa-sha256; cv=none; b=lsd8GQRnRYoJqNOcA9KgzfzKkmkLDE/1SUsXs1LXFftwRG8h8hzGorazjL2FI31EVsaVSM WdJ6NmOigXOd51NEvM6ljtRr9zhGcKyNqPXgtp4OH8hzKGmhc1EVk0ms10jVM4Gsqhq0f8 KjKAp9d9qx+WkfzO6dVfCqgyWkkODz1CGKyl3uMzIMo0dY9rs9BlAj5A/JrJ/0ksXS/414 AvCRLMG+zXnKheb7HVnVmOAvYa/PTZFVoLlWCvgd1ERTwXCLvMNuGQTCQ0F8+Ae4XfHC80 oeDo9oy2QX2a95sZDOwJI9hj4mMQYYOJYu1NoAc/VDtVrr4DcIMwSml4pDGG/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4ZystF54cqz6Ky; Thu, 15 May 2025 14:24:53 +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 54FEOrUb058253; Thu, 15 May 2025 14:24:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54FEOr7w058250; Thu, 15 May 2025 14:24:53 GMT (envelope-from git) Date: Thu, 15 May 2025 14:24:53 GMT Message-Id: <202505151424.54FEOr7w058250@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: ae28929b7c78 - main - libusb: use eventfd List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ae28929b7c78267815e994e0ad12e3cc7db361bc Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=ae28929b7c78267815e994e0ad12e3cc7db361bc commit ae28929b7c78267815e994e0ad12e3cc7db361bc Author: Baptiste Daroussin AuthorDate: 2025-05-15 13:21:50 +0000 Commit: Baptiste Daroussin CommitDate: 2025-05-15 14:24:46 +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 --- 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 afa25eabf459..679f4e64b5f6 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); @@ -234,19 +232,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) { @@ -296,8 +291,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 3402e0377c92..f34ea25740d6 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -106,7 +106,7 @@ typedef enum { struct libusb_context { int debug; int debug_fixed; - int ctrl_pipe[2]; + int event; int tr_done_ref; int tr_done_gen; usb_event_mode_t usb_event_mode; 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) - ; } }