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.
31 #include "base/timebuf.hh"
32 #include "cpu/activity.hh"
34 ActivityRecorder::ActivityRecorder(int num_stages
, int longest_latency
,
36 : activityBuffer(longest_latency
, 0), longestLatency(longest_latency
),
37 activityCount(activity
), numStages(num_stages
)
39 stageActive
= new bool[numStages
];
40 memset(stageActive
, 0, numStages
);
44 ActivityRecorder::activity()
46 // If we've already recorded activity for this cycle, we don't
47 // want to increment the count any more.
48 if (activityBuffer
[0]) {
52 activityBuffer
[0] = true;
56 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
60 ActivityRecorder::advance()
62 // If there's a 1 in the slot that is about to be erased once the
63 // time buffer advances, then decrement the activityCount.
64 if (activityBuffer
[-longestLatency
]) {
67 assert(activityCount
>= 0);
69 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
71 if (activityCount
== 0) {
72 DPRINTF(Activity
, "No activity left!\n");
76 activityBuffer
.advance();
80 ActivityRecorder::activateStage(const int idx
)
82 // Increment the activity count if this stage wasn't already active.
83 if (!stageActive
[idx
]) {
86 stageActive
[idx
] = true;
88 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
90 DPRINTF(Activity
, "Stage %i already active.\n", idx
);
93 // assert(activityCount < longestLatency + numStages + 1);
97 ActivityRecorder::deactivateStage(const int idx
)
99 // Decrement the activity count if this stage was active.
100 if (stageActive
[idx
]) {
103 stageActive
[idx
] = false;
105 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
107 DPRINTF(Activity
, "Stage %i already inactive.\n", idx
);
110 assert(activityCount
>= 0);
114 ActivityRecorder::reset()
117 memset(stageActive
, 0, numStages
);
118 for (int i
= 0; i
< longestLatency
+ 1; ++i
)
119 activityBuffer
.advance();
123 ActivityRecorder::dump()
125 for (int i
= 0; i
<= longestLatency
; ++i
) {
126 cprintf("[Idx:%i %i] ", i
, activityBuffer
[-i
]);
131 for (int i
= 0; i
< numStages
; ++i
) {
132 cprintf("[Stage:%i %i]\n", i
, stageActive
[i
]);
137 cprintf("Activity count: %i\n", activityCount
);
141 ActivityRecorder::validate()
144 for (int i
= 0; i
<= longestLatency
; ++i
) {
145 if (activityBuffer
[-i
]) {
150 for (int i
= 0; i
< numStages
; ++i
) {
151 if (stageActive
[i
]) {
156 assert(count
== activityCount
);