Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/mips/cavium/dev CN70XX iobdma limit appears to be 1...



details:   https://anonhg.NetBSD.org/src/rev/569a9977b967
branches:  trunk
changeset: 933743:569a9977b967
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat May 30 03:12:52 2020 +0000

description:
CN70XX iobdma limit appears to be 128 words, so gather that many samples
as a time.
Gather the full 512 bytes of samples and process in a single call to
rnd_add_data_sync() - about 10% faster than 4 calls to rnd_add_data_sync().
Put sample buffer in the softc to save some stack usage.

diffstat:

 sys/arch/mips/cavium/dev/octeon_rnm.c |  34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)

diffs (87 lines):

diff -r 2c363a891143 -r 569a9977b967 sys/arch/mips/cavium/dev/octeon_rnm.c
--- a/sys/arch/mips/cavium/dev/octeon_rnm.c     Sat May 30 02:56:54 2020 +0000
+++ b/sys/arch/mips/cavium/dev/octeon_rnm.c     Sat May 30 03:12:52 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: octeon_rnm.c,v 1.6 2020/05/18 16:05:09 riastradh Exp $ */
+/*     $NetBSD: octeon_rnm.c,v 1.7 2020/05/30 03:12:52 simonb Exp $    */
 
 /*
  * Copyright (c) 2007 Internet Initiative Japan, Inc.
@@ -99,7 +99,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: octeon_rnm.c,v 1.6 2020/05/18 16:05:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: octeon_rnm.c,v 1.7 2020/05/30 03:12:52 simonb Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -123,6 +123,7 @@
 #define        RNG_FIFO_WORDS  (512/sizeof(uint64_t))
 
 struct octeon_rnm_softc {
+       uint64_t                sc_sample[RNG_FIFO_WORDS];
        bus_space_tag_t         sc_bust;
        bus_space_handle_t      sc_regh;
        kmutex_t                sc_lock;
@@ -222,8 +223,8 @@
 octeon_rnm_rng(size_t nbytes, void *vsc)
 {
        const unsigned BPB = 256; /* bits of data per bit of entropy */
-       uint64_t sample[32];
        struct octeon_rnm_softc *sc = vsc;
+       uint64_t *samplepos;
        size_t needed = NBBY*nbytes;
        unsigned i;
 
@@ -244,20 +245,21 @@
                octeon_rnm_raw_entropy(sc, sc->sc_rogroup);
 
                /*
-                * Gather half the FIFO at a time -- we are limited to
-                * 256 bytes because of limits on the CVMSEG buffer.
+                * Gather quarter the FIFO at a time -- we are limited
+                * to 128 bytes because of limits on the CVMSEG buffer.
                 */
-               CTASSERT(sizeof sample == 256);
-               CTASSERT(2*__arraycount(sample) == RNG_FIFO_WORDS);
-               for (i = 0; i < 2; i++) {
-                       octeon_rnm_iobdma(sc, sample, __arraycount(sample));
+               CTASSERT(sizeof sc->sc_sample == 512);
+               CTASSERT(__arraycount(sc->sc_sample) == RNG_FIFO_WORDS);
+               for (samplepos = sc->sc_sample, i = 0; i < 4; i++) {
+                       octeon_rnm_iobdma(sc, samplepos, RNG_FIFO_WORDS / 4);
+                       samplepos += RNG_FIFO_WORDS / 4;
+               }
 #ifdef OCTEON_RNM_DEBUG
-                       hexdump(printf, "rnm", sample, sizeof sample);
+               hexdump(printf, "rnm", sc->sc_sample, sizeof sc->sc_sample);
 #endif
-                       rnd_add_data_sync(&sc->sc_rndsrc, sample,
-                           sizeof sample, NBBY*sizeof(sample)/BPB);
-                       needed -= MIN(needed, MAX(1, NBBY*sizeof(sample)/BPB));
-               }
+               rnd_add_data_sync(&sc->sc_rndsrc, sc->sc_sample,
+                   sizeof sc->sc_sample, NBBY*sizeof(sc->sc_sample)/BPB);
+               needed -= MIN(needed, MAX(1, NBBY*sizeof(sc->sc_sample)/BPB));
 
                /* Yield if requested.  */
                if (__predict_false(curcpu()->ci_schedstate.spc_flags &
@@ -270,7 +272,7 @@
        mutex_exit(&sc->sc_lock);
 
        /* Zero the sample.  */
-       explicit_memset(sample, 0, sizeof sample);
+       explicit_memset(sc->sc_sample, 0, sizeof sc->sc_sample);
 }
 
 /*
@@ -366,7 +368,7 @@
            __SHIFTIN(RNM_IOBDMA_MAJORDID, IOBDMA_MAJORDID) |
            __SHIFTIN(RNM_IOBDMA_SUBDID, IOBDMA_SUBDID);
 
-       KASSERT(nwords < 256);  /* iobdma address restriction */
+       KASSERT(nwords < 128);  /* iobdma address restriction */
        KASSERT(nwords <= 32);  /* octeon_cvmseg_map limitation */
 
        octeon_iobdma_write_8(iobdma);



Home | Main Index | Thread Index | Old Index