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>
17 int frsh_synchobj_create(frsh_synchobj_handle_t *synch_handle)
20 return FRSH_ERR_BAD_ARGUMENT;
22 *synch_handle = fres_synchobj_new();
23 if (!(*synch_handle)) goto err;
30 int frsh_synchobj_destroy(const frsh_synchobj_handle_t synch_handle)
32 return fres_synchobj_destroy(synch_handle);
36 __frsh_synchobj_check_wcet_and_deadline(frsh_thread_id_t thread,
37 fres_thread_vres_t *th_vres,
38 bool *was_deadline_missed,
39 bool *was_budget_overrun)
41 fosa_clock_id_t th_clockid;
42 fosa_abs_time_t curr_time, curr_exec_time;
45 fres_block_timing_reqs *t;
47 if (!was_deadline_missed && !was_budget_overrun)
50 *was_deadline_missed = false;
51 *was_budget_overrun = false;
53 fosa_thread_get_cputime_clock(thread, &th_clockid);
54 fosa_clock_get_time(FOSA_CLOCK_REALTIME, &curr_time);
55 fosa_clock_get_time(th_clockid, &curr_exec_time);
57 curr_time = fosa_abs_time_decr(curr_time, th_vres->job_start_time);
58 curr_exec_time = fosa_abs_time_decr(curr_exec_time,
59 th_vres->job_cpu_time);
62 b = fres_contract_get_basic(vres->perceived);
63 t = fres_contract_get_timing_reqs(vres->perceived);
65 if (was_deadline_missed &&
66 fosa_abs_time_smaller_or_equal(t->deadline, curr_time))
67 *was_deadline_missed = true;
69 if (was_budget_overrun &&
70 fosa_abs_time_smaller_or_equal(b->budget, curr_exec_time))
71 *was_budget_overrun = false;
75 __frsh_synchobj_set_wcet_and_deadline(frsh_thread_id_t thread,
76 fres_thread_vres_t *th_vres)
78 fosa_clock_id_t th_clockid;
80 fosa_thread_get_cputime_clock(thread, &th_clockid);
81 fosa_clock_get_time(FOSA_CLOCK_REALTIME,
82 &th_vres->job_start_time);
83 fosa_clock_get_time(th_clockid, &th_vres->job_cpu_time);
87 int frsh_synchobj_wait
88 (const frsh_synchobj_handle_t synch_handle,
89 frsh_rel_time_t *next_budget,
90 frsh_rel_time_t *next_period,
91 bool *was_deadline_missed,
92 bool *was_budget_overrun)
94 frsh_thread_id_t thread = fosa_thread_self();
95 fres_thread_vres_t *th_vres;
98 th_vres = fra_get_thread_vres(&thread, FRSH_RT_PROCESSOR);
99 if (!th_vres) goto out;
101 __frsh_synchobj_check_wcet_and_deadline(thread,
106 ret = fres_synchobj_wait_with_timeout(synch_handle, NULL);
109 __frsh_synchobj_set_wcet_and_deadline(thread, th_vres);
110 frsh_vres_get_budget_and_period(th_vres->vres,
118 int frsh_synchobj_wait_with_timeout
119 (const frsh_synchobj_handle_t synch_handle,
120 const frsh_abs_time_t *abs_timeout,
122 frsh_rel_time_t *next_budget,
123 frsh_rel_time_t *next_period,
124 bool *was_deadline_missed,
125 bool *was_budget_overrun)
127 frsh_thread_id_t thread = fosa_thread_self();
128 fres_thread_vres_t *th_vres;
131 th_vres = fra_get_thread_vres(&thread, FRSH_RT_PROCESSOR);
132 if (!th_vres) goto out;
134 __frsh_synchobj_check_wcet_and_deadline(thread,
139 ret = fres_synchobj_wait_with_timeout(synch_handle, abs_timeout);
140 if (ret == ETIMEDOUT) *timed_out = true;
141 else if (ret != 0) goto out;
143 __frsh_synchobj_set_wcet_and_deadline(thread, th_vres);
144 frsh_vres_get_budget_and_period(th_vres->vres,
152 int frsh_synchobj_signal(const frsh_synchobj_handle_t synch_handle)
154 return fres_synchobj_signal(synch_handle);
158 (const frsh_abs_time_t *abs_time,
159 frsh_rel_time_t *next_budget,
160 frsh_rel_time_t *next_period,
161 bool *was_deadline_missed,
162 bool *was_budget_overrun)
164 frsh_thread_id_t thread = fosa_thread_self();
165 fres_thread_vres_t *th_vres;
168 th_vres = fra_get_thread_vres(&thread, FRSH_RT_PROCESSOR);
169 if (!th_vres) goto out;
171 __frsh_synchobj_check_wcet_and_deadline(thread,
177 ret = nanosleep(abs_time, NULL);
179 ret = clock_nanosleep(FOSA_CLOCK_REALTIME,
184 __frsh_synchobj_set_wcet_and_deadline(thread, th_vres);
185 frsh_vres_get_budget_and_period(th_vres->vres,
193 int frsh_vresperiod_wait
194 (unsigned long period_num,
195 frsh_rel_time_t *next_budget,
196 frsh_rel_time_t *next_period,
197 bool *was_deadline_missed,
198 bool *was_budget_overran)
200 return FRSH_ERR_NOT_IMPLEMENTED;
203 int frsh_get_period_number(const frsh_vres_id_t vres, long *period_num)
206 return FRSH_ERR_NOT_IMPLEMENTED;