From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 339EDA00E6 for ; Tue, 14 May 2019 11:21:53 +0200 (CEST) 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=20R=C3=B6nnblom?= To: CC: , , , , =?UTF-8?q?Mattias=20R=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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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" Message-ID: <20190514092043.9ZENiG_P54ZpguaFUUOcBhFDr6q5uONYP7aJWdV_0mg@z> 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); } -- 2.17.1