Changeset 657 for trunk/kernel/mm/kcm.c


Ignore:
Timestamp:
Mar 18, 2020, 11:16:59 PM (4 years ago)
Author:
alain
Message:

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File:
1 edited

Legend:

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

    r656 r657  
    4343//////////////////////////////////////////////////////////////////////////////////////
    4444// This static function must be called by a local thread.
    45 // It returns a pointer on a block allocated from a non-full kcm_page.
    46 // It makes a panic if no block is available in selected page.
     45// It returns a pointer on a block allocated from an active kcm_page.
     46// It makes a panic if no block is available in the selected page.
    4747// It changes the page status as required.
    4848//////////////////////////////////////////////////////////////////////////////////////
    4949// @ kcm      : pointer on KCM allocator.
    50 // @ kcm_page : pointer on a non-full kcm_page.
     50// @ kcm_page : pointer on an active kcm_page.
    5151// @ return pointer on allocated block.
    5252/////////////////////////////////////////////////////////////////////////////////////
     
    6464    uint32_t index  = 1;
    6565    uint64_t mask   = (uint64_t)0x2;
    66     uint32_t found  = 0;
    6766
    6867        // allocate first free block in kcm_page, update status,
     
    7069    while( index <= max )
    7170    {
    72         if( (status & mask) == 0 )   // block non allocated
     71        if( (status & mask) == 0 )   // block found
    7372        {
     73            // update page count and status
    7474            kcm_page->status = status | mask;
    7575            kcm_page->count  = count + 1;
    76             found  = 1;
    77 
    7876            break;     
    7977        }
     
    8381    }
    8482
    85     // change the page list if almost full
     83    // change the page list if found block is the last
    8684    if( count == max-1 )
    8785    {
     
    162160
    163161/////////////////////////////////////////////////////////////////////////////////////
    164 // This private static function must be called by a local thread.
    165 // It returns one non-full kcm_page with te following policy :
     162// This static function must be called by a local thread.
     163// It returns one non-full kcm_page with the following policy :
    166164// - if the "active_list" is non empty, it returns the first "active" page,
    167165//   without modifying the KCM state.
    168 // - if the "active_list" is empty, it allocates a new page fromm PPM, inserts
     166// - if the "active_list" is empty, it allocates a new page from PPM, inserts
    169167//   this page in the active_list, and returns it.
    170168/////////////////////////////////////////////////////////////////////////////////////
     
    275273        // release KCM lock
    276274        remote_busylock_release( lock_xp );
    277 }
     275
     276}  // end kcm_destroy()
    278277
    279278//////////////////////////////////
     
    284283        void       * block_ptr;
    285284
    286     // min block size is 64 bytes
     285   // min block size is 64 bytes
    287286    if( order < 6 ) order = 6;
    288287
     
    301300    kcm_page = kcm_get_page( kcm_ptr );
    302301
     302#if DEBUG_KCM
     303thread_t * this  = CURRENT_THREAD;
     304uint32_t   cycle = (uint32_t)hal_get_cycles();
     305if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
     306{
     307printk("\n[%s] thread[%x,%x] enters / order %d / page %x / kcm %x / page_status (%x|%x)\n",
     308__FUNCTION__, this->process->pid, this->trdid, order, kcm_page, kcm_ptr,
     309GET_CXY( kcm_page->status ), GET_PTR( kcm_page->status ) );
     310kcm_remote_display( local_cxy , kcm_ptr );
     311}
     312#endif
     313
    303314    if( kcm_page == NULL )
    304315        {
     
    314325
    315326#if DEBUG_KCM
    316 thread_t * this  = CURRENT_THREAD;
    317 uint32_t   cycle = (uint32_t)hal_get_cycles();
    318 if( DEBUG_KCM < cycle )
    319 printk("\n[%s] thread[%x,%x] allocated block %x / order %d / kcm %x / status[%x,%x] / count %d\n",
    320 __FUNCTION__, this->process->pid, this->trdid, block_ptr, order, kcm_ptr,
    321 GET_CXY(kcm_page->status), GET_PTR(kcm_page->status), kcm_page->count );
     327if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
     328{
     329printk("\n[%s] thread[%x,%x] exit / order %d / block %x / kcm %x / page_status (%x|%x)\n",
     330__FUNCTION__, this->process->pid, this->trdid, order, block_ptr, kcm_ptr,
     331GET_CXY( kcm_page->status ), GET_PTR( kcm_page->status ) );
     332kcm_remote_display( local_cxy , kcm_ptr );
     333}
    322334#endif
    323335
     
    344356thread_t * this  = CURRENT_THREAD;
    345357uint32_t   cycle = (uint32_t)hal_get_cycles();
    346 if( DEBUG_KCM < cycle )
    347 printk("\n[%s] thread[%x,%x] release block %x / order %d / kcm %x / status [%x,%x] / count %d\n",
    348 __FUNCTION__, this->process->pid, this->trdid, block_ptr, kcm_ptr->order, kcm_ptr,
    349 GET_CXY(kcm_page->status), GET_PTR(kcm_page->status), kcm_page->count );
     358if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
     359{
     360printk("\n[%s] thread[%x,%x] enters / order %d / block %x / page %x / kcm %x / status [%x,%x]\n",
     361__FUNCTION__, this->process->pid, this->trdid, kcm_ptr->order, block_ptr, kcm_page, kcm_ptr,
     362GET_CXY(kcm_page->status), GET_PTR(kcm_page->status) );
     363kcm_remote_display( local_cxy , kcm_ptr );
     364}
    350365#endif
    351366
     
    361376        // release lock
    362377        remote_busylock_release( lock_xp );
     378
     379#if DEBUG_KCM
     380if( (DEBUG_KCM < cycle) && (local_cxy == 1) )
     381{
     382printk("\n[%s] thread[%x,%x] exit / order %d / page %x / status [%x,%x]\n",
     383__FUNCTION__, this->process->pid, this->trdid, kcm_ptr->order, kcm_ptr,
     384GET_CXY(kcm_page->status), GET_PTR(kcm_page->status) );
     385kcm_remote_display( local_cxy , kcm_ptr );
    363386}
     387#endif
     388
     389}  // end kcm_free()
    364390
    365391/////////////////////////////////////////////////////////////////////////////////////
     
    369395/////////////////////////////////////////////////////////////////////////////////////
    370396// This static function can be called by any thread running in any cluster.
    371 // It returns a local pointer on a block allocated from an non-full kcm_page.
    372 // It makes a panic if no block available in selected page.
     397// It returns a local pointer on a block allocated from an active kcm_page.
     398// It makes a panic if no block available in the selected kcm_page.
    373399// It changes the page status as required.
    374400/////////////////////////////////////////////////////////////////////////////////////
    375 // @ kcm_cxy  : remote KCM cluster identidfier.
     401// @ kcm_cxy  : remote KCM cluster identifier.
    376402// @ kcm_ptr  : local pointer on remote KCM allocator.
    377 // @ kcm_page : pointer on active kcm page to use.
     403// @ kcm_page : local pointer on remote active kcm_page to use.
    378404// @ return a local pointer on the allocated block.
    379405/////////////////////////////////////////////////////////////////////////////////////
     
    392418    uint32_t index  = 1;
    393419    uint64_t mask   = (uint64_t)0x2;
    394     uint32_t found  = 0;
    395420   
    396421        // allocate first free block in kcm_page, update status,
     
    398423    while( index <= max )
    399424    {
    400         if( (status & mask) == 0 )   // block non allocated
     425        if( (status & mask) == 0 )   // block found
    401426        {
    402427            hal_remote_s64( XPTR( kcm_cxy , &kcm_page->status ) , status | mask );
    403             hal_remote_s64( XPTR( kcm_cxy , &kcm_page->count  ) , count + 1 );
    404             found  = 1;
     428            hal_remote_s32( XPTR( kcm_cxy , &kcm_page->count  ) , count + 1 );
    405429            break;     
    406430        }
     
    410434    }
    411435
    412         // change the page list if almost full
     436        // change the page list if found block is the last
    413437        if( count == max-1 )
    414438        {
     
    631655                         kcm_t * kcm_ptr )
    632656{
     657    list_entry_t * iter;
     658    kcm_page_t   * kcm_page;
     659    uint64_t       status;
     660    uint32_t       count;
     661
    633662    uint32_t order           = hal_remote_l32( XPTR( kcm_cxy , &kcm_ptr->order) );
    634663    uint32_t full_pages_nr   = hal_remote_l32( XPTR( kcm_cxy , &kcm_ptr->full_pages_nr ) );
    635664    uint32_t active_pages_nr = hal_remote_l32( XPTR( kcm_cxy , &kcm_ptr->active_pages_nr ) );
    636665
    637         printk("*** KCM / cxy %x / order %d / full_pages %d / empty_pages %d / active_pages %d\n",
     666        printk("*** KCM : cxy %x / order %d / full_pages_nr %d / active_pages_nr %d\n",
    638667        kcm_cxy, order, full_pages_nr, active_pages_nr );
    639 }
     668
     669    if( active_pages_nr )
     670    {
     671        LIST_REMOTE_FOREACH( kcm_cxy , &kcm_ptr->active_root , iter )
     672        {
     673            kcm_page = LIST_ELEMENT( iter , kcm_page_t , list );
     674            status   = hal_remote_l64( XPTR( kcm_cxy , &kcm_page->status ) );
     675            count    = hal_remote_l32( XPTR( kcm_cxy , &kcm_page->count ) );
     676
     677            printk("- active page %x / status (%x,%x) / count %d\n",
     678            kcm_page, GET_CXY( status ), GET_PTR( status ), count );
     679        }
     680    }
     681
     682    if( full_pages_nr )
     683    {
     684        LIST_REMOTE_FOREACH( kcm_cxy , &kcm_ptr->full_root , iter )
     685        {
     686            kcm_page = LIST_ELEMENT( iter , kcm_page_t , list );
     687            status   = hal_remote_l64( XPTR( kcm_cxy , &kcm_page->status ) );
     688            count    = hal_remote_l32( XPTR( kcm_cxy , &kcm_page->count ) );
     689
     690            printk("- full page %x / status (%x,%x) / count %d\n",
     691            kcm_page, GET_CXY( status ), GET_PTR( status ), count );
     692        }
     693    }
     694}  // end kcm remote_display()
Note: See TracChangeset for help on using the changeset viewer.