Changeset 657 for trunk/kernel/libk


Ignore:
Timestamp:
Mar 18, 2020, 11:16:59 PM (5 years ago)
Author:
alain
Message:

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

Location:
trunk/kernel/libk
Files:
2 added
10 edited

Legend:

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

    r635 r657  
    11/*
    2  * bits.c - bits manipulation functions implementation
     2 * bits.c - bitmap API implementation
    33 *
    44 * Author  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
     
    2626#include <bits.h>
    2727
     28//////////////////////////////////////////////////////////////////////////////
     29//////////////     local access functions     ///////////////////////////////
     30//////////////////////////////////////////////////////////////////////////////
     31
    2832////////////////////////////////////
    2933void bitmap_init( bitmap_t * bitmap,
     
    4246                        uint32_t   index )
    4347{
    44         uint32_t  word = index / 32;
    45         uint32_t  bit  = index % 32;
     48        uint32_t  word = index >> 5;
     49        uint32_t  bit  = index & 0x1F;
    4650
    4751        bitmap[word] |= ( 1 << bit );
     
    5256                          uint32_t   index )
    5357{
    54         uint32_t  word = index / 32;
    55         uint32_t  bit  = index % 32;
     58        uint32_t  word = index >> 5;
     59        uint32_t  bit  = index & 0x1F;
    5660
    5761        bitmap[word] &= ~( 1 << bit );
     
    6266                            uint32_t   index )
    6367{
    64         uint32_t  word = index / 32;
    65         uint32_t  bit  = index % 32;
     68        uint32_t  word = index >> 5;
     69        uint32_t  bit  = index & 0x1F;
    6670
    6771        return (bitmap[word] & ( 1 << bit )) != 0;
    6872}
     73
     74/////////////////////////////////////////
     75uint32_t bitmap_alloc( bitmap_t * bitmap,
     76                       uint32_t   size )
     77{
     78    uint32_t max_word;
     79    uint32_t max_bit;
     80        uint32_t word;
     81        uint32_t bit;
     82 
     83    if( size )
     84    {
     85        max_word = ( (size-1) >>5 ) + 1;
     86
     87        for( word = 0 ; word < max_word ; word++ )
     88            {
     89            max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32;
     90
     91                    if(bitmap[word] != 0XFFFFFFFF)
     92                    {
     93                            for(bit = 0 ; bit < max_bit ; bit++)
     94                            {
     95                                    if( (bitmap[word] & (1 << bit)) == 0 )
     96                    {
     97                        bitmap[word] |= (1 << bit);
     98                        return (word*32 + bit);
     99                    }
     100                            }
     101            }
     102                }
     103        }
     104
     105        return -1;
     106
     107}  // end bitmap_alloc()
    69108
    70109//////////////////////////////////////////
     
    207246{
    208247    uint32_t max_word;
     248    uint32_t max_bit;
    209249        uint32_t word;
    210250        uint32_t bit;
     
    216256        for( word = 0 ; word < max_word ; word++ )
    217257            {
     258            max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32;
     259
    218260                    if(bitmap[word] != 0)
    219261                    {
    220                             for(bit = 0 ; bit < 32 ; bit++)
     262                            for(bit = 0 ; bit < max_bit ; bit++)
    221263                            {
    222264                                    if( bitmap[word] & (1 << bit) ) return (word*32 + bit);
     
    235277{
    236278    uint32_t max_word;
     279    uint32_t max_bit;
    237280        uint32_t word;
    238281        uint32_t bit;
     
    244287        for( word = 0 ; word < max_word ; word++ )
    245288            {
     289            max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32;
     290
    246291                    if(bitmap[word] != 0XFFFFFFFF)
    247292                    {
    248                             for(bit = 0 ; bit < 32 ; bit++)
     293                            for(bit = 0 ; bit < max_bit ; bit++)
    249294                            {
    250295                                    if( (bitmap[word] & (1 << bit)) == 0 ) return (word*32 + bit);
     
    258303}  // bitmap_ffc()
    259304
     305
     306//////////////////////////////////////////////////////////////////////////////
     307//////////////     remote access functions     ///////////////////////////////
     308//////////////////////////////////////////////////////////////////////////////
     309
     310////////////////////////////////////////////
     311void bitmap_remote_init( xptr_t   bitmap_xp,
     312                         uint32_t len )
     313{
     314    bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp );
     315    cxy_t      bitmap_cxy = GET_CXY( bitmap_xp );
     316
     317    uint32_t word;
     318    uint32_t nwords = BITMAP_SIZE( len );
     319
     320    for( word = 0 ; word < nwords ; word++ )
     321    {
     322        hal_remote_s32( XPTR( bitmap_cxy , &bitmap_ptr[word] ) , 0 );
     323    }
     324}
     325
     326////////////////////////////////////////////////////
     327inline void bitmap_remote_set( xptr_t     bitmap_xp,
     328                               uint32_t   index )
     329{
     330    bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp );
     331    cxy_t      bitmap_cxy = GET_CXY( bitmap_xp );
     332
     333        uint32_t  word = index / 32;
     334        uint32_t  bit  = index % 32;
     335
     336    hal_remote_atomic_or( XPTR( bitmap_cxy , &bitmap_ptr[word] ) , (1 <<bit) );
     337}
     338
     339//////////////////////////////////////////////////////
     340inline void bitmap_remote_clear( xptr_t     bitmap_xp,
     341                                 uint32_t   index )
     342{
     343    bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp );
     344    cxy_t      bitmap_cxy = GET_CXY( bitmap_xp );
     345
     346        uint32_t  word = index / 32;
     347        uint32_t  bit  = index % 32;
     348
     349    hal_remote_atomic_and( XPTR( bitmap_cxy , &bitmap_ptr[word] ) , ~(1 <<bit) );
     350}
     351
     352///////////////////////////////////////////////////
     353uint32_t bitmap_remote_alloc( xptr_t     bitmap_xp,
     354                              uint32_t   size )
     355{
     356    uint32_t max_word;
     357    uint32_t max_bit;
     358        uint32_t word;
     359        uint32_t bit;
     360    xptr_t   word_xp;
     361    uint32_t value;
     362 
     363    bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp );
     364    cxy_t      bitmap_cxy = GET_CXY( bitmap_xp );
     365
     366    if( size )
     367    {
     368        max_word = ( (size-1) >>5 ) + 1;
     369
     370        for( word = 0 ; word < max_word ; word++ )
     371            {
     372            max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32;
     373
     374            word_xp = XPTR( bitmap_cxy , &bitmap_ptr[word] );
     375
     376            value   = hal_remote_l32( word_xp );
     377
     378                    if( value != 0XFFFFFFFF )
     379                    {
     380                            for(bit = 0 ; bit < max_bit ; bit++)
     381                            {
     382                                    if( (value & (1 << bit)) == 0 )
     383                    {
     384                        hal_remote_s32( word_xp , value | (1 << bit) );
     385                        return (word*32 + bit);
     386                    }
     387                            }
     388            }
     389                }
     390        }
     391
     392        return -1;
     393
     394}  // end bitmap_alloc()
     395
     396///////////////////////////////////////////////
     397uint32_t bitmap_remote_ffc( xptr_t   bitmap_xp,
     398                                     uint32_t size )
     399{
     400    uint32_t max_word;
     401    uint32_t max_bit;
     402        uint32_t word;
     403        uint32_t bit;
     404    uint32_t value;
     405 
     406    bitmap_t * bitmap_ptr = GET_PTR( bitmap_xp );
     407    cxy_t      bitmap_cxy = GET_CXY( bitmap_xp );
     408
     409    if( size )
     410    {
     411        max_word = ( (size-1) >>5 ) + 1;
     412
     413        for( word = 0 ; word < max_word ; word++ )
     414            {
     415            max_bit = (word == (max_word - 1)) ? (size & 0x1F) : 32;
     416
     417            value = hal_remote_l32( XPTR( bitmap_cxy , &bitmap_ptr[word] ) );
     418
     419                    if( value != 0xFFFFFFFF )
     420                    {
     421                            for(bit = 0 ; bit < max_bit ; bit++)
     422                            {
     423                                    if( (value & (1 << bit)) == 0 ) return (word*32 + bit);
     424                            }
     425            }
     426                }
     427        }
     428
     429        return -1;
     430
     431}  // bitmap_remote_ffc()
     432
     433
  • trunk/kernel/libk/bits.h

    r635 r657  
    11/*
    2  * bits.h - bits manipulation helper functions
     2 * bits.h - bitmap API definition
    33 *
    44 * Author   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
     
    2828#include <kernel_config.h>
    2929#include <hal_kernel_types.h>
    30 
    31 /*********************************************************************************************
    32  * These macros are NOT used by the bitmap, but can be useful in other contexts... [AG]
    33  *********************************************************************************************/
    34 
    35 #define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val))
    36 #define ARROUND_DOWN(val, size)  ((val) & ~((size) - 1))
    37 
    38 #define ABS(x) (((x) < 0) ? -(x) : (x))
    39 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
    40 #define MAX(x,y) (((x) < (y)) ? (y) : (x))
     30#include <hal_remote.h>
     31
     32/**********************************************************************************************
     33 * This file defines the API to access a generic bitmap, that can be local or remote.
     34 * It is implemented as an array of uint32_t words.
     35 * The number of entries in this array is statically defined at compile time
     36 * and defines the max number of items that can be registered in the bitmap.
     37 * The remote accesses are used in the VFS by the inum allocator.
     38 *********************************************************************************************/
     39
     40typedef uint32_t    bitmap_t;
     41
     42/**********************************************************************************************
     43 * This macro returns the number of 32 bits words required to register <size> entries.
     44 *********************************************************************************************/
     45
     46#define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) )
    4147
    4248/**********************************************************************************************
     
    4450 * It returns 0xFFFFFFFF if data is larger than 0x80000000.
    4551 *********************************************************************************************/
     52
    4653#define POW2_ROUNDUP(data) ( (data <= 0x00000001) ? 0x00000001  : \
    4754                             (data <= 0x00000002) ? 0x00000002  : \
     
    7784                             (data <= 0x80000000) ? 0x80000000  : 0xFFFFFFFF )
    7885
    79 /**********************************************************************************************
    80  * This macro returns the number of 32 bits words required to register <size> entries.
    81  *********************************************************************************************/
    82 
    83 #define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) )
    84 
    85 typedef uint32_t    bitmap_t;
    86 
    87 /*********************************************************************************************
    88  * This function reset all bits in a bitmap. (array ot 32 bits words).
     86/*********************************************************************************************
     87 * These macros are NOT used by the bitmap, but are useful in other contexts... [AG]
     88 *********************************************************************************************/
     89
     90#define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val))
     91#define ARROUND_DOWN(val, size)  ((val) & ~((size) - 1))
     92
     93#define ABS(x) (((x) < 0) ? -(x) : (x))
     94#define MIN(x,y) (((x) < (y)) ? (x) : (y))
     95#define MAX(x,y) (((x) < (y)) ? (y) : (x))
     96
     97/*********************************************************************************************
     98 * This function reset all bits in a local or remote bitmap.
    8999 *********************************************************************************************
    90100 * @ bitmap  : pointer on first word in the bitmap.
    91  * @ len     : number of bits to reset.
    92  ********************************************************************************************/
    93 void bitmap_init( bitmap_t * bitmap,
    94                   uint32_t   len );
    95 
    96 /*********************************************************************************************
    97  * This function set a specific bit in a bitmap.
     101 * @ size    : number of bits in bitmap.
     102 ********************************************************************************************/
     103extern void bitmap_init( bitmap_t * bitmap,
     104                         uint32_t   size );
     105
     106extern void bitmap_remote_init( xptr_t   bitmap_xp,
     107                                uint32_t size );
     108
     109/*********************************************************************************************
     110 * These functions set a specific bit in a local or remote bitmap.
    98111 *********************************************************************************************
    99112 * @ bitmap  : pointer on the bitmap
     
    103116                               uint32_t   index );
    104117
    105 /*********************************************************************************************
    106  * This function clear a specific bit in a bitmap.
     118extern inline void bitmap_remote_set( xptr_t    bitmap_xp,
     119                                      uint32_t  index );
     120
     121/*********************************************************************************************
     122 * These functions clear a specific bit in a local or remote bitmap.
    107123 *********************************************************************************************
    108124 * @ bitmap  : pointer on the bitmap
     
    112128                                 uint32_t   index );
    113129
    114 /*********************************************************************************************
    115  * This function returns a specific bit in a bitmap.
     130extern inline void bitmap_remote_clear( xptr_t     bitmap_xp,
     131                                        uint32_t   index );
     132
     133/*********************************************************************************************
     134 * These functions search the first bit non-set in a local or remote bitmap, in the
     135 * range [0 , size-1], set this bit, and return the index of the found bit.
     136 * The lock protecting the bitmap must be taken by the caller.
     137 *********************************************************************************************
     138 * @ bitmap  : pointer on the bitmap.
     139 * @ size    : number of bits to scan.
     140 * @ returns index of found bit / returns 0xFFFFFFFF if not found.
     141 ********************************************************************************************/
     142extern uint32_t bitmap_alloc( bitmap_t * bitmap,
     143                              uint32_t   size );
     144
     145extern uint32_t bitmap_remote_alloc( xptr_t    bitmap_xp,
     146                                     uint32_t  size );
     147
     148/*********************************************************************************************
     149 * This function returns the index of aa specific bit in a bitmap.
    116150 *********************************************************************************************
    117151 * @ bitmap  : pointer on the bitmap
     
    179213
    180214/*********************************************************************************************
    181  * This function returns the index of first bit cleared in a bitmap, starting from bit 0.
     215 * These functions return the index of first bit cleared in a local or remote bitmap,
     216 * starting from bit 0.
    182217 *********************************************************************************************
    183218 * @ bitmap  : pointer on the bitmap
     
    187222extern uint32_t bitmap_ffc( bitmap_t * bitmap,
    188223                            uint32_t   size );
     224
     225extern uint32_t bitmap_remote_ffc( xptr_t   bitmap_xp,
     226                                   uint32_t size );
    189227
    190228/*********************************************************************************************
  • trunk/kernel/libk/elf.c

    r651 r657  
    224224        error_t      error;
    225225
    226     // get file name for error reporting and debug
     226    // get file cluster and local pointer
    227227    cxy_t         file_cxy = GET_CXY( file_xp );
    228228    vfs_file_t  * file_ptr = GET_PTR( file_xp );
     229
     230    // get file name for error reporting and debug
    229231    vfs_inode_t * inode    = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
    230232    vfs_inode_get_name( XPTR( file_cxy , inode ) , name );
  • trunk/kernel/libk/grdxt.c

    r656 r657  
    332332////////////////////////////////////////////////////////////////////////////////////////
    333333
     334////////////////////////////////////////////
     335error_t grdxt_remote_init( xptr_t     rt_xp,
     336                           uint32_t   ix1_width,
     337                           uint32_t   ix2_width,
     338                           uint32_t   ix3_width )
     339{
     340    void      ** root;
     341        kmem_req_t   req;
     342
     343    // get cluster and local pointer
     344    cxy_t     rt_cxy = GET_CXY( rt_xp );
     345    grdxt_t * rt_ptr = GET_PTR( rt_xp );
     346 
     347    // initialize widths
     348    hal_remote_s32( XPTR( rt_cxy , &rt_ptr->ix1_width ) , ix1_width );
     349    hal_remote_s32( XPTR( rt_cxy , &rt_ptr->ix2_width ) , ix2_width );
     350    hal_remote_s32( XPTR( rt_cxy , &rt_ptr->ix3_width ) , ix3_width );
     351
     352    // allocates first level array
     353        req.type  = KMEM_KCM;
     354        req.order = ix1_width + ( (sizeof(void*) == 4) ? 2 : 3 );
     355        req.flags = AF_KERNEL | AF_ZERO;
     356        root      = kmem_remote_alloc( rt_cxy , &req );
     357
     358        if( root == NULL )
     359    {
     360        printk("\n[ERROR] in %s : cannot allocate first level array\n", __FUNCTION__);
     361        return -1;
     362    }
     363 
     364    // register first level array in rt descriptor
     365    hal_remote_spt( XPTR( rt_cxy , &rt_ptr->root ) , root );
     366 
     367        return 0;
     368
     369}  // end grdxt_remote_init()
     370
     371//////////////////////////////////////////
     372void grdxt_remote_destroy( xptr_t  rt_xp )
     373{
     374        kmem_req_t req;
     375
     376    uint32_t   w1;
     377    uint32_t   w2;
     378    uint32_t   w3;
     379
     380        uint32_t   ix1;
     381        uint32_t   ix2;
     382        uint32_t   ix3;
     383
     384    void    ** ptr1;
     385    void    ** ptr2;
     386    void    ** ptr3;
     387
     388    // get cluster and local pointer
     389    cxy_t     rt_cxy = GET_CXY( rt_xp );
     390    grdxt_t * rt_ptr = GET_PTR( rt_xp );
     391
     392    // get widths
     393    w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     394    w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) );
     395    w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
     396
     397    // get ptr1
     398    ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     399
     400        for( ix1=0 ; ix1 < (uint32_t)(1 << w1) ; ix1++ )
     401        {
     402        // get ptr2
     403        ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     404
     405                if( ptr2 == NULL ) continue;
     406
     407        for( ix2=0 ; ix2 < (uint32_t)(1 << w2) ; ix2++ )
     408        {
     409            // get ptr2
     410            ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     411
     412                    if( ptr3 == NULL ) continue;
     413
     414            for( ix3=0 ; ix3 < (uint32_t)(1 << w3) ; ix3++ )
     415            {
     416                 if( ptr3[ix3] != NULL )
     417                 {
     418                     printk("\n[WARNING] in %s : ptr3[%d][%d][%d] non empty\n",
     419                     __FUNCTION__, ix1, ix2, ix3 );
     420                 }
     421            }
     422
     423            // release level 3 array
     424            req.type = KMEM_KCM;
     425                    req.ptr  = ptr3;
     426                    kmem_remote_free( rt_cxy , &req );
     427        }
     428
     429        // release level 2 array
     430        req.type = KMEM_KCM;
     431                req.ptr  = ptr2;
     432            kmem_remote_free( rt_cxy , &req );
     433    }
     434
     435    // release level 1 array
     436    req.type = KMEM_KCM;
     437        req.ptr  = ptr1;
     438    kmem_remote_free( rt_cxy , &req );
     439
     440}  // end grdxt_remote_destroy()
     441
    334442//////////////////////////////////////////////
    335443error_t grdxt_remote_insert( xptr_t     rt_xp,
     
    464572
    465573////////////////////////////////////////////
    466 void * grdxt_remote_remove( xptr_t    rt_xp,
     574xptr_t grdxt_remote_remove( xptr_t    rt_xp,
    467575                            uint32_t  key )
    468576{
     
    489597    // get ptr2
    490598        void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
    491         if( ptr2 == NULL ) return NULL;
     599        if( ptr2 == NULL ) return XPTR_NULL;
    492600
    493601    // get ptr3
    494602        void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
    495         if( ptr3 == NULL ) return NULL;
     603        if( ptr3 == NULL ) return XPTR_NULL;
    496604
    497605    // get value
     
    502610        hal_fence();
    503611
    504         return value;
     612        return XPTR( rt_cxy , value );
    505613
    506614}  // end grdxt_remote_remove()
     
    523631
    524632    // compute indexes
    525     uint32_t        ix1 = key >> (w2 + w3);              // index in level 1 array
    526         uint32_t        ix2 = (key >> w3) & ((1 << w2) -1);  // index in level 2 array
    527         uint32_t        ix3 = key & ((1 << w3) - 1);         // index in level 3 array
     633    uint32_t       ix1 = key >> (w2 + w3);              // index in level 1 array
     634        uint32_t       ix2 = (key >> w3) & ((1 << w2) -1);  // index in level 2 array
     635        uint32_t       ix3 = key & ((1 << w3) - 1);         // index in level 3 array
    528636
    529637    // get ptr1
     
    546654
    547655}  // end grdxt_remote_lookup()
     656
     657////////////////////////////////////////////////
     658xptr_t grdxt_remote_get_first( xptr_t     rt_xp,
     659                               uint32_t   start_key,
     660                               uint32_t * found_key )
     661{
     662    uint32_t        ix1;
     663    uint32_t        ix2;
     664    uint32_t        ix3;
     665
     666    void        ** ptr1;       // local base address of remote first level array
     667    void        ** ptr2;       // local base address of remote second level array
     668    void        ** ptr3;       // local base address of remote third level array
     669
     670    // get cluster and local pointer on remote rt descriptor
     671    grdxt_t       * rt_ptr = GET_PTR( rt_xp );
     672    cxy_t           rt_cxy = GET_CXY( rt_xp );
     673
     674    // get widths
     675    uint32_t        w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     676    uint32_t        w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) );
     677    uint32_t        w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
     678
     679// Check key value
     680assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
     681
     682    // compute min indexes
     683    uint32_t       min1 = start_key >> (w2 + w3);           
     684        uint32_t       min2 = (start_key >> w3) & ((1 << w2) -1);
     685        uint32_t       min3 = start_key & ((1 << w3) - 1); 
     686
     687    // compute max indexes
     688    uint32_t       max1 = 1 << w1;
     689    uint32_t       max2 = 1 << w2;
     690    uint32_t       max3 = 1 << w3;
     691
     692    // get ptr1
     693    ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     694
     695    for( ix1 = min1 ; ix1 < max1 ; ix1++ )
     696    {
     697        ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     698        if( ptr2 == NULL ) continue;
     699
     700        for( ix2 = min2 ; ix2 < max2 ; ix2++ )
     701        {
     702            ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     703            if( ptr3 == NULL ) continue;
     704
     705            for( ix3 = min3 ; ix3 < max3 ; ix3++ )
     706            {
     707                void * item = hal_remote_lpt( XPTR( rt_cxy , &ptr3[ix3] ) );
     708
     709                if( item == NULL ) continue;
     710                else                   
     711                {
     712                    *found_key = (ix1 << (w2+w3)) | (ix2 << w3) | ix3;
     713                    return XPTR( rt_cxy , item );
     714                }
     715            }
     716        }
     717    }
     718
     719    return XPTR_NULL;
     720
     721}  // end grdxt_remote_get_first()
    548722
    549723/////////////////////////i/////////////////
  • trunk/kernel/libk/grdxt.h

    r656 r657  
    22 * grdxt.h - Three-levels Generic Radix-tree definition.
    33 *
    4  * Authors  Alain Greiner (2016,2017,2018,2019)
     4 * Authors  Alain Greiner (2016,2017,2018,2019,2019)
    55 *
    66 * Copyright  UPMC Sorbonne Universites
     
    124124/*******************************************************************************************
    125125 * This function scan all radix-tree entries in increasing key order, starting from
    126  * the value defined by the <start_key> argument, and return a pointer on the first valid
    127  * registered item, and the found item key value.
     126 * the key defined by the <start_key> argument. It returns a pointer on the first valid
     127 * registered item, and returns in the <found_key> buffer the found item key value.
    128128 * It must be called by a local thread.
    129129 *******************************************************************************************
     
    142142
    143143/*******************************************************************************************
     144 * This function initialises the radix-tree descriptor,
     145 * and allocates memory for the first level array of pointers.
     146 * It can be called by any thread running in any cluster
     147 *******************************************************************************************
     148 * @ rt_xp     : extended pointer on the radix-tree descriptor.
     149 * @ ix1_width : number of bits in ix1 field
     150 * @ ix2_width : number of bits in ix2 field
     151 * @ ix3_width : number of bits in ix3 field
     152 * @ returns 0 if success / returns ENOMEM if no more memory.     
     153 ******************************************************************************************/
     154error_t grdxt_remote_init( xptr_t     rt_xp,
     155                           uint32_t   ix1_width,
     156                           uint32_t   ix2_width,
     157                           uint32_t   ix3_width );
     158
     159/*******************************************************************************************
     160 * This function releases all memory allocated to the radix-tree infrastructure.
     161 * A warning message is printed on the kernel TXT0 if the radix tree is not empty.
     162 * It can be called by any thread running in any cluster
     163 *******************************************************************************************
     164 * @ rt_xp    : extended pointer on the radix-tree descriptor.
     165 ******************************************************************************************/
     166void grdxt_remote_destroy( xptr_t  rt_xp );
     167
     168/*******************************************************************************************
    144169 * This function insert a new item in a - possibly remote - radix tree.
    145170 * It dynamically allocates memory for new second and third level arrays if required.
     171 * It can be called by any thread running in any cluster
    146172 *******************************************************************************************
    147173 * @ rt_xp   : extended pointer on the radix-tree descriptor.
     
    157183 * This function removes an item identified by its key from a - possibly remote - radix
    158184 * tree, and returns a local pointer on the removed item. No memory is released.
     185 * It can be called by a thread running in any cluster
    159186 *******************************************************************************************
    160187 * @ rt_xp   : pointer on the radix-tree descriptor.
    161188 * @ key     : key value.
    162  * @ returns local pointer on removed item if success / returns NULL if failure.
    163  ******************************************************************************************/
    164 void * grdxt_remote_remove( xptr_t    rt_xp,
     189 * @ returns extended pointer on removed item if success / returns XPTR_NULL if failure.
     190 ******************************************************************************************/
     191xptr_t grdxt_remote_remove( xptr_t    rt_xp,
    165192                            uint32_t  key );
    166193
     
    169196 * on the item identified by the <key> argument, from the radix tree identified by
    170197 * the <rt_xp> remote pointer.
     198 * It can be called by a thread running in any cluster
    171199 *******************************************************************************************
    172200 * @ rt_xp   : extended pointer on the radix-tree descriptor.
    173201 * @ key     : key value.
    174  * @ returns an extended pointer on found item if success / returns XPTR_NULL if failure.
     202 * @ returns extended pointer on found item if success / returns XPTR_NULL if not found.
    175203 ******************************************************************************************/
    176204xptr_t grdxt_remote_lookup( xptr_t     rt_xp,
     
    178206
    179207/*******************************************************************************************
     208 * This function scan all radix-tree entries of a - possibly remote - radix tree <rt_xp>,
     209 * in increasing key order, starting from the key defined by the <start_key> argument.
     210 * It returns an extended pointer on the first valid registered item, and returns in the
     211 * <found_key> buffer the found item key value.
     212 * It can be called by a thread running in any cluster
     213 *******************************************************************************************
     214 * @ rt_xp      : extended pointer on the radix-tree descriptor.
     215 * @ start_key  : key starting value for the scan.
     216 * @ found_key  : [out] buffer for found key value.
     217 * @ return xptr on first valid item if found / return XPTR_NULL if no item found.
     218 ******************************************************************************************/
     219xptr_t grdxt_remote_get_first( xptr_t     rt_xp,
     220                               uint32_t   start_key,
     221                               uint32_t * found_key );
     222
     223/*******************************************************************************************
    180224 * This function displays the current content of a possibly remote radix_tree.
     225 * It can be called by a thread running in any cluster
    181226 *******************************************************************************************
    182227 * @ rt      : extended pointer on the radix-tree descriptor.
  • trunk/kernel/libk/remote_fifo.c

    r563 r657  
    6565    watchdog = 0;
    6666
    67     // get write slot index with atomic increment
     67    // get write slot index with atomic increment QQQQQQQQQQ
    6868        wr_id = hal_remote_atomic_add( XPTR( fifo_cxy , &fifo_ptr->wr_id ) , 1 );
    6969
  • trunk/kernel/libk/remote_rwlock.h

    r629 r657  
    11/*
    2  * remote_rwlock.h - kernel remote read/writelock definition.
     2 * remote_rwlock.h - kernel remote read/write lock definition.
    33 *
    4  * Authors   Alain Greiner   (2016,2017,2018,2019)
     4 * Authors   Alain Greiner   (2016,2017,2018,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/libk/xhtab.c

    r635 r657  
    5353
    5454        return (name[0] % XHASHTAB_SIZE);
    55 /*
    56     uint32_t   index = 0;
    57         while( *name )
    58     {
    59         index = index + (*(name++) ^ index);
    60     }
    61         return index % XHASHTAB_SIZE;
    62 */
    63 
    6455}
    6556
     
    128119////////////////////////////////////////////////////////////////////////////////////////
    129120
    130 //////////////////////////////////////////
    131 void xhtab_init( xhtab_t          * xhtab,
     121/////////////////////////////////////////////
     122void xhtab_init( xptr_t             xhtab_xp,
    132123                 xhtab_item_type_t  type )
    133124{
    134         uint32_t i;
     125    uint32_t i;
     126
     127    // get cluster and local pointer
     128    xhtab_t * ptr = GET_PTR( xhtab_xp );
     129    cxy_t     cxy = GET_CXY( xhtab_xp );
    135130
    136131    // initialize lock
    137     remote_busylock_init( XPTR( local_cxy , &xhtab->lock), LOCK_XHTAB_STATE );
    138 
    139     xhtab->items            = 0;
    140     xhtab->current_index    = 0;
    141     xhtab->current_xlist_xp = XPTR_NULL;
    142 
     132    remote_busylock_init( XPTR( cxy , &ptr->lock), LOCK_XHTAB_STATE );
     133
     134    // initialise various fiels
     135    hal_remote_s32( XPTR( cxy , &ptr->items ) , 0 );
     136    hal_remote_s32( XPTR( cxy , &ptr->current_index ) , 0 );
     137    hal_remote_s64( XPTR( cxy , &ptr->current_xlist_xp ) , XPTR_NULL );
     138   
     139    // initialize functions pointers
    143140    if( type == XHTAB_DENTRY_TYPE )
    144141    {
    145         xhtab->item_match_key  = &xhtab_dentry_item_match_key;
    146         xhtab->index_from_key  = &xhtab_dentry_index_from_key;
    147         xhtab->item_from_xlist = &xhtab_dentry_item_from_xlist;
    148         xhtab->item_print_key  = &xhtab_dentry_item_print_key;
     142        hal_remote_spt( XPTR( cxy , &ptr->item_match_key  ) , &xhtab_dentry_item_match_key );
     143        hal_remote_spt( XPTR( cxy , &ptr->index_from_key  ) , &xhtab_dentry_index_from_key );
     144        hal_remote_spt( XPTR( cxy , &ptr->item_from_xlist ) , &xhtab_dentry_item_from_xlist );
     145        hal_remote_spt( XPTR( cxy , &ptr->item_print_key  ) , &xhtab_dentry_item_print_key );
    149146    }
    150147    else
     
    153150    }
    154151
     152    // initialize all lists
     153    for( i=0 ; i < XHASHTAB_SIZE ; i++ )
     154    {
     155        xlist_root_init( XPTR( cxy , &ptr->roots[i] ) );
     156    }
     157 
    155158#if DEBUG_XHTAB
    156159printk("\n[%s] for xhtab (%x,%x)\n"
    157 " - index_from_key  = %x (@ %x)\n"
    158 " - item_match_key  = %x (@ %x)\n"
    159 " - item_from_xlist = %x (@ %x)\n",
    160 __FUNCTION__, local_cxy, xhtab,
    161 xhtab->index_from_key , &xhtab->index_from_key,
    162 xhtab->item_match_key , &xhtab->item_match_key,
    163 xhtab->item_from_xlist, &xhtab->item_from_xlist );
    164 #endif
    165 
    166         for( i=0 ; i < XHASHTAB_SIZE ; i++ )
    167     {
    168                 xlist_root_init( XPTR( local_cxy , &xhtab->roots[i] ) );
    169 
    170 #if (DEBUG_XHTAB & 1)
    171 printk("\n - initialize root[%d] / %x\n", i , &xhtab->roots[i] );
    172 #endif
    173 
    174     } 
     160" - index_from_key  = %x\n"
     161" - item_match_key  = %x\n"
     162" - item_from_xlist = %x\n",
     163__FUNCTION__, cxy, ptr,
     164hal_remote_lpt( XPTR( cxy , &ptr->index_from_key ) ),
     165hal_remote_lpt( XPTR( cxy , &ptr->item_match_key ) ),
     166hal_remote_lpt( XPTR( cxy , &ptr->item_from_xlist ) ) );
     167#endif
    175168
    176169}  // end xhtab_init()
     
    200193    xhtab_ptr = GET_PTR( xhtab_xp );
    201194
     195#if DEBUG_XHTAB
     196printk("\n[%s] enter : index = %d / key = %s\n", __FUNCTION__ , index , key );
     197#endif
     198
    202199    // get pointer on "item_from_xlist" function
    203200    item_from_xlist = (item_from_xlist_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
     
    206203    item_match_key = (item_match_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
    207204                                                         &xhtab_ptr->item_match_key ) );
    208 
    209205    // scan sub-list[index]
    210206    XLIST_FOREACH( XPTR( xhtab_cxy , &xhtab_ptr->roots[index] ) , xlist_xp )
     
    216212        if( item_match_key( item_xp , key ) ) return item_xp;
    217213    }
     214
     215#if DEBUG_XHTAB
     216printk("\n[%s] exit\n", __FUNCTION__ );
     217#endif
     218
    218219
    219220    // No matching item found
     
    248249    index_from_key = (index_from_key_t *)hal_remote_lpt( XPTR( xhtab_cxy ,
    249250                                                         &xhtab_ptr->index_from_key ) );
    250 #if DEBUG_XHTAB
    251 printk("\n[%s] remote = %x / direct = %x / @ = %x\n",
    252 __FUNCTION__, index_from_key, xhtab_ptr->index_from_key, &xhtab_ptr->index_from_key );
    253 #endif
    254 
    255251    // compute index from key
    256252        index = index_from_key( key );
    257 
    258 #if DEBUG_XHTAB
    259 printk("\n[%s] index = %x\n", __FUNCTION__, index );
    260 #endif
    261253
    262254    // take the lock protecting hash table
     
    285277   
    286278#if DEBUG_XHTAB
    287 printk("\n[%s] success / <%s>\n", __FUNCTION__, key );
     279printk("\n[%s] success for <%s>\n", __FUNCTION__, key );
    288280#endif
    289281
     
    362354   
    363355#if DEBUG_XHTAB
    364 printk("\n[%s] enter / %s\n", __FUNCTION__, key );
     356printk("\n[%s] enter\n", __FUNCTION__ );
    365357#endif
    366358
     
    368360    remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    369361   
    370 #if DEBUG_XHTAB
    371 printk("\n[%s] after lock acquire / %s\n", __FUNCTION__, key );
    372 #endif
    373 
    374362    // scan sub-list
    375363    item_xp = xhtab_scan( xhtab_xp , index , key );
    376364
    377 #if DEBUG_XHTAB
    378 printk("\n[%s] after xhtab scan / %s\n", __FUNCTION__, key );
    379 #endif
    380 
    381365    // release the lock protecting hash table
    382366    remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    383367
    384368#if DEBUG_XHTAB
    385 printk("\n[%s] after lock release / %s\n", __FUNCTION__, key );
     369printk("\n[%s] exit\n", __FUNCTION__ );
    386370#endif
    387371
  • trunk/kernel/libk/xhtab.h

    r635 r657  
    105105/******************************************************************************************
    106106 * This function initializes an empty hash table (zero registered item).
    107  * The initialisation must be done by a thread running in cluster containing the table.
    108107 ******************************************************************************************
    109  * @ xhtab    : local pointer on local xhtab to be initialized.
    110  * @ type     : item type (see above).
     108 * @ xhtab_xp  : extended pointer on xhtab.
     109 * @ type      : item type (see above).
    111110 *****************************************************************************************/
    112 void xhtab_init( xhtab_t           * xhtab,
     111void xhtab_init( xptr_t              xhtab_xp,
    113112                 xhtab_item_type_t   type );
    114113
  • trunk/kernel/libk/xlist.h

    r656 r657  
    22 * xlist.h - Trans-cluster double circular linked list, using extended pointers.
    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
     
    5050/***************************************************************************
    5151 * This macro returns the offset (in bytes) of a field in a structure.
     52 ***************************************************************************
    5253 * @ type   : structure type
    5354 * @ member : name of the field
     
    6162 * This macro returns an extended pointer on the structure containing an
    6263 * embedded xlist_entry_t field.
     64 ***************************************************************************
    6365 * @ xlist_xp : extended pointer on the xlist_entry_t field
    6466 * @ type     : type of the structure containing the xlist_entry_t
     
    7476 * the root xlist_entry_t.
    7577 * WARNING : check list non empty before using this macro.
     78 ***************************************************************************
    7679 * @ root_xp : extended pointer on the root xlist_entry_t
    7780 * @ type    : type of the linked elements
     
    8891 * the root xlist_entry_t.
    8992 * WARNING : check list non empty before using this macro.
     93 ***************************************************************************
    9094 * @ root_xp : extended pointer on the root xlist_entry_t
    9195 * @ type    : type of the linked elements
     
    100104 * This macro traverses an extended double linked list in forward order.
    101105 * WARNING : the iter variable should NOT be deleted during traversal.
     106 ***************************************************************************
    102107 * @ root_xp  : extended pointer on the root xlist_entry_t
    103108 * @ iter_xp  : current extended pointer on a xlist_entry_t
     
    112117 * This macro traverses an extended double linked list in backward order.
    113118 * WARNING : the iter variable should NOT be deleted during traversal.
     119 ***************************************************************************
    114120 * @ root_xp  : extended pointer on the root xlist_entry_t
    115121 * @ iter_xp  : current extended pointer on a xlist_entry_t
     
    124130 * This function returns an extended pointer on the next xlist_entry_t,
    125131 * from an extended pointer on a reference xlist_entry_t.
     132 ***************************************************************************
    126133 * @ root    : extended pointer on the root xlist_entry_t
    127134 * @ ref     : extended pointer on the reference xlist_entry_t
     
    144151/***************************************************************************
    145152 * This function returns an extended pointer on the previous xlist_entry_t.
     153 ***************************************************************************
    146154 * @ root    : extended pointer on the root xlist_entry_t
    147155 * @ ref     : extended pointer on the reference xlist_entry_t
     
    165173 * This function initialises the root of an extended double linked list.
    166174 * The root can be located in any cluster.
     175 ***************************************************************************
    167176 * @ root_xp   :  extended pointer on the root xlist_entry_t
    168177xixi **************************************************************************/
     
    176185 * This function initialises an entry of an extended double linked list.
    177186 * The entry can be located in any cluster.
     187 ***************************************************************************
    178188 * @ entry_xp  : extended pointer on the xlist_entry_t
    179189 **************************************************************************/
     
    188198 * double linked list. Four extended pointers must be modified.
    189199 * The lock protecting the list should have been previously taken.
     200 ***************************************************************************
    190201 * @ root_xp   : extended pointer on the root xlist_entry_t
    191202 * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
     
    214225 * double linked list.  Four extended pointers must be modified.
    215226 * The lock protecting the list should have been previously taken.
     227 ***************************************************************************
    216228 * @ root_xp   : extended pointer on the root xlist_entry_t
    217229 * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
     
    239251/***************************************************************************
    240252 * This function returns true if the list is empty.
     253 ***************************************************************************
    241254 * @ root_xp  : extended pointer on the root xlist_entry_t.
    242255 **************************************************************************/
     
    253266 * Two extended pointers must be modified.
    254267 * The memory allocated to the removed entry is not released.
     268 ***************************************************************************
    255269 * @ xp : extended pointer on the xlist_entry_t to be removed.
    256270 **************************************************************************/
     
    277291 * Four extended pointers must be modified.
    278292 * The memory allocated to the removed entry is not released.
     293 ***************************************************************************
    279294 * @ old      : extended pointer on the xlist_entry_t to be removed.
    280295 * @ new      : extended pointer on the xlist_entry_t to be inserted.
     
    307322/***************************************************************************
    308323 * This debug function displays all entries of an xlist.
     324 ***************************************************************************
    309325 * @ root_xp : extended pointer on the root xlist_entry_t.
    310326 * @ string  : list identifier displayed in header.
Note: See TracChangeset for help on using the changeset viewer.