]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
Added cpu_renegotiation test
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 28 May 2009 14:23:53 +0000 (16:23 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 28 May 2009 14:23:53 +0000 (16:23 +0200)
This test renegotiates its CPU contract every 5 seconds.

frsh_api/tests/Makefile.omk
frsh_api/tests/cpu_renegotiation.c [new file with mode: 0644]

index ea0c8ec853fb2ead610c824984fcc38f97992974..f06cdf2d8f4978a842408fc61a3b01af169259cc 100644 (file)
@@ -8,6 +8,9 @@ spare_capacity_SOURCES = spare_capacity.c
 test_PROGRAMS += cpu_spare_capacity
 cpu_spare_capacity_SOURCES = cpu_spare_capacity.c
 
+test_PROGRAMS += cpu_renegotiation
+cpu_renegotiation_SOURCES = cpu_renegotiation.c
+
 test_PROGRAMS += negobench
 negobench_SOURCES = negobench.c
 
diff --git a/frsh_api/tests/cpu_renegotiation.c b/frsh_api/tests/cpu_renegotiation.c
new file mode 100644 (file)
index 0000000..5e7d11f
--- /dev/null
@@ -0,0 +1,142 @@
+#include <frsh.h>
+#include <aqcpu_res.h>
+#include <error.h>
+#include <signal.h>
+#include <getopt.h>
+#include <ul_logreg.h>
+
+volatile int finish = 0;
+
+void int_handler(int signal)
+{
+       finish = 1;
+}
+
+void* work_thread()
+{
+       int ret;
+       unsigned long i = 0;
+       volatile int j;
+       frsh_vres_id_t vres_id;
+       frsh_rel_time_t budget;
+       frsh_rel_time_t period;
+
+       while(!finish) {
+               i++;
+               
+               for (j=0; j<1000000; j++);
+               
+               ret = frsh_thread_get_vres_id(fosa_thread_self(), &vres_id);
+               if (ret) PERROR_AND_EXIT(ret, "frsh_get_vres_id");
+
+               ret = frsh_vres_get_budget_and_period(vres_id, &budget, &period);
+               if (ret) PERROR_AND_EXIT(ret, "frsh_vres_get_budget_and_period");
+
+               printf("Consuming budget %ld ms - %lu\n",
+                      fosa_rel_time_to_msec(budget), i);
+       }
+
+       return EXIT_SUCCESS;
+}
+
+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_thread_attr_t attr;
+       frsh_thread_id_t thread;
+       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, FRSH_RT_PROCESSOR,
+                                                          FRSH_CPU_ID_DEFAULT, "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");
+
+                       printf("Aqcpu vres negotiated, vres-ID: %d\n", (int) vres);
+                       pthread_attr_init(&attr);
+                       ret = frsh_thread_create_and_bind(vres, &thread, &attr, 
+                                                         work_thread, (void*) NULL);
+                       if (ret) PERROR_AND_EXIT(ret, "frsh_thread_create_and_bind");
+                       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;
+       }
+       
+       pthread_join(thread.pthread_id, (void**) NULL); 
+
+       ret = frsh_contract_cancel(vres);
+       if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
+
+       return 0;       
+}
+