Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (3 years ago)
Author:
alain
Message:

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/user_dir.c

    r671 r683  
    22 * user_dir.c - kernel DIR related operations implementation.
    33 *
    4  * Authors   Alain   Greiner (2016,2017,2018,2019)
     4 * Authors   Alain   Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    105105    list_entry_t    root;              // root of temporary list of allocated pages
    106106    uint32_t        page_id;           // page index in list of physical pages
    107     kmem_req_t      req;               // kmem request descriptor
    108107    ppn_t           fake_ppn;          // unused, but required by hal_gptlock_pte()
    109108    uint32_t        fake_attr;         // unused, but required by hal_gptlock_pte()
    110109    error_t         error;
     110
     111#if DEBUG_USER_DIR_CREATE || DEBUG_USER_DIR_ERROR
     112uint32_t   cycle = (uint32_t)hal_get_cycles();
     113thread_t * this  = CURRENT_THREAD;
     114#endif
    111115
    112116    // get cluster, local pointer, and pid of reference process
     
    115119    ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) );
    116120
    117 #if DEBUG_USER_DIR
    118 uint32_t cycle = (uint32_t)hal_get_cycles();
    119 thread_t * this = CURRENT_THREAD;
    120 if( cycle > DEBUG_USER_DIR )
     121#if DEBUG_USER_DIR_CREATE
     122if( DEBUG_USER_DIR_CREATE < cycle )
    121123printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) and process %x / cycle %d\n",
    122124__FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, ref_pid, cycle );
     
    133135
    134136    // allocate memory for a local user_dir descriptor
    135     req.type  = KMEM_KCM;
    136     req.order = bits_log2( sizeof(user_dir_t) );
    137     req.flags = AF_ZERO | AF_KERNEL;
    138     dir       = kmem_alloc( &req );
     137    dir = kmem_alloc( bits_log2(sizeof(user_dir_t)) , AF_ZERO );
    139138
    140139    if( dir == NULL )
    141140    {
    142         printk("\n[ERROR] in %s : cannot allocate user_dir_t in cluster %x\n",
    143         __FUNCTION__, local_cxy );
     141
     142#if DEBUG_USER_DIR_ERROR
     143printk("\n[ERROR] in %s : thread[%x,%x] cannot allocate user_dir_t in cluster %x / cycle %d\n",
     144__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
     145#endif
    144146        return NULL;
    145147    }
    146148
    147     // Build and initialize the dirent array as a list of pages.
    148     // For each iteration in this while loop:
     149    // First loop to build and initialize the dirent array
     150    // as a temporary list of pages. For each iteration :
    149151    // - allocate one physical 4 Kbytes (64 dirent slots)
    150152    // - call the relevant FS specific function to scan the directory mapper,
     
    162164    {
    163165        // allocate one physical page
    164         req.type  = KMEM_PPM;
    165         req.order = 0;
    166         req.flags = AF_ZERO;
    167         base      = kmem_alloc( &req );
     166        base = kmem_alloc( CONFIG_PPM_PAGE_ORDER , AF_ZERO );
    168167
    169168        if( base == NULL )
    170169        {
    171             printk("\n[ERROR] in %s : cannot allocate page in cluster %x\n",
    172             __FUNCTION__, ref_cxy );
     170
     171#if DEBUG_USER_DIR_ERROR
     172printk("\n[ERROR] in %s : thread[%x,%x] cannot allocate page in cluster %x / cycle %d\n",
     173__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
     174#endif
    173175            goto user_dir_create_failure;
    174176        }
     
    184186        if( error )
    185187        {
    186             printk("\n[ERROR] in %s : cannot initialise dirent array in cluster %x\n",
    187             __FUNCTION__, ref_cxy );
     188
     189#if DEBUG_USER_DIR_ERROR
     190printk("\n[ERROR] in %s : thread[%x,%x] cannot initialize dirent array in cluster %x / cycle %d\n",
     191__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
     192#endif
    188193            goto user_dir_create_failure;
    189194        }
     
    204209    } // end while
    205210       
    206 #if DEBUG_USER_DIR
    207 if( cycle > DEBUG_USER_DIR )
     211#if DEBUG_USER_DIR_CREATE
     212if( DEBUG_USER_DIR_CREATE < cycle )
    208213printk("\n[%s] thread[%x,%x] initialised dirent array / %d entries\n",
    209214__FUNCTION__, this->process->pid, this->trdid, total_dirents, cycle );
     
    241246    if( vseg == NULL )
    242247    {
    243         printk("\n[ERROR] in %s : cannot create vseg for user_dir in cluster %x\n",
    244         __FUNCTION__, ref_cxy);
     248
     249#if DEBUG_USER_DIR_ERROR
     250printk("\n[ERROR] in %s : thread[%x,%x] cannot create vseg in cluster %x / cycle %d\n",
     251__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
     252#endif
    245253        goto user_dir_create_failure;
    246254    }
    247255
    248 #if DEBUG_USER_DIR
    249 if( cycle > DEBUG_USER_DIR )
     256#if DEBUG_USER_DIR_CREATE
     257if( DEBUG_USER_DIR_CREATE < cycle )
    250258printk("\n[%s] thread[%x,%x] allocated vseg ANON / base %x / size %x\n",
    251259__FUNCTION__, this->process->pid, this->trdid, vseg->min, vseg->max - vseg->min );
     
    269277    vpn_base = hal_remote_l32( XPTR( ref_cxy , &vseg->vpn_base ) );
    270278
    271     // scan the list of allocated physical pages to map
     279    // Second loop on the allocated physical pages to map
    272280    // all physical pages in the reference process GPT
     281    // The pages are mapped in the user process GPT, but
     282    // are removed from the temporary list
     283
    273284    page_id = 0;
     285
    274286    while( list_is_empty( &root ) == false )
    275287    {
     
    290302        if( error )
    291303        {
    292             printk("\n[ERROR] in %s : cannot map vpn %x in GPT\n",
    293             __FUNCTION__, vpn );
    294 
     304
     305#if DEBUG_USER_DIR_ERROR
     306printk("\n[ERROR] in %s : thread[%x,%x] cannot map vpn %x in cluster %x / cycle %d\n",
     307__FUNCTION__, this->process->pid, this->trdid, vpn, local_cxy, cycle );
     308#endif
    295309            // delete the vseg
    296310            intptr_t base = (intptr_t)hal_remote_lpt( XPTR( ref_cxy , &vseg->min ) );
     
    298312         
    299313            // release the user_dir descriptor
    300             req.type = KMEM_KCM;
    301             req.ptr  = dir;
    302             kmem_free( &req );
     314            kmem_free( dir , bits_log2(sizeof(user_dir_t)) );
    303315            return NULL;
    304316        }
     
    310322                         ppn );
    311323
    312 #if DEBUG_USER_DIR 
    313 if( cycle > DEBUG_USER_DIR )
     324#if DEBUG_USER_DIR_CREATE
     325if( DEBUG_USER_DIR_CREATE < cycle )
    314326printk("\n[%s] thread[%x,%x] mapped vpn %x to ppn %x\n",
    315327__FUNCTION__, this->process->pid, this->trdid, vpn + page_id, ppn );
     
    329341    dir->current = 0;
    330342    dir->entries = total_dirents;
    331     dir->ident   = (intptr_t)(vpn_base << CONFIG_PPM_PAGE_SHIFT);
     343    dir->ident   = (intptr_t)(vpn_base << CONFIG_PPM_PAGE_ORDER);
    332344
    333345    // build extended pointers on root and lock of user_dir xlist in ref process
     
    347359    remote_queuelock_release( lock_xp );
    348360
    349 #if DEBUG_USER_DIR
    350 cycle = (uint32_t)hal_get_cycles();
    351 if( cycle > DEBUG_USER_DIR )
     361#if DEBUG_USER_DIR_CREATE
     362if( DEBUG_USER_DIR_CREATE < cycle )
    352363printk("\n[%s] thread[%x,%x] created user_dir (%x,%x) / %d entries / cycle %d\n",
    353364__FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, total_dirents, cycle );
     
    358369user_dir_create_failure:
    359370
    360     // release local user_dir_t structure
    361     req.type = KMEM_KCM;
    362     req.ptr  = dir;
    363     kmem_free( &req );
    364 
    365     // release local physical pages
     371    // release user_dir_t structure
     372    kmem_free( dir , bits_log2(sizeof(user_dir_t)) );
     373
     374    // release physical pages
    366375    while( list_is_empty( &root ) == false )
    367376    {
     377        // get page descriptor
    368378        page = LIST_FIRST( &root , page_t , list );
    369379
     
    371381        base = GET_PTR( ppm_page2base( XPTR( local_cxy , page ) ) );
    372382 
    373         req.type  = KMEM_PPM;
    374         req.ptr   = base;
    375         kmem_free( &req );
     383        // release the page
     384        kmem_free( base , CONFIG_PPM_PAGE_ORDER );
    376385    }
    377386
     
    402411    cluster = LOCAL_CLUSTER;
    403412
     413#if DEBUG_USER_DIR_DESTROY
     414uint32_t cycle = (uint32_t)hal_get_cycles();
     415#endif
     416
    404417    // get cluster, local pointer, and PID of reference user process
    405418    ref_cxy = GET_CXY( ref_xp );
     
    407420    ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) );
    408421
    409 #if DEBUG_USER_DIR
    410 uint32_t cycle = (uint32_t)hal_get_cycles();
    411 if( cycle > DEBUG_USER_DIR )
     422#if DEBUG_USER_DIR_DESTROY
     423if( DEBUG_USER_DIR_DESTROY < cycle )
    412424printk("\n[%s] thread[%x,%x] enter for user_dir (%x,%x) and process %x / cycle %d\n",
    413425__FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, ref_pid, cycle );
     
    475487        hal_atomic_add( &responses , 1 );
    476488
    477 #if (DEBUG_USER_DIR & 1)
    478 uint32_t cycle = (uint32_t)hal_get_cycles();
    479 if( cycle > DEBUG_USER_DIR )
     489#if (DEBUG_USER_DIR_DESTROY & 1)
     490if(  DEBUG_USER_DIR_DESTROY < cycle )
    480491printk("\n[%s] thread[%x,%x] register RPC request in cluster %x\n",
    481492__FUNCTION__, this->process->pid, this->trdid, process_cxy );
     
    496507
    497508    // release local user_dir_t structure
    498     kmem_req_t  req;
    499     req.type = KMEM_KCM;
    500     req.ptr  = dir;
    501     kmem_free( &req );
    502 
    503 #if DEBUG_USER_DIR
     509    kmem_free( dir , bits_log2(sizeof(user_dir_t)) );
     510
     511#if DEBUG_USER_DIR_DESTROY
    504512cycle = (uint32_t)hal_get_cycles();
    505 if( cycle > DEBUG_USER_DIR )
     513if( DEBUG_USER_DIR_DESTROY < cycle )
    506514printk("\n[%s] thread[%x,%x] deleted user_dir (%x,%x) / cycle %d\n",
    507515__FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, cycle );
Note: See TracChangeset for help on using the changeset viewer.