diff options
author | Petri Savolainen <petri.savolainen@linaro.org> | 2015-01-26 15:05:47 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-01-27 15:34:30 +0300 |
commit | 8d0f8982236b400b11b2e712e3bbd289694e6f2b (patch) | |
tree | 0d4fc7575ee10c44812dd71910b029b293d41693 /platform | |
parent | 9cb80344f017193a3c432c2a12fe7af348881396 (diff) |
api: pool: Rename pool params and remove buffer types
* Renamed odp_buffer_pool_param_t to odp_pool_param_t
* Moved buffer pool parameters into "buf" struct
* Left other structs for other types (pkt and tmo) to
be added and implemented
* Pool type field is common to all pool types
* Removed buffer types and use ODP_EVENT_XXX for event
type and ODP_POOL_XXX for pool type instead. So event
types may not be assosiated to a pool (and may not have
a corresponding pool type).
Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/include/api/odp_pool.h | 79 | ||||
-rw-r--r-- | platform/linux-generic/include/odp_buffer_inlines.h | 2 | ||||
-rw-r--r-- | platform/linux-generic/include/odp_buffer_internal.h | 3 | ||||
-rw-r--r-- | platform/linux-generic/include/odp_buffer_pool_internal.h | 6 | ||||
-rw-r--r-- | platform/linux-generic/odp_buffer_pool.c | 76 | ||||
-rw-r--r-- | platform/linux-generic/odp_event.c | 11 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet.c | 12 | ||||
-rw-r--r-- | platform/linux-generic/odp_schedule.c | 10 | ||||
-rw-r--r-- | platform/linux-generic/odp_timer.c | 2 |
9 files changed, 104 insertions, 97 deletions
diff --git a/platform/linux-generic/include/api/odp_pool.h b/platform/linux-generic/include/api/odp_pool.h index 3b9b38412..eba7b833d 100644 --- a/platform/linux-generic/include/api/odp_pool.h +++ b/platform/linux-generic/include/api/odp_pool.h @@ -26,35 +26,54 @@ extern "C" { #include <odp_event.h> /** @addtogroup odp_buffer - * Operations on a buffer pool. + * Operations on a pool. * @{ */ /** Maximum queue name lenght in chars */ -#define ODP_BUFFER_POOL_NAME_LEN 32 +#define ODP_POOL_NAME_LEN 32 /** - * Buffer pool parameters - * Used to communicate buffer pool creation options. + * Pool parameters + * Used to communicate pool creation options. */ -typedef struct odp_buffer_pool_param_t { - uint32_t buf_size; /**< Buffer size in bytes. The maximum - number of bytes application will - store in each buffer. For packets, this - is the maximum packet data length, and - configured headroom and tailroom will be - added to this number */ - uint32_t buf_align; /**< Minimum buffer alignment in bytes. - Valid values are powers of two. Use 0 - for default alignment. Default will - always be a multiple of 8. */ - uint32_t num_bufs; /**< Number of buffers in the pool */ - int buf_type; /**< Buffer type */ -} odp_buffer_pool_param_t; - -#define ODP_BUFFER_TYPE_RAW ODP_EVENT_BUFFER -#define ODP_BUFFER_TYPE_PACKET ODP_EVENT_PACKET -#define ODP_BUFFER_TYPE_TIMEOUT ODP_EVENT_TIMEOUT +typedef struct odp_pool_param_t { + union { + struct { + uint32_t size; /**< Buffer size in bytes. The + maximum number of bytes + application will store in each + buffer. */ + uint32_t align; /**< Minimum buffer alignment in bytes. + Valid values are powers of two. + Use 0 for default alignment. + Default will always be a multiple + of 8. */ + uint32_t num; /**< Number of buffers in the pool */ + } buf; +/* Reserved for packet and timeout specific params + struct { + uint32_t seg_size; + uint32_t seg_align; + uint32_t num; + } pkt; + struct { + } tmo; +*/ + }; + + int type; /**< Pool type */ + +} odp_pool_param_t; + +/** Invalid pool type */ +#define ODP_POOL_TYPE_INVALID ODP_EVENT_TYPE_INVALID +/** Packet pool*/ +#define ODP_POOL_PACKET ODP_EVENT_PACKET +/** Buffer pool */ +#define ODP_POOL_BUFFER ODP_EVENT_BUFFER +/** Timeout pool */ +#define ODP_POOL_TIMEOUT ODP_EVENT_TIMEOUT /** * Create a buffer pool @@ -79,7 +98,7 @@ typedef struct odp_buffer_pool_param_t { odp_buffer_pool_t odp_buffer_pool_create(const char *name, odp_shm_t shm, - odp_buffer_pool_param_t *params); + odp_pool_param_t *params); /** * Destroy a buffer pool previously created by odp_buffer_pool_create() @@ -118,13 +137,13 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name); * Used to get information about a buffer pool. */ typedef struct odp_buffer_pool_info_t { - const char *name; /**< pool name */ - odp_shm_t shm; /**< handle of shared memory area - supplied by application to - contain buffer pool, or - ODP_SHM_INVALID if this pool is - managed by ODP */ - odp_buffer_pool_param_t params; /**< pool parameters */ + const char *name; /**< pool name */ + odp_shm_t shm; /**< handle of shared memory area + supplied by application to + contain buffer pool, or + ODP_SHM_INVALID if this pool is + managed by ODP */ + odp_pool_param_t params; /**< pool parameters */ } odp_buffer_pool_info_t; /** diff --git a/platform/linux-generic/include/odp_buffer_inlines.h b/platform/linux-generic/include/odp_buffer_inlines.h index ee264a656..000e67377 100644 --- a/platform/linux-generic/include/odp_buffer_inlines.h +++ b/platform/linux-generic/include/odp_buffer_inlines.h @@ -116,7 +116,7 @@ static inline odp_buffer_hdr_t *validate_buf(odp_buffer_t buf) /* A valid buffer index must be on stride, and must be in range */ if ((handle.index % buf_stride != 0) || - ((uint32_t)(handle.index / buf_stride) >= pool->s.params.num_bufs)) + ((uint32_t)(handle.index / buf_stride) >= pool->s.params.buf.num)) return NULL; buf_hdr = (odp_buffer_hdr_t *)(void *) diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index 9475c8bd0..14c32c191 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -28,6 +28,7 @@ extern "C" { #include <odp_config.h> #include <odp_byteorder.h> #include <odp_thread.h> +#include <odp_event.h> #define ODP_BITSIZE(x) \ @@ -163,8 +164,6 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool, size_t size); */ int _odp_buffer_type(odp_buffer_t buf); -#define _ODP_BUFFER_TYPE_ANY 0 - #ifdef __cplusplus } diff --git a/platform/linux-generic/include/odp_buffer_pool_internal.h b/platform/linux-generic/include/odp_buffer_pool_internal.h index b0e696e45..4ace3c380 100644 --- a/platform/linux-generic/include/odp_buffer_pool_internal.h +++ b/platform/linux-generic/include/odp_buffer_pool_internal.h @@ -84,8 +84,8 @@ struct pool_entry_s { odp_spinlock_t lock ODP_ALIGNED_CACHE; #endif - char name[ODP_BUFFER_POOL_NAME_LEN]; - odp_buffer_pool_param_t params; + char name[ODP_POOL_NAME_LEN]; + odp_pool_param_t params; _odp_buffer_pool_init_t init_params; odp_buffer_pool_t pool_hdl; uint32_t pool_id; @@ -239,7 +239,7 @@ static inline void ret_buf(struct pool_entry_s *pool, odp_buffer_hdr_t *buf) buf->allocator = ODP_FREEBUF; /* Mark buffer free */ - if (!buf->flags.hdrdata && buf->type != ODP_BUFFER_TYPE_RAW) { + if (!buf->flags.hdrdata && buf->type != ODP_EVENT_BUFFER) { while (buf->segcount > 0) { if (buffer_is_secure(buf) || pool_is_secure(pool)) memset(buf->addr[buf->segcount - 1], diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c index d24304555..fb65c2db2 100644 --- a/platform/linux-generic/odp_buffer_pool.c +++ b/platform/linux-generic/odp_buffer_pool.c @@ -101,7 +101,7 @@ int odp_buffer_pool_init_global(void) odp_buffer_pool_t odp_buffer_pool_create(const char *name, odp_shm_t shm, - odp_buffer_pool_param_t *params) + odp_pool_param_t *params) { odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID; pool_entry_t *pool; @@ -131,7 +131,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, 0; uint32_t blk_size, buf_stride; - uint32_t buf_align = params->buf_align; + uint32_t buf_align = params->buf.align; /* Validate requested buffer alignment */ if (buf_align > ODP_CONFIG_BUFFER_ALIGN_MAX || @@ -145,36 +145,35 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, buf_align = ODP_CONFIG_BUFFER_ALIGN_MIN; /* Calculate space needed for buffer blocks and metadata */ - switch (params->buf_type) { - case ODP_BUFFER_TYPE_RAW: - case ODP_BUFFER_TYPE_TIMEOUT: - blk_size = params->buf_size; + switch (params->type) { + case ODP_POOL_BUFFER: + case ODP_POOL_TIMEOUT: + blk_size = params->buf.size; /* Optimize small raw buffers */ - if (blk_size > ODP_MAX_INLINE_BUF || params->buf_align != 0) + if (blk_size > ODP_MAX_INLINE_BUF || params->buf.align != 0) blk_size = ODP_ALIGN_ROUNDUP(blk_size, buf_align); - buf_stride = params->buf_type == ODP_BUFFER_TYPE_RAW ? + buf_stride = params->type == ODP_POOL_BUFFER ? sizeof(odp_buffer_hdr_stride) : sizeof(odp_timeout_hdr_stride); break; - case ODP_BUFFER_TYPE_PACKET: - case _ODP_BUFFER_TYPE_ANY: + case ODP_POOL_PACKET: headroom = ODP_CONFIG_PACKET_HEADROOM; tailroom = ODP_CONFIG_PACKET_TAILROOM; - unsegmented = params->buf_size > ODP_CONFIG_PACKET_BUF_LEN_MAX; + unsegmented = params->buf.size > ODP_CONFIG_PACKET_BUF_LEN_MAX; if (unsegmented) blk_size = ODP_ALIGN_ROUNDUP( - headroom + params->buf_size + tailroom, + headroom + params->buf.size + tailroom, buf_align); else blk_size = ODP_ALIGN_ROUNDUP( - headroom + params->buf_size + tailroom, + headroom + params->buf.size + tailroom, ODP_CONFIG_PACKET_BUF_LEN_MIN); - buf_stride = params->buf_type == ODP_BUFFER_TYPE_PACKET ? + buf_stride = params->type == ODP_POOL_PACKET ? sizeof(odp_packet_hdr_stride) : sizeof(odp_any_hdr_stride); break; @@ -184,7 +183,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, } /* Validate requested number of buffers against addressable limits */ - if (params->num_bufs > + if (params->buf.num > (ODP_BUFFER_MAX_BUFFERS / (buf_stride / ODP_CACHE_LINE_SIZE))) return ODP_BUFFER_POOL_INVALID; @@ -207,8 +206,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, pool->s.name[0] = 0; } else { strncpy(pool->s.name, name, - ODP_BUFFER_POOL_NAME_LEN - 1); - pool->s.name[ODP_BUFFER_POOL_NAME_LEN - 1] = 0; + ODP_POOL_NAME_LEN - 1); + pool->s.name[ODP_POOL_NAME_LEN - 1] = 0; pool->s.flags.has_name = 1; } @@ -221,13 +220,13 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, block_size = 0; pool->s.buf_align = blk_size == 0 ? 0 : sizeof(void *); } else { - block_size = params->num_bufs * blk_size; + block_size = params->buf.num * blk_size; pool->s.buf_align = buf_align; } pad_size = ODP_CACHE_LINE_SIZE_ROUNDUP(block_size) - block_size; - mdata_size = params->num_bufs * buf_stride; - udata_size = params->num_bufs * udata_stride; + mdata_size = params->buf.num * buf_stride; + udata_size = params->buf.num * udata_stride; pool->s.pool_size = ODP_PAGE_SIZE_ROUNDUP(block_size + pad_size + @@ -310,7 +309,7 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, tmp->flags.zeroized = zeroized; tmp->size = 0; odp_atomic_store_u32(&tmp->ref_count, 0); - tmp->type = params->buf_type; + tmp->type = params->type; tmp->pool_hdl = pool->s.pool_hdl; tmp->udata_addr = (void *)udat; tmp->udata_size = init_params->udata_size; @@ -365,8 +364,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, pool->s.tailroom = tailroom; /* Watermarks are hard-coded for now to control caching */ - pool->s.high_wm = params->num_bufs / 2; - pool->s.low_wm = params->num_bufs / 4; + pool->s.high_wm = params->buf.num / 2; + pool->s.low_wm = params->buf.num / 4; pool_hdl = pool->s.pool_hdl; break; @@ -408,10 +407,10 @@ int odp_buffer_pool_info(odp_buffer_pool_t pool_hdl, info->name = pool->s.name; info->shm = pool->s.flags.user_supplied_shm ? pool->s.pool_shm : ODP_SHM_INVALID; - info->params.buf_size = pool->s.params.buf_size; - info->params.buf_align = pool->s.params.buf_align; - info->params.num_bufs = pool->s.params.num_bufs; - info->params.buf_type = pool->s.params.buf_type; + info->params.buf.size = pool->s.params.buf.size; + info->params.buf.align = pool->s.params.buf.align; + info->params.buf.num = pool->s.params.buf.num; + info->params.type = pool->s.params.type; return 0; } @@ -437,7 +436,7 @@ int odp_buffer_pool_destroy(odp_buffer_pool_t pool_hdl) flush_cache(&local_cache[pool_id], &pool->s); /* Call fails if pool has allocated buffers */ - if (odp_atomic_load_u32(&pool->s.bufcount) < pool->s.params.num_bufs) { + if (odp_atomic_load_u32(&pool->s.bufcount) < pool->s.params.buf.num) { POOL_UNLOCK(&pool->s.lock); return -1; } @@ -494,7 +493,7 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size) /* By default, buffers inherit their pool's zeroization setting */ buf->buf.flags.zeroized = pool->s.flags.zeroized; - if (buf->buf.type == ODP_BUFFER_TYPE_PACKET) { + if (buf->buf.type == ODP_EVENT_PACKET) { packet_init(pool, &buf->pkt, size); if (pool->s.init_params.buf_init != NULL) @@ -509,7 +508,7 @@ odp_buffer_t buffer_alloc(odp_buffer_pool_t pool_hdl, size_t size) odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_hdl) { return buffer_alloc(pool_hdl, - odp_pool_to_entry(pool_hdl)->s.params.buf_size); + odp_pool_to_entry(pool_hdl)->s.params.buf.size); } void odp_buffer_free(odp_buffer_t buf) @@ -558,11 +557,10 @@ void odp_buffer_pool_print(odp_buffer_pool_t pool_hdl) ODP_DBG(" name %s\n", pool->s.flags.has_name ? pool->s.name : "Unnamed Pool"); ODP_DBG(" pool type %s\n", - pool->s.params.buf_type == ODP_BUFFER_TYPE_RAW ? "raw" : - (pool->s.params.buf_type == ODP_BUFFER_TYPE_PACKET ? "packet" : - (pool->s.params.buf_type == ODP_BUFFER_TYPE_TIMEOUT ? "timeout" : - (pool->s.params.buf_type == _ODP_BUFFER_TYPE_ANY ? "any" : - "unknown")))); + pool->s.params.type == ODP_POOL_BUFFER ? "buffer" : + (pool->s.params.type == ODP_POOL_PACKET ? "packet" : + (pool->s.params.type == ODP_POOL_TIMEOUT ? "timeout" : + "unknown"))); ODP_DBG(" pool storage %sODP managed\n", pool->s.flags.user_supplied_shm ? "application provided, " : ""); @@ -578,14 +576,14 @@ void odp_buffer_pool_print(odp_buffer_pool_t pool_hdl) ODP_DBG(" pool mdata base %p\n", pool->s.pool_mdata_addr); ODP_DBG(" udata size %zu\n", pool->s.init_params.udata_size); ODP_DBG(" headroom %u\n", pool->s.headroom); - ODP_DBG(" buf size %zu\n", pool->s.params.buf_size); + ODP_DBG(" buf size %zu\n", pool->s.params.buf.size); ODP_DBG(" tailroom %u\n", pool->s.tailroom); ODP_DBG(" buf align %u requested, %u used\n", - pool->s.params.buf_align, pool->s.buf_align); - ODP_DBG(" num bufs %u\n", pool->s.params.num_bufs); + pool->s.params.buf.align, pool->s.buf_align); + ODP_DBG(" num bufs %u\n", pool->s.params.buf.num); ODP_DBG(" bufs available %u %s\n", bufcount, pool->s.low_wm_assert ? " **low wm asserted**" : ""); - ODP_DBG(" bufs in use %u\n", pool->s.params.num_bufs - bufcount); + ODP_DBG(" bufs in use %u\n", pool->s.params.buf.num - bufcount); ODP_DBG(" buf allocs %lu\n", bufallocs); ODP_DBG(" buf frees %lu\n", buffrees); ODP_DBG(" buf empty %lu\n", bufempty); diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c index f3e70b9bb..c4291f846 100644 --- a/platform/linux-generic/odp_event.c +++ b/platform/linux-generic/odp_event.c @@ -15,14 +15,5 @@ int odp_event_type(odp_event_t event) buf = odp_buffer_from_event(event); - switch (_odp_buffer_type(buf)) { - case ODP_BUFFER_TYPE_RAW: - return ODP_EVENT_BUFFER; - case ODP_BUFFER_TYPE_PACKET: - return ODP_EVENT_PACKET; - case ODP_BUFFER_TYPE_TIMEOUT: - return ODP_EVENT_TIMEOUT; - default: - return ODP_EVENT_TYPE_INVALID; - } + return _odp_buffer_type(buf); } diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 3ce6f47a2..6b38b80c7 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -29,17 +29,17 @@ odp_packet_t odp_packet_alloc(odp_buffer_pool_t pool_hdl, uint32_t len) { pool_entry_t *pool = odp_pool_to_entry(pool_hdl); - if (pool->s.params.buf_type != ODP_BUFFER_TYPE_PACKET) + if (pool->s.params.type != ODP_POOL_PACKET) return ODP_PACKET_INVALID; /* Handle special case for zero-length packets */ if (len == 0) { odp_packet_t pkt = (odp_packet_t)buffer_alloc(pool_hdl, - pool->s.params.buf_size); + pool->s.params.buf.size); if (pkt != ODP_PACKET_INVALID) pull_tail(odp_packet_hdr(pkt), - pool->s.params.buf_size); + pool->s.params.buf.size); return pkt; } @@ -581,7 +581,7 @@ int odp_packet_is_valid(odp_packet_t pkt) { odp_buffer_hdr_t *buf = validate_buf((odp_buffer_t)pkt); - return (buf != NULL && buf->type == ODP_BUFFER_TYPE_PACKET); + return (buf != NULL && buf->type == ODP_EVENT_PACKET); } /* @@ -627,11 +627,11 @@ odp_packet_t _odp_packet_alloc(odp_buffer_pool_t pool_hdl) { pool_entry_t *pool = odp_pool_to_entry(pool_hdl); - if (pool->s.params.buf_type != ODP_BUFFER_TYPE_PACKET) + if (pool->s.params.type != ODP_POOL_PACKET) return ODP_PACKET_INVALID; return (odp_packet_t)buffer_alloc(pool_hdl, - pool->s.params.buf_size); + pool->s.params.buf.size); } /** diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 13ed6e964..79ae1b3d1 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -85,7 +85,7 @@ int odp_schedule_init_global(void) odp_shm_t shm; odp_buffer_pool_t pool; int i, j; - odp_buffer_pool_param_t params; + odp_pool_param_t params; ODP_DBG("Schedule init ... "); @@ -100,10 +100,10 @@ int odp_schedule_init_global(void) return -1; } - params.buf_size = sizeof(queue_desc_t); - params.buf_align = 0; - params.num_bufs = SCHED_POOL_SIZE/sizeof(queue_desc_t); - params.buf_type = ODP_BUFFER_TYPE_RAW; + params.buf.size = sizeof(queue_desc_t); + params.buf.align = 0; + params.buf.num = SCHED_POOL_SIZE/sizeof(queue_desc_t); + params.type = ODP_POOL_BUFFER; pool = odp_buffer_pool_create("odp_sched_pool", ODP_SHM_NULL, ¶ms); diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index 107cf3d5d..a09d1895a 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -557,7 +557,7 @@ static unsigned timer_expire(odp_timer_pool *tp, uint32_t idx, uint64_t tick) #endif if (odp_likely(tmo_buf != ODP_BUFFER_INVALID)) { /* Fill in metadata fields in system timeout buffer */ - if (_odp_buffer_type(tmo_buf) == ODP_BUFFER_TYPE_TIMEOUT) { + if (_odp_buffer_type(tmo_buf) == ODP_EVENT_TIMEOUT) { /* Convert from buffer to timeout hdr */ odp_timeout_hdr_t *tmo_hdr = timeout_hdr_from_buf(tmo_buf); |