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

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

Removing useless prints

File size: 12.6 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.0
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,       // Packets ratio on the network
55    //  const float  rho,       // Packets ratio on the network
56      const uint32_t depth,     // Fifo depth
57      const uint32_t xmesh,     
58      const uint32_t ymesh,
59      const uint32_t bc_period, // Broadcast period, if no broadcast => 0
60      const uint32_t xmin, 
61      const uint32_t xmax,
62      const uint32_t ymin,
63      const uint32_t ymax
64      )
65
66    : soclib::caba::BaseModule(name),
67
68    p_clk("clk"),
69    p_resetn("resetn"),
70    p_vci("vci_ini"),
71
72    m_srcid( mt.indexForId(vci_index) ),
73    //  FIFOs
74    m_length(length),
75    m_rho(rho),
76    m_depth(depth),
77    m_xmesh(xmesh),
78    m_ymesh(ymesh),
79    m_bc_period(bc_period),
80    m_xmin(xmin),
81    m_xmax(xmax),
82    m_ymin(ymin),
83    m_ymax(ymax),
84    m_date_fifo("m_date_fifo", depth),
85    r_count           ("r_count"),             
86    r_npackets        ("r_npackets"),           
87    r_start_latency1  ("r_start_latency1"), 
88    r_start_latency2  ("r_start_latency2"),   
89    r_latency1        ("r_latency1"),           
90    r_latency2        ("r_latency2"),           
91    r_address_to_send ("r_address_to_send"),     
92    r_local_seed      ("r_local_seed"),
93    r_id_to_send      ("r_id_to_send"),
94    r_start_latency_bc("r_start_latency_bc"),
95    r_latency_bc      ("r_latency_bc"),
96    r_nb_bc           ("r_nb_bc"),
97    r_cmd_fsm("r_cmd_fsm"),
98    r_bc_rsp_fsm("r_bc_rsp_fsm"),
99    r_index("r_index"),
100    r_broadcast_req("r_broadcast_req"),
101    r_broadcast_rsp("r_broadcast_rsp"),
102    r_bc_nrsp("r_bc_nrsp")                 
103    //r_req_id("r_req_id")
104{
105
106      r_req_id = new sc_signal<uint64_t>*[tab_size];
107      for(int i = 0; i < tab_size ; i++){
108        r_req_id[i] = new sc_signal<uint64_t>[2];
109      }
110
111      SC_METHOD(transition);
112      dont_initialize();
113      sensitive << p_clk.pos();
114
115      SC_METHOD(genMoore);
116      dont_initialize();
117      sensitive << p_clk.neg();
118
119    } // end constructor
120
121
122  /////////////////////////////////
123  tmpl(/**/)::~VciSyntheticInitiator()
124    /////////////////////////////////
125  {
126        for(int i = 0; i < tab_size ; i++){
127          delete r_req_id[i];
128        }
129        delete r_req_id;
130  }
131
132  ///////////////////////////////////
133  tmpl(uint32_t)::destAdress()
134  ///////////////////////////////////
135  {
136    return (uint32_t) (rand() % (m_xmesh * m_ymesh)) ;
137  }
138
139
140  ///////////////////////////////////
141  tmpl(uint32_t)::destAdress(uint32_t *rand_seed)
142  ///////////////////////////////////
143  {
144    return (uint32_t) (rand_r(rand_seed) % (m_xmesh * m_ymesh)) ;
145  }
146
147 
148  //////////////////////////////////
149  tmpl(void)::print_trace()
150  //////////////////////////////////
151  {
152        const char* state_cmd_str[] = { "IDLE",
153                                        "SINGLE_SEND",
154                                        "BC_SEND"};
155
156        const char* state_bc_rsp_str[] = {"IDLE",
157                                          "WAIT_RSP"};
158
159        std::cout << "Vci_Synthetic_Initiator " << name()
160                  << " : " << std::dec << m_cpt_cycles << " cycles " 
161                  << " : state_cmd_fsm = " << state_cmd_str[r_cmd_fsm] 
162                  << " : state_rsp_fsm = " << state_bc_rsp_str[r_bc_rsp_fsm] 
163                  << " Adresse to send : " << std::hex << r_address_to_send.read()
164                  << " Number of broadcast to receive : " << std::dec << r_bc_nrsp.read() 
165                  << " Number of packets sent : " << std::dec << r_npackets.read() << " " << r_id_to_send.read() << std::endl;
166        for(int i = 0; i < (1<<vci_param::T) ; i++){
167          std::cout << "ID : " << i << " " << (uint64_t)(r_req_id[i][0].read()) << " " << (uint64_t)(r_req_id[i][1].read()) << std::endl;
168        }
169  }
170
171  //////////////////////////////////
172  tmpl(void)::printStats()
173  //////////////////////////////////
174  {
175        std::cout << name() << " : "<< std::dec << m_cpt_cycles << " cycles, " << r_npackets.read() << " packets sent" << std::endl;
176        std::cout << ((double)r_latency1.read()/(double)r_npackets.read()) << " | " << ((double)r_latency2.read()/(double)r_npackets.read()) << std::endl;
177        if(m_bc_period)
178          std::cout << ((double)r_latency_bc.read()/(double)r_nb_bc.read()) << std::endl;
179  }
180
181  //////////////////////////////////
182  tmpl(void)::transition()
183  //////////////////////////////////
184  {
185    //  RESET         
186    if ( ! p_resetn.read() ) {
187      // Initializing seed for random numbers generation
188#ifndef DETERMINISTIC
189      srand(time(NULL));
190#endif
191
192      // Initializing FSMs
193      r_cmd_fsm = VCI_IDLE;
194
195      r_bc_rsp_fsm = BC_RSP_IDLE;
196
197      // Initializing FIFOs
198      m_date_fifo.init();
199
200      // Initializing the stats
201      r_latency1 = 0 ;
202      r_latency2 = 0 ;
203      // Activity counters
204      m_cpt_cycles              = 0;
205     
206      r_start_latency_bc        = 0;
207      r_latency_bc              = 0;
208      r_nb_bc                   = 0;
209      r_id_to_send              = -1;
210
211      r_broadcast_req           = false;
212
213      r_broadcast_rsp           = false;
214
215      r_bc_nrsp                 = 0;
216      r_count                   = 0;       
217      r_npackets                = 0;     
218      r_start_latency1          = 0;       
219      r_start_latency2          = 0;       
220      r_address_to_send         = 0;     
221      r_local_seed              = (uint32_t)m_srcid;
222
223      r_latency_bc              = 0;
224
225      for(int i = 0; i < tab_size; i++){
226        r_req_id[i][0] = 0;
227        r_req_id[i][1] = 0;
228      }
229
230      return;
231    }
232
233    bool    date_fifo_put = false;
234    bool    date_fifo_get = false;
235
236    uint32_t m_local_seed ;
237
238
239    // FSM controling effective requests send
240    switch ( r_cmd_fsm.read() ) {
241      //////////////////
242      case VCI_IDLE:
243        {
244          if (m_date_fifo.rok()){
245            if (r_broadcast_req.read() && !r_broadcast_rsp.read()){
246              r_address_to_send = 0x3 | (0x7c1f << vci_param::N-20) ;
247              r_cmd_fsm = VCI_BC_SEND ;
248            } else {
249              r_id_to_send = -1;
250              for(int i = 0; i < tab_size; i++){
251                if(r_req_id[i][0].read() == 0){
252                  r_id_to_send = i;
253                  break;
254                }
255              }
256              if(r_id_to_send.read() == -1){
257                r_cmd_fsm = VCI_IDLE ;
258                break;
259              } else {
260                r_cmd_fsm = VCI_SINGLE_SEND ;
261              }
262#ifdef DETERMINISTIC
263              m_local_seed = r_local_seed.read();
264              r_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));
265              r_local_seed = m_local_seed;
266#else
267              r_address_to_send = destAdress() << (vci_param::N)-(soclib::common::uint32_log2((uint32_t)m_xmesh)+soclib::common::uint32_log2((uint32_t)m_ymesh));
268#endif
269              r_count = 0;
270            }
271          }
272          break;
273        }
274        //////////////////
275      case VCI_SINGLE_SEND:
276        {
277          if (p_vci.cmdack.read()){
278            if (r_count.read() == m_length-1) {
279              r_req_id[r_id_to_send.read()][0] = (uint64_t)(m_date_fifo.read());
280              r_req_id[r_id_to_send.read()][1] = m_cpt_cycles;
281              //std::cout << name () << " FIFO " << m_date_fifo.read() << std::endl;
282              date_fifo_get = true;
283              r_npackets = r_npackets.read() + 1;
284              r_cmd_fsm = VCI_IDLE ;
285            } else {
286              r_cmd_fsm = VCI_SINGLE_SEND ;
287              r_count = r_count.read() + 1;
288            }
289          }
290          break;
291        }
292      ///////////////////
293      case VCI_BC_SEND:
294        {
295          if (p_vci.rspval.read()) {
296            r_bc_nrsp = (m_xmax - m_xmin) * (m_ymax - m_ymin) ;
297            r_start_latency_bc = m_cpt_cycles;
298            r_broadcast_rsp = true;
299            date_fifo_get = true;
300            r_bc_rsp_fsm = VCI_IDLE;
301            break;
302          }
303        }
304    } // end switch vci_fsm
305
306    switch(r_bc_rsp_fsm.read()){
307      ///////////////////
308      case BC_RSP_IDLE:
309        {
310          if (p_vci.rspval.read() && r_broadcast_rsp.read()) {
311            r_bc_rsp_fsm = BC_RSP_WAIT_RSP;
312            break;
313          }
314        }
315      ////////////////////
316      case BC_RSP_WAIT_RSP:
317        {
318          if (p_vci.rspval.read() && (p_vci.rpktid.read() == 1)){
319            if (r_bc_nrsp == 1) {
320              r_broadcast_req = false;
321              r_broadcast_rsp = false;
322              //r_address_to_send.read() = 0;
323              r_latency_bc = r_latency_bc.read() + (m_cpt_cycles - r_start_latency_bc.read());
324              r_nb_bc = r_nb_bc.read() + 1;
325              r_bc_rsp_fsm = BC_RSP_IDLE ;
326            } else {
327              r_bc_nrsp = r_bc_nrsp.read() - 1;;
328              r_bc_rsp_fsm = BC_RSP_WAIT_RSP ;
329            }
330          }
331          break;
332        }   
333    }
334
335    if(p_vci.rspval.read()){
336      if((int)(p_vci.pktid.read()) == 0){
337        r_latency1 = r_latency1.read() + (m_cpt_cycles - r_req_id[(int)(p_vci.rtrdid.read())][0].read());
338        r_latency2 = r_latency2.read() + (m_cpt_cycles - r_req_id[(int)(p_vci.rtrdid.read())][1].read());
339        r_req_id[(int)(p_vci.rtrdid.read())][0] = 0;
340        r_req_id[(int)(p_vci.rtrdid.read())][1] = 0;
341        //std::cout << name() << " bla bla " << p_vci.rtrdid.read() << std::endl;
342      }
343    }
344
345    /////////////////// Filling fifo
346    if( ( (uint64_t)(m_rho*m_cpt_cycles) > (uint64_t)(m_length*r_npackets.read()*1000)) ){
347      if (m_date_fifo.wok()){
348        date_fifo_put = true ;
349      } 
350      if (m_bc_period){
351              if (!r_broadcast_req.read() && (m_cpt_cycles % m_bc_period)){
352                      r_broadcast_req = true;
353              }
354      }
355    }
356
357    if (date_fifo_put){
358      if (date_fifo_get){
359        m_date_fifo.put_and_get(m_cpt_cycles);
360      } else {
361        m_date_fifo.simple_put(m_cpt_cycles);
362      }
363    } else {
364      if (date_fifo_get){
365        m_date_fifo.simple_get();
366      }
367    }
368   
369    m_cpt_cycles++;
370
371    return;
372
373  } // end transition()
374
375  /////////////////////////////
376  tmpl(void)::genMoore()
377    /////////////////////////////
378  {
379    ////////////////////////////////////////////////////////////
380    // Command signals on the p_vci port
381    ////////////////////////////////////////////////////////////
382     p_vci.cmd        = vci_param::CMD_WRITE;   
383     p_vci.be         = 0xF;                             
384     p_vci.srcid      = m_srcid;   
385     p_vci.pktid      = 0;     
386     p_vci.cons       = false;       
387     p_vci.wrap       = false;       
388     p_vci.contig     = true;       
389     p_vci.clen       = 0;         
390     p_vci.cfixed     = false;           
391     p_vci.rspack     = true;
392
393
394    switch ( r_cmd_fsm.read() ) {
395
396      //////////////////
397      case VCI_IDLE:
398        {
399          p_vci.cmdval  = false;                 
400          p_vci.address = 0; 
401          p_vci.plen    = 0;                                         
402          p_vci.wdata   = 0;                                       
403          p_vci.trdid   = 0;                 
404          p_vci.eop     = false;                                   
405          break;
406        }
407        //////////////////
408      case VCI_SINGLE_SEND:
409        {
410          p_vci.cmdval  = true;                 
411          p_vci.address = (addr_t)(r_address_to_send.read() + (r_count.read()*4)); 
412          p_vci.plen    = m_length*4;                                         
413          p_vci.wdata   = 0;                                       
414          p_vci.trdid   = r_id_to_send.read();                 
415          if (r_count.read() == m_length - 1 ) {
416            p_vci.eop     = true;                                   
417          } else {
418            p_vci.eop     = false;                                   
419          }
420          break;
421        }
422        ///////////////////
423      case VCI_BC_SEND:
424        {
425          p_vci.cmdval  = true;                 
426          p_vci.address = (addr_t) r_address_to_send.read(); 
427          p_vci.plen    = 4;                                         
428          p_vci.wdata   = 0;                                       
429          p_vci.pktid   = 1;     
430          p_vci.trdid   = 0;                 
431          p_vci.eop     = true;                                   
432          break;
433        }
434    } // end switch vci_cmd_fsm
435
436  } // end genMoore()
437
438}} // end name space
Note: See TracBrowser for help on using the repository browser.