Subversion Repositories shark

Rev

Rev 1618 | 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
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
1045 tullio 21
 CVS :        $Id: activate.c,v 1.11 2006-06-27 08:56:57 tullio Exp $
2 pj 22
 
23
 File:        $File$
1045 tullio 24
 Revision:    $Revision: 1.11 $
25
 Last update: $Date: 2006-06-27 08:56:57 $
2 pj 26
 ------------
27
 
28
 task_activate & group_activate
29
 
30
**/
31
 
32
/*
33
 * Copyright (C) 2000 Paolo Gai
34
 *
35
 * This program is free software; you can redistribute it and/or modify
36
 * it under the terms of the GNU General Public License as published by
37
 * the Free Software Foundation; either version 2 of the License, or
38
 * (at your option) any later version.
39
 *
40
 * This program is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43
 * GNU General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU General Public License
46
 * along with this program; if not, write to the Free Software
47
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
48
 *
49
 */
50
 
51
#include <stdarg.h>
52
#include <ll/ll.h>
1621 fabio 53
#include <arch/stdlib.h>
54
#include <arch/stdio.h>
55
#include <arch/string.h>
2 pj 56
#include <kernel/config.h>
57
#include <kernel/model.h>
58
#include <kernel/const.h>
59
#include <sys/types.h>
60
#include <kernel/types.h>
61
#include <kernel/descr.h>
62
#include <errno.h>
63
#include <kernel/var.h>
64
#include <kernel/func.h>
353 giacomo 65
#include <tracer.h>
2 pj 66
 
67
/*+
690 anton 68
  Activates a single task now
2 pj 69
+*/
70
int task_activate(PID p)
71
{
690 anton 72
  struct timespec t;
73
  kern_gettime(&t);
74
  return task_activate_at(p, &t);
75
}
76
 
77
/*+
78
  Activates a single task at time t
79
+*/
80
int task_activate_at(PID p, struct timespec *t)
81
{
2 pj 82
    LEVEL l;  /* the level of the task p */
83
 
84
    /* some controls on the task p */
85
    if (p<0 || p>=MAX_PROC) {
14 pj 86
        errno = EINVALID_TASK_ID;
2 pj 87
        return -1;
88
    }
89
    if (proc_table[p].status == FREE) {
14 pj 90
        errno = EINVALID_TASK_ID;
2 pj 91
        return -1;
92
    }
93
 
94
    /*+ if we are calling the runlevel functions the system is
95
        into the global_context... we only have to call
96
        the task_activate of the level +*/
97
    if (calling_runlevel_func) {
98
        SYS_FLAGS f;
99
        f=kern_fsave();
100
        if (proc_table[p].control & FREEZE_ACTIVATION)
101
          proc_table[p].frozen_activations++;
102
        else {
103
          l = proc_table[p].task_level;
690 anton 104
          level_table[l]->public_activate(l,p,t);
2 pj 105
        }
106
        kern_frestore(f);
107
        return 0;
108
    }
109
 
110
 
111
    /* Begin activate */
112
    if (ll_ActiveInt()) {
113
      SYS_FLAGS f;
114
      f = kern_fsave();
115
      if (proc_table[p].control & FREEZE_ACTIVATION)
116
        proc_table[p].frozen_activations++;
117
      else {
118
        l = proc_table[p].task_level;
803 giacomo 119
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[p].context,0);
690 anton 120
        level_table[l]->public_activate(l,p,t);
2 pj 121
        event_need_reschedule();
122
      }
123
      kern_frestore(f);
124
    }
125
    else {
126
      proc_table[exec_shadow].context = kern_context_save();
127
 
128
      if (proc_table[p].control & FREEZE_ACTIVATION)
129
        proc_table[p].frozen_activations++;
130
      else {
131
        /* tracer stuff */
502 giacomo 132
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[p].context,0);
2 pj 133
        l = proc_table[p].task_level;  
690 anton 134
        level_table[l]->public_activate(l,p,t);
2 pj 135
 
136
        /* Preempt if necessary */
137
        scheduler();
138
      }
139
      kern_context_load(proc_table[exec_shadow].context);
140
    }
141
 
142
    return 0;
143
}
144
 
145
 
146
/*+
690 anton 147
  Activate a group of tasks identified by the group g now.
2 pj 148
  It returns -1 if the group is not valid
149
+*/
150
int group_activate(WORD g)
151
{
690 anton 152
  struct timespec t;
153
  kern_gettime(&t);
154
  return group_activate_at(g, &t);
155
}
156
 
157
/*+
158
  Activate a group of tasks identified by the group g at time t.
159
  It returns -1 if the group is not valid
160
+*/
161
int group_activate_at(WORD g, struct timespec *t)
162
{
1045 tullio 163
  PID i;              /* a counter */
164
  register LEVEL l;   /* a level value */
2 pj 165
 
166
  if (g == 0) {
14 pj 167
    errno = EINVALID_GROUP;
2 pj 168
    return -1;
169
  }
170
 
171
  /*+ if we are calling the runlevel functions the system is
172
      into the global_context... we only have to call
173
      the task_activate of the level +*/
174
  if (calling_runlevel_func) {
1045 tullio 175
    SYS_FLAGS f;
176
    f = kern_fsave();
2 pj 177
 
1045 tullio 178
    for (i = 0; i < MAX_PROC; i++) {
179
      if (proc_table[i].status != FREE) {
2 pj 180
        if (proc_table[i].group == g) {
181
          if (proc_table[i].control & FREEZE_ACTIVATION) {
182
            proc_table[i].frozen_activations++;
183
            continue;
184
          }
185
          /* tracer stuff */
1045 tullio 186
          TRACER_LOGEVENT(FTrace_EVT_task_activate, (unsigned short int)proc_table[i].context, 0);        
2 pj 187
          l = proc_table[i].task_level;
690 anton 188
          level_table[l]->public_activate(l,i,t);
2 pj 189
        }
1045 tullio 190
      }
191
    }
2 pj 192
 
1045 tullio 193
    kern_frestore(f);
194
    return 0;
2 pj 195
  }
196
 
197
  if (ll_ActiveInt()) {
198
    SYS_FLAGS f;
1045 tullio 199
    f = kern_fsave();
200
    for (i = 0; i < MAX_PROC; i++) {
201
      if (proc_table[i].status != FREE) {
202
        if (proc_table[i].group == g) {
203
          if (proc_table[i].control & FREEZE_ACTIVATION) {
204
            proc_table[i].frozen_activations++;
205
            continue;
206
          }
207
          /* tracer stuff */
208
          TRACER_LOGEVENT(FTrace_EVT_task_activate, (unsigned short int)proc_table[i].context, 0);        
209
          l = proc_table[i].task_level;
210
          level_table[l]->public_activate(l,i,t);
211
          event_need_reschedule();
2 pj 212
        }
213
      }
1045 tullio 214
    }
2 pj 215
    kern_frestore(f);
216
  }
217
  else {
218
    proc_table[exec_shadow].context = kern_context_save();
318 giacomo 219
 
1045 tullio 220
    for (i = 0 ; i < MAX_PROC; i++) {
221
      if (proc_table[i].status != FREE) {
222
        if (proc_table[i].group == g) {
223
          if (proc_table[i].control & FREEZE_ACTIVATION) {
224
            proc_table[i].frozen_activations++;
225
            continue;
226
          }
227
          l = proc_table[i].task_level;
228
          level_table[l]->public_activate(l,i,t);
229
          /* tracer stuff */
230
          TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);
2 pj 231
        }
232
      }
1045 tullio 233
    }
2 pj 234
 
235
    scheduler();
236
    kern_context_load(proc_table[exec_shadow].context);
237
  }
238
  return 0;
239
}