Changeset 641 for trunk/kernel/mm
- Timestamp:
- Oct 10, 2019, 1:42:04 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/vmm.c
r640 r641 3 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011, 2012) 5 * Mohamed Lamine Karaoui (2015)6 5 * Alain Greiner (2016,2017,2018,2019) 7 6 * … … 29 28 #include <hal_gpt.h> 30 29 #include <hal_vmm.h> 30 #include <hal_irqmask.h> 31 31 #include <hal_macros.h> 32 32 #include <printk.h> … … 217 217 218 218 //////////////////////////////////////////////////////////////////////////////////////////// 219 // This static function i s called by the vmm_remove_vseg() function, and implements220 // the VMM MMAP specific desallocator.219 // This static function implements the VMM MMAP specific desallocator. 220 // It is called by the vmm_remove_vseg() function. 221 221 //////////////////////////////////////////////////////////////////////////////////////////// 222 222 // @ vmm : [in] pointer on VMM. … … 495 495 intptr_t base ) 496 496 { 497 pid_t pid;498 497 cxy_t owner_cxy; 499 498 lpid_t owner_lpid; 500 501 xlist_entry_t * process_root_ptr; 499 reg_t save_sr; 500 501 xptr_t process_lock_xp; 502 502 xptr_t process_root_xp; 503 503 xptr_t process_iter_xp; … … 511 511 xptr_t vsl_iter_xp; 512 512 513 rpc_desc_t rpc; // shared rpc descriptor for parallel RPCs 514 uint32_t responses; // RPC responses counter 515 516 thread_t * this = CURRENT_THREAD; 517 pid_t pid = process->pid; 518 cluster_t * cluster = LOCAL_CLUSTER; 519 513 520 #if DEBUG_VMM_GLOBAL_DELETE_VSEG 514 521 uint32_t cycle = (uint32_t)hal_get_cycles(); 515 thread_t * this = CURRENT_THREAD;516 522 #endif 517 523 518 524 #if (DEBUG_VMM_GLOBAL_DELETE_VSEG & 1) 519 525 if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle ) 520 printk("\n[%s] thread[%x,%x] :process %x / base %x / cycle %d\n",526 printk("\n[%s] thread[%x,%x] enters / process %x / base %x / cycle %d\n", 521 527 __FUNCTION__, this->process->pid, this->trdid, process->pid, base, cycle ); 522 528 #endif 523 529 530 // initialize a shared RPC descriptor 531 rpc.rsp = &responses; 532 rpc.blocking = false; // non blocking behaviour for rpc_send() 533 rpc.index = RPC_VMM_REMOVE_VSEG; 534 rpc.thread = this; 535 rpc.lid = this->core->lid; 536 rpc.args[0] = this->process->pid; 537 rpc.args[1] = base; 538 524 539 // get owner process cluster and local index 525 pid = process->pid;526 540 owner_cxy = CXY_FROM_PID( pid ); 527 541 owner_lpid = LPID_FROM_PID( pid ); 528 542 529 // get extended pointer on root of process copies xlist in owner cluster 530 process_root_ptr = &LOCAL_CLUSTER->pmgr.copies_root[owner_lpid]; 531 process_root_xp = XPTR( owner_cxy , process_root_ptr ); 543 // get extended pointer on root and lock of process copies xlist in owner cluster 544 process_root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[owner_lpid] ); 545 process_lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[owner_lpid] ); 546 547 // mask IRQs 548 hal_disable_irq( &save_sr ); 549 550 // client thread blocks itself 551 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_RPC ); 552 553 // take the lock protecting process copies 554 remote_queuelock_acquire( process_lock_xp ); 555 556 // initialize responses counter 557 responses = 0; 532 558 533 559 // loop on process copies … … 559 585 if( vseg_base == base ) // found searched vseg 560 586 { 561 if( remote_process_cxy == local_cxy ) 562 { 563 vmm_remove_vseg( process, 564 vseg_ptr ); 565 } 566 else 567 { 568 rpc_vmm_remove_vseg_client( remote_process_cxy, 569 remote_process_ptr, 570 vseg_ptr ); 571 } 587 // atomically increment responses counter 588 hal_atomic_add( &responses , 1 ); 572 589 573 590 #if (DEBUG_VMM_GLOBAL_DELETE_VSEG & 1) 574 591 if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle ) 575 printk("\n[%s] thread[%x,%x] deleted vseg %x for process %x in cluster %x\n", 576 __FUNCTION__, this->process->pid, this->trdid, base, process->pid, remote_process_cxy ); 577 #endif 578 592 printk("\n[%s] thread[%x,%x] register RPC request in cluster %x\n", 593 __FUNCTION__, this->process->pid, this->trdid, remote_process_cxy ); 594 #endif 595 // send RPC to remote cluster 596 rpc_send( remote_process_cxy , &rpc ); 597 598 // exit loop on vsegs 599 break; 579 600 } 580 601 } // end of loop on vsegs 581 602 603 // release lock on remote VSL 604 remote_queuelock_release( vsl_lock_xp ); 605 606 } // end of loop on process copies 607 608 // release the lock protecting process copies 609 remote_queuelock_release( process_lock_xp ); 610 582 611 #if (DEBUG_VMM_GLOBAL_DELETE_VSEG & 1) 583 612 if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle ) 584 hal_vmm_display( remote_process_xp , false ); 585 #endif 586 587 // release lock on remote VSL 588 remote_queuelock_release( vsl_lock_xp ); 589 590 } // end of loop on process copies 613 printk("\n[%s] thread[%x,%x] deschedule / process %x / base %x\n", 614 __FUNCTION__, this->process->pid, this->trdid, process->pid, base ); 615 #endif 616 617 // client thread deschedule 618 sched_yield("blocked on rpc_vmm_delete_vseg"); 619 620 // restore IRQs 621 hal_restore_irq( save_sr ); 591 622 592 623 #if DEBUG_VMM_GLOBAL_DELETE_VSEG 593 624 cycle = (uint32_t)hal_get_cycles(); 594 625 if( DEBUG_VMM_GLOBAL_DELETE_VSEG < cycle ) 595 printk("\n[%s] thread[%x,%x] exit forprocess %x / base %x / cycle %d\n",596 __FUNCTION__, this->process->pid, this->trdid, process->pid 626 printk("\n[%s] thread[%x,%x] exit / process %x / base %x / cycle %d\n", 627 __FUNCTION__, this->process->pid, this->trdid, process->pid, base, cycle ); 597 628 #endif 598 629 … … 605 636 intptr_t new_size ) 606 637 { 607 pid_t pid;608 638 cxy_t owner_cxy; 609 639 lpid_t owner_lpid; 610 611 xlist_entry_t * process_root_ptr; 640 reg_t save_sr; 641 642 xptr_t process_lock_xp; 612 643 xptr_t process_root_xp; 613 644 xptr_t process_iter_xp; … … 621 652 xptr_t vsl_iter_xp; 622 653 654 rpc_desc_t rpc; // shared rpc descriptor for parallel RPCs 655 uint32_t responses; // RPC responses counter 656 657 thread_t * this = CURRENT_THREAD; 658 pid_t pid = process->pid; 659 cluster_t * cluster = LOCAL_CLUSTER; 660 623 661 #if DEBUG_VMM_GLOBAL_RESIZE_VSEG 624 662 uint32_t cycle = (uint32_t)hal_get_cycles(); 625 thread_t * this = CURRENT_THREAD;626 663 #endif 627 664 … … 632 669 #endif 633 670 634 // get owner process cluster and local index 635 pid = process->pid; 671 // initialize a shared RPC descriptor 672 rpc.rsp = &responses; 673 rpc.blocking = false; // non blocking behaviour for rpc_send() 674 rpc.index = RPC_VMM_REMOVE_VSEG; 675 rpc.thread = this; 676 rpc.lid = this->core->lid; 677 rpc.args[0] = this->process->pid; 678 rpc.args[1] = base; 679 rpc.args[2] = new_base; 680 rpc.args[3] = new_size; 681 682 // get owner process cluster and local index 636 683 owner_cxy = CXY_FROM_PID( pid ); 637 684 owner_lpid = LPID_FROM_PID( pid ); 638 685 639 // get extended pointer on root of process copies xlist in owner cluster 640 process_root_ptr = &LOCAL_CLUSTER->pmgr.copies_root[owner_lpid]; 641 process_root_xp = XPTR( owner_cxy , process_root_ptr ); 686 // get extended pointer on root and lock of process copies xlist in owner cluster 687 process_root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[owner_lpid] ); 688 process_lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[owner_lpid] ); 689 690 // mask IRQs 691 hal_disable_irq( &save_sr ); 692 693 // client thread blocks itself 694 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_RPC ); 695 696 // take the lock protecting process copies 697 remote_queuelock_acquire( process_lock_xp ); 698 699 // initialize responses counter 700 responses = 0; 642 701 643 702 // loop on process copies … … 669 728 if( vseg_base == base ) // found searched vseg 670 729 { 671 if( remote_process_cxy == local_cxy ) 672 { 673 vmm_resize_vseg( remote_process_ptr, 674 vseg_ptr, 675 new_base, 676 new_size ); 677 } 678 else 679 { 680 rpc_vmm_resize_vseg_client( remote_process_cxy, 681 remote_process_ptr, 682 vseg_ptr, 683 new_base, 684 new_size ); 685 } 686 730 // atomically increment responses counter 731 hal_atomic_add( &responses , 1 ); 732 687 733 #if (DEBUG_VMM_GLOBAL_RESIZE_VSEG & 1) 688 734 if( DEBUG_VMM_GLOBAL_RESIZE_VSEG < cycle ) 689 printk("\n[%s] thread[%x,%x] resized vseg %x for process %x in cluster %x\n", 690 __FUNCTION__, this->process->pid, this->trdid, base, process->pid, remote_process_cxy ); 691 #endif 692 735 printk("\n[%s] thread[%x,%x] register RPC request in cluster %x\n", 736 __FUNCTION__, this->process->pid, this->trdid, remote_process_cxy ); 737 #endif 738 // send RPC to remote cluster 739 rpc_send( remote_process_cxy , & rpc ); 740 741 // exit loop on vsegs 742 break; 693 743 } 744 694 745 } // end of loop on vsegs 695 746 … … 701 752 // release lock on remote VSL 702 753 remote_queuelock_release( vsl_lock_xp ); 754 703 755 } // end of loop on process copies 756 757 // release the lock protecting process copies 758 remote_queuelock_release( process_lock_xp ); 759 760 #if (DEBUG_VMM_GLOBAL_RESIZE_VSEG & 1) 761 if( DEBUG_VMM_GLOBAL_RESIZE_VSEG < cycle ) 762 printk("\n[%s] thread[%x,%x] deschedule / process %x / base %x\n", 763 __FUNCTION__, this->process->pid, this->trdid, process->pid, base ); 764 #endif 765 766 // client thread deschedule 767 sched_yield("blocked on rpc_vmm_delete_vseg"); 768 769 // restore IRQs 770 hal_restore_irq( save_sr ); 704 771 705 772 #if DEBUG_VMM_GLOBAL_RESIZE_VSEG … … 1552 1619 #if (DEBUG_VMM_REMOVE_VSEG & 1 ) 1553 1620 if( DEBUG_VMM_REMOVE_VSEG < cycle ) 1554 printk("\n[%s] thread[%x,%x] enter / process %x /%s / base %x / cycle %d\n",1621 printk("\n[%s] thread[%x,%x] enters / process %x / type %s / base %x / cycle %d\n", 1555 1622 __FUNCTION__, this->process->pid, this->trdid, 1556 1623 process->pid, vseg_type_str(vseg->type), vseg->min, cycle ); … … 1568 1635 #if( DEBUG_VMM_REMOVE_VSEG & 1 ) 1569 1636 if( DEBUG_VMM_REMOVE_VSEG < cycle ) 1570 printk("\n[%s] thread[%x,%x] unmap vpn %x / ppn %x / %s",1637 printk("\n[%s] thread[%x,%x] unmap vpn %x / ppn %x / type %s\n", 1571 1638 __FUNCTION__, this->process->pid, this->trdid, vpn , ppn, vseg_type_str(vseg_type) ); 1572 1639 #endif … … 1607 1674 cycle = (uint32_t)hal_get_cycles(); 1608 1675 if( DEBUG_VMM_REMOVE_VSEG < cycle ) 1609 printk(" [%s] thread[%x,%x] exit / process %x /%s / base %x / cycle %d\n",1676 printk("\n[%s] thread[%x,%x] exit / process %x / type %s / base %x / cycle %d\n", 1610 1677 __FUNCTION__, this->process->pid, this->trdid, 1611 1678 process->pid, vseg_type_str(vseg->type), vseg->min, cycle ); … … 1684 1751 { 1685 1752 1686 #if( DEBUG_VMM_RE MOVE_VSEG & 1 )1753 #if( DEBUG_VMM_RESIZE_VSEG & 1 ) 1687 1754 if( DEBUG_VMM_RESIZE_VSEG < cycle ) 1688 1755 printk("\n[%s] thread[%x,%x] unmap vpn %x / ppn %x / %s", … … 2189 2256 #if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT) 2190 2257 uint32_t end_cycle = (uint32_t)hal_get_cycles(); 2258 uint32_t cost = end_cycle - start_cycle; 2191 2259 #endif 2192 2260 … … 2199 2267 #if CONFIG_INSTRUMENTATION_PGFAULTS 2200 2268 this->info.local_pgfault_nr++; 2201 this->info.local_pgfault_cost += (end_cycle - start_cycle); 2269 this->info.local_pgfault_cost += cost; 2270 if( cost > this->info.local_pgfault_max ) this->info.local_pgfault_max = cost; 2202 2271 #endif 2203 2272 return EXCP_NON_FATAL; … … 2267 2336 #if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT) 2268 2337 uint32_t end_cycle = (uint32_t)hal_get_cycles(); 2338 uint32_t cost = end_cycle - start_cycle; 2269 2339 #endif 2270 2340 … … 2277 2347 #if CONFIG_INSTRUMENTATION_PGFAULTS 2278 2348 this->info.false_pgfault_nr++; 2279 this->info.false_pgfault_cost += (end_cycle - start_cycle); 2349 this->info.false_pgfault_cost += cost; 2350 if( cost > this->info.false_pgfault_max ) this->info.false_pgfault_max = cost; 2280 2351 #endif 2281 2352 return EXCP_NON_FATAL; … … 2332 2403 #if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT) 2333 2404 uint32_t end_cycle = (uint32_t)hal_get_cycles(); 2405 uint32_t cost = end_cycle - start_cycle; 2334 2406 #endif 2335 2407 … … 2342 2414 #if CONFIG_INSTRUMENTATION_PGFAULTS 2343 2415 this->info.global_pgfault_nr++; 2344 this->info.global_pgfault_cost += (end_cycle - start_cycle); 2416 this->info.global_pgfault_cost += cost; 2417 if( cost > this->info.global_pgfault_max ) this->info.global_pgfault_max = cost; 2345 2418 #endif 2346 2419 return EXCP_NON_FATAL; … … 2355 2428 #if (CONFIG_INSTRUMENTATION_PGFAULTS || DEBUG_VMM_HANDLE_PAGE_FAULT) 2356 2429 uint32_t end_cycle = (uint32_t)hal_get_cycles(); 2430 uint32_t cost = end_cycle - start_cycle; 2357 2431 #endif 2358 2432 … … 2365 2439 #if CONFIG_INSTRUMENTATION_PGFAULTS 2366 2440 this->info.false_pgfault_nr++; 2367 this->info.false_pgfault_cost += (end_cycle - start_cycle); 2441 this->info.false_pgfault_cost += cost; 2442 if( cost > this->info.false_pgfault_max ) this->info.false_pgfault_max = cost; 2368 2443 #endif 2369 2444 return EXCP_NON_FATAL;
Note: See TracChangeset
for help on using the changeset viewer.