get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/53487/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 53487,
    "url": "http://patches.dpdk.org/api/patches/53487/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20190516175510.27154-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": "<20190516175510.27154-5-mattias.ronnblom@ericsson.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20190516175510.27154-5-mattias.ronnblom@ericsson.com",
    "date": "2019-05-16T17:55:08",
    "name": "[v2,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": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20190516175510.27154-5-mattias.ronnblom@ericsson.com/mbox/",
    "series": [
        {
            "id": 4698,
            "url": "http://patches.dpdk.org/api/series/4698/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=4698",
            "date": "2019-05-16T17:55:04",
            "name": "Pseudo-random number generation improvements",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/4698/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/53487/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/53487/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 180CE7CCF;\n\tThu, 16 May 2019 19:55:32 +0200 (CEST)",
            "from sessmg23.ericsson.net (sessmg23.ericsson.net [193.180.251.45])\n\tby dpdk.org (Postfix) with ESMTP id 6EF365F19\n\tfor <dev@dpdk.org>; Thu, 16 May 2019 19:55:21 +0200 (CEST)",
            "from ESESBMB504.ericsson.se (Unknown_Domain [153.88.183.117])\n\tby sessmg23.ericsson.net (Symantec Mail Security) with SMTP id\n\t9B.27.06765.904ADDC5; Thu, 16 May 2019 19:55:21 +0200 (CEST)",
            "from ESESSMR504.ericsson.se (153.88.183.126) by\n\tESESBMB504.ericsson.se (153.88.183.171) 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; Thu, 16 May 2019 19:55:20 +0200",
            "from ESESSMB503.ericsson.se (153.88.183.164) by\n\tESESSMR504.ericsson.se (153.88.183.126) 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; Thu, 16 May 2019 19:55:21 +0200",
            "from selio1a020.lmera.ericsson.se (153.88.183.153) by\n\tsmtp.internal.ericsson.com (153.88.183.191) with Microsoft SMTP\n\tServer id\n\t15.1.1713.5 via Frontend Transport; Thu, 16 May 2019 19:55:20 +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\tx4GHtHcw023701; Thu, 16 May 2019 19:55:20 +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=1558029321; x=1560621321;\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=S/h1DoAkXCzKBmNCgdYEVo7lZSo6k8+XMVLKTo6r3vw=;\n\tb=WVmp3OLad78FjVRBvXmjIs35h9yEn4CbMiWLIQA2h15QTyR0nwHS8fW21A31VWro\n\ta8phNEW8dr9hCJGFQvFwxjEIw3WKvGXc6bRogF9Ar0UA1xfCaaidokvAriGGFGP8\n\tKLQvkPRebAcpAyoOJJt/G27PfC/fStUCCoCzP7EDy/A=;",
        "X-AuditID": "c1b4fb2d-195ff70000001a6d-71-5cdda409fade",
        "From": "=?utf-8?q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>",
        "To": "<dev@dpdk.org>",
        "CC": "<bruce.richardson@intel.com>, <stephen@networkplumber.org>,\n\t=?utf-8?q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>",
        "Date": "Thu, 16 May 2019 19:55:08 +0200",
        "Message-ID": "<20190516175510.27154-5-mattias.ronnblom@ericsson.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20190516175510.27154-1-mattias.ronnblom@ericsson.com>",
        "References": "<20190514092046.30808-1-mattias.ronnblom@ericsson.com>\n\t<20190516175510.27154-1-mattias.ronnblom@ericsson.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"UTF-8\"",
        "Content-Transfer-Encoding": "8bit",
        "X-Brightmail-Tracker": "H4sIAAAAAAAAA+NgFnrKLMWRmVeSWpSXmKPExsUyM2J7qS7nkrsxBpN3ilncWGVv8e7TdiaL\n\txXfkHJg9fi1YyuqxeM9LJo+ek/OYApijuGxSUnMyy1KL9O0SuDJ+T73MUnBSquLIt7OsDYyf\n\tRLsYOTkkBEwkmhdvZuli5OIQEjjKKLH3E4zzjVHiR+Nydjjn7JfvjBDORUaJFYf+Q2UuM0o8\n\t3/GEFWQYm4CnxOR33SwgtoiAkMTSj5fBipgFWhkldjxsBCsSFgiU2L7wJpjNIqAq0bz5MFgD\n\tr4CTxNee3SwQV8lLrN5wgBnE5hRwlrh6/gBYvZBAtcTPrjVMEPWCEidnPgGrZxbQlGjd/psd\n\twpaXaN46mxmiXkvi/pIvzBMYhWchaZmFpGUWkpYFjMyrGEWLU4uLc9ONjPVSizKTi4vz8/Ty\n\tUks2MQID/+CW37o7GFe/djzEKMDBqMTD+33O3Rgh1sSy4srcQ4wSHMxKIrwb3t+OEeJNSays\n\tSi3Kjy8qzUktPsQozcGiJM4bvXpPjJBAemJJanZqakFqEUyWiYNTqoFR88Cq4hWX/2zt6NB1\n\tMgyW4NsetNXVyttBp+MeY5b3vZQ7hz4pH/UQv7RJ7EqOcsbsx4lPX6xd+PJ6XIFptF9/PPsL\n\tnZPRHVX9ByecOhteEvXximrqa2FvleXznho4xqRtOi5S8+LCZVmNbjbTBzs2cxTYPX4v9vln\n\tgJ1I0qo1LWXqeR7nLhkrsRRnJBpqMRcVJwIAwbpNFngCAAA=",
        "Subject": "[dpdk-dev] [PATCH v2 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>\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 e615d7cb9..82483aed2 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -382,6 +382,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": [
        "v2",
        "4/6"
    ]
}