[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH 3/4] lib/uknetdev: `uk_netbuf_alloc_buf()`: Introduce alignment



The API function `uk_netbuf_alloc_buf()` gets an alignment parameter which
can be used to request an aligned allocation for the packet buffer area
(`m->buf`).

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/uknetdev/include/uk/netbuf.h | 4 +++-
 lib/uknetdev/netbuf.c            | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/uknetdev/include/uk/netbuf.h b/lib/uknetdev/include/uk/netbuf.h
index ea803ae8..5212614a 100644
--- a/lib/uknetdev/include/uk/netbuf.h
+++ b/lib/uknetdev/include/uk/netbuf.h
@@ -245,6 +245,8 @@ struct uk_netbuf *uk_netbuf_alloc_indir(struct uk_alloc *a,
  *   to this allocator.
  * @param buflen
  *   Size of the buffer area
+ * @param bufalign
+ *   Alignment for the buffer area (`m->buf` will be aligned to it)
  * @param headroom
  *   Number of bytes reserved as headroom from the buffer area.
  *   `headroom` has to be smaller or equal to `buflen`.
@@ -263,7 +265,7 @@ struct uk_netbuf *uk_netbuf_alloc_indir(struct uk_alloc *a,
  *   - initialized uk_netbuf
  */
 struct uk_netbuf *uk_netbuf_alloc_buf(struct uk_alloc *a, size_t buflen,
-                                     uint16_t headroom,
+                                     size_t bufalign, uint16_t headroom,
                                      size_t privlen, uk_netbuf_dtor_t dtor);
 
 /**
diff --git a/lib/uknetdev/netbuf.c b/lib/uknetdev/netbuf.c
index c5cf662e..d87af053 100644
--- a/lib/uknetdev/netbuf.c
+++ b/lib/uknetdev/netbuf.c
@@ -99,7 +99,7 @@ struct uk_netbuf *uk_netbuf_alloc_indir(struct uk_alloc *a,
 }
 
 struct uk_netbuf *uk_netbuf_alloc_buf(struct uk_alloc *a, size_t buflen,
-                                     uint16_t headroom,
+                                     size_t bufalign, uint16_t headroom,
                                      size_t privlen, uk_netbuf_dtor_t dtor)
 {
        void *mem;
@@ -111,7 +111,7 @@ struct uk_netbuf *uk_netbuf_alloc_buf(struct uk_alloc *a, 
size_t buflen,
 
        alloc_len = NETBUF_ADDR_ALIGN_UP(buflen)
                    + NETBUF_ADDR_ALIGN_UP(sizeof(*m) + privlen);
-       mem = uk_malloc(a, alloc_len);
+       mem = uk_memalign(a, bufalign, alloc_len);
        if (!mem)
                return NULL;
 
-- 
2.20.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.