OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_verilator/] [simulator.h] - Blame information for rev 52

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
 
2
#ifndef SIMULATOR_H
3
        #define  SIMULATOR_H
4
 
5
#if (__cplusplus > 201103L) //"C++11\n";
6
 
7
        void* operator new(std::size_t size, std::align_val_t align) {
8
        #if defined(_WIN32) || defined(__CYGWIN__)
9
                auto ptr = _aligned_malloc(size, static_cast<std::size_t>(align));
10
        #else
11
                auto ptr = aligned_alloc(static_cast<std::size_t>(align), size);
12
        #endif
13
 
14
                if (!ptr)
15
                        throw std::bad_alloc{};
16
        /*
17
                std::cout << "new: " << size << ", align: "
18
                                  << static_cast<std::size_t>(align)
19
                                  << ", ptr: " << ptr << '\n';
20
        */
21
                return ptr;
22
 
23
        }
24
 
25
        void operator delete(void* ptr, std::size_t size, std::align_val_t align) noexcept {
26
        /*
27
                std::cout << "delete: " << size << ", align: "
28
                                  << static_cast<std::size_t>(align)
29
                                  << ", ptr : " << ptr << '\n';
30
        */
31
        #if defined(_WIN32) || defined(__CYGWIN__)
32
                _aligned_free(ptr);
33
        #else
34
                free(ptr);
35
        #endif
36
        }
37
 
38
        void operator delete(void* ptr, std::align_val_t align) noexcept {
39
          /*  std::cout << "delete: align: "
40
                                  << static_cast<std::size_t>(align)
41
                                  << ", ptr : " << ptr << '\n';
42
          */
43
        #if defined(_WIN32) || defined(__CYGWIN__)
44
                _aligned_free(ptr);
45
        #else
46
                free(ptr);
47
        #endif
48
        }
49
 
50
#endif
51
 
52
 
53
//traffic type
54
#define SYNTHETIC 0
55
#define TASK      1
56
#define NETRACE   2
57
#define STND_DEV_EN 1
58
 
59
 
60
int TRAFFIC_TYPE=SYNTHETIC;
61
 
62
 
63
void * addr1;
64
void * addr2;
65
 
66
int get_router_num (int , int );
67
 
68
 
69
 
70
        #define ideal_port router_top_v__DOT__router__DOT__router_is_ideal
71
        #define active_port router_top_v__DOT__router__DOT__nb_router_active
72
        #define pck_active_port  packet_injector_verilator__DOT__endp_is_active
73
        #define traffic_active_port traffic_gen_top__DOT__endp_is_active
74
 
75
        #define CHAN_SIZE   sizeof(router1[0]->chan_in[0])
76
 
77
        #define conect_r2r(T1,r1,p1,T2,r2,p2)  \
78
                memcpy(&router##T1 [r1]->chan_in[p1] , &router##T2 [r2]->chan_out[p2], CHAN_SIZE );
79
//              router_is_active[get_router_num(T1,r1)] |=(( router##T1 [r1]-> ideal_port!=0) |  (router##T2 [r2]-> active_port[p2]==1))
80
 
81
        #define connect_r2gnd(T,r,p)\
82
                memset(&router##T [r]->chan_in [p],0x00,CHAN_SIZE)
83
 
84
        #define connect_r2e(T,r,p,e) \
85
                addr1=(TRAFFIC_TYPE==NETRACE)? &pck_inj[e]->chan_out  : &traffic[e]->chan_out;\
86
                addr2=(TRAFFIC_TYPE==NETRACE)? &pck_inj[e]->chan_in  : &traffic[e]->chan_in;\
87
                memcpy(&router##T [r]->chan_in[p], addr1, CHAN_SIZE );\
88
                memcpy(addr2, &router##T [r]->chan_out[p], CHAN_SIZE );
89
//              router_is_active[get_router_num(T,r)] |= (TRAFFIC_TYPE==NETRACE)? \
90
                        (( router##T [r]-> ideal_port!=0) |  (pck_inj[e]->pck_active_port==1)):\
91
                        (( router##T [r]-> ideal_port!=0) |  (traffic[e]->traffic_active_port==1))
92
 
93
 
94
 
95
 
96
#define IS_SELF_LOOP_EN (strcmp(SELF_LOOP_EN ,"YES")==0)
97
 
98
 
99
#include "parameter.h"
100
//alignas(64) int router_is_active [NR]={1};
101
 
102
int reset,clk;
103
 
104
Vtraffic                *traffic[NE]; // for synthetic and trace traffic pattern
105
Vpck_inj        *pck_inj[NE]; // for netrace
106
 
107
unsigned int total_rsv_pck_num=0;
108
unsigned int total_sent_pck_num=0;
109
unsigned int end_sim_pck_num=0;
110
unsigned int sim_end_clk_num;
111
unsigned long int nt_tr_list_pck=0;
112
int netrace_speed_up =1;
113
 
114
unsigned int * rsv_size_array;
115
int AVG_PACKET_SIZE=5;
116
int MIN_PACKET_SIZE=5;
117
int MAX_PACKET_SIZE=5;
118
 
119
unsigned int rsvd_core_total_pck_num[NE]= {0};
120
unsigned int rsvd_core_total_flit_num[NE]= {0};
121
unsigned int rsvd_core_worst_delay[NE] =  {0};
122
unsigned int sent_core_total_pck_num[NE]= {0};
123
unsigned int sent_core_total_flit_num[NE]= {0};
124
unsigned int sent_core_worst_delay[NE] =  {0};
125
unsigned int random_var[NE] = {100};
126
 
127
 
128
typedef struct  statistic_struct {
129
        unsigned int pck_num;
130
        unsigned int flit_num;
131
        unsigned int worst_latency;
132
        unsigned int min_latency;
133
        double sum_clk_h2h;
134
        double sum_clk_h2t;
135
        double sum_clk_per_hop;
136
#if (STND_DEV_EN)
137
        double sum_clk_pow2;
138
#endif
139
 
140
} statistic_t;
141
 
142
 
143
typedef struct  avg_st_struct {
144
        double avg_latency_per_hop;
145
        double avg_latency_flit;
146
        double avg_latency_pck;
147
        double avg_throughput;
148
        double avg_pck_siz;
149
#if (STND_DEV_EN)
150
        double std_dev;
151
#endif
152
 
153
} avg_st_t;
154
 
155
#if (C>1)
156
        statistic_t sent_stat [NE][C];
157
        statistic_t rsvd_stat [NE][C];
158
#else
159
        statistic_t sent_stat [NE];
160
        statistic_t rsvd_stat [NE];
161
#endif
162
 
163
 
164
 
165
void update_statistic_at_ejection (     int     ,       unsigned int, unsigned int, unsigned int,  unsigned int, unsigned int );
166
void update_noc_statistic (     int);
167
unsigned char pck_class_in_gen(unsigned int);
168
unsigned int pck_dst_gen_task_graph ( unsigned int);
169
void print_statistic (void);
170
void print_parameter();
171
void reset_all_register();
172
void sim_eval_all (void);
173
void sim_final_all (void);
174
void traffic_clk_negedge_event(void);
175
void traffic_clk_posedge_event(void);
176
void connect_clk_reset_start_all(void);
177
unsigned int rnd_between (unsigned int, unsigned int );
178
void traffic_gen_init( void );
179
void  pck_inj_init(void);
180
void traffic_gen_final_report(void);
181
void processArgs (int, char ** );
182
void task_traffic_init (char * );
183
int parse_string ( char *, int *);
184
void update_pck_size(char *);
185
void update_custom_traffic (char *);
186
void update_hotspot(char * );
187
void initial_threads (void);
188
void print_statistic_new (unsigned long int);
189
 
190
 
191
 
192
#include "topology_top.h"
193
#include "traffic_task_graph.h"
194
#include "traffic_synthetic.h"
195
#include "netrace_lib.h"
196
 
197
 
198
#define RATIO_INIT              2
199
#define DISABLE -1
200
#define MY_VL_SETBIT_W(data,bit) (data[VL_BITWORD_I(bit)] |= (VL_UL(1) << VL_BITBIT_I(bit)))
201
 
202
#define RANDOM_RANGE 1
203
#define RANDOM_discrete 2
204
 
205
 
206
 
207
 
208
 
209
 
210
 
211
int HOTSPOT_NUM;
212
int  * class_percentage;
213
char * TRAFFIC;
214
char * netrace_file;
215
unsigned char FIXED_SRC_DST_PAIR;
216
unsigned char  NEw=0;
217
unsigned long int main_time = 0;     // Current simulation time
218
unsigned int saved_time = 0;
219
 
220
unsigned int sum_clk_h2h=0;
221
unsigned int sum_clk_h2t=0;
222
double           sum_clk_per_hop=0;
223
const int  CC=(C==0)? 1 : C;
224
unsigned int total_rsv_pck_num_per_class[CC]={0};
225
unsigned int sum_clk_h2h_per_class[CC]={0};
226
unsigned int sum_clk_h2t_per_class[CC]={0};
227
double           sum_clk_per_hop_per_class[CC]={0};
228
 
229
unsigned int clk_counter,ideal_rsv_cnt;
230
unsigned int count_en;
231
unsigned int total_active_endp;
232
char all_done=0;
233
unsigned int total_sent_flit_number =0;
234
unsigned int total_rsv_flit_number =0;
235
unsigned int total_rsv_flit_number_old=0;
236
int ratio=RATIO_INIT;
237
double first_avg_latency_flit,current_avg_latency_flit;
238
double sc_time_stamp ();
239
int pow2( int );
240
char inject_done=0;
241
char simulation_done=0;
242
char pck_size_sel=RANDOM_RANGE;
243
int  * discrete_size;
244
int  * discrete_prob;
245
int verbosity=1;
246
int thread_num =1;
247
 
248
 
249
 
250
 
251
 
252
 
253
#if (STND_DEV_EN)
254
        //#include <math.h>
255
        double sqroot (double s){
256
                int i;
257
                double root = s/3;
258
                if (s<=0) return 0;
259
                for(i=0;i<32;i++) root = (root +s/root)/2;
260
                return root;
261
        }
262
 
263
        double       sum_clk_pow2=0;
264
        double       sum_clk_pow2_per_class[C];
265
        double standard_dev( double , unsigned int, double);
266
#endif
267
 
268
 
269
 
270
 
271
#endif
272
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.