Rev 225 | Rev 241 | 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 | |
226 | giacomo | 77 | if (proc_table[exec_shadow].task_level != local_scheduler_level) return 0; |
78 | |||
221 | giacomo | 79 | switch (scheduler_id) { |
80 | case FSF_SCHEDULER_POSIX: |
||
81 | budget = POSIXSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
82 | break; |
||
83 | case FSF_SCHEDULER_EDF: |
||
84 | budget = EDFSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
85 | break; |
||
86 | case FSF_SCHEDULER_RM: |
||
87 | default: |
||
88 | budget = -1; |
||
89 | break; |
||
90 | } |
||
91 | |||
92 | if (budget == -1) return FSF_ERR_INVALID_SERVER; |
||
93 | |||
94 | if (next_budget != NULL && next_period != NULL) { |
||
95 | |||
224 | giacomo | 96 | CBSSTAR_getbudgetinfo(fsf_cbsstar_level, &Q, &T, budget); |
221 | giacomo | 97 | |
98 | #ifdef FSF_DEBUG |
||
99 | kern_printf("(budget %d Q=%d T=%d)",budget,(int)Q,(int)T); |
||
100 | #endif |
||
101 | |||
102 | next_budget->tv_sec = Q / 1000000; |
||
103 | next_budget->tv_nsec = (Q % 1000000) * 1000; |
||
104 | next_period->tv_sec = T / 1000000; |
||
105 | next_period->tv_nsec = (T % 1000000) * 1000; |
||
106 | |||
107 | } |
||
108 | |||
224 | giacomo | 109 | if (was_deadline_missed != NULL) |
110 | *was_deadline_missed = false; |
||
221 | giacomo | 111 | if (was_budget_overran != NULL) |
224 | giacomo | 112 | *was_budget_overran = false; |
221 | giacomo | 113 | |
114 | if (at_absolute_time != NULL) |
||
115 | kern_event_post(at_absolute_time, (void (*)(void *))&task_activate, (void *)(exec_shadow)); |
||
116 | |||
117 | #ifdef FSF_DEBUG |
||
118 | if (at_absolute_time != NULL) |
||
119 | kern_printf("(Next act s%d:us%d)",(int)at_absolute_time->tv_sec,(int)at_absolute_time->tv_nsec/1000); |
||
120 | else |
||
121 | kern_printf("(End Cycle %d)",exec_shadow); |
||
122 | #endif |
||
123 | |||
124 | task_endcycle(); |
||
125 | |||
126 | return 0; |
||
127 | |||
128 | } |
||
129 | |||
130 | int |
||
131 | fsf_schedule_next_event_triggered_job |
||
132 | (fsf_synch_object_handle_t *synch_handle, |
||
133 | struct timespec *next_budget, |
||
134 | struct timespec *next_period, |
||
135 | bool *was_deadline_missed, |
||
136 | bool *was_budget_overran) |
||
137 | { |
||
138 | |||
139 | TIME T,Q; |
||
140 | int budget, local_scheduler_level, scheduler_id; |
||
141 | |||
224 | giacomo | 142 | local_scheduler_level = CBSSTAR_get_local_scheduler_level_from_pid(fsf_cbsstar_level, exec_shadow); |
143 | scheduler_id = CBSSTAR_get_local_scheduler_id_from_pid(fsf_cbsstar_level, exec_shadow); |
||
226 | giacomo | 144 | |
145 | if (proc_table[exec_shadow].task_level != local_scheduler_level) return 0; |
||
146 | |||
221 | giacomo | 147 | switch (scheduler_id) { |
148 | case FSF_SCHEDULER_POSIX: |
||
149 | budget = POSIXSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
150 | break; |
||
151 | case FSF_SCHEDULER_EDF: |
||
152 | budget = EDFSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
153 | break; |
||
154 | case FSF_SCHEDULER_RM: |
||
155 | default: |
||
156 | budget = -1; |
||
157 | break; |
||
158 | } |
||
159 | |||
160 | if (budget == -1) return FSF_ERR_INVALID_SERVER; |
||
161 | |||
162 | if (next_budget != NULL && next_period != NULL) { |
||
163 | |||
224 | giacomo | 164 | CBSSTAR_getbudgetinfo(fsf_cbsstar_level, &Q, &T, budget); |
221 | giacomo | 165 | |
166 | #ifdef FSF_DEBUG |
||
167 | kern_printf("(budget %d Q=%d T=%d)",budget,(int)Q,(int)T); |
||
168 | #endif |
||
169 | |||
170 | next_budget->tv_sec = Q / 1000000; |
||
171 | next_budget->tv_nsec = (Q % 1000000) * 1000; |
||
172 | next_period->tv_sec = T / 1000000; |
||
173 | next_period->tv_nsec = (T % 1000000) * 1000; |
||
174 | |||
175 | } |
||
176 | |||
225 | giacomo | 177 | if (was_deadline_missed != NULL) |
178 | *was_deadline_missed = false; |
||
221 | giacomo | 179 | if (was_budget_overran != NULL) |
225 | giacomo | 180 | *was_budget_overran = false; |
221 | giacomo | 181 | |
182 | if (synch_handle->events > 0) { |
||
183 | task_activate(exec_shadow); |
||
184 | synch_handle->events--; |
||
185 | } else |
||
186 | iq_insertlast(exec_shadow,&synch_handle->threads); |
||
187 | |||
188 | #ifdef FSF_DEBUG |
||
189 | kern_printf("(Synch_Handle Events %d)",synch_handle->events); |
||
190 | #endif |
||
191 | |||
192 | task_endcycle(); |
||
193 | |||
194 | return 0; |
||
195 | |||
196 | } |