From patchwork Wed Jun 25 14:35:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 32490 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4F7FE20C88 for ; Wed, 25 Jun 2014 14:30:05 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id m20sf3619318qcx.1 for ; Wed, 25 Jun 2014 07:30:05 -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=cZBZijwjIPkMyvlAgIXz91MG7gKhv6Rcdgnk15XAcpA=; b=YSF4QS2BBVMA9qFCxkHYODMJ4hPVeASmxHjkmzen4onhsM5voZhyPHCYg9Yk52Fy+O hGy3Kqy8lC0wGcoUeYEFeAIJ6TEwXWUFn0JOnQ9ZZSKvpoLCV624VwswEGYKwg0baDnZ zICV3YjHh1WJUqffSLOcGxN9kYFRIVYHhEdJAbZ5UZW8X/wfZliQ9B5b2v4bATMURqhU 8ZnxkiA6nlFHXrDMsol7OthRnRDAW8WLjdKz1o0ky3S5HeOqqKklz+aj0GftsQnYV9Xr JEKfcGDhWMQpzNHV65VwEi9crosACbnaDc8hQLyBsOTywYqfkx2t8s3tHsQpQwj65p9d QS2Q== X-Gm-Message-State: ALoCoQmCDfI1boQk8InXXzSNAwuxkFcBi2j82rQV98BFdlxTRzY6d5/75VAz8zfG0mH3ahNeHsX9 X-Received: by 10.58.187.44 with SMTP id fp12mr4636483vec.24.1403706605169; Wed, 25 Jun 2014 07:30:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.247 with SMTP id l110ls2668023qgf.90.gmail; Wed, 25 Jun 2014 07:30:05 -0700 (PDT) X-Received: by 10.58.1.9 with SMTP id 9mr7393575vei.14.1403706605059; Wed, 25 Jun 2014 07:30:05 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id cb8si2374250vcb.36.2014.06.25.07.30.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 07:30:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.181 as permitted sender) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id db11so2040678veb.26 for ; Wed, 25 Jun 2014 07:30:05 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr7354849vcg.16.1403706604945; Wed, 25 Jun 2014 07:30:04 -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 tc5csp294255vcb; Wed, 25 Jun 2014 07:30:04 -0700 (PDT) X-Received: by 10.224.54.133 with SMTP id q5mr12442649qag.84.1403706604429; Wed, 25 Jun 2014 07:30:04 -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 y4si4830832qay.122.2014.06.25.07.30.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Jun 2014 07:30:04 -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 1WzoBE-0003sg-QE; Wed, 25 Jun 2014 14:28:08 +0000 Received: from mail-qg0-f52.google.com ([209.85.192.52]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WzoB8-0003sY-3W for lng-odp@lists.linaro.org; Wed, 25 Jun 2014 14:28:02 +0000 Received: by mail-qg0-f52.google.com with SMTP id f51so1750343qge.11 for ; Wed, 25 Jun 2014 07:29:51 -0700 (PDT) X-Received: by 10.140.104.106 with SMTP id z97mr4528014qge.21.1403706591309; Wed, 25 Jun 2014 07:29:51 -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 j1sm6191908qaa.11.2014.06.25.07.29.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Jun 2014 07:29:50 -0700 (PDT) From: Petri Savolainen To: lng-odp@lists.linaro.org Date: Wed, 25 Jun 2014 17:35:00 +0300 Message-Id: <1403706900-30989-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 2.0.0 X-Topics: patch Subject: [lng-odp] [PATCH] Buffer header C99 compliance and cleanup 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.128.181 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 Fixed C99 compliance bug in buffer header (removed the empty array). Cleaned and harmonized buffer pool implementation for different buffer types. Signed-off-by: Petri Savolainen --- .../linux-generic/include/odp_buffer_internal.h | 14 ++- .../include/odp_buffer_pool_internal.h | 4 +- .../linux-generic/include/odp_packet_internal.h | 5 +- .../linux-generic/include/odp_timer_internal.h | 4 +- platform/linux-generic/source/odp_buffer_pool.c | 130 ++++++++++++--------- platform/linux-generic/source/odp_packet.c | 4 +- 6 files changed, 94 insertions(+), 67 deletions(-) diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index a1a6b4e..11024f8 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -79,6 +79,7 @@ typedef struct odp_buffer_chunk_t { } odp_buffer_chunk_t; +/* Common buffer header */ typedef struct odp_buffer_hdr_t { struct odp_buffer_hdr_t *next; /* next buf in a list */ odp_buffer_bits_t handle; /* handle */ @@ -92,13 +93,20 @@ typedef struct odp_buffer_hdr_t { int type; /* type of next header */ odp_buffer_pool_t pool; /* buffer pool */ - uint8_t payload[]; /* next header or data */ } odp_buffer_hdr_t; -ODP_ASSERT(sizeof(odp_buffer_hdr_t) == ODP_OFFSETOF(odp_buffer_hdr_t, payload), - ODP_BUFFER_HDR_T__SIZE_ERROR); +/* Ensure next header starts from 8 byte align */ +ODP_ASSERT((sizeof(odp_buffer_hdr_t) % 8) == 0, ODP_BUFFER_HDR_T__SIZE_ERROR); +/* Raw buffer header */ +typedef struct { + odp_buffer_hdr_t buf_hdr; /* common buffer header */ + uint8_t buf_data[]; /* start of buffer data area */ +} odp_raw_buffer_hdr_t; + + +/* Chunk header */ typedef struct odp_buffer_chunk_hdr_t { odp_buffer_hdr_t buf_hdr; odp_buffer_chunk_t chunk; diff --git a/platform/linux-generic/include/odp_buffer_pool_internal.h b/platform/linux-generic/include/odp_buffer_pool_internal.h index 381482f..1c0a9fc 100644 --- a/platform/linux-generic/include/odp_buffer_pool_internal.h +++ b/platform/linux-generic/include/odp_buffer_pool_internal.h @@ -58,8 +58,8 @@ struct pool_entry_s { uint64_t num_bufs; void *pool_base_addr; uint64_t pool_size; - size_t payload_size; - size_t payload_align; + size_t user_size; + size_t user_align; int buf_type; size_t hdr_size; }; diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index eb978a3..45ed412 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -115,11 +115,10 @@ typedef struct { odp_pktio_t input; uint32_t pad; - uint8_t payload[]; - + uint8_t buf_data[]; /* start of buffer data area */ } odp_packet_hdr_t; -ODP_ASSERT(sizeof(odp_packet_hdr_t) == ODP_OFFSETOF(odp_packet_hdr_t, payload), +ODP_ASSERT(sizeof(odp_packet_hdr_t) == ODP_OFFSETOF(odp_packet_hdr_t, buf_data), ODP_PACKET_HDR_T__SIZE_ERR); ODP_ASSERT(sizeof(odp_packet_hdr_t) % sizeof(uint64_t) == 0, ODP_PACKET_HDR_T__SIZE_ERR2); diff --git a/platform/linux-generic/include/odp_timer_internal.h b/platform/linux-generic/include/odp_timer_internal.h index f99a10e..76f1545 100644 --- a/platform/linux-generic/include/odp_timer_internal.h +++ b/platform/linux-generic/include/odp_timer_internal.h @@ -48,13 +48,13 @@ typedef struct odp_timeout_hdr_t { timeout_t meta; - uint8_t payload[]; + uint8_t buf_data[]; } odp_timeout_hdr_t; ODP_ASSERT(sizeof(odp_timeout_hdr_t) == - ODP_OFFSETOF(odp_timeout_hdr_t, payload), + ODP_OFFSETOF(odp_timeout_hdr_t, buf_data), ODP_TIMEOUT_HDR_T__SIZE_ERR); ODP_ASSERT(sizeof(odp_timeout_hdr_t) % sizeof(uint64_t) == 0, diff --git a/platform/linux-generic/source/odp_buffer_pool.c b/platform/linux-generic/source/odp_buffer_pool.c index f4aedff..25c9565 100644 --- a/platform/linux-generic/source/odp_buffer_pool.c +++ b/platform/linux-generic/source/odp_buffer_pool.c @@ -46,9 +46,15 @@ union buffer_type_any_u { odp_timeout_hdr_t tmo; }; -ODP_ASSERT(sizeof(union buffer_type_any_u) % sizeof(uint64_t) == 0, +ODP_ASSERT((sizeof(union buffer_type_any_u) % 8) == 0, BUFFER_TYPE_ANY_U__SIZE_ERR); +/* Any buffer type header */ +typedef struct { + union buffer_type_any_u any_hdr; /* any buffer type */ + uint8_t buf_data[]; /* start of buffer data area */ +} odp_any_buffer_hdr_t; + typedef union pool_entry_u { struct pool_entry_s s; @@ -184,10 +190,9 @@ static odp_buffer_chunk_hdr_t *rem_chunk(pool_entry_t *pool) static void add_chunk(pool_entry_t *pool, odp_buffer_chunk_hdr_t *chunk_hdr) { - if (pool->s.head) { - /* link pool head to the chunk */ + if (pool->s.head) /* link pool head to the chunk */ add_buf_index(chunk_hdr, pool->s.head->buf_hdr.index); - } else + else add_buf_index(chunk_hdr, NULL_INDEX); pool->s.head = chunk_hdr; @@ -197,9 +202,9 @@ static void add_chunk(pool_entry_t *pool, odp_buffer_chunk_hdr_t *chunk_hdr) static void check_align(pool_entry_t *pool, odp_buffer_hdr_t *hdr) { - if (!ODP_ALIGNED_CHECK_POWER_2(hdr->addr, pool->s.payload_align)) { - ODP_ERR("check_align: payload align error %p, align %zu\n", - hdr->addr, pool->s.payload_align); + if (!ODP_ALIGNED_CHECK_POWER_2(hdr->addr, pool->s.user_align)) { + ODP_ERR("check_align: user data align error %p, align %zu\n", + hdr->addr, pool->s.user_align); exit(0); } @@ -216,28 +221,45 @@ static void fill_hdr(void *ptr, pool_entry_t *pool, uint32_t index, { odp_buffer_hdr_t *hdr = (odp_buffer_hdr_t *)ptr; size_t size = pool->s.hdr_size; - uint8_t *payload = hdr->payload; + uint8_t *buf_data; if (buf_type == ODP_BUFFER_TYPE_CHUNK) size = sizeof(odp_buffer_chunk_hdr_t); - if (pool->s.buf_type == ODP_BUFFER_TYPE_PACKET) { - odp_packet_hdr_t *packet_hdr = ptr; - payload = packet_hdr->payload; - } else if (pool->s.buf_type == ODP_BUFFER_TYPE_TIMEOUT) { - odp_timeout_hdr_t *tmo_hdr = ptr; - payload = tmo_hdr->payload; - } else if (pool->s.buf_type == ODP_BUFFER_TYPE_ANY) { - payload = ((uint8_t *)ptr) + sizeof(union buffer_type_any_u); + switch (pool->s.buf_type) { + odp_raw_buffer_hdr_t *raw_hdr; + odp_packet_hdr_t *packet_hdr; + odp_timeout_hdr_t *tmo_hdr; + odp_any_buffer_hdr_t *any_hdr; + + case ODP_BUFFER_TYPE_RAW: + raw_hdr = ptr; + buf_data = raw_hdr->buf_data; + break; + case ODP_BUFFER_TYPE_PACKET: + packet_hdr = ptr; + buf_data = packet_hdr->buf_data; + break; + case ODP_BUFFER_TYPE_TIMEOUT: + tmo_hdr = ptr; + buf_data = tmo_hdr->buf_data; + break; + case ODP_BUFFER_TYPE_ANY: + any_hdr = ptr; + buf_data = any_hdr->buf_data; + break; + default: + ODP_ERR("Bad buffer type\n"); + exit(0); } memset(hdr, 0, size); set_handle(hdr, pool, index); - hdr->addr = &payload[pool->s.buf_offset - pool->s.hdr_size]; + hdr->addr = &buf_data[pool->s.buf_offset - pool->s.hdr_size]; hdr->index = index; - hdr->size = pool->s.payload_size; + hdr->size = pool->s.user_size; hdr->pool = pool->s.pool; hdr->type = buf_type; @@ -249,9 +271,9 @@ static void link_bufs(pool_entry_t *pool) { odp_buffer_chunk_hdr_t *chunk_hdr; size_t hdr_size; - size_t payload_size; - size_t payload_align; - size_t size; + size_t data_size; + size_t data_align; + size_t tot_size; size_t offset; size_t min_size; uint64_t pool_size; @@ -260,51 +282,49 @@ static void link_bufs(pool_entry_t *pool) uintptr_t pool_base; int buf_type; - buf_type = pool->s.buf_type; - payload_size = pool->s.payload_size; - payload_align = pool->s.payload_align; - pool_size = pool->s.pool_size; - pool_base = (uintptr_t) pool->s.pool_base_addr; + buf_type = pool->s.buf_type; + data_size = pool->s.user_size; + data_align = pool->s.user_align; + pool_size = pool->s.pool_size; + pool_base = (uintptr_t) pool->s.pool_base_addr; - if (buf_type == ODP_BUFFER_TYPE_RAW) - hdr_size = sizeof(odp_buffer_hdr_t); - else if (buf_type == ODP_BUFFER_TYPE_PACKET) + if (buf_type == ODP_BUFFER_TYPE_RAW) { + hdr_size = sizeof(odp_raw_buffer_hdr_t); + } else if (buf_type == ODP_BUFFER_TYPE_PACKET) { hdr_size = sizeof(odp_packet_hdr_t); - else if (buf_type == ODP_BUFFER_TYPE_TIMEOUT) + } else if (buf_type == ODP_BUFFER_TYPE_TIMEOUT) { hdr_size = sizeof(odp_timeout_hdr_t); - else if (buf_type == ODP_BUFFER_TYPE_ANY) - hdr_size = sizeof(union buffer_type_any_u); - else { - ODP_ERR("odp_buffer_pool_create: Bad type %i\n", - buf_type); + } else if (buf_type == ODP_BUFFER_TYPE_ANY) { + hdr_size = sizeof(odp_any_buffer_hdr_t); + } else { + ODP_ERR("odp_buffer_pool_create: Bad type %i\n", buf_type); exit(0); } - /* Chunk must fit into buffer payload.*/ + /* Chunk must fit into buffer data area.*/ min_size = sizeof(odp_buffer_chunk_hdr_t) - hdr_size; - if (payload_size < min_size) - payload_size = min_size; + if (data_size < min_size) + data_size = min_size; - /* Roundup payload size to full cachelines */ - payload_size = ODP_CACHE_LINE_SIZE_ROUNDUP(payload_size); + /* Roundup data size to full cachelines */ + data_size = ODP_CACHE_LINE_SIZE_ROUNDUP(data_size); - /* Min cacheline alignment for buffer header and payload */ - payload_align = ODP_CACHE_LINE_SIZE_ROUNDUP(payload_align); - offset = ODP_CACHE_LINE_SIZE_ROUNDUP(hdr_size); + /* Min cacheline alignment for buffer header and data */ + data_align = ODP_CACHE_LINE_SIZE_ROUNDUP(data_align); + offset = ODP_CACHE_LINE_SIZE_ROUNDUP(hdr_size); /* Multiples of cacheline size */ - if (payload_size > payload_align) - size = payload_size + offset; + if (data_size > data_align) + tot_size = data_size + offset; else - size = payload_align + offset; + tot_size = data_align + offset; /* First buffer */ - buf_base = ODP_ALIGN_ROUNDUP(pool_base + offset, payload_align) - - offset; + buf_base = ODP_ALIGN_ROUNDUP(pool_base + offset, data_align) - offset; pool->s.hdr_size = hdr_size; pool->s.buf_base = buf_base; - pool->s.buf_size = size; + pool->s.buf_size = tot_size; pool->s.buf_offset = offset; index = 0; @@ -312,7 +332,7 @@ static void link_bufs(pool_entry_t *pool) pool->s.head = NULL; pool_size -= buf_base - pool_base; - while (pool_size > ODP_BUFS_PER_CHUNK * size) { + while (pool_size > ODP_BUFS_PER_CHUNK * tot_size) { int i; fill_hdr(chunk_hdr, pool, index, ODP_BUFFER_TYPE_CHUNK); @@ -333,7 +353,7 @@ static void link_bufs(pool_entry_t *pool) chunk_hdr = (odp_buffer_chunk_hdr_t *)index_to_hdr(pool, index); pool->s.num_bufs += ODP_BUFS_PER_CHUNK; - pool_size -= ODP_BUFS_PER_CHUNK * size; + pool_size -= ODP_BUFS_PER_CHUNK * tot_size; } } @@ -360,8 +380,8 @@ odp_buffer_pool_t odp_buffer_pool_create(const char *name, pool->s.name[ODP_BUFFER_POOL_NAME_LEN - 1] = 0; pool->s.pool_base_addr = base_addr; pool->s.pool_size = size; - pool->s.payload_size = buf_size; - pool->s.payload_align = buf_align; + pool->s.user_size = buf_size; + pool->s.user_align = buf_align; pool->s.buf_type = buf_type; link_bufs(pool); @@ -486,8 +506,8 @@ void odp_buffer_pool_print(odp_buffer_pool_t pool_id) printf(" pool base %p\n", pool->s.pool_base_addr); printf(" buf base 0x%"PRIxPTR"\n", pool->s.buf_base); printf(" pool size 0x%"PRIx64"\n", pool->s.pool_size); - printf(" buf size %zu\n", pool->s.payload_size); - printf(" buf align %zu\n", pool->s.payload_align); + printf(" buf size %zu\n", pool->s.user_size); + printf(" buf align %zu\n", pool->s.user_align); printf(" hdr size %zu\n", pool->s.hdr_size); printf(" alloc size %zu\n", pool->s.buf_size); printf(" offset to hdr %zu\n", pool->s.buf_offset); diff --git a/platform/linux-generic/source/odp_packet.c b/platform/linux-generic/source/odp_packet.c index 530e513..99fcc6d 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -28,7 +28,7 @@ void odp_packet_init(odp_packet_t pkt) size_t len; start = (uint8_t *)pkt_hdr + start_offset; - len = ODP_OFFSETOF(odp_packet_hdr_t, payload) - start_offset; + len = ODP_OFFSETOF(odp_packet_hdr_t, buf_data) - start_offset; memset(start, 0, len); pkt_hdr->l2_offset = ODP_PACKET_OFFSET_INVALID; @@ -348,7 +348,7 @@ int odp_packet_copy(odp_packet_t pkt_dst, odp_packet_t pkt_src) /* Copy packet header */ start_dst = (uint8_t *)pkt_hdr_dst + start_offset; start_src = (uint8_t *)pkt_hdr_src + start_offset; - len = ODP_OFFSETOF(odp_packet_hdr_t, payload) - start_offset; + len = ODP_OFFSETOF(odp_packet_hdr_t, buf_data) - start_offset; memcpy(start_dst, start_src, len); /* Copy frame payload */