Subversion Repositories shark

Rev

Rev 918 | 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
 ------------
918 pj 21
 CVS :        $Id: jet.c,v 1.3 2005-01-08 14:47:16 pj Exp $
2 pj 22
 
23
 File:        $File$
918 pj 24
 Revision:    $Revision: 1.3 $
25
 Last update: $Date: 2005-01-08 14:47:16 $
2 pj 26
 ------------
27
 
28
 Kernel Job Execution Time functions
29
 
30
 This file contains:
31
 
32
 jet_delstat
33
 jet_getstat
34
 jet_gettable
35
 jet_update_endcycle
36
 jet_update_slice
37
 
38
**/
39
 
40
/*
41
 * Copyright (C) 2000 Paolo Gai
42
 *
43
 * This program is free software; you can redistribute it and/or modify
44
 * it under the terms of the GNU General Public License as published by
45
 * the Free Software Foundation; either version 2 of the License, or
46
 * (at your option) any later version.
47
 *
48
 * This program is distributed in the hope that it will be useful,
49
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51
 * GNU General Public License for more details.
52
 *
53
 * You should have received a copy of the GNU General Public License
54
 * along with this program; if not, write to the Free Software
55
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
56
 *
57
 */
58
 
59
#include <stdarg.h>
60
#include <ll/ll.h>
1689 fabio 61
#include <arch/stdlib.h>
62
#include <arch/stdio.h>
63
#include <arch/string.h>
2 pj 64
#include <kernel/config.h>
65
#include <kernel/model.h>
66
#include <kernel/const.h>
67
#include <sys/types.h>
68
#include <kernel/types.h>
69
#include <kernel/descr.h>
70
#include <errno.h>
71
#include <kernel/var.h>
72
#include <kernel/func.h>
73
 
74
/*---------------------------------------------------------------------*/
75
/* Jet management primitives                                           */
76
/*---------------------------------------------------------------------*/
77
 
78
/*+ This primitive returns the maximum execution time and the total
79
    execution time from the task_create or the last jet_delstat
80
    It returns also the number of instances to use to calculate the mean
81
    time and the current job execution time.
82
    The value returned is 0 if all ok, -1 if the PID is not correct or
83
    the task doesn't have the JET_ENABLE bit set.
84
+*/
85
int jet_getstat(PID p, TIME *sum, TIME *max, int *n, TIME *curr)
86
{
318 giacomo 87
  SYS_FLAGS f;
2 pj 88
 
318 giacomo 89
  f = kern_fsave();
90
 
2 pj 91
  if (p<0 || p>=MAX_PROC ||
92
      !(proc_table[p].control & JET_ENABLED) ||
93
      proc_table[p].status == FREE) {
318 giacomo 94
    kern_frestore(f);
2 pj 95
    return -1;
96
  }
97
 
98
  if (sum != NULL)  *sum = proc_table[p].jet_sum;
99
  if (max != NULL)  *max = proc_table[p].jet_max;
100
  if (n != NULL)    *n   = proc_table[p].jet_n;
101
  if (curr != NULL) *curr= proc_table[p].jet_table[proc_table[p].jet_curr];
102
 
318 giacomo 103
  kern_frestore(f);
2 pj 104
  return 0;
105
}
106
 
107
/*+ This primitive reset to 0 the maximum execution time and the mean
108
    execution time of the task p, and reset to 0 all the entries in
109
    jet_table.
110
    The value returned is 0 if all ok, -1 if the PID is not correct or
111
    the task doesn't have the JET_ENABLE bit set.                     +*/
112
int jet_delstat(PID p)
113
{
318 giacomo 114
  SYS_FLAGS f;
2 pj 115
 
318 giacomo 116
  f = kern_fsave();
117
 
2 pj 118
  if (p<0 || p>=MAX_PROC ||
119
      !(proc_table[p].control & JET_ENABLED) ||
120
      proc_table[p].status == FREE) {
318 giacomo 121
    kern_frestore(f);
2 pj 122
    return -1;
123
  }
124
 
125
  proc_table[p].jet_sum = 0;
126
  proc_table[p].jet_n   = 0;
127
  proc_table[p].jet_max = 0;
128
 
318 giacomo 129
  kern_frestore(f);
2 pj 130
  return 0;
131
}
132
 
133
 
134
/*+ This primitive returns the last n values of the task execution time
135
    recorded after the last call to jet_gettable or jet_delstat.
136
    If n is
137
    <0 it will be set only the last values inserted in the table
138
       since the last call of jet_gettable.
139
    >0 it will be set up to JET_TABLE_DIM datas.
140
 
141
    The value returned is -1 if the PID is not correct or
142
    the task doesn't have the JET_ENABLE bit set, otherwise it returns the
143
    number of values set in the parameter table.
144
    (can be from 0 to JET_TABLE_DIM-1)
145
+*/
146
int jet_gettable(PID p, TIME *table, int n)
147
{
148
  int i;
318 giacomo 149
  SYS_FLAGS f;
2 pj 150
 
318 giacomo 151
  f = kern_fsave();
2 pj 152
 
153
  if (p<0 || p>=MAX_PROC ||
154
      !(proc_table[p].control & JET_ENABLED) ||
155
      proc_table[p].status == FREE) {
318 giacomo 156
    kern_frestore(f);
2 pj 157
    return -1;
158
  }
159
 
160
  /* Copy all the info to the user */
161
  if (n < 0) {
162
    n = proc_table[p].jet_tvalid;
163
    proc_table[p].jet_tvalid = 0;
164
  }
165
  else if (n > JET_TABLE_DIM-1)
166
    n = JET_TABLE_DIM-1;
167
 
168
  for (i=(proc_table[p].jet_curr + JET_TABLE_DIM - n) % JET_TABLE_DIM;
169
       i!= proc_table[p].jet_curr;
170
       i= (i+1) % JET_TABLE_DIM)
171
     *table++ = proc_table[p].jet_table[i];
172
 
318 giacomo 173
  kern_frestore(f);
2 pj 174
  return n;
175
}
176
 
177
/*+ This function updates the jet information. +*/
178
void jet_update_slice(TIME t)
179
{
180
  if (proc_table[exec_shadow].control & JET_ENABLED)
181
    proc_table[exec_shadow].jet_table[ proc_table[exec_shadow].jet_curr ]
182
      += t;
183
 
184
 
185
  if (TIMESPEC_A_LT_B(&schedule_time, &cap_lasttime)) {
186
      kern_printf("scheduletime %lus %luns * caplasttime %lus %luns * exec=%d TIME = %lu \n",
187
                schedule_time.tv_sec,schedule_time.tv_nsec,
188
                cap_lasttime.tv_sec,cap_lasttime.tv_nsec, exec_shadow, t);
918 pj 189
      kern_raise(XUNSPECIFIED_EXCEPTION,exec_shadow);
2 pj 190
  }
191
}
192
 
193
/*+ This function updates the jet information at the task end period
194
    it is called in task_endcycle and task_sleep +*/
195
void jet_update_endcycle()
196
{
197
  int s,n;
198
 
199
  if (proc_table[exec_shadow].control & JET_ENABLED) {
200
    s = proc_table[exec_shadow].jet_table[proc_table[exec_shadow].jet_curr];
201
    n = proc_table[exec_shadow].jet_n;
202
 
203
    if (proc_table[exec_shadow].jet_max < s)
204
      proc_table[exec_shadow].jet_max = s;
205
 
206
    proc_table[exec_shadow].jet_sum += s;
207
 
208
    proc_table[exec_shadow].jet_n = n+1;
209
 
210
    proc_table[exec_shadow].jet_curr = (proc_table[exec_shadow].jet_curr + 1)
211
      % JET_TABLE_DIM;
212
    proc_table[exec_shadow].jet_table[proc_table[exec_shadow].jet_curr] = 0;
213
 
214
    /* we update the tvalid field... */
215
    if (proc_table[exec_shadow].jet_tvalid < JET_TABLE_DIM)
216
      proc_table[exec_shadow].jet_tvalid++;
217
  }
218
}
219
 
220