Hoa Nguyen has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/56889 )
Change subject: dev: Make VirtIORng device use gem5's rng instead of C++'s
......................................................................
dev: Make VirtIORng device use gem5's rng instead of C++'s
Currently, VirtIORng uses C++'s RNG. This causes nondeterminism
across simulations using this device. One example is the example RISC-V
board booting Ubuntu,
configs/example/gem5_library/riscv-ubuntu-run.py
JIRA: https://gem5.atlassian.net/browse/GEM5-1193
Change-Id: I299e72eb891819007b4260390f5c2ba94d2dec7b
Signed-off-by: Hoa Nguyen <hoangu...@ucdavis.edu>
---
M src/dev/virtio/rng.cc
M src/dev/virtio/rng.hh
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/dev/virtio/rng.cc b/src/dev/virtio/rng.cc
index 50a747c..6123589 100644
--- a/src/dev/virtio/rng.cc
+++ b/src/dev/virtio/rng.cc
@@ -41,6 +41,7 @@
#include <fcntl.h>
#include <unistd.h>
+#include "base/random.hh"
#include "debug/VIORng.hh"
#include "params/VirtIORng.hh"
#include "sim/system.hh"
@@ -63,7 +64,7 @@
VirtIORng::RngQueue::RngQueue(PortProxy &proxy, ByteOrder bo,
uint16_t size, const std::string &rng_file_path,
VirtIORng &_parent)
- : VirtQueue(proxy, bo, size), parent(_parent), dist(0,255)
+ : VirtQueue(proxy, bo, size), parent(_parent)
{
rng_fd = open(rng_file_path.c_str(), O_RDONLY);
if (rng_fd < 0) {
@@ -97,7 +98,7 @@
}
if (!rng_read_success) {
// fallback to C++ std rng generator
- byte = dist(rd_device);
+ byte = gem5::random_mt.random<uint8_t>();
}
d->chainWrite(len, &byte, sizeof(uint8_t));
++len;
diff --git a/src/dev/virtio/rng.hh b/src/dev/virtio/rng.hh
index 50a3723..631e353 100644
--- a/src/dev/virtio/rng.hh
+++ b/src/dev/virtio/rng.hh
@@ -39,8 +39,6 @@
#ifndef __DEV_VIRTIO_RNG_HH__
#define __DEV_VIRTIO_RNG_HH__
-#include <random>
-
#include "base/compiler.hh"
#include "dev/virtio/base.hh"
@@ -93,9 +91,6 @@
private:
// system's special file for generating random number
int rng_fd;
- // fallback random number generator
- std::random_device rd_device;
- std::uniform_int_distribution<int> dist;
};
/** Receive queue for port 0 */
RngQueue qReq;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56889
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I299e72eb891819007b4260390f5c2ba94d2dec7b
Gerrit-Change-Number: 56889
Gerrit-PatchSet: 1
Gerrit-Owner: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s