diff -r bdd606534bdc src/sim/clocked_object.hh --- a/src/sim/clocked_object.hh Tue Dec 03 10:51:40 2013 -0600 +++ b/src/sim/clocked_object.hh Mon Dec 16 12:43:32 2013 -0500 @@ -118,6 +118,9 @@ ClockedObject(const ClockedObjectParams* p) : SimObject(p), tick(0), cycle(0), clockDomain(*p->clk_domain) { + // Register with the clock domain, so that if the clock domain + // frequency changes, we can update this object's tick. + clockDomain.registerWithClockDomain(this); } /** diff -r bdd606534bdc src/sim/clock_domain.cc --- a/src/sim/clock_domain.cc Tue Dec 03 10:51:40 2013 -0600 +++ b/src/sim/clock_domain.cc Mon Dec 16 12:43:32 2013 -0500 @@ -45,6 +45,7 @@ #include "params/SrcClockDomain.hh" #include "sim/clock_domain.hh" #include "sim/voltage_domain.hh" +#include "sim/clocked_object.hh" double ClockDomain::voltage() const @@ -65,6 +66,12 @@ fatal("%s has a clock period of zero\n", name()); } + // Align all members to the current tick by calling curCycle(), + // which calls update() internally + for (auto m = members.begin(); m != members.end(); ++m) { + (*m)->curCycle(); + } + _clockPeriod = clock_period; DPRINTF(ClockDomain, @@ -105,6 +112,12 @@ void DerivedClockDomain::updateClockPeriod() { + // Align all members to the current tick by calling curCycle(), + // which calls update() internally + for (auto m = members.begin(); m != members.end(); ++m) { + (*m)->curCycle(); + } + // recalculate the clock period, relying on the fact that changes // propagate downwards in the tree _clockPeriod = parent.clockPeriod() * clockDivider; diff -r bdd606534bdc src/sim/clock_domain.hh --- a/src/sim/clock_domain.hh Tue Dec 03 10:51:40 2013 -0600 +++ b/src/sim/clock_domain.hh Mon Dec 16 12:43:32 2013 -0500 @@ -46,6 +46,8 @@ #ifndef __SIM_CLOCK_DOMAIN_HH__ #define __SIM_CLOCK_DOMAIN_HH__ +#include + #include "base/statistics.hh" #include "params/ClockDomain.hh" #include "params/DerivedClockDomain.hh" @@ -57,6 +59,7 @@ */ class DerivedClockDomain; class VoltageDomain; +class ClockedObject; /** * The ClockDomain provides clock to group of clocked objects bundled @@ -86,6 +89,12 @@ */ std::vector children; + /** + * Pointers to members of this clock domain, so that when the clock + * period changes, we can update each member's tick. + */ + std::vector members; + public: typedef ClockDomainParams Params; @@ -102,6 +111,18 @@ inline Tick clockPeriod() const { return _clockPeriod; } /** + * Register a ClockedObject to this ClockDomain. + * + * @param ClockedObject to add as a member + */ + inline void registerWithClockDomain(ClockedObject *c) + { + assert(c != NULL); + assert(std::find(members.begin(), members.end(), c) == members.end()); + members.push_back(c); + } + + /** * Get the voltage domain. * * @return Voltage domain this clock domain belongs to @@ -145,6 +166,8 @@ */ void clockPeriod(Tick clock_period); + // Explicitly import the otherwise hidden clockPeriod + using ClockDomain::clockPeriod; }; /**