Subversion Repositories shark

Rev

Rev 1024 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
 
22
/**
23
 ------------
1024 mauro 24
 CVS :        $Id: model.h,v 1.16 2006-03-09 11:55:10 mauro Exp $
2 pj 25
 
26
 File:        $File$
1024 mauro 27
 Revision:    $Revision: 1.16 $
28
 Last update: $Date: 2006-03-09 11:55:10 $
2 pj 29
 ------------
30
 
31
 This file contains the definitions of the task and resource models.
32
 
33
**/
34
 
35
/*
36
 * Copyright (C) 2000 Paolo Gai
37
 *
38
 * This program is free software; you can redistribute it and/or modify
39
 * it under the terms of the GNU General Public License as published by
40
 * the Free Software Foundation; either version 2 of the License, or
41
 * (at your option) any later version.
42
 *
43
 * This program is distributed in the hope that it will be useful,
44
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
 * GNU General Public License for more details.
47
 *
48
 * You should have received a copy of the GNU General Public License
49
 * along with this program; if not, write to the Free Software
50
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
51
 *
52
 */
53
 
54
#ifndef __KERNEL_MODEL_H__
55
#define __KERNEL_MODEL_H__
56
 
57
#include "ll/ll.h"
38 pj 58
#include "kernel/types.h"
1689 fabio 59
#include <arch/sys/cdefs.h>
2 pj 60
 
79 pj 61
__BEGIN_DECLS
62
 
2 pj 63
/* -----------------------------------------------------------------------
64
   -----------------------------------------------------------------------
65
   -----------------------------------------------------------------------
66
   -----------------------------------------------------------------------
67
   TASK MODELS
68
   -----------------------------------------------------------------------
69
   -----------------------------------------------------------------------
70
   -----------------------------------------------------------------------
71
   ----------------------------------------------------------------------- */
72
 
73
 
74
/* -----------------------------------------------------------------------
75
   TASK_MODELS: the base struct
76
   ----------------------------------------------------------------------- */
77
 
78
/*+
79
 TASK_MODEL
80
 
81
 IMPORTANT: this structure shall not be used by the end-user!!!
82
 
83
 This structure is only used to group together a set of optional
84
 parameters describing the task model. This structure is passed
85
 to the task_create primitive.
86
 
87
 The control field is used to set special task processing
88
 functions.
89
 
90
 Currently it supports:
91
 
92
 - USE_FPU     bit
93
   If the hw architecture is not smart enough to allow automatic
94
   FPU context switch, this information is used at the VM level
95
   to perform transparently the preemption of a FPU-task
96
 
97
 - NO_KILL     bit
98
   If this bit is set, the task can't be killed via the task_kill
99
   function. To make a task unkillable for short periods of time,
100
   use the cancellability functions instead.
101
 
102
 - NO_PREEMPT  bit
103
   If this bit is set, the task can't be preempted. To set/reset it,
104
   use the primitive task_preempt/task_no_preempt
105
 
106
 - SYSTEM_TASK bit
107
   If this bit is set, the task is a system task. The whole system exit
108
   only when all the non-system tasks are terminated.
109
 
110
 - JET_ENABLED bit
111
   If this bit is set the Generic Kernel records the Job Execution Times
112
   for the task. See the jet_XXX functions...
113
 
114
 - TASK_JOINABLE bit
115
   If this bit is set the task is joinable with task_join, otherwise the
116
   task is detached...
117
 
118
 - STACKADDR_SPECIFIED bit
119
   This bit is set when the task was created if we specify in the model
120
   the stack address. When the task ends, if this bi is set, the stack
121
   is not freed.
122
 
123
 
124
 - KILL_*      bits
125
   These bits are used to memorize the cancelability state of the task.
126
 
127
 - CONTROL_CAP bit
128
   This flag has to be set in the scheduling modules (NOT by the end-user)
129
   only if the kernel has to check the capacity for the task. The kernel
130
   uses only the avail_time field of the process descriptor.
131
 
132
 - TASK_DOING_SIGNALS bit
133
   It is an internal flag used with signal handling. It is set only when
134
   the task is executing a signal handler
135
 
136
 - FREEZE_ACTIVATION
137
   If this bit is set, the task_activate primitive doesn't activate any task;
138
   instead, it increment a counter. See task_[un]block_activations in kern.c
139
 
140
 - WAIT_FOR_JOIN
141
   The flag is set when the task terminates; the descriptor is not
142
   freed because we wait a task_join
143
 
144
 - DESCRIPTOR_DISCARDED
145
   This bit is set when the task descriptor is discarded by task_createn
146
   (the wait_for_join flag is set and the task was inserted in the free
147
   queue by a scheduling level). The task will be reinserted into the
148
   free queue by task_join...
149
 
150
 All the models redefines the TASK_MODEL structure
151
 - adding new fields if needed
152
 - using a unique number in the pclass variable
153
 
154
 When the user wants to create a task, he must specify a task model.
155
 First, he have to define a XXX_TASK_MODEL, then he must initialize it with
156
 a XXX_task_default_model.
157
 
158
 Then, he can specify some attributes that characterize the model.
159
 
160
 Not all the fields of a task model are mandatory, but a scheduling level
161
 or an ahard server may require some of them.
162
 For example, if the user wants to create an ahard tasks, he may specify
163
 a wcet. The wcet is not required by a Deferrable Server, but it is mandatory
164
 for a TBS!!!.
165
 
166
+*/
167
 
168
 
169
typedef struct {
170
    WORD    pclass;
38 pj 171
    LEVEL   level;
2 pj 172
    size_t  stacksize;
173
    void    *stackaddr;
174
    WORD    group;
175
    void    *arg;
176
    DWORD   control;
177
} TASK_MODEL;
178
 
179
/*+ Value for the control field, It is set if +*/
180
#define USE_FPU              0x0001 /*+ the task use FPU registers +*/
181
#define NO_KILL              0x0002 /*+ the task isn't killable at all +*/
182
#define NO_PREEMPT           0x0004 /*+ the task isn't preemptable +*/
183
#define SYSTEM_TASK          0x0008 /*+ the task is a system task. +*/
184
#define JET_ENABLED          0x0010 /*+ execution time monitoring enabled +*/
185
#define TASK_JOINABLE        0x0020 /*+ the task is joinable (see task_join)+*/
186
#define STACKADDR_SPECIFIED  0x0040 /*+ the stackaddr was specified +*/
187
#define TRACE_TASK          0x20000 /*+ the task must be traced +*/
188
 
189
/*+ flags contained in the control field, usettables from the models: +*/
190
#define KILLED_ON_CONDITION  0x0080 /*+ the task is killed but it is waiting
191
                                        to die because it must reaquire
192
                                        the mutex +*/
193
#define KILL_ENABLED         0x0100 /*+ cancelability enabled +*/
194
#define KILL_DEFERRED        0x0200 /*+ cancelability type deferred/async. +*/
195
#define KILL_REQUEST         0x0400 /*+ kill issued but not executed +*/
196
#define CONTROL_CAP          0x0800 /*+ Capacity control enabled +*/
197
#define TASK_DOING_SIGNALS   0x1000 /*+ see kern_deliver_pending_signals
198
                                        in signal.c +*/
199
#define FREEZE_ACTIVATION    0x2000 /*+ see task_block_activation in kern.c +*/
200
 
201
/* flags used in the implementation of the task_join */
202
#define WAIT_FOR_JOIN        0x4000 /*+ the task is terminated, but the
203
                                        descriptor is not freed because we wait
204
                                        a task_join +*/
205
#define DESCRIPTOR_DISCARDED 0x8000 /*+ the task descriptor is discarded by
206
                                        task_createn because the wait_for_join
207
                                        flag is set and it was inserted in the
208
                                        free queue by a scheduling level +*/
209
 
210
/* flag used in the implementation of the sig_timedwait */
211
#define SIGTIMEOUT_EXPIRED   0x10000 /*+ if the sigwait timer expires this
212
                                        flag is set... +*/
213
 
328 giacomo 214
/* flag to avoid task_makefree called 2 times */
215
#define TASK_MAKEFREE       0x100000
2 pj 216
 
217
/* Some macros to set various task-model parameters */
218
#define task_default_model(m,p) (m).pclass = (p), \
38 pj 219
                                (m).level = 0; \
2 pj 220
                                (m).stacksize = 4096, \
221
                                (m).stackaddr = NULL, \
222
                                (m).group = 0, \
223
                                (m).arg = NULL,\
224
                                (m).control = 0
38 pj 225
#define task_def_level(m,l)     (m).level = (l)
2 pj 226
#define task_def_arg(m,a)       (m).arg = (a)
227
#define task_def_stack(m,s)     (m).stacksize = (s)
228
#define task_def_stackaddr(m,s) (m).stackaddr = (s)
229
#define task_def_group(m,g)     (m).group = (g)
230
#define task_def_usemath(m)     (m).control |= USE_FPU
231
#define task_def_system(m)      (m).control |= SYSTEM_TASK
232
#define task_def_nokill(m)      (m).control |= NO_KILL
233
#define task_def_ctrl_jet(m)    (m).control |= JET_ENABLED
234
#define task_def_joinable(m)    (m).control |= TASK_JOINABLE
235
#define task_def_unjoinable(m)  (m).control &= ~TASK_JOINABLE
236
#define task_def_trace(m)       (m).control |= TRACE_TASK
237
#define task_def_notrace(m)     (m).control &= ~TRACE_TASK
238
 
239
 
240
 
241
 
242
/* -----------------------------------------------------------------------
243
   PCLASS values
244
   ----------------------------------------------------------------------- */
245
 
38 pj 246
/* These are the value for the pclass field */
2 pj 247
 
38 pj 248
#define DUMMY_PCLASS        0
249
#define HARD_PCLASS         1
250
#define SOFT_PCLASS         2
251
#define NRT_PCLASS          3
252
#define JOB_PCLASS          4
671 giacomo 253
#define ELASTIC_PCLASS      5
1024 mauro 254
#define INTERRUPT_PCLASS    6
2 pj 255
 
256
/* -----------------------------------------------------------------------
257
   Useful stuffs
258
   ----------------------------------------------------------------------- */
259
 
260
#define PERIODIC       0
261
#define APERIODIC      1
262
 
263
#define SAVE_ARRIVALS  0
264
#define SKIP_ARRIVALS  1
265
 
266
/* -----------------------------------------------------------------------
267
   DUMMY_TASK_MODEL: model used only for the dummy task
268
   ----------------------------------------------------------------------- */
269
 
270
/*+ the dummy task doesn't add any new field +*/
271
typedef TASK_MODEL DUMMY_TASK_MODEL;
272
 
273
#define dummy_task_default_model(m) task_default_model(m,DUMMY_PCLASS)
274
#define dummy_task_def_level(m,l)   task_def_level(m,l)
275
#define dummy_task_def_system(m)    task_def_system(m)
276
#define dummy_task_def_nokill(m)    task_def_nokill(m)
277
#define dummy_task_def_ctrl_jet(m)  task_def_ctrl_jet(m)
878 trimarchi 278
#define dummy_task_def_group(m,g)   task_def_group(m,g)
279
#define dummy_task_def_arg(m,a)     task_def_arg(m,a)
2 pj 280
 
281
 
282
/* -----------------------------------------------------------------------
1024 mauro 283
   INTERRUPT_TASK_MODEL: model used only for the INTDrive task
284
   ----------------------------------------------------------------------- */
285
 
286
/*+ The only added field is the wcet used to check ISR overrun +*/
287
 
288
typedef struct {
289
  TASK_MODEL t;
290
  TIME wcet;
291
} INTERRUPT_TASK_MODEL;
292
 
293
#define interrupt_task_default_model(m)                             \
294
                        task_default_model((m).t,INTERRUPT_PCLASS), \
295
                        (m).wcet        = 0 
296
#define interrupt_task_def_level(m,l)    task_def_level((m).t,l)
297
#define interrupt_task_def_arg(m,a)      task_def_arg((m).t,a)
298
#define interrupt_task_def_system(m)     task_def_system((m).t)
299
#define interrupt_task_def_nokill(m)     task_def_nokill((m).t)
300
#define interrupt_task_def_wcet(m,w)     (m).wcet = (w)
301
 
302
 
303
/* -----------------------------------------------------------------------
2 pj 304
   HARD_TASK_MODEL: hard Tasks
305
   ----------------------------------------------------------------------- */
306
 
307
/*  A Hard Task model can be used to model periodic and sporadic tasks.
308
    These tasks are usually guaranteed basing on their minimum interarrival
657 anton 309
    time (mit) and wcet, and may have a relative deadline and a release
310
    offset.
2 pj 311
 
312
    A hard task can raise these exceptions:
313
    XDEADLINE_MISS XWCET_VIOLATION XACTIVATION
314
 
315
    The default model sets wcet, mit and relative deadline to 0, and
316
    the periodicity to PERIODIC.
317
*/
318
 
319
typedef struct {
320
  TASK_MODEL t;
321
  TIME mit;
322
  TIME drel;
323
  TIME wcet;
324
  int periodicity;
657 anton 325
  TIME offset;
2 pj 326
} HARD_TASK_MODEL;
327
 
328
#define hard_task_default_model(m)                             \
329
                        task_default_model((m).t,HARD_PCLASS), \
330
                        (m).mit         = 0,                   \
331
                        (m).drel        = 0,                   \
332
                        (m).wcet        = 0,                   \
657 anton 333
                        (m).periodicity = PERIODIC,            \
334
                        (m).offset      = 0 
2 pj 335
#define hard_task_def_level(m,l)    task_def_level((m).t,l)
336
#define hard_task_def_arg(m,a)      task_def_arg((m).t,a)
337
#define hard_task_def_stack(m,s)    task_def_stack((m).t,s)
338
#define hard_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s)
339
#define hard_task_def_group(m,g)    task_def_group((m).t,g)
340
#define hard_task_def_usemath(m)    task_def_usemath((m).t)
341
#define hard_task_def_system(m)     task_def_system((m).t)
342
#define hard_task_def_nokill(m)     task_def_nokill((m).t)
343
#define hard_task_def_ctrl_jet(m)   task_def_ctrl_jet((m).t)
344
#define hard_task_def_mit(m,p)      (m).mit = (p)
345
#define hard_task_def_drel(m,d)     (m).drel = (d)
346
#define hard_task_def_wcet(m,w)     (m).wcet = (w)
657 anton 347
#define hard_task_def_offset(m,o)   (m).offset = (o)
2 pj 348
#define hard_task_def_periodic(m)   (m).periodicity = PERIODIC
349
#define hard_task_def_aperiodic(m)  (m).periodicity = APERIODIC
350
#define hard_task_def_joinable(m)   task_def_joinable((m).t)
351
#define hard_task_def_unjoinable(m) task_def_unjoinable((m).t)
352
#define hard_task_def_trace(m)      task_def_trace((m).t)
353
#define hard_task_def_notrace(m)    task_def_notrace((m).t)
354
 
355
 
356
/* -----------------------------------------------------------------------
357
   SOFT_TASK_MODEL: Soft Tasks
358
   ----------------------------------------------------------------------- */
359
 
360
/*  A Soft Task model can be used to model periodic and aperiodic tasks
361
    usually not guaranteed or guaranteed basing on their period and mean
362
    execution time (met). A Soft task can also record pending activations if
363
    the arrivals are set to SAVE.
364
 
365
    A wcet field is also present for those servers that need if (i.e., TBS)
366
 
367
    The default model sets met, period and wcet to 0, the periodicity to
368
    PERIODIC and the arrivals to SAVE.
369
 
370
    A Soft Task don't raise any exception.
371
*/
372
 
373
typedef struct {
374
  TASK_MODEL t;
375
  TIME period;
376
  TIME met;
377
  TIME wcet;
378
  int periodicity;
379
  int arrivals;
380
} SOFT_TASK_MODEL;
381
 
382
#define soft_task_default_model(m)                             \
383
                        task_default_model((m).t,SOFT_PCLASS), \
384
                        (m).period      = 0,                   \
385
                        (m).met         = 0,                   \
386
                        (m).wcet        = 0,                   \
387
                        (m).periodicity = PERIODIC,            \
388
                        (m).arrivals    = SAVE_ARRIVALS
389
#define soft_task_def_level(m,l)       task_def_level((m).t,l)
390
#define soft_task_def_arg(m,a)         task_def_arg((m).t,a)
391
#define soft_task_def_stack(m,s)       task_def_stack((m).t,s)
392
#define soft_task_def_stackaddr(m,s)   task_def_stackaddr((m).t,s)
393
#define soft_task_def_group(m,g)       task_def_group((m).t,g)
394
#define soft_task_def_usemath(m)       task_def_usemath((m).t)
395
#define soft_task_def_system(m)        task_def_system((m).t)
396
#define soft_task_def_nokill(m)        task_def_nokill((m).t)
397
#define soft_task_def_ctrl_jet(m)      task_def_ctrl_jet((m).t)
398
#define soft_task_def_period(m,p)      (m).period = (p)
399
#define soft_task_def_met(m,d)         (m).met = (d)
400
#define soft_task_def_wcet(m,w)        (m).wcet = (w)
401
#define soft_task_def_periodic(m)      (m).periodicity = PERIODIC
402
#define soft_task_def_aperiodic(m)     (m).periodicity = APERIODIC
403
#define soft_task_def_save_arrivals(m) (m).arrivals    = SAVE_ARRIVALS
404
#define soft_task_def_skip_arrivals(m) (m).arrivals    = SKIP_ARRIVALS
405
#define soft_task_def_joinable(m)      task_def_joinable((m).t)
406
#define soft_task_def_unjoinable(m)    task_def_unjoinable((m).t)
407
#define soft_task_def_trace(m)         task_def_trace((m).t)
408
#define soft_task_def_notrace(m)       task_def_notrace((m).t)
409
 
1024 mauro 410
 
2 pj 411
/* -----------------------------------------------------------------------
412
   NRT_TASK_MODEL: Non Realtime Tasks
413
   ----------------------------------------------------------------------- */
414
 
415
/* A NRT task has a weight and a time slice, plus  a policy attribute.
416
   It can be used to model Round Robin, Proportional Share, POSIX,
417
   and Priority tasks.
418
 
419
   Policy and inherit is inserted in the model to support posix
420
   compliant scheduling...
421
 
422
   The default model set weight and slice to 0, policy to RR, and inherit
423
   to explicit.
424
*/
425
 
426
#define NRT_RR_POLICY   0
427
#define NRT_FIFO_POLICY 1
428
 
429
#define NRT_INHERIT_SCHED  0
430
#define NRT_EXPLICIT_SCHED 1
431
 
432
typedef struct {
433
  TASK_MODEL t;
434
  int weight;
435
  TIME slice;
436
  int arrivals;
437
  int policy;
438
  int inherit;
439
} NRT_TASK_MODEL;
440
 
441
#define nrt_task_default_model(m) task_default_model((m).t,NRT_PCLASS), \
442
                                      (m).weight   = 0,                 \
443
                                      (m).slice    = 0,                 \
444
                                      (m).arrivals = SAVE_ARRIVALS,     \
445
                                      (m).policy   = NRT_RR_POLICY,     \
446
                                      (m).inherit  = NRT_EXPLICIT_SCHED
447
#define nrt_task_def_level(m,l)       task_def_level((m).t,l)
448
#define nrt_task_def_arg(m,a)         task_def_arg((m).t,a)
449
#define nrt_task_def_stack(m,s)       task_def_stack((m).t,s)
450
#define nrt_task_def_stackaddr(m,s)   task_def_stackaddr((m).t,s)
451
#define nrt_task_def_group(m,g)       task_def_group((m).t,g)
452
#define nrt_task_def_usemath(m)       task_def_usemath((m).t)
453
#define nrt_task_def_system(m)        task_def_system((m).t)
454
#define nrt_task_def_nokill(m)        task_def_nokill((m).t)
455
#define nrt_task_def_ctrl_jet(m)      task_def_ctrl_jet((m).t)
456
#define nrt_task_def_joinable(m)      task_def_joinable((m).t)
457
#define nrt_task_def_unjoinable(m)    task_def_unjoinable((m).t)
458
#define nrt_task_def_weight(m,w)      (m).weight = (w)
459
#define nrt_task_def_slice(m,s)       (m).slice = (s)
460
#define nrt_task_def_save_arrivals(m) (m).arrivals    = SAVE_ARRIVALS
461
#define nrt_task_def_skip_arrivals(m) (m).arrivals    = SKIP_ARRIVALS
462
#define nrt_task_def_policy(m,p)      (m).policy = (p)
463
#define nrt_task_def_inherit(m,i)     (m).inherit = (i)
464
#define nrt_task_def_trace(m)         task_def_trace((m).t)
465
#define nrt_task_def_notrace(m)       task_def_notrace((m).t)
466
 
467
 
468
/* -----------------------------------------------------------------------
469
   JOB_TASK_MODEL: Job Task
470
   ----------------------------------------------------------------------- */
471
 
472
/*  This model implements a Job with an optional period and a starting
473
    deadline (for the first activation).
474
 
475
    A Job task can raise a XDEADLINE_MISS exception;
476
    if the flag noraiseexc is != 0, the exception is not raised.
477
 
478
    It represent a SINGLE job activation. Typically, a task with this
479
    model NEVER call a task_sleep or task_endcycle. Why? because it is
480
    a single activation.
481
 
482
    In fact, this model is normally used with aperiodic
483
    servers: the aperiodic server insert a guest task in another level
484
    with that model; then, when the current activation is ended (e.g. a
485
    task_sleep() is called) the level, into the XXX_task_sleep, calls
486
    the XXX_guest_end to terminate the actual activation.
487
 
488
    Note that there is no capacity control on this model.
489
    Note that the task that accept this task DOESN'T reactivate the
490
    task after a period... There is NOT a guest_endcycle defined
491
    for this model...
492
 
493
    The default model set noraiseexc and period to 0, and accept a deadline
494
*/
495
 
691 anton 496
 
2 pj 497
typedef struct {
498
  TASK_MODEL t;
499
  TIME period;
500
  struct timespec deadline;
501
  int noraiseexc;
502
} JOB_TASK_MODEL;
503
 
504
#define job_task_default_model(m,dl)                     \
505
                  task_default_model((m).t,JOB_PCLASS),  \
506
                  (m).period = 0,                        \
507
                  TIMESPEC_ASSIGN(&((m).deadline),&(dl)),\
508
                  (m).noraiseexc = 0
509
#define job_task_def_level(m,l)     task_def_level((m).t,l)
510
#define job_task_def_arg(m,a)       task_def_arg((m).t,a)
511
#define job_task_def_stack(m,s)     task_def_stack((m).t,s)
512
#define job_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s)
513
#define job_task_def_group(m,g)     task_def_group((m).t,g)
514
#define job_task_def_usemath(m)     task_def_usemath((m).t)
515
#define job_task_def_system(m)      task_def_system((m).t)
516
#define job_task_def_nokill(m)      task_def_nokill((m).t)
517
#define job_task_def_ctrl_jet(m)    task_def_ctrl_jet((m).t)
518
#define job_task_def_period(m,per)  (m).period = (per)
519
#define job_task_def_deadline(m,dl) TIMESPEC_ASSIGN(&((m).deadline),&(dl))
520
#define job_task_def_noexc(m)       (m).noraiseexc = 1
521
#define job_task_def_yesexc(m)      (m).noraiseexc = 0
522
#define job_task_def_joinable(m)    task_def_joinable((m).t)
523
#define job_task_def_unjoinable(m)  task_def_unjoinable((m).t)
524
#define job_task_def_trace(m)       task_def_trace((m).t)
525
#define job_task_def_notrace(m)     task_def_notrace((m).t)
526
 
691 anton 527
 
528
/* -----------------------------------------------------------------------
529
   ELASTIC_TASK_MODEL: Elastic Task
530
   ----------------------------------------------------------------------- */
531
 
532
/*  This model implements an elastic task. An elastic task is described by
533
    the following attributes:
534
 
535
    Tmin   - The nominal (minimum) period. This is the period the task
536
             wants to execute at whenever there are enough resources.
537
 
538
    Tmax   - The maximum tolerable period. The elastic model will never
539
             force the task to execute at a longer period than this.
540
 
541
    C      - The declared worst-case execution time. By default,
542
             an exception will be raised if the wcet is violated.
543
 
544
    E      - The elasticity coefficient. A coefficient of 0 means
545
             that its utilization cannot be changed by the elastic
546
             algorithm. A large number means that the task is very
547
             elastic. The default value is 0.
548
 
549
    beta  -  This parameter determines how the elastic scaling is done.
550
             PERIOD_SCALING means that the period will be changed, while
551
             WCET_SCALING means that the wcet will be changed. The
552
             default is PERIOD_SCALING.
553
*/
554
 
555
 
671 giacomo 556
/* Elastic Task */
2 pj 557
 
691 anton 558
#define PERIOD_SCALING 0   
559
#define WCET_SCALING   1
560
 
561
 
671 giacomo 562
typedef struct {
563
  TASK_MODEL t;
564
  TIME Tmin;
565
  TIME Tmax;
691 anton 566
  TIME C;
567
  int  E;
671 giacomo 568
  int  beta;
569
  int  arrivals;
570
} ELASTIC_TASK_MODEL;
571
 
672 giacomo 572
#define elastic_task_default_model(m)                        \
671 giacomo 573
                  task_default_model((m).t,ELASTIC_PCLASS),  \
574
                  (m).Tmin = 0,                        \
575
                  (m).Tmax = 0,                        \
691 anton 576
                  (m).C = 0,                           \
577
                  (m).E = 0,                           \
578
                  (m).beta = PERIOD_SCALING,           \
671 giacomo 579
                  (m).arrivals = SKIP_ARRIVALS
580
#define elastic_task_def_level(m,l)     task_def_level((m).t,l)
581
#define elastic_task_def_arg(m,a)       task_def_arg((m).t,a)
582
#define elastic_task_def_stack(m,s)     task_def_stack((m).t,s)
583
#define elastic_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s)
584
#define elastic_task_def_group(m,g)     task_def_group((m).t,g)
585
#define elastic_task_def_usemath(m)     task_def_usemath((m).t)
586
#define elastic_task_def_system(m)      task_def_system((m).t)
587
#define elastic_task_def_nokill(m)      task_def_nokill((m).t)
588
#define elastic_task_def_ctrl_jet(m)    task_def_ctrl_jet((m).t)
677 giacomo 589
#define elastic_task_def_period(m,min,max)  (m).Tmin = (min),\
590
                                              (m).Tmax = (max)
691 anton 591
#define elastic_task_def_wcet(m,w)      (m).C = (w)
739 giacomo 592
#define elastic_task_def_param(m,e,b)   (m).E = (e), \
677 giacomo 593
                                        (m).beta = (b)
671 giacomo 594
#define elastic_task_def_save_arrivals(m) (m).arrivals    = SAVE_ARRIVALS
595
#define elastic_task_def_skip_arrivals(m) (m).arrivals    = SKIP_ARRIVALS
596
#define elastic_task_def_joinable(m)    task_def_joinable((m).t)
597
#define elastic_task_def_unjoinable(m)  task_def_unjoinable((m).t)
598
#define elastic_task_def_trace(m)       task_def_trace((m).t)
599
#define elastic_task_def_notrace(m)     task_def_notrace((m).t)
2 pj 600
 
601
 
602
 
603
 
604
 
605
 
606
 
607
 
608
 
671 giacomo 609
 
2 pj 610
/* -----------------------------------------------------------------------
611
   -----------------------------------------------------------------------
612
   -----------------------------------------------------------------------
613
   -----------------------------------------------------------------------
614
   RESOURCE MODELS
615
   -----------------------------------------------------------------------
616
   -----------------------------------------------------------------------
617
   -----------------------------------------------------------------------
618
   ----------------------------------------------------------------------- */
619
 
620
 
621
 
622
 
623
 
624
 
625
 
626
/* -----------------------------------------------------------------------
627
   RTYPE values
628
   ----------------------------------------------------------------------- */
629
 
630
/* These are the values for the rtype field of a resource descriptor.
631
   The value in the rtype field is used to distinguish the interface really
632
   implemented by the resource object.
633
 
634
   For example, a mutex resource descriptor "inherit" from a resource_des
635
   and implements also all the mutex functions as "virtual", so a type field
636
   is added to the resource descriptor to distinguish witch interface is
637
   really added. +*/
638
 
639
#define DEFAULT_RTYPE     0  /*+ no fields added to resource_des +*/
640
#define MUTEX_RTYPE       1  /*+ the structure implements a mutex
641
                                 protocol, so a cast to mutex_resource_des
642
                                 is legal +*/
643
 
644
 
645
 
646
/* -----------------------------------------------------------------------
647
   RES_MODEL - the base struct
648
   ----------------------------------------------------------------------- */
649
 
650
/*+
651
 RES_MODEL
652
 
653
 This structure is used like the TASK_MODEL.
654
 It groups together a set of optional parameters describing
655
 the resource model used by a task.
656
 
657
 It contains only a field; the others are model-dependent.
658
+*/
659
 
660
typedef struct {
38 pj 661
  int rclass;        /* protocol */
662
  RLEVEL level;          /* level */
2 pj 663
} RES_MODEL;
664
 
38 pj 665
#define res_default_model(r, p)      (r).rclass = (p), (r).level = 0
666
#define res_def_level(r,l)           (r).level = (l)
2 pj 667
 
668
 
669
 
670
/* -----------------------------------------------------------------------
671
   RCLASS values
672
   ----------------------------------------------------------------------- */
673
 
674
/*+ These are the values for the type field in the resource models
675
    a resource level l that accept a resource model with rclass r
676
    accept also the alias pclass (p | l)
677
    => the LSByte MUST be 0 (256 levels maximum) (as for PCLASS!!!) +*/
678
 
679
#define PC_RCLASS    0x0100
680
#define SRP_RCLASS   0x0200
681
#define SRP2_RCLASS  0x0300
682
 
683
#define BDEDF_RCLASS   0x0400
684
#define BDPSCAN_RCLASS 0x0500
685
 
686
/* -----------------------------------------------------------------------
687
   PC_RES_MODEL: BlockDevice EDF resource model
688
   ----------------------------------------------------------------------- */
689
 
690
typedef struct {
691
  RES_MODEL r;
692
  TIME dl;
693
} BDEDF_RES_MODEL;
694
 
695
#define BDEDF_res_default_model(res) \
696
  res_default_model((res).r,BDEDF_RCLASS); \
697
  (res).dl=0     
698
#define BDEDF_res_def_level(res,l)  res_def_level((res).r,l)     
699
#define BDEDF_res_def_dl(res,reldl)  (res).dl=reldl
700
 
701
/* -----------------------------------------------------------------------
702
   PC_RES_MODEL: BlockDevice PSCAN resource model
703
   ----------------------------------------------------------------------- */
704
 
705
typedef struct {
706
  RES_MODEL r;
707
  int priority;
708
} BDPSCAN_RES_MODEL;
709
 
710
#define BDPSCAN_res_default_model(res) \
711
  res_default_model((res).r,BDPSCAN_RCLASS); \
712
  (res).priority=255     
713
#define BDPSCAN_res_def_level(res,l)  res_def_level((res).r,l)     
714
#define BDPSCAN_res_def_priority(res,pri)  (res).priority=pri
715
 
716
/* -----------------------------------------------------------------------
717
   PC_RES_MODEL: Priority ceiling resource model
718
   ----------------------------------------------------------------------- */
719
 
720
/* the tasks created without using this resource models are assumed to have
721
   priority = MAX_DWORD (the lowest). */
722
 
723
typedef struct {
724
  RES_MODEL r;
725
  DWORD priority;
726
} PC_RES_MODEL;
727
 
728
#define PC_res_default_model(res, prio) \
729
                                 res_default_model((res).r, PC_RCLASS); \
730
                                 (res).priority = (prio)
731
#define PC_res_def_level(res,l)  res_def_level(res,l)
732
 
733
/* -----------------------------------------------------------------------
734
   SRP_RES_MODEL: Stack Resource Policy resource model
735
   ----------------------------------------------------------------------- */
736
 
737
/* the tasks created without using this resource model are not allowed to
738
   lock any SRP mutex. if two of this models are passed to the task_create,
739
   one of them is chosen, in a nondeterministic way, so use only one of
740
   this resource model per task!!!
741
 
742
   The First SRP version uses another resource model that is embedded into
743
   the mutex structure. refer to kernel/modules/srp.c. this second resource
744
   model has the SRP2_RCLASS
745
*/
746
 
747
typedef struct {
748
  RES_MODEL r;
749
  DWORD preempt;  /* the preemption level of a task */
750
} SRP_RES_MODEL;
751
 
752
#define SRP_res_default_model(res, pre) \
753
                                 res_default_model((res).r, SRP_RCLASS); \
754
                                 (res).preempt = (pre)
755
#define SRP_res_def_level(res,l) res_def_level(res,l)
756
 
757
 
758
/* -----------------------------------------------------------------------
759
   MUTEX Attributes
760
   ----------------------------------------------------------------------- */
761
 
762
/*+
763
  MUTEX ATTRIBUTES
764
 
765
  A mutexattr object act as the task model for the tasks in the system:
766
  It specifies the particular options used by a protocol.
767
 
768
  From this basic attribute object many other objects can be derived
769
  as done for the TASK_MODEL. These objects are used to initialize a mutex
770
  with a specified protocol.
771
+*/
772
typedef struct {
773
  int mclass;      /* the protocol type... */
774
} mutexattr_t;
775
 
776
#define mutexattr_default(a, c)  (a).mclass = (c)
777
 
778
 
779
/* -----------------------------------------------------------------------
780
   MCLASS values
781
   ----------------------------------------------------------------------- */
782
 
783
/*+ These are the value for the mclass field;
784
    a mutex level l that accept a task model with mclass m
785
    accept also the alias mclass (m | l)
786
    => the LSByte MUST be 0 (256 levels maximum) +*/
787
 
788
#define NPP_MCLASS      0x0100
789
#define PI_MCLASS       0x0200
790
#define PC_MCLASS       0x0300
791
#define SRP_MCLASS      0x0400
792
#define NOP_MCLASS      0x0500
793
#define NOPM_MCLASS     0x0600
796 trimarchi 794
#define PISTAR_MCLASS   0x0700
2 pj 795
 
796
/* -----------------------------------------------------------------------
797
   PI_mutexattr_t: Priority Inheritance Mutex Attribute
798
   ----------------------------------------------------------------------- */
799
 
800
typedef mutexattr_t PI_mutexattr_t;
801
 
802
#define PI_MUTEXATTR_INITIALIZER {PI_MCLASS}
803
#define PI_mutexattr_default(a)  mutexattr_default(a, PI_MCLASS)
804
 
805
/* -----------------------------------------------------------------------
796 trimarchi 806
   PISTAR_mutexattr_t: Priority Inheritance Mutex Attribute for server
807
   ----------------------------------------------------------------------- */
808
 
808 trimarchi 809
typedef mutexattr_t PISTAR_mutexattr_t;
796 trimarchi 810
 
811
#define PISTAR_MUTEXATTR_INITIALIZER {PISTAR_MCLASS}
808 trimarchi 812
#define PISTAR_mutexattr_default(a)  mutexattr_default(a, PISTAR_MCLASS); 
796 trimarchi 813
 
814
/* -----------------------------------------------------------------------
2 pj 815
   NPP_mutexattr_t: Non Preemptive Protocol Mutex Attribute
816
   ----------------------------------------------------------------------- */
817
 
818
typedef mutexattr_t NPP_mutexattr_t;
819
 
820
#define NPP_MUUEXATTR_INITIALIZER {NPP_MCLASS}
821
#define NPP_mutexattr_default(a)  mutexattr_default(a, NPP_MCLASS)
822
 
823
/* -----------------------------------------------------------------------
824
   PC_mutexattr_t: Priority Ceiling Mutex Attribute
825
   ----------------------------------------------------------------------- */
826
 
827
typedef struct {
828
  mutexattr_t a;
829
  DWORD ceiling;
830
} PC_mutexattr_t;
831
 
832
#define PC_MUTEXATTR_INITIALIZER {{PC_MCLASS},MAX_DWORD}
833
#define PC_mutexattr_default(at,c)  mutexattr_default((at).a, PC_MCLASS); \
834
                                    (at).ceiling = (c)
835
 
836
/* -----------------------------------------------------------------------
837
   SRP_mutexattr_t: Stack Resource Policy Mutex Attribute
838
   ----------------------------------------------------------------------- */
839
 
840
typedef mutexattr_t SRP_mutexattr_t;
841
 
842
#define SRP_MUTEXATTR_INITIALIZER {SRP_MCLASS}
843
#define SRP_mutexattr_default(a)  mutexattr_default(a, SRP_MCLASS)
844
 
845
/* -----------------------------------------------------------------------
846
   NOP_mutexattr_t: No Protocol Mutex Attribute
847
   ----------------------------------------------------------------------- */
848
 
849
typedef mutexattr_t NOP_mutexattr_t;
850
 
851
#define NOP_MUTEXATTR_INITIALIZER {NOP_MCLASS}
852
#define NOP_mutexattr_default(a)  mutexattr_default(a, NOP_MCLASS)
853
 
854
/* -----------------------------------------------------------------------
855
   NOPM_mutexattr_t: No Protocol Multiple lock Mutex Attribute
856
   ----------------------------------------------------------------------- */
857
 
858
typedef mutexattr_t NOPM_mutexattr_t;
859
 
860
#define NOPM_MUTEXATTR_INITIALIZER {NOPM_MCLASS}
861
#define NOPM_mutexattr_default(a)  mutexattr_default(a, NOPM_MCLASS)
862
 
79 pj 863
__END_DECLS
2 pj 864
#endif /* __MODEL_H__ */
865