source: rtems/cpukit/score/src/schedulercbsunblock.c @ 25f5730f

4.115
Last change on this file since 25f5730f was f39f667a, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/14 at 11:50:48

score: Simplify _Thread_Change_priority()

The function to change a thread priority was too complex. Simplify it
with a new scheduler operation. This increases the average case
performance due to the simplified logic. The interrupt disabled
critical section is a bit prolonged since now the extract, update and
enqueue steps are executed atomically. This should however not impact
the worst-case interrupt latency since at least for the Deterministic
Priority Scheduler this sequence can be carried out with a wee bit of
instructions and no loops.

Add _Scheduler_Change_priority() to replace the sequence of

  • _Thread_Set_transient(),
  • _Scheduler_Extract(),
  • _Scheduler_Enqueue(), and
  • _Scheduler_Enqueue_first().

Delete STATES_TRANSIENT, _States_Is_transient() and
_Thread_Set_transient() since this state is now superfluous.

With this change it is possible to get rid of the
SCHEDULER_SMP_NODE_IN_THE_AIR state. This considerably simplifies the
implementation of the new SMP locking protocols.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Unblocks a Thread from the Queue
5 *
6 * @ingroup ScoreScheduler
7 */
8
9/*
10 *  Copyright (C) 2011 Petr Benes.
11 *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/schedulercbsimpl.h>
23#include <rtems/score/scheduleredfimpl.h>
24#include <rtems/score/schedulerimpl.h>
25#include <rtems/score/threadimpl.h>
26#include <rtems/score/watchdogimpl.h>
27
28void _Scheduler_CBS_Unblock(
29  const Scheduler_Control *scheduler,
30  Thread_Control          *the_thread
31)
32{
33  Scheduler_CBS_Node   *node = _Scheduler_CBS_Node_get( the_thread );
34  Scheduler_CBS_Server *serv_info = node->cbs_server;
35  Priority_Control      new_priority;
36
37  _Scheduler_EDF_Enqueue( scheduler, the_thread );
38  /* TODO: flash critical section? */
39
40  /*
41   * Late unblock rule for deadline-driven tasks. The remaining time to
42   * deadline must be sufficient to serve the remaining computation time
43   * without increased utilization of this task. It might cause a deadline
44   * miss of another task.
45   */
46  if (serv_info) {
47    time_t deadline = serv_info->parameters.deadline;
48    time_t budget = serv_info->parameters.budget;
49    time_t deadline_left = the_thread->cpu_time_budget;
50    time_t budget_left = the_thread->real_priority -
51                           _Watchdog_Ticks_since_boot;
52
53    if ( deadline*budget_left > budget*deadline_left ) {
54      /* Put late unblocked task to background until the end of period. */
55      new_priority = the_thread->Start.initial_priority;
56      if ( the_thread->real_priority != new_priority )
57        the_thread->real_priority = new_priority;
58      if ( the_thread->current_priority != new_priority )
59        _Thread_Change_priority(the_thread, new_priority, true);
60    }
61  }
62
63  /*
64   *  If the thread that was unblocked is more important than the heir,
65   *  then we have a new heir.  This may or may not result in a
66   *  context switch.
67   *
68   *  Normal case:
69   *    If the current thread is preemptible, then we need to do
70   *    a context switch.
71   *  Pseudo-ISR case:
72   *    Even if the thread isn't preemptible, if the new heir is
73   *    a pseudo-ISR system task, we need to do a context switch.
74   */
75  if (
76    _Scheduler_Is_priority_higher_than(
77       scheduler,
78       the_thread->current_priority,
79       _Thread_Heir->current_priority
80    )
81  ) {
82    _Thread_Heir = the_thread;
83    if ( _Thread_Executing->is_preemptible ||
84         the_thread->current_priority == 0 )
85      _Thread_Dispatch_necessary = true;
86  }
87}
Note: See TracBrowser for help on using the repository browser.