[PATCH 1/3] score: Add flexible per-CPU data

2018-09-07 Thread Sebastian Huber
Update #3507.
---
 cpukit/headers.am  |   1 +
 cpukit/include/rtems/score/percpu.h|   9 +-
 cpukit/include/rtems/score/percpudata.h| 104 
 cpukit/score/src/wkspace.c | 128 +++--
 testsuites/sptests/Makefile.am |   9 +
 testsuites/sptests/configure.ac|   1 +
 testsuites/sptests/sppercpudata01/init.c   | 290 +
 testsuites/sptests/sppercpudata01/item.c   |  21 ++
 .../sptests/sppercpudata01/sppercpudata01.doc  |  13 +
 testsuites/sptests/sppercpudata01/sppercpudata01.h |  30 +++
 .../sptests/sppercpudata01/sppercpudata01.scn  |   7 +
 11 files changed, 591 insertions(+), 22 deletions(-)
 create mode 100644 cpukit/include/rtems/score/percpudata.h
 create mode 100644 testsuites/sptests/sppercpudata01/init.c
 create mode 100644 testsuites/sptests/sppercpudata01/item.c
 create mode 100644 testsuites/sptests/sppercpudata01/sppercpudata01.doc
 create mode 100644 testsuites/sptests/sppercpudata01/sppercpudata01.h
 create mode 100644 testsuites/sptests/sppercpudata01/sppercpudata01.scn

diff --git a/cpukit/headers.am b/cpukit/headers.am
index 303dbc58a7..a848690e3a 100644
--- a/cpukit/headers.am
+++ b/cpukit/headers.am
@@ -375,6 +375,7 @@ include_rtems_score_HEADERS += 
include/rtems/score/objectimpl.h
 include_rtems_score_HEADERS += include/rtems/score/objectmp.h
 include_rtems_score_HEADERS += include/rtems/score/onceimpl.h
 include_rtems_score_HEADERS += include/rtems/score/percpu.h
+include_rtems_score_HEADERS += include/rtems/score/percpudata.h
 include_rtems_score_HEADERS += include/rtems/score/priority.h
 include_rtems_score_HEADERS += include/rtems/score/prioritybitmap.h
 include_rtems_score_HEADERS += include/rtems/score/prioritybitmapimpl.h
diff --git a/cpukit/include/rtems/score/percpu.h 
b/cpukit/include/rtems/score/percpu.h
index f0b155d4c1..712d1cde36 100644
--- a/cpukit/include/rtems/score/percpu.h
+++ b/cpukit/include/rtems/score/percpu.h
@@ -9,7 +9,7 @@
  *  COPYRIGHT (c) 1989-2011.
  *  On-Line Applications Research Corporation (OAR).
  *
- *  Copyright (c) 2012, 2016 embedded brains GmbH
+ *  Copyright (c) 2012, 2018 embedded brains GmbH
  *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
@@ -477,6 +477,13 @@ typedef struct Per_CPU_Control {
 } Scheduler;
 
 /**
+ * @brief Begin of the per-CPU data area.
+ *
+ * Contains items defined via PER_CPU_DATA_ITEM().
+ */
+char *data;
+
+/**
  * @brief Indicates the current state of the CPU.
  *
  * This field is protected by the _Per_CPU_State_lock lock.
diff --git a/cpukit/include/rtems/score/percpudata.h 
b/cpukit/include/rtems/score/percpudata.h
new file mode 100644
index 00..3de99566ad
--- /dev/null
+++ b/cpukit/include/rtems/score/percpudata.h
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _RTEMS_SCORE_PERCPUDATA_H
+#define _RTEMS_SCORE_PERCPUDATA_H
+
+#include 
+#include 
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup PerCPUData Flexible Per-CPU Data
+ *
+ * @ingroup PerCPU
+ *
+ * Provides the definition of custom per-CPU items.  The items are collected in
+ * a special linker set.  During system initialization the content of the
+ * linker set is duplicated for all secondary processors using memory allocated
+ * from the workspace.  The begin and end of the per-CPU data area is cache
+ * line aligned (CPU_CACHE_LINE_BYTES).
+ *
+ * @{
+ */
+
+RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char );
+
+/**
+ * @brief Declares a per-CPU item of the specified type.
+ *
+ * Items declared with this macro have external linkage.
+ *
+ * @param type The type of the item.
+ * @param item The designator of the item.
+ */
+#define PER_CPU_DATA_ITEM_DECLARE( type, item ) \
+  RTEMS_LINKER_RWSET_ITEM_DECLARE( _Per_CPU_Data, type, item )
+
+/**
+ * @brief Defines a per-CPU item of the specified type.
+ *
+ * @param type The type of the item.
+ * @param item The designator of the item.
+ */
+#define PER_CPU_DATA_ITEM( type, item ) \
+  RTEMS_LINKER_RWSET_ITEM( _Per_CPU_Data, type, item )
+
+/**
+ * @brief Returns the offset of the per-CPU item to the begin of the per-CPU
+ * data area.
+ *
+ * @param item The designator of the item.
+ */
+#define PER_CPU_DATA_OFFSET( item ) \
+  ( (uintptr_t) &_Linker_set__Per_CPU_Data_##item \
+- (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) )
+
+/**
+ * @brief Returns a pointer of the specified type to the per-CPU item at the
+ * specified offset for the specified processor.
+ *
+ * @pa

[PATCH 2/3] score: Modify _Scheduler_Unblock()

2018-09-07 Thread Sebastian Huber
In SMP configurations, obtain the scheduler node for the block and
unblock operations through the same way via
Thread_Control::Scheduler::Scheduler_node.  This symmetry is important
in a follow up patch which introduces thread pinning.

Update #3508.
---
 cpukit/include/rtems/score/schedulerimpl.h | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/cpukit/include/rtems/score/schedulerimpl.h 
b/cpukit/include/rtems/score/schedulerimpl.h
index 10c12242a9..2fe30b3d6b 100644
--- a/cpukit/include/rtems/score/schedulerimpl.h
+++ b/cpukit/include/rtems/score/schedulerimpl.h
@@ -299,16 +299,22 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Block( 
Thread_Control *the_thread )
  */
 RTEMS_INLINE_ROUTINE void _Scheduler_Unblock( Thread_Control *the_thread )
 {
+  Scheduler_Node  *scheduler_node;
   const Scheduler_Control *scheduler;
   ISR_lock_Context lock_context;
 
+#if defined(RTEMS_SMP)
+  scheduler_node = SCHEDULER_NODE_OF_THREAD_SCHEDULER_NODE(
+_Chain_First( &the_thread->Scheduler.Scheduler_nodes )
+  );
+  scheduler = _Scheduler_Node_get_scheduler( scheduler_node );
+#else
+  scheduler_node = _Thread_Scheduler_get_home_node( the_thread );
   scheduler = _Thread_Scheduler_get_home( the_thread );
+#endif
+
   _Scheduler_Acquire_critical( scheduler, &lock_context );
-  ( *scheduler->Operations.unblock )(
-scheduler,
-the_thread,
-_Thread_Scheduler_get_home_node( the_thread )
-  );
+  ( *scheduler->Operations.unblock )( scheduler, the_thread, scheduler_node );
   _Scheduler_Release_critical( scheduler, &lock_context );
 }
 
-- 
2.13.7

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 3/3] score: Add thread pin/unpin support

2018-09-07 Thread Sebastian Huber
Add support to temporarily pin a thread to its current processor.  This
may be used to access per-processor data structures in critical sections
with enabled thread dispatching, e.g. a pinned thread is allowed to
block.

Update #3508.
---
 cpukit/include/rtems/score/scheduler.h |  48 ++
 cpukit/include/rtems/score/scheduleredfsmp.h   |  33 +-
 cpukit/include/rtems/score/schedulerimpl.h |  20 +-
 .../rtems/score/schedulerpriorityaffinitysmp.h |   2 +
 cpukit/include/rtems/score/schedulerprioritysmp.h  |   4 +-
 cpukit/include/rtems/score/schedulersimplesmp.h|   4 +-
 cpukit/include/rtems/score/schedulersmpimpl.h  |   1 +
 cpukit/include/rtems/score/schedulerstrongapa.h|   4 +-
 cpukit/include/rtems/score/smpimpl.h   |   3 +-
 cpukit/include/rtems/score/thread.h|  43 +-
 cpukit/include/rtems/score/threadimpl.h|  52 +-
 cpukit/rtems/src/scheduleraddprocessor.c   |   2 +-
 cpukit/score/Makefile.am   |   2 +
 cpukit/score/src/schedulerdefaultpinunpin.c|  35 ++
 cpukit/score/src/scheduleredfsmp.c |  96 +++-
 cpukit/score/src/threaddispatch.c  |  93 +++-
 cpukit/score/src/threadinitialize.c|   2 +-
 cpukit/score/src/threadunpin.c |  72 +++
 testsuites/smptests/Makefile.am|  11 +
 testsuites/smptests/configure.ac   |   1 +
 testsuites/smptests/smpthreadpin01/init.c  | 620 +
 .../smptests/smpthreadpin01/smpthreadpin01.doc |  12 +
 .../smptests/smpthreadpin01/smpthreadpin01.scn |   7 +
 23 files changed, 1114 insertions(+), 53 deletions(-)
 create mode 100644 cpukit/score/src/schedulerdefaultpinunpin.c
 create mode 100644 cpukit/score/src/threadunpin.c
 create mode 100644 testsuites/smptests/smpthreadpin01/init.c
 create mode 100644 testsuites/smptests/smpthreadpin01/smpthreadpin01.doc
 create mode 100644 testsuites/smptests/smpthreadpin01/smpthreadpin01.scn

diff --git a/cpukit/include/rtems/score/scheduler.h 
b/cpukit/include/rtems/score/scheduler.h
index a6066c8e4a..fe6315daef 100644
--- a/cpukit/include/rtems/score/scheduler.h
+++ b/cpukit/include/rtems/score/scheduler.h
@@ -137,6 +137,36 @@ typedef struct {
   );
 
   /**
+   * @brief Pin thread operation.
+   *
+   * @param[in] scheduler The scheduler instance of the specified processor.
+   * @param[in] the_thread The thread to pin.
+   * @param[in] node The scheduler node of the thread.
+   * @param[in] cpu The processor to pin the thread.
+   */
+  void ( *pin )(
+const Scheduler_Control *scheduler,
+Thread_Control  *the_thread,
+Scheduler_Node  *node,
+struct Per_CPU_Control  *cpu
+  );
+
+  /**
+   * @brief Unpin thread operation.
+   *
+   * @param[in] scheduler The scheduler instance of the specified processor.
+   * @param[in] the_thread The thread to unpin.
+   * @param[in] node The scheduler node of the thread.
+   * @param[in] cpu The processor to unpin the thread.
+   */
+  void ( *unpin )(
+const Scheduler_Control *scheduler,
+Thread_Control  *the_thread,
+Scheduler_Node  *node,
+struct Per_CPU_Control  *cpu
+  );
+
+  /**
* @brief Add processor operation.
*
* @param[in] scheduler The scheduler instance to add the processor.
@@ -405,10 +435,28 @@ Priority_Control _Scheduler_default_Unmap_priority(
 Thread_Scheduler_state   next_state
   );
 
+  /**
+   * @brief Does nothing in a single processor system, otherwise a fatal error
+   * is issued.
+   *
+   * @param[in] scheduler Unused.
+   * @param[in] the_thread Unused.
+   * @param[in] node Unused.
+   * @param[in] cpu Unused.
+   */
+  void _Scheduler_default_Pin_or_unpin(
+const Scheduler_Control *scheduler,
+Thread_Control  *the_thread,
+Scheduler_Node  *node,
+struct Per_CPU_Control  *cpu
+  );
+
   #define SCHEDULER_OPERATION_DEFAULT_ASK_FOR_HELP \
 _Scheduler_default_Ask_for_help, \
 _Scheduler_default_Reconsider_help_request, \
 _Scheduler_default_Withdraw_node, \
+_Scheduler_default_Pin_or_unpin, \
+_Scheduler_default_Pin_or_unpin, \
 NULL, \
 NULL,
 #else
diff --git a/cpukit/include/rtems/score/scheduleredfsmp.h 
b/cpukit/include/rtems/score/scheduleredfsmp.h
index 018568190e..72c906eefe 100644
--- a/cpukit/include/rtems/score/scheduleredfsmp.h
+++ b/cpukit/include/rtems/score/scheduleredfsmp.h
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2017 embedded brains GmbH.
+ * Copyright (c) 2017, 2018 embedded brains GmbH.
  *
  * The license and distribution terms for this file may be
  * found in the file LICENSE in this distribution or at
@@ -43,13 +43,24 @@ typedef struct {
   int64_t generation;
 
   /**
-   * @brief The ready queue index depending on the processor affinity of the 
thread.
+   * @brief The ready queue index depending on the processor affinity and
+   * pinning of the thread.
*
 

[PATCH 1/2] c-user: Mention per-processor data

2018-09-07 Thread Sebastian Huber
Close #3507.
---
 c-user/symmetric_multiprocessing_services.rst | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/c-user/symmetric_multiprocessing_services.rst 
b/c-user/symmetric_multiprocessing_services.rst
index 638292b..4204d3f 100644
--- a/c-user/symmetric_multiprocessing_services.rst
+++ b/c-user/symmetric_multiprocessing_services.rst
@@ -791,3 +791,21 @@ from the executing to the heir thread neither the stack of 
the executing nor
 the heir thread must be used during interrupt processing.  For this purpose a
 temporary per-processor stack is set up which may be used by the interrupt
 prologue before the stack is switched to the interrupt stack.
+
+Per-Processor Data
+--
+
+RTMES provides two means for per-processor data:
+
+1. Per-processor data which used by RTEMS itself is contained in the
+   `Per_CPU_Control` structure.  The application configuration via
+   `` creates a table of these structures
+   (`_Per_CPU_Information[]`).  The table is dimensioned according to the count
+   of configured processors
+   (:ref:`CONFIGURE_MAXIMUM_PROCESSORS `).
+
+2. For low level support libraries an API for statically allocated
+   per-processor data is available via
+   ` 
`_.
+   This API is not intended for general application use.  Please ask on the
+   development mailing list in case you want to use it.
-- 
2.13.7

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/2] c-user: Mention thread pinning

2018-09-07 Thread Sebastian Huber
Close #3508.
---
 c-user/symmetric_multiprocessing_services.rst | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/c-user/symmetric_multiprocessing_services.rst 
b/c-user/symmetric_multiprocessing_services.rst
index 4204d3f..4c80cb9 100644
--- a/c-user/symmetric_multiprocessing_services.rst
+++ b/c-user/symmetric_multiprocessing_services.rst
@@ -809,3 +809,21 @@ RTMES provides two means for per-processor data:
` 
`_.
This API is not intended for general application use.  Please ask on the
development mailing list in case you want to use it.
+
+Thread Pinning
+--
+
+Thread pinning may be used to access per-processor data structures in critical
+sections with enabled thread dispatching, e.g. a pinned thread is allowed to
+block.  The `_Thread_Pin()` operation will pin the executing thread to its
+current processor.  A thread may be pinned recursively, the last unpin request
+via `_Thread_Unpin()` revokes the pinning.
+
+Thread pinning should be used only for short critical sections and not all
+the time.  Thread pinning is a very low overhead operation in case the
+thread is not preempted during the pinning.  A preemption will result in
+scheduler operations to ensure that the thread executes only on its pinned
+processor.  Thread pinning must be used with care, since it prevents help
+through the locking protocols.  This makes the :ref:`OMIP ` and
+:ref:`MrsP ` locking protocols ineffective if pinned threads are
+involved.
-- 
2.13.7

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: rtems-bsp-builder .ini file syntax question (for epiphany)

2018-09-07 Thread Joel Sherrill
On Thu, Sep 6, 2018 at 9:07 PM Chris Johns  wrote:

> On 6/9/18 9:00 am, Joel Sherrill wrote:
> > https://lists.rtems.org/pipermail/build/2018-September/000997.html
> still has
> > epiphany
> > failures. Not sure what else is going on. Do you see the pattern?
>
> The 'debug' build is not adding '--disable-networking' as the BSP builder
> is not
> tracking defaults or more specifically enabled by default. The SMP works
> because
> the default is disabled while networking has a default of enabled.
>

Yes. That's clearly the problem. Any ideas on how to address this? I can
always
force networking off for epiphany in the cpukit. We were talking about that
anyway.
Would it be better if exclude implied --disable?

>
> Chris
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: rtems-bsp-builder .ini file syntax question (for epiphany)

2018-09-07 Thread Chris Johns
On 8/9/18 12:59 am, Joel Sherrill wrote:
> On Thu, Sep 6, 2018 at 9:07 PM Chris Johns  > wrote:
> On 6/9/18 9:00 am, Joel Sherrill wrote:
> > https://lists.rtems.org/pipermail/build/2018-September/000997.html 
> still has
> > epiphany
> > failures. Not sure what else is going on. Do you see the pattern?
> 
> The 'debug' build is not adding '--disable-networking' as the BSP builder 
> is not
> tracking defaults or more specifically enabled by default. The SMP works 
> because
> the default is disabled while networking has a default of enabled.
> 
> Yes. That's clearly the problem. Any ideas on how to address this? I can 
> always
> force networking off for epiphany in the cpukit. We were talking about that 
> anyway.
> Would it be better if exclude implied --disable?

The solution is add the excluded 'no-' variant of the 'config' to the 'base'
flags. The code currently removes the excluded builds from the build list, code
needs to be added to update the base flags.

A consequence of this is the need for me to handle the excludes better and
report any errors if not correct. Currently the support is not strict to make
the code simpler.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: rtems-bsp-builder .ini file syntax question (for epiphany)

2018-09-07 Thread Joel Sherrill
On Fri, Sep 7, 2018, 10:06 PM Chris Johns  wrote:

> On 8/9/18 12:59 am, Joel Sherrill wrote:
> > On Thu, Sep 6, 2018 at 9:07 PM Chris Johns  > > wrote:
> > On 6/9/18 9:00 am, Joel Sherrill wrote:
> > > https://lists.rtems.org/pipermail/build/2018-September/000997.html
> still has
> > > epiphany
> > > failures. Not sure what else is going on. Do you see the pattern?
> >
> > The 'debug' build is not adding '--disable-networking' as the BSP
> builder is not
> > tracking defaults or more specifically enabled by default. The SMP
> works because
> > the default is disabled while networking has a default of enabled.
> >
> > Yes. That's clearly the problem. Any ideas on how to address this? I can
> always
> > force networking off for epiphany in the cpukit. We were talking about
> that anyway.
> > Would it be better if exclude implied --disable?
>
> The solution is add the excluded 'no-' variant of the 'config' to the
> 'base'
> flags. The code currently removes the excluded builds from the build list,
> code
> needs to be added to update the base flags.
>

What's the syntax for that? Or am I making a new features request?

>
> A consequence of this is the need for me to handle the excludes better and
> report any errors if not correct. Currently the support is not strict to
> make
> the code simpler.
>

Glad to hear it is your fault. Lol

Just joking. Rather peeved that Internet is out at my house and so far
Monday 8-10 is their solution. My laptop connected directly to the cable
modem isn't a stable connection. Down varies and up is non-existent.

--joel

>
> Chris
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: rtems-bsp-builder .ini file syntax question (for epiphany)

2018-09-07 Thread Chris Johns
On 8/9/18 1:12 pm, Joel Sherrill wrote:
> On Fri, Sep 7, 2018, 10:06 PM Chris Johns  > wrote:
> 
> The solution is add the excluded 'no-' variant of the 'config' to the 
> 'base'
> flags. The code currently removes the excluded builds from the build 
> list, code
> needs to be added to update the base flags.
> 
> 
> What's the syntax for that? Or am I making a new features request?

Just code changes.

> 
> A consequence of this is the need for me to handle the excludes better and
> report any errors if not correct. Currently the support is not strict to 
> make
> the code simpler.
> 
> 
> Glad to hear it is your fault. Lol
> 

Haha I seem to be the only committer so I suspect most problems will be mine.

> Just joking.

Yeah yeah go on kick someone when they are down with the flue! ;)

> Rather peeved that Internet is out at my house and so far Monday
> 8-10 is their solution. My laptop connected directly to the cable modem isn't 
> a
> stable connection. Down varies and up is non-existent.

That is a bit sad, I suppose you will have time to do all those chores around
the house now.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: rtems-bsp-builder .ini file syntax question (for epiphany)

2018-09-07 Thread Chris Johns
On 8/9/18 1:23 pm, Chris Johns wrote:
> On 8/9/18 1:12 pm, Joel Sherrill wrote:
>> On Fri, Sep 7, 2018, 10:06 PM Chris Johns > > wrote:
>>
>> The solution is add the excluded 'no-' variant of the 'config' to the 
>> 'base'
>> flags. The code currently removes the excluded builds from the build 
>> list, code
>> needs to be added to update the base flags.
>>
>>
>> What's the syntax for that? Or am I making a new features request?
> 
> Just code changes.
> 

I have pushed a change. Please let me know how you go.

Thanks
Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel