aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-06-25 14:17:51 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-06-25 14:17:51 -0400
commit08e29e6e3928927ab5eb85dd3da06c772ac50cc1 (patch)
treeee2f5baa27590e3c274b4b264c2c19eea893e70b
parent3bcf13b5c38f23b3663f6a7030ae34383f651b4e (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"
-rw-r--r--bin/npsf_add_server.c99
-rw-r--r--include/litmus.h17
-rw-r--r--src/syscalls.c4
3 files changed, 87 insertions, 33 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 @@
9void usage(char *error) { 13void 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
16int main(int argc, char** argv) 20int 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}
diff --git a/include/litmus.h b/include/litmus.h
index 9d2339f..0ccad9f 100644
--- a/include/litmus.h
+++ b/include/litmus.h
@@ -150,24 +150,15 @@ int null_call(cycles_t *timestamp);
150struct control_page* get_ctrl_page(void); 150struct control_page* get_ctrl_page(void);
151 151
152/* NPS-F syscall to add a notional processor (a server) to a cpu. 152/* NPS-F syscall to add a notional processor (a server) to a cpu.
153 * A notional processor may span across multiple cpu. If the NP. 153 * A notional processor may span across multiple cpu.
154 * spans multiple cpus, each "segment" must be initialized indipendently
155 * with the proper fraction of budget of the original NP. For example:
156 *
157 * NP1 = 0.75 = inflated utilization; it spans on CPU0 and CPU1:
158 * NP1_0 = 0.2; NP1_1 = 0.55
159 *
160 * So, we have to initialize a segment (0.2 * slot_length) on CPU0
161 * and a segment (0.55 * slot_length) on CPU1 (both should have
162 * the same npsf_id).
163 * 154 *
164 * @npsf_id: a "unique" identifier for the notional processor. 155 * @npsf_id: a "unique" identifier for the notional processor.
165 * @budget: the length of the segment for this NP. on this CPU (in ns). 156 * @budgets: array of (cpu, budget-ns) that describes this np.
166 * @cpu: the cpu that holds this NP segment. 157 * on possibly more than one cpu.
167 * 158 *
168 * Currently implemented on x86_64 only. 159 * Currently implemented on x86_64 only.
169 */ 160 */
170int add_server(int *npsf_id, lt_t *budget, int *cpu); 161int add_server(int *npsf_id, struct npsf_budgets *budgets);
171 162
172#ifdef __cplusplus 163#ifdef __cplusplus
173} 164}
diff --git a/src/syscalls.c b/src/syscalls.c
index 58d7151..6df716b 100644
--- a/src/syscalls.c
+++ b/src/syscalls.c
@@ -96,7 +96,7 @@ int null_call(cycles_t *timestamp)
96 return syscall(__NR_null_call, timestamp); 96 return syscall(__NR_null_call, timestamp);
97} 97}
98 98
99int add_server(int *npsf_id, lt_t *budget, int *cpu) 99int add_server(int *npsf_id, struct npsf_budgets *budgets)
100{ 100{
101 return syscall(__NR_add_server, npsf_id, budget, cpu); 101 return syscall(__NR_add_server, npsf_id, budgets);
102} 102}