[1] | 1 | /* |
---|
| 2 | * thread.h - Thread and related operations definition. |
---|
[174] | 3 | * |
---|
[1] | 4 | * Author Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
[625] | 5 | * Alain Greiner (2016,2017,2018,2019) |
---|
[1] | 6 | * |
---|
| 7 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 8 | * |
---|
| 9 | * This file is part of ALMOS-MKH. |
---|
| 10 | * |
---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 14 | * |
---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef _THREAD_H_ |
---|
| 26 | #define _THREAD_H_ |
---|
| 27 | |
---|
[457] | 28 | #include <hal_kernel_types.h> |
---|
[407] | 29 | #include <shared_syscalls.h> |
---|
[1] | 30 | #include <hal_special.h> |
---|
[625] | 31 | #include <hal_kentry.h> |
---|
[1] | 32 | #include <xlist.h> |
---|
| 33 | #include <list.h> |
---|
| 34 | #include <hal_context.h> |
---|
[564] | 35 | #include <remote_busylock.h> |
---|
[1] | 36 | #include <core.h> |
---|
[408] | 37 | #include <chdev.h> |
---|
[1] | 38 | #include <cluster.h> |
---|
| 39 | #include <process.h> |
---|
| 40 | #include <dev_ioc.h> |
---|
| 41 | #include <dev_nic.h> |
---|
| 42 | #include <dev_txt.h> |
---|
| 43 | #include <dev_mmc.h> |
---|
[5] | 44 | #include <dev_dma.h> |
---|
[1] | 45 | |
---|
| 46 | /*************************************************************************************** |
---|
[409] | 47 | * These macros are used to compose or decompose the global thread identifier (TRDID) |
---|
[23] | 48 | * to or from cluster identifier / local thread index (CXY , LTID) |
---|
[1] | 49 | **************************************************************************************/ |
---|
| 50 | |
---|
[174] | 51 | #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF) |
---|
[23] | 52 | #define CXY_FROM_TRDID( trdid ) (cxy_t)(trdid >> 16) |
---|
| 53 | #define TRDID( cxy , ltid ) (trdid_t)((cxy << 16) | ltid ) |
---|
[1] | 54 | |
---|
| 55 | /*************************************************************************************** |
---|
| 56 | * This enum defines the thread types. |
---|
| 57 | **************************************************************************************/ |
---|
| 58 | |
---|
| 59 | typedef enum |
---|
[174] | 60 | { |
---|
| 61 | THREAD_USER = 0, /*! user thread (pthread) */ |
---|
[1] | 62 | THREAD_RPC = 1, /*! kernel thread executing pending RPCs */ |
---|
| 63 | THREAD_DEV = 2, /*! kernel thread executing I/O device commands */ |
---|
[407] | 64 | THREAD_IDLE = 3, /*! kernel idle thread */ |
---|
[174] | 65 | } |
---|
[1] | 66 | thread_type_t; |
---|
| 67 | |
---|
| 68 | /*************************************************************************************** |
---|
[23] | 69 | * This defines the thread flags bit-vector. |
---|
[1] | 70 | **************************************************************************************/ |
---|
| 71 | |
---|
[409] | 72 | #define THREAD_FLAG_DETACHED 0x0001 /*! This thread is detached from parent */ |
---|
[436] | 73 | #define THREAD_FLAG_JOIN_DONE 0x0002 /*! Parent thread made a join request */ |
---|
| 74 | #define THREAD_FLAG_KILL_DONE 0x0004 /*! This thread received a kill request */ |
---|
| 75 | #define THREAD_FLAG_REQ_ACK 0x0010 /*! Acknowledge required from scheduler */ |
---|
| 76 | #define THREAD_FLAG_REQ_DELETE 0x0020 /*! Destruction required from scheduler */ |
---|
[1] | 77 | |
---|
| 78 | /*************************************************************************************** |
---|
[443] | 79 | * This defines the thread blocking causes bit-vector. |
---|
[1] | 80 | **************************************************************************************/ |
---|
| 81 | |
---|
[174] | 82 | #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread deactivated / wait activation */ |
---|
[1] | 83 | #define THREAD_BLOCKED_IO 0x0002 /*! thread wait IO operation completion */ |
---|
| 84 | #define THREAD_BLOCKED_MAPPER 0x0004 /*! thread wait mapper */ |
---|
[409] | 85 | #define THREAD_BLOCKED_EXIT 0x0008 /*! thread blocked in join / wait exit */ |
---|
| 86 | #define THREAD_BLOCKED_JOIN 0x0010 /*! thread blocked in exit / wait join */ |
---|
| 87 | #define THREAD_BLOCKED_SEM 0x0020 /*! thread wait semaphore */ |
---|
| 88 | #define THREAD_BLOCKED_PAGE 0x0040 /*! thread wait page access */ |
---|
[438] | 89 | #define THREAD_BLOCKED_IDLE 0x0080 /*! thread RPC wait RPC_FIFO non empty */ |
---|
[409] | 90 | #define THREAD_BLOCKED_USERSYNC 0x0100 /*! thread wait (cond/mutex/barrier) */ |
---|
[407] | 91 | #define THREAD_BLOCKED_RPC 0x0200 /*! thread wait RPC completion */ |
---|
[436] | 92 | #define THREAD_BLOCKED_ISR 0x0400 /*! thread DEV wait ISR */ |
---|
[446] | 93 | #define THREAD_BLOCKED_WAIT 0x0800 /*! thread wait child process termination */ |
---|
[564] | 94 | #define THREAD_BLOCKED_LOCK 0x1000 /*! thread wait queuelock or rwlock */ |
---|
[23] | 95 | |
---|
[1] | 96 | /*************************************************************************************** |
---|
| 97 | * This structure defines thread instrumentation informations. |
---|
| 98 | **************************************************************************************/ |
---|
| 99 | |
---|
| 100 | typedef struct thread_info_s |
---|
| 101 | { |
---|
[629] | 102 | uint32_t false_pgfault_nr; /*! number of local page fault */ |
---|
| 103 | uint32_t false_pgfault_cost; /*! cumulated cost */ |
---|
| 104 | uint32_t local_pgfault_nr; /*! number of local page fault */ |
---|
| 105 | uint32_t local_pgfault_cost; /*! cumulated cost */ |
---|
| 106 | uint32_t global_pgfault_nr; /*! number of global page fault */ |
---|
| 107 | uint32_t global_pgfault_cost; /*! cumulated cost */ |
---|
| 108 | |
---|
| 109 | cycle_t last_cycle; /*! last cycle counter value (date) */ |
---|
| 110 | cycle_t usr_cycles; /*! user execution duration (cycles) */ |
---|
| 111 | cycle_t sys_cycles; /*! system execution duration (cycles) */ |
---|
[1] | 112 | } |
---|
| 113 | thread_info_t; |
---|
| 114 | |
---|
| 115 | /*************************************************************************************** |
---|
| 116 | * This structure defines a thread descriptor. |
---|
| 117 | * It is used for both the user threads and the kernel threads. |
---|
[459] | 118 | * In a process, a user thread is identified by a unique TRDID (thread identifier): |
---|
[1] | 119 | * - The TRDID 16 LSB bits contain the LTID (Local Thread Index). |
---|
[23] | 120 | * - The TRDID 16 MSB bits contain the CXY of cluster containing the thread. |
---|
[459] | 121 | * The main thread LTID value is always 0. |
---|
| 122 | * The LTID is used to index the th_tbl[] array in the local process descriptor. |
---|
| 123 | * This TRDID is computed by the process_register_thread() function, when the user |
---|
[174] | 124 | * thread is registered in the local copy of the process descriptor. |
---|
[564] | 125 | * |
---|
| 126 | * WARNING (1) Don't modify the first 4 fields order, as this order is used by the |
---|
[625] | 127 | * hal_kentry assembly code for the TSAR architectures. |
---|
[564] | 128 | * |
---|
| 129 | * WARNING (2) Most of the thread state is private and accessed only by this thread, |
---|
| 130 | * but some fields are shared, and can be modified by other threads. |
---|
| 131 | * - the "blocked" bit_vector can be modified by another thread |
---|
| 132 | * running in another cluster (using atomic instructions), |
---|
| 133 | * to change this thread scheduling status. |
---|
| 134 | * - the "flags" bit_vector can be modified by another thread |
---|
| 135 | * running in another cluster (using atomic instructions), |
---|
| 136 | * to register requests such as ACK or DELETE. |
---|
| 137 | * - the "join_xp" field can be modified by the joining thread, |
---|
| 138 | * and this rendez-vous is protected by the dedicated "join_lock". |
---|
| 139 | * |
---|
| 140 | * WARNING (3) When this thread is blocked on a shared resource (queuelock, condvar, |
---|
| 141 | * or chdev), it registers in the associated waiting queue, using the |
---|
| 142 | * "wait_list" (local list) or "wait_xlist" (trans-cluster list) fields. |
---|
[1] | 143 | **************************************************************************************/ |
---|
| 144 | |
---|
| 145 | #define THREAD_SIGNATURE 0xDEADBEEF |
---|
| 146 | |
---|
| 147 | typedef struct thread_s |
---|
| 148 | { |
---|
[619] | 149 | void * cpu_context; /*! CPU context used by sched_yield */ |
---|
| 150 | void * fpu_context; /*! FPU context used by sched_yield */ |
---|
[428] | 151 | void * uzone_current; /*! used by hal_do_syscall & hal_do_except */ |
---|
| 152 | void * uzone_previous; /*! used by hal_do_syscall & hal_do_except */ |
---|
[16] | 153 | |
---|
[406] | 154 | intptr_t k_stack_base; /*! kernel stack base address */ |
---|
| 155 | uint32_t k_stack_size; /*! kernel stack size (bytes) */ |
---|
| 156 | |
---|
[23] | 157 | uint32_t trdid; /*! thread index (cxy.ltid) */ |
---|
[1] | 158 | thread_type_t type; /*! thread type */ |
---|
| 159 | uint32_t quantum; /*! number of clock ticks given to thread */ |
---|
| 160 | uint32_t ticks_nr; /*! number of ticks used */ |
---|
| 161 | uint32_t time_last_check; /*! last cpu_time_stamp */ |
---|
| 162 | core_t * core; /*! pointer to the owner core */ |
---|
| 163 | process_t * process; /*! pointer on local process descriptor */ |
---|
[174] | 164 | xptr_t parent; /*! extended pointer on parent thread */ |
---|
[1] | 165 | |
---|
[564] | 166 | remote_busylock_t join_lock; /*! lock protecting the join/exit */ |
---|
[436] | 167 | xptr_t join_xp; /*! joining/killer thread extended pointer */ |
---|
[23] | 168 | |
---|
[416] | 169 | uint32_t * ack_rsp_count; /*! pointer on acknowledge response counter */ |
---|
[1] | 170 | |
---|
[625] | 171 | vseg_t * user_stack_vseg; /*! local pointer on user stack vseg */ |
---|
[1] | 172 | |
---|
| 173 | void * entry_func; /*! pointer on entry function */ |
---|
| 174 | void * entry_args; /*! pointer on entry function arguments */ |
---|
[457] | 175 | uint32_t main_argc; /*! main thread number of arguments */ |
---|
| 176 | char ** main_argv; /*! main thread array of strings arguments */ |
---|
[1] | 177 | |
---|
| 178 | uint32_t flags; /*! bit vector of flags */ |
---|
[408] | 179 | uint32_t blocked; /*! bit vector of blocking causes */ |
---|
[1] | 180 | |
---|
[16] | 181 | error_t errno; /*! errno value set by last system call */ |
---|
[23] | 182 | uint32_t utls; /*! user thread local storage */ |
---|
[1] | 183 | |
---|
| 184 | bool_t fork_user; /*! user defined placement for next fork() */ |
---|
| 185 | cxy_t fork_cxy; /*! target cluster for next fork() */ |
---|
| 186 | |
---|
| 187 | list_entry_t sched_list; /*! member of threads attached to same core */ |
---|
| 188 | |
---|
[408] | 189 | chdev_t * chdev; /*! chdev pointer (for a DEV thread only) */ |
---|
[174] | 190 | |
---|
[408] | 191 | reg_t save_sr; /*! used by sched_yield() function */ |
---|
| 192 | |
---|
[279] | 193 | ioc_command_t ioc_cmd; /*! IOC device generic command */ |
---|
| 194 | txt_command_t txt_cmd; /*! TXT device generic command */ |
---|
| 195 | nic_command_t nic_cmd; /*! NIC device generic command */ |
---|
| 196 | mmc_command_t mmc_cmd; /*! MMC device generic command */ |
---|
| 197 | dma_command_t dma_cmd; /*! DMA device generic command */ |
---|
| 198 | |
---|
[610] | 199 | xptr_t rpc_client_xp; /*! client thread (for a RPC thread only) */ |
---|
[1] | 200 | |
---|
[564] | 201 | list_entry_t wait_list; /*! member of a local waiting queue */ |
---|
| 202 | xlist_entry_t wait_xlist; /*! member of a trans-cluster waiting queue */ |
---|
[1] | 203 | |
---|
[564] | 204 | uint32_t busylocks; /*! number of taken busylocks */ |
---|
[409] | 205 | |
---|
[564] | 206 | #if DEBUG_BUSYLOCK |
---|
| 207 | xlist_entry_t busylocks_root; /*! root of xlist of taken busylocks */ |
---|
| 208 | #endif |
---|
| 209 | |
---|
[1] | 210 | thread_info_t info; /*! embedded thread_info_t */ |
---|
| 211 | |
---|
| 212 | uint32_t signature; /*! for kernel stack overflow detection */ |
---|
[174] | 213 | } |
---|
[1] | 214 | thread_t; |
---|
| 215 | |
---|
| 216 | /*************************************************************************************** |
---|
| 217 | * This macro returns a pointer on the calling thread from the core hardware register. |
---|
| 218 | **************************************************************************************/ |
---|
| 219 | |
---|
| 220 | #define CURRENT_THREAD (hal_get_current_thread()) |
---|
| 221 | |
---|
| 222 | /*************************************************************************************** |
---|
[16] | 223 | * This function returns a printable string for a thread type. |
---|
| 224 | *************************************************************************************** |
---|
| 225 | * @ type : thread type. |
---|
| 226 | * returns pointer on string. |
---|
| 227 | **************************************************************************************/ |
---|
[527] | 228 | const char * thread_type_str( thread_type_t type ); |
---|
[16] | 229 | |
---|
| 230 | /*************************************************************************************** |
---|
[408] | 231 | * This function is used by the pthread_create() system call to create a "new" thread |
---|
| 232 | * in an existing process. It allocates memory for an user thread descriptor in the |
---|
| 233 | * local cluster, and initializes it from information contained in the arguments. |
---|
[440] | 234 | * The CPU context is initialized from scratch. |
---|
[23] | 235 | * It is registered in the local process descriptor specified by the <pid> argument. |
---|
[457] | 236 | * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated by the caller |
---|
| 237 | * to start at the next scheduling point. |
---|
[1] | 238 | *************************************************************************************** |
---|
[23] | 239 | * @ pid : process identifier. |
---|
| 240 | * @ start_func : pointer on entry function. |
---|
| 241 | * @ start_args : pointer on function argument (can be NULL). |
---|
[1] | 242 | * @ attr : pointer on pthread attributes descriptor. |
---|
[174] | 243 | * @ new_thread : [out] address of buffer for new thread descriptor pointer. |
---|
[1] | 244 | * @ returns 0 if success / returns ENOMEM if error. |
---|
| 245 | **************************************************************************************/ |
---|
[23] | 246 | error_t thread_user_create( pid_t pid, |
---|
| 247 | void * start_func, |
---|
| 248 | void * start_arg, |
---|
[1] | 249 | pthread_attr_t * attr, |
---|
[23] | 250 | thread_t ** new_thread ); |
---|
[1] | 251 | |
---|
| 252 | /*************************************************************************************** |
---|
[625] | 253 | * This function is used by the sys_fork() syscall to create the "child" main thread |
---|
| 254 | * in the local cluster. It is called, generally through the RPC_PROCESS_MAKE_FORK, |
---|
| 255 | * by the process_make_fork() function. It allocates memory from the local cluster |
---|
| 256 | * for a "child" thread descriptor, and initializes it from the "parent" thread |
---|
| 257 | * descriptor defined by the <parent_thread_xp> argument. |
---|
[407] | 258 | * The new thread is attached to the core that has the lowest load in local cluster. |
---|
[408] | 259 | * It is registered in the "child" process defined by the <child_process> argument. |
---|
[407] | 260 | * This new thread inherits its user stack from the parent thread, as it uses the |
---|
| 261 | * Copy-On-Write mechanism to get a private stack when required. |
---|
| 262 | * The content of the parent kernel stack is copied into the child kernel stack, as |
---|
| 263 | * the Copy-On-Write mechanism cannot be used for kernel segments (because kernel |
---|
| 264 | * uses physical addressing on some architectures). |
---|
[408] | 265 | * The CPU and FPU execution contexts are created and linked to the new thread. |
---|
[625] | 266 | * but the actual context copy is NOT done, and is done by the sys_fork() function. |
---|
[408] | 267 | * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start. |
---|
[1] | 268 | *************************************************************************************** |
---|
[408] | 269 | * @ parent_thread_xp : extended pointer on parent thread descriptor. |
---|
| 270 | * @ child_process : local pointer on child process descriptor. |
---|
| 271 | * @ child_thread : [out] address of buffer for child thread descriptor pointer. |
---|
| 272 | * @ returns 0 if success / returns -1 if error. |
---|
[1] | 273 | **************************************************************************************/ |
---|
[408] | 274 | error_t thread_user_fork( xptr_t parent_thread_xp, |
---|
| 275 | process_t * child_process, |
---|
| 276 | thread_t ** child_thread ); |
---|
[1] | 277 | |
---|
| 278 | /*************************************************************************************** |
---|
[457] | 279 | * This function is called by the process_make_exec() function to re-initialise the |
---|
[625] | 280 | * calling thread descriptor, that will become the new process main thread. |
---|
[457] | 281 | * It must be called by the main thread of the calling process. |
---|
[625] | 282 | * - The calling thread TRDID is not modified. |
---|
| 283 | * - The kernel stack (currently in use) is not modified. |
---|
[457] | 284 | * - A new user stack vseg is created and initialised. |
---|
| 285 | * - The function calls the hal_cpu_context_exec() to re-initialize the CPU context |
---|
[625] | 286 | * and the uzone registered in kernel stack, an jump to user code. |
---|
[457] | 287 | *************************************************************************************** |
---|
| 288 | * @ entry_func : main thread entry point. |
---|
| 289 | * @ argc : number of main thread arguments. |
---|
| 290 | * @ argv : array of pointers on stringarguments. |
---|
| 291 | * @ returns 0 if success / returns ENOMEM if error. |
---|
| 292 | **************************************************************************************/ |
---|
| 293 | error_t thread_user_exec( void * entry_func, |
---|
| 294 | uint32_t argc, |
---|
| 295 | char ** argv); |
---|
| 296 | |
---|
| 297 | /*************************************************************************************** |
---|
[1] | 298 | * This function allocates memory for a kernel thread descriptor in the local cluster, |
---|
[408] | 299 | * and initializes it from arguments values. |
---|
| 300 | * It is called by kernel_init() to statically create all DEV server threads |
---|
| 301 | * It is also called to dynamically create RPC threads when required. |
---|
[174] | 302 | * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. |
---|
[1] | 303 | *************************************************************************************** |
---|
| 304 | * @ new_thread : address of buffer for new thread pointer. |
---|
| 305 | * @ type : kernel thread type. |
---|
| 306 | * @ func : pointer on function. |
---|
| 307 | * @ args : function arguments. |
---|
| 308 | * @ core_lid : local core index. |
---|
| 309 | * @ returns 0 if success / returns ENOMEM if error |
---|
| 310 | **************************************************************************************/ |
---|
| 311 | error_t thread_kernel_create( thread_t ** new_thread, |
---|
| 312 | thread_type_t type, |
---|
[174] | 313 | void * func, |
---|
[1] | 314 | void * args, |
---|
| 315 | lid_t core_lid ); |
---|
| 316 | |
---|
| 317 | /*************************************************************************************** |
---|
[443] | 318 | * This function is called by the kernel_init() function to initialize the IDLE thread |
---|
| 319 | * descriptor from arguments values. |
---|
[174] | 320 | * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. |
---|
[457] | 321 | * It returns a kernel panic if failure. |
---|
[14] | 322 | *************************************************************************************** |
---|
| 323 | * @ thread : pointer on existing thread descriptor. |
---|
| 324 | * @ type : kernel thread type. |
---|
| 325 | * @ func : pointer on function. |
---|
| 326 | * @ args : function arguments. |
---|
| 327 | * @ core_lid : local core index. |
---|
| 328 | **************************************************************************************/ |
---|
[457] | 329 | void thread_idle_init( thread_t * thread, |
---|
| 330 | thread_type_t type, |
---|
| 331 | void * func, |
---|
| 332 | void * args, |
---|
| 333 | lid_t core_lid ); |
---|
[14] | 334 | |
---|
| 335 | /*************************************************************************************** |
---|
[625] | 336 | * This low-level function is called by the sched_handle_signals() function when a |
---|
| 337 | * thread is marked for delete. It removes the thread identified by the <thread> |
---|
| 338 | * argument from the process th_tbl[], and releases all physical memory allocated for |
---|
| 339 | * this. This includes the thread descriptor itself, the associated CPU and FPU context, |
---|
| 340 | * and the physical memory allocated for an user thread stack. |
---|
[1] | 341 | *************************************************************************************** |
---|
[174] | 342 | * @ thread : pointer on the thread descriptor to release. |
---|
[625] | 343 | * @ return the number of threads registered in the process th_tbl[] before deletion. |
---|
[1] | 344 | **************************************************************************************/ |
---|
[625] | 345 | uint32_t thread_destroy( thread_t * thread ); |
---|
[1] | 346 | |
---|
| 347 | /*************************************************************************************** |
---|
[14] | 348 | * This function defines the code of the thread executed by all cores after kernel_init, |
---|
| 349 | * or when no other thread is runnable for a given core. |
---|
[443] | 350 | * It enter and infinite loop in wich: |
---|
| 351 | * - it unmask the IRQs |
---|
| 352 | * - it optionally calls the hal_core_sleep() function to reduce the power consumption |
---|
| 353 | * (this behavior is controlled by the CONFIG_THREAD_IDLE_MODE_SLEEP flag). |
---|
| 354 | * - it call the sched_yield() function to find another runnable thread. |
---|
[14] | 355 | * |
---|
[443] | 356 | * TODO: In the TSAR architecture the hal_core_sleep() function forces the core to |
---|
| 357 | * low-power mode. Any IRQ will force the core to exit this low-power mode, but no ISR |
---|
| 358 | * is executed. We must analyse if we have the same behaviour for I86 architectures... |
---|
[1] | 359 | **************************************************************************************/ |
---|
[485] | 360 | void thread_idle_func( void ); |
---|
[1] | 361 | |
---|
| 362 | /*************************************************************************************** |
---|
[416] | 363 | * This function is used by a "blocker" thread running in the same cluster as a "target" |
---|
| 364 | * thread to request the scheduler of the target thread to acknowledge that the target |
---|
| 365 | * thread is blocked and not running, at the next context switch. |
---|
| 366 | * This function executes atomically the following actions : |
---|
| 367 | * - it set the request_pending boolean in the target scheduler descriptor. |
---|
| 368 | * - it set the REQ_ACK flag in the "flags" field of the target thread descriptor. |
---|
[409] | 369 | * - It registers the responses counter pointer in the target thread descriptor. |
---|
[416] | 370 | * The request_pending flag is handled as a set/reset flip-flop by the "blocker" thread |
---|
| 371 | * and by the "target" scheduler. |
---|
[1] | 372 | *************************************************************************************** |
---|
[409] | 373 | * @ target : local pointer on target thread. |
---|
[416] | 374 | * @ ack_rsp_count : local pointer on responses counter. |
---|
[1] | 375 | **************************************************************************************/ |
---|
[416] | 376 | void thread_set_req_ack( thread_t * target, |
---|
| 377 | uint32_t * ack_rsp_count ); |
---|
[1] | 378 | |
---|
| 379 | /*************************************************************************************** |
---|
[416] | 380 | * This function is used by the sched_handle_signal() function executed by the |
---|
| 381 | * scheduler of a "target" thread to reset a "blocked not running" acknowledge request |
---|
| 382 | * in both the target thread descriptor, and in the target thread scheduler. |
---|
[1] | 383 | *************************************************************************************** |
---|
[416] | 384 | * @ target : local pointer on target thread. |
---|
[1] | 385 | **************************************************************************************/ |
---|
[416] | 386 | void thread_reset_req_ack( thread_t * target ); |
---|
[1] | 387 | |
---|
| 388 | /*************************************************************************************** |
---|
[440] | 389 | * This function is used by the four sys_thread_cancel(), sys_thread_exit(), |
---|
[443] | 390 | * sys_kill() and sys_exit() system calls to mark for delete a given thread. |
---|
[625] | 391 | * It set the THREAD_BLOCKED_GLOBAL bit and set the THREAD_FLAG_REQ_DELETE bit in the |
---|
| 392 | * thread descriptor identified by the <thread_xp> argument, to ask the scheduler |
---|
[440] | 393 | * to asynchronously delete the target thread, at the next scheduling point. |
---|
[625] | 394 | * The calling thread can run in any cluster, as it uses remote accesses. |
---|
| 395 | * This function makes a kernel panic if the target thread is the main thread, |
---|
| 396 | * because * the main thread deletion will cause the process deletion, and a process |
---|
| 397 | * must be deleted by the parent process, running the wait function. |
---|
[440] | 398 | * If the target thread is running in "attached" mode, and the <is_forced> argument |
---|
[436] | 399 | * is false, this function implements the required sychronisation with the joining |
---|
[583] | 400 | * thread, blocking the killer thread until the pthread_join() syscall is executed |
---|
| 401 | * by the joining thread. |
---|
[1] | 402 | *************************************************************************************** |
---|
[436] | 403 | * @ thread_xp : extended pointer on the target thread. |
---|
[440] | 404 | * @ pid : process identifier (to get the owner cluster identifier). |
---|
| 405 | * @ is_forced : the deletion does not depends on the attached mode. |
---|
[407] | 406 | **************************************************************************************/ |
---|
[440] | 407 | void thread_delete( xptr_t thread_xp, |
---|
| 408 | pid_t pid, |
---|
| 409 | bool_t is_forced ); |
---|
[407] | 410 | |
---|
| 411 | /*************************************************************************************** |
---|
[436] | 412 | * This function registers a blocking cause defined by the <cause> argument |
---|
| 413 | * in a remote thread descriptor identified by the <thread_xp> argument. |
---|
| 414 | * We need an extended pointer, because this function can be called by another thread |
---|
| 415 | * than the target thread, executing the sys_kill() function. |
---|
| 416 | * WARNING : this function does not deschedule the target thread, and the descheduling |
---|
[407] | 417 | * must be explicitely forced by a sched_yield(). |
---|
[1] | 418 | *************************************************************************************** |
---|
[436] | 419 | * @ thread_xp : extended pointer on remote thread descriptor. |
---|
| 420 | * @ cause : mask defining the cause (one hot). |
---|
[1] | 421 | **************************************************************************************/ |
---|
[436] | 422 | void thread_block( xptr_t thread_xp, |
---|
| 423 | uint32_t cause ); |
---|
[1] | 424 | |
---|
[174] | 425 | /*************************************************************************************** |
---|
[436] | 426 | * This function resets the bit identified by the <cause> argument in a remote |
---|
| 427 | * thread descriptor identified by the <thread_xp> argument. |
---|
[1] | 428 | * We need an extended pointer, because the client thread of an I/O operation on a |
---|
[564] | 429 | * given device is generally not in the same cluster as the associated server thread. |
---|
[436] | 430 | * WARNING : this function does not reschedule the remote thread. |
---|
[1] | 431 | * The scheduling can be forced by sending an IPI to the core running the remote thread. |
---|
| 432 | *************************************************************************************** |
---|
[436] | 433 | * @ thread_xp : extended pointer the remote thread. |
---|
| 434 | * @ cause : mask defining the cause (one hot). |
---|
[407] | 435 | * @ return non zero if the bit-vector was actually modified / return 0 otherwise |
---|
[1] | 436 | **************************************************************************************/ |
---|
[436] | 437 | uint32_t thread_unblock( xptr_t thread_xp, |
---|
[407] | 438 | uint32_t cause ); |
---|
[1] | 439 | |
---|
[174] | 440 | /*************************************************************************************** |
---|
[473] | 441 | * This function updates the calling thread user_time or kernel_time counters. |
---|
[16] | 442 | *************************************************************************************** |
---|
| 443 | * @ thread : local pointer on target thread. |
---|
[564] | 444 | * @ is_user : update user time if true / update kernel time if false |
---|
[16] | 445 | **************************************************************************************/ |
---|
[473] | 446 | void thread_time_update( thread_t * thread, |
---|
[564] | 447 | bool_t is_user ); |
---|
[16] | 448 | |
---|
| 449 | /*************************************************************************************** |
---|
[23] | 450 | * This function returns the extended pointer on a thread descriptor identified |
---|
| 451 | * by its thread identifier, and process identifier. |
---|
| 452 | * It can be called by any thread running in any cluster. |
---|
| 453 | *************************************************************************************** |
---|
| 454 | * @ pid : process identifier. |
---|
| 455 | * @ trdid : thread identifier. |
---|
[174] | 456 | * @ return the extended pointer if thread found / return XPTR_NULL if not found. |
---|
[23] | 457 | **************************************************************************************/ |
---|
| 458 | xptr_t thread_get_xptr( pid_t pid, |
---|
| 459 | trdid_t trdid ); |
---|
[16] | 460 | |
---|
[564] | 461 | /*************************************************************************************** |
---|
| 462 | * This function checks that the thread identified by the <thread> argument does hold |
---|
| 463 | * any busylock (local or remote). |
---|
| 464 | * If the xlist of taken busylocks is not empty, it displays the set of taken locks, |
---|
| 465 | * and makes a kernel panic. |
---|
| 466 | *************************************************************************************** |
---|
| 467 | * @ thread : local pointer on target thread. |
---|
| 468 | * @ func_str : faulty function name. |
---|
| 469 | **************************************************************************************/ |
---|
| 470 | void thread_assert_can_yield( thread_t * thread, |
---|
| 471 | const char * func_str ); |
---|
[16] | 472 | |
---|
[564] | 473 | /*************************************************************************************** |
---|
[619] | 474 | * This debug function display the list of busylocks (local or remote) |
---|
| 475 | * currently owned by a the thread identified by the <thead_xp> argument. |
---|
| 476 | * The <string> argument is printed in header (can be the calling function name). |
---|
| 477 | * WARNING : the DEBUG_BUSYLOCK parameter must be set in the kernel_config.h file. |
---|
[564] | 478 | *************************************************************************************** |
---|
[580] | 479 | * @ thread_xp : extended pointer on target thread. |
---|
[619] | 480 | * @ string : defines the calling context. |
---|
[564] | 481 | **************************************************************************************/ |
---|
[619] | 482 | void thread_display_busylocks( xptr_t thread_xp, |
---|
| 483 | const char * string ); |
---|
[564] | 484 | |
---|
| 485 | |
---|
| 486 | |
---|
[1] | 487 | #endif /* _THREAD_H_ */ |
---|