gem5 v24.0.0.0
Loading...
Searching...
No Matches
activity.cc
Go to the documentation of this file.
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
29#include "cpu/activity.hh"
30
31#include <string>
32
33#include "cpu/timebuf.hh"
34#include "debug/Activity.hh"
35
36namespace gem5
37{
38
39ActivityRecorder::ActivityRecorder(const std::string &name, int num_stages,
40 int longest_latency, int activity)
41 : _name(name), activityBuffer(longest_latency, 0),
42 longestLatency(longest_latency), activityCount(activity),
43 numStages(num_stages)
44{
45 stageActive = new bool[numStages];
46 std::memset(stageActive, 0, numStages);
47}
48
53
54void
56{
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]) {
60 return;
61 }
62
63 activityBuffer[0] = true;
64
66
67 DPRINTF(Activity, "Activity: %i\n", activityCount);
68}
69
70void
72{
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.
77
78 assert(activityCount >= 0);
79
80 DPRINTF(Activity, "Activity: %i\n", activityCount);
81
82 if (activityCount == 0) {
83 DPRINTF(Activity, "No activity left!\n");
84 }
85 }
86
88}
89
90void
92{
93 // Increment the activity count if this stage wasn't already active.
94 if (!stageActive[idx]) {
96
97 stageActive[idx] = true;
98
99 DPRINTF(Activity, "Activity: %i\n", activityCount);
100 } else {
101 DPRINTF(Activity, "Stage %i already active.\n", idx);
102 }
103
104// assert(activityCount < longestLatency + numStages + 1);
105}
106
107void
109{
110 // Decrement the activity count if this stage was active.
111 if (stageActive[idx]) {
113
114 stageActive[idx] = false;
115
116 DPRINTF(Activity, "Activity: %i\n", activityCount);
117 } else {
118 DPRINTF(Activity, "Stage %i already inactive.\n", idx);
119 }
120
121 assert(activityCount >= 0);
122}
123
124void
126{
127 activityCount = 0;
128 std::memset(stageActive, 0, numStages);
129 for (int i = 0; i < longestLatency + 1; ++i)
131}
132
133void
135{
136 for (int i = 0; i <= longestLatency; ++i) {
137 cprintf("[Idx:%i %i] ", i, activityBuffer[-i]);
138 }
139
140 cprintf("\n");
141
142 for (int i = 0; i < numStages; ++i) {
143 cprintf("[Stage:%i %i]\n", i, stageActive[i]);
144 }
145
146 cprintf("\n");
147
148 cprintf("Activity count: %i\n", activityCount);
149}
150
151void
153{
154#ifdef DEBUG
155 int count = 0;
156 for (int i = 0; i <= longestLatency; ++i) {
157 if (activityBuffer[-i]) {
158 count++;
159 }
160 }
161
162 for (int i = 0; i < numStages; ++i) {
163 if (stageActive[i]) {
164 count++;
165 }
166 }
167
168 assert(count == activityCount);
169#endif
170}
171
172} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
int activityCount
Tracks how many stages and cycles of time buffer have activity.
Definition activity.hh:132
int numStages
Number of stages that can be marked as active or inactive.
Definition activity.hh:135
void dump()
Debug function to dump the contents of the time buffer.
Definition activity.cc:134
int longestLatency
Longest latency time buffer in the CPU.
Definition activity.hh:121
void advance()
Advances the activity buffer, decrementing the activityCount if active communication just left the ti...
Definition activity.cc:71
void validate()
Debug function to ensure that the activity count matches the contents of the time buffer.
Definition activity.cc:152
void reset()
Clears the time buffer and the activity count.
Definition activity.cc:125
void activity()
Records that there is activity this cycle.
Definition activity.cc:55
bool * stageActive
Records which stages are active/inactive.
Definition activity.hh:138
ActivityRecorder(const std::string &name, int num_stages, int longest_latency, int count)
Definition activity.cc:39
void deactivateStage(const int idx)
Deactivates a stage.
Definition activity.cc:108
TimeBuffer< bool > activityBuffer
Time buffer that tracks if any cycles has active communication in them.
Definition activity.hh:118
void activateStage(const int idx)
Marks a stage as active.
Definition activity.cc:91
Bitfield< 7 > i
Definition misc_types.hh:67
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void cprintf(const char *format, const Args &...args)
Definition cprintf.hh:155
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0