Changeset 204 for trunk/kernel/mm


Ignore:
Timestamp:
Jul 17, 2017, 8:42:59 AM (7 years ago)
Author:
alain
Message:

Bug fix in kernel_init
-This line, and those below, will be ignored--

M params.mk
M kernel_config.h
M Makefile
M hdd/virt_hdd.dmg
M tools/bootloader_tsar/boot.c
M kernel/libk/bits.h
M kernel/libk/elf.c
M kernel/libk/xhtab.c
M kernel/libk/elf.h
M kernel/libk/xhtab.h
M kernel/devices/dev_pic.c
M kernel/mm/vmm.c
M kernel/mm/mapper.c
M kernel/mm/mapper.h
M kernel/vfs/devfs.h
M kernel/vfs/vfs.c
M kernel/vfs/vfs.h
M kernel/vfs/devfs.c
M kernel/kern/chdev.h
M kernel/kern/kernel_init.c
M kernel/kern/process.c
M kernel/kern/process.h
M hal/tsar_mips32/core/hal_remote.c
M hal/tsar_mips32/drivers/soclib_pic.c

Location:
trunk/kernel/mm
Files:
3 edited

Legend:

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

    r183 r204  
    8888
    8989    return mapper;
    90 }
     90
     91}  // end mapper_create()
    9192
    9293///////////////////////////////////////////
     
    127128
    128129    return 0;
    129 }
     130
     131}  // end mapper_destroy()
    130132
    131133////////////////////////////////////////////
     
    137139    error_t       error;
    138140
     141    mapper_dmsg("\n[INFO] %s : enter for page %d / mapper = %x\n",
     142                __FUNCTION__ , index , mapper );
     143
    139144    thread_t * this = CURRENT_THREAD;
    140145
     
    148153    if( ( page == NULL) || page_is_flag( page , PG_INLOAD ) )  // page not available
    149154    {
     155
    150156        // release the lock in READ_MODE and take it in WRITE_MODE
    151157        rwlock_rd_unlock( &mapper->lock );
     
    160166        if ( page == NULL )   // missing page => load it from file system
    161167        {
     168            mapper_dmsg("\n[INFO] %s : missing page => load from FS\n", __FUNCTION__ );
     169
    162170            // allocate one page from PPM
    163171            req.type  = KMEM_PAGE;
     
    237245                sched_yield();
    238246            }
    239 
    240         }
    241 
    242         return page;
    243     }
    244     else
    245     {
    246          // release lock from READ_MODE
    247          rwlock_rd_unlock( &mapper->lock );
    248 
    249          return page;
    250     }
    251 }
     247        }
     248    }
     249    else                          // page available in mapper
     250    {
     251
     252        rwlock_rd_unlock( &mapper->lock );
     253    }
     254
     255    mapper_dmsg("\n[INFO] %s : exit for page %d / page desc = %x\n",
     256                __FUNCTION__ , index , page );
     257
     258    return page;
     259
     260}  // end mapper_get_page()
    252261
    253262///////////////////////////////////////////////
     
    282291
    283292    return 0;
    284 }
     293
     294}  // end mapper_release_page()
    285295
    286296/////////////////////////////////////////
     
    298308    uint8_t  * map_ptr;        // current mapper  address
    299309    uint8_t  * buf_ptr;        // current buffer  address
     310 
     311    mapper_dmsg("\n[INFO] %s : enter / to_buf = %d / buffer = %x\n",
     312                __FUNCTION__ , to_buffer , buffer );
    300313
    301314    // compute offsets of first and last bytes in file
     
    347360    }
    348361
     362    mapper_dmsg("\n[INFO] %s : exit for buffer %x\n",
     363                __FUNCTION__, buffer );
     364
    349365    return 0;
    350 }
    351 
     366
     367}  // end mapper_move()
     368
  • trunk/kernel/mm/mapper.h

    r23 r204  
    5050 *   readers, and only one writer. This lock implement a busy waiting policy.
    5151 * - The two functions vfs_move_page_to_mapper() and vfs_move_page_from_mapper() define
    52  *   the generic API used to move pages to or from the relevant file system on IOC device.
     52 *   the generic API used to move pages to or from the relevant file system.
    5353 * - the mapper_move() function is used to move data to or from a, possibly distributed
    5454 *   user buffer in user space.
     
    122122 * The offset in the file descriptor is not modified by this function.
    123123 *******************************************************************************************
    124  * @ mapper       : extended pointer on local mapper.
     124 * @ mapper       : local pointer on local mapper.
    125125 * @ to_buffer    : move data from mapper to buffer if true.
    126126 * @ file_offset  : first byte to move in file.
  • trunk/kernel/mm/vmm.c

    r179 r204  
    6262    intptr_t  size;
    6363
     64    vmm_dmsg("\n[INFO] %s : enter for process %x\n", __FUNCTION__ , process->pid );
     65
    6466    // get pointer on VMM
    6567    vmm_t   * vmm = &process->vmm;
    6668
    67     // check UTILS zone size
    68     if( (CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + CONFIG_VMM_ENVS_SIZE ) >
    69         CONFIG_VMM_ELF_BASE )
    70     {
    71         printk("\n[PANIC] in %s : UTILS zone too small for process %x\n",
    72                __FUNCTION__ , process->pid );
    73         hal_core_sleep();
    74     }
    75 
    76     // check max number of stacks slots
    77     if( CONFIG_THREAD_MAX_PER_CLUSTER > 32 )
    78     {
    79         printk("\n[PANIC] in %s : max number of threads per cluster for a single process"
    80                " cannot be larger than 32\n", __FUNCTION__ );
    81         hal_core_sleep();
    82     }
    83 
    84     // check STACK zone size
    85     if( (CONFIG_VMM_STACK_SIZE * CONFIG_THREAD_MAX_PER_CLUSTER) >
    86         (CONFIG_VMM_VSPACE_SIZE - CONFIG_VMM_STACK_BASE) )
    87     {
    88         printk("\n[PANIC] in %s : STACK zone too small for process %x\n",
    89                __FUNCTION__ , process->pid );
    90         hal_core_sleep();
    91     }
     69    assert( ((CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + CONFIG_VMM_ENVS_SIZE)
     70            <= CONFIG_VMM_ELF_BASE) , __FUNCTION__ , "UTILS zone too small\n" );
     71
     72    assert( (CONFIG_THREAD_MAX_PER_CLUSTER <= 32) , __FUNCTION__ ,
     73            "no more than 32 threads per cluster for a single process\n");
     74
     75    assert( ((CONFIG_VMM_STACK_SIZE * CONFIG_THREAD_MAX_PER_CLUSTER) <=
     76             (CONFIG_VMM_VSPACE_SIZE - CONFIG_VMM_STACK_BASE)) , __FUNCTION__ ,
     77             "STACK zone too small\n");
    9278
    9379    // initialize the rwlock protecting the vsegs list
     
    10187                        CONFIG_VMM_GRDXT_W2,
    10288                        CONFIG_VMM_GRDXT_W3 );
    103     if( error )
    104     {
    105         printk("\n[PANIC] in %s : cannot initialize radix tree for process %x\n",
    106                __FUNCTION__ , process->pid );
    107         hal_core_sleep();
    108     }
     89 
     90    assert( (error == 0) , __FUNCTION__ , "cannot initialize radix tree\n" );
    10991
    11092    // register kentry vseg in VMM
     
    11294    size = CONFIG_VMM_KENTRY_SIZE << CONFIG_PPM_PAGE_SHIFT;
    11395    vseg_kentry = vmm_create_vseg( process , base , size , VSEG_TYPE_CODE );
    114     if( vseg_kentry == NULL )
    115     {
    116         printk("\n[PANIC] in %s : cannot register kent vseg for process %x\n",
    117                __FUNCTION__ , process->pid );
    118         hal_core_sleep();
    119     }
     96
     97    assert( (vseg_kentry != NULL) , __FUNCTION__ , "cannot register kentry vseg\n" );
     98
    12099    vmm->kent_vpn_base = 1;
    121100
     
    124103    size = CONFIG_VMM_ARGS_SIZE << CONFIG_PPM_PAGE_SHIFT;
    125104    vseg_args = vmm_create_vseg( process , base , size , VSEG_TYPE_DATA );
    126     if( vseg_args == NULL )
    127     {
    128         printk("\n[PANIC] in %s : cannot register args vseg for process %x\n",
    129                __FUNCTION__ , process->pid );
    130         hal_core_sleep();
    131     }
     105
     106    assert( (vseg_args != NULL) , __FUNCTION__ , "cannot register args vseg\n" );
     107
    132108    vmm->args_vpn_base = CONFIG_VMM_KENTRY_SIZE + 1;
    133109
     
    136112    size = CONFIG_VMM_ENVS_SIZE << CONFIG_PPM_PAGE_SHIFT;
    137113    vseg_envs = vmm_create_vseg( process , base , size , VSEG_TYPE_DATA );
    138     if( vseg_envs == NULL )
    139     {
    140         printk("\n[PANIC] in %s : cannot register envs vseg for process %x\n",
    141                __FUNCTION__ , process->pid );
    142         hal_core_sleep();
    143     }
     114
     115    assert( (vseg_envs != NULL) , __FUNCTION__ , "cannot register envs vseg\n" );
     116
    144117    vmm->envs_vpn_base = CONFIG_VMM_KENTRY_SIZE + CONFIG_VMM_ARGS_SIZE + 1;
    145118
     
    148121    size = (CONFIG_VMM_MMAP_BASE-CONFIG_VMM_HEAP_BASE) << CONFIG_PPM_PAGE_SHIFT;
    149122    vseg_heap = vmm_create_vseg( process , base , size , VSEG_TYPE_HEAP );
    150     if( vseg_heap == NULL )
    151     {
    152         printk("\n[PANIC] in %s : cannot register heap vseg in for process %x\n",
    153                __FUNCTION__ , process->pid );
    154         hal_core_sleep();
    155     }
     123
     124    assert( (vseg_heap != NULL) , __FUNCTION__ , "cannot register heap vseg\n" );
     125
    156126    vmm->heap_vpn_base = CONFIG_VMM_HEAP_BASE;
    157127
    158128    // initialize generic page table
    159129    error = hal_gpt_create( &vmm->gpt );
    160     if( error )
    161     {
    162         printk("PANIC in %s : cannot initialize page table\n", __FUNCTION__ );
    163         hal_core_sleep();
    164     }
     130
     131    assert( (error == 0) , __FUNCTION__ , "cannot initialize page table\n");
    165132
    166133    // initialize STACK allocator
     
    181148
    182149    hal_fence();
    183 }
     150
     151    vmm_dmsg("\n[INFO] %s : exit for process %x\n", __FUNCTION__ , process->pid );
     152
     153}  // end vmm_init()
    184154
    185155//////////////////////////////////////////
     
    301271
    302272    return 0;
    303 }
     273
     274}  // vmm_copy()
    304275
    305276///////////////////////////////////////
     
    342313    // release memory allocated to the local page table
    343314    hal_gpt_destroy( &vmm->gpt );
    344 }
     315
     316}  // end vmm_destroy()
    345317
    346318/////////////////////////////////////////////////
     
    357329        {
    358330                vseg = LIST_ELEMENT( iter , vseg_t , list );
     331
    359332                if( ((vpn_base + vpn_size) > vseg->vpn_base) &&
    360333             (vpn_base < (vseg->vpn_base + vseg->vpn_size)) ) return vseg;
    361334        }
    362335    return NULL;
    363 }
     336
     337}  // end vmm_check_conflict()
    364338
    365339////////////////////////////////////////////////////////////////////////////////////////////
     
    399373    *vpn_size = CONFIG_VMM_STACK_SIZE - 1;
    400374    return 0;
    401 }
     375
     376} // end vmm_stack_alloc()
    402377
    403378////////////////////////////////////////////////////////////////////////////////////////////
     
    464439    *vpn_size = size;
    465440    return 0;
    466 }
     441
     442}  // end vmm_mmap_alloc()
    467443
    468444//////////////////////////////////////////////
     
    473449{
    474450    vseg_t     * vseg;          // created vseg pointer
    475     vpn_t        vpn_base;      // vseg first page
     451    vpn_t        vpn_base;      // first page index
    476452    vpn_t        vpn_size;      // number of pages
    477453        error_t      error;
     
    480456        vmm_t * vmm = &process->vmm;
    481457
    482         vmm_dmsg("\n[INFO] %s enter for process %x / base = %x / size = %x / type = %s\n",
     458        vmm_dmsg("\n[INFO] %s : enter for process %x / base = %x / size = %x / type = %s\n",
    483459                     __FUNCTION__ , process->pid , base , size , vseg_type_str(type) );
    484460
    485     // compute base, size, vpn_base, vpn_size, depending on type
     461    // compute base, size, vpn_base, vpn_size, depending on vseg type
    486462    // we use the VMM specific allocators for STACK and MMAP vsegs
    487463    if( type == VSEG_TYPE_STACK )
     
    520496    else
    521497    {
    522         vpn_base = ARROUND_DOWN( base , CONFIG_PPM_PAGE_SIZE ) >> CONFIG_PPM_PAGE_SHIFT;
    523             vpn_size = ARROUND_UP( base + size , CONFIG_PPM_PAGE_SIZE ) >> CONFIG_PPM_PAGE_SHIFT;
     498        uint32_t vpn_min = base >> CONFIG_PPM_PAGE_SHIFT;
     499        uint32_t vpn_max = (base + size - 1) >> CONFIG_PPM_PAGE_SHIFT;
     500
     501        vpn_base = vpn_min;
     502            vpn_size = vpn_max - vpn_min + 1;
    524503    }
    525504
     
    555534        rwlock_wr_unlock( &vmm->vsegs_lock );
    556535
    557         vmm_dmsg("\n[INFO] : %s exit for process %x, vseg [%x, %x] has been mapped\n",
     536        vmm_dmsg("\n[INFO] %s : exit for process %x / vseg [%x, %x] has been mapped\n",
    558537                     __FUNCTION__ , process->pid , vseg->min , vseg->max );
    559538
Note: See TracChangeset for help on using the changeset viewer.