From patchwork Tue Dec 11 17:57:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 48652 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 29C397D05; Tue, 11 Dec 2018 18:57:35 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 6041E5F72 for ; Tue, 11 Dec 2018 18:57:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 09:57:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="129035923" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 11 Dec 2018 09:57:30 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBBHvSr7014318; Tue, 11 Dec 2018 17:57:28 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBBHvSOj024641; Tue, 11 Dec 2018 17:57:28 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBBHvEd2024407; Tue, 11 Dec 2018 17:57:14 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: Neil Horman , John McNamara , Marko Kovacevic , Cristian Dumitrescu , thomas@monjalon.net, jasvinder.singh@intel.com, jerin.jacob@caviumnetworks.com Date: Tue, 11 Dec 2018 17:57:09 +0000 Message-Id: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH 1/6] bitmap: remove deprecated bsf64 function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The function rte_bsf64 was deprecated in a previous release, so remove the function, and the deprecation notice associated with it. Signed-off-by: Anatoly Burakov --- doc/guides/rel_notes/deprecation.rst | 5 ----- doc/guides/rel_notes/release_19_02.rst | 4 ++++ lib/librte_eal/common/include/rte_bitmap.h | 6 ------ 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index b48486d36..aa96d9b19 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -20,11 +20,6 @@ Deprecation Notices * kvargs: The function ``rte_kvargs_process`` will get a new parameter for returning key match count. It will ease handling of no-match case. -* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to - ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function - will be added in the next release in ``rte_common.h`` that follows convention - set by existing ``rte_bsf32`` function. - * eal: both declaring and identifying devices will be streamlined in v18.11. New functions will appear to query a specific port from buses, classes of device and device drivers. Device declaration will be made coherent with the diff --git a/doc/guides/rel_notes/release_19_02.rst b/doc/guides/rel_notes/release_19_02.rst index a94fa86a7..ff81357d4 100644 --- a/doc/guides/rel_notes/release_19_02.rst +++ b/doc/guides/rel_notes/release_19_02.rst @@ -84,6 +84,10 @@ API Changes ========================================================= +* eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to + ``rte_bsf64_safe`` and moved to ``rte_common.h``. + + ABI Changes ----------- diff --git a/lib/librte_eal/common/include/rte_bitmap.h b/lib/librte_eal/common/include/rte_bitmap.h index 77727c828..6b846f251 100644 --- a/lib/librte_eal/common/include/rte_bitmap.h +++ b/lib/librte_eal/common/include/rte_bitmap.h @@ -93,12 +93,6 @@ __rte_bitmap_index2_set(struct rte_bitmap *bmp) bmp->index2 = (((bmp->index1 << RTE_BITMAP_SLAB_BIT_SIZE_LOG2) + bmp->offset1) << RTE_BITMAP_CL_SLAB_SIZE_LOG2); } -static inline int __rte_deprecated -rte_bsf64(uint64_t slab, uint32_t *pos) -{ - return rte_bsf64_safe(slab, pos); -} - static inline uint32_t __rte_bitmap_get_memory_footprint(uint32_t n_bits, uint32_t *array1_byte_offset, uint32_t *array1_slabs, From patchwork Tue Dec 11 17:57:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 48654 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1F4651B113; Tue, 11 Dec 2018 18:57:39 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 9CC85683E for ; Tue, 11 Dec 2018 18:57:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 09:57:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="97933895" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga007.jf.intel.com with ESMTP; 11 Dec 2018 09:57:29 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBBHvTN1014321; Tue, 11 Dec 2018 17:57:29 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBBHvTSa024648; Tue, 11 Dec 2018 17:57:29 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBBHvS8K024644; Tue, 11 Dec 2018 17:57:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: John McNamara , Marko Kovacevic , thomas@monjalon.net, jasvinder.singh@intel.com, cristian.dumitrescu@intel.com, jerin.jacob@caviumnetworks.com Date: Tue, 11 Dec 2018 17:57:10 +0000 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH 2/6] common: add bsf64 function similar to existing bsf32 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement a new rte_bsf64 function that is following convention set by existing rte_bsf32 function. Also, document the change in release notes. Signed-off-by: Anatoly Burakov --- doc/guides/rel_notes/release_19_02.rst | 4 +++- lib/librte_eal/common/include/rte_common.h | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/guides/rel_notes/release_19_02.rst b/doc/guides/rel_notes/release_19_02.rst index ff81357d4..1d56ad43e 100644 --- a/doc/guides/rel_notes/release_19_02.rst +++ b/doc/guides/rel_notes/release_19_02.rst @@ -85,7 +85,9 @@ API Changes * eal: function ``rte_bsf64`` in ``rte_bitmap.h`` has been renamed to - ``rte_bsf64_safe`` and moved to ``rte_common.h``. + ``rte_bsf64_safe`` and moved to ``rte_common.h``. A new ``rte_bsf64`` function + has been added in ``rte_common.h`` that follows convention set by existing + ``rte_bsf32`` function. ABI Changes diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 66cdf60b2..2735dcca7 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -482,6 +482,23 @@ rte_fls_u32(uint32_t x) return (x == 0) ? 0 : 32 - __builtin_clz(x); } +/** + * Searches the input parameter for the least significant set bit + * (starting from zero). + * If a least significant 1 bit is found, its bit index is returned. + * If the content of the input parameter is zero, then the content of the return + * value is undefined. + * @param v + * input parameter, should not be zero. + * @return + * least significant set bit in the input parameter. + */ +static inline int +rte_bsf64(uint64_t v) +{ + return (uint32_t)__builtin_ctzll(v); +} + /** * Searches the input parameter for the least significant set bit * (starting from zero). Safe version (checks for input parameter being zero). @@ -502,7 +519,7 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos) if (v == 0) return 0; - *pos = __builtin_ctzll(v); + *pos = rte_bsf64(v); return 1; } From patchwork Tue Dec 11 17:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 48653 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E66CA1B107; Tue, 11 Dec 2018 18:57:37 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id A6F926904 for ; Tue, 11 Dec 2018 18:57:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 09:57:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="282756745" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga005.jf.intel.com with ESMTP; 11 Dec 2018 09:57:30 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBBHvTYX014324; Tue, 11 Dec 2018 17:57:29 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBBHvTga024655; Tue, 11 Dec 2018 17:57:29 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBBHvTmO024651; Tue, 11 Dec 2018 17:57:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, jasvinder.singh@intel.com, cristian.dumitrescu@intel.com, jerin.jacob@caviumnetworks.com Date: Tue, 11 Dec 2018 17:57:11 +0000 Message-Id: X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH 3/6] common: add missing implementations X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement missing functions for 32-bit safe bsf, as well as 64-bit fls and log2. Signed-off-by: Anatoly Burakov --- Notes: v4: - Fixed to use proper rte_bsf64 v3: - Added clarification that pos is not checked lib/librte_eal/common/include/rte_common.h | 62 +++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 2735dcca7..4bbfef7a0 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -447,6 +447,30 @@ rte_bsf32(uint32_t v) return (uint32_t)__builtin_ctz(v); } +/** + * Searches the input parameter for the least significant set bit + * (starting from zero). Safe version (checks for input parameter being zero). + * + * @warning ``pos`` must be a valid pointer. It is not checked! + * + * @param v + * The input parameter. + * @param pos + * If ``v`` was not 0, this value will contain position of least significant + * bit within the input parameter. + * @return + * Returns 0 if ``v`` was 0, otherwise returns 1. + */ +static inline int +rte_bsf32_safe(uint64_t v, uint32_t *pos) +{ + if (v == 0) + return 0; + + *pos = rte_bsf32(v); + return 1; +} + /** * Return the rounded-up log2 of a integer. * @@ -464,7 +488,6 @@ rte_log2_u32(uint32_t v) return rte_bsf32(v); } - /** * Return the last (most-significant) bit set. * @@ -523,6 +546,43 @@ rte_bsf64_safe(uint64_t v, uint32_t *pos) return 1; } +/** + * Return the last (most-significant) bit set. + * + * @note The last (most significant) bit is at position 64. + * @note rte_fls_u64(0) = 0, rte_fls_u64(1) = 1, + * rte_fls_u64(0x8000000000000000) = 64 + * + * @param x + * The input parameter. + * @return + * The last (most-significant) bit set, or 0 if the input is 0. + */ +static inline int +rte_fls_u64(uint64_t x) +{ + return (x == 0) ? 0 : 64 - __builtin_clzll(x); +} + +/** + * Return the rounded-up log2 of a 64-bit integer. + * + * @param v + * The input parameter. + * @return + * The rounded-up log2 of the input, or 0 if the input is 0. + */ +static inline uint32_t +rte_log2_u64(uint64_t v) +{ + if (v == 0) + return 0; + v = rte_align64pow2(v); + /* we checked for v being 0 already, so no undefined behavior */ + return rte_bsf64(v); +} + + #ifndef offsetof /** Return the offset of a field in a structure. */ #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) From patchwork Tue Dec 11 17:57:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 48651 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6E2476904; Tue, 11 Dec 2018 18:57:33 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 61E326833 for ; Tue, 11 Dec 2018 18:57:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 09:57:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="124972238" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 11 Dec 2018 09:57:30 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBBHvTcj014327; Tue, 11 Dec 2018 17:57:29 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBBHvTfD024662; Tue, 11 Dec 2018 17:57:29 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBBHvThS024658; Tue, 11 Dec 2018 17:57:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, jasvinder.singh@intel.com, cristian.dumitrescu@intel.com, jerin.jacob@caviumnetworks.com Date: Tue, 11 Dec 2018 17:57:12 +0000 Message-Id: <82204e76ebc56b7956d0388777aab03fbc4e343a.1544550999.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH 4/6] memalloc: use library implementation of 64-bit log2 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Remove duplicated code and use library version of 64-bit log2. Signed-off-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c index 784939566..6e6af5b06 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c +++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c @@ -208,28 +208,13 @@ get_file_size(int fd) return st.st_size; } -static inline uint32_t -bsf64(uint64_t v) -{ - return (uint32_t)__builtin_ctzll(v); -} - -static inline uint32_t -log2_u64(uint64_t v) -{ - if (v == 0) - return 0; - v = rte_align64pow2(v); - return bsf64(v); -} - static int pagesz_flags(uint64_t page_sz) { /* as per mmap() manpage, all page sizes are log2 of page size * shifted by MAP_HUGE_SHIFT */ - int log2 = log2_u64(page_sz); + int log2 = rte_log2_u64(page_sz); return log2 << RTE_MAP_HUGE_SHIFT; } From patchwork Tue Dec 11 17:57:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 48656 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9F70F1B11F; Tue, 11 Dec 2018 18:57:41 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 5960F6833 for ; Tue, 11 Dec 2018 18:57:33 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 09:57:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="108734005" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga008.fm.intel.com with ESMTP; 11 Dec 2018 09:57:30 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBBHvTsc014330; Tue, 11 Dec 2018 17:57:29 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBBHvTjW024669; Tue, 11 Dec 2018 17:57:29 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBBHvTtV024665; Tue, 11 Dec 2018 17:57:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: Wenzhuo Lu , Jingjing Wu , Bernard Iremonger , thomas@monjalon.net, jasvinder.singh@intel.com, cristian.dumitrescu@intel.com, jerin.jacob@caviumnetworks.com Date: Tue, 11 Dec 2018 17:57:13 +0000 Message-Id: <723491152c80082b01ca2f6fb44cd1cf66968047.1544550999.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH 5/6] testpmd: use library implementation of 64-bit log2 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Remove duplicated code and use library version of 64-bit log2. Signed-off-by: Anatoly Burakov Acked-by: Bernard Iremonger --- app/test-pmd/testpmd.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 4c75587d0..0c75e123b 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -649,28 +649,13 @@ calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out) return 0; } -static inline uint32_t -bsf64(uint64_t v) -{ - return (uint32_t)__builtin_ctzll(v); -} - -static inline uint32_t -log2_u64(uint64_t v) -{ - if (v == 0) - return 0; - v = rte_align64pow2(v); - return bsf64(v); -} - static int pagesz_flags(uint64_t page_sz) { /* as per mmap() manpage, all page sizes are log2 of page size * shifted by MAP_HUGE_SHIFT */ - int log2 = log2_u64(page_sz); + int log2 = rte_log2_u64(page_sz); return (log2 << HUGE_SHIFT); } From patchwork Tue Dec 11 17:57:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Burakov, Anatoly" X-Patchwork-Id: 48655 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 724041B118; Tue, 11 Dec 2018 18:57:40 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 1C8455F72 for ; Tue, 11 Dec 2018 18:57:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 09:57:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="258636221" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 11 Dec 2018 09:57:30 -0800 Received: from sivswdev05.ir.intel.com (sivswdev05.ir.intel.com [10.243.17.64]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id wBBHvU1l014333; Tue, 11 Dec 2018 17:57:30 GMT Received: from sivswdev05.ir.intel.com (localhost [127.0.0.1]) by sivswdev05.ir.intel.com with ESMTP id wBBHvU0W024680; Tue, 11 Dec 2018 17:57:30 GMT Received: (from aburakov@localhost) by sivswdev05.ir.intel.com with LOCAL id wBBHvTCR024672; Tue, 11 Dec 2018 17:57:29 GMT From: Anatoly Burakov To: dev@dpdk.org Cc: thomas@monjalon.net, jasvinder.singh@intel.com, cristian.dumitrescu@intel.com, jerin.jacob@caviumnetworks.com Date: Tue, 11 Dec 2018 17:57:14 +0000 Message-Id: <271055f8b29eafbf0638fcf63e3eac9ef323bc1e.1544550999.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> In-Reply-To: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> References: <1cf22c82b6ca7561966be674afb8a02add0913b9.1544550999.git.anatoly.burakov@intel.com> Subject: [dpdk-dev] [PATCH 6/6] test/common: extend autotest to newly added functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a new autotest for bsf32, bsf64, bsf32_safe and bsf64_safe functions, and extend existing fls and log2 autotests to also cover 64-bit versions. Signed-off-by: Anatoly Burakov --- test/test/test_common.c | 82 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/test/test/test_common.c b/test/test/test_common.c index c6d17baae..94d367471 100644 --- a/test/test/test_common.c +++ b/test/test/test_common.c @@ -50,12 +50,48 @@ test_macros(int __rte_unused unused_parm) return 0; } +static int +test_bsf(void) +{ + uint32_t shift, pos; + + /* safe versions should be able to handle 0 */ + if (rte_bsf32_safe(0, &pos) != 0) + FAIL("rte_bsf32_safe"); + if (rte_bsf64_safe(0, &pos) != 0) + FAIL("rte_bsf64_safe"); + + for (shift = 0; shift < 63; shift++) { + uint32_t val32; + uint64_t val64; + + val64 = 1ULL << shift; + if ((uint32_t)rte_bsf64(val64) != shift) + FAIL("rte_bsf64"); + if (rte_bsf64_safe(val64, &pos) != 1) + FAIL("rte_bsf64_safe"); + if (pos != shift) + FAIL("rte_bsf64_safe"); + + if (shift > 31) + continue; + + val32 = 1U << shift; + if ((uint32_t)rte_bsf32(val32) != shift) + FAIL("rte_bsf32"); + if (rte_bsf32_safe(val32, &pos) != 1) + FAIL("rte_bsf32_safe"); + if (pos != shift) + FAIL("rte_bsf32_safe"); + } + + return 0; +} + static int test_misc(void) { char memdump[] = "memdump_test"; - if (rte_bsf32(129)) - FAIL("rte_bsf32"); rte_memdump(stdout, "test", memdump, sizeof(memdump)); rte_hexdump(stdout, "test", memdump, sizeof(memdump)); @@ -177,13 +213,31 @@ test_log2(void) const uint32_t step = 1; for (i = 0; i < max; i = i + step) { + uint64_t i64; + + /* extend range for 64-bit */ + i64 = (uint64_t)i << 32; + base = (uint32_t)ceilf(log2(i64)); + compare = rte_log2_u64(i64); + if (base != compare) { + printf("Wrong rte_log2_u64(%" PRIx64 ") val %x, expected %x\n", + i64, compare, base); + return TEST_FAILED; + } + base = (uint32_t)ceilf(log2((uint32_t)i)); - compare = rte_log2_u32(i); + compare = rte_log2_u32((uint32_t)i); if (base != compare) { printf("Wrong rte_log2_u32(%x) val %x, expected %x\n", i, compare, base); return TEST_FAILED; } + compare = rte_log2_u64((uint64_t)i); + if (base != compare) { + printf("Wrong rte_log2_u64(%x) val %x, expected %x\n", + i, compare, base); + return TEST_FAILED; + } } return 0; } @@ -206,6 +260,8 @@ test_fls(void) }; for (i = 0; i < RTE_DIM(test); i++) { + uint64_t arg64; + arg = test[i].arg; rc = rte_fls_u32(arg); expected = test[i].rc; @@ -214,6 +270,25 @@ test_fls(void) arg, rc, expected); return TEST_FAILED; } + /* 64-bit version */ + arg = test[i].arg; + rc = rte_fls_u64(arg); + expected = test[i].rc; + if (rc != expected) { + printf("Wrong rte_fls_u64(0x%x) rc=%d, expected=%d\n", + arg, rc, expected); + return TEST_FAILED; + } + /* 64-bit version shifted by 32 bits */ + arg64 = (uint64_t)test[i].arg << 32; + rc = rte_fls_u64(arg64); + /* don't shift zero */ + expected = test[i].rc == 0 ? 0 : test[i].rc + 32; + if (rc != expected) { + printf("Wrong rte_fls_u64(0x%" PRIx64 ") rc=%d, expected=%d\n", + arg64, rc, expected); + return TEST_FAILED; + } } return 0; @@ -226,6 +301,7 @@ test_common(void) ret |= test_align(); ret |= test_macros(0); ret |= test_misc(); + ret |= test_bsf(); ret |= test_log2(); ret |= test_fls();