From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [PATCH 3/7] vhost: make use of FD manager init function
Date: Thu, 29 Feb 2024 13:24:58 +0100 [thread overview]
Message-ID: <20240229122502.2572343-4-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20240229122502.2572343-1-maxime.coquelin@redhat.com>
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 <maxime.coquelin@redhat.com>
---
lib/vhost/fd_man.c | 9 +++++++--
lib/vhost/fd_man.h | 2 +-
lib/vhost/socket.c | 11 +++++------
lib/vhost/vduse.c | 14 ++++++--------
4 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/lib/vhost/fd_man.c b/lib/vhost/fd_man.c
index 5dde40e51a..d33036a171 100644
--- a/lib/vhost/fd_man.c
+++ b/lib/vhost/fd_man.c
@@ -96,19 +96,24 @@ 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);
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 2517ae5a9b..92d24d8591 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 a2fdac30a4..b544e39be7 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -89,12 +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,
- .num = 0
- },
.vsocket_cnt = 0,
.mutex = PTHREAD_MUTEX_INITIALIZER,
};
@@ -1187,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 d462428d2c..d83d7b0d7c 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -31,14 +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,
- .num = 0
- },
-};
+static struct vduse vduse;
static bool vduse_events_thread;
@@ -434,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.43.2
next prev parent reply other threads:[~2024-02-29 12:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 12:24 [PATCH 0/7] vhost: FD manager improvements Maxime Coquelin
2024-02-29 12:24 ` [PATCH 1/7] vhost: fix VDUSE device destruction failure Maxime Coquelin
2024-02-29 13:31 ` David Marchand
2024-03-04 10:35 ` [PATCH v2] " David Marchand
2024-03-04 15:12 ` Maxime Coquelin
2024-03-05 9:05 ` David Marchand
2024-02-29 12:24 ` [PATCH 2/7] vhost: rename polling mutex Maxime Coquelin
2024-02-29 13:41 ` David Marchand
2024-02-29 12:24 ` Maxime Coquelin [this message]
2024-02-29 13:42 ` [PATCH 3/7] vhost: make use of FD manager init function David Marchand
2024-02-29 12:24 ` [PATCH 4/7] vhost: hide synchronization within FD manager Maxime Coquelin
2024-02-29 12:25 ` [PATCH 5/7] vhost: improve fdset initialization Maxime Coquelin
2024-02-29 12:25 ` [PATCH 6/7] vhost: convert fdset sync to eventfd Maxime Coquelin
2024-02-29 12:25 ` [PATCH 7/7] vhost: improve FD manager logging Maxime Coquelin
2024-03-04 10:35 ` [PATCH 0/7] vhost: FD manager improvements David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240229122502.2572343-4-maxime.coquelin@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=chenbox@nvidia.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).