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 6543243DE5; Wed, 3 Apr 2024 11:25:13 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4622C40685; Wed, 3 Apr 2024 11:25:06 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id E1E8040684 for ; Wed, 3 Apr 2024 11:25:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712136304; 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=BZ4KSua0IFlOlbJVV/HSws9MtZxPeUMYx8hV9p5AOiOFqLtNrYrg+jv8HSTtjSBHK5/9c4 B0brxkkl3DQcuIRku/extxE7+M//ac0M+q3W+7r8+G+alJAcR9joKVcKFxJrR2wJc4smih V6pqbcWJn7jbJ1PfJ1F3ulB71/kyTLc= 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-631-xm8_YOz4PTmRbenX9opvUA-1; Wed, 03 Apr 2024 05:25:01 -0400 X-MC-Unique: xm8_YOz4PTmRbenX9opvUA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 AB44D811E81; Wed, 3 Apr 2024 09:25:00 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D045492BC6; Wed, 3 Apr 2024 09:24:57 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v2 2/5] vhost: make use of FD manager init function Date: Wed, 3 Apr 2024 11:24:45 +0200 Message-ID: <20240403092448.1361820-3-maxime.coquelin@redhat.com> In-Reply-To: <20240403092448.1361820-1-maxime.coquelin@redhat.com> References: <20240403092448.1361820-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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