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 38

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

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

powered by: WebSVN 2.1.0

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