From: Andrew Morton <akpm@osdl.org>
To: davidm@hpl.hp.com
Cc: davidm@napali.hpl.hp.com, mpm@selenic.com, linux-kernel@vger.kernel.org
Subject: Re: Fw: potential /dev/urandom scalability improvement
Date: Thu, 25 Mar 2004 18:00:14 -0800 [thread overview]
Message-ID: <20040325180014.29e40b65.akpm@osdl.org> (raw)
In-Reply-To: <16483.35656.864787.827149@napali.hpl.hp.com>
David Mosberger <davidm@napali.hpl.hp.com> wrote:
>
> The
> patch below is updated to go on top of your patch and gives about the
> same performance as I reported yesterday. For now, I defined an
> inline prefetch_range(). If and when all architectures get updated to
> define this directly, we can simply remove prefetch_range() from the
> driver.
We may as well stick prefetch_range() in prefetch.h.
And Matt's patch series is not a thing I want to take on board at present,
so let's stick with the straight scalability patch for now.
I moved the prefetch_range() call to outside the spinlock. Does that make
sense?
25-akpm/drivers/char/random.c | 51 ++++++++++++++++++++++++++-------------
25-akpm/include/linux/prefetch.h | 11 ++++++++
2 files changed, 46 insertions(+), 16 deletions(-)
diff -puN drivers/char/random.c~urandom-scalability-fix drivers/char/random.c
--- 25/drivers/char/random.c~urandom-scalability-fix 2004-03-25 17:53:57.498675480 -0800
+++ 25-akpm/drivers/char/random.c 2004-03-25 17:57:39.795881168 -0800
@@ -490,12 +490,15 @@ static inline __u32 int_ln_12bits(__u32
**********************************************************************/
struct entropy_store {
+ /* mostly-read data: */
+ struct poolinfo poolinfo;
+ __u32 *pool;
+
+ /* read-write data: */
+ spinlock_t lock ____cacheline_aligned;
unsigned add_ptr;
int entropy_count;
int input_rotate;
- struct poolinfo poolinfo;
- __u32 *pool;
- spinlock_t lock;
};
/*
@@ -571,38 +574,54 @@ static void add_entropy_words(struct ent
static __u32 const twist_table[8] = {
0, 0x3b6e20c8, 0x76dc4190, 0x4db26158,
0xedb88320, 0xd6d6a3e8, 0x9b64c2b0, 0xa00ae278 };
- unsigned i;
- int new_rotate;
+ unsigned long i, add_ptr, tap1, tap2, tap3, tap4, tap5;
+ int new_rotate, input_rotate;
int wordmask = r->poolinfo.poolwords - 1;
- __u32 w;
+ __u32 w, next_w;
unsigned long flags;
+ /* Taps are constant, so we can load them without holding r->lock. */
+ tap1 = r->poolinfo.tap1;
+ tap2 = r->poolinfo.tap2;
+ tap3 = r->poolinfo.tap3;
+ tap4 = r->poolinfo.tap4;
+ tap5 = r->poolinfo.tap5;
+ next_w = *in++;
+
+ prefetch_range(r->pool, wordmask);
spin_lock_irqsave(&r->lock, flags);
+ input_rotate = r->input_rotate;
+ add_ptr = r->add_ptr;
while (nwords--) {
- w = rotate_left(r->input_rotate, *in++);
- i = r->add_ptr = (r->add_ptr - 1) & wordmask;
+ w = rotate_left(input_rotate, next_w);
+ if (nwords > 0)
+ next_w = *in++;
+ i = add_ptr = (add_ptr - 1) & wordmask;
/*
* Normally, we add 7 bits of rotation to the pool.
* At the beginning of the pool, add an extra 7 bits
* rotation, so that successive passes spread the
* input bits across the pool evenly.
*/
- new_rotate = r->input_rotate + 14;
+ new_rotate = input_rotate + 14;
if (i)
- new_rotate = r->input_rotate + 7;
- r->input_rotate = new_rotate & 31;
+ new_rotate = input_rotate + 7;
+ input_rotate = new_rotate & 31;
/* XOR in the various taps */
- w ^= r->pool[(i + r->poolinfo.tap1) & wordmask];
- w ^= r->pool[(i + r->poolinfo.tap2) & wordmask];
- w ^= r->pool[(i + r->poolinfo.tap3) & wordmask];
- w ^= r->pool[(i + r->poolinfo.tap4) & wordmask];
- w ^= r->pool[(i + r->poolinfo.tap5) & wordmask];
+ w ^= r->pool[(i + tap1) & wordmask];
+ w ^= r->pool[(i + tap2) & wordmask];
+ w ^= r->pool[(i + tap3) & wordmask];
+ w ^= r->pool[(i + tap4) & wordmask];
+ w ^= r->pool[(i + tap5) & wordmask];
w ^= r->pool[i];
r->pool[i] = (w >> 3) ^ twist_table[w & 7];
}
+ r->input_rotate = input_rotate;
+ r->add_ptr = add_ptr;
+
spin_unlock_irqrestore(&r->lock, flags);
}
diff -puN include/linux/prefetch.h~urandom-scalability-fix include/linux/prefetch.h
--- 25/include/linux/prefetch.h~urandom-scalability-fix 2004-03-25 17:54:27.279148160 -0800
+++ 25-akpm/include/linux/prefetch.h 2004-03-25 17:55:34.456935584 -0800
@@ -54,4 +54,15 @@ static inline void prefetchw(const void
#define PREFETCH_STRIDE (4*L1_CACHE_BYTES)
#endif
+static inline void prefetch_range(void *addr, size_t len)
+{
+#ifdef ARCH_HAS_PREFETCH
+ char *cp;
+ char *end = addr + len;
+
+ for (cp = addr; cp < end; cp += PREFETCH_STRIDE)
+ prefetch(cp);
+#endif
+}
+
#endif
_
next prev parent reply other threads:[~2004-03-26 2:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20040325141923.7080c6f0.akpm@osdl.org>
2004-03-25 22:47 ` Matt Mackall
2004-03-26 1:45 ` David Mosberger
2004-03-26 2:00 ` Andrew Morton [this message]
2004-03-26 2:10 ` David Mosberger
2004-03-26 4:07 ` Matt Mackall
2004-03-26 4:19 ` Matt Mackall
2004-03-26 4:51 ` David Mosberger
2004-03-26 5:15 ` Matt Mackall
2004-03-26 5:24 ` David Mosberger
2004-03-26 11:06 ` Dave Jones
2004-03-26 18:08 ` David Mosberger
2004-03-26 18:23 ` Dave Jones
2004-03-26 21:31 ` David Mosberger
2004-03-26 18:49 ` Andrew Morton
2004-03-26 20:25 ` David Mosberger
2004-03-26 20:33 ` Andrew Morton
2004-03-26 20:45 ` Arjan van de Ven
2004-03-26 21:17 ` Andrew Morton
2004-03-27 7:44 ` Arjan van de Ven
2004-03-26 21:12 ` David Mosberger
[not found] <1DLZM-8aK-67@gated-at.bofh.it>
[not found] ` <1DLZM-8aK-65@gated-at.bofh.it>
[not found] ` <1DOE1-20o-17@gated-at.bofh.it>
[not found] ` <1DOXn-2k7-5@gated-at.bofh.it>
[not found] ` <1DXxI-Z7-39@gated-at.bofh.it>
[not found] ` <1E467-6KK-17@gated-at.bofh.it>
[not found] ` <1E4IT-7f3-21@gated-at.bofh.it>
2004-03-27 1:29 ` Andi Kleen
2004-03-27 15:48 ` Matt Mackall
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=20040325180014.29e40b65.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=davidm@hpl.hp.com \
--cc=davidm@napali.hpl.hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
/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®