source: rtems/testsuites/sptests/spsize/size.c @ 34b098e

5
Last change on this file since 34b098e was 34b098e, checked in by Sebastian Huber <sebastian.huber@…>, on 05/05/20 at 12:37:30

rtems: Deprecate use of _RTEMS_version

Close #3970.

  • Property mode set to 100644
File size: 19.6 KB
Line 
1/**
2 *  @file
3 *
4 *  This program is run to determine the data space and work space
5 *  requirements of the current version of RTEMS.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22
23#include <rtems/config.h>
24#include <rtems/score/copyrt.h>
25#include <rtems/rtems/clock.h>
26#include <rtems/rtems/tasksimpl.h>
27#include <rtems/rtems/dpmemimpl.h>
28#include <rtems/rtems/eventimpl.h>
29#include <rtems/extensionimpl.h>
30#include <rtems/fatal.h>
31#include <rtems/init.h>
32#include <rtems/score/isr.h>
33#include <rtems/rtems/intr.h>
34#include <rtems/io.h>
35#include <rtems/rtems/messageimpl.h>
36#if defined(RTEMS_MULTIPROCESSING)
37#include <rtems/rtems/mp.h>
38#include <rtems/score/mpciimpl.h>
39#endif
40#include <rtems/rtems/partimpl.h>
41#include <rtems/score/priority.h>
42#include <rtems/rtems/ratemonimpl.h>
43#include <rtems/rtems/regionimpl.h>
44#include <rtems/rtems/semimpl.h>
45#include <rtems/rtems/signal.h>
46#include <rtems/score/scheduler.h>
47#include <rtems/score/sysstate.h>
48#include <rtems/score/thread.h>
49#include <rtems/rtems/timerimpl.h>
50#include <rtems/score/todimpl.h>
51#include <rtems/score/userextimpl.h>
52#include <rtems/score/watchdogimpl.h>
53#include <rtems/score/wkspace.h>
54#if defined(RTEMS_SMP)
55  #include <rtems/score/smp.h>
56#endif
57
58#include <stdlib.h>
59#include <stdio.h>
60#include <unistd.h>
61#include <tmacros.h>
62
63#include "system.h"
64
65/* external function prototypes */
66int getint( void );
67void size_rtems(int mode);
68void help_size(void);
69void print_formula(void);
70
71
72/* These are always defined by the executive.
73 *
74 * #include <rtems/copyrt.h>
75 * #include <rtems/tables.h>
76 */
77#define  HEAP_OVHD        16    /* wasted heap space per task stack */
78#define  NAME_PTR_SIZE     8    /* size of name and pointer table entries */
79
80/*
81 *  This assumes the default Priority Scheduler
82 */
83#include <rtems/score/prioritybitmapimpl.h>
84#include <rtems/score/schedulerpriority.h>
85
86/* Priority scheduling per-thread consumption. Gets
87 * included in the PER_TASK consumption.
88 */
89#define SCHEDULER_TASK_WKSP     (sizeof(Scheduler_priority_Node))
90
91/* Priority scheduling workspace consumption
92 *
93 * Include allocation of ready queue.
94 */
95#define SCHEDULER_WKSP_SIZE  \
96    (sizeof(Scheduler_priority_Context) + \
97     RTEMS_MAXIMUM_PRIORITY * sizeof(Chain_Control ))
98/****** END OF MEMORY USAGE OF DEFAULT PRIORITY SCHEDULER ******/
99
100#define PER_TASK      \
101     (long) (sizeof (Thread_Control) + \
102      NAME_PTR_SIZE + HEAP_OVHD + sizeof( RTEMS_API_Control ) + \
103      SCHEDULER_TASK_WKSP )
104#define PER_SEMAPHORE \
105     (long) (sizeof (Semaphore_Control) + NAME_PTR_SIZE)
106#define PER_TIMER     \
107     (long) (sizeof (Timer_Control) + NAME_PTR_SIZE)
108#define PER_MSGQ      \
109     (long) (sizeof (Message_queue_Control) + NAME_PTR_SIZE)
110#define PER_REGN      \
111     (long) (sizeof (Region_Control) + NAME_PTR_SIZE)
112#define PER_PART      \
113     (long) (sizeof (Partition_Control) + NAME_PTR_SIZE)
114#define PER_PERIOD      \
115     (long) (sizeof (Rate_monotonic_Control) + NAME_PTR_SIZE)
116#define PER_PORT      \
117     (long) (sizeof (Dual_ported_memory_Control) + NAME_PTR_SIZE)
118#define PER_EXTENSION     \
119     (long) (sizeof (Extension_Control) + NAME_PTR_SIZE)
120
121#define PER_DRV       (long) (0)
122#define PER_FPTASK    (long) (CONTEXT_FP_SIZE)
123#define PER_GOBTBL    (long) (sizeof (Chain_Control)*4)
124#define PER_NODE      (long) PER_GOBTBL
125#if defined(RTEMS_MULTIPROCESSING)
126#define PER_GOBJECT   (long) (sizeof (Objects_MP_Control))
127#else
128#define PER_GOBJECT   (long) 0
129#endif
130#define PER_PROXY     (long) (sizeof (Thread_Proxy_control))
131
132#if !defined(RTEMS_MULTIPROCESSING) || (CPU_ALL_TASKS_ARE_FP != TRUE)
133#define MPCI_RECEIVE_SERVER_FP (long) 0
134#else
135#define MPCI_RECEIVE_SERVER_FP (long) (sizeof( Context_Control_fp ))
136#endif
137
138#if (CPU_IDLE_TASK_IS_FP == TRUE)
139#define SYSTEM_IDLE_FP (long) (sizeof( Context_Control_fp ))
140#else
141#define SYSTEM_IDLE_FP (long) 0
142#endif
143
144#if !defined(RTEMS_MULTIPROCESSING)
145#define MPCI_RECEIVE_SERVER_STACK_SIZE 0
146#endif
147
148#if defined(RTEMS_MULTIPROCESSING)
149#define MPCI_RECEIVE_SERVER_STACK_SIZE \
150
151#define MP_SYSTEM_TASKS \
152   (STACK_MINIMUM_SIZE + CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK + \
153    sizeof(Thread_Control) + \
154    MPCI_RECEIVE_SERVER_FP)
155
156extern CORE_semaphore_Control _MPCI_Semaphore;
157#else
158#define MP_SYSTEM_TASKS 0
159#endif
160
161/*
162 *  Idle and the MPCI Receive Server Threads
163 */
164
165#define SYSTEM_TASKS  \
166    (STACK_MINIMUM_SIZE + sizeof(Thread_Control) + SYSTEM_IDLE_FP + \
167     MP_SYSTEM_TASKS)
168
169/* FIXME: uint32_t doesn't seem right */
170uint32_t   sys_req;
171
172void size_rtems(
173  int mode
174)
175{
176int uninitialized = 0;
177int initialized = 0;
178
179/*
180 *  The following data is allocated for each Manager:
181 *
182 *    + Per Manager Object Information
183 *      - local pointer table
184 *      - local name table
185 *      - the object's control blocks
186 *      - global name chains
187 *
188 *  The following is the data allocate from the RTEMS Workspace Area.
189 *  The order indicates the order in which RTEMS allocates it.
190 *
191 *    + Object MP
192 *      - Global Object CB's
193 *    + Thread MP
194 *      - Proxies Chain
195 *    + Scheduler
196 *      - Ready queue
197 *    + Interrupt Manager
198 *      - Interrupt Stack
199 *    + Timer Manager
200 *      - per Manager Object Data
201 *    + Extension Manager
202 *      - per Manager Object Data
203 *    + Message Queue Manager
204 *      - per Manager Object Data
205 *      - Message Buffers
206 *    + Semaphore Manager
207 *      - per Manager Object Data
208 *    + Partition Manager
209 *      - per Manager Object Data
210 *    + Region Manager
211 *      - per Manager Object Data
212 *    + Dual Ported Memory Manager
213 *      - per Manager Object Data
214 *    + Rate Monotonic Manager
215 *      - per Manager Object Data
216 *    + Internal Threads Handler
217 *      - MPCI Receive Server Thread TCB
218 *      - IDLE Thread TCB
219 *      - MPCI Receive Server Thread stack
220 *      - MPCI Receive Server Thread FP area (if CPU requires this)
221 *      - IDLE Thread stack
222 *      - IDLE Thread FP area (if CPU requires this)
223 *
224 *  This does not take into account any CPU dependent alignment requirements.
225 *
226 *  The following calculates the overhead needed by RTEMS from the
227 *  Workspace Area.
228 */
229sys_req = SYSTEM_TASKS        +     /* MPCI Receive Server and IDLE */
230          NAME_PTR_SIZE       +     /* Task Overhead */
231          SCHEDULER_WKSP_SIZE +     /* Scheduler Overhead */
232          NAME_PTR_SIZE       +     /* Timer Overhead */
233          NAME_PTR_SIZE       +     /* Semaphore Overhead */
234          NAME_PTR_SIZE       +     /* Message Queue Overhead */
235          NAME_PTR_SIZE       +     /* Region Overhead */
236          NAME_PTR_SIZE       +     /* Partition Overhead */
237          NAME_PTR_SIZE       +     /* Dual-Ported Memory Overhead */
238          NAME_PTR_SIZE       +     /* Rate Monotonic Overhead */
239          NAME_PTR_SIZE       +     /* Extension Overhead */
240          PER_NODE;                 /* Extra Gobject Table */
241
242uninitialized =
243/*address.h*/   0                                         +
244
245/*asr.h*/       0                                         +
246
247/*attr.h*/      0                                         +
248
249/*bitfield.h*/  0                                         +
250
251/*chain.h*/     0                                         +
252
253/*clock.h*/     0                                         +
254
255/*config.h*/    0                                         +
256
257/*context.h*/   (sizeof _Thread_Dispatch_necessary)        +
258
259/*copyrt.h*/    0                                         +
260
261/*dpmemimpl.h*/ (sizeof _Dual_ported_memory_Information)  +
262
263#if defined(RTEMS_MULTIPROCESSING)
264/*eventmp.h*/   0                                         +
265#endif
266
267/*extensionimpl.h*/ (sizeof _Extension_Information)       +
268
269/*fatal.h*/     0                                         +
270
271/*heap.h*/      0                                         +
272
273/*init.h*/      0                                         +
274
275/*interr.h*/    (sizeof _Internal_errors_What_happened)   +
276
277/*intr.h*/      0                                         +
278
279/*isr.h*/       (sizeof _ISR_Nest_level)                  +
280#if (CPU_SIMPLE_VECTORED_INTERRUPTS == TRUE)
281                (sizeof _ISR_Vector_table)                +
282#endif
283
284/*messageimpl.h*/ (sizeof _Message_queue_Information)     +
285
286/*modes.h*/     0                                         +
287
288#if defined(RTEMS_MULTIPROCESSING)
289/*mp.h*/        0                                         +
290#endif
291
292#if defined(RTEMS_MULTIPROCESSING)
293/*mpciimpl.h*/  (sizeof _MPCI_Remote_blocked_threads)     +
294                (sizeof _MPCI_Semaphore)                  +
295                (sizeof _MPCI_table)                      +
296                (sizeof _MPCI_Receive_server_tcb)         +
297                (sizeof _MPCI_Packet_processors)          +
298#endif
299
300#if defined(RTEMS_MULTIPROCESSING)
301/*mppkt.h*/     0                                         +
302#endif
303
304#if defined(RTEMS_MULTIPROCESSING)
305/*mptables.h*/  0                                         +
306#endif
307
308#if defined(RTEMS_MULTIPROCESSING)
309/*msgmp.h*/     0                                         +
310#endif
311
312/*object.h*/    (sizeof _Objects_Local_node)              +
313                (sizeof _Objects_Maximum_nodes)           +
314                (sizeof _Objects_Information_table)       +
315
316/*options.h*/   0                                         +
317
318/*partimpl.h*/  (sizeof _Partition_Information)           +
319
320#if defined(RTEMS_MULTIPROCESSING)
321/*partmp.h*/    0                                         +
322#endif
323
324/*percpu.h*/    (_SMP_Get_processor_maximum() * sizeof(Per_CPU_Control))  +
325
326/*ratemonimpl.h*/ (sizeof _Rate_monotonic_Information)    +
327
328/*regionimpl.h*/ (sizeof _Region_Information)             +
329
330#if defined(RTEMS_MULTIPROCESSING)
331/*regionmp.h*/  0                                         +
332#endif
333
334/*rtems.h*/     /* Not applicable */
335
336/*semimpl.h*/   (sizeof _Semaphore_Information)           +
337
338#if defined(RTEMS_MULTIPROCESSING)
339/*semmp.h*/     0                                         +
340#endif
341
342/*signal.h*/    0                                         +
343
344/*signalmp.h*/  0                                         +
345
346/*stack.h*/     0                                         +
347
348/*states.h*/    0                                         +
349
350/*status.h*/    0                                         +
351
352/*sysstate.h*/  (sizeof _System_state_Current)            +
353#if defined(RTEMS_MULTIPROCESSING)
354                (sizeof _System_state_Is_multiprocessing) +
355#endif
356
357#if defined(RTEMS_MULTIPROCESSING)
358/*taskmp.h*/    0                                         +
359#endif
360
361/*tasksimpl.h*/ (sizeof _RTEMS_tasks_Information)         +
362
363/*thread.h*/    (sizeof _Thread_Dispatch_disable_level)   +
364                (sizeof _Thread_Executing)                +
365                (sizeof _Thread_Heir)                     +
366#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
367                (sizeof _Thread_Allocated_fp)             +
368#endif
369                (sizeof _Thread_Information)     +
370
371/*threadq.h*/
372
373/*timerimpl.h*/ (sizeof _Timer_Information)               +
374
375/*tqdata.h*/    0                                         +
376
377/*types.h*/     0                                         +
378
379/*userext.h*/   (sizeof _User_extensions_List)            +
380
381/*watchdog.h*/  (sizeof _Watchdog_Ticks_since_boot)       +
382
383/*wkspace.h*/   (sizeof _Workspace_Area);
384
385#ifndef unix  /* make sure this is not a native compile */
386
387#ifdef __i386__
388
389/* cpu.h */
390uninitialized += (sizeof _CPU_Null_fp_context);
391
392uninitialized += (sizeof _CPU_Interrupt_stack_low) +
393                 (sizeof _CPU_Interrupt_stack_high);
394
395#endif
396
397#ifdef __mc68000__
398
399/* cpu.h */
400uninitialized += (sizeof _CPU_Interrupt_stack_low) +
401                 (sizeof _CPU_Interrupt_stack_high);
402
403#endif
404
405#ifdef __sparc__
406
407/* cpu.h */
408uninitialized += (sizeof _CPU_Interrupt_stack_low) +
409                 (sizeof _CPU_Interrupt_stack_high);
410
411#endif
412
413
414#ifdef no_cpu
415
416/* cpu.h */
417uninitialized += (sizeof _CPU_Null_fp_context) +
418                 (sizeof _CPU_Interrupt_stack_low) +
419                 (sizeof _CPU_Interrupt_stack_high) +
420                 (sizeof _CPU_Thread_dispatch_pointer);
421
422#endif
423
424#ifdef __PPC__
425
426/* cpu.h */
427uninitialized += (sizeof _CPU_Interrupt_stack_low) +
428                 (sizeof _CPU_Interrupt_stack_high);
429
430#endif
431#endif /* !unix */
432
433initialized +=
434/*copyrt.h*/    (strlen(_Copyright_Notice)+1)             +
435                (strlen(_RTEMS_version)+1);
436
437
438
439#ifndef unix /* make sure this is not native */
440#ifdef __sparc__
441
442initialized +=  (sizeof _CPU_Trap_slot_template);
443
444#endif
445#endif /* !unix */
446
447puts( "" );
448
449  if ( mode == 0 ) help_size();
450  else             print_formula();
451
452printf( "\n" );
453printf( "RTEMS uninitialized data consumes %d bytes\n", uninitialized );
454printf( "RTEMS initialized data consumes %d bytes\n", initialized );
455
456}
457
458void help_size()
459{
460int c = '\0';
461int break_loop;
462int total_size;
463int task_stacks;
464int interrupt_stack;
465int maximum_tasks, size_tasks;
466int maximum_sems, size_sems;
467int maximum_timers, size_timers;
468int maximum_msgqs, size_msgqs;
469int maximum_msgs, size_msgs_overhead;
470int maximum_regns, size_regns;
471int maximum_parts, size_parts;
472int maximum_ports, size_ports;
473int maximum_periods, size_periods;
474int maximum_extensions, size_extensions;
475int maximum_drvs, size_drvs;
476int maximum_fps, size_fps;
477int maximum_nodes, size_nodes;
478int maximum_gobjs, size_gobjs;
479int maximum_proxies, size_proxies;
480
481total_size = sys_req;    /* Fixed Overhead */
482printf( "What is maximum_tasks? " );
483maximum_tasks = getint();
484size_tasks = PER_TASK * maximum_tasks;
485total_size += size_tasks;
486
487printf( "What is maximum_semaphores? " );
488maximum_sems = getint();
489size_sems = PER_SEMAPHORE * maximum_sems;
490total_size += size_sems;
491
492printf( "What is maximum_timers? " );
493maximum_timers = getint();
494size_timers = PER_TIMER * maximum_timers;
495total_size += size_timers;
496
497printf( "What is maximum_message_queues? " );
498maximum_msgqs = getint();
499size_msgqs = PER_MSGQ * maximum_msgqs;
500total_size += size_msgqs;
501
502printf( "What is maximum_messages?  XXXX " );
503maximum_msgs = getint();
504size_msgs_overhead = 0;
505total_size += size_msgs_overhead;
506
507printf( "What is maximum_regions? " );
508maximum_regns = getint();
509size_regns = PER_REGN * maximum_regns;
510total_size += size_regns;
511
512printf( "What is maximum_partitions? " );
513maximum_parts = getint();
514size_parts = PER_PART * maximum_parts;
515total_size += size_parts;
516
517printf( "What is maximum_ports? " );
518maximum_ports = getint();
519size_ports = PER_PORT * maximum_ports;
520total_size += size_ports;
521
522printf( "What is maximum_periods? " );
523maximum_periods = getint();
524size_periods = PER_PERIOD * maximum_periods;
525total_size += size_periods;
526
527printf( "What is maximum_extensions? " );
528maximum_extensions = getint();
529size_extensions = PER_EXTENSION * maximum_extensions;
530total_size += size_extensions;
531
532printf( "What is number_of_device_drivers? " );
533maximum_drvs = getint();
534size_drvs = PER_DRV  * maximum_drvs;
535total_size += size_drvs;
536
537printf( "What will be total stack requirement for all tasks? " );
538task_stacks = getint();
539total_size += task_stacks;
540
541printf( "What is the size of the interrupt stack? " );
542interrupt_stack = getint();
543total_size += interrupt_stack;
544
545printf( "How many tasks will be created with the FP flag? " );
546maximum_fps = getint();
547size_fps = PER_FPTASK  * maximum_fps;
548total_size += size_fps;
549
550printf( "Is this a single processor system? " );
551for ( break_loop=0 ; !break_loop; c = getchar() ) {
552  switch ( c ) {
553    case 'Y':  case 'y':
554    case 'N':  case 'n':
555      break_loop = 1;
556      break;
557  }
558}
559printf( "%c\n", c );
560if ( c == 'n' || c == 'N' ) {
561  printf( "What is maximum_nodes? " );
562  maximum_nodes = getint();
563  size_nodes = PER_NODE * maximum_nodes;
564  total_size += size_nodes;
565  printf( "What is maximum_global_objects? " );
566  maximum_gobjs = getint();
567  size_gobjs = PER_GOBJECT * maximum_gobjs;
568  total_size += size_gobjs;
569  printf( "What is maximum_proxies? " );
570  maximum_proxies = getint();
571  size_proxies = PER_PROXY * maximum_proxies;
572  total_size += size_proxies;
573} else {
574  maximum_nodes = 0;
575  size_nodes = PER_NODE * 0;
576  maximum_gobjs = 0;
577  size_gobjs = PER_GOBJECT * 0;
578  maximum_proxies = 0;
579  size_proxies = PER_PROXY * 0;
580}
581
582printf( "\n\n" );
583printf( " ************** EXECUTIVE WORK SPACE REQUIRED **************\n" );
584printf( " Tasks                - %03d * %03ld            =  %ld\n",
585          maximum_tasks, PER_TASK, (long) size_tasks );
586printf( " Semaphores           - %03d * %03ld            =  %ld\n",
587          maximum_sems, PER_SEMAPHORE, (long) size_sems );
588printf( " Timers               - %03d * %03ld            =  %ld\n",
589          maximum_timers, PER_TIMER, (long) size_timers );
590printf( " Msg Queues           - %03d * %03ld            =  %ld\n",
591          maximum_msgqs, PER_MSGQ, (long) size_msgqs );
592printf( " Messages Overhead    - %03d * %03d            =  %ld\n",
593          maximum_msgs, 0 /* PER_MSG_OVERHEAD */, (long) size_msgs_overhead );
594printf( " Regions              - %03d * %03ld            =  %ld\n",
595          maximum_regns, PER_REGN, (long) size_regns);
596printf( " Partitions           - %03d * %03ld            =  %ld\n",
597          maximum_parts, PER_PART, (long) size_parts );
598printf( " Periods              - %03d * %03ld            =  %ld\n",
599          maximum_periods, PER_PERIOD, (long) size_periods );
600printf( " Extensions           - %03d * %03ld            =  %ld\n",
601          maximum_extensions, PER_EXTENSION, (long) size_extensions );
602printf( " Device Drivers       - %03d * %03ld            =  %ld\n",
603          maximum_drvs, PER_DRV, (long) size_drvs );
604
605printf( " System Requirements  - %04" PRIu32 "                 =  %"PRIu32 "\n",
606          sys_req, sys_req );
607
608printf( " Floating Point Tasks - %03d * %03ld            =  %ld\n",
609          maximum_fps, PER_FPTASK, (long) size_fps );
610printf( " Application Task Stacks -                     =  %d\n",
611          task_stacks );
612printf( " Interrupt Stacks -                            =  %d\n",
613          task_stacks );
614printf( " \n" );
615printf( " Global object tables - %03d * %03ld            =  %ld\n",
616          maximum_nodes, PER_NODE, (long) size_nodes );
617printf( " Global objects       - %03d * %03ld            =  %ld\n",
618          maximum_gobjs, PER_GOBJECT, (long) size_gobjs );
619printf( " Proxies              - %03d * %03ld            =  %ld\n",
620          maximum_proxies, PER_PROXY, (long) size_proxies );
621printf( "\n\n" );
622printf( " TOTAL                                       = %d bytes\n",
623      total_size );
624}
625
626void print_formula()
627{
628printf( " ************** EXECUTIVE WORK SPACE FORMULA **************\n" );
629printf( " Tasks                - maximum_tasks * %ld\n",      PER_TASK );
630printf( " Timers               - maximum_timers * %ld\n",     PER_TIMER );
631printf( " Semaphores           - maximum_semaphores * %ld\n", PER_SEMAPHORE);
632printf( " Message Queues       - maximum_message_queues * %ld\n", PER_MSGQ );
633printf( " Messages             -\n");
634printf( " Regions              - maximum_regions * %ld\n",    PER_REGN );
635printf( " Partitions           - maximum_partitions * %ld\n", PER_PART );
636printf( " Ports                - maximum_ports * %ld\n",      PER_PORT );
637printf( " Periods              - maximum_periods * %ld\n",    PER_PORT );
638printf( " Extensions           - maximum_extensions * %ld\n", PER_EXTENSION );
639printf( " Device Drivers       - number_of_device_drivers * %ld\n", PER_DRV);
640printf( " System Requirements  - %" PRIu32 "\n",              sys_req );
641printf( " Floating Point Tasks - FPMASK Tasks * %ld\n",       PER_FPTASK );
642printf( " User's Tasks' Stacks -\n" );
643printf( " Interrupt Stack      -\n" );
644printf( " \n" );
645printf( " Global object tables - maximum_nodes * %ld\n",          PER_NODE );
646printf( " Global objects       - maximum_global_objects * %ld\n", PER_GOBJECT );
647printf( " Proxies              - maximum_proxies * %ld\n",        PER_PROXY );
648}
Note: See TracBrowser for help on using the repository browser.