Changeset 457 for trunk/kernel/kern/thread.c
- Timestamp:
- Aug 2, 2018, 11:47:13 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.c
r450 r457 24 24 25 25 #include <kernel_config.h> 26 #include <hal_ types.h>26 #include <hal_kernel_types.h> 27 27 #include <hal_context.h> 28 28 #include <hal_irqmask.h> … … 167 167 thread->quantum = 0; // TODO 168 168 thread->ticks_nr = 0; // TODO 169 thread->time_last_check = 0; 169 thread->time_last_check = 0; // TODO 170 170 thread->core = &local_cluster->core_tbl[core_lid]; 171 171 thread->process = process; … … 243 243 uint32_t cycle = (uint32_t)hal_get_cycles(); 244 244 if( DEBUG_THREAD_USER_CREATE < cycle ) 245 printk("\n[DBG] %s : thread %x enter for process %xin cluster %x / cycle %d\n",246 __FUNCTION__, CURRENT_THREAD , pid , local_cxy , cycle );245 printk("\n[DBG] %s : thread %x in process %x enter in cluster %x / cycle %d\n", 246 __FUNCTION__, CURRENT_THREAD->trdid, pid , local_cxy , cycle ); 247 247 #endif 248 248 … … 301 301 } 302 302 303 #if( DEBUG_THREAD_USER_CREATE & 1) 304 if( DEBUG_THREAD_USER_CREATE < cycle ) 305 printk("\n[DBG] %s : stack vseg created / vpn_base %x / %d pages\n", 306 __FUNCTION__, vseg->vpn_base, vseg->vpn_size ); 307 #endif 308 303 309 // allocate memory for thread descriptor 304 310 thread = thread_alloc(); … … 313 319 #if( DEBUG_THREAD_USER_CREATE & 1) 314 320 if( DEBUG_THREAD_USER_CREATE < cycle ) 315 printk("\n[DBG] %s : thread descriptor %x allocated\n",321 printk("\n[DBG] %s : new thread descriptor %x allocated\n", 316 322 __FUNCTION__, thread ); 317 323 #endif … … 336 342 #if( DEBUG_THREAD_USER_CREATE & 1) 337 343 if( DEBUG_THREAD_USER_CREATE < cycle ) 338 printk("\n[DBG] %s : thread descriptor %x initialised / trdid =%x\n",339 __FUNCTION__, thread , thread->trdid );344 printk("\n[DBG] %s : new thread descriptor initialised / trdid %x\n", 345 __FUNCTION__, thread->trdid ); 340 346 #endif 341 347 … … 347 353 348 354 // allocate & initialize CPU context 349 if( hal_cpu_context_ create( thread ) )355 if( hal_cpu_context_alloc( thread ) ) 350 356 { 351 357 printk("\n[ERROR] in %s : cannot create CPU context\n", __FUNCTION__ ); … … 354 360 return ENOMEM; 355 361 } 356 357 // allocate FPU context 362 hal_cpu_context_init( thread ); 363 364 // allocate & initialize FPU context 358 365 if( hal_fpu_context_alloc( thread ) ) 359 366 { … … 363 370 return ENOMEM; 364 371 } 372 hal_fpu_context_init( thread ); 373 374 #if( DEBUG_THREAD_USER_CREATE & 1) 375 if( DEBUG_THREAD_USER_CREATE < cycle ) 376 printk("\n[DBG] %s : CPU & FPU contexts created\n", 377 __FUNCTION__, thread->trdid ); 378 vmm_display( process , true ); 379 #endif 365 380 366 381 #if DEBUG_THREAD_USER_CREATE 367 382 cycle = (uint32_t)hal_get_cycles(); 368 383 if( DEBUG_THREAD_USER_CREATE < cycle ) 369 printk("\n[DBG] %s : thread %x exit / new_thread %x in process%x / core %d / cycle %d\n",370 __FUNCTION__, CURRENT_THREAD , thread->trdid , pid, core_lid, cycle );384 printk("\n[DBG] %s : thread %x in process %x exit / new_thread %x / core %d / cycle %d\n", 385 __FUNCTION__, CURRENT_THREAD->trdid , pid, thread->trdid, core_lid, cycle ); 371 386 #endif 372 387 … … 554 569 } // end thread_user_fork() 555 570 571 //////////////////////////////////////////////// 572 error_t thread_user_exec( void * entry_func, 573 uint32_t argc, 574 char ** argv ) 575 { 576 thread_t * thread = CURRENT_THREAD; 577 process_t * process = thread->process; 578 579 #if DEBUG_THREAD_USER_EXEC 580 uint32_t cycle = (uint32_t)hal_get_cycles(); 581 if( DEBUG_THREAD_USER_EXEC < cycle ) 582 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n", 583 __FUNCTION__, thread->trdid, process->pid, cycle ); 584 #endif 585 586 assert( (thread->type == THREAD_USER ) , __FUNCTION__, "bad type" ); 587 assert( (thread->signature == THREAD_SIGNATURE) , __FUNCTION__, "bad signature" ); 588 assert( (thread->local_locks == 0) , __FUNCTION__, "bad local locks" ); 589 assert( (thread->remote_locks == 0) , __FUNCTION__, "bad remote locks" ); 590 591 // re-initialize various thread descriptor fields 592 thread->quantum = 0; // TODO 593 thread->ticks_nr = 0; // TODO 594 thread->time_last_check = 0; // TODO 595 596 #if CONFIG_LOCKS_DEBUG 597 list_root_init( &thread->locks_root ); 598 xlist_root_init( XPTR( local_cxy , &thread->xlocks_root ) ); 599 #endif 600 601 thread->entry_func = entry_func; 602 thread->main_argc = argc; 603 thread->main_argv = argv; 604 605 // the main thread is always detached 606 thread->flags = THREAD_FLAG_DETACHED; 607 thread->blocked = 0; 608 thread->errno = 0; 609 thread->fork_user = 0; // not inherited 610 thread->fork_cxy = 0; // not inherited 611 612 // reset thread info 613 memset( &thread->info , 0 , sizeof(thread_info_t) ); 614 615 // initialize join_lock 616 remote_spinlock_init( XPTR( local_cxy , &thread->join_lock ) ); 617 618 // allocate an user stack vseg for main thread 619 vseg_t * vseg = vmm_create_vseg( process, 620 VSEG_TYPE_STACK, 621 0, // size unused 622 0, // length unused 623 0, // file_offset unused 624 0, // file_size unused 625 XPTR_NULL, // mapper_xp unused 626 local_cxy ); 627 if( vseg == NULL ) 628 { 629 printk("\n[ERROR] in %s : cannot create stack vseg for main thread\n", __FUNCTION__ ); 630 return -1; 631 } 632 633 // update user stack in stack descriptor 634 thread->u_stack_base = vseg->min; 635 thread->u_stack_size = vseg->max - vseg->min; 636 637 // release FPU ownership if required 638 if( thread->core->fpu_owner == thread ) thread->core->fpu_owner = NULL; 639 640 // re-initialize FPU context 641 hal_fpu_context_init( thread ); 642 643 #if DEBUG_THREAD_USER_EXEC 644 cycle = (uint32_t)hal_get_cycles(); 645 if( DEBUG_THREAD_USER_EXEC < cycle ) 646 printk("\n[DBG] %s : thread %x in process %x set CPU context & jump to user code / cycle %d\n", 647 __FUNCTION__, thread->trdid, process->pid, cycle ); 648 vmm_display( process , true ); 649 #endif 650 651 // re-initialize CPU context... and jump to user code 652 hal_cpu_context_exec( thread ); 653 654 assert( false, __FUNCTION__, "we should execute this code"); 655 656 return 0; 657 658 } // end thread_user_exec() 659 556 660 ///////////////////////////////////////////////////////// 557 661 error_t thread_kernel_create( thread_t ** new_thread, … … 594 698 { 595 699 thread_release( thread ); 700 return ENOMEM; 701 } 702 703 // allocate & initialize CPU context 704 error = hal_cpu_context_alloc( thread ); 705 if( error ) 706 { 707 thread_release( thread ); 596 708 return EINVAL; 597 709 } 598 599 // allocate & initialize CPU context 600 hal_cpu_context_create( thread ); 710 hal_cpu_context_init( thread ); 711 601 712 602 713 #if DEBUG_THREAD_KERNEL_CREATE … … 612 723 } // end thread_kernel_create() 613 724 614 ////////////////////////////////////////////// ///615 error_tthread_idle_init( thread_t * thread,616 617 618 619 725 ////////////////////////////////////////////// 726 void thread_idle_init( thread_t * thread, 727 thread_type_t type, 728 void * func, 729 void * args, 730 lid_t core_lid ) 620 731 { 621 732 assert( (type == THREAD_IDLE) , __FUNCTION__ , "illegal thread type" ); 622 623 733 assert( (core_lid < LOCAL_CLUSTER->cores_nr) , __FUNCTION__ , "illegal core index" ); 624 734 735 // initialize thread descriptor 625 736 error_t error = thread_init( thread, 626 737 &process_zero, … … 631 742 0 , 0 ); // no user stack for a kernel thread 632 743 744 assert( (error == 0), __FUNCTION__, "cannot create thread idle" ); 745 633 746 // allocate & initialize CPU context if success 634 if( error == 0 ) hal_cpu_context_create( thread ); 635 636 return error; 747 error = hal_cpu_context_alloc( thread ); 748 749 assert( (error == 0), __FUNCTION__, "cannot allocate CPU context" ); 750 751 hal_cpu_context_init( thread ); 637 752 638 753 } // end thread_idle_init() … … 798 913 799 914 #if DEBUG_THREAD_BLOCK 800 uint32_t cycle = (uint32_t)hal_get_cycles(); 915 uint32_t cycle = (uint32_t)hal_get_cycles(); 916 process_t * process = hal_remote_lpt( XPTR( cxy , &ptr->process ) ); 801 917 if( DEBUG_THREAD_BLOCK < cycle ) 802 printk("\n[DBG] %s : thread %x in cxy %x blocked thread %x in cxy %x / cause %x / cycle %d\n", 803 __FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle ); 918 printk("\n[DBG] %s : thread %x in process %x blocked thread %x in process %x / cause %x\n", 919 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, 920 ptr->trdid, hal_remote_lw(XPTR( cxy , &process->pid )), cause ); 804 921 #endif 805 922 … … 819 936 820 937 #if DEBUG_THREAD_BLOCK 821 uint32_t cycle = (uint32_t)hal_get_cycles(); 938 uint32_t cycle = (uint32_t)hal_get_cycles(); 939 process_t * process = hal_remote_lpt( XPTR( cxy , &ptr->process ) ); 822 940 if( DEBUG_THREAD_BLOCK < cycle ) 823 printk("\n[DBG] %s : thread %x in cxy %x unblocked thread %x in cxy %x / cause %x / cycle %d\n", 824 __FUNCTION__ , CURRENT_THREAD , local_cxy , ptr , cxy , cause , cycle ); 941 printk("\n[DBG] %s : thread %x in process %x unblocked thread %x in process %x / cause %x\n", 942 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, 943 ptr->trdid, hal_remote_lw(XPTR( cxy , &process->pid )), cause ); 825 944 #endif 826 945
Note: See TracChangeset
for help on using the changeset viewer.