Changeset 568


Ignore:
Timestamp:
Oct 5, 2018, 12:02:49 AM (6 years ago)
Author:
alain
Message:

omplete restructuration of kernel locks.

Location:
trunk/kernel/fs
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/fs/devfs.c

    r494 r568  
    5252#endif
    5353
    54 ///////////////////////////////
     54/////////////////////////////////////
    5555devfs_ctx_t * devfs_ctx_alloc( void )
    5656{
     
    9191{
    9292    error_t  error;
    93 
    94 #if DEBUG_DEVFS_INIT
    95 uint32_t cycle = (uint32_t)hal_get_cycles();
    96 if( DEBUG_DEVFS_INIT < cycle )
    97 printk("\n[DBG] %s : thread %x enter at cycle %d\n",
    98 __FUNCTION__ , CURRENT_THREAD , cycle );
    99 #endif
    10093
    10194    // creates DEVFS "dev" inode in cluster 0
     
    110103    assert( (error == 0) , "cannot create <dev>\n" );
    111104
    112 #if( DEBUG_DEVFS_INIT & 1 )
    113 if( DEBUG_DEVFS_INIT < cycle )
    114 printk("\n[DBG] %s : created <dev> inode at cycle %d\n", __FUNCTION__, cycle );
     105#if DEBUG_DEVFS_INIT
     106uint32_t cycle = (uint32_t)hal_get_cycles();
     107if( DEBUG_DEVFS_INIT < cycle )
     108printk("\n[DBG] %s : thread %x in process %x created <dev> inode / cycle %d\n",
     109__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ,cycle );
    115110#endif
    116111
     
    129124cycle = (uint32_t)hal_get_cycles();
    130125if( DEBUG_DEVFS_INIT < cycle )
    131 printk("\n[DBG] %s : thread %x exit at cycle %d\n",
    132 __FUNCTION__ , CURRENT_THREAD , cycle );
     126printk("\n[DBG] %s : thread %x in process %x created <external> inode / cycle %d\n",
     127__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid , cycle );
    133128#endif
    134129
     
    147142    uint32_t      channel;
    148143
    149 #if DEBUG_DEVFS_INIT
    150 uint32_t cycle = (uint32_t)hal_get_cycles();
    151 if( DEBUG_DEVFS_INIT < cycle )
    152 printk("\n[DBG] %s : thread %x enter at cycle %d\n",
    153 __FUNCTION__ , CURRENT_THREAD , cycle );
    154 #endif
    155 
    156     // create "internal" directory linked to "dev"
     144    // create "internal" directory
    157145    snprintf( node_name , 16 , "internal_%x" , local_cxy );
    158146    vfs_add_child_in_parent( local_cxy,
     
    163151                             NULL,
    164152                             devfs_internal_inode_xp );
     153#if DEBUG_DEVFS_INIT
     154uint32_t cycle = (uint32_t)hal_get_cycles();
     155trdid_t  trdid = CURRENT_THREAD->trdid;
     156pid_t    pid   = CURRENT_THREAD->process->pid;
     157if( DEBUG_DEVFS_INIT < cycle )
     158printk("\n[DBG] %s : thread %x in process %x created <%s> in cluster %x / cycle %d\n",
     159__FUNCTION__, trdid, pid, node_name, local_cxy, cycle );
     160#endif
    165161
    166162    // create MMC chdev inode
     
    176172                                 GET_PTR( chdev_xp ),
    177173                                 &inode_xp );
     174#if DEBUG_DEVFS_INIT
     175cycle = (uint32_t)hal_get_cycles();
     176if( DEBUG_DEVFS_INIT < cycle )
     177printk("\n[DBG] %s : thread %x in process %x created <mmc> inode in cluster %x\n",
     178__FUNCTION__, trdid, pid, local_cxy, cycle );
     179#endif
     180
    178181    }
    179182
     
    192195                                     GET_PTR( chdev_xp ),
    193196                                     &inode_xp );
     197#if DEBUG_DEVFS_INIT
     198cycle = (uint32_t)hal_get_cycles();
     199if( DEBUG_DEVFS_INIT < cycle )
     200printk("\n[DBG] %s : thread %x in process %x created <dma[%d]> inode in cluster %x\n",
     201__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     202#endif
    194203        }
    195204    }
     
    210219                                     GET_PTR( chdev_xp ),
    211220                                     &inode_xp );
     221#if DEBUG_DEVFS_INIT
     222cycle = (uint32_t)hal_get_cycles();
     223if( DEBUG_DEVFS_INIT < cycle )
     224printk("\n[DBG] %s : thread %x in process %x created <iob> inode in cluster %x\n",
     225__FUNCTION__, trdid, pid, local_cxy, cycle );
     226#endif
    212227        }
    213228    }
     
    228243                                     GET_PTR( chdev_xp ),
    229244                                     &inode_xp );
     245#if DEBUG_DEVFS_INIT
     246cycle = (uint32_t)hal_get_cycles();
     247if( DEBUG_DEVFS_INIT < cycle )
     248printk("\n[DBG] %s : thread %x in process %x created <pic> inode in cluster %x\n",
     249__FUNCTION__, trdid, pid, local_cxy, cycle );
     250#endif
    230251        }
    231252    }
     
    248269                                         GET_PTR( chdev_xp ),
    249270                                         &inode_xp );
     271#if DEBUG_DEVFS_INIT
     272cycle = (uint32_t)hal_get_cycles();
     273if( DEBUG_DEVFS_INIT < cycle )
     274printk("\n[DBG] %s : thread %x in process %x created <txt_rx[%d]> inode in cluster %x\n",
     275__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     276#endif
    250277            }
    251278        }
     
    269296                                         GET_PTR( chdev_xp ),
    270297                                         &inode_xp );
     298#if DEBUG_DEVFS_INIT
     299cycle = (uint32_t)hal_get_cycles();
     300if( DEBUG_DEVFS_INIT < cycle )
     301printk("\n[DBG] %s : thread %x in process %x created <txt_tx[%d]> inode in cluster %x\n",
     302__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     303#endif
    271304            }
    272305        }
     
    290323                                         GET_PTR( chdev_xp ),
    291324                                         &inode_xp );
     325#if DEBUG_DEVFS_INIT
     326cycle = (uint32_t)hal_get_cycles();
     327if( DEBUG_DEVFS_INIT < cycle )
     328printk("\n[DBG] %s : thread %x in process %x created <ioc[%d]> inode in cluster %x\n",
     329__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     330#endif
    292331            }
    293332        }
     
    295334
    296335    // create a FBF inode in each cluster containing a FBF chdev
    297     for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ )
     336    for( channel = 0 ; channel < CONFIG_MAX_FBF_CHANNELS ; channel++ )
    298337    {
    299338        chdev_xp = chdev_dir.fbf[channel];
     
    311350                                         GET_PTR( chdev_xp ),
    312351                                         &inode_xp );
     352#if DEBUG_DEVFS_INIT
     353cycle = (uint32_t)hal_get_cycles();
     354if( DEBUG_DEVFS_INIT < cycle )
     355printk("\n[DBG] %s : thread %x in process %x created <fbf[%d]> inode in cluster %x\n",
     356__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     357#endif
    313358            }
    314359        }
     
    332377                                         GET_PTR( chdev_xp ),
    333378                                         &inode_xp );
     379#if DEBUG_DEVFS_INIT
     380cycle = (uint32_t)hal_get_cycles();
     381if( DEBUG_DEVFS_INIT < cycle )
     382printk("\n[DBG] %s : thread %x in process %x created <nic_rx[%d]> inode in cluster %x\n",
     383__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     384#endif
    334385            }
    335386        }
     
    353404                                         GET_PTR( chdev_xp ),
    354405                                         &inode_xp );
    355             }
    356         }
    357     }
    358 
    359 #if DEBUG_DEVFS_INIT
    360 cycle = (uint32_t)hal_get_cycles();
    361 if( DEBUG_DEVFS_INIT < cycle )
    362 printk("\n[DBG] %s : thread %x exit at cycle %d\n",
    363 __FUNCTION__ , CURRENT_THREAD , cycle );
    364 #endif
    365 
     406#if DEBUG_DEVFS_INIT
     407cycle = (uint32_t)hal_get_cycles();
     408if( DEBUG_DEVFS_INIT < cycle )
     409printk("\n[DBG] %s : thread %x in process %x created <nic_tx[%d]> inode in cluster %x\n",
     410__FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     411#endif
     412            }
     413        }
     414    }
    366415}  // end devfs_local_init()
    367416
     
    408457
    409458    // get chdev functionnal type and channel
    410     func    = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->func ) );
    411     channel = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->channel ) );
     459    func    = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->func ) );
     460    channel = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    412461
    413462    // action depends on "func" and "to_buffer"
  • trunk/kernel/fs/devfs.h

    r484 r568  
    8888 * This function start to create the DEVFS subtree.
    8989 * This function should be called once in the cluster containing the VFS parent inode.
    90  * More precisely, it creates in cluster IO the "dev" and "external" DEVFS directories.
     90 * More precisely, it creates in cluster 0 the "dev" and "external" DEVFS directories.
    9191 * For each one, it creates the inode and link the associated dentry to parent inode.
    9292 * The DEVFS root inode is linked to the VFS parent inode identified by <parent_inode_xp>.
  • trunk/kernel/fs/fatfs.c

    r519 r568  
    4444extern vfs_ctx_t          fs_context[FS_TYPES_NR];   // allocated in vfs.c file
    4545
    46 extern remote_barrier_t   global_barrier;            // allocated in kernel_init.c
    47  
    4846//////////////////////////////////////////////////////////////////////////////////////////
    4947//              FATFS specific and static functions
     
    5553//////////////////////////////////////////////////////////////////////////////////////////
    5654
    57 static inline
    58 int get_length(
    59     int offset __attribute__((unused) ),
    60     int length)
    61 {
    62     return length;
    63 }
    64 
    65 static inline
    66 int get_offset(
    67     int offset,
    68     int length __attribute__((unused)) )
    69 {
    70     return offset;
    71 }
     55static inline int get_length( int offset __attribute__((unused)), int length ) { return length; }
     56
     57static inline int get_offset( int offset, int length __attribute__((unused)) ) { return offset; }
    7258
    7359//////////////////////////////////////////////////////////////////////////////////////////
     
    231217
    232218//////////////////////////////////////////////////////////////////////////////////////////
    233 //              FATFS specific but extern functions
     219//              FATFS specific extern functions
    234220//////////////////////////////////////////////////////////////////////////////////////////
    235221
     
    338324///////////////////////////////////////////////////////////////////////////////////////
    339325
    340 ///////////////////////////////
     326/////////////////////////////////////
    341327fatfs_ctx_t * fatfs_ctx_alloc( void )
    342328{
     
    778764        vfs_inode_type_t type = (is_dir) ? INODE_TYPE_DIR : INODE_TYPE_FILE;
    779765
    780         hal_remote_sw( XPTR( child_cxy , &child_ptr->type   ) , type );
    781         hal_remote_sw( XPTR( child_cxy , &child_ptr->size   ) , size );
    782         hal_remote_sw( XPTR( child_cxy , &child_ptr->extend ) , cluster );
     766        hal_remote_s32( XPTR( child_cxy , &child_ptr->type   ) , type );
     767        hal_remote_s32( XPTR( child_cxy , &child_ptr->size   ) , size );
     768        hal_remote_s32( XPTR( child_cxy , &child_ptr->extend ) , cluster );
    783769
    784770#if DEBUG_FATFS_LOAD
  • trunk/kernel/fs/ramfs.c

    r561 r568  
    2626#include <hal_kernel_types.h>
    2727#include <hal_special.h>
    28 #include <printk.h>
    29 #include <kmem.h>
    3028#include <vfs.h>
     29#include <cluster.h>
    3130#include <ramfs.h>
    3231
  • trunk/kernel/fs/vfs.c

    r561 r568  
    2828#include <hal_atomic.h>
    2929#include <hal_special.h>
    30 #include <readlock.h>
    31 #include <spinlock.h>
    3230#include <printk.h>
    3331#include <list.h>
     
    4341#include <chdev.h>
    4442#include <process.h>
     43#include <cluster.h>
    4544#include <vfs.h>
    4645#include <fatfs.h>
     
    5554
    5655extern vfs_ctx_t          fs_context[FS_TYPES_NR];    // allocated in kernel_init.c
    57 
    5856extern chdev_directory_t  chdev_dir;                  // allocated in kernel_init.c 
     57extern char *             lock_type_str[];            // allocated in kernel_init.c
    5958 
    6059//////////////////////////////////////////////////////////////////////////////////////////
     
    7978    vfs_ctx->extend         = extend;
    8079
    81     spinlock_init( &vfs_ctx->lock );
     80    busylock_init( &vfs_ctx->lock , LOCK_VFS_CTX );
    8281
    8382    bitmap_init( vfs_ctx->bitmap , BITMAP_SIZE(CONFIG_VFS_MAX_INODES) );
     
    8988{
    9089    // get lock on inum allocator
    91     spinlock_lock( &ctx->lock );
     90    busylock_acquire( &ctx->lock );
    9291
    9392    // get lid from local inum allocator
     
    9796    {
    9897        // release lock
    99         spinlock_unlock( &ctx->lock );
     98        busylock_release( &ctx->lock );
    10099
    101100        // return error
     
    108107
    109108        // release lock
    110         spinlock_unlock( &ctx->lock );
     109        busylock_release( &ctx->lock );
    111110
    112111        // return inum
     
    160159
    161160#if DEBUG_VFS_INODE_CREATE
    162 uint32_t cycle = (uint32_t)hal_get_cycles();
     161char           name[CONFIG_VFS_MAX_NAME_LENGTH];
     162uint32_t       cycle      = (uint32_t)hal_get_cycles();
     163cxy_t          dentry_cxy = GET_CXY( dentry_xp );
     164vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
     165thread_t *     this       = CURRENT_THREAD;
     166if( dentry_xp != XPTR_NULL ) hal_remote_strcpy( XPTR( local_cxy  , name ),
     167                                                XPTR( dentry_cxy , dentry_ptr->name ) );
     168else                         strcpy( name , "/" );
    163169if( DEBUG_VFS_INODE_CREATE < cycle )
    164 printk("\n[DBG] %s : thread %x enter / dentry = %x in cluster %x / cycle %d\n",
    165 __FUNCTION__, CURRENT_THREAD, GET_PTR(dentry_xp), GET_CXY(dentry_xp), cycle );
     170printk("\n[DBG] %s : thread %x in process %x enter for <%s> / cycle %d\n",
     171__FUNCTION__, this->trdid, this->process->pid, name, cycle );
    166172#endif
    167173 
     
    232238    xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
    233239
    234     // initialize inode locks
    235     remote_rwlock_init( XPTR( local_cxy , &inode->data_lock ) );
    236     remote_spinlock_init( XPTR( local_cxy , &inode->main_lock ) );
     240    // initialize inode lock
     241    remote_rwlock_init( XPTR( local_cxy , &inode->data_lock ), LOCK_VFS_INODE );
     242
     243    // initialise lock protecting inode three traversal
     244    remote_busylock_init( XPTR( local_cxy , &inode->main_lock ), LOCK_VFS_MAIN );
    237245
    238246#if DEBUG_VFS_INODE_CREATE
    239 cycle = (uint32_t)hal_get_cycles();
     247cycle      = (uint32_t)hal_get_cycles();
    240248if( DEBUG_VFS_INODE_CREATE < cycle )
    241 printk("\n[DBG] %s : thread %x exit / inode = %x in cluster %x / cycle %d\n",
    242 __FUNCTION__, CURRENT_THREAD, inode, local_cxy, cycle );
     249printk("\n[DBG] %s : thread %x in process %x exit for <%s> / inode [%x,%x] / cycle %d\n",
     250__FUNCTION__, this->trdid, this->process->pid, name, local_cxy, inode, cycle );
    243251#endif
    244252 
     
    346354
    347355    // get size
    348     remote_rwlock_rd_lock( XPTR( cxy , &ptr->data_lock ) );
    349     uint32_t size = hal_remote_lw( XPTR( cxy , &ptr->size ) );
    350     remote_rwlock_rd_unlock( XPTR( cxy , &ptr->data_lock ) );
     356    remote_rwlock_rd_acquire( XPTR( cxy , &ptr->data_lock ) );
     357    uint32_t size = hal_remote_l32( XPTR( cxy , &ptr->size ) );
     358    remote_rwlock_rd_release( XPTR( cxy , &ptr->data_lock ) );
    351359    return size;
    352360}
     
    361369
    362370    // set size
    363     remote_rwlock_wr_unlock( XPTR( cxy , &ptr->data_lock ) );
    364     hal_remote_sw( XPTR( cxy , &ptr->size ) , size );
    365     remote_rwlock_wr_unlock( XPTR( cxy , &ptr->data_lock ) );
     371    remote_rwlock_wr_release( XPTR( cxy , &ptr->data_lock ) );
     372    hal_remote_s32( XPTR( cxy , &ptr->size ) , size );
     373    remote_rwlock_wr_release( XPTR( cxy , &ptr->data_lock ) );
    366374}
    367375
     
    374382
    375383    // release the main lock
    376     remote_spinlock_unlock( XPTR( cxy , &ptr->main_lock ) );
     384    remote_busylock_release( XPTR( cxy , &ptr->main_lock ) );
    377385}
    378386
     
    385393
    386394    // get the main lock
    387     remote_spinlock_lock( XPTR( cxy , &ptr->main_lock ) );
     395    remote_busylock_acquire( XPTR( cxy , &ptr->main_lock ) );
    388396}
    389397
     
    403411
    404412    // get parent dentry
    405     dentry_xp  = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
     413    dentry_xp  = hal_remote_l64( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
    406414
    407415    // get local copy of name
     
    475483cycle = (uint32_t)hal_get_cycles();
    476484if( DEBUG_VFS_DENTRY_CREATE < cycle )
    477 printk("\n[DBG] %s : dentry initialised\n", __FUNCTION__ );
     485printk("\n[DBG] %s : thread %x in process %x / dentry <%s> initialised / cycle %d\n",
     486__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, dentry->name, cycle );
    478487#endif
    479488
     
    488497cycle = (uint32_t)hal_get_cycles();
    489498if( DEBUG_VFS_DENTRY_CREATE < cycle )
    490 printk("\n[DBG] %s : dentry registerd in htab\n", __FUNCTION__ );
     499printk("\n[DBG] %s : thread %x in process %x / dentry <%s> registered / cycle %d\n",
     500__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, dentry->name, cycle );
    491501#endif
    492502
     
    544554    vfs_file_t  * file;
    545555        kmem_req_t    req;
     556
     557#if DEBUG_VFS_FILE_CREATE
     558uint32_t cycle = (uint32_t)hal_get_cycles();
     559if( DEBUG_VFS_OPEN < cycle )
     560printk("\n[DBG] %s : thread %x in process %x enter for inode %x in cluster %x / cycle %d\n",
     561__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, inode, local_cxy, cycle );
     562#endif
    546563
    547564    // allocate memory for new file descriptor
     
    563580    file->mapper   = inode->mapper;
    564581
    565     remote_rwlock_init( XPTR( local_cxy , &file->lock ) );
     582    remote_rwlock_init( XPTR( local_cxy , &file->lock ), LOCK_VFS_FILE );
    566583
    567584    *file_xp = XPTR( local_cxy , file );
    568585
    569 #if DEBUG_VFS_OPEN
    570 uint32_t cycle = (uint32_t)hal_get_cycles();
     586#if DEBUG_VFS_FILE_CREATE
     587cycle = (uint32_t)hal_get_cycles();
    571588if( DEBUG_VFS_OPEN < cycle )
    572589printk("\n[DBG] %s : thread %x in process %x created file %x in cluster %x / cycle %d\n",
     
    729746
    730747    // get inode type from remote file descriptor
    731     inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type   ) );
     748    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type   ) );
    732749   
    733750    assert( (inode_type == INODE_TYPE_FILE) ,
     
    735752
    736753    // get mapper pointer and file offset from file descriptor
    737     file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
     754    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
    738755    mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
    739756
     
    784801
    785802    // get inode type from remote file descriptor
    786     inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type   ) );
     803    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type   ) );
    787804   
    788805    // action depends on inode type
     
    790807    {
    791808        // get mapper pointer and file offset from file descriptor
    792         file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
     809        file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
    793810        mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
    794811
     
    848865
    849866    // take file descriptor lock
    850     remote_rwlock_wr_lock( lock_xp );
     867    remote_rwlock_wr_acquire( lock_xp );
    851868
    852869    if      ( whence == SEEK_CUR )   // new = current + offset
    853870    {
    854         new = hal_remote_lw( offset_xp ) + offset;
     871        new = hal_remote_l32( offset_xp ) + offset;
    855872    }
    856873    else if ( whence == SEEK_SET )   // new = offset
     
    863880        inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
    864881
    865         new = hal_remote_lw( XPTR( file_cxy , &inode_ptr->size ) ) + offset;
     882        new = hal_remote_l32( XPTR( file_cxy , &inode_ptr->size ) ) + offset;
    866883    }
    867884    else
    868885    {
    869886        printk("\n[ERROR] in %s : illegal whence value\n", __FUNCTION__ );
    870         remote_rwlock_wr_unlock( lock_xp );
     887        remote_rwlock_wr_release( lock_xp );
    871888        return -1;
    872889    }
    873890
    874891    // set new offset
    875     hal_remote_sw( offset_xp , new );
     892    hal_remote_s32( offset_xp , new );
    876893
    877894    // release file descriptor lock
    878     remote_rwlock_wr_unlock( lock_xp );
     895    remote_rwlock_wr_release( lock_xp );
    879896
    880897    // success
     
    929946
    930947    // take the lock protecting the list of copies
    931     remote_spinlock_lock( lock_xp );
     948    remote_queuelock_acquire( lock_xp );
    932949
    933950    XLIST_FOREACH( root_xp , iter_xp )
     
    948965        xptr_t entry_xp         = XPTR( process_cxy , &process_ptr->fd_array.array[file_id] );
    949966
    950 // remote_rwlock_wr_lock( fd_array_lock_xp );
    951 
    952         hal_remote_swd( entry_xp , XPTR_NULL );
     967// remote_rwlock_wr_acquire( fd_array_lock_xp );
     968
     969        hal_remote_s64( entry_xp , XPTR_NULL );
    953970       
    954 // remote_rwlock_wr_unlock( fd_array_lock_xp );
     971// remote_rwlock_wr_release( fd_array_lock_xp );
    955972
    956973        vfs_file_count_down( file_xp );
     
    960977
    961978    // release the lock protecting the list of copies
    962     remote_spinlock_unlock( lock_xp );
     979    remote_queuelock_release( lock_xp );
    963980
    964981#if (DEBUG_VFS_CLOSE & 1)
     
    10641081
    10651082    // get inode type from remote file
    1066     inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
     1083    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
    10671084
    10681085    if( inode_type != INODE_TYPE_DIR )
     
    10721089    }
    10731090
    1074     assert( false , "not implemented\n" );
     1091    // TODO implement this function using process CWD lock
     1092
     1093assert( false , "not implemented\n" );
     1094
    10751095    return 0;
    10761096}
     
    11011121   
    11021122    // get inode type from remote inode
    1103     inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
     1123    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
    11041124
    11051125   
     
    11231143//            Inode Tree functions
    11241144//////////////////////////////////////////////////////////////////////////////////////////
    1125 
    11261145
    11271146//////////////////////////////////////////////////////////////////////////
     
    11721191
    11731192    // get inode type
    1174     inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
     1193    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
    11751194
    11761195    // get local pointer on associated mapper
     
    11921211
    11931212        // get xhtab lock
    1194         xhtab_read_lock( children_xp );
     1213        xhtab_lock( children_xp );
    11951214
    11961215        // get first dentry from xhtab
     
    12041223
    12051224            // get extended pointer on child inode
    1206             child_inode_xp = hal_remote_lwd( XPTR( child_dentry_cxy,
     1225            child_inode_xp = hal_remote_l64( XPTR( child_dentry_cxy,
    12071226                                                   &child_dentry_ptr->child_xp ) );
    12081227
     
    12101229            child_dentry_name_xp = XPTR( child_dentry_cxy , &child_dentry_ptr->name );
    12111230
    1212             // recursive call on child inode
     1231            // recursive call on inode display
    12131232            vfs_recursive_display( child_inode_xp,
    12141233                                   child_dentry_name_xp,
     
    12201239
    12211240        // release xhtab lock
    1222         xhtab_read_unlock( children_xp );
     1241        xhtab_unlock( children_xp );
    12231242    }
    12241243}  // end vfs_recursive_display()
     
    12311250    cxy_t          dentry_cxy;
    12321251    vfs_dentry_t * dentry_ptr;
    1233     uint32_t       save_sr;
    12341252
    12351253    // get target inode cluster and local pointer
     
    12381256
    12391257    // get extended pointer on associated dentry
    1240     dentry_xp   = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
     1258    dentry_xp   = hal_remote_l64( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
    12411259
    12421260    // check if target inode is the File System root
     
    12651283
    12661284    // get TXT0 lock in busy waiting mode
    1267     remote_spinlock_lock_busy( lock_xp , &save_sr );
     1285    remote_busylock_acquire( lock_xp );
    12681286
    12691287    // print header
     
    12741292
    12751293    // release lock
    1276     remote_spinlock_unlock_busy( lock_xp , save_sr );
     1294    remote_busylock_release( lock_xp );
    12771295
    12781296}  // end vfs_display()
     
    12981316
    12991317    // get inode access mode, UID, and GID
    1300     // TODO uint32_t  mode = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->mode ) );
    1301     uid_t     uid  = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->uid  ) );
    1302     gid_t     gid  = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->gid  ) );
     1318    // TODO uint32_t  mode = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->mode ) );
     1319    uid_t     uid  = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->uid  ) );
     1320    gid_t     gid  = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->gid  ) );
    13031321
    13041322    // FIXME : me must use mode
     
    13421360
    13431361    // return child inode
    1344     *child_xp = (xptr_t)hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) );
     1362    *child_xp = (xptr_t)hal_remote_l64( XPTR( dentry_cxy , &dentry_ptr->child_xp ) );
    13451363    return true;
    13461364
     
    14961514            parent_ptr = GET_PTR( parent_xp );
    14971515            ctx_ptr    = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy,&parent_ptr->ctx ) );
    1498             fs_type    = hal_remote_lw( XPTR( parent_cxy , &ctx_ptr->type ) );
     1516            fs_type    = hal_remote_l32( XPTR( parent_cxy , &ctx_ptr->type ) );
    14991517
    15001518            // select a cluster for missing inode
     
    15451563                if( last && create && dir )  // new directory  => update inode type
    15461564                {
    1547                      hal_remote_sw( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_DIR );
     1565                     hal_remote_s32( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_DIR );
    15481566
    15491567#if (DEBUG_VFS_LOOKUP & 1)
     
    15551573                else if ( last && create )   // new file => update inode type
    15561574                {
    1557                      hal_remote_sw( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_FILE );
     1575                     hal_remote_s32( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_FILE );
    15581576
    15591577#if (DEBUG_VFS_LOOKUP & 1)
     
    15741592            {
    15751593                // load child mapper from device if child is a directory (prefetch)
    1576                 if( hal_remote_lw( XPTR( child_cxy , &child_ptr->type ) ) == INODE_TYPE_DIR )
     1594                if( hal_remote_l32( XPTR( child_cxy , &child_ptr->type ) ) == INODE_TYPE_DIR )
    15771595                {
    15781596                    if( child_cxy == local_cxy )
     
    17001718
    17011719        // get extended pointer on parent dentry               
    1702         dentry_xp = (xptr_t)hal_remote_lwd( XPTR( inode_cxy , inode_ptr->parent_xp ) );
     1720        dentry_xp = (xptr_t)hal_remote_l64( XPTR( inode_cxy , inode_ptr->parent_xp ) );
    17031721
    17041722        // get dentry cluster and local pointer
     
    17071725
    17081726        // get dentry name length and pointer
    1709         length =  hal_remote_lw( XPTR( dentry_cxy , &dentry_ptr->length ) );
     1727        length =  hal_remote_l32( XPTR( dentry_cxy , &dentry_ptr->length ) );
    17101728        name   = (char *)hal_remote_lpt( XPTR( dentry_cxy , &dentry_ptr->name ) );
    17111729
     
    17271745
    17281746                // get extended pointer on next inode
    1729         inode_xp = (xptr_t)hal_remote_lwd( XPTR( dentry_cxy , dentry_ptr->parent ) );
     1747        inode_xp = (xptr_t)hal_remote_l64( XPTR( dentry_cxy , dentry_ptr->parent ) );
    17301748    }
    17311749    while( (dentry_xp != XPTR_NULL) );
     
    17571775#if DEBUG_VFS_ADD_CHILD
    17581776uint32_t cycle = (uint32_t)hal_get_cycles();
     1777thread_t * this = CURRENT_THREAD;
    17591778if( DEBUG_VFS_ADD_CHILD < cycle )
    1760 printk("\n[DBG] %s : thread %x enter for <%s> / child_cxy = %x / parent_cxy = %x / cycle %d\n",
    1761 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, name,
     1779printk("\n[DBG] %s : thread %x in process %x enter for <%s>\n"
     1780"      child_cxy = %x / parent_cxy = %x / cycle %d\n",
     1781__FUNCTION__, this->trdid, this->process->pid, name,
    17621782child_cxy, parent_cxy, (uint32_t)hal_get_cycles() );
    17631783#endif
     
    17701790                                   parent_ptr,
    17711791                                   &dentry_xp );
    1772 
    1773 #if (DEBUG_VFS_ADD_CHILD & 1)
    1774 if( (DEBUG_VFS_ADD_CHILD < cycle) && (error == 0) )
    1775 printk("\n[DBG] %s : dentry <%s> created in cluster %x\n", __FUNCTION__, name, local_cxy );
    1776 #endif
    1777 
    17781792    }
    17791793    else                               // parent cluster is remote
     
    17851799                                      &dentry_xp,
    17861800                                      &error );
    1787 
    1788 #if (DEBUG_VFS_ADD_CHILD & 1)
    1789 if( (DEBUG_VFS_ADD_CHILD < cycle) && (error == 0) )
    1790 printk("\n[DBG] %s : dentry <%s> created in cluster %x\n", __FUNCTION__, name, parent_cxy );
    1791 #endif
    1792 
    17931801    }
    17941802                                     
     
    17991807        return ENOMEM;
    18001808    }
     1809
     1810#if(DEBUG_VFS_ADD_CHILD & 1)
     1811if( DEBUG_VFS_ADD_CHILD < cycle )
     1812printk("\n[DBG] %s : thread %x in process %x / dentry <%s> created in cluster %x\n",
     1813__FUNCTION__, this->trdid, this->process->pid, name, parent_cxy );
     1814#endif
    18011815
    18021816    // 2. create child inode TODO : define attr / mode / uid / gid
     
    18171831                                  gid,
    18181832                                  &inode_xp );
    1819 
    1820 #if (DEBUG_VFS_ADD_CHILD & 1)
    1821 if( DEBUG_VFS_ADD_CHILD < cycle )
    1822 printk("\n[DBG] %s : inode <%x> created in cluster %x\n",
    1823 __FUNCTION__ , GET_PTR(inode_xp) , local_cxy );
    1824 #endif
    1825 
    18261833    }
    18271834    else                              // child cluster is remote
     
    18381845                                     &inode_xp,
    18391846                                     &error );
    1840 
    1841 #if (DEBUG_VFS_ADD_CHILD & 1)
    1842 if( DEBUG_VFS_ADD_CHILD < cycle )
    1843 printk("\n[DBG] %s : inode <%s> created in cluster %x\n",
    1844 __FUNCTION__ , GET_PTR(inode_xp) , child_cxy );
    1845 #endif
    1846 
    18471847    }
    18481848                                     
     
    18581858    }
    18591859
     1860#if(DEBUG_VFS_ADD_CHILD & 1)
     1861if( DEBUG_VFS_ADD_CHILD < cycle )
     1862printk("\n[DBG] %s : thread %x in process %x / inode <%s> created in cluster %x\n",
     1863__FUNCTION__ , this->trdid, this->process->pid, name , child_cxy );
     1864#endif
     1865
    18601866    // 3. update extended pointer on inode in dentry
    18611867    cxy_t          dentry_cxy = GET_CXY( dentry_xp );
    18621868    vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
    1863     hal_remote_swd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp );
     1869    hal_remote_s64( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp );
    18641870
    18651871#if DEBUG_VFS_ADD_CHILD
    18661872cycle = (uint32_t)hal_get_cycles();
    18671873if( DEBUG_VFS_ADD_CHILD < cycle )
    1868 printk("\n[DBG] %s : thread %x in process %x exit for <%s>\n",
    1869 __FUNCTION__, CURRENT_THREAD, CURRENT_THREAD->process->pid, name );
     1874printk("\n[DBG] %s : thread %x in process %x exit for <%s> / cycle %d\n",
     1875__FUNCTION__, this->trdid, this->process->pid, name, (uint32_t)hal_get_cycles() );
    18701876#endif
    18711877
     
    18931899
    18941900    // get cluster and pointers of associated dentry
    1895     dentry_xp  = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
     1901    dentry_xp  = hal_remote_l64( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
    18961902    dentry_cxy = GET_CXY( dentry_xp );
    18971903    dentry_ptr = GET_PTR( dentry_xp );
     
    19581964    if( fs_type == FS_TYPE_FATFS )
    19591965    {
    1960         rwlock_wr_lock( &mapper->lock );
     1966        // enter mapper in write mode
     1967        rwlock_wr_acquire( &mapper->lock );
     1968
     1969        // move page to mapper
    19611970        error = fatfs_mapper_move_page( page , to_mapper );
    1962         rwlock_wr_unlock( &mapper->lock );
     1971
     1972        // exit mapper in write mode
     1973        rwlock_wr_release( &mapper->lock );
    19631974    }
    19641975    else if( fs_type == FS_TYPE_RAMFS )
  • trunk/kernel/fs/vfs.h

    r561 r568  
    3030#include <hal_atomic.h>
    3131#include <remote_rwlock.h>
    32 #include <remote_spinlock.h>
    33 #include <spinlock.h>
     32#include <remote_busylock.h>
     33#include <busylock.h>
    3434#include <list.h>
    3535#include <xlist.h>
    36 #include <slist.h>
    3736#include <bits.h>
    3837#include <xhtab.h>
     
    105104
    106105/******************************************************************************************
    107  * This structure defines informations common to all inodes and dentries
    108  * of a given file system. As it is declared a global variable in the kdata segment,
    109  * it is replicated in all clusters and handled as private by each OS intance.
     106 * This structure defines a VFS context, that contains informations common to all inodes
     107 * and dentries for a given file system. As it is declared as a global variable in the
     108 * kdata segment, it is handled as private by each OS intance in a given cluster.
    110109 *****************************************************************************************/
    111110
     
    134133        uint32_t       cluster_size;             /*! cluster size on device (bytes)          */
    135134        xptr_t         vfs_root_xp;              /*! extended pointer on VFS root inode      */
    136     spinlock_t     lock;                     /*! lock protecting inum allocator          */
     135    busylock_t     lock;                     /*! lock protecting inum allocator          */
    137136    uint32_t       bitmap[BITMAP_SIZE(CONFIG_VFS_MAX_INODES)];  /* inum allocator        */
    138137    void         * extend;                   /*! FS specific context extension           */
     
    143142 * This structure define a VFS inode.
    144143 * It contains an extended pointer on the parent dentry, and (for directory only)
    145  * an hash table xhtab refering all children dentries.
    146  * The <parent> inode is unique for a directory (not hard links for directories).
     144 * an hash table (xhtab) registering all children dentries.
     145 * The <parent> inode is unique for a directory (no hard links for directories).
    147146 * For a file, the parent field points to the first dentry who created this inode.
    148  * Syncrhonisation:
    149  * - the main_lock (spinlock) is used during the inode tree traversal or for inode
    150  *   modification (add/remove children).
    151  * - the data_lock (rwlock) is used during read/write accesses to the data stored
    152  *   in the mapper.
    153  * - the mapper lock (rwlock) is only used during the radix tree traversal to return
    154  *   the relevant page for read/write.
     147 * Synchronisation:
     148 * - the main_lock (remote_busylock) is used during the inode tree traversal,
     149 *   or for inode modification (add/remove children).
     150 * - the data_lock (remote_rwlock) is used during read/write accesses to the data
     151 *   stored in the mapper.
     152 * - the mapper lock (remote rwlock) is only used during the radix tree traversal
     153 *   to return the relevant page for read/write.
    155154 *****************************************************************************************/
    156155
     
    195194        xhtab_t            children;         /*! embedded xhtab of children dentries         */
    196195        remote_rwlock_t    data_lock;        /*! protect read/write to data and to size      */
    197         remote_spinlock_t  main_lock;        /*! protect inode tree traversal and modifs     */
     196        remote_busylock_t  main_lock;        /*! protect inode tree traversal and modifs     */
    198197        list_entry_t       list;             /*! member of set of inodes in same cluster     */
    199198        xlist_entry_t      wait_root;        /*! root of threads waiting on this inode       */
Note: See TracChangeset for help on using the changeset viewer.