From 2698e739660516af442c0f913eb0e91a00e7b7db Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Wed, 3 Sep 2014 07:42:54 -0400 Subject: base: Use the global Mersenne twister throughout This patch tidies up random number generation to ensure that it is done consistently throughout the code base. In essence this involves a clean-up of Ruby, and some code simplifications in the traffic generator. As part of this patch a bunch of skewed distributions (off-by-one etc) have been fixed. Note that a single global random number generator is used, and that the object instantiation order will impact the behaviour (the sequence of numbers will be unaffected, but if module A calles random before module B then they would obviously see a different outcome). The dependency on the instantiation order is true in any case due to the execution-model of gem5, so we leave it as is. Also note that the global ranom generator is not thread safe at this point. Regressions using the memtest, TrafficGen or any Ruby tester are affected and will be updated accordingly. --- src/cpu/testers/traffic_gen/generators.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/cpu/testers/traffic_gen/generators.cc') diff --git a/src/cpu/testers/traffic_gen/generators.cc b/src/cpu/testers/traffic_gen/generators.cc index 7c6bab92c..135765fce 100644 --- a/src/cpu/testers/traffic_gen/generators.cc +++ b/src/cpu/testers/traffic_gen/generators.cc @@ -84,7 +84,7 @@ LinearGen::getNextPacket() { // choose if we generate a read or a write here bool isRead = readPercent != 0 && - (readPercent == 100 || random_mt.random(0, 100) < readPercent); + (readPercent == 100 || random_mt.random(0, 100) < readPercent); assert((readPercent == 0 && !isRead) || (readPercent == 100 && isRead) || readPercent != 100); @@ -124,7 +124,7 @@ LinearGen::nextPacketTick(bool elastic, Tick delay) const return MaxTick; } else { // return the time when the next request should take place - Tick wait = random_mt.random(minPeriod, maxPeriod); + Tick wait = random_mt.random(minPeriod, maxPeriod); // compensate for the delay experienced to not be elastic, by // default the value we generate is from the time we are @@ -152,13 +152,13 @@ RandomGen::getNextPacket() { // choose if we generate a read or a write here bool isRead = readPercent != 0 && - (readPercent == 100 || random_mt.random(0, 100) < readPercent); + (readPercent == 100 || random_mt.random(0, 100) < readPercent); assert((readPercent == 0 && !isRead) || (readPercent == 100 && isRead) || readPercent != 100); // address of the request - Addr addr = random_mt.random(startAddr, endAddr - 1); + Addr addr = random_mt.random(startAddr, endAddr - 1); // round down to start address of block addr -= addr % blocksize; @@ -184,15 +184,14 @@ DramGen::getNextPacket() // choose if we generate a read or a write here isRead = readPercent != 0 && - (readPercent == 100 || - random_mt.random(0, 100) < readPercent); + (readPercent == 100 || random_mt.random(0, 100) < readPercent); assert((readPercent == 0 && !isRead) || (readPercent == 100 && isRead) || readPercent != 100); // start by picking a random address in the range - addr = random_mt.random(startAddr, endAddr - 1); + addr = random_mt.random(startAddr, endAddr - 1); // round down to start address of a block, i.e. a DRAM burst addr -= addr % blocksize; @@ -275,7 +274,7 @@ RandomGen::nextPacketTick(bool elastic, Tick delay) const return MaxTick; } else { // return the time when the next request should take place - Tick wait = random_mt.random(minPeriod, maxPeriod); + Tick wait = random_mt.random(minPeriod, maxPeriod); // compensate for the delay experienced to not be elastic, by // default the value we generate is from the time we are -- cgit v1.2.3