Changeset 627 for trunk/kernel


Ignore:
Timestamp:
May 1, 2019, 5:13:47 PM (6 years ago)
Author:
alain
Message:

Replace the queuelock protectingthe FAT by a rwlock in the FATFS.

Location:
trunk/kernel
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_ioc.h

    r626 r627  
    180180 * This blocking function moves one or several contiguous blocks of data
    181181 * from the block device to a - possibly remote - memory buffer.
     182 * It uses an extended pointer, because the target buffer is generally a remote mapper.
    182183 * It does  not uses the IOC device waiting queue and server thread, and does not use
    183184 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
     
    197198 * This blocking function moves one or several contiguous blocks of data
    198199 * from a - possibly remote - memory buffer to the block device.
     200 * It uses an extended pointer, because the target buffer is generally a remote mapper.
    199201 * It does  not uses the IOC device waiting queue and server thread, and does not use
    200202 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
  • trunk/kernel/fs/fatfs.c

    r626 r627  
    491491// FS_INFO sector on the IOC device. It can be called by a thead running in any cluster.
    492492//
    493 // WARNING : The free_lock protecting exclusive access to these variables
     493// WARNING : The lock protecting exclusive access to these variables
    494494//           must be taken by the calling function.
    495495//////////////////////////////////////////////////////////////////////////////////////////
     
    618618// FS_INFO sector on the IOC device. It can be called by a thead running in any cluster.
    619619//
    620 // WARNING : The free_lock protecting exclusive access to these variables
     620// WARNING : The lock protecting exclusive access to these variables
    621621//           must be taken by the calling function.
    622622//////////////////////////////////////////////////////////////////////////////////////////
     
    853853    uint32_t   page_count_in_file;     // index of page in file (index in linked list)
    854854    uint32_t   next_cluster_id;        // content of current FAT slot
     855    xptr_t     lock_xp;                // extended pointer on FAT lock
    855856
    856857assert( (searched_page_index > 0) ,
     
    865866#endif
    866867
     868    // get local pointer on VFS context (same in all clusters)
     869    vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS];
     870
    867871    // get local pointer on local FATFS context
    868     fatfs_ctx_t * ctx = fs_context[FS_TYPE_FATFS].extend;
     872    fatfs_ctx_t * loc_fatfs_ctx = vfs_ctx->extend;
    869873
    870874    // get extended pointer and cluster on FAT mapper
    871     xptr_t fat_mapper_xp  = ctx->fat_mapper_xp;
    872     cxy_t  fat_mapper_cxy = GET_CXY( fat_mapper_xp );
     875    xptr_t fat_mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
     876    cxy_t  fat_cxy        = GET_CXY( fat_mapper_xp );
     877
     878    // get local pointer on FATFS context in FAT cluster
     879    fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) );
     880
     881    // build extended pointer on FAT lock in FAT cluster
     882    lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock );
     883
     884    // take FAT lock in read mode
     885    remote_rwlock_rd_acquire( lock_xp );
    873886
    874887    // initialize loop variable (1024 slots per page)
     
    887900        {
    888901            printk("\n[ERROR] in %s : cannot get next page from FAT mapper\n", __FUNCTION__);
     902            remote_rwlock_rd_release( lock_xp );
    889903            return -1;
    890904        }
     
    895909
    896910        // get FAT slot content
    897         next_cluster_id = hal_remote_l32( XPTR( fat_mapper_cxy,
    898                                                 &buffer[current_slot_index] ) );
     911        next_cluster_id = hal_remote_l32( XPTR( fat_cxy, &buffer[current_slot_index] ) );
    899912
    900913#if (DEBUG_FATFS_GET_CLUSTER & 1)
     
    904917__FUNCTION__, current_page_index, current_slot_index , next_cluster_id );
    905918#endif
    906 
    907919        // update loop variables
    908920        current_page_index = next_cluster_id >> 10;
     
    914926    {
    915927        printk("\n[ERROR] in %s : searched_cluster_id not found in FAT\n", __FUNCTION__ );
     928        remote_rwlock_rd_release( lock_xp );
    916929        return -1;
    917930    }
    918931   
     932    // release FAT lock
     933    remote_rwlock_rd_release( lock_xp );
     934
    919935#if DEBUG_FATFS_GET_CLUSTER
    920936cycle = (uint32_t)hal_get_cycles();
     
    10931109    fatfs_ctx->fs_info_buffer        = buffer;
    10941110
    1095     remote_queuelock_init( XPTR( local_cxy , &fatfs_ctx->free_lock ) , LOCK_FATFS_FREE );
     1111    remote_rwlock_init( XPTR( local_cxy , &fatfs_ctx->lock ) , LOCK_FATFS_FREE );
    10961112
    10971113#if (DEBUG_FATFS_CTX_INIT & 0x1)
     
    23432359
    23442360    // build relevant extended pointers on free clusters info in mapper cluster
    2345     lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_lock );
     2361    lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock );
    23462362    hint_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_cluster_hint );
    23472363    free_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_clusters );
    23482364
    2349     // take the lock protecting free clusters
    2350     remote_queuelock_acquire( lock_xp );
     2365    // take the FAT lock in write mode
     2366    remote_rwlock_wr_acquire( lock_xp );
    23512367
    23522368    // get hint and free_clusters values from FATFS context in FAT cluster
     
    23642380    {
    23652381        printk("\n[ERROR] in %s : no more free FATFS clusters\n", __FUNCTION__ );
    2366         remote_queuelock_acquire( lock_xp );
     2382        remote_rwlock_wr_release( lock_xp );
    23672383        return -1;
    23682384    }
     
    23832399    {
    23842400        printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ );
     2401        remote_rwlock_wr_release( lock_xp );
    23852402        return -1;
    23862403    }
     
    23932410    {
    23942411        printk("\n[ERROR] in %s : selected cluster %x not free\n", __FUNCTION__, cluster );
    2395         remote_queuelock_acquire( lock_xp );
     2412        remote_rwlock_wr_release( lock_xp );
    23962413        return -1;
    23972414    }
     
    24032420    {
    24042421        printk("\n[ERROR] in %s : cannot update free cluster info\n", __FUNCTION__ );
    2405         remote_queuelock_acquire( lock_xp );
     2422        remote_rwlock_wr_release( lock_xp );
    24062423        return -1;
    24072424    }
     
    24162433    {
    24172434        printk("\n[ERROR] in %s : cannot update FAT on IOC device\n", __FUNCTION__ );
    2418         remote_queuelock_acquire( lock_xp );
     2435        remote_rwlock_wr_release( lock_xp );
    24192436        return -1;
    24202437    }
    24212438
    2422     // release free clusters busylock
    2423     remote_queuelock_release( lock_xp );
     2439    // release FAT lock
     2440    remote_rwlock_wr_release( lock_xp );
    24242441
    24252442#if DEBUG_FATFS_CLUSTER_ALLOC
     
    24922509    fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) );
    24932510
    2494     // get extended pointer on free clusters lock in FAT cluster
    2495     lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->free_lock );
    2496 
    2497     // take lock protecting free clusters
    2498     remote_queuelock_acquire( lock_xp );
     2511    // get extended pointer on FAT lock in FAT cluster
     2512    lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->lock );
     2513
     2514    // take FAT lock in write mode
     2515    remote_rwlock_wr_acquire( lock_xp );
    24992516
    25002517    // call the recursive function to release all clusters from FAT mapper
     
    25052522    {
    25062523        printk("\n[ERROR] in %s : cannot update FAT mapper\n", __FUNCTION__ );
    2507         remote_queuelock_release( lock_xp );
     2524        remote_rwlock_wr_release( lock_xp );
    25082525        return -1;
    25092526    }
    2510 
    2511     // release lock protecting free cluster
    2512     remote_queuelock_release( lock_xp );
    25132527
    25142528#if (DEBUG_FATFS_RELEASE_INODE & 1)
     
    25212535    {
    25222536        printk("\n[ERROR] in %s : cannot update FAT on device\n", __FUNCTION__ );
     2537        remote_rwlock_wr_release( lock_xp );
    25232538        return -1;
    25242539    }
     
    25332548    {
    25342549        printk("\n[ERROR] in %s: cannot update FS_INFO on device\n", __FUNCTION__ );
     2550        remote_rwlock_wr_release( lock_xp );
    25352551        return -1;
    25362552    }
     2553
     2554    // release FAT lock
     2555    remote_rwlock_wr_release( lock_xp );
    25372556
    25382557#if DEBUG_FATFS_RELEASE_INODE
  • trunk/kernel/fs/fatfs.h

    r626 r627  
    3232
    3333
    34 ///////////////////////////////////////////////////////////////////////////////////////////
    35 // The FATFS File System implements a FAT32 read/write file system.
    36 //
    37 // The FATFS specific extensions to the generic VFS are the following:
    38 //
    39 // 1) The vfs_ctx_t "extend" field is a void* pointing on the fatfs_ctx_t structure.
    40 //    This structure contains various general informations such as the total
    41 //    number of sectors in FAT region, the number of bytes per sector, the number
    42 //    of sectors per cluster, the lba of FAT region, the lba of data region, or the
    43 //    cluster index for the root directory. It contains also an extended pointer
    44 //    on the FAT mapper.
    45 //
    46 // 2) The vfs_inode_t "extend" contains, for each inode,
    47 //    the first FAT cluster index (after cast to intptr).
    48 //
    49 // 3) The vfs_dentry_t "extend" field contains, for each dentry, the entry index
    50 //    in the FATFS directory (32 bytes per FATFS entry).
     34/**************************************************************************************
     35 * The FATFS File System implements a FAT32 read/write file system.
     36 *
     37 * The FATFS specific extensions to the generic VFS are the following:
     38 * 1) The vfs_ctx_t "extend" field is a void* pointing on the fatfs_ctx_t structure.
     39 *    This structure contains various general informations such as the total
     40 *    number of sectors in FAT region, the number of bytes per sector, the number
     41 *    of sectors per cluster, the lba of FAT region, the lba of data region, or the
     42 *    cluster index for the root directory. It contains also an extended pointer
     43 *    on the FAT mapper.
     44 * 2) The vfs_inode_t "extend" contains, for each inode,
     45 *    the first FAT cluster index (after cast to intptr).
     46 * 3) The vfs_dentry_t "extend" field contains, for each dentry, the entry index
     47 *    in the FATFS directory (32 bytes per FATFS entry).
     48 *************************************************************************************/
     49 
    5150///////////////////////////////////////////////////////////////////////////////////////////
    5251
     
    175174 * This fatfs context is replicated in all clusters.
    176175 *
    177  * WARNING : Almost all fields are constant values, but the <free_cluster_hint>,
    178  * <free_clusters> and <free_lock> are shared variables. Moreover, the <fs_info_buffer>,
    179  * only allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all
     176 * WARNING 1 : All access to the FAT are protected by a remote_rwlock.
     177 * - it is taken in READ mode by the fatfs_get_cluster() function to scan the
     178 *   linked list associated to a given inode.
     179 * - it is taken in WRITE mode by the fatfs_cluster_alloc() and fatfs_release_inode()
     180 *   functions to modify the FAT in both the FAT mapper and on IOC device.
     181 *
     182 * WARNING é : Almost all fields are constant values, but the <free_cluster_hint>,
     183 * <free_clusters> and <lock> are shared variables. The <fs_info_buffer>, only
     184 * allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all
    180185 * kernel instances to synchronously update the free clusters info on IOC device.
    181186 * For these four variables, all kernel instances must use the values in cluster 0,
    182  * and take the <free_lock> stored in this cluster for exclusive access to FAT.
     187 * containing the FAT mapper.
    183188 ****************************************************************************************/
    184189
     
    198203    uint32_t            free_cluster_hint;     /*! cluster[hint+1] is the first free    */
    199204    uint32_t            free_clusters;         /*! free clusters number                 */
    200     remote_queuelock_t  free_lock;             /*! exclusive access to FAT              */
     205    remote_rwlock_t     lock;                  /*! exclusive access to FAT              */
    201206    uint8_t           * fs_info_buffer;        /*! local pointer on FS_INFO buffer      */
    202207}
  • trunk/kernel/kern/cluster.c

    r593 r627  
    700700    xptr_t        txt0_xp;
    701701    xptr_t        txt0_lock_xp;
     702    uint32_t      pref_nr;       // number of owned processes in cluster cxy
    702703
    703704assert( (cluster_is_undefined( cxy ) == false), "illegal cluster index" );
     
    707708    lock_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_lock );
    708709
     710    // get number of owned processes in cluster cxy
     711    pref_nr = hal_remote_l32( XPTR( cxy , &LOCAL_CLUSTER->pmgr.pref_nr ) );
     712
     713    // display nothing if no user process in cluster cxy
     714    if( (owned != false) && (pref_nr < 2) ) return;
     715   
    709716    // get pointers on TXT0 chdev
    710717    txt0_xp  = chdev_dir.txt_tx[0];
     
    721728    remote_busylock_acquire( txt0_lock_xp );
    722729     
    723     // display header
    724730    nolock_printk("\n***** processes in cluster %x / cycle %d\n",
    725731    cxy , (uint32_t)hal_get_cycles() );
  • trunk/kernel/libk/remote_rwlock.c

    r626 r627  
    22 * remote_rwlock.c - kernel remote read/write lock implementation.
    33 *
    4  * Authors    Alain   Greiner (2016,2017,2018)
     4 * Authors    Alain   Greiner (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/libk/remote_rwlock.h

    r563 r627  
    22 * remote_rwlock.h - kernel remote read/writelock definition.
    33 *
    4  * Authors   Alain Greiner   (2016,2017,2018)
     4 * Authors   Alain Greiner   (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
Note: See TracChangeset for help on using the changeset viewer.