diff mbox

[PATCHv4,ODP,v1.0,Buffer/Packet,APIs,9/9] Implement ODP v1.0 buffer/packet APIs for linux-generic

Message ID 546238AF.6060400@linaro.org
State New
Headers show

Commit Message

Taras Kondratiuk Nov. 11, 2014, 4:26 p.m. UTC
On 11/11/2014 04:13 PM, Bill Fischofer wrote:
> v4 fixes bufcount initialization during pool creation
> 
> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> ---
>   platform/linux-generic/odp_buffer.c       |  263 ++++++-
>   platform/linux-generic/odp_buffer_pool.c  |  664 +++++++---------
>   platform/linux-generic/odp_packet.c       | 1200 +++++++++++++++++++++++------
>   platform/linux-generic/odp_packet_flags.c |  202 -----
>   4 files changed, 1458 insertions(+), 871 deletions(-)
>   delete mode 100644 platform/linux-generic/odp_packet_flags.c

[snip]

> diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
> index a48d7d6..3e37d60 100644
> --- a/platform/linux-generic/odp_buffer_pool.c
> +++ b/platform/linux-generic/odp_buffer_pool.c

[snip]

> @@ -431,93 +291,172 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name)
>   	return ODP_BUFFER_POOL_INVALID;
>   }
>   
> -
> -odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_hdl)
> +odp_buffer_pool_t odp_buffer_pool_next(odp_buffer_pool_t pool_hdl,
> +				       char *name,
> +				       size_t *udata_size,
> +				       odp_buffer_pool_param_t *params,
> +				       int *predef)
>   {
> -	pool_entry_t *pool;
> -	odp_buffer_chunk_hdr_t *chunk;
> -	odp_buffer_bits_t handle;
> -	uint32_t pool_id = pool_handle_to_index(pool_hdl);
> -
> -	pool  = get_pool_entry(pool_id);
> -	chunk = local_chunk[pool_id];
> -
> -	if (chunk == NULL) {
> -		LOCK(&pool->s.lock);
> -		chunk = rem_chunk(pool);
> -		UNLOCK(&pool->s.lock);
> +	pool_entry_t *next_pool;
> +	uint32_t pool_id;
>   
> -		if (chunk == NULL)
> -			return ODP_BUFFER_INVALID;
> +	/* NULL input means first element */
> +	if (pool_hdl == ODP_BUFFER_POOL_INVALID) {
> +		pool_id = 0;
> +		next_pool = get_pool_entry(pool_id);
> +	} else {
> +		pool_id = pool_handle_to_index(pool_hdl);
>   
> -		local_chunk[pool_id] = chunk;
> +		if (pool_id == ODP_CONFIG_BUFFER_POOLS)
> +			return ODP_BUFFER_POOL_INVALID;
> +		else
> +			next_pool = get_pool_entry(++pool_id);
>   	}
>   
> -	if (chunk->chunk.num_bufs == 0) {
> -		/* give the chunk buffer */
> -		local_chunk[pool_id] = NULL;
> -		chunk->buf_hdr.type = pool->s.buf_type;
> +	/* Only interested in pools that exist */
> +	while (next_pool->s.shm == ODP_SHM_INVALID) {
> +		if (pool_id == ODP_CONFIG_BUFFER_POOLS)
> +			return ODP_BUFFER_POOL_INVALID;
> +		else
> +			next_pool = get_pool_entry(++pool_id);
> +	}

pool_id should be incremented before comparing it with
ODP_CONFIG_BUFFER_POOLS. Otherwise for the last pool next_pool will
point out of pool_entry_ptr array. Working fix:
diff mbox

Patch

diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c
index 3e37d60..2724a11 100644
--- a/platform/linux-generic/odp_buffer_pool.c
+++ b/platform/linux-generic/odp_buffer_pool.c
@@ -307,18 +307,18 @@  odp_buffer_pool_t odp_buffer_pool_next(odp_buffer_pool_t pool_hdl,
 	} else {
 		pool_id = pool_handle_to_index(pool_hdl);
 
-		if (pool_id == ODP_CONFIG_BUFFER_POOLS)
+		if (++pool_id == ODP_CONFIG_BUFFER_POOLS)
 			return ODP_BUFFER_POOL_INVALID;
 		else
-			next_pool = get_pool_entry(++pool_id);
+			next_pool = get_pool_entry(pool_id);
 	}
 
 	/* Only interested in pools that exist */
 	while (next_pool->s.shm == ODP_SHM_INVALID) {
-		if (pool_id == ODP_CONFIG_BUFFER_POOLS)
+		if (++pool_id == ODP_CONFIG_BUFFER_POOLS)
 			return ODP_BUFFER_POOL_INVALID;
 		else
-			next_pool = get_pool_entry(++pool_id);
+			next_pool = get_pool_entry(pool_id);
 	}
 
 	/* Found the next pool, so return info about it */