Changeset 5 for trunk/kernel/kern/thread.c
- Timestamp:
- Apr 26, 2017, 2:11:56 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.c
r1 r5 8 8 * Copyright (c) UPMC Sorbonne Universites 9 9 * 10 * This file is part of ALMOS-MKH. .10 * This file is part of ALMOS-MKH. 11 11 * 12 * ALMOS-MKH .is free software; you can redistribute it and/or modify it12 * ALMOS-MKH is free software; you can redistribute it and/or modify it 13 13 * under the terms of the GNU General Public License as published by 14 14 * the Free Software Foundation; version 2.0 of the License. 15 15 * 16 * ALMOS-MKH .is distributed in the hope that it will be useful, but16 * ALMOS-MKH is distributed in the hope that it will be useful, but 17 17 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 20 20 * 21 21 * You should have received a copy of the GNU General Public License 22 * along with ALMOS-MKH .; if not, write to the Free Software Foundation,22 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 23 23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 24 */ … … 62 62 }; 63 63 64 ////////////////////////////////////////////////////////////////////////////////////// 65 // This static function returns a printable string for the thread type. 66 ////////////////////////////////////////////////////////////////////////////////////// 67 char * thread_type_str( uint32_t type ) 68 { 69 if ( type == THREAD_USER ) return "THREAD_USER"; 70 else if( type == THREAD_RPC ) return "THREAD_RPC"; 71 else if( type == THREAD_DEV ) return "THREAD_DEV"; 72 else if( type == THREAD_KERNEL ) return "THREAD_KERNEL"; 73 else if( type == THREAD_IDLE ) return "THREAD_IDLE"; 74 else return "undefined"; 75 } 76 64 77 ///////////////////////////////////////////////////////////////////////////////////// 65 78 // This static function makes the actual allocation and initialisation for a thread … … 76 89 // @ core_lid : target core local index. 77 90 ///////////////////////////////////////////////////////////////////////////////////// 78 static error_t __thread_create( thread_t ** new_thread,79 80 81 82 83 84 85 91 static error_t thread_create( thread_t ** new_thread, 92 process_t * process, 93 thread_type_t type, 94 void * func, 95 void * args, 96 lid_t core_lid, 97 intptr_t u_stack_base, 98 uint32_t u_stack_size ) 86 99 { 87 100 error_t error; … … 171 184 *new_thread = thread; 172 185 return 0; 173 } // end __thread_create()186 } // end thread_create() 174 187 175 188 … … 185 198 lid_t core_lid; // selected core local index 186 199 200 thread_dmsg("\n[INFO] %s : enters\n", 201 __FUNCTION__ ); 202 187 203 cluster_t * local_cluster = LOCAL_CLUSTER; 188 204 … … 199 215 200 216 // make allocation / initialisation 201 error = __thread_create( &thread,202 203 204 205 206 207 208 217 error = thread_create( &thread, 218 process, 219 THREAD_USER, 220 attr->entry_func, 221 attr->entry_args, 222 core_lid, 223 u_stack_base, 224 u_stack_size ); 209 225 if( error ) return ENOMEM; 210 226 … … 220 236 error = hal_fpu_context_create( thread ); 221 237 if( error ) return ENOMEM; 222 223 thread_dmsg(" INFO : %s thread %x for process %x on core %d in cluster %x\n",224 __FUNCTION__, thread->trdid, process->pid, core_lid, local_cluster->cxy);238 239 thread_dmsg("\n[INFO] %s : exit / trdid = %x / process %x / core = %d\n", 240 __FUNCTION__ , thread->trdid , process->pid , core_lid ); 225 241 226 242 *new_thread = thread; … … 239 255 lid_t core_lid; // selected core local index 240 256 257 thread_dmsg("\n[INFO] %s : enters\n", 258 __FUNCTION__ ); 259 241 260 // select a target core in local cluster 242 261 core_lid = cluster_select_local_core(); … … 246 265 247 266 // make allocation / initialisation 248 error = __thread_create( &new,249 250 251 252 253 254 255 267 error = thread_create( &new, 268 process, 269 THREAD_USER, 270 this->entry_func, 271 this->entry_args, 272 core_lid, 273 u_stack_base, 274 u_stack_size ); 256 275 if( error ) return ENOMEM; 257 276 … … 268 287 269 288 thread_dmsg("INFO : %s thread %x for process %x on core %d in cluster %x\n", 270 __FUNCTION__, new->trdid, process->pid, core_lid, local_c luster->cxy );289 __FUNCTION__, new->trdid, process->pid, core_lid, local_cxy ); 271 290 272 291 *new_thread = new; 273 292 return 0; 293 274 294 } // end thread_user_fork() 275 295 … … 286 306 thread_t * new; // pointer on new thread descriptor 287 307 288 cluster_t * local_cluster = LOCAL_CLUSTER; 289 290 // check type argument 291 if( (type != THREAD_KERNEL) && (type != THREAD_RPC) && 292 (type != THREAD_IDLE) && (type != THREAD_DEV) ) 293 { 294 printk("ERROR : %s received an illegal thread type\n", __FUNCTION__ ); 295 hal_core_sleep(); 296 } 297 298 // check core local index 299 if( core_lid >= local_cluster->cores_nr ) 300 { 301 printk("ERROR : %s received an illegal core_lid\n", __FUNCTION__ ); 302 hal_core_sleep(); 303 } 308 thread_dmsg("\n[INFO] %s : enters for %s in cluster %x\n", 309 __FUNCTION__ , thread_type_str( type ) , local_cxy ); 310 311 assert( ( (type == THREAD_KERNEL) || (type == THREAD_RPC) || 312 (type == THREAD_IDLE) || (type == THREAD_DEV) ) , 313 __FUNCTION__ , "illegal thread type" ); 314 315 assert( (core_lid < LOCAL_CLUSTER->cores_nr) , 316 __FUNCTION__ , "illegal core_lid" ); 304 317 305 318 // make allocation / initialisation 306 error = __thread_create( &new,307 308 309 310 311 312 319 error = thread_create( &new, 320 &process_zero, 321 type, 322 func, 323 args, 324 core_lid, 325 0 , 0 ); // no user stack for a kernel thread 313 326 if( error ) 314 327 { 315 printk(" ERROR : %scannot create thread\n", __FUNCTION__ );316 hal_core_sleep();328 printk("\n[ERROR] in %s : cannot create thread\n", __FUNCTION__ ); 329 return ENOMEM; 317 330 } 318 331 … … 320 333 hal_cpu_context_create( new ); 321 334 322 thread_dmsg(" INFO : %s thread %x in cluster %x on core%d\n",323 __FUNCTION__ , new->trdid , local_cluster->cxy ,core_lid );335 thread_dmsg("\n[INFO] %s : sucessfully exit / trdid = %x / core = %d\n", 336 __FUNCTION__ , new->trdid , core_lid ); 324 337 325 338 *new_thread = new; 326 339 return 0; 340 327 341 } // end thread_kernel_create() 328 342 … … 341 355 core_t * core = thread->core; 342 356 343 if( thread->children_nr ) 344 { 345 printk("\n[PANIC] in %s : thread %x for process %x on core %d in cluster %x" 346 " has still attached children\n", 347 __FUNCTION__, thread->trdid, process->pid, core->lid, local_cxy ); 348 hal_core_sleep(); 349 } 350 351 if( (thread->local_locks != 0) || (thread->remote_locks != 0) ) 352 { 353 printk("\n[PANIC] in %s : thread %x for process %x on core %d in cluster %x" 354 " did not released all locks\n", 355 __FUNCTION__, thread->trdid, process->pid, core->lid, local_cxy ); 356 hal_core_sleep(); 357 } 357 thread_dmsg("\n[INFO] %s : enters for thread %x in process %x / type = %s\n", 358 __FUNCTION__ , thread->trdid , process->pid , thread_type_str( thread->type ) ); 359 360 assert( (thread->children_nr == 0) , __FUNCTION__ , "still attached children" ); 361 362 assert( (thread->local_locks == 0) , __FUNCTION__ , "all local locks not released" ); 358 363 364 assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" ); 365 359 366 tm_start = hal_time_stamp(); 360 367 … … 402 409 tm_end = hal_time_stamp(); 403 410 404 thread_dmsg("INFO : %s destroy thread %x for process %x on core %d in cluster %x\n" 405 " / duration = %d / page_faults = %d / ticks = %d\n", 406 __FUNCTION__, trdid , pid , core_lid , local_cxy , 407 tm_end - tm_start , pgfaults , ticks ); 411 thread_dmsg("\n[INFO] %s : exit for thread %x in process %x / duration = %d\n", 412 __FUNCTION__, thread->trdid , process->pid , tm_end - tm_start ); 408 413 409 414 } // end thread_destroy() … … 592 597 while( 1 ) 593 598 { 594 thread_dmsg(" INFO: core %d in cluster %x goes to sleeping state at cycle\n",595 core->lid , cluster->cxy, hal_time_stamp() );599 thread_dmsg("\n[INFO] %s : core %d in cluster %x goes to sleeping state at cycle\n", 600 __FUNCTION__ , core->lid , local_cxy , hal_time_stamp() ); 596 601 597 602 // force core to sleeping state 598 603 hal_core_sleep(); 599 604 600 thread_dmsg(" INFO: core %d in cluster %x wake up at cycle %d\n",601 core->lid , cluster->cxy, hal_time_stamp() );605 thread_dmsg("\n[INFO] %s : core %d in cluster %x wake up at cycle %d\n", 606 __FUNCTION__ , core->lid , local_cxy , hal_time_stamp() ); 602 607 603 608 // force scheduling at wake-up
Note: See TracChangeset
for help on using the changeset viewer.