DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: Jan Wickbom <jan.wickbom@ericsson.com>
Cc: dev@dpdk.org, patrik.r.andersson@ericsson.com
Subject: Re: [dpdk-dev] [PATCH v4] vhost: allow for many vhost user ports
Date: Wed, 14 Dec 2016 11:25:06 +0800	[thread overview]
Message-ID: <20161214032506.GI18991@yliu-dev.sh.intel.com> (raw)
In-Reply-To: <1481635187-12624-1-git-send-email-jan.wickbom@ericsson.com>

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 <stdint.h>
>  #include <pthread.h>
> +#include <poll.h>
>  
>  #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

  reply	other threads:[~2016-12-14  3:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-01 15:26 [dpdk-dev] [PATCH] " Jan Wickbom
2016-12-06  6:56 ` Yuanhan Liu
2016-12-06 11:42   ` Jan Wickbom
2016-12-07  7:43     ` Yuanhan Liu
2016-12-07 10:12 ` Yuanhan Liu
2016-12-07 13:23   ` Jan Wickbom
2016-12-08  5:50     ` Yuanhan Liu
2016-12-12 16:55       ` Jan Wickbom
2016-12-07 12:46 ` [dpdk-dev] [PATCH v2] " Jan Wickbom
2016-12-12 16:50 ` [dpdk-dev] [PATCH v3] " Jan Wickbom
2016-12-13  9:14   ` Yuanhan Liu
2016-12-13 13:15     ` Jan Wickbom
2016-12-13 13:19 ` [dpdk-dev] [PATCH v4] " Jan Wickbom
2016-12-14  3:25   ` Yuanhan Liu [this message]
2016-12-14 15:30 ` [dpdk-dev] [PATCH v5] " Jan Wickbom
2016-12-21  9:45   ` [dpdk-dev] [PATCH v6] " Yuanhan Liu
2016-12-21 18:06     ` Stephen Hemminger
2016-12-22  3:16       ` Yuanhan Liu
2017-01-12  4:05     ` Yuanhan Liu

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=20161214032506.GI18991@yliu-dev.sh.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=dev@dpdk.org \
    --cc=jan.wickbom@ericsson.com \
    --cc=patrik.r.andersson@ericsson.com \
    /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).