]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added renegotiation and spare capacity demos for dummy resource
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 24 Aug 2009 13:08:09 +0000 (15:08 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 24 Aug 2009 13:08:09 +0000 (15:08 +0200)
frsh_api/tests/Makefile.omk
frsh_api/tests/dummy_renegotiation.c [new file with mode: 0644]
frsh_api/tests/dummy_spare_capacity.c [new file with mode: 0644]

index edcb7dfa84865fd59d7dd0293a3d21acaa0da126..d4919863fa181d236f776ae84659125feec69b06 100644 (file)
@@ -13,6 +13,12 @@ test_PROGRAMS += cpu_renegotiation
 cpu_renegotiation_SOURCES = cpu_renegotiation.c
 endif
 
 cpu_renegotiation_SOURCES = cpu_renegotiation.c
 endif
 
+test_PROGRAMS += dummy_renegotiation
+dummy_renegotiation_SOURCES = dummy_renegotiation.c
+
+test_PROGRAMS += dummy_spare_capacity
+dummy_spare_capacity_SOURCES = dummy_spare_capacity.c
+
 test_PROGRAMS += negobench
 negobench_SOURCES = negobench.c
 
 test_PROGRAMS += negobench
 negobench_SOURCES = negobench.c
 
diff --git a/frsh_api/tests/dummy_renegotiation.c b/frsh_api/tests/dummy_renegotiation.c
new file mode 100644 (file)
index 0000000..9e5557c
--- /dev/null
@@ -0,0 +1,106 @@
+#include <frsh.h>
+#include <error.h>
+#include <signal.h>
+#include <getopt.h>
+#include <ul_logreg.h>
+#include <res_dummy.h>
+
+volatile int finish = 0;
+
+void int_handler(int signal)
+{
+       finish = 1;
+}
+
+static struct option long_opts[] = {
+    { "loglevel", 1, 0, 'l' },
+    { 0, 0, 0, 0}
+};
+
+static void
+usage(void)
+{
+       printf("usage: cpu_renegotiation [ options ]\n");
+       printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
+}
+
+
+#define MSEC(x) { x/1000, (x%1000) * 1000000 }
+frsh_utilization_set_t utilization_set = {
+       .size = 3,
+       .utilizations = {
+               { .budget = MSEC(10),  .period = MSEC(100),  .deadline = MSEC(100) },
+               { .budget = MSEC(20),  .period = MSEC(100),  .deadline = MSEC(100) },
+               { .budget = MSEC(30),  .period = MSEC(100),  .deadline = MSEC(100) },
+       },
+};
+
+int main(int argc, char *argv[])
+{
+       frsh_vres_id_t vres;
+       frsh_contract_t contract;
+       int ret;
+       char opt;
+
+       while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) {
+               switch (opt) {
+                       case 'l':
+                               ul_log_domain_arg2levels(optarg);
+                               break;
+                       case 'h':
+                       /*default:*/
+                               usage();
+                               exit(opt == 'h' ? 0 : 1);
+               }
+       }
+
+       ret = frsh_init();
+       if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+       
+       signal(SIGINT, int_handler);
+       signal(SIGTERM, int_handler);
+
+       /* Contract negotiation for CPU */
+       ret = frsh_contract_init(&contract);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+
+       int variant = 0;
+       bool first = true;
+       while (!finish) {
+               
+               ret = frsh_contract_set_basic_params(&contract,
+                                                    &utilization_set.utilizations[variant].budget,
+                                                    &utilization_set.utilizations[variant].period,
+                                                    FRSH_WT_BOUNDED,
+                                                    FRSH_CT_REGULAR);
+               if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+
+               ret = frsh_contract_set_resource_and_label(&contract,
+                                                          DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
+                                                          "renegotiation test");               
+               if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+               if (first) {
+                       ret = frsh_contract_negotiate(&contract, &vres);
+                       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+                       first = false;
+               } else {
+                       ret = frsh_contract_renegotiate_sync(&contract, vres);
+                       if (ret == 0) {
+                               printf("Renegotiation accepted\n");
+                       } else if (ret == FRSH_ERR_CONTRACT_REJECTED) {
+                               printf("Renegotiaton REJECTED\n");
+                       } else
+                               PERROR_AND_EXIT(ret, "frsh_contract_renegotiate_sync");
+               }
+               sleep(5);
+               variant++;
+               if (variant >= utilization_set.size) variant = 0;
+       }
+       
+       ret = frsh_contract_cancel(vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
+
+       return 0;       
+}
+
diff --git a/frsh_api/tests/dummy_spare_capacity.c b/frsh_api/tests/dummy_spare_capacity.c
new file mode 100644 (file)
index 0000000..08872d1
--- /dev/null
@@ -0,0 +1,102 @@
+#include <frsh.h>
+#include <error.h>
+#include <signal.h>
+#include <getopt.h>
+#include <ul_logreg.h>
+#include <res_dummy.h>
+#include <semaphore.h>
+
+sem_t finish;
+
+void int_handler(int signal)
+{
+       sem_post(&finish);
+}
+
+static struct option long_opts[] = {
+    { "loglevel", 1, 0, 'l' },
+    { 0, 0, 0, 0}
+};
+
+static void
+usage(void)
+{
+       printf("usage: cpu_spare_capacity [ options ]\n");
+       printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
+}
+
+
+#define MSEC(x) { x/1000, (x%1000) * 1000000 }
+frsh_utilization_set_t utilization_set = {
+       .size = 2,
+       .utilizations = {
+               { .budget = MSEC(20),  .period = MSEC(100),  .deadline = MSEC(100) },
+               { .budget = MSEC(50),  .period = MSEC(100),  .deadline = MSEC(100) },
+       },
+};
+
+int main(int argc, char *argv[])
+{
+       frsh_vres_id_t vres;
+       frsh_contract_t contract;
+       frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
+       int ret;
+       char opt;
+
+       sem_init(&finish, 0, 0);
+
+       while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) {
+               switch (opt) {
+                       case 'l':
+                               ul_log_domain_arg2levels(optarg);
+                               break;
+                       case 'h':
+                       /*default:*/
+                               usage();
+                               exit(opt == 'h' ? 0 : 1);
+               }
+       }
+
+       ret = frsh_init();
+       if (ret) PERROR_AND_EXIT(ret, "frsh_init");
+       
+       signal(SIGINT, int_handler);
+       signal(SIGTERM, int_handler);
+
+       /* Contract negotiation for CPU */
+       ret = frsh_contract_init(&contract);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
+               
+       ret = frsh_contract_set_basic_params(&contract,
+                                            &utilization_set.utilizations[0].budget,
+                                            &utilization_set.utilizations[0].period,
+                                            FRSH_WT_BOUNDED,
+                                            FRSH_CT_REGULAR);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+
+       ret = frsh_contract_set_resource_and_label(&contract ,
+                                                  DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
+                                                  "spare cap test");
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+
+       ret = frsh_contract_set_reclamation_params(&contract,
+                                                  &zero,
+                                                  &utilization_set.utilizations[utilization_set.size-1].budget,
+                                                  &utilization_set.utilizations[utilization_set.size-1].period,
+                                                  FRSH_GR_DISCRETE,
+                                                  &utilization_set,
+                                                  0,
+                                                  0);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_reclamation_params");
+
+       ret = frsh_contract_negotiate(&contract, &vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+
+       sem_wait(&finish);
+
+       ret = frsh_contract_cancel(vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
+
+       return 0;       
+}
+