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

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

Initiator with only one FSM for responses

File size: 13.0 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_fsm("r_bc_fsm"),     
91    //r_bc_date("r_bc_date"),   
92    r_bc_nrsp("r_bc_nrsp"),     
93    r_cpt_cycles("r_cpt_cycles"),               
94    r_cpt_period("r_cpt_period"),               
95    r_nb_single("r_nb_single"), 
96    r_latency_single("r_latency_single"),       
97    r_nb_bc("r_nb_bc"), 
98    r_latency_bc("r_latency_bc")               
[126]99{
[77]100
[131]101      r_pending_fsm = new sc_signal<bool>[m_tab_size];
102      r_pending_date = new sc_signal<uint64_t>[m_tab_size];
[77]103
104      SC_METHOD(transition);
105      dont_initialize();
106      sensitive << p_clk.pos();
107
108      SC_METHOD(genMoore);
109      dont_initialize();
110      sensitive << p_clk.neg();
111
112    } // end constructor
113
114
115  /////////////////////////////////
[78]116  tmpl(/**/)::~VciSyntheticInitiator()
[77]117    /////////////////////////////////
118  {
[131]119        delete r_pending_fsm;
120        delete r_pending_date;
[77]121  }
122
[81]123  ///////////////////////////////////
[115]124  tmpl(uint32_t)::destAdress()
[81]125  ///////////////////////////////////
126  {
[115]127    return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ;
[81]128  }
129
[98]130
131  ///////////////////////////////////
[115]132  tmpl(uint32_t)::destAdress(uint32_t *rand_seed)
[98]133  ///////////////////////////////////
[115]134  {
135    return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ;
136  }
[98]137
[106]138 
[77]139  //////////////////////////////////
[106]140  tmpl(void)::print_trace()
141  //////////////////////////////////
142  {
[123]143        const char* state_cmd_str[] = { "IDLE",
144                                        "SINGLE_SEND",
145                                        "BC_SEND"};
[106]146
[123]147        const char* state_bc_rsp_str[] = {"IDLE",
148                                          "WAIT_RSP"};
149
[106]150        std::cout << "Vci_Synthetic_Initiator " << name()
[131]151                  << " : " << std::dec << r_cpt_cycles.read() << " cycles " 
[123]152                  << " : state_cmd_fsm = " << state_cmd_str[r_cmd_fsm] 
[131]153                  << " : state_rsp_fsm = " << state_bc_rsp_str[r_pending_fsm[0].read()] 
[128]154                  << " Adresse to send : " << std::hex << r_cmd_address.read()
[123]155                  << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() 
[131]156                  << " Number of packets sent : " << std::dec << r_nb_single.read() << " " << r_cmd_trdid.read() << std::endl;
[123]157        for(int i = 0; i < (1<<vci_param::T) ; i++){
[131]158          std::cout << "ID : " << i << " " << (uint64_t)(r_pending_date[i].read()) << std::endl;
[123]159        }
[106]160  }
161
162  //////////////////////////////////
163  tmpl(void)::printStats()
164  //////////////////////////////////
165  {
[131]166        std::cout << name() << " : "<< std::dec << r_cpt_cycles.read() << " cycles, " << r_nb_single.read() << " packets sent" << std::endl;
[122]167        if(m_bc_period)
[126]168          std::cout << ((double)r_latency_bc.read()/(double)r_nb_bc.read()) << std::endl;
[106]169  }
170
171  //////////////////////////////////
[77]172  tmpl(void)::transition()
[106]173  //////////////////////////////////
[77]174  {
175    //  RESET         
[128]176    if ( ! p_resetn.read() ) 
177    {
[98]178      // Initializing seed for random numbers generation
[128]179
[122]180#ifndef DETERMINISTIC
[98]181      srand(time(NULL));
[115]182#endif
[77]183
[98]184      // Initializing FSMs
[123]185      r_cmd_fsm = VCI_IDLE;
[131]186      //r_bc_fsm = false;
[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          {
[131]278            //r_bc_fsm = true;
[123]279            r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
[131]280            //r_bc_date = (uint64_t)(r_date_fifo.read());
281            r_pending_fsm[0] = true;
282            r_pending_date[0] = (uint64_t)(r_date_fifo.read());
[128]283            fifo_get = true;
284            r_cmd_fsm = VCI_IDLE;
[123]285            break;
[81]286          }
[77]287        }
[123]288    } // end switch vci_fsm
289
[128]290    /////////////////////
291    // BC_FSM
292    /////////////////////
[131]293    //if ( r_pending_fsm[0].read() && p_vci.rspval.read() )
294    //{
295    //  if ( p_vci.rtrdid.read() == 0 ) r_bc_nrsp = r_bc_nrsp.read() - 1;
296    //  if (r_bc_nrsp.read() == 1)
297    //  {
298    //    //r_bc_fsm = false;
299    //    r_pending_fsm[0] = false ;
300    //    r_latency_bc = r_latency_bc.read() + (r_cpt_cycles.read() - r_pending_date[0].read());
301    //  }
302    //}
[77]303
[128]304    ///////////////////
305    // PENDING FSMs
306    //////////////////
[131]307    if(p_vci.rspval.read())
[128]308    {
[131]309      if(p_vci.rtrdid.read() == 0)      // not a broadcast
[128]310      {
[131]311        assert( ( r_pending_fsm[0].read() == true ) && 
312                "illegal broadcast response received");
313        r_bc_nrsp = r_bc_nrsp.read() - 1 ;
314        if(r_bc_nrsp.read() == 1) 
315        {
316          r_pending_fsm[0] = false;
317          r_latency_bc = r_latency_bc.read() + (r_cpt_cycles.read() - r_pending_date[0].read());
318        }
319      }
320      else
321      {
[128]322        assert( ( r_pending_fsm[(int)p_vci.rtrdid.read()] == true ) && 
[131]323                "illegal single response received");
[128]324        r_pending_fsm[p_vci.rtrdid.read()] = false;
325        r_latency_single = r_latency_single.read() + 
326                           (r_cpt_cycles.read() - r_pending_date[(int)p_vci.rtrdid.read()].read());
[123]327      }
328    }
[77]329
[128]330    ////////////////////////
331    //  traffic regulator
332    ////////////////////////
333    if ( m_bc_period && (r_cpt_period.read() > m_bc_period) )
334    { 
335      fifo_put = true ;
336      fifo_bc  = true;
[129]337      if (r_date_fifo.wok())   
338      {
339        r_nb_bc = r_nb_bc.read() + 1;
340        r_cpt_period = 0;
341      }
[81]342    }
[128]343    else if( ( (uint64_t)(m_rho*r_cpt_cycles.read()) > (uint64_t)(m_length*r_nb_single.read()*1000)) )
344    {
345      fifo_put = true ;
346      fifo_bc  = false;
347      if (r_date_fifo.wok())   r_nb_single = r_nb_single.read() + 1;
348    }
[81]349
[131]350    if ( m_bc_period && (r_cpt_period.read() > m_bc_period) && r_date_fifo.wok() ) 
351      r_cpt_period = 0;
[129]352    else
[131]353      r_cpt_period = r_cpt_period.read() + 1;
[129]354
[128]355    ////////////////////////
356    //  update fifos
357    ////////////////////////
[131]358    if (fifo_put){
359      if (fifo_get){
[128]360        r_date_fifo.put_and_get(r_cpt_cycles.read());
361        r_bc_fifo.put_and_get(fifo_bc);
[77]362      } else {
[131]363        r_date_fifo.simple_put(r_cpt_cycles.read());
[128]364        r_bc_fifo.simple_put(fifo_bc);
[77]365      }
366    } else {
[131]367      if (fifo_get){
[128]368        r_date_fifo.simple_get();
369        r_bc_fifo.simple_get();
[77]370      }
371    }
[98]372   
[128]373    ///////////////////////////
374    //  increment local time
375    ///////////////////////////
376    r_cpt_cycles = r_cpt_cycles.read() + 1;
[77]377
[81]378    return;
379
[77]380  } // end transition()
381
382  /////////////////////////////
383  tmpl(void)::genMoore()
[128]384  /////////////////////////////
[77]385  {
386    ////////////////////////////////////////////////////////////
[98]387    // Command signals on the p_vci port
[77]388    ////////////////////////////////////////////////////////////
[98]389     p_vci.cmd        = vci_param::CMD_WRITE;   
[81]390     p_vci.be         = 0xF;                             
[123]391     p_vci.srcid      = m_srcid;   
[81]392     p_vci.cons       = false;       
393     p_vci.wrap       = false;       
394     p_vci.contig     = true;       
395     p_vci.clen       = 0;         
396     p_vci.cfixed     = false;           
[123]397     p_vci.rspack     = true;
[77]398
399
[123]400    switch ( r_cmd_fsm.read() ) {
[77]401
[78]402      //////////////////
403      case VCI_IDLE:
404        {
[81]405          p_vci.cmdval  = false;                 
406          p_vci.address = 0; 
407          p_vci.plen    = 0;                                         
408          p_vci.wdata   = 0;                                       
409          p_vci.trdid   = 0;                 
[131]410          p_vci.pktid      = 0;     
[81]411          p_vci.eop     = false;                                   
[78]412          break;
413        }
414        //////////////////
415      case VCI_SINGLE_SEND:
416        {
[98]417          p_vci.cmdval  = true;                 
[131]418          p_vci.address = (addr_t)(r_cmd_address.read() + (r_cmd_count.read()*4)); 
[98]419          p_vci.plen    = m_length*4;                                         
420          p_vci.wdata   = 0;                                       
[131]421          p_vci.trdid   = r_cmd_trdid.read();                 
422          p_vci.pktid   = 0;     
423          if (r_cmd_count.read() == m_length - 1 ) {
[98]424            p_vci.eop     = true;                                   
425          } else {
426            p_vci.eop     = false;                                   
427          }
[78]428          break;
429        }
430        ///////////////////
431      case VCI_BC_SEND:
432        {
[98]433          p_vci.cmdval  = true;                 
[128]434          p_vci.address = (addr_t) r_cmd_address.read(); 
[98]435          p_vci.plen    = 4;                                         
436          p_vci.wdata   = 0;                                       
437          p_vci.trdid   = 0;                 
[131]438          p_vci.pktid   = 0;     
[98]439          p_vci.eop     = true;                                   
[78]440          break;
441        }
[131]442      //////////////////
443      case VCI_SINGLE_REGISTER:
444        {
445          p_vci.cmdval  = false;                 
446          p_vci.address = 0; 
447          p_vci.plen    = 0;                                         
448          p_vci.wdata   = 0;                                       
449          p_vci.trdid   = 0;                 
450          p_vci.pktid   = 0;     
451          p_vci.eop     = false;                                   
452          break;
453        }
[123]454    } // end switch vci_cmd_fsm
[77]455
456  } // end genMoore()
457
458}} // end name space
Note: See TracBrowser for help on using the repository browser.