Rev 799 | Rev 868 | 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" |
||
241 | giacomo | 15 | #include "fsf_server.h" |
221 | giacomo | 16 | |
241 | giacomo | 17 | extern int fsf_server_level; |
221 | giacomo | 18 | |
19 | //#define FSF_DEBUG |
||
20 | |||
21 | int |
||
22 | fsf_create_synchobject(fsf_synch_object_handle_t *synch_handle) |
||
23 | { |
||
24 | |||
25 | if (!synch_handle) return FSF_ERR_INVALID_SYNCH_OBJECT_HANDLE; |
||
26 | |||
27 | iq_init(&synch_handle->threads, NULL, 0); |
||
28 | synch_handle->events = 0; |
||
29 | |||
30 | return 0; |
||
31 | |||
32 | } |
||
33 | |||
34 | int |
||
35 | fsf_signal_synchobject(fsf_synch_object_handle_t *synch_handle) |
||
36 | { |
||
37 | |||
38 | PID p; |
||
39 | |||
40 | if (!synch_handle) return FSF_ERR_INVALID_SYNCH_OBJECT_HANDLE; |
||
41 | |||
42 | if ((p = iq_getfirst(&synch_handle->threads)) != NIL) |
||
43 | task_activate(p); |
||
44 | else |
||
45 | synch_handle->events++; |
||
46 | |||
47 | return 0; |
||
48 | |||
49 | } |
||
50 | |||
51 | int |
||
52 | fsf_destroy_synchobject(fsf_synch_object_handle_t *synch_handle) |
||
53 | { |
||
54 | |||
55 | if (!synch_handle) return FSF_ERR_INVALID_SYNCH_OBJECT_HANDLE; |
||
56 | |||
57 | while (iq_getfirst(&synch_handle->threads) != NIL); |
||
58 | synch_handle->events = 0; |
||
59 | |||
60 | return 0; |
||
61 | |||
62 | } |
||
63 | |||
64 | int fsf_schedule_next_timed_job |
||
65 | (const struct timespec *at_absolute_time, |
||
66 | struct timespec *next_budget, |
||
67 | struct timespec *next_period, |
||
68 | bool *was_deadline_missed, |
||
69 | bool *was_budget_overran) |
||
70 | { |
||
71 | |||
661 | giacomo | 72 | TIME T,Q,D; |
221 | giacomo | 73 | int budget, local_scheduler_level, scheduler_id; |
74 | |||
241 | giacomo | 75 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level, exec_shadow); |
76 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, exec_shadow); |
||
221 | giacomo | 77 | |
226 | giacomo | 78 | if (proc_table[exec_shadow].task_level != local_scheduler_level) return 0; |
79 | |||
221 | giacomo | 80 | switch (scheduler_id) { |
81 | case FSF_SCHEDULER_POSIX: |
||
82 | budget = POSIXSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
83 | break; |
||
84 | case FSF_SCHEDULER_EDF: |
||
85 | budget = EDFSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
86 | break; |
||
858 | trimarchi | 87 | case FSF_SCHEDULER_NONE: |
88 | budget = NONESTAR_getbudget(local_scheduler_level, exec_shadow); |
||
89 | break; |
||
221 | giacomo | 90 | case FSF_SCHEDULER_RM: |
858 | trimarchi | 91 | budget = RMSTAR_getbudget(local_scheduler_level, exec_shadow); |
92 | break; |
||
93 | |||
221 | giacomo | 94 | default: |
95 | budget = -1; |
||
96 | break; |
||
97 | } |
||
98 | |||
99 | if (budget == -1) return FSF_ERR_INVALID_SERVER; |
||
100 | |||
101 | if (next_budget != NULL && next_period != NULL) { |
||
102 | |||
661 | giacomo | 103 | SERVER_getbudgetinfo(fsf_server_level, &Q, &T, &D, budget); |
221 | giacomo | 104 | |
105 | #ifdef FSF_DEBUG |
||
106 | kern_printf("(budget %d Q=%d T=%d)",budget,(int)Q,(int)T); |
||
107 | #endif |
||
108 | |||
109 | next_budget->tv_sec = Q / 1000000; |
||
110 | next_budget->tv_nsec = (Q % 1000000) * 1000; |
||
111 | next_period->tv_sec = T / 1000000; |
||
112 | next_period->tv_nsec = (T % 1000000) * 1000; |
||
113 | |||
114 | } |
||
115 | |||
224 | giacomo | 116 | if (was_deadline_missed != NULL) |
117 | *was_deadline_missed = false; |
||
221 | giacomo | 118 | if (was_budget_overran != NULL) |
224 | giacomo | 119 | *was_budget_overran = false; |
221 | giacomo | 120 | |
121 | if (at_absolute_time != NULL) |
||
799 | giacomo | 122 | kern_event_post(at_absolute_time, (void (*)(void *))task_activate, (void *)(exec_shadow)); |
221 | giacomo | 123 | |
124 | #ifdef FSF_DEBUG |
||
125 | if (at_absolute_time != NULL) |
||
126 | kern_printf("(Next act s%d:us%d)",(int)at_absolute_time->tv_sec,(int)at_absolute_time->tv_nsec/1000); |
||
127 | else |
||
128 | kern_printf("(End Cycle %d)",exec_shadow); |
||
129 | #endif |
||
130 | |||
798 | giacomo | 131 | task_endcycle(); |
221 | giacomo | 132 | |
133 | return 0; |
||
134 | |||
135 | } |
||
136 | |||
137 | int |
||
138 | fsf_schedule_next_event_triggered_job |
||
139 | (fsf_synch_object_handle_t *synch_handle, |
||
140 | struct timespec *next_budget, |
||
141 | struct timespec *next_period, |
||
142 | bool *was_deadline_missed, |
||
143 | bool *was_budget_overran) |
||
144 | { |
||
145 | |||
661 | giacomo | 146 | TIME T,Q,D; |
221 | giacomo | 147 | int budget, local_scheduler_level, scheduler_id; |
148 | |||
241 | giacomo | 149 | local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level, exec_shadow); |
150 | scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, exec_shadow); |
||
226 | giacomo | 151 | |
152 | if (proc_table[exec_shadow].task_level != local_scheduler_level) return 0; |
||
153 | |||
221 | giacomo | 154 | switch (scheduler_id) { |
155 | case FSF_SCHEDULER_POSIX: |
||
156 | budget = POSIXSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
157 | break; |
||
158 | case FSF_SCHEDULER_EDF: |
||
159 | budget = EDFSTAR_getbudget(local_scheduler_level, exec_shadow); |
||
160 | break; |
||
161 | case FSF_SCHEDULER_RM: |
||
162 | default: |
||
163 | budget = -1; |
||
164 | break; |
||
165 | } |
||
166 | |||
167 | if (budget == -1) return FSF_ERR_INVALID_SERVER; |
||
168 | |||
169 | if (next_budget != NULL && next_period != NULL) { |
||
170 | |||
661 | giacomo | 171 | SERVER_getbudgetinfo(fsf_server_level, &Q, &T, &D, budget); |
221 | giacomo | 172 | |
173 | #ifdef FSF_DEBUG |
||
174 | kern_printf("(budget %d Q=%d T=%d)",budget,(int)Q,(int)T); |
||
175 | #endif |
||
176 | |||
177 | next_budget->tv_sec = Q / 1000000; |
||
178 | next_budget->tv_nsec = (Q % 1000000) * 1000; |
||
179 | next_period->tv_sec = T / 1000000; |
||
180 | next_period->tv_nsec = (T % 1000000) * 1000; |
||
181 | |||
182 | } |
||
183 | |||
225 | giacomo | 184 | if (was_deadline_missed != NULL) |
185 | *was_deadline_missed = false; |
||
221 | giacomo | 186 | if (was_budget_overran != NULL) |
225 | giacomo | 187 | *was_budget_overran = false; |
221 | giacomo | 188 | |
189 | if (synch_handle->events > 0) { |
||
190 | task_activate(exec_shadow); |
||
191 | synch_handle->events--; |
||
192 | } else |
||
193 | iq_insertlast(exec_shadow,&synch_handle->threads); |
||
194 | |||
195 | #ifdef FSF_DEBUG |
||
196 | kern_printf("(Synch_Handle Events %d)",synch_handle->events); |
||
197 | #endif |
||
198 | |||
798 | giacomo | 199 | task_endcycle(); |
221 | giacomo | 200 | |
201 | return 0; |
||
202 | |||
203 | } |