From patchwork Thu May 26 20:26:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111922 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 22B34A0547; Thu, 26 May 2022 22:27:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E4D4427EC; Thu, 26 May 2022 22:27:02 +0200 (CEST) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by mails.dpdk.org (Postfix) with ESMTP id 71FD140DF7 for ; Thu, 26 May 2022 22:26:58 +0200 (CEST) Received: by mail-pf1-f172.google.com with SMTP id x143so2581041pfc.11 for ; Thu, 26 May 2022 13:26:58 -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=HeE7fHxqMA863zxLIscJSWOqklG7gOFE2iJ5Kfe2h7s=; b=4P2it92/N4pJQZnWLrp5dwqD6XE+OAUCqZVgrntkR3sreIt/0ljQY3A3Yp72zhditn 60NXOrHDKfLKr19oSFkKUm44dF6/XuMWXcn2Il8tSRBiZkGbYtIMSSCDKwZT+ZXRpR7E RbK4dZ4L3WmiWnemPdgZyJr8wqKhqB7cX0U90w7XLf1+wWHdN28erClnKtwTCulfLxkm 2XhQk5bd2PsfKYkCmvDGmPdPQLcGPs/DfcbiT/rAad2OZiQ/PNQPx33Vuhf9FS3JYn+B afy3Pa1l+k+4bkIDAtgJZU53K3GUlL1E/569vLtfU6K8nIqkRpKxNsxUL5DFbZ4ANPVH COWg== 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=HeE7fHxqMA863zxLIscJSWOqklG7gOFE2iJ5Kfe2h7s=; b=eeqWNFWsw0jBEwFgkUnizOZ1ARRfk2J9PMT0Wj2YoDwzVLug6B2RSBDQeuwAHmJAL/ lcZa3riD5wTMX/v/5ftyDGAfLN/YzNmbKa4RNmEK3Iv+8+e6AASHVS9IXL+c1grQQbxb 0cNiQgr7jz3F05k8d0zM+Dpc1KLcH2WRlVrSGO7AdRPKLoqspJnsVmEYX7MRrs6jvWDX fcxmrUkQs8K659x+HxS5Jc4u1EhYx+Z6sV04l6md8+SfqmXZb4aDHkF361EcZpin+03K vbWjhRVAoTF6SZweMhFRFnGgHkcDM6kfaNN5cqVGSDL6ZNjkGEZ5iyoLQ87v7CnFQYzP 3XNA== X-Gm-Message-State: AOAM530uFjKGojGtSZJnhe8gS4u8wBywIOhc3X1Y5D4EM2lN9vzuyeQo CgoS3zI5TZydUmOmMIfbjhqhEc9NQG8cjA== X-Google-Smtp-Source: ABdhPJx6qeJEd5px6XHwgN3l8S7yeF44/xq28wpu1k1q6w7MZYnCtWpUwRlRhw9Vqj/NJlGr4K51vQ== X-Received: by 2002:a63:4d2:0:b0:3fa:b0a0:450e with SMTP id 201-20020a6304d2000000b003fab0a0450emr12380899pge.95.1653596817309; Thu, 26 May 2022 13:26:57 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id c20-20020a170902b69400b0015e8d4eb1e5sm2025316pls.47.2022.05.26.13.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 13:26:56 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Ray Kinsella , =?utf-8?q?Mattias_R=C3=B6nnblom?= , Ray Kinsella Subject: [PATCH v5 1/3] random: add rte_drand() function Date: Thu, 26 May 2022 13:26:51 -0700 Message-Id: <20220526202653.99796-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220526202653.99796-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220526202653.99796-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 Acked-by: Ray Kinsella --- app/test/test_rand_perf.c | 7 +++++++ doc/guides/rel_notes/release_22_07.rst | 5 +++++ lib/eal/common/rte_random.c | 19 +++++++++++++++++++ lib/eal/include/rte_random.h | 18 ++++++++++++++++++ lib/eal/version.map | 1 + 5 files changed, 50 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..b131ea577226 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..166b0d8921c9 100644 --- a/lib/eal/common/rte_random.c +++ b/lib/eal/common/rte_random.c @@ -173,6 +173,25 @@ rte_rand_max(uint64_t upper_bound) return res; } +double +rte_drand(void) +{ + static const uint64_t denom = (uint64_t)1 << 53; + uint64_t rand64 = rte_rand(); + + /* + * The double mantissa only has 53 bits, so we uniformly mask off the + * high 11 bits and then floating-point divide by 2^53 to achieve a + * result in [0, 1). + * + * We are not allowed to emit 1.0, so denom must be one greater than + * the possible range of the preceding step. + */ + + rand64 &= denom - 1; + return (double)rand64 / denom; +} + 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 Thu May 26 20:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111923 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 5C210A0547; Thu, 26 May 2022 22:27:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53C3C427F6; Thu, 26 May 2022 22:27:03 +0200 (CEST) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mails.dpdk.org (Postfix) with ESMTP id 8D4FD427EA for ; Thu, 26 May 2022 22:26:59 +0200 (CEST) Received: by mail-pf1-f169.google.com with SMTP id f21so2611740pfa.3 for ; Thu, 26 May 2022 13:26:59 -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=RAzbMDFiIwiPJhzEkWWAkxxdDj6dwlxR+qdCBT14VP0=; b=g8fWd22d9lhdBdoYiveh2b6jxc4/6ls7rF3HsNbCfnrrtbA9nI42kQ+lMuxwCq2T79 hCMh+4Es0Fwa59r16LOFMw3/H967cE16zBK5VLvdJctHOdbJCZOi4K3RNCIFZ7wNeu+Q MIR3jF+995swnMlwnhMwygx+2vFo99IXvD99pLhbPdZoqr9Urdz5PVAqImTz77CljLzF jQuDCNcqrl63N7+Xf8nZ5bo5eCOo/AOPCqQUq9OLV7Pj+UHcgq+ts2Zy5R5HprI6Gof+ q9h2ukMLUgQLne7ulvqT/w2axo90yDnKEqK/UltvI8EwaCy1hJChjVVCrz031aVJgvyi UJ0A== 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=RAzbMDFiIwiPJhzEkWWAkxxdDj6dwlxR+qdCBT14VP0=; b=NxYqYnFxpdyRFSGc5nD9UBj4nAdnJDG1zgw1tySBI5nfDOLbMe3ONabLsP4ZVyvFb0 +ubd93czmpTT/CB91P1lkO1RuON33MJRFLJpLWEV9jzQy0zwR1D8vV+SvHvfPRKTkVck mv0EqzTxyUXSfh5LNhgVx4jFEHplynwTwHEkmA6sutv3DghFtp4hDZYfF8LFaK9LGSs3 IteIpFOV7WEOmSLbiZCesyEsEXWcELe75hQYWMFaC+/am0+1zcESMJCNt0XdVpcd/4av sAXv95WK96ClVU6afY8nTPf5C9v5A6mRxVKacDchWTVGezgfPn9PHOvGPnPmfVp1w0Zb WHuA== X-Gm-Message-State: AOAM530870Rq24oP5o588Wh/KFaRqNvf28fZf5BgAqYmBWbVDrPjNOZU VETDz28S6XLth5XrhFMQVNakFNxDHSfD2w== X-Google-Smtp-Source: ABdhPJzO5VByhVlAbspzlXLYcYcTU7/iPeCQFAoQ9ZaNyo8Cuj6RvRTb6gFa50Moj+C5vIGQFt86cw== X-Received: by 2002:aa7:8dd8:0:b0:518:11:18db with SMTP id j24-20020aa78dd8000000b00518001118dbmr40490815pfr.29.1653596818515; Thu, 26 May 2022 13:26:58 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id c20-20020a170902b69400b0015e8d4eb1e5sm2025316pls.47.2022.05.26.13.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 13:26:57 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Cristian Dumitrescu , Jasvinder Singh , Wojciech Liguzinski Subject: [PATCH v5 2/3] rte_pie: remove unnecessary floating point Date: Thu, 26 May 2022 13:26:52 -0700 Message-Id: <20220526202653.99796-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220526202653.99796-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220526202653.99796-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") Signed-off-by: Stephen Hemminger Acked-by: Jasvinder Singh --- 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 Thu May 26 20:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 111924 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 D3703A0547; Thu, 26 May 2022 22:27:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 35CD24281B; Thu, 26 May 2022 22:27:04 +0200 (CEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id E843A427EA for ; Thu, 26 May 2022 22:27:00 +0200 (CEST) Received: by mail-pf1-f176.google.com with SMTP id b135so2577972pfb.12 for ; Thu, 26 May 2022 13:27:00 -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=dn470I1AAXYIPllkE0iKbl8OtBnx1LYxnn0mwkxAqPY=; b=26mDrDq8AwlTp+mPD8+6Kysic6mo72Linr72U5N0ysfxU9Wy063dz+Lr/DHeu3ivlZ ehiyA6vlZPPQujelOYJi2Gw7mNXMPdyRelviy/LVyZiPH8NVYMXdbTdiZ393s4jnkBNF 2GNNS/xeleuiOJlxLO4GBL53DKkq9XCpv4N5xQEMA6qtAkDQpdyoD7msFi69Il8EFydo 9xKz6cat0n68fVdjirC7Kq6UAAYYbZr8VW/rIM7T1WkmlEqX7gm5R+vAFfopGXNjqykE tn+6GOen5NZONxwJ5prFtgvnlNKYHCZwAdU10YVDKG/V4N39j8ZvTmce/nzV4+6Myf/E /WCw== 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=dn470I1AAXYIPllkE0iKbl8OtBnx1LYxnn0mwkxAqPY=; b=l6uqkNUXawvZh2KrGKkxlj81s2Q3QZhs6NxP32CK4KlmF21u21rz3hCWdksjOe3wr6 DPF19m4qhxWHzFL3tXYZkvOAWAKNEn2LKZ99bzGmvSiE+10AlY0PO81/f6lfCIvvDz8+ tbelcMEmOEiBwC/vufMQ6N1f1aB2QVY6B5MJG4s9HaLpBGwjzCRmkbUMsHL2Sw+Nqltq BCXhng4Il6hT8Sb7kJ2R1oWBzLiGOLU018S554efF2f3u34B9s+E0b2Rh1lhVPUcoEh0 wJPpVMmVLZZQmMQMarDKWr62qf7U+cV15NrYLgaHNDX0X49d2LI6jBVeSrqo/OL/mzep YBtQ== X-Gm-Message-State: AOAM531QAZcdHKaLYtw/ixXZhBhBMTV8bmdw35DZWIft8IPkEhtRkLnh ejKoh1atelZeU1ZoI42QYQqJYqqEESCzaw== X-Google-Smtp-Source: ABdhPJz1Nv7wPjay2Y92K6Kw+fnPZpviMOGbgGKFvaL2KyiI0xWlyfw6/CvfXqcR6DuUFZZBnyXSqQ== X-Received: by 2002:a62:8604:0:b0:519:363d:8eb3 with SMTP id x4-20020a628604000000b00519363d8eb3mr68692pfd.83.1653596819792; Thu, 26 May 2022 13:26:59 -0700 (PDT) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id c20-20020a170902b69400b0015e8d4eb1e5sm2025316pls.47.2022.05.26.13.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 13:26:59 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Cristian Dumitrescu , Jasvinder Singh , Wojciech Liguzinski Subject: [PATCH v5 3/3] rte_pie: fix incorrect floating point math Date: Thu, 26 May 2022 13:26:53 -0700 Message-Id: <20220526202653.99796-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220526202653.99796-1-stephen@networkplumber.org> References: <20220524184623.480646-1-stephen@networkplumber.org> <20220526202653.99796-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") Signed-off-by: Stephen Hemminger Acked-by: Jasvinder Singh --- 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; }