1 // -----------------------------------------------------------------------
2 // Copyright (C) 2005 Mälardalen University, SWEDEN
3 // Scuola Superiore S.Anna, ITALY
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
7 // FRSH API web pages: http://marte.unican.es/frsh/docs/
8 // http://shark.sssup.it/contrib/first/docs/
10 // This file is part of FRSH API
12 // FRSH API is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2, or (at your option)
17 // FRSH API is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // distributed with FRSH API; see file COPYING. If not, write to the
24 // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 // As a special exception, if you include this header file into source
28 // files to be compiled, this header file does not by itself cause
29 // the resulting executable to be covered by the GNU General Public
30 // License. This exception does not however invalidate any other
31 // reasons why the executable file might be covered by the GNU General
33 // -----------------------------------------------------------------------
35 //====================================================================
36 // FFFFFFIII RRRRR SSTTTTTTT
44 // FRSH(FIRST Scheduling Framework)
45 // hierarchical scheduling management
46 //===================================================================
49 #include "frsh_basic_types.h"
50 #include "frsh_core.h"
52 #ifndef _FRSH_HIERARCHICAL_H_
53 #define _FRSH_HIERARCHICAL_H_
55 #define FRSH_HIERARCHICAL_MODULE_SUPPORTED 1
57 //// The definition of this types is in frsh_basic_types.h
59 //// Scheduling policies
60 //typedef enum {FRSH_FP, FRSH_EDF, FRSH_TABLE_DRIVEN, FRSH_NONE}
61 // frsh_sched_policy_t;
63 //// Scheduling policy and parameters
65 // frsh_sched_policy_t policy;
67 //} frsh_sched_params_t;
68 //// The params member is a pointer to one of the
70 //// FP: int (priority)
71 //// EDF: struct timespec (deadline)
72 //// TABLE_DRIVEN : struct frsh_table_driven_params_t
75 ////Scheduling parameters for the table-driven policy (t.b.d)
77 // // list of target windows (t.b.d.)
78 // // deadline (for the API): end of september
79 //} frsh_table_driven_params_t;
82 ////Initialization information for a scheduling policy
83 //typedef void * frsh_sched_init_info_t;
84 //// It shall be one of the following:
87 //// TABLE_DRIVEN : struct timespec (schedule duration)
90 //frsh_init_local_scheduler: This call has the following effects:
94 // Records the schedule duration, and starts the
95 // schedule at the time of the call. After the
96 // schedule duration has elapsed, the schedule in
97 // the table is repeated.
100 FRSH_ERR_BAD_ARGUMENT : if the value of the server argument is not in range,
102 FRSH_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
103 scheduled under the FRSH
104 FRSH_ERR_INVALID_SCHEDULER_REPLY : the scheduler is wrong or not running
105 FRSH_ERR_NOT_CONTRACTED_SERVER : if the server of the calling thread
106 has been cancelled or it is not valid
109 int frsh_init_local_scheduler(
110 frsh_server_id_t server,
111 frsh_sched_init_info_t info);
114 // Constants for assigning default values
115 #define FRSH_DEFAULT_SCHED_POLICY FRSH_NONE
118 /////////////////////////////////////////////////
119 // CONTRACT PARAMETERS
120 ////////////////////////////////////////////////
122 //frsh_set_contract_scheduling_policy: The operation updates the
123 //specified contract parameters object by setting its scheduling
124 //policy to the specified input parameter. The default policy is
125 //FRSH_NONE, which means that only one thread may be bound to the
129 FRSH_ERR_BAD_ARGUMENT : if sched_policy is not in range,
135 frsh_set_contract_scheduling_policy
136 (frsh_contract_parameters_t *contract,
137 frsh_sched_policy_t sched_policy);
140 //frsh_get_contract_scheduling_policy: This operation obtains from the
141 //specified contract parameters object its scheduling policy, and
142 //copies it to the place pointed to by the corresponding input
146 FRSH_ERR_BAD_ARGUMENT : if sched_policy or contract are NULL
151 frsh_get_contract_scheduling_policy
152 (const frsh_contract_parameters_t *contract,
153 frsh_sched_policy_t *sched_policy);
156 //frsh_create_local_thread: : This operation creates a thread and binds
157 //it to the specified server, which must have a policy different than
158 //FRSH_NONE. The new thread is created with the arguments thread, attr,
159 //thread_code and arg as they are defined for the pthread_create()
160 //POSIX function call, and its local scheduling parameters are set to
161 //the value stored in the variable pointed to by sched_params, which
162 //must be compatible with the server's scheduling policy. Then, the
163 //function binds the created thread to the new server. The attr
164 //parameter is overwritten as necessary to introduce the adequate
165 //scheduling policy and priority, according to the preemption level
166 //given in the contract and the frsh_priority_map() function defined by
170 FRSH_ERR_BAD_ARGUMENT : if the value of the server argument is not in range,
171 or sched_params is NULL
172 FRSH_ERR_SCHED_POLICY_NOT_COMPATIBLE : if the scheduling policy
173 in sched_params is not compatible to the server's one.
174 FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
176 FRSH_ERR_NOT_CONTRACTED_SERVER : if the referenced server is not valid
177 FRSH_ERR_SERVER_WORKLOAD_NOT_COMPATIBLE: if the kind of workload
178 of the server is FRSH_OVERHEAD
180 It may also return any of the errors that may be returned by the
181 pthread_create()POSIX function call
186 frsh_create_local_thread
187 (frsh_server_id_t server,
188 frsh_sched_params_t *sched_params,
190 pthread_attr_t *attr,
191 frsh_thread_code_t thread_code,
194 //frsh_bind_local_thread_to_server: This operation associates a thread
195 //with a server, which must have a policy different than FRSH_NONE. The
196 //thread's local scheduling parameters are set to the value stored in
197 //the variable pointed to by sched_params, which must be compatible
198 //with the server's scheduling policy. After the call the thread
199 //starts consuming the server's budget and is executed according to
200 //the contract established for that server and to its scheduling
201 //policy. If the thread was already bound to another server, it is
202 //effectively unbound from it and bound to the specified one.
204 //Implementation dependent issue: In order to allow the usage of
205 //application defined schedulers, the given thread must not have the
206 //scheduling policy SCHED_APP and at the same time be attached to an
207 //application scheduler different than the frsh scheduler.
211 FRSH_ERR_BAD_ARGUMENT : if the server argument does not complain with
212 the expected format or valid range, the given thread does not exist,
213 or sched_params is NULL
214 FRSH_ERR_SCHED_POLICY_NOT_COMPATIBLE : if the scheduling policy
215 in sched_params is not compatible to the server's one.
216 FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
218 FRSH_ERR_UNKNOWN_APPSCHEDULED_THREAD : if the thread is attached to
219 an application defined scheduler different than the frsh scheduler
220 FRSH_ERR_NOT_CONTRACTED_SERVER : if the referenced server is not valid
221 FRSH_ERR_SERVER_WORKLOAD_NOT_COMPATIBLE: if the kind of workload
222 of the server is FRSH_OVERHEAD
227 frsh_bind_local_thread_to_server
228 (frsh_server_id_t server,
230 frsh_sched_params_t *sched_params);
233 // frsh_set_local_thread_sched_params: this function changes the
234 // local scheduling parameters of the thread to the value pointed to
235 // by sched_params. This value must be compatible with the scheduling
236 // policy of the server to which the thread is bound.
239 FRSH_ERR_BAD_ARGUMENT : if the given thread does not exist,
240 or sched_params is NULL
241 FRSH_ERR_SCHED_POLICY_NOT_COMPATIBLE : if the thread is already bound
242 and the scheduling policy in sched_params is not compatible to the
243 one of the thread's server.
244 FRSH_ERR_NOT_SCHEDULED_THREAD : if the given thread is not scheduled
246 FRSH_ERR_INTERNAL_ERROR : erroneous binding or malfunction of the FRSH
248 FRSH_ERR_UNKNOWN_APPSCHEDULED_THREAD : if the thread is attached to
249 an application defined scheduler different than the frsh scheduler
250 FRSH_ERR_NOT_CONTRACTED_SERVER : if the thread is bound and its server
256 frsh_set_local_thread_sched_params
258 const frsh_sched_params_t *sched_params);
261 // frsh_get_local_thread_sched_params: this function stores the
262 // local scheduling parameters of the specified thread in the variable
263 // pointed to by sched_params
266 FRSH_ERR_BAD_ARGUMENT : if sched_params is NULL or the thread does
268 FRSH_ERR_NOT_SCHEDULED_THREAD : if the given thread is not scheduled
274 frsh_get_local_thread_sched_params
276 frsh_sched_params_t *sched_params);
279 #endif // _FRSH_HIERARCHICAL_H_