1 //==========================================================================
5 // POSIX scheduler API implementation
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
44 // Contributors: nickg
46 // Purpose: POSIX scheduler API implementation
47 // Description: This file contains the implementation of the POSIX scheduler
52 //####DESCRIPTIONEND####
54 //==========================================================================
56 #include <pkgconf/hal.h>
57 #include <pkgconf/kernel.h>
58 #include <pkgconf/posix.h>
60 #include <cyg/kernel/ktypes.h> // base kernel types
61 #include <cyg/infra/cyg_trac.h> // tracing macros
62 #include <cyg/infra/cyg_ass.h> // assertion macros
64 #include "pprivate.h" // POSIX private header
66 #include <cyg/kernel/sched.hxx> // scheduler definitions
67 #include <cyg/kernel/thread.hxx> // thread definitions
69 #include <cyg/kernel/sched.inl> // scheduler inlines
70 #include <cyg/kernel/thread.inl> // thread inlines
72 //==========================================================================
73 // Process scheduling functions.
75 //--------------------------------------------------------------------------
76 // Set scheduling parameters for given process.
78 int sched_setparam (pid_t pid, const struct sched_param *param)
80 CYG_REPORT_FUNCTYPE( "returning %d" );
85 CYG_REPORT_RETVAL( -1 );
90 CYG_REPORT_RETVAL( -1 );
94 //--------------------------------------------------------------------------
95 // Get scheduling parameters for given process.
97 int sched_getparam (pid_t pid, struct sched_param *param)
99 CYG_REPORT_FUNCTYPE( "returning %d" );
104 CYG_REPORT_RETVAL( -1 );
109 CYG_REPORT_RETVAL( -1 );
113 //--------------------------------------------------------------------------
114 // Set scheduling policy and/or parameters for given process.
115 int sched_setscheduler (pid_t pid,
117 const struct sched_param *param)
119 CYG_REPORT_FUNCTYPE( "returning %d" );
124 CYG_REPORT_RETVAL( -1 );
129 CYG_REPORT_RETVAL( -1 );
134 //--------------------------------------------------------------------------
135 // Get scheduling policy for given process.
137 int sched_getscheduler (pid_t pid)
139 CYG_REPORT_FUNCTYPE( "returning %d" );
144 CYG_REPORT_RETVAL( 0 );
149 CYG_REPORT_RETVAL( -1 );
153 //--------------------------------------------------------------------------
154 // Force current thread to relinquish the processor.
156 int sched_yield (void)
158 CYG_REPORT_FUNCTYPE( "returning %d" );
162 CYG_REPORT_RETVAL( 0 );
167 //==========================================================================
168 // Scheduler parameter limits.
170 //--------------------------------------------------------------------------
171 // Get maximum priority value for a policy.
173 int sched_get_priority_max (int policy)
175 CYG_REPORT_FUNCTYPE( "returning %d" );
177 if( policy != SCHED_FIFO &&
178 policy != SCHED_RR &&
179 policy != SCHED_OTHER )
182 CYG_REPORT_RETVAL( -1 );
186 int pri = PTHREAD_POSIX_PRIORITY( CYG_THREAD_MAX_PRIORITY );
188 CYG_REPORT_RETVAL( pri );
192 //--------------------------------------------------------------------------
193 // Get minimum priority value for a policy.
195 int sched_get_priority_min (int policy)
197 CYG_REPORT_FUNCTYPE( "returning %d" );
199 if( policy != SCHED_FIFO &&
200 policy != SCHED_RR &&
201 policy != SCHED_OTHER )
204 CYG_REPORT_RETVAL( -1 );
208 // idle thread priority isn't valid for general use, so subtract 1
209 int pri = PTHREAD_POSIX_PRIORITY( CYG_THREAD_MIN_PRIORITY-1 );
211 CYG_REPORT_RETVAL( pri );
215 //--------------------------------------------------------------------------
216 // Get the SCHED_RR interval for the given process.
218 int sched_rr_get_interval (pid_t pid, struct timespec *t)
220 CYG_REPORT_FUNCTYPE( "returning %d" );
222 #ifdef CYGPKG_POSIX_CLOCKS
226 CYG_REPORT_RETVAL( -1 );
230 cyg_ticks_to_timespec( CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS, t );
232 CYG_REPORT_RETVAL( 0 );
236 CYG_REPORT_RETVAL( -1 );
241 // -------------------------------------------------------------------------