From patchwork Mon Dec 11 14:06:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukasz Stelmach X-Patchwork-Id: 10105183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99491602A7 for ; Mon, 11 Dec 2017 14:06:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A30D9295FA for ; Mon, 11 Dec 2017 14:06:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97B9B29605; Mon, 11 Dec 2017 14:06:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB88295FA for ; Mon, 11 Dec 2017 14:06:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753045AbdLKOGu (ORCPT ); Mon, 11 Dec 2017 09:06:50 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:51095 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752869AbdLKOGl (ORCPT ); Mon, 11 Dec 2017 09:06:41 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20171211140639euoutp01c25e4d931c77d3b6e55697748b4c5dee~-QpMD4tvQ2775827758euoutp01m; Mon, 11 Dec 2017 14:06:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20171211140639euoutp01c25e4d931c77d3b6e55697748b4c5dee~-QpMD4tvQ2775827758euoutp01m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1513001199; bh=Cq0SLas83FYPVwrJ3WcsSkQ5dMGKomaw+W2sBLkvAO0=; h=From:To:Cc:Subject:Date:In-reply-to:In-reply-to:References:From; b=Jy8UFny92gGnY3Ol+aTO1+DAIGGlwOyiLPuU9IKeV3ymFla4263Ak3NSL3moZDstP LNT022PH3/TjPCUdr+pXycOgY8UzFa7bryct3K6G52OUvavQf/2cSiQfgAuYBqIHMu H8GejCp6mijtYWJUbBMotG71RrKsnJZsHOESjS8s= Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171211140638eucas1p1d64d70ccfbf526a8f42d0719d49c60d5~-QpLWCZAe0545305453eucas1p15; Mon, 11 Dec 2017 14:06:38 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3.samsung.com (EUCPMTA) with SMTP id 0D.30.12867.DE09E2A5; Mon, 11 Dec 2017 14:06:37 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171211140637eucas1p2ebe62e41964d2ea55a1b1be488f3694a~-QpKiKcue0694806948eucas1p2a; Mon, 11 Dec 2017 14:06:37 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-8c-5a2e90ed95c3 Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id D8.A3.20118.DE09E2A5; Mon, 11 Dec 2017 14:06:37 +0000 (GMT) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset="UTF-8" Received: from localhost ([106.116.147.110]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P0S00I7AV71SHB0@eusync2.samsung.com>; Mon, 11 Dec 2017 14:06:37 +0000 (GMT) From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= To: Krzysztof Kozlowski , robh+dt@kernel.org, Stephan Mueller , Herbert Xu , "David S . Miller" , Kukjin Kim , linux-crypto@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?=C5=81ukasz=20Stelmach?= , Marek Szyprowski , Bartlomiej Zolnierkiewicz Subject: [PATCH v2 2/4] crypto: exynos - Improve performance of PRNG Date: Mon, 11 Dec 2017 15:06:21 +0100 Message-id: <20171211140623.7673-3-l.stelmach@samsung.com> X-Mailer: git-send-email 2.11.0 In-reply-to: <20171211140623.7673-1-l.stelmach@samsung.com> In-reply-to: <20171205123558.31087-1-l.stelmach@samsung.com> Organization: Samsung R&D Institute Poland X-Brightmail-Tracker: H4sIAAAAAAAAA02Sa0hTYRjHec/Zzo7iyeO0fFBxtvJD5qWw4KAmBhIjUoJCaF9y5UFFp7Kp ZR9Ey80bOa81TJhSlpfE+9J5KafkLZulEH5IJbHMzLykaUnk8Uzy2+95/+/zPO//z0viYpPQ hYxNSGZVCYp4KWErML7efuvzvdBXfir7RSDTrG8UMhWWLAGTv+jG6Oa+4YzF0iRipsw1iJmZ 3saYCVMFwegtvRjTMPBRxGh6BkRM2WiDIMROtjY5icnaaqcwmfGVp6ylLpeQFbTVIdl6i/tl Qm4bFMXGx6ayKr/gSNuYrx2ZRFKn8+3S2SVBBtoR5yEbEugzYNzeEvF8BManG4k8ZEuK6WoE yx0/BHyxjqDpiVa03zE+s4JzLKafIujc9OCYoh1gq2R6t4EkcVoCA+/juGOcPgHtXY0ifs5P BN3NrRgnEPR50FUPCTnBie7FYK6oDHEFzg3tMw4T3C1HOhTyauv3WEB7wnbmKMFvC4AmywjO v0gCJu07Icc2dCDkDmYTPAdB1Zh+j+1pL3h+98OeHaBLRKCb77HaCYXe+WErO8LiYJuV3WCi JN/a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akFqEUyWiYNT qoFxc7rGRBalDfV932a43vAJXFrO/+V18rPY+VaecVv5beMnRMjF7msKa1rTq/fy2YomG8aA i3w794b/FJIxvaUYtUZlZcGB5y32fzvOCK3RO5/qP8nqlcjmWrmKLMfUT4ua/H6zzNr6gedC Y0AMd+y306ms0Sy6AnJLSruK8rbkb+bY7LzpTLsSS3FGoqEWc1FxIgCAl8JerAIAAA== X-CMS-MailID: 20171211140637eucas1p2ebe62e41964d2ea55a1b1be488f3694a X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20171211140637eucas1p2ebe62e41964d2ea55a1b1be488f3694a X-RootMTR: 20171211140637eucas1p2ebe62e41964d2ea55a1b1be488f3694a References: <20171211140623.7673-1-l.stelmach@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Cc: Marek Szyprowski , Bartlomiej Zolnierkiewicz Use memcpy_fromio() instead of custom exynos_rng_copy_random() function to retrieve generated numbers from the registers of PRNG. Rearrange the loop around cpu_relax(). In a loop with while() at the beginning and the cpu_relax() removed the retry variable is decremented twice (down to 98). This means, the status register is read three times before the hardware is ready (which is very quick). Apparently, cpu_relax() requires noticeable amount of time to execute, so it seems better to call it for the first time before checking the status of PRNG. The do {} while () loop decrements the retry variable only once, which means, the time required for cpu_relax() is long enough to for the PRNG to provide results. On the other hand, performance in this arrangement isn't much worse than in a loop without cpu_relax(). Signed-off-by: Ɓukasz Stelmach --- drivers/crypto/exynos-rng.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/drivers/crypto/exynos-rng.c b/drivers/crypto/exynos-rng.c index 2f554b82f49f..7d8f658480d3 100644 --- a/drivers/crypto/exynos-rng.c +++ b/drivers/crypto/exynos-rng.c @@ -131,34 +131,6 @@ static int exynos_rng_set_seed(struct exynos_rng_dev *rng, } /* - * Read from output registers and put the data under 'dst' array, - * up to dlen bytes. - * - * Returns number of bytes actually stored in 'dst' (dlen - * or EXYNOS_RNG_SEED_SIZE). - */ -static unsigned int exynos_rng_copy_random(struct exynos_rng_dev *rng, - u8 *dst, unsigned int dlen) -{ - unsigned int cnt = 0; - int i, j; - u32 val; - - for (j = 0; j < EXYNOS_RNG_SEED_REGS; j++) { - val = exynos_rng_readl(rng, EXYNOS_RNG_OUT(j)); - - for (i = 0; i < 4; i++) { - dst[cnt] = val & 0xff; - val >>= 8; - if (++cnt >= dlen) - return cnt; - } - } - - return cnt; -} - -/* * Start the engine and poll for finish. Then read from output registers * filling the 'dst' buffer up to 'dlen' bytes or up to size of generated * random data (EXYNOS_RNG_SEED_SIZE). @@ -180,9 +152,10 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, EXYNOS_RNG_SEED_CONF); } - while (!(exynos_rng_readl(rng, - EXYNOS_RNG_STATUS) & EXYNOS_RNG_STATUS_RNG_DONE) && --retry) + do { cpu_relax(); + } while (!(exynos_rng_readl(rng, EXYNOS_RNG_STATUS) & + EXYNOS_RNG_STATUS_RNG_DONE) && --retry); if (!retry) return -ETIMEDOUT; @@ -190,7 +163,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev *rng, /* Clear status bit */ exynos_rng_writel(rng, EXYNOS_RNG_STATUS_RNG_DONE, EXYNOS_RNG_STATUS); - *read = exynos_rng_copy_random(rng, dst, dlen); + *read = min_t(size_t, dlen, EXYNOS_RNG_SEED_SIZE); + memcpy_fromio(dst, rng->mem + EXYNOS_RNG_OUT_BASE, *read); return 0; }