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

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

Synthetic Initiator before being change for multiple requests

File size: 10.5 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#define DETERMINISTIC
35
36namespace 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 << name() << " : "<< std::dec << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl;
143        std::cout << ((double)m_latency1/(double)m_npackets) << " | " << ((double)m_latency2/(double)m_npackets) << std::endl;
144        if(m_bc_period)
145          std::cout << ((double)m_latency_bc/(double)m_nb_bc) << std::endl;
146  }
147
148  //////////////////////////////////
149  tmpl(void)::transition()
150  //////////////////////////////////
151  {
152    //  RESET         
153    if ( ! p_resetn.read() ) {
154      // Initializing seed for random numbers generation
155#ifndef DETERMINISTIC
156      srand(time(NULL));
157#endif
158
159      // Initializing FSMs
160      r_vci_fsm = VCI_IDLE;
161
162      // Initializing FIFOs
163      m_date_fifo.init();
164
165      // Initializing the stats
166      m_latency1 = 0 ;
167      m_latency2 = 0 ;
168      // Activity counters
169      m_cpt_cycles              = 0;
170      m_npackets                = 0;
171     
172      m_start_latency_bc        = 0;
173      m_latency_bc              = 0;
174      m_nb_bc                   = 0;
175
176      r_broadcast_req           = false;
177
178      return;
179    }
180
181    bool    date_fifo_put = false;
182    bool    date_fifo_get = false;
183
184
185
186    switch ( r_vci_fsm.read() ) {
187
188        std::cout << m_cpt_cycles << " cycles, " << m_npackets << " packets sent" << std::endl;
189      //printStats();
190      //////////////////
191      case VCI_IDLE:
192        {
193          if (m_date_fifo.rok()){
194            if (r_broadcast_req.read()){
195              m_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ;
196              r_vci_fsm = VCI_BC_SEND ;
197            } else {
198              r_vci_fsm = VCI_SINGLE_SEND ;
199#ifdef DETERMINISTIC
200              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));
201#else
202              m_address_to_send = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
203#endif
204              m_count = 0;
205            }
206          }
207          break;
208        }
209        //////////////////
210      case VCI_SINGLE_SEND:
211        {
212          if (p_vci.cmdack.read()){
213            if (m_count == m_length-1) {
214              m_start_latency1 = m_date_fifo.read();
215              m_start_latency2 = m_cpt_cycles;
216              r_vci_fsm = VCI_SINGLE_RECEIVE ;
217            } else {
218              r_vci_fsm = VCI_SINGLE_SEND ;
219              m_count++;
220            }
221          }
222          break;
223        }
224        //////////////////////
225      case VCI_SINGLE_RECEIVE:
226        {
227          if (p_vci.rspval.read()) {
228            m_latency1 = m_latency1 + (m_cpt_cycles - m_start_latency1);
229            m_latency2 = m_latency2 + (m_cpt_cycles - m_start_latency2);
230            m_npackets++;
231            date_fifo_get = true;
232            m_address_to_send = 0;
233            r_vci_fsm = VCI_IDLE ;
234          }
235          break;
236        }
237        ///////////////////
238      case VCI_BC_SEND:
239        {
240          if (p_vci.cmdack.read()) {
241            m_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
242            m_start_latency_bc = m_cpt_cycles;
243            r_vci_fsm = VCI_BC_RECEIVE;
244            break;
245          }
246        }
247        ////////////////////
248      case VCI_BC_RECEIVE:
249        {
250          if (p_vci.rspval.read()){
251            if (m_bc_nrsp == 1) {
252              r_broadcast_req = false;
253              m_address_to_send = 0;
254              date_fifo_get = true;
255              m_latency_bc = m_latency_bc + (m_cpt_cycles - m_start_latency_bc);
256              m_nb_bc++;
257              r_vci_fsm = VCI_IDLE ;
258            } else {
259              m_bc_nrsp--;
260              r_vci_fsm = VCI_BC_RECEIVE ;
261            }
262          }
263          break;
264        }
265    } // end switch vci_fsm
266
267
268    /////////////////// Filling fifo
269    if( ( (uint64_t)(m_rho*m_cpt_cycles) > (uint64_t)(m_length*m_npackets*1000)) ){
270      if (m_date_fifo.wok()){
271        date_fifo_put = true ;
272      } 
273      if (m_bc_period){
274              if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){
275                      r_broadcast_req = true;
276              }
277      }
278    }
279
280    if (date_fifo_put){
281      if (date_fifo_get){
282        m_date_fifo.put_and_get(m_cpt_cycles);
283      } else {
284        m_date_fifo.simple_put(m_cpt_cycles);
285      }
286    } else {
287      if (date_fifo_get){
288        m_date_fifo.simple_get();
289      }
290    }
291   
292    m_cpt_cycles++;
293
294    return;
295
296  } // end transition()
297
298  /////////////////////////////
299  tmpl(void)::genMoore()
300    /////////////////////////////
301  {
302    ////////////////////////////////////////////////////////////
303    // Command signals on the p_vci port
304    ////////////////////////////////////////////////////////////
305     p_vci.cmd        = vci_param::CMD_WRITE;   
306     p_vci.be         = 0xF;                             
307     p_vci.pktid      = 0;     
308     p_vci.srcid      = m_srcid;   
309     p_vci.cons       = false;       
310     p_vci.wrap       = false;       
311     p_vci.contig     = true;       
312     p_vci.clen       = 0;         
313     p_vci.cfixed     = false;           
314
315
316    switch ( r_vci_fsm.read() ) {
317
318      //////////////////
319      case VCI_IDLE:
320        {
321          p_vci.cmdval  = false;                 
322          p_vci.address = 0; 
323          p_vci.plen    = 0;                                         
324          p_vci.wdata   = 0;                                       
325          p_vci.trdid   = 0;                 
326          p_vci.eop     = false;                                   
327          p_vci.rspack  = false;
328          break;
329        }
330        //////////////////
331      case VCI_SINGLE_SEND:
332        {
333          p_vci.cmdval  = true;                 
334          p_vci.address = (addr_t)(m_address_to_send + (m_count*4)); 
335          p_vci.plen    = m_length*4;                                         
336          p_vci.wdata   = 0;                                       
337          p_vci.trdid   = 0;                 
338          if (m_count == m_length - 1 ) {
339            p_vci.eop     = true;                                   
340          } else {
341            p_vci.eop     = false;                                   
342          }
343          p_vci.rspack  = false;
344          break;
345        }
346        //////////////////////
347      case VCI_SINGLE_RECEIVE:
348        {
349          p_vci.cmdval  = false;                 
350          p_vci.address = 0; 
351          p_vci.plen    = 0;                                         
352          p_vci.wdata   = 0;                                       
353          p_vci.trdid   = 0;                 
354          p_vci.eop     = false;                                   
355          p_vci.rspack  = true;
356          break;
357        }
358        ///////////////////
359      case VCI_BC_SEND:
360        {
361          p_vci.cmdval  = true;                 
362          p_vci.address = (addr_t) m_address_to_send; 
363          p_vci.plen    = 4;                                         
364          p_vci.wdata   = 0;                                       
365          p_vci.trdid   = 0;                 
366          p_vci.eop     = true;                                   
367          p_vci.rspack  = false;
368          break;
369        }
370        ////////////////////
371      case VCI_BC_RECEIVE:
372        {
373          p_vci.cmdval  = false;                 
374          p_vci.address = 0; 
375          p_vci.plen    = 0;                                         
376          p_vci.wdata   = 0;                                       
377          p_vci.trdid   = 0;                 
378          p_vci.eop     = false;                                   
379          p_vci.rspack  = true;
380          break;
381        }
382    } // end switch vci_fsm
383
384  } // end genMoore()
385
386}} // end name space
Note: See TracBrowser for help on using the repository browser.