source: rtems/cpukit/score/src/schedulercbsunblock.c @ 2369b10

4.115
Last change on this file since 2369b10 was beab7329, checked in by Sebastian Huber <sebastian.huber@…>, on 05/13/14 at 14:03:05

score: Introduce scheduler nodes

Rename scheduler per-thread information into scheduler nodes using
Scheduler_Node as the base type. Use inheritance for specialized
schedulers.

Move the scheduler specific states from the thread control block into
the scheduler node structure.

Validate the SMP scheduler node state transitions in case RTEMS_DEBUG is
defined.

  • 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/schedulerimpl.h>
24#include <rtems/score/threadimpl.h>
25#include <rtems/score/watchdogimpl.h>
26
27void _Scheduler_CBS_Unblock(
28  const Scheduler_Control *scheduler,
29  Thread_Control          *the_thread
30)
31{
32  Scheduler_CBS_Node   *node = _Scheduler_CBS_Node_get( the_thread );
33  Scheduler_CBS_Server *serv_info = node->cbs_server;
34  Priority_Control      new_priority;
35
36  _Scheduler_EDF_Enqueue( scheduler, the_thread );
37  /* TODO: flash critical section? */
38
39  /*
40   * Late unblock rule for deadline-driven tasks. The remaining time to
41   * deadline must be sufficient to serve the remaining computation time
42   * without increased utilization of this task. It might cause a deadline
43   * miss of another task.
44   */
45  if (serv_info) {
46    time_t deadline = serv_info->parameters.deadline;
47    time_t budget = serv_info->parameters.budget;
48    time_t deadline_left = the_thread->cpu_time_budget;
49    time_t budget_left = the_thread->real_priority -
50                           _Watchdog_Ticks_since_boot;
51
52    if ( deadline*budget_left > budget*deadline_left ) {
53      /* Put late unblocked task to background until the end of period. */
54      new_priority = the_thread->Start.initial_priority;
55      if ( the_thread->real_priority != new_priority )
56        the_thread->real_priority = new_priority;
57      if ( the_thread->current_priority != new_priority )
58        _Thread_Change_priority(the_thread, new_priority, true);
59    }
60  }
61
62  /*
63   *  If the thread that was unblocked is more important than the heir,
64   *  then we have a new heir.  This may or may not result in a
65   *  context switch.
66   *
67   *  Normal case:
68   *    If the current thread is preemptible, then we need to do
69   *    a context switch.
70   *  Pseudo-ISR case:
71   *    Even if the thread isn't preemptible, if the new heir is
72   *    a pseudo-ISR system task, we need to do a context switch.
73   */
74  if (
75    _Scheduler_Is_priority_higher_than(
76       scheduler,
77       the_thread->current_priority,
78       _Thread_Heir->current_priority
79    )
80  ) {
81    _Thread_Heir = the_thread;
82    if ( _Thread_Executing->is_preemptible ||
83         the_thread->current_priority == 0 )
84      _Thread_Dispatch_necessary = true;
85  }
86}
Note: See TracBrowser for help on using the repository browser.