GPUart  1.01
Prototype of GPUart, an application-based limited preemptive GPU scheduler for embedded real-time systems
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Classes | Macros | Functions | Variables
GPUart_Scheduler.cpp File Reference

Implementation of the GPUart Scheduling layer. More...

#include "GPUart_Scheduler.h"
#include "../GPUart_Impl/GPUart_Impl_Sched_IF.h"
#include "../SW-C/Scheduler/SWC_Scheduler.h"
#include <string.h>
#include <pthread.h>
Include dependency graph for GPUart_Scheduler.cpp:

Classes

struct  job_s
 Data type for job (kernel instance), including the kernel ID and the jobs priority. More...
 
struct  job_priority_list_s
 Data type for the priority list (gpuS_JobList_s) which holds all active jobs (kernel instances). More...
 
struct  job_stack_s
 Data type for the priority stacks (gpuS_JobStackShared_s and gpuS_JobStack_s) which hold new jobs (kernel instances). More...
 

Macros

#define S_POLICY_EDF   (1)
 Scheduling policy: Gang Earliest Deadline First (Gang-EDF) More...
 
#define S_POLICY_FTP   (2)
 Scheduling policy: Gang Fixed Task Priority (Gang-FTP). Set deadlines in gpuS_relDeadlines_u32 to the period times to get Gang Rate Monotonic scheduling (Gang-RM). More...
 
#define S_SCHED_POLICY   S_POLICY_EDF
 Set S_SCHED_POLICY to either S_POLICY_EDF or S_POLICY_FTP. More...
 
#define C_GPUS_RESOURCE_FACTOR   1
 Defines the resource factor µ, that is, how many thread blocks are allowed per Streaming Multiprocessor. More...
 

Functions

static GPUart_Retval gpuS_priorityList_insert (job_priority_list_s *pJobList, job_s pJob)
 Insert a job into a priority based list. More...
 
static GPUart_Retval gpuS_priorityList_delete (job_priority_list_s *pJobList, uint8 pId)
 Delete a job from a priority based list. More...
 
static GPUart_Retval gpuS_jobStack_push (job_stack_s *pJobStack, job_s pJob)
 Push a new kernel instance to the shared job stack. More...
 
static GPUart_Retval gpuS_jobStack_copy (job_stack_s *pJobStackDest, job_stack_s *pJobStackSrc)
 Copies a job stack job_stack_s. More...
 
static GPUart_Retval gpuS_jobStack_pull (job_stack_s *pJobStack, job_s *pJob)
 Pull a job from a job stack. More...
 
static GPUart_Retval gpuS_getPriority (kernel_task_id_e task_id_e, uint32 *priority)
 Get the priority of a job (kernel instance). More...
 
static GPUart_Retval gpuS_updateListWithNewJobs (void)
 Updates a priority based job list with all new released jobs. More...
 
static GPUart_Retval gpuS_updateRunningStatus (void)
 Updates a the scheduling state (gpuS_kernelTaskStatus_e) of each kernel. More...
 
GPUart_Retval gpuS_schedule (void)
 Executes the scheduling decision. More...
 
GPUart_Retval gpuS_new_Job (kernel_task_id_e task_id_e)
 Releases a new job and pushes it to the shared job stack gpuS_JobStackShared_s. More...
 
GPUart_Retval gpuS_query_terminated (kernel_task_id_e task_id_e)
 Queries whether a job has terminated. More...
 
GPUart_Retval gpuS_query_ready_to_call (kernel_task_id_e task_id_e)
 Queries whether a kernel is ready to get instantiated. More...
 
GPUart_Retval gpuS_init (void)
 Initializes the GPUart Scheduling layer. More...
 
GPUart_Retval gpuS_destroy (void)
 Destroys the GPUart Scheduling layer. More...
 

Variables

static job_priority_list_s gpuS_JobList_s
 The priority ordered list which manages all active jobs. More...
 
static job_stack_s gpuS_JobStackShared_s
 The shared stack which holds all new jobs. More...
 
static job_stack_s gpuS_JobStack_s
 The private stack which holds all new jobs. It is a copy of gpuS_JobStackShared_s. More...
 
static sint8 gpuS_ktRunFlags_new_s8 [E_KTID_NUMBER_OF_KERNEL_TASKS] = {0}
 An array which holds the current running status of each kernel. More...
 
static sint8 gpuS_ktRunFlags_old_s8 [E_KTID_NUMBER_OF_KERNEL_TASKS] = {0}
 An array which holds the running status of each kernel from the last scheduling decision. More...
 
static uint32 gpuS_relDeadlines_u32 [E_KTID_NUMBER_OF_KERNEL_TASKS]
 An array for the configuration of the kernels' relative deadlines in µs. More...
 
static enum
gpuS_kernelTask_status_e 
gpuS_kernelTaskStatus_e [E_KTID_NUMBER_OF_KERNEL_TASKS]
 An array which represents the state machine for each kernel. More...
 
static uint32 gpuS_nrOfMultiprocessor_u32 = 0u
 Represents the number of Streaming Multiprocessors m on the GPU. More...
 

Detailed Description

Implementation of the GPUart Scheduling layer.

Author
Christoph Hartmann
Date
Created on: 3 Apr 2017

Macro Definition Documentation

#define C_GPUS_RESOURCE_FACTOR   1

Defines the resource factor µ, that is, how many thread blocks are allowed per Streaming Multiprocessor.

#define S_POLICY_EDF   (1)

Scheduling policy: Gang Earliest Deadline First (Gang-EDF)

See Also
Kato et al. Gang EDF Scheduling of Parallel Task Systems, in: RTSS10, Washington, USA, 2009 http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=5368128
https://en.wikipedia.org/wiki/Earliest_deadline_first_scheduling
#define S_POLICY_FTP   (2)

Scheduling policy: Gang Fixed Task Priority (Gang-FTP). Set deadlines in gpuS_relDeadlines_u32 to the period times to get Gang Rate Monotonic scheduling (Gang-RM).

See Also
Goosens et al. Gang FTP scheduling of periodic and parallel rigid real-time tasks in Real-Time and Network Systems (RTNS 2010), Tolouse France, 2010 https://arxiv.org/abs/1006.2617
https://en.wikipedia.org/wiki/Fixed-priority_pre-emptive_scheduling
https://en.wikipedia.org/wiki/Rate-monotonic_scheduling
#define S_SCHED_POLICY   S_POLICY_EDF

Set S_SCHED_POLICY to either S_POLICY_EDF or S_POLICY_FTP.

Function Documentation

GPUart_Retval gpuS_destroy ( void  )

Destroys the GPUart Scheduling layer.

Destroys the mutex of each job_stack_s.

Returns
GPUART_SUCCESS

Here is the caller graph for this function:

static GPUart_Retval gpuS_getPriority ( kernel_task_id_e  task_id_e,
uint32 priority 
)
static

Get the priority of a job (kernel instance).

Returns the priority of a job. The smaller the value, the higher the priority.

Parameters
[in]kernel_task_id_etask_id_e, -> The kernel for which the priority should be returned.
[out]uint8pId -> The priority of the kernel instance.
Returns
GPUART_SUCCESS

Here is the call graph for this function:

Here is the caller graph for this function:

GPUart_Retval gpuS_init ( void  )

Initializes the GPUart Scheduling layer.

Initializes all variables of the Scheduling layer.

Returns
GPUART_SUCCESS

Here is the call graph for this function:

Here is the caller graph for this function:

static GPUart_Retval gpuS_jobStack_copy ( job_stack_s pJobStackDest,
job_stack_s pJobStackSrc 
)
static

Copies a job stack job_stack_s.

Make a copy of the shared job stack an save its content into the non-shared job stack of the GPUart scheduling host.

Parameters
[in]job_stack_s* pJobStackDest -> The job_stack_s to be copied.
[out]job_stack_s* pJobStackSrc -> The copy of pJobStackDest
Returns
GPUART_SUCCESS
See Also
gpuS_JobStackShared_s
gpuS_JobStack_s

Here is the caller graph for this function:

static GPUart_Retval gpuS_jobStack_pull ( job_stack_s pJobStack,
job_s pJob 
)
static

Pull a job from a job stack.

Befor each scheduling decision, the scheduler pulls all jobs from gpuS_JobStack_s and insert them into gpuS_JobList_s in priority based order.

Parameters
[in]job_stack_s* pJobStack -> The job_stack_s from which this function pulls a job_s.
[out]job_s* pJob -> The job_s to be pulled.
Returns
GPUART_SUCCESS if job has been pulled successfully.
GPUART_NO_SUCCESS if pJobStack is empty.
See Also
gpuS_JobStack_s
gpuS_JobList_s

Here is the caller graph for this function:

static GPUart_Retval gpuS_jobStack_push ( job_stack_s pJobStack,
job_s  pJob 
)
static

Push a new kernel instance to the shared job stack.

This function is called, when a new kernel instance has been activated due to a call to a kernel's call-function in GPUart_Service_IF.h. The new job is pushed on the shared job stack, which is accessed in a mutual exlusive manner.

Parameters
[out]job_stack_s* pJobStack -> The shared job stack
[in]job_spJob -> The new job to be released
Returns
GPUART_SUCCESS if job could be inserted
GPUART_NO_SUCCESS if priority list is full
See Also
gpuS_JobStackShared_s

Here is the caller graph for this function:

GPUart_Retval gpuS_new_Job ( kernel_task_id_e  task_id_e)

Releases a new job and pushes it to the shared job stack gpuS_JobStackShared_s.

Parameters
kernel_task_id_etask_id_e -> The ID of the kernel which this function instatiates.
Returns
GPUART_SUCCESS if kernel has been instantiated successfully.
GPUART_ERROR_INVALID_ARGUMENT if kernel ID is invalid.
GPUART_ERROR_NO_OPERTATION if there is already an active instance (job) of that kernel.

Here is the call graph for this function:

Here is the caller graph for this function:

static GPUart_Retval gpuS_priorityList_delete ( job_priority_list_s pJobList,
uint8  pId 
)
static

Delete a job from a priority based list.

After a job (kernel instance) has been completed, it is deleted from the list gpuS_JobList_s

Parameters
[out]job_priority_list_s* pJobList -> The job_priority_list_s from which this function deletes a job.
[in]uint8pId -> The index of the list element wich is deleted by this function.
Returns
GPUART_SUCCESS if job has been deleted successfully.
GPUART_ERROR_INVALID_ARGUMENT if pID is out of bounds.
See Also
gpuS_JobList_s

Here is the caller graph for this function:

static GPUart_Retval gpuS_priorityList_insert ( job_priority_list_s pJobList,
job_s  pJob 
)
static

Insert a job into a priority based list.

Befor each scheduling decision, the scheduler pulls all jobs from gpuS_JobStack_s and insert them into gpuS_JobList_s in priority based order. The job list gpuS_JobList_s contains all active kernels.

Parameters
[out]job_priority_list_s* pJobList -> The job_priority_list_s in which this function inserts a job.
[in]job_spJob -> The job_s to be inserted.
Returns
GPUART_SUCCESS if job has been inserted successfully.
GPUART_NO_SUCCESS if pJobList is full.
See Also
gpuS_JobList_s

Here is the caller graph for this function:

GPUart_Retval gpuS_query_ready_to_call ( kernel_task_id_e  task_id_e)

Queries whether a kernel is ready to get instantiated.

Parameters
kernel_task_id_etask_id_e -> The ID of the kernel.
Returns
GPUART_SUCCESS if kernel can get instantiated.
GPUART_ERROR_NOT_READY if there is already an active instance (job) of that kernel.

Here is the caller graph for this function:

GPUart_Retval gpuS_query_terminated ( kernel_task_id_e  task_id_e)

Queries whether a job has terminated.

Parameters
kernel_task_id_etask_id_e -> The ID of the kernel.
Returns
GPUART_SUCCESS if kernel has been terminated
GPUART_ERROR_NOT_READY if kernel is still active.

Here is the caller graph for this function:

GPUart_Retval gpuS_schedule ( void  )

Executes the scheduling decision.

If the compiler switch S_NON_PREEMPTIVE is defined, this function schedules kernel non-preemptively, otherwise it schedules them in a limited preemptive manner. First this function updates the kernel's scheduling state and deletes completed kernels form gpuS_JobList_s, then it updates the job list gpuS_JobList_s with all new released kernels. After that, this function iterates through gpuS_JobList_s and executes the scheduling decision according to the scheduling policy defined in S_SCHED_POLICY.

Returns
GPUART_SUCCESS

Here is the call graph for this function:

Here is the caller graph for this function:

static GPUart_Retval gpuS_updateListWithNewJobs ( void  )
static

Updates a priority based job list with all new released jobs.

Befor each scheduling decision, the scheduler pulls all jobs from gpuS_JobStack_s and insert them into gpuS_JobList_s in priority based order. The job list gpuS_JobList_s contains all active kernels.

Returns
GPUART_SUCCESS if job list could be updated successfully.
GPUART_NO_SUCCESS if job list is full.

Here is the call graph for this function:

Here is the caller graph for this function:

static GPUart_Retval gpuS_updateRunningStatus ( void  )
static

Updates a the scheduling state (gpuS_kernelTaskStatus_e) of each kernel.

Befor each scheduling decision the scheduler polls each active job in gpuS_JobList_s if it has been terminated or preempted. Terminated jobs are deleted in gpuS_JobList_s by calling gpuS_priorityList_delete(). The state of the corresponding kernel instance is set to E_STATUS_TERMINATED. If a kernel has been preempted, its state set to E_STATUS_READY.

Returns
GPUART_SUCCESS

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

job_priority_list_s gpuS_JobList_s
static

The priority ordered list which manages all active jobs.

job_stack_s gpuS_JobStack_s
static

The private stack which holds all new jobs. It is a copy of gpuS_JobStackShared_s.

This stack is used to reduce the blocking times, resulting by the mutual exclusive access, by copying the content of gpuS_JobStackShared_s into this stack. The scheduler periodically pulls new jobs from this stack and inserts them into gpuS_JobList_s in a priority order.

job_stack_s gpuS_JobStackShared_s
static

The shared stack which holds all new jobs.

This stack can be accessed by any thread via the call-interface of a kernel in the Abstraction layer (GPUart_Service_IF.h). Data integrity is assured by mutual exclusion.

enum gpuS_kernelTask_status_e gpuS_kernelTaskStatus_e[E_KTID_NUMBER_OF_KERNEL_TASKS]
static
Initial value:
= {
E_STATUS_INIT
}
Definition: GPUart_Scheduler.h:72

An array which represents the state machine for each kernel.

The length of this array is equal to the number of kernels E_KTID_NUMBER_OF_KERNEL_TASKS. The i'th element represents the i'th kernel, according to the enum kernel_task_id_e. A kernel can be either INIT, READY, RUNNING, or TERMINATED.

sint8 gpuS_ktRunFlags_new_s8[E_KTID_NUMBER_OF_KERNEL_TASKS] = {0}
static

An array which holds the current running status of each kernel.

The length of this array is equal to the number of kernels E_KTID_NUMBER_OF_KERNEL_TASKS. The i'th element represents the i'th kernel, according to the enum kernel_task_id_e. If an element is equal to 0, then this kernel is NOT running currently. Otherwise, the corresponding kernel is running. The array gets updated with each scheduling decision.

sint8 gpuS_ktRunFlags_old_s8[E_KTID_NUMBER_OF_KERNEL_TASKS] = {0}
static

An array which holds the running status of each kernel from the last scheduling decision.

See gpuS_ktRunFlags_new_s8

uint32 gpuS_nrOfMultiprocessor_u32 = 0u
static

Represents the number of Streaming Multiprocessors m on the GPU.

uint32 gpuS_relDeadlines_u32[E_KTID_NUMBER_OF_KERNEL_TASKS]
static
Initial value:
= {
10000,
100000,
1000000
}

An array for the configuration of the kernels' relative deadlines in µs.

The length of this array is equal to the number of kernels E_KTID_NUMBER_OF_KERNEL_TASKS. The i'th element represents the i'th kernel, according to the enum kernel_task_id_e.