activity.cc (3918:1f9a98d198e8) activity.cc (5804:34fe9bbc6705)
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 * Authors: Kevin Lim
29 */
30
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 * Authors: Kevin Lim
29 */
30
31#include <cstring>
31#include
32
33#include "base/timebuf.hh"
34#include "cpu/activity.hh"
35
32
33#include "base/timebuf.hh"
34#include "cpu/activity.hh"
35
36ActivityRecorder::ActivityRecorder(int num_stages, int longest_latency,
37 int activity)
38 : activityBuffer(longest_latency, 0), longestLatency(longest_latency),
39 activityCount(activity), numStages(num_stages)
36using namespace std;
37
38ActivityRecorder::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),
42 numStages(num_stages)
40{
41 stageActive = new bool[numStages];
42 std::memset(stageActive, 0, numStages);
43}
44
45void
46ActivityRecorder::activity()
47{
48 // If we've already recorded activity for this cycle, we don't
49 // want to increment the count any more.
50 if (activityBuffer[0]) {
51 return;
52 }
53
54 activityBuffer[0] = true;
55
56 ++activityCount;
57
58 DPRINTF(Activity, "Activity: %i\n", activityCount);
59}
60
61void
62ActivityRecorder::advance()
63{
64 // If there's a 1 in the slot that is about to be erased once the
65 // time buffer advances, then decrement the activityCount.
66 if (activityBuffer[-longestLatency]) {
67 --activityCount;
68
69 assert(activityCount >= 0);
70
71 DPRINTF(Activity, "Activity: %i\n", activityCount);
72
73 if (activityCount == 0) {
74 DPRINTF(Activity, "No activity left!\n");
75 }
76 }
77
78 activityBuffer.advance();
79}
80
81void
82ActivityRecorder::activateStage(const int idx)
83{
84 // Increment the activity count if this stage wasn't already active.
85 if (!stageActive[idx]) {
86 ++activityCount;
87
88 stageActive[idx] = true;
89
90 DPRINTF(Activity, "Activity: %i\n", activityCount);
91 } else {
92 DPRINTF(Activity, "Stage %i already active.\n", idx);
93 }
94
95// assert(activityCount < longestLatency + numStages + 1);
96}
97
98void
99ActivityRecorder::deactivateStage(const int idx)
100{
101 // Decrement the activity count if this stage was active.
102 if (stageActive[idx]) {
103 --activityCount;
104
105 stageActive[idx] = false;
106
107 DPRINTF(Activity, "Activity: %i\n", activityCount);
108 } else {
109 DPRINTF(Activity, "Stage %i already inactive.\n", idx);
110 }
111
112 assert(activityCount >= 0);
113}
114
115void
116ActivityRecorder::reset()
117{
118 activityCount = 0;
119 std::memset(stageActive, 0, numStages);
120 for (int i = 0; i < longestLatency + 1; ++i)
121 activityBuffer.advance();
122}
123
124void
125ActivityRecorder::dump()
126{
127 for (int i = 0; i <= longestLatency; ++i) {
128 cprintf("[Idx:%i %i] ", i, activityBuffer[-i]);
129 }
130
131 cprintf("\n");
132
133 for (int i = 0; i < numStages; ++i) {
134 cprintf("[Stage:%i %i]\n", i, stageActive[i]);
135 }
136
137 cprintf("\n");
138
139 cprintf("Activity count: %i\n", activityCount);
140}
141
142void
143ActivityRecorder::validate()
144{
145 int count = 0;
146 for (int i = 0; i <= longestLatency; ++i) {
147 if (activityBuffer[-i]) {
148 count++;
149 }
150 }
151
152 for (int i = 0; i < numStages; ++i) {
153 if (stageActive[i]) {
154 count++;
155 }
156 }
157
158 assert(count == activityCount);
159}
43{
44 stageActive = new bool[numStages];
45 std::memset(stageActive, 0, numStages);
46}
47
48void
49ActivityRecorder::activity()
50{
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]) {
54 return;
55 }
56
57 activityBuffer[0] = true;
58
59 ++activityCount;
60
61 DPRINTF(Activity, "Activity: %i\n", activityCount);
62}
63
64void
65ActivityRecorder::advance()
66{
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]) {
70 --activityCount;
71
72 assert(activityCount >= 0);
73
74 DPRINTF(Activity, "Activity: %i\n", activityCount);
75
76 if (activityCount == 0) {
77 DPRINTF(Activity, "No activity left!\n");
78 }
79 }
80
81 activityBuffer.advance();
82}
83
84void
85ActivityRecorder::activateStage(const int idx)
86{
87 // Increment the activity count if this stage wasn't already active.
88 if (!stageActive[idx]) {
89 ++activityCount;
90
91 stageActive[idx] = true;
92
93 DPRINTF(Activity, "Activity: %i\n", activityCount);
94 } else {
95 DPRINTF(Activity, "Stage %i already active.\n", idx);
96 }
97
98// assert(activityCount < longestLatency + numStages + 1);
99}
100
101void
102ActivityRecorder::deactivateStage(const int idx)
103{
104 // Decrement the activity count if this stage was active.
105 if (stageActive[idx]) {
106 --activityCount;
107
108 stageActive[idx] = false;
109
110 DPRINTF(Activity, "Activity: %i\n", activityCount);
111 } else {
112 DPRINTF(Activity, "Stage %i already inactive.\n", idx);
113 }
114
115 assert(activityCount >= 0);
116}
117
118void
119ActivityRecorder::reset()
120{
121 activityCount = 0;
122 std::memset(stageActive, 0, numStages);
123 for (int i = 0; i < longestLatency + 1; ++i)
124 activityBuffer.advance();
125}
126
127void
128ActivityRecorder::dump()
129{
130 for (int i = 0; i <= longestLatency; ++i) {
131 cprintf("[Idx:%i %i] ", i, activityBuffer[-i]);
132 }
133
134 cprintf("\n");
135
136 for (int i = 0; i < numStages; ++i) {
137 cprintf("[Stage:%i %i]\n", i, stageActive[i]);
138 }
139
140 cprintf("\n");
141
142 cprintf("Activity count: %i\n", activityCount);
143}
144
145void
146ActivityRecorder::validate()
147{
148 int count = 0;
149 for (int i = 0; i <= longestLatency; ++i) {
150 if (activityBuffer[-i]) {
151 count++;
152 }
153 }
154
155 for (int i = 0; i < numStages; ++i) {
156 if (stageActive[i]) {
157 count++;
158 }
159 }
160
161 assert(count == activityCount);
162}