forked from oslab-ewha/memwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memwork.c
160 lines (134 loc) · 2.44 KB
/
memwork.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "simrts.h"
static void
usage(void)
{
fprintf(stdout,
"Usage: memwork <options> <config path>\n"
" <options>\n"
" -h: this message\n"
" -v: verbose mode\n"
" -t <max simulation time>: (default: 1000)\n"
" -p <policy>: dvshm, dvsdram, hm, dram, fixed\n"
);
}
extern policy_t policy_dvshm;
extern policy_t policy_dvsdram;
extern policy_t policy_hm;
extern policy_t policy_dram;
extern policy_t policy_fixed;
extern policy_t policy_dvshm_greedy;
extern policy_t policy_hm_chk;
unsigned max_simtime = 1000;
unsigned simtime;
policy_t *policy = NULL;
BOOL verbose;
static policy_t *all_policies[] = {
&policy_dvshm, &policy_dvsdram, &policy_hm, &policy_dram, &policy_fixed,
&policy_dvshm_greedy, NULL
};
void
errmsg(const char *fmt, ...)
{
va_list ap;
char *errmsg;
va_start(ap, fmt);
vasprintf(&errmsg, fmt, ap);
va_end(ap);
fprintf(stderr, "ERROR: %s\n", errmsg);
free(errmsg);
}
static void
setup_policy(const char *strpol)
{
int i;
for (i = 0; all_policies[i]; i++) {
if (strcmp(strpol, all_policies[i]->name) == 0) {
policy = all_policies[i];
return;
}
}
FATAL(1, "unknown policy: %s", strpol);
}
static void
parse_args(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "t:p:vh")) != -1) {
switch (c) {
case 't':
if (sscanf(optarg, "%u", &max_simtime) != 1) {
usage();
exit(1);
}
break;
case 'p':
setup_policy(optarg);
break;
case 'v':
verbose = TRUE;
break;
case 'h':
usage();
exit(0);
default:
errmsg("invalid option");
usage();
exit(1);
}
}
if (argc - optind < 1) {
usage();
exit(1);
}
load_conf(argv[optind]);
}
static void
runsim(void)
{
task_t *task;
if (policy->init != NULL) {
if (!policy->init())
FATAL(3, "failed to initialize policy");
}
if (!setup_tasks()) {
errmsg("failed to setup tasks");
return;
}
while (simtime <= max_simtime && (task = pop_head_task())) {
if (!schedule_task(task)) {
FATAL(2, "simulation failed");
}
check_queued_tasks();
add_utilization();
if (verbose)
show_queued_tasks();
}
report_result();
}
static void
runsim_all(void)
{
int i;
init_mems();
report_header();
for (i = 0; all_policies[i]; i++) {
policy = all_policies[i];
runsim();
simtime = 11;
cleanup_report();
reinit_tasks();
reinit_mems();
}
}
int
main(int argc, char *argv[])
{
parse_args(argc, argv);
if (policy == NULL)
runsim_all();
else {
init_mems();
runsim();
}
return 0;
}