SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2004 David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 #ifndef _SOS_SCHED_H_
019 #define _SOS_SCHED_H_
020 
021 
022 /**
023  * @file sched.h
024  *
025  * A basic scheduler inspired from the O(1) Linux scheduler. Supports
026  * 2 classes of thread priorities:
027  *  - so-called 'real-time' threads scheduled according to a simple
028  *    traditional static priority real-time scheduler. "Real-time" round
029  *    robin scheduling is not supported.
030  * - "fair" time-sharing scheduling for non real-time threads. "fair"
031  *    because no starvation among the non real-time threads is
032  *    possible. Contrary to the original O(1) Linux scheduler, the
033  *    on-line adjustment of the scheduling priorities to cope with
034  *    interactive/non interactive threads discrimination is not
035  *    supported: threads keep having the same priority as long as the
036  *    user does not change it.
037  *
038  * The functions below manage CPU queues, and are NEVER responsible
039  * for context switches (see thread.h for that) or synchronizations
040  * (see kwaitq.h or the higher levels primitives [mutex, semaphore,
041  * ...] for that).
042  *
043  * @note IMPORTANT: all the functions below are meant to be called
044  * ONLY by the thread/timer/kwaitq subsystems. DO NOT use them
045  * directly from anywhere else: use ONLY the thread/kwaitq functions!
046  * If you still want to call them directly despite this disclaimer,
047  * simply disable interrupts before clling them.
048  */
049 
050 #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 
059 
060 #include <sos/thread.h>
061 
062 
063 /**
064  * Valid priority interval ("real-time" and non real-time threads altogether)
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  /**< Highest 'real-time' static prio. */
075 #define SOS_SCHED_PRIO_RT_LOWEST  15 /**< Lowest 'real-time' static priority */
076 #define SOS_SCHED_PRIO_TS_HIGHEST 16 /**< Highest time-sharing priority */
077 #define SOS_SCHED_PRIO_TS_LOWEST  63 /**< Lowest time-sharing priority */
078 
079 #define SOS_SCHED_PRIO_DEFAULT 40    /**< Default priority */
080 
081 
082 /**
083  * Helper macros (Yes, priorities ordered in decreasing numerical value)
084  *
085  * @note: The use of this function is RESERVED
086  */
087 #define SOS_SCHED_PRIO_CMP(prio1,prio2)  ((prio1) - (prio2))
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 threads, in ms
104  */
105 #define SOS_TIME_SLICE_MIN  10 /* for SOS_SCHED_PRIO_TS_HIGHEST */
106 #define SOS_TIME_SLICE_MAX 200 /* for SOS_SCHED_PRIO_TS_LOWEST */
107 
108 
109 /**
110  * Initialize the scheduler
111  *
112  * @note: The use of this function is RESERVED
113  */
114 sos_ret_t sos_sched_subsystem_setup(void);
115 
116 
117 /**
118  * Mark the given thread as ready
119  *
120  * @note: The use of this function is RESERVED
121  */
122 sos_ret_t sos_sched_set_ready(struct sos_thread * thr);
123 
124 
125 /**
126  * Return the identifier of the next thread to run. Also removes it
127  * from the ready list, but does NOT set is as current_thread !
128  *
129  * @param current_thread TCB of the thread calling the function
130  *
131  * @param do_yield When TRUE, put the current executing thread at the
132  * end of the ready list. Otherwise it is kept at the head of it.
133  *
134  * @note: The use of this function is RESERVED
135  */
136 struct sos_thread * sos_reschedule(struct sos_thread * current_thread,
137                                     sos_bool_t do_yield);
138 
139 /**
140  * Called by thread subsystem each time a READY thread's priority is
141  * changed
142  *
143  * @note: The use of this function is RESERVED (to thread.c)
144  */
145 sos_ret_t sos_sched_change_priority(struct sos_thread * thr,
146                                     sos_sched_priority_t priority);
147 
148 
149 /**
150  * Account for the execution of a time tick. Should be called
151  * immediately before the timer ISR calls sos_reschedule() before
152  * returning to thread context.
153  *
154  * @note The use of this function is RESERVED (to timer IRQ)
155  */
156 sos_ret_t sos_sched_do_timer_tick(void);
157 
158 #endif /* _SOS_WAITQUEUE_H_ */

source navigation ] diff markup ] identifier search ] general search ]