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.

File:
1 edited

Legend:

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