public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, josht@linux.vnet.ibm.com,
	dipankar@in.ibm.com, bunk@kernel.org
Subject: [PATCH] Make rcutorture RNG use locally grown entropy
Date: Fri, 10 Aug 2007 17:41:29 -0700	[thread overview]
Message-ID: <20070811004129.GA26356@linux.vnet.ibm.com> (raw)

This patch converts rcutorture's random-number generator from
get_random_bytes() (which has locking issues in some builds with patches)
to instead use local-to-rcutorture statistical counters.  This involves
reading other CPUs' statistics, so the frequency of entropy addition
is simultaneously decreased by an order of magnitude.

This patch is an alternative to adding an EXPORT_SYMBOL_GPL() for the new
cpu_clock() API.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---

 rcutorture.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff -urpNa -X dontdiff linux-2.6.22.1-rt4/kernel/rcutorture.c linux-2.6.22.1-rt4-rcutorturesched/kernel/rcutorture.c
--- linux-2.6.22.1-rt4/kernel/rcutorture.c	2007-07-21 16:58:22.000000000 -0700
+++ linux-2.6.22.1-rt4-rcutorturesched/kernel/rcutorture.c	2007-08-10 08:42:41.000000000 -0700
@@ -155,26 +155,27 @@ rcu_torture_free(struct rcu_torture *p)
 struct rcu_random_state {
 	unsigned long rrs_state;
 	long rrs_count;
+	int rrs_cpu;
 };
 
 #define RCU_RANDOM_MULT 39916801  /* prime */
 #define RCU_RANDOM_ADD	479001701 /* prime */
-#define RCU_RANDOM_REFRESH 10000
+#define RCU_RANDOM_REFRESH 100000
 
 #define DEFINE_RCU_RANDOM(name) struct rcu_random_state name = { 0, 0 }
 
 /*
  * Crude but fast random-number generator.  Uses a linear congruential
- * generator, with occasional help from get_random_bytes().
+ * generator, with occasional help from other CPUs' fast-running statistics.
  */
 static unsigned long
 rcu_random(struct rcu_random_state *rrsp)
 {
-	long refresh;
-
 	if (--rrsp->rrs_count < 0) {
-		get_random_bytes(&refresh, sizeof(refresh));
-		rrsp->rrs_state += refresh;
+		rrsp->rrs_cpu = next_cpu(rrsp->rrs_cpu, cpu_online_map);
+		if (rrsp->rrs_cpu >= NR_CPUS)
+			rrsp->rrs_cpu = 0;
+		rrsp->rrs_state += per_cpu(rcu_torture_count, rrsp->rrs_cpu)[0];
 		rrsp->rrs_count = RCU_RANDOM_REFRESH;
 	}
 	rrsp->rrs_state = rrsp->rrs_state * RCU_RANDOM_MULT + RCU_RANDOM_ADD;

                 reply	other threads:[~2007-08-11  0:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20070811004129.GA26356@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@kernel.org \
    --cc=dipankar@in.ibm.com \
    --cc=josht@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /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