diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-06-25 14:17:51 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-06-25 14:17:51 -0400 |
commit | 08e29e6e3928927ab5eb85dd3da06c772ac50cc1 (patch) | |
tree | ee2f5baa27590e3c274b4b264c2c19eea893e70b /bin | |
parent | 3bcf13b5c38f23b3663f6a7030ae34383f651b4e (diff) |
[NPS-F] Rework add_server() API
- add_server() syscall takes a npsf_id and an array of struct 'npsf_budgets'.
Each entry of the array is a tuple (cpu, budget) that defines the budget
reserved for the server 'npsf_id' on the cpu 'cpu'.
- Input data is read from a file with struture: "npsf_id cpu budget-us"
Diffstat (limited to 'bin')
-rw-r--r-- | bin/npsf_add_server.c | 99 |
1 files changed, 81 insertions, 18 deletions
diff --git a/bin/npsf_add_server.c b/bin/npsf_add_server.c index 3983e77..9fa59c0 100644 --- a/bin/npsf_add_server.c +++ b/bin/npsf_add_server.c | |||
@@ -1,4 +1,8 @@ | |||
1 | /* wrapper for sys_add_server */ | 1 | /* wrapper for sys_add_server |
2 | * | ||
3 | * Input: a file with on each line: | ||
4 | * npsf_id cpu budget(us) | ||
5 | */ | ||
2 | #include <stdio.h> | 6 | #include <stdio.h> |
3 | #include <stdlib.h> | 7 | #include <stdlib.h> |
4 | #include <unistd.h> | 8 | #include <unistd.h> |
@@ -9,37 +13,96 @@ | |||
9 | void usage(char *error) { | 13 | void usage(char *error) { |
10 | fprintf(stderr, "Error: %s\n", error); | 14 | fprintf(stderr, "Error: %s\n", error); |
11 | fprintf(stderr, | 15 | fprintf(stderr, |
12 | "Usage: npsf_add_server NPSF-ID UTIL SLOT-SIZE(ms) CPU \n"); | 16 | "Usage: npsf_add_server SERVERS-FILE MAX-SPLITS-PER-NPSFID\n"); |
13 | exit(1); | 17 | exit(1); |
14 | } | 18 | } |
15 | 19 | ||
16 | int main(int argc, char** argv) | 20 | int main(int argc, char** argv) |
17 | { | 21 | { |
18 | int ret; | 22 | int ret; |
19 | int cpu = 0; | 23 | FILE *file; |
20 | int npsf_id = 0; | 24 | int i,j; |
21 | double util = 0; | 25 | int npsf_id, curr_id = -1; |
22 | int slot_ms = 0; | 26 | int cpu, max_splits_server; |
23 | lt_t budget_ns = 0; | 27 | int budget_us; |
28 | struct npsf_budgets *budgets; | ||
24 | 29 | ||
25 | if (argc < 5) | 30 | if (argc < 3) |
26 | usage("Arguments missing."); | 31 | usage("Arguments missing."); |
27 | npsf_id = atoi(argv[1]); | ||
28 | util = atof(argv[2]); | ||
29 | slot_ms = atoi(argv[3]); | ||
30 | cpu = atoi(argv[4]); | ||
31 | 32 | ||
32 | if (util > 1) | 33 | max_splits_server = atoi(argv[2]); |
33 | usage("Utilization > 1"); | ||
34 | 34 | ||
35 | budget_ns = (lt_t)((__NS_PER_MS * util) * slot_ms); | 35 | if ((file = fopen(argv[1], "r")) == NULL) { |
36 | fprintf(stderr, "Cannot open %s\n", argv[1]); | ||
37 | return -1; | ||
38 | } | ||
36 | 39 | ||
37 | printf("Trying to add NP(%d): budget = %f\n", npsf_id, (double)(budget_ns) / __NS_PER_MS); | 40 | /* format: npsf_id cpu budget-us */ |
41 | i = 0; | ||
42 | while (fscanf(file, "%d %d %d\n", &npsf_id, &cpu, &budget_us) != EOF) { | ||
38 | 43 | ||
39 | ret = add_server(&npsf_id, &budget_ns, &cpu); | 44 | printf("Read: %d %d %d\n", npsf_id, cpu, budget_us); |
40 | 45 | ||
41 | if (ret < 0) | 46 | if (curr_id == -1) { |
47 | curr_id = npsf_id; | ||
48 | budgets = malloc(max_splits_server * | ||
49 | sizeof(struct npsf_budgets)); | ||
50 | for(j = 0; j < max_splits_server; j++) { | ||
51 | budgets[j].cpu = -1; | ||
52 | budgets[j].budget = 0; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | if (npsf_id == curr_id) { | ||
57 | /* same notional processor, different cpu and budget */ | ||
58 | budgets[i].cpu = cpu; | ||
59 | budgets[i].budget = (lt_t) (budget_us * 1000); | ||
60 | i++; | ||
61 | } else { | ||
62 | /* different notional processor */ | ||
63 | /* add server */ | ||
64 | printf("Adding npsf_id = %d\n", curr_id); | ||
65 | ret = add_server(&curr_id, budgets); | ||
66 | |||
67 | if (ret < 0) { | ||
68 | fclose(file); | ||
69 | free(budgets); | ||
70 | printf("Cannot add Notional Processor %d\n", | ||
71 | curr_id); | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | /* reinit new */ | ||
76 | i = 0; | ||
77 | budgets = malloc(max_splits_server * | ||
78 | sizeof(struct npsf_budgets)); | ||
79 | for(j = 0; j < max_splits_server; j++) { | ||
80 | budgets[j].cpu = -1; | ||
81 | budgets[j].budget = 0; | ||
82 | } | ||
83 | curr_id = npsf_id; | ||
84 | budgets[i].cpu = cpu; | ||
85 | budgets[i].budget = (lt_t) (budget_us * 1000); | ||
86 | i++; | ||
87 | } | ||
88 | } | ||
89 | |||
90 | if (ferror(file)) { | ||
91 | fprintf(stderr, "Error while reading\n"); | ||
92 | fclose(file); | ||
93 | return -1; | ||
94 | } | ||
95 | |||
96 | /* save the last entry */ | ||
97 | ret = add_server(&curr_id, budgets); | ||
98 | printf("Adding npsf_id = %d\n", curr_id); | ||
99 | if (ret < 0) { | ||
100 | fclose(file); | ||
101 | free(budgets); | ||
42 | bail_out("Cannot add Notional Processor: "); | 102 | bail_out("Cannot add Notional Processor: "); |
103 | } | ||
104 | |||
105 | fclose(file); | ||
43 | 106 | ||
44 | return 0; | 107 | return 0; |
45 | } | 108 | } |