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 "base/timebuf.hh"
34 #include "cpu/activity.hh"
38 ActivityRecorder::ActivityRecorder(const string
&name
, int num_stages
,
39 int longest_latency
, int activity
)
40 : _name(name
), activityBuffer(longest_latency
, 0),
41 longestLatency(longest_latency
), activityCount(activity
),
44 stageActive
= new bool[numStages
];
45 std::memset(stageActive
, 0, numStages
);
49 ActivityRecorder::activity()
51 // If we've already recorded activity for this cycle, we don't
52 // want to increment the count any more.
53 if (activityBuffer
[0]) {
57 activityBuffer
[0] = true;
61 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
65 ActivityRecorder::advance()
67 // If there's a 1 in the slot that is about to be erased once the
68 // time buffer advances, then decrement the activityCount.
69 if (activityBuffer
[-longestLatency
]) {
72 assert(activityCount
>= 0);
74 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
76 if (activityCount
== 0) {
77 DPRINTF(Activity
, "No activity left!\n");
81 activityBuffer
.advance();
85 ActivityRecorder::activateStage(const int idx
)
87 // Increment the activity count if this stage wasn't already active.
88 if (!stageActive
[idx
]) {
91 stageActive
[idx
] = true;
93 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
95 DPRINTF(Activity
, "Stage %i already active.\n", idx
);
98 // assert(activityCount < longestLatency + numStages + 1);
102 ActivityRecorder::deactivateStage(const int idx
)
104 // Decrement the activity count if this stage was active.
105 if (stageActive
[idx
]) {
108 stageActive
[idx
] = false;
110 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
112 DPRINTF(Activity
, "Stage %i already inactive.\n", idx
);
115 assert(activityCount
>= 0);
119 ActivityRecorder::reset()
122 std::memset(stageActive
, 0, numStages
);
123 for (int i
= 0; i
< longestLatency
+ 1; ++i
)
124 activityBuffer
.advance();
128 ActivityRecorder::dump()
130 for (int i
= 0; i
<= longestLatency
; ++i
) {
131 cprintf("[Idx:%i %i] ", i
, activityBuffer
[-i
]);
136 for (int i
= 0; i
< numStages
; ++i
) {
137 cprintf("[Stage:%i %i]\n", i
, stageActive
[i
]);
142 cprintf("Activity count: %i\n", activityCount
);
146 ActivityRecorder::validate()
149 for (int i
= 0; i
<= longestLatency
; ++i
) {
150 if (activityBuffer
[-i
]) {
155 for (int i
= 0; i
< numStages
; ++i
) {
156 if (stageActive
[i
]) {
161 assert(count
== activityCount
);