summaryrefslogtreecommitdiff
path: root/src/cpu/activity.hh
blob: 2d53dc4bbb89a4a2b18bbd8d92614128a5bc6019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#ifndef __CPU_ACTIVITY_HH__
#define __CPU_ACTIVITY_HH__

#include "base/timebuf.hh"
#include "base/trace.hh"

class ActivityRecorder {
  public:
    ActivityRecorder(int num_stages, int longest_latency, int count);

    /** Records that there is activity this cycle. */
    void activity();
    /** Advances the activity buffer, decrementing the activityCount if active
     *  communication just left the time buffer, and descheduling the CPU if
     *  there is no activity.
     */
    void advance();
    /** Marks a stage as active. */
    void activateStage(const int idx);
    /** Deactivates a stage. */
    void deactivateStage(const int idx);

    int getActivityCount() { return activityCount; }

    void setActivityCount(int count)
    { activityCount = count; }

    bool active() { return activityCount; }

    void reset();

    void dump();

    void validate();

  private:
    /** Time buffer that tracks if any cycles has active communication
     *  in them.  It should be as long as the longest communication
     *  latency in the system.  Each time any time buffer is written,
     *  the activity buffer should also be written to. The
     *  activityBuffer is advanced along with all the other time
     *  buffers, so it should have a 1 somewhere in it only if there
     *  is active communication in a time buffer.
     */
    TimeBuffer<bool> activityBuffer;

    int longestLatency;

    /** Tracks how many stages and cycles of time buffer have
     *  activity. Stages increment this count when they switch to
     *  active, and decrement it when they switch to
     *  inactive. Whenever a cycle that previously had no information
     *  is written in the time buffer, this is incremented. When a
     *  cycle that had information exits the time buffer due to age,
     *  this count is decremented. When the count is 0, there is no
     *  activity in the CPU, and it can be descheduled.
     */
    int activityCount;

    int numStages;

    /** Records which stages are active/inactive. */
    bool *stageActive;
};

#endif // __CPU_ACTIVITY_HH__