Subversion Repositories shark

Rev

Rev 690 | Rev 1045 | Go to most recent revision | 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
 ------------
803 giacomo 21
 CVS :        $Id: activate.c,v 1.10 2004-09-02 13:48:08 giacomo Exp $
2 pj 22
 
23
 File:        $File$
803 giacomo 24
 Revision:    $Revision: 1.10 $
25
 Last update: $Date: 2004-09-02 13:48:08 $
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>
53
#include <ll/stdlib.h>
54
#include <ll/stdio.h>
55
#include <ll/string.h>
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
{
2 pj 163
  PID i;    /* a counter */
164
  register LEVEL l;  /* a level value */
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) {
175
      SYS_FLAGS f;
176
      f=kern_fsave();
177
 
178
      for (i=0 ; i<MAX_PROC; i++)
179
        if (proc_table[i].group == g) {
180
          if (proc_table[i].control & FREEZE_ACTIVATION) {
181
            proc_table[i].frozen_activations++;
182
            continue;
183
          }
184
          /* tracer stuff */
502 giacomo 185
          TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);        
2 pj 186
          l = proc_table[i].task_level;
690 anton 187
          level_table[l]->public_activate(l,i,t);
2 pj 188
        }
189
 
190
      kern_frestore(f);
191
      return 0;
192
  }
193
 
194
  if (ll_ActiveInt()) {
195
    SYS_FLAGS f;
196
    f=kern_fsave();
197
    for (i=0 ; i<MAX_PROC; i++)
198
      if (proc_table[i].group == g) {
199
        if (proc_table[i].control & FREEZE_ACTIVATION) {
200
          proc_table[i].frozen_activations++;
201
          continue;
202
        }
203
        /* tracer stuff */
502 giacomo 204
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);        
2 pj 205
        l = proc_table[i].task_level;
690 anton 206
        level_table[l]->public_activate(l,i,t);
318 giacomo 207
        event_need_reschedule();
2 pj 208
      }
209
    kern_frestore(f);
210
  }
211
  else {
212
    proc_table[exec_shadow].context = kern_context_save();
318 giacomo 213
 
2 pj 214
    for (i=0 ; i<MAX_PROC; i++)
215
      if (proc_table[i].group == g) {
216
        if (proc_table[i].control & FREEZE_ACTIVATION) {
217
          proc_table[i].frozen_activations++;
218
          continue;
219
        }
220
        l = proc_table[i].task_level;
690 anton 221
        level_table[l]->public_activate(l,i,t);
2 pj 222
        /* tracer stuff */
502 giacomo 223
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);
2 pj 224
      }
225
 
226
    scheduler();
227
    kern_context_load(proc_table[exec_shadow].context);
228
  }
229
  return 0;
230
}