From: Pravin Shelar Date: Mon, 31 Mar 2014 20:22:39 +0000 (-0700) Subject: ofpbuf: Add ofpbuf_init_dpdk() X-Git-Tag: sliver-openvswitch-2.2.90-1~5^2~66 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=d8a59e895d7ffaf8fa83093e9ceb30bd3d3085ad;p=sliver-openvswitch.git ofpbuf: Add ofpbuf_init_dpdk() Signed-off-by: Pravin B Shelar Acked-by: Jarno Rajahalme --- diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 56521b7ae..21d8df6e9 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -22,6 +22,16 @@ #include "netdev-dpdk.h" #include "util.h" +static void +ofpbuf_init__(struct ofpbuf *b, size_t allocated, enum ofpbuf_source source) +{ + b->allocated = allocated; + b->source = source; + b->l2 = NULL; + b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX; + list_poison(&b->list_node); +} + static void ofpbuf_use__(struct ofpbuf *b, void *base, size_t allocated, enum ofpbuf_source source) @@ -30,11 +40,7 @@ ofpbuf_use__(struct ofpbuf *b, void *base, size_t allocated, ofpbuf_set_data(b, base); ofpbuf_set_size(b, 0); - b->allocated = allocated; - b->source = source; - b->l2 = NULL; - b->l2_5_ofs = b->l3_ofs = b->l4_ofs = UINT16_MAX; - list_poison(&b->list_node); + ofpbuf_init__(b, allocated, source); } /* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of @@ -101,6 +107,18 @@ ofpbuf_use_const(struct ofpbuf *b, const void *data, size_t size) ofpbuf_set_size(b, size); } +/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of + * memory starting at 'base'. DPDK allocated ofpbuf and *data is allocated + * from one continous memory region, so in memory data start right after + * ofpbuf. Therefore there is special method to free this type of + * buffer. ofpbuf base, data and size are initialized by dpdk rcv() so no + * need to initialize those fields. */ +void +ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated) +{ + ofpbuf_init__(b, allocated, OFPBUF_DPDK); +} + /* Initializes 'b' as an empty ofpbuf with an initial capacity of 'size' * bytes. */ void diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h index 975438b26..f19da7b32 100644 --- a/lib/ofpbuf.h +++ b/lib/ofpbuf.h @@ -85,6 +85,8 @@ void ofpbuf_use_stack(struct ofpbuf *, void *, size_t); void ofpbuf_use_stub(struct ofpbuf *, void *, size_t); void ofpbuf_use_const(struct ofpbuf *, const void *, size_t); +void ofpbuf_init_dpdk(struct ofpbuf *b, size_t allocated); + void ofpbuf_init(struct ofpbuf *, size_t); void ofpbuf_uninit(struct ofpbuf *); static inline void *ofpbuf_get_uninit_pointer(struct ofpbuf *);