2013-11-27 16:28:31 +01:00
|
|
|
/*
|
2014-04-07 11:16:32 +02:00
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
|
|
|
* This file subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
/**
|
2013-11-27 16:28:31 +01:00
|
|
|
* @defgroup core_sched Scheduler
|
|
|
|
* @ingroup core
|
|
|
|
* @brief The RIOT scheduler
|
2010-09-22 15:10:42 +02:00
|
|
|
* @{
|
2013-11-27 16:28:31 +01:00
|
|
|
*
|
2013-06-21 22:37:14 +02:00
|
|
|
* @file sched.h
|
2013-11-27 16:28:31 +01:00
|
|
|
* @brief Scheduler API definion
|
|
|
|
*
|
2013-03-08 11:30:23 +01:00
|
|
|
* @author Freie Universität Berlin, Computer Systems & Telematics
|
2010-09-22 15:10:42 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SCHEDULER_H
|
|
|
|
#define _SCHEDULER_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "bitarithm.h"
|
2010-09-22 15:10:42 +02:00
|
|
|
#include "tcb.h"
|
|
|
|
|
2014-04-07 11:16:32 +02:00
|
|
|
#define MAXTHREADS 32 /**< the maximum number of threads to be scheduled */
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-04-07 11:16:32 +02:00
|
|
|
/**
|
|
|
|
* @def SCHED_PRIO_LEVELS
|
|
|
|
* @brief The number of thread priority levels
|
|
|
|
*/
|
2010-10-29 17:32:03 +02:00
|
|
|
#if ARCH_32_BIT
|
2010-09-22 15:10:42 +02:00
|
|
|
#define SCHED_PRIO_LEVELS 32
|
|
|
|
#else
|
|
|
|
#define SCHED_PRIO_LEVELS 16
|
|
|
|
#endif
|
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
2013-08-14 14:15:11 +02:00
|
|
|
* @brief Triggers the scheduler to schedule the next task
|
2013-08-14 13:04:19 +02:00
|
|
|
*/
|
2013-02-06 13:20:21 +01:00
|
|
|
void sched_run(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
|
|
|
* @brief Set the status of the specified process
|
|
|
|
*
|
2014-02-11 18:15:43 +01:00
|
|
|
* @param[in] process Pointer to the thread control block of the
|
2013-08-14 13:04:19 +02:00
|
|
|
* targeted process
|
|
|
|
* @param[in] status The new status of this thread
|
|
|
|
*/
|
2011-03-08 11:43:21 +01:00
|
|
|
void sched_set_status(tcb_t *process, unsigned int status);
|
2013-08-14 13:04:19 +02:00
|
|
|
|
|
|
|
/**
|
2013-08-14 14:15:11 +02:00
|
|
|
* @brief Compare thread priorities and yield() (or set
|
|
|
|
* sched_context_switch_request if in_isr) when other_prio is higher
|
|
|
|
* (has a lower value) than current_prio
|
2013-08-14 13:04:19 +02:00
|
|
|
*
|
|
|
|
* @param[in] current_prio The priority of the current thread
|
|
|
|
* @param[in] other_prio The priority of the target thread
|
2014-02-11 18:15:43 +01:00
|
|
|
*/
|
2014-02-15 18:49:49 +01:00
|
|
|
void sched_switch(uint16_t current_prio, uint16_t other_prio);
|
2013-08-14 13:04:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Call context switching at task exit
|
|
|
|
*/
|
2013-03-27 14:53:38 +01:00
|
|
|
void cpu_switch_context_exit(void);
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
2013-08-14 14:15:11 +02:00
|
|
|
* Flag indicating whether a context switch is necessary after handling an
|
|
|
|
* interrupt. Supposed to be set in an ISR.
|
2013-08-14 13:04:19 +02:00
|
|
|
*/
|
2011-06-24 17:53:09 +02:00
|
|
|
extern volatile unsigned int sched_context_switch_request;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
|
|
|
* Thread table
|
|
|
|
*/
|
2011-06-24 17:53:09 +02:00
|
|
|
extern volatile tcb_t *sched_threads[MAXTHREADS];
|
2013-08-14 13:04:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Currently active thread
|
|
|
|
*/
|
2011-06-24 17:53:09 +02:00
|
|
|
extern volatile tcb_t *active_thread;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
|
|
|
* Number of running (non-terminated) threads
|
|
|
|
*/
|
2010-09-22 15:10:42 +02:00
|
|
|
extern volatile int num_tasks;
|
2013-08-14 13:04:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process ID of active thread
|
|
|
|
*/
|
2011-06-24 17:53:09 +02:00
|
|
|
extern volatile int thread_pid;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2014-04-07 11:16:32 +02:00
|
|
|
/**
|
|
|
|
* Process ID of the thread that was active before the current one
|
|
|
|
*/
|
|
|
|
extern volatile int last_pid;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of runqueues per priority level
|
|
|
|
*/
|
|
|
|
extern clist_node_t *runqueues[SCHED_PRIO_LEVELS];
|
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#if SCHEDSTATISTICS
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
|
|
|
* Scheduler statistics
|
|
|
|
*/
|
2013-06-20 18:18:29 +02:00
|
|
|
typedef struct {
|
2013-08-14 13:04:19 +02:00
|
|
|
unsigned int laststart; /*< Time stamp of the last time this thread was
|
|
|
|
scheduled to run */
|
|
|
|
unsigned int schedules; /*< How often the thread was scheduled to run */
|
2013-11-18 12:14:43 +01:00
|
|
|
unsigned long runtime_ticks; /*< The total runtime of this thread in ticks */
|
2013-06-20 18:18:29 +02:00
|
|
|
} schedstat;
|
2010-09-22 15:10:42 +02:00
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
|
|
|
* Thread statistics table
|
|
|
|
*/
|
2013-06-20 18:18:29 +02:00
|
|
|
extern schedstat pidlist[MAXTHREADS];
|
2013-08-14 10:58:08 +02:00
|
|
|
|
2013-08-14 13:04:19 +02:00
|
|
|
/**
|
2014-04-07 11:16:32 +02:00
|
|
|
* @brief Register a callback that will be called on every scheduler run
|
|
|
|
*
|
|
|
|
* @param[in] callback The callback functions the will be called
|
2013-08-14 13:04:19 +02:00
|
|
|
*/
|
2013-08-14 10:58:08 +02:00
|
|
|
void sched_register_cb(void (*callback)(uint32_t, uint32_t));
|
2014-04-07 11:16:32 +02:00
|
|
|
|
2010-09-22 15:10:42 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // _SCHEDULER_H
|
2014-04-07 11:16:32 +02:00
|
|
|
/** @} */
|