2 * @file frsh_synchobj.c
3 * @author Dario Faggioli <faggioli@gandalf.sssup.it>
5 * @brief FRSH core synchronization objects related functions
6 * not implamented in managers.
10 #include <fres_vres.h>
11 #include <fra_generic.h>
12 #include <fres_synchobj.h>
14 #include <frsh_core.h>
16 int frsh_synchobj_create(frsh_synchobj_handle_t *synch_handle)
19 return FRSH_ERR_BAD_ARGUMENT;
21 *synch_handle = fres_synchobj_new();
22 if (!(*synch_handle)) goto err;
29 int frsh_synchobj_destroy(const frsh_synchobj_handle_t synch_handle)
31 return fres_synchobj_destroy(synch_handle);
35 __frsh_synchobj_check_wcet_and_deadline(frsh_thread_id_t thread,
36 fres_thread_vres_t *th_vres,
37 bool *was_deadline_missed,
38 bool *was_budget_overrun)
40 fosa_clock_id_t th_clockid;
41 fosa_abs_time_t curr_time, curr_exec_time;
44 fres_block_timing_reqs *t;
46 if (!was_deadline_missed && !was_budget_overrun)
49 *was_deadline_missed = false;
50 *was_budget_overrun = false;
52 fosa_thread_get_cputime_clock(thread, &th_clockid);
53 fosa_clock_get_time(FOSA_CLOCK_REALTIME, &curr_time);
54 fosa_clock_get_time(th_clockid, &curr_exec_time);
56 curr_time = fosa_abs_time_decr(curr_time, th_vres->job_start_time);
57 curr_exec_time = fosa_abs_time_decr(curr_exec_time,
58 th_vres->job_cpu_time);
61 b = fres_contract_get_basic(vres->perceived);
62 t = fres_contract_get_timing_reqs(vres->perceived);
64 if (was_deadline_missed &&
65 fosa_abs_time_smaller_or_equal(t->deadline, curr_time))
66 *was_deadline_missed = true;
68 if (was_budget_overrun &&
69 fosa_abs_time_smaller_or_equal(b->budget, curr_exec_time))
70 *was_budget_overrun = false;
74 __frsh_synchobj_set_wcet_and_deadline(frsh_thread_id_t thread,
75 fres_thread_vres_t *th_vres)
77 fosa_clock_id_t th_clockid;
79 fosa_thread_get_cputime_clock(thread, &th_clockid);
80 fosa_clock_get_time(FOSA_CLOCK_REALTIME,
81 &th_vres->job_start_time);
82 fosa_clock_get_time(th_clockid, &th_vres->job_cpu_time);
86 int frsh_synchobj_wait
87 (const frsh_synchobj_handle_t synch_handle,
88 frsh_rel_time_t *next_budget,
89 frsh_rel_time_t *next_period,
90 bool *was_deadline_missed,
91 bool *was_budget_overrun)
93 frsh_thread_id_t thread = fosa_thread_self();
94 fres_thread_vres_t *th_vres;
97 th_vres = fra_get_thread_vres(&thread, FRSH_RT_PROCESSOR);
98 if (!th_vres) goto out;
100 __frsh_synchobj_check_wcet_and_deadline(thread,
105 ret = fres_synchobj_wait_with_timeout(synch_handle, NULL);
108 __frsh_synchobj_set_wcet_and_deadline(thread, th_vres);
109 frsh_vres_get_budget_and_period(th_vres->vres,
117 int frsh_synchobj_wait_with_timeout
118 (const frsh_synchobj_handle_t synch_handle,
119 const frsh_abs_time_t *abs_timeout,
121 frsh_rel_time_t *next_budget,
122 frsh_rel_time_t *next_period,
123 bool *was_deadline_missed,
124 bool *was_budget_overrun)
126 frsh_thread_id_t thread = fosa_thread_self();
127 fres_thread_vres_t *th_vres;
130 th_vres = fra_get_thread_vres(&thread, FRSH_RT_PROCESSOR);
131 if (!th_vres) goto out;
133 __frsh_synchobj_check_wcet_and_deadline(thread,
138 ret = fres_synchobj_wait_with_timeout(synch_handle, abs_timeout);
139 if (ret == ETIMEDOUT) *timed_out = true;
140 else if (ret != 0) goto out;
142 __frsh_synchobj_set_wcet_and_deadline(thread, th_vres);
143 frsh_vres_get_budget_and_period(th_vres->vres,
151 int frsh_synchobj_signal(const frsh_synchobj_handle_t synch_handle)
153 return fres_synchobj_signal(synch_handle);
157 (const frsh_abs_time_t *abs_time,
158 frsh_rel_time_t *next_budget,
159 frsh_rel_time_t *next_period,
160 bool *was_deadline_missed,
161 bool *was_budget_overrun)
163 frsh_thread_id_t thread = fosa_thread_self();
164 fres_thread_vres_t *th_vres;
167 th_vres = fra_get_thread_vres(&thread, FRSH_RT_PROCESSOR);
168 if (!th_vres) goto out;
170 __frsh_synchobj_check_wcet_and_deadline(thread,
175 ret = clock_nanosleep(FOSA_CLOCK_REALTIME,
179 __frsh_synchobj_set_wcet_and_deadline(thread, th_vres);
180 frsh_vres_get_budget_and_period(th_vres->vres,
188 int frsh_vresperiod_wait
189 (unsigned long period_num,
190 frsh_rel_time_t *next_budget,
191 frsh_rel_time_t *next_period,
192 bool *was_deadline_missed,
193 bool *was_budget_overran)
195 return FRSH_ERR_NOT_IMPLEMENTED;
198 int frsh_get_period_number(const frsh_vres_id_t vres, long *period_num)
201 return FRSH_ERR_NOT_IMPLEMENTED;