From: Krzysztof Kozlowski <krzk@kernel.org>
To: "Łukasz Stelmach" <l.stelmach@samsung.com>
Cc: Stephan Mueller <smueller@chronox.de>,
robh+dt@kernel.org, Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Kukjin Kim <kgene@kernel.org>,
linux-crypto@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
linux-kernel@vger.kernel.org, m.szyprowski@samsung.com,
b.zolnierkie@samsung.com
Subject: Re: [PATCH 2/3] crypto: exynos - Improve performance of PRNG
Date: Tue, 5 Dec 2017 18:53:31 +0100 [thread overview]
Message-ID: <20171205175331.psayjpxolxv5vg3t@kozik-lap> (raw)
In-Reply-To: <87zi6x9lcx.fsf%l.stelmach@samsung.com>
On Tue, Dec 05, 2017 at 05:43:10PM +0100, Łukasz Stelmach wrote:
> It was <2017-12-05 wto 14:54>, when Stephan Mueller wrote:
> > Am Dienstag, 5. Dezember 2017, 13:35:57 CET schrieb Łukasz Stelmach:
> >
> > Hi Łukasz,
> >
> >> Use memcpy_fromio() instead of custom exynos_rng_copy_random() function
> >> to retrieve generated numbers from the registers of PRNG.
> >>
> >> Remove unnecessary invocation of cpu_relax().
> >>
> >> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> >> ---
> >> 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 894ef93ef5ec..002e9d2a83cc 100644
> >> --- a/drivers/crypto/exynos-rng.c
> >> +++ b/drivers/crypto/exynos-rng.c
>
> [...]
>
> >> @@ -171,6 +143,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev
> >> *rng, {
> >> int retry = EXYNOS_RNG_WAIT_RETRIES;
> >>
> >> + *read = min_t(size_t, dlen, EXYNOS_RNG_SEED_SIZE);
> >> +
> >> if (rng->type == EXYNOS_PRNG_TYPE4) {
> >> exynos_rng_writel(rng, EXYNOS_RNG_CONTROL_START,
> >> EXYNOS_RNG_CONTROL);
> >> @@ -180,8 +154,8 @@ static int exynos_rng_get_random(struct exynos_rng_dev
> >> *rng, }
> >>
> >> while (!(exynos_rng_readl(rng,
> >> - EXYNOS_RNG_STATUS) & EXYNOS_RNG_STATUS_RNG_DONE) && --retry)
> >> - cpu_relax();
> >> + EXYNOS_RNG_STATUS) & EXYNOS_RNG_STATUS_RNG_DONE) &&
> >> + --retry);
> SM>
> SM> Is this related to the patch?
>
> KK> It looks like unrelated change so split it into separate commit with
> KK> explanation why you are changing the common busy-loop pattern.
> KK> exynos_rng_readl() uses relaxed versions of readl() so I would expect
> KK> here cpu_relax().
>
> Yes. As far as I can tell this gives the major part of the performance
> improvement brought by this patch.
In that case definitely split and explain... what and why you want to
achieve here.
>
> The busy loop is not very busy. Every time I checked the loop (w/o
> cpu_relax()) was executed twice (retry was 98) and the operation was
> reliable. I don't see why do we need a memory barrier here. On the other
> hand, I am not sure the whole exynos_rng_get_random() shouldn't be ran
> under a mutex or a spinlock (I don't see anything like this in the upper
> layers of the crypto framework).
>
> The *_relaxed() I/O operations do not enforce memory
The cpu_relax() is a common pattern for busy-loop. If you want to break
this pattern - please explain why only this part of kernel should not
follow it (and rest of kernel should).
The other part - this code is already using relaxed versions which might
get you into difficult to debug issues. You mentioned that loop works
reliable after removing the cpu_relax... yeah, it might for 99.999% but
that's not the argument. I remember few emails from Arnd Bergmann
mentioning explicitly to avoid using relaxed versions "just because",
unless it is necessary or really understood.
The code first writes to control register, then checks for status so you
should have these operations strictly ordered. Therefore I think
cpu_relax() should not be removed.
Best regards,
Krzysztof
next prev parent reply other threads:[~2017-12-05 17:53 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20171205123601eucas1p2ef1a2fdce84dce8dc4b54c419ce566a7@eucas1p2.samsung.com>
2017-12-05 12:35 ` [PATCH 0/3] Assorted changes for Exynos PRNG driver Łukasz Stelmach
[not found] ` <CGME20171205123602eucas1p2d3ee1e53adc35df7c52917d43bcdebfd@eucas1p2.samsung.com>
2017-12-05 12:35 ` [PATCH 1/3] crypto: exynos - Support Exynos5250+ SoCs Łukasz Stelmach
2017-12-05 13:34 ` Krzysztof Kozlowski
[not found] ` <CGME20171206134305eucas1p218c38b977c14cae58763586458c3e78d@eucas1p2.samsung.com>
2017-12-06 13:42 ` Łukasz Stelmach
2017-12-06 14:05 ` Krzysztof Kozlowski
[not found] ` <CGME20171206145312eucas1p226d52f60f15e45456aefd6270cc88e07@eucas1p2.samsung.com>
2017-12-06 14:53 ` Łukasz Stelmach
2017-12-06 15:28 ` Krzysztof Kozlowski
[not found] ` <CGME20171207092032eucas1p296f7cbc547d159c52561182cc6461504@eucas1p2.samsung.com>
2017-12-07 9:20 ` Łukasz Stelmach
2017-12-06 17:56 ` Joe Perches
[not found] ` <CGME20171205123603eucas1p177cceb022e3a5c0a9d13ca437c05b669@eucas1p1.samsung.com>
2017-12-05 12:35 ` [PATCH 2/3] crypto: exynos - Improve performance of PRNG Łukasz Stelmach
2017-12-05 13:49 ` Krzysztof Kozlowski
2017-12-05 13:54 ` Stephan Mueller
[not found] ` <CGME20171205164319eucas1p1e79b9798d655851762cc83a6737b73b4@eucas1p1.samsung.com>
2017-12-05 16:43 ` Łukasz Stelmach
2017-12-05 17:53 ` Krzysztof Kozlowski [this message]
2017-12-05 18:06 ` Krzysztof Kozlowski
[not found] ` <CGME20171206113301eucas1p23da9decc34cc646b0bf4eb88953ef94a@eucas1p2.samsung.com>
2017-12-06 11:32 ` Łukasz Stelmach
2017-12-06 11:37 ` Krzysztof Kozlowski
[not found] ` <CGME20171206130651eucas1p22b5d0799f2a128d3d9efcc799fc3cfdc@eucas1p2.samsung.com>
2017-12-06 13:06 ` Łukasz Stelmach
[not found] ` <CGME20171205123604eucas1p2a6a2738e3cf1f9c300e8d128362429ed@eucas1p2.samsung.com>
2017-12-05 12:35 ` [PATCH 3/3] crypto: exynos - Reseed PRNG after generating 2^16 random bytes Łukasz Stelmach
2017-12-05 13:52 ` Stephan Mueller
2017-12-05 13:55 ` Krzysztof Kozlowski
[not found] ` <CGME20171211140635eucas1p22ab5dac69623926c583779a6b93872ce@eucas1p2.samsung.com>
2017-12-11 14:06 ` [PATCH v2 0/4] Assorted changes for Exynos PRNG driver Łukasz Stelmach
[not found] ` <CGME20171212163609eucas1p2aaee0a21276b66f4cb492a4502f66756@eucas1p2.samsung.com>
2017-12-12 16:36 ` [PATCH v3 " Łukasz Stelmach
2017-12-22 9:09 ` Herbert Xu
2017-12-12 16:36 ` [PATCH v3 1/4] crypto: exynos - Support Exynos5250+ SoCs Łukasz Stelmach
2017-12-13 8:06 ` Krzysztof Kozlowski
2017-12-12 16:36 ` [PATCH v3 2/4] crypto: exynos - Improve performance of PRNG Łukasz Stelmach
2017-12-13 8:07 ` Krzysztof Kozlowski
2017-12-12 16:36 ` [PATCH v3 3/4] crypto: exynos - Reseed PRNG after generating 2^16 random bytes Łukasz Stelmach
2017-12-13 8:12 ` Krzysztof Kozlowski
2017-12-12 16:36 ` [PATCH v3 4/4] crypto: exynos - Introduce mutex to prevent concurrent access to hardware Łukasz Stelmach
2017-12-11 14:06 ` [PATCH v2 1/4] crypto: exynos - Support Exynos5250+ SoCs Łukasz Stelmach
2017-12-11 14:36 ` Krzysztof Kozlowski
2017-12-11 14:06 ` [PATCH v2 2/4] crypto: exynos - Improve performance of PRNG Łukasz Stelmach
2017-12-11 14:54 ` Krzysztof Kozlowski
[not found] ` <CGME20171212144953eucas1p2079156cb46dc72e2a73868ca2d88ba05@eucas1p2.samsung.com>
2017-12-12 14:49 ` Łukasz Stelmach
2017-12-11 14:06 ` [PATCH v2 3/4] crypto: exynos - Reseed PRNG after generating 2^16 random bytes Łukasz Stelmach
2017-12-11 14:57 ` Krzysztof Kozlowski
2017-12-11 14:06 ` [PATCH v2 4/4] crypto: exynos - Introduce mutex to prevent concurrent access to hardware Łukasz Stelmach
2017-12-11 15:03 ` Krzysztof Kozlowski
[not found] ` <CGME20171212103021eucas1p19a2a24930cadde55eac2f822a6a9f80c@eucas1p1.samsung.com>
2017-12-12 10:30 ` Łukasz Stelmach
2017-12-12 11:09 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171205175331.psayjpxolxv5vg3t@kozik-lap \
--to=krzk@kernel.org \
--cc=b.zolnierkie@samsung.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kgene@kernel.org \
--cc=l.stelmach@samsung.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robh+dt@kernel.org \
--cc=smueller@chronox.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®