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, 14 years ago

Synthetic Initiator with the latests bugs fixed

File size: 12.5 KB
RevLine 
[123]1
[77]2/* -*- c++ -*-
[123]3 * File         : vci_synthetic_initiator.cpp
4 * Date         : 23/12/2010
[77]5 * Copyright    : UPMC / LIP6
6 * Authors      : Christophe Choichillon
[131]7 * Version      : 2.1
[77]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
[78]32#include "../include/vci_synthetic_initiator.h"
[106]33#include <iostream>
[77]34
35
[122]36#define DETERMINISTIC
[77]37
38namespace soclib { namespace caba {
39
40
[78]41#define tmpl(x) template<typename vci_param> x VciSyntheticInitiator<vci_param>
[77]42
[78]43  //using soclib::common::uint32_log2; 
44 
[77]45  ////////////////////////////////
46  //    Constructor
47  ////////////////////////////////
48
[78]49  tmpl(/**/)::VciSyntheticInitiator( 
[77]50      sc_module_name name,
[102]51      const soclib::common::MappingTable &mt,
52      const soclib::common::IntTab       &vci_index,
53      const uint32_t length,    // Packet length (flit numbers)
[128]54      const uint32_t rho,       // Offered load * 1000
[102]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
[78]63      )
[77]64
65    : soclib::caba::BaseModule(name),
66
67    p_clk("clk"),
68    p_resetn("resetn"),
69    p_vci("vci_ini"),
70
[98]71    m_srcid( mt.indexForId(vci_index) ),
[77]72    //  FIFOs
[81]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),
[131]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")               
[126]97{
[77]98
[131]99      r_pending_fsm = new sc_signal<bool>[m_tab_size];
100      r_pending_date = new sc_signal<uint64_t>[m_tab_size];
[77]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  /////////////////////////////////
[78]114  tmpl(/**/)::~VciSyntheticInitiator()
[77]115    /////////////////////////////////
116  {
[131]117        delete r_pending_fsm;
118        delete r_pending_date;
[77]119  }
120
[81]121  ///////////////////////////////////
[115]122  tmpl(uint32_t)::destAdress()
[81]123  ///////////////////////////////////
124  {
[115]125    return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ;
[81]126  }
127
[98]128
129  ///////////////////////////////////
[115]130  tmpl(uint32_t)::destAdress(uint32_t *rand_seed)
[98]131  ///////////////////////////////////
[115]132  {
133    return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ;
134  }
[98]135
[106]136 
[77]137  //////////////////////////////////
[106]138  tmpl(void)::print_trace()
139  //////////////////////////////////
140  {
[123]141        const char* state_cmd_str[] = { "IDLE",
142                                        "SINGLE_SEND",
143                                        "BC_SEND"};
[106]144
[123]145        const char* state_bc_rsp_str[] = {"IDLE",
146                                          "WAIT_RSP"};
147
[106]148        std::cout << "Vci_Synthetic_Initiator " << name()
[131]149                  << " : " << std::dec << r_cpt_cycles.read() << " cycles " 
[123]150                  << " : state_cmd_fsm = " << state_cmd_str[r_cmd_fsm] 
[131]151                  << " : state_rsp_fsm = " << state_bc_rsp_str[r_pending_fsm[0].read()] 
[128]152                  << " Adresse to send : " << std::hex << r_cmd_address.read()
[123]153                  << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() 
[131]154                  << " Number of packets sent : " << std::dec << r_nb_single.read() << " " << r_cmd_trdid.read() << std::endl;
[123]155        for(int i = 0; i < (1<<vci_param::T) ; i++){
[131]156          std::cout << "ID : " << i << " " << (uint64_t)(r_pending_date[i].read()) << std::endl;
[123]157        }
[106]158  }
159
160  //////////////////////////////////
161  tmpl(void)::printStats()
162  //////////////////////////////////
163  {
[131]164        std::cout << name() << " : "<< std::dec << r_cpt_cycles.read() << " cycles, " << r_nb_single.read() << " packets sent" << std::endl;
[122]165        if(m_bc_period)
[132]166        {
167          std::cout << "Number of broadcast sent and received : " << r_nb_bc.read() << std::endl;
[126]168          std::cout << ((double)r_latency_bc.read()/(double)r_nb_bc.read()) << std::endl;
[132]169        }
[106]170  }
171
172  //////////////////////////////////
[77]173  tmpl(void)::transition()
[106]174  //////////////////////////////////
[77]175  {
176    //  RESET         
[128]177    if ( ! p_resetn.read() ) 
178    {
[98]179      // Initializing seed for random numbers generation
[128]180
[122]181#ifndef DETERMINISTIC
[98]182      srand(time(NULL));
[115]183#endif
[77]184
[98]185      // Initializing FSMs
[123]186      r_cmd_fsm = VCI_IDLE;
[128]187      for(size_t i=0 ; i<m_tab_size ; i++) r_pending_fsm[i] = false;
[77]188
[98]189      // Initializing FIFOs
[128]190      r_date_fifo.init();
191      r_bc_fifo.init();
[77]192
[128]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;
[122]200     
[128]201      r_cmd_seed        = (uint32_t)m_srcid;
[77]202
203      return;
204    }
205
[128]206    bool    fifo_put = false;
207    bool    fifo_get = false;
208    bool    fifo_bc;
[77]209
[127]210    uint32_t m_local_seed ;
[106]211
[128]212    //////////////////
213    // VCI CMD FSM
214    //////////////////
[123]215    switch ( r_cmd_fsm.read() ) {
[78]216      case VCI_IDLE:
[77]217        {
[128]218          if (r_date_fifo.rok())
219          {
[131]220            if ( r_bc_fifo.read() == true )     // its a broadcast request
[128]221            {
[131]222              if ( r_pending_fsm[0].read() == false )   // no current broadcast
[128]223              {
[131]224                r_cmd_fsm = VCI_BC_SEND ;
225                r_cmd_address = 0x3 | (0x7c1f << vci_param::N-20) ;
[128]226              }
227            }
228            else                        // its a single request
229            {
230              int id = -1;
[131]231              for(int i = 1; i < m_tab_size; i++){      // ID 0 reserved for broadcast transactions
[128]232                if(r_pending_fsm[i].read() == false)
233                {
234                  id = i;
[123]235                  break;
236                }
237              }
[128]238              if(id != -1){
[123]239                r_cmd_fsm = VCI_SINGLE_SEND ;
[128]240                r_cmd_count = 0;
241                r_cmd_trdid = id;
[123]242              }
[122]243#ifdef DETERMINISTIC
[128]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;
[115]247#else
[128]248              r_cmd_address = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
[115]249#endif
[98]250            }
251          }
[77]252          break;
253        }
[78]254      case VCI_SINGLE_SEND:
[77]255        {
[128]256          if ( p_vci.cmdack.read())
257          {
[131]258            r_cmd_count = r_cmd_count.read() + 1;
[128]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 ;
[98]263            }
264          }
[77]265          break;
266        }
[128]267      case VCI_SINGLE_REGISTER:
268        {
[131]269          r_pending_date[r_cmd_trdid.read()] = (uint64_t)(r_date_fifo.read());
[128]270          r_pending_fsm[r_cmd_trdid.read()] = true;
271          fifo_get = true;
272          r_cmd_fsm = VCI_IDLE;
273        }
[123]274      case VCI_BC_SEND:
[77]275        {
[128]276          if (p_vci.cmdack.read()) 
277          {
[123]278            r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
[131]279            r_pending_fsm[0] = true;
280            r_pending_date[0] = (uint64_t)(r_date_fifo.read());
[128]281            fifo_get = true;
282            r_cmd_fsm = VCI_IDLE;
[123]283            break;
[81]284          }
[77]285        }
[123]286    } // end switch vci_fsm
287
[132]288   
[128]289    ///////////////////
290    // PENDING FSMs
291    //////////////////
[131]292    if(p_vci.rspval.read())
[128]293    {
[131]294      if(p_vci.rtrdid.read() == 0)      // not a broadcast
[128]295      {
[131]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      {
[128]307        assert( ( r_pending_fsm[(int)p_vci.rtrdid.read()] == true ) && 
[131]308                "illegal single response received");
[128]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());
[123]312      }
313    }
[77]314
[128]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;
[129]322      if (r_date_fifo.wok())   
323      {
324        r_nb_bc = r_nb_bc.read() + 1;
325        r_cpt_period = 0;
326      }
[81]327    }
[128]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    }
[81]334
[131]335    if ( m_bc_period && (r_cpt_period.read() > m_bc_period) && r_date_fifo.wok() ) 
336      r_cpt_period = 0;
[129]337    else
[131]338      r_cpt_period = r_cpt_period.read() + 1;
[129]339
[128]340    ////////////////////////
341    //  update fifos
342    ////////////////////////
[131]343    if (fifo_put){
344      if (fifo_get){
[128]345        r_date_fifo.put_and_get(r_cpt_cycles.read());
346        r_bc_fifo.put_and_get(fifo_bc);
[77]347      } else {
[131]348        r_date_fifo.simple_put(r_cpt_cycles.read());
[128]349        r_bc_fifo.simple_put(fifo_bc);
[77]350      }
351    } else {
[131]352      if (fifo_get){
[128]353        r_date_fifo.simple_get();
354        r_bc_fifo.simple_get();
[77]355      }
356    }
[98]357   
[128]358    ///////////////////////////
359    //  increment local time
360    ///////////////////////////
361    r_cpt_cycles = r_cpt_cycles.read() + 1;
[77]362
[81]363    return;
364
[77]365  } // end transition()
366
367  /////////////////////////////
368  tmpl(void)::genMoore()
[128]369  /////////////////////////////
[77]370  {
371    ////////////////////////////////////////////////////////////
[98]372    // Command signals on the p_vci port
[77]373    ////////////////////////////////////////////////////////////
[98]374     p_vci.cmd        = vci_param::CMD_WRITE;   
[81]375     p_vci.be         = 0xF;                             
[123]376     p_vci.srcid      = m_srcid;   
[81]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;           
[123]382     p_vci.rspack     = true;
[77]383
384
[123]385    switch ( r_cmd_fsm.read() ) {
[77]386
[78]387      //////////////////
388      case VCI_IDLE:
389        {
[81]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;                 
[131]395          p_vci.pktid      = 0;     
[81]396          p_vci.eop     = false;                                   
[78]397          break;
398        }
399        //////////////////
400      case VCI_SINGLE_SEND:
401        {
[98]402          p_vci.cmdval  = true;                 
[131]403          p_vci.address = (addr_t)(r_cmd_address.read() + (r_cmd_count.read()*4)); 
[98]404          p_vci.plen    = m_length*4;                                         
405          p_vci.wdata   = 0;                                       
[131]406          p_vci.trdid   = r_cmd_trdid.read();                 
407          p_vci.pktid   = 0;     
408          if (r_cmd_count.read() == m_length - 1 ) {
[98]409            p_vci.eop     = true;                                   
410          } else {
411            p_vci.eop     = false;                                   
412          }
[78]413          break;
414        }
415        ///////////////////
416      case VCI_BC_SEND:
417        {
[98]418          p_vci.cmdval  = true;                 
[128]419          p_vci.address = (addr_t) r_cmd_address.read(); 
[98]420          p_vci.plen    = 4;                                         
421          p_vci.wdata   = 0;                                       
422          p_vci.trdid   = 0;                 
[131]423          p_vci.pktid   = 0;     
[98]424          p_vci.eop     = true;                                   
[78]425          break;
426        }
[131]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        }
[123]439    } // end switch vci_cmd_fsm
[77]440
441  } // end genMoore()
442
443}} // end name space
Note: See TracBrowser for help on using the repository browser.