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 "cpu/activity.hh"
35 #include "cpu/timebuf.hh"
36 #include "debug/Activity.hh"
40 ActivityRecorder::ActivityRecorder(const string
&name
, int num_stages
,
41 int longest_latency
, int activity
)
42 : _name(name
), activityBuffer(longest_latency
, 0),
43 longestLatency(longest_latency
), activityCount(activity
),
46 stageActive
= new bool[numStages
];
47 std::memset(stageActive
, 0, numStages
);
50 ActivityRecorder::~ActivityRecorder()
56 ActivityRecorder::activity()
58 // If we've already recorded activity for this cycle, we don't
59 // want to increment the count any more.
60 if (activityBuffer
[0]) {
64 activityBuffer
[0] = true;
68 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
72 ActivityRecorder::advance()
74 // If there's a 1 in the slot that is about to be erased once the
75 // time buffer advances, then decrement the activityCount.
76 if (activityBuffer
[-longestLatency
]) {
79 assert(activityCount
>= 0);
81 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
83 if (activityCount
== 0) {
84 DPRINTF(Activity
, "No activity left!\n");
88 activityBuffer
.advance();
92 ActivityRecorder::activateStage(const int idx
)
94 // Increment the activity count if this stage wasn't already active.
95 if (!stageActive
[idx
]) {
98 stageActive
[idx
] = true;
100 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
102 DPRINTF(Activity
, "Stage %i already active.\n", idx
);
105 // assert(activityCount < longestLatency + numStages + 1);
109 ActivityRecorder::deactivateStage(const int idx
)
111 // Decrement the activity count if this stage was active.
112 if (stageActive
[idx
]) {
115 stageActive
[idx
] = false;
117 DPRINTF(Activity
, "Activity: %i\n", activityCount
);
119 DPRINTF(Activity
, "Stage %i already inactive.\n", idx
);
122 assert(activityCount
>= 0);
126 ActivityRecorder::reset()
129 std::memset(stageActive
, 0, numStages
);
130 for (int i
= 0; i
< longestLatency
+ 1; ++i
)
131 activityBuffer
.advance();
135 ActivityRecorder::dump()
137 for (int i
= 0; i
<= longestLatency
; ++i
) {
138 cprintf("[Idx:%i %i] ", i
, activityBuffer
[-i
]);
143 for (int i
= 0; i
< numStages
; ++i
) {
144 cprintf("[Stage:%i %i]\n", i
, stageActive
[i
]);
149 cprintf("Activity count: %i\n", activityCount
);
153 ActivityRecorder::validate()
156 for (int i
= 0; i
<= longestLatency
; ++i
) {
157 if (activityBuffer
[-i
]) {
162 for (int i
= 0; i
< numStages
; ++i
) {
163 if (stageActive
[i
]) {
168 assert(count
== activityCount
);