|
[ 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 inspired from the O(1) Linux scheduler. Supports 026 * 2 classes of thread priorities: 026 * 2 classes of thread priorities: 027 * - so-called 'real-time' threads scheduled 027 * - so-called 'real-time' threads scheduled according to a simple 028 * traditional static priority real-time sc 028 * traditional static priority real-time scheduler. "Real-time" round 029 * robin scheduling is not supported. 029 * robin scheduling is not supported. 030 * - "fair" time-sharing scheduling for non re 030 * - "fair" time-sharing scheduling for non real-time threads. "fair" 031 * because no starvation among the non real 031 * because no starvation among the non real-time threads is 032 * possible. Contrary to the original O(1) 032 * possible. Contrary to the original O(1) Linux scheduler, the 033 * on-line adjustment of the scheduling pri 033 * on-line adjustment of the scheduling priorities to cope with 034 * interactive/non interactive threads disc 034 * interactive/non interactive threads discrimination is not 035 * supported: threads keep having the same 035 * supported: threads keep having the same priority as long as the 036 * user does not change it. 036 * user does not change it. 037 * 037 * 038 * The functions below manage CPU queues, and 038 * The functions below manage CPU queues, and are NEVER responsible 039 * for context switches (see thread.h for that 039 * for context switches (see thread.h for that) or synchronizations 040 * (see kwaitq.h or the higher levels primitiv 040 * (see kwaitq.h or the higher levels primitives [mutex, semaphore, 041 * ...] for that). 041 * ...] for that). 042 * 042 * 043 * @note IMPORTANT: all the functions below ar 043 * @note IMPORTANT: all the functions below are meant to be called 044 * ONLY by the thread/timer/kwaitq subsystems. 044 * ONLY by the thread/timer/kwaitq subsystems. DO NOT use them 045 * directly from anywhere else: use ONLY the t 045 * directly from anywhere else: use ONLY the thread/kwaitq functions! 046 * If you still want to call them directly des 046 * If you still want to call them directly despite this disclaimer, 047 * simply disable interrupts before clling the 047 * simply disable interrupts before clling them. 048 */ 048 */ 049 049 050 #include <sos/errno.h> 050 #include <sos/errno.h> 051 #include <sos/time.h> 051 #include <sos/time.h> 052 052 053 053 054 /** 054 /** 055 * The definition of a priority 055 * The definition of a priority 056 */ 056 */ 057 typedef unsigned char sos_sched_priority_t; 057 typedef unsigned char sos_sched_priority_t; 058 058 059 059 060 #include <sos/thread.h> 060 #include <sos/thread.h> 061 061 062 062 063 /** 063 /** 064 * Valid priority interval ("real-time" and no 064 * Valid priority interval ("real-time" and non real-time threads altogether) 065 */ 065 */ 066 #define SOS_SCHED_PRIO_HIGHEST 0 066 #define SOS_SCHED_PRIO_HIGHEST 0 067 #define SOS_SCHED_PRIO_LOWEST 63 067 #define SOS_SCHED_PRIO_LOWEST 63 068 #define SOS_SCHED_NUM_PRIO 64 068 #define SOS_SCHED_NUM_PRIO 64 069 069 070 070 071 /** 071 /** 072 * Class-specific priorities 072 * Class-specific priorities 073 */ 073 */ 074 #define SOS_SCHED_PRIO_RT_HIGHEST 0 /**< High 074 #define SOS_SCHED_PRIO_RT_HIGHEST 0 /**< Highest 'real-time' static prio. */ 075 #define SOS_SCHED_PRIO_RT_LOWEST 15 /**< Lowe 075 #define SOS_SCHED_PRIO_RT_LOWEST 15 /**< Lowest 'real-time' static priority */ 076 #define SOS_SCHED_PRIO_TS_HIGHEST 16 /**< High 076 #define SOS_SCHED_PRIO_TS_HIGHEST 16 /**< Highest time-sharing priority */ 077 #define SOS_SCHED_PRIO_TS_LOWEST 63 /**< Lowe 077 #define SOS_SCHED_PRIO_TS_LOWEST 63 /**< Lowest time-sharing priority */ 078 078 079 #define SOS_SCHED_PRIO_DEFAULT 40 /**< Defa 079 #define SOS_SCHED_PRIO_DEFAULT 40 /**< Default priority */ 080 080 081 081 082 /** 082 /** 083 * Helper macros (Yes, priorities ordered in d 083 * Helper macros (Yes, priorities ordered in decreasing numerical value) 084 * 084 * 085 * @note: The use of this function is RESERVED 085 * @note: The use of this function is RESERVED 086 */ 086 */ 087 #define SOS_SCHED_PRIO_CMP(prio1,prio2) ((pri 087 #define SOS_SCHED_PRIO_CMP(prio1,prio2) ((prio1) - (prio2)) 088 088 089 #define SOS_SCHED_PRIO_IS_VALID(prio) \ 089 #define SOS_SCHED_PRIO_IS_VALID(prio) \ 090 ({ int __prio = (int)(prio); \ 090 ({ int __prio = (int)(prio); \ 091 ((__prio) <= SOS_SCHED_PRIO_LOWEST) \ 091 ((__prio) <= SOS_SCHED_PRIO_LOWEST) \ 092 && \ 092 && \ 093 ((__prio) >= SOS_SCHED_PRIO_HIGHEST); }) 093 ((__prio) >= SOS_SCHED_PRIO_HIGHEST); }) 094 094 095 #define SOS_SCHED_PRIO_IS_RT(prio) \ 095 #define SOS_SCHED_PRIO_IS_RT(prio) \ 096 ({ int __prio = (int)(prio); \ 096 ({ int __prio = (int)(prio); \ 097 ((__prio) <= SOS_SCHED_PRIO_RT_LOWEST) \ 097 ((__prio) <= SOS_SCHED_PRIO_RT_LOWEST) \ 098 && \ 098 && \ 099 ((__prio) >= SOS_SCHED_PRIO_RT_HIGHEST); 099 ((__prio) >= SOS_SCHED_PRIO_RT_HIGHEST); }) 100 100 101 101 102 /** 102 /** 103 * The time slices for 'time-sharing' user thr 103 * The time slices for 'time-sharing' user threads, in ms 104 */ 104 */ 105 #define SOS_TIME_SLICE_MIN 10 /* for SOS_SCHE 105 #define SOS_TIME_SLICE_MIN 10 /* for SOS_SCHED_PRIO_TS_HIGHEST */ 106 #define SOS_TIME_SLICE_MAX 200 /* for SOS_SCHE 106 #define SOS_TIME_SLICE_MAX 200 /* for SOS_SCHED_PRIO_TS_LOWEST */ 107 107 108 108 109 /** 109 /** 110 * Initialize the scheduler 110 * Initialize the scheduler 111 * 111 * 112 * @note: The use of this function is RESERVED 112 * @note: The use of this function is RESERVED 113 */ 113 */ 114 sos_ret_t sos_sched_subsystem_setup(); 114 sos_ret_t sos_sched_subsystem_setup(); 115 115 116 116 117 /** 117 /** 118 * Mark the given thread as ready 118 * Mark the given thread as ready 119 * 119 * 120 * @note: The use of this function is RESERVED 120 * @note: The use of this function is RESERVED 121 */ 121 */ 122 sos_ret_t sos_sched_set_ready(struct sos_threa 122 sos_ret_t sos_sched_set_ready(struct sos_thread * thr); 123 123 124 124 125 /** 125 /** 126 * Return the identifier of the next thread to 126 * Return the identifier of the next thread to run. Also removes it 127 * from the ready list, but does NOT set is as 127 * from the ready list, but does NOT set is as current_thread ! 128 * 128 * 129 * @param current_thread TCB of the thread cal 129 * @param current_thread TCB of the thread calling the function 130 * 130 * 131 * @param do_yield When TRUE, put the current 131 * @param do_yield When TRUE, put the current executing thread at the 132 * end of the ready list. Otherwise it is kept 132 * end of the ready list. Otherwise it is kept at the head of it. 133 * 133 * 134 * @note: The use of this function is RESERVED 134 * @note: The use of this function is RESERVED 135 */ 135 */ 136 struct sos_thread * sos_reschedule(struct sos_ 136 struct sos_thread * sos_reschedule(struct sos_thread * current_thread, 137 sos_bool_t 137 sos_bool_t do_yield); 138 138 139 /** 139 /** 140 * Called by thread subsystem each time a READ 140 * Called by thread subsystem each time a READY thread's priority is 141 * changed 141 * changed 142 * 142 * 143 * @note: The use of this function is RESERVED 143 * @note: The use of this function is RESERVED (to thread.c) 144 */ 144 */ 145 sos_ret_t sos_sched_change_priority(struct sos 145 sos_ret_t sos_sched_change_priority(struct sos_thread * thr, 146 sos_sched_ 146 sos_sched_priority_t priority); 147 147 148 148 149 /** 149 /** 150 * Account for the execution of a time tick. S 150 * Account for the execution of a time tick. Should be called 151 * immediately before the timer ISR calls sos_ 151 * immediately before the timer ISR calls sos_reschedule() before 152 * returning to thread context. 152 * returning to thread context. 153 * 153 * 154 * @note The use of this function is RESERVED 154 * @note The use of this function is RESERVED (to timer IRQ) 155 */ 155 */ 156 sos_ret_t sos_sched_do_timer_tick(); 156 sos_ret_t sos_sched_do_timer_tick(); 157 157 158 #endif /* _SOS_WAITQUEUE_H_ */ 158 #endif /* _SOS_WAITQUEUE_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |