source: rtems/cpukit/posix/src/pthreadsetschedprio.c @ eec08ef

5
Last change on this file since eec08ef was eec08ef, checked in by Sebastian Huber <sebastian.huber@…>, on 06/15/16 at 04:59:57

posix: Rework sporadic server scheduling policy

Instead of lowering the priority in case the initial budget is consumed
raise the priority for each new period. Restore the normal priority
once the initial budget is consumed. This makes it later easier to
combine the high priority phase with temporary priority boosts (e.g. via
priority ceiling and inheritance).

Use the thread lock to protect the POSIX thread attributes instead of
the thread state lock. This makes it easier to change the thread
priority and keep the POSIX attributes consistent.

Fixes a false positive use of uninitialized variable warning.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#if HAVE_CONFIG_H
10#include "config.h"
11#endif
12
13#include <pthread.h>
14#include <errno.h>
15
16#include <rtems/posix/priorityimpl.h>
17#include <rtems/posix/threadsup.h>
18#include <rtems/score/threadimpl.h>
19
20typedef struct {
21  int prio;
22  int error;
23} POSIX_Set_sched_prio_context;
24
25static bool _POSIX_Set_sched_prio_filter(
26  Thread_Control   *the_thread,
27  Priority_Control *new_priority_p,
28  void             *arg
29)
30{
31  POSIX_Set_sched_prio_context *context;
32  int                           prio;
33  POSIX_API_Control            *api;
34  Priority_Control              current_priority;
35  Priority_Control              new_priority;
36
37  context = arg;
38  prio = context->prio;
39
40  if ( !_POSIX_Priority_Is_valid( prio ) ) {
41    context->error = EINVAL;
42    return false;
43  }
44
45  new_priority = _POSIX_Priority_To_core( prio );
46  *new_priority_p = new_priority;
47
48  current_priority = the_thread->current_priority;
49  the_thread->real_priority = new_priority;
50
51  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
52
53  api->Sporadic.high_priority = new_priority;
54
55  if ( api->Sporadic.low_priority < new_priority ) {
56    api->Sporadic.low_priority  = new_priority;
57  }
58
59  context->error = 0;
60  return _Thread_Priority_less_than( current_priority, new_priority )
61    || !_Thread_Owns_resources( the_thread );
62}
63
64int pthread_setschedprio( pthread_t thread, int prio )
65{
66  Thread_Control               *the_thread;
67  Per_CPU_Control              *cpu_self;
68  POSIX_Set_sched_prio_context  context;
69  ISR_lock_Context              lock_context;
70
71  context.prio = prio;
72
73  the_thread = _Thread_Get( thread, &lock_context );
74
75  if ( the_thread == NULL ) {
76    return ESRCH;
77  }
78
79  cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
80  _ISR_lock_ISR_enable( &lock_context );
81
82  _Thread_Change_priority(
83    the_thread,
84    0,
85    &context,
86    _POSIX_Set_sched_prio_filter,
87    true
88  );
89
90  _Thread_Dispatch_enable( cpu_self );
91  return context.error;
92}
Note: See TracBrowser for help on using the repository browser.