Rev 221 | Rev 225 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
221 | giacomo | 1 | //===================================================================== |
2 | // FFFFFFIII RRRRR SSTTTTTTT |
||
3 | // FF IIR RR SS |
||
4 | // FF IR SS |
||
5 | // FFFFFF RRRR SSSSST |
||
6 | // FF FI RRR SS |
||
7 | // FF II RRR SS |
||
8 | // FF IIIIIR RS |
||
9 | // |
||
10 | // Basic FSF(FIRST Scheduling Framework) contract management |
||
11 | // S.Ha.R.K. Implementation |
||
12 | //===================================================================== |
||
13 | |||
14 | #include "fsf_contract.h" |
||
15 | |||
224 | giacomo | 16 | extern int fsf_cbsstar_level; |
221 | giacomo | 17 | |
18 | //#define FSF_DEBUG |
||
19 | |||
20 | int |
||
21 | fsf_create_synchobject(fsf_synch_object_handle_t *synch_handle) |
||
22 | { |
||
23 | |||
24 | if (!synch_handle) return FSF_ERR_INVALID_SYNCH_OBJECT_HANDLE; |
||
25 | |||
26 | iq_init(&synch_handle->threads, NULL, 0); |
||
27 | synch_handle->events = 0; |
||
28 | |||
29 | return 0; |
||
30 | |||
31 | } |
||
32 | |||
33 | int |
||
34 | fsf_signal_synchobject(fsf_synch_object_handle_t *synch_handle) |
||
35 | { |
||
36 | |||
37 | PID p; |
||
38 | |||
39 | if (!synch_handle) return FSF_ERR_INVALID_SYNCH_OBJECT_HANDLE; |
||
40 | |||
41 | if ((p = iq_getfirst(&synch_handle->threads)) != NIL) |
||
42 | task_activate(p); |
||
43 | else |
||
44 | synch_handle->events++; |
||
45 | |||
46 | return 0; |
||
47 | |||
48 | } |
||
49 | |||
50 | int |
||
51 | fsf_destroy_synchobject(fsf_synch_object_handle_t *synch_handle) |
||
52 | { |
||
53 | |||
54 | if (!synch_handle) return FSF_ERR_INVALID_SYNCH_OBJECT_HANDLE; |
||
55 | |||
56 | while (iq_getfirst(&synch_handle->threads) != NIL); |
||
57 | synch_handle->events = 0; |
||
58 | |||
59 | return 0; |
||
60 | |||
61 | } |
||
62 | |||
63 | int fsf_schedule_next_timed_job |
||
64 | (const struct timespec *at_absolute_time, |
||
65 | struct timespec *next_budget, |
||
66 | struct timespec *next_period, |
||
67 | bool *was_deadline_missed, |
||
68 | bool *was_budget_overran) |
||
69 | { |
||
70 | |||
71 | TIME T,Q; |
||
72 | int budget, local_scheduler_level, scheduler_id; |
||
73 | |||
224 | giacomo | 74 | local_scheduler_level = CBSSTAR_get_local_scheduler_level_from_pid(fsf_cbsstar_level, exec_shadow); |
75 | scheduler_id = CBSSTAR_get_local_scheduler_id_from_pid(fsf_cbsstar_level, exec_shadow); |
||
221 | giacomo | 76 | |
77 | switch (scheduler_id) { |
||
78 | case FSF_SCHEDULER_POSIX: |
||
79 | budget = POSIXSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
80 | break; |
||
81 | case FSF_SCHEDULER_EDF: |
||
82 | budget = EDFSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
83 | break; |
||
84 | case FSF_SCHEDULER_RM: |
||
85 | default: |
||
86 | budget = -1; |
||
87 | break; |
||
88 | } |
||
89 | |||
90 | if (budget == -1) return FSF_ERR_INVALID_SERVER; |
||
91 | |||
92 | if (next_budget != NULL && next_period != NULL) { |
||
93 | |||
224 | giacomo | 94 | CBSSTAR_getbudgetinfo(fsf_cbsstar_level, &Q, &T, budget); |
221 | giacomo | 95 | |
96 | #ifdef FSF_DEBUG |
||
97 | kern_printf("(budget %d Q=%d T=%d)",budget,(int)Q,(int)T); |
||
98 | #endif |
||
99 | |||
100 | next_budget->tv_sec = Q / 1000000; |
||
101 | next_budget->tv_nsec = (Q % 1000000) * 1000; |
||
102 | next_period->tv_sec = T / 1000000; |
||
103 | next_period->tv_nsec = (T % 1000000) * 1000; |
||
104 | |||
105 | } |
||
106 | |||
224 | giacomo | 107 | if (was_deadline_missed != NULL) |
108 | *was_deadline_missed = false; |
||
221 | giacomo | 109 | if (was_budget_overran != NULL) |
224 | giacomo | 110 | *was_budget_overran = false; |
221 | giacomo | 111 | |
112 | if (at_absolute_time != NULL) |
||
113 | kern_event_post(at_absolute_time, (void (*)(void *))&task_activate, (void *)(exec_shadow)); |
||
114 | |||
115 | #ifdef FSF_DEBUG |
||
116 | if (at_absolute_time != NULL) |
||
117 | kern_printf("(Next act s%d:us%d)",(int)at_absolute_time->tv_sec,(int)at_absolute_time->tv_nsec/1000); |
||
118 | else |
||
119 | kern_printf("(End Cycle %d)",exec_shadow); |
||
120 | #endif |
||
121 | |||
122 | task_endcycle(); |
||
123 | |||
124 | return 0; |
||
125 | |||
126 | } |
||
127 | |||
128 | int |
||
129 | fsf_schedule_next_event_triggered_job |
||
130 | (fsf_synch_object_handle_t *synch_handle, |
||
131 | struct timespec *next_budget, |
||
132 | struct timespec *next_period, |
||
133 | bool *was_deadline_missed, |
||
134 | bool *was_budget_overran) |
||
135 | { |
||
136 | |||
137 | TIME T,Q; |
||
138 | int budget, local_scheduler_level, scheduler_id; |
||
139 | |||
224 | giacomo | 140 | local_scheduler_level = CBSSTAR_get_local_scheduler_level_from_pid(fsf_cbsstar_level, exec_shadow); |
141 | scheduler_id = CBSSTAR_get_local_scheduler_id_from_pid(fsf_cbsstar_level, exec_shadow); |
||
221 | giacomo | 142 | |
143 | switch (scheduler_id) { |
||
144 | case FSF_SCHEDULER_POSIX: |
||
145 | budget = POSIXSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
146 | break; |
||
147 | case FSF_SCHEDULER_EDF: |
||
148 | budget = EDFSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
149 | break; |
||
150 | case FSF_SCHEDULER_RM: |
||
151 | default: |
||
152 | budget = -1; |
||
153 | break; |
||
154 | } |
||
155 | |||
156 | if (budget == -1) return FSF_ERR_INVALID_SERVER; |
||
157 | |||
158 | if (next_budget != NULL && next_period != NULL) { |
||
159 | |||
224 | giacomo | 160 | CBSSTAR_getbudgetinfo(fsf_cbsstar_level, &Q, &T, budget); |
221 | giacomo | 161 | |
162 | #ifdef FSF_DEBUG |
||
163 | kern_printf("(budget %d Q=%d T=%d)",budget,(int)Q,(int)T); |
||
164 | #endif |
||
165 | |||
166 | next_budget->tv_sec = Q / 1000000; |
||
167 | next_budget->tv_nsec = (Q % 1000000) * 1000; |
||
168 | next_period->tv_sec = T / 1000000; |
||
169 | next_period->tv_nsec = (T % 1000000) * 1000; |
||
170 | |||
171 | } |
||
172 | |||
173 | if (was_deadline_missed != NULL) *was_deadline_missed = false; |
||
174 | if (was_budget_overran != NULL) |
||
224 | giacomo | 175 | *was_budget_overran = (bool)CBSSTAR_was_budget_overran(fsf_cbsstar_level,budget); |
221 | giacomo | 176 | |
177 | if (synch_handle->events > 0) { |
||
178 | task_activate(exec_shadow); |
||
179 | synch_handle->events--; |
||
180 | } else |
||
181 | iq_insertlast(exec_shadow,&synch_handle->threads); |
||
182 | |||
183 | #ifdef FSF_DEBUG |
||
184 | kern_printf("(Synch_Handle Events %d)",synch_handle->events); |
||
185 | #endif |
||
186 | |||
187 | task_endcycle(); |
||
188 | |||
189 | return 0; |
||
190 | |||
191 | } |