gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Kevin Lim
29  */
30 
31 #include "cpu/activity.hh"
32 
33 #include <string>
34 
35 #include "cpu/timebuf.hh"
36 #include "debug/Activity.hh"
37 
38 using namespace std;
39 
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),
44  numStages(num_stages)
45 {
46  stageActive = new bool[numStages];
47  std::memset(stageActive, 0, numStages);
48 }
49 
51 {
52  delete[] stageActive;
53 }
54 
55 void
57 {
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]) {
61  return;
62  }
63 
64  activityBuffer[0] = true;
65 
66  ++activityCount;
67 
68  DPRINTF(Activity, "Activity: %i\n", activityCount);
69 }
70 
71 void
73 {
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.
77  --activityCount;
78 
79  assert(activityCount >= 0);
80 
81  DPRINTF(Activity, "Activity: %i\n", activityCount);
82 
83  if (activityCount == 0) {
84  DPRINTF(Activity, "No activity left!\n");
85  }
86  }
87 
89 }
90 
91 void
93 {
94  // Increment the activity count if this stage wasn't already active.
95  if (!stageActive[idx]) {
96  ++activityCount;
97 
98  stageActive[idx] = true;
99 
100  DPRINTF(Activity, "Activity: %i\n", activityCount);
101  } else {
102  DPRINTF(Activity, "Stage %i already active.\n", idx);
103  }
104 
105 // assert(activityCount < longestLatency + numStages + 1);
106 }
107 
108 void
110 {
111  // Decrement the activity count if this stage was active.
112  if (stageActive[idx]) {
113  --activityCount;
114 
115  stageActive[idx] = false;
116 
117  DPRINTF(Activity, "Activity: %i\n", activityCount);
118  } else {
119  DPRINTF(Activity, "Stage %i already inactive.\n", idx);
120  }
121 
122  assert(activityCount >= 0);
123 }
124 
125 void
127 {
128  activityCount = 0;
129  std::memset(stageActive, 0, numStages);
130  for (int i = 0; i < longestLatency + 1; ++i)
132 }
133 
134 void
136 {
137  for (int i = 0; i <= longestLatency; ++i) {
138  cprintf("[Idx:%i %i] ", i, activityBuffer[-i]);
139  }
140 
141  cprintf("\n");
142 
143  for (int i = 0; i < numStages; ++i) {
144  cprintf("[Stage:%i %i]\n", i, stageActive[i]);
145  }
146 
147  cprintf("\n");
148 
149  cprintf("Activity count: %i\n", activityCount);
150 }
151 
152 void
154 {
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 }
count
Definition: misc.hh:704
#define DPRINTF(x,...)
Definition: trace.hh:212
const std::string & name()
Definition: trace.cc:49
void validate()
Debug function to ensure that the activity count matches the contents of the time buffer...
Definition: activity.cc:153
TimeBuffer< bool > activityBuffer
Time buffer that tracks if any cycles has active communication in them.
Definition: activity.hh:117
bool * stageActive
Records which stages are active/inactive.
Definition: activity.hh:137
int activityCount
Tracks how many stages and cycles of time buffer have activity.
Definition: activity.hh:131
Bitfield< 7 > i
Definition: miscregs.hh:1378
int numStages
Number of stages that can be marked as active or inactive.
Definition: activity.hh:134
void activity()
Records that there is activity this cycle.
Definition: activity.cc:56
void advance()
Definition: timebuf.hh:179
void reset()
Clears the time buffer and the activity count.
Definition: activity.cc:126
ActivityRecorder(const std::string &name, int num_stages, int longest_latency, int count)
Definition: activity.cc:40
void deactivateStage(const int idx)
Deactivates a stage.
Definition: activity.cc:109
void dump()
Debug function to dump the contents of the time buffer.
Definition: activity.cc:135
void activateStage(const int idx)
Marks a stage as active.
Definition: activity.cc:92
int longestLatency
Longest latency time buffer in the CPU.
Definition: activity.hh:120
void advance()
Advances the activity buffer, decrementing the activityCount if active communication just left the ti...
Definition: activity.cc:72
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155

Generated on Fri Jun 9 2017 13:03:41 for gem5 by doxygen 1.8.6