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 CE659424CD; Tue, 11 Jun 2024 15:40:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFCC840A75; Tue, 11 Jun 2024 15:40:15 +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 58E6C40A73 for ; Tue, 11 Jun 2024 15:40:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718113213; 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=i8vTeGeJLTACkfcOVafWfHL+9Xm0MEhbWXRHx2TT8Do=; b=FlspXn5FXJGuK8HsVAKMJmuUNM513E4rQ2W3cWinATpY+pRGRwQkEalIlgQYnhbfVhzmbF MMK5E7Phjc6FpjfBx8kMVgo32XzJBwlM/xufTFLZqlubUJgu+TWbvfFBLQCEaT2n+sg6Vd tzJq5E+A/dfG6H6IRqgyY7rrowUtLG4= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-lE0ixlWoNHedtAwo7HMJ_A-1; Tue, 11 Jun 2024 09:40:09 -0400 X-MC-Unique: lE0ixlWoNHedtAwo7HMJ_A-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 140EC1955E8C; Tue, 11 Jun 2024 13:40:08 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.15]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3729E1956087; Tue, 11 Jun 2024 13:40:05 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v4 2/5] vhost: make use of FD manager init function Date: Tue, 11 Jun 2024 15:39:54 +0200 Message-ID: <20240611133957.72032-3-maxime.coquelin@redhat.com> In-Reply-To: <20240611133957.72032-1-maxime.coquelin@redhat.com> References: <20240611133957.72032-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 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 | 10 +++++++--- lib/vhost/fd_man.h | 2 +- lib/vhost/socket.c | 12 +++++------- lib/vhost/vduse.c | 15 ++++++--------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c index 67ee1589e1..a07fba5b6d 100644 --- a/lib/vhost/fd_man.c +++ b/lib/vhost/fd_man.c @@ -96,19 +96,23 @@ 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; + 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 c681d53abb..896c8e6471 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -90,13 +90,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, }; @@ -1192,6 +1185,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.45.1