Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/54414/?format=api
http://patches.dpdk.org/api/patches/54414/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/20190605104400.24484-5-mattias.ronnblom@ericsson.com/", "project": { "id": 1, "url": "http://patches.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": "<20190605104400.24484-5-mattias.ronnblom@ericsson.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20190605104400.24484-5-mattias.ronnblom@ericsson.com", "date": "2019-06-05T10:43:58", "name": "[v3,4/6] eal: introduce random generator function with upper bound", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "bc5b7d609d493b4fa076defcde5e762b197a9caf", "submitter": { "id": 1077, "url": "http://patches.dpdk.org/api/people/1077/?format=api", "name": "Mattias Rönnblom", "email": "mattias.ronnblom@ericsson.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/20190605104400.24484-5-mattias.ronnblom@ericsson.com/mbox/", "series": [ { "id": 4905, "url": "http://patches.dpdk.org/api/series/4905/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=4905", "date": "2019-06-05T10:43:54", "name": "Pseudo-random number generation improvements", "version": 3, "mbox": "http://patches.dpdk.org/series/4905/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/54414/comments/", "check": "fail", "checks": "http://patches.dpdk.org/api/patches/54414/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 5BB721BB22;\n\tWed, 5 Jun 2019 12:44:43 +0200 (CEST)", "from sessmg23.ericsson.net (sessmg23.ericsson.net [193.180.251.45])\n\tby dpdk.org (Postfix) with ESMTP id 8C2E91BA8F\n\tfor <dev@dpdk.org>; Wed, 5 Jun 2019 12:44:37 +0200 (CEST)", "from ESESBMB501.ericsson.se (Unknown_Domain [153.88.183.114])\n\tby sessmg23.ericsson.net (Symantec Mail Security) with SMTP id\n\t70.58.06765.41D97FC5; Wed, 5 Jun 2019 12:44:36 +0200 (CEST)", "from ESESBMB504.ericsson.se (153.88.183.171) by\n\tESESBMB501.ericsson.se (153.88.183.168) with Microsoft SMTP Server\n\t(version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id\n\t15.1.1713.5; Wed, 5 Jun 2019 12:44:26 +0200", "from selio1a020.lmera.ericsson.se (153.88.183.153) by\n\tsmtp.internal.ericsson.com (153.88.183.187) with Microsoft SMTP\n\tServer id\n\t15.1.1713.5 via Frontend Transport; Wed, 5 Jun 2019 12:44:26 +0200", "from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se\n\t[150.132.109.241])\n\tby selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id\n\tx55AiQRE025408; Wed, 5 Jun 2019 12:44:27 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801;\n\tc=relaxed/relaxed; \n\tq=dns/txt; i=@ericsson.com; t=1559731476; x=1562323476;\n\th=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type:\n\tContent-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From:\n\tResent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:\n\tList-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive;\n\tbh=uZiIz4oSZOfhKYpEU373SIY5pIImkCt1mT2IwfQZKBU=;\n\tb=Z+GcW31ZnCtL82R0sntUHSeVouDh2XM5s5zCu2u/jWKlp95nR8PhYRXOk9i4TfaZ\n\tGGPdrT9JIouhcpUmyOa9Y9Xat0Hk5hAlZQMSZDnrsF5JdSBv9YfT8x52BQqNoOTs\n\tQkUzGVKodKwhtpYf/rp/QCzi/aW3AhW7cJiWNbBg49c=;", "X-AuditID": "c1b4fb2d-195ff70000001a6d-41-5cf79d1480d1", "From": "=?utf-8?q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>", "To": "<dev@dpdk.org>", "CC": "<nhorman@tuxdriver.com>, <stephen@networkplumber.org>,\n\t<david.marchand@redhat.com>, <bruce.richardson@intel.com>, \n\t=?utf-8?q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>", "Date": "Wed, 5 Jun 2019 12:43:58 +0200", "Message-ID": "<20190605104400.24484-5-mattias.ronnblom@ericsson.com>", "X-Mailer": "git-send-email 2.17.1", "In-Reply-To": "<20190605104400.24484-1-mattias.ronnblom@ericsson.com>", "References": "<20190516203529.GA642@bricha3-MOBL.ger.corp.intel.com>\n\t<20190605104400.24484-1-mattias.ronnblom@ericsson.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"UTF-8\"", "Content-Transfer-Encoding": "8bit", "X-Brightmail-Tracker": "H4sIAAAAAAAAA+NgFnrDLMWRmVeSWpSXmKPExsUyM2J7ka7I3O8xBouPsVncWGVvsX1FF5vF\n\tu0/bmSxuNZ9ks1h8R86B1ePXgqWsHov3vGTy6Dk5j8nj/b6rbB5Xvq9mDGCN4rJJSc3JLEst\n\t0rdL4Mr48mUac0GTdMX8S1dYGxiXiXUxcnJICJhIdL6bx9TFyMUhJHCUUeL+70VsEM5XRolH\n\tkzZCZS4wSqze3s0M4VxilFj6fgobSD+bgKfE5HfdLCC2iICQxNKPl9lBipgF9jJKvFo3Dywh\n\tLBAosfHOdLAGFgEVibXL2thBbF4BJ4n9hw+zQBwiL7F6wwFmEJtTwFni8fT9TCC2kEC1xIS3\n\tzUwQ9YISJ2c+AatnFtCUaN3+mx3Clpdo3jqbGaJeS+L+ki/MExiFZiFpmYWkZRaSlgWMzKsY\n\tRYtTi4tz042M9VKLMpOLi/Pz9PJSSzYxAuPg4JbfujsYV792PMQowMGoxMMr3/s9Rog1say4\n\tMvcQowQHs5IIb+LtLzFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeaNX74kREkhPLEnNTk0tSC2C\n\tyTJxcEo1MC7YtsvcPPa0vaR0rUGTf4Ln+0WvVhw9/mpb87ON/haiV/UiohIKGZfwGPF1z7/s\n\tUzY3Y0Pd432cxxkvnTq+QnEnb8uqt2d9H9r0LXpk1r5/tp9KO+Phummv9ka/9q+YbpZ47lGo\n\t42OXs6+1uUxaUqLzBLw3Zsa4P2Fb8eZPPC/bjU/NSxm3MiqxFGckGmoxFxUnAgB9zlkKfwIA\n\tAA==", "Subject": "[dpdk-dev] [PATCH v3 4/6] eal: introduce random generator function\n\twith upper bound", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<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\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Add a function rte_rand_max() which generates an uniformly distributed\npseudo-random number less than a user-specified upper bound.\n\nThe commonly used pattern rte_rand() % SOME_VALUE creates biased\nresults (as in some values in the range are more frequently occurring\nthan others) if SOME_VALUE is not a power of 2.\n\nSigned-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>\nAcked-by: Bruce Richardson <bruce.richardson@intel.com>\n---\n lib/librte_eal/common/include/rte_random.h | 18 ++++++++++\n lib/librte_eal/common/rte_random.c | 39 ++++++++++++++++++++++\n lib/librte_eal/rte_eal_version.map | 1 +\n 3 files changed, 58 insertions(+)", "diff": "diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h\nindex 66dfe8ae7..939e6aaa9 100644\n--- a/lib/librte_eal/common/include/rte_random.h\n+++ b/lib/librte_eal/common/include/rte_random.h\n@@ -17,6 +17,8 @@ extern \"C\" {\n \n #include <stdint.h>\n \n+#include <rte_compat.h>\n+\n /**\n * Seed the pseudo-random generator.\n *\n@@ -47,6 +49,22 @@ rte_srand(uint64_t seedval);\n uint64_t\n rte_rand(void);\n \n+/**\n+ * Generates a pseudo-random number with an upper bound.\n+ *\n+ * This function returns an uniformly distributed (unbiased) random\n+ * number less than a user-specified maximum value.\n+ *\n+ * If called from lcore threads, this function is thread-safe.\n+ *\n+ * @param upper_bound\n+ * The upper bound of the generated number.\n+ * @return\n+ * A pseudo-random value between 0 and (upper_bound-1).\n+ */\n+uint64_t __rte_experimental\n+rte_rand_max(uint64_t upper_bound);\n+\n #ifdef __cplusplus\n }\n #endif\ndiff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c\nindex e53d96d18..3d9b9b7d8 100644\n--- a/lib/librte_eal/common/rte_random.c\n+++ b/lib/librte_eal/common/rte_random.c\n@@ -137,6 +137,45 @@ rte_rand(void)\n \treturn __rte_rand_lfsr258(state);\n }\n \n+uint64_t __rte_experimental\n+rte_rand_max(uint64_t upper_bound)\n+{\n+\tstruct rte_rand_state *state;\n+\tuint8_t ones;\n+\tuint8_t leading_zeros;\n+\tuint64_t mask = ~((uint64_t)0);\n+\tuint64_t res;\n+\n+\tif (unlikely(upper_bound < 2))\n+\t\treturn 0;\n+\n+\tstate = __rte_rand_get_state();\n+\n+\tones = __builtin_popcountll(upper_bound);\n+\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 = __builtin_clzll(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+\n+\treturn res;\n+}\n+\n static uint64_t\n __rte_random_initial_seed(void)\n {\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex 20c1a9018..a53a29a35 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -384,6 +384,7 @@ EXPERIMENTAL {\n \trte_mp_request_async;\n \trte_mp_sendmsg;\n \trte_option_register;\n+\trte_rand_max;\n \trte_realloc_socket;\n \trte_service_lcore_attr_get;\n \trte_service_lcore_attr_reset_all;\n", "prefixes": [ "v3", "4/6" ] }{ "id": 54414, "url": "