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 | //#define DETERMINISM |
---|
35 | |
---|
36 | namespace soclib { namespace caba { |
---|
37 | |
---|
38 | |
---|
39 | #define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param> |
---|
40 | |
---|
41 | //using soclib::common::uint32_log2; |
---|
42 | |
---|
43 | //////////////////////////////// |
---|
44 | // Constructor |
---|
45 | //////////////////////////////// |
---|
46 | |
---|
47 | tmpl(/**/)::VciSyntheticInitiator( |
---|
48 | sc_module_name name, |
---|
49 | const soclib::common::MappingTable &mt, |
---|
50 | const soclib::common::IntTab &vci_index, |
---|
51 | const uint32_t length, // Packet length (flit numbers) |
---|
52 | const uint32_t rho, // Packets ratio on the network |
---|
53 | // const float rho, // Packets ratio on the network |
---|
54 | const uint32_t depth, // Fifo depth |
---|
55 | const uint32_t xmesh, |
---|
56 | const uint32_t ymesh, |
---|
57 | const uint32_t bc_period, // Broadcast period, if no broadcast => 0 |
---|
58 | const uint32_t xmin, |
---|
59 | const uint32_t xmax, |
---|
60 | const uint32_t ymin, |
---|
61 | const uint32_t ymax |
---|
62 | ) |
---|
63 | |
---|
64 | : soclib::caba::BaseModule(name), |
---|
65 | |
---|
66 | p_clk("clk"), |
---|
67 | p_resetn("resetn"), |
---|
68 | p_vci("vci_ini"), |
---|
69 | |
---|
70 | m_srcid( mt.indexForId(vci_index) ), |
---|
71 | // FIFOs |
---|
72 | m_length(length), |
---|
73 | m_rho(rho), |
---|
74 | m_depth(depth), |
---|
75 | m_xmesh(xmesh), |
---|
76 | m_ymesh(ymesh), |
---|
77 | m_bc_period(bc_period), |
---|
78 | m_xmin(xmin), |
---|
79 | m_xmax(xmax), |
---|
80 | m_ymin(ymin), |
---|
81 | m_ymax(ymax), |
---|
82 | m_date_fifo("m_date_fifo", depth), |
---|
83 | m_local_seed(m_srcid), |
---|
84 | r_vci_fsm("r_vci_fsm") |
---|
85 | { |
---|
86 | |
---|
87 | |
---|
88 | SC_METHOD(transition); |
---|
89 | dont_initialize(); |
---|
90 | sensitive << p_clk.pos(); |
---|
91 | |
---|
92 | SC_METHOD(genMoore); |
---|
93 | dont_initialize(); |
---|
94 | sensitive << p_clk.neg(); |
---|
95 | |
---|
96 | } // end constructor |
---|
97 | |
---|
98 | |
---|
99 | ///////////////////////////////// |
---|
100 | tmpl(/**/)::~VciSyntheticInitiator() |
---|
101 | ///////////////////////////////// |
---|
102 | { |
---|
103 | } |
---|
104 | |
---|
105 | /////////////////////////////////// |
---|
106 | tmpl(uint32_t)::destAdress() |
---|
107 | /////////////////////////////////// |
---|
108 | { |
---|
109 | return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | /////////////////////////////////// |
---|
114 | tmpl(uint32_t)::destAdress(uint32_t *rand_seed) |
---|
115 | /////////////////////////////////// |
---|
116 | { |
---|
117 | return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | ////////////////////////////////// |
---|
122 | tmpl(void)::print_trace() |
---|
123 | ////////////////////////////////// |
---|
124 | { |
---|
125 | const char* state_str[] = { "IDLE", |
---|
126 | "SINGLE_SEND", |
---|
127 | "SINGLE_RECEIVE", |
---|
128 | "BC_SEND", |
---|
129 | "BC_RECEIVE" }; |
---|
130 | |
---|
131 | std::cout << "Vci_Synthetic_Initiator " << name() |
---|
132 | << " : " << std::dec << m_cpt_cycles << " cycles " |
---|
133 | << " : state = " << state_str[r_vci_fsm] |
---|
134 | << " Adresse to send : " << std::hex << m_address_to_send |
---|
135 | << " Number of broadcast to receive : " << std::dec << m_bc_nrsp << std::endl; |
---|
136 | } |
---|
137 | |
---|
138 | ////////////////////////////////// |
---|
139 | tmpl(void)::printStats() |
---|
140 | ////////////////////////////////// |
---|
141 | { |
---|
142 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
143 | } |
---|
144 | |
---|
145 | ////////////////////////////////// |
---|
146 | tmpl(void)::transition() |
---|
147 | ////////////////////////////////// |
---|
148 | { |
---|
149 | // RESET |
---|
150 | if ( ! p_resetn.read() ) { |
---|
151 | // Initializing seed for random numbers generation |
---|
152 | #ifndef DETERMINISM |
---|
153 | srand(time(NULL)); |
---|
154 | #endif |
---|
155 | |
---|
156 | // Initializing FSMs |
---|
157 | r_vci_fsm = VCI_IDLE; |
---|
158 | |
---|
159 | // Initializing FIFOs |
---|
160 | m_date_fifo.init(); |
---|
161 | |
---|
162 | // Activity counters |
---|
163 | m_cpt_cycles = 0; |
---|
164 | m_npackets = 0; |
---|
165 | |
---|
166 | r_broadcast_req = false; |
---|
167 | |
---|
168 | return; |
---|
169 | } |
---|
170 | |
---|
171 | bool date_fifo_put = false; |
---|
172 | bool date_fifo_get = false; |
---|
173 | |
---|
174 | // if (m_cpt_cycles == 0) { |
---|
175 | // m_rhos = 0.0 ; |
---|
176 | // } else { |
---|
177 | // m_rhos = static_cast<float>(m_npackets * m_length) / static_cast<float>(m_cpt_cycles) ; |
---|
178 | // } |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | switch ( r_vci_fsm.read() ) { |
---|
183 | |
---|
184 | std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl; |
---|
185 | //printStats(); |
---|
186 | ////////////////// |
---|
187 | case VCI_IDLE: |
---|
188 | { |
---|
189 | if (m_date_fifo.rok()){ |
---|
190 | if (r_broadcast_req.read()){ |
---|
191 | m_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ; |
---|
192 | r_vci_fsm = VCI_BC_SEND ; |
---|
193 | } else { |
---|
194 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
195 | #ifdef DETERMINISM |
---|
196 | m_address_to_send = destAdress(&m_local_seed) << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh)); |
---|
197 | #else |
---|
198 | m_address_to_send = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh)); |
---|
199 | #endif |
---|
200 | m_count = 0; |
---|
201 | } |
---|
202 | } |
---|
203 | break; |
---|
204 | } |
---|
205 | ////////////////// |
---|
206 | case VCI_SINGLE_SEND: |
---|
207 | { |
---|
208 | if (p_vci.cmdack.read()){ |
---|
209 | if (m_count == m_length-1) { |
---|
210 | m_start_latency1 = m_date_fifo.read(); |
---|
211 | m_start_latency2 = m_cpt_cycles; |
---|
212 | r_vci_fsm = VCI_SINGLE_RECEIVE ; |
---|
213 | } else { |
---|
214 | r_vci_fsm = VCI_SINGLE_SEND ; |
---|
215 | m_count++; |
---|
216 | } |
---|
217 | } |
---|
218 | break; |
---|
219 | } |
---|
220 | ////////////////////// |
---|
221 | case VCI_SINGLE_RECEIVE: |
---|
222 | { |
---|
223 | if (p_vci.rspval.read()) { |
---|
224 | m_start_latency1 = m_date_fifo.read(); |
---|
225 | m_start_latency2 = m_cpt_cycles; |
---|
226 | m_npackets++; |
---|
227 | date_fifo_get = true; |
---|
228 | m_address_to_send = 0; |
---|
229 | r_vci_fsm = VCI_IDLE ; |
---|
230 | } |
---|
231 | break; |
---|
232 | } |
---|
233 | /////////////////// |
---|
234 | case VCI_BC_SEND: |
---|
235 | { |
---|
236 | if (p_vci.cmdack.read()) { |
---|
237 | m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ; |
---|
238 | r_vci_fsm = VCI_BC_RECEIVE; |
---|
239 | break; |
---|
240 | } |
---|
241 | } |
---|
242 | //////////////////// |
---|
243 | case VCI_BC_RECEIVE: |
---|
244 | { |
---|
245 | if (p_vci.rspval.read()){ |
---|
246 | if (m_bc_nrsp == 1) { |
---|
247 | r_broadcast_req = false; |
---|
248 | m_address_to_send = 0; |
---|
249 | r_vci_fsm = VCI_IDLE ; |
---|
250 | } else { |
---|
251 | m_bc_nrsp--; |
---|
252 | r_vci_fsm = VCI_BC_RECEIVE ; |
---|
253 | } |
---|
254 | } |
---|
255 | break; |
---|
256 | } |
---|
257 | } // end switch vci_fsm |
---|
258 | |
---|
259 | |
---|
260 | /////////////////// Filling fifo |
---|
261 | if( ( (uint64_t)(m_rho*m_cpt_cycles) >= (uint64_t)(m_length*m_npackets*1000)) ){ |
---|
262 | if (m_date_fifo.wok()){ |
---|
263 | date_fifo_put = true ; |
---|
264 | } |
---|
265 | if (m_bc_period){ |
---|
266 | if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){ |
---|
267 | r_broadcast_req = true; |
---|
268 | } |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | if (date_fifo_put){ |
---|
273 | if (date_fifo_get){ |
---|
274 | m_date_fifo.put_and_get(m_cpt_cycles); |
---|
275 | } else { |
---|
276 | m_date_fifo.simple_put(m_cpt_cycles); |
---|
277 | } |
---|
278 | } else { |
---|
279 | if (date_fifo_get){ |
---|
280 | m_date_fifo.simple_get(); |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | m_cpt_cycles++; |
---|
285 | |
---|
286 | return; |
---|
287 | |
---|
288 | } // end transition() |
---|
289 | |
---|
290 | ///////////////////////////// |
---|
291 | tmpl(void)::genMoore() |
---|
292 | ///////////////////////////// |
---|
293 | { |
---|
294 | //////////////////////////////////////////////////////////// |
---|
295 | // Command signals on the p_vci port |
---|
296 | //////////////////////////////////////////////////////////// |
---|
297 | p_vci.cmd = vci_param::CMD_WRITE; |
---|
298 | p_vci.be = 0xF; |
---|
299 | p_vci.pktid = 0; |
---|
300 | p_vci.srcid = m_srcid; |
---|
301 | p_vci.cons = false; |
---|
302 | p_vci.wrap = false; |
---|
303 | p_vci.contig = true; |
---|
304 | p_vci.clen = 0; |
---|
305 | p_vci.cfixed = false; |
---|
306 | |
---|
307 | |
---|
308 | switch ( r_vci_fsm.read() ) { |
---|
309 | |
---|
310 | ////////////////// |
---|
311 | case VCI_IDLE: |
---|
312 | { |
---|
313 | p_vci.cmdval = false; |
---|
314 | p_vci.address = 0; |
---|
315 | p_vci.plen = 0; |
---|
316 | p_vci.wdata = 0; |
---|
317 | p_vci.trdid = 0; |
---|
318 | p_vci.eop = false; |
---|
319 | p_vci.rspack = false; |
---|
320 | break; |
---|
321 | } |
---|
322 | ////////////////// |
---|
323 | case VCI_SINGLE_SEND: |
---|
324 | { |
---|
325 | p_vci.cmdval = true; |
---|
326 | p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); |
---|
327 | p_vci.plen = m_length*4; |
---|
328 | p_vci.wdata = 0; |
---|
329 | p_vci.trdid = 0; |
---|
330 | if (m_count == m_length - 1 ) { |
---|
331 | p_vci.eop = true; |
---|
332 | } else { |
---|
333 | p_vci.eop = false; |
---|
334 | } |
---|
335 | p_vci.rspack = false; |
---|
336 | break; |
---|
337 | } |
---|
338 | ////////////////////// |
---|
339 | case VCI_SINGLE_RECEIVE: |
---|
340 | { |
---|
341 | p_vci.cmdval = false; |
---|
342 | p_vci.address = 0; |
---|
343 | p_vci.plen = 0; |
---|
344 | p_vci.wdata = 0; |
---|
345 | p_vci.trdid = 0; |
---|
346 | p_vci.eop = false; |
---|
347 | p_vci.rspack = true; |
---|
348 | break; |
---|
349 | } |
---|
350 | /////////////////// |
---|
351 | case VCI_BC_SEND: |
---|
352 | { |
---|
353 | p_vci.cmdval = true; |
---|
354 | p_vci.address = (addr_t) m_address_to_send; |
---|
355 | p_vci.plen = 4; |
---|
356 | p_vci.wdata = 0; |
---|
357 | p_vci.trdid = 0; |
---|
358 | p_vci.eop = true; |
---|
359 | p_vci.rspack = false; |
---|
360 | break; |
---|
361 | } |
---|
362 | //////////////////// |
---|
363 | case VCI_BC_RECEIVE: |
---|
364 | { |
---|
365 | p_vci.cmdval = false; |
---|
366 | p_vci.address = 0; |
---|
367 | p_vci.plen = 0; |
---|
368 | p_vci.wdata = 0; |
---|
369 | p_vci.trdid = 0; |
---|
370 | p_vci.eop = false; |
---|
371 | p_vci.rspack = true; |
---|
372 | break; |
---|
373 | } |
---|
374 | } // end switch vci_fsm |
---|
375 | |
---|
376 | } // end genMoore() |
---|
377 | |
---|
378 | }} // end name space |
---|