Changeset 174 for trunk/kernel/kern
- Timestamp:
- Jul 11, 2017, 10:46:55 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.h
r23 r174 1 1 /* 2 2 * thread.h - Thread and related operations definition. 3 * 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 5 * Alain Greiner (2016) … … 46 46 **************************************************************************************/ 47 47 48 #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF) 48 #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF) 49 49 #define CXY_FROM_TRDID( trdid ) (cxy_t)(trdid >> 16) 50 50 #define TRDID( cxy , ltid ) (trdid_t)((cxy << 16) | ltid ) … … 55 55 56 56 /*************************************************************************************** 57 * This opaque structure contains the user defined attributes for a nuser thread.57 * This opaque structure contains the user defined attributes for a user thread. 58 58 * It is passed as input argument to the thread_user_create() function. 59 59 * It is set by the user application itself, using the pthread_attr_***() functions. 60 60 * The currently supported attributes are defined below. 61 61 **************************************************************************************/ 62 62 63 63 typedef struct pthread_attr_s 64 64 { … … 66 66 cxy_t cxy; /*! target cluster identifier */ 67 67 lid_t lid; /*! target core index */ 68 } 68 } 69 69 pthread_attr_t; 70 70 … … 82 82 83 83 typedef enum 84 { 85 THREAD_USER = 0, /*! user thread (pthread) */ 84 { 85 THREAD_USER = 0, /*! user thread (pthread) */ 86 86 THREAD_RPC = 1, /*! kernel thread executing pending RPCs */ 87 87 THREAD_DEV = 2, /*! kernel thread executing I/O device commands */ … … 89 89 THREAD_IDLE = 4, /*! kernel idle thread */ 90 90 THREAD_TYPES_NR 91 } 91 } 92 92 thread_type_t; 93 93 … … 111 111 **************************************************************************************/ 112 112 113 #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread de sactivated / wait activation */113 #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread deactivated / wait activation */ 114 114 #define THREAD_BLOCKED_IO 0x0002 /*! thread wait IO operation completion */ 115 115 #define THREAD_BLOCKED_MAPPER 0x0004 /*! thread wait mapper */ … … 150 150 * This structure defines a thread descriptor. 151 151 * It is used for both the user threads and the kernel threads. 152 * In a process, a nuser thread is identified by a unique TRDID (thread identifier),152 * In a process, a user thread is identified by a unique TRDID (thread identifier), 153 153 * that is returned by the kernel to the user: 154 154 * - The TRDID 16 LSB bits contain the LTID (Local Thread Index). … … 156 156 * - The LTID is used to index the th_tbl[] array in the local process descriptor. 157 157 * This TRDID is computed by the process_register_thread() function, when the user 158 * thread is register d in the local copy of the process descriptor.158 * thread is registered in the local copy of the process descriptor. 159 159 **************************************************************************************/ 160 160 … … 174 174 core_t * core; /*! pointer to the owner core */ 175 175 process_t * process; /*! pointer on local process descriptor */ 176 xptr_t parent; /*! extended pointer on parent thread */ 176 xptr_t parent; /*! extended pointer on parent thread */ 177 177 178 178 void * exit_value; /*! exit_value used in case of join */ 179 179 180 180 uint32_t local_locks; /*! number of local locks owned by thread */ 181 181 list_entry_t locks_root; /*! root of local locks list */ … … 220 220 mmc_command_t mmc; /*! MMC device generic command */ 221 221 dma_command_t dma; /*! DMA device generic command */ 222 } 222 } 223 223 command; 224 224 225 225 cxy_t rpc_client_cxy; /*! client cluster index (for a RPC thread) */ 226 226 … … 230 230 231 231 uint32_t signature; /*! for kernel stack overflow detection */ 232 } 232 } 233 233 thread_t; 234 234 … … 248 248 249 249 /*************************************************************************************** 250 * This function allocates memory for a nuser thread descriptor in the local cluster,250 * This function allocates memory for a user thread descriptor in the local cluster, 251 251 * and initializes it from information contained in the arguments. 252 * It is used by the "pthread_create" system call. 253 * The CPU context is initiali sed from scratch, and the "loadable" field is set.252 * It is used by the "pthread_create" system call. 253 * The CPU context is initialized from scratch, and the "loadable" field is set. 254 254 * The new thread is attached to the core specified in the <attr> argument. 255 255 * It is registered in the local process descriptor specified by the <pid> argument. 256 256 * The thread descriptor pointer is returned to allow the parent thread to register it 257 257 * in its children list. 258 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start. 258 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start. 259 259 *************************************************************************************** 260 260 * @ pid : process identifier. … … 262 262 * @ start_args : pointer on function argument (can be NULL). 263 263 * @ attr : pointer on pthread attributes descriptor. 264 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 264 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 265 265 * @ returns 0 if success / returns ENOMEM if error. 266 266 **************************************************************************************/ … … 273 273 /*************************************************************************************** 274 274 * This function allocates memory for an user thread descriptor in the local cluster, 275 * and initiali ses it from informationscontained in the calling thread descriptor.275 * and initializes it from information contained in the calling thread descriptor. 276 276 * It is used by the fork() system call to create the child process main thread. 277 * The new thread is attached to the core with the lowest load. 277 * The new thread is attached to the core with the lowest load. 278 278 * It is registered in the process descriptor defined by the "process" argument. 279 279 * This new thread inherits its execution context from the calling thread, 280 280 * and the "loadable" field is NOT set. 281 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 281 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 282 282 *************************************************************************************** 283 283 * @ process : local pointer on owner process descriptor. 284 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 284 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 285 285 * @ returns 0 if success / returns ENOMEM if error. 286 286 **************************************************************************************/ … … 290 290 /*************************************************************************************** 291 291 * This function allocates memory for a kernel thread descriptor in the local cluster, 292 * and initiali seit from arguments values, calling the thread_kernel_init() function,292 * and initializes it from arguments values, calling the thread_kernel_init() function, 293 293 * that also allocates and initializes the CPU context. 294 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 294 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 295 295 *************************************************************************************** 296 296 * @ new_thread : address of buffer for new thread pointer. … … 303 303 error_t thread_kernel_create( thread_t ** new_thread, 304 304 thread_type_t type, 305 void * func, 305 void * func, 306 306 void * args, 307 307 lid_t core_lid ); 308 308 309 309 /*************************************************************************************** 310 * This function initiali ses an existing kernel thread descriptor from arguments values.311 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 310 * This function initializes an existing kernel thread descriptor from arguments values. 311 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 312 312 *************************************************************************************** 313 313 * @ thread : pointer on existing thread descriptor. … … 320 320 error_t thread_kernel_init( thread_t * thread, 321 321 thread_type_t type, 322 void * func, 322 void * func, 323 323 void * args, 324 324 lid_t core_lid ); 325 325 326 326 /*************************************************************************************** 327 * This function releases the physical memory allocated for a thread descriptor 327 * This function releases the physical memory allocated for a thread descriptor 328 328 * in the local cluster. It can be used for both an user and a kernel thread. 329 * The physical memory dynamically allocated in the HEAP or MMAP zones by an user 329 * The physical memory dynamically allocated in the HEAP or MMAP zones by an user 330 330 * thread will be released when the process is killed, and the page table flushed. 331 331 *************************************************************************************** 332 * @ thread : pointer on the thread descriptor to release. 332 * @ thread : pointer on the thread descriptor to release. 333 333 **************************************************************************************/ 334 334 void thread_destroy( thread_t * thread ); … … 338 338 * or when no other thread is runnable for a given core. 339 339 * 340 * TODO: In the TSAR architecture, it enters an infinite loop, in wich it forces 340 * TODO: In the TSAR architecture, it enters an infinite loop, in wich it forces 341 341 * the core in sleep (low-power) mode. Any IRQ will force the core to exit this sleep 342 342 * mode, but no ISR is executed. … … 346 346 347 347 /*************************************************************************************** 348 * This function registers a child thread in the global list of attached 348 * This function registers a child thread in the global list of attached 349 349 * children threads of a parent thread. 350 * It does NOT take a lock, as this function is al lways called by the parent thread.350 * It does NOT take a lock, as this function is always called by the parent thread. 351 351 *************************************************************************************** 352 352 * @ xp_parent : extended pointer on the parent thread descriptor. … … 357 357 358 358 /*************************************************************************************** 359 * This function removes an user thread from the parent thread global list 360 * of attached children threads. 359 * This function removes an user thread from the parent thread global list 360 * of attached children threads. 361 361 *************************************************************************************** 362 362 * @ xp_parent : extended pointer on the parent thread descriptor. … … 367 367 368 368 /*************************************************************************************** 369 * This function atomically set a signal in a thread descriptor.369 * This function atomically sets a signal in a thread descriptor. 370 370 *************************************************************************************** 371 371 * @ thread : local pointer on target thread. … … 376 376 377 377 /*************************************************************************************** 378 * This function reset a signal in a thread descriptor.378 * This function resets a signal in a thread descriptor. 379 379 *************************************************************************************** 380 380 * @ thread : local pointer on target thread. … … 395 395 396 396 /*************************************************************************************** 397 * This function che ks if the calling thread can deschedule.397 * This function checks if the calling thread can deschedule. 398 398 *************************************************************************************** 399 399 * @ returns true if no locks taken. … … 402 402 403 403 /*************************************************************************************** 404 * This function checks if the calling thread must be descheduled. 404 * This function checks if the calling thread must be descheduled. 405 405 *************************************************************************************** 406 406 * @ returns true if no locks taken, and elapsed time. … … 410 410 /*************************************************************************************** 411 411 * This function can be used by the calling thread to suicide. 412 * All locks must be previou ly released.412 * All locks must be previously released. 413 413 * The scenario depends on the attached/detached flag : 414 * - if detached, it set the SIG_KILL signal in the "signals" bit_vector, registers414 * - if detached, it sets the SIG_KILL signal in the "signals" bit_vector, registers 415 415 * the BLOCKED_EXIT bit in the "blocked" bit_vector, and deschedule. 416 * - if attached, it simply set the BLOCKED_EXIT bit in the "blocked" bit vector416 * - if attached, it simply sets the BLOCKED_EXIT bit in the "blocked" bit vector 417 417 * and deschedule. The SIG_KILL signal will be set by the parent thread when 418 418 * executing the pthread_join(). … … 422 422 error_t thread_exit(); 423 423 424 /*************************************************************************************** 424 /*************************************************************************************** 425 425 * This function registers a blocking cause in the target thread "blocked" bit vector. 426 426 * Warning : this function does not deschedule the calling thread. 427 * The descheduling can be forced by a sched_yield(). 427 * The descheduling can be forced by a sched_yield(). 428 428 *************************************************************************************** 429 429 * @ thread : local pointer on target thread. … … 433 433 uint32_t cause ); 434 434 435 /*************************************************************************************** 436 * This function reset the bit identified by the cause argument in the "blocked"435 /*************************************************************************************** 436 * This function resets the bit identified by the cause argument in the "blocked" 437 437 * bit vector of a remote thread descriptor. 438 438 * We need an extended pointer, because the client thread of an I/O operation on a 439 439 * given device is not in the same cluster as the associated device descriptor. 440 * Warning : this function does not reschedule the remote thread. 440 * Warning : this function does not reschedule the remote thread. 441 441 * The scheduling can be forced by sending an IPI to the core running the remote thread. 442 442 *************************************************************************************** … … 447 447 uint32_t cause ); 448 448 449 /*************************************************************************************** 449 /*************************************************************************************** 450 450 * This function kills a target thread, identified by its local pointer. 451 451 * It is generally called by the local process_destroy() function. … … 460 460 461 461 /*************************************************************************************** 462 * This function updates the calling thread user_time counter, and reset the thread462 * This function updates the calling thread user_time counter, and resets the thread 463 463 * cycles counter. 464 464 * TODO This function is not implemented. … … 469 469 470 470 /**************************************************************************************n 471 * This function updates the calling thread kernel_time counter, and reset the thread471 * This function updates the calling thread kernel_time counter, and resets the thread 472 472 * cycles counter. 473 473 * TODO This function is not implemented. … … 478 478 479 479 /*************************************************************************************** 480 * This function handle all pending signals for the thread identified by the <thread>481 * argument. It is called each time the core exit the kernel, after handling an482 * interrupt, exception or syscall. 480 * This function handles all pending signals for the thread identified by the <thread> 481 * argument. It is called each time the core exits the kernel, after handling an 482 * interrupt, exception or syscall. 483 483 * TODO This function is not implemented. 484 484 *************************************************************************************** … … 494 494 * @ pid : process identifier. 495 495 * @ trdid : thread identifier. 496 * @ return the extended pointer if thread found / return XPTR_NULL if not found. 496 * @ return the extended pointer if thread found / return XPTR_NULL if not found. 497 497 **************************************************************************************/ 498 498 xptr_t thread_get_xptr( pid_t pid,
Note: See TracChangeset
for help on using the changeset viewer.