From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 37FF743E29; Tue, 9 Apr 2024 13:49:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A6F184064A; Tue, 9 Apr 2024 13:49:01 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 5A09A40633 for ; Tue, 9 Apr 2024 13:49:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712663339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bEu9gm7Al6r5CvVfB2f2tmW6aS8LWq/Z2KvSNplMR8o=; b=TzMafx2vb5SMX4IM20nMvXsqurtafr72ToayVvLTmayVIMnI5h++IIvy/rrGsIMK5LTLdl bL2VMdgyRdF3k+Pfvo74kthuSvhnDX9vtYdm5hSJNjKzatnxb9vY6HYGAb4OyhSzqzJ/Hn gIo0REJRCmF3GwvqwIefTtYkQOk+vy0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-05RQu48oO5G1ief6JvYnWg-1; Tue, 09 Apr 2024 07:48:57 -0400 X-MC-Unique: 05RQu48oO5G1ief6JvYnWg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B8E480D0F2; Tue, 9 Apr 2024 11:48:56 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2030010061E0; Tue, 9 Apr 2024 11:48:54 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v3 2/5] vhost: make use of FD manager init function Date: Tue, 9 Apr 2024 13:48:42 +0200 Message-ID: <20240409114845.1336403-3-maxime.coquelin@redhat.com> In-Reply-To: <20240409114845.1336403-1-maxime.coquelin@redhat.com> References: <20240409114845.1336403-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Instead of statically initialize the fdset, this patch converts VDUSE and Vhost-user to use fdset_init() function, which now also initialize the mutexes. This is preliminary rework to hide FDs manager pipe from its users. Signed-off-by: Maxime Coquelin --- lib/vhost/fd_man.c | 11 +++++++++-- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 12 +++++------- lib/vhost/vduse.c | 15 ++++++--------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 67ee1589e1..e42c491fdb 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -96,19 +96,26 @@ fdset_add_fd(struct fdset *pfdset, int idx, int fd, pfd->revents = 0; } -void +int fdset_init(struct fdset *pfdset) { int i; if (pfdset == NULL) - return; + return -1; + + pthread_mutex_init(&pfdset->fd_mutex, NULL); + pthread_mutex_init(&pfdset->fd_polling_mutex, NULL); + pthread_mutex_init(&pfdset->sync_mutex, NULL); + pthread_cond_init(&pfdset->sync_cond, NULL); for (i = 0; i < MAX_FDS; i++) { pfdset->fd[i].fd = -1; pfdset->fd[i].dat = NULL; } pfdset->num = 0; + + return 0; } /** diff --git a/lib/vhost/fd_man.h b/lib/vhost/fd_man.h index 4e00f94758..0f4cddfe56 100644 --- a/lib/vhost/fd_man.h +++ b/lib/vhost/fd_man.h @@ -43,7 +43,7 @@ struct fdset { }; -void fdset_init(struct fdset *pfdset); +int fdset_init(struct fdset *pfdset); int fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat); diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 96b3ab5595..8155749972 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -89,13 +89,6 @@ static int create_unix_socket(struct vhost_user_socket *vsocket); static int vhost_user_start_client(struct vhost_user_socket *vsocket); static struct vhost_user vhost_user = { - .fdset = { - .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} }, - .fd_mutex = PTHREAD_MUTEX_INITIALIZER, - .fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER, - .sync_mutex = PTHREAD_MUTEX_INITIALIZER, - .num = 0 - }, .vsocket_cnt = 0, .mutex = PTHREAD_MUTEX_INITIALIZER, }; @@ -1188,6 +1181,11 @@ rte_vhost_driver_start(const char *path) return vduse_device_create(path, vsocket->net_compliant_ol_flags); if (fdset_tid.opaque_id == 0) { + if (fdset_init(&vhost_user.fdset) < 0) { + VHOST_CONFIG_LOG(path, ERR, "failed to init Vhost-user fdset"); + return -1; + } + /** * create a pipe which will be waited by poll and notified to * rebuild the wait list of poll. diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c index e0c6991b69..530c148399 100644 --- a/lib/vhost/vduse.c +++ b/lib/vhost/vduse.c @@ -31,15 +31,7 @@ struct vduse { struct fdset fdset; }; -static struct vduse vduse = { - .fdset = { - .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} }, - .fd_mutex = PTHREAD_MUTEX_INITIALIZER, - .fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER, - .sync_mutex = PTHREAD_MUTEX_INITIALIZER, - .num = 0 - }, -}; +static struct vduse vduse; static bool vduse_events_thread; @@ -435,6 +427,11 @@ vduse_device_create(const char *path, bool compliant_ol_flags) /* If first device, create events dispatcher thread */ if (vduse_events_thread == false) { + if (fdset_init(&vduse.fdset) < 0) { + VHOST_CONFIG_LOG(path, ERR, "failed to init VDUSE fdset"); + return -1; + } + /** * create a pipe which will be waited by poll and notified to * rebuild the wait list of poll. -- 2.44.0