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
|
/* wrapper for sys_add_server
*
* Input: a file with on each line:
* npsf_id cpu budget(us)
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "litmus.h"
#include "common.h"
void usage(char *error) {
fprintf(stderr, "Error: %s\n", error);
fprintf(stderr,
"Usage: npsf_add_server SERVERS-FILE MAX-SPLITS-PER-NPSFID\n");
exit(1);
}
int main(int argc, char** argv)
{
int ret;
FILE *file;
int i,j;
int npsf_id, curr_id = -1;
int cpu, max_splits_server;
int budget_us;
struct npsf_budgets *budgets;
if (argc < 3)
usage("Arguments missing.");
max_splits_server = atoi(argv[2]);
if ((file = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "Cannot open %s\n", argv[1]);
return -1;
}
/* format: npsf_id cpu budget-us */
i = 0;
while (fscanf(file, "%d %d %d\n", &npsf_id, &cpu, &budget_us) != EOF) {
printf("Read: %d %d %d\n", npsf_id, cpu, budget_us);
if (curr_id == -1) {
curr_id = npsf_id;
budgets = malloc(max_splits_server *
sizeof(struct npsf_budgets));
for(j = 0; j < max_splits_server; j++) {
budgets[j].cpu = -1;
budgets[j].budget = 0;
}
}
if (npsf_id == curr_id) {
/* same notional processor, different cpu and budget */
budgets[i].cpu = cpu;
budgets[i].budget = (lt_t) (budget_us * 1000);
i++;
} else {
/* different notional processor */
/* add server */
printf("Adding npsf_id = %d\n", curr_id);
ret = add_server(&curr_id, budgets, 0);
if (ret < 0) {
fclose(file);
free(budgets);
printf("Cannot add Notional Processor %d\n",
curr_id);
return ret;
}
/* reinit new */
i = 0;
budgets = malloc(max_splits_server *
sizeof(struct npsf_budgets));
for(j = 0; j < max_splits_server; j++) {
budgets[j].cpu = -1;
budgets[j].budget = 0;
}
curr_id = npsf_id;
budgets[i].cpu = cpu;
budgets[i].budget = (lt_t) (budget_us * 1000);
i++;
}
}
if (ferror(file)) {
fprintf(stderr, "Error while reading\n");
fclose(file);
return -1;
}
/* save the last entry */
ret = add_server(&curr_id, budgets, 1);
printf("Adding npsf_id = %d\n", curr_id);
if (ret < 0) {
fclose(file);
free(budgets);
bail_out("Cannot add Notional Processor: ");
}
fclose(file);
return 0;
}
|