gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Switch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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 
30 
31 #include <numeric>
32 
33 #include "base/cast.hh"
34 #include "base/stl_helpers.hh"
39 
40 using namespace std;
42 using m5::stl_helpers::operator<<;
43 
45 {
46  m_perfect_switch = new PerfectSwitch(m_id, this, p->virt_nets);
47  m_port_buffers = p->port_buffers;
49 }
50 
52 {
53  delete m_perfect_switch;
54 
55  // Delete throttles (one per output port)
57 
58  // Delete MessageBuffers
60 }
61 
62 void
64 {
67 }
68 
69 void
71 {
73 }
74 
75 void
77  const NetDest& routing_table_entry,
78  Cycles link_latency, int bw_multiplier)
79 {
80  // Create a throttle
81  RubySystem *rs = m_network_ptr->params()->ruby_system;
82  Throttle* throttle_ptr = new Throttle(m_id, rs, m_throttles.size(),
83  link_latency, bw_multiplier,
85  this);
86 
87  m_throttles.push_back(throttle_ptr);
88 
89  // Create one buffer per vnet (these are intermediaryQueues)
90  vector<MessageBuffer*> intermediateBuffers;
91 
92  for (int i = 0; i < out.size(); ++i) {
93  assert(m_num_connected_buffers < m_port_buffers.size());
96  intermediateBuffers.push_back(buffer_ptr);
97  }
98 
99  // Hook the queues to the PerfectSwitch
100  m_perfect_switch->addOutPort(intermediateBuffers, routing_table_entry);
101 
102  // Hook the queues to the Throttle
103  throttle_ptr->addLinks(intermediateBuffers, out);
104 }
105 
106 const Throttle*
107 Switch::getThrottle(LinkID link_number) const
108 {
109  assert(m_throttles[link_number] != NULL);
110  return m_throttles[link_number];
111 }
112 
113 void
115 {
117 
118  for (int link = 0; link < m_throttles.size(); link++) {
119  m_throttles[link]->regStats(name());
120  }
121 
122  m_avg_utilization.name(name() + ".percent_links_utilized");
123  for (unsigned int i = 0; i < m_throttles.size(); i++) {
124  m_avg_utilization += m_throttles[i]->getUtilization();
125  }
127 
128  for (unsigned int type = MessageSizeType_FIRST;
129  type < MessageSizeType_NUM; ++type) {
131  .name(name() + ".msg_count." +
132  MessageSizeType_to_string(MessageSizeType(type)))
134  ;
136  .name(name() + ".msg_bytes." +
137  MessageSizeType_to_string(MessageSizeType(type)))
139  ;
140 
141  for (unsigned int i = 0; i < m_throttles.size(); i++) {
142  m_msg_counts[type] += m_throttles[i]->getMsgCount(type);
143  }
145  Network::MessageSizeType_to_int(MessageSizeType(type)));
146  }
147 }
148 
149 void
151 {
153  for (int i = 0; i < m_throttles.size(); i++) {
154  m_throttles[i]->clearStats();
155  }
156 }
157 
158 void
160 {
162  for (int i = 0; i < m_throttles.size(); i++) {
163  m_throttles[i]->collateStats();
164  }
165 }
166 
167 void
168 Switch::print(std::ostream& out) const
169 {
170  // FIXME printing
171  out << "[Switch]";
172 }
173 
174 bool
176 {
177  return false;
178 }
179 
180 uint32_t
182 {
183  // Access the buffers in the switch for performing a functional write
184  uint32_t num_functional_writes = 0;
185  for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
186  num_functional_writes += m_port_buffers[i]->functionalWrite(pkt);
187  }
188  return num_functional_writes;
189 }
190 
191 Switch *
192 SwitchParams::create()
193 {
194  return new Switch(this);
195 }
void addInPort(const std::vector< MessageBuffer * > &in)
Definition: Switch.cc:70
BasicRouterParams Params
Definition: BasicRouter.hh:42
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
void addLinks(const std::vector< MessageBuffer * > &in_vec, const std::vector< MessageBuffer * > &out_vec)
Definition: Throttle.cc:70
Bitfield< 7 > i
Definition: miscregs.hh:1378
uint32_t m_id
Definition: BasicRouter.hh:53
const Throttle * getThrottle(LinkID link_number) const
Definition: Switch.cc:107
~Switch()
Definition: Switch.cc:51
std::vector< MessageBuffer * > m_port_buffers
Definition: Switch.hh:92
void resetStats()
Reset statistics associated with this object.
Definition: Switch.cc:150
bool functionalRead(Packet *)
Definition: Switch.cc:175
std::vector< Throttle * > m_throttles
Definition: Switch.hh:91
PerfectSwitch * m_perfect_switch
Definition: Switch.hh:89
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:311
uint32_t functionalWrite(Packet *)
Definition: Switch.cc:181
int getEndpointBandwidth()
Definition: Switch.hh:57
Stats::Formula m_msg_bytes[MessageSizeType_NUM]
Definition: Switch.hh:98
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Switch.cc:63
SimpleNetwork * m_network_ptr
Definition: Switch.hh:90
void regStats()
Register statistics for this object.
Definition: Switch.cc:114
void collateStats()
Definition: Switch.cc:159
Temp constant(T val)
Definition: statistics.hh:3211
const Params * params() const
Definition: Network.hh:63
void deletePointers(C< T, A > &container)
Definition: stl_helpers.hh:77
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: BasicRouter.cc:39
void print(std::ostream &out) const
Definition: Switch.cc:168
unsigned m_num_connected_buffers
Definition: Switch.hh:93
void addOutPort(const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry)
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:110
void init(SimpleNetwork *)
Stats::Formula m_avg_utilization
Definition: Switch.hh:96
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:254
type
Definition: misc.hh:728
virtual const std::string name() const
Definition: sim_object.hh:117
Stats::Formula m_msg_counts[MessageSizeType_NUM]
Definition: Switch.hh:97
void addOutPort(const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry, Cycles link_latency, int bw_multiplier)
Definition: Switch.cc:76
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
Bitfield< 0 > p
Bitfield< 9, 8 > rs
Definition: miscregs.hh:1560
void addInPort(const std::vector< MessageBuffer * > &in)
void regStats() override
Register statistics for this object.
Switch(const Params *p)
Definition: Switch.cc:44
unsigned int LinkID
Definition: TypeDefines.hh:33

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