Commit eb8010ad authored by Jan Ahlbrecht's avatar Jan Ahlbrecht Committed by Oliver Horst
Browse files

[add] added minimum priotity scheduling based on hst

Added Minimum priority scheduling which tries to adapt to the current workload to keep dealdines.
parent f2f9f3fc
......@@ -29,6 +29,7 @@
#define schedSCHEDULING_POLICY_EDF 3 /* Earliest deadline first */
#define schedSCHEDULING_POLICY_DP 4 /* Dual priority scheduling */
#define schedSCHEDULING_POLICY_SS 5 /* Rate-monotonic scheduling with slack stealing */
#define schedSCHEDULING_POLICY_MP 6 /* Minimum Prioriy scheduling */
#define schedSCHEDULER_INTEGRATION_EFFICIENT 0 /* Integrate the scheduler extension through trace macros */
#define schedSCHEDULER_INTEGRATION_NAIVE 1 /* Integrate the schedulerextensions without modifying the FreeRTOS kernel */
......@@ -54,7 +55,8 @@
#if !( ( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_RMS ) || \
( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_EDF ) || \
( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_DP ) || \
( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_SS ) )
( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_SS ) || \
( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_MP) )
#error "HST only supports one of the following scheduling policies: RMS, EDF, DP, or SS!"
#endif
......
......@@ -26,6 +26,8 @@ struct TaskInfo
TickType_t xDeadline; /* Relative deadline. */
TickType_t xAbsolutDeadline; /* Absolute deadline of the current release. */
TickType_t xRelease; /* Most recent task release absolute time. */
UBaseType_t xHunger; /* Hunger variable */
UBaseType_t xDynamicPriority; /*Dynamic Priority that can be used for scheduling */
// ----------------------
TickType_t xWcet; /* Worst case execution time. */
......
......@@ -12,3 +12,4 @@ add_subdirectory(dp)
add_subdirectory(edf)
add_subdirectory(rm)
add_subdirectory(ss)
add_subdirectory(mp)
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
target_sources(
freertos-plus
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/scheduler_logic_mp.c"
)
Scheduling policy for Minimum Priority scheduling.
\ No newline at end of file
#include "freertos/FreeRTOS.h"
#if ( 1 == ENABLE_SchedulerExtension_HST) && ( schedSCHEDULING_POLICY == schedSCHEDULING_POLICY_MP)
#include "freertos+/sched-ext/hst/scheduler.h"
#define ONE_TICK ( ( TickType_t ) 1 )
/* Ready tasks list. */
List_t xReadyTasksList;
List_t * pxReadyTasksList = NULL;
List_t * pxAllTasksList = NULL;
/* Current minimum priority */
UBaseType_t xMinimumPriority;
void vSchedulerTaskSchedulerStartLogic ( void )
{
return;
}
/* Scheduling logic that is checked for on every tick */
BaseType_t vSchedulerTaskSchedulerTickLogic ( void ) {
/* Increment the current task executed time. */
struct TaskInfo * pxTask = ( struct TaskInfo * ) listGET_OWNER_OF_HEAD_ENTRY(pxReadyTasksList);
pxTask->xCur = pxTask->xCur + ONE_TICK;
return pdFALSE;
}
/* Scheduling Logic */
void vSchedulerTaskSchedulerLogic ( struct TaskInfo **pxCurrentTask )
{
const ListItem_t * pxAppTasksListEndMarker = listGET_END_MARKER( pxReadyTasksList );
ListItem_t * pxAppTasksListItem = listGET_HEAD_ENTRY( pxReadyTasksList );
/* Suspend all ready tasks. */
while( pxAppTasksListEndMarker != pxAppTasksListItem )
{
struct TaskInfo * pxAppTask = ( struct TaskInfo * ) listGET_LIST_ITEM_OWNER( pxAppTasksListItem );
/* Checking if the task is starving and deserves a priority boost */
if ( pxAppTask->xHunger > 3 ) {
pxAppTask->xHunger = 0;
pxAppTask->xDynamicPriority + 4;
}
/* Adding tasks that are ready and have the correct priority to the ready queue */
if( ( eTaskGetState( pxAppTask->xHandle ) == eReady ) && ( pxAppTask->xDynamicPriority ) > xMinimumPriority )
{
vTaskSuspend( pxAppTask->xHandle );
}
pxAppTasksListItem = listGET_NEXT( pxAppTasksListItem );
}
/* Check if the current task has finished. Then check if it has held its deadline or the min prio needs to boosted */
if ( *pxCurrentTask != NULL )
{
if ( listIS_CONTAINED_WITHIN( pxReadyTasksList, &( ( *pxCurrentTask )->xReadyListItem ) ) == pdFALSE )
{
/* Checking if the current task held its deadline. Then adapting the minimum priority */
if ( ( * pxCurrentTask )->xDeadline < ( * pxCurrentTask )->xCur)
{
if ( xMinimumPriority < 4 )
{
xMinimumPriority = xMinimumPriority + 1;
}
} else if ( xMinimumPriority > 0 )
{
xMinimumPriority = xMinimumPriority - 1;
}
pxCurrentTask = NULL;
}
}
if( listLIST_IS_EMPTY( pxReadyTasksList ) == pdFALSE )
{
*pxCurrentTask = ( struct TaskInfo * ) listGET_OWNER_OF_HEAD_ENTRY( pxReadyTasksList );
vTaskResume( ( *pxCurrentTask )->xHandle );
}
}
/* Logic for adding a task to the ready list */
void vSchedulerLogicAddTaskToReadyList( struct TaskInfo *xTask )
{
xTask->xDynamicPriority = xTask->xPriority;
listSET_LIST_ITEM_VALUE( &( xTask->xReadyListItem ), xTask->xAbsolutDeadline );
vListInsert( pxReadyTasksList, &( xTask->xReadyListItem ) );
}
/* Logic for removing a task from the ready queue */
void vSchedulerLogicRemoveTaskFromReadyList( struct TaskInfo *xTask )
{
uxListRemove( &( xTask->xReadyListItem ) );
}
/* Logic for adding a task to the scheduling */
void vSchedulerLogicAddTask( struct TaskInfo * pxTask )
{
/* Initialize the task's ready item list. */
listSET_LIST_ITEM_OWNER( &( pxTask->xReadyListItem ), pxTask );
listSET_LIST_ITEM_VALUE( &( pxTask->xReadyListItem ), pxTask->xDeadline );
/* Insert the task into the ready list. */
vListInsert( pxReadyTasksList, &( pxTask->xReadyListItem ) );
}
/* Init the lists and set the initial minimum priority */
void vSchedulerLogicSetup( void )
{
/* Initialize the ready task ready list. */
vListInitialise( &( xReadyTasksList ) );
pxReadyTasksList = &( xReadyTasksList );
pxAllTasksList = &( xReadyTasksList );
xMinimumPriority = 0;
}
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment