EE445M RTOS
Taken at the University of Texas Spring 2015
schedule.h File Reference
Include dependency graph for schedule.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SCHEDULER_DEFAULT_MAX_THREADS   5
 
#define SYSTICKS_PER_HZ   80000000
 
#define MAX_SYSTICKS_PER_HZ   16777216
 
#define SYSCTLCLOCK   16000000
 
#define SCHEDULER_MAX_THREADS   SCHEDULER_DEFAULT_MAX_THREADS
 

Typedefs

typedef void(* pisr_t) (notification note)
 

Functions

void schedule_init ()
 
void schedule (task_t, frequency_t, DEADLINE_TYPE)
 
void schedule_aperiodic (pisr_t, HW_TYPE, hw_metadata, microseconds_t, DEADLINE_TYPE)
 
sched_task_poolschedule_hash_find_int (sched_task_pool *queues, frequency_t target_frequency)
 
void schedule_hash_add_int (sched_task_pool *queues, sched_task_pool *add)
 
sched_taskedf_get_edf_queue ()
 
void _os_choose_next_thread ()
 

Variables

static sched_task_pool SCHEDULER_TASK_QUEUES [5]
 
static volatile sched_task_poolSCHEDULER_UNUSED_QUEUES = NULL
 
static volatile sched_task_poolSCHEDULER_QUEUES = NULL
 
static sched_task SCHEDULER_TASKS [5]
 
static sched_taskSCHEDULER_UNUSED_TASKS = NULL
 

Macro Definition Documentation

#define MAX_SYSTICKS_PER_HZ   16777216

Definition at line 21 of file schedule.h.

Referenced by schedule().

#define SCHEDULER_DEFAULT_MAX_THREADS   5

Definition at line 19 of file schedule.h.

#define SCHEDULER_MAX_THREADS   SCHEDULER_DEFAULT_MAX_THREADS

Definition at line 25 of file schedule.h.

#define SYSCTLCLOCK   16000000

Definition at line 22 of file schedule.h.

#define SYSTICKS_PER_HZ   80000000

Definition at line 20 of file schedule.h.

Referenced by edf_pop().

Typedef Documentation

typedef void(* pisr_t) (notification note)

Definition at line 28 of file schedule.h.

Function Documentation

void _os_choose_next_thread ( )
Precondition
disable interrupts before we get here

Definition at line 544 of file os.c.

References scheduler_reschedule().

Referenced by os_launch().

544  {
545 
547 
548 }
always void scheduler_reschedule(void)
Definition: os.c:237

Here is the call graph for this function:

Here is the caller graph for this function:

sched_task* edf_get_edf_queue ( )

Definition at line 538 of file os.c.

References EDF_QUEUE.

538  {
539  return EDF_QUEUE;
540 }
volatile sched_task * EDF_QUEUE
Definition: os.c:27
void schedule ( task_t  ,
frequency_t  ,
DEADLINE_TYPE   
)

Definition at line 386 of file os.c.

References sched_task::absolute_deadline, CDL_APPEND, CDL_DELETE, CDL_PREPEND, clock, sched_task_pool::deadline, MAX_SYSTICKS_PER_HZ, sched_task_pool::next, NULL, os_add_thread(), postpone_death, sched_task_pool::prev, sched_task_pool::queue, schedule_hash_find_int(), SCHEDULER_QUEUES, SCHEDULER_UNUSED_QUEUES, SCHEDULER_UNUSED_TASKS, sched_task::seriousness, sched_task::task, and sched_task::tcb.

Referenced by main().

386  {
387 
388  sched_task *ready_task = NULL;
389  sched_task_pool *ready_queue = NULL;
390 
391  /* Grab a new task from the unused task pile */
392  ready_task = SCHEDULER_UNUSED_TASKS;
393  CDL_DELETE(SCHEDULER_UNUSED_TASKS, ready_task);
394 
395  /* Set new task's metadata */
396  ready_task->task = task;
397  ready_task->seriousness = seriousness;
398 
399  if (frequency > MAX_SYSTICKS_PER_HZ) {
400  postpone_death();
401  }
402  ready_task->absolute_deadline = frequency + clock;
403 
404  ready_task->tcb = os_add_thread(task);
405 
406  /* Test the pool of ready queues for a queue of tasks with this
407  * frequency */
408  /* todo: uthash configurable without malloc */
409  ready_queue = schedule_hash_find_int(SCHEDULER_QUEUES, frequency);
410  /* HASH_FIND_INT(SCHEDULER_QUEUES, &frequency, ready_queue); */
411 
412  /* No similar tasks exist yet -- create the pool */
413  if (!ready_queue) {
414  /* Grab a new queue, remove it from the unused pile,
415  * initialize it and associate it with this requency of
416  * task */
417  ready_queue = SCHEDULER_UNUSED_QUEUES;
418  CDL_DELETE(SCHEDULER_UNUSED_QUEUES, ready_queue);
419 
420  ready_queue->deadline = frequency;
421  if (!SCHEDULER_QUEUES) {
422  SCHEDULER_QUEUES = ready_queue;
425  } else {
426  CDL_PREPEND(SCHEDULER_QUEUES, ready_queue);
427  }
428  /* HASH_ADD_INT(SCHEDULER_QUEUES, deadline, ready_queue); */
429  }
430 
431  /* Add task to ready queue */
432  CDL_APPEND(ready_queue->queue, ready_task);
433 }
static volatile sched_task_pool * SCHEDULER_UNUSED_QUEUES
Definition: schedule.h:34
tcb_t * os_add_thread(task_t task)
Definition: os.c:72
#define MAX_SYSTICKS_PER_HZ
Definition: schedule.h:21
DEADLINE_TYPE seriousness
static sched_task * SCHEDULER_UNUSED_TASKS
Definition: schedule.h:45
#define CDL_DELETE(head, del)
Definition: utlist.h:705
#define postpone_death()
Definition: nexus.h:40
frequency_t deadline
struct sched_task_pool * next
volatile uint32_t clock
Definition: os.c:20
sched_task * queue
sched_task_pool * schedule_hash_find_int(sched_task_pool *queues, frequency_t target_frequency)
Definition: os.c:456
#define NULL
Definition: defines.h:32
tick_t absolute_deadline
#define CDL_APPEND(head, add)
Definition: utlist.h:688
struct sched_task_pool * prev
static volatile sched_task_pool * SCHEDULER_QUEUES
Definition: schedule.h:38
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

Here is the caller graph for this function:

void schedule_aperiodic ( pisr_t  ,
HW_TYPE  ,
hw_metadata  ,
microseconds_t  ,
DEADLINE_TYPE   
)

Schedule a pseudo-isr to be executed when a hardware event described by HW_TYPE and hw_metadata occurs.

Definition at line 435 of file os.c.

References _hw_subscribe().

439  {
440 
441  /* todo: utilize \allowed_run_time, \seriousness */
442  _hw_subscribe(hw_type, metadata, pisr, true);
443 }
void _hw_subscribe(HW_TYPE type, hw_metadata metadata, void(*isr)(notification note), bool single_shot)
Definition: hardware.c:121

Here is the call graph for this function:

void schedule_hash_add_int ( sched_task_pool queues,
sched_task_pool add 
)
sched_task_pool* schedule_hash_find_int ( sched_task_pool queues,
frequency_t  target_frequency 
)

Definition at line 456 of file os.c.

References sched_task_pool::deadline, sched_task_pool::next, and NULL.

Referenced by schedule().

456  {
457 
458  sched_task_pool* start = queues;
459  sched_task_pool* inspect = queues;
460 
461  if (!inspect) { return NULL; }
462 
463  do {
464  if(inspect->deadline == target_frequency) {
465  return inspect;
466  }
467  inspect = inspect->next;
468  } while (inspect != start);
469  return NULL;
470 }
frequency_t deadline
struct sched_task_pool * next
#define NULL
Definition: defines.h:32

Here is the caller graph for this function:

void schedule_init ( )

Initialize all deep datastructures used by libschedule.

Definition at line 445 of file os.c.

References DL_PREPEND, SCHEDULER_MAX_THREADS, SCHEDULER_TASK_QUEUES, SCHEDULER_TASKS, SCHEDULER_UNUSED_QUEUES, and SCHEDULER_UNUSED_TASKS.

Referenced by os_threading_init().

445  {
446 
447  int32_t i;
448  for(i=0; i<SCHEDULER_MAX_THREADS; ++i) {
449  /* Add all tasks to the unused pile */
451  /* Add all task queues to the unused pile */
453  }
454 }
static volatile sched_task_pool * SCHEDULER_UNUSED_QUEUES
Definition: schedule.h:34
#define DL_PREPEND(head, add)
Definition: utlist.h:510
static sched_task SCHEDULER_TASKS[5]
Definition: schedule.h:42
static sched_task * SCHEDULER_UNUSED_TASKS
Definition: schedule.h:45
#define SCHEDULER_MAX_THREADS
static sched_task_pool SCHEDULER_TASK_QUEUES[5]
Definition: schedule.h:31

Here is the caller graph for this function:

Variable Documentation

volatile sched_task_pool* SCHEDULER_QUEUES = NULL
static

UTHash of live task queues

Definition at line 38 of file schedule.h.

Referenced by edf_init(), edf_pop(), schedule(), and scheduler_reschedule().

sched_task_pool SCHEDULER_TASK_QUEUES[5]
static

Statically allocated multiple queues of tasks

Definition at line 31 of file schedule.h.

Referenced by schedule_init().

sched_task SCHEDULER_TASKS[5]
static

Statically allocated task metadata structures for the scheduler to manage

Definition at line 42 of file schedule.h.

Referenced by schedule_init().

volatile sched_task_pool* SCHEDULER_UNUSED_QUEUES = NULL
static

Doubly linked list of unused task queues

Definition at line 34 of file schedule.h.

Referenced by schedule(), and schedule_init().

sched_task* SCHEDULER_UNUSED_TASKS = NULL
static

Doubly linked list of unused tasks

Definition at line 45 of file schedule.h.

Referenced by schedule(), and schedule_init().