cpu: make ExecSymbol show the symbol in addition to address
[gem5.git] / src / cpu / activity.hh
1 /*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __CPU_ACTIVITY_HH__
30 #define __CPU_ACTIVITY_HH__
31
32 #include "base/trace.hh"
33 #include "cpu/timebuf.hh"
34
35 /**
36 * ActivityRecorder helper class that informs the CPU if it can switch
37 * over to being idle or not. It works by having a time buffer as
38 * long as any time buffer in the CPU, and the CPU and all of its
39 * stages inform the ActivityRecorder when they write to any time
40 * buffer. The ActivityRecorder marks a 1 in the "0" slot of the time
41 * buffer any time a stage writes to a time buffer, and it advances
42 * its time buffer at the same time as all other stages. The
43 * ActivityRecorder also records if a stage has activity to do next
44 * cycle. The recorder keeps a count of these two. Thus any time the
45 * count is non-zero, there is either communication still in flight,
46 * or activity that still must be done, meaning that the CPU can not
47 * idle. If count is zero, then the CPU can safely idle as it has no
48 * more outstanding work to do.
49 */
50 class ActivityRecorder
51 {
52 public:
53 ActivityRecorder(const std::string &name, int num_stages,
54 int longest_latency, int count);
55 ~ActivityRecorder();
56
57 /** Records that there is activity this cycle. */
58 void activity();
59
60 /** Advances the activity buffer, decrementing the activityCount
61 * if active communication just left the time buffer, and
62 * determining if there is no activity.
63 */
64 void advance();
65
66 /** Marks a stage as active. */
67 void activateStage(const int idx);
68
69 /** Deactivates a stage. */
70 void deactivateStage(const int idx);
71
72 /** Returns the activity status of a stage. */
73 bool getStageActive(const int idx) const { return stageActive[idx]; }
74
75 /** Returns the number of stages. */
76 int getNumStages() const { return numStages; }
77
78 /** Returns how many things are active within the recorder. */
79 int getActivityCount() const { return activityCount; }
80
81 /** Sets the count to a starting value. Can be used to disable
82 * the idling option.
83 */
84 void setActivityCount(int count)
85 { activityCount = count; }
86
87 /** Returns if the CPU should be active. */
88 bool active() { return activityCount; }
89
90 /** Clears the time buffer and the activity count. */
91 void reset();
92
93 /** Debug function to dump the contents of the time buffer. */
94 void dump();
95
96 /** Debug function to ensure that the activity count matches the
97 * contents of the time buffer.
98 */
99 void validate();
100
101 const std::string &name() const { return _name; }
102
103 private:
104 // provide name() for DPRINTF.
105 std::string _name;
106
107 /** Time buffer that tracks if any cycles has active communication
108 * in them. It should be as long as the longest communication
109 * latency in the system. Each time any time buffer is written,
110 * the activity buffer should also be written to. The
111 * activityBuffer is advanced along with all the other time
112 * buffers, so it should have a 1 somewhere in it only if there
113 * is active communication in a time buffer.
114 */
115 TimeBuffer<bool> activityBuffer;
116
117 /** Longest latency time buffer in the CPU. */
118 int longestLatency;
119
120 /** Tracks how many stages and cycles of time buffer have
121 * activity. Stages increment this count when they switch to
122 * active, and decrement it when they switch to
123 * inactive. Whenever a cycle that previously had no information
124 * is written in the time buffer, this is incremented. When a
125 * cycle that had information exits the time buffer due to age,
126 * this count is decremented. When the count is 0, there is no
127 * activity in the CPU, and it can be descheduled.
128 */
129 int activityCount;
130
131 /** Number of stages that can be marked as active or inactive. */
132 int numStages;
133
134 /** Records which stages are active/inactive. */
135 bool *stageActive;
136 };
137
138 #endif // __CPU_ACTIVITY_HH__