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/] [traffic_task_graph.h] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 alirezamon
#ifndef TRAFFIC_TASK_GRAPH_H
2
#define TRAFFIC_TASK_GRAPH_H
3
 
4
 
5 43 alirezamon
 
6 38 alirezamon
#define SET_AUTO -1
7
 
8
 
9
 
10
#define MAX_LINE_LEN 1000
11
#define DEAFULT_INIT_WEIGHT             1
12
#define DEAFULT_MIN_PCK_SIZE    8 // must be larger than 1
13
 
14
 
15
 
16
typedef struct INDEX_INFO{
17
        unsigned int active_index;
18
        unsigned int total_index;
19
} index_t;
20
 
21
 
22
 
23
typedef struct TRAFFIC_TASK {
24
        char enable;
25
    unsigned int src;
26 48 alirezamon
    unsigned int dst; // ID of the destination endpoint (PE)
27 38 alirezamon
    unsigned int bytes;
28
    unsigned int initial_weight;
29
    unsigned int min_pck_size;          //in flit
30
    unsigned int max_pck_size;          //in flit
31
 
32
    unsigned int avg_pck_size;          //in flit
33
    unsigned int estimated_total_pck_num;
34
    unsigned int burst_size;
35
    float injection_rate;
36
    unsigned int jnjct_var;
37
 
38
    unsigned int pck_sent;
39
    unsigned int byte_sent;
40
    unsigned int burst_sent;
41
} task_t;
42
 
43
 
44
 
45 48 alirezamon
typedef struct endpt {
46 38 alirezamon
     task_t task;
47 48 alirezamon
    struct endpt * next;
48
} endpt_t;
49 38 alirezamon
 
50
 
51
 
52
unsigned int total_active_routers=0;
53
unsigned int task_graph_total_pck_num=0;
54 48 alirezamon
unsigned int task_graph_min_pck_size=999999;
55
unsigned int task_graph_max_pck_size=0;
56
 
57
endpt_t * task_graph_data[NE];
58 43 alirezamon
index_t task_graph_abstract[NE];
59 38 alirezamon
 
60
 
61
 
62
 
63 48 alirezamon
void push(endpt_t ** head,  task_t task) {
64
    endpt_t * new_endpt;
65
    new_endpt =  (endpt_t *) malloc(sizeof(endpt_t));
66
    if( new_endpt == NULL){
67
        printf("ERROR: cannot allocate memory in push function\n");
68 38 alirezamon
            exit(1);
69
        }
70 48 alirezamon
    new_endpt->task=task;
71
    new_endpt->next = *head;
72
    *head = new_endpt;
73 38 alirezamon
}
74
 
75 48 alirezamon
int pop(endpt_t ** head) {
76 38 alirezamon
   // int retval = -1;
77 48 alirezamon
    endpt_t * next_endpt = NULL;
78 38 alirezamon
 
79
    if (*head == NULL) {
80
        return -1;
81
    }
82
 
83 48 alirezamon
    next_endpt = (*head)->next;
84 38 alirezamon
    //retval = (*head)->val;
85
    free(*head);
86 48 alirezamon
    *head = next_endpt;
87 38 alirezamon
        return 1;
88
    //return retval;
89
}
90
 
91
 
92 48 alirezamon
int remove_by_index(endpt_t ** head, int n) {
93 38 alirezamon
    int i = 0;
94
   // int retval = -1;
95 48 alirezamon
    endpt_t * current = *head;
96
    endpt_t * temp_endpt = NULL;
97 38 alirezamon
 
98
    if (n == 0) {
99
        return pop(head);
100
    }
101
 
102
    for (i = 0; i < n-1; i++) {
103
        if (current->next == NULL) {
104
            return -1;
105
        }
106
        current = current->next;
107
    }
108
 
109 48 alirezamon
    temp_endpt = current->next;
110
    //retval = temp_endpt->val;
111
    current->next = temp_endpt->next;
112
    free(temp_endpt);
113 38 alirezamon
    return 1;
114
 
115
}
116
 
117
 
118 48 alirezamon
int update_by_index(endpt_t * head,int loc,  task_t  task) {
119
    endpt_t * current = head;
120 38 alirezamon
        int i;
121
        for (i=0;i<loc && current != NULL;i++){
122
                current = current->next;
123
 
124
        }
125
        if(current == NULL) return 0;
126
        current->task=task;
127
    return 1;
128
 
129
}
130
 
131
 
132 48 alirezamon
int read(endpt_t * head, int loc,  task_t  * task ) {
133
    endpt_t * current = head;
134 38 alirezamon
        int i;
135
        for (i=0;i<loc && current != NULL;i++){
136
                current = current->next;
137
 
138
        }
139
        if(current == NULL) return 0;
140
        *task =  current->task;
141
    return 1;
142
}
143
 
144
 
145
char* removewhiteSpacses (char * oldstr ) {
146
        char *newstr = (char*) malloc(strlen(oldstr)+1);
147
        char *np = newstr, *op = oldstr;
148
        do {
149
           if (*op != ' ' && *op != '\t')
150
                   *np++ = *op;
151
        } while (*op++);
152
        return newstr;
153
}
154
 
155
 
156
int extract_traffic_data ( char * str,  task_t*  st)
157
{
158
 
159
        unsigned int src;
160 48 alirezamon
        unsigned int dst; // ID of the destination endpt (PE)
161 38 alirezamon
        unsigned int bytes;
162
        unsigned int initial_weight;
163
        unsigned int min_pck_size;              //in flit
164
        unsigned int max_pck_size;              //in flit
165
        unsigned int burst;
166
        float inject_rate;
167
        int jnjct_var;
168
 
169
        int n;
170
        n=sscanf( str, "%u,%u,%u,%u,%u,%u,%u,%f,%u",&src, &dst, &bytes, &initial_weight, &min_pck_size, &max_pck_size,&burst,&inject_rate,&jnjct_var);
171
 
172
        if (n<3) return 0;
173
 
174
        st->src = src;
175
        st->dst=dst;
176
        st->bytes=bytes;
177
        st->initial_weight=(n>3 && initial_weight >0 )? initial_weight :DEAFULT_INIT_WEIGHT;
178
        st->min_pck_size=  (n>4 && min_pck_size>1 )? min_pck_size : DEAFULT_MIN_PCK_SIZE;
179
        st->max_pck_size=  (n>5 && max_pck_size >= st->min_pck_size )? max_pck_size : st->min_pck_size;
180
        st->burst_size =   (n>6 )? burst : SET_AUTO;
181
        st->injection_rate= (n>7 )? inject_rate : SET_AUTO;
182
        st->jnjct_var= (n>8 )?  jnjct_var : 20;
183
        //
184
        st->avg_pck_size=  (st->min_pck_size + st->max_pck_size)/2;
185
        st->estimated_total_pck_num = (bytes*8) /(st->avg_pck_size*Fpay);
186
        if(st->estimated_total_pck_num==0) st->estimated_total_pck_num= 1;
187
        task_graph_total_pck_num=task_graph_total_pck_num+st->estimated_total_pck_num;
188 48 alirezamon
        if(task_graph_min_pck_size > st->min_pck_size ) task_graph_min_pck_size=  st->min_pck_size;
189
        if(task_graph_max_pck_size < st->max_pck_size ) task_graph_max_pck_size=  st->max_pck_size;
190 38 alirezamon
 
191
        st->pck_sent=0;
192
        st->byte_sent=0;
193
    st->burst_sent=0;
194
 
195
   return 1;
196
}
197
 
198 48 alirezamon
int calcualte_traffic_parameters(endpt_t * head[NE],index_t (* info)){
199 38 alirezamon
        int i,j;
200
         task_t  task;
201
 
202 43 alirezamon
        unsigned int max_bytes=0,accum[NE];
203
        unsigned int min_total[NE];
204 38 alirezamon
 
205
        //find the maximum bytes that an IP sends
206 43 alirezamon
        for(i=0;i<NE;i++){
207 38 alirezamon
 
208
                info[i].active_index=-1;
209
                j=0;
210
                accum[i]=0;
211
                if(head[i]!=NULL){
212
                        info[i].active_index=0;
213
 
214
                        min_total[i] = -1;
215
                        while(  read(head[i],j,&task)==1){
216
                                accum[i]=accum[i]+task.bytes;
217
                                if(  min_total[i] > task.estimated_total_pck_num) min_total[i] = task.estimated_total_pck_num;
218
                                j++;
219
                        }
220
                        info[i].total_index=j;
221
                        if(max_bytes < accum[i])        max_bytes=accum[i];
222
                }
223
 
224
        }
225
 
226
 
227 43 alirezamon
        for(i=0;i<NE;i++){
228 38 alirezamon
 
229
                j=0;
230
                if(head[i]!=NULL){
231
                        while(  read(head[i],j,&task)==1){
232
                                if(task.burst_size ==SET_AUTO) task.burst_size = task.estimated_total_pck_num/min_total[i];
233
                                if(task.injection_rate ==SET_AUTO) task.injection_rate= (float)(200*accum[i] / (3*max_bytes));
234
 
235
                                update_by_index(head[i],j,task);
236
                                j++;
237
                        }
238
                }
239
        }
240
        return 0;
241
}
242
 
243
 
244
 
245
 
246
 
247 48 alirezamon
void load_traffic_file(char * file, endpt_t * head[NE], index_t (* info)){
248 38 alirezamon
        FILE * in;
249
        char * line = NULL;
250
 
251
     task_t st;
252
    char l[MAX_LINE_LEN];
253
    in = fopen(file,"rb");
254
    int n,i;
255
 
256
    if(in == NULL){
257 48 alirezamon
        fprintf(stderr,"ERROR: cannot open %s file in read mode!\n",file);
258
        exit(1);
259 38 alirezamon
        }
260
 
261 43 alirezamon
    for(i=0;i<NE;i++){
262 38 alirezamon
                        head[i]=NULL;
263
    }
264
 
265
 
266
        while (fgets(l,MAX_LINE_LEN, in) != NULL)  {
267
                line = removewhiteSpacses(l);
268
        if(line[0] != '%' && line[0] != 0 ) {
269
                        n=extract_traffic_data(line, &st);
270 43 alirezamon
                        if(n==0 || st.dst >=NE) continue;// the  destination address must be smaller than NC
271 38 alirezamon
                    push(&head[st.src],st);
272
                }
273
        }
274
        fclose(in);
275
        calcualte_traffic_parameters(head,info);
276 43 alirezamon
        for(i=0;i<NE;i++){
277 38 alirezamon
                if(info[i].total_index !=0) total_active_routers++;
278
        }
279
}
280
 
281
 
282
 
283
 
284
#endif

powered by: WebSVN 2.1.0

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