Subversion Repositories shark

Rev

Rev 657 | Rev 803 | 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
 ------------
690 anton 21
 CVS :        $Id: activate.c,v 1.9 2004-05-26 15:33:46 anton Exp $
2 pj 22
 
23
 File:        $File$
690 anton 24
 Revision:    $Revision: 1.9 $
25
 Last update: $Date: 2004-05-26 15:33:46 $
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;
690 anton 119
        level_table[l]->public_activate(l,p,t);
2 pj 120
        event_need_reschedule();
121
      }
122
      kern_frestore(f);
123
    }
124
    else {
125
      proc_table[exec_shadow].context = kern_context_save();
126
 
127
      if (proc_table[p].control & FREEZE_ACTIVATION)
128
        proc_table[p].frozen_activations++;
129
      else {
130
        /* tracer stuff */
502 giacomo 131
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[p].context,0);
2 pj 132
        l = proc_table[p].task_level;  
690 anton 133
        level_table[l]->public_activate(l,p,t);
2 pj 134
 
135
        /* Preempt if necessary */
136
        scheduler();
137
      }
138
      kern_context_load(proc_table[exec_shadow].context);
139
    }
140
 
141
    return 0;
142
}
143
 
144
 
145
/*+
690 anton 146
  Activate a group of tasks identified by the group g now.
2 pj 147
  It returns -1 if the group is not valid
148
+*/
149
int group_activate(WORD g)
150
{
690 anton 151
  struct timespec t;
152
  kern_gettime(&t);
153
  return group_activate_at(g, &t);
154
}
155
 
156
/*+
157
  Activate a group of tasks identified by the group g at time t.
158
  It returns -1 if the group is not valid
159
+*/
160
int group_activate_at(WORD g, struct timespec *t)
161
{
2 pj 162
  PID i;    /* a counter */
163
  register LEVEL l;  /* a level value */
164
 
165
  if (g == 0) {
14 pj 166
    errno = EINVALID_GROUP;
2 pj 167
    return -1;
168
  }
169
 
170
  /*+ if we are calling the runlevel functions the system is
171
      into the global_context... we only have to call
172
      the task_activate of the level +*/
173
  if (calling_runlevel_func) {
174
      SYS_FLAGS f;
175
      f=kern_fsave();
176
 
177
      for (i=0 ; i<MAX_PROC; i++)
178
        if (proc_table[i].group == g) {
179
          if (proc_table[i].control & FREEZE_ACTIVATION) {
180
            proc_table[i].frozen_activations++;
181
            continue;
182
          }
183
          /* tracer stuff */
502 giacomo 184
          TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);        
2 pj 185
          l = proc_table[i].task_level;
690 anton 186
          level_table[l]->public_activate(l,i,t);
2 pj 187
        }
188
 
189
      kern_frestore(f);
190
      return 0;
191
  }
192
 
193
  if (ll_ActiveInt()) {
194
    SYS_FLAGS f;
195
    f=kern_fsave();
196
    for (i=0 ; i<MAX_PROC; i++)
197
      if (proc_table[i].group == g) {
198
        if (proc_table[i].control & FREEZE_ACTIVATION) {
199
          proc_table[i].frozen_activations++;
200
          continue;
201
        }
202
        /* tracer stuff */
502 giacomo 203
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);        
2 pj 204
        l = proc_table[i].task_level;
690 anton 205
        level_table[l]->public_activate(l,i,t);
318 giacomo 206
        event_need_reschedule();
2 pj 207
      }
208
    kern_frestore(f);
209
  }
210
  else {
211
    proc_table[exec_shadow].context = kern_context_save();
318 giacomo 212
 
2 pj 213
    for (i=0 ; i<MAX_PROC; i++)
214
      if (proc_table[i].group == g) {
215
        if (proc_table[i].control & FREEZE_ACTIVATION) {
216
          proc_table[i].frozen_activations++;
217
          continue;
218
        }
219
        l = proc_table[i].task_level;
690 anton 220
        level_table[l]->public_activate(l,i,t);
2 pj 221
        /* tracer stuff */
502 giacomo 222
        TRACER_LOGEVENT(FTrace_EVT_task_activate,(unsigned short int)proc_table[i].context,0);
2 pj 223
      }
224
 
225
    scheduler();
226
    kern_context_load(proc_table[exec_shadow].context);
227
  }
228
  return 0;
229
}