Ticket #1895: pluggable_scheduler.diff

File pluggable_scheduler.diff, 14.1 KB (added by Petr Benes, on 08/11/11 at 13:28:33)

Pluggable scheduler priority_compare and release_job hooks

  • cpukit/rtems/src/ratemoncancel.c

    diff --git a/cpukit/rtems/src/ratemoncancel.c b/cpukit/rtems/src/ratemoncancel.c
    index 47776e2..1854d2a 100644
    a b rtems_status_code rtems_rate_monotonic_cancel( 
    5353      }
    5454      (void) _Watchdog_Remove( &the_period->Timer );
    5555      the_period->state = RATE_MONOTONIC_INACTIVE;
     56      _Scheduler_Release_job(the_period->owner, 0);
    5657      _Thread_Enable_dispatch();
    5758      return RTEMS_SUCCESSFUL;
    5859
  • cpukit/rtems/src/ratemondelete.c

    diff --git a/cpukit/rtems/src/ratemondelete.c b/cpukit/rtems/src/ratemondelete.c
    index 53dfa8d..b313667 100644
    a b rtems_status_code rtems_rate_monotonic_delete( 
    5151      (void) _Watchdog_Remove( &the_period->Timer );
    5252      the_period->state = RATE_MONOTONIC_INACTIVE;
    5353      _Rate_monotonic_Free( the_period );
     54      _Scheduler_Release_job(the_period->owner, 0);
    5455      _Thread_Enable_dispatch();
    5556      return RTEMS_SUCCESSFUL;
    5657
  • cpukit/rtems/src/ratemonperiod.c

    diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c
    index 037d1fd..f1d4102 100644
    a b void _Rate_monotonic_Initiate_statistics( 
    143143      _Timespec_Add_to( &the_period->cpu_usage_period_initiated, &ran );
    144144    }
    145145  #endif
     146
     147  _Scheduler_Release_job(the_period->owner, the_period->next_length);
    146148}
    147149
    148150void _Rate_monotonic_Update_statistics(
    rtems_status_code rtems_rate_monotonic_period( 
    282284      if ( the_period->state == RATE_MONOTONIC_INACTIVE ) {
    283285        _ISR_Enable( level );
    284286
     287        the_period->next_length = length;
     288
    285289        /*
    286290         *  Baseline statistics information for the beginning of a period.
    287291         */
    rtems_status_code rtems_rate_monotonic_period( 
    295299          NULL
    296300        );
    297301
    298         the_period->next_length = length;
    299 
    300302        _Watchdog_Insert_ticks( &the_period->Timer, length );
    301303        _Thread_Enable_dispatch();
    302304        return RTEMS_SUCCESSFUL;
    rtems_status_code rtems_rate_monotonic_period( 
    353355        the_period->next_length = length;
    354356
    355357        _Watchdog_Insert_ticks( &the_period->Timer, length );
     358        _Scheduler_Release_job(the_period->owner, the_period->next_length);
    356359        _Thread_Enable_dispatch();
    357360        return RTEMS_TIMEOUT;
    358361      }
  • cpukit/score/Makefile.am

    diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
    index c314c84..85e9caf 100644
    a b libscore_a_SOURCES += src/schedulerpriority.c \ 
    203203    src/schedulerpriorityenqueuefirst.c \
    204204    src/schedulerpriorityextract.c \
    205205    src/schedulerpriorityfree.c \
     206    src/schedulerpriorityprioritycompare.c \
     207    src/schedulerpriorityreleasejob.c \
    206208    src/schedulerpriorityschedule.c \
    207209    src/schedulerpriorityunblock.c \
    208210    src/schedulerpriorityupdate.c \
  • cpukit/score/include/rtems/score/scheduler.h

    diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
    index 19dcc06..1c22ed2 100644
    a b typedef struct { 
    7777  /** extract a thread from the ready set */
    7878  void ( *extract )(Thread_Control *);
    7979
     80  /**
     81   * Compares two priorities (returns 1 for higher priority, 0 for equal
     82   * and -1 for lower priority).
     83   */
     84  int ( *priority_compare )(Priority_Control, Priority_Control);
     85
     86  /** This routine is called upon release of a new job. */
     87  void ( *release_job ) (Thread_Control *, uint32_t);
     88
    8089  /** perform scheduler update actions required at each clock tick */
    8190  void ( *tick )(void);
     91
    8292} Scheduler_Operations;
    8393
    8494/**
    typedef struct { 
    107117extern Scheduler_Control  _Scheduler;
    108118
    109119/**
     120 * Macro testing whether @a p1 has lower priority than @a p2
     121 * in the intuitive sense of priority.
     122 */
     123#define _Scheduler_Is_priority_lower_than( _p1, _p2 ) \
     124  (_Scheduler_Priority_compare(_p1,_p2) == -1)
     125
     126/**
     127 * Macro testing whether @a p1 has higher priority than @a p2
     128 * in the intuitive sense of priority.
     129 */
     130#define _Scheduler_Is_priority_higher_than( _p1, _p2 ) \
     131  (_Scheduler_Priority_compare(_p1,_p2) == 1)
     132
     133/**
    110134 *  This routine initializes the scheduler to the policy chosen by the user
    111135 *  through confdefs, or to the priority scheduler with ready chains by
    112136 *  default.
  • cpukit/score/include/rtems/score/schedulerpriority.h

    diff --git a/cpukit/score/include/rtems/score/schedulerpriority.h b/cpukit/score/include/rtems/score/schedulerpriority.h
    index 7f6876d..2b062aa 100644
    a b extern "C" { 
    3838 */
    3939#define SCHEDULER_PRIORITY_ENTRY_POINTS \
    4040  { \
    41     _Scheduler_priority_Initialize,    /* initialize entry point */ \
    42     _Scheduler_priority_Schedule,      /* schedule entry point */ \
    43     _Scheduler_priority_Yield,         /* yield entry point */ \
    44     _Scheduler_priority_Block,         /* block entry point */ \
    45     _Scheduler_priority_Unblock,       /* unblock entry point */ \
    46     _Scheduler_priority_Allocate,      /* allocate entry point */ \
    47     _Scheduler_priority_Free,          /* free entry point */ \
    48     _Scheduler_priority_Update,        /* update entry point */ \
    49     _Scheduler_priority_Enqueue,       /* enqueue entry point */ \
    50     _Scheduler_priority_Enqueue_first, /* enqueue_first entry point */ \
    51     _Scheduler_priority_Extract,       /* extract entry point */ \
    52     _Scheduler_priority_Tick           /* tick entry point */ \
     41    _Scheduler_priority_Initialize,       /* initialize entry point */ \
     42    _Scheduler_priority_Schedule,         /* schedule entry point */ \
     43    _Scheduler_priority_Yield,            /* yield entry point */ \
     44    _Scheduler_priority_Block,            /* block entry point */ \
     45    _Scheduler_priority_Unblock,          /* unblock entry point */ \
     46    _Scheduler_priority_Allocate,         /* allocate entry point */ \
     47    _Scheduler_priority_Free,             /* free entry point */ \
     48    _Scheduler_priority_Update,           /* update entry point */ \
     49    _Scheduler_priority_Enqueue,          /* enqueue entry point */ \
     50    _Scheduler_priority_Enqueue_first,    /* enqueue_first entry point */ \
     51    _Scheduler_priority_Extract,          /* extract entry point */ \
     52    _Scheduler_priority_Priority_compare, /* compares two priorities */ \
     53    _Scheduler_priority_Release_job,      /* new period of task */ \
     54    _Scheduler_priority_Tick              /* tick entry point */ \
    5355  }
    5456
    5557/**
    void _Scheduler_priority_Extract( 
    172174);
    173175
    174176/**
     177 *  @brief Scheduler priority Priority compare
     178 *
     179 *  This routine compares two priorities.
     180 */
     181int _Scheduler_priority_Priority_compare(
     182  Priority_Control      p1,
     183  Priority_Control      p2
     184);
     185
     186/**
     187 *  @brief Scheduler priority Release job
     188 *
     189 *  This routine is called when a new job of task is released.
     190 *
     191 *  @param[in] the_thread is the owner of the job.
     192 *  @param[in] deadline of the new job from now. If equal to 0,
     193 *             the job was cancelled or deleted.
     194 */
     195void _Scheduler_priority_Release_job (
     196  Thread_Control  *the_thread,
     197  uint32_t         deadline
     198);
     199
     200/**
    175201 *  @brief Deterministic Priority Scheduler Tick Method
    176202 *
    177203 *  This routine is invoked as part of processing each clock tick.
  • cpukit/score/include/rtems/score/schedulersimple.h

    diff --git a/cpukit/score/include/rtems/score/schedulersimple.h b/cpukit/score/include/rtems/score/schedulersimple.h
    index e95385e..83e95a1 100644
    a b extern "C" { 
    3535 */
    3636#define SCHEDULER_SIMPLE_ENTRY_POINTS \
    3737  { \
    38     _Scheduler_simple_Initialize,    /* initialize entry point */ \
    39     _Scheduler_simple_Schedule,      /* schedule entry point */ \
    40     _Scheduler_simple_Yield,         /* yield entry point */ \
    41     _Scheduler_simple_Block,         /* block entry point */ \
    42     _Scheduler_simple_Unblock,       /* unblock entry point */ \
    43     _Scheduler_simple_Allocate,      /* allocate entry point */ \
    44     _Scheduler_simple_Free,          /* free entry point */ \
    45     _Scheduler_simple_Update,        /* update entry point */ \
    46     _Scheduler_simple_Enqueue,       /* enqueue entry point */ \
    47     _Scheduler_simple_Enqueue_first, /* enqueue_first entry point */ \
    48     _Scheduler_simple_Extract,       /* extract entry point */ \
    49     _Scheduler_priority_Tick         /* tick entry point */ \
     38    _Scheduler_simple_Initialize,         /* initialize entry point */ \
     39    _Scheduler_simple_Schedule,           /* schedule entry point */ \
     40    _Scheduler_simple_Yield,              /* yield entry point */ \
     41    _Scheduler_simple_Block,              /* block entry point */ \
     42    _Scheduler_simple_Unblock,            /* unblock entry point */ \
     43    _Scheduler_simple_Allocate,           /* allocate entry point */ \
     44    _Scheduler_simple_Free,               /* free entry point */ \
     45    _Scheduler_simple_Update,             /* update entry point */ \
     46    _Scheduler_simple_Enqueue,            /* enqueue entry point */ \
     47    _Scheduler_simple_Enqueue_first,      /* enqueue_first entry point */ \
     48    _Scheduler_simple_Extract,            /* extract entry point */ \
     49    _Scheduler_priority_Priority_compare, /* compares two priorities */ \
     50    _Scheduler_priority_Release_job,      /* new period of task */ \
     51    _Scheduler_priority_Tick              /* tick entry point */ \
    5052  }
    5153
    5254/**
  • cpukit/score/include/rtems/score/schedulersimplesmp.h

    diff --git a/cpukit/score/include/rtems/score/schedulersimplesmp.h b/cpukit/score/include/rtems/score/schedulersimplesmp.h
    index 74424dc..fd36cf0 100644
    a b extern "C" { 
    4040
    4141#include <rtems/score/scheduler.h>
    4242#include <rtems/score/schedulersimple.h>
     43#include <rtems/score/schedulerpriority.h>
    4344
    4445/**
    4546 *  Entry points for Scheduler Simple SMP
    4647 */
    4748#define SCHEDULER_SIMPLE_SMP_ENTRY_POINTS \
    4849  { \
    49     _Scheduler_simple_Initialize,    /* initialize entry point */ \
    50     _Scheduler_simple_smp_Schedule,  /* schedule entry point */ \
    51     _Scheduler_simple_Yield,         /* yield entry point */ \
    52     _Scheduler_simple_smp_Block,     /* block entry point */ \
    53     _Scheduler_simple_smp_Unblock,   /* unblock entry point */ \
    54     _Scheduler_simple_Allocate,      /* allocate entry point */ \
    55     _Scheduler_simple_Free,          /* free entry point */ \
    56     _Scheduler_simple_Update,        /* update entry point */ \
    57     _Scheduler_simple_Enqueue,       /* enqueue entry point */ \
    58     _Scheduler_simple_Enqueue_first, /* enqueue_first entry point */ \
    59     _Scheduler_simple_Extract,       /* extract entry point */ \
    60     _Scheduler_simple_smp_Tick       /* tick entry point */ \
     50    _Scheduler_simple_Initialize,         /* initialize entry point */ \
     51    _Scheduler_simple_smp_Schedule,       /* schedule entry point */ \
     52    _Scheduler_simple_Yield,              /* yield entry point */ \
     53    _Scheduler_simple_smp_Block,          /* block entry point */ \
     54    _Scheduler_simple_smp_Unblock,        /* unblock entry point */ \
     55    _Scheduler_simple_Allocate,           /* allocate entry point */ \
     56    _Scheduler_simple_Free,               /* free entry point */ \
     57    _Scheduler_simple_Update,             /* update entry point */ \
     58    _Scheduler_simple_Enqueue,            /* enqueue entry point */ \
     59    _Scheduler_simple_Enqueue_first,      /* enqueue_first entry point */ \
     60    _Scheduler_simple_Extract,            /* extract entry point */ \
     61    _Scheduler_priority_Priority_compare, /* compares two priorities */ \
     62    _Scheduler_priority_Release_job,      /* new period of task */ \
     63    _Scheduler_simple_smp_Tick            /* tick entry point */ \
    6164  }
    6265
    6366/**
  • cpukit/score/inline/rtems/score/scheduler.inl

    diff --git a/cpukit/score/inline/rtems/score/scheduler.inl b/cpukit/score/inline/rtems/score/scheduler.inl
    index 0bd3dc7..36c99c7 100644
    a b RTEMS_INLINE_ROUTINE void _Scheduler_Extract( 
    159159  _Scheduler.Operations.extract( the_thread );
    160160}
    161161
     162/**
     163 * @brief Scheduler Priority compare
     164 *
     165 * This routine compares two priorities.
     166 */
     167RTEMS_INLINE_ROUTINE int _Scheduler_Priority_compare(
     168  Priority_Control p1,
     169  Priority_Control p2
     170)
     171{
     172  return _Scheduler.Operations.priority_compare(p1, p2);
     173}
     174
     175/**
     176 * @brief Scheduler Release job
     177 *
     178 * This routine is called when a new period of task is issued.
     179 */
     180RTEMS_INLINE_ROUTINE void _Scheduler_Release_job(
     181  Thread_Control *the_thread,
     182  uint32_t       length
     183)
     184{
     185  _Scheduler.Operations.release_job(the_thread, length);
     186}
     187
    162188/** @brief Scheduler Method Invoked at Each Clock Tick
    163189 *
    164190 * This method is invoked at each clock tick to allow the scheduler
  • cpukit/score/inline/rtems/score/schedulerpriority.inl

    diff --git a/cpukit/score/inline/rtems/score/schedulerpriority.inl b/cpukit/score/inline/rtems/score/schedulerpriority.inl
    index 0eddbf5..1c0263c 100644
    a b RTEMS_INLINE_ROUTINE void _Scheduler_priority_Schedule_body(void) 
    185185  );
    186186}
    187187
     188/**
     189 *  @brief Scheduler priority Priority compare body
     190 *
     191 *  This routine implements priority comparison for priority-based
     192 *  scheduling.
     193 *
     194 *  @return 1 for higher priority, 0 for equal and -1 for lower priority.
     195 */
     196RTEMS_INLINE_ROUTINE int _Scheduler_priority_Priority_compare_body(
     197  Priority_Control      p1,
     198  Priority_Control      p2
     199)
     200{
     201  /* High priority in priority scheduler is represented by low numbers. */
     202  return ((p1<p2) - (p1>p2));
     203}
     204
    188205/**@}*/
    189206
    190207#endif
  • cpukit/score/src/coremutexseize.c

    diff --git a/cpukit/score/src/coremutexseize.c b/cpukit/score/src/coremutexseize.c
    index bab9293..c7bfcd8 100644
    a b void _CORE_mutex_Seize_interrupt_blocking( 
    6060
    6161  executing = _Thread_Executing;
    6262  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
    63     if ( the_mutex->holder->current_priority > executing->current_priority ) {
     63    if ( _Scheduler_Is_priority_higher_than(
     64         executing->current_priority,
     65         the_mutex->holder->current_priority)) {
    6466      _Thread_Change_priority(
    6567        the_mutex->holder,
    6668        executing->current_priority,