From: Andreas Sandberg Date: Tue, 12 Mar 2013 17:41:29 +0000 (+0100) Subject: cpu: Fix state transition bug in the traffic generator X-Git-Tag: stable_2013_06_16~59 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fc6f569d94fe35a8c9a833e64dd82d6978dfb1cf;p=gem5.git cpu: Fix state transition bug in the traffic generator The traffic generator used to incorrectly determine the next state in when state 0 had a non-zero probability. Due to the way the next transition was determined, state 0 could never be entered other than as an initial state. This changeset updates the transitition() method to correctly handle such cases and cases where the transition matrix is a 1x1 matrix. --- diff --git a/src/cpu/testers/traffic_gen/traffic_gen.cc b/src/cpu/testers/traffic_gen/traffic_gen.cc index d9d040858..292fe54e0 100644 --- a/src/cpu/testers/traffic_gen/traffic_gen.cc +++ b/src/cpu/testers/traffic_gen/traffic_gen.cc @@ -324,13 +324,14 @@ TrafficGen::StateGraph::transition() // determine next state double p = random_mt.gen_real1(); assert(currState < transitionMatrix.size()); - double cumulative = transitionMatrix[currState][0]; - size_t i = 1; - while (p < cumulative && i != transitionMatrix[currState].size()) { + double cumulative = 0.0; + size_t i = 0; + do { cumulative += transitionMatrix[currState][i]; ++i; - } - enterState(i); + } while (cumulative < p && i < transitionMatrix[currState].size()); + + enterState(i - 1); } void