source: rtems/cpukit/include/rtems/score/wkspaceinitone.h @ 3d0620b

Last change on this file since 3d0620b was 3d0620b, checked in by Sebastian Huber <sebastian.huber@…>, on 04/08/20 at 14:54:34

score: Optimize Workspace Handler initialization

The BSPs provide memory for the workspace initialization via
_Memory_Get(). Most BSPs provide exactly one memory area. Only two
BSPs provide more than one memory area (arm/altera-cyclone-v and
bsps/powerpc/mpc55xxevb). Only if more than one memory area is
provided, there is a need to use _Heap_Extend(). Provide two
implementations to initialize the workspace handler and let the BSP
select one of the implementations based on the number of provided memory
areas. This gets rid of a dependency on _Heap_Extend(). It also avoids
dead code sections for most BSPs.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreWorkspace
7 *
8 * @brief This header file provides the implementation of
9 *   _Workspace_Initialize_for_one_area().
10 */
11
12/*
13 * Copyright (C) 2012, 2020 embedded brains GmbH (http://www.embedded-brains.de)
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_WKSPACEINITONE_H
38#define _RTEMS_SCORE_WKSPACEINITONE_H
39
40#include <rtems/score/wkspace.h>
41#include <rtems/score/assert.h>
42#include <rtems/score/heapimpl.h>
43#include <rtems/score/interr.h>
44#include <rtems/score/memory.h>
45#include <rtems/config.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * @ingroup RTEMSScoreWorkspace
53 *
54 * @brief Initializes the RTEMS Workspace with support for exactly one memory
55 *   area.
56 *
57 * This implementation should be used by BSPs which provide exactly one memory
58 * area via _Memory_Get() to implement _Workspace_Handler_initialization().
59 */
60RTEMS_INLINE_ROUTINE void _Workspace_Initialize_for_one_area( void )
61{
62  uintptr_t page_size;
63  uintptr_t wkspace_size;
64  uintptr_t wkspace_size_with_overhead;
65  uintptr_t available_size;
66
67  page_size = CPU_HEAP_ALIGNMENT;
68  wkspace_size = rtems_configuration_get_work_space_size();
69  wkspace_size_with_overhead = wkspace_size + _Heap_Area_overhead( page_size );
70
71  if ( wkspace_size < wkspace_size_with_overhead ) {
72    const Memory_Information *mem;
73    Memory_Area              *area;
74    uintptr_t                 free_size;
75    uintptr_t                 size;
76
77    mem = _Memory_Get();
78    _Assert( _Memory_Get_count( mem ) == 1 );
79
80    area = _Memory_Get_area( mem, 0 );
81    free_size = _Memory_Get_free_size( area );
82
83    if ( rtems_configuration_get_unified_work_area() ) {
84      size = free_size;
85    } else {
86      size = wkspace_size_with_overhead;
87    }
88
89    available_size = _Heap_Initialize(
90      &_Workspace_Area,
91      _Memory_Get_free_begin( area ),
92      size,
93      page_size
94    );
95
96    _Memory_Consume( area, size );
97  } else {
98    /* An unsigned integer overflow happened */
99    available_size = 0;
100  }
101
102  if ( wkspace_size > available_size ) {
103    _Internal_error( INTERNAL_ERROR_TOO_LITTLE_WORKSPACE );
104  }
105
106  _Heap_Protection_set_delayed_free_fraction( &_Workspace_Area, 1 );
107}
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif /* _RTEMS_SCORE_WKSPACEINITONE_H */
Note: See TracBrowser for help on using the repository browser.