[rtems commit] score: Fix PER_CPU_DATA_GET_BY_OFFSET()
Sebastian Huber
sebh at rtems.org
Mon Sep 10 10:03:30 UTC 2018
Module: rtems
Branch: master
Commit: 1fe1b820de02c274c2b2b3431340152734ee9fb6
Changeset: http://git.rtems.org/rtems/commit/?id=1fe1b820de02c274c2b2b3431340152734ee9fb6
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Sep 10 11:47:24 2018 +0200
score: Fix PER_CPU_DATA_GET_BY_OFFSET()
Add uniprocessor version for PER_CPU_DATA_GET_BY_OFFSET(). Fix warnings
in uniprocessor configurations.
Update #3507.
---
cpukit/include/rtems/score/percpudata.h | 8 +++++++-
testsuites/sptests/sppercpudata01/init.c | 10 ++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/cpukit/include/rtems/score/percpudata.h b/cpukit/include/rtems/score/percpudata.h
index 3de9956..fe29fd9 100644
--- a/cpukit/include/rtems/score/percpudata.h
+++ b/cpukit/include/rtems/score/percpudata.h
@@ -76,8 +76,14 @@ RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char );
* @param type The type of the item.
* @param offset The offset of the item.
*/
+#ifdef RTEMS_SMP
#define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \
(type *) ( cpu->data + offset )
+#else
+#define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \
+ (type *) ( (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) + offset ), \
+ (void) cpu
+#endif
/**
* @brief Returns a pointer of the specified type to the specified per-CPU item
@@ -92,7 +98,7 @@ RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char );
PER_CPU_DATA_GET_BY_OFFSET( cpu, type, PER_CPU_DATA_OFFSET( item ) )
#else
#define PER_CPU_DATA_GET( cpu, type, item ) \
- &_Linker_set__Per_CPU_Data_##item
+ &_Linker_set__Per_CPU_Data_##item, (void) cpu
#endif
/** @} */
diff --git a/testsuites/sptests/sppercpudata01/init.c b/testsuites/sptests/sppercpudata01/init.c
index 4c20ea7..94f5185 100644
--- a/testsuites/sptests/sppercpudata01/init.c
+++ b/testsuites/sptests/sppercpudata01/init.c
@@ -74,11 +74,16 @@ static void test_initial_values(void)
unsigned short *s;
unsigned int *i;
unsigned long *l;
+ uintptr_t off;
t *pt;
set_affinity(cpu_index);
cpu = _Per_CPU_Get_by_index(cpu_index);
+ off = PER_CPU_DATA_OFFSET(c);
+ c = PER_CPU_DATA_GET_BY_OFFSET(cpu, unsigned char, off);
+ rtems_test_assert(*c == 1);
+
c = PER_CPU_DATA_GET(cpu, unsigned char, c);
rtems_test_assert(*c == 1);
@@ -197,6 +202,7 @@ static void test_unique_values(unsigned int v)
unsigned short *s;
unsigned int *i;
unsigned long *l;
+ uintptr_t off;
t *pt;
set_affinity(cpu_index);
@@ -206,6 +212,10 @@ static void test_unique_values(unsigned int v)
++v;
rtems_test_assert(*c == (unsigned char) v);
+ off = PER_CPU_DATA_OFFSET(c);
+ c = PER_CPU_DATA_GET_BY_OFFSET(cpu, unsigned char, off);
+ rtems_test_assert(*c == (unsigned char) v);
+
c = PER_CPU_DATA_GET(cpu, unsigned char, cz);
++v;
rtems_test_assert(*c == (unsigned char) v);
More information about the vc
mailing list