From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id A91F82B96 for ; Wed, 7 Dec 2016 11:12:13 +0100 (CET) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP; 07 Dec 2016 02:12:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,310,1477983600"; d="scan'208";a="37843769" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.67.162]) by orsmga004.jf.intel.com with ESMTP; 07 Dec 2016 02:12:11 -0800 Date: Wed, 7 Dec 2016 18:12:57 +0800 From: Yuanhan Liu To: Jan Wickbom Cc: dev@dpdk.org, patrik.r.andersson@ericsson.com Message-ID: <20161207101257.GK31182@yliu-dev.sh.intel.com> References: <1480606010-6132-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: <1480606010-6132-1-git-send-email-jan.wickbom@ericsson.com> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH] 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, 07 Dec 2016 10:12:14 -0000 On Thu, Dec 01, 2016 at 04:26:50PM +0100, Jan Wickbom wrote: > static int > -fdset_fill(fd_set *rfset, fd_set *wfset, struct fdset *pfdset) > +fdset_fill(struct pollfd *rwfds, struct fdset *pfdset) > { > struct fdentry *pfdentry; > - int i, maxfds = -1; > - int num = MAX_FDS; > - > - if (pfdset == NULL) > - return -1; > + int i; > + int num; > > - for (i = 0; i < num; i++) { > + for (i = 0, num = pfdset->num; i < num; i++) { > pfdentry = &pfdset->fd[i]; > - if (pfdentry->fd != -1) { > - int added = 0; > - if (pfdentry->rcb && rfset) { > - FD_SET(pfdentry->fd, rfset); > - added = 1; > - } > - if (pfdentry->wcb && wfset) { > - FD_SET(pfdentry->fd, wfset); > - added = 1; > - } > - if (added) > - maxfds = pfdentry->fd < maxfds ? > - maxfds : pfdentry->fd; > + > + if (pfdentry->fd < 0) { > + /* Hole in the list. Move the last one here */ > + > + *pfdentry = pfdset->fd[num - 1]; > + pfdset->fd[num - 1].fd = -1; > + num = fdset_adjust_num(pfdset); > } > + rwfds[i].fd = pfdentry->fd; > + rwfds[i].events = pfdentry->rcb ? POLLIN : 0; > + rwfds[i].events |= pfdentry->wcb ? POLLOUT : 0; Another thing is we don't have to re-init this rwfds array again and again. Instead, we could - set it up correctly when fdset_add is invoked: set the fd and events. - reset revents when it's been handled at fdset_event_dispatch(). - swap with the last one and shrink the array on fd delete Could you make a follow up patch for that? Thanks. --yliu