source: trunk/modules/vci_synthetic_initator/caba/sources/src/vci_synthetic_initiator.cpp @ 111

Last change on this file since 111 was 111, checked in by choichil, 14 years ago

Puisque c'est comme ça, je commite mon truc...

File size: 10.0 KB
Line 
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
35namespace 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
137                  << " Number of broadcast to receive : " << m_bc_nrsp << std::endl;
138  }
139
140  //////////////////////////////////
141  tmpl(void)::printStats()
142  //////////////////////////////////
143  {
144        std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl;
145  }
146
147  //////////////////////////////////
148  tmpl(void)::transition()
149  //////////////////////////////////
150  {
151    //  RESET         
152    if ( ! p_resetn.read() ) {
153      // Initializing seed for random numbers generation
154      srand(time(NULL));
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              m_address_to_send = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
196              m_count = 0;
197            }
198          }
199          break;
200        }
201        //////////////////
202      case VCI_SINGLE_SEND:
203        {
204          if (p_vci.cmdack.read()){
205            if (m_count == m_length-1) {
206              m_start_latency1 = m_date_fifo.read();
207              m_start_latency2 = m_cpt_cycles;
208              r_vci_fsm = VCI_SINGLE_RECEIVE ;
209            } else {
210              r_vci_fsm = VCI_SINGLE_SEND ;
211              m_count++;
212            }
213          }
214          break;
215        }
216        //////////////////////
217      case VCI_SINGLE_RECEIVE:
218        {
219          if (p_vci.rspval.read()) {
220            m_start_latency1 = m_date_fifo.read();
221            m_start_latency2 = m_cpt_cycles;
222            m_npackets++;
223            date_fifo_get = true;
224            m_address_to_send = 0;
225            r_vci_fsm = VCI_IDLE ;
226          }
227          break;
228        }
229        ///////////////////
230      case VCI_BC_SEND:
231        {
232          if (p_vci.cmdack.read()) {
233            m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
234            r_vci_fsm = VCI_BC_RECEIVE;
235            break;
236          }
237        }
238        ////////////////////
239      case VCI_BC_RECEIVE:
240        {
241          if (p_vci.rspval.read()){
242            if (m_bc_nrsp == 1) {
243              r_broadcast_req = false;
244              m_address_to_send = 0;
245              r_vci_fsm = VCI_IDLE ;
246            } else {
247              m_bc_nrsp--;
248              r_vci_fsm = VCI_BC_RECEIVE ;
249            }
250          }
251          break;
252        }
253    } // end switch vci_fsm
254
255
256    /////////////////// Filling fifo
257    if( ( (uint64_t)(m_rho*m_cpt_cycles) >= (uint64_t)(m_length*m_npackets*1000)) ){
258      if (m_date_fifo.wok()){
259        date_fifo_put = true ;
260      } 
261      if (m_bc_period){
262              if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){
263                      r_broadcast_req = true;
264              }
265      }
266    }
267
268    if (date_fifo_put){
269      if (date_fifo_get){
270        m_date_fifo.put_and_get(m_cpt_cycles);
271      } else {
272        m_date_fifo.simple_put(m_cpt_cycles);
273      }
274    } else {
275      if (date_fifo_get){
276        m_date_fifo.simple_get();
277      }
278    }
279   
280    m_cpt_cycles++;
281
282    return;
283
284  } // end transition()
285
286  /////////////////////////////
287  tmpl(void)::genMoore()
288    /////////////////////////////
289  {
290    ////////////////////////////////////////////////////////////
291    // Command signals on the p_vci port
292    ////////////////////////////////////////////////////////////
293     p_vci.cmd        = vci_param::CMD_WRITE;   
294     p_vci.be         = 0xF;                             
295     p_vci.pktid      = 0;     
296     p_vci.srcid      = m_srcid;   
297     p_vci.cons       = false;       
298     p_vci.wrap       = false;       
299     p_vci.contig     = true;       
300     p_vci.clen       = 0;         
301     p_vci.cfixed     = false;           
302
303
304    switch ( r_vci_fsm.read() ) {
305
306      //////////////////
307      case VCI_IDLE:
308        {
309          p_vci.cmdval  = false;                 
310          p_vci.address = 0; 
311          p_vci.plen    = 0;                                         
312          p_vci.wdata   = 0;                                       
313          p_vci.trdid   = 0;                 
314          p_vci.eop     = false;                                   
315          p_vci.rspack  = false;
316          break;
317        }
318        //////////////////
319      case VCI_SINGLE_SEND:
320        {
321          p_vci.cmdval  = true;                 
322          p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); 
323          p_vci.plen    = m_length*4;                                         
324          p_vci.wdata   = 0;                                       
325          p_vci.trdid   = 0;                 
326          if (m_count == m_length - 1 ) {
327            p_vci.eop     = true;                                   
328          } else {
329            p_vci.eop     = false;                                   
330          }
331          p_vci.rspack  = false;
332          break;
333        }
334        //////////////////////
335      case VCI_SINGLE_RECEIVE:
336        {
337          p_vci.cmdval  = false;                 
338          p_vci.address = 0; 
339          p_vci.plen    = 0;                                         
340          p_vci.wdata   = 0;                                       
341          p_vci.trdid   = 0;                 
342          p_vci.eop     = false;                                   
343          p_vci.rspack  = true;
344          break;
345        }
346        ///////////////////
347      case VCI_BC_SEND:
348        {
349          p_vci.cmdval  = true;                 
350          p_vci.address = (addr_t) m_address_to_send; 
351          p_vci.plen    = 4;                                         
352          p_vci.wdata   = 0;                                       
353          p_vci.trdid   = 0;                 
354          p_vci.eop     = true;                                   
355          p_vci.rspack  = false;
356          break;
357        }
358        ////////////////////
359      case VCI_BC_RECEIVE:
360        {
361          p_vci.cmdval  = false;                 
362          p_vci.address = 0; 
363          p_vci.plen    = 0;                                         
364          p_vci.wdata   = 0;                                       
365          p_vci.trdid   = 0;                 
366          p_vci.eop     = false;                                   
367          p_vci.rspack  = true;
368          break;
369        }
370    } // end switch vci_fsm
371
372  } // end genMoore()
373
374}} // end name space
Note: See TracBrowser for help on using the repository browser.