1 | /* -*- c++ -*- |
---|
2 | * File : vci_traffic_generator.cpp |
---|
3 | * Date : 26/08/2010 |
---|
4 | * Copyright : UPMC / LIP6 |
---|
5 | * Authors : Christophe Choichillon |
---|
6 | * |
---|
7 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
8 | * |
---|
9 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
10 | * |
---|
11 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU Lesser General Public License as published |
---|
13 | * by the Free Software Foundation; version 2.1 of the License. |
---|
14 | * |
---|
15 | * SoCLib is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * Lesser General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Lesser General Public |
---|
21 | * License along with SoCLib; if not, write to the Free Software |
---|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
23 | * 02110-1301 USA |
---|
24 | * |
---|
25 | * SOCLIB_LGPL_HEADER_END |
---|
26 | * |
---|
27 | * Maintainers: christophe.choichillon@lip6.fr |
---|
28 | */ |
---|
29 | |
---|
30 | #include "../include/vci_synthetic_initiator.h" |
---|
31 | #include <iostream> |
---|
32 | |
---|
33 | |
---|
34 | |
---|
35 | namespace soclib { namespace caba { |
---|
36 | |
---|
37 | |
---|
38 | #define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param> |
---|
39 | |
---|
40 | //using soclib::common::uint32_log2; |
---|
41 | |
---|
42 | //////////////////////////////// |
---|
43 | // Constructor |
---|
44 | //////////////////////////////// |
---|
45 | |
---|
46 | tmpl(/**/)::VciSyntheticInitiator( |
---|
47 | sc_module_name name, |
---|
48 | const soclib::common::MappingTable &mt, |
---|
49 | const soclib::common::IntTab &vci_index, |
---|
50 | const uint32_t length, // Packet length (flit numbers) |
---|
51 | const uint32_t rho, // Packets ratio on the network |
---|
52 | // const float rho, // Packets ratio on the network |
---|
53 | const uint32_t depth, // Fifo depth |
---|
54 | const uint32_t xmesh, |
---|
55 | const uint32_t ymesh, |
---|
56 | const uint32_t bc_period, // Broadcast period, if no broadcast => 0 |
---|
57 | const uint32_t xmin, |
---|
58 | const uint32_t xmax, |
---|
59 | const uint32_t ymin, |
---|
60 | const uint32_t ymax |
---|
61 | ) |
---|
62 | |
---|
63 | : soclib::caba::BaseModule(name), |
---|
64 | |
---|
65 | p_clk("clk"), |
---|
66 | p_resetn("resetn"), |
---|
67 | p_vci("vci_ini"), |
---|
68 | |
---|
69 | m_srcid( mt.indexForId(vci_index) ), |
---|
70 | // FIFOs |
---|
71 | m_length(length), |
---|
72 | m_rho(rho), |
---|
73 | m_depth(depth), |
---|
74 | m_xmesh(xmesh), |
---|
75 | m_ymesh(ymesh), |
---|
76 | m_bc_period(bc_period), |
---|
77 | m_xmin(xmin), |
---|
78 | m_xmax(xmax), |
---|
79 | m_ymin(ymin), |
---|
80 | m_ymax(ymax), |
---|
81 | m_date_fifo("m_date_fifo", depth), |
---|
82 | r_vci_fsm("r_vci_fsm") |
---|
83 | { |
---|
84 | |
---|
85 | |
---|
86 | SC_METHOD(transition); |
---|
87 | dont_initialize(); |
---|
88 | sensitive << p_clk.pos(); |
---|
89 | |
---|
90 | SC_METHOD(genMoore); |
---|
91 | dont_initialize(); |
---|
92 | sensitive << p_clk.neg(); |
---|
93 | |
---|
94 | } // end constructor |
---|
95 | |
---|
96 | |
---|
97 | ///////////////////////////////// |
---|
98 | tmpl(/**/)::~VciSyntheticInitiator() |
---|
99 | ///////////////////////////////// |
---|
100 | { |
---|
101 | } |
---|
102 | |
---|
103 | /////////////////////////////////// |
---|
104 | tmpl(size_t)::destAdress() |
---|
105 | /////////////////////////////////// |
---|
106 | { |
---|
107 | return (size_t) (rand() % (m_xmesh * m_ymesh)) ; |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | /////////////////////////////////// |
---|
112 | // tmpl(void)::destAdress(/*size_t X_local, size_t Y_local,*/ size_t &X_dest, size_t &Y_dest) |
---|
113 | /////////////////////////////////// |
---|
114 | // { |
---|
115 | // size_t x_dest_calc, y_dest_calc; |
---|
116 | // do{ |
---|
117 | // x_dest_calc = (rand()%m_xmesh); |
---|
118 | // y_dest_calc = (rand()%m_ymesh); |
---|
119 | // } while((x_dest_calc = m_x) && (y_dest_calc == m_y)); |
---|
120 | // } |
---|
121 | |
---|
122 | |
---|
123 | ////////////////////////////////// |
---|
124 | tmpl(void)::print_trace() |
---|
125 | ////////////////////////////////// |
---|
126 | { |
---|
127 | const char* state_str[] = { "IDLE", |
---|
128 | "SINGLE_SEND", |
---|
129 | "SINGLE_RECEIVE", |
---|
130 | "BC_SEND", |
---|
131 | "BC_RECEIVE" }; |
---|
132 | |
---|
133 | std::cout << "Vci_Synthetic_Initiator " << name() |
---|
134 | << " : " << m_cpt_cycles << " cycles " |
---|
135 | << " : state = " << state_str[r_vci_fsm] |
---|
136 | << " Adresse to send : " << m_address_to_send << std::endl; |
---|
137 | } |
---|
138 | |
---|
139 | ////////////////////////////////// |
---|
140 | tmpl(void)::printStats() |
---|
141 | ////////////////////////////////// |
---|
142 | { |
---|
143 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
144 | } |
---|
145 | |
---|
146 | ////////////////////////////////// |
---|
147 | tmpl(void)::transition() |
---|
148 | ////////////////////////////////// |
---|
149 | { |
---|
150 | // RESET |
---|
151 | if ( ! p_resetn.read() ) { |
---|
152 | // Initializing seed for random numbers generation |
---|
153 | srand(time(NULL)); |
---|
154 | |
---|
155 | // Initializing FSMs |
---|
156 | r_vci_fsm = VCI_IDLE; |
---|
157 | |
---|
158 | // Initializing FIFOs |
---|
159 | m_date_fifo.init(); |
---|
160 | |
---|
161 | // Activity counters |
---|
162 | m_cpt_cycles = 0; |
---|
163 | m_npackets = 0; |
---|
164 | |
---|
165 | r_broadcast_req = false; |
---|
166 | |
---|
167 | return; |
---|
168 | } |
---|
169 | |
---|
170 | bool date_fifo_put = false; |
---|
171 | bool date_fifo_get = false; |
---|
172 | |
---|
173 | // if (m_cpt_cycles == 0) { |
---|
174 | // m_rhos = 0.0 ; |
---|
175 | // } else { |
---|
176 | // m_rhos = static_cast<float>(m_npackets * m_length) / static_cast<float>(m_cpt_cycles) ; |
---|
177 | // } |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | switch ( r_vci_fsm.read() ) { |
---|
182 | |
---|
183 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
184 | //printStats(); |
---|
185 | ////////////////// |
---|
186 | case VCI_IDLE: |
---|
187 | { |
---|
188 | if (m_date_fifo.rok()){ |
---|
189 | if (r_broadcast_req.read()){ |
---|
190 | m_address_to_send = (((((((((m_xmin << 5) | m_xmax ) << 5 ) | m_ymin ) << 5 ) | m_ymax ) << 5 ) << vci_param::N-(4*5) ) | 0x3) | 0 ; |
---|
191 | r_vci_fsm = VCI_BC_SEND ; |
---|
192 | } else { |
---|
193 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
194 | m_address_to_send = destAdress() << 32-10; |
---|
195 | m_count = 0; |
---|
196 | } |
---|
197 | } |
---|
198 | break; |
---|
199 | } |
---|
200 | ////////////////// |
---|
201 | case VCI_SINGLE_SEND: |
---|
202 | { |
---|
203 | if (p_vci.cmdack.read()){ |
---|
204 | if (m_count == m_length-1) { |
---|
205 | m_start_latency1 = m_date_fifo.read(); |
---|
206 | m_start_latency2 = m_cpt_cycles; |
---|
207 | r_vci_fsm = VCI_SINGLE_RECEIVE ; |
---|
208 | } else { |
---|
209 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
210 | m_count++; |
---|
211 | } |
---|
212 | } |
---|
213 | break; |
---|
214 | } |
---|
215 | ////////////////////// |
---|
216 | case VCI_SINGLE_RECEIVE: |
---|
217 | { |
---|
218 | if (p_vci.rspval.read()) { |
---|
219 | m_start_latency1 = m_date_fifo.read(); |
---|
220 | m_start_latency2 = m_cpt_cycles; |
---|
221 | m_npackets++; |
---|
222 | date_fifo_get = true; |
---|
223 | m_address_to_send = 0; |
---|
224 | r_vci_fsm = VCI_IDLE ; |
---|
225 | } |
---|
226 | break; |
---|
227 | } |
---|
228 | /////////////////// |
---|
229 | case VCI_BC_SEND: |
---|
230 | { |
---|
231 | m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin); |
---|
232 | r_vci_fsm = VCI_BC_SEND; |
---|
233 | break; |
---|
234 | } |
---|
235 | //////////////////// |
---|
236 | case VCI_BC_RECEIVE: |
---|
237 | { |
---|
238 | if (p_vci.rspval.read()){ |
---|
239 | if (m_bc_nrsp == 0) { |
---|
240 | r_broadcast_req = false; |
---|
241 | m_address_to_send = 0; |
---|
242 | r_vci_fsm = VCI_IDLE ; |
---|
243 | } else { |
---|
244 | m_bc_nrsp--; |
---|
245 | r_vci_fsm = VCI_BC_RECEIVE ; |
---|
246 | } |
---|
247 | } |
---|
248 | break; |
---|
249 | } |
---|
250 | } // end switch vci_fsm |
---|
251 | |
---|
252 | |
---|
253 | /////////////////// Filling fifo |
---|
254 | if( ( (uint64_t)(m_rho*m_cpt_cycles) >= (uint64_t)(m_length*m_npackets*1000)) ){ |
---|
255 | if (m_date_fifo.wok()){ |
---|
256 | date_fifo_put = true ; |
---|
257 | } |
---|
258 | if (m_bc_period){ |
---|
259 | if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){ |
---|
260 | r_broadcast_req = true; |
---|
261 | } |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | if (date_fifo_put){ |
---|
266 | if (date_fifo_get){ |
---|
267 | m_date_fifo.put_and_get(m_cpt_cycles); |
---|
268 | } else { |
---|
269 | m_date_fifo.simple_put(m_cpt_cycles); |
---|
270 | } |
---|
271 | } else { |
---|
272 | if (date_fifo_get){ |
---|
273 | m_date_fifo.simple_get(); |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | m_cpt_cycles++; |
---|
278 | |
---|
279 | return; |
---|
280 | |
---|
281 | } // end transition() |
---|
282 | |
---|
283 | ///////////////////////////// |
---|
284 | tmpl(void)::genMoore() |
---|
285 | ///////////////////////////// |
---|
286 | { |
---|
287 | //////////////////////////////////////////////////////////// |
---|
288 | // Command signals on the p_vci port |
---|
289 | //////////////////////////////////////////////////////////// |
---|
290 | p_vci.cmd = vci_param::CMD_WRITE; |
---|
291 | p_vci.be = 0xF; |
---|
292 | p_vci.pktid = 0; |
---|
293 | p_vci.srcid = m_srcid; |
---|
294 | p_vci.cons = false; |
---|
295 | p_vci.wrap = false; |
---|
296 | p_vci.contig = true; |
---|
297 | p_vci.clen = 0; |
---|
298 | p_vci.cfixed = false; |
---|
299 | |
---|
300 | |
---|
301 | switch ( r_vci_fsm.read() ) { |
---|
302 | |
---|
303 | ////////////////// |
---|
304 | case VCI_IDLE: |
---|
305 | { |
---|
306 | p_vci.cmdval = false; |
---|
307 | p_vci.address = 0; |
---|
308 | p_vci.plen = 0; |
---|
309 | p_vci.wdata = 0; |
---|
310 | p_vci.trdid = 0; |
---|
311 | p_vci.eop = false; |
---|
312 | p_vci.rspack = false; |
---|
313 | break; |
---|
314 | } |
---|
315 | ////////////////// |
---|
316 | case VCI_SINGLE_SEND: |
---|
317 | { |
---|
318 | p_vci.cmdval = true; |
---|
319 | p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); |
---|
320 | p_vci.plen = m_length*4; |
---|
321 | p_vci.wdata = 0; |
---|
322 | p_vci.trdid = 0; |
---|
323 | if (m_count == m_length - 1 ) { |
---|
324 | p_vci.eop = true; |
---|
325 | } else { |
---|
326 | p_vci.eop = false; |
---|
327 | } |
---|
328 | p_vci.rspack = false; |
---|
329 | break; |
---|
330 | } |
---|
331 | ////////////////////// |
---|
332 | case VCI_SINGLE_RECEIVE: |
---|
333 | { |
---|
334 | p_vci.cmdval = false; |
---|
335 | p_vci.address = 0; |
---|
336 | p_vci.plen = 0; |
---|
337 | p_vci.wdata = 0; |
---|
338 | p_vci.trdid = 0; |
---|
339 | p_vci.eop = false; |
---|
340 | p_vci.rspack = true; |
---|
341 | break; |
---|
342 | } |
---|
343 | /////////////////// |
---|
344 | case VCI_BC_SEND: |
---|
345 | { |
---|
346 | p_vci.cmdval = true; |
---|
347 | p_vci.address = (addr_t) m_address_to_send; |
---|
348 | p_vci.plen = 4; |
---|
349 | p_vci.wdata = 0; |
---|
350 | p_vci.trdid = 0; |
---|
351 | p_vci.eop = true; |
---|
352 | p_vci.rspack = false; |
---|
353 | break; |
---|
354 | } |
---|
355 | //////////////////// |
---|
356 | case VCI_BC_RECEIVE: |
---|
357 | { |
---|
358 | p_vci.cmdval = false; |
---|
359 | p_vci.address = 0; |
---|
360 | p_vci.plen = 0; |
---|
361 | p_vci.wdata = 0; |
---|
362 | p_vci.trdid = 0; |
---|
363 | p_vci.eop = false; |
---|
364 | p_vci.rspack = true; |
---|
365 | break; |
---|
366 | } |
---|
367 | } // end switch vci_fsm |
---|
368 | |
---|
369 | } // end genMoore() |
---|
370 | |
---|
371 | }} // end name space |
---|