1 #include <xen/cache.h>
2 #include <xen/init.h>
3 #include <xen/percpu.h>
4 #include <xen/random.h>
5 #include <xen/time.h>
6 #include <asm/random.h>
7 
8 static DEFINE_PER_CPU(unsigned int, seed);
9 unsigned int __read_mostly boot_random;
10 
get_random(void)11 unsigned int get_random(void)
12 {
13     unsigned int next = this_cpu(seed), val = arch_get_random();
14 
15     if ( unlikely(!next) )
16         next = val ?: NOW();
17 
18     if ( !val )
19     {
20         unsigned int i;
21 
22         for ( i = 0; i < sizeof(val) * 8; i += 11 )
23         {
24             next = next * 1103515245 + 12345;
25             val |= ((next >> 16) & 0x7ff) << i;
26         }
27     }
28 
29     this_cpu(seed) = next;
30 
31     return val;
32 }
33 
init_boot_random(void)34 static int __init init_boot_random(void)
35 {
36     boot_random = get_random();
37     return 0;
38 }
39 __initcall(init_boot_random);
40