From patchwork Tue May 14 09:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 53394 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8E96C5B2A; Tue, 14 May 2019 11:21:34 +0200 (CEST) Received: from sessmg22.ericsson.net (sessmg22.ericsson.net [193.180.251.58]) by dpdk.org (Postfix) with ESMTP id 9DB1A5A4A for ; Tue, 14 May 2019 11:21:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1557825693; x=1560417693; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=d8IrLP7hWL5S+xfzhDw/zKwOPIKdITQcZEqq2N7axeU=; b=OKy7gGNqpahmLT9bF7jTec2CocPjHyXq7S5Wnus+i0jDMz2oAYb/cF5IDKAzrwfa tCP+MKT/6rnMZATf9u+c8U6B65qMnfN8VHfaLB/srj9KCIV1aUYGmQTOlWo6Io/A tnS9z2eiy3nqaLoQoYSr3INsFta5MlDDrHwBdd5M7mE=; X-AuditID: c1b4fb3a-709ff7000000189f-9b-5cda889d804c Received: from ESESBMB503.ericsson.se (Unknown_Domain [153.88.183.116]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id 65.2B.06303.D988ADC5; Tue, 14 May 2019 11:21:33 +0200 (CEST) Received: from ESESBMB502.ericsson.se (153.88.183.169) by ESESBMB503.ericsson.se (153.88.183.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:32 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.185) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 May 2019 11:21:32 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id x4E9LQN5027252; Tue, 14 May 2019 11:21:32 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , , , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Tue, 14 May 2019 11:20:41 +0200 Message-ID: <20190514092046.30808-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514092046.30808-1-mattias.ronnblom@ericsson.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJLMWRmVeSWpSXmKPExsUyM2J7ie7cjlsxBpd381rcWGVvsX1FF5vF u0/bmSxuNZ9ks1h8R86B1ePXgqWsHov3vGTy6Dk5j8nj/b6rbB5Xvq9mDGCN4rJJSc3JLEst 0rdL4MpY93Y2e8F7j4rDC0QaGLfbdDFycEgImEgce2PcxcjFISRwlFGiefl8FgjnG6PErfUf 2CGci4wSrz4eYYVwLjNKTG/7A1TGycEm4Ckx+V03mC0iICSx9ONlsA5mgb1AHevmgSWEBfwl lvz7wwqyj0VAVWLn2WqQMK+Ak8Tjq2dYQWwJAXmJ1RsOMIPYnALOEpOm3GIHsYUEUiT+9Dxi gagXlDg58wmYzSygKdG6/Tc7hC0v0bx1NjNEvZbE/SVfmCcwCs1C0jILScssJC0LGJlXMYoW pxYX56YbGemlFmUmFxfn5+nlpZZsYgRGwMEtv612MB587niIUYCDUYmHNzb9VowQa2JZcWXu IUYJDmYlEd4oxRsxQrwpiZVVqUX58UWlOanFhxilOViUxHmjV++JERJITyxJzU5NLUgtgsky cXBKNTBm1ulfOlg/TSRblGtp8O2MVd8zcnZO5A621YsqKmcU2KP/jMt8mlDGRSGZ7a7P8njj JqXutXXY3qu0wvLTzo2Ptykfe94izPQ7+kv03kc3xR/8eujlUNmk8NU2Sfeu76bz26Y49VS7 S551mhMZyXNul/2kdeHiVz/9nMW5NVihVMZk7ektZxKUWIozEg21mIuKEwHXCbS+fAIAAA== Subject: [dpdk-dev] [PATCH 1/6] eal: replace libc-based random number generation with LFSR X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit replaces rte_rand()'s use of lrand48() with a DPDK-native combined Linear Feedback Shift Register (LFSR) (also known as Tausworthe) pseudo-random number generator. This generator is faster and produces better-quality random numbers than the linear congruential generator (LCG) of lib's lrand48(). The implementation, as opposed to lrand48(), is multi-thread safe in regards to concurrent rte_rand() calls from different lcore threads. A LCG is still used, but only to seed the five per-lcore LFSR sequences. In addition, this patch also addresses the issue of the legacy implementation only producing 62 bits of pseudo randomness, while the API requires all 64 bits to be random. This pseudo-random number generator is not cryptographically secure - just like lrand48(). Bugzilla ID: 114 Bugzilla ID: 276 Signed-off-by: Mattias Rönnblom --- lib/librte_eal/common/include/rte_random.h | 29 ++--- lib/librte_eal/common/meson.build | 1 + lib/librte_eal/common/rte_random.c | 139 +++++++++++++++++++++ lib/librte_eal/freebsd/eal/Makefile | 1 + lib/librte_eal/freebsd/eal/eal.c | 2 - lib/librte_eal/linux/eal/Makefile | 1 + lib/librte_eal/linux/eal/eal.c | 2 - lib/librte_eal/rte_eal_version.map | 8 ++ 8 files changed, 161 insertions(+), 22 deletions(-) create mode 100644 lib/librte_eal/common/rte_random.c diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h index b2ca1c209..66dfe8ae7 100644 --- a/lib/librte_eal/common/include/rte_random.h +++ b/lib/librte_eal/common/include/rte_random.h @@ -16,7 +16,6 @@ extern "C" { #endif #include -#include /** * Seed the pseudo-random generator. @@ -25,34 +24,28 @@ extern "C" { * value. It may need to be re-seeded by the user with a real random * value. * + * This function is not multi-thread safe in regards to other + * rte_srand() calls, nor is it in relation to concurrent rte_rand() + * calls. + * * @param seedval * The value of the seed. */ -static inline void -rte_srand(uint64_t seedval) -{ - srand48((long)seedval); -} +void +rte_srand(uint64_t seedval); /** * Get a pseudo-random value. * - * This function generates pseudo-random numbers using the linear - * congruential algorithm and 48-bit integer arithmetic, called twice - * to generate a 64-bit value. + * 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<<64)-1. */ -static inline uint64_t -rte_rand(void) -{ - uint64_t val; - val = (uint64_t)lrand48(); - val <<= 32; - val += (uint64_t)lrand48(); - return val; -} +uint64_t +rte_rand(void); #ifdef __cplusplus } diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index 0670e4102..bafd23207 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -35,6 +35,7 @@ common_sources = files( 'rte_keepalive.c', 'rte_malloc.c', 'rte_option.c', + 'rte_random.c', 'rte_reciprocal.c', 'rte_service.c' ) diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c new file mode 100644 index 000000000..4d3cf5226 --- /dev/null +++ b/lib/librte_eal/common/rte_random.c @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Ericsson AB + */ + +#include + +#include +#include +#include +#include +#include +#include + +struct rte_rand_state { + uint64_t z1; + uint64_t z2; + uint64_t z3; + uint64_t z4; + uint64_t z5; +} __rte_cache_aligned; + +static struct rte_rand_state rand_states[RTE_MAX_LCORE]; + +static uint32_t +__rte_rand_lcg32(uint32_t *seed) +{ + *seed = 1103515245U * *seed + 12345U; + + return *seed; +} + +static uint64_t +__rte_rand_lcg64(uint32_t *seed) +{ + uint64_t low; + uint64_t high; + + /* A 64-bit LCG would have been much cleaner, but good + * multiplier/increments for such seem hard to come by. + */ + + low = __rte_rand_lcg32(seed); + high = __rte_rand_lcg32(seed); + + return low | (high << 32); +} + +static uint64_t +__rte_rand_lfsr258_gen_seed(uint32_t *seed, uint64_t min_value) +{ + uint64_t res; + + res = __rte_rand_lcg64(seed); + + if (res < min_value) + res += min_value; + + return res; +} + +static void +__rte_srand_lfsr258(uint64_t seed, struct rte_rand_state *state) +{ + uint32_t lcg_seed; + + lcg_seed = (uint32_t)(seed ^ (seed >> 32)); + + state->z1 = __rte_rand_lfsr258_gen_seed(&lcg_seed, 2UL); + state->z2 = __rte_rand_lfsr258_gen_seed(&lcg_seed, 512UL); + state->z3 = __rte_rand_lfsr258_gen_seed(&lcg_seed, 4096UL); + state->z4 = __rte_rand_lfsr258_gen_seed(&lcg_seed, 131072UL); + state->z5 = __rte_rand_lfsr258_gen_seed(&lcg_seed, 8388608UL); +} + +void +rte_srand(uint64_t seed) +{ + unsigned int lcore_id; + + /* add lcore_id to seed to avoid having the same sequence */ + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) + __rte_srand_lfsr258(seed + lcore_id, &rand_states[lcore_id]); +} + +static __rte_always_inline uint64_t +__rte_rand_lfsr258_comp(uint64_t z, uint64_t a, uint64_t b, uint64_t c, + uint64_t d) +{ + return ((z & c) << d) ^ (((z << a) ^ z) >> b); +} + +/* Based on L’Ecuyer, P.: Tables of maximally equidistributed combined + * LFSR generators. + */ + +static __rte_always_inline uint64_t +__rte_rand_lfsr258(struct rte_rand_state *state) +{ + state->z1 = __rte_rand_lfsr258_comp(state->z1, 1UL, 53UL, + 18446744073709551614UL, 10UL); + state->z2 = __rte_rand_lfsr258_comp(state->z2, 24UL, 50UL, + 18446744073709551104UL, 5UL); + state->z3 = __rte_rand_lfsr258_comp(state->z3, 3UL, 23UL, + 18446744073709547520UL, 29UL); + state->z4 = __rte_rand_lfsr258_comp(state->z4, 5UL, 24UL, + 18446744073709420544UL, 23UL); + state->z5 = __rte_rand_lfsr258_comp(state->z5, 3UL, 33UL, + 18446744073701163008UL, 8UL); + + return state->z1 ^ state->z2 ^ state->z3 ^ state->z4 ^ state->z5; +} + +static __rte_always_inline +struct rte_rand_state *__rte_rand_get_state(void) +{ + unsigned int lcore_id; + + lcore_id = rte_lcore_id(); + + if (unlikely(lcore_id == LCORE_ID_ANY)) + lcore_id = rte_get_master_lcore(); + + return &rand_states[lcore_id]; +} + +uint64_t +rte_rand(void) +{ + struct rte_rand_state *state; + + state = __rte_rand_get_state(); + + return __rte_rand_lfsr258(state); +} + +RTE_INIT(rte_rand_init) +{ + rte_srand(rte_get_timer_cycles()); +} diff --git a/lib/librte_eal/freebsd/eal/Makefile b/lib/librte_eal/freebsd/eal/Makefile index 19854ee2c..ca616c480 100644 --- a/lib/librte_eal/freebsd/eal/Makefile +++ b/lib/librte_eal/freebsd/eal/Makefile @@ -69,6 +69,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += malloc_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_keepalive.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_option.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_service.c +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_random.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_reciprocal.c # from arch dir diff --git a/lib/librte_eal/freebsd/eal/eal.c b/lib/librte_eal/freebsd/eal/eal.c index c6ac9028f..5d43310b3 100644 --- a/lib/librte_eal/freebsd/eal/eal.c +++ b/lib/librte_eal/freebsd/eal/eal.c @@ -727,8 +727,6 @@ rte_eal_init(int argc, char **argv) #endif } - rte_srand(rte_rdtsc()); - /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/librte_eal/linux/eal/Makefile b/lib/librte_eal/linux/eal/Makefile index 6e5261152..729795a10 100644 --- a/lib/librte_eal/linux/eal/Makefile +++ b/lib/librte_eal/linux/eal/Makefile @@ -77,6 +77,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += malloc_mp.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_keepalive.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_option.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_service.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_random.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_reciprocal.c # from arch dir diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c index 161399619..d6bf0e89e 100644 --- a/lib/librte_eal/linux/eal/eal.c +++ b/lib/librte_eal/linux/eal/eal.c @@ -1083,8 +1083,6 @@ rte_eal_init(int argc, char **argv) #endif } - rte_srand(rte_rdtsc()); - if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 245493461..e615d7cb9 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -287,6 +287,14 @@ DPDK_19.05 { } DPDK_18.11; +DPDK_19.08 { + global: + + rte_rand; + rte_srand; + +} DPDK_19.05; + EXPERIMENTAL { global: From patchwork Tue May 14 09:20:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 53395 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1E8CC5F13; Tue, 14 May 2019 11:21:41 +0200 (CEST) Received: from sesbmg22.ericsson.net (sesbmg22.ericsson.net [193.180.251.48]) by dpdk.org (Postfix) with ESMTP id D02DB5F0D for ; Tue, 14 May 2019 11:21:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1557825699; x=1560417699; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=sCbbIv/xOw/DWYTaCt6jmAP/dF/zn8swp9Q9wpMlpc0=; b=VxUu7LoF8nNLNg+pwXSrVQ/SjxCMXHPzhu3+FZuKYnG2BgmUrDQ2lpnTcP0i45J4 j8QkhIWmujOisf+XEYvfZ9gqEyCrvGCNwsIMMgyiaH+bD16FwFH8vMX7vw12QrvE oOGt8wiMsbMBM/r0P/ad5f8tjPyjPl5umdUl6ULDLOs=; X-AuditID: c1b4fb30-6ddff70000001814-8a-5cda88a3fdbb Received: from ESESSMB503.ericsson.se (Unknown_Domain [153.88.183.121]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id F3.33.06164.3A88ADC5; Tue, 14 May 2019 11:21:39 +0200 (CEST) Received: from ESESBMB504.ericsson.se (153.88.183.171) by ESESSMB503.ericsson.se (153.88.183.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:39 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.187) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 May 2019 11:21:39 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id x4E9LQN6027252; Tue, 14 May 2019 11:21:39 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , , , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Tue, 14 May 2019 11:20:42 +0200 Message-ID: <20190514092046.30808-3-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514092046.30808-1-mattias.ronnblom@ericsson.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRmVeSWpSXmKPExsUyM2J7pe7ijlsxBpc2yVvcWGVvsX1FF5vF u0/bmSxuNZ9ks1h8R86B1ePXgqWsHov3vGTy6Dk5j8nj/b6rbB5Xvq9mDGCN4rJJSc3JLEst 0rdL4Mp4e/MvW8FLwYoL/w6yNDAe5uti5OSQEDCRmPL0DksXIxeHkMBRRokf17uYIZxvjBI7 fv1ihHAuMkpc3n+UHcK5zCix8NtRJpB+NgFPicnvullAbBEBIYmlHy+DFTEL7GWUeLVuHlhC WMBPYkfbXXYQm0VAVaLx/UtWEJtXwEli7cSbrBCHyEus3nCAGcTmFHCWmDTlFli9kECKxJ+e RywQ9YISJ2c+AbOZBTQlWrf/Zoew5SWat85mhqjXkri/5AvzBEahWUhaZiFpmYWkZQEj8ypG 0eLU4qTcdCMjvdSizOTi4vw8vbzUkk2MwDg4uOW3wQ7Gl88dDzEKcDAq8fCez7gVI8SaWFZc mXuIUYKDWUmEN0rxRowQb0piZVVqUX58UWlOavEhRmkOFiVx3ujVe2KEBNITS1KzU1MLUotg skwcnFINjKGvboT8s1l/02rHgYU/ExdUhK73MXFjOPJhT5PFZq2GmU4/f3zcY3//bGTipEUV tSq5pnf2nTnysemB388tW5/Z3r96Rse5MezEs7STmR6n3vus21Ju+znNSvPrnOPsv5VqmM2W bbKa/KZ9W5A5V2zij0MfSgUftd2S9mT1vFr4k1E78T2v+X4lluKMREMt5qLiRADPkX2bfwIA AA== Subject: [dpdk-dev] [PATCH 2/6] eal: add pseudo-random number generation performance test X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add performance test for rte_rand(). Signed-off-by: Mattias Rönnblom --- app/test/Makefile | 1 + app/test/test_rand_perf.c | 75 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 app/test/test_rand_perf.c diff --git a/app/test/Makefile b/app/test/Makefile index 68d6b4fbc..be0f39227 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -73,6 +73,7 @@ SRCS-y += test_reciprocal_division.c SRCS-y += test_reciprocal_division_perf.c SRCS-y += test_fbarray.c SRCS-y += test_external_mem.c +SRCS-y += test_rand_perf.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c diff --git a/app/test/test_rand_perf.c b/app/test/test_rand_perf.c new file mode 100644 index 000000000..771713757 --- /dev/null +++ b/app/test/test_rand_perf.c @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Ericsson AB + */ + +#include +#include + +#include +#include +#include + +#include "test.h" + +static volatile uint64_t vsum; + +#define ITERATIONS (100000000) + +enum rand_type { + rand_type_64 +}; + +static const char * +rand_type_desc(enum rand_type rand_type) +{ + switch (rand_type) { + case rand_type_64: + return "Full 64-bit [rte_rand()]"; + default: + return NULL; + } +} + +static __rte_always_inline void +test_rand_perf_type(enum rand_type rand_type) +{ + uint64_t start; + uint32_t i; + uint64_t end; + uint64_t sum = 0; + uint64_t op_latency; + + start = rte_rdtsc(); + + for (i = 0; i < ITERATIONS; i++) { + switch (rand_type) { + case rand_type_64: + sum += rte_rand(); + break; + } + } + + end = rte_rdtsc(); + + /* to avoid an optimizing compiler removing the whole loop */ + vsum = sum; + + op_latency = (end - start) / ITERATIONS; + + printf("%s: %"PRId64" TSC cycles/op\n", rand_type_desc(rand_type), + op_latency); +} + +static int +test_rand_perf(void) +{ + rte_srand(42); + + printf("Pseudo-random number generation latencies:\n"); + + test_rand_perf_type(rand_type_64); + + return 0; +} + +REGISTER_TEST_COMMAND(rand_perf_autotest, test_rand_perf); From patchwork Tue May 14 09:20:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 53396 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1BA245F1D; Tue, 14 May 2019 11:21:49 +0200 (CEST) Received: from sesbmg23.ericsson.net (sesbmg23.ericsson.net [193.180.251.37]) by dpdk.org (Postfix) with ESMTP id 4E0F75F1B for ; Tue, 14 May 2019 11:21:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1557825708; x=1560417708; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=h5GAOK7LZyMqXa8dFI/Hz/qrD/CKwXlWzZPkx0rt9vs=; b=Y16jGUA83eUHMOdBwIOBC/SHWnedtcDSmcw1uRIEhvN2cA7uN5BMoI89vGOubD9p 4dNe4LHH0sBa2zxpx07JnEt6sUdUEV0DhU0Ys2qGI8DBJRwv9L+Fs9OV38YG45NX xwHGW7f60c377Z5/SBG28CrGkkQLeophQSzJ3I/rWmw=; X-AuditID: c1b4fb25-3b1ff700000029f0-03-5cda88ab9f24 Received: from ESESBMB503.ericsson.se (Unknown_Domain [153.88.183.116]) by sesbmg23.ericsson.net (Symantec Mail Security) with SMTP id 60.30.10736.BA88ADC5; Tue, 14 May 2019 11:21:47 +0200 (CEST) Received: from ESESBMR503.ericsson.se (153.88.183.135) by ESESBMB503.ericsson.se (153.88.183.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:47 +0200 Received: from ESESSMB503.ericsson.se (153.88.183.164) by ESESBMR503.ericsson.se (153.88.183.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:47 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.191) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 May 2019 11:21:47 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id x4E9LQN7027252; Tue, 14 May 2019 11:21:46 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , , , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Tue, 14 May 2019 11:20:43 +0200 Message-ID: <20190514092046.30808-4-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514092046.30808-1-mattias.ronnblom@ericsson.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRmVeSWpSXmKPExsUyM2J7ie7qjlsxBkuabS1urLK32L6ii83i 3aftTBa3mk+yWSy+I+fA6vFrwVJWj8V7XjJ59Jycx+Txft9VNo8r31czBrBGcdmkpOZklqUW 6dslcGW8XHiApWAVR0V35zqmBsY/bF2MHBwSAiYST3YndDFycQgJHGWUOLl9N3sXIyeQ841R 4lWLP0QCyH7xaC8rhHORUaK96TKUc5lRYtWF08wgLWwCnhKT33WzgNgiAkISSz9eZgcpYhbY CzRq3TywhLCAvcS1uz/BGlgEVCVad3Qxgdi8Ak4S13oawWokBOQlVm84AFbDKeAsMWnKLaib UiT+9DxigagXlDg58wmYzSygKdG6/Tc7hC0v0bx1NjNEvZbE/SVfmCcwCs9C0jILScssJC0L GJlXMYoWpxYn5aYbGeulFmUmFxfn5+nlpZZsYgRGx8Etv1V3MF5+43iIUYCDUYmH1y/9VowQ a2JZcWXuIUYJDmYlEd4oxRsxQrwpiZVVqUX58UWlOanFhxilOViUxHmjV++JERJITyxJzU5N LUgtgskycXBKNTC29AYesw5Vr1k03af8mWLPcv+OuI8C8moXdYu1gww3e5ivS+H69kkncn9Z xa3Wb72V/9/tTXB0qrN3Pf1p6dwFrnwKjSyHwtLPHUhJKtPN3u4Wk2TOpdO1elVpz8qu51OK U+bFMq4IOnfr6s2i/tcH1jCIK3rn8q0NlEuyvXl5orXO/U1cbUosxRmJhlrMRcWJAExYeTqK AgAA Subject: [dpdk-dev] [PATCH 3/6] eal: improve entropy for initial PRNG seed X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Replace the use of rte_get_timer_cycles() with getentropy() for seeding the pseudo-random number generator. getentropy() provides a more truly random value. Suggested-by: Stephen Hemminger Signed-off-by: Mattias Rönnblom --- lib/librte_eal/common/rte_random.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c index 4d3cf5226..aafc2f7ad 100644 --- a/lib/librte_eal/common/rte_random.c +++ b/lib/librte_eal/common/rte_random.c @@ -3,6 +3,7 @@ */ #include +#include #include #include @@ -135,5 +136,14 @@ rte_rand(void) RTE_INIT(rte_rand_init) { - rte_srand(rte_get_timer_cycles()); + uint64_t seed; + int rc; + + rc = getentropy(&seed, sizeof(seed)); + + /* fall back to rdtsc in case of failure */ + if (rc < 0) + seed = rte_get_timer_cycles(); + + rte_srand(seed); } From patchwork Tue May 14 09:20:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 53397 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 33A695F22; Tue, 14 May 2019 11:21:56 +0200 (CEST) Received: from sessmg23.ericsson.net (sessmg23.ericsson.net [193.180.251.45]) by dpdk.org (Postfix) with ESMTP id A3F5A568A for ; Tue, 14 May 2019 11:21:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1557825715; x=1560417715; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fo/08qnoTaUwhTj/JNiFfFYvkUN9tqEjm/Qgb6LsjZU=; b=PMPRbGj4DlvcPix0rsZj8jTZ78mhQvAFybTnf3Nfw9z7DMiJUB4l9qPK8bOFW+G5 M8hZUihcsf7WvdIzfAnOKFXY3227WZWB3i+7/Bodnzv8DfGs55j3sWn/Qrt3STCV pVzh6grrAbABYIs6GGw7k+JwMYTEjsHg30rgCcMCGWs=; X-AuditID: c1b4fb2d-17dff70000001a6d-94-5cda88b37bea Received: from ESESSMB502.ericsson.se (Unknown_Domain [153.88.183.120]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id AC.A2.06765.3B88ADC5; Tue, 14 May 2019 11:21:55 +0200 (CEST) Received: from ESESSMB502.ericsson.se (153.88.183.163) by ESESSMB502.ericsson.se (153.88.183.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:54 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.190) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 May 2019 11:21:54 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id x4E9LQN8027252; Tue, 14 May 2019 11:21:54 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , , , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Tue, 14 May 2019 11:20:44 +0200 Message-ID: <20190514092046.30808-5-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514092046.30808-1-mattias.ronnblom@ericsson.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRmVeSWpSXmKPExsUyM2J7he7mjlsxBpfvClrcWGVvsX1FF5vF u0/bmSxuNZ9ks1h8R86B1ePXgqWsHov3vGTy6Dk5j8nj/b6rbB5Xvq9mDGCN4rJJSc3JLEst 0rdL4Mp497iTqeCgVMWFGQ9ZGhhfinYxcnJICJhIHJv1grmLkYtDSOAoo0T/759sIAkhgW+M Et8/5EIkLgLZm2+wQDiXGSXm3OgBq2IT8JSY/K6bBcQWERCSWPrxMjtIEbPAXkaJV+vmgSWE Bfwk/p0/CGazCKhK3P64jRnE5hVwkjjY3MEGcYe8xOoNB8DinALOEpOm3GKHOCNF4k/PIxaI ekGJkzOfgNnMApoSrdt/s0PY8hLNW2czQ9RrSdxf8oV5AqPQLCQts5C0zELSsoCReRWjaHFq cXFuupGxXmpRZnJxcX6eXl5qySZGYBQc3PJbdwfj6teOhxgFOBiVeHjfpd+KEWJNLCuuzD3E KMHBrCTCG6V4I0aINyWxsiq1KD++qDQntfgQozQHi5I4b/TqPTFCAumJJanZqakFqUUwWSYO TqkGxkz++YeN6vNXcXNfVnqwyVXl6bP57Cqv7z2eXzxvwyWXhQ80593o5uv24fshsPpdjnBO zmap7H+FZstYapc/t4r6tOlmqzX3hD+XG8N41h8K5DMviHMWPrViWf+u4rsX6t9abd1QzHne 2CYj+7LSjZ6Ll+Pme88Q8r4kFCVQ8FP96Q+rWanp75RYijMSDbWYi4oTAXdclK1+AgAA Subject: [dpdk-dev] [PATCH 4/6] eal: introduce random generator function with upper bound X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a function rte_rand_max() which generates an uniformly distributed pseudo-random number less than a user-specified upper bound. The commonly used pattern rte_rand() % SOME_VALUE creates biased results (as in some values in the range are more frequently occurring than others) if SOME_VALUE is not a power of 2. Signed-off-by: Mattias Rönnblom --- lib/librte_eal/common/include/rte_random.h | 18 ++++++++++ lib/librte_eal/common/rte_random.c | 39 ++++++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 3 files changed, 58 insertions(+) diff --git a/lib/librte_eal/common/include/rte_random.h b/lib/librte_eal/common/include/rte_random.h index 66dfe8ae7..939e6aaa9 100644 --- a/lib/librte_eal/common/include/rte_random.h +++ b/lib/librte_eal/common/include/rte_random.h @@ -17,6 +17,8 @@ extern "C" { #include +#include + /** * Seed the pseudo-random generator. * @@ -47,6 +49,22 @@ rte_srand(uint64_t seedval); uint64_t rte_rand(void); +/** + * Generates a pseudo-random number with an upper bound. + * + * This function returns an uniformly distributed (unbiased) random + * number less than a user-specified maximum value. + * + * If called from lcore threads, this function is thread-safe. + * + * @param upper_bound + * The upper bound of the generated number. + * @return + * A pseudo-random value between 0 and (upper_bound-1). + */ +uint64_t __rte_experimental +rte_rand_max(uint64_t upper_bound); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/rte_random.c b/lib/librte_eal/common/rte_random.c index aafc2f7ad..0e8abbb1c 100644 --- a/lib/librte_eal/common/rte_random.c +++ b/lib/librte_eal/common/rte_random.c @@ -134,6 +134,45 @@ rte_rand(void) return __rte_rand_lfsr258(state); } +uint64_t __rte_experimental +rte_rand_max(uint64_t upper_bound) +{ + struct rte_rand_state *state; + uint8_t ones; + uint8_t leading_zeros; + uint64_t mask = ~((uint64_t)0); + uint64_t res; + + if (unlikely(upper_bound < 2)) + return 0; + + state = __rte_rand_get_state(); + + ones = __builtin_popcountll(upper_bound); + + /* Handle power-of-2 upper_bound as a special case, since it + * has no bias issues. + */ + if (unlikely(ones == 1)) + return __rte_rand_lfsr258(state) & (upper_bound - 1); + + /* The approach to avoiding bias is to create a mask that + * stretches beyond the request value range, and up to the + * next power-of-2. In case the masked generated random value + * is equal to or greater than the upper bound, just discard + * the value and generate a new one. + */ + + leading_zeros = __builtin_clzll(upper_bound); + mask >>= leading_zeros; + + do { + res = __rte_rand_lfsr258(state) & mask; + } while (unlikely(res >= upper_bound)); + + return res; +} + RTE_INIT(rte_rand_init) { uint64_t seed; diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index e615d7cb9..82483aed2 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -382,6 +382,7 @@ EXPERIMENTAL { rte_mp_request_async; rte_mp_sendmsg; rte_option_register; + rte_rand_max; rte_realloc_socket; rte_service_lcore_attr_get; rte_service_lcore_attr_reset_all; From patchwork Tue May 14 09:20:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 53398 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 19B165B1E; Tue, 14 May 2019 11:22:01 +0200 (CEST) Received: from sessmg22.ericsson.net (sessmg22.ericsson.net [193.180.251.58]) by dpdk.org (Postfix) with ESMTP id 9735F5398 for ; Tue, 14 May 2019 11:21:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1557825719; x=1560417719; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=emEpPp6la2DesqpGTlZk9fmNqO+dTPyXy9NhN852tTA=; b=cwrPbjMAT3il4k78wG9lzwzwSG8Oavy1VOkP1FU19EXVcgVXaPfKF+vE4XHnyI8x C+HcqQbnNppeaxBq0gwpxvhrROzj/RrpjkCRXq+8hmvOVYv/KCCLAFiT7mJsvsQ6 JMj0LGzUqRrFzJ2T42GKa+qMq9qfsmXt5sb5Ha/zcfQ=; X-AuditID: c1b4fb3a-709ff7000000189f-ca-5cda88b73ad5 Received: from ESESBMB501.ericsson.se (Unknown_Domain [153.88.183.114]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id FC.2B.06303.7B88ADC5; Tue, 14 May 2019 11:21:59 +0200 (CEST) Received: from ESESSMR504.ericsson.se (153.88.183.126) by ESESBMB501.ericsson.se (153.88.183.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:59 +0200 Received: from ESESSMB505.ericsson.se (153.88.183.166) by ESESSMR504.ericsson.se (153.88.183.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:21:59 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.193) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 May 2019 11:21:58 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id x4E9LQN9027252; Tue, 14 May 2019 11:21:58 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , , , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Tue, 14 May 2019 11:20:45 +0200 Message-ID: <20190514092046.30808-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514092046.30808-1-mattias.ronnblom@ericsson.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRmVeSWpSXmKPExsUyM2J7ke72jlsxBhP+i1vcWGVvsX1FF5vF u0/bmSxuNZ9ks1h8R86B1ePXgqWsHov3vGTy6Dk5j8nj/b6rbB5Xvq9mDGCN4rJJSc3JLEst 0rdL4Mr4ce03c8EG3orP146yNzB2cXcxcnJICJhInLn5l6mLkYtDSOAoo8SzdVNZIJxvjBI3 /7xhhXNebN/AAtIiJHCRUeLqi0iIxGVGiWu75oAl2AQ8JSa/6wazRQSEJJZ+vMwOUsQssJdR 4tW6eWAJYQEbiVsfVzF3MXJwsAioSlw8qAYS5hVwktg7ZRMzxE3yEqs3HACzOQWcJSZNucUO sThF4k/PIxaIekGJkzOfgNnMApoSrdt/s0PY8hLNW2czQ9RrSdxf8oV5AqPwLCQts5C0zELS soCReRWjaHFqcXFuupGRXmpRZnJxcX6eXl5qySZGYHQc3PLbagfjweeOhxgFOBiVeHhj02/F CLEmlhVX5h5ilOBgVhLhjVK8ESPEm5JYWZValB9fVJqTWnyIUZqDRUmcN3r1nhghgfTEktTs 1NSC1CKYLBMHp1QDo9d7lpBpYVP27JIOjzw37W6d0IGtkqqLuHPU/VOrtHorj059pOfDPte7 9sn0rUyOTkvXJbWc3CS9akGrC4PP1Ckq5s+4LF7FTzh6w4BRyTNrwj3LJzxltyb8kuW1/1di 25g976bVhz2XFXem8lqkrNG4mb3w8NGejF71XMlcrd5lz59N8Nl9RImlOCPRUIu5qDgRAOmP Dz6KAgAA Subject: [dpdk-dev] [PATCH 5/6] eal: add bounded PRNG performance tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add best- and worst-case performance tests for rte_rand_max(). Signed-off-by: Mattias Rönnblom --- app/test/test_rand_perf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/test/test_rand_perf.c b/app/test/test_rand_perf.c index 771713757..fe797ebfa 100644 --- a/app/test/test_rand_perf.c +++ b/app/test/test_rand_perf.c @@ -15,8 +15,13 @@ static volatile uint64_t vsum; #define ITERATIONS (100000000) +#define BEST_CASE_BOUND (1<<16) +#define WORST_CASE_BOUND (BEST_CASE_BOUND + 1) + enum rand_type { - rand_type_64 + rand_type_64, + rand_type_bounded_best_case, + rand_type_bounded_worst_case }; static const char * @@ -25,6 +30,10 @@ rand_type_desc(enum rand_type rand_type) switch (rand_type) { case rand_type_64: return "Full 64-bit [rte_rand()]"; + case rand_type_bounded_best_case: + return "Bounded average best-case [rte_rand_max()]"; + case rand_type_bounded_worst_case: + return "Bounded average worst-case [rte_rand_max()]"; default: return NULL; } @@ -46,6 +55,12 @@ test_rand_perf_type(enum rand_type rand_type) case rand_type_64: sum += rte_rand(); break; + case rand_type_bounded_best_case: + sum += rte_rand_max(BEST_CASE_BOUND); + break; + case rand_type_bounded_worst_case: + sum += rte_rand_max(WORST_CASE_BOUND); + break; } } @@ -68,6 +83,8 @@ test_rand_perf(void) printf("Pseudo-random number generation latencies:\n"); test_rand_perf_type(rand_type_64); + test_rand_perf_type(rand_type_bounded_best_case); + test_rand_perf_type(rand_type_bounded_worst_case); return 0; } From patchwork Tue May 14 09:20:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Mattias_R=C3=B6nnblom?= X-Patchwork-Id: 53399 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D0EC75F36; Tue, 14 May 2019 11:22:02 +0200 (CEST) Received: from sesbmg23.ericsson.net (sesbmg23.ericsson.net [193.180.251.37]) by dpdk.org (Postfix) with ESMTP id E9C625398 for ; Tue, 14 May 2019 11:22:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1557825720; x=1560417720; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ls8Mjm9CFGRB66jtIfCySrGPBQnZ0YUTZcME3NlHAqo=; b=eCPePIarsanYC5BWBVhge9joNU3Oj0gWXni8gVjkGJeKN37brjlbCFogJUcemf0B NX3x59WdooblP6EdPUdpp32wLDtheijV9G/ltxbyO4LeLI9xWpkANaAOA5vxrD11 m0NwdZot7hj0LgNFfnhTKVj9VrUBGvASNETp/0fGZd4=; X-AuditID: c1b4fb25-399ff700000029f0-13-5cda88b8d982 Received: from ESESSMB504.ericsson.se (Unknown_Domain [153.88.183.122]) by sesbmg23.ericsson.net (Symantec Mail Security) with SMTP id 33.30.10736.8B88ADC5; Tue, 14 May 2019 11:22:00 +0200 (CEST) Received: from ESESSMR505.ericsson.se (153.88.183.127) by ESESSMB504.ericsson.se (153.88.183.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:22:00 +0200 Received: from ESESSMB503.ericsson.se (153.88.183.164) by ESESSMR505.ericsson.se (153.88.183.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 14 May 2019 11:22:00 +0200 Received: from selio1a020.lmera.ericsson.se (153.88.183.153) by smtp.internal.ericsson.com (153.88.183.191) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Tue, 14 May 2019 11:22:00 +0200 Received: from breslau.lmera.ericsson.se (breslau.lmera.ericsson.se [150.132.109.241]) by selio1a020.lmera.ericsson.se (8.15.1+Sun/8.15.1) with ESMTP id x4E9LQNA027252; Tue, 14 May 2019 11:22:00 +0200 (CEST) From: =?utf-8?q?Mattias_R=C3=B6nnblom?= To: CC: , , , , =?utf-8?q?Mattias_R=C3=B6nnblom?= Date: Tue, 14 May 2019 11:20:46 +0200 Message-ID: <20190514092046.30808-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514092046.30808-1-mattias.ronnblom@ericsson.com> References: <20190508181014.7dde7580@xps13> <20190514092046.30808-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRmVeSWpSXmKPExsUyM2J7le6OjlsxBt1vtCxurLK32L6ii83i 3aftTBa3mk+yWSy+I+fA6vFrwVJWj8V7XjJ59Jycx+Txft9VNo8r31czBrBGcdmkpOZklqUW 6dslcGVcP7eCveAda8X797cYGxgbWLsYOTkkBEwkHl6czN7FyMUhJHCUUeJ8909GkISQwDdG ievf7CESQHb7xCdQVRcZJda8mMgM4VxmlHj8pR+shU3AU2Lyu24WEFtEQEhi6cfLYB3MAnsZ JV6tmweWEBbwkVhwaTlbFyMHB4uAqsSTizogYV4BJ4m+m1NZIG6Sl1i94QAziM0p4Cwxacot doiTUiT+9DxigagXlDg58wmYzSygKdG6/Tc7hC0v0bx1NjNEvZbE/SVfmCcwCs9C0jILScss JC0LGJlXMYoWpxYn5aYbGeulFmUmFxfn5+nlpZZsYgRGx8Etv1V3MF5+43iIUYCDUYmH1y/9 VowQa2JZcWXuIUYJDmYlEd4oxRsxQrwpiZVVqUX58UWlOanFhxilOViUxHmjV++JERJITyxJ zU5NLUgtgskycXBKNTDKSbf95XnjlNO/7PgGhwnr1sYoOQaszpVX2v3LhH3NWo+FVRt5Dn4p nrOhNIdt87Y3Lw6wv/wt9TXmpUVX4Twuy3+ul/V+pmR+Mfx6+eZqJpV7R4SOzIxPePJ35eGF Nrd+cy+33Mk/K2BVZRxPlqt3zGRx4dP5zzf22i7Li0k5lR1wfca/JfG2SizFGYmGWsxFxYkA uUceAIoCAAA= Subject: [dpdk-dev] [PATCH 6/6] eal: add pseudo-random number generation to MAINTAINERS X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a section on PRNG in MAINTAINERS. Signed-off-by: Mattias Rönnblom --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 15d0829c5..d06f5da90 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -222,6 +222,12 @@ M: Joyce Kong F: lib/librte_eal/common/include/generic/rte_ticketlock.h F: app/test/test_ticketlock.c +Pseudo-random Number Generation +M: Mattias Rönnblom +F: lib/librte_eal/common/include/rte_random.h +F: lib/librte_eal/common/rte_random.c +F: app/test/test_rand_perf.c + ARM v7 M: Jan Viktorin M: Gavin Hu