source: rtems/cpukit/rtems/src/semsetpriority.c @ 8fcafdd5

4.115
Last change on this file since 8fcafdd5 was 8fcafdd5, checked in by Sebastian Huber <sebastian.huber@…>, on 05/21/14 at 08:33:43

score: Multiprocessor Resource Sharing Protocol

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.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/rtems/semimpl.h>
20#include <rtems/rtems/attrimpl.h>
21#include <rtems/rtems/tasksimpl.h>
22#include <rtems/score/schedulerimpl.h>
23
24static rtems_status_code _Semaphore_Set_priority(
25  Semaphore_Control   *the_semaphore,
26  rtems_id             scheduler_id,
27  rtems_task_priority  new_priority,
28  rtems_task_priority *old_priority_p
29)
30{
31  rtems_status_code   sc;
32  rtems_attribute     attribute_set = the_semaphore->attribute_set;
33  rtems_task_priority old_priority;
34
35  new_priority = _RTEMS_tasks_Priority_to_Core( new_priority );
36
37#if defined(RTEMS_SMP)
38  if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) {
39    MRSP_Control *mrsp = &the_semaphore->Core_control.mrsp;
40    uint32_t scheduler_index = _Scheduler_Get_index_by_id( scheduler_id );
41
42    old_priority = _MRSP_Get_ceiling_priority( mrsp, scheduler_index );
43
44    if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
45      _MRSP_Set_ceiling_priority( mrsp, scheduler_index, new_priority );
46    }
47
48    sc = RTEMS_SUCCESSFUL;
49  } else
50#endif
51  if ( _Attributes_Is_priority_ceiling( attribute_set ) ) {
52    CORE_mutex_Control *mutex = &the_semaphore->Core_control.mutex;
53
54    old_priority = mutex->Attributes.priority_ceiling;
55
56    if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
57      mutex->Attributes.priority_ceiling = new_priority;
58    }
59
60    sc = RTEMS_SUCCESSFUL;
61  } else {
62    old_priority = 0;
63
64    sc = RTEMS_NOT_DEFINED;
65  }
66
67  *old_priority_p = _RTEMS_tasks_Priority_from_Core( old_priority );
68
69  _Objects_Put( &the_semaphore->Object );
70
71  return sc;
72}
73
74rtems_status_code rtems_semaphore_set_priority(
75  rtems_id             semaphore_id,
76  rtems_id             scheduler_id,
77  rtems_task_priority  new_priority,
78  rtems_task_priority *old_priority
79)
80{
81  Semaphore_Control *the_semaphore;
82  Objects_Locations  location;
83
84  if ( new_priority != RTEMS_CURRENT_PRIORITY &&
85       !_RTEMS_tasks_Priority_is_valid( new_priority ) ) {
86    return RTEMS_INVALID_PRIORITY;
87  }
88
89  if ( old_priority == NULL ) {
90    return RTEMS_INVALID_ADDRESS;
91  }
92
93  if ( !_Scheduler_Is_id_valid( scheduler_id ) ) {
94    return RTEMS_INVALID_ID;
95  }
96
97  the_semaphore = _Semaphore_Get( semaphore_id, &location );
98  switch ( location ) {
99    case OBJECTS_LOCAL:
100      return _Semaphore_Set_priority(
101        the_semaphore,
102        scheduler_id,
103        new_priority,
104        old_priority
105      );
106#if defined(RTEMS_MULTIPROCESSING)
107    case OBJECTS_REMOTE:
108      _Thread_Dispatch();
109      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
110#endif
111    case OBJECTS_ERROR:
112      break;
113  }
114
115  return RTEMS_INVALID_ID;
116}
Note: See TracBrowser for help on using the repository browser.