Subversion Repositories shark

Rev

Details | 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
 ------------
21
 CVS :        $Id: jet.c,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2002-03-29 14:12:51 $
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>
61
#include <ll/stdlib.h>
62
#include <ll/stdio.h>
63
#include <ll/string.h>
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
{
87
  kern_cli();
88
 
89
  if (p<0 || p>=MAX_PROC ||
90
      !(proc_table[p].control & JET_ENABLED) ||
91
      proc_table[p].status == FREE) {
92
    kern_sti();
93
    return -1;
94
  }
95
 
96
  if (sum != NULL)  *sum = proc_table[p].jet_sum;
97
  if (max != NULL)  *max = proc_table[p].jet_max;
98
  if (n != NULL)    *n   = proc_table[p].jet_n;
99
  if (curr != NULL) *curr= proc_table[p].jet_table[proc_table[p].jet_curr];
100
 
101
  kern_sti();
102
  return 0;
103
}
104
 
105
/*+ This primitive reset to 0 the maximum execution time and the mean
106
    execution time of the task p, and reset to 0 all the entries in
107
    jet_table.
108
    The value returned is 0 if all ok, -1 if the PID is not correct or
109
    the task doesn't have the JET_ENABLE bit set.                     +*/
110
int jet_delstat(PID p)
111
{
112
  kern_cli();
113
 
114
  if (p<0 || p>=MAX_PROC ||
115
      !(proc_table[p].control & JET_ENABLED) ||
116
      proc_table[p].status == FREE) {
117
    kern_sti();
118
    return -1;
119
  }
120
 
121
  proc_table[p].jet_sum = 0;
122
  proc_table[p].jet_n   = 0;
123
  proc_table[p].jet_max = 0;
124
 
125
  kern_sti();
126
  return 0;
127
}
128
 
129
 
130
/*+ This primitive returns the last n values of the task execution time
131
    recorded after the last call to jet_gettable or jet_delstat.
132
    If n is
133
    <0 it will be set only the last values inserted in the table
134
       since the last call of jet_gettable.
135
    >0 it will be set up to JET_TABLE_DIM datas.
136
 
137
    The value returned is -1 if the PID is not correct or
138
    the task doesn't have the JET_ENABLE bit set, otherwise it returns the
139
    number of values set in the parameter table.
140
    (can be from 0 to JET_TABLE_DIM-1)
141
+*/
142
int jet_gettable(PID p, TIME *table, int n)
143
{
144
  int i;
145
 
146
  kern_cli();
147
 
148
  if (p<0 || p>=MAX_PROC ||
149
      !(proc_table[p].control & JET_ENABLED) ||
150
      proc_table[p].status == FREE) {
151
    kern_sti();
152
    return -1;
153
  }
154
 
155
  /* Copy all the info to the user */
156
  if (n < 0) {
157
    n = proc_table[p].jet_tvalid;
158
    proc_table[p].jet_tvalid = 0;
159
  }
160
  else if (n > JET_TABLE_DIM-1)
161
    n = JET_TABLE_DIM-1;
162
 
163
  for (i=(proc_table[p].jet_curr + JET_TABLE_DIM - n) % JET_TABLE_DIM;
164
       i!= proc_table[p].jet_curr;
165
       i= (i+1) % JET_TABLE_DIM)
166
     *table++ = proc_table[p].jet_table[i];
167
 
168
  kern_sti();
169
  return n;
170
}
171
 
172
/*+ This function updates the jet information. +*/
173
void jet_update_slice(TIME t)
174
{
175
  if (proc_table[exec_shadow].control & JET_ENABLED)
176
    proc_table[exec_shadow].jet_table[ proc_table[exec_shadow].jet_curr ]
177
      += t;
178
 
179
 
180
  if (TIMESPEC_A_LT_B(&schedule_time, &cap_lasttime)) {
181
      kern_printf("scheduletime %lus %luns * caplasttime %lus %luns * exec=%d TIME = %lu \n",
182
                schedule_time.tv_sec,schedule_time.tv_nsec,
183
                cap_lasttime.tv_sec,cap_lasttime.tv_nsec, exec_shadow, t);
184
      sys_end();
185
  }
186
}
187
 
188
/*+ This function updates the jet information at the task end period
189
    it is called in task_endcycle and task_sleep +*/
190
void jet_update_endcycle()
191
{
192
  int s,n;
193
 
194
  if (proc_table[exec_shadow].control & JET_ENABLED) {
195
    s = proc_table[exec_shadow].jet_table[proc_table[exec_shadow].jet_curr];
196
    n = proc_table[exec_shadow].jet_n;
197
 
198
    if (proc_table[exec_shadow].jet_max < s)
199
      proc_table[exec_shadow].jet_max = s;
200
 
201
    proc_table[exec_shadow].jet_sum += s;
202
 
203
    proc_table[exec_shadow].jet_n = n+1;
204
 
205
    proc_table[exec_shadow].jet_curr = (proc_table[exec_shadow].jet_curr + 1)
206
      % JET_TABLE_DIM;
207
    proc_table[exec_shadow].jet_table[proc_table[exec_shadow].jet_curr] = 0;
208
 
209
    /* we update the tvalid field... */
210
    if (proc_table[exec_shadow].jet_tvalid < JET_TABLE_DIM)
211
      proc_table[exec_shadow].jet_tvalid++;
212
  }
213
}
214
 
215