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_renegotiation [ 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(10), .period = MSEC(100), .deadline = MSEC(100) },
60 { .budget = MSEC(20), .period = MSEC(100), .deadline = MSEC(100) },
61 { .budget = MSEC(30), .period = MSEC(100), .deadline = MSEC(100) },
65 int main(int argc, char *argv[])
68 frsh_thread_attr_t attr;
69 frsh_thread_id_t thread;
70 frsh_contract_t contract;
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");
100 ret = frsh_contract_set_basic_params(&contract,
101 &utilization_set.utilizations[variant].budget,
102 &utilization_set.utilizations[variant].period,
105 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
107 ret = frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR,
108 FRSH_CPU_ID_DEFAULT, "renegotiation test");
109 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
112 ret = frsh_contract_negotiate(&contract, &vres);
113 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
115 printf("Aqcpu vres negotiated, vres-ID: %d\n", (int) vres);
116 pthread_attr_init(&attr);
117 ret = frsh_thread_create_and_bind(vres, &thread, &attr,
118 work_thread, (void*) NULL);
119 if (ret) PERROR_AND_EXIT(ret, "frsh_thread_create_and_bind");
122 ret = frsh_contract_renegotiate_sync(&contract, vres);
124 printf("Renegotiation accepted\n");
125 } else if (ret == FRSH_ERR_CONTRACT_REJECTED) {
126 printf("Renegotiaton REJECTED\n");
128 PERROR_AND_EXIT(ret, "frsh_contract_renegotiate_sync");
132 if (variant >= utilization_set.size) variant = 0;
135 pthread_join(thread.pthread_id, (void**) NULL);
137 ret = frsh_contract_cancel(vres);
138 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");