source: rtems/cpukit/include/rtems/confdefs/wkspace.h @ f2185d10

Last change on this file since f2185d10 was f2185d10, checked in by Sebastian Huber <sebastian.huber@…>, on 09/30/20 at 09:31:58

Decouple the C Program Heap initialization

Before this patch RTEMS_Malloc_Initialize() had a fixed dependency on
_Workspace_Area. Introduce _Workspace_Malloc_initializer to have this
dependency only if CONFIGURE_UNIFIED_WORK_AREAS is defined by the
application configuration.

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSApplicationConfiguration
7 *
8 * @brief Evaluate Workspace Configuration Options
9 */
10
11/*
12 * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_CONFDEFS_WKSPACE_H
37#define _RTEMS_CONFDEFS_WKSPACE_H
38
39#ifndef __CONFIGURATION_TEMPLATE_h
40#error "Do not include this file directly, use <rtems/confdefs.h> instead"
41#endif
42
43#ifdef CONFIGURE_INIT
44
45#include <rtems/confdefs/bdbuf.h>
46#include <rtems/confdefs/inittask.h>
47#include <rtems/confdefs/initthread.h>
48#include <rtems/confdefs/objectsposix.h>
49#include <rtems/confdefs/threads.h>
50#include <rtems/confdefs/wkspacesupport.h>
51#include <rtems/score/coremsg.h>
52#include <rtems/score/context.h>
53#include <rtems/score/memory.h>
54#include <rtems/score/stack.h>
55#include <rtems/sysinit.h>
56
57#ifdef CONFIGURE_TASK_STACK_FROM_ALLOCATOR
58  #define _Configure_From_stackspace( _stack_size ) \
59    CONFIGURE_TASK_STACK_FROM_ALLOCATOR( _stack_size + CONTEXT_FP_SIZE )
60#else
61  #define _Configure_From_stackspace( _stack_size ) \
62    _Configure_From_workspace( _stack_size + CONTEXT_FP_SIZE )
63#endif
64
65#ifndef CONFIGURE_EXTRA_TASK_STACKS
66  #define CONFIGURE_EXTRA_TASK_STACKS 0
67#endif
68
69#ifndef CONFIGURE_EXECUTIVE_RAM_SIZE
70
71#define CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE( _messages, _size ) \
72  _Configure_From_workspace( \
73    ( _messages ) * ( _Configure_Align_up( _size, sizeof( uintptr_t ) ) \
74        + sizeof( CORE_message_queue_Buffer ) ) )
75
76#ifndef CONFIGURE_MESSAGE_BUFFER_MEMORY
77  #define CONFIGURE_MESSAGE_BUFFER_MEMORY 0
78#endif
79
80#ifndef CONFIGURE_MEMORY_OVERHEAD
81  #define CONFIGURE_MEMORY_OVERHEAD 0
82#endif
83
84/*
85 * We must be able to split the free block used for the second last allocation
86 * into two parts so that we have a free block for the last allocation.  See
87 * _Heap_Block_split().
88 */
89#define _CONFIGURE_HEAP_HANDLER_OVERHEAD \
90  _Configure_Align_up( HEAP_BLOCK_HEADER_SIZE, CPU_HEAP_ALIGNMENT )
91
92#define CONFIGURE_EXECUTIVE_RAM_SIZE \
93  ( _CONFIGURE_MEMORY_FOR_POSIX_OBJECTS \
94    + CONFIGURE_MESSAGE_BUFFER_MEMORY \
95    + 1024 * CONFIGURE_MEMORY_OVERHEAD \
96    + _CONFIGURE_HEAP_HANDLER_OVERHEAD )
97
98#define _CONFIGURE_STACK_SPACE_SIZE \
99  ( _CONFIGURE_INIT_TASK_STACK_EXTRA \
100    + _CONFIGURE_POSIX_INIT_THREAD_STACK_EXTRA \
101    + _CONFIGURE_LIBBLOCK_TASKS_STACK_EXTRA \
102    + CONFIGURE_EXTRA_TASK_STACKS \
103    + rtems_resource_maximum_per_allocation( \
104        _CONFIGURE_TASKS - CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE \
105      ) \
106      * _Configure_From_stackspace( CONFIGURE_MINIMUM_TASK_STACK_SIZE ) \
107    + rtems_resource_maximum_per_allocation( CONFIGURE_MAXIMUM_POSIX_THREADS ) \
108      * _Configure_From_stackspace( CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE ) \
109    + _CONFIGURE_HEAP_HANDLER_OVERHEAD )
110
111#else /* CONFIGURE_EXECUTIVE_RAM_SIZE */
112
113#if CONFIGURE_EXTRA_TASK_STACKS != 0
114  #error "CONFIGURE_EXECUTIVE_RAM_SIZE defined with request for CONFIGURE_EXTRA_TASK_STACKS"
115#endif
116
117#define _CONFIGURE_STACK_SPACE_SIZE 0
118
119#endif /* CONFIGURE_EXECUTIVE_RAM_SIZE */
120
121#ifdef __cplusplus
122extern "C" {
123#endif
124
125const uintptr_t _Workspace_Size = CONFIGURE_EXECUTIVE_RAM_SIZE;
126
127#ifdef CONFIGURE_UNIFIED_WORK_AREAS
128  const bool _Workspace_Is_unified = true;
129
130  struct Heap_Control *( * const _Workspace_Malloc_initializer )( void ) =
131    _Workspace_Malloc_initialize_unified;
132#endif
133
134uint32_t rtems_minimum_stack_size = CONFIGURE_MINIMUM_TASK_STACK_SIZE;
135
136const uintptr_t _Stack_Space_size = _CONFIGURE_STACK_SPACE_SIZE;
137
138#if defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
139  && defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
140  #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_AVOIDS_WORK_SPACE
141    const bool _Stack_Allocator_avoids_workspace = true;
142  #else
143    const bool _Stack_Allocator_avoids_workspace = false;
144  #endif
145
146  #ifdef CONFIGURE_TASK_STACK_ALLOCATOR_INIT
147    const Stack_Allocator_initialize _Stack_Allocator_initialize =
148      CONFIGURE_TASK_STACK_ALLOCATOR_INIT;
149  #else
150    const Stack_Allocator_initialize _Stack_Allocator_initialize = NULL;
151  #endif
152
153  const Stack_Allocator_allocate _Stack_Allocator_allocate =
154    CONFIGURE_TASK_STACK_ALLOCATOR;
155
156  const Stack_Allocator_free _Stack_Allocator_free =
157    CONFIGURE_TASK_STACK_DEALLOCATOR;
158
159  RTEMS_SYSINIT_ITEM(
160    _Stack_Allocator_do_initialize,
161    RTEMS_SYSINIT_DIRTY_MEMORY,
162    RTEMS_SYSINIT_ORDER_MIDDLE
163  );
164#elif defined(CONFIGURE_TASK_STACK_ALLOCATOR) \
165  || defined(CONFIGURE_TASK_STACK_DEALLOCATOR)
166  #error "CONFIGURE_TASK_STACK_ALLOCATOR and CONFIGURE_TASK_STACK_DEALLOCATOR must be both defined or both undefined"
167#endif
168
169#ifdef CONFIGURE_DIRTY_MEMORY
170  RTEMS_SYSINIT_ITEM(
171    _Memory_Dirty_free_areas,
172    RTEMS_SYSINIT_DIRTY_MEMORY,
173    RTEMS_SYSINIT_ORDER_MIDDLE
174  );
175#endif
176
177#ifdef CONFIGURE_ZERO_WORKSPACE_AUTOMATICALLY
178  const bool _Memory_Zero_before_use = true;
179
180  RTEMS_SYSINIT_ITEM(
181    _Memory_Zero_free_areas,
182    RTEMS_SYSINIT_ZERO_MEMORY,
183    RTEMS_SYSINIT_ORDER_MIDDLE
184  );
185#endif
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif /* CONFIGURE_INIT */
192
193#endif /* _RTEMS_CONFDEFS_WKSPACE_H */
Note: See TracBrowser for help on using the repository browser.