[1] | 1 | /* |
---|
| 2 | * thread.h - Thread and related operations definition. |
---|
[174] | 3 | * |
---|
[1] | 4 | * Author Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
| 5 | * Alain Greiner (2016) |
---|
| 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 | |
---|
| 28 | #include <hal_types.h> |
---|
| 29 | #include <hal_special.h> |
---|
| 30 | #include <xlist.h> |
---|
| 31 | #include <list.h> |
---|
| 32 | #include <hal_context.h> |
---|
| 33 | #include <spinlock.h> |
---|
| 34 | #include <core.h> |
---|
| 35 | #include <cluster.h> |
---|
| 36 | #include <process.h> |
---|
| 37 | #include <dev_ioc.h> |
---|
| 38 | #include <dev_nic.h> |
---|
| 39 | #include <dev_txt.h> |
---|
| 40 | #include <dev_mmc.h> |
---|
[5] | 41 | #include <dev_dma.h> |
---|
[1] | 42 | |
---|
| 43 | /*************************************************************************************** |
---|
[23] | 44 | * These macros are used to compose or decompose global thread identifier (TRDID) |
---|
| 45 | * to or from cluster identifier / local thread index (CXY , LTID) |
---|
[1] | 46 | **************************************************************************************/ |
---|
| 47 | |
---|
[174] | 48 | #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF) |
---|
[23] | 49 | #define CXY_FROM_TRDID( trdid ) (cxy_t)(trdid >> 16) |
---|
| 50 | #define TRDID( cxy , ltid ) (trdid_t)((cxy << 16) | ltid ) |
---|
[1] | 51 | |
---|
| 52 | /*************************************************************************************** |
---|
[23] | 53 | * This defines the various pthread_attr_t attributes bit-vector. |
---|
[1] | 54 | **************************************************************************************/ |
---|
[23] | 55 | |
---|
| 56 | /*************************************************************************************** |
---|
[174] | 57 | * This opaque structure contains the user defined attributes for a user thread. |
---|
[23] | 58 | * It is passed as input argument to the thread_user_create() function. |
---|
| 59 | * It is set by the user application itself, using the pthread_attr_***() functions. |
---|
| 60 | * The currently supported attributes are defined below. |
---|
| 61 | **************************************************************************************/ |
---|
[174] | 62 | |
---|
[1] | 63 | typedef struct pthread_attr_s |
---|
| 64 | { |
---|
[23] | 65 | uint32_t attributes; /*! user defined attributes bit vector */ |
---|
| 66 | cxy_t cxy; /*! target cluster identifier */ |
---|
| 67 | lid_t lid; /*! target core index */ |
---|
[174] | 68 | } |
---|
[1] | 69 | pthread_attr_t; |
---|
| 70 | |
---|
[23] | 71 | typedef enum |
---|
| 72 | { |
---|
| 73 | PT_ATTR_DETACH = 0x0001, /*! user defined not joinable */ |
---|
| 74 | PT_ATTR_CLUSTER_DEFINED = 0x0002, /*! user defined target cluster */ |
---|
| 75 | PT_ATTR_CORE_DEFINED = 0x0004, /*! user defined core index in cluster */ |
---|
| 76 | } |
---|
| 77 | pt_attributes_t; |
---|
[1] | 78 | |
---|
| 79 | /*************************************************************************************** |
---|
| 80 | * This enum defines the thread types. |
---|
| 81 | **************************************************************************************/ |
---|
| 82 | |
---|
| 83 | typedef enum |
---|
[174] | 84 | { |
---|
| 85 | THREAD_USER = 0, /*! user thread (pthread) */ |
---|
[1] | 86 | THREAD_RPC = 1, /*! kernel thread executing pending RPCs */ |
---|
| 87 | THREAD_DEV = 2, /*! kernel thread executing I/O device commands */ |
---|
| 88 | THREAD_KERNEL = 3, /*! other kernel thread */ |
---|
| 89 | THREAD_IDLE = 4, /*! kernel idle thread */ |
---|
| 90 | THREAD_TYPES_NR |
---|
[174] | 91 | } |
---|
[1] | 92 | thread_type_t; |
---|
| 93 | |
---|
| 94 | /*************************************************************************************** |
---|
[23] | 95 | * This defines the thread flags bit-vector. |
---|
[1] | 96 | **************************************************************************************/ |
---|
| 97 | |
---|
| 98 | #define THREAD_FLAG_LOADABLE 0x0001 /*! This thread has not been executed yet */ |
---|
[23] | 99 | #define THREAD_FLAG_DETACHED 0x0002 /*! This thread is detached from parent */ |
---|
| 100 | #define THREAD_FLAG_JOIN 0x0004 /*! Parent thread made a join */ |
---|
| 101 | #define THREAD_FLAG_EXIT 0x0008 /*! This thread made an exit */ |
---|
[1] | 102 | |
---|
| 103 | /*************************************************************************************** |
---|
| 104 | * This defines the masks associated to the thread signals. |
---|
| 105 | **************************************************************************************/ |
---|
| 106 | |
---|
| 107 | #define THREAD_SIG_KILL 0x0001 /*! This thread must be destroyed ASAP */ |
---|
| 108 | |
---|
| 109 | /*************************************************************************************** |
---|
| 110 | * This defines the masks associated to the blocking causes. |
---|
| 111 | **************************************************************************************/ |
---|
| 112 | |
---|
[174] | 113 | #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread deactivated / wait activation */ |
---|
[1] | 114 | #define THREAD_BLOCKED_IO 0x0002 /*! thread wait IO operation completion */ |
---|
| 115 | #define THREAD_BLOCKED_MAPPER 0x0004 /*! thread wait mapper */ |
---|
[23] | 116 | #define THREAD_BLOCKED_JOIN 0x0008 /*! thread blocked in join / wait exit */ |
---|
| 117 | #define THREAD_BLOCKED_EXIT 0x0010 /*! thread blocked in exit / wait join i */ |
---|
[1] | 118 | #define THREAD_BLOCKED_KILL 0x0020 /*! thread received kill signal */ |
---|
| 119 | #define THREAD_BLOCKED_SEM 0x0040 /*! thread wait semaphore */ |
---|
| 120 | #define THREAD_BLOCKED_PAGE 0x0080 /*! thread wait page access */ |
---|
[23] | 121 | #define THREAD_BLOCKED_USERSYNC 0x0100 /*! thread wait POSIX (cond/mutex/barrier) */ |
---|
| 122 | |
---|
[1] | 123 | #define THREAD_BLOCKED_IDLE 0x1000 /*! thread RPC wait activation */ |
---|
| 124 | #define THREAD_BLOCKED_DEV_QUEUE 0x2000 /*! thread DEV wait queue */ |
---|
| 125 | #define THREAD_BLOCKED_DEV_ISR 0x4000 /*! thread DEV wait ISR */ |
---|
| 126 | |
---|
| 127 | /*************************************************************************************** |
---|
| 128 | * This structure defines thread instrumentation informations. |
---|
| 129 | **************************************************************************************/ |
---|
| 130 | |
---|
| 131 | typedef struct thread_info_s |
---|
| 132 | { |
---|
| 133 | uint32_t pgfault_nr; /*! cumulated number of page fault */ |
---|
| 134 | uint32_t sched_nr; /*! TODO ??? [AG] */ |
---|
| 135 | uint32_t u_err_nr; /*! TODO ??? [AG] */ |
---|
| 136 | uint32_t m_err_nr; /*! TODO ??? [AG] */ |
---|
| 137 | uint32_t tm_tmp; /*! temp date to compute execution duration */ |
---|
| 138 | uint32_t tm_exec; /*! TODO ??? [AG] */ |
---|
| 139 | uint32_t tm_create; /*! date of the creation */ |
---|
| 140 | uint32_t tm_born; /*! date of the thread loading */ |
---|
| 141 | uint32_t tm_dead; /*! date of the death */ |
---|
[16] | 142 | cycle_t tm_sleep; /*! TODO ??? [AG] */ |
---|
| 143 | cycle_t tm_wait; /*! TODO ??? [AG] */ |
---|
| 144 | cycle_t tm_usr; /*! user execution duration */ |
---|
| 145 | cycle_t tm_sys; /*! system execution duration */ |
---|
[1] | 146 | } |
---|
| 147 | thread_info_t; |
---|
| 148 | |
---|
| 149 | /*************************************************************************************** |
---|
| 150 | * This structure defines a thread descriptor. |
---|
| 151 | * It is used for both the user threads and the kernel threads. |
---|
[174] | 152 | * In a process, a user thread is identified by a unique TRDID (thread identifier), |
---|
[1] | 153 | * that is returned by the kernel to the user: |
---|
| 154 | * - The TRDID 16 LSB bits contain the LTID (Local Thread Index). |
---|
[23] | 155 | * - The TRDID 16 MSB bits contain the CXY of cluster containing the thread. |
---|
[1] | 156 | * - The LTID is used to index the th_tbl[] array in the local process descriptor. |
---|
| 157 | * This TRDID is computed by the process_register_thread() function, when the user |
---|
[174] | 158 | * thread is registered in the local copy of the process descriptor. |
---|
[1] | 159 | **************************************************************************************/ |
---|
| 160 | |
---|
| 161 | #define THREAD_SIGNATURE 0xDEADBEEF |
---|
| 162 | |
---|
| 163 | typedef struct thread_s |
---|
| 164 | { |
---|
[16] | 165 | void * cpu_uzone; /*! used for exception/interrupt/syscall */ |
---|
| 166 | void * cpu_context; /*! used for context switch */ |
---|
| 167 | void * fpu_context; /*! used for dynamic FPU allocation */ |
---|
| 168 | |
---|
[23] | 169 | uint32_t trdid; /*! thread index (cxy.ltid) */ |
---|
[1] | 170 | thread_type_t type; /*! thread type */ |
---|
| 171 | uint32_t quantum; /*! number of clock ticks given to thread */ |
---|
| 172 | uint32_t ticks_nr; /*! number of ticks used */ |
---|
| 173 | uint32_t time_last_check; /*! last cpu_time_stamp */ |
---|
| 174 | core_t * core; /*! pointer to the owner core */ |
---|
| 175 | process_t * process; /*! pointer on local process descriptor */ |
---|
[174] | 176 | xptr_t parent; /*! extended pointer on parent thread */ |
---|
[1] | 177 | |
---|
[23] | 178 | void * exit_value; /*! exit_value used in case of join */ |
---|
[174] | 179 | |
---|
[1] | 180 | uint32_t local_locks; /*! number of local locks owned by thread */ |
---|
| 181 | list_entry_t locks_root; /*! root of local locks list */ |
---|
| 182 | |
---|
[23] | 183 | remote_spinlock_t * flags_lock; /*! lock protecting the flags */ |
---|
| 184 | |
---|
[1] | 185 | uint32_t remote_locks; /*! number of local locks owned by thread */ |
---|
| 186 | xlist_entry_t xlocks_root; /*! root of remote locks list */ |
---|
| 187 | |
---|
| 188 | intptr_t u_stack_base; /*! user stack base address */ |
---|
| 189 | uint32_t u_stack_size; /*! user stack size (bytes) */ |
---|
| 190 | intptr_t k_stack_base; /*! kernel stack base address */ |
---|
| 191 | uint32_t k_stack_size; /*! kernel stack size (bytes) */ |
---|
| 192 | |
---|
| 193 | void * entry_func; /*! pointer on entry function */ |
---|
| 194 | void * entry_args; /*! pointer on entry function arguments */ |
---|
| 195 | |
---|
| 196 | uint32_t flags; /*! bit vector of flags */ |
---|
| 197 | uint32_t blocked; /*! bit vector of blocking causes */ |
---|
| 198 | uint32_t signals; /*! bit vector of signals */ |
---|
| 199 | |
---|
[16] | 200 | error_t errno; /*! errno value set by last system call */ |
---|
[23] | 201 | uint32_t utls; /*! user thread local storage */ |
---|
[1] | 202 | |
---|
| 203 | bool_t fork_user; /*! user defined placement for next fork() */ |
---|
| 204 | cxy_t fork_cxy; /*! target cluster for next fork() */ |
---|
| 205 | |
---|
| 206 | xlist_entry_t children_root; /*! root of list of attached children */ |
---|
| 207 | uint32_t children_nr; /*! number of attached children threads */ |
---|
| 208 | remote_spinlock_t * children_lock; /*! lock protecting the children list */ |
---|
| 209 | |
---|
| 210 | xlist_entry_t brothers_list; /*! member of threads with same parent */ |
---|
| 211 | |
---|
| 212 | list_entry_t sched_list; /*! member of threads attached to same core */ |
---|
| 213 | |
---|
| 214 | uint32_t dev_channel; /*! device channel for a DEV thread */ |
---|
[174] | 215 | |
---|
[279] | 216 | ioc_command_t ioc_cmd; /*! IOC device generic command */ |
---|
| 217 | txt_command_t txt_cmd; /*! TXT device generic command */ |
---|
| 218 | nic_command_t nic_cmd; /*! NIC device generic command */ |
---|
| 219 | mmc_command_t mmc_cmd; /*! MMC device generic command */ |
---|
| 220 | dma_command_t dma_cmd; /*! DMA device generic command */ |
---|
| 221 | |
---|
[1] | 222 | cxy_t rpc_client_cxy; /*! client cluster index (for a RPC thread) */ |
---|
| 223 | |
---|
| 224 | xlist_entry_t wait_list; /*! member of threads blocked on same cond */ |
---|
| 225 | |
---|
| 226 | thread_info_t info; /*! embedded thread_info_t */ |
---|
| 227 | |
---|
| 228 | uint32_t signature; /*! for kernel stack overflow detection */ |
---|
[174] | 229 | } |
---|
[1] | 230 | thread_t; |
---|
| 231 | |
---|
| 232 | /*************************************************************************************** |
---|
| 233 | * This macro returns a pointer on the calling thread from the core hardware register. |
---|
| 234 | **************************************************************************************/ |
---|
| 235 | |
---|
| 236 | #define CURRENT_THREAD (hal_get_current_thread()) |
---|
| 237 | |
---|
| 238 | /*************************************************************************************** |
---|
[16] | 239 | * This function returns a printable string for a thread type. |
---|
| 240 | *************************************************************************************** |
---|
| 241 | * @ type : thread type. |
---|
| 242 | * returns pointer on string. |
---|
| 243 | **************************************************************************************/ |
---|
| 244 | char * thread_type_str( uint32_t type ); |
---|
| 245 | |
---|
| 246 | /*************************************************************************************** |
---|
[174] | 247 | * This function allocates memory for a user thread descriptor in the local cluster, |
---|
[23] | 248 | * and initializes it from information contained in the arguments. |
---|
[174] | 249 | * It is used by the "pthread_create" system call. |
---|
| 250 | * The CPU context is initialized from scratch, and the "loadable" field is set. |
---|
[23] | 251 | * The new thread is attached to the core specified in the <attr> argument. |
---|
| 252 | * It is registered in the local process descriptor specified by the <pid> argument. |
---|
[1] | 253 | * The thread descriptor pointer is returned to allow the parent thread to register it |
---|
| 254 | * in its children list. |
---|
[174] | 255 | * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start. |
---|
[1] | 256 | *************************************************************************************** |
---|
[23] | 257 | * @ pid : process identifier. |
---|
| 258 | * @ start_func : pointer on entry function. |
---|
| 259 | * @ start_args : pointer on function argument (can be NULL). |
---|
[1] | 260 | * @ attr : pointer on pthread attributes descriptor. |
---|
[174] | 261 | * @ new_thread : [out] address of buffer for new thread descriptor pointer. |
---|
[1] | 262 | * @ returns 0 if success / returns ENOMEM if error. |
---|
| 263 | **************************************************************************************/ |
---|
[23] | 264 | error_t thread_user_create( pid_t pid, |
---|
| 265 | void * start_func, |
---|
| 266 | void * start_arg, |
---|
[1] | 267 | pthread_attr_t * attr, |
---|
[23] | 268 | thread_t ** new_thread ); |
---|
[1] | 269 | |
---|
| 270 | /*************************************************************************************** |
---|
| 271 | * This function allocates memory for an user thread descriptor in the local cluster, |
---|
[174] | 272 | * and initializes it from information contained in the calling thread descriptor. |
---|
[1] | 273 | * It is used by the fork() system call to create the child process main thread. |
---|
[174] | 274 | * The new thread is attached to the core with the lowest load. |
---|
[1] | 275 | * It is registered in the process descriptor defined by the "process" argument. |
---|
| 276 | * This new thread inherits its execution context from the calling thread, |
---|
| 277 | * and the "loadable" field is NOT set. |
---|
[174] | 278 | * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. |
---|
[1] | 279 | *************************************************************************************** |
---|
| 280 | * @ process : local pointer on owner process descriptor. |
---|
[174] | 281 | * @ new_thread : [out] address of buffer for new thread descriptor pointer. |
---|
[1] | 282 | * @ returns 0 if success / returns ENOMEM if error. |
---|
| 283 | **************************************************************************************/ |
---|
[23] | 284 | error_t thread_user_fork( process_t * process, |
---|
| 285 | thread_t ** new_thread ); |
---|
[1] | 286 | |
---|
| 287 | /*************************************************************************************** |
---|
| 288 | * This function allocates memory for a kernel thread descriptor in the local cluster, |
---|
[174] | 289 | * and initializes it from arguments values, calling the thread_kernel_init() function, |
---|
[14] | 290 | * that also allocates and initializes the CPU context. |
---|
[174] | 291 | * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. |
---|
[1] | 292 | *************************************************************************************** |
---|
| 293 | * @ new_thread : address of buffer for new thread pointer. |
---|
| 294 | * @ type : kernel thread type. |
---|
| 295 | * @ func : pointer on function. |
---|
| 296 | * @ args : function arguments. |
---|
| 297 | * @ core_lid : local core index. |
---|
| 298 | * @ returns 0 if success / returns ENOMEM if error |
---|
| 299 | **************************************************************************************/ |
---|
| 300 | error_t thread_kernel_create( thread_t ** new_thread, |
---|
| 301 | thread_type_t type, |
---|
[174] | 302 | void * func, |
---|
[1] | 303 | void * args, |
---|
| 304 | lid_t core_lid ); |
---|
| 305 | |
---|
| 306 | /*************************************************************************************** |
---|
[174] | 307 | * This function initializes an existing kernel thread descriptor from arguments values. |
---|
| 308 | * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. |
---|
[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 | * @ returns 0 if success / returns EINVAL if error |
---|
| 316 | **************************************************************************************/ |
---|
| 317 | error_t thread_kernel_init( thread_t * thread, |
---|
| 318 | thread_type_t type, |
---|
[174] | 319 | void * func, |
---|
[14] | 320 | void * args, |
---|
| 321 | lid_t core_lid ); |
---|
| 322 | |
---|
| 323 | /*************************************************************************************** |
---|
[174] | 324 | * This function releases the physical memory allocated for a thread descriptor |
---|
[1] | 325 | * in the local cluster. It can be used for both an user and a kernel thread. |
---|
[174] | 326 | * The physical memory dynamically allocated in the HEAP or MMAP zones by an user |
---|
[1] | 327 | * thread will be released when the process is killed, and the page table flushed. |
---|
| 328 | *************************************************************************************** |
---|
[174] | 329 | * @ thread : pointer on the thread descriptor to release. |
---|
[1] | 330 | **************************************************************************************/ |
---|
| 331 | void thread_destroy( thread_t * thread ); |
---|
| 332 | |
---|
| 333 | /*************************************************************************************** |
---|
[14] | 334 | * This function defines the code of the thread executed by all cores after kernel_init, |
---|
| 335 | * or when no other thread is runnable for a given core. |
---|
| 336 | * |
---|
[174] | 337 | * TODO: In the TSAR architecture, it enters an infinite loop, in wich it forces |
---|
[14] | 338 | * the core in sleep (low-power) mode. Any IRQ will force the core to exit this sleep |
---|
| 339 | * mode, but no ISR is executed. |
---|
| 340 | * TODO: We must analyse if we have the same behaviour for I86 architectures... |
---|
[1] | 341 | **************************************************************************************/ |
---|
[14] | 342 | void thread_idle_func(); |
---|
[1] | 343 | |
---|
| 344 | /*************************************************************************************** |
---|
[174] | 345 | * This function registers a child thread in the global list of attached |
---|
[1] | 346 | * children threads of a parent thread. |
---|
[174] | 347 | * It does NOT take a lock, as this function is always called by the parent thread. |
---|
[1] | 348 | *************************************************************************************** |
---|
| 349 | * @ xp_parent : extended pointer on the parent thread descriptor. |
---|
| 350 | * @ xp_child : extended pointer on the child thread descriptor. |
---|
| 351 | **************************************************************************************/ |
---|
| 352 | void thread_child_parent_link( xptr_t xp_parent, |
---|
| 353 | xptr_t xp_child ); |
---|
| 354 | |
---|
| 355 | /*************************************************************************************** |
---|
[174] | 356 | * This function removes an user thread from the parent thread global list |
---|
| 357 | * of attached children threads. |
---|
[1] | 358 | *************************************************************************************** |
---|
| 359 | * @ xp_parent : extended pointer on the parent thread descriptor. |
---|
| 360 | * @ xp_child : extended pointer on the child thread descriptor. |
---|
| 361 | **************************************************************************************/ |
---|
| 362 | void thread_child_parent_unlink( xptr_t xp_parent, |
---|
| 363 | xptr_t xp_child ); |
---|
| 364 | |
---|
| 365 | /*************************************************************************************** |
---|
[174] | 366 | * This function atomically sets a signal in a thread descriptor. |
---|
[1] | 367 | *************************************************************************************** |
---|
| 368 | * @ thread : local pointer on target thread. |
---|
| 369 | * @ mask : mask on selected signal. |
---|
| 370 | **************************************************************************************/ |
---|
| 371 | inline void thread_set_signal( thread_t * thread, |
---|
| 372 | uint32_t mask ); |
---|
| 373 | |
---|
| 374 | /*************************************************************************************** |
---|
[174] | 375 | * This function resets a signal in a thread descriptor. |
---|
[1] | 376 | *************************************************************************************** |
---|
| 377 | * @ thread : local pointer on target thread. |
---|
| 378 | * @ mask : mask on selected signal. |
---|
| 379 | **************************************************************************************/ |
---|
| 380 | inline void thread_reset_signal( thread_t * thread, |
---|
| 381 | uint32_t mask ); |
---|
| 382 | |
---|
| 383 | /*************************************************************************************** |
---|
| 384 | * This function returns true if the calling thread is attached to its parent thread. |
---|
| 385 | **************************************************************************************/ |
---|
| 386 | inline bool_t thread_is_joinable(); |
---|
| 387 | |
---|
| 388 | /*************************************************************************************** |
---|
| 389 | * This function returns true if the calling thread is not blocked. |
---|
| 390 | **************************************************************************************/ |
---|
| 391 | inline bool_t thread_is_runnable(); |
---|
| 392 | |
---|
| 393 | /*************************************************************************************** |
---|
[174] | 394 | * This function checks if the calling thread can deschedule. |
---|
[1] | 395 | *************************************************************************************** |
---|
| 396 | * @ returns true if no locks taken. |
---|
| 397 | **************************************************************************************/ |
---|
| 398 | inline bool_t thread_can_yield(); |
---|
| 399 | |
---|
| 400 | /*************************************************************************************** |
---|
[174] | 401 | * This function checks if the calling thread must be descheduled. |
---|
[1] | 402 | *************************************************************************************** |
---|
| 403 | * @ returns true if no locks taken, and elapsed time. |
---|
| 404 | **************************************************************************************/ |
---|
| 405 | bool_t thread_check_sched(); |
---|
| 406 | |
---|
| 407 | /*************************************************************************************** |
---|
| 408 | * This function can be used by the calling thread to suicide. |
---|
[174] | 409 | * All locks must be previously released. |
---|
[1] | 410 | * The scenario depends on the attached/detached flag : |
---|
[174] | 411 | * - if detached, it sets the SIG_KILL signal in the "signals" bit_vector, registers |
---|
[1] | 412 | * the BLOCKED_EXIT bit in the "blocked" bit_vector, and deschedule. |
---|
[174] | 413 | * - if attached, it simply sets the BLOCKED_EXIT bit in the "blocked" bit vector |
---|
[1] | 414 | * and deschedule. The SIG_KILL signal will be set by the parent thread when |
---|
| 415 | * executing the pthread_join(). |
---|
| 416 | *************************************************************************************** |
---|
| 417 | * @ returns 0 if success / returns EINVAL if locks_count is not zero. |
---|
| 418 | **************************************************************************************/ |
---|
| 419 | error_t thread_exit(); |
---|
| 420 | |
---|
[174] | 421 | /*************************************************************************************** |
---|
[1] | 422 | * This function registers a blocking cause in the target thread "blocked" bit vector. |
---|
| 423 | * Warning : this function does not deschedule the calling thread. |
---|
[174] | 424 | * The descheduling can be forced by a sched_yield(). |
---|
[1] | 425 | *************************************************************************************** |
---|
| 426 | * @ thread : local pointer on target thread. |
---|
| 427 | * @ cause : mask defining the cause (one hot). |
---|
| 428 | **************************************************************************************/ |
---|
| 429 | void thread_block( thread_t * thread, |
---|
| 430 | uint32_t cause ); |
---|
| 431 | |
---|
[174] | 432 | /*************************************************************************************** |
---|
| 433 | * This function resets the bit identified by the cause argument in the "blocked" |
---|
[1] | 434 | * bit vector of a remote thread descriptor. |
---|
| 435 | * We need an extended pointer, because the client thread of an I/O operation on a |
---|
| 436 | * given device is not in the same cluster as the associated device descriptor. |
---|
[174] | 437 | * Warning : this function does not reschedule the remote thread. |
---|
[1] | 438 | * The scheduling can be forced by sending an IPI to the core running the remote thread. |
---|
| 439 | *************************************************************************************** |
---|
| 440 | * @ thread : extended pointer on the remote thread. |
---|
| 441 | * @ cause : mask defining the cause (one hot). |
---|
| 442 | **************************************************************************************/ |
---|
| 443 | void thread_unblock( xptr_t thread, |
---|
| 444 | uint32_t cause ); |
---|
| 445 | |
---|
[174] | 446 | /*************************************************************************************** |
---|
[1] | 447 | * This function kills a target thread, identified by its local pointer. |
---|
| 448 | * It is generally called by the local process_destroy() function. |
---|
| 449 | * - it forces the global blocked bit in target thread descriptor. |
---|
| 450 | * - it set the SIG_KILL signal in target thread. |
---|
| 451 | * - it send an IPI_SCHED_REQUEST to the target thread core. |
---|
| 452 | *************************************************************************************** |
---|
| 453 | * @ thread : local pointer on the target thread. |
---|
| 454 | * @ returns 0 if success / returns EINVAL if locks_count is not zero. |
---|
| 455 | **************************************************************************************/ |
---|
| 456 | void thread_kill( thread_t * thread ); |
---|
| 457 | |
---|
[16] | 458 | /*************************************************************************************** |
---|
[174] | 459 | * This function updates the calling thread user_time counter, and resets the thread |
---|
[16] | 460 | * cycles counter. |
---|
| 461 | * TODO This function is not implemented. |
---|
| 462 | *************************************************************************************** |
---|
| 463 | * @ thread : local pointer on target thread. |
---|
| 464 | **************************************************************************************/ |
---|
| 465 | void thread_user_time_update( thread_t * thread ); |
---|
| 466 | |
---|
| 467 | /**************************************************************************************n |
---|
[174] | 468 | * This function updates the calling thread kernel_time counter, and resets the thread |
---|
[16] | 469 | * cycles counter. |
---|
| 470 | * TODO This function is not implemented. |
---|
| 471 | *************************************************************************************** |
---|
| 472 | * @ thread : local pointer on target thread. |
---|
| 473 | **************************************************************************************/ |
---|
| 474 | void thread_kernel_time_update( thread_t * thread ); |
---|
| 475 | |
---|
| 476 | /*************************************************************************************** |
---|
[174] | 477 | * This function handles all pending signals for the thread identified by the <thread> |
---|
| 478 | * argument. It is called each time the core exits the kernel, after handling an |
---|
| 479 | * interrupt, exception or syscall. |
---|
[16] | 480 | * TODO This function is not implemented. |
---|
| 481 | *************************************************************************************** |
---|
| 482 | * @ thread : local pointer on target thread. |
---|
| 483 | **************************************************************************************/ |
---|
| 484 | void thread_signals_handle( thread_t * thread ); |
---|
| 485 | |
---|
[23] | 486 | /*************************************************************************************** |
---|
| 487 | * This function returns the extended pointer on a thread descriptor identified |
---|
| 488 | * by its thread identifier, and process identifier. |
---|
| 489 | * It can be called by any thread running in any cluster. |
---|
| 490 | *************************************************************************************** |
---|
| 491 | * @ pid : process identifier. |
---|
| 492 | * @ trdid : thread identifier. |
---|
[174] | 493 | * @ return the extended pointer if thread found / return XPTR_NULL if not found. |
---|
[23] | 494 | **************************************************************************************/ |
---|
| 495 | xptr_t thread_get_xptr( pid_t pid, |
---|
| 496 | trdid_t trdid ); |
---|
[16] | 497 | |
---|
| 498 | |
---|
[1] | 499 | #endif /* _THREAD_H_ */ |
---|