source: trunk/kernel/kern/scheduler.h @ 93

Last change on this file since 93 was 14, checked in by alain, 8 years ago

Bugs fix.

File size: 7.9 KB
Line 
1/*
2 * scheduler.h - Core scheduler definition.
3 *
4 * Author    Alain Greiner (2016)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _SCHEDULER_H_
25#define _SCHEDULER_H_
26
27#include <hal_types.h>
28#include <list.h>
29#include <spinlock.h>
30
31/****  Forward declarations  ****/
32
33struct core_s;
34struct thread_s;
35
36/***********************************************************************************************
37 * This structure define the scheduler associated to a given core.
38 * WARNING : the idle thread is executed when there is no runable thread in the list
39 * of attached threads, but is NOT part of the list of attached threads.
40 **********************************************************************************************/
41
42typedef struct scheduler_s
43{
44    spinlock_t        lock;         /*! readlock protecting lists of threads                  */
45    uint16_t          u_threads_nr; /*! total numbre of attached user threads                 */
46    uint16_t          k_threads_nr; /*! total number of attached kernel threads               */
47    list_entry_t      u_root;       /*! root of list of user threads for this scheduler       */
48    list_entry_t      k_root;       /*! root of list of kernel threads for this scheduler     */
49    list_entry_t    * u_last;       /*! pointer on list_entry for last executed kernel thread */
50    list_entry_t    * k_last;       /*! pointer on list entry for last executed user thread   */
51    struct thread_s * idle;         /*! pointer on idle thread                                */
52    struct thread_s * current;      /*! pointer on current running thread                     */
53}
54scheduler_t;
55
56/***********************************************************************************************
57 *  This function initialises the scheduler for a given core.
58 **********************************************************************************************/ 
59void sched_init( struct core_s * core );
60
61/***********************************************************************************************
62 * This function register a new thread in a given core scheduler.
63 ***********************************************************************************************
64 * @ core    : local pointer on the core descriptor.
65 * @ thread  : local pointer on the thread descriptor.
66 **********************************************************************************************/ 
67void sched_register_thread( struct core_s   * core,
68                            struct thread_s * thread );
69
70/***********************************************************************************************
71 *  This function removes a thread from the set of threads attached to a given core.
72 ***********************************************************************************************
73 * @ thread  : local pointer on the thread descriptor.
74 **********************************************************************************************/ 
75void sched_remove_thread( struct thread_s * thread );
76
77/***********************************************************************************************
78 * This function handles pending signals for all registered threads, and tries to make
79 * a context switch for the core running the calling thread.
80 * - If there is a runable thread (other than the current thread or the idle thread),
81 *   the calling thread is descheduled, but its state is not modified.
82 * - If there is no other runable thread, the calling thread continues execution.
83 * - If there is no runable thread, the idle thread is executed.
84 **********************************************************************************************/
85void sched_yield();
86
87/***********************************************************************************************
88 * This function handles pending signals for all registered threads, and make
89 * a context switch to the thread defined by the <thread> argument.
90 * If the selected thread is not attached to the same core as the calling thread,
91 * or is blocked, it causes a kernel panic.
92 ***********************************************************************************************
93 * @ new   : local pointer on the thread to run.
94 **********************************************************************************************/
95void sched_switch_to( struct thread_s * new );
96
97/***********************************************************************************************
98 * This function scan all threads attached to a given core scheduler, and executes
99 * the relevant actions for pending signals, such as the THREAD_SIG_KILL signal.
100 ***********************************************************************************************
101 * @ core    : local pointer on the core descriptor.
102 **********************************************************************************************/
103void sched_handle_signals( struct core_s * core );
104
105/***********************************************************************************************
106 * This function is used by the scheduler of a given core to actually kill a thread that has
107 * the SIG_KILL signal set (following a thread_exit() or a thread_kill() event).
108 * - It checks that the thread has released all locks => panic otherwise...
109 * - It detach the thread from the local process descriptor.
110 * - It removes the thread from the scheduler.
111 * - It release physical memory allocated for thread descriptor.
112 ***********************************************************************************************
113 * @ thread  : local pointer on the thread descriptor.
114 **********************************************************************************************/
115void sched_kill_thread( struct thread_s * thread );
116
117/***********************************************************************************************
118 * This function does NOT modify the scheduler state.
119 * It just select a thread in the list of attached threads, implementing the following policy:
120 * 1) it scan the list of kernel threads, from the next thread after the last executed one,
121 *    and returns the first runnable found (can be the current thread).
122 * 2) if no kernel thread found, it scan the list of user thread, from the next thread after
123 *    the last executed one, and returns the first runable found (can be the current thread).
124 * 3) if no runable thread found, it returns the idle thread.
125 ***********************************************************************************************
126 * @ core    : local pointer on the core descriptor.
127 * @ returns pointer on selected thread descriptor
128 **********************************************************************************************/
129struct thread_s * sched_select( struct core_s * core );
130
131/***********************************************************************************************
132 * This function scan the list of kernel threads to find an idle (blocked) RPC thread.
133 ***********************************************************************************************
134 * @ core    : local pointer on the core descriptor.
135 * @ returns pointer on RPC thread descriptor / returns NULL if no idle RPC thread.
136 **********************************************************************************************/
137struct thread_s * sched_get_rpc_thead( struct core_s * core );
138
139
140
141#endif  /* _SCHEDULER_H_ */
Note: See TracBrowser for help on using the repository browser.