source: trunk/Softwares/Basic_test.or32/src/c/main.c @ 26

Last change on this file since 26 was 2, checked in by kane, 18 years ago

Import Morpheo

File size: 5.3 KB
Line 
1#include <sys/lock.h>
2#include <sys/reent.h>
3#include <errno.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <time.h>
8#include <sys/types.h>
9#include <unistd.h>
10#include <math.h>
11
12#include "bool.h"
13#include "test_setjmp.h"
14#include "func_io.h"
15#include "func_test_io.h"
16#include "func_test_lock.h"
17#include "func_integrity.h"
18#include "thread_info.h"
19#include "cpu_info.h"
20#include "uncached_mask.h"
21#include "bottles.h"
22
23#include "workload.h"
24
25#define verbose_none      0
26#define verbose_low       1
27#define verbose_medium    2
28#define verbose_high      3
29#define VERBOSE_SYSTEM    verbose_none
30#define HAVE_SYSTEM       1
31
32void init_thread  ();
33void exit_thread  ();
34#if (HAVE_SYSTEM != 0)
35void init_system  ();
36void exit_system  ();
37#endif //HAVE_SYSTEM
38
39//~~~~~[ global variable ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
41__LOCK_INIT(static,system_lock);
42
43#if (HAVE_SYSTEM != 0)
44static volatile bool         system_init   = false;
45#endif //HAVE_SYSTEM
46static volatile unsigned int nb_thread_run = 0;
47
48//=====[ main ]=================================================================
49/*
50 * All thread execute this routine
51 * Initialize the thread and attribute a Workload at each thread
52 */
53
54int main()
55{
56  init_thread();
57
58/*   test_integrity (); */
59/*   test_setjmp(); */
60/*   func_test_io(); */
61/*   test_lock1(); */
62/*   test_lock2(); */
63/*   test_lock_recursive1(); */
64/*   test_lock_recursive2(); */
65
66  /*
67   * Lunch thread with a Workload
68   */
69#if (VERBOSE_SYSTEM >= verbose_medium)
70  printf("<main> : lunch workload\n");
71#endif //VERBOSE_SYSTEM
72
73  {
74   int pid = (int)getpid();
75
76   if (pid < NB_WORKLOAD)
77     (*WorkLoad[pid])();
78   else
79     printf("<main> pid is %d but the number of function in the workload is %d\n",pid,(int)NB_WORKLOAD);
80  }
81 
82#if (VERBOSE_SYSTEM >= verbose_medium)
83  printf("<main> : exit workload\n");
84#endif //VERBOSE_SYSTEM
85 
86  exit (0);
87}
88
89//-----[ init_thread ]----------------------------------------------------------
90/*
91 * Initialize all thread
92 */
93
94void init_thread()
95{
96  unsigned int pid;
97
98  set_uncached_mask (0x80000000);
99 
100  __lock_init    (system_lock);
101
102  // Test if is the first thread -> initialization of system
103  __lock_acquire (system_lock);
104  pid = nb_thread_run ++;
105  __lock_release (system_lock);
106 
107  // Change parameters of thread
108  //  * Identificator
109  //  * Priority
110  set_thread_id       (pid);
111  set_thread_priority (0xF);
112
113  // Initialize Reentrant structure
114  _REENT_INIT_PTR(_REENT);
115
116#if (HAVE_SYSTEM != 0)
117  if (pid == 0)
118    init_system();
119 
120  while (system_init == false);
121#endif //HAVE_SYSTEM
122
123
124  // Test if is the first thread -> initialization of system
125  atexit (exit_thread);
126
127  print((get_thread_id() << 16) | get_cpu_id());
128 
129#if (VERBOSE_SYSTEM >= verbose_low)
130  printf("<init_thread> Thread[%d] executed on CPU[%d]\n",getpid(),get_cpu_id());
131#endif //VERBOSE_SYSTEM
132}
133
134//-----[ exit_thread ]----------------------------------------------------------
135/*
136 * Free all ressource
137 */
138
139void exit_thread()
140{
141  bool last = false;
142
143#if (VERBOSE_SYSTEM >= verbose_low)
144  printf("<exit_thread> Thread[%d] is finish\n",getpid());
145#endif //VERBOSE_SYSTEM
146 
147  __lock_acquire (system_lock);
148 
149  nb_thread_run --;
150  last = (nb_thread_run == 0)?true:false;
151 
152  __lock_release (system_lock);
153
154#if (HAVE_SYSTEM != 0)
155  if (last == true)
156    exit_system();
157#endif //HAVE_SYSTEM
158
159  quit(getpid());
160
161  while(1);
162}
163
164
165#if (HAVE_SYSTEM != 0)
166//-----[ init_system ]----------------------------------------------------------
167/*
168 * Initialize all system
169 */
170
171void init_system()
172{
173#if (VERBOSE_SYSTEM >= verbose_high)
174  time_t * my_time = (time_t *) malloc (sizeof (time_t));
175
176  if (my_time == NULL)
177    {
178      printf("<init_system> {error} malloc\n");
179      exit(-1);
180    }
181 
182  if (time(my_time) == ((time_t)-1))
183    {
184      printf("<init_system> {error} time\n");
185      exit (-1);
186    }
187 
188  printf("<init_system> System boot     - %s",ctime(my_time));
189
190  free(my_time);
191#else
192#if (VERBOSE_SYSTEM >= verbose_low)
193  printf("<init_system> System boot\n");
194#endif //VERBOSE_SYSTEM
195#endif //VERBOSE_SYSTEM
196
197#if (VERBOSE_SYSTEM >= verbose_medium)
198  printf("\n");
199  printf("@     @    @@@@    @@@@@    @@@@@    @    @   @@@@@@    @@@@     \n");
200  printf("@@   @@   @    @   @    @   @    @   @    @   @        @    @    \n");
201  printf("@ @@@ @   @    @   @@@@@    @@@@@    @@@@@@   @@@@     @    @    \n");
202  printf("@     @   @    @   @    @   @        @    @   @        @    @    \n");
203  printf("@     @    @@@@    @    @   @        @    @   @@@@@@    @@@@     \n");
204  printf("@     @utiple ORganization for a Processor HEterogenous and Open.\n");
205  printf("\n");
206#endif //VERBOSE_SYSTEM
207
208  system_init = true;
209}
210
211//-----[ exit_system ]----------------------------------------------------------
212/*
213 * Free all ressource
214 */
215
216void exit_system()
217{
218#if (VERBOSE_SYSTEM >= verbose_high)
219  time_t * my_time = (time_t *) malloc (sizeof (time_t));
220 
221  if (my_time == NULL)
222    {
223      printf("<exit_system> {error} malloc\n");
224      exit(-1);
225    }
226 
227  if (time(my_time) == ((time_t)-1))
228    {
229      printf("<exit_system> {error} time\n");
230      exit (-1);
231    }
232 
233  printf("<exit_system> System shutdown  - %s",ctime(my_time));
234
235  free (my_time);
236#else
237#if (VERBOSE_SYSTEM >= verbose_medium)
238  printf("<exit_system> System shutdown\n");
239#endif //VERBOSE_SYSTEM
240#endif //VERBOSE_SYSTEM
241}
242#endif //HAVE_SYSTEM
Note: See TracBrowser for help on using the repository browser.