From patchwork Tue May 24 22:18:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111758 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7663FA0545; Wed, 25 May 2022 00:18:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 94ECD410FB; Wed, 25 May 2022 00:18:32 +0200 (CEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id F2E73400D6 for ; Wed, 25 May 2022 00:18:28 +0200 (CEST) Received: by mail-pl1-f172.google.com with SMTP id m1so17023343plx.3 for ; Tue, 24 May 2022 15:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cr+nVcu93iTKqmM0WXMa4rnBpBNrgN7TIbVkXze94wM=; b=6Z2DjBiW5MZDReDkd1kGlNE/EhYDM64+pekmMYqtIl9Uf6F8HL/Dm6o1Uq1Chq/UFW RYIEENrAmCaFU2VborLRiYKZ9/OlsrLLfuiU8wh0gvDbkH3c+LfxfL3iQe43qrG+W80K cQ+vU1rWBp5bB/Wx8ExO7uWOEU4SpdaLzXo/eCh7yWoODBbJQNkUUQqs2ujKKTJL/tSt Uew4okU4DlIgjDqVK2WdGWVpz0gSRoFihqhX48tJSnNnPPZtXmf7sPJTEKT0vfp/Q/PS 7s+BJSvCKGalhfgj5pvmHyM/niwSaZbJOwCSKlli+WuQQnqVd7+28FXRIQScWmm4PfaY jL6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cr+nVcu93iTKqmM0WXMa4rnBpBNrgN7TIbVkXze94wM=; b=5RqkqDOfZqzzTmcO/DgsNy7R5CsETwzRNw2awF0UVg5pl+vg49txiU0hUTP6b8PHZG oqxq9OQP3RY7zNo8aUCbMfIMk/h+PorOlHb1Y6Ervkttx5566gGOGlu0QdEfYdzJytIv ITjtCygaF/9XaDBBxAXgmuv01sFnohGRYWTz3o5j67NbkGGFu44ADHosk5XcDMJ6AYNx 4fA9heOrQb4msBFMq4tYoOWf03in7AU2KXhgH/GMML0HmM3HaB+9AzHGUUFnFy8fHSMo MyjXet9pceCjaKFrAMLvbVHnMk8uRpWsLClBJd+Pg98NzTP+etO+Xfu1tjHgIhotpLX6 v51Q== X-Gm-Message-State: AOAM532J0u2ul6KWKGF75Zjrj/qIrp2Ovd1vUAfIVkW5Y8HvPpCV+1Fa TU4ghTn/1oHSP8PBG4acsrOIZac4sj7J8w== X-Google-Smtp-Source: ABdhPJyqNz6/sleKEgTUO+B0I2mB9/aLquvhlWI70WBbpMSrzhuiIy1/zyJvCEgF+TUV6aygwtbxVQ== X-Received: by 2002:a17:903:32cc:b0:161:9539:fd69 with SMTP id i12-20020a17090332cc00b001619539fd69mr29824363plr.153.1653430707909; Tue, 24 May 2022 15:18:27 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id j64-20020a62c543000000b0050dc7628158sm10007121pfg.50.2022.05.24.15.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 15:18:27 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?utf-8?q?Mattias_R?= =?utf-8?q?=C3=B6nnblom?= , Ray Kinsella Subject: [RFT v2 1/3] random: add rte_rand_float() Date: Tue, 24 May 2022 15:18:22 -0700 Message-Id: <20220524221824.1037693-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524221824.1037693-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220524221824.1037693-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The PIE code and other applications can benefit from having a fast way to get a random floating point value. This new function is equivalent to erand48_r in the standard library. Signed-off-by: Stephen Hemminger --- app/test/test_rand_perf.c | 7 +++++++ doc/guides/rel_notes/release_22_07.rst | 5 +++++ lib/eal/common/rte_random.c | 21 +++++++++++++++++++++ lib/eal/include/rte_random.h | 17 +++++++++++++++++ lib/eal/version.map | 1 + 5 files changed, 51 insertions(+) diff --git a/app/test/test_rand_perf.c b/app/test/test_rand_perf.c index fe797ebfa1ca..f3602da5b2d4 100644 --- a/app/test/test_rand_perf.c +++ b/app/test/test_rand_perf.c @@ -20,6 +20,7 @@ static volatile uint64_t vsum; enum rand_type { rand_type_64, + rand_type_float, rand_type_bounded_best_case, rand_type_bounded_worst_case }; @@ -30,6 +31,8 @@ rand_type_desc(enum rand_type rand_type) switch (rand_type) { case rand_type_64: return "Full 64-bit [rte_rand()]"; + case rand_type_float: + return "Floating point [rte_rand_float()]"; case rand_type_bounded_best_case: return "Bounded average best-case [rte_rand_max()]"; case rand_type_bounded_worst_case: @@ -55,6 +58,9 @@ test_rand_perf_type(enum rand_type rand_type) case rand_type_64: sum += rte_rand(); break; + case rand_type_float: + sum += rte_rand_float() * UINT64_MAX; + break; case rand_type_bounded_best_case: sum += rte_rand_max(BEST_CASE_BOUND); break; @@ -83,6 +89,7 @@ test_rand_perf(void) printf("Pseudo-random number generation latencies:\n"); test_rand_perf_type(rand_type_64); + test_rand_perf_type(rand_type_float); test_rand_perf_type(rand_type_bounded_best_case); test_rand_perf_type(rand_type_bounded_worst_case); diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst index e49cacecefd4..128d4fca85b3 100644 --- a/doc/guides/rel_notes/release_22_07.rst +++ b/doc/guides/rel_notes/release_22_07.rst @@ -104,6 +104,11 @@ New Features * ``RTE_EVENT_QUEUE_ATTR_WEIGHT`` * ``RTE_EVENT_QUEUE_ATTR_AFFINITY`` +* ** Added function get random floating point number.** + + Added the function ``rte_rand_float()`` to provide a pseudo-random + floating point number. + Removed Items ------------- diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c index 4535cc980cec..024c3c41dc16 100644 --- a/lib/eal/common/rte_random.c +++ b/lib/eal/common/rte_random.c @@ -6,6 +6,7 @@ #include #endif #include +#include #include #include @@ -173,6 +174,26 @@ rte_rand_max(uint64_t upper_bound) return res; } +double +rte_rand_float(void) +{ + struct rte_rand_state *state = __rte_rand_get_state(); + union ieee754_double u = { + .ieee = { + .negative = 0, + .exponent = IEEE754_DOUBLE_BIAS, + }, + }; + uint64_t val; + + /* Take 64 bit random value and put it into the mantissa */ + val = __rte_rand_lfsr258(state); + u.ieee.mantissa0 = val >> 32; /* only 20 bits used */ + u.ieee.mantissa1 = (uint32_t)val; + + return u.d - 1.0; +} + static uint64_t __rte_random_initial_seed(void) { diff --git a/lib/eal/include/rte_random.h b/lib/eal/include/rte_random.h index 29f5f1325a30..553beb2d9c6f 100644 --- a/lib/eal/include/rte_random.h +++ b/lib/eal/include/rte_random.h @@ -65,6 +65,23 @@ rte_rand(void); uint64_t rte_rand_max(uint64_t upper_bound); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Generates a pseudo-random floating point number. + * + * This function returns a nonnegative double-precison floating random + * number uniformly distributed over the interval [0.0, 1.0). + * + * If called from lcore threads, this function is thread-safe. + * + * @return + * A pseudo-random value between 0 and 1.0. + */ +__rte_experimental +double rte_rand_float(void); + #ifdef __cplusplus } #endif diff --git a/lib/eal/version.map b/lib/eal/version.map index d49e30bd042f..861906af2999 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -422,6 +422,7 @@ EXPERIMENTAL { rte_intr_type_set; # added in 22.07 + rte_rand_float; rte_thread_get_affinity_by_id; rte_thread_self; rte_thread_set_affinity_by_id; From patchwork Tue May 24 22:18:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111759 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 71681A0545; Wed, 25 May 2022 00:18:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 89BEB427EC; Wed, 25 May 2022 00:18:33 +0200 (CEST) Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by mails.dpdk.org (Postfix) with ESMTP id 3A19340C35 for ; Wed, 25 May 2022 00:18:30 +0200 (CEST) Received: by mail-pj1-f53.google.com with SMTP id z11so8221916pjc.3 for ; Tue, 24 May 2022 15:18:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5/3sc9SGpZ9Q/YTgJdFfIYh1zwzoVJ75BgiA+TOIsyk=; b=jsGE3vwUVrJPxbBauOb9nBpHxWNVFIqTXbBAzD+dK8JAPxowzMt4niMSTR++w3DwWN Jr6d7DwgayokfsIi3m9F3JN7+EWMACVDRz+sM7qMys8wC5IjCqWo8cMidjnZyvpobBpu QM7wfDzXLclGKJUCguRHLQGaRwz2wQc31E5hQRtl2Fwnoqnl827nnZylVwbK75ctsFj0 ZXUHD9dFq9c/jLgLyFqey2I0b+QQ8bPW0iXq9yWo+HwBxwRqS7BegNaG2KgfALWSs/sW 6i8NasPmxVHlGJszvzI8VlEJa5vFbb3JGw3ECLHYlqc8rzuwU4p+B8sZjKY71tA0zJgr bGsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5/3sc9SGpZ9Q/YTgJdFfIYh1zwzoVJ75BgiA+TOIsyk=; b=FeFo9kzOgsQAg36zeqXDrfX6cYcfMGElWd9ZrY40sFmQihu3qxt3schsVVQdRYXMbP O6WGUC2lcRaC/D0DXQuFmBkizcxhHu4/u11iwPbbGZVA3+TaR0GdTcx61Nmn7IZE2oyk 5IMWoiS/FD47y13alNk4O0o+MzguYUKIURwuKwjXQLeSxEVDibmYdu1mnMB79OtI84z3 xXU5CPpgqrB/sI+Q93/NdLHbLueaUHrxUuBW6t3nk4UqLIllNpLPWhDphnU+ziduQ1TG 0D0FqF3rmQkdWuqwSI/R1U9vb3zgkWz0kTtQ2WSa9UlQcN4vxTUvAWLNvarQ5LrOCGVb x3ZA== X-Gm-Message-State: AOAM5334+Pr+v5YgiLJdyxbDHoIODT/Xzsg+MqnVAcyEZj52uUaa/qdW N4IoWt0wAKRFc1r84R/bQiTFB0JhKGOWLw== X-Google-Smtp-Source: ABdhPJwZlBur/L6gFInWxIzqOjVSH0wT5H+gfC2lBZRlOdGHNh0oqmNHnvHHRArovF4o+UwT7zxK4A== X-Received: by 2002:a17:902:7c11:b0:162:1122:8a7f with SMTP id x17-20020a1709027c1100b0016211228a7fmr15757210pll.37.1653430709119; Tue, 24 May 2022 15:18:29 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id j64-20020a62c543000000b0050dc7628158sm10007121pfg.50.2022.05.24.15.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 15:18:28 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , wojciechx.liguzinski@intel.com, Cristian Dumitrescu , Jasvinder Singh Subject: [RFT v2 2/3] rte_pie: remove unnecessary floating point Date: Tue, 24 May 2022 15:18:23 -0700 Message-Id: <20220524221824.1037693-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524221824.1037693-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220524221824.1037693-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The qdelay variable is derived from and compared to 64 bit value so it doesn't have to be floating point. Fixes: 44c730b0e379 ("sched: add PIE based congestion management") Cc: wojciechx.liguzinski@intel.com Signed-off-by: Stephen Hemminger --- lib/sched/rte_pie.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sched/rte_pie.h b/lib/sched/rte_pie.h index 02a987f54ad1..3e2c1ef46721 100644 --- a/lib/sched/rte_pie.h +++ b/lib/sched/rte_pie.h @@ -218,7 +218,7 @@ _rte_pie_drop(const struct rte_pie_config *pie_cfg, struct rte_pie *pie) { uint64_t rand_value; - double qdelay = pie_cfg->qdelay_ref * 0.5; + uint64_t qdelay = pie_cfg->qdelay_ref / 2; /* PIE is active but the queue is not congested: return 0 */ if (((pie->qdelay_old < qdelay) && (pie->drop_prob < 0.2)) || From patchwork Tue May 24 22:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111760 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 49226A0545; Wed, 25 May 2022 00:18:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C2E4427F9; Wed, 25 May 2022 00:18:34 +0200 (CEST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 5B8BA40E2D for ; Wed, 25 May 2022 00:18:31 +0200 (CEST) Received: by mail-pj1-f54.google.com with SMTP id fw21-20020a17090b129500b001df9f62edd6so2832806pjb.0 for ; Tue, 24 May 2022 15:18:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K1gatM5F9Uu69n0XVDFQSNbf7MVSyExw7ku4hOjpi4k=; b=J5XAtf5SqxJdPoUaNLvQNy4QJtCULioAZqH1uJ2Z5ZiA1dpGSyYsFsOIBjfSTpU9mh sdYGc1SwtnTaZd8axhYXD6NjzdBgmotJGeozAmjrIfXdPdpZ0DlgtQ95EiitmfWi1nS5 QrsB3Cdl3ME7U7sbFLzuNp9OD8yXFv3ZB4bzhfC4H156nhnlZ4QOAzlTYIbglmml5aki +P+YaGCnz3nM97ZG84h/s4snNxDkhG1cACBhp441i9p3yAlcAkjJ+0NA26WFEmv2dvYl pWAR2v8kxJZg1hRzSkQx7ZAXLaSqZquCJu/d22jq0O6TQNM9Ped6AYMeUFVeSogtZAEn CnQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K1gatM5F9Uu69n0XVDFQSNbf7MVSyExw7ku4hOjpi4k=; b=Yd6YRrOyDanxPlrIHfMdTaD0MHoX8AAv3m5Be4foYVnRYfHv7T55GUHDI1GUWnsoik cNMPg3cZCyZgF1ozokIBTYUt/K9Fe4g0pPUmBIMnGPwhyDMSPj0uUxDlhTjazpNVGui6 6HpKhmE0Bht1a8+osRQbzI01kS0QV82zOIhbx3VOFQKPAJ3m1PfyzFMYLVaLFvL6aZKQ BaU2gFi97s4kA+w9FjV8gobv0b1mL0lGv2g9qlG2hkVaaPN5hV4H8yynNtSylEnX4Rxy rOJCVVZBY82gDZ6r7pQgZs4tvXcMezfEiaNFoh0YB1mHopboHiYbIalDMGpcZrlf14oa VhQA== X-Gm-Message-State: AOAM531PI4PYLLmmoY4FtoHasa0oHF6+ahyNvJMe8HyrmxTfGa6nJCBh GezvRItqAVMDfndbSfDokrM7y/Vke6YTWw== X-Google-Smtp-Source: ABdhPJx4f1gX/4afNWx6PErijbKuQR6Y5EF9ecjppGxTHXd5xu9MdPMHpqDCynlCkpqS8ee7sGy8uA== X-Received: by 2002:a17:90b:3a85:b0:1e0:548:2bf7 with SMTP id om5-20020a17090b3a8500b001e005482bf7mr6787341pjb.55.1653430710223; Tue, 24 May 2022 15:18:30 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id j64-20020a62c543000000b0050dc7628158sm10007121pfg.50.2022.05.24.15.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 15:18:29 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , wojciechx.liguzinski@intel.com, Cristian Dumitrescu , Jasvinder Singh Subject: [RFT v2 3/3] rte_pie: fix incorrect floating point math Date: Tue, 24 May 2022 15:18:24 -0700 Message-Id: <20220524221824.1037693-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524221824.1037693-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220524221824.1037693-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The function rte_pie_drop was attempting to do a random probability drop, but because of incorrect usage of fixed point divide it would always return 1. Change to use new rte_rand_float() instead. Fixes: 44c730b0e379 ("sched: add PIE based congestion management") Cc: wojciechx.liguzinski@intel.com Signed-off-by: Stephen Hemminger --- lib/sched/rte_pie.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/sched/rte_pie.h b/lib/sched/rte_pie.h index 3e2c1ef46721..ed433300c2cf 100644 --- a/lib/sched/rte_pie.h +++ b/lib/sched/rte_pie.h @@ -217,7 +217,6 @@ __rte_experimental _rte_pie_drop(const struct rte_pie_config *pie_cfg, struct rte_pie *pie) { - uint64_t rand_value; uint64_t qdelay = pie_cfg->qdelay_ref / 2; /* PIE is active but the queue is not congested: return 0 */ @@ -240,9 +239,7 @@ _rte_pie_drop(const struct rte_pie_config *pie_cfg, if (pie->accu_prob >= 8.5) return 1; - rand_value = rte_rand()/RTE_RAND_MAX; - - if ((double)rand_value < pie->drop_prob) { + if (rte_rand_float() < pie->drop_prob) { pie->accu_prob = 0; return 1; }