qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Vincenzo Maffione <v.maffione@gmail.com>, qemu-devel@nongnu.org
Cc: g.lettieri@iet.unipi.it, rizzo@iet.unipi.it
Subject: Re: [Qemu-devel] [PATCH 2/2] net: netmap: avoid mmap() when ports use the same shared memory area
Date: Thu, 14 Jan 2016 11:25:16 +0800	[thread overview]
Message-ID: <5697151C.6090506@redhat.com> (raw)
In-Reply-To: <b666d94d3251d0fc7da536fce47b8af2228cc896.1452258704.git.v.maffione@gmail.com>



On 01/08/2016 09:15 PM, Vincenzo Maffione wrote:
> With this patch, nm_open() does not mmap() the netmap device. This
> operation is performed separately only if the memory area of the
> port just opened was not known before.
> A global list of netmap clients is kept to check when matches
> occur.
>
> Signed-off-by: Vincenzo Maffione <v.maffione@gmail.com>
> ---
>  net/netmap.c | 38 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/net/netmap.c b/net/netmap.c
> index 27295ab..6a4c01c 100644
> --- a/net/netmap.c
> +++ b/net/netmap.c
> @@ -49,8 +49,12 @@ typedef struct NetmapState {
>      bool                write_poll;
>      struct iovec        iov[IOV_MAX];
>      int                 vnet_hdr_len;  /* Current virtio-net header length. */
> +    QTAILQ_ENTRY(NetmapState) next;
>  } NetmapState;
>  
> +static QTAILQ_HEAD(, NetmapState) netmap_clients =
> +                   QTAILQ_HEAD_INITIALIZER(netmap_clients);
> +
>  #ifndef __FreeBSD__
>  #define pkt_copy bcopy
>  #else
> @@ -78,6 +82,23 @@ pkt_copy(const void *_src, void *_dst, int l)
>  #endif /* __FreeBSD__ */
>  
>  /*
> + * find nm_desc parent with same allocator
> + */
> +static struct nm_desc *
> +netmap_find_memory(struct nm_desc *nmd)
> +{
> +    NetmapState *s;
> +
> +    QTAILQ_FOREACH(s, &netmap_clients, next) {
> +        if (nmd->req.nr_arg2 == s->nmd->req.nr_arg2) {
> +            return s->nmd;
> +        }
> +    }
> +
> +    return NULL;
> +}
> +
> +/*
>   * Open a netmap device. We assume there is only one queue
>   * (which is the case for the VALE bridge).
>   */
> @@ -86,10 +107,11 @@ static struct nm_desc *netmap_open(const NetdevNetmapOptions *nm_opts,
>  {
>      struct nm_desc *nmd;
>      struct nmreq req;
> +    int ret;
>  
>      memset(&req, 0, sizeof(req));
>  
> -    nmd = nm_open(nm_opts->ifname, &req, NETMAP_NO_TX_POLL,
> +    nmd = nm_open(nm_opts->ifname, &req, NETMAP_NO_TX_POLL | NM_OPEN_NO_MMAP,
>                    NULL);
>      if (nmd == NULL) {
>          error_setg_errno(errp, errno, "Failed to nm_open() %s",
> @@ -97,6 +119,17 @@ static struct nm_desc *netmap_open(const NetdevNetmapOptions *nm_opts,
>          return NULL;
>      }
>  
> +    /* Check if we already have a nm_desc that uses the same memory as the one
> +     * just opened, so that nm_mmap() can skip mmap() and inherit from parent.
> +     */
> +    ret = nm_mmap(nmd, netmap_find_memory(nmd));

Looks like I could not find nm_mmap() definition in neither qemu or
freebsd source. Is there anything missed?

> +    if (ret) {
> +        error_setg_errno(errp, errno, "Failed to nm_mmap() %s",
> +                         nm_opts->ifname);
> +        nm_close(nmd);
> +        return NULL;
> +    }
> +
>      return nmd;
>  }
>  
> @@ -321,6 +354,8 @@ static void netmap_cleanup(NetClientState *nc)
>      netmap_poll(nc, false);
>      nm_close(s->nmd);
>      s->nmd = NULL;
> +
> +    QTAILQ_REMOVE(&netmap_clients, s, next);
>  }
>  
>  /* Offloading manipulation support callbacks. */
> @@ -423,6 +458,7 @@ int net_init_netmap(const NetClientOptions *opts,
>      s->rx = NETMAP_RXRING(nmd->nifp, 0);
>      s->vnet_hdr_len = 0;
>      pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname);
> +    QTAILQ_INSERT_TAIL(&netmap_clients, s, next);
>      netmap_read_poll(s, true); /* Initially only poll for reads. */
>  
>      return 0;

  reply	other threads:[~2016-01-14  3:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-08 13:15 [Qemu-devel] [PATCH 0/2] net: netmap: use nm_open() to open netmap port Vincenzo Maffione
2016-01-08 13:15 ` [Qemu-devel] [PATCH 1/2] net: netmap: use nm_open() to open netmap ports Vincenzo Maffione
2016-01-08 13:15 ` [Qemu-devel] [PATCH 2/2] net: netmap: avoid mmap() when ports use the same shared memory area Vincenzo Maffione
2016-01-14  3:25   ` Jason Wang [this message]
2016-01-22  8:35     ` Vincenzo Maffione

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=5697151C.6090506@redhat.com \
    --to=jasowang@redhat.com \
    --cc=g.lettieri@iet.unipi.it \
    --cc=qemu-devel@nongnu.org \
    --cc=rizzo@iet.unipi.it \
    --cc=v.maffione@gmail.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).