Changeset 628 for trunk/kernel/mm


Ignore:
Timestamp:
May 6, 2019, 1:28:01 PM (6 years ago)
Author:
alain
Message:

Introduce teh page_min / page_max mechanism in the fatfs_release_inode()
function, to avoid to scan all pages in FAT mapper.

Location:
trunk/kernel/mm
Files:
2 edited

Legend:

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

    r626 r628  
    395395{
    396396    uint32_t   page_offset;    // first byte to move to/from a mapper page
    397     uint32_t   page_count;     // number of bytes to move to/from a mapper page
     397    uint32_t   page_bytes;     // number of bytes to move to/from a mapper page
    398398    uint32_t   page_id;        // current mapper page index
    399399    uint32_t   done;           // number of moved bytes
     
    420420#endif
    421421
    422     // compute offsets of first and last bytes in file
     422    // compute indexes of first and last bytes in file
    423423    uint32_t min_byte = file_offset;
    424424    uint32_t max_byte = file_offset + size - 1;
     
    444444
    445445        // compute number of bytes in page
    446         if      ( first   == last  ) page_count = size;
    447         else if ( page_id == first ) page_count = CONFIG_PPM_PAGE_SIZE - page_offset;
    448         else if ( page_id == last  ) page_count = (max_byte & CONFIG_PPM_PAGE_MASK) + 1;
    449         else                         page_count = CONFIG_PPM_PAGE_SIZE;
     446        if      ( first   == last  ) page_bytes = size;
     447        else if ( page_id == first ) page_bytes = CONFIG_PPM_PAGE_SIZE - page_offset;
     448        else if ( page_id == last  ) page_bytes = (max_byte & CONFIG_PPM_PAGE_MASK) + 1;
     449        else                         page_bytes = CONFIG_PPM_PAGE_SIZE;
    450450
    451451#if (DEBUG_MAPPER_MOVE_USER & 1)
    452452if( DEBUG_MAPPER_MOVE_USER < cycle )
    453453printk("\n[%s] thread[%x,%x] : page_id %d / page_offset %d / bytes %d\n",
    454 __FUNCTION__, this->process->pid, this->trdid, page_id , page_offset , page_count );
    455 #endif
    456 
    457         // get extended pointer on page descriptor
     454__FUNCTION__, this->process->pid, this->trdid, page_id , page_offset , page_bytes );
     455#endif
     456
     457        // get extended pointer on page descriptor in mapper
    458458        page_xp = mapper_remote_get_page( mapper_xp , page_id );
    459459
     
    476476        if( to_buffer )
    477477        {
    478             hal_copy_to_uspace( map_cxy , map_ptr , buf_ptr , page_count );
     478            hal_copy_to_uspace( map_cxy , map_ptr + page_offset , buf_ptr , page_bytes );
    479479
    480480#if DEBUG_MAPPER_MOVE_USER & 1
    481481if( DEBUG_MAPPER_MOVE_USER < cycle )
    482482printk("\n[%s] thread[%x,%x] moved %d bytes / mapper %s (%x,%x) -> user buffer(%x,%x)\n",
    483 __FUNCTION__, this->process->pid, this->trdid, page_count,
    484 name, map_cxy, map_ptr, local_cxy, buf_ptr );
     483__FUNCTION__, this->process->pid, this->trdid, page_bytes,
     484name, map_cxy, map_ptr + page_offset, local_cxy, buf_ptr );
    485485#endif
    486486
     
    489489        {
    490490            ppm_page_do_dirty( page_xp );
    491             hal_copy_from_uspace( map_cxy , map_ptr , buf_ptr , page_count );
     491            hal_copy_from_uspace( map_cxy , map_ptr + page_offset , buf_ptr , page_bytes );
    492492
    493493#if DEBUG_MAPPER_MOVE_USER & 1
    494494if( DEBUG_MAPPER_MOVE_USER < cycle )
    495495printk("\n[%s] thread[%x,%x] moved %d bytes / user buffer(%x,%x) -> mapper %s (%x,%x)\n",
    496 __FUNCTION__, this->process->pid, this->trdid, page_count,
    497 local_cxy, buf_ptr, name, map_cxy, map_ptr );
     496__FUNCTION__, this->process->pid, this->trdid, page_bytes,
     497local_cxy, buf_ptr, name, map_cxy, map_ptr + page_offset );
    498498mapper_display_page(  mapper_xp , page_id, 128 );
    499499#endif
     
    501501        }
    502502
    503         done += page_count;
     503        done += page_bytes;
    504504    }
    505505
     
    529529{
    530530    uint32_t   page_offset;    // first byte to move to/from a mapper page
    531     uint32_t   page_count;     // number of bytes to move to/from a mapper page
     531    uint32_t   page_bytes;     // number of bytes to move to/from a mapper page
    532532    uint32_t   page_id;        // current mapper page index
    533533    uint32_t   done;           // number of moved bytes
     
    588588
    589589        // compute number of bytes to move in page
    590         if      ( first == last  )   page_count = size;
    591         else if ( page_id == first ) page_count = CONFIG_PPM_PAGE_SIZE - page_offset;
    592         else if ( page_id == last  ) page_count = (max_byte & CONFIG_PPM_PAGE_MASK) + 1;
    593         else                         page_count = CONFIG_PPM_PAGE_SIZE;
     590        if      ( first == last  )   page_bytes = size;
     591        else if ( page_id == first ) page_bytes = CONFIG_PPM_PAGE_SIZE - page_offset;
     592        else if ( page_id == last  ) page_bytes = (max_byte & CONFIG_PPM_PAGE_MASK) + 1;
     593        else                         page_bytes = CONFIG_PPM_PAGE_SIZE;
    594594
    595595        // get extended pointer on page descriptor
     
    621621    if( to_buffer )
    622622    printk("\n[%s] mapper <%s> page %d => buffer(%x,%x) / %d bytes\n",
    623     __FUNCTION__, name, page_id, dst_cxy, dst_ptr, page_count );
     623    __FUNCTION__, name, page_id, dst_cxy, dst_ptr, page_bytes );
    624624    else
    625625    printk("\n[%s] buffer(%x,%x) => mapper <%s> page %d / %d bytes\n",
    626     __FUNCTION__, src_cxy, src_ptr, name, page_id, page_count );
     626    __FUNCTION__, src_cxy, src_ptr, name, page_id, page_bytes );
    627627}
    628628#endif
    629629
    630630        // move fragment
    631         hal_remote_memcpy( XPTR( dst_cxy , dst_ptr ), XPTR( src_cxy , src_ptr ), page_count );
    632 
    633         done += page_count;
     631        hal_remote_memcpy( XPTR( dst_cxy , dst_ptr ), XPTR( src_cxy , src_ptr ), page_bytes );
     632
     633        done += page_bytes;
    634634    }
    635635
     
    647647///////////////////////////////////////////////////
    648648error_t mapper_remote_get_32( xptr_t     mapper_xp,
     649                              uint32_t   page_id,
    649650                              uint32_t   word_id,
    650                               uint32_t * p_value )
    651 {
    652     uint32_t   page_id;      // page index in file
    653     uint32_t   local_id;     // word index in page
     651                              uint32_t * value )
     652{
    654653    xptr_t     page_xp;      // extended pointer on searched page descriptor
    655654    xptr_t     base_xp;      // extended pointer on searched page base
    656 
    657655   
    658     // get page index and local word index
    659     page_id  = word_id >> 10;
    660     local_id = word_id & 0x3FF;
    661 
    662656    // get page containing the searched word
    663657    page_xp  = mapper_remote_get_page( mapper_xp , page_id );
     
    669663
    670664    // get the value from mapper
    671     *p_value = hal_remote_l32( base_xp + (local_id<<2) );
     665    *value = hal_remote_l32( base_xp + (word_id<<2) );
    672666
    673667    return 0;
     
    677671///////////////////////////////////////////////////
    678672error_t mapper_remote_set_32( xptr_t     mapper_xp,
     673                              uint32_t   page_id,
    679674                              uint32_t   word_id,
    680675                              uint32_t   value )
    681676{
    682    
    683     uint32_t   page_id;      // page index in file
    684     uint32_t   local_id;     // word index in page
    685677    xptr_t     page_xp;      // extended pointer on searched page descriptor
    686678    xptr_t     base_xp;      // extended pointer on searched page base
    687679
    688     // get page index and local vord index
    689     page_id  = word_id >> 10;
    690     local_id = word_id & 0x3FF;
    691 
    692680    // get page containing the searched word
    693681    page_xp  = mapper_remote_get_page( mapper_xp , page_id );
     
    699687
    700688    // set value to mapper
    701     hal_remote_s32( (base_xp + (local_id << 2)) , value );
    702 
    703     // set the dirty flag
     689    hal_remote_s32( (base_xp + (word_id << 2)) , value );
     690
     691    // set the dirty flag in page descriptor
    704692    ppm_page_do_dirty( page_xp );
    705693
  • trunk/kernel/mm/mapper.h

    r626 r628  
    206206 *******************************************************************************************
    207207 * @ mapper_xp  : [in]  extended pointer on the mapper.
    208  * @ word_id    : [in]  32 bits word index in file.
    209  * @ p_value    : [out] local pointer on destination buffer.
     208 * @ page_id    : [in]  page index in mapper.
     209 * @ word_id    : [in]  32 bits word index in page.
     210 * @ value      : [out] local pointer on destination buffer.
    210211 * @ returns 0 if success / return -1 if error.
    211212 ******************************************************************************************/
    212213error_t mapper_remote_get_32( xptr_t     mapper_xp,
     214                              uint32_t   page_id,
    213215                              uint32_t   word_id,
    214                               uint32_t * p_value );
     216                              uint32_t * value );
    215217
    216218/*******************************************************************************************
     
    220222 * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
    221223 * page from device to mapper, and release the mapper lock.
     224 * It does not update the FAT on IOC device.
    222225 *******************************************************************************************
    223226 * @ mapper_xp  : [in]  extended pointer on the mapper.
    224  * @ word_id    : [in]  32 bits word index in file.
     227 * @ page_id    : [in]  page index in mapper.
     228 * @ word_id    : [in]  32 bits word index in page.
    225229 * @ value      : [in]  value to be written.
    226230 * @ returns 0 if success / return -1 if error.
    227231 ******************************************************************************************/
    228232error_t mapper_remote_set_32( xptr_t     mapper_xp,
     233                              uint32_t   page_id,
    229234                              uint32_t   word_id,
    230235                              uint32_t   value );
Note: See TracChangeset for help on using the changeset viewer.