Subversion Repositories shark

Rev

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