Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (4 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/mm/mapper.c

    r672 r683  
    33 *
    44 * Authors   Mohamed Lamine Karaoui (2015)
    5  *           Alain Greiner (2016,2017,2018,2019,2020)
     5 *           Alain Greiner          (2016,2017,2018,2019,2020)
    66 *
    77 * Copyright (c)  UPMC Sorbonne Universites
     
    5151{
    5252    mapper_t * mapper_ptr;
    53     kmem_req_t req;
    5453    error_t    error;
    5554
    5655    // allocate memory for mapper descriptor
    57     req.type    = KMEM_KCM;
    58     req.order   = bits_log2( sizeof(mapper_t) );
    59     req.flags   = AF_KERNEL | AF_ZERO;
    60     mapper_ptr  = kmem_remote_alloc( cxy , &req );
     56    mapper_ptr  = kmem_remote_alloc( cxy , bits_log2(sizeof(mapper_t)) , AF_ZERO );
    6157
    6258    if( mapper_ptr == NULL )
    6359    {
    64         printk("\n[ERROR] in %s : no memory for mapper descriptor\n", __FUNCTION__ );
     60
     61#if DEBUG_MAPPER_ERROR
     62printk("\n[ERROR] in %s : no memory for mapper descriptor\n", __FUNCTION__ );
     63#endif
    6564        return XPTR_NULL;
    6665    }
     
    7776    if( error )
    7877    {
    79         printk("\n[ERROR] in %s : cannot initialize radix tree\n", __FUNCTION__ );
    80         req.type  = KMEM_KCM;
    81         req.ptr   = mapper_ptr;
    82         kmem_remote_free( cxy , &req );
     78
     79#if DEBUG_MAPPER_ERROR
     80printk("\n[ERROR] in %s : cannot initialize radix tree\n", __FUNCTION__ );
     81kmem_remote_free( cxy , mapper_ptr , bits_log2(sizeof(mapper_t)) );
     82#endif
    8383        return XPTR_NULL;
    8484    }
     
    104104    uint32_t   found_index = 0;
    105105    uint32_t   start_index = 0;
    106     kmem_req_t req;
    107106
    108107    cxy_t      mapper_cxy = GET_CXY( mapper_xp );
     
    137136
    138137    // release memory for mapper descriptor
    139     req.type = KMEM_KCM;
    140     req.ptr  = mapper_ptr;
    141     kmem_remote_free( mapper_cxy , &req );
     138    kmem_remote_free( mapper_cxy , mapper_ptr , bits_log2(sizeof(mapper_t)) );
    142139
    143140}  // end mapper_destroy()
     
    153150    uint32_t   inode_type = 0;
    154151
    155     thread_t * this = CURRENT_THREAD;
     152#if DEBUG_MAPPER_HANDLE_MISS || DEBUG_MAPPER_ERROR
     153thread_t * this  = CURRENT_THREAD;
     154uint32_t   cycle = (uint32_t)hal_get_cycles();
     155#endif
    156156
    157157    // get target mapper cluster and local pointer
     
    170170
    171171#if DEBUG_MAPPER_HANDLE_MISS
    172 uint32_t      cycle = (uint32_t)hal_get_cycles();
    173172char          name[CONFIG_VFS_MAX_NAME_LENGTH];
    174173if( (DEBUG_MAPPER_HANDLE_MISS < cycle) && (inode != NULL) )
     
    185184#endif
    186185
    187 #if( DEBUG_MAPPER_HANDLE_MISS & 2 )
     186#if( DEBUG_MAPPER_HANDLE_MISS & 1 )
    188187if( DEBUG_MAPPER_HANDLE_MISS < cycle )
    189188{
     
    193192#endif
    194193
    195     // allocate one 4 Kbytes page from the remote mapper cluster
    196     xptr_t page_xp = ppm_remote_alloc_pages( mapper_cxy , 0 );
     194    // allocate one 4 Kbytes page in the remote mapper cluster
     195    void * base_ptr = kmem_remote_alloc( mapper_cxy , 12 , AF_NONE );
     196
     197    if( base_ptr == NULL )
     198    {
     199
     200#if DEBUG_MAPPER_ERROR
     201printk("\n[ERROR] in %s : thread [%x,%x] cannot allocate page in cluster %x / cycle %d\n",
     202__FUNCTION__ , this->process->pid, this->trdid , mapper_cxy , cycle );
     203#endif
     204        return -1;
     205    }
     206
     207    // get pointers on allocated page descrptor
     208    xptr_t   page_xp  = ppm_base2page( XPTR( mapper_cxy , base_ptr ) );
    197209    page_t * page_ptr = GET_PTR( page_xp );
    198                            
    199     if( page_xp == XPTR_NULL )
    200     {
    201         printk("\n[ERROR] in %s : thread [%x,%x] cannot allocate page in cluster %x\n",
    202         __FUNCTION__ , this->process->pid, this->trdid , mapper_cxy );
    203         return -1;
    204     }
    205210
    206211    // initialize the page descriptor
     
    217222                                 page_id,
    218223                                 page_ptr );
    219 
    220224    if( error )
    221225    {
    222         printk("\n[ERROR] in %s : thread[%x,%x] cannot insert page in mapper\n",
    223         __FUNCTION__ , this->process->pid, this->trdid );
    224         ppm_remote_free_pages( mapper_cxy , page_ptr );
     226
     227#if DEBUG_MAPPER_ERROR
     228printk("\n[ERROR] in %s : thread[%x,%x] cannot insert page in mapper / cycle %d\n",
     229__FUNCTION__ , this->process->pid, this->trdid , cycle );
     230ppm_remote_free_pages( mapper_cxy , page_ptr );
     231#endif
    225232        return -1;
    226233    }
     
    236243        if( error )
    237244        {
    238             printk("\n[ERROR] in %s : thread[%x,%x] cannot load page from device\n",
    239             __FUNCTION__ , this->process->pid, this->trdid );
    240             mapper_remote_release_page( mapper_xp , page_ptr );
     245
     246#if DEBUG_MAPPER_ERROR
     247printk("\n[ERROR] in %s : thread[%x,%x] cannot load page from device / cycle %d\n",
     248__FUNCTION__ , this->process->pid, this->trdid , cycle );
     249mapper_remote_release_page( mapper_xp , page_ptr );
     250#endif
    241251            return -1;
    242252         }
     
    260270#endif
    261271
    262 #if( DEBUG_MAPPER_HANDLE_MISS & 2 )
     272#if( DEBUG_MAPPER_HANDLE_MISS & 1 )
    263273if( DEBUG_MAPPER_HANDLE_MISS < cycle )
    264274{
     
    299309#endif
    300310
    301 #if( DEBUG_MAPPER_GET_PAGE & 2 )
     311#if( DEBUG_MAPPER_GET_PAGE & 1 )
    302312if( DEBUG_MAPPER_GET_PAGE < cycle )
    303313ppm_remote_display( local_cxy );
     
    336346            if( error )
    337347            {
    338                 printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
    339                 __FUNCTION__ , this->process->pid, this->trdid );
    340                 remote_rwlock_wr_release( lock_xp );
     348
     349#if DEBUG_MAPPER_ERROR
     350printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
     351__FUNCTION__ , this->process->pid, this->trdid );
     352remote_rwlock_wr_release( lock_xp );
     353#endif
    341354                return XPTR_NULL;
    342355            }
     
    364377#endif
    365378
    366 #if( DEBUG_MAPPER_GET_PAGE & 2)
     379#if( DEBUG_MAPPER_GET_PAGE & 1)
    367380if( DEBUG_MAPPER_GET_PAGE < cycle )
    368381ppm_remote_display( local_cxy );
     
    432445            if( error )
    433446            {
    434                 printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
    435                 __FUNCTION__ , this->process->pid, this->trdid );
    436                 remote_rwlock_wr_release( lock_xp );
     447
     448#if DEBUG_MAPPER_ERROR
     449printk("\n[ERROR] in %s : thread[%x,%x] cannot handle mapper miss\n",
     450__FUNCTION__ , this->process->pid, this->trdid );
     451remote_rwlock_wr_release( lock_xp );
     452#endif
    437453                return XPTR_NULL;
    438454            }
     
    460476#endif
    461477
    462 #if( DEBUG_MAPPER_GET_FAT_PAGE & 2)
     478#if( DEBUG_MAPPER_GET_FAT_PAGE & 1)
    463479if( DEBUG_MAPPER_GET_FAT_PAGE < cycle )
    464480ppm_remote_display( local_cxy );
     
    532548
    533549    // compute indexes of pages for first and last byte in mapper
    534     uint32_t first = min_byte >> CONFIG_PPM_PAGE_SHIFT;
    535     uint32_t last  = max_byte >> CONFIG_PPM_PAGE_SHIFT;
     550    uint32_t first = min_byte >> CONFIG_PPM_PAGE_ORDER;
     551    uint32_t last  = max_byte >> CONFIG_PPM_PAGE_ORDER;
    536552
    537553#if (DEBUG_MAPPER_MOVE_USER & 1)
     
    668684
    669685    // compute indexes for first and last pages in mapper
    670     uint32_t first = min_byte >> CONFIG_PPM_PAGE_SHIFT;
    671     uint32_t last  = max_byte >> CONFIG_PPM_PAGE_SHIFT;
     686    uint32_t first = min_byte >> CONFIG_PPM_PAGE_ORDER;
     687    uint32_t last  = max_byte >> CONFIG_PPM_PAGE_ORDER;
    672688
    673689    // compute source and destination clusters
     
    853869            if( error )
    854870            {
    855                 printk("\n[ERROR] in %s : cannot synchonize dirty page %d\n",
    856                 __FUNCTION__, page_ptr->index );
     871
     872#if DEBUG_MAPPER_SYNC
     873printk("\n[ERROR] in %s : cannot synchonize dirty page %d\n",
     874__FUNCTION__, page_ptr->index );
     875#endif
    857876                return -1;
    858877            }
Note: See TracChangeset for help on using the changeset viewer.