Changeset 635 for trunk/kernel/mm/ppm.c


Ignore:
Timestamp:
Jun 26, 2019, 11:42:37 AM (16 months ago)
Author:
alain
Message:

This version is a major evolution: The physical memory allocators,
defined in the kmem.c, ppm.c, and kcm.c files have been modified
to support remote accesses. The RPCs that were previously user
to allocate physical memory in a remote cluster have been removed.
This has been done to cure a dead-lock in case of concurrent page-faults.

This version 2.2 has been tested on a (4 clusters / 2 cores per cluster)
TSAR architecture, for both the "sort" and the "fft" applications.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/ppm.c

    r634 r635  
    212212        page_t   * found_block; 
    213213
     214    thread_t * this = CURRENT_THREAD;
     215
    214216#if DEBUG_PPM_ALLOC_PAGES
    215 thread_t * this = CURRENT_THREAD;
    216217uint32_t cycle = (uint32_t)hal_get_cycles();
    217218if( DEBUG_PPM_ALLOC_PAGES < cycle )
     
    237238
    238239        current_block = NULL;
    239 
    240         // find a free block equal or larger to requested size
    241         for( current_order = order ; current_order < CONFIG_PPM_MAX_ORDER ; current_order ++ )
    242         {
    243                 if( !list_is_empty( &ppm->free_pages_root[current_order] ) )
     240    current_order = order;
     241
     242        // search a free block equal or larger than requested size
     243        while( current_order < CONFIG_PPM_MAX_ORDER )
     244        {
     245        // get local pointer on the root of relevant free_list (same in all clusters)
     246        list_entry_t * root = &ppm->free_pages_root[current_order];
     247
     248                if( !list_is_empty( root ) )
    244249                {
    245250            // get first free block in this free_list
    246                         current_block = LIST_FIRST( &ppm->free_pages_root[current_order] , page_t , list );
     251                        current_block = LIST_FIRST( root , page_t , list );
    247252
    248253            // remove this block from this free_list
    249254                        list_unlink( &current_block->list );
     255                ppm->free_pages_nr[current_order] --;
    250256
    251257            // register pointer on found block
    252258            found_block = current_block;
    253259
    254             // update this free-list number of blocks
    255                 ppm->free_pages_nr[current_order] --;
    256 
    257260            // compute found block size
    258261                current_size = (1 << current_order);
     
    260263                        break; 
    261264                }
     265
     266        // increment loop index
     267        current_order++;
    262268        }
    263269
     
    267273                remote_busylock_release( lock_xp );
    268274
    269 #if DEBUG_PPM_ALLOC_PAGES
    270 cycle = (uint32_t)hal_get_cycles();
    271 if( DEBUG_PPM_ALLOC_PAGES < cycle )
    272 printk("\n[%s] thread[%x,%x] cannot allocate %d page(s) in cluster %x / cycle %d\n",
    273 __FUNCTION__, this->process->pid, this->trdid, 1<<order, local_cxy, cycle );
    274 #endif
     275        printk("\n[%s] thread[%x,%x] cannot allocate %d page(s) in cluster %x\n",
     276        __FUNCTION__, this->process->pid, this->trdid, 1<<order, local_cxy );
    275277
    276278                return NULL;
     
    282284        while( current_order > order )
    283285        {
     286        // update size and order
    284287                current_order --;
    285 
    286         // update pointer, size, and order fiels for new free block
    287288                current_size >>= 1;
     289
     290        // update order fiels in new free block
    288291                current_block = found_block + current_size;
    289292                current_block->order = current_order;
     
    291294        // insert new free block in relevant free_list
    292295                list_add_first( &ppm->free_pages_root[current_order] , &current_block->list );
    293 
    294         // update number of blocks in free list
    295296                ppm->free_pages_nr[current_order] ++;
    296297        }
     
    312313printk("\n[%s] thread[%x,%x] exit for %d page(s) in cluster %x / ppn = %x / cycle %d\n",
    313314__FUNCTION__, this->process->pid, this->trdid,
    314 1<<order, ppm_page2ppn(XPTR( local_cxy , found_block )), local_cxy, cycle );
     3151<<order, local_cxy, ppm_page2ppn(XPTR( local_cxy , found_block )), cycle );
    315316#endif
    316317
     
    374375
    375376/////////////////////////////////////////////
    376 xptr_t ppm_remote_alloc_pages( cxy_t     cxy,
     377void * ppm_remote_alloc_pages( cxy_t     cxy,
    377378                               uint32_t  order )
    378379{
     
    382383    page_t   * found_block;
    383384
     385    thread_t * this  = CURRENT_THREAD;
     386
    384387#if DEBUG_PPM_REMOTE_ALLOC_PAGES
    385 thread_t * this  = CURRENT_THREAD;
    386388uint32_t   cycle = (uint32_t)hal_get_cycles();
    387389if( DEBUG_PPM_REMOTE_ALLOC_PAGES < cycle )
     
    408410
    409411    current_block = NULL;   
    410 
    411         // find in remote cluster a free block equal or larger to requested size
    412         for( current_order = order ; current_order < CONFIG_PPM_MAX_ORDER ; current_order ++ )
    413         {
    414         // get local pointer on the root of relevant free_list in remote cluster
     412    current_order = order;
     413
     414    // search a free block equal or larger than requested size
     415    while( current_order < CONFIG_PPM_MAX_ORDER )
     416    {
     417        // get local pointer on the root of relevant free_list (same in all clusters)
    415418        list_entry_t * root = &ppm->free_pages_root[current_order];
    416419
    417                 if( !list_remote_is_empty( cxy , root ) )
     420                if( !list_remote_is_empty( cxy , root ) )  // list non empty => success
    418421                {
    419422            // get local pointer on first free page descriptor in remote cluster
     
    422425            // remove first free page from the free-list in remote cluster
    423426                        list_remote_unlink( cxy , &current_block->list );
     427                hal_remote_atomic_add( XPTR( cxy , &ppm->free_pages_nr[current_order] ), -1 );
    424428
    425429            // register found block
    426430            found_block = current_block;
    427431
    428                 // decrement relevant free-list number of items in remote cluster
    429                 hal_remote_atomic_add( XPTR( cxy , &ppm->free_pages_nr[current_order] ), -1 );
    430 
    431432            // compute found block size
    432433                current_size = (1 << current_order);
     
    434435                        break;
    435436                }
     437
     438        // increment loop index
     439        current_order++;
    436440        }
    437441
     
    441445                remote_busylock_release( lock_xp );
    442446
    443 #if DEBUG_REMOTE_PPM_ALLOC_PAGES
    444 cycle = (uint32_t)hal_get_cycles();
    445 if( DEBUG_PPM_REMOTE_ALLOC_PAGES < cycle )
    446 printk("\n[%s] thread[%x,%x] cannot allocate %d page(s) in cluster %x / cycle %d\n",
    447 __FUNCTION__, this->process->pid, this->trdid, 1<<order, cxy, cycle );
    448 #endif
     447        printk("\n[ERROR] in %s : thread[%x,%x] cannot allocate %d page(s) in cluster %x\n",
     448        __FUNCTION__, this->process->pid, this->trdid, 1<<order, cxy );
    449449
    450450                return XPTR_NULL;
     
    455455        while( current_order > order )
    456456        {
    457         // update order, size, and local pointer for new free block
     457        // update order and size
    458458                current_order --;
    459459                current_size >>= 1;
     460
     461        // update new free block order field in remote cluster
    460462                current_block = found_block + current_size;
    461 
    462         // update new free block order field in remote cluster
    463463                hal_remote_s32( XPTR( cxy , &current_block->order ) , current_order );
    464464
     
    497497#endif
    498498
    499         return XPTR( cxy , found_block );
     499        return found_block;
    500500
    501501}  // end ppm_remote_alloc_pages()
Note: See TracChangeset for help on using the changeset viewer.