Changeset 671


Ignore:
Timestamp:
Nov 19, 2020, 11:47:00 PM (4 years ago)
Author:
alain
Message:

Cosmetic.

Location:
trunk/kernel/libk
Files:
14 edited

Legend:

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

    r657 r671  
    22 * elf.c - elf parser: find and map process CODE and DATA segments
    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
     
    4343static bool_t elf_isValidHeader(Elf_Ehdr *header)
    4444{
    45         if((header->e_ident[EI_CLASS] == ELFCLASS)
    46            && (header->e_ident[EI_DATA] == ELFDATA2LSB)
    47            && (header->e_ident[EI_VERSION] == EV_CURRENT)
    48            && ((header->e_machine == EM_MIPS) ||
    49                (header->e_machine == EM_MIPS_RS3_LE) ||
    50                (header->e_machine == EM_X86_64))
    51            && (header->e_type == ET_EXEC))
     45        if( (header->e_ident[EI_CLASS]   == ELFCLASS)    &&
     46            (header->e_ident[EI_DATA]    == ELFDATA2LSB) &&
     47            (header->e_ident[EI_VERSION] == EV_CURRENT)  &&
     48        ( (header->e_machine == EM_MIPS)        ||
     49              (header->e_machine == EM_MIPS_RS3_LE) ||
     50              (header->e_machine == EM_X86_64) )         &&
     51            (header->e_type == ET_EXEC) )
    5252                return true;
    5353
     
    7373
    7474///////////////////////////////////////////////////////////////////////////////////////
    75 // This function loads the .elf header in the buffer allocated by the caller.
     75// This static function loads the .elf header in the buffer allocated by the caller.
    7676///////////////////////////////////////////////////////////////////////////////////////
    7777// @ file   : extended pointer on the remote file descriptor.
     
    171171        // get .elf file descriptor cluster and local pointer
    172172        cxy_t        file_cxy = GET_CXY( file_xp );
    173         vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
     173        vfs_file_t * file_ptr = GET_PTR( file_xp );
    174174
    175175        // get local pointer on .elf file mapper
     
    192192                }
    193193
    194         // update reference counter in file descriptor
    195                 vfs_file_count_up( file_xp );
    196 
    197194#if DEBUG_ELF_LOAD
    198195uint32_t   cycle = (uint32_t)hal_get_cycles();
     
    200197if( DEBUG_ELF_LOAD < cycle )
    201198printk("\n[%s] thread[%x,%x] found %s vseg / base %x / size %x\n"
    202 "  file_size %x / file_offset %x / mapper_xp %l / cycle %d\n",
     199"  file_size %x / file_offset %x / mapper[%x,%x] / cycle %d\n",
    203200__FUNCTION__ , this->process->pid, this->trdid,
    204201vseg_type_str(vseg->type) , vseg->min , vseg->max - vseg->min ,
    205 vseg->file_size , vseg->file_offset , vseg->mapper_xp, cycle );
     202vseg->file_size , vseg->file_offset ,
     203GET_CXY(vseg->mapper_xp), GET_PTR(vseg->mapper_xp), cycle );
    206204#endif
    207205
     
    225223
    226224    // get file cluster and local pointer
    227     cxy_t         file_cxy = GET_CXY( file_xp );
    228     vfs_file_t  * file_ptr = GET_PTR( file_xp );
    229 
     225    cxy_t        file_cxy = GET_CXY( file_xp );
     226    vfs_file_t * file_ptr = GET_PTR( file_xp );
     227
     228    // get inode pointer
     229    vfs_inode_t * inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     230 
    230231    // get file name for error reporting and debug
    231     vfs_inode_t * inode    = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
    232     vfs_inode_get_name( XPTR( file_cxy , inode ) , name );
     232    vfs_inode_get_name( XPTR( file_cxy , inode_ptr ) , name );
    233233   
    234234#if DEBUG_ELF_LOAD
     
    252252#if (DEBUG_ELF_LOAD & 1)
    253253if( DEBUG_ELF_LOAD < cycle )
    254 printk("\n[%s] loaded elf header for <%s>\n", __FUNCTION__ , name );
     254printk("\n[%s] loaded elf header for <%s>\n"
     255       "      - size    = %x\n"
     256       "      - version = %x\n"
     257       "      - entry   = %x\n"
     258       "      - machine = %x\n"
     259       "      - offset  = %x\n"
     260       "      - segnum  = %x\n",
     261       __FUNCTION__, name,
     262       header.e_ehsize,
     263       header.e_version,
     264       header.e_entry,
     265       header.e_machine,
     266       header.e_phoff,
     267       header.e_phnum );
    255268#endif
    256269
  • trunk/kernel/libk/elf.h

    r625 r671  
    229229/****************************************************************************************
    230230 * This function registers in the VSL of the process identified by the <process>
    231  * argument the CODE and DATA vsegs defined in the .elf file descriptor <file_xp>.
    232  * The segments are not loaded in memory.
    233  * It also registers the process entry point in VMM.
     231 * argument the CODE and DATA vsegs defined in the .elf file identidied by the
     232 * file descriptor <file_xp>.  The segments themselve are not loaded in memory.
     233 * It also registers the process entry point in the process VMM.
    234234 ****************************************************************************************
    235  * @ file_xp  : extended pointer on .elf file descriptor.
     235 * @ file_xp  : extended pointer on the .elf file descriptor.
    236236 * @ process  : local pointer on target process descriptor.
    237237 ***************************************************************************************/
  • trunk/kernel/libk/grdxt.c

    r657 r671  
    8282        uint32_t   ix3;
    8383
    84 assert( (rt != NULL) , "pointer on radix tree is NULL\n" );
     84assert( __FUNCTION__, (rt != NULL) , "pointer on radix tree is NULL\n" );
    8585
    8686        for( ix1=0 ; ix1 < (uint32_t)(1 << w1) ; ix1++ )
     
    136136
    137137// Check key value
    138 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     138assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    139139
    140140    // compute indexes
     
    202202
    203203// Check key value
    204 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     204assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    205205
    206206    // compute indexes
     
    244244
    245245// Check key value
    246 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     246assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    247247
    248248    void         ** ptr1 = rt->root;
     
    284284
    285285// Check key value
    286 assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
     286assert( __FUNCTION__, ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
    287287
    288288    // compute max indexes
     
    407407        for( ix2=0 ; ix2 < (uint32_t)(1 << w2) ; ix2++ )
    408408        {
    409             // get ptr2
     409            // get ptr3
    410410            ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
    411411
     
    470470
    471471// Check key value
    472 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     472assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    473473
    474474    // compute indexes
     
    585585
    586586// Check key value
    587 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     587assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    588588
    589589    // compute indexes
     
    628628
    629629// Check key value
    630 assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     630assert( __FUNCTION__, ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    631631
    632632    // compute indexes
     
    678678
    679679// Check key value
    680 assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
     680assert( __FUNCTION__, ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
    681681
    682682    // compute min indexes
     
    734734
    735735// check rt_xp
    736 assert( (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" );
     736assert( __FUNCTION__, (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" );
    737737
    738738    // get cluster and local pointer on remote rt descriptor
  • trunk/kernel/libk/grdxt.h

    r657 r671  
    22 * grdxt.h - Three-levels Generic Radix-tree definition.
    33 *
    4  * Authors  Alain Greiner (2016,2017,2018,2019,2019)
     4 * Authors  Alain Greiner (2016,2017,2018,2019,2019,2020)
    55 *
    66 * Copyright  UPMC Sorbonne Universites
  • trunk/kernel/libk/htab.c

    r610 r671  
    104104    else
    105105    {
    106         assert( false , "undefined item type\n" );
     106        assert( __FUNCTION__, false , "undefined item type\n" );
    107107    }
    108108
  • trunk/kernel/libk/list.h

    r656 r671  
    33 *
    44 * Authors Ghassan Almaless  (2008,2009,2010,2011,2012)
    5  *         Alain Greiner     (2016,2017,2018,2019)
     5 *         Alain Greiner     (2016,2017,2018,2019,2020)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    219219static inline void list_unlink( list_entry_t * entry )
    220220{
    221         list_entry_t * pred;
    222     list_entry_t * next;
    223 
    224         pred = entry->pred;
    225         next = entry->next;
     221        list_entry_t * pred = entry->pred;
     222    list_entry_t * next = entry->next;
    226223
    227224        pred->next = next;
    228225        next->pred = pred;
     226
     227    entry->next = NULL;
     228    entry->pred = NULL;
    229229}
    230230
     
    406406                                       list_entry_t * entry )
    407407{
    408         list_entry_t * pred;
    409     list_entry_t * next;
    410 
    411         pred = hal_remote_lpt( XPTR( cxy , &entry->pred ) );
    412         next = hal_remote_lpt( XPTR( cxy , &entry->next ) );
     408        list_entry_t * pred = hal_remote_lpt( XPTR( cxy , &entry->pred ) );
     409    list_entry_t * next = hal_remote_lpt( XPTR( cxy , &entry->next ) );
    413410
    414411        hal_remote_spt( XPTR( cxy , &pred->next ) , next );
    415412        hal_remote_spt( XPTR( cxy , &next->pred ) , pred );
     413
     414        hal_remote_spt( XPTR( cxy , &entry->next ) , NULL );
     415        hal_remote_spt( XPTR( cxy , &entry->pred ) , NULL );
    416416}
    417417
  • trunk/kernel/libk/remote_barrier.c

    r635 r671  
    478478
    479479// check x_size and y_size arguments
    480 assert( (z <= 16) , "DQT mesh size larger than (16*16)\n");
     480assert( __FUNCTION__, (z <= 16) , "DQT mesh size larger than (16*16)\n");
    481481
    482482// check size of an array of 5 DQT nodes
    483 assert( (sizeof(dqt_node_t) * 5 <= 512 ), "array of DQT nodes larger than 512 bytes\n");
     483assert( __FUNCTION__, (sizeof(dqt_node_t) * 5 <= 512 ), "array of DQT nodes larger than 512 bytes\n");
    484484
    485485// check size of DQT barrier descriptor
    486 assert( (sizeof(dqt_barrier_t) <= 0x4000 ), "DQT barrier descriptor larger than 4 pages\n");
     486assert( __FUNCTION__, (sizeof(dqt_barrier_t) <= 0x4000 ), "DQT barrier descriptor larger than 4 pages\n");
    487487
    488488    // get pointer on client thread and process descriptors
     
    767767                void  * buf       = GET_PTR( buf_xp );
    768768
    769 assert( (cxy == GET_CXY(buf_xp)) , "bad extended pointer on dqt_nodes array\n" );
     769assert( __FUNCTION__, (cxy == GET_CXY(buf_xp)) , "bad extended pointer on dqt_nodes array\n" );
    770770
    771771                req.type  = KMEM_KCM;
  • trunk/kernel/libk/remote_buf.c

    r666 r671  
    3131#include <remote_buf.h>
    3232
     33/////////////////////////////////////////////
     34remote_buf_t * remote_buf_alloc( cxy_t  cxy )
     35{
     36    kmem_req_t req;
     37
     38    req.type  = KMEM_KCM;
     39    req.order = bits_log2( sizeof(remote_buf_t) );
     40    req.flags = AF_ZERO;
     41    return kmem_remote_alloc( cxy , &req );
     42}
     43
    3344/////////////////////////////////////////
    3445error_t remote_buf_init( xptr_t   buf_xp,
    35                          uint32_t size )
    36 {
     46                         uint32_t order )
     47{
     48
     49assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     50assert( __FUNCTION__ , (order < 32) , "order cannot be larger than 31" );
     51
    3752    kmem_req_t     req;
    3853    uint8_t      * data;
     
    4257
    4358    // allocate the data buffer
    44     if( size == 0 )
    45     {
    46         data = NULL;
    47     }
    48     else if( size >= CONFIG_PPM_PAGE_SIZE )
     59    if( order >= CONFIG_PPM_PAGE_SHIFT )  // use KMEM_PPM
    4960    {
    5061        req.type  = KMEM_PPM;
    51         req.order = bits_log2( size >> CONFIG_PPM_PAGE_SHIFT );
     62        req.order = order - CONFIG_PPM_PAGE_SHIFT;
    5263        req.flags = AF_NONE;
    5364        data = kmem_remote_alloc( buf_cxy , &req );
     
    5566        if( data == NULL )  return -1;
    5667    }
    57     else
     68    else                                     // use KMEM_KCM
    5869    {
    5970        req.type  = KMEM_KCM;
    60         req.order = bits_log2( size );
     71        req.order = order;
    6172        req.flags = AF_NONE;
    6273        data = kmem_remote_alloc( buf_cxy , &req );
     
    6677
    6778    // initialize buffer descriptor
    68     hal_remote_s32( XPTR( buf_cxy , &buf_ptr->size ) , size );
    69     hal_remote_s32( XPTR( buf_cxy , &buf_ptr->ptw  ) , 0 );
    70     hal_remote_s32( XPTR( buf_cxy , &buf_ptr->ptr  ) , 0 );
    71     hal_remote_s32( XPTR( buf_cxy , &buf_ptr->sts  ) , 0 );
    72     hal_remote_spt( XPTR( buf_cxy , &buf_ptr->data ) , data );
     79    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->order ) , order );
     80    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->wid   ) , 0 );
     81    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->rid   ) , 0 );
     82    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->sts   ) , 0 );
     83    hal_remote_spt( XPTR( buf_cxy , &buf_ptr->data  ) , data );
    7384
    7485    return 0;
    7586
    7687}  // end remote_buf_init()
     88
     89//////////////////////////////////////////////
     90void remote_buf_release_data( xptr_t  buf_xp )
     91{
     92    kmem_req_t     req;
     93
     94assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     95
     96    remote_buf_t * buf_ptr = GET_PTR( buf_xp );
     97    cxy_t          buf_cxy = GET_CXY( buf_xp );
     98
     99    // gets data buffer local pointer and order
     100    uint32_t  order    = hal_remote_l32( XPTR( buf_cxy , &buf_ptr->order ));
     101    char    * data_ptr = hal_remote_lpt( XPTR( buf_cxy , &buf_ptr->data ));
     102
     103    // release memory allocated for data buffer  if required
     104    if( data_ptr != NULL )
     105    {
     106        if( order >= CONFIG_PPM_PAGE_SHIFT )          // use KMEM_PPM
     107        {
     108            req.type  = KMEM_PPM;
     109            req.ptr   = data_ptr;
     110            kmem_remote_free( buf_cxy , &req );
     111        }
     112        else                                          // use KMEM_KCM
     113        {
     114            req.type  = KMEM_KCM;
     115            req.ptr   = data_ptr;
     116            kmem_remote_free( buf_cxy , &req );
     117        }
     118    }
     119}  // end remote_buf_release_data()
    77120
    78121/////////////////////////////////////////
    79122void remote_buf_destroy( xptr_t  buf_xp )
    80123{
     124
     125assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     126
    81127    kmem_req_t   req;
    82128
     
    84130    cxy_t          buf_cxy = GET_CXY( buf_xp );
    85131
    86     uint32_t size = hal_remote_l32( XPTR( buf_cxy , &buf_ptr->size ));
    87 
    88     // release memory allocated to data buffer if required
    89     if( size == 0 )
    90     {
    91         return;
    92     }
    93     else if( size >= CONFIG_PPM_PAGE_SIZE )
    94     {
    95         req.type  = KMEM_PPM;
    96         req.ptr   = hal_remote_lpt( XPTR( buf_cxy , &buf_ptr->data ) );
    97         kmem_remote_free( buf_cxy , &req );
    98     }
    99     else
    100     {
    101         req.type  = KMEM_KCM;
    102         req.ptr   = hal_remote_lpt( XPTR( buf_cxy , &buf_ptr->data ) );
    103         kmem_remote_free( buf_cxy , &req );
    104     }
    105 }
     132    // release data buffer
     133    remote_buf_release_data( buf_xp );
     134
     135    // release remote_buf descriptor
     136    req.type = KMEM_KCM;
     137    req.ptr  = buf_ptr;
     138    kmem_remote_free( buf_cxy , &req );
     139
     140}  // end remote_buf_destroy()
    106141
    107142/////////////////////////////////////////
    108143void remote_buf_reset( xptr_t    buf_xp )
    109144{
    110     remote_buf_t * buf_ptr = GET_PTR( buf_xp );
    111     cxy_t          buf_cxy = GET_CXY( buf_xp );
    112 
    113     hal_remote_s32( XPTR( buf_cxy , &buf_ptr->ptw ) , 0 );
    114     hal_remote_s32( XPTR( buf_cxy , &buf_ptr->ptr ) , 0 );
     145
     146assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     147
     148    remote_buf_t * buf_ptr = GET_PTR( buf_xp );
     149    cxy_t          buf_cxy = GET_CXY( buf_xp );
     150
     151    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->wid ) , 0 );
     152    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->rid ) , 0 );
    115153    hal_remote_s32( XPTR( buf_cxy , &buf_ptr->sts ) , 0 );
    116154}
     
    121159                                uint32_t  nbytes )
    122160{
     161
     162assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     163
    123164    remote_buf_t * buf_ptr = GET_PTR( buf_xp );
    124165    cxy_t          buf_cxy = GET_CXY( buf_xp );
    125166
    126167    // build relevant extended pointers
    127     xptr_t sts_xp  = XPTR( buf_cxy , &buf_ptr->sts );
    128     xptr_t ptr_xp  = XPTR( buf_cxy , &buf_ptr->ptr );
    129     xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size );
    130     xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );
     168    xptr_t sts_xp   = XPTR( buf_cxy , &buf_ptr->sts );
     169    xptr_t rid_xp   = XPTR( buf_cxy , &buf_ptr->rid );
     170    xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order );
     171    xptr_t data_xp  = XPTR( buf_cxy , &buf_ptr->data );
    131172
    132173    // get relevant infos from remote buffer descriptor
    133174    uint32_t  sts  = hal_remote_l32( sts_xp );
    134     uint32_t  ptr  = hal_remote_l32( ptr_xp );
    135     uint32_t  size = hal_remote_l32( size_xp );
     175    uint32_t  rid  = hal_remote_l32( rid_xp );
     176    uint32_t  order = hal_remote_l32( order_xp );
    136177    uint8_t * data = hal_remote_lpt( data_xp );
     178
     179    uint32_t  size = 1 << order;
     180    uint32_t  mask = size - 1;
    137181
    138182    // check enough bytes in buffer
     
    140184
    141185    // move nbytes
    142     if( (ptr + nbytes) <= size)  // no wrap around => one move
     186    if( (rid + nbytes) <= size)  // no wrap around => one move
    143187    {
    144188        hal_copy_to_uspace( u_buf,
    145                             XPTR( buf_cxy , data + ptr ),
     189                            XPTR( buf_cxy , data + rid ),
    146190                            nbytes );
    147191    }
    148192    else                         // wrap around => two moves
    149193    {
    150         uint32_t bytes_1 = size - ptr;
     194        uint32_t bytes_1 = size - rid;
    151195        uint32_t bytes_2 = nbytes - bytes_1;
    152196     
    153197        hal_copy_to_uspace( u_buf,
    154                             XPTR( buf_cxy , data + ptr ),
     198                            XPTR( buf_cxy , data + rid ),
    155199                            bytes_1 );
    156200
     
    160204    }
    161205
    162     // update ptr in buffer descriptor
    163     hal_remote_s32( ptr_xp , (ptr + nbytes) % size );
     206    // update rid in buffer descriptor
     207    hal_remote_s32( rid_xp , (rid + nbytes) & mask );
    164208
    165209    // atomically update sts
     
    175219                                  uint32_t  nbytes )
    176220{
     221
     222assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     223
    177224    remote_buf_t * buf_ptr = GET_PTR( buf_xp );
    178225    cxy_t          buf_cxy = GET_CXY( buf_xp );
    179226
    180227    // build relevant extended pointers
    181     xptr_t sts_xp  = XPTR( buf_cxy , &buf_ptr->sts );
    182     xptr_t ptr_xp  = XPTR( buf_cxy , &buf_ptr->ptr );
    183     xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size );
    184     xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );
     228    xptr_t sts_xp   = XPTR( buf_cxy , &buf_ptr->sts );
     229    xptr_t rid_xp   = XPTR( buf_cxy , &buf_ptr->rid );
     230    xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order );
     231    xptr_t data_xp  = XPTR( buf_cxy , &buf_ptr->data );
    185232
    186233    // get relevant infos from remote buffer descriptor
    187234    uint32_t  sts  = hal_remote_l32( sts_xp );
    188     uint32_t  ptr  = hal_remote_l32( ptr_xp );
    189     uint32_t  size = hal_remote_l32( size_xp );
     235    uint32_t  rid  = hal_remote_l32( rid_xp );
     236    uint32_t  order = hal_remote_l32( order_xp );
    190237    uint8_t * data = hal_remote_lpt( data_xp );
     238
     239    uint32_t  size = 1 << order;
     240    uint32_t  mask = size - 1;
    191241
    192242    // check enough bytes in buffer
     
    194244
    195245    // move nbytes
    196     if( (ptr + nbytes) <= size)  // no wrap around => one move
     246    if( (rid + nbytes) <= size)  // no wrap around => one move
    197247    {
    198248        hal_remote_memcpy( XPTR( local_cxy , k_buf ),
    199                            XPTR( buf_cxy   , data + ptr ),
     249                           XPTR( buf_cxy   , data + rid ),
    200250                           nbytes );
    201251    }
    202252    else                         // wrap around => two moves
    203253    {
    204         uint32_t bytes_1 = size - ptr;
     254        uint32_t bytes_1 = size - rid;
    205255        uint32_t bytes_2 = nbytes - bytes_1;
    206256     
    207257        hal_remote_memcpy( XPTR( local_cxy , k_buf ),
    208                            XPTR( buf_cxy   , data + ptr ),
     258                           XPTR( buf_cxy   , data + rid ),
    209259                           bytes_1 );
    210260
     
    214264    }
    215265
    216     // update ptr in buffer descriptor
    217     hal_remote_s32( ptr_xp , (ptr + nbytes) % size );
     266    // update rid in buffer descriptor
     267    hal_remote_s32( rid_xp , (rid + nbytes) & mask );
    218268
    219269    // atomically update sts
     
    222272    return 0;
    223273
    224 }  // end remote_buf_get_to_user()
     274}  // end remote_buf_get_to_kernel()
    225275
    226276///////////////////////////////////////////////////
     
    229279                                  uint32_t  nbytes )
    230280{
     281
     282assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     283
    231284    remote_buf_t * buf_ptr = GET_PTR( buf_xp );
    232285    cxy_t          buf_cxy = GET_CXY( buf_xp );
    233286
    234287    // build relevant extended pointers
    235     xptr_t sts_xp  = XPTR( buf_cxy , &buf_ptr->sts );
    236     xptr_t ptw_xp  = XPTR( buf_cxy , &buf_ptr->ptw );
    237     xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size );
    238     xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );
     288    xptr_t sts_xp   = XPTR( buf_cxy , &buf_ptr->sts );
     289    xptr_t wid_xp   = XPTR( buf_cxy , &buf_ptr->wid );
     290    xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order );
     291    xptr_t data_xp  = XPTR( buf_cxy , &buf_ptr->data );
    239292
    240293    // get relevant infos from remote buffer descriptor
    241294    uint32_t  sts  = hal_remote_l32( sts_xp );
    242     uint32_t  ptw  = hal_remote_l32( ptw_xp );
    243     uint32_t  size = hal_remote_l32( size_xp );
     295    uint32_t  wid  = hal_remote_l32( wid_xp );
     296    uint32_t  order = hal_remote_l32( order_xp );
    244297    uint8_t * data = hal_remote_lpt( data_xp );
     298
     299    uint32_t  size = 1 << order;
     300    uint32_t  mask = size - 1;
    245301
    246302    // check enough space in buffer
     
    248304
    249305    // move nbytes
    250     if( (ptw + nbytes) <= size)  // no wrap around => one move
    251     {
    252         hal_copy_from_uspace( XPTR( buf_cxy , data + ptw ),
     306    if( (wid + nbytes) <= size)  // no wrap around => one move
     307    {
     308        hal_copy_from_uspace( XPTR( buf_cxy , data + wid ),
    253309                              u_buf,
    254310                              nbytes );
     
    256312    else                         // wrap around => two moves
    257313    {
    258         uint32_t bytes_1 = size - ptw;
     314        uint32_t bytes_1 = size - wid;
    259315        uint32_t bytes_2 = nbytes - bytes_1;
    260316     
    261         hal_copy_from_uspace( XPTR( buf_cxy , data + ptw ),
     317        hal_copy_from_uspace( XPTR( buf_cxy , data + wid ),
    262318                              u_buf,
    263319                              bytes_1 );
     
    268324    }
    269325
    270     // update ptw in buffer descriptor
    271     hal_remote_s32( ptw_xp , (ptw + nbytes) % size );
     326    // update wid in buffer descriptor
     327    hal_remote_s32( wid_xp , (wid + nbytes) & mask );
    272328
    273329    // atomically update sts
     
    283339                                    uint32_t  nbytes )
    284340{
     341
     342assert( __FUNCTION__ , (buf_xp != XPTR_NULL) , "buf_xp cannot be NULL" );
     343
    285344    remote_buf_t * buf_ptr = GET_PTR( buf_xp );
    286345    cxy_t          buf_cxy = GET_CXY( buf_xp );
    287346
    288347    // build relevant extended pointers
    289     xptr_t sts_xp  = XPTR( buf_cxy , &buf_ptr->sts );
    290     xptr_t ptw_xp  = XPTR( buf_cxy , &buf_ptr->ptw );
    291     xptr_t size_xp = XPTR( buf_cxy , &buf_ptr->size );
    292     xptr_t data_xp = XPTR( buf_cxy , &buf_ptr->data );
     348    xptr_t sts_xp   = XPTR( buf_cxy , &buf_ptr->sts );
     349    xptr_t wid_xp   = XPTR( buf_cxy , &buf_ptr->wid );
     350    xptr_t order_xp = XPTR( buf_cxy , &buf_ptr->order );
     351    xptr_t data_xp  = XPTR( buf_cxy , &buf_ptr->data );
    293352
    294353    // get relevant infos from remote buffer descriptor
    295354    uint32_t  sts  = hal_remote_l32( sts_xp );
    296     uint32_t  ptw  = hal_remote_l32( ptw_xp );
    297     uint32_t  size = hal_remote_l32( size_xp );
     355    uint32_t  wid  = hal_remote_l32( wid_xp );
     356    uint32_t  order = hal_remote_l32( order_xp );
    298357    uint8_t * data = hal_remote_lpt( data_xp );
     358
     359    uint32_t  size = 1 << order;
     360    uint32_t  mask = size - 1;
    299361
    300362    // check enough space in buffer
     
    302364
    303365    // move nbytes
    304     if( (ptw + nbytes) <= size)  // no wrap around => one move
    305     {
    306         hal_remote_memcpy( XPTR( buf_cxy   , data + ptw ),
     366    if( (wid + nbytes) <= size)  // no wrap around => one move
     367    {
     368        hal_remote_memcpy( XPTR( buf_cxy   , data + wid ),
    307369                           XPTR( local_cxy , k_buf ),
    308370                           nbytes );
     
    310372    else                         // wrap around => two moves
    311373    {
    312         uint32_t bytes_1 = size - ptw;
     374        uint32_t bytes_1 = size - wid;
    313375        uint32_t bytes_2 = nbytes - bytes_1;
    314376     
    315         hal_remote_memcpy( XPTR( buf_cxy   , data + ptw ),
     377        hal_remote_memcpy( XPTR( buf_cxy   , data + wid ),
    316378                           XPTR( local_cxy , k_buf ),
    317379                           bytes_1 );
     
    322384    }
    323385
    324     // update ptw in buffer descriptor
    325     hal_remote_s32( ptw_xp , (ptw + nbytes) % size );
     386    // update wid in buffer descriptor
     387    hal_remote_s32( wid_xp , (wid + nbytes) & mask );
    326388
    327389    // atomically update sts
  • trunk/kernel/libk/remote_buf.h

    r666 r671  
    3232 * This structure and the associated access functions define a remotely accessible,
    3333 * kernel buffer, handled as a single-reader & single-writer FIFO.
    34  * This kernel buffer is implementes as an array of bytes, whose size is
    35  * dynamically defined by an argument of the "remote_buf_init()" function.
     34 * This kernel buffer is implementes as an array of bytes. The size must be a power
     35 * of 2, dynamically defined by an argument of the "remote_buf_init()" function.
    3636 * The "put()" and "get()" functions defined below move the content of another
    3737 * buffer (can be in kernel or in user space) to/from this circular kernel buffer.
    3838 * This structure is NOT protected by a lock, as the only shared variable is the
    3939 * "sts" variable, that is updated by the hal_remote_atomic_add() primitive.
    40  * It is used to implement the three socket buffers (rx_buf / r2tq / crqq).
    41  * - the "ptw" field defines the first empty slot (for write).
    42  * - the "ptr" field defines the first non empty slot (for read).
    43  * - the "sts" field defines the total number of non empty slots.
     40 *
     41 * - It is used to implement the three socket buffers (rx_buf / r2tq / crqq).
     42 * - It is also used to implement the inter-process communications channels
     43 *   based on named "fifos", or unamed "pipes".
    4444 ***********************************************************************************/
    4545
    4646typedef struct remote_buf_s
    4747{
    48     uint32_t   size;    /*! number of slots in data buffer                         */
    49         uint32_t   ptw;     /*! first empty slot index                                 */
    50         uint32_t   ptr;     /*! first non-empty slot index                             */
     48    uint32_t   order;   /*! ln2( size of data buffer in bytes)                     */
     49        uint32_t   rid;     /*! first empty slot index                                 */
     50        uint32_t   wid;     /*! first non-empty slot index                             */
    5151    uint32_t   sts;     /*! current number of non empty slots                      */
    5252        uint8_t  * data;    /*! local pointer on local data buffer                     */
     
    5555
    5656/************************************************************************************
     57 * This function allocates memory for a remote_buf descriptor in cluster
     58 * defined by the <cxy> argument, and return a local pointer on this descriptor.
     59 ************************************************************************************
     60 * @ cxy    : target cluster identifier.
     61 * @ return local pointer on remote_buf descriptor.
     62 ***********************************************************************************/
     63remote_buf_t * remote_buf_alloc( cxy_t  cxy );
     64
     65/************************************************************************************
    5766 * This function initializes a remote_buf descriptor identified by the <buf_xp>
    58  * argument. It allocates memory for the data, as defined by the <size> argument,
     67 * argument. It allocates memory for the data, as defined by the <order> argument,
    5968 * and initializes the buffer as empty. It must be called by a local thread.
    60  * No memory is allocated if <size> value is 0.
     69 * The <order> value cannot be larger than 31.
    6170 ************************************************************************************
    6271 * @ buf_xp    : [in] extended pointer on buffer descriptor.
    63  * @ size      : [in] number of bytes in buffer / no memory allocated when null.
    64  * @ return  0 if success / return -1 if memory failure.
     72 * @ order     : [in] ln2( number of bytes in buffer) / must be in [0,31].
     73 * @ return  0 if success / return -1 if memory failure or illegal order.
    6574 ***********************************************************************************/
    6675error_t remote_buf_init( xptr_t   buf_xp,
    67                          uint32_t size );
     76                         uint32_t order );
    6877
    6978/************************************************************************************
    70  * This function releases memory allocated for the data buffer of a remote-buf
    71  * descriptor identified by the <buf_xp> argument.
    72  * It must be called by a local thread.
     79 * This function releases memory allocated for the data buffer of an embedded
     80 * remote-buf descriptor identified by the <buf_xp> argument, when the "data"
     81 * pointer is not NULL. It does nothing if the data buffer was not allocated.
     82 * WARNING : do NOT use this function for a dynamically allocated remote_buf.
     83 ************************************************************************************
     84 * @ buf_xp      : [in] extended pointer on buffer descriptor.
     85 ***********************************************************************************/
     86void remote_buf_release_data( xptr_t buf_xp );
     87
     88/************************************************************************************
     89 * This function releases both the memory allocated for the data buffer, and the
     90 * memory allocated for the remote_buf descriptor, for a remote-buf identified
     91 * by the <buf_xp> argument.
     92 * WARNING : do NOT use this function an embedded remote_buf.
    7393 ************************************************************************************
    7494 * @ buf_xp      : [in] extended pointer on buffer descriptor.
  • trunk/kernel/libk/remote_sem.c

    r635 r671  
    188188
    189189// check calling thread can yield
    190 assert( (this->busylocks == 0),
     190assert( __FUNCTION__, (this->busylocks == 0),
    191191"cannot yield : busylocks = %d\n", this->busylocks );
    192192
  • trunk/kernel/libk/user_dir.c

    r641 r671  
    124124
    125125// check dirent size
    126 assert( ( sizeof(struct dirent) == 64), "sizeof(dirent) must be 64\n");
     126assert( __FUNCTION__, ( sizeof(struct dirent) == 64), "sizeof(dirent) must be 64\n");
    127127
    128128    // compute number of dirent per page
     
    253253
    254254// check vseg size
    255 assert( (total_pages == hal_remote_l32( XPTR( ref_cxy , &vseg->vpn_size ) ) ),
     255assert( __FUNCTION__, (total_pages == hal_remote_l32( XPTR( ref_cxy , &vseg->vpn_size ) ) ),
    256256"unconsistent vseg size for dirent array " );
    257257
     
    324324
    325325// check number of pages
    326 assert( (page_id == total_pages) , "unconsistent pages number\n" );
     326assert( __FUNCTION__, (page_id == total_pages) , "unconsistent pages number\n" );
    327327
    328328    // initialise user_dir_t structure
  • trunk/kernel/libk/xhtab.c

    r657 r671  
    22 * xhtab.c - Remote access embedded hash table implementation.
    33 *
    4  * Author     Alain Greiner   (2016,2017,2018,2019)
     4 * Author     Alain Greiner   (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3636///////////////////////////////////////////////////////////////////////////////////////////
    3737// Item type specific functions (four functions for each item type).
    38 // Example below is for <vfs_dentry_t> where the identifier is the dentry name.
     38// Example below is for <vfs_dentry_t> type where the identifier is the dentry name.
    3939///////////////////////////////////////////////////////////////////////////////////////////
    4040
     
    147147    else
    148148    {
    149         assert( false , "illegal item type\n" );
     149        assert( __FUNCTION__, false , "illegal item type\n" );
    150150    }
    151151
     
    285285
    286286///////////////////////////////////////
    287 bool_t xhtab_remove( xptr_t   xhtab_xp,
    288                      void   * key,
    289                      xptr_t   xlist_entry_xp )
     287error_t xhtab_remove( xptr_t   xhtab_xp,
     288                      void   * key,
     289                      xptr_t   xlist_entry_xp )
    290290{
    291291    xptr_t             item_xp;
     
    316316        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    317317
    318         return false;
     318        return -1;
    319319    }
    320320    else                          // remove item if found
     
    329329        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    330330
    331         return true;
     331        return 0;
    332332    }
    333333}  // end xhtab_remove()
  • trunk/kernel/libk/xhtab.h

    r657 r671  
    6161///////////////////////////////////////////////////////////////////////////////////////////
    6262
    63 #define XHASHTAB_SIZE    128   // number of subsets
     63#define XHASHTAB_SIZE    32   // number of subsets
    6464
    6565/******************************************************************************************
     
    118118 * @ key        : local pointer on item identifier.
    119119 * @ xlist_xp   : extended pointer on xlist_entry_t embedded in item to be registered.
    120  * @ return 0 if success / return EINVAL if item already registered.
     120 * @ return 0 if success / return -1 if item already registered.
    121121 *****************************************************************************************/
    122122error_t xhtab_insert( xptr_t   xhtab_xp,
     
    130130 * @ key        : local pointer on item identifier.
    131131 * @ xlist_xp   : extended pointer on xlist_entry embedded in item to be removed.
    132  * @ return 0 if item found / return false if item not found.
     132 * @ return 0 if item found / return -1 if item not found.
    133133 *****************************************************************************************/
    134 bool_t xhtab_remove( xptr_t   xhtab_xp,
    135                      void   * key,
    136                      xptr_t   xlist_entry_xp );
     134error_t xhtab_remove( xptr_t   xhtab_xp,
     135                      void   * key,
     136                      xptr_t   xlist_entry_xp );
    137137
    138138/******************************************************************************************
  • trunk/kernel/libk/xlist.h

    r666 r671  
    264264/***************************************************************************
    265265 * This function removes an entry from an extended  double linked list.
    266  * Two extended pointers must be modified.
    267266 * The memory allocated to the removed entry is not released.
    268267 ***************************************************************************
     
    280279    xptr_t pred = entry.pred;
    281280
    282     // update pred.next <= next
     281    // update pred.next & next.pred
    283282    hal_remote_s64( pred , (uint64_t)next );
    284 
    285     // update next.pred <= pred
    286283    hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)pred );
     284
     285    // reset the removed entry itself
     286    hal_remote_s64( xp , XPTR_NULL );
     287    hal_remote_s64( xp + sizeof(xptr_t) , XPTR_NULL );
    287288}
    288289
Note: See TracChangeset for help on using the changeset viewer.