8 volatile int finish = 0;
10 void int_handler(int signal)
20 frsh_vres_id_t vres_id;
21 frsh_rel_time_t budget;
22 frsh_rel_time_t period;
27 for (j=0; j<1000000; j++);
29 ret = frsh_thread_get_vres_id(fosa_thread_self(), &vres_id);
30 if (ret) PERROR_AND_EXIT(ret, "frsh_get_vres_id");
32 ret = frsh_vres_get_budget_and_period(vres_id, &budget, &period);
33 if (ret) PERROR_AND_EXIT(ret, "frsh_vres_get_budget_and_period");
35 printf("Consuming budget %ld ms - %lu\n",
36 fosa_rel_time_to_msec(budget), i);
42 static struct option long_opts[] = {
43 { "loglevel", 1, 0, 'l' },
50 printf("usage: cpu_spare_capacity [ options ]\n");
51 printf(" -l, --loglevel <number>|<domain>=<number>,...\n");
55 #define MSEC(x) { x/1000, (x%1000) * 1000000 }
56 frsh_utilization_set_t utilization_set = {
59 { .budget = MSEC(20), .period = MSEC(100), .deadline = MSEC(100) },
60 { .budget = MSEC(50), .period = MSEC(100), .deadline = MSEC(100) },
64 int main(int argc, char *argv[])
67 frsh_thread_attr_t attr;
68 frsh_thread_id_t thread;
69 frsh_contract_t contract;
70 frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
74 while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) {
77 ul_log_domain_arg2levels(optarg);
82 exit(opt == 'h' ? 0 : 1);
87 if (ret) PERROR_AND_EXIT(ret, "frsh_init");
89 signal(SIGINT, int_handler);
90 signal(SIGTERM, int_handler);
92 /* Contract negotiation for CPU */
93 ret = frsh_contract_init(&contract);
94 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
96 ret = frsh_contract_set_basic_params(&contract,
97 &utilization_set.utilizations[0].budget,
98 &utilization_set.utilizations[0].period,
101 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
103 ret = frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR,
104 FRSH_CPU_ID_DEFAULT, "spare cap test");
105 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
107 ret = frsh_contract_set_reclamation_params(&contract,
109 &utilization_set.utilizations[utilization_set.size-1].budget,
110 &utilization_set.utilizations[utilization_set.size-1].period,
115 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_reclamation_params");
117 ret = frsh_contract_negotiate(&contract, &vres);
118 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
120 printf("Aqcpu vres negotiated, vres-ID: %p\n", vres);
121 pthread_attr_init(&attr);
122 ret = frsh_thread_create_and_bind(vres, &thread, &attr,
123 work_thread, (void*) NULL);
124 if (ret) PERROR_AND_EXIT(ret, "frsh_thread_create_and_bind");
126 pthread_join(thread.pthread_id, (void**) NULL);
128 ret = frsh_contract_cancel(vres);
129 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");