diff mbox series

[v2,07/10] libxl: event: poller pipe optimisation

Message ID 20200113170843.21332-8-ian.jackson@eu.citrix.com (mailing list archive)
State Superseded
Headers show
Series libxl: event: Fix hang for some applications | expand

Commit Message

Ian Jackson Jan. 13, 2020, 5:08 p.m. UTC
Track in userland whether the poller pipe is nonempty.  This saves us
writing many many bytes to the pipe if nothing ever reads them.

This is going to be relevant in a moment, where we are going to create
a situation where this will happen quite a lot.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>

squash! libxl: event: poller pipe optimisation
---
 tools/libxl/libxl_event.c    | 3 +++
 tools/libxl/libxl_internal.h | 1 +
 2 files changed, 4 insertions(+)

Comments

George Dunlap Jan. 17, 2020, 12:06 p.m. UTC | #1
On 1/13/20 5:08 PM, Ian Jackson wrote:
> Track in userland whether the poller pipe is nonempty.  This saves us
> writing many many bytes to the pipe if nothing ever reads them.
> 
> This is going to be relevant in a moment, where we are going to create
> a situation where this will happen quite a lot.
> 
> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
> 
> squash! libxl: event: poller pipe optimisation

Stray "squash" detrius.

Other than that:

Reviewed-by: George Dunlap <george.dunlap@citrix.com>
Ian Jackson Jan. 17, 2020, 1:41 p.m. UTC | #2
George Dunlap writes ("Re: [PATCH v2 07/10] libxl: event: poller pipe optimisation"):
> On 1/13/20 5:08 PM, Ian Jackson wrote:
> > squash! libxl: event: poller pipe optimisation
> 
> Stray "squash" detrius.

Oops.

> Other than that:
> 
> Reviewed-by: George Dunlap <george.dunlap@citrix.com>

Thanks, fixed.

Ian.
diff mbox series

Patch

diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c
index b50d4e5074..3e76fa5af5 100644
--- a/tools/libxl/libxl_event.c
+++ b/tools/libxl/libxl_event.c
@@ -1417,6 +1417,7 @@  static void afterpoll_internal(libxl__egc *egc, libxl__poller *poller,
     }
 
     if (afterpoll_check_fd(poller,fds,nfds, poller->wakeup_pipe[0],POLLIN)) {
+        poller->pipe_nonempty = 0;
         int e = libxl__self_pipe_eatall(poller->wakeup_pipe[0]);
         if (e) LIBXL__EVENT_DISASTER(gc, "read wakeup", e, 0);
     }
@@ -1809,6 +1810,8 @@  void libxl__poller_put(libxl_ctx *ctx, libxl__poller *p)
 
 void libxl__poller_wakeup(libxl__gc *gc, libxl__poller *p)
 {
+    if (p->pipe_nonempty) return;
+    p->pipe_nonempty = 1;
     int e = libxl__self_pipe_wakeup(p->wakeup_pipe[1]);
     if (e) LIBXL__EVENT_DISASTER(gc, "cannot poke watch pipe", e, 0);
 }
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index eec4bf767d..0ab324102b 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -625,6 +625,7 @@  struct libxl__poller {
     int (*fd_rindices)[3]; /* see libxl_event.c:beforepoll_internal */
 
     int wakeup_pipe[2]; /* 0 means no fd allocated */
+    bool pipe_nonempty;
 
     /*
      * We also use the poller to record whether any fds have been