]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
netbuf: Aligned buffers with `lwip_alloc_netbuf()`
authorSimon Kuenzer <simon.kuenzer@neclab.eu>
Mon, 9 Nov 2020 16:06:25 +0000 (17:06 +0100)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Thu, 12 Nov 2020 22:43:26 +0000 (23:43 +0100)
Adds an alignment parameter to `lwip_alloc_netbuf()` that enables
alignment of the buffer area (`m->buf`).

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
netbuf.c
netbuf.h
uknetdev.c

index 4878f74cc209929f6ea02953d6453fbfaf5911db..97c129c0101a31464d16c3cf454519e41495a032 100644 (file)
--- a/netbuf.c
+++ b/netbuf.c
@@ -50,32 +50,20 @@ static void _netbuf_free(struct pbuf *p)
 }
 
 struct uk_netbuf *lwip_alloc_netbuf(struct uk_alloc *a, size_t alloc_size,
-                                   size_t headroom)
+                                   size_t alloc_align, uint16_t headroom)
 {
-       void *allocation;
        struct uk_netbuf *b;
        struct _netbuf_pbuf *np;
 
-       allocation = uk_malloc(a, alloc_size);
-       if (unlikely(!allocation))
-               goto err_out;
-
-       b = uk_netbuf_prepare_buf(allocation, alloc_size,
-                                 headroom, sizeof(struct _netbuf_pbuf), NULL);
+       b = uk_netbuf_alloc_buf(a, alloc_size, alloc_align,
+                               headroom, sizeof(struct _netbuf_pbuf), NULL);
        if (unlikely(!b)) {
                LWIP_DEBUGF(PBUF_DEBUG,
-                           ("Failed to initialize netbuf with encapsulated pbuf: requested headroom: %"__PRIsz", alloc_size: %"__PRIsz"\n",
-                            headroom, alloc_size));
-               goto err_free_allocation;
+                           ("Failed to allocate netbuf with encapsulated pbuf: requested headroom: %"__PRIu16", size: %"__PRIsz", alignement: %"__PRIsz"\n",
+                            headroom, alloc_size, alloc_align));
+               goto err_out;
        }
 
-       /*
-        * Register allocator so that uk_netbuf_free() will
-        * return our memory back to this allocator when free'ing
-        * this netbuf
-        */
-       b->_a = a;
-
        /* Fill-out meta data */
        np = (struct _netbuf_pbuf *) uk_netbuf_get_priv(b);
        memset(np, 0, sizeof(struct _netbuf_pbuf));
@@ -97,8 +85,6 @@ struct uk_netbuf *lwip_alloc_netbuf(struct uk_alloc *a, size_t alloc_size,
                     b, b->buflen, uk_netbuf_headroom(b)));
        return b;
 
-err_free_allocation:
-       uk_free(a, allocation);
 err_out:
        return NULL;
 }
index 14920653a729f3b75e7865857913f565c99b90ea..db5adf7506f2200b1794bfb7dad5a56183547762 100644 (file)
--- a/netbuf.h
+++ b/netbuf.h
@@ -61,7 +61,7 @@ struct _netbuf_pbuf {
  * before handing over the embedded pbuf to the network stack.
  */
 struct uk_netbuf *lwip_alloc_netbuf(struct uk_alloc *a, size_t alloc_size,
-                                   size_t headroom);
+                                   size_t alloc_align, uint16_t headroom);
 
 /**
  * Returns the reference of the embedded pbuf of a netbuf
index 1d8c5e8ddf52f869b46a18cbe9bf067f1c4989b4..881eb60d036e84b14ceb8c5a9162cbdb65e29425 100644 (file)
@@ -120,6 +120,7 @@ static uint16_t netif_alloc_rxpkts(void *argp, struct uk_netbuf *nb[],
        for (i = 0; i < count; ++i) {
                nb[i] = lwip_alloc_netbuf(lwip_data->pkt_a,
                                          UKNETDEV_BUFLEN,
+                                         1 /* no alignment */,
                                          lwip_data->dev_info.nb_encap_rx);
                if (!nb[i]) {
                        /* we run out of memory */