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 43

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

powered by: WebSVN 2.1.0

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