Subversion Repositories shark

Rev

Rev 353 | Rev 502 | 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
 ------------
385 giacomo 21
 CVS :        $Id: activate.c,v 1.6 2004-01-08 20:14:08 giacomo Exp $
2 pj 22
 
23
 File:        $File$
385 giacomo 24
 Revision:    $Revision: 1.6 $
25
 Last update: $Date: 2004-01-08 20:14: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
/*+
68
  Activates a single task
69
+*/
70
int task_activate(PID p)
71
{
72
    LEVEL l;  /* the level of the task p */
73
 
74
    /* some controls on the task p */
75
    if (p<0 || p>=MAX_PROC) {
14 pj 76
        errno = EINVALID_TASK_ID;
2 pj 77
        return -1;
78
    }
79
    if (proc_table[p].status == FREE) {
14 pj 80
        errno = EINVALID_TASK_ID;
2 pj 81
        return -1;
82
    }
83
 
84
    /*+ if we are calling the runlevel functions the system is
85
        into the global_context... we only have to call
86
        the task_activate of the level +*/
87
    if (calling_runlevel_func) {
88
        SYS_FLAGS f;
89
        f=kern_fsave();
90
        if (proc_table[p].control & FREEZE_ACTIVATION)
91
          proc_table[p].frozen_activations++;
92
        else {
93
          l = proc_table[p].task_level;
38 pj 94
          level_table[l]->public_activate(l,p);
2 pj 95
        }
96
        kern_frestore(f);
97
        return 0;
98
    }
99
 
100
 
101
    /* Begin activate */
102
    if (ll_ActiveInt()) {
103
      SYS_FLAGS f;
104
      f = kern_fsave();
105
      if (proc_table[p].control & FREEZE_ACTIVATION)
106
        proc_table[p].frozen_activations++;
107
      else {
108
        l = proc_table[p].task_level;
38 pj 109
        level_table[l]->public_activate(l,p);
2 pj 110
        event_need_reschedule();
111
      }
112
      kern_frestore(f);
113
    }
114
    else {
115
      proc_table[exec_shadow].context = kern_context_save();
116
 
117
      if (proc_table[p].control & FREEZE_ACTIVATION)
118
        proc_table[p].frozen_activations++;
119
      else {
120
        /* tracer stuff */
385 giacomo 121
        TRACER_LOGEVENT(FTrace_EVT_task_activate,1,proc_table[p].context,0);
2 pj 122
        l = proc_table[p].task_level;  
38 pj 123
        level_table[l]->public_activate(l,p);
2 pj 124
 
125
        /* Preempt if necessary */
126
        scheduler();
127
      }
128
      kern_context_load(proc_table[exec_shadow].context);
129
    }
130
 
131
    return 0;
132
}
133
 
134
 
135
/*+
136
  Activate a group of tasks, identified by the group g
137
  It returns -1 if the group is not valid
138
+*/
139
int group_activate(WORD g)
140
{
141
  PID i;    /* a counter */
142
  register LEVEL l;  /* a level value */
143
 
144
  if (g == 0) {
14 pj 145
    errno = EINVALID_GROUP;
2 pj 146
    return -1;
147
  }
148
 
149
  /*+ if we are calling the runlevel functions the system is
150
      into the global_context... we only have to call
151
      the task_activate of the level +*/
152
  if (calling_runlevel_func) {
153
      SYS_FLAGS f;
154
      f=kern_fsave();
155
 
156
      for (i=0 ; i<MAX_PROC; i++)
157
        if (proc_table[i].group == g) {
158
          if (proc_table[i].control & FREEZE_ACTIVATION) {
159
            proc_table[i].frozen_activations++;
160
            continue;
161
          }
162
          /* tracer stuff */
385 giacomo 163
          TRACER_LOGEVENT(FTrace_EVT_task_activate,1,proc_table[i].context,0);        
2 pj 164
          l = proc_table[i].task_level;
38 pj 165
          level_table[l]->public_activate(l,i);
2 pj 166
        }
167
 
168
      kern_frestore(f);
169
      return 0;
170
  }
171
 
172
  if (ll_ActiveInt()) {
173
    SYS_FLAGS f;
174
    f=kern_fsave();
175
    for (i=0 ; i<MAX_PROC; i++)
176
      if (proc_table[i].group == g) {
177
        if (proc_table[i].control & FREEZE_ACTIVATION) {
178
          proc_table[i].frozen_activations++;
179
          continue;
180
        }
181
        /* tracer stuff */
385 giacomo 182
        TRACER_LOGEVENT(FTrace_EVT_task_activate,1,proc_table[i].context,0);        
2 pj 183
        l = proc_table[i].task_level;
38 pj 184
        level_table[l]->public_activate(l,i);
318 giacomo 185
        event_need_reschedule();
2 pj 186
      }
187
    kern_frestore(f);
188
  }
189
  else {
190
    proc_table[exec_shadow].context = kern_context_save();
318 giacomo 191
 
2 pj 192
    for (i=0 ; i<MAX_PROC; i++)
193
      if (proc_table[i].group == g) {
194
        if (proc_table[i].control & FREEZE_ACTIVATION) {
195
          proc_table[i].frozen_activations++;
196
          continue;
197
        }
198
        l = proc_table[i].task_level;
38 pj 199
        level_table[l]->public_activate(l,i);
2 pj 200
        /* tracer stuff */
385 giacomo 201
        TRACER_LOGEVENT(FTrace_EVT_task_activate,1,proc_table[i].context,0);
2 pj 202
      }
203
 
204
    scheduler();
205
    kern_context_load(proc_table[exec_shadow].context);
206
  }
207
  return 0;
208
}