In order to conserve CPU, the read(2) syscall would schedule_timeout
unconditionally. This also crippled speed, and was a bad design
decision. This cset merges the updated read(2) logic of the sister
driver amd768_rng from Alan, which schedules only when it needs to.
On my test system, by one microbenmark, read(2) output jumped
from 0.08 kbit/s to "what Intel expects" of 20 kbit/s.
End users may notice a significant decrease in idle time after
this change (and a correspondingly large increase in /dev/hwrng user
speed), if /dev/hwrng is used to its maximum capacity.
#include <linux/miscdevice.h>
#include <linux/smp_lock.h>
#include <linux/mm.h>
+#include <linux/delay.h>
#include <asm/io.h>
#include <asm/uaccess.h>
if (filp->f_flags & O_NONBLOCK)
return ret ? : -EAGAIN;
- current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(1);
+ if (need_resched())
+ {
+ current->state = TASK_INTERRUPTIBLE;
+ schedule_timeout(1);
+ }
+ else
+ udelay(200);
if (signal_pending (current))
return ret ? : -ERESTARTSYS;