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


Ignore:
Timestamp:
Dec 6, 2019, 12:07:51 PM (5 years ago)
Author:
alain
Message:

Fix several bugs in the FATFS and in the VFS,
related to the creation of big files requiring
more than 4 Kbytes (one cluster) on device.

File:
1 edited

Legend:

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

    r651 r656  
    151151        page_t   * buddy;               // searched buddy page descriptor
    152152        uint32_t   buddy_index;         // buddy page index in page_tbl[]
    153         page_t   * current;             // current (merged) page descriptor
     153        page_t   * current_ptr;         // current (merged) page descriptor
    154154        uint32_t   current_index;       // current (merged) page index in page_tbl[]
    155155        uint32_t   current_order;       // current (merged) page order
     
    168168
    169169    // initialise loop variables
    170     current       = page;
     170    current_ptr   = page;
    171171    current_order = page->order;
    172172        current_index = page - ppm->pages_tbl;
     
    191191                buddy->order = 0;
    192192
    193                 // compute next (merged) page index in page_tbl[]
     193                // compute next values for loop variables
    194194                current_index &= buddy_index;
    195 
    196         // compute next (merged) page order
    197195        current_order++;
    198 
    199         // compute next (merged) page descripror
    200         current = pages_tbl + current_index;
     196        current_ptr = pages_tbl + current_index;
    201197    }
    202198
    203199        // update order field for merged page descriptor
    204         current->order = current_order;
     200        current_ptr->order = current_order;
    205201
    206202        // insert merged page in relevant free list
    207         list_add_first( &ppm->free_pages_root[current_order] , &current->list );
     203        list_add_first( &ppm->free_pages_root[current_order] , &current_ptr->list );
    208204        ppm->free_pages_nr[current_order] ++;
    209205
    210206}  // end ppm_free_pages_nolock()
    211 
    212207
    213208////////////////////////////////////////////
     
    221216    thread_t * this = CURRENT_THREAD;
    222217
     218        ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
     219
    223220#if DEBUG_PPM_ALLOC_PAGES
    224221uint32_t cycle = (uint32_t)hal_get_cycles();
    225222#endif
    226223
    227 #if (DEBUG_PPM_ALLOC_PAGES & 1)
     224#if DEBUG_PPM_ALLOC_PAGES
    228225if( DEBUG_PPM_ALLOC_PAGES < cycle )
    229226{
    230227    printk("\n[%s] thread[%x,%x] enter for %d page(s) in cluster %x / cycle %d\n",
    231228    __FUNCTION__, this->process->pid, this->trdid, 1<<order, local_cxy, cycle );
    232     ppm_remote_display( local_cxy );
    233 }
    234 #endif
    235 
    236         ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
     229    if( DEBUG_PPM_ALLOC_PAGES & 1 ) ppm_remote_display( local_cxy );
     230}
     231#endif
    237232
    238233// check order
     
    316311    dqdt_increment_pages( local_cxy , order );
    317312
     313    hal_fence();
     314
    318315#if DEBUG_PPM_ALLOC_PAGES
    319316if( DEBUG_PPM_ALLOC_PAGES < cycle )
     
    322319    __FUNCTION__, this->process->pid, this->trdid,
    323320    1<<order, local_cxy, ppm_page2ppn(XPTR( local_cxy , found_block )), cycle );
    324     ppm_remote_display( local_cxy );
     321    if( DEBUG_PPM_ALLOC_PAGES & 1 ) ppm_remote_display( local_cxy );
    325322}
    326323#endif
     
    340337#endif
    341338
    342 #if ( DEBUG_PPM_FREE_PAGES & 1 )
     339#if DEBUG_PPM_FREE_PAGES
    343340if( DEBUG_PPM_FREE_PAGES < cycle )
    344341{
     
    346343    __FUNCTION__, this->process->pid, this->trdid,
    347344    1<<page->order, local_cxy, ppm_page2ppn(XPTR(local_cxy , page)), cycle );
    348     ppm_remote_display( local_cxy );
     345    if( DEBUG_PPM_FREE_PAGES & 1 ) ppm_remote_display( local_cxy );
     346}
    349347#endif
    350348
     
    362360    // update DQDT
    363361    dqdt_decrement_pages( local_cxy , page->order );
     362
     363    hal_fence();
    364364
    365365#if DEBUG_PPM_FREE_PAGES
     
    369369    __FUNCTION__, this->process->pid, this->trdid,
    370370    1<<page->order, local_cxy, ppm_page2ppn(XPTR(local_cxy , page)) , cycle );
    371     ppm_remote_display( local_cxy );
     371    if( DEBUG_PPM_FREE_PAGES & 1 ) ppm_remote_display( local_cxy );
    372372}
    373373#endif
     
    376376
    377377
    378 
    379 
    380378/////////////////////////////////////////////
    381 void * ppm_remote_alloc_pages( cxy_t     cxy,
     379xptr_t ppm_remote_alloc_pages( cxy_t     cxy,
    382380                               uint32_t  order )
    383381{
     
    389387    thread_t * this  = CURRENT_THREAD;
    390388
     389// check order
     390assert( (order < CONFIG_PPM_MAX_ORDER) , "illegal order argument = %d\n" , order );
     391
     392    // get local pointer on PPM (same in all clusters)
     393        ppm_t * ppm = &LOCAL_CLUSTER->ppm;
     394
    391395#if DEBUG_PPM_REMOTE_ALLOC_PAGES
    392396uint32_t   cycle = (uint32_t)hal_get_cycles();
    393397#endif
    394398
    395 #if ( DEBUG_PPM_REMOTE_ALLOC_PAGES & 1 )
     399#if DEBUG_PPM_REMOTE_ALLOC_PAGES
    396400if( DEBUG_PPM_REMOTE_ALLOC_PAGES < cycle )
    397401{
    398     printk("\n[%s] thread[%x,%x] enter for %d small page(s) in cluster %x / cycle %d\n",
     402    printk("\n[%s] thread[%x,%x] enter for %d page(s) in cluster %x / cycle %d\n",
    399403    __FUNCTION__, this->process->pid, this->trdid, 1<<order, cxy, cycle );
    400     ppm_remote_display( cxy );
    401 }
    402 #endif
    403 
    404 // check order
    405 assert( (order < CONFIG_PPM_MAX_ORDER) , "illegal order argument = %d\n" , order );
    406 
    407     // get local pointer on PPM (same in all clusters)
    408         ppm_t * ppm = &LOCAL_CLUSTER->ppm;
     404    if( DEBUG_PPM_REMOTE_ALLOC_PAGES & 1 ) ppm_remote_display( cxy );
     405}
     406#endif
    409407
    410408    //build extended pointer on lock protecting remote PPM
     
    489487    dqdt_increment_pages( cxy , order );
    490488
     489    hal_fence();
     490
    491491#if DEBUG_PPM_REMOTE_ALLOC_PAGES
    492492if( DEBUG_PPM_REMOTE_ALLOC_PAGES < cycle )
     
    495495    __FUNCTION__, this->process->pid, this->trdid,
    496496    1<<order, cxy, ppm_page2ppn(XPTR( cxy , found_block )), cycle );
    497     ppm_remote_display( cxy );
    498 }
    499 #endif
    500 
    501         return found_block;
     497    if( DEBUG_PPM_REMOTE_ALLOC_PAGES & 1 ) ppm_remote_display( cxy );
     498}
     499#endif
     500
     501        return XPTR( cxy , found_block );
    502502
    503503}  // end ppm_remote_alloc_pages()
     
    515515        uint32_t   current_order;    // current (merged) page order
    516516
     517    // get local pointer on PPM (same in all clusters)
     518        ppm_t * ppm = &LOCAL_CLUSTER->ppm;
     519
     520    // get page ppn and order
     521    uint32_t   order = hal_remote_l32( XPTR( page_cxy , &page_ptr->order ) );
     522
    517523#if DEBUG_PPM_REMOTE_FREE_PAGES
    518524thread_t * this  = CURRENT_THREAD;
    519525uint32_t   cycle = (uint32_t)hal_get_cycles();
    520 #endif
    521 
    522 #if ( DEBUG_PPM_REMOTE_FREE_PAGES & 1 )
     526ppn_t      ppn   = ppm_page2ppn( XPTR( page_cxy , page_ptr ) );
     527#endif
     528
     529#if DEBUG_PPM_REMOTE_FREE_PAGES
    523530if( DEBUG_PPM_REMOTE_FREE_PAGES < cycle )
    524531{
    525532    printk("\n[%s] thread[%x,%x] enter for %d page(s) in cluster %x / ppn %x / cycle %d\n",
    526     __FUNCTION__, this->process->pid, this->trdid,
    527     1<<page_ptr->order, page_cxy, ppm_page2ppn(XPTR( page_cxy , page_ptr )), cycle );
    528     ppm_remote_display( page_cxy );
     533    __FUNCTION__, this->process->pid, this->trdid, 1<<order, page_cxy, ppn, cycle );
     534    if( DEBUG_PPM_REMOTE_FREE_PAGES & 1 ) ppm_remote_display( page_cxy );
    529535}
    530536#endif
     
    533539    page_xp = XPTR( page_cxy , page_ptr );
    534540   
    535     // get local pointer on PPM (same in all clusters)
    536         ppm_t * ppm = &LOCAL_CLUSTER->ppm;
    537 
    538541    // build extended pointer on lock protecting remote PPM
    539542    xptr_t lock_xp = XPTR( page_cxy , &ppm->free_lock );
     
    556559    // initialise loop variables
    557560    current_ptr   = page_ptr;
    558     current_order = hal_remote_l32( XPTR( page_cxy , &page_ptr->order ) );
     561    current_order = order;
    559562        current_index = page_ptr - ppm->pages_tbl;
    560563
     
    582585        hal_remote_s32( XPTR( page_cxy , &buddy_ptr->order ) , 0 );
    583586
    584                 // compute next (merged) page index in page_tbl[]
     587                // compute next values for loop variables
    585588                current_index &= buddy_index;
    586 
    587         // compute next (merged) page order
    588589        current_order++;
    589 
    590         // compute next (merged) page descripror
    591590        current_ptr = pages_tbl + current_index;
    592591
     
    594593
    595594        // update current (merged) page descriptor order field
    596         current_ptr = pages_tbl + current_index;
    597595    hal_remote_s32( XPTR( page_cxy , &current_ptr->order ) , current_order );
    598596
    599597        // insert current (merged) page into relevant free list
    600         list_remote_add_first( page_cxy , &ppm->free_pages_root[current_order] , &current_ptr->list );
     598        list_remote_add_first( page_cxy, &ppm->free_pages_root[current_order], &current_ptr->list );
    601599    hal_remote_atomic_add( XPTR( page_cxy , &ppm->free_pages_nr[current_order] ) , 1 );
    602600
     
    607605    dqdt_decrement_pages( page_cxy , page_ptr->order );
    608606
     607    hal_fence();
     608
    609609#if DEBUG_PPM_REMOTE_FREE_PAGES
    610610if( DEBUG_PPM_REMOTE_FREE_PAGES < cycle )
    611611{
    612612    printk("\n[%s] thread[%x,%x] released %d page(s) in cluster %x / ppn %x / cycle %d\n",
    613     __FUNCTION__, this->process->pid, this->trdid,
    614     1<<page_ptr->order, page_cxy, ppm_page2ppn(XPTR( page_cxy , page_ptr ) ), cycle );
    615     ppm_remote_display( page_cxy );
     613    __FUNCTION__, this->process->pid, this->trdid, 1<<order, page_cxy, ppn, cycle );
     614    if( DEBUG_PPM_REMOTE_FREE_PAGES & 1 ) ppm_remote_display( page_cxy );
    616615}
    617616#endif
     
    658657        uint32_t n = hal_remote_l32( XPTR( cxy , &ppm->free_pages_nr[order] ) );
    659658
    660         // display direct free_list[order]
    661                 nolock_printk("- forward  : order = %d / n = %d\t: ", order , n );
     659        // display forward free_list[order]
     660                nolock_printk("- forward  : order = %d / n = %d : ", order , n );
    662661                LIST_REMOTE_FOREACH( cxy , &ppm->free_pages_root[order] , iter )
     662                {
     663            page_xp = XPTR( cxy , LIST_ELEMENT( iter , page_t , list ) );
     664                        nolock_printk("%x," , ppm_page2ppn( page_xp ) );
     665                }
     666                nolock_printk("\n");
     667
     668        // display backward free_list[order]
     669                nolock_printk("- backward : order = %d / n = %d : ", order , n );
     670                LIST_REMOTE_FOREACH_BACKWARD( cxy , &ppm->free_pages_root[order] , iter )
    663671                {
    664672            page_xp = XPTR( cxy , LIST_ELEMENT( iter , page_t , list ) );
Note: See TracChangeset for help on using the changeset viewer.