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