activity.hh revision 2325
1 2#ifndef __CPU_ACTIVITY_HH__ 3#define __CPU_ACTIVITY_HH__ 4 5#include "base/timebuf.hh" 6#include "base/trace.hh" 7 8class ActivityRecorder { 9 public: 10 ActivityRecorder(int num_stages, int longest_latency, int count); 11 12 /** Records that there is activity this cycle. */ 13 void activity(); 14 /** Advances the activity buffer, decrementing the activityCount if active 15 * communication just left the time buffer, and descheduling the CPU if 16 * there is no activity. 17 */ 18 void advance(); 19 /** Marks a stage as active. */ 20 void activateStage(const int idx); 21 /** Deactivates a stage. */ 22 void deactivateStage(const int idx); 23 24 int getActivityCount() { return activityCount; } 25 26 void setActivityCount(int count) 27 { activityCount = count; } 28 29 bool active() { return activityCount; } 30 31 void reset(); 32 33 void dump(); 34 35 void validate(); 36 37 private: 38 /** Time buffer that tracks if any cycles has active communication 39 * in them. It should be as long as the longest communication 40 * latency in the system. Each time any time buffer is written, 41 * the activity buffer should also be written to. The 42 * activityBuffer is advanced along with all the other time 43 * buffers, so it should have a 1 somewhere in it only if there 44 * is active communication in a time buffer. 45 */ 46 TimeBuffer<bool> activityBuffer; 47 48 int longestLatency; 49 50 /** Tracks how many stages and cycles of time buffer have 51 * activity. Stages increment this count when they switch to 52 * active, and decrement it when they switch to 53 * inactive. Whenever a cycle that previously had no information 54 * is written in the time buffer, this is incremented. When a 55 * cycle that had information exits the time buffer due to age, 56 * this count is decremented. When the count is 0, there is no 57 * activity in the CPU, and it can be descheduled. 58 */ 59 int activityCount; 60 61 int numStages; 62 63 /** Records which stages are active/inactive. */ 64 bool *stageActive; 65}; 66 67#endif // __CPU_ACTIVITY_HH__ 68