Changeset 407 for trunk/kernel/kern/thread.h
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.h
r406 r407 27 27 28 28 #include <hal_types.h> 29 #include <shared_syscalls.h> 29 30 #include <hal_special.h> 30 31 #include <xlist.h> … … 51 52 52 53 /*************************************************************************************** 53 * This defines the various pthread_attr_t attributes bit-vector.54 **************************************************************************************/55 56 /***************************************************************************************57 * This opaque structure contains the user defined attributes for a user thread.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 **************************************************************************************/62 63 typedef struct pthread_attr_s64 {65 uint32_t attributes; /*! user defined attributes bit vector */66 cxy_t cxy; /*! target cluster identifier */67 lid_t lid; /*! target core index */68 }69 pthread_attr_t;70 71 typedef enum72 {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;78 79 /***************************************************************************************80 54 * This enum defines the thread types. 81 55 **************************************************************************************/ … … 86 60 THREAD_RPC = 1, /*! kernel thread executing pending RPCs */ 87 61 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 62 THREAD_IDLE = 3, /*! kernel idle thread */ 91 63 } 92 64 thread_type_t; … … 100 72 #define THREAD_FLAG_JOIN 0x0004 /*! Parent thread made a join */ 101 73 #define THREAD_FLAG_EXIT 0x0008 /*! This thread made an exit */ 102 #define THREAD_FLAG_SCHED 0x0010 /*! Descheduling required for this thread*/74 #define THREAD_FLAG_SCHED 0x0010 /*! Scheduling required for this thread */ 103 75 104 76 /*************************************************************************************** … … 106 78 **************************************************************************************/ 107 79 108 #define THREAD_SIG_KILL 0x0001 /*! This thread must be destroyed ASAP */ 80 #define THREAD_SIG_KILL 0x0001 /*! This thread killed by another thread */ 81 #define THREAD_SIG_SUICIDE 0x0002 /*! This thread required exit */ 109 82 110 83 /*************************************************************************************** … … 116 89 #define THREAD_BLOCKED_MAPPER 0x0004 /*! thread wait mapper */ 117 90 #define THREAD_BLOCKED_JOIN 0x0008 /*! thread blocked in join / wait exit */ 118 #define THREAD_BLOCKED_EXIT 0x0010 /*! thread blocked in exit / wait join i*/91 #define THREAD_BLOCKED_EXIT 0x0010 /*! thread blocked in exit / wait join */ 119 92 #define THREAD_BLOCKED_KILL 0x0020 /*! thread received kill signal */ 120 93 #define THREAD_BLOCKED_SEM 0x0040 /*! thread wait semaphore */ 121 94 #define THREAD_BLOCKED_PAGE 0x0080 /*! thread wait page access */ 122 95 #define THREAD_BLOCKED_USERSYNC 0x0100 /*! thread wait POSIX (cond/mutex/barrier) */ 123 124 #define THREAD_BLOCKED_IDLE 0x1000 /*! thread RPC wait activation */ 96 #define THREAD_BLOCKED_RPC 0x0200 /*! thread wait RPC completion */ 97 125 98 #define THREAD_BLOCKED_DEV_QUEUE 0x2000 /*! thread DEV wait queue */ 126 99 #define THREAD_BLOCKED_DEV_ISR 0x4000 /*! thread DEV wait ISR */ … … 199 172 200 173 uint32_t flags; /*! bit vector of flags */ 201 uint32_tblocked; /*! bit vector of blocking causes */202 uint32_t signals; /*! bit vector of signals*/174 volatile uint32_t blocked; /*! bit vector of blocking causes */ 175 volatile uint32_t signals; /*! bit vector of (KILL / SUICIDE) signals */ 203 176 204 177 error_t errno; /*! errno value set by last system call */ … … 212 185 remote_spinlock_t * children_lock; /*! lock protecting the children list */ 213 186 214 xlist_entry_t brothers_list; /*! member of threads with same parent*/187 xlist_entry_t brothers_list; /*! list of attached threads to same parent */ 215 188 216 189 list_entry_t sched_list; /*! member of threads attached to same core */ … … 273 246 274 247 /*************************************************************************************** 275 * This function allocates memory for an user thread descriptor in the local cluster, 248 * This function is used by the fork() system call to create the child process main 249 * thread. It allocates memory for an user thread descriptor in the local cluster, 276 250 * and initializes it from information contained in the calling thread descriptor. 277 * It is used by the fork() system call to create the child process main thread. 278 * The new thread is attached to the core with the lowest load. 279 * It is registered in the process descriptor defined by the "process" argument. 280 * This new thread inherits its execution context from the calling thread, 281 * and the "loadable" field is NOT set. 282 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 251 * The new thread is attached to the core that has the lowest load in local cluster. 252 * It is registered in the child process descriptor defined by the <process> argument. 253 * This new thread inherits its user stack from the parent thread, as it uses the 254 * Copy-On-Write mechanism to get a private stack when required. 255 * The content of the parent kernel stack is copied into the child kernel stack, as 256 * the Copy-On-Write mechanism cannot be used for kernel segments (because kernel 257 * uses physical addressing on some architectures). 258 * The CPU and FPU execution contexts are created and linked to the new thread, 259 * but the actual context copy is NOT done. The THREAD_BLOCKED_GLOBAL bit is set, 260 * and the thread must be explicitely unblocked later to make the new thread runable. 283 261 *************************************************************************************** 284 262 * @ process : local pointer on owner process descriptor. 263 * @ stack_base : user stack base address (from parent). 264 * @ stack_size : user stack size (from parent). 285 265 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 286 266 * @ returns 0 if success / returns ENOMEM if error. 287 267 **************************************************************************************/ 288 268 error_t thread_user_fork( process_t * process, 269 intptr_t stack_base, 270 uint32_t stack_size, 289 271 thread_t ** new_thread ); 290 272 … … 351 333 * It does NOT take a lock, as this function is always called by the parent thread. 352 334 *************************************************************************************** 353 * @ xp_parent: extended pointer on the parent thread descriptor.354 * @ xp_child: extended pointer on the child thread descriptor.355 **************************************************************************************/ 356 void thread_child_parent_link( xptr_t xp_parent,357 xptr_t xp_child);335 * @ parent_xp : extended pointer on the parent thread descriptor. 336 * @ child_xp : extended pointer on the child thread descriptor. 337 **************************************************************************************/ 338 void thread_child_parent_link( xptr_t parent_xp, 339 xptr_t child_xp ); 358 340 359 341 /*************************************************************************************** … … 361 343 * of attached children threads. 362 344 *************************************************************************************** 363 * @ xp_parent: extended pointer on the parent thread descriptor.364 * @ xp_child: extended pointer on the child thread descriptor.365 **************************************************************************************/ 366 void thread_child_parent_unlink( xptr_t xp_parent,367 xptr_t xp_child);345 * @ parent_xp : extended pointer on the parent thread descriptor. 346 * @ child_xp : extended pointer on the child thread descriptor. 347 **************************************************************************************/ 348 void thread_child_parent_unlink( xptr_t parent_xp, 349 xptr_t child_xp ); 368 350 369 351 /*************************************************************************************** … … 386 368 387 369 /*************************************************************************************** 388 * This function returns true if the calling thread is attached to its parent thread.389 **************************************************************************************/390 inline bool_t thread_is_joinable();391 392 /***************************************************************************************393 * This function returns true if the calling thread is not blocked.394 **************************************************************************************/395 inline bool_t thread_is_runnable();396 397 /***************************************************************************************398 370 * This function checks if the calling thread can deschedule. 399 371 *************************************************************************************** … … 403 375 404 376 /*************************************************************************************** 405 * This function implements the delayed descheduling m achanism : It is called by377 * This function implements the delayed descheduling mechanism : It is called by 406 378 * all lock release functions, and calls the sched_yield() function when all locks 407 * have beeen released and the THREAD_FLAG_SCHED flag is set.379 * have beeen released and the calling thread THREAD_FLAG_SCHED flag is set. 408 380 **************************************************************************************/ 409 381 void thread_check_sched(); 410 382 411 383 /*************************************************************************************** 412 * This function can be used by the calling thread to suicide. 413 * All locks must be previously released. 414 * The scenario depends on the attached/detached flag : 415 * - if detached, it sets the SIG_KILL signal in the "signals" bit_vector, registers 416 * the BLOCKED_EXIT bit in the "blocked" bit_vector, and deschedule. 417 * - if attached, it simply sets the BLOCKED_EXIT bit in the "blocked" bit vector 418 * and deschedule. The SIG_KILL signal will be set by the parent thread when 419 * executing the pthread_join(). 384 * This function is used by the calling thread to suicide. 385 * All locks must be previously released. The scenario depends on the DETACHED flag. 386 * if detached : 387 * 1) the calling thread sets the SIG_SUICIDE bit in the "signals" bit_vector, 388 * registers the BLOCKED_GLOBAL bit in the "blocked" bit_vector, and deschedule. 389 * 2) the scheduler, detecting the SIG_SUICIDE bit, remove the thread from the 390 * scheduler list, remove the thread from its process, and destroys the thread. 391 * if attached : 392 * 1) the calling thread simply sets the BLOCKED_EXIT bit in the "blocked" bit vector 393 * and deschedule. 394 * 2) The SIG_KILL bit and BLOCKED_SIGNAL bits are set by the parent thread when 395 * executing the pthread_join(), and detecting the BLOCKED_EXIT bit. 396 * The scenario is a standard kill as described below. 420 397 *************************************************************************************** 421 398 * @ returns 0 if success / returns EINVAL if locks_count is not zero. … … 424 401 425 402 /*************************************************************************************** 403 * This function request to kill a local target thread, with the following scenario: 404 * 1. This function set the BLOCKED_GLOBAL bit in target thread "blocked" bit_vector, 405 * set the SIG_KILL bit in target thread "signals" bit_vector, and send an IPI 406 * to the target thread core to force scheduling. 407 * 2. The scheduler, detecting the SIG_KILL set, removes the thread from the scheduler 408 * list, and reset the SIG_KILL bit to acknowledge the killer. 409 * 3. The caller of this function, (such as the process_kill() function), must poll 410 * SIG_KILL bit until reset, detach the thread from its parent if the thread is 411 * attached, remove the thread from its process, and destroys the thread. 412 * 413 * NOTE: The third step must be done by the caller to allows the process_kill() 414 * function to parallelize the work on all schedulers in a given cluster. 415 *************************************************************************************** 416 * @ thread : local pointer on the target thread. 417 **************************************************************************************/ 418 void thread_kill( thread_t * thread ); 419 420 /*************************************************************************************** 426 421 * This function registers a blocking cause in the target thread "blocked" bit vector. 427 * Warning : this function does not deschedule the calling thread .428 * The descheduling can beforced by a sched_yield().429 *************************************************************************************** 430 * @ thread : local pointer on target thread .422 * Warning : this function does not deschedule the calling thread, and the descheduling 423 * must be explicitely forced by a sched_yield(). 424 *************************************************************************************** 425 * @ thread : local pointer on target thread descriptor. 431 426 * @ cause : mask defining the cause (one hot). 432 427 **************************************************************************************/ … … 436 431 /*************************************************************************************** 437 432 * This function resets the bit identified by the cause argument in the "blocked" 438 * bit vector of a remote thread descriptor .433 * bit vector of a remote thread descriptor, using an atomic access. 439 434 * We need an extended pointer, because the client thread of an I/O operation on a 440 435 * given device is not in the same cluster as the associated device descriptor. … … 444 439 * @ thread : extended pointer on the remote thread. 445 440 * @ cause : mask defining the cause (one hot). 446 **************************************************************************************/ 447 void thread_unblock( xptr_t thread, 448 uint32_t cause ); 449 450 /*************************************************************************************** 451 * This function kills a target thread, identified by its local pointer. 452 * It is generally called by the local process_destroy() function. 453 * - it forces the global blocked bit in target thread descriptor. 454 * - it set the SIG_KILL signal in target thread. 455 * - it send an IPI_SCHED_REQUEST to the target thread core. 456 *************************************************************************************** 457 * @ thread : local pointer on the target thread. 458 * @ returns 0 if success / returns EINVAL if locks_count is not zero. 459 **************************************************************************************/ 460 void thread_kill( thread_t * thread ); 441 * @ return non zero if the bit-vector was actually modified / return 0 otherwise 442 **************************************************************************************/ 443 uint32_t thread_unblock( xptr_t thread, 444 uint32_t cause ); 461 445 462 446 /***************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.