OpenASIP  2.0
RFAccessTracker.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file RFAccessTracker.cc
26  *
27  * Definition of RFAccessTracker class.
28  *
29  * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "RFAccessTracker.hh"
34 #include "Application.hh"
35 #include "SimulatorToolbox.hh"
37 #include "SimulatorFrontend.hh"
38 #include "InstructionMemory.hh"
39 #include "ExecutableInstruction.hh"
40 #include "Machine.hh"
41 #include "Instruction.hh"
42 #include "Move.hh"
43 #include "MapTools.hh"
44 #include "Terminal.hh"
45 #include "hash_map.hh"
46 #include "NullInstruction.hh"
47 #include "Program.hh"
48 #include "boost/tuple/tuple_comparison.hpp"
49 
50 #include <algorithm>
51 #include <vector>
52 #include <string>
53 #include <iostream>
54 #include <iomanip>
55 
56 /**
57  * Constructor.
58  *
59  * @param frontend The SimulationFrontend which is used to access simulation
60  * data.
61  * @param instructions Used to fetch instruction execution counts.
62  */
64  SimulatorFrontend& frontend,
65  const InstructionMemory& instructions) :
66  frontend_(frontend), instructionExecutions_(instructions) {
67  frontend.eventHandler().registerListener(
69  frontend.eventHandler().registerListener(
71 }
72 
73 /**
74  * Destructor.
75  */
81 }
82 
83 /**
84  * Counts the concurrent register file accesses of current clock cycle.
85  */
86 void
88 
90 
91  // create a final sum stats which includes the conditional and unconditional
92  // executions
93 
94  totalAccesses_.clear();
95 
97  const TTAProgram::Instruction* currentInstruction =
98  &program.instructionAt(program.startAddress().location());
99  while (currentInstruction !=
101 
102  const ExecutableInstruction& execInstruction =
104  currentInstruction->address().location());
105 
106  if (!currentInstruction->hasRegisterAccesses() ||
107  currentInstruction->hasConditionalRegisterAccesses() ||
108  execInstruction.executionCount() == 0) {
109  currentInstruction = &program.nextInstruction(*currentInstruction);
110  continue;
111  }
112 
113  accessesInInstruction_.clear();
114 
115  for (int i = 0; i < currentInstruction->moveCount(); ++i) {
116  const TTAProgram::Move& move = currentInstruction->move(i);
117  if (move.source().isGPR()) {
119  move.source().registerFile().name().c_str()].get<1>();
120  }
121 
122  if (move.destination().isGPR()) {
124  move.destination().registerFile().name().c_str()].
125  get<0>();
126  }
127  }
128 
129  for (RFAccessIndex::iterator i = accessesInInstruction_.begin();
130  i != accessesInInstruction_.end(); ++i) {
131 
132  ConcurrentRFAccess key(
133  (*i).first, (*i).second.get<0>(), (*i).second.get<1>());
134  totalAccesses_[key] += execInstruction.executionCount();
135  }
136 
137  currentInstruction = &program.nextInstruction(*currentInstruction);
138  }
139 
140  // add the access data of the instruction with the conditional accesses
141  ConcurrentRFAccessIndex::iterator i = conditionalAccesses_.begin();
142  for (; i != conditionalAccesses_.end(); ++i) {
143  ConcurrentRFAccess key = (*i).first;
145  }
146 
147  } else if (event == SimulationEventHandler::SE_CYCLE_END) {
148 
149  const InstructionAddress& address =
151  const TTAProgram::Instruction& instruction =
152  frontend_.program().instructionAt(address);
153  if (!instruction.hasConditionalRegisterAccesses())
154  return;
155 
156  accessesInInstruction_.clear();
157 
158  const ExecutableInstruction& execInstruction =
160 
161  for (int i = 0; i < instruction.moveCount(); ++i) {
162  if (execInstruction.moveSquashed(i))
163  continue;
164  const TTAProgram::Move& move = instruction.move(i);
165  if (move.source().isGPR()) {
167  move.source().registerFile().name().c_str()].get<1>();
168  }
169 
170  if (move.destination().isGPR()) {
172  move.destination().registerFile().name().c_str()].get<0>();
173  }
174  }
175 
176  for (RFAccessIndex::iterator i = accessesInInstruction_.begin();
177  i != accessesInInstruction_.end(); ++i) {
178  ++conditionalAccesses_[boost::make_tuple(
179  (*i).first, (*i).second.get<0>(),
180  (*i).second.get<1>())];
181  }
182  } else {
183  abortWithError("RFAccessTracker received an unknown event.");
184  }
185 }
186 
187 /**
188  * Returns the count of clock cycles in which the given register file was
189  * written and read concurrently the given times.
190  *
191  * @param rfName Name of the register file.
192  * @param concurrentWrites Count of concurrent writes.
193  * @param concurrentReads Count of concurrent reads.
194  * @return The count of cycles in which the given count of concurrent accesses
195  * was made to the given register file.
196  */
199  const std::string& rfName,
200  std::size_t concurrentWrites,
201  std::size_t concurrentReads) const {
202  try {
203  return MapTools::valueForKey<ClockCycleCount>(
204  totalAccesses_, boost::make_tuple(
205  rfName, concurrentWrites, concurrentReads));
206  } catch (const Exception& e) {
207  return 0;
208  }
209 }
210 
211 /**
212  * Returns the access data base.
213  *
214  * In case statistics are not up-to-date, finalizes the calculation before
215  * returning the index.
216  *
217  * @return The access data base.
218  */
221  return totalAccesses_;
222 }
223 
InstructionMemory::instructionAtConst
const ExecutableInstruction & instructionAtConst(InstructionAddress address) const
TTAProgram::Program
Definition: Program.hh:63
ExecutableInstruction
Definition: ExecutableInstruction.hh:49
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
ExecutableInstruction::executionCount
ClockCycleCount executionCount() const
Definition: ExecutableInstruction.cc:85
SimulationEventHandler::SE_SIMULATION_STOPPED
@ SE_SIMULATION_STOPPED
Generated after simulation has stopped, temporarily or permantently, and control is being returned to...
Definition: SimulationEventHandler.hh:54
RFAccessTracker::ConcurrentRFAccessIndex
std::map< ConcurrentRFAccess, ClockCycleCount > ConcurrentRFAccessIndex
concurrent accesses and their counts
Definition: RFAccessTracker.hh:61
TTAProgram::Terminal::registerFile
virtual const TTAMachine::RegisterFile & registerFile() const
Definition: Terminal.cc:225
TTAProgram::Instruction::hasConditionalRegisterAccesses
bool hasConditionalRegisterAccesses() const
Definition: Instruction.cc:412
RFAccessTracker::ConcurrentRFAccess
boost::tuple< std::string, std::size_t, std::size_t > ConcurrentRFAccess
type to be used as a key for storing concurrent access info
Definition: RFAccessTracker.hh:58
TTAProgram::Instruction
Definition: Instruction.hh:57
MapTools.hh
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
InstructionMemory.hh
RFAccessTracker::accessesInInstruction_
RFAccessIndex accessesInInstruction_
container used in collecting register accesses in an instruction
Definition: RFAccessTracker.hh:93
Terminal.hh
InstructionMemory
Definition: InstructionMemory.hh:54
Listener::handleEvent
virtual void handleEvent()
Definition: Listener.cc:70
TTAProgram::Program::instructionAt
Instruction & instructionAt(InstructionAddress address) const
Definition: Program.cc:374
SimulationEventHandler.hh
SimulatorToolbox.hh
RFAccessTracker::concurrentRegisterFileAccessCount
ClockCycleCount concurrentRegisterFileAccessCount(const std::string &rfName, std::size_t concurrentWrites, std::size_t concurrentReads) const
Definition: RFAccessTracker.cc:198
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
Instruction.hh
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition: Informer.cc:104
SimulationEventHandler::SE_CYCLE_END
@ SE_CYCLE_END
Generated before advancing the simulator clock at the end of a simulation cycle.
Definition: SimulationEventHandler.hh:50
Application.hh
NullInstruction.hh
RFAccessTracker::instructionExecutions_
const InstructionMemory & instructionExecutions_
used to access instruction execution data
Definition: RFAccessTracker.hh:86
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition: Informer.cc:87
ExecutableInstruction::moveSquashed
bool moveSquashed(std::size_t moveIndex) const
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::Move
Definition: Move.hh:55
Machine.hh
Exception
Definition: Exception.hh:54
SimulatorFrontend::lastExecutedInstruction
virtual InstructionAddress lastExecutedInstruction(int coreId=-1) const
Definition: SimulatorFrontend.cc:1182
TTAProgram::NullInstruction::instance
static NullInstruction & instance()
Definition: NullInstruction.cc:66
RFAccessTracker::~RFAccessTracker
virtual ~RFAccessTracker()
Definition: RFAccessTracker.cc:76
SimulatorFrontend.hh
RFAccessTracker::RFAccessTracker
RFAccessTracker(SimulatorFrontend &frontend, const InstructionMemory &instructions)
Definition: RFAccessTracker.cc:63
TTAProgram::Instruction::hasRegisterAccesses
bool hasRegisterAccesses() const
Definition: Instruction.cc:399
RFAccessTracker::frontend_
SimulatorFrontend & frontend_
the simulator frontend used to access simulation data
Definition: RFAccessTracker.hh:84
hash_map.hh
RFAccessTracker::accessDataBase
const ConcurrentRFAccessIndex & accessDataBase() const
Definition: RFAccessTracker.cc:220
Program.hh
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
RFAccessTracker::conditionalAccesses_
ConcurrentRFAccessIndex conditionalAccesses_
conditional register file accesses are counted in this container
Definition: RFAccessTracker.hh:88
ExecutableInstruction.hh
RFAccessTracker.hh
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
Move.hh
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
RFAccessTracker::totalAccesses_
ConcurrentRFAccessIndex totalAccesses_
total (conditional + unconditional) register file accesses are counted in this container
Definition: RFAccessTracker.hh:91
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327