[ovs-dev] [PATCH] latch-unix: Make the latch read buffer shared

anton.ivanov at cambridgegreys.com anton.ivanov at cambridgegreys.com
Wed Jul 14 16:36:36 UTC 2021


From: Anton Ivanov <anton.ivanov at cambridgegreys.com>

There is no point to add 512 bytes on the stack
every time latch is polled. Alignment, cache line thrashing,
etc - you name it.

The result of the read is discarded anyway so the buffer
can be shared by all latches.

Signed-off-by: Anton Ivanov <anton.ivanov at cambridgegreys.com>
---
 lib/latch-unix.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/latch-unix.c b/lib/latch-unix.c
index 2995076d6..e43fab770 100644
--- a/lib/latch-unix.c
+++ b/lib/latch-unix.c
@@ -23,6 +23,9 @@
 #include "openvswitch/poll-loop.h"
 #include "socket-util.h"
 
+/* All writes to latch are zero sized. Even 16 bytes are an overkill */
+static char latch_buffer[16];
+
 /* Initializes 'latch' as initially unset. */
 void
 latch_init(struct latch *latch)
@@ -43,9 +46,7 @@ latch_destroy(struct latch *latch)
 bool
 latch_poll(struct latch *latch)
 {
-    char buffer[_POSIX_PIPE_BUF];
-
-    return read(latch->fds[0], buffer, sizeof buffer) > 0;
+    return read(latch->fds[0], &latch_buffer, sizeof latch_buffer) > 0;
 }
 
 /* Sets 'latch'.
-- 
2.20.1



More information about the dev mailing list