-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvent.c
84 lines (57 loc) · 1.32 KB
/
Event.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <knightsim.h>
#include <rdtsc.h>
#define EVENTS 16
#define TOTAL_CYCLES 1000000
#define STACKSIZE 16384
void event(context * my_ctx);
void event_init(void);
long long p_pid = 0;
unsigned long long sim_start = 0;
unsigned long long sim_end = 0;
unsigned long long sim_time = 0;
int iters = 0;
int main(void){
//user must initialize DESim
KnightSim_init();
event_init();
/*starts simulation and won't return until simulation
is complete or all contexts complete*/
printf("Simulating %d events @ %d total\n", EVENTS, TOTAL_CYCLES);
sim_start = rdtsc();
simulate();
sim_time += (rdtsc() - sim_start);
//clean up
KnightSim_clean_up();
printf("End simulation time %llu cycles %llu events %d iters %d\n", sim_time, CYCLE, EVENTS, iters);
return 1;
}
void event_init(void){
int i = 0;
char buff[100];
//create the user defined contexts
for(i = 0; i < EVENTS; i++)
{
memset(buff,'\0' , 100);
snprintf(buff, 100, "events_%d", i);
context_create(event, DEFAULT_STACK_SIZE, strdup(buff), i);
}
return;
}
void event(context * my_ctx){
volatile int i = 0;
context_init_halt(my_ctx);
while(CYCLE < TOTAL_CYCLES)
{
while(i < 375)
i++;
iters++;
pause(1, my_ctx);
i = 0;
}
//context will terminate
return;
}