From patchwork Wed Feb 7 18:00:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 127203 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp710977ljc; Wed, 7 Feb 2018 10:00:40 -0800 (PST) X-Google-Smtp-Source: AH8x227pBE2zBv642GmpU8llQ387RedgJzVgZCuz3TTAQ5nqZbHSMa7cYcg7bsIsQ2nNM085kps5 X-Received: by 10.37.196.68 with SMTP id u65mr4741382ybf.487.1518026440664; Wed, 07 Feb 2018 10:00:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518026440; cv=none; d=google.com; s=arc-20160816; b=eKe345dsDY16MmVXcZjqONnYZUQC9ZgQn9gcWP3+rzRI+5hLucjGIyOofFKuNn0s7C SDh2WEZBQL+FxhhUETL8ebH4V975Eqdp/KahOMoGvtNwbuIhRW2ITi7bda/TNq9VpBu2 aPKGnSn/OtVMlqRyZJ+pt//ZrWfj/ayZUCUksktsdc+ruBCGD2KYxl6UK8op8DiueyRL vpWCAthRq+QjVMFyGa6pJh2ElA7ODXWIlKxXQI9kGtMfXfXmXOqS4wJQPNOJvlbcYowU umxhw8rSKDsKkPcE4qTS/nD7KBR6zmv3oePstBCvO0F5qXryJjHp1IgUTQilmQFBSmZW 4K6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=m0pldb8rlagfU/fpFiCIMXGcvQu0CDYBAIT7R55F65o=; b=XsmfipgBKGCipr3X5mqSKIZeEsiOATG+7GOEisGXWJI5sWYeGAFT9p/N/Z0vMH7bpz 8HNAk6rQlSuCRUkQFfbCBkrq5ugGktDmyXfsqi9gMlM5+xka5EWgHCkguDjcg5qD4CHn 0jnmE6Fw4XayBnYr4mdrBf00YWdQ0RFnMIoCkHRFDGFzYftne/KS3OtwpObtiD1dvqub cTT/2WTbUyV9+IlguPF7azzMXe2BL9U8oUxqKqG/zktWI+OzZ3gb28QEQQBlsChba+No 0GvuqalJ8VLmoXUyOyz5+f8TTm1pnc8aDxGdehr9Adgp3WS8FtrmntjOfvYYldJI56Ex OjHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id t5si1940895qtn.185.2018.02.07.10.00.39; Wed, 07 Feb 2018 10:00:40 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 66E4B61750; Wed, 7 Feb 2018 18:00:39 +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,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 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 5939D60855; Wed, 7 Feb 2018 18:00:26 +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 ACD0D6176F; Wed, 7 Feb 2018 18:00:18 +0000 (UTC) Received: from forward101o.mail.yandex.net (forward101o.mail.yandex.net [37.140.190.181]) by lists.linaro.org (Postfix) with ESMTPS id 58A57627D0 for ; Wed, 7 Feb 2018 18:00:12 +0000 (UTC) Received: from mxback8j.mail.yandex.net (mxback8j.mail.yandex.net [IPv6:2a02:6b8:0:1619::111]) by forward101o.mail.yandex.net (Yandex) with ESMTP id B5EBF1345951 for ; Wed, 7 Feb 2018 21:00:10 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback8j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id eLvaTtksgt-0AdOk09I; Wed, 07 Feb 2018 21:00:10 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 1cUE6Z0aqT-0AVKbS6F; Wed, 07 Feb 2018 21:00:10 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Wed, 7 Feb 2018 21:00:09 +0300 Message-Id: <1518026409-2373-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518026409-2373-1-git-send-email-odpbot@yandex.ru> References: <1518026409-2373-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 452 Subject: [lng-odp] [PATCH v5 1/1] linux-gen: move common macros to odp_macros_internal.h 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Mykyta Iziumtsev Gather macros needed for upcoming mediated devices in one location. Fix signed vs. unsigned comparisons caused by incorrect MIN / MAX usage. Signed-off-by: Mykyta Iziumtsev Reviewed-by: Bill Fischofer --- /** Email created from pull request 452 (MykytaI:master_min_max) ** https://github.com/Linaro/odp/pull/452 ** Patch: https://github.com/Linaro/odp/pull/452.patch ** Base sha: 257b08b35ceea41bad5a7f1c626496cf111e657a ** Merge commit sha: 493451a7409264238934415c24cdb54f268f4b70 **/ platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp_bitmap_internal.h | 4 +- .../linux-generic/include/odp_macros_internal.h | 54 ++++++++++++++++++++++ .../include/odp_traffic_mngr_internal.h | 3 -- platform/linux-generic/odp_name_table.c | 15 +++--- platform/linux-generic/odp_pkt_queue.c | 8 ++-- platform/linux-generic/odp_timer_wheel.c | 3 +- platform/linux-generic/odp_traffic_mngr.c | 13 ++++-- 8 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 platform/linux-generic/include/odp_macros_internal.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 1c2b625cb..9e82f2622 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -101,6 +101,7 @@ noinst_HEADERS = \ include/odp_internal.h \ include/odp_ipsec_internal.h \ include/odp_llqueue.h \ + include/odp_macros_internal.h \ include/odp_name_table_internal.h \ include/odp_packet_internal.h \ include/odp_packet_io_internal.h \ diff --git a/platform/linux-generic/include/odp_bitmap_internal.h b/platform/linux-generic/include/odp_bitmap_internal.h index 1be4d0287..bd0b15d70 100644 --- a/platform/linux-generic/include/odp_bitmap_internal.h +++ b/platform/linux-generic/include/odp_bitmap_internal.h @@ -21,14 +21,12 @@ extern "C" { #include #include #include +#include /* Generate unique identifier for instantiated class */ #define TOKENIZE(template, line) \ template ## _ ## line ## _ ## __COUNTER__ -/* Array size in general */ -#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) - #define BITS_PER_BYTE (8) #define BITS_PER_LONG __WORDSIZE #define BYTES_PER_LONG (BITS_PER_LONG / BITS_PER_BYTE) diff --git a/platform/linux-generic/include/odp_macros_internal.h b/platform/linux-generic/include/odp_macros_internal.h new file mode 100644 index 000000000..357572757 --- /dev/null +++ b/platform/linux-generic/include/odp_macros_internal.h @@ -0,0 +1,54 @@ +/* Copyright (c) 2018, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP miscellaneous macros + */ + +#ifndef ODP_MACROS_INTERNAL_H_ +#define ODP_MACROS_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#define MIN(a, b) \ + ({ \ + __typeof__(a) tmp_a = (a); \ + __typeof__(b) tmp_b = (b); \ + tmp_a < tmp_b ? tmp_a : tmp_b; \ + }) + +#define MAX(a, b) \ + ({ \ + __typeof__(a) tmp_a = (a); \ + __typeof__(b) tmp_b = (b); \ + tmp_a > tmp_b ? tmp_a : tmp_b; \ + }) + +#define odp_container_of(pointer, type, member) \ + ((type *)(void *)(((char *)pointer) - offsetof(type, member))) + +#define DIV_ROUND_UP(a, b) \ + ({ \ + __typeof__(a) tmp_a = (a); \ + __typeof__(b) tmp_b = (b); \ + ODP_STATIC_ASSERT(__builtin_constant_p(b), ""); \ + ODP_STATIC_ASSERT((((b) - 1) & (b)) == 0, ""); \ + (tmp_a + tmp_b - 1) >> __builtin_ctz(tmp_b); \ + }) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp_traffic_mngr_internal.h b/platform/linux-generic/include/odp_traffic_mngr_internal.h index e8254f5ed..2d1fc5493 100644 --- a/platform/linux-generic/include/odp_traffic_mngr_internal.h +++ b/platform/linux-generic/include/odp_traffic_mngr_internal.h @@ -34,9 +34,6 @@ extern "C" { typedef struct stat file_stat_t; -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - #define INPUT_WORK_RING_SIZE (16 * 1024) #define TM_QUEUE_MAGIC_NUM 0xBABEBABE diff --git a/platform/linux-generic/odp_name_table.c b/platform/linux-generic/odp_name_table.c index e9a84ef32..60af095e5 100644 --- a/platform/linux-generic/odp_name_table.c +++ b/platform/linux-generic/odp_name_table.c @@ -14,9 +14,7 @@ #include #include #include - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#include /* The following constants define some tunable parameters of this module. * They are set to fairly reasonable values (perhaps somewhat biased toward @@ -298,7 +296,7 @@ static int new_name_tbl_add(void) name_tbls_idx = name_tbls.num_name_tbls; num_entries = INITIAL_NAME_TBL_SIZE << name_tbls_idx; new_name_tbl = name_tbl_alloc(name_tbls_idx, num_entries); - name_tbl_free_list_add(new_name_tbl, MIN(num_entries, 256)); + name_tbl_free_list_add(new_name_tbl, MIN(num_entries, UINT32_C(256))); name_tbls.tbls[name_tbls_idx] = new_name_tbl; name_tbls.avail_space_bit_mask |= 1 << name_tbls_idx; @@ -387,7 +385,7 @@ static hash_tbl_entry_t make_hash_tbl_entry(name_tbl_entry_t *name_tbl_entry, hash_tbl_entry_t hash_tbl_entry; uint32_t new_entry_cnt; - new_entry_cnt = MIN(entry_cnt + 1, 0x3F); + new_entry_cnt = MIN(entry_cnt + 1, UINT32_C(0x3F)); hash_tbl_entry = (hash_tbl_entry_t)(uintptr_t)name_tbl_entry; hash_tbl_entry &= ~0x3F; hash_tbl_entry |= new_entry_cnt; @@ -1006,7 +1004,7 @@ static uint32_t level2_hash_histo(secondary_hash_tbl_t *hash_tbl, collisions = linked_list_len(name_tbl_entry); } - level2_histo[MIN(collisions, 256)]++; + level2_histo[MIN(collisions, UINT32_C(256))]++; total_collisions += collisions; } @@ -1038,7 +1036,7 @@ static uint32_t level1_hash_histo(secondary_hash_tbl_t *hash_tbl, level2_histo); } - level1_histo[MIN(collisions, 256)]++; + level1_histo[MIN(collisions, UINT32_C(256))]++; total_collisions += collisions; } @@ -1147,7 +1145,8 @@ void _odp_int_name_tbl_stats_print(void) memset(primary_hash_histo, 0, sizeof(primary_hash_histo)); for (idx = 0; idx < PRIMARY_HASH_TBL_SIZE; idx++) { - collisions = MIN(name_hash_tbl.hash_collisions[idx], 256); + collisions = + MIN(name_hash_tbl.hash_collisions[idx], UINT32_C(256)); primary_hash_histo[collisions]++; } diff --git a/platform/linux-generic/odp_pkt_queue.c b/platform/linux-generic/odp_pkt_queue.c index 172191931..41f0e4df6 100644 --- a/platform/linux-generic/odp_pkt_queue.c +++ b/platform/linux-generic/odp_pkt_queue.c @@ -16,9 +16,7 @@ #include #include #include - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#include #define NUM_PKTS 7 @@ -230,7 +228,7 @@ _odp_int_queue_pool_t _odp_queue_pool_create(uint32_t max_num_queues, /* Initialize the queue_blk_tbl_sizes array based upon the * max_queued_pkts. */ - max_queued_pkts = MAX(max_queued_pkts, 64 * 1024); + max_queued_pkts = MAX(max_queued_pkts, 64 * UINT32_C(1024)); queue_region_desc_init(pool, 0, max_queued_pkts / 4); queue_region_desc_init(pool, 1, max_queued_pkts / 64); queue_region_desc_init(pool, 2, max_queued_pkts / 64); @@ -242,7 +240,7 @@ _odp_int_queue_pool_t _odp_queue_pool_create(uint32_t max_num_queues, /* Now allocate the first queue_blk_tbl and add its blks to the free * list. Replenish the queue_blk_t free list. */ - initial_free_list_size = MIN(64 * 1024, max_queued_pkts / 4); + initial_free_list_size = MIN(64 * UINT32_C(1024), max_queued_pkts / 4); rc = pkt_queue_free_list_add(pool, initial_free_list_size); if (rc < 0) { free(pool->queue_num_tbl); diff --git a/platform/linux-generic/odp_timer_wheel.c b/platform/linux-generic/odp_timer_wheel.c index b37d269bd..ee7b5694c 100644 --- a/platform/linux-generic/odp_timer_wheel.c +++ b/platform/linux-generic/odp_timer_wheel.c @@ -16,6 +16,7 @@ #include #include #include +#include /* The following constants can be changed either at compile time or run time * as long as the following constraints are met (by the way REV stands for @@ -627,7 +628,7 @@ static int timer_current_wheel_update(timer_wheels_t *timer_wheels, slot_idx = wheel_desc->slot_idx; num_slots = wheel_desc->num_slots; max_ticks = wheel_desc->max_ticks; - max_cnt = (uint32_t)MIN(elapsed_ticks, 32); + max_cnt = MIN(elapsed_ticks, UINT32_C(32)); current_wheel = timer_wheels->current_wheel; ret_code = 0; rc = -1; diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c index 03094cc37..5c19b7c17 100644 --- a/platform/linux-generic/odp_traffic_mngr.c +++ b/platform/linux-generic/odp_traffic_mngr.c @@ -28,6 +28,7 @@ #include #include #include +#include /* Local vars */ static const @@ -731,7 +732,8 @@ static uint64_t time_till_not_red(tm_shaper_params_t *shaper_params, commit_delay = (-shaper_obj->commit_cnt) / shaper_params->commit_rate; - min_time_delay = MAX(shaper_obj->shaper_params->min_time_delta, 256); + min_time_delay = + MAX(shaper_obj->shaper_params->min_time_delta, UINT64_C(256)); commit_delay = MAX(commit_delay, min_time_delay); if (shaper_params->peak_rate == 0) return commit_delay; @@ -1670,7 +1672,7 @@ static odp_tm_percent_t tm_queue_fullness(tm_wred_params_t *wred_params, return 0; fullness = (10000 * current_cnt) / max_cnt; - return (odp_tm_percent_t)MIN(fullness, 50000); + return (odp_tm_percent_t)MIN(fullness, UINT64_C(50000)); } static odp_bool_t tm_local_random_drop(tm_system_t *tm_system, @@ -2501,7 +2503,7 @@ static void tm_system_capabilities_set(odp_tm_capabilities_t *cap_ptr, memset(cap_ptr, 0, sizeof(odp_tm_capabilities_t)); max_queues = MIN(req_ptr->max_tm_queues, - ODP_TM_MAX_NUM_TM_NODES); + (uint32_t)ODP_TM_MAX_NUM_TM_NODES); shaper_supported = req_ptr->tm_queue_shaper_needed; wred_supported = req_ptr->tm_queue_wred_needed; dual_slope = req_ptr->tm_queue_dual_slope_needed; @@ -2525,8 +2527,9 @@ static void tm_system_capabilities_set(odp_tm_capabilities_t *cap_ptr, per_level_req = &req_ptr->per_level[level_idx]; max_nodes = MIN(per_level_req->max_num_tm_nodes, - ODP_TM_MAX_NUM_TM_NODES); - max_fanin = MIN(per_level_req->max_fanin_per_node, 1024); + (uint32_t)ODP_TM_MAX_NUM_TM_NODES); + max_fanin = MIN(per_level_req->max_fanin_per_node, + UINT32_C(1024)); max_priority = MIN(per_level_req->max_priority, ODP_TM_MAX_PRIORITIES - 1); min_weight = MAX(per_level_req->min_weight,