forked from CapstoneStorage/TOMS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conf.c
114 lines (98 loc) · 2.42 KB
/
conf.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
#include "gastask.h"
char *
trim(char *str)
{
char *p;
if (str == NULL)
return NULL;
for (p = str; *p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'; p++);
str = p;
if (*p != '\0') {
for (p = p + 1; *p != '\0'; p++);
for (p = p - 1; (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') && p != str; p--);
p[1] = '\0';
}
return str;
}
section_t
check_section(const char *line)
{
if (*line != '*')
return FALSE;
if (strncmp(line + 1, "genetic", 7) == 0)
return SECT_GENETIC;
if (strncmp(line + 1, "gentask", 7) == 0)
return SECT_GENTASK;
if (strncmp(line + 1, "cpufreq", 7) == 0)
return SECT_CPUFREQ;
if (strncmp(line + 1, "mem", 3) == 0)
return SECT_MEM;
if (strncmp(line + 1, "task", 4) == 0)
return SECT_TASK;
if(strncmp(line + 1, "gennetwork", 10) == 0)
return SECT_GENNETWORK;
if(strncmp(line + 1, "gennetcommander", 15) == 0)
return SECT_GENNETCOMMANDER;
if(strncmp(line + 1, "cloud", 5) == 0)
return SECT_CLOUD;
if(strncmp(line + 1, "offloadingratio", 15) == 0)
return SECT_OFFLOADINGRATIO;
if(strncmp(line + 1, "network", 7) == 0)
return SECT_NETWORK;
if(strncmp(line + 1, "netcommander", 12) == 0)
return SECT_NET_COMMANDER;
return SECT_UNKNOWN;
}
void
skip_section(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
}
}
void
parse_mem(FILE *fp)
{
char buf[1024];
while (fgets(buf, 1024, fp)) {
unsigned max_capacity;
double wcet_scale, power_active, power_idle;
char type[1024];
if (buf[0] == '#')
continue;
if (buf[0] == '\n' || buf[0] == '*') {
fseek(fp, -1 * strlen(buf), SEEK_CUR);
return;
}
if (sscanf(buf, "%s %u %lf %lf %lf", type, &max_capacity, &wcet_scale, &power_active, &power_idle) != 5) {
FATAL(2, "cannot load configuration: invalid memory spec: %s", trim(buf));
}
if (max_capacity == 0) {
FATAL(2, "invalid max memory capacity: %s", trim(buf));
}
if (wcet_scale < 0 || wcet_scale > 1) {
FATAL(2, "invalid memory wcet scale: %s", trim(buf));
}
if (power_active < 0 || power_idle < 0) {
FATAL(2, "invalid memory power: %s", trim(buf));
}
add_mem(type, max_capacity, wcet_scale, power_active, power_idle);
}
}
void
load_conf(const char *fpath)
{
FILE *fp;
fp = fopen(fpath, "r");
if (fp == NULL) {
FATAL(1, "configuration not found: %s", fpath);
}
parse_conf(fp);
fclose(fp);
}