From patchwork Wed Apr 6 17:22:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 65211 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1180667lbc; Wed, 6 Apr 2016 10:22:56 -0700 (PDT) X-Received: by 10.107.6.6 with SMTP id 6mr28323507iog.24.1459963376821; Wed, 06 Apr 2016 10:22:56 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p128si3925759iop.87.2016.04.06.10.22.55; Wed, 06 Apr 2016 10:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2A6BA61836; Wed, 6 Apr 2016 17:22:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4599561618; Wed, 6 Apr 2016 17:22:48 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0BC6C61647; Wed, 6 Apr 2016 17:22:46 +0000 (UTC) Received: from mail-ob0-f180.google.com (mail-ob0-f180.google.com [209.85.214.180]) by lists.linaro.org (Postfix) with ESMTPS id 84BDE611FA for ; Wed, 6 Apr 2016 17:22:43 +0000 (UTC) Received: by mail-ob0-f180.google.com with SMTP id bg3so35819575obb.1 for ; Wed, 06 Apr 2016 10:22:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=FL8d08fIc87QOrVtEcojeqEZOSublbBSIejJ3fOSwQU=; b=Q5yXYkTxgPMcj+1S4b14+pMd4CMW/0hrf1dmst+ORhgdTZr6mpgSbKIcZGMyWmCimH e2+l7k9RkBQUrkAsYHtpoaRGP53MD2ziCddBNAy5VqqtDA3gmYZCHUo9DLekxFdy/Vs7 Dy43B6qoifHYPg6yjMmQgWTjAqcJPUiUVUGPZhhRjTvlNbMkxqOlcICRBoZkVaXbkK+H zGu84Ws0jUsAcRsbgrSDu5oZUkncgZhHmHAVs0To8GZ/raftFMlx7ByU3fssWaZzE3RP Pxh1q6owXuwmBGZVYwNVEj7sMDO6scbIpjaZ+X0TdhXi6fftjnlZ2siv1nxNF2Lwl082 pXpg== X-Gm-Message-State: AD7BkJKcoNDMtbGKCwk/y3U0scyCdksZKxjdbW3HJSHoqreU4XRAHA86t4/wVbwemaxFYk9Lf40= X-Received: by 10.60.177.134 with SMTP id cq6mr3267205oec.68.1459963363073; Wed, 06 Apr 2016 10:22:43 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id 8sm1113684obo.12.2016.04.06.10.22.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Apr 2016 10:22:42 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 6 Apr 2016 12:22:40 -0500 Message-Id: <1459963360-8901-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.5.0 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH] api: debug: promote ODP_STATIC_ASSERT() to be an ODP API X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Convert the formerly internal _ODP_STATIC_ASSERT() macro to be a full ODP API named ODP_STATIC_ASSERT(). This provides a wrapper around any platform-specific compile-time assertion macro. Signed-off-by: Bill Fischofer --- helper/include/odp/helper/eth.h | 9 ++++--- helper/include/odp/helper/icmp.h | 3 ++- helper/include/odp/helper/ip.h | 6 +++-- helper/include/odp/helper/ipsec.h | 9 ++++--- helper/include/odp/helper/udp.h | 3 ++- include/odp/api/spec/debug.h | 29 +++++----------------- platform/linux-generic/include/odp/api/debug.h | 21 ++++++++++++++++ .../linux-generic/include/odp_buffer_internal.h | 10 ++++---- .../linux-generic/include/odp_packet_internal.h | 12 ++++----- .../linux-generic/include/odp_packet_io_queue.h | 4 +-- platform/linux-generic/include/odp_packet_socket.h | 5 ++-- platform/linux-generic/odp_cpumask.c | 4 +-- platform/linux-generic/odp_schedule.c | 4 +-- platform/linux-generic/odp_shared_memory.c | 4 +-- platform/linux-generic/odp_timer.c | 2 +- platform/linux-generic/pktio/ipc.c | 4 +-- 16 files changed, 72 insertions(+), 57 deletions(-) diff --git a/helper/include/odp/helper/eth.h b/helper/include/odp/helper/eth.h index 1e16225..60949d9 100644 --- a/helper/include/odp/helper/eth.h +++ b/helper/include/odp/helper/eth.h @@ -40,7 +40,8 @@ typedef struct ODP_PACKED { } odph_ethaddr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_ethaddr_t) == ODPH_ETHADDR_LEN, "ODPH_ETHADDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_ethaddr_t) == ODPH_ETHADDR_LEN, + "ODPH_ETHADDR_T__SIZE_ERROR"); /** * Ethernet header @@ -52,7 +53,8 @@ typedef struct ODP_PACKED { } odph_ethhdr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_ethhdr_t) == ODPH_ETHHDR_LEN, "ODPH_ETHHDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_ethhdr_t) == ODPH_ETHHDR_LEN, + "ODPH_ETHHDR_T__SIZE_ERROR"); /** * VLAN header @@ -65,7 +67,8 @@ typedef struct ODP_PACKED { } odph_vlanhdr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_vlanhdr_t) == ODPH_VLANHDR_LEN, "ODPH_VLANHDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_vlanhdr_t) == ODPH_VLANHDR_LEN, + "ODPH_VLANHDR_T__SIZE_ERROR"); /* Ethernet header Ether Type ('type') values, a selected few */ diff --git a/helper/include/odp/helper/icmp.h b/helper/include/odp/helper/icmp.h index 929b8bc..e25646a 100644 --- a/helper/include/odp/helper/icmp.h +++ b/helper/include/odp/helper/icmp.h @@ -92,7 +92,8 @@ typedef struct ODP_PACKED { exceeded*/ /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_icmphdr_t) == ODPH_ICMPHDR_LEN, "ODPH_ICMPHDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_icmphdr_t) == ODPH_ICMPHDR_LEN, + "ODPH_ICMPHDR_T__SIZE_ERROR"); /** * @} diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h index 3789d54..4df41d9 100644 --- a/helper/include/odp/helper/ip.h +++ b/helper/include/odp/helper/ip.h @@ -71,7 +71,8 @@ typedef struct ODP_PACKED { } odph_ipv4hdr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_ipv4hdr_t) == ODPH_IPV4HDR_LEN, "ODPH_IPV4HDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_ipv4hdr_t) == ODPH_IPV4HDR_LEN, + "ODPH_IPV4HDR_T__SIZE_ERROR"); /** * Check if IPv4 checksum is valid @@ -146,7 +147,8 @@ typedef struct ODP_PACKED { } odph_ipv6hdr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_ipv6hdr_t) == ODPH_IPV6HDR_LEN, "ODPH_IPV6HDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_ipv6hdr_t) == ODPH_IPV6HDR_LEN, + "ODPH_IPV6HDR_T__SIZE_ERROR"); /** * IPv6 Header extensions diff --git a/helper/include/odp/helper/ipsec.h b/helper/include/odp/helper/ipsec.h index af3de87..034a341 100644 --- a/helper/include/odp/helper/ipsec.h +++ b/helper/include/odp/helper/ipsec.h @@ -38,7 +38,8 @@ typedef struct ODP_PACKED { } odph_esphdr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_esphdr_t) == ODPH_ESPHDR_LEN, "ODPH_ESPHDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_esphdr_t) == ODPH_ESPHDR_LEN, + "ODPH_ESPHDR_T__SIZE_ERROR"); /** * IPSec ESP trailer @@ -50,7 +51,8 @@ typedef struct ODP_PACKED { } odph_esptrl_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_esptrl_t) == ODPH_ESPTRL_LEN, "ODPH_ESPTRL_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_esptrl_t) == ODPH_ESPTRL_LEN, + "ODPH_ESPTRL_T__SIZE_ERROR"); /** * IPSec AH header @@ -65,7 +67,8 @@ typedef struct ODP_PACKED { } odph_ahhdr_t; /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_ahhdr_t) == ODPH_AHHDR_LEN, "ODPH_AHHDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_ahhdr_t) == ODPH_AHHDR_LEN, + "ODPH_AHHDR_T__SIZE_ERROR"); /** * @} diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h index 812f5b9..6f0621b 100644 --- a/helper/include/odp/helper/udp.h +++ b/helper/include/odp/helper/udp.h @@ -87,7 +87,8 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) } /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(sizeof(odph_udphdr_t) == ODPH_UDPHDR_LEN, "ODPH_UDPHDR_T__SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(odph_udphdr_t) == ODPH_UDPHDR_LEN, + "ODPH_UDPHDR_T__SIZE_ERROR"); /** * @} diff --git a/include/odp/api/spec/debug.h b/include/odp/api/spec/debug.h index 252a82f..0540268 100644 --- a/include/odp/api/spec/debug.h +++ b/include/odp/api/spec/debug.h @@ -17,31 +17,14 @@ extern "C" { #endif -#if defined(__GNUC__) && !defined(__clang__) - - -#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6)) - -/** - * @internal _Static_assert was only added in GCC 4.6. Provide a weak replacement - * for previous versions. - */ -#define _Static_assert(e, s) (extern int (*static_assert_checker(void)) \ - [sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })]) - -#endif - - - -#endif - - /** - * @internal Compile time assertion-macro - fail compilation if cond is false. - * This macro has zero runtime overhead + * @def ODP_STATIC_ASSERT + * Compile time assertion macro - fail compilation if cond if false. + * + * @param cond Conditional expression to be evaluated at compile time + * + * @param msg Compile time error message to be displayed if cond is false */ -#define _ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) - #ifdef __cplusplus } diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h index dc1fce0..047b49d 100644 --- a/platform/linux-generic/include/odp/api/debug.h +++ b/platform/linux-generic/include/odp/api/debug.h @@ -19,6 +19,27 @@ extern "C" { #include +#if defined(__GNUC__) && !defined(__clang__) + +#if __GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 6)) + +/** + * @internal _Static_assert was only added in GCC 4.6. Provide a weak replacement + * for previous versions. + */ +#define _Static_assert(e, s) (extern int (*static_assert_checker(void)) \ + [sizeof(struct { unsigned int error_if_negative:(e) ? 1 : -1; })]) + +#endif + +#endif + +/** + * @internal Compile time assertion-macro - fail compilation if cond is false. + * This macro has zero runtime overhead + */ +#define ODP_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h index ea092ca..a7a3ffd 100644 --- a/platform/linux-generic/include/odp_buffer_internal.h +++ b/platform/linux-generic/include/odp_buffer_internal.h @@ -50,10 +50,10 @@ extern "C" { ((x) <= 65536 ? 16 : \ (0/0))))))))))))))))) -_ODP_STATIC_ASSERT(ODP_CONFIG_PACKET_SEG_LEN_MIN >= 256, - "ODP Segment size must be a minimum of 256 bytes"); +ODP_STATIC_ASSERT(ODP_CONFIG_PACKET_SEG_LEN_MIN >= 256, + "ODP Segment size must be a minimum of 256 bytes"); -_ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MAX % +ODP_STATIC_ASSERT((ODP_CONFIG_PACKET_BUF_LEN_MAX % ODP_CONFIG_PACKET_SEG_LEN_MIN) == 0, "Packet max size must be a multiple of segment size"); @@ -146,8 +146,8 @@ struct odp_buffer_hdr_t { /** @internal Compile time assert that the * allocator field can handle any allocator id*/ -_ODP_STATIC_ASSERT(INT16_MAX >= ODP_THREAD_COUNT_MAX, - "ODP_BUFFER_HDR_T__ALLOCATOR__SIZE_ERROR"); +ODP_STATIC_ASSERT(INT16_MAX >= ODP_THREAD_COUNT_MAX, + "ODP_BUFFER_HDR_T__ALLOCATOR__SIZE_ERROR"); typedef struct odp_buffer_hdr_stride { uint8_t pad[ODP_CACHE_LINE_SIZE_ROUNDUP(sizeof(odp_buffer_hdr_t))]; diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 92b770f..47f4ff8 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -74,8 +74,8 @@ typedef union { }; } input_flags_t; -_ODP_STATIC_ASSERT(sizeof(input_flags_t) == sizeof(uint32_t), - "INPUT_FLAGS_SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(input_flags_t) == sizeof(uint32_t), + "INPUT_FLAGS_SIZE_ERROR"); /** * Packet error flags @@ -96,8 +96,8 @@ typedef union { }; } error_flags_t; -_ODP_STATIC_ASSERT(sizeof(error_flags_t) == sizeof(uint32_t), - "ERROR_FLAGS_SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(error_flags_t) == sizeof(uint32_t), + "ERROR_FLAGS_SIZE_ERROR"); /** * Packet output flags @@ -117,8 +117,8 @@ typedef union { }; } output_flags_t; -_ODP_STATIC_ASSERT(sizeof(output_flags_t) == sizeof(uint32_t), - "OUTPUT_FLAGS_SIZE_ERROR"); +ODP_STATIC_ASSERT(sizeof(output_flags_t) == sizeof(uint32_t), + "OUTPUT_FLAGS_SIZE_ERROR"); /** * Internal Packet header diff --git a/platform/linux-generic/include/odp_packet_io_queue.h b/platform/linux-generic/include/odp_packet_io_queue.h index 12e2b9f..5843f6a 100644 --- a/platform/linux-generic/include/odp_packet_io_queue.h +++ b/platform/linux-generic/include/odp_packet_io_queue.h @@ -24,8 +24,8 @@ extern "C" { /** Max nbr of pkts to receive in one burst (keep same as QUEUE_MULTI_MAX) */ #define ODP_PKTIN_QUEUE_MAX_BURST 16 /* pktin_deq_multi() depends on the condition: */ -_ODP_STATIC_ASSERT(ODP_PKTIN_QUEUE_MAX_BURST >= QUEUE_MULTI_MAX, - "ODP_PKTIN_DEQ_MULTI_MAX_ERROR"); +ODP_STATIC_ASSERT(ODP_PKTIN_QUEUE_MAX_BURST >= QUEUE_MULTI_MAX, + "ODP_PKTIN_DEQ_MULTI_MAX_ERROR"); int pktin_enqueue(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain); odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *queue); diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index bc83e80..09a571b 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -65,8 +65,9 @@ struct ring { struct tpacket_req req; }; -_ODP_STATIC_ASSERT(offsetof(struct ring, mm_space) <= ODP_CACHE_LINE_SIZE, - "ERR_STRUCT_RING"); + +ODP_STATIC_ASSERT(offsetof(struct ring, mm_space) <= ODP_CACHE_LINE_SIZE, + "ERR_STRUCT_RING"); /** Packet socket using mmap rings for both Rx and Tx */ typedef struct { diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c index fd672e2..3d35ade 100644 --- a/platform/linux-generic/odp_cpumask.c +++ b/platform/linux-generic/odp_cpumask.c @@ -21,8 +21,8 @@ #include /** @internal Compile time assert */ -_ODP_STATIC_ASSERT(CPU_SETSIZE >= ODP_CPUMASK_SIZE, - "ODP_CPUMASK_SIZE__SIZE_ERROR"); +ODP_STATIC_ASSERT(CPU_SETSIZE >= ODP_CPUMASK_SIZE, + "ODP_CPUMASK_SIZE__SIZE_ERROR"); void odp_cpumask_from_str(odp_cpumask_t *mask, const char *str_in) { diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 14a1197..0595e70 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -45,8 +45,8 @@ odp_thrmask_t sched_mask_all; /* Mask of queues per priority */ typedef uint8_t pri_mask_t; -_ODP_STATIC_ASSERT((8*sizeof(pri_mask_t)) >= QUEUES_PER_PRIO, - "pri_mask_t_is_too_small"); +ODP_STATIC_ASSERT((8 * sizeof(pri_mask_t)) >= QUEUES_PER_PRIO, + "pri_mask_t_is_too_small"); /* Internal: Start of named groups in group mask arrays */ #define _ODP_SCHED_GROUP_NAMED (ODP_SCHED_GROUP_CONTROL + 1) diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 6364105..0beff37 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -28,8 +28,8 @@ #include #include -_ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, - "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); +ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, + "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); typedef struct { char name[ODP_SHM_NAME_LEN]; diff --git a/platform/linux-generic/odp_timer.c b/platform/linux-generic/odp_timer.c index ac72709..f4fb1f6 100644 --- a/platform/linux-generic/odp_timer.c +++ b/platform/linux-generic/odp_timer.c @@ -107,7 +107,7 @@ ODP_ALIGNED(16) /* 16-byte atomic operations need properly aligned addresses */ #endif ; -_ODP_STATIC_ASSERT(sizeof(tick_buf_t) == 16, "sizeof(tick_buf_t) == 16"); +ODP_STATIC_ASSERT(sizeof(tick_buf_t) == 16, "sizeof(tick_buf_t) == 16"); typedef struct odp_timer_s { void *user_ptr; diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c index ad8dc55..18fa5c6 100644 --- a/platform/linux-generic/pktio/ipc.c +++ b/platform/linux-generic/pktio/ipc.c @@ -396,8 +396,8 @@ static int ipc_pktio_open(odp_pktio_t id ODP_UNUSED, int ret = -1; int slave; - _ODP_STATIC_ASSERT(ODP_POOL_NAME_LEN == _RING_NAMESIZE, - "mismatch pool and ring name arrays"); + ODP_STATIC_ASSERT(ODP_POOL_NAME_LEN == _RING_NAMESIZE, + "mismatch pool and ring name arrays"); if (strncmp(dev, "ipc", 3)) return -1;