All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@citrix.com>
To: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>, xen-devel@lists.xensource.com
Subject: Re: [PATCH 5/6] libxl: events: Deregister evtchn fd when not needed
Date: Fri, 28 Nov 2014 13:04:11 +0000	[thread overview]
Message-ID: <1417179851.23604.41.camel@citrix.com> (raw)
In-Reply-To: <1417112870-31894-6-git-send-email-ian.jackson@eu.citrix.com>

On Thu, 2014-11-27 at 18:27 +0000, Ian Jackson wrote:
> We want to have no fd events registered when we are idle.
> In this patch, deal with the evtchn fd:
> 
>  * Defer setup of the evtchn handle to the first use.
>  * Defer registration of the evtchn fd; register as needed on use.
>  * When cancelling an evtchn wait, or when wait setup fails, check
>    whether there are now no evtchn waits and if so deregister the fd.
>  * On libxl teardown, the evtchn fd should therefore be unregistered.
>    assert that this is the case.

Is there no locking required when registering/deregistering? Since there
are list manipulations in most of these places I presume it already
exists, but I thought I should check.

> 
> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
> ---
>  tools/libxl/libxl.c          |    4 +---
>  tools/libxl/libxl_event.c    |   27 +++++++++++++++++++--------
>  tools/libxl/libxl_internal.h |    1 +
>  3 files changed, 21 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> index 785253d..e0db4eb 100644
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -118,8 +118,6 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
>          rc = ERROR_FAIL; goto out;
>      }
>  
> -    rc = libxl__ctx_evtchn_init(gc);
> -
>      *pctx = ctx;
>      return 0;
>  
> @@ -166,7 +164,7 @@ int libxl_ctx_free(libxl_ctx *ctx)
>      for (i = 0; i < ctx->watch_nslots; i++)
>          assert(!libxl__watch_slot_contents(gc, i));
>      assert(!libxl__ev_fd_isregistered(&ctx->watch_efd));
> -    libxl__ev_fd_deregister(gc, &ctx->evtchn_efd);
> +    assert(!libxl__ev_fd_isregistered(&ctx->evtchn_efd));
>      assert(!libxl__ev_fd_isregistered(&ctx->sigchld_selfpipe_efd));
>  
>      /* Now there should be no more events requested from the application: */
> diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c
> index da0a20e..716f318 100644
> --- a/tools/libxl/libxl_event.c
> +++ b/tools/libxl/libxl_event.c
> @@ -721,7 +721,7 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,
>  
>  int libxl__ctx_evtchn_init(libxl__gc *gc) {
>      xc_evtchn *xce;
> -    int rc, fd;
> +    int rc;
>  
>      if (CTX->xce)
>          return 0;
> @@ -733,14 +733,10 @@ int libxl__ctx_evtchn_init(libxl__gc *gc) {
>          goto out;
>      }
>  
> -    fd = xc_evtchn_fd(xce);
> -    assert(fd >= 0);
> +    CTX->evtchn_fd = xc_evtchn_fd(xce);
> +    assert(CTX->evtchn_fd >= 0);

Given that you can always retrieve this no demand with xc_evtchn_fd(xce)
and that it is cheap do you need to stash it in the ctx?

> -    rc = libxl_fd_set_nonblock(CTX, fd, 1);
> -    if (rc) goto out;
> -
> -    rc = libxl__ev_fd_register(gc, &CTX->evtchn_efd,
> -                               evtchn_fd_callback, fd, POLLIN);
> +    rc = libxl_fd_set_nonblock(CTX, CTX->evtchn_fd, 1);
>      if (rc) goto out;
>  
>      CTX->xce = xce;
> @@ -751,6 +747,12 @@ int libxl__ctx_evtchn_init(libxl__gc *gc) {
>      return rc;
>  }
>  
> +static void evtchn_check_fd_deregister(libxl__gc *gc)
> +{
> +    if (CTX->xce && LIBXL_LIST_EMPTY(&CTX->evtchns_waiting))
> +        libxl__ev_fd_deregister(gc, &CTX->evtchn_efd);
> +}
> +
>  int libxl__ev_evtchn_wait(libxl__gc *gc, libxl__ev_evtchn *evev)
>  {
>      int r, rc;
> @@ -758,6 +760,13 @@ int libxl__ev_evtchn_wait(libxl__gc *gc, libxl__ev_evtchn *evev)
>      DBG("ev_evtchn=%p port=%d wait (was waiting=%d)",
>          evev, evev->port, evev->waiting);
>  
> +    rc = libxl__ctx_evtchn_init(gc);
> +    if (rc) goto out;
> +
> +    rc = libxl__ev_fd_register(gc, &CTX->evtchn_efd,
> +                               evtchn_fd_callback, CTX->evtchn_fd, POLLIN);
> +    if (rc) goto out;

Do you not need to do this only if evtchns_waiting is currently empty or
the efd is idle?

> +
>      if (evev->waiting)
>          return 0;

If you hit this you leave the stuff above done. Which may or may not 
matter depending on the answer above.


Ian.

  reply	other threads:[~2014-11-28 13:04 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 15:37 segv in osevent_release_nexus with libxl backend to libvirt Ian Campbell
     [not found] ` <21621.61406.151530.376288@mariner.uk.xensource.com>
2014-11-26 15:40   ` Ian Campbell
2014-11-26 15:52     ` Ian Campbell
2014-11-26 17:38       ` Ian Jackson
2014-11-27 10:22         ` Ian Campbell
2014-11-27 18:27           ` [PATCH for-4.5 0/6] libxl: events: Tear down fd interests when idle Ian Jackson
2014-11-27 18:27             ` [PATCH 1/6] libxl: events: Assert that libxl_ctx_free is not called from a hook Ian Jackson
2014-11-28 12:42               ` Ian Campbell
2014-11-27 18:27             ` [PATCH 2/6] libxl: events: Deregister xenstore watch fd when not needed Ian Jackson
2014-11-28 13:06               ` Ian Campbell
2014-11-28 14:56                 ` Ian Jackson
2014-11-28 15:00                   ` Ian Campbell
2014-11-28 13:19               ` Ian Campbell
2014-11-27 18:27             ` [PATCH 3/6] libxl: events: Deregister, don't just modify, sigchld pipe fd Ian Jackson
2014-11-28 12:48               ` Ian Campbell
2014-11-28 14:42                 ` Ian Jackson
2014-11-28 14:44                   ` Ian Campbell
2014-11-27 18:27             ` [PATCH 4/6] libxl: events: Tear down SIGCHLD machinery on ctx destruction Ian Jackson
2014-11-28 12:51               ` Ian Campbell
2014-11-27 18:27             ` [PATCH 5/6] libxl: events: Deregister evtchn fd when not needed Ian Jackson
2014-11-28 13:04               ` Ian Campbell [this message]
2014-11-28 14:47                 ` Ian Jackson
2014-11-28 14:52                   ` Ian Campbell
2014-12-09 11:22                     ` Ian Jackson
2014-12-09 11:31                       ` Ian Campbell
2014-12-09 15:48                         ` [PATCH 5/6] libxl: events: Deregister evtchn fd when not needed [and 1 more messages] Ian Jackson
2014-11-27 18:27             ` [PATCH 6/6] libxl: events: Document and enforce actual callbacks restriction Ian Jackson
2014-11-28 13:04               ` Ian Campbell
2014-11-27 18:30             ` [PATCH for-4.5 0/6] libxl: events: Tear down fd interests when idle Ian Jackson
2014-11-28 13:05               ` Ian Campbell
2014-12-08 16:18                 ` Konrad Rzeszutek Wilk
2014-12-08 10:33               ` Ian Campbell
2014-12-09 15:54             ` [PATCH for-4.5 v2 " Ian Jackson
2014-12-09 15:54               ` [PATCH 1/6] libxl: events: Assert that libxl_ctx_free is not called from a hook Ian Jackson
2014-12-09 15:54               ` [PATCH 2/6] libxl: events: Deregister xenstore watch fd when not needed Ian Jackson
2014-12-09 15:59                 ` Ian Campbell
2014-12-09 16:13                   ` Ian Jackson
2014-12-09 15:54               ` [PATCH 3/6] libxl: events: Deregister, don't just modify, sigchld pipe fd Ian Jackson
2014-12-09 15:54               ` [PATCH 4/6] libxl: events: Tear down SIGCHLD machinery on ctx destruction Ian Jackson
2014-12-09 15:54               ` [PATCH 5/6] libxl: events: Deregister evtchn fd when not needed Ian Jackson
2014-12-09 15:56                 ` Ian Campbell
2014-12-09 15:54               ` [PATCH 6/6] libxl: events: Document and enforce actual callbacks restriction Ian Jackson
2014-12-10 10:45               ` [PATCH for-4.5 v2 0/6] libxl: events: Tear down fd interests when idle Ian Campbell

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=1417179851.23604.41.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jfehlig@suse.com \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.