on some old AMD CPU(eg: older then AMD EPYC 7K62) , rdrand is slowly,
random using rdrand to make the random num more hard to be guessed.
while the randomness is not really affect by rdrand.
when user not using random for security case, (eg: just geting some
random num, not using it to generate password) using rdrand on old
amd processor is so expensive.
so, add a swith to rdrand, by default using the rdrand, when closed
using tsc, jiffies, and entropy from the fast_pool to emulate the rdrand
testing on AMD EPYC 7K62 like follow:
---
echo 1 > /proc/sys/kernel/random/tos_use_rdrand
stress-ng --urandom 2 --timeout 10s --times --metrics
bogo ops real time usr time sys time bogo ops/s bogo ops/s
(secs) (secs) (secs) (real time) (usr+sys time)
16542 10.00 0.00 19.98 1654.09 827.93
---
echo 0 > /proc/sys/kernel/random/tos_use_rdrand
stress-ng --urandom 2 --timeout 10s --times --metrics
bogo ops real time usr time sys time bogo ops/s bogo ops/s
(secs) (secs) (secs) (real time) (usr+sys time)
222005 10.00 0.05 19.93 22200.41 11111.36
/dev/urandom reading and geturandom syscall 13 times faster then using
really rdrand.
Signed-off-by: mengensun <mengensun@tencent.com>
Reviewed-by: frankjpliu <frankjpliu@tencent.com>
Reviewed-by: anakinzhang <anakinzhang@tencent.com>
Reviewed-by: Ruippan <Ruippan@tencent.com>