More completely seed UUID::Random()
Generate enuogh randomness with std::random_device to fully seed the
internal state of an std::mt19937. This ensures that even the first
UUID::Random() call after boot has full entropy, so long as
`std::random_device` is non-deterministic.
Also, initialize the random number generator during AOS initialization.
Change-Id: Ie09d85f09f7969bcd47576a577b4415d39186233
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/realtime.cc b/aos/realtime.cc
index 14849a4..8b34ada 100644
--- a/aos/realtime.cc
+++ b/aos/realtime.cc
@@ -19,6 +19,7 @@
#include "glog/raw_logging.h"
#include "aos/thread_local.h"
+#include "aos/uuid.h"
DEFINE_bool(
die_on_malloc, true,
@@ -184,6 +185,10 @@
}
void SetCurrentThreadRealtimePriority(int priority) {
+ // Ensure that we won't get expensive reads of /dev/random when the realtime
+ // scheduler is running.
+ UUID::Random();
+
if (FLAGS_skip_realtime_scheduler) {
LOG(WARNING) << "Ignoring request to switch to the RT scheduler due to "
"--skip_realtime_scheduler.";