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 10DF543C3B; Thu, 29 Feb 2024 14:42:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 01E92402CD; Thu, 29 Feb 2024 14:42:47 +0100 (CET) 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 141F64025C for ; Thu, 29 Feb 2024 14:42:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709214165; 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=EKiEdebbup10Pe0J9CDUzYvcAWtTXphDOA0NKWiBvxs=; b=BlgNeoEp+lh50HKwKW+DuHKmUrt8FpJdcaBLA7pmQ+ak9Ar77JljiEu/DS9x/7IeW1hBWC TpdzJdf12AgBmnoJc9jqGGbHBNkw7BUK3kLIEae5rPCb31T7u7a18M8yLRgaWcMEnBM0Fy 4qmZDHQKn7NEgBSot+/8sroTQgApboE= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-hO5Mj8GWMT-9JBzBSThP_A-1; Thu, 29 Feb 2024 08:42:43 -0500 X-MC-Unique: hO5Mj8GWMT-9JBzBSThP_A-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-5132027acc8so759793e87.1 for ; Thu, 29 Feb 2024 05:42:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709214161; x=1709818961; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EKiEdebbup10Pe0J9CDUzYvcAWtTXphDOA0NKWiBvxs=; b=tU9JNJK23dHeSVoQ9pw+kFCGYA1hclqaQs2F0PIVOBTAKkuGpDtteNCu6ehUKFqsNM dUOjpX2n0lxOLVdV0l511EbCYMAgnu9R+xgSticIEUUmR8rjiRRQzmSBX3FJ6Ap23TRE 2P6IZGJYQmj0jH8D40v0nhIjSQM+5r/376lqMPmOaM8t/pZpDyjil49nXhitfPEuPSTw t4cnnM3rqZ2saRvNb9lJH2slf+CAdR2bpvCxw15kd3MjN4Uap8qCEt3ED4XPF+uqcedB 7UG6L2IywanT9EQhWnf5SHW3NRETzhafb5zBy9rSGGkdu46iCiUXuUCMRN70/LIaH+0F 6Ncw== X-Gm-Message-State: AOJu0YzUfj+qd6ha+fL6tH3Q8t3x1zzgzdMDLGAKcAhFOxx7FS8jRc9U L01pMwN+o6q7ItfSsqGOJqe7UWN6bMEjTcfrndKUMLnfyeQ68UziRL4WB0h+9VeKLmUhhGbsnes kx//UcVhSchRhVWZ8pgukbQEtjVLovgCUz3VJhAM0Xrk9cjnqSFkbvf34qJIa/dXtGDRiHTsKU5 3awfleh/Hd0AsKI6k= X-Received: by 2002:ac2:597b:0:b0:512:fabd:8075 with SMTP id h27-20020ac2597b000000b00512fabd8075mr1444437lfp.48.1709214161712; Thu, 29 Feb 2024 05:42:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVWHeyRwV/yS7xquKGt01JvPIoFrXlPi0cFD5U2Lp4ncMxlIipjyd+2LJNYG2KhPDt6bnBPHewaixkmPvsnjM= X-Received: by 2002:ac2:597b:0:b0:512:fabd:8075 with SMTP id h27-20020ac2597b000000b00512fabd8075mr1444426lfp.48.1709214161357; Thu, 29 Feb 2024 05:42:41 -0800 (PST) MIME-Version: 1.0 References: <20240229122502.2572343-1-maxime.coquelin@redhat.com> <20240229122502.2572343-4-maxime.coquelin@redhat.com> In-Reply-To: <20240229122502.2572343-4-maxime.coquelin@redhat.com> From: David Marchand Date: Thu, 29 Feb 2024 14:42:29 +0100 Message-ID: Subject: Re: [PATCH 3/7] vhost: make use of FD manager init function To: Maxime Coquelin Cc: dev@dpdk.org, chenbox@nvidia.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Thu, Feb 29, 2024 at 1:25=E2=80=AFPM Maxime Coquelin wrote: > > 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 | 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 =3D 0; > } > > -void > +int > fdset_init(struct fdset *pfdset) > { > int i; > > if (pfdset =3D=3D NULL) > - return; > + return -1; > + > + pthread_mutex_init(&pfdset->fd_mutex, NULL); > + pthread_mutex_init(&pfdset->fd_polling_mutex, NULL); Following patch 1, we are missing init of sync_* variables. > > for (i =3D 0; i < MAX_FDS; i++) { > pfdset->fd[i].fd =3D -1; > pfdset->fd[i].dat =3D NULL; > } > pfdset->num =3D 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 =3D { > - .fdset =3D { > - .fd =3D { [0 ... MAX_FDS - 1] =3D {-1, NULL, NULL, NULL, = 0} }, > - .fd_mutex =3D PTHREAD_MUTEX_INITIALIZER, > - .fd_pooling_mutex =3D PTHREAD_MUTEX_INITIALIZER, > - .num =3D 0 > - }, > .vsocket_cnt =3D 0, > .mutex =3D PTHREAD_MUTEX_INITIALIZER, > }; > @@ -1187,6 +1181,11 @@ rte_vhost_driver_start(const char *path) > return vduse_device_create(path, vsocket->net_compliant_o= l_flags); > > if (fdset_tid.opaque_id =3D=3D 0) { > + if (fdset_init(&vhost_user.fdset) < 0) { > + VHOST_CONFIG_LOG(path, ERR, "Failed to init Vhost= -user fdset"); Nit: other log messages in this function are not consistent wrt starting with a capital letter. > + return -1; > + } > + > /** > * create a pipe which will be waited by poll and notifie= d 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 =3D { > - .fdset =3D { > - .fd =3D { [0 ... MAX_FDS - 1] =3D {-1, NULL, NULL, NULL, = 0} }, > - .fd_mutex =3D PTHREAD_MUTEX_INITIALIZER, > - .fd_pooling_mutex =3D PTHREAD_MUTEX_INITIALIZER, > - .num =3D 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 =3D=3D false) { > + if (fdset_init(&vduse.fdset) < 0) { > + VHOST_CONFIG_LOG(path, ERR, "Failed to init VDUSE= fdset"); > + return -1; > + } > + Nit: idem + other log messages use "vduse fdset". --=20 David Marchand