Switch.cc (9858:f2417ecf5cc9) Switch.cc (9863:9483739f83ee)
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;

--- 30 unchanged lines hidden (view full) ---

39
40using namespace std;
41using m5::stl_helpers::deletePointers;
42using m5::stl_helpers::operator<<;
43
44Switch::Switch(const Params *p) : BasicRouter(p)
45{
46 m_perfect_switch = new PerfectSwitch(m_id, this, p->virt_nets);
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;

--- 30 unchanged lines hidden (view full) ---

39
40using namespace std;
41using m5::stl_helpers::deletePointers;
42using m5::stl_helpers::operator<<;
43
44Switch::Switch(const Params *p) : BasicRouter(p)
45{
46 m_perfect_switch = new PerfectSwitch(m_id, this, p->virt_nets);
47 m_msg_counts.resize(MessageSizeType_NUM);
48 m_msg_bytes.resize(MessageSizeType_NUM);
47}
48
49Switch::~Switch()
50{
51 delete m_perfect_switch;
52
53 // Delete throttles (one per output port)
54 deletePointers(m_throttles);

--- 50 unchanged lines hidden (view full) ---

105
106 // Hook the queues to the PerfectSwitch
107 m_perfect_switch->addOutPort(intermediateBuffers, routing_table_entry);
108
109 // Hook the queues to the Throttle
110 throttle_ptr->addLinks(intermediateBuffers, out);
111}
112
49}
50
51Switch::~Switch()
52{
53 delete m_perfect_switch;
54
55 // Delete throttles (one per output port)
56 deletePointers(m_throttles);

--- 50 unchanged lines hidden (view full) ---

107
108 // Hook the queues to the PerfectSwitch
109 m_perfect_switch->addOutPort(intermediateBuffers, routing_table_entry);
110
111 // Hook the queues to the Throttle
112 throttle_ptr->addLinks(intermediateBuffers, out);
113}
114
113void
114Switch::clearRoutingTables()
115{
116 m_perfect_switch->clearRoutingTables();
117}
118
119void
120Switch::clearBuffers()
121{
122 m_perfect_switch->clearBuffers();
123 for (int i = 0; i < m_throttles.size(); i++) {
124 if (m_throttles[i] != NULL) {
125 m_throttles[i]->clear();
126 }
127 }
128}
129
130void
131Switch::reconfigureOutPort(const NetDest& routing_table_entry)
132{
133 m_perfect_switch->reconfigureOutPort(routing_table_entry);
134}
135
136const Throttle*
137Switch::getThrottle(LinkID link_number) const
138{
139 assert(m_throttles[link_number] != NULL);
140 return m_throttles[link_number];
141}
142
143const vector<Throttle*>*
144Switch::getThrottles() const
145{
146 return &m_throttles;
147}
148
149void
115const Throttle*
116Switch::getThrottle(LinkID link_number) const
117{
118 assert(m_throttles[link_number] != NULL);
119 return m_throttles[link_number];
120}
121
122const vector<Throttle*>*
123Switch::getThrottles() const
124{
125 return &m_throttles;
126}
127
128void
150Switch::printStats(std::ostream& out) const
129Switch::regStats()
151{
130{
152 ccprintf(out, "switch_%d_inlinks: %d\n", m_id,
153 m_perfect_switch->getInLinks());
154 ccprintf(out, "switch_%d_outlinks: %d\n", m_id,
155 m_perfect_switch->getOutLinks());
156
157 // Average link utilizations
158 double average_utilization = 0.0;
159 int throttle_count = 0;
160
161 for (int i = 0; i < m_throttles.size(); i++) {
162 Throttle* throttle_ptr = m_throttles[i];
163 if (throttle_ptr) {
164 average_utilization += throttle_ptr->getUtilization();
165 throttle_count++;
166 }
131 for (int link = 0; link < m_throttles.size(); link++) {
132 m_throttles[link]->regStats(name());
167 }
133 }
168 average_utilization =
169 throttle_count == 0 ? 0 : average_utilization / throttle_count;
170
134
171 // Individual link utilizations
172 out << "links_utilized_percent_switch_" << m_id << ": "
173 << average_utilization << endl;
174
175 for (int link = 0; link < m_throttles.size(); link++) {
176 Throttle* throttle_ptr = m_throttles[link];
177 if (throttle_ptr != NULL) {
178 out << " links_utilized_percent_switch_" << m_id
179 << "_link_" << link << ": "
180 << throttle_ptr->getUtilization() << " bw: "
181 << throttle_ptr->getLinkBandwidth()
182 << " base_latency: " << throttle_ptr->getLatency() << endl;
183 }
135 m_avg_utilization.name(name() + ".percent_links_utilized");
136 for (unsigned int i = 0; i < m_throttles.size(); i++) {
137 m_avg_utilization += m_throttles[i]->getUtilization();
184 }
138 }
185 out << endl;
139 m_avg_utilization /= Stats::constant(m_throttles.size());
186
140
187 // Traffic breakdown
188 for (int link = 0; link < m_throttles.size(); link++) {
189 Throttle* throttle_ptr = m_throttles[link];
190 if (!throttle_ptr)
191 continue;
141 for (unsigned int type = MessageSizeType_FIRST;
142 type < MessageSizeType_NUM; ++type) {
143 m_msg_counts[type]
144 .name(name() + ".msg_count." +
145 MessageSizeType_to_string(MessageSizeType(type)))
146 .flags(Stats::nozero)
147 ;
148 m_msg_bytes[type]
149 .name(name() + ".msg_bytes." +
150 MessageSizeType_to_string(MessageSizeType(type)))
151 .flags(Stats::nozero)
152 ;
192
153
193 const vector<vector<int> >& message_counts =
194 throttle_ptr->getCounters();
195 for (int int_type = 0; int_type < MessageSizeType_NUM; int_type++) {
196 MessageSizeType type = MessageSizeType(int_type);
197 const vector<int> &mct = message_counts[type];
198 int sum = accumulate(mct.begin(), mct.end(), 0);
199 if (sum == 0)
200 continue;
201
202 out << " outgoing_messages_switch_" << m_id
203 << "_link_" << link << "_" << type << ": " << sum << " "
204 << sum * m_network_ptr->MessageSizeType_to_int(type)
205 << " ";
206 out << mct;
207 out << " base_latency: "
208 << throttle_ptr->getLatency() << endl;
154 for (unsigned int i = 0; i < m_throttles.size(); i++) {
155 m_msg_counts[type] += m_throttles[i]->getMsgCount(type);
209 }
156 }
157 m_msg_bytes[type] = m_msg_counts[type] * Stats::constant(
158 Network::MessageSizeType_to_int(MessageSizeType(type)));
210 }
159 }
211 out << endl;
212}
213
214void
160}
161
162void
215Switch::clearStats()
163Switch::resetStats()
216{
217 m_perfect_switch->clearStats();
218 for (int i = 0; i < m_throttles.size(); i++) {
164{
165 m_perfect_switch->clearStats();
166 for (int i = 0; i < m_throttles.size(); i++) {
219 if (m_throttles[i] != NULL)
220 m_throttles[i]->clearStats();
167 m_throttles[i]->clearStats();
221 }
222}
223
224void
168 }
169}
170
171void
172Switch::collateStats()
173{
174 m_perfect_switch->collateStats();
175 for (int i = 0; i < m_throttles.size(); i++) {
176 m_throttles[i]->collateStats();
177 }
178}
179
180void
225Switch::print(std::ostream& out) const
226{
227 // FIXME printing
228 out << "[Switch]";
229}
230
231bool
232Switch::functionalRead(Packet *pkt)

--- 26 unchanged lines hidden ---
181Switch::print(std::ostream& out) const
182{
183 // FIXME printing
184 out << "[Switch]";
185}
186
187bool
188Switch::functionalRead(Packet *pkt)

--- 26 unchanged lines hidden ---