From patchwork Wed May 25 17:12:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111841 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 A78E8A0555; Wed, 25 May 2022 19:12:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D63CB4113D; Wed, 25 May 2022 19:12:37 +0200 (CEST) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTP id 8D14C400EF for ; Wed, 25 May 2022 19:12:36 +0200 (CEST) Received: by mail-pj1-f52.google.com with SMTP id pq9-20020a17090b3d8900b001df622bf81dso5690627pjb.3 for ; Wed, 25 May 2022 10:12:36 -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=Tygx89Zhqtg6Bhg8l7jVAKmZEg/X3T+sUwkuOfRrSkQ=; b=neON6zVKr9WgjWkcomR1Z9TY32IgXJHvrpxt1EvJzQgEunlqGg0sExfEzk4P3cwQ3K 5J+zUcwOVgdg0v9RQPYL0UMNdDHUsIi5YVXG6BcZB2Ar1oOr0QUAv//bqKhef8C7K7gU FUFDX4BOQT9p9RdzdjcPXCb59SBAuFDK2/YcZ3gUN3WN4liDII2awl7mRHEEyJszqc4N lD0PHWpjJU1XXFD7714uPFW6Xnu9u43/JLGA54CIZZy6ouDgNmKLoO0kDdGYO4yxc6du 44Ny1waObqyEL7byuGwdSaeNbtyouyV9o97J+A78an12J+vny0/Rd7sx+6w+P1fd+JRu yx/A== 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=Tygx89Zhqtg6Bhg8l7jVAKmZEg/X3T+sUwkuOfRrSkQ=; b=EWo0tRbt/3N9+geiue5Hdbe5xTyFPe3RqG52sU9dUtwoigZTHior35gk4rcjv5/RbY gVw9p8T2YM/X8Zlc3q7v5T0ehoWj2jzoZm+INg4xU4ExZufHakR0wxg4gXsauftvCtW1 vs4whLMWaDkBXTiP/xussPnVXyV0IREy3ETlZ3JUTpH6n7YZPGRG5x8/FdlRtJQYBMd9 0/YSi24TGWvQ3eVO/I/DfCfS9kFMLWBhz4DZ4kwXwPaibETVt8WIUKw8sTdaGIFKV4IS LWJn3h9GWRVK73dPtAfoZA7s9d0V7nrw6CQn9Oqyreo3HsedcOzQUgxGRiWynkzUN0YS YMlA== X-Gm-Message-State: AOAM5300q5gKxF+xZ5MlcalSHVLXy719PPjLRTozUaZ1JpvPLzKhgj5C NWgoaIEZlL4n0uJdbBMaExtM4ST2bj10fw== X-Google-Smtp-Source: ABdhPJxp5MmWssaUPDjDa5L+a0TW3kUhhZ+fFypez3IGEu/cCnqoiIEwKQNLitDORUJL9kDgDk2J6A== X-Received: by 2002:a17:90a:68c7:b0:1e0:a8b9:a85e with SMTP id q7-20020a17090a68c700b001e0a8b9a85emr4886389pjj.134.1653498755513; Wed, 25 May 2022 10:12:35 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id s23-20020a170902b19700b001622c377c3esm6139599plr.117.2022.05.25.10.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 10:12:34 -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: [PATCH v3 1/3] random: add rte_drand() funciton Date: Wed, 25 May 2022 10:12:28 -0700 Message-Id: <20220525171231.200035-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220525171231.200035-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220525171231.200035-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 drand() 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 | 24 ++++++++++++++++++++++++ lib/eal/include/rte_random.h | 18 ++++++++++++++++++ lib/eal/version.map | 1 + 5 files changed, 55 insertions(+) diff --git a/app/test/test_rand_perf.c b/app/test/test_rand_perf.c index fe797ebfa1ca..26fb1d9a586e 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_drand()]"; 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 += 1000. * rte_drand(); + 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_drand()`` 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..a30bb104015b 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,29 @@ rte_rand_max(uint64_t upper_bound) return res; } +double +rte_drand(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 + * This uses direct access to IEEE format to avoid doing + * any direct floating point math here. + */ + val = __rte_rand_lfsr258(state); + u.ieee.mantissa0 = val >> 32; + u.ieee.mantissa1 = 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..f6541c2b0f08 100644 --- a/lib/eal/include/rte_random.h +++ b/lib/eal/include/rte_random.h @@ -65,6 +65,24 @@ 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-precision floating random + * number uniformly distributed over the interval [0.0, 1.0). + * + * The generator is not cryptographically secure. + * If called from lcore threads, this function is thread-safe. + * + * @return + * A pseudo-random value between 0 and 1.0. + */ +__rte_experimental +double rte_drand(void); + #ifdef __cplusplus } #endif diff --git a/lib/eal/version.map b/lib/eal/version.map index d49e30bd042f..cfbade9a33e9 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_drand; rte_thread_get_affinity_by_id; rte_thread_self; rte_thread_set_affinity_by_id; From patchwork Wed May 25 17:12:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111842 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 1DD54A0555; Wed, 25 May 2022 19:12:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EAA2041133; Wed, 25 May 2022 19:12:39 +0200 (CEST) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mails.dpdk.org (Postfix) with ESMTP id 4566442670 for ; Wed, 25 May 2022 19:12:38 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id h186so19396366pgc.3 for ; Wed, 25 May 2022 10:12:38 -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=J9DaLWmcVol7QtevyyiH8DedyYubJituluZuya9NGfjCq6pnykg0Nmjy6hrCdQYXWo 8gBZjQ3lTiAnkrr5KSRO3HasqQwly71gMZbEhRXRcBrcr8+MxHClFdKu9tXLk24sT6H5 XNDnJJUmFRNwUGFZAFEZlVro7w2PszQxZ9/ugBOUQ+XMm9oHiVaIePgHCOY3Iq/ndVbg hy/KqnDICzGKoLOIvKjwi0rKcOPNeXivfb0Zz8PkojitKkZLo5R49JFk21PGj+QThMsJ I+NZvLYFty4M9gnyOq1fdum1zKOhuKYHl9QPzOLb60rS2BScClo7shfWLXlWW0UdzCG7 CITA== 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=spfmI3lAQYPgaoUApG+b5afZNotiXtrX0XJzzQsJvYz6i59SZtypPmfjJVhnYms85o KYUQ6bvDTehpKiRWl1am/rG/NiHc4mBvpMVlcLTfhe+C+dI/bV2fF6/VFtPKY20uW1ME ZNtmdhDUgmMcDRrStlBSeqJ3+NHH8qBvGI3KTG4ob+4QYqmIciJQQyGWLgrODLKIXzSR hUzAQBpaCubPz5EAwB1r54NQDzOor30snhJGkQuEvYQulSaXfO2K4rfmPA0tG1jut4r5 ug870GkyU3QGwopCjEZsowVpmARW0S2wF+qOQRzmLHQR5X/EauJ1lE7iv/ZRkRZMHQ6A c/kA== X-Gm-Message-State: AOAM530YxbcZYwGlyspfh+X99eRi8vrLWdlSSH0njehIgMc867wUTRzj ZFMGIao9EdpUo+/JHrYfOUmYd5Bvj4R3+A== X-Google-Smtp-Source: ABdhPJyjIBK2DEhWJ0HYcLhDU9kYFiHyloPakYxziZOa/pKCj+bgvVAqBo+54VA5quMui4ap8cWCdw== X-Received: by 2002:a63:f913:0:b0:3fa:2b27:bb82 with SMTP id h19-20020a63f913000000b003fa2b27bb82mr16203936pgi.213.1653498757241; Wed, 25 May 2022 10:12:37 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id s23-20020a170902b19700b001622c377c3esm6139599plr.117.2022.05.25.10.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 10:12:36 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , wojciechx.liguzinski@intel.com, Cristian Dumitrescu , Jasvinder Singh Subject: [PATCH v3 2/3] rte_pie: remove unnecessary floating point Date: Wed, 25 May 2022 10:12:29 -0700 Message-Id: <20220525171231.200035-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220525171231.200035-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220525171231.200035-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 Wed May 25 17:12:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111843 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 05C27A0555; Wed, 25 May 2022 19:12:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D827E427F9; Wed, 25 May 2022 19:12:41 +0200 (CEST) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mails.dpdk.org (Postfix) with ESMTP id F18DF427F9 for ; Wed, 25 May 2022 19:12:40 +0200 (CEST) Received: by mail-pj1-f46.google.com with SMTP id x2-20020a17090a1f8200b001e07a64c461so2196174pja.4 for ; Wed, 25 May 2022 10:12:40 -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=6EbH89RIQ9T1r4Bv5a9z0U19T6cYdGe3OiQ5CK+/Phs=; b=RCr+gEb0vfpV5pjkDg5f9YBK0axPKMsiDyrxPbqPZzZc/3E6w5rTusI3yO0pK+j+Y5 q+qiZLMBgyF4Nx/zTqRAZiHopkB+khOwXx1NfMi+SD2ny/YlPvj8sTxKaTQdaHZA9exe Z3LOcUgsO/4Nuj/CXw6TNYxpNSzOGjxeHavwHF3rPDojhZ0MRI5SGx6/kTsDfLoaDHUG IDf5DRunlLzLXZYWkcvTEjB+lJSjUwiWB/qBn3F+1+QOeYBZfFryIu5WiGdD39ZXA/Pl wFtApy14eHwuhkatAjF5nkiT/YU4Ub6PUuYcnPZrlhsIvohHtllSrgC8W7Q+/JeieMq1 37YA== 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=6EbH89RIQ9T1r4Bv5a9z0U19T6cYdGe3OiQ5CK+/Phs=; b=ZdPMGG1LHPA2l983gLkTYliCWmPCfGVZEVgrDmWPgPTbM+sD6jM7v/P8pdOpi3c2G1 7tfMZlvAxgPRbfekuR27MXW0dcG8Ge6Ae55tiNKtXKwJ+m1UZYGe6QRRbIZKcO0cdP21 bstOZrtPyjToPhy2cikH0g4V1YDpScYPOgYipHdT+rB4Mk8h2/+bRwzpK9kIcmaMHjOz xJCB/KPV3HngxDQlXXcudyyy+IOSDFzqjGQkblFfIN9AW7+zX+fFS0ojW06XVEVzF9Us P3sJm3SJ7UjTyQ6V9HHq0ARszZFsimZRJ2YO/6U3l4BjHEECaVNn7mDBIgI8gw05nXQk 7ZBA== X-Gm-Message-State: AOAM532uqGMqUcQecJRKxicEtjK+xC2+5MW8W3dZZ/N2XNcBUVK0+Aem lPZJz5AM5+ffX72UgujM1UTTfV33L3W9cg== X-Google-Smtp-Source: ABdhPJzZzoJ+E7NkkZeeViJJ2+SMaYAtgtOgWLdWF7CMxZCUvINbrhIxAMpsXEnTRPz8qHg+omJfuQ== X-Received: by 2002:a17:90a:a096:b0:1df:58d7:5b20 with SMTP id r22-20020a17090aa09600b001df58d75b20mr11462435pjp.212.1653498758772; Wed, 25 May 2022 10:12:38 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id s23-20020a170902b19700b001622c377c3esm6139599plr.117.2022.05.25.10.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 10:12:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , wojciechx.liguzinski@intel.com, Cristian Dumitrescu , Jasvinder Singh Subject: [PATCH v3 3/3] rte_pie: fix incorrect floating point math Date: Wed, 25 May 2022 10:12:30 -0700 Message-Id: <20220525171231.200035-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220525171231.200035-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220525171231.200035-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_drand() 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..528f2ea878e8 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_drand() < pie->drop_prob) { pie->accu_prob = 0; return 1; }