Changeset 603 for trunk/kernel/libk


Ignore:
Timestamp:
Dec 3, 2018, 12:17:35 PM (5 years ago)
Author:
alain
Message:

Improve the FAT32 file system to support cat, rm, cp commands.

Location:
trunk/kernel/libk
Files:
11 edited

Legend:

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

    r457 r603  
    198198uint32_t cycle = (uint32_t)hal_get_cycles();
    199199if( DEBUG_ELF_LOAD < cycle )
    200 printk("\n[DBG] %s : found %s vseg / base %x / size %x\n"
     200printk("\n[%s] found %s vseg / base %x / size %x\n"
    201201"  file_size %x / file_offset %x / mapper_xp %l / cycle %d\n",
    202202__FUNCTION__ , vseg_type_str(vseg->type) , vseg->min , vseg->max - vseg->min ,
     
    228228   
    229229#if DEBUG_ELF_LOAD
    230 uint32_t      cycle = (uint32_t)hal_get_cycles();
    231 if( DEBUG_ELF_LOAD < cycle )
    232 printk("\n[DBG] %s : thread %d in process %x enter for <%s> / cycle %d\n",
    233 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, cycle );
     230uint32_t   cycle = (uint32_t)hal_get_cycles();
     231thread_t * this  = CURRENT_THREAD;
     232if( DEBUG_ELF_LOAD < cycle )
     233printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     234__FUNCTION__, this->process->pid, this->trdid, name, cycle );
    234235#endif
    235236
     
    246247#if (DEBUG_ELF_LOAD & 1)
    247248if( DEBUG_ELF_LOAD < cycle )
    248 printk("\n[DBG] %s : loaded elf header for <%s>\n", __FUNCTION__ , name );
     249printk("\n[%s] loaded elf header for <%s>\n", __FUNCTION__ , name );
    249250#endif
    250251
     
    283284#if (DEBUG_ELF_LOAD & 1)
    284285if( DEBUG_ELF_LOAD < cycle )
    285 printk("\n[DBG] %s : segments array allocated for <%s>\n", __FUNCTION__ , name );
     286printk("\n[%s] segments array allocated for <%s>\n", __FUNCTION__ , name );
    286287#endif
    287288
     
    302303#if (DEBUG_ELF_LOAD & 1)
    303304if( DEBUG_ELF_LOAD < cycle )
    304 printk("\n[DBG] %s loaded segments descriptors for <%s>\n", __FUNCTION__ , name );
     305printk("\n[%s] loaded segments descriptors for <%s>\n", __FUNCTION__ , name );
    305306#endif
    306307
     
    330331cycle = (uint32_t)hal_get_cycles();
    331332if( DEBUG_ELF_LOAD < cycle )
    332 printk("\n[DBG] %s : thread %x in process %x exit for <%s> / entry_point %x / cycle %d\n",
    333 __FUNCTION__, CURRENT_THREAD->trdid, process->pid, name, header.e_entry, cycle );
     333printk("\n[%s] thread[%x,%x] exit for <%s> / entry_point %x / cycle %d\n",
     334__FUNCTION__, this->process->pid, this->trdid, name, header.e_entry, cycle );
    334335#endif
    335336
  • trunk/kernel/libk/grdxt.c

    r492 r603  
    2424#include <hal_kernel_types.h>
    2525#include <hal_special.h>
     26#include <hal_remote.h>
    2627#include <errno.h>
    2728#include <printk.h>
    28 #include <vseg.h>
    2929#include <kmem.h>
    3030#include <grdxt.h>
     
    5353
    5454        return 0;
    55 }
     55
     56}  // end grdxt_init()
    5657
    5758//////////////////////////////////
     
    7071        uint32_t   ix1;
    7172        uint32_t   ix2;
     73
     74// check rt
     75assert( (rt != NULL) , "pointer on radix tree is NULL\n" );
    7276
    7377        req.type = KMEM_GENERIC;
     
    107111}  // end grdxt_destroy()
    108112
    109 ///////////////////////////////
    110 void grdxt_print( grdxt_t * rt,
    111                   char    * name )
    112 {
    113         uint32_t        ix1; 
    114         uint32_t        ix2;
    115         uint32_t        ix3;
    116 
    117     uint32_t        w1 = rt->ix1_width;
    118     uint32_t        w2 = rt->ix2_width;
    119     uint32_t        w3 = rt->ix3_width;
    120 
    121     void         ** ptr1 = rt->root;
    122     void         ** ptr2;
    123     void         ** ptr3;
    124 
    125     intptr_t        key;
    126     intptr_t        value;
    127 
    128         printk("\n***** Generic Radix tree %s : n1 = %d / n2 = %d / n3 = %d\n\n",
    129            name, 1<<w1 , 1<<w2 , 1<<w3 );
     113////////////////////////////////////
     114void grdxt_display( xptr_t    rt_xp,
     115                    char    * name )
     116{
     117        uint32_t       ix1; 
     118        uint32_t       ix2;
     119        uint32_t       ix3;
     120
     121// check rt_xp
     122assert( (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" );
     123
     124    // get cluster and local pointer on remote rt descriptor
     125    grdxt_t      * rt_ptr = GET_PTR( rt_xp );
     126    cxy_t          rt_cxy = GET_CXY( rt_xp );
     127
     128    // get widths
     129    uint32_t       w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     130    uint32_t       w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) );
     131    uint32_t       w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
     132
     133    void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     134
     135        printk("\n***** Generic Radix Tree for <%s> : %d / %d / %d\n",
     136    name, 1<<w1 , 1<<w2 , 1<<w3 );
    130137
    131138        for( ix1=0 ; ix1 < (uint32_t)(1<<w1) ; ix1++ )
    132139        {
    133         ptr2 = ptr1[ix1];
     140            void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
    134141        if( ptr2 == NULL )  continue;
    135142   
    136143        for( ix2=0 ; ix2 < (uint32_t)(1<<w2) ; ix2++ )
    137144        {
    138             ptr3 = ptr2[ix2];
     145                void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
    139146            if( ptr3 == NULL ) continue;
    140147
    141148            for( ix3=0 ; ix3 < (uint32_t)(1<<w3) ; ix3++ )
    142149            {
    143                 value = (intptr_t)ptr3[ix3];
    144                 if( value == 0 )  continue;
    145 
    146                 key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3;
    147                 printk(" - key = %x / value = %x\n", key , value );
     150                void * value = hal_remote_lpt( XPTR( rt_cxy , &ptr3[ix3] ) );
     151                if( value == NULL )  continue;
     152
     153                uint32_t key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3;
     154                printk(" - key = %x / value = %x\n", key , (intptr_t)value );
    148155            }
    149156        }
    150157        }
    151 } // end grdxt_print()
     158
     159} // end grdxt_display()
    152160
    153161////////////////////////////////////
     
    162170    uint32_t        w3 = rt->ix3_width;
    163171
    164     // Check key
    165     if( (key >> (w1 + w2 + w3)) != 0 )
    166     {
    167         assert( false ,
    168         "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 );
    169     }
     172// Check key value
     173assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    170174
    171175    // compute indexes
     
    179183
    180184    // If required, we must allocate memory for the selected level 2 array,
    181     // and atomically update the level 1 array.
     185    // and update the level 1 array.
    182186        if( ptr1[ix1] == NULL )
    183187        {
     
    198202
    199203    // If required, we must allocate memory for the selected level 3 array,
    200     // and atomically update the level 2 array.
     204    // and update the level 2 array.
    201205        if( ptr2[ix2] == NULL )
    202206        {
     
    224228
    225229        return 0;
    226 }
     230
     231}  // end grdxt_insert()
    227232
    228233///////////////////////////////////
     
    234239    uint32_t        w3 = rt->ix3_width;
    235240
    236     // Check key
    237     if( (key >> (w1 + w2 + w3)) != 0 )
    238     {
    239         assert( false ,
    240         "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 );
    241     }
     241// Check key value
     242assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    242243
    243244    // compute indexes
     
    266267
    267268        return value;
    268 }
     269
     270}  // end grdxt_remove()
    269271
    270272///////////////////////////////////
     
    276278    uint32_t        w3 = rt->ix3_width;
    277279
    278     // Check key
    279     if( (key >> (w1 + w2 + w3)) != 0 )
    280     {
    281         assert( false ,
    282         "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 );
    283     }
     280// Check key value
     281assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    284282
    285283    void         ** ptr1 = rt->root;
     
    304302
    305303        return value;
    306 }
     304
     305}  // end grdxt_lookup()
     306
     307////////////////////////////////////////////
     308xptr_t grdxt_remote_lookup( xptr_t    rt_xp,
     309                            uint32_t  key )
     310{
     311    // get cluster and local pointer on remote rt descriptor
     312    grdxt_t       * rt_ptr = GET_PTR( rt_xp );
     313    cxy_t           rt_cxy = GET_CXY( rt_xp );
     314
     315    // get widths
     316    uint32_t        w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     317    uint32_t        w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) );
     318    uint32_t        w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
     319
     320// Check key value
     321assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     322
     323    // compute indexes
     324    uint32_t        ix1 = key >> (w2 + w3);              // index in level 1 array
     325        uint32_t        ix2 = (key >> w3) & ((1 << w2) -1);  // index in level 2 array
     326        uint32_t        ix3 = key & ((1 << w3) - 1);         // index in level 3 array
     327
     328    // get ptr1
     329    void         ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     330
     331    // get ptr2
     332        void         ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     333        if( ptr2 == NULL ) return XPTR_NULL;
     334
     335    // get ptr3
     336        void         ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     337        if( ptr3 == NULL ) return XPTR_NULL;
     338
     339    // get value
     340        xptr_t      value = XPTR( rt_cxy , ptr3[ix3] );
     341
     342        return value;
     343
     344}  // end grdxt_remote_lookup()
    307345
    308346//////////////////////////////////////
     
    319357    uint32_t        w3 = rt->ix3_width;
    320358
    321     // Check start_key
    322     if( (start_key >> (w1 + w2 + w3)) != 0 )
    323     {
    324         assert( false ,
    325         "start_key value %x exceed (%d + %d + %d) bits", start_key , w1 , w2 , w3 );
    326     }
     359// Check key value
     360assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
    327361
    328362    // compute max indexes
     
    363397
    364398    return NULL;
    365 }
     399
     400}  // end grdxt_get_first()
  • trunk/kernel/libk/grdxt.h

    r457 r603  
    3636 * Memory for the second and third levels arrays is dynamically allocated by the
    3737 * grdxt_insert() function and is only released by grdxt_destroy().
    38  * It is used by the MAPPER to implement the file cache: key is the page index in file.
     38 * - This structure is entirely contained in one single cluster.
     39 * - All modifications (insert / remove) must be done by a thread running in local cluster.
     40 * - Lookup can be done by a thread running in any cluster (local or remote).
     41 ******************************************************************************************
     42 * It is used by the mapper implementing the file cache:
     43 * - the key is the page index in file.
     44 * - the registered value is a local pointer on the page descriptor.
    3945 ******************************************************************************************/
    4046
     
    96102
    97103/*******************************************************************************************
    98  * This function returns the pointer on the item identified by its key.
     104 * This function returns to a local client, a local pointer on the item identified
     105 * by the <key> argument, from the radix tree identified by the <rt> local pointer.
    99106 *******************************************************************************************
    100  * @ rt      : pointer on the radix-tree descriptor.
     107 * @ rt      : local pointer on the radix-tree descriptor.
    101108 * @ key     : key value.
    102  * @ returns pointer on found item if success / returns NULL if failure.
     109 * @ returns a local pointer on found item if success / returns NULL if failure.
    103110 ******************************************************************************************/
    104111void * grdxt_lookup( grdxt_t  * rt,
    105112                     uint32_t   key );
     113
     114/*******************************************************************************************
     115 * This function returns to a - possibly remote - remote client, an extended pointer
     116 * on the item identified by the <key> argument, from the radix tree identified by
     117 * the <rt_xp> remote pointer.
     118 *******************************************************************************************
     119 * @ rt_xp   : extended pointer on the radix-tree descriptor.
     120 * @ key     : key value.
     121 * @ returns an extended pointer on found item if success / returns XPTR_NULL if failure.
     122 ******************************************************************************************/
     123xptr_t grdxt_remote_lookup( xptr_t     rt_xp,
     124                            uint32_t   key );
    106125
    107126/*******************************************************************************************
     
    120139
    121140/*******************************************************************************************
    122  * This function displays the current content of a radix_tree.
     141 * This function displays the current content of a possibly remote radix_tree.
    123142 *******************************************************************************************
    124  * @ rt      : pointer on the radix-tree descriptor.
     143 * @ rt      : extended pointer on the radix-tree descriptor.
    125144 * @ string  : radix tree identifier.
    126145 ******************************************************************************************/
    127 void grdxt_print( grdxt_t * rt,
    128                   char    * string );
     146void grdxt_display( xptr_t    rt_xp,
     147                    char    * string );
    129148
    130149
  • trunk/kernel/libk/queuelock.c

    r600 r603  
    4444    list_root_init( &lock->root );
    4545    busylock_init( &lock->lock , type );
     46
     47#if DEBUG_QUEUELOCK
     48thread_t * this = CURRENT_THREAD;
     49if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     50printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
     51__FUNCTION__, this->process->pid, this->trdid,
     52lock_type_str[type], local_cxy, lock );
     53#endif
     54
    4655}
    4756
     
    6473if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
    6574printk("\n[%s ] thread[%x,%x] BLOCK on q_lock %s [%x,%x]\n",
    66 __FUNCTION__, this->process->pid, this->trdid, lock_type_str[lock->lock.type], local_cxy, lock );
     75__FUNCTION__, this->process->pid, this->trdid,
     76lock_type_str[lock->lock.type], local_cxy, lock );
    6777#endif
    6878        // get pointer on calling thread
     
    8898if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
    8999printk("\n[%s] thread[%x,%x] ACQUIRE q_lock %s [%x,%x]\n",
    90 __FUNCTION__, this->process->pid, this->trdid, lock_type_str[lock->lock.type], local_cxy, lock );
     100__FUNCTION__, this->process->pid, this->trdid,
     101lock_type_str[lock->lock.type], local_cxy, lock );
    91102#endif
    92103
     
    112123if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
    113124printk("\n[%s] thread[%x,%x] RELEASE q_lock %s [%x,%x]\n",
    114 __FUNCTION__, this->process->pid, this->trdid, lock_type_str[lock->lock.type], local_cxy, lock );
     125__FUNCTION__, this->process->pid, this->trdid,
     126lock_type_str[lock->lock.type], local_cxy, lock );
    115127#endif
    116128
  • trunk/kernel/libk/remote_busylock.h

    r563 r603  
    11/*
    2  * remote_busylock.h: remote kernel busy waiting lock definition.     
     2 * remote_busylock.h: remote kernel busy-waiting lock definition.     
    33 *
    44 * Authors  Alain Greiner (2016,2017,2018)
     
    3333 * This synchronisation object sequencializes all concurrent read or write accesses to a
    3434 * shared object located in any cluster, made by any thread(s) running in any cluster.
    35  * It uses a busy waiting policy when the tock is taken by another thread, and should
     35 * It uses a busy waiting policy when the lock is taken by another thread, and should
    3636 * be used ro execute very short actions, such as basic allocators, or to protect 
    3737 * higher level synchronisation objects, such as remote_queuelock and remote_rwlock.
     38 *
    3839 * WARNING: a thread cannot yield when it is owning a busylock (local or remote).
    3940 *
     
    4546 *   decrements its busylocks counter.
    4647 *
    47 :w * - When a thread takes a busylock, it enters a critical section: the busylock_acquire()
     48 * - When a thread takes a busylock, it enters a critical section: the busylock_acquire()
    4849 *   function disables the IRQs, takes the lock, increments the thread busylocks counter,
    49  *   and save the SR in lock descriptor and returns.
     50 *    save the SR in the lock descriptor and returns.
    5051 *
    51  * - The busylock_release() function releases the lock, decrements the thread busylock
    52  *   counter, restores the SR to exit the critical section, and returns
     52 * - The busylock_release() function decrements the thread busylock counter,
     53 *   restores the SR to exit the critical section, and returns
    5354 *
    5455 * - If a thread owning a busylock (local or remote) tries to deschedule, the scheduler
     
    5859/*******************************************************************************************
    5960 * This structure defines a remote_busylock.
    60  * The <type> and <xlist> fields are used for debug.
    61  * The type defines the lock usage as detailed in the kernel_config.h file.
     61 * - The <ticket> and <current> fields implement the ticket policy described above.
     62 * - The <type> and <xlist> fields are used for debug. The type defines the lock usage,
     63 *   as detailed in the kernel_config.h file.
     64 * - The <save_sr> field is used to implement the critical section as decribed above.
    6265 ******************************************************************************************/
    6366
  • trunk/kernel/libk/remote_queuelock.c

    r600 r603  
    5353    // initialise busylock field
    5454    remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type );
    55 }
     55
     56#if DEBUG_QUEUELOCK
     57thread_t * this = CURRENT_THREAD;
     58if( DEBUG_QUEUELOCK < (uint32_t)hal_get_cycles() )
     59printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
     60__FUNCTION__, this->process->pid, this->trdid,
     61lock_type_str[type], lock_cxy, lock_ptr );
     62#endif
     63
     64}  // end remote_queuelock_init()
    5665
    5766///////////////////////////////////////////////
  • trunk/kernel/libk/remote_rwlock.c

    r600 r603  
    5252
    5353    remote_busylock_init( XPTR( lock_cxy , &lock_ptr->lock ) , type );
     54
     55#if DEBUG_RWLOCK
     56thread_t * this = CURRENT_THREAD;
     57if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     58printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
     59__FUNCTION__, this->process->pid, this->trdid,
     60lock_type_str[type], local_cxy, lock_ptr );
     61#endif
     62
    5463}
    5564
     
    8594#if DEBUG_RWLOCK
    8695if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    87 printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x]\n",
     96printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
    8897__FUNCTION__, this->process->pid, this->trdid,
    89 lock_type_str[lock_type], lock_cxy, lock_ptr );
     98lock_type_str[lock_type], lock_cxy, lock_ptr,
     99hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
    90100#endif
    91101        // get pointer on calling thread
     
    108118    }
    109119
    110 #if DEBUG_RWLOCK
    111 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    112 printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x]\n",
    113 __FUNCTION__, this->process->pid, this->trdid,
    114 lock_type_str[lock_type], lock_cxy, lock_ptr );
    115 #endif
    116 
    117120    // increment number of readers
    118121    hal_remote_atomic_add( count_xp , 1 );
     122
     123    hal_fence();
     124
     125#if DEBUG_RWLOCK
     126if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     127printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken = %d / count = %d\n",
     128__FUNCTION__, this->process->pid, this->trdid,
     129lock_type_str[lock_type], lock_cxy, lock_ptr,
     130hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
     131#endif
    119132
    120133    // release busylock
     
    154167#if DEBUG_RWLOCK
    155168if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    156 printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x]\n",
     169printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
    157170__FUNCTION__, this->process->pid, this->trdid,
    158 lock_type_str[lock_type], lock_cxy, lock_ptr );
    159 #endif
     171lock_type_str[lock_type], lock_cxy, lock_ptr,
     172hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
     173#endif
     174
    160175        // get local pointer on calling thread
    161176        thread_t * this = CURRENT_THREAD;
     
    177192    }
    178193
    179 #if DEBUG_RWLOCK
    180 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    181 printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x]\n",
     194    // take rwlock for write
     195    hal_remote_s32( taken_xp , 1 );
     196
     197#if DEBUG_RWLOCK
     198if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     199printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
    182200__FUNCTION__, this->process->pid, this->trdid,
    183 lock_type_str[lock_type], lock_cxy, lock_ptr );
    184 #endif
    185 
    186     // take rwlock
    187     hal_remote_s32( taken_xp , 1 );
     201lock_type_str[lock_type], lock_cxy, lock_ptr,
     202hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
     203#endif
    188204
    189205    // release busylock
     
    212228    remote_busylock_acquire( busylock_xp );
    213229
     230        // decrement number of readers
     231    hal_remote_atomic_add( count_xp , -1 );
     232
    214233#if DEBUG_RWLOCK
    215234thread_t * this      = CURRENT_THREAD;
    216235uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    217 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    218 printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x]\n",
     236xptr_t     taken_xp  = XPTR( lock_cxy , &lock_ptr->taken );
     237if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     238printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
    219239__FUNCTION__, this->process->pid, this->trdid,
    220 lock_type_str[lock_type], lock_cxy, lock_ptr );
    221 #endif
    222 
    223         // decrement number of readers
    224     hal_remote_atomic_add( count_xp , -1 );
     240lock_type_str[lock_type], lock_cxy, lock_ptr,
     241hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
     242#endif
    225243
    226244    // release first writer in waiting queue if no current readers
     
    309327    remote_busylock_acquire( busylock_xp );
    310328
     329    // release rwlock
     330    hal_remote_s32( taken_xp , 0 );
     331
    311332#if DEBUG_RWLOCK
    312333thread_t * this      = CURRENT_THREAD;
    313334uint32_t   lock_type = hal_remote_l32( XPTR( lock_cxy , &lock_ptr->lock.type ) );
    314 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    315 printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x]\n",
     335xptr_t     count_xp  = XPTR( lock_cxy , &lock_ptr->count );
     336if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     337printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
    316338__FUNCTION__, this->process->pid, this->trdid,
    317 lock_type_str[lock_type], lock_cxy, lock_ptr );
    318 #endif
    319 
    320     // release rwlock
    321     hal_remote_s32( taken_xp , 0 );
     339lock_type_str[lock_type], lock_cxy, lock_ptr,
     340hal_remote_l32( taken_xp ), hal_remote_l32( count_xp ) );
     341#endif
    322342
    323343    // unblock first waiting writer thread if writers waiting queue non empty
  • trunk/kernel/libk/rwlock.c

    r600 r603  
    4949
    5050    busylock_init( &lock->lock , type );
     51
     52#if DEBUG_RWLOCK
     53thread_t * this = CURRENT_THREAD;
     54if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     55printk("\n[%s] thread[%x,%x] initialise lock %s [%x,%x]\n",
     56__FUNCTION__, this->process->pid, this->trdid,
     57lock_type_str[type], local_cxy, lock );
     58#endif
     59
    5160}
    5261
     
    6877#if DEBUG_RWLOCK
    6978if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    70 printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x]\n",
    71 __FUNCTION__, this->process->pid, this->trdid,
    72 lock_type_str[lock->lock.type], local_cxy, lock );
     79printk("\n[%s] thread[%x,%x] READ BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
     80__FUNCTION__, this->process->pid, this->trdid,
     81lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
    7382#endif
    7483        // register reader thread in waiting queue
     
    8897    }
    8998
    90 #if DEBUG_RWLOCK
    91 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    92 printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x]\n",
    93 __FUNCTION__, this->process->pid, this->trdid,
    94 lock_type_str[lock->lock.type], local_cxy, lock );
    95 #endif
    96 
    9799    // increment number of readers
    98100    lock->count++;
     101
     102#if DEBUG_RWLOCK
     103if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     104printk("\n[%s] thread[%x,%x] READ ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
     105__FUNCTION__, this->process->pid, this->trdid,
     106lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     107#endif
    99108
    100109    // release busylock
     
    120129#if DEBUG_RWLOCK
    121130if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    122 printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x]\n",
    123 __FUNCTION__, this->process->pid, this->trdid,
    124 lock_type_str[lock->lock.type], local_cxy, lock );
     131printk("\n[%s] thread[%x,%x] WRITE BLOCK on rwlock %s [%x,%x] / taken %d / count %d\n",
     132__FUNCTION__, this->process->pid, this->trdid,
     133lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
    125134#endif
    126135        // register writer in waiting queue
    127136        list_add_last( &lock->wr_root , &this->wait_list );
    128137
    129         // block reader thread
     138        // block writer thread
    130139        thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_LOCK );
    131140       
     
    140149    }
    141150
    142 #if DEBUG_RWLOCK
    143 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    144 printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x]\n",
    145 __FUNCTION__, this->process->pid, this->trdid,
    146 lock_type_str[lock->lock.type], local_cxy, lock );
    147 #endif
    148 
    149151    // take the rwlock
    150152    lock->taken = 1;
     153
     154#if DEBUG_RWLOCK
     155if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     156printk("\n[%s] thread[%x,%x] WRITE ACQUIRE rwlock %s [%x,%x] / taken %d / count %d\n",
     157__FUNCTION__, this->process->pid, this->trdid,
     158lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     159#endif
    151160
    152161    // release busylock
     
    164173    busylock_acquire( &lock->lock );
    165174
    166 #if DEBUG_RWLOCK
    167 thread_t * this = CURRENT_THREAD;
    168 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    169 printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x]\n",
    170 __FUNCTION__, this->process->pid, this->trdid,
    171 lock_type_str[lock->lock.type], local_cxy, lock );
    172 #endif
    173 
    174175    // decrement number of readers
    175176    lock->count--;
     177
     178#if DEBUG_RWLOCK
     179thread_t * this = CURRENT_THREAD;
     180if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     181printk("\n[%s] thread[%x,%x] READ RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
     182__FUNCTION__, this->process->pid, this->trdid,
     183lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     184#endif
    176185
    177186    // release first writer in waiting queue if no current readers
     
    233242    busylock_acquire( &lock->lock );
    234243
    235 #if DEBUG_RWLOCK
    236 thread_t * this = CURRENT_THREAD;
    237 if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
    238 printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x]\n",
    239 __FUNCTION__, this->process->pid, this->trdid,
    240 lock_type_str[lock->lock.type], local_cxy, lock );
    241 #endif
    242 
    243244    // release the rwlock
    244245    lock->taken = 0;
     246
     247#if DEBUG_RWLOCK
     248thread_t * this = CURRENT_THREAD;
     249if( DEBUG_RWLOCK < (uint32_t)hal_get_cycles() )
     250printk("\n[%s] thread[%x,%x] WRITE RELEASE rwlock %s [%x,%x] / taken %d / count %d\n",
     251__FUNCTION__, this->process->pid, this->trdid,
     252lock_type_str[lock->lock.type], local_cxy, lock, lock->taken, lock->count );
     253#endif
    245254
    246255    // release first waiting writer thread if writers waiting queue non empty
  • trunk/kernel/libk/xhtab.c

    r563 r603  
    203203   
    204204#if DEBUG_XHTAB
    205 printk("\n[DBG] %s : enter / %s\n", __FUNCTION__, key );
     205printk("\n[%s] enter / key %s\n", __FUNCTION__, key );
    206206#endif
    207207
     
    241241   
    242242#if DEBUG_XHTAB
    243 printk("\n[DBG] %s : success / %s\n", __FUNCTION__, key );
     243printk("\n[%s] success / %s\n", __FUNCTION__, key );
    244244#endif
    245245
     
    248248}  // end xhtab_insert()
    249249
    250 /////////////////////////////////////
    251 error_t xhtab_remove( xptr_t   xhtab_xp,
    252                       void   * key,
    253                       xptr_t   xlist_entry_xp )
     250///////////////////////////////////////
     251bool_t xhtab_remove( xptr_t   xhtab_xp,
     252                     void   * key,
     253                     xptr_t   xlist_entry_xp )
    254254{
    255255    xptr_t             item_xp;
     
    275275    item_xp = xhtab_scan( xhtab_xp , index , key );
    276276
    277     if( item_xp == XPTR_NULL )    // error if not found
     277    if( item_xp == XPTR_NULL )    // return error if not found
    278278    {
    279279        // release the lock protecting hash table
    280280        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    281281
    282         return EINVAL;
     282        return false;
    283283    }
    284284    else                          // remove item if found
     
    293293        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    294294
    295         return 0;
     295        return true;
    296296    }
    297297}  // end xhtab_remove()
     
    318318   
    319319#if DEBUG_XHTAB
    320 printk("\n[DBG] %s : enter / %s\n", __FUNCTION__, key );
     320printk("\n[%s] enter / %s\n", __FUNCTION__, key );
    321321#endif
    322322
     
    325325   
    326326#if DEBUG_XHTAB
    327 printk("\n[DBG] %s : after lock acquire / %s\n", __FUNCTION__, key );
     327printk("\n[%s] after lock acquire / %s\n", __FUNCTION__, key );
    328328#endif
    329329
     
    332332
    333333#if DEBUG_XHTAB
    334 printk("\n[DBG] %s : after xhtab scan / %s\n", __FUNCTION__, key );
     334printk("\n[%s] after xhtab scan / %s\n", __FUNCTION__, key );
    335335#endif
    336336
     
    339339
    340340#if DEBUG_XHTAB
    341 printk("\n[DBG] %s : after lock release / %s\n", __FUNCTION__, key );
     341printk("\n[%s] after lock release / %s\n", __FUNCTION__, key );
    342342#endif
    343343
  • trunk/kernel/libk/xhtab.h

    r563 r603  
    127127 * @ key        : local pointer on item identifier.
    128128 * @ xlist_xp   : extended pointer on xlist_entry embedded in item to be removed.
    129  * @ return 0 if success / return EINVAL if item not found.
     129 * @ return 0 if item found / return false if item not found.
    130130 *****************************************************************************************/
    131 error_t xhtab_remove( xptr_t   xhtab_xp,
    132                       void   * key,
    133                       xptr_t   xlist_entry_xp );
     131bool_t xhtab_remove( xptr_t   xhtab_xp,
     132                     void   * key,
     133                     xptr_t   xlist_entry_xp );
    134134
    135135/******************************************************************************************
  • trunk/kernel/libk/xlist.h

    r563 r603  
    2525 */
    2626
    27 #ifndef _ALMOS_XLIST_H_
    28 #define _ALMOS_XLIST_H_
     27#ifndef _XLIST_H_
     28#define _XLIST_H_
    2929
    3030#include <kernel_config.h>
     
    8181 **************************************************************************/
    8282
    83 #define XLIST_FIRST( root_xp , type , member ) \
    84     ({ xptr_t __first = hal_remote_l64( root_xp );     \
     83#define XLIST_FIRST( root_xp , type , member )       \
     84    ({ xptr_t __first = hal_remote_l64( root_xp );   \
    8585           XLIST_ELEMENT( __first , type , member ); })
    8686
     
    9595 **************************************************************************/
    9696
    97 #define XLIST_LAST( root_xp , type , member )  \
    98     ({ xptr_t __last = hal_remote_l64( root_xp + 8 );  \
     97#define XLIST_LAST( root_xp , type , member )                       \
     98    ({ xptr_t __last = hal_remote_l64( root_xp + sizeof(xptr_t) );  \
    9999           XLIST_ELEMENT( __last , type , member ); })
    100100
     
    118118 **************************************************************************/
    119119
    120 #define XLIST_FOREACH_BACKWARD( root_xp , iter_xp )  \
    121 for( (iter_xp) = hal_remote_l64( (root_xp) + 8 ) ;   \
    122      (iter_xp) != (root_xp) ;                        \
    123      (iter_xp) = hal_remote_l64( (iter_xp) + 8 ) )
     120#define XLIST_FOREACH_BACKWARD( root_xp , iter_xp )              \
     121for( (iter_xp) = hal_remote_l64( (root_xp) + sizeof(xptr_t) ) ;  \
     122     (iter_xp) != (root_xp) ;                                    \
     123     (iter_xp) = hal_remote_l64( (iter_xp) + sizeof(xptr_t) ) )
    124124
    125125/***************************************************************************
     
    156156
    157157    // get ref->pred
    158     xptr_t ref_pred  = (xptr_t)hal_remote_l64( ref + 8 );
     158    xptr_t ref_pred  = (xptr_t)hal_remote_l64( ref + sizeof(xptr_t) );
    159159
    160160    // test if list is empty or ref is the first element 
     
    171171static inline void xlist_root_init( xptr_t root_xp )
    172172{
    173     hal_remote_s64(  root_xp   , root_xp );
    174     hal_remote_s64(  root_xp+8 , root_xp );
     173    hal_remote_s64( root_xp                  , root_xp );
     174    hal_remote_s64( root_xp + sizeof(xptr_t) , root_xp );
    175175}
    176176
     
    182182static inline void xlist_entry_init( xptr_t entry_xp )
    183183{
    184     hal_remote_s64(  entry_xp   , 0 );
    185     hal_remote_s64(  entry_xp+8 , 0 );
     184    hal_remote_s64( entry_xp                  , 0 );
     185    hal_remote_s64( entry_xp + sizeof(xptr_t) , 0 );
    186186}
    187187
     
    206206
    207207    // entry.pred <= root
    208     hal_remote_s64( entry + 8 , (uint64_t)root );
     208    hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)root );
    209209   
    210210    // first.pred <= new
    211     hal_remote_s64( first + 8 , (uint64_t)entry );
     211    hal_remote_s64( first + sizeof(xptr_t) , (uint64_t)entry );
    212212}
    213213
     
    223223{
    224224    // get the extended pointer on the last element in list
    225     xptr_t last = (xptr_t)hal_remote_l64( root + 8 );
     225    xptr_t last = (xptr_t)hal_remote_l64( root + sizeof(xptr_t) );
    226226
    227227    // update root.pred <= entry
    228     hal_remote_s64( root + 8 , (uint64_t)entry );
     228    hal_remote_s64( root + sizeof(xptr_t) , (uint64_t)entry );
    229229
    230230    // update entry.pred <= last
    231     hal_remote_s64( entry + 8 , (uint64_t)last );
     231    hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)last );
    232232
    233233    // entry.next <= root
     
    262262    xlist_entry_t entry;
    263263    hal_remote_memcpy( XPTR( local_cxy , &entry ) ,
    264                                   xp ,
    265                                   sizeof(xlist_entry_t) );
     264                       xp ,
     265                       sizeof(xlist_entry_t) );
    266266
    267267    xptr_t next = entry.next;
     
    272272
    273273    // update next.pred <= pred
    274     hal_remote_s64( next + 8 , (uint64_t)pred );
     274    hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)pred );
    275275}
    276276
     
    298298
    299299    // update new.pred <= pred
    300     hal_remote_s64( new + 8 , (uint64_t)pred );
     300    hal_remote_s64( new + sizeof(xptr_t) , (uint64_t)pred );
    301301
    302302        // update pred.next <= new
     
    304304
    305305    // update next.pred <= new
    306     hal_remote_s64( next + 8 , (uint64_t)new );
    307 }
    308 
    309 #endif  /* _ALMOS_LIST_H_ */
     306    hal_remote_s64( next + sizeof(xptr_t) , (uint64_t)new );
     307}
     308
     309#endif  /* _XLIST_H_ */
Note: See TracChangeset for help on using the changeset viewer.