[PATCH 19/22] /dev/random: use sched_clock for timing data

From: Matt Mackall
Date: Thu Mar 25 2004 - 19:29:51 EST



/dev/random use sched_clock for timing data

Use the sched_clock() source for timing data, to get jiffies or better
resolution on all arches.


tiny-mpm/drivers/char/random.c | 21 +++++++++------------
1 files changed, 9 insertions(+), 12 deletions(-)

diff -puN drivers/char/random.c~random-sched-clock drivers/char/random.c
--- tiny/drivers/char/random.c~random-sched-clock 2004-03-20 13:38:46.000000000 -0600
+++ tiny-mpm/drivers/char/random.c 2004-03-20 13:38:46.000000000 -0600
@@ -250,6 +250,7 @@
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/percpu.h>
+#include <linux/sched.h>

#include <asm/processor.h>
#include <asm/uaccess.h>
@@ -711,7 +712,8 @@ static struct timer_rand_state *irq_time
*/
static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
{
- __u32 time;
+ long long clock;
+ u32 time;
__s32 delta, delta2, delta3;
int entropy = 0;

@@ -720,17 +722,8 @@ static void add_timer_randomness(struct
(__get_cpu_var(trickle_count)++ & 0xfff))
return;

-#if defined (__i386__) || defined (__x86_64__)
- if (cpu_has_tsc) {
- __u32 high;
- rdtsc(time, high);
- num ^= high;
- } else {
- time = jiffies;
- }
-#else
+ /* Use slow clock for conservative entropy estimation */
time = jiffies;
-#endif

/*
* Calculate number of bits of randomness we probably added.
@@ -765,7 +758,11 @@ static void add_timer_randomness(struct
*/
entropy = min_t(int, fls(delta>>1), 11);
}
- batch_entropy_store(num, time, entropy);
+
+ /* Mix in fast clock for entropy data */
+ clock = sched_clock();
+ num ^= clock >> 32;
+ batch_entropy_store(num, time ^ (u32)clock, entropy);
}

void add_keyboard_randomness(unsigned char scancode)

_
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/