From f3bcf0f5b24ac135cbe5a3deea3146710b003380 Mon Sep 17 00:00:00 2001
From: Will Dietz <w@wdtz.org>
Date: Sat, 16 May 2015 18:58:46 -0500
Subject: [PATCH] Introduce NOOPT state (like in the paper!), use to fastpath.

Results in significantly better performance when optimization
is not possible.
---
 libipc/io.cpp            | 9 +++++++++
 libipc/ipcreg_internal.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/libipc/io.cpp b/libipc/io.cpp
index 25dce02..5dba16d 100644
--- a/libipc/io.cpp
+++ b/libipc/io.cpp
@@ -145,6 +145,8 @@ void attempt_optimization(int fd, bool send) {
       // Configure localfd
       copy_bufsizes(fd, i.localfd);
       set_local_nonblocking(fd, i.non_blocking);
+    } else {
+      i.state = STATE_NOOPT;
     }
   }
 }
@@ -168,6 +170,9 @@ ssize_t do_ipc_io(int fd, buf_t buf, size_t count, int flags, IOFunc IO,
     return ret;
   }
 
+  if (i.state == STATE_NOOPT)
+    return IO(fd, buf, count, flags);
+
   // Otherwise, use original fd:
   size_t &bytes = get_byte_counter(i, send);
   ssize_t rem = (TRANS_THRESHOLD - bytes);
@@ -293,6 +298,10 @@ ssize_t do_ipc_iov(int fd, const struct iovec *vec, int count, IOVFunc IO,
     return ret;
   }
 
+  if (i.state == STATE_NOOPT) {
+    return IO(fd, vec, count);
+  }
+
   size_t bytes = 0;
   for (int i = 0; i < count; ++i) {
     // Overflow check...
diff --git a/libipc/ipcreg_internal.h b/libipc/ipcreg_internal.h
index 96cc314..c3c071e 100644
--- a/libipc/ipcreg_internal.h
+++ b/libipc/ipcreg_internal.h
@@ -37,6 +37,7 @@ enum EndpointState {
   STATE_UNOPT,
   STATE_ID_EXCHANGE,
   STATE_OPTIMIZED,
+  STATE_NOOPT
 };
 
 struct epoll_entry {
-- 
GitLab