Subversion Repositories shark

Rev

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