Hoa Nguyen has submitted this change. (
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
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/56889
Maintainer: Bobby Bruce
Reviewed-by: Jason Lowe-Power
Tested-by: kokoro
---
M src/dev/virtio/VirtIORng.py
M src/dev/virtio/rng.cc
M src/dev/virtio/rng.hh
3 files changed, 29 insertions(+), 36 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved
Bobby Bruce: Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/dev/virtio/VirtIORng.py b/src/dev/virtio/VirtIORng.py
index 54848ee..13df059 100644
--- a/src/dev/virtio/VirtIORng.py
+++ b/src/dev/virtio/VirtIORng.py
@@ -46,5 +46,3 @@
cxx_class = 'gem5::VirtIORng'
qSize = Param.Unsigned(16, "Request queue size")
-
-entropy_source = Param.String("/dev/random", "The source of entropy")
diff --git a/src/dev/virtio/rng.cc b/src/dev/virtio/rng.cc
index 50a747c..c26568e 100644
--- a/src/dev/virtio/rng.cc
+++ b/src/dev/virtio/rng.cc
@@ -38,9 +38,7 @@
#include "dev/virtio/rng.hh"
-#include
-#include
-
+#include "base/random.hh"
#include "debug/VIORng.hh"
#include "params/VirtIORng.hh"
#include "sim/system.hh"
@@ -50,8 +48,7 @@
VirtIORng::VirtIORng(const Params )
: VirtIODeviceBase(params, ID_RNG, 0, 0),
- qReq(params.system->physProxy, byteOrder, params.qSize,
- params.entropy_source, *this)
+ qReq(params.system->physProxy, byteOrder, params.qSize, *this)
{
registerQueue(qReq);
}
@@ -60,16 +57,10 @@
{
}
-VirtIORng::RngQueue::RngQueue(PortProxy , ByteOrder bo,
-uint16_t size, const std::string _file_path,
+VirtIORng::RngQueue::RngQueue(PortProxy , ByteOrder bo, uint16_t
size,
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) {
-DPRINTF(VIORng, "error when open entropy source: %s\n",
-rng_file_path.c_str());
-}
}
void
@@ -89,16 +80,7 @@
DPRINTF(VIORng, "Got descriptor (len: %i)\n", d->size());
size_t len = 0;
while (len < d->size()) {
-uint8_t byte = 0;
-bool rng_read_success = false;
-if (rng_fd >= 0) {
-ssize_t result = read(rng_fd, , sizeof(uint8_t));
-rng_read_success = (result > 0);
-}
-if (!rng_read_success) {
-// fallback to C++ std rng generator
-byte = dist(rd_device);
-}
+uint8_t byte = gem5::random_mt.random();
d->chainWrite(len, , sizeof(uint8_t));
++len;
}
diff --git a/src/dev/virtio/rng.hh b/src/dev/virtio/rng.hh
index 50a3723..7be2354 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
-
#include "base/compiler.hh"
#include "dev/virtio/base.hh"
@@ -76,9 +74,8 @@
: public VirtQueue
{
public:
-RngQueue(PortProxy , ByteOrder bo,
-uint16_t size, const std::string _file_path,
-VirtIORng &_parent);
+RngQueue(PortProxy , ByteOrder bo, uint16_t size,
+ VirtIORng &_parent);
virtual ~RngQueue() {}
void onNotify() { trySend(); }
@@ -90,12 +87,6 @@
protected:
VirtIORng
- 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 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: 4
Gerrit-Owner: Hoa Nguyen
Gerrit-Reviewer: Bobby Bruce
Gerrit-Reviewer: Gabe Black
Gerrit-Reviewer: Hoa Nguyen
Gerrit-Reviewer: Jason Lowe-Power
Gerrit-Reviewer: kokoro
Gerrit-CC: Luming Wang
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an