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

Last change on this file since 132 was 132, checked in by choichil, 13 years ago

Synthetic Initiator with the latests bugs fixed

File size: 12.5 KB
Line 
1
2/* -*- c++ -*-
3 * File         : vci_synthetic_initiator.cpp
4 * Date         : 23/12/2010
5 * Copyright    : UPMC / LIP6
6 * Authors      : Christophe Choichillon
7 * Version      : 2.1
8 *
9 * SOCLIB_LGPL_HEADER_BEGIN
10 *
11 * This file is part of SoCLib, GNU LGPLv2.1.
12 *
13 * SoCLib is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU Lesser General Public License as published
15 * by the Free Software Foundation; version 2.1 of the License.
16 *
17 * SoCLib is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with SoCLib; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * 02110-1301 USA
26 *
27 * SOCLIB_LGPL_HEADER_END
28 *
29 * Maintainers: christophe.choichillon@lip6.fr
30 */
31
32#include "../include/vci_synthetic_initiator.h"
33#include <iostream>
34
35
36#define DETERMINISTIC
37
38namespace soclib { namespace caba {
39
40
41#define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param>
42
43  //using soclib::common::uint32_log2; 
44 
45  ////////////////////////////////
46  //    Constructor
47  ////////////////////////////////
48
49  tmpl(/**/)::VciSyntheticInitiator( 
50      sc_module_name name,
51      const soclib::common::MappingTable &mt,
52      const soclib::common::IntTab       &vci_index,
53      const uint32_t length,    // Packet length (flit numbers)
54      const uint32_t rho,       // Offered load * 1000
55      const uint32_t depth,     // Fifo depth
56      const uint32_t xmesh,     
57      const uint32_t ymesh,
58      const uint32_t bc_period, // Broadcast period, if no broadcast => 0
59      const uint32_t xmin, 
60      const uint32_t xmax,
61      const uint32_t ymin,
62      const uint32_t ymax
63      )
64
65    : soclib::caba::BaseModule(name),
66
67    p_clk("clk"),
68    p_resetn("resetn"),
69    p_vci("vci_ini"),
70
71    m_srcid( mt.indexForId(vci_index) ),
72    //  FIFOs
73    m_length(length),
74    m_rho(rho),
75    m_depth(depth),
76    m_xmesh(xmesh),
77    m_ymesh(ymesh),
78    m_bc_period(bc_period),
79    m_xmin(xmin),
80    m_xmax(xmax),
81    m_ymin(ymin),
82    m_ymax(ymax),
83    r_date_fifo("r_date_fifo", m_depth),
84    r_bc_fifo("r_bc_fifo", m_depth),
85    r_cmd_fsm("r_cmd_fsm"),
86    r_cmd_address("r_cmd_address"),             
87    r_cmd_trdid("r_cmd_trdid"), 
88    r_cmd_count("r_cmd_count"),         
89    r_cmd_seed("r_cmd_seed"),   
90    r_bc_nrsp("r_bc_nrsp"),     
91    r_cpt_cycles("r_cpt_cycles"),               
92    r_cpt_period("r_cpt_period"),               
93    r_nb_single("r_nb_single"), 
94    r_latency_single("r_latency_single"),       
95    r_nb_bc("r_nb_bc"), 
96    r_latency_bc("r_latency_bc")               
97{
98
99      r_pending_fsm = new sc_signal<bool>[m_tab_size];
100      r_pending_date = new sc_signal<uint64_t>[m_tab_size];
101
102      SC_METHOD(transition);
103      dont_initialize();
104      sensitive << p_clk.pos();
105
106      SC_METHOD(genMoore);
107      dont_initialize();
108      sensitive << p_clk.neg();
109
110    } // end constructor
111
112
113  /////////////////////////////////
114  tmpl(/**/)::~VciSyntheticInitiator()
115    /////////////////////////////////
116  {
117        delete r_pending_fsm;
118        delete r_pending_date;
119  }
120
121  ///////////////////////////////////
122  tmpl(uint32_t)::destAdress()
123  ///////////////////////////////////
124  {
125    return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ;
126  }
127
128
129  ///////////////////////////////////
130  tmpl(uint32_t)::destAdress(uint32_t *rand_seed)
131  ///////////////////////////////////
132  {
133    return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ;
134  }
135
136 
137  //////////////////////////////////
138  tmpl(void)::print_trace()
139  //////////////////////////////////
140  {
141        const char* state_cmd_str[] = { "IDLE",
142                                        "SINGLE_SEND",
143                                        "BC_SEND"};
144
145        const char* state_bc_rsp_str[] = {"IDLE",
146                                          "WAIT_RSP"};
147
148        std::cout << "Vci_Synthetic_Initiator " << name()
149                  << " : " << std::dec << r_cpt_cycles.read() << " cycles " 
150                  << " : state_cmd_fsm = " << state_cmd_str[r_cmd_fsm] 
151                  << " : state_rsp_fsm = " << state_bc_rsp_str[r_pending_fsm[0].read()] 
152                  << " Adresse to send : " << std::hex << r_cmd_address.read()
153                  << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() 
154                  << " Number of packets sent : " << std::dec << r_nb_single.read() << " " << r_cmd_trdid.read() << std::endl;
155        for(int i = 0; i < (1<<vci_param::T) ; i++){
156          std::cout << "ID : " << i << " " << (uint64_t)(r_pending_date[i].read()) << std::endl;
157        }
158  }
159
160  //////////////////////////////////
161  tmpl(void)::printStats()
162  //////////////////////////////////
163  {
164        std::cout << name() << " : "<< std::dec << r_cpt_cycles.read() << " cycles, " << r_nb_single.read() << " packets sent" << std::endl;
165        if(m_bc_period)
166        {
167          std::cout << "Number of broadcast sent and received : " << r_nb_bc.read() << std::endl;
168          std::cout << ((double)r_latency_bc.read()/(double)r_nb_bc.read()) << std::endl;
169        }
170  }
171
172  //////////////////////////////////
173  tmpl(void)::transition()
174  //////////////////////////////////
175  {
176    //  RESET         
177    if ( ! p_resetn.read() ) 
178    {
179      // Initializing seed for random numbers generation
180
181#ifndef DETERMINISTIC
182      srand(time(NULL));
183#endif
184
185      // Initializing FSMs
186      r_cmd_fsm = VCI_IDLE;
187      for(size_t i=0 ; i<m_tab_size ; i++) r_pending_fsm[i] = false;
188
189      // Initializing FIFOs
190      r_date_fifo.init();
191      r_bc_fifo.init();
192
193      // Initializing the instrumentation registers
194      r_latency_single          = 0 ;
195      r_nb_single               = 0;
196      r_latency_bc              = 0 ;
197      r_nb_bc                   = 0;
198      r_cpt_cycles              = 0;
199      r_cpt_period              = 0;
200     
201      r_cmd_seed        = (uint32_t)m_srcid;
202
203      return;
204    }
205
206    bool    fifo_put = false;
207    bool    fifo_get = false;
208    bool    fifo_bc;
209
210    uint32_t m_local_seed ;
211
212    //////////////////
213    // VCI CMD FSM
214    //////////////////
215    switch ( r_cmd_fsm.read() ) {
216      case VCI_IDLE:
217        {
218          if (r_date_fifo.rok())
219          {
220            if ( r_bc_fifo.read() == true )     // its a broadcast request
221            {
222              if ( r_pending_fsm[0].read() == false )   // no current broadcast
223              {
224                r_cmd_fsm = VCI_BC_SEND ;
225                r_cmd_address = 0x3 | (0x7c1f << vci_param::N-20) ;
226              }
227            }
228            else                        // its a single request
229            {
230              int id = -1;
231              for(int i = 1; i < m_tab_size; i++){      // ID 0 reserved for broadcast transactions
232                if(r_pending_fsm[i].read() == false)
233                {
234                  id = i;
235                  break;
236                }
237              }
238              if(id != -1){
239                r_cmd_fsm = VCI_SINGLE_SEND ;
240                r_cmd_count = 0;
241                r_cmd_trdid = id;
242              }
243#ifdef DETERMINISTIC
244              m_local_seed = r_cmd_seed.read();
245              r_cmd_address = destAdress(&m_local_seed) << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
246              r_cmd_seed = m_local_seed;
247#else
248              r_cmd_address = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
249#endif
250            }
251          }
252          break;
253        }
254      case VCI_SINGLE_SEND:
255        {
256          if ( p_vci.cmdack.read())
257          {
258            r_cmd_count = r_cmd_count.read() + 1;
259            if (r_cmd_count.read() == m_length-1) 
260            {
261              r_nb_single = r_nb_single.read() + 1;
262              r_cmd_fsm = VCI_SINGLE_REGISTER ;
263            }
264          }
265          break;
266        }
267      case VCI_SINGLE_REGISTER:
268        {
269          r_pending_date[r_cmd_trdid.read()] = (uint64_t)(r_date_fifo.read());
270          r_pending_fsm[r_cmd_trdid.read()] = true;
271          fifo_get = true;
272          r_cmd_fsm = VCI_IDLE;
273        }
274      case VCI_BC_SEND:
275        {
276          if (p_vci.cmdack.read()) 
277          {
278            r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
279            r_pending_fsm[0] = true;
280            r_pending_date[0] = (uint64_t)(r_date_fifo.read());
281            fifo_get = true;
282            r_cmd_fsm = VCI_IDLE;
283            break;
284          }
285        }
286    } // end switch vci_fsm
287
288   
289    ///////////////////
290    // PENDING FSMs
291    //////////////////
292    if(p_vci.rspval.read())
293    {
294      if(p_vci.rtrdid.read() == 0)      // not a broadcast
295      {
296        assert( ( r_pending_fsm[0].read() == true ) && 
297                "illegal broadcast response received");
298        r_bc_nrsp = r_bc_nrsp.read() - 1 ;
299        if(r_bc_nrsp.read() == 1) 
300        {
301          r_pending_fsm[0] = false;
302          r_latency_bc = r_latency_bc.read() + (r_cpt_cycles.read() - r_pending_date[0].read());
303        }
304      }
305      else
306      {
307        assert( ( r_pending_fsm[(int)p_vci.rtrdid.read()] == true ) && 
308                "illegal single response received");
309        r_pending_fsm[p_vci.rtrdid.read()] = false;
310        r_latency_single = r_latency_single.read() + 
311                           (r_cpt_cycles.read() - r_pending_date[(int)p_vci.rtrdid.read()].read());
312      }
313    }
314
315    ////////////////////////
316    //  traffic regulator
317    ////////////////////////
318    if ( m_bc_period && (r_cpt_period.read() > m_bc_period) )
319    { 
320      fifo_put = true ;
321      fifo_bc  = true;
322      if (r_date_fifo.wok())   
323      {
324        r_nb_bc = r_nb_bc.read() + 1;
325        r_cpt_period = 0;
326      }
327    }
328    else if( ( (uint64_t)(m_rho*r_cpt_cycles.read()) > (uint64_t)(m_length*r_nb_single.read()*1000)) )
329    {
330      fifo_put = true ;
331      fifo_bc  = false;
332      if (r_date_fifo.wok())   r_nb_single = r_nb_single.read() + 1;
333    }
334
335    if ( m_bc_period && (r_cpt_period.read() > m_bc_period) && r_date_fifo.wok() ) 
336      r_cpt_period = 0;
337    else
338      r_cpt_period = r_cpt_period.read() + 1;
339
340    ////////////////////////
341    //  update fifos
342    ////////////////////////
343    if (fifo_put){
344      if (fifo_get){
345        r_date_fifo.put_and_get(r_cpt_cycles.read());
346        r_bc_fifo.put_and_get(fifo_bc);
347      } else {
348        r_date_fifo.simple_put(r_cpt_cycles.read());
349        r_bc_fifo.simple_put(fifo_bc);
350      }
351    } else {
352      if (fifo_get){
353        r_date_fifo.simple_get();
354        r_bc_fifo.simple_get();
355      }
356    }
357   
358    ///////////////////////////
359    //  increment local time
360    ///////////////////////////
361    r_cpt_cycles = r_cpt_cycles.read() + 1;
362
363    return;
364
365  } // end transition()
366
367  /////////////////////////////
368  tmpl(void)::genMoore()
369  /////////////////////////////
370  {
371    ////////////////////////////////////////////////////////////
372    // Command signals on the p_vci port
373    ////////////////////////////////////////////////////////////
374     p_vci.cmd        = vci_param::CMD_WRITE;   
375     p_vci.be         = 0xF;                             
376     p_vci.srcid      = m_srcid;   
377     p_vci.cons       = false;       
378     p_vci.wrap       = false;       
379     p_vci.contig     = true;       
380     p_vci.clen       = 0;         
381     p_vci.cfixed     = false;           
382     p_vci.rspack     = true;
383
384
385    switch ( r_cmd_fsm.read() ) {
386
387      //////////////////
388      case VCI_IDLE:
389        {
390          p_vci.cmdval  = false;                 
391          p_vci.address = 0; 
392          p_vci.plen    = 0;                                         
393          p_vci.wdata   = 0;                                       
394          p_vci.trdid   = 0;                 
395          p_vci.pktid      = 0;     
396          p_vci.eop     = false;                                   
397          break;
398        }
399        //////////////////
400      case VCI_SINGLE_SEND:
401        {
402          p_vci.cmdval  = true;                 
403          p_vci.address = (addr_t)(r_cmd_address.read() + (r_cmd_count.read()*4)); 
404          p_vci.plen    = m_length*4;                                         
405          p_vci.wdata   = 0;                                       
406          p_vci.trdid   = r_cmd_trdid.read();                 
407          p_vci.pktid   = 0;     
408          if (r_cmd_count.read() == m_length - 1 ) {
409            p_vci.eop     = true;                                   
410          } else {
411            p_vci.eop     = false;                                   
412          }
413          break;
414        }
415        ///////////////////
416      case VCI_BC_SEND:
417        {
418          p_vci.cmdval  = true;                 
419          p_vci.address = (addr_t) r_cmd_address.read(); 
420          p_vci.plen    = 4;                                         
421          p_vci.wdata   = 0;                                       
422          p_vci.trdid   = 0;                 
423          p_vci.pktid   = 0;     
424          p_vci.eop     = true;                                   
425          break;
426        }
427      //////////////////
428      case VCI_SINGLE_REGISTER:
429        {
430          p_vci.cmdval  = false;                 
431          p_vci.address = 0; 
432          p_vci.plen    = 0;                                         
433          p_vci.wdata   = 0;                                       
434          p_vci.trdid   = 0;                 
435          p_vci.pktid   = 0;     
436          p_vci.eop     = false;                                   
437          break;
438        }
439    } // end switch vci_cmd_fsm
440
441  } // end genMoore()
442
443}} // end name space
Note: See TracBrowser for help on using the repository browser.