From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 6EFAA530F for ; Wed, 14 Dec 2016 04:23:19 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP; 13 Dec 2016 19:23:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,344,1477983600"; d="scan'208";a="202342020" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.67.162]) by fmsmga004.fm.intel.com with ESMTP; 13 Dec 2016 19:23:17 -0800 Date: Wed, 14 Dec 2016 11:25:06 +0800 From: Yuanhan Liu To: Jan Wickbom Cc: dev@dpdk.org, patrik.r.andersson@ericsson.com Message-ID: <20161214032506.GI18991@yliu-dev.sh.intel.com> References: <1480606010-6132-1-git-send-email-jan.wickbom@ericsson.com> <1481635187-12624-1-git-send-email-jan.wickbom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1481635187-12624-1-git-send-email-jan.wickbom@ericsson.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH v4] vhost: allow for many vhost user ports X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Dec 2016 03:23:19 -0000 On Tue, Dec 13, 2016 at 02:19:47PM +0100, Jan Wickbom wrote: > + > + poll(pfdset->rwfds, numfds, 1000 /* millisecs */); > + > + for (i = 0; i < numfds; ) { > pthread_mutex_lock(&pfdset->fd_mutex); > + > pfdentry = &pfdset->fd[i]; > fd = pfdentry->fd; > + pfd = &pfdset->rwfds[i]; > + > + if (fd < 0) { > + /* Removed during poll */ > + /* shrink first, last migth be deleted*/ > + > + fdset_shrink(pfdset); > + fdset_move_last(pfdset, i); > + fdset_shrink(pfdset); > + > + pthread_mutex_unlock(&pfdset->fd_mutex); This patch looks better, but as said, I will not do shrink in the event processing loop: I would simply set a flag, something like "need_shrink" here, and do the shrink outside this for loop. > + if (remove1 || remove2) { > + pthread_mutex_lock(&pfdset->fd_mutex); > + > + /* shrink first, last migth be deleted*/ > + fdset_shrink(pfdset); > + fdset_move_last(pfdset, i); > + fdset_shrink(pfdset); > + > + pthread_mutex_unlock(&pfdset->fd_mutex); > + > + continue; Same here: just sets a flag. > + } > + > + i++; > } > + > + /* fdset_del do not shrink, pack eventual remainings of array */ > + pthread_mutex_lock(&pfdset->fd_mutex); > + > + fdset_shrink(pfdset); > + > + for ( ; i < pfdset->num; i++) { > + pfdentry = &pfdset->fd[i]; > + > + if (pfdentry->fd < 0) { > + fdset_move_last(pfdset, i); > + fdset_shrink(pfdset); > + } > + } And yes, do the shrink here (when the shrink flag is set). But I would simply call fdset_shrink() here (without the for loop), and let the fdset_shrink() to handle the details: it could either be a swap with last __valid__ entry, or simply a memmov. That said, if you prefer to choose fdset_move_last(), fine, invoke it inside fdset_shrink() then. Let fdset_shrink be able to remove an fd in the middle. > + > + pthread_mutex_unlock(&pfdset->fd_mutex); > } > } > diff --git a/lib/librte_vhost/fd_man.h b/lib/librte_vhost/fd_man.h > index bd66ed1..03e7881 100644 > --- a/lib/librte_vhost/fd_man.h > +++ b/lib/librte_vhost/fd_man.h > @@ -35,6 +35,7 @@ > #define _FD_MAN_H_ > #include > #include > +#include > > #define MAX_FDS 1024 > > @@ -49,9 +50,10 @@ struct fdentry { > }; > > struct fdset { > + struct pollfd rwfds[MAX_FDS]; > struct fdentry fd[MAX_FDS]; > pthread_mutex_t fd_mutex; > - int num; /* current fd number of this fdset */ > + int num; /* highest index occupied in fd array + 1 */ I don't see the comment change makes it more readable. --yliu