Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/131232/?format=api
http://patchwork.dpdk.org/api/patches/131232/?format=api", "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20230907152456.20570-3-stephen@networkplumber.org/", "project": { "id": 1, "url": "http://patchwork.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20230907152456.20570-3-stephen@networkplumber.org>", "list_archive_url": "https://inbox.dpdk.org/dev/20230907152456.20570-3-stephen@networkplumber.org", "date": "2023-09-07T15:24:56", "name": "[v2,2/2] random: make rte_rand() thread safe for non-EAL threads", "commit_ref": null, "pull_url": null, "state": "rejected", "archived": true, "hash": "5863077dfd2820de73014cee7f1e1ba05f8ecf10", "submitter": { "id": 27, "url": "http://patchwork.dpdk.org/api/people/27/?format=api", "name": "Stephen Hemminger", "email": "stephen@networkplumber.org" }, "delegate": { "id": 24651, "url": "http://patchwork.dpdk.org/api/users/24651/?format=api", "username": "dmarchand", "first_name": "David", "last_name": "Marchand", "email": "david.marchand@redhat.com" }, "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20230907152456.20570-3-stephen@networkplumber.org/mbox/", "series": [ { "id": 29449, "url": "http://patchwork.dpdk.org/api/series/29449/?format=api", "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=29449", "date": "2023-09-07T15:24:54", "name": "fixes to rte_random for non-EAL threads", "version": 2, "mbox": "http://patchwork.dpdk.org/series/29449/mbox/" } ], "comments": "http://patchwork.dpdk.org/api/patches/131232/comments/", "check": "fail", "checks": "http://patchwork.dpdk.org/api/patches/131232/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "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])\n\tby inbox.dpdk.org (Postfix) with ESMTP id A2DE942537;\n\tThu, 7 Sep 2023 17:25:23 +0200 (CEST)", "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id D8983402E5;\n\tThu, 7 Sep 2023 17:25:13 +0200 (CEST)", "from mail-pl1-f173.google.com (mail-pl1-f173.google.com\n [209.85.214.173])\n by mails.dpdk.org (Postfix) with ESMTP id A4E24402C6\n for <dev@dpdk.org>; Thu, 7 Sep 2023 17:25:10 +0200 (CEST)", "by mail-pl1-f173.google.com with SMTP id\n d9443c01a7336-1c328b53aeaso9145595ad.2\n for <dev@dpdk.org>; Thu, 07 Sep 2023 08:25:10 -0700 (PDT)", "from hermes.local (204-195-112-131.wavecable.com. [204.195.112.131])\n by smtp.gmail.com with ESMTPSA id\n e2-20020a170902b78200b001aaf2e8b1eesm12864400pls.248.2023.09.07.08.25.08\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 07 Sep 2023 08:25:09 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1694100309;\n x=1694705109; darn=dpdk.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=TY+OZQDjCfeely1UFsBLMdsvhdMtisbaGN6NwHNR1aU=;\n b=Srl2nkr4fVUsptc+RJ8WzaJX8s226GGgv07iYEheeZGi5khBJD0bMlQutKmYPAGWWm\n bLXvkdL+5hg7w7dz4f2U8Vu9dsx8azQdiJGs1Pgr2WPlWaC0MekAWqCVsNUNWGTJr6b1\n mrEZQcbXj74RDhfs9C9ZH0dbSY2DC4d4CIh5sJ83EL45Ph/CRvu7HTTimM4pm6Q5vqaM\n V+0paKygsxSxb/P3Oi+FecSxnjrPt/KshmEdKLfj92dPSy5FOPDvhYy2TRnGqq+h6CzG\n e5Sggs9JeEkIFH+ljiEA9JWv5+Xwu56fpElU988If9UnCUIwLXeGFEvc76UTRB3QsNdE\n U01g==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20221208; t=1694100309; x=1694705109;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=TY+OZQDjCfeely1UFsBLMdsvhdMtisbaGN6NwHNR1aU=;\n b=k8crTZvM71eoiEUOVIemCfPe1LJvFzGbhgwH9LMwXRgfixHKCj6ldMn6BpWkrSZ4f8\n MS4VY55fkyMOl49M+97g3FEvrlzHu2xWmzsULFzNKmfrHjnuK9j/dxqff8BM4gfsd7iv\n ZjGMZoS8tvDu3MAKYB4h+bp5gcNbL4pgFmuMdAAmj6/IIifLOtAp3ZCNocpK3c61oAPi\n oE7z4ZBONdNEOpw3wTfxU1BJ375xewzlHU+XL8H5gLHa+4Arbj2J6CLdazuZWVlXifXv\n 61r+JkT7fPJqo4935hoQcuz/Q/KlvYHjNjKXS7ZBtJm1dTSnL911ZgIOn3GrVcRjSAZU\n y8UQ==", "X-Gm-Message-State": "AOJu0YwE4khfCwdF49FX3DOxbuFgXJcj/6jlZb0DGUWpYSNwL6FJnJM2\n dqlZPzgnXJpOeiHBjQtFKuEtRIhH+zrDuro9Huk=", "X-Google-Smtp-Source": "\n AGHT+IE0n0UsPe4yloLnIRX9jUP+hC5ITZlOWZDHvp6rH1evKQfGZdM6/IqK1NRymHKFE3bskzz1AQ==", "X-Received": "by 2002:a17:902:b485:b0:1bc:9651:57c6 with SMTP id\n y5-20020a170902b48500b001bc965157c6mr18525153plr.57.1694100309507;\n Thu, 07 Sep 2023 08:25:09 -0700 (PDT)", "From": "Stephen Hemminger <stephen@networkplumber.org>", "To": "dev@dpdk.org", "Cc": "Stephen Hemminger <stephen@networkplumber.org>, =?utf-8?q?Mattias_R?=\n\t=?utf-8?q?=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>,\n Bruce Richardson <bruce.richardson@intel.com>", "Subject": "[PATCH v2 2/2] random: make rte_rand() thread safe for non-EAL\n threads", "Date": "Thu, 7 Sep 2023 08:24:56 -0700", "Message-Id": "<20230907152456.20570-3-stephen@networkplumber.org>", "X-Mailer": "git-send-email 2.39.2", "In-Reply-To": "<20230907152456.20570-1-stephen@networkplumber.org>", "References": "<20230906155302.82749-1-stephen@networkplumber.org>\n <20230907152456.20570-1-stephen@networkplumber.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Add missing locking so that if two non-EAL threads call rte_rand()\nthey will not corrupt the per-thread state.\n\nFixes: 3f002f069612 (\"eal: replace libc-based random generation with LFSR\")\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\n lib/eal/common/rte_random.c | 54 ++++++++++++++++++++++++-------------\n 1 file changed, 36 insertions(+), 18 deletions(-)", "diff": "diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c\nindex 812e5b4757b5..02b6b6b97bc0 100644\n--- a/lib/eal/common/rte_random.c\n+++ b/lib/eal/common/rte_random.c\n@@ -11,6 +11,7 @@\n #include <rte_branch_prediction.h>\n #include <rte_cycles.h>\n #include <rte_lcore.h>\n+#include <rte_spinlock.h>\n #include <rte_random.h>\n \n struct rte_rand_state {\n@@ -21,6 +22,9 @@ struct rte_rand_state {\n \tuint64_t z5;\n } __rte_cache_aligned;\n \n+/* Used for thread safety for non EAL threads. */\n+static rte_spinlock_t rte_rand_lock = RTE_SPINLOCK_INITIALIZER;\n+\n /* One instance each for every lcore id-equipped thread, and one\n * additional instance to be shared by all others threads (i.e., all\n * unregistered non-EAL threads).\n@@ -124,20 +128,32 @@ struct rte_rand_state *__rte_rand_get_state(void)\n \tidx = rte_lcore_id();\n \n \t/* last instance reserved for unregistered non-EAL threads */\n-\tif (unlikely(idx == LCORE_ID_ANY))\n+\tif (unlikely(idx == LCORE_ID_ANY)) {\n \t\tidx = RTE_MAX_LCORE;\n+\t\trte_spinlock_lock(&rte_rand_lock);\n+\t}\n \n \treturn &rand_states[idx];\n }\n \n+static __rte_always_inline\n+void __rte_rand_put_state(struct rte_rand_state *state)\n+{\n+\tif (state == &rand_states[RTE_MAX_LCORE])\n+\t\trte_spinlock_unlock(&rte_rand_lock);\n+}\n+\n uint64_t\n rte_rand(void)\n {\n \tstruct rte_rand_state *state;\n+\tuint64_t res;\n \n \tstate = __rte_rand_get_state();\n+\tres = __rte_rand_lfsr258(state);\n+\t__rte_rand_put_state(state);\n \n-\treturn __rte_rand_lfsr258(state);\n+\treturn res;\n }\n \n uint64_t\n@@ -159,22 +175,24 @@ rte_rand_max(uint64_t upper_bound)\n \t/* Handle power-of-2 upper_bound as a special case, since it\n \t * has no bias issues.\n \t */\n-\tif (unlikely(ones == 1))\n-\t\treturn __rte_rand_lfsr258(state) & (upper_bound - 1);\n-\n-\t/* The approach to avoiding bias is to create a mask that\n-\t * stretches beyond the request value range, and up to the\n-\t * next power-of-2. In case the masked generated random value\n-\t * is equal to or greater than the upper bound, just discard\n-\t * the value and generate a new one.\n-\t */\n-\n-\tleading_zeros = rte_clz64(upper_bound);\n-\tmask >>= leading_zeros;\n-\n-\tdo {\n-\t\tres = __rte_rand_lfsr258(state) & mask;\n-\t} while (unlikely(res >= upper_bound));\n+\tif (unlikely(ones == 1)) {\n+\t\tres = __rte_rand_lfsr258(state) & (upper_bound - 1);\n+\t} else {\n+\t\t/* The approach to avoiding bias is to create a mask that\n+\t\t * stretches beyond the request value range, and up to the\n+\t\t * next power-of-2. In case the masked generated random value\n+\t\t * is equal to or greater than the upper bound, just discard\n+\t\t * the value and generate a new one.\n+\t\t */\n+\n+\t\tleading_zeros = rte_clz64(upper_bound);\n+\t\tmask >>= leading_zeros;\n+\n+\t\tdo {\n+\t\t\tres = __rte_rand_lfsr258(state) & mask;\n+\t\t} while (unlikely(res >= upper_bound));\n+\t}\n+\t__rte_rand_put_state(state);\n \n \treturn res;\n }\n", "prefixes": [ "v2", "2/2" ] }{ "id": 131232, "url": "