From patchwork Mon Aug 18 11:21:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 35490 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f198.google.com (mail-pd0-f198.google.com [209.85.192.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B585220676 for ; Mon, 18 Aug 2014 11:21:36 +0000 (UTC) Received: by mail-pd0-f198.google.com with SMTP id fp1sf41839901pdb.1 for ; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=pBpvRFW38aqqIf47qWtRQ+c2MyuYRiK7K9pJHUbbtrQ=; b=JfFQQoAH6L7ipBaBw3XlPUKeqA4oZydAoC1naOe3/uFWVZ7yg+7EdbTNiJTHBFN3MU 5tLB/iwqNiLO3GzF6WQWbXlQJLiNX84lEGffHzQijze5lBujZP/lTdiKBJHqj3UpiQFt 6WtsuXI6WEhkqNY97FVsDg845mx5ZJF/MN6gAoWVDZGrc2ar+2v1OEWPXj0goTBQrJrL QxaM9TR6XKQaxwnbbbrs4MxaMVMMX+kwHulWlmuNZsLETNgIEACKsRq22BEztUQcEaKQ 4dDkf6Oui9e+b6JN+JJhclWvkcY/jQ6ThFr98InXbGMyALnLfEPPk8jcAF4p8LOfvSZ2 V9pQ== X-Gm-Message-State: ALoCoQn92N1JzH0rs/c7sN7LW1TOyHkpSS5hYifBV398DOdtxv6K0Ebp0MAG3niYoI3MHxAfwjwZ X-Received: by 10.66.222.9 with SMTP id qi9mr18275480pac.28.1408360895930; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.95.21 with SMTP id h21ls2366119qge.52.gmail; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) X-Received: by 10.221.61.5 with SMTP id wu5mr24561539vcb.13.1408360895783; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id xe4si7042298vcb.10.2014.08.18.04.21.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 04:21:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so5652128vcb.9 for ; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) X-Received: by 10.53.0.164 with SMTP id az4mr309736vdd.52.1408360895645; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp143796vcb; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) X-Received: by 10.140.16.194 with SMTP id 60mr4801190qgb.105.1408360895002; Mon, 18 Aug 2014 04:21:35 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id f19si23623039qaq.68.2014.08.18.04.21.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 18 Aug 2014 04:21:34 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XJL0I-0001VP-2t; Mon, 18 Aug 2014 11:21:34 +0000 Received: from mail-qc0-f178.google.com ([209.85.216.178]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XJL0C-0001Up-E3 for lng-odp@lists.linaro.org; Mon, 18 Aug 2014 11:21:28 +0000 Received: by mail-qc0-f178.google.com with SMTP id x3so4697045qcv.9 for ; Mon, 18 Aug 2014 04:21:23 -0700 (PDT) X-Received: by 10.224.26.84 with SMTP id d20mr54561152qac.11.1408360883187; Mon, 18 Aug 2014 04:21:23 -0700 (PDT) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id b19sm29231254qaw.44.2014.08.18.04.21.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Aug 2014 04:21:22 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Mon, 18 Aug 2014 14:21:52 +0300 Message-Id: <1408360912-17592-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.0.4 X-Topics: patch Subject: [lng-odp] [PATCH] Change invalid buffer pool handle to zero X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 For consistency and easier debugging, use zero as the value of an invalid pool handle (in linux-generic). Signed-off-by: Petri Savolainen --- include/odp_buffer_pool.h | 2 +- .../linux-generic/include/odp_buffer_internal.h | 4 +- .../include/odp_buffer_pool_internal.h | 2 +- platform/linux-generic/odp_buffer_pool.c | 50 +++++++++++++++------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/include/odp_buffer_pool.h b/include/odp_buffer_pool.h index 26d9f14..fe88898 100644 --- a/include/odp_buffer_pool.h +++ b/include/odp_buffer_pool.h @@ -27,7 +27,7 @@ extern "C" { #define ODP_BUFFER_POOL_NAME_LEN 32 /** Invalid buffer pool */ -#define ODP_BUFFER_POOL_INVALID (0xffffffff) +#define ODP_BUFFER_POOL_INVALID 0 /** ODP buffer pool */ typedef uint32_t odp_buffer_pool_t; diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index bffd0dd..232ddb5 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -48,7 +48,7 @@ typedef union odp_buffer_bits_t { odp_buffer_t handle; struct { - uint32_t pool:ODP_BUFFER_POOL_BITS; + uint32_t pool:ODP_BUFFER_POOL_BITS; /* pool index */ uint32_t index:ODP_BUFFER_INDEX_BITS; }; } odp_buffer_bits_t; @@ -91,7 +91,7 @@ typedef struct odp_buffer_hdr_t { odp_atomic_int_t ref_count; /* reference count */ odp_buffer_scatter_t scatter; /* Scatter/gather list */ int type; /* type of next header */ - odp_buffer_pool_t pool; /* buffer pool */ + odp_buffer_pool_t pool; /* buffer pool handle */ } odp_buffer_hdr_t; diff --git a/platform/linux-generic/include/odp_buffer_pool_internal.h b/platform/linux-generic/include/odp_buffer_pool_internal.h index 1c0a9fc..52a507e 100644 --- a/platform/linux-generic/include/odp_buffer_pool_internal.h +++ b/platform/linux-generic/include/odp_buffer_pool_internal.h @@ -68,7 +68,7 @@ struct pool_entry_s { extern void *pool_entry_ptr[]; -static inline void *get_pool_entry(odp_buffer_pool_t pool_id) +static inline void *get_pool_entry(uint32_t pool_id) { return pool_entry_ptr[pool_id]; } diff --git a/platform/linux-generic/odp_buffer_pool.c b/platform/linux-generic/odp_buffer_pool.c index a48781a..10697cc 100644 --- a/platform/linux-generic/odp_buffer_pool.c +++ b/platform/linux-generic/odp_buffer_pool.c @@ -80,13 +80,28 @@ void *pool_entry_ptr[ODP_CONFIG_BUFFER_POOLS]; static __thread odp_buffer_chunk_hdr_t *local_chunk[ODP_CONFIG_BUFFER_POOLS]; +static inline odp_buffer_pool_t pool_index_to_handle(uint32_t pool_id) +{ + return pool_id + 1; +} + + +static inline uint32_t pool_handle_to_index(odp_buffer_pool_t pool_hdl) +{ + return pool_hdl - 1; +} + + static inline void set_handle(odp_buffer_hdr_t *hdr, pool_entry_t *pool, uint32_t index) { - uint32_t pool_id = (uint32_t) pool->s.pool; + odp_buffer_pool_t pool_hdl = pool->s.pool; + uint32_t pool_id = pool_handle_to_index(pool_hdl); - if (pool_id > ODP_CONFIG_BUFFER_POOLS) - ODP_ERR("set_handle: Bad pool id\n"); + if (pool_id >= ODP_CONFIG_BUFFER_POOLS) { + ODP_ERR("set_handle: Bad pool handle %u\n", pool_hdl); + exit(0); + } if (index > ODP_BUFFER_MAX_INDEX) ODP_ERR("set_handle: Bad buffer index\n"); @@ -98,7 +113,7 @@ static inline void set_handle(odp_buffer_hdr_t *hdr, int odp_buffer_pool_init_global(void) { - odp_buffer_pool_t i; + uint32_t i; pool_tbl = odp_shm_reserve("odp_buffer_pools", sizeof(pool_table_t), @@ -113,7 +128,7 @@ int odp_buffer_pool_init_global(void) /* init locks */ pool_entry_t *pool = &pool_tbl->pool[i]; LOCK_INIT(&pool->s.lock); - pool->s.pool = i; + pool->s.pool = pool_index_to_handle(i); pool_entry_ptr[i] = pool; } @@ -363,9 +378,9 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, size_t buf_size, size_t buf_align, int buf_type) { - odp_buffer_pool_t i; + odp_buffer_pool_t pool_hdl = ODP_BUFFER_POOL_INVALID; pool_entry_t *pool; - odp_buffer_pool_t pool_id = ODP_BUFFER_POOL_INVALID; + uint32_t i; for (i = 0; i < ODP_CONFIG_BUFFER_POOLS; i++) { pool = get_pool_entry(i); @@ -388,20 +403,20 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, UNLOCK(&pool->s.lock); - pool_id = i; + pool_hdl = pool->s.pool; break; } UNLOCK(&pool->s.lock); } - return pool_id; + return pool_hdl; } odp_buffer_pool_t odp_buffer_pool_lookup(const char *name) { - odp_buffer_pool_t i; + uint32_t i; pool_entry_t *pool; for (i = 0; i < ODP_CONFIG_BUFFER_POOLS; i++) { @@ -411,7 +426,7 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name) if (strcmp(name, pool->s.name) == 0) { /* found it */ UNLOCK(&pool->s.lock); - return i; + return pool->s.pool; } UNLOCK(&pool->s.lock); } @@ -420,11 +435,12 @@ odp_buffer_pool_t odp_buffer_pool_lookup(const char *name) } -odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_id) +odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_hdl) { 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]; @@ -462,12 +478,12 @@ odp_buffer_t odp_buffer_alloc(odp_buffer_pool_t pool_id) void odp_buffer_free(odp_buffer_t buf) { odp_buffer_hdr_t *hdr; - odp_buffer_pool_t pool_id; + uint32_t pool_id; pool_entry_t *pool; odp_buffer_chunk_hdr_t *chunk_hdr; hdr = odp_buf_to_hdr(buf); - pool_id = hdr->pool; + pool_id = pool_handle_to_index(hdr->pool); pool = get_pool_entry(pool_id); chunk_hdr = local_chunk[pool_id]; @@ -500,13 +516,15 @@ odp_buffer_pool_t odp_buffer_pool(odp_buffer_t buf) } -void odp_buffer_pool_print(odp_buffer_pool_t pool_id) +void odp_buffer_pool_print(odp_buffer_pool_t pool_hdl) { pool_entry_t *pool; odp_buffer_chunk_hdr_t *chunk_hdr; uint32_t i; + uint32_t pool_id; - pool = get_pool_entry(pool_id); + pool_id = pool_handle_to_index(pool_hdl); + pool = get_pool_entry(pool_id); printf("Pool info\n"); printf("---------\n");