summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-08-07 20:13:00 -0700
committerGabe Black <gabeblack@google.com>2019-08-13 22:32:31 +0000
commit5e83d703522a71ec4f3eb61a01acd8c53f6f3860 (patch)
tree4d07b4d38844c95e7b18bf50be18ada1f13f1bd4
parentea8c435b6c6c092d72047eee50f125f5ae7347c3 (diff)
downloadgem5-5e83d703522a71ec4f3eb61a01acd8c53f6f3860.tar.xz
sim: Add a hook Clocked objects can implement for frequency changes.
This hook will let them implement whatever additional behavior is necessary for when the clock changes. An alternative design for this might have made the "update" function virtual, and required anyone overriding it to call into the base class. I think that would be an inferior design for two reasons. First, the subclass author might forget to call update. Second, while it might *seem* like this would have some performance benefit since you wouldn't call into the virtual function and then call update, incurring the function call overhead twice, you're going to call into update once regardless, and then you're either going to call the virtual funciton which does nothing (the norm) or does something. In either case you call the same functions the same number of times. There may be a slight penalty in code size since the call to update may be inlined in the call sights before the virtual function, and there will almost certainly be more of those than there would be implementations of the virtual function, but that should be negligable when compared to gem5's size as a whole. Change-Id: Id25a5359f2b1f7e42c6d1dcbc70a37d3ce092d38 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20089 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chun-Chen TK Hsu <chunchenhsu@google.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Anthony Gutierrez <anthony.gutierrez@amd.com> Reviewed-by: Srikant Bharadwaj <srikant.bharadwaj@amd.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
-rw-r--r--src/sim/clocked_object.hh13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/sim/clocked_object.hh b/src/sim/clocked_object.hh
index 5df404dba..d41f71a17 100644
--- a/src/sim/clocked_object.hh
+++ b/src/sim/clocked_object.hh
@@ -144,12 +144,23 @@ class Clocked
tick = elapsedCycles * clockPeriod();
}
+ /**
+ * A hook subclasses can implement so they can do any extra work that's
+ * needed when the clock rate is changed.
+ */
+ virtual void clockPeriodUpdated() {}
+
public:
/**
* Update the tick to the current tick.
*/
- void updateClockPeriod() const { update(); }
+ void
+ updateClockPeriod()
+ {
+ update();
+ clockPeriodUpdated();
+ }
/**
* Determine the tick when a cycle begins, by default the current one, but