[PATCH] score: Multiprocessor Resource Sharing Protocol

Gedare Bloom gedare at rtems.org
Wed May 21 14:53:25 UTC 2014


On Wed, May 21, 2014 at 8:09 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
> Add basic support for the Multiprocessor Resource Sharing Protocol
> (MrsP).
>
> The Multiprocessor Resource Sharing Protocol (MrsP) is defined in A.
> Burns and A.J.  Wellings, A Schedulability Compatible Multiprocessor
> Resource Sharing Protocol - MrsP, Proceedings of the 25th Euromicro
> Conference on Real-Time Systems (ECRTS 2013), July 2013.  It is a
> generalization of the Priority Ceiling Protocol to SMP systems.  Each
> MrsP semaphore uses a ceiling priority per scheduler instance.  These
> ceiling priorities can be specified with rtems_semaphore_set_priority().
> A task obtaining or owning a MrsP semaphore will execute with the
> ceiling priority for its scheduler instance as specified by the MrsP
> semaphore object.  Tasks waiting to get ownership of a MrsP semaphore
> will not relinquish the processor voluntarily.  In case the owner of a
> MrsP semaphore gets preempted it can ask all tasks waiting for this
> semaphore to help out and temporarily borrow the right to execute on one
> of their assigned processors.
>
> The help out feature is not implemented with this patch.
> ---
>  cpukit/rtems/Makefile.am                         |    1 +
>  cpukit/rtems/include/rtems/rtems/attr.h          |   14 +
>  cpukit/rtems/include/rtems/rtems/attrimpl.h      |   31 ++
>  cpukit/rtems/include/rtems/rtems/sem.h           |   46 +++
>  cpukit/rtems/include/rtems/rtems/semimpl.h       |    9 +
>  cpukit/rtems/src/semcreate.c                     |   38 ++-
>  cpukit/rtems/src/semdelete.c                     |   21 +-
>  cpukit/rtems/src/semflush.c                      |    7 +-
>  cpukit/rtems/src/semobtain.c                     |   19 +-
>  cpukit/rtems/src/semrelease.c                    |   14 +-
>  cpukit/rtems/src/semsetpriority.c                |  116 +++++++
>  cpukit/sapi/include/confdefs.h                   |   14 +-
>  cpukit/score/Makefile.am                         |    2 +
>  cpukit/score/include/rtems/score/mrsp.h          |  135 ++++++++
>  cpukit/score/include/rtems/score/mrspimpl.h      |  301 +++++++++++++++++
>  cpukit/score/include/rtems/score/schedulerimpl.h |   10 +
>  cpukit/score/preinstall.am                       |    8 +
>  doc/user/Makefile.am                             |    2 +-
>  doc/user/conf.t                                  |   32 ++
>  doc/user/sem.t                                   |  198 +++++++++++-
>  testsuites/smptests/Makefile.am                  |    1 +
>  testsuites/smptests/configure.ac                 |    1 +
>  testsuites/smptests/smpmrsp01/Makefile.am        |   19 ++
>  testsuites/smptests/smpmrsp01/init.c             |  287 +++++++++++++++++
>  testsuites/smptests/smpmrsp01/smpmrsp01.doc      |   15 +
>  testsuites/smptests/smpmrsp01/smpmrsp01.scn      |    2 +
>  testsuites/sptests/Makefile.am                   |    1 +
>  testsuites/sptests/configure.ac                  |    1 +
>  testsuites/sptests/spmrsp01/Makefile.am          |   19 ++
>  testsuites/sptests/spmrsp01/init.c               |  374 ++++++++++++++++++++++
>  testsuites/sptests/spmrsp01/spmrsp01.doc         |   13 +
>  testsuites/sptests/spmrsp01/spmrsp01.scn         |    8 +
>  32 files changed, 1743 insertions(+), 16 deletions(-)
>  create mode 100644 cpukit/rtems/src/semsetpriority.c
>  create mode 100644 cpukit/score/include/rtems/score/mrsp.h
>  create mode 100644 cpukit/score/include/rtems/score/mrspimpl.h
>  create mode 100644 testsuites/smptests/smpmrsp01/Makefile.am
>  create mode 100644 testsuites/smptests/smpmrsp01/init.c
>  create mode 100644 testsuites/smptests/smpmrsp01/smpmrsp01.doc
>  create mode 100644 testsuites/smptests/smpmrsp01/smpmrsp01.scn
>  create mode 100644 testsuites/sptests/spmrsp01/Makefile.am
>  create mode 100644 testsuites/sptests/spmrsp01/init.c
>  create mode 100644 testsuites/sptests/spmrsp01/spmrsp01.doc
>  create mode 100644 testsuites/sptests/spmrsp01/spmrsp01.scn

[...]

> diff --git a/cpukit/rtems/src/semflush.c b/cpukit/rtems/src/semflush.c
> index f73c929..e818d68 100644
> --- a/cpukit/rtems/src/semflush.c
> +++ b/cpukit/rtems/src/semflush.c
> @@ -43,12 +43,17 @@ rtems_status_code rtems_semaphore_flush(
>  {
>    Semaphore_Control          *the_semaphore;
>    Objects_Locations           location;
> +  rtems_attribute             attribute_set;
>
>    the_semaphore = _Semaphore_Get( id, &location );
>    switch ( location ) {
>
>      case OBJECTS_LOCAL:
> -      if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) {
> +      attribute_set = the_semaphore->attribute_set;
> +      if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
> +        _Objects_Put( &the_semaphore->Object );
> +        return RTEMS_NOT_DEFINED;
> +      } else if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) {
>          _CORE_mutex_Flush(
>            &the_semaphore->Core_control.mutex,
>            SEND_OBJECT_WAS_DELETED,
Need #if defined(RTEMS_SMP)...#endif here.

> diff --git a/cpukit/rtems/src/semsetpriority.c b/cpukit/rtems/src/semsetpriority.c
> new file mode 100644
> index 0000000..bb3a688
> --- /dev/null
> +++ b/cpukit/rtems/src/semsetpriority.c
> @@ -0,0 +1,116 @@
> +/*
> + * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
> + *
> + *  embedded brains GmbH
> + *  Dornierstr. 4
> + *  82178 Puchheim
> + *  Germany
> + *  <rtems at embedded-brains.de>
> + *
> + * 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.
> + */
> +
> +#if HAVE_CONFIG_H
> +  #include "config.h"
> +#endif
> +
> +#include <rtems/rtems/semimpl.h>
> +#include <rtems/rtems/attrimpl.h>
> +#include <rtems/rtems/tasksimpl.h>
> +#include <rtems/score/schedulerimpl.h>
> +
> +static rtems_status_code _Semaphore_Set_priorities(
Minor nit, should this be named _Semaphore_Set_priority()?

> diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
> index 1c97d15..f3e5127 100644
> --- a/cpukit/sapi/include/confdefs.h
> +++ b/cpukit/sapi/include/confdefs.h
> @@ -1792,6 +1792,17 @@ const rtems_libio_helper rtems_fs_init_helper =
>        CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \
>        CONFIGURE_NETWORKING_SEMAPHORES)
>
> +  #if !defined(RTEMS_SMP) || \
> +    !defined(CONFIGURE_MAXIMUM_MULTIPROCESSOR_RESOURCE_SHARING_SEMAPHORES)
Can this be CONFIGURE_MAXIMUM_MRSP_SEMAPHORES?


> diff --git a/cpukit/score/include/rtems/score/mrsp.h b/cpukit/score/include/rtems/score/mrsp.h
> new file mode 100644
> index 0000000..4a790d4
> --- /dev/null
> +++ b/cpukit/score/include/rtems/score/mrsp.h
> @@ -0,0 +1,135 @@
> +/*
> + * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
> + *
> + *  embedded brains GmbH
> + *  Dornierstr. 4
> + *  82178 Puchheim
> + *  Germany
> + *  <rtems at embedded-brains.de>
> + *
> + * 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_MRSP_H
> +#define _RTEMS_SCORE_MRSP_H
> +
> +#include <rtems/score/cpuopts.h>
> +
> +#if defined(RTEMS_SMP)
> +
> +#include <rtems/score/atomic.h>
> +#include <rtems/score/chain.h>
> +#include <rtems/score/scheduler.h>
> +#include <rtems/score/thread.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif /* __cplusplus */
> +
> +/**
> + * @defgroup ScoreMRSP Multiprocessor Resource Sharing Protocol Handler
> + *
> + * @ingroup Score
> + *
> + * @brief Multiprocessor Resource Sharing Protocol (MrsP).
> + *
> + * The Multiprocessor Resource Sharing Protocol (MrsP) is defined in A.  Burns
> + * and A.J.  Wellings, A Schedulability Compatible Multiprocessor Resource
> + * Sharing Protocol - MrsP, Proceedings of the 25th Euromicro Conference on
> + * Real-Time Systems (ECRTS 2013), July 2013.  It is a generalization of the
> + * Priority Ceiling Protocol to SMP systems.  Each MrsP semaphore uses a
> + * ceiling priority per scheduler instance.  A task obtaining or owning a MrsP
> + * semaphore will execute with the ceiling priority for its scheduler instance
> + * as specified by the MrsP semaphore object.  Tasks waiting to get ownership
> + * of a MrsP semaphore will not relinquish the processor voluntarily.  In case
> + * the owner of a MrsP semaphore gets preempted it can ask all tasks waiting
> + * for this semaphore to help out and temporarily borrow the right to execute
> + * on one of their assigned processors.
> + *
> + * @{
> + */
> +
> +/**
> + * @brief MRSP status code.
> + *
> + * The values are chosen to directly map to RTEMS status codes.  In case this
> + * implementation is used for other APIs, then for example the errno values can
> + * be added with a bit shift.
> + */
> +typedef enum {
> +  MRSP_SUCCESSFUL = 0,
> +  MRSP_TIMEOUT = 6,
> +  MRSP_RESOUCE_IN_USE = 12,
> +  MRSP_UNSATISFIED = 13,
> +  MRSP_INVALID_PRIORITY = 19,
> +  MRSP_NOT_OWNER_OF_RESOURCE = 23,
> +  MRSP_NO_MEMORY = 26
> +} MRSP_Status;
> +
> +/**
> + * @brief MRSP rival.
> + *
> + * The rivals are used by threads waiting for resource ownership.  They are
> + * registered in the MRSP control block.
> + */
> +typedef struct {
> +  /**
> +   * @brief The node for registration in the MRSP rival chain.
> +   */
> +  Chain_Node Node;
> +
> +  /**
> +   * @brief Identification of the rival thread.
> +   */
> +  Thread_Control *thread;
> +
> +  /**
> +   * @brief The rival state.
> +   *
> +   * Initially no state bits are set.  The rival will busy wait until a state
> +   * change happens.  This an be MRSP_RIVAL_STATE_NEW_OWNER or
"This an be" -> "This can be"

> diff --git a/cpukit/score/include/rtems/score/mrspimpl.h b/cpukit/score/include/rtems/score/mrspimpl.h
> new file mode 100644
> index 0000000..7adb88f
> --- /dev/null
> +++ b/cpukit/score/include/rtems/score/mrspimpl.h
> @@ -0,0 +1,301 @@
> +/*
> + * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
> + *
> + *  embedded brains GmbH
> + *  Dornierstr. 4
> + *  82178 Puchheim
> + *  Germany
> + *  <rtems at embedded-brains.de>
> + *
> + * 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_MRSPIMPL_H
> +#define _RTEMS_SCORE_MRSPIMPL_H
> +
> +#include <rtems/score/mrsp.h>
> +
> +#if defined(RTEMS_SMP)
> +
> +#include <rtems/score/assert.h>
> +#include <rtems/score/chainimpl.h>
> +#include <rtems/score/schedulerimpl.h>
> +#include <rtems/score/watchdogimpl.h>
> +#include <rtems/score/wkspace.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif /* __cplusplus */
> +
> +/**
> + * @addtogroup ScoreMRSP
> + *
> + * @{
> + */
> +
> +#define MRSP_RIVAL_STATE_NEW_OWNER 0x1U
> +
> +#define MRSP_RIVAL_STATE_TIMEOUT 0x2U
> +
Does it make sense to have MRSP_RIVAL_STATE_WAITING 0x0? Also, the
functions in this file could use some doxygen.


> diff --git a/doc/user/Makefile.am b/doc/user/Makefile.am
> index ef91a41..e774319 100644
> --- a/doc/user/Makefile.am
> +++ b/doc/user/Makefile.am
> @@ -96,7 +96,7 @@ sem.texi: sem.t
>             -n "Barrier Manager" < $< > $@
>
>  barrier.texi: barrier.t
> -       $(BMENU2) -p "Semaphore Manager SEMAPHORE_FLUSH - Unblock all tasks waiting on a semaphore" \
> +       $(BMENU2) -p "Semaphore Manager SEMAPHORE_SET_PRIORITY - Set priority by scheduler for a semaphore" \
This should probably say "Set ceiling priority by scheduler"

-Gedare



More information about the devel mailing list