gem5  v20.1.0.0
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 
36 using namespace std;
37 
38 ActivityRecorder::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)
43 {
44  stageActive = new bool[numStages];
45  std::memset(stageActive, 0, numStages);
46 }
47 
49 {
50  delete[] stageActive;
51 }
52 
53 void
55 {
56  // If we've already recorded activity for this cycle, we don't
57  // want to increment the count any more.
58  if (activityBuffer[0]) {
59  return;
60  }
61 
62  activityBuffer[0] = true;
63 
64  ++activityCount;
65 
66  DPRINTF(Activity, "Activity: %i\n", activityCount);
67 }
68 
69 void
71 {
72  // If there's a 1 in the slot that is about to be erased once the
73  // time buffer advances, then decrement the activityCount.
75  --activityCount;
76 
77  assert(activityCount >= 0);
78 
79  DPRINTF(Activity, "Activity: %i\n", activityCount);
80 
81  if (activityCount == 0) {
82  DPRINTF(Activity, "No activity left!\n");
83  }
84  }
85 
87 }
88 
89 void
91 {
92  // Increment the activity count if this stage wasn't already active.
93  if (!stageActive[idx]) {
94  ++activityCount;
95 
96  stageActive[idx] = true;
97 
98  DPRINTF(Activity, "Activity: %i\n", activityCount);
99  } else {
100  DPRINTF(Activity, "Stage %i already active.\n", idx);
101  }
102 
103 // assert(activityCount < longestLatency + numStages + 1);
104 }
105 
106 void
108 {
109  // Decrement the activity count if this stage was active.
110  if (stageActive[idx]) {
111  --activityCount;
112 
113  stageActive[idx] = false;
114 
115  DPRINTF(Activity, "Activity: %i\n", activityCount);
116  } else {
117  DPRINTF(Activity, "Stage %i already inactive.\n", idx);
118  }
119 
120  assert(activityCount >= 0);
121 }
122 
123 void
125 {
126  activityCount = 0;
127  std::memset(stageActive, 0, numStages);
128  for (int i = 0; i < longestLatency + 1; ++i)
130 }
131 
132 void
134 {
135  for (int i = 0; i <= longestLatency; ++i) {
136  cprintf("[Idx:%i %i] ", i, activityBuffer[-i]);
137  }
138 
139  cprintf("\n");
140 
141  for (int i = 0; i < numStages; ++i) {
142  cprintf("[Stage:%i %i]\n", i, stageActive[i]);
143  }
144 
145  cprintf("\n");
146 
147  cprintf("Activity count: %i\n", activityCount);
148 }
149 
150 void
152 {
153  int count = 0;
154  for (int i = 0; i <= longestLatency; ++i) {
155  if (activityBuffer[-i]) {
156  count++;
157  }
158  }
159 
160  for (int i = 0; i < numStages; ++i) {
161  if (stageActive[i]) {
162  count++;
163  }
164  }
165 
166  assert(count == activityCount);
167 }
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ActivityRecorder::advance
void advance()
Advances the activity buffer, decrementing the activityCount if active communication just left the ti...
Definition: activity.cc:70
X86ISA::count
count
Definition: misc.hh:703
ActivityRecorder::longestLatency
int longestLatency
Longest latency time buffer in the CPU.
Definition: activity.hh:118
timebuf.hh
cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
ActivityRecorder::~ActivityRecorder
~ActivityRecorder()
Definition: activity.cc:48
activity.hh
ActivityRecorder::reset
void reset()
Clears the time buffer and the activity count.
Definition: activity.cc:124
ActivityRecorder::numStages
int numStages
Number of stages that can be marked as active or inactive.
Definition: activity.hh:132
ActivityRecorder::activityBuffer
TimeBuffer< bool > activityBuffer
Time buffer that tracks if any cycles has active communication in them.
Definition: activity.hh:115
name
const std::string & name()
Definition: trace.cc:50
ActivityRecorder::activityCount
int activityCount
Tracks how many stages and cycles of time buffer have activity.
Definition: activity.hh:129
ActivityRecorder::validate
void validate()
Debug function to ensure that the activity count matches the contents of the time buffer.
Definition: activity.cc:151
ActivityRecorder::stageActive
bool * stageActive
Records which stages are active/inactive.
Definition: activity.hh:135
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
ActivityRecorder::activity
void activity()
Records that there is activity this cycle.
Definition: activity.cc:54
ActivityRecorder::activateStage
void activateStage(const int idx)
Marks a stage as active.
Definition: activity.cc:90
TimeBuffer::advance
void advance()
Definition: timebuf.hh:176
ActivityRecorder::deactivateStage
void deactivateStage(const int idx)
Deactivates a stage.
Definition: activity.cc:107
ActivityRecorder::ActivityRecorder
ActivityRecorder(const std::string &name, int num_stages, int longest_latency, int count)
Definition: activity.cc:38
ActivityRecorder::dump
void dump()
Debug function to dump the contents of the time buffer.
Definition: activity.cc:133

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17