[rtems commit] score: Allocate per-CPU data only if necessary

Sebastian Huber sebh at rtems.org
Wed Sep 19 09:58:11 UTC 2018


Module:    rtems
Branch:    master
Commit:    776464aad46cd317b9707870acc5f6be5531e15a
Changeset: http://git.rtems.org/rtems/commit/?id=776464aad46cd317b9707870acc5f6be5531e15a

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Sep 19 11:52:47 2018 +0200

score: Allocate per-CPU data only if necessary

The _Workspace_Allocate_aligned() would returns a non-NULL pointer for a
zero size allocation request if there is enough memory available.  This
conflicts with the size estimate of zero in
_Workspace_Space_for_per_CPU_data() if the per-CPU data set is empty.

Update #3507.

---

 cpukit/score/src/wkspace.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/cpukit/score/src/wkspace.c b/cpukit/score/src/wkspace.c
index 823e357..ea2ab84 100644
--- a/cpukit/score/src/wkspace.c
+++ b/cpukit/score/src/wkspace.c
@@ -129,22 +129,26 @@ static uintptr_t _Workspace_Space_for_per_CPU_data( uintptr_t page_size )
 static void _Workspace_Allocate_per_CPU_data( void )
 {
 #ifdef RTEMS_SMP
-  Per_CPU_Control *cpu;
-  uintptr_t        size;
-  uint32_t         cpu_index;
-  uint32_t         cpu_max;
-
-  cpu = _Per_CPU_Get_by_index( 0 );
-  cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data );
+  uintptr_t size;
 
   size = RTEMS_LINKER_SET_SIZE( _Per_CPU_Data );
-  cpu_max = rtems_configuration_get_maximum_processors();
 
-  for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) {
-    cpu = _Per_CPU_Get_by_index( cpu_index );
-    cpu->data = _Workspace_Allocate_aligned( size, CPU_CACHE_LINE_BYTES );
-    _Assert( cpu->data != NULL );
-    memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size);
+  if ( size > 0 ) {
+    Per_CPU_Control *cpu;
+    uint32_t         cpu_index;
+    uint32_t         cpu_max;
+
+    cpu = _Per_CPU_Get_by_index( 0 );
+    cpu->data = RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data );
+
+    cpu_max = rtems_configuration_get_maximum_processors();
+
+    for ( cpu_index = 1 ; cpu_index < cpu_max ; ++cpu_index ) {
+      cpu = _Per_CPU_Get_by_index( cpu_index );
+      cpu->data = _Workspace_Allocate_aligned( size, CPU_CACHE_LINE_BYTES );
+      _Assert( cpu->data != NULL );
+      memcpy( cpu->data, RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ), size);
+    }
   }
 #endif
 }



More information about the vc mailing list