From 08e29e6e3928927ab5eb85dd3da06c772ac50cc1 Mon Sep 17 00:00:00 2001 From: Andrea Bastoni Date: Fri, 25 Jun 2010 14:17:51 -0400 Subject: [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" --- bin/npsf_add_server.c | 99 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 18 deletions(-) (limited to 'bin') 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 @@ -/* wrapper for sys_add_server */ +/* wrapper for sys_add_server + * + * Input: a file with on each line: + * npsf_id cpu budget(us) + */ #include #include #include @@ -9,37 +13,96 @@ void usage(char *error) { fprintf(stderr, "Error: %s\n", error); fprintf(stderr, - "Usage: npsf_add_server NPSF-ID UTIL SLOT-SIZE(ms) CPU \n"); + "Usage: npsf_add_server SERVERS-FILE MAX-SPLITS-PER-NPSFID\n"); exit(1); } int main(int argc, char** argv) { int ret; - int cpu = 0; - int npsf_id = 0; - double util = 0; - int slot_ms = 0; - lt_t budget_ns = 0; + 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 < 5) + if (argc < 3) usage("Arguments missing."); - npsf_id = atoi(argv[1]); - util = atof(argv[2]); - slot_ms = atoi(argv[3]); - cpu = atoi(argv[4]); - if (util > 1) - usage("Utilization > 1"); + max_splits_server = atoi(argv[2]); - budget_ns = (lt_t)((__NS_PER_MS * util) * slot_ms); + if ((file = fopen(argv[1], "r")) == NULL) { + fprintf(stderr, "Cannot open %s\n", argv[1]); + return -1; + } - printf("Trying to add NP(%d): budget = %f\n", npsf_id, (double)(budget_ns) / __NS_PER_MS); + /* format: npsf_id cpu budget-us */ + i = 0; + while (fscanf(file, "%d %d %d\n", &npsf_id, &cpu, &budget_us) != EOF) { - ret = add_server(&npsf_id, &budget_ns, &cpu); + printf("Read: %d %d %d\n", npsf_id, cpu, budget_us); - if (ret < 0) + 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); + + 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); + 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; } -- cgit v1.2.2