Subversion Repositories shark

Rev

Rev 1123 | Go to most recent revision | Details | 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
 *
37
 * CVS :        $Id: preempt.c,v 1.1 2002-11-11 08:22:46 pj Exp $
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
 
56
  return 0;
57
}
58
 
59
void *blocker(void *arg)
60
{
61
  struct timespec t;
62
 
63
  task_nopreempt();
64
  cprintf("Blocker: Task nopreempt\n");
65
 
66
  do {
67
    sys_gettime(&t);
68
  } while (t.tv_sec < 5);
69
 
70
  cprintf("Blocker: Task preempt\n");
71
  task_preempt();
72
 
73
  cprintf("Blocker: end\n");
74
 
75
  return 0;
76
}
77
 
78
 
79
 
80
int main(int argc, char **argv)
81
{
82
  struct timespec t;
83
  NRT_TASK_MODEL m;
84
  SOFT_TASK_MODEL m_aper;
85
  PID p;
86
 
87
  clear();
88
  cprintf("Preemption Test.\n");
89
  cprintf("Start time: two periodic tasks and a blocker are created and activated.\n");
90
  cprintf("2 seconds : blocker calls task_nopreempt.\n");
91
  cprintf("5 seconds : task_preempt is called.\n");
92
  cprintf("            The blocked task exec its pending activations.\n");
93
  cprintf("10 seconds: the test stops.\n");
94
  puts_xy(1,20,7,"save task:");
95
  puts_xy(1,21,7,"skip task:");
96
 
97
  nrt_task_default_model(m);
98
 
99
  soft_task_default_model(m_aper);
100
  soft_task_def_met(m_aper,10000);
101
  soft_task_def_period(m_aper,200000);
102
  soft_task_def_group(m_aper,1);
103
  soft_task_def_arg(m_aper, (void *)20);
104
  soft_task_def_periodic(m_aper);
105
 
106
  p = task_create("save", periodic, &m_aper, NULL);
107
  if (p == NIL)
108
    {
109
      perror("Can't create save task...\n");
110
      sys_end();
111
    }
112
 
113
  soft_task_def_skip_arrivals(m_aper);
114
  soft_task_def_arg(m_aper, (void *)21);
115
 
116
  p = task_create("skip", periodic, &m_aper, NULL);
117
  if (p == NIL)
118
    {
119
      perror("Can't create skip task...\n");
120
      sys_end();
121
    }
122
 
123
  p = task_create("blocker", blocker, &m, NULL);
124
  if (p == NIL)
125
    {
126
      perror("Can't create blocker task...\n");
127
      sys_end();
128
    }
129
 
130
  cprintf("main   : save & skip tasks activated.\n");
131
  group_activate(1);
132
 
133
  do {
134
    sys_gettime(&t);
135
  } while (t.tv_sec < 2);
136
 
137
  cprintf("main   : blocker activated.\n");
138
  task_activate(p);
139
 
140
  do {
141
    sys_gettime(&t);
142
  } while (t.tv_sec < 10);
143
 
144
  cprintf("main   : End!!!\n");
145
 
146
  return 0;
147
}