Subversion Repositories shark

Rev

Rev 1120 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1120 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
 * Copyright (C) 2000 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 *
1123 pj 37
 * CVS :        $Id: preempt.c,v 1.2 2003-01-07 17:10:15 pj Exp $
1120 pj 38
 
39
 CBS test with preemption disabling
40
 
41
*/
42
 
43
#include "kernel/kern.h"
44
 
45
void *periodic(void *arg)
46
{
47
  int i;
48
  int y = (int)arg;
49
 
50
  for (i = 19; i < 60; i++) {
51
    puts_xy(i,y,7,"*");
52
 
53
    task_endcycle();
54
  }
55
 
1123 pj 56
  cprintf("Periodic: Task %d end.\n", exec_shadow);
57
 
1120 pj 58
  return 0;
59
}
60
 
61
void *blocker(void *arg)
62
{
63
  struct timespec t;
64
 
65
  task_nopreempt();
66
  cprintf("Blocker: Task nopreempt\n");
67
 
68
  do {
69
    sys_gettime(&t);
70
  } while (t.tv_sec < 5);
71
 
72
  cprintf("Blocker: Task preempt\n");
73
  task_preempt();
74
 
75
  cprintf("Blocker: end\n");
76
 
77
  return 0;
78
}
79
 
80
 
81
 
82
int main(int argc, char **argv)
83
{
84
  struct timespec t;
85
  NRT_TASK_MODEL m;
86
  SOFT_TASK_MODEL m_aper;
87
  PID p;
88
 
89
  clear();
90
  cprintf("Preemption Test.\n");
91
  cprintf("Start time: two periodic tasks and a blocker are created and activated.\n");
92
  cprintf("2 seconds : blocker calls task_nopreempt.\n");
93
  cprintf("5 seconds : task_preempt is called.\n");
94
  cprintf("            The blocked task exec its pending activations.\n");
95
  cprintf("10 seconds: the test stops.\n");
96
  puts_xy(1,20,7,"save task:");
97
  puts_xy(1,21,7,"skip task:");
98
 
99
  nrt_task_default_model(m);
100
 
101
  soft_task_default_model(m_aper);
102
  soft_task_def_met(m_aper,10000);
103
  soft_task_def_period(m_aper,200000);
104
  soft_task_def_group(m_aper,1);
105
  soft_task_def_arg(m_aper, (void *)20);
106
  soft_task_def_periodic(m_aper);
107
 
108
  p = task_create("save", periodic, &m_aper, NULL);
109
  if (p == NIL)
110
    {
111
      perror("Can't create save task...\n");
112
      sys_end();
113
    }
114
 
115
  soft_task_def_skip_arrivals(m_aper);
116
  soft_task_def_arg(m_aper, (void *)21);
117
 
118
  p = task_create("skip", periodic, &m_aper, NULL);
119
  if (p == NIL)
120
    {
121
      perror("Can't create skip task...\n");
122
      sys_end();
123
    }
124
 
125
  p = task_create("blocker", blocker, &m, NULL);
126
  if (p == NIL)
127
    {
128
      perror("Can't create blocker task...\n");
129
      sys_end();
130
    }
131
 
132
  cprintf("main   : save & skip tasks activated.\n");
133
  group_activate(1);
134
 
135
  do {
136
    sys_gettime(&t);
137
  } while (t.tv_sec < 2);
138
 
139
  cprintf("main   : blocker activated.\n");
140
  task_activate(p);
141
 
142
  do {
143
    sys_gettime(&t);
144
  } while (t.tv_sec < 10);
145
 
146
  cprintf("main   : End!!!\n");
147
 
148
  return 0;
149
}