source: rtems/cpukit/sapi/src/exinit.c @ 0577ec1d

4.104.114.84.9
Last change on this file since 0577ec1d was 0577ec1d, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 1, 2002 at 10:31:29 PM

2002-07-01 Joel Sherrill <joel@…>

  • Mega patch merge to change the format of the object IDs to loosen the dependency between the SCORE and the various APIs. There was considerable work to simplify the object name management and it appears that the name_table field is no longer needed. This patch also includes the addition of the internal mutex which is currently only used to protect some types of allocation and deallocation. This significantly can reduce context switch latency under certain circumstances. In particular, some heap/region operations were O(n) and had dispatching disabled. This should help enormously. With this merge, the patch is not as clean as it should be. In particular, the documentation has not been modified to reflect the new object ID layout, the IDs in the test screens are not updated, and _Objects_Get_information needs to be a real routine not inlined. As part of this patch a lot of MP code for thread/proxy blocking was made conditional and cleaned up.
  • include/confdefs.h, src/exinit.c, src/extension.c, src/itronapi.c, src/posixapi.c, src/rtemsapi.c: Modified as part of above.
  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 *  Initialization Manager
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14/*
15 *  SCORE_INIT and SAPI_INIT are defined so all of the super core and
16 *  super API data will be included in this object file.
17 */
18
19#define SAPI_INIT
20#define SCORE_INIT
21
22#include <rtems/system.h>
23#include <rtems/config.h>
24#include <rtems/debug.h>
25#include <rtems/extension.h>
26#include <rtems/fatal.h>
27#include <rtems/init.h>
28#include <rtems/io.h>
29#include <rtems/score/sysstate.h>
30
31#include <rtems/score/apiext.h>
32#include <rtems/score/apimutex.h>
33#include <rtems/score/copyrt.h>
34#include <rtems/score/heap.h>
35#include <rtems/score/interr.h>
36#include <rtems/score/isr.h>
37#if defined(RTEMS_MULTIPROCESSING)
38#include <rtems/score/mpci.h>
39#endif
40#include <rtems/score/priority.h>
41#include <rtems/score/thread.h>
42#include <rtems/score/tod.h>
43#include <rtems/score/userext.h>
44#include <rtems/score/watchdog.h>
45#include <rtems/score/wkspace.h>
46
47#include <rtems/directives.h>
48#include <rtems/sptables.h>
49
50
51#include <rtems/rtems/rtemsapi.h>
52#ifdef RTEMS_POSIX_API
53#include <rtems/posix/posixapi.h>
54#endif
55#ifdef RTEMS_ITRON_API
56#include <rtems/itron/itronapi.h>
57#endif
58
59Objects_Information *_Internal_Objects[ OBJECTS_INTERNAL_CLASSES_LAST + 1 ];
60
61/*PAGE
62 *
63 *  rtems_initialize_executive
64 *
65 *  This directive initializes all the kernels data structures
66 *  to the states necessary for the kernel to begin execution.  All
67 *  include files that contain global variable definitions should be
68 *  included in this file.  The system threads and initialization threads
69 *  are created and started by this routine.  This routine then
70 *  initiates multithreading.
71 *
72 *  Input parameters:
73 *    configuration_table - pointer to the user's configuration table
74 *    cpu_table           - pointer to the user's CPU configuration table
75 *
76 *  Output parameters:  NONE
77 */
78
79void rtems_initialize_executive(
80  rtems_configuration_table *configuration_table,
81  rtems_cpu_table           *cpu_table
82)
83{
84  rtems_interrupt_level bsp_level;
85
86  bsp_level = rtems_initialize_executive_early(configuration_table, cpu_table);
87  rtems_initialize_executive_late( bsp_level );
88}
89
90rtems_interrupt_level rtems_initialize_executive_early(
91  rtems_configuration_table *configuration_table,
92  rtems_cpu_table           *cpu_table
93)
94{
95  rtems_interrupt_level        bsp_level;
96  rtems_multiprocessing_table *multiprocessing_table;
97
98  /*
99   *  Dispatching and interrupts are disabled until the end of the
100   *  initialization sequence.  This prevents an inadvertent context
101   *  switch before the executive is initialized.
102   */
103
104  _ISR_Disable( bsp_level );
105
106  if ( configuration_table == NULL )
107    _Internal_error_Occurred(
108      INTERNAL_ERROR_CORE,
109      TRUE,
110      INTERNAL_ERROR_NO_CONFIGURATION_TABLE
111    );
112
113  /*
114   *  Initialize the system state based on whether this is an MP system.
115   */
116
117#if defined(RTEMS_MULTIPROCESSING)
118  multiprocessing_table = configuration_table->User_multiprocessing_table;
119
120  _System_state_Handler_initialization(
121    (multiprocessing_table) ? TRUE : FALSE
122  );
123#else
124  multiprocessing_table = NULL;
125
126  _System_state_Handler_initialization( FALSE );
127#endif
128
129  /*
130   *  Provided just for user convenience.
131   */
132
133  _Configuration_Table    = configuration_table;
134  _Configuration_MP_table = multiprocessing_table;
135
136  /*
137   *  Internally we view single processor systems as a very restricted
138   *  multiprocessor system.
139   */
140
141  if ( multiprocessing_table == NULL )
142    multiprocessing_table = 
143      (void *)&_Initialization_Default_multiprocessing_table;
144
145  if ( cpu_table == NULL )
146    _Internal_error_Occurred(
147      INTERNAL_ERROR_CORE,
148      TRUE,
149      INTERNAL_ERROR_NO_CPU_TABLE
150    );
151
152  _CPU_Initialize( cpu_table, _Thread_Dispatch );
153
154  /*
155   *  Do this as early as possible to insure no debugging output
156   *  is even attempted to be printed.
157   */
158
159  _Debug_Manager_initialization();
160
161  _API_extensions_Initialization();
162
163  _Thread_Dispatch_initialization();
164
165  _Workspace_Handler_initialization(
166     (void *)configuration_table->work_space_start,
167     configuration_table->work_space_size
168  );
169
170  _User_extensions_Handler_initialization(
171    configuration_table->number_of_initial_extensions,
172    configuration_table->User_extension_table
173  );
174
175  _ISR_Handler_initialization();
176
177  _Objects_Handler_initialization(
178    multiprocessing_table->node,
179    multiprocessing_table->maximum_nodes,
180    multiprocessing_table->maximum_global_objects
181  );
182
183  _Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
184
185  _Priority_Handler_initialization();
186
187  _Watchdog_Handler_initialization();
188
189  _TOD_Handler_initialization( configuration_table->microseconds_per_tick );
190
191  _Thread_Handler_initialization(
192    configuration_table->ticks_per_timeslice,
193    configuration_table->maximum_extensions,
194    multiprocessing_table->maximum_proxies
195  );
196
197#if defined(RTEMS_MULTIPROCESSING)
198  _MPCI_Handler_initialization(
199    multiprocessing_table->User_mpci_table,
200    RTEMS_TIMEOUT
201  );
202#endif
203
204/* MANAGERS */
205
206  _RTEMS_API_Initialize( configuration_table );
207
208  _Extension_Manager_initialization( configuration_table->maximum_extensions );
209
210  _IO_Manager_initialization(
211    configuration_table->Device_driver_table,
212    configuration_table->number_of_device_drivers,
213    configuration_table->maximum_drivers,
214    configuration_table->maximum_devices
215  );
216
217#ifdef RTEMS_POSIX_API
218  _POSIX_API_Initialize( configuration_table );
219#endif
220
221#ifdef RTEMS_ITRON_API
222  _ITRON_API_Initialize( configuration_table );
223#endif
224
225  _System_state_Set( SYSTEM_STATE_BEFORE_MULTITASKING );
226
227  /*
228   *  No threads should be created before this point!!!
229   *  _Thread_Executing and _Thread_Heir are not set.
230   *
231   *  At this point all API extensions are in place.  After the call to
232   *  _Thread_Create_idle() _Thread_Executing and _Thread_Heir will be set.
233   */
234
235  _Thread_Create_idle();
236
237
238  /*
239   *  Scheduling can properly occur now as long as we avoid dispatching.
240   */
241
242  if ( cpu_table->pretasking_hook )
243    (*cpu_table->pretasking_hook)();
244
245#if defined(RTEMS_MULTIPROCESSING)
246  _MPCI_Create_server();
247#endif
248
249  /*
250   *  Run the API and BSPs predriver hook.
251   */
252 
253  _API_extensions_Run_predriver();
254 
255  if ( _CPU_Table.predriver_hook )
256    (*_CPU_Table.predriver_hook)();
257 
258  /*
259   *  Initialize all the device drivers and initialize the MPCI layer.
260   *
261   *  NOTE:  The MPCI may be build upon a device driver.
262   */
263 
264  _IO_Initialize_all_drivers();
265 
266#if defined(RTEMS_MULTIPROCESSING)
267  if ( _System_state_Is_multiprocessing ) {
268    _MPCI_Initialization();
269    _MPCI_Internal_packets_Send_process_packet(
270      MPCI_PACKETS_SYSTEM_VERIFY
271    );
272  }
273#endif
274 
275  /*
276   *  Run the APIs and BSPs postdriver hooks.
277   *
278   *  The API extensions are supposed to create user initialization tasks.
279   */
280 
281  _API_extensions_Run_postdriver();
282 
283  if ( _CPU_Table.postdriver_hook )
284    (*_CPU_Table.postdriver_hook)();
285
286  return bsp_level;
287}
288
289void rtems_initialize_executive_late(
290  rtems_interrupt_level bsp_level
291)
292{
293
294  _System_state_Set( SYSTEM_STATE_BEGIN_MULTITASKING );
295
296  _Thread_Start_multitasking();
297
298  /*
299   *  Restore the interrupt level to what the BSP had.  Technically,
300   *  this is unnecessary since the BSP should have all interrupts
301   *  disabled when rtems_initialize_executive is invoked.  But this keeps
302   *  the ISR Disable/Enable calls paired.
303   */
304
305  _ISR_Enable( bsp_level );
306}
307
308/*PAGE
309 *
310 *  rtems_shutdown_executive
311 *
312 *  This kernel routine shutdowns the executive.  It halts multitasking
313 *  and returns control to the application execution "thread" which
314 *  initialially invoked the rtems_initialize_executive directive.
315 *
316 *  Input parameters:   NONE
317 *
318 *  Output parameters:  NONE
319 */
320
321void rtems_shutdown_executive(
322   unsigned32 result
323)
324{
325  if ( _System_state_Current != SYSTEM_STATE_SHUTDOWN ) {
326    _System_state_Set( SYSTEM_STATE_SHUTDOWN );
327    _Thread_Stop_multitasking();
328  }
329}
Note: See TracBrowser for help on using the repository browser.