Thread (46 messages) flat view 46 messages, 10 authors, 2011-06-20
STALE5542d

[PATCH 4/5] tsc: wire up entropy generation function

From: Jarod Wilson <hidden>
Date: 2011-06-13 22:07:44
Subsystem: the rest, x86 architecture (32-bit and 64-bit) · Maintainers: Linus Torvalds, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen

TSC is high enough resolution that we can use its low-order byte to
stir new data into the random number generator entropy pool.

CC: Matt Mackall <redacted>
CC: "Venkatesh Pallipadi (Venki)" <redacted>
CC: Thomas Gleixner <redacted>
CC: Ingo Molnar <redacted>
CC: John Stultz <redacted>
CC: Herbert Xu <herbert@gondor.apana.org.au>
CC: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Jarod Wilson <redacted>
---
 arch/x86/kernel/tsc.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 6cc6922..d206ec3 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -10,6 +10,7 @@
 #include <linux/clocksource.h>
 #include <linux/percpu.h>
 #include <linux/timex.h>
+#include <linux/random.h>
 
 #include <asm/hpet.h>
 #include <asm/timer.h>
@@ -768,11 +769,28 @@ static void resume_tsc(struct clocksource *cs)
 	clocksource_tsc.cycle_last = 0;
 }
 
+static void tsc_add_entropy(void)
+{
+	static u64 last;
+	u64 counter;
+	int delta;
+
+	rdtscll(counter);
+	delta = (int)(counter - last);
+	last = counter;
+
+	if (delta == counter)
+		return;
+
+	add_clocksource_randomness(delta);
+}
+
 static struct clocksource clocksource_tsc = {
 	.name                   = "tsc",
 	.rating                 = 300,
 	.read                   = read_tsc,
 	.resume			= resume_tsc,
+	.entropy		= tsc_add_entropy,
 	.mask                   = CLOCKSOURCE_MASK(64),
 	.flags                  = CLOCK_SOURCE_IS_CONTINUOUS |
 				  CLOCK_SOURCE_MUST_VERIFY,
-- 
1.7.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help