Changeset 610 for trunk/kernel/libk


Ignore:
Timestamp:
Dec 27, 2018, 7:38:58 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in VFS to support the following
ksh commandis : cp, mv, rm, mkdir, cd, pwd

Location:
trunk/kernel/libk
Files:
12 edited

Legend:

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

    r603 r610  
    133133    void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
    134134
    135         printk("\n***** Generic Radix Tree for <%s> : %d / %d / %d\n",
    136     name, 1<<w1 , 1<<w2 , 1<<w3 );
     135        printk("\n***** Generic Radix Tree for <%s>\n", name );
    137136
    138137        for( ix1=0 ; ix1 < (uint32_t)(1<<w1) ; ix1++ )
     
    327326
    328327    // get ptr1
    329     void         ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     328    void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
    330329
    331330    // get ptr2
    332         void         ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     331        void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
    333332        if( ptr2 == NULL ) return XPTR_NULL;
    334333
    335334    // get ptr3
    336         void         ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     335        void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
    337336        if( ptr3 == NULL ) return XPTR_NULL;
    338337
    339     // get value
    340         xptr_t      value = XPTR( rt_cxy , ptr3[ix3] );
    341 
    342         return value;
     338    // get pointer on registered item
     339    void  * item_ptr = hal_remote_lpt( XPTR( rt_cxy , &ptr3[ix3] ) );
     340
     341    // return extended pointer on registered item
     342    if ( item_ptr == NULL )  return XPTR_NULL;
     343        else                     return XPTR( rt_cxy , item_ptr );
    343344
    344345}  // end grdxt_remote_lookup()
  • trunk/kernel/libk/grdxt.h

    r603 r610  
    4040 * - Lookup can be done by a thread running in any cluster (local or remote).
    4141 ******************************************************************************************
    42  * It is used by the mapper implementing the file cache:
     42 * When it is used by the mapper implementing the file cache:
    4343 * - the key is the page index in file.
    4444 * - the registered value is a local pointer on the page descriptor.
  • trunk/kernel/libk/htab.c

    r563 r610  
    3434///////////////////////////////////////////////////////////////////////////////////////////
    3535//    Item type specific (static) functions (two functions for each item type).
    36 // Example below if for <vhs_inode_t>, where the identifier is the inum field.
    37 ///////////////////////////////////////////////////////////////////////////////////////////
    38 
    39 ///////////////////////////////////////////////////////////////////////////////////////////
    40 // These static functions compute the hash index from the key.
     36// Example below if for <bloup_t> type, where the identifier is an uint32_t field.
     37///////////////////////////////////////////////////////////////////////////////////////////
     38
     39typedef struct bloup_s
     40{
     41    uint32_t       key;
     42    list_entry_t   list;
     43}
     44bloup_t;
     45
     46///////////////////////////////////////////////////////////////////////////////////////////
     47// This static function computes the hash index from the key.
    4148///////////////////////////////////////////////////////////////////////////////////////////
    4249// @ key      : local pointer on key.
    4350// @ return the index value, from 0 to (HASHTAB_SIZE - 1)
    4451///////////////////////////////////////////////////////////////////////////////////////////
    45 static uint32_t htab_inode_index( void * key )
    46 {
    47         uint32_t * inum = key;
    48         return (((*inum) >> 16) ^ ((*inum) & 0xFFFF)) % HASHTAB_SIZE;
     52static uint32_t htab_bloup_index( void * key )
     53{
     54        return (*(uint32_t *)key) % HASHTAB_SIZE;
    4955}
    5056
    5157///////////////////////////////////////////////////////////////////////////////////////
    52 // These static functions are used by htab_lookup(), htab_insert(), and htab_remove().
     58// This static function is used by htab_lookup(), htab_insert(), and htab_remove().
    5359// They scan one sub-list identified by  <index> to find an item  identified by <key>.
    5460// The sub-list is not modified, but the lock must have been taken by the caller.
     
    5965// @ return pointer on item if found / return NULL if not found.
    6066///////////////////////////////////////////////////////////////////////////////////////
    61 static void * htab_inode_scan( htab_t  * htab,
     67static void * htab_bloup_scan( htab_t  * htab,
    6268                               uint32_t  index,
    6369                               void    * key )
    6470{
    6571    list_entry_t * list_entry;   // pointer on list_entry_t (iterator)
    66     vfs_inode_t  * inode;        // pointer on item
     72    bloup_t      * bloup;        // pointer on item
    6773   
    6874        LIST_FOREACH( &htab->roots[index] , list_entry )
    6975        {
    70         inode = (vfs_inode_t *)LIST_ELEMENT( list_entry , vfs_inode_t , list );
    71         if( inode->inum == *(uint32_t *)key ) return inode;
     76        bloup = (bloup_t *)LIST_ELEMENT( list_entry , bloup_t , list );
     77        if( bloup->key == *(uint32_t *)key ) return bloup;
    7278    }
    7379
     
    9197    htab->items = 0;
    9298
    93     if( type == HTAB_INODE_TYPE )
    94     {
    95         htab->scan    = &htab_inode_scan;
    96         htab->index   = &htab_inode_index;
     99    if( type == HTAB_BLOUP_TYPE )
     100    {
     101        htab->scan    = &htab_bloup_scan;
     102        htab->index   = &htab_bloup_index;
    97103    }
    98104    else
  • trunk/kernel/libk/htab.h

    r563 r610  
    3131
    3232/////////////////////////////////////////////////////////////////////////////////////////
    33 // This file define a generic, embedded, hash table.
     33// This file define a generic, embedded, local hash table.
    3434//
    3535// It can only be accessed by threads running in the local cluster.
     
    7070typedef enum
    7171{
    72     HTAB_INODE_TYPE = 1,                     /*! item is a vfs_inode_t                 */
     72    HTAB_BLOUP_TYPE = 1,                     /*! item is a bloup_t                     */
    7373}
    7474htab_item_type_t;
  • trunk/kernel/libk/list.h

    r457 r610  
    33 *
    44 * Authors Ghassan Almaless  (2008,2009,2010,2011,2012)
    5  *         Alain Greiner     (2016)
     5 *         Alain Greiner     (2016,2017,2018)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    2323 */
    2424
    25 #ifndef _ALMOS_LIST_H_
    26 #define _ALMOS_LIST_H_
     25#ifndef _LIST_H_
     26#define _LIST_H_
    2727
    2828#include <kernel_config.h>
    2929#include <hal_kernel_types.h>
     30#include <printk.h>
    3031
    3132#ifndef NULL
     
    240241}
    241242
    242 
    243 #endif  /* _ALMOS_LIST_H_ */
     243/***************************************************************************
     244 * This debug function displays all entries of a list.
     245 * @ root    : local pointer on the root list_entry_t.
     246 * @ string  : list identifier displayed in header.
     247 * @ max     : max number of éléments to display.
     248 **************************************************************************/
     249static inline void list_display( list_entry_t * root,
     250                                 char         * string,
     251                                 uint32_t       max )
     252{
     253    list_entry_t * iter;
     254    list_entry_t * next;
     255    list_entry_t * pred;
     256    uint32_t       index;
     257
     258    next = root->next;
     259    pred = root->pred;
     260
     261    printk("\n***** root (%x) / next (%x) / pred (%x) / %s *****\n",
     262    root, next, pred, string );
     263
     264    if( list_is_empty( root ) == false )
     265    {
     266        for( iter = next , index = 0 ;
     267             (iter != root) && (index < max) ;
     268             iter = next , index++ )
     269        {
     270            next = iter->next;
     271                        pred = iter->pred;
     272
     273            printk(" - %d : iter (%x) / next (%x) / pred (%x)\n",
     274            index, iter, next, pred );
     275        }
     276    }
     277}  // end list_display()
     278
     279
     280#endif  /* _LIST_H_ */
  • trunk/kernel/libk/queuelock.c

    r603 r610  
    4545    busylock_init( &lock->lock , type );
    4646
    47 #if DEBUG_QUEUELOCK
     47#if DEBUG_QUEUELOCK_TYPE
    4848thread_t * this = CURRENT_THREAD;
    49 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     49if( DEBUG_QUEUELOCK_TYPE == type )
    5050printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
    5151__FUNCTION__, this->process->pid, this->trdid,
     
    7070    {
    7171
    72 #if DEBUG_QUEUELOCK
    73 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     72#if DEBUG_QUEUELOCK_TYPE
     73uint32_t   lock_type = lock->lock.type;
     74if( DEBUG_QUEUELOCK_TYPE == lock_type )
    7475printk("\n[%s ] thread[%x,%x] BLOCK on q_lock %s [%x,%x]\n",
    7576__FUNCTION__, this->process->pid, this->trdid,
    76 lock_type_str[lock->lock.type], local_cxy, lock );
     77lock_type_str[lock_type], local_cxy, lock );
    7778#endif
    7879        // get pointer on calling thread
     
    9596    }
    9697
    97 #if DEBUG_QUEUELOCK
    98 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     98#if DEBUG_QUEUELOCK_TYPE
     99if( DEBUG_QUEUELOCK_TYPE == lock_type )
    99100printk("\n[%s] thread[%x,%x] ACQUIRE q_lock %s [%x,%x]\n",
    100101__FUNCTION__, this->process->pid, this->trdid,
    101 lock_type_str[lock->lock.type], local_cxy, lock );
     102lock_type_str[lock_type], local_cxy, lock );
    102103#endif
    103104
     
    119120    busylock_acquire( &lock->lock );
    120121
    121 #if DEBUG_QUEUELOCK
    122 thread_t * this = CURRENT_THREAD;
    123 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     122#if DEBUG_QUEUELOCK_TYPE
     123uint32_t   lock_type = lock->lock.type;
     124thread_t * this      = CURRENT_THREAD;
     125if( DEBUG_QUEUELOCK_TYPE == lock_type )
    124126printk("\n[%s] thread[%x,%x] RELEASE q_lock %s [%x,%x]\n",
    125127__FUNCTION__, this->process->pid, this->trdid,
    126 lock_type_str[lock->lock.type], local_cxy, lock );
     128lock_type_str[lock_type], local_cxy, lock );
    127129#endif
    128130
     
    136138        thread_t * thread = LIST_FIRST( &lock->root , thread_t , wait_list );
    137139
    138 #if DEBUG_QUEUELOCK
    139 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     140#if DEBUG_QUEUELOCK_TYPE
     141if( DEBUG_QUEUELOCK_TYPE == lock_type )
    140142printk("\n[%s] thread[%x,%x] UNBLOCK thread [%x,%x] / q_lock %s [%x,%x]\n",
    141143__FUNCTION__, this->process->pid, this->trdid, thread->process->pid, thread->trdid,
    142 lock_type_str[lock->lock.type], local_cxy, lock );
     144lock_type_str[lock_type], local_cxy, lock );
    143145#endif
    144146        // remove this waiting thread from waiting list
  • trunk/kernel/libk/remote_queuelock.c

    r603 r610  
    5454    remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type );
    5555
    56 #if DEBUG_QUEUELOCK
     56#if DEBUG_QUEUELOCK_TYPE
    5757thread_t * this = CURRENT_THREAD;
    58 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     58if( DEBUG_QUEUELOCK_TYPE == type )
    5959printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
    6060__FUNCTION__, this->process->pid, this->trdid,
     
    7676    remote_queuelock_t * lock_ptr = GET_PTR( lock_xp );
    7777
    78 #if DEBUG_QUEUELOCK
     78#if DEBUG_QUEUELOCK_TYPE
    7979uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    8080#endif
     
    9090    {
    9191
    92 #if DEBUG_QUEUELOCK
    93 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     92#if DEBUG_QUEUELOCK_TYPE
     93if( DEBUG_QUEUELOCK_TYPE == lock_type )
    9494printk("\n[%s] thread[%x,%x] BLOCK on q_lock %s [%x,%x]\n",
    9595__FUNCTION__, this->process->pid, this->trdid,
     
    116116    }
    117117
    118 #if DEBUG_QUEUELOCK
    119 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     118#if DEBUG_QUEUELOCK_TYPE
     119if( DEBUG_QUEUELOCK_TYPE == lock_type )
    120120printk("\n[%s] thread[%x,%x] ACQUIRE q_lock %s [%x,%x]\n",
    121121__FUNCTION__, this->process->pid, this->trdid,
     
    128128    // release busylock
    129129    remote_busylock_release( busylock_xp );
     130
     131    hal_fence();
    130132
    131133}  // end remote_queuelock_acquire()
     
    147149    remote_busylock_acquire( busylock_xp );
    148150
    149 #if DEBUG_QUEUELOCK
     151#if DEBUG_QUEUELOCK_TYPE
    150152thread_t * this      = CURRENT_THREAD;
    151153uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    152 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     154if( DEBUG_QUEUELOCK_TYPE == lock_type )
    153155printk("\n[%s] thread[%x,%x] RELEASE q_lock %s (%x,%x)\n",
    154156__FUNCTION__, this->process->pid, this->trdid,
     
    168170        thread_t * thread_ptr = GET_PTR( thread_xp );
    169171
    170 #if DEBUG_QUEUELOCK
    171 if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     172#if DEBUG_QUEUELOCK_TYPE
     173if( DEBUG_QUEUELOCK_TYPE == lock_type )
    172174{
    173175    trdid_t     trdid   = hal_remote_l32( XPTR( thread_cxy , &thread_ptr->trdid ) );
  • trunk/kernel/libk/remote_rwlock.c

    r603 r610  
    5353    remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type );
    5454
    55 #if DEBUG_RWLOCK
     55#if DEBUG_RWLOCK_TYPE
    5656thread_t * this = CURRENT_THREAD;
    57 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     57if( type == DEBUG_RWLOCK_TYPE )
    5858printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
    5959__FUNCTION__, this->process->pid, this->trdid,
     
    7575    cxy_t             lock_cxy = GET_CXY( lock_xp );
    7676
    77 #if DEBUG_RWLOCK
     77#if DEBUG_RWLOCK_TYPE
    7878uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    7979#endif
     
    9292    {
    9393
    94 #if DEBUG_RWLOCK
    95 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     94#if DEBUG_RWLOCK_TYPE
     95if( lock_type == DEBUG_RWLOCK_TYPE )
    9696printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
    9797__FUNCTION__, this->process->pid, this->trdid,
     
    123123    hal_fence();
    124124
    125 #if DEBUG_RWLOCK
    126 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     125#if DEBUG_RWLOCK_TYPE
     126if( lock_type == DEBUG_RWLOCK_TYPE )
    127127printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken = %d / count = %d\n",
    128128__FUNCTION__, this->process->pid, this->trdid,
     
    148148    cxy_t             lock_cxy = GET_CXY( lock_xp );
    149149
    150 #if DEBUG_RWLOCK
     150#if DEBUG_RWLOCK_TYPE
    151151uint32_t lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    152152#endif
     
    165165    {
    166166
    167 #if DEBUG_RWLOCK
    168 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     167#if DEBUG_RWLOCK_TYPE
     168if( lock_type == DEBUG_RWLOCK_TYPE )
    169169printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
    170170__FUNCTION__, this->process->pid, this->trdid,
     
    195195    hal_remote_s32( taken_xp , 1 );
    196196
    197 #if DEBUG_RWLOCK
    198 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     197#if DEBUG_RWLOCK_TYPE
     198if( lock_type == DEBUG_RWLOCK_TYPE )
    199199printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
    200200__FUNCTION__, this->process->pid, this->trdid,
     
    231231    hal_remote_atomic_add( count_xp , -1 );
    232232
    233 #if DEBUG_RWLOCK
     233#if DEBUG_RWLOCK_TYPE
    234234thread_t * this      = CURRENT_THREAD;
    235235uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    236236xptr_t     taken_xp  = XPTR( lock_cxy , &lock_ptr->taken );
    237 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     237if( lock_type == DEBUG_RWLOCK_TYPE )
    238238printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
    239239__FUNCTION__, this->process->pid, this->trdid,
     
    257257        thread_unblock( thread_xp , THREAD_BLOCKED_LOCK );
    258258
    259 #if DEBUG_RWLOCK
    260 if( (uint32_t)hal_get_cycles() > DEBUG_RWLOCK )
     259#if DEBUG_RWLOCK_TYPE
     260if( lock_type == DEBUG_RWLOCK_TYPE )
    261261{
    262262    trdid_t     trdid     = hal_remote_l32( XPTR( thread_cxy , &thread_ptr->trdid ) );
     
    288288            thread_unblock( thread_xp , THREAD_BLOCKED_LOCK );
    289289
    290 #if DEBUG_RWLOCK
    291 if( (uint32_t)hal_get_cycles() > DEBUG_RWLOCK )
     290#if DEBUG_RWLOCK_TYPE
     291if( lock_type == DEBUG_RWLOCK_TYPE )
    292292{
    293293    trdid_t     trdid     = hal_remote_l32( XPTR( thread_cxy , &thread_ptr->trdid ) );
     
    330330    hal_remote_s32( taken_xp , 0 );
    331331
    332 #if DEBUG_RWLOCK
     332#if DEBUG_RWLOCK_TYPE
    333333thread_t * this      = CURRENT_THREAD;
    334334uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    335335xptr_t     count_xp  = XPTR( lock_cxy , &lock_ptr->count );
    336 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     336if( lock_type == DEBUG_RWLOCK_TYPE )
    337337printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
    338338__FUNCTION__, this->process->pid, this->trdid,
     
    355355        thread_unblock( thread_xp , THREAD_BLOCKED_LOCK );
    356356
    357 #if DEBUG_RWLOCK
    358 if( (uint32_t)hal_get_cycles() > DEBUG_RWLOCK )
     357#if DEBUG_RWLOCK_TYPE
     358if( lock_type == DEBUG_RWLOCK_TYPE )
    359359{
    360360    trdid_t     trdid     = hal_remote_l32( XPTR( thread_cxy , &thread_ptr->trdid ) );
     
    385385            thread_unblock( thread_xp , THREAD_BLOCKED_LOCK );
    386386
    387 #if DEBUG_RWLOCK
    388 if( (uint32_t)hal_get_cycles() > DEBUG_RWLOCK )
     387#if DEBUG_RWLOCK_TYPE
     388if( lock_type == DEBUG_RWLOCK_TYPE )
    389389{
    390390    trdid_t     trdid     = hal_remote_l32( XPTR( thread_cxy , &thread_ptr->trdid ) );
  • trunk/kernel/libk/rwlock.c

    r603 r610  
    5050    busylock_init( &lock->lock , type );
    5151
    52 #if DEBUG_RWLOCK
     52#if DEBUG_RWLOCK_TYPE
    5353thread_t * this = CURRENT_THREAD;
    54 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     54if( DEBUG_RWLOCK_TYPE == type )
    5555printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
    5656__FUNCTION__, this->process->pid, this->trdid,
     
    7575    {
    7676
    77 #if DEBUG_RWLOCK
    78 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     77#if DEBUG_RWLOCK_TYPE
     78uint32_t lock_type = lock->lock.type;
     79if( DEBUG_RWLOCK_TYPE == lock_type )
    7980printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
    8081__FUNCTION__, this->process->pid, this->trdid,
    81 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     82lock_type_str[lock_type], local_cxy, lock, lock->taken, lock->count );
    8283#endif
    8384        // register reader thread in waiting queue
     
    100101    lock->count++;
    101102
    102 #if DEBUG_RWLOCK
    103 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     103#if DEBUG_RWLOCK_TYPE
     104if( DEBUG_RWLOCK_TYPE == lock_type )
    104105printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
    105106__FUNCTION__, this->process->pid, this->trdid,
    106 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     107lock_type_str[lock_type], local_cxy, lock, lock->taken, lock->count );
    107108#endif
    108109
     
    127128    {
    128129
    129 #if DEBUG_RWLOCK
    130 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     130#if DEBUG_RWLOCK_TYPE
     131uint32_t lock_type = lock->lock.type;
     132if( DEBUG_RWLOCK_TYPE == lock_type )
    131133printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
    132134__FUNCTION__, this->process->pid, this->trdid,
    133 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     135lock_type_str[lock_type], local_cxy, lock, lock->taken, lock->count );
    134136#endif
    135137        // register writer in waiting queue
     
    152154    lock->taken = 1;
    153155
    154 #if DEBUG_RWLOCK
    155 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     156#if DEBUG_RWLOCK_TYPE
     157if( DEBUG_RWLOCK_TYPE == lock_type )
    156158printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
    157159__FUNCTION__, this->process->pid, this->trdid,
    158 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     160lock_type_str[lock_type], local_cxy, lock, lock->taken, lock->count );
    159161#endif
    160162
     
    176178    lock->count--;
    177179
    178 #if DEBUG_RWLOCK
     180#if DEBUG_RWLOCK_TYPE
    179181thread_t * this = CURRENT_THREAD;
    180 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     182uint32_t lock_type = lock->lock.type;
     183if( DEBUG_RWLOCK_TYPE == lock_type )
    181184printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
    182185__FUNCTION__, this->process->pid, this->trdid,
    183 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     186lock_type_str[lock_type], local_cxy, lock, lock->taken, lock->count );
    184187#endif
    185188
     
    191194        thread_t * thread = LIST_FIRST( &lock->wr_root , thread_t , wait_list );
    192195
    193 #if DEBUG_RWLOCK
    194 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     196#if DEBUG_RWLOCK_TYPE
     197if( DEBUG_RWLOCK_TYPE == lock_type )
    195198printk("\n[%s] thread[%x,%x] UNBLOCK thread[%x,%x] / rwlock %s [%x,%x]\n",
    196199__FUNCTION__, this->process->pid, this->trdid, thread->process->pid, thread->trdid,
    197 lock_type_str[lock->lock.type], local_cxy, lock );
     200lock_type_str[lock_type], local_cxy, lock );
    198201#endif
    199202
     
    213216            thread_t * thread = LIST_FIRST( &lock->wr_root , thread_t , wait_list );
    214217
    215 #if DEBUG_RWLOCK
    216 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     218#if DEBUG_RWLOCK_TYPE
     219if( DEBUG_RWLOCK_TYPE == lock_type )
    217220printk("\n[%s] thread[%x,%x] UNBLOCK thread[%x,%x] / rwlock %s [%x,%x]\n",
    218221__FUNCTION__, this->process->pid, this->trdid, thread->process->pid, thread->trdid,
    219 lock_type_str[lock->lock.type], local_cxy, lock );
     222lock_type_str[lock_type], local_cxy, lock );
    220223#endif
    221224   
     
    245248    lock->taken = 0;
    246249
    247 #if DEBUG_RWLOCK
     250#if DEBUG_RWLOCK_TYPE
    248251thread_t * this = CURRENT_THREAD;
    249 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     252uint32_t lock_type = lock->lock.type;
     253if( DEBUG_RWLOCK_TYPE == lock_type )
    250254printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
    251255__FUNCTION__, this->process->pid, this->trdid,
    252 lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     256lock_type_str[lock_type], local_cxy, lock, lock->taken, lock->count );
    253257#endif
    254258
     
    259263        thread_t * thread = LIST_FIRST( &lock->wr_root , thread_t , wait_list );
    260264
    261 #if DEBUG_RWLOCK
    262 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     265#if DEBUG_RWLOCK_TYPE
     266if( DEBUG_RWLOCK_TYPE == lock_type )
    263267printk("\n[%s] thread[%x,%x] UNBLOCK thread[%x,%x] / rwlock %s [%x,%x]\n",
    264268__FUNCTION__, this->process->pid, this->trdid, thread->process->pid, thread->trdid,
    265 lock_type_str[lock->lock.type], local_cxy, lock );
     269lock_type_str[lock_type], local_cxy, lock );
    266270#endif
    267271        // remove this waiting thread from waiting list
     
    280284            thread_t * thread = LIST_FIRST( &lock->rd_root , thread_t , wait_list );
    281285
    282 #if DEBUG_RWLOCK
    283 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     286#if DEBUG_RWLOCK_TYPE
     287if( DEBUG_RWLOCK_TYPE == lock_type )
    284288printk("\n[%s] thread[%x,%x] UNBLOCK thread[%x,%x] / rwlock %s [%x,%x]\n",
    285289__FUNCTION__, this->process->pid, this->trdid, thread->process->pid, thread->trdid,
    286 lock_type_str[lock->lock.type], local_cxy, lock );
     290lock_type_str[lock_type], local_cxy, lock );
    287291#endif
    288292            // remove this waiting thread from waiting list
  • trunk/kernel/libk/xhtab.c

    r603 r610  
    4040
    4141///////////////////////////////////////////////////////////////////////////////////////////
    42 // vfs_dentry_t
     42// XHTAB_DENTRY_TYPE
    4343// This functions compute the hash index from the key, that is the directory entry name.
    4444///////////////////////////////////////////////////////////////////////////////////////////
     
    5858
    5959///////////////////////////////////////////////////////////////////////////////////////////
    60 // vfs_dentry_t
     60// XHTAB_DENTRY_TYPE
    6161// This functions returns the extended pointer on the item, from the extended pointer
    6262// on xlist contained in the item.
     
    6767static xptr_t xhtab_dentry_item_from_xlist( xptr_t xlist_xp )
    6868{
    69     return XLIST_ELEMENT( xlist_xp , vfs_dentry_t , list );
     69    return XLIST_ELEMENT( xlist_xp , vfs_dentry_t , children );
    7070}
    7171
    7272////////////////////////////////////////////////////////////////////////////////////////////
    73 // vfs_dentry_t
     73// XHTAB_DENTRY_TYPE
    7474// This function compares the identifier of an item to a given <key>.
    7575// it returns true when the directory name matches the name pointed by the <key> argument.
     
    9696
    9797////////////////////////////////////////////////////////////////////////////////////////////
    98 // vfs_dentry_t
     98// XHTAB_DENTRY_TYPE
    9999// This function print the item key, that is the name for a vfs_dentry_t.
    100100////////////////////////////////////////////////////////////////////////////////////////////
     
    150150                xlist_root_init( XPTR( local_cxy , &xhtab->roots[i] ) );
    151151    } 
     152
     153#if DEBUG_XHTAB
     154printk("\n@@@ %s for xhtab (%x,%x)\n"
     155" - index_from_key  = %x (@ %x)\n"
     156" - item_match_key  = %x (@ %x)\n"
     157" - item_from_xlist = %x (@ %x)\n",
     158__FUNCTION__, local_cxy, xhtab,
     159xhtab->index_from_key , &xhtab->index_from_key,
     160xhtab->item_match_key , &xhtab->item_match_key,
     161xhtab->item_from_xlist, &xhtab->item_from_xlist );
     162#endif
    152163
    153164}  // end xhtab_init()
  • trunk/kernel/libk/xhtab.h

    r603 r610  
    7373/******************************************************************************************
    7474 * This define the supported item types.
     75 * - The XHTAB_DENTRY_TYPE is used to implement the set of directory entries for a
     76 *   directory inode : the "children" inode field is an embedded xhtab.
    7577 *****************************************************************************************/
    7678
  • trunk/kernel/libk/xlist.h

    r603 r610  
    55 * xlist.h - Double Circular Linked lists, using extended pointers.
    66 *
    7  * Author : Alain Greiner (2016)
     7 * Author : Alain Greiner (2016,2017,2018)
    88 *
    99 * Copyright (c) UPMC Sorbonne Universites
     
    3131#include <hal_kernel_types.h>
    3232#include <hal_remote.h>
     33#include <printk.h>
    3334
    3435/**** global variables ***/
     
    190191 * double linked list. Four extended pointers must be modified.
    191192 * The lock protecting the list should have been previously taken.
    192  * @ root   : extended pointer on the root xlist_entry_t
    193  * @ entry  : extended pointer on the xlist_entry_t to be inserted
    194  **************************************************************************/
    195 static inline void xlist_add_first( xptr_t root,
    196                                     xptr_t entry )
     193 * @ root_xp   : extended pointer on the root xlist_entry_t
     194 * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
     195 **************************************************************************/
     196static inline void xlist_add_first( xptr_t root_xp,
     197                                    xptr_t entry_xp )
    197198{
    198199    // get the extended pointer on the first element in list
    199     xptr_t first = (xptr_t)hal_remote_l64( root );
    200 
    201     // update root.next <= entry
    202     hal_remote_s64( root , (uint64_t)entry );
    203 
    204     // update entry.next <= first
    205     hal_remote_s64( entry , (uint64_t)first );
    206 
    207     // entry.pred <= root
    208     hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)root );
     200    xptr_t first_xp = hal_remote_l64( root_xp );
     201
     202    // update root_xp->next <= entry_xp
     203    hal_remote_s64( root_xp , entry_xp );
     204
     205    // update entry_xp->next <= first_xp
     206    hal_remote_s64( entry_xp , first_xp );
     207
     208    // update entry_xp->pred <= root_xp
     209    hal_remote_s64( entry_xp + sizeof(xptr_t) , root_xp );
    209210   
    210     // first.pred <= new
    211     hal_remote_s64( first + sizeof(xptr_t) , (uint64_t)entry );
     211    // update first_xp->pred <= entry_xp
     212    hal_remote_s64( first_xp + sizeof(xptr_t) , entry_xp );
    212213}
    213214
     
    216217 * double linked list.  Four extended pointers must be modified.
    217218 * The lock protecting the list should have been previously taken.
    218  * @ root   : extended pointer on the root xlist_entry_t
    219  * @ entry  : extended pointer on the xlist_entry_t to be inserted
    220  **************************************************************************/
    221 static inline void xlist_add_last( xptr_t root,
    222                                    xptr_t entry )
     219 * @ root_xp   : extended pointer on the root xlist_entry_t
     220 * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
     221 **************************************************************************/
     222static inline void xlist_add_last( xptr_t root_xp,
     223                                   xptr_t entry_xp )
    223224{
    224225    // get the extended pointer on the last element in list
    225     xptr_t last = (xptr_t)hal_remote_l64( root + sizeof(xptr_t) );
    226 
    227     // update root.pred <= entry
    228     hal_remote_s64( root + sizeof(xptr_t) , (uint64_t)entry );
    229 
    230     // update entry.pred <= last
    231     hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)last );
    232 
    233     // entry.next <= root
    234     hal_remote_s64( entry , (uint64_t)root );
     226    xptr_t last_xp = hal_remote_l64( root_xp + sizeof(xptr_t) );
     227
     228    // update root_xp->pred <= entry_xp
     229    hal_remote_s64( root_xp + sizeof(xptr_t) , entry_xp );
     230
     231    // update entry_xp->pred <= last_xp
     232    hal_remote_s64( entry_xp + sizeof(xptr_t) , last_xp );
     233
     234    // update entry_xp->next <= root_xp
     235    hal_remote_s64( entry_xp , root_xp );
    235236   
    236     // last.next <= entry
    237     hal_remote_s64( last , (uint64_t)entry );
     237    // update last_xp->next <= entry_xp
     238    hal_remote_s64( last_xp , entry_xp );
    238239}
    239240
     
    241242/***************************************************************************
    242243 * This function returns true if the list is empty.
    243  * @ root  : extended pointer on the root xlist_entry_t
    244  **************************************************************************/
    245 static inline bool_t xlist_is_empty( xptr_t root )
     244 * @ root_xp  : extended pointer on the root xlist_entry_t.
     245 **************************************************************************/
     246static inline bool_t xlist_is_empty( xptr_t root_xp )
    246247{
    247248    // get the extended pointer root.next value
    248     xptr_t next = (xptr_t)hal_remote_l64( root );
    249 
    250     return ( root == next );
     249    xptr_t next = (xptr_t)hal_remote_l64( root_xp );
     250
     251    return ( root_xp == next );
    251252}
    252253
     
    279280 * Four extended pointers must be modified.
    280281 * The memory allocated to the removed entry is not released.
    281  * @old      : extended pointer on the xlist_entry_t to be removed.
    282  * @new      : extended pointer on the xlist_entry_t to be inserted.
     282 * @ old      : extended pointer on the xlist_entry_t to be removed.
     283 * @ new      : extended pointer on the xlist_entry_t to be inserted.
    283284 **************************************************************************/
    284285static inline void xlist_replace( xptr_t old,
     
    307308}
    308309
     310/***************************************************************************
     311 * This debug function displays all entries of an xlist.
     312 * @ root_xp : extended pointer on the root xlist_entry_t.
     313 * @ string  : list identifier displayed in header.
     314 * @ max     : max number of éléments to display.
     315 **************************************************************************/
     316static inline void xlist_display( xptr_t  root_xp,
     317                                  char  * string,
     318                                  uint32_t max )
     319{
     320    cxy_t           root_cxy;
     321    xlist_entry_t * root_ptr;
     322
     323    xptr_t          iter_xp;
     324    cxy_t           iter_cxy;
     325    xlist_entry_t * iter_ptr;
     326
     327    xptr_t          next_xp;
     328    cxy_t           next_cxy;
     329    xlist_entry_t * next_ptr;
     330
     331    xptr_t          pred_xp;
     332    cxy_t           pred_cxy;
     333    xlist_entry_t * pred_ptr;
     334
     335    uint32_t        index;
     336
     337    root_cxy = GET_CXY( root_xp );
     338    root_ptr = GET_PTR( root_xp );
     339
     340    next_xp  = hal_remote_l64( XPTR( root_cxy , &root_ptr->next ) );
     341    next_cxy = GET_CXY( next_xp );
     342    next_ptr = GET_PTR( next_xp );
     343
     344    pred_xp  = hal_remote_l64( XPTR( root_cxy , &root_ptr->pred ) );
     345    pred_cxy = GET_CXY( pred_xp );
     346    pred_ptr = GET_PTR( pred_xp );
     347
     348    printk("\n***** root (%x,%x) / next (%x,%x) / pred (%x,%x) / %s *****\n",
     349    root_cxy, root_ptr, next_cxy, next_ptr, pred_cxy, pred_ptr, string );
     350
     351    if( xlist_is_empty( root_xp ) == false )
     352    {
     353        for( iter_xp = hal_remote_l64( XPTR( root_cxy , &root_ptr->next) ) , index = 0 ;
     354             (iter_xp != root_xp) && (index < max) ;
     355             iter_xp = next_xp , index++ )
     356        {
     357            iter_cxy = GET_CXY( iter_xp );
     358            iter_ptr = GET_PTR( iter_xp );
     359
     360            next_xp  = hal_remote_l64( XPTR( iter_cxy , &iter_ptr->next ) );
     361            next_cxy = GET_CXY( next_xp );
     362            next_ptr = GET_PTR( next_xp );
     363
     364            pred_xp  = hal_remote_l64( XPTR( iter_cxy , &iter_ptr->pred ) );
     365            pred_cxy = GET_CXY( pred_xp );
     366            pred_ptr = GET_PTR( pred_xp );
     367
     368            printk(" - %d : iter (%x,%x) / next (%x,%x) / pred (%x,%x)\n",
     369            index, iter_cxy, iter_ptr, next_cxy, next_ptr, pred_cxy, pred_ptr );
     370        }
     371    }
     372}  // end xlist_display()
     373
    309374#endif  /* _XLIST_H_ */
Note: See TracChangeset for help on using the changeset viewer.