2 * Copyright (c) 2006 The Regents of The University of Michigan
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.
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.
33 #include "cpu/activity.hh"
34 #include "cpu/timebuf.hh"
35 #include "debug/Activity.hh"
39 ActivityRecorder::ActivityRecorder(const string
&name
, int num_stages
,
40 int longest_latency
, int activity
)
41 : _name(name
), activityBuffer(longest_latency
, 0),
42 longestLatency(longest_latency
), activityCount(activity
),
45 stageActive
= new bool[numStages
];
46 std::memset(stageActive
, 0, numStages
);
49 ActivityRecorder::~ActivityRecorder()
55 ActivityRecorder::activity()
57 // If we've already recorded activity for this cycle, we don't
58 // want to increment the count any more.
59 if (activityBuffer
[0]) {
63 activityBuffer
[0] = true;
67 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
71 ActivityRecorder::advance()
73 // If there's a 1 in the slot that is about to be erased once the
74 // time buffer advances, then decrement the activityCount.
75 if (activityBuffer
[-longestLatency
]) {
78 assert(activityCount
>= 0);
80 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
82 if (activityCount
== 0) {
83 DPRINTF(Activity
, "No activity left!\n");
87 activityBuffer
.advance();
91 ActivityRecorder::activateStage(const int idx
)
93 // Increment the activity count if this stage wasn't already active.
94 if (!stageActive
[idx
]) {
97 stageActive
[idx
] = true;
99 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
101 DPRINTF(Activity
, "Stage %i already active.\n", idx
);
104 // assert(activityCount < longestLatency + numStages + 1);
108 ActivityRecorder::deactivateStage(const int idx
)
110 // Decrement the activity count if this stage was active.
111 if (stageActive
[idx
]) {
114 stageActive
[idx
] = false;
116 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
118 DPRINTF(Activity
, "Stage %i already inactive.\n", idx
);
121 assert(activityCount
>= 0);
125 ActivityRecorder::reset()
128 std::memset(stageActive
, 0, numStages
);
129 for (int i
= 0; i
< longestLatency
+ 1; ++i
)
130 activityBuffer
.advance();
134 ActivityRecorder::dump()
136 for (int i
= 0; i
<= longestLatency
; ++i
) {
137 cprintf("[Idx:%i %i] ", i
, activityBuffer
[-i
]);
142 for (int i
= 0; i
< numStages
; ++i
) {
143 cprintf("[Stage:%i %i]\n", i
, stageActive
[i
]);
148 cprintf("Activity count: %i\n", activityCount
);
152 ActivityRecorder::validate()
155 for (int i
= 0; i
<= longestLatency
; ++i
) {
156 if (activityBuffer
[-i
]) {
161 for (int i
= 0; i
< numStages
; ++i
) {
162 if (stageActive
[i
]) {
167 assert(count
== activityCount
);