Changeset 614 for trunk/kernel/mm


Ignore:
Timestamp:
Jan 15, 2019, 1:59:32 PM (6 years ago)
Author:
alain
Message:

1) introduce a dev_ioc_sync_write() function in IOC API,

to improve the DEVFS synchronous update.

2) fix a big bug in both the user_dir_create() and user_dir_destroy()

functions: add an extended pointer on the reference client process
in the function's arguments.

Location:
trunk/kernel/mm
Files:
4 edited

Legend:

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

    r611 r614  
    2828#include <hal_uspace.h>
    2929#include <grdxt.h>
     30#include <string.h>
    3031#include <rwlock.h>
    3132#include <printk.h>
     
    4142#include <vfs.h>
    4243#include <mapper.h>
     44#include <dev_ioc.h>
    4345
    4446
     
    302304
    303305    // launch I/O operation to load page from device to mapper
    304     error = vfs_fs_move_page( XPTR( local_cxy , page ) , true );
     306    error = vfs_fs_move_page( XPTR( local_cxy , page ) , IOC_SYNC_READ );
    305307
    306308    if( error )
     
    647649error_t mapper_display_page( xptr_t     mapper_xp,
    648650                             uint32_t   page_id,
    649                              uint32_t   nbytes,
    650                              char     * string )
    651 {
    652     xptr_t     page_xp;        // extended pointer on page descriptor
    653     xptr_t     base_xp;        // extended pointer on page base
    654     char       buffer[4096];   // local buffer
    655     uint32_t * tab;            // pointer on uint32_t to scan the buffer
    656     uint32_t   line;           // line index
    657     uint32_t   word;           // word index
     651                             uint32_t   nbytes )
     652{
     653    xptr_t        page_xp;        // extended pointer on page descriptor
     654    xptr_t        base_xp;        // extended pointer on page base
     655    char          buffer[4096];   // local buffer
     656    uint32_t    * tabi;           // pointer on uint32_t to scan buffer
     657    char        * tabc;           // pointer on char to scan buffer
     658    uint32_t      line;           // line index
     659    uint32_t      word;           // word index
     660    uint32_t      n;              // char index
     661    cxy_t         mapper_cxy;     // mapper cluster identifier
     662    mapper_t    * mapper_ptr;     // mapper local pointer
     663    vfs_inode_t * inode_ptr;      // inode local pointer
     664 
     665    char       name[CONFIG_VFS_MAX_NAME_LENGTH];
    658666
    659667    if( nbytes > 4096)
     
    674682    }
    675683
     684    // get cluster and local pointer
     685    mapper_cxy = GET_CXY( mapper_xp );
     686    mapper_ptr = GET_PTR( mapper_xp );
     687
     688    // get inode
     689    inode_ptr = hal_remote_lpt( XPTR( mapper_cxy , &mapper_ptr->inode ) );
     690
     691    // get inode name
     692    if( inode_ptr == NULL ) strcpy( name , "fat" );
     693    else  vfs_inode_get_name( XPTR( mapper_cxy , inode_ptr ) , name );
     694   
    676695    // get extended pointer on page base
    677696    base_xp = ppm_page2base( page_xp );
     
    681700
    682701    // display 8 words per line
    683     tab = (uint32_t *)buffer;
    684     printk("\n***** %s : first %d bytes of page %d *****\n", string, nbytes, page_id );
     702    tabi = (uint32_t *)buffer;
     703    tabc = (char *)buffer;
     704    printk("\n***** <%s> first %d bytes of page %d *****\n", name, nbytes, page_id );
    685705    for( line = 0 ; line < (nbytes >> 5) ; line++ )
    686706    {
    687707        printk("%X : ", line );
    688         for( word = 0 ; word < 8 ; word++ ) printk("%X ", tab[(line<<3) + word] );
     708        for( word = 0 ; word < 8 ; word++ ) printk("%X ", tabi[(line<<3) + word] );
     709        printk(" | ");
     710        for( n = 0 ; n < 32 ; n++ ) printk("%c", tabc[(line<<5) + n] );
    689711        printk("\n");
    690712    }
  • trunk/kernel/mm/mapper.h

    r612 r614  
    3838
    3939/*******************************************************************************************
    40  * The mapper implements the kernel cache for a given VFS file or directory.
     40 * This mapper_t object implements the kernel cache for a given VFS file or directory.
    4141 * There is one mapper per file/dir. It is implemented as a three levels radix tree,
    4242 * entirely stored in the same cluster as the inode representing the file/dir.
     
    6363 *
    6464 * TODO : the mapper being only used to implement the VFS cache(s), the mapper.c
    65  *        and mapper.h file should beerro trandfered to the vfs directory.
     65 *        and mapper.h file should be trandfered to the vfs directory.
    6666 ******************************************************************************************/
    6767
     
    8585
    8686/*******************************************************************************************
    87  * This structure defines a "fragment". It is used to move data between the kernel mapper,
    88  * and an user buffer, that can be split in several distributed physical pages located
    89  * in different clusters. A fragment is a set of contiguous bytes in the file.
    90  * - It can be stored in one single physical page in the user buffer.
    91  * - It can spread two successive physical pages in the kernel mapper.
    92  ******************************************************************************************/
    93 
    94 typedef struct fragment_s
    95 {
    96     uint32_t    file_offset;         /*! offset of fragment in file (i.e. in mapper)      */
    97     uint32_t    size;                /*! number of bytes in fragment                      */
    98     cxy_t       buf_cxy;             /*! user buffer cluster identifier                   */
    99     void      * buf_ptr;             /*! local pointer on first byte in user buffer       */
    100 }
    101 fragment_t;
    102 
    103 /*******************************************************************************************
    10487 * This function allocates physical memory for a mapper descriptor, and initializes it
    10588 * (refcount <= 0) / inode <= NULL).
     
    158141 * returns O if success / returns -1 if error.
    159142 ******************************************************************************************/
    160 error_t mapper_move_user( xptr_t     mappe_xp,
     143error_t mapper_move_user( xptr_t     mapper_xp,
    161144                          bool_t     to_buffer,
    162145                          uint32_t   file_offset,
     
    258241 * @ page_id    : [in]  page index in file.
    259242 * @ nbytes     : [in]  value to be written.
    260  * @ string     : [in]  string printed in header.
    261243 * @ returns 0 if success / return -1 if error.
    262244 ******************************************************************************************/
    263245error_t mapper_display_page( xptr_t     mapper_xp,
    264246                             uint32_t   page_id,
    265                              uint32_t   nbytes,
    266                              char     * string );
     247                             uint32_t   nbytes );
    267248
    268249
  • trunk/kernel/mm/vmm.c

    r611 r614  
    6464    intptr_t  base;
    6565    intptr_t  size;
     66    uint32_t  i;
    6667
    6768#if DEBUG_VMM_INIT
     
    6970uint32_t cycle = (uint32_t)hal_get_cycles();
    7071if( DEBUG_VMM_INIT )
    71 printk("\n[%s] thread[%x,%x] enter for process %x / cycle %d\n",
    72 __FUNCTION__ , this->process->pid, this->trdid, process->pid , cycle );
     72printk("\n[%s] thread[%x,%x] enter for process %x in cluster %x / cycle %d\n",
     73__FUNCTION__ , this->process->pid, this->trdid, process->pid, local_cxy, cycle );
    7374#endif
    7475
     
    183184    vmm->mmap_mgr.first_free_vpn  = CONFIG_VMM_HEAP_BASE;
    184185    busylock_init( &vmm->mmap_mgr.lock , LOCK_VMM_MMAP );
    185 
    186     uint32_t i;
    187186    for( i = 0 ; i < 32 ; i++ ) list_root_init( &vmm->mmap_mgr.zombi_list[i] );
    188187
     
    195194cycle = (uint32_t)hal_get_cycles();
    196195if( DEBUG_VMM_INIT )
    197 printk("\n[%s] thread[%x,%x] exit / process %x / entry_point %x / cycle %d\n",
    198 __FUNCTION__, this->process->pid, this->trdid, process->pid, process->vmm.entry_point, cycle );
     196printk("\n[%s] thread[%x,%x] exit for process %x in cluster %x / cycle %d\n",
     197__FUNCTION__, this->process->pid, this->trdid, process->pid, local_cxy, cycle );
    199198#endif
    200199
     
    944943    vpn_t      free;
    945944
    946     // mmap vseg size must be power of 2
     945#if DEBUG_VMM_MMAP_ALLOC
     946thread_t * this = CURRENT_THREAD;
     947uint32_t cycle = (uint32_t)hal_get_cycles();
     948if( DEBUG_VMM_MMAP_ALLOC < cycle )
     949printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
     950__FUNCTION__, this->process->pid, this->trdid, cycle );
     951#endif
     952
     953    // vseg size must be power of 2
    947954    // compute actual size and index in zombi_list array
    948955    size  = POW2_ROUNDUP( npages );
     
    952959    mmap_mgr_t * mgr = &vmm->mmap_mgr;
    953960
     961printk("\n@@@ in %s : size = %d / index = %d / first = %d / empty = %d\n",
     962__FUNCTION__, size, index, mgr->vpn_size, list_is_empty(&mgr->zombi_list[index]) );
     963
    954964    // get lock on mmap allocator
    955965    busylock_acquire( &mgr->lock );
     
    958968    if( list_is_empty( &mgr->zombi_list[index] ) )     // from mmap zone
    959969    {
     970
     971printk("\n@@@ from mmap zone\n" );
     972
    960973        // check overflow
    961974        free = mgr->first_free_vpn;
    962         if( (free + size) > mgr->vpn_size ) return ENOMEM;
    963 
    964         // update STACK allocator
     975        if( (free + size) > mgr->vpn_size ) return -1;
     976
     977        // update MMAP allocator
    965978        mgr->first_free_vpn += size;
    966979
     
    970983    else                                             // from zombi_list
    971984    {
     985
     986printk("\n@@@ from zombi_list\n" );
     987
    972988        // get pointer on zombi vseg from zombi_list
    973989        vseg = LIST_FIRST( &mgr->zombi_list[index] , vseg_t , zlist );
     
    982998    // release lock on mmap allocator
    983999    busylock_release( &mgr->lock );
     1000
     1001#if DEBUG_VMM_MMAP_ALLOC
     1002cycle = (uint32_t)hal_get_cycles();
     1003if( DEBUG_VMM_DESTROY < cycle )
     1004printk("\n[%s] thread[%x,%x] exit / vpn_base %x / vpn_size %x / cycle %d\n",
     1005__FUNCTION__, this->process->pid, this->trdid, base, size, cycle );
     1006#endif
    9841007
    9851008    // returns vpn_base, vpn_size
     
    10091032uint32_t   cycle = (uint32_t)hal_get_cycles();
    10101033if( DEBUG_VMM_CREATE_VSEG < cycle )
    1011 printk("\n[%s] thread[%x,%x] enter / %s / cxy %x / cycle %d\n",
    1012 __FUNCTION__, this->process->pid, this->trdid, vseg_type_str(type), cxy, cycle );
     1034printk("\n[%s] thread[%x,%x] enter for process %x / %s / cxy %x / cycle %d\n",
     1035__FUNCTION__, this->process->pid, this->trdid, process->pid, vseg_type_str(type), cxy, cycle );
    10131036#endif
    10141037
     
    10921115    if( vseg != NULL )
    10931116    {
    1094         printk("\n[ERROR] in %s for process %x : new vseg [vpn_base = %x / vpn_size = %x]\n"
    1095                "  overlap existing vseg [vpn_base = %x / vpn_size = %x]\n",
     1117        printk("\n[ERROR] in %s for process %x : new vseg [vpn_base %x / vpn_size %x]\n"
     1118               "  overlap existing vseg [vpn_base %x / vpn_size %x]\n",
    10961119        __FUNCTION__ , process->pid, vpn_base, vpn_size, vseg->vpn_base, vseg->vpn_size );
    10971120        return NULL;
     
    11061129        return NULL;
    11071130        }
     1131
     1132#if DEBUG_VMM_CREATE_VSEG
     1133if( DEBUG_VMM_CREATE_VSEG < cycle )
     1134printk("\n[%s] thread[%x,%x] : base %x / size %x / vpn_base %x / vpn_size %x\n",
     1135__FUNCTION__, this->process->pid, this->trdid, base, size, vpn_base, vpn_size );
     1136#endif
    11081137
    11091138    // initialize vseg descriptor
  • trunk/kernel/mm/vmm.h

    r611 r614  
    138138 * - It initializes the generic page table, calling the HAL specific hal_gpt_init() function.
    139139 * - For TSAR it map all pages for the "kentry" vseg, that must be identity mapping.
    140  * Note:
     140 ******************************************************a**************************************
     141 * Implementation notes:
    141142 * - The "code" and "data" vsegs are registered by the elf_load_process() function.
    142143 * - The "stack" vsegs are dynamically created by the thread_user_create() function.
Note: See TracChangeset for help on using the changeset viewer.