libnet: use shifts instead of divisions for netbuf
authorReto Achermann <reto.achermann@inf.ethz.ch>
Thu, 6 Apr 2017 11:26:09 +0000 (13:26 +0200)
committerReto Achermann <reto.achermann@inf.ethz.ch>
Thu, 6 Apr 2017 11:26:09 +0000 (13:26 +0200)
Signed-off-by: Reto Achermann <reto.achermann@inf.ethz.ch>

lib/net/netbufs.c
lib/net/networking_internal.h

index 6951f63..726e00d 100644 (file)
@@ -87,6 +87,11 @@ errval_t net_buf_add(struct net_buf_pool *bp, struct capref frame, size_t buffer
     }
 
     reg->buffer_size = ROUND_UP(buffersize, NETWORKING_BUFFER_ALIGN);
+    reg->buffer_shift = 0;
+    while(!((reg->buffer_size >> reg->buffer_shift) & 0x1)) {
+        reg->buffer_shift++;
+    }
+
     reg->framecap = frame;
     reg->pool = bp;
 
@@ -285,6 +290,9 @@ struct pbuf *net_buf_get_by_region(struct net_buf_pool *bp,
             assert((offset & (reg->buffer_size - 1)) == 0);
             assert(offset / reg->buffer_size < reg->pool->buffer_count);
             struct net_buf_p *nb = reg->netbufs + (offset / reg->buffer_size);
+
+            assert((offset / reg->buffer_size) == (offset >> reg->buffer_shift));
+
             assert(nb->offset == offset);
 
             return (struct pbuf *)nb;
index c4ffae9..1eb636b 100644 (file)
@@ -38,7 +38,7 @@
 #define BENCH_NUM_MEASUREMENTS_BITS 16
 #define BENCH_NUM_MEASUREMENTS (1UL << BENCH_NUM_MEASUREMENTS_BITS)
 
-#define NETBUF_DEBGUG 1
+#define NETBUF_DEBGUG 0
 
 /**
  * @brief encapsulates the state of the networking library
@@ -88,6 +88,7 @@ struct net_buf_region
     struct capref framecap;
     struct net_buf_region *next;
     size_t buffer_size;
+    uint8_t buffer_shift;
     regionid_t regionid;
     struct net_buf_pool *pool;
     struct net_buf_p *netbufs;    /// array of netbufs