From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, tglx@linutronix.de
Subject: [PATCH] [1/2] Use an own random generator for pageattr-test.c
Date: Tue, 4 Mar 2008 18:34:48 +0100 (CET) [thread overview]
Message-ID: <20080304634.504158800@firstfloor.org> (raw)
pageattr-test attempts to be repeatable and uses srandom32 to get a
repeatable random number sequence.
Using srandom32() wasn't a good idea for various reasons:
- it is per cpu and if the cpu changes on a preemptible kernel it gets lost
- networking and random32 puts in some own state
- srandom32() does not actually reset the state, but just adds bits to
it
Instead use a very simple private standard rnd that gives repeatable
results. I took the reference rand() from ISO-C.
Signed-off-by: Andi Kleen <ak@suse.de>
Index: linux/arch/x86/mm/pageattr-test.c
===================================================================
--- linux.orig/arch/x86/mm/pageattr-test.c
+++ linux/arch/x86/mm/pageattr-test.c
@@ -101,6 +101,14 @@ static int print_split(struct split_stat
static unsigned long addr[NTEST];
static unsigned int len[NTEST];
+static int next = 100;
+
+static unsigned my_rand(void)
+{
+ next = next * 1103515245 + 12345;
+ return next;
+}
+
/* Change the global bit on random pages in the direct mapping */
static int pageattr_test(void)
{
@@ -123,10 +131,9 @@ static int pageattr_test(void)
memset(bm, 0, (max_pfn_mapped + 7) / 8);
failed += print_split(&sa);
- srandom32(100);
for (i = 0; i < NTEST; i++) {
- unsigned long pfn = random32() % max_pfn_mapped;
+ unsigned long pfn = my_rand() % max_pfn_mapped;
addr[i] = (unsigned long)__va(pfn << PAGE_SHIFT);
len[i] = random32() % 100;
next reply other threads:[~2008-03-04 17:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-04 17:34 Andi Kleen [this message]
2008-03-04 17:34 ` [PATCH] [2/2] srandom32 fixes Andi Kleen
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=20080304634.504158800@firstfloor.org \
--to=andi@firstfloor.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tglx@linutronix.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;
as well as URLs for NNTP newsgroup(s).