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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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/////////////////
Note: See TracChangeset for help on using the changeset viewer.