OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [include/] [mlqueue.hxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_KERNEL_MLQUEUE_HXX
2
#define CYGONCE_KERNEL_MLQUEUE_HXX
3
 
4
//==========================================================================
5
//
6
//      mlqueue.hxx
7
//
8
//      Multi-Level Queue scheduler class declarations
9
//
10
//==========================================================================
11
// ####ECOSGPLCOPYRIGHTBEGIN####
12
// -------------------------------------------
13
// This file is part of eCos, the Embedded Configurable Operating System.
14
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
15
//
16
// eCos is free software; you can redistribute it and/or modify it under
17
// the terms of the GNU General Public License as published by the Free
18
// Software Foundation; either version 2 or (at your option) any later
19
// version.
20
//
21
// eCos is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with eCos; if not, write to the Free Software Foundation, Inc.,
28
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29
//
30
// As a special exception, if other files instantiate templates or use
31
// macros or inline functions from this file, or you compile this file
32
// and link it with other works to produce a work based on this file,
33
// this file does not by itself cause the resulting work to be covered by
34
// the GNU General Public License. However the source code for this file
35
// must still be made available in accordance with section (3) of the GNU
36
// General Public License v2.
37
//
38
// This exception does not invalidate any other reasons why a work based
39
// on this file might be covered by the GNU General Public License.
40
// -------------------------------------------
41
// ####ECOSGPLCOPYRIGHTEND####
42
//==========================================================================
43
//#####DESCRIPTIONBEGIN####
44
//
45
// Author(s):    nickg
46
// Contributors: jlarmour
47
// Date:         1997-09-10
48
// Purpose:      Define multilevel queue scheduler implementation
49
// Description:  The classes defined here are used as base classes
50
//               by the common classes that define schedulers and thread
51
//               things. The MLQ scheduler in various configurations
52
//               provides standard FIFO, round-robin and single priority
53
//               schedulers.
54
// Usage:        Included according to configuration by
55
//               
56
//
57
//####DESCRIPTIONEND####
58
//
59
//==========================================================================
60
 
61
#include 
62
 
63
#include                   // List implementation
64
 
65
// -------------------------------------------------------------------------
66
// The macro CYGNUM_KERNEL_SCHED_PRIORITIES contains the number of priorities
67
// supported by the scheduler.
68
 
69
#ifndef CYGNUM_KERNEL_SCHED_PRIORITIES
70
#define CYGNUM_KERNEL_SCHED_PRIORITIES 32       // define a default
71
#endif
72
 
73
// set bitmap size
74
#define CYGNUM_KERNEL_SCHED_BITMAP_SIZE CYGNUM_KERNEL_SCHED_PRIORITIES
75
 
76
// -------------------------------------------------------------------------
77
// The macro CYGNUM_KERNEL_SCHED_BITMAP_SIZE contains the number of bits that the
78
// scheduler bitmap should contain. It is derived from the number of prioirity
79
// levels defined by the configuration.
80
 
81
#if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8
82
typedef cyg_ucount8 cyg_sched_bitmap;
83
#elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16
84
typedef cyg_ucount16 cyg_sched_bitmap;
85
#elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32
86
typedef cyg_ucount32 cyg_sched_bitmap;
87
#else
88
#error Bitmaps greater than 32 bits not currently allowed
89
#endif
90
 
91
// -------------------------------------------------------------------------
92
// Customize the scheduler
93
 
94
#define CYGIMP_THREAD_PRIORITY  1       // Threads have changable priorities
95
 
96
#define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES-1)
97
#define CYG_THREAD_MAX_PRIORITY 0
98
 
99
// set default scheduling info value for thread constructors.
100
#define CYG_SCHED_DEFAULT_INFO  CYG_THREAD_MAX_PRIORITY
101
 
102
// -------------------------------------------------------------------------
103
// scheduler Run queue object
104
 
105
typedef Cyg_CList_T Cyg_RunQueue;
106
 
107
// -------------------------------------------------------------------------
108
// Thread queue implementation.
109
// This class provides the (scheduler specific) implementation of the
110
// thread queue class.
111
 
112
class Cyg_ThreadQueue_Implementation
113
    : public Cyg_CList_T
114
{
115
    friend class Cyg_Scheduler_Implementation;
116
    friend class Cyg_SchedThread_Implementation;
117
 
118
    void                set_thread_queue(Cyg_Thread *thread,
119
                                         Cyg_ThreadQueue *tq );
120
 
121
protected:
122
 
123
    // API used by Cyg_ThreadQueue
124
 
125
    Cyg_ThreadQueue_Implementation() {};   // Constructor
126
 
127
                                        // Add thread to queue
128
    void                enqueue(Cyg_Thread *thread);
129
 
130
                                        // return first thread on queue
131
    Cyg_Thread          *highpri();
132
 
133
                                        // remove first thread on queue
134
    Cyg_Thread          *dequeue();
135
 
136
                                        // Remove thread from queue
137
    void                remove(Cyg_Thread *thread);
138
 
139
};
140
 
141
// -------------------------------------------------------------------------
142
// This class contains the implementation details of the scheduler, and
143
// provides a standard API for accessing it.
144
 
145
class Cyg_Scheduler_Implementation
146
    : public Cyg_Scheduler_Base
147
{
148
    friend class Cyg_ThreadQueue_Implementation;
149
    friend class Cyg_SchedThread_Implementation;
150
    friend class Cyg_HardwareThread;
151
    friend void cyg_scheduler_set_need_reschedule();
152
 
153
    // Mask of which run queues have ready threads
154
    cyg_sched_bitmap    queue_map;
155
 
156
    // Each run queue is a double linked circular list of threads.
157
    // These pointers point to the head element of each list.
158
    Cyg_RunQueue run_queue[CYGNUM_KERNEL_SCHED_PRIORITIES];
159
 
160
#ifdef CYGPKG_KERNEL_SMP_SUPPORT
161
 
162
    // In SMP systems we additionally keep a counter for each priority
163
    // of the number of pending but not running threads in each queue.
164
 
165
    cyg_uint32 pending[CYGNUM_KERNEL_SCHED_PRIORITIES];
166
 
167
    cyg_sched_bitmap pending_map;
168
 
169
#endif
170
 
171
protected:
172
 
173
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
174
 
175
    // Timeslice counter. This is decremented on each
176
    // clock tick, and a timeslice is performed each
177
    // time it zeroes.
178
 
179
    static cyg_ucount32 timeslice_count[CYGNUM_KERNEL_CPU_MAX]
180
                                        CYGBLD_ANNOTATE_VARIABLE_SCHED;
181
 
182
#endif
183
 
184
    Cyg_Scheduler_Implementation();     // Constructor
185
 
186
    // The following functions provide the scheduler implementation
187
    // interface to the Cyg_Scheduler class. These are protected
188
    // so that only the scheduler can call them.
189
 
190
    // choose a new thread
191
    Cyg_Thread  *schedule();
192
 
193
    // make thread schedulable
194
    void        add_thread(Cyg_Thread *thread);
195
 
196
    // make thread un-schedulable
197
    void        rem_thread(Cyg_Thread *thread);
198
 
199
    // register thread with scheduler
200
    void        register_thread(Cyg_Thread *thread);
201
 
202
    // deregister thread
203
    void        deregister_thread(Cyg_Thread *thread);
204
 
205
    // Test the given priority for uniqueness
206
    cyg_bool    unique( cyg_priority priority);
207
 
208
    // Set need_reschedule if the supplied thread is of lower
209
    // priority than any that are currently running.
210
    static void set_need_reschedule( Cyg_Thread *thread );
211
    static void set_need_reschedule();
212
 
213
public:
214
    void set_idle_thread( Cyg_Thread *thread, HAL_SMP_CPU_TYPE cpu );
215
 
216
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
217
 
218
    // If timeslicing is enbled, define a scheduler
219
    // entry points to do timeslicing. This will be
220
    // called from the RTC DSR.
221
public:
222
    void timeslice();
223
    void timeslice_cpu();
224
 
225
#endif
226
 
227
};
228
 
229
// -------------------------------------------------------------------------
230
// Cyg_Scheduler_Implementation inlines
231
 
232
inline void Cyg_Scheduler_Implementation::set_need_reschedule()
233
{
234
    need_reschedule[CYG_KERNEL_CPU_THIS()] = true;
235
}
236
 
237
 
238
// -------------------------------------------------------------------------
239
// Scheduler thread implementation.
240
// This class provides the implementation of the scheduler specific parts
241
// of each thread.
242
 
243
class Cyg_SchedThread_Implementation
244
    : public Cyg_DNode_T
245
{
246
    friend class Cyg_Scheduler_Implementation;
247
    friend class Cyg_ThreadQueue_Implementation;
248
 
249
protected:
250
 
251
    cyg_priority        priority;       // current thread priority
252
 
253
#ifdef CYGPKG_KERNEL_SMP_SUPPORT
254
    HAL_SMP_CPU_TYPE    cpu;            // CPU id of cpu currently running
255
                                        // this thread, or CYG_KERNEL_CPU_NONE
256
                                        // if not running.
257
#endif
258
 
259
    Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info);
260
 
261
    void yield();                       // Yield CPU to next thread
262
 
263
    static void rotate_queue( cyg_priority pri );
264
                                        // Rotate that run queue
265
 
266
    void to_queue_head( void );         // Move this thread to the head
267
                                        // of its queue (not necessarily
268
                                        // a scheduler queue)
269
 
270
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
271
 
272
    cyg_ucount32 timeslice_count;
273
 
274
    void timeslice_save();
275
 
276
    void timeslice_restore();
277
 
278
    void timeslice_reset();
279
 
280
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE_ENABLE
281
 
282
    // This defines whether this thread is subject to timeslicing.
283
    // If false, timeslice expiry has no effect on the thread.
284
 
285
    cyg_bool            timeslice_enabled;
286
 
287
public:
288
 
289
    void timeslice_enable();
290
 
291
    void timeslice_disable();
292
 
293
#endif
294
 
295
#else
296
 
297
    inline void timeslice_save() {};
298
    inline void timeslice_restore() {};
299
    inline void timeslice_reset() {};
300
 
301
#endif
302
 
303
};
304
 
305
// -------------------------------------------------------------------------
306
// Cyg_SchedThread_Implementation inlines.
307
 
308
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
309
 
310
inline void Cyg_SchedThread_Implementation::timeslice_save()
311
{
312
    timeslice_count = Cyg_Scheduler_Implementation::timeslice_count[CYG_KERNEL_CPU_THIS()];
313
}
314
 
315
inline void Cyg_SchedThread_Implementation::timeslice_restore()
316
{
317
    Cyg_Scheduler_Implementation::timeslice_count[CYG_KERNEL_CPU_THIS()] = timeslice_count;
318
}
319
 
320
inline void Cyg_SchedThread_Implementation::timeslice_reset()
321
{
322
    timeslice_count = CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS;
323
}
324
 
325
#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE_ENABLE
326
 
327
inline void Cyg_SchedThread_Implementation::timeslice_enable()
328
{
329
    timeslice_enabled = true;
330
}
331
 
332
inline void Cyg_SchedThread_Implementation::timeslice_disable()
333
{
334
    timeslice_enabled = false;
335
}
336
 
337
#endif
338
 
339
#endif
340
 
341
 
342
// -------------------------------------------------------------------------
343
#endif // ifndef CYGONCE_KERNEL_MLQUEUE_HXX
344
// EOF mlqueue.hxx

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.