|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2004 David Decotigny 001 /* Copyright (C) 2004 David Decotigny 002 002 003 This program is free software; you can redi 003 This program is free software; you can redistribute it and/or 004 modify it under the terms of the GNU Genera 004 modify it under the terms of the GNU General Public License 005 as published by the Free Software Foundatio 005 as published by the Free Software Foundation; either version 2 006 of the License, or (at your option) any lat 006 of the License, or (at your option) any later version. 007 007 008 This program is distributed in the hope tha 008 This program is distributed in the hope that it will be useful, 009 but WITHOUT ANY WARRANTY; without even the 009 but WITHOUT ANY WARRANTY; without even the implied warranty of 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 011 GNU General Public License for more details 011 GNU General Public License for more details. 012 012 013 You should have received a copy of the GNU 013 You should have received a copy of the GNU General Public License 014 along with this program; if not, write to t 014 along with this program; if not, write to the Free Software 015 Foundation, Inc., 59 Temple Place - Suite 3 015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 016 USA. 016 USA. 017 */ 017 */ 018 #ifndef _SOS_SCHED_H_ 018 #ifndef _SOS_SCHED_H_ 019 #define _SOS_SCHED_H_ 019 #define _SOS_SCHED_H_ 020 020 021 021 022 /** 022 /** 023 * @file sched.h 023 * @file sched.h 024 * 024 * 025 * A basic scheduler inspired from the O(1) Li !! 025 * A basic scheduler with simple FIFO threads' ordering. 026 * 2 classes of thread priorities: << 027 * - so-called 'real-time' threads scheduled << 028 * traditional static priority real-time sc << 029 * robin scheduling is not supported. << 030 * - "fair" time-sharing scheduling for non re << 031 * because no starvation among the non real << 032 * possible. Contrary to the original O(1) << 033 * on-line adjustment of the scheduling pri << 034 * interactive/non interactive threads disc << 035 * supported: threads keep having the same << 036 * user does not change it. << 037 * 026 * 038 * The functions below manage CPU queues, and 027 * The functions below manage CPU queues, and are NEVER responsible 039 * for context switches (see thread.h for that 028 * for context switches (see thread.h for that) or synchronizations 040 * (see kwaitq.h or the higher levels primitiv 029 * (see kwaitq.h or the higher levels primitives [mutex, semaphore, 041 * ...] for that). 030 * ...] for that). 042 * 031 * 043 * @note IMPORTANT: all the functions below ar 032 * @note IMPORTANT: all the functions below are meant to be called 044 * ONLY by the thread/timer/kwaitq subsystems. 033 * ONLY by the thread/timer/kwaitq subsystems. DO NOT use them 045 * directly from anywhere else: use ONLY the t 034 * directly from anywhere else: use ONLY the thread/kwaitq functions! 046 * If you still want to call them directly des 035 * If you still want to call them directly despite this disclaimer, 047 * simply disable interrupts before clling the 036 * simply disable interrupts before clling them. 048 */ 037 */ 049 038 050 #include <sos/errno.h> 039 #include <sos/errno.h> 051 #include <sos/time.h> << 052 << 053 << 054 /** << 055 * The definition of a priority << 056 */ << 057 typedef unsigned char sos_sched_priority_t; << 058 040 059 041 060 #include <sos/thread.h> 042 #include <sos/thread.h> 061 043 062 044 063 /** 045 /** 064 * Valid priority interval ("real-time" and no << 065 */ << 066 #define SOS_SCHED_PRIO_HIGHEST 0 << 067 #define SOS_SCHED_PRIO_LOWEST 63 << 068 #define SOS_SCHED_NUM_PRIO 64 << 069 << 070 << 071 /** << 072 * Class-specific priorities << 073 */ << 074 #define SOS_SCHED_PRIO_RT_HIGHEST 0 /**< High << 075 #define SOS_SCHED_PRIO_RT_LOWEST 15 /**< Lowe << 076 #define SOS_SCHED_PRIO_TS_HIGHEST 16 /**< High << 077 #define SOS_SCHED_PRIO_TS_LOWEST 63 /**< Lowe << 078 << 079 #define SOS_SCHED_PRIO_DEFAULT 40 /**< Defa << 080 << 081 << 082 /** << 083 * Helper macros (Yes, priorities ordered in d << 084 * << 085 * @note: The use of this function is RESERVED << 086 */ << 087 #define SOS_SCHED_PRIO_CMP(prio1,prio2) ((pri << 088 << 089 #define SOS_SCHED_PRIO_IS_VALID(prio) \ << 090 ({ int __prio = (int)(prio); \ << 091 ((__prio) <= SOS_SCHED_PRIO_LOWEST) \ << 092 && \ << 093 ((__prio) >= SOS_SCHED_PRIO_HIGHEST); }) << 094 << 095 #define SOS_SCHED_PRIO_IS_RT(prio) \ << 096 ({ int __prio = (int)(prio); \ << 097 ((__prio) <= SOS_SCHED_PRIO_RT_LOWEST) \ << 098 && \ << 099 ((__prio) >= SOS_SCHED_PRIO_RT_HIGHEST); << 100 << 101 << 102 /** << 103 * The time slices for 'time-sharing' user thr << 104 */ << 105 #define SOS_TIME_SLICE_MIN 10 /* for SOS_SCHE << 106 #define SOS_TIME_SLICE_MAX 200 /* for SOS_SCHE << 107 << 108 << 109 /** << 110 * Initialize the scheduler 046 * Initialize the scheduler 111 * 047 * 112 * @note: The use of this function is RESERVED 048 * @note: The use of this function is RESERVED 113 */ 049 */ 114 sos_ret_t sos_sched_subsystem_setup(); 050 sos_ret_t sos_sched_subsystem_setup(); 115 051 116 052 117 /** 053 /** 118 * Mark the given thread as ready 054 * Mark the given thread as ready 119 * 055 * 120 * @note: The use of this function is RESERVED 056 * @note: The use of this function is RESERVED 121 */ 057 */ 122 sos_ret_t sos_sched_set_ready(struct sos_threa 058 sos_ret_t sos_sched_set_ready(struct sos_thread * thr); 123 059 124 060 125 /** 061 /** 126 * Return the identifier of the next thread to 062 * Return the identifier of the next thread to run. Also removes it 127 * from the ready list, but does NOT set is as 063 * from the ready list, but does NOT set is as current_thread ! 128 * 064 * 129 * @param current_thread TCB of the thread cal 065 * @param current_thread TCB of the thread calling the function 130 * 066 * 131 * @param do_yield When TRUE, put the current 067 * @param do_yield When TRUE, put the current executing thread at the 132 * end of the ready list. Otherwise it is kept 068 * end of the ready list. Otherwise it is kept at the head of it. 133 * 069 * 134 * @note: The use of this function is RESERVED 070 * @note: The use of this function is RESERVED 135 */ 071 */ 136 struct sos_thread * sos_reschedule(struct sos_ 072 struct sos_thread * sos_reschedule(struct sos_thread * current_thread, 137 sos_bool_t 073 sos_bool_t do_yield); 138 << 139 /** << 140 * Called by thread subsystem each time a READ << 141 * changed << 142 * << 143 * @note: The use of this function is RESERVED << 144 */ << 145 sos_ret_t sos_sched_change_priority(struct sos << 146 sos_sched_ << 147 << 148 << 149 /** << 150 * Account for the execution of a time tick. S << 151 * immediately before the timer ISR calls sos_ << 152 * returning to thread context. << 153 * << 154 * @note The use of this function is RESERVED << 155 */ << 156 sos_ret_t sos_sched_do_timer_tick(); << 157 074 158 #endif /* _SOS_WAITQUEUE_H_ */ 075 #endif /* _SOS_WAITQUEUE_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |