Changeset 626 for trunk/kernel/devices


Ignore:
Timestamp:
Apr 29, 2019, 7:25:09 PM (5 years ago)
Author:
alain
Message:

This version has been tested on the sort multithreaded application
for TSAR_IOB architectures ranging from 1 to 8 clusters.
It fixes three bigs bugs:
1) the dev_ioc device API has been modified: the dev_ioc_sync_read()
and dev_ioc_sync_write() function use now extended pointers on the
kernel buffer to access a mapper stored in any cluster.
2) the hal_uspace API has been modified: the hal_copy_to_uspace()
and hal_copy_from_uspace() functions use now a (cxy,ptr) couple
to identify the target buffer (equivalent to an extended pointer.
3) an implementation bug has been fixed in the assembly code contained
in the hal_copy_to_uspace() and hal_copy_from_uspace() functions.

Location:
trunk/kernel/devices
Files:
5 edited

Legend:

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

    r619 r626  
    22 * dev_ioc.c - IOC (Block Device Controler) generic device API implementation.
    33 *
    4  * Author  Alain Greiner    (2016,2017,2018)
     4 * Author  Alain Greiner    (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3636
    3737extern chdev_directory_t  chdev_dir;     // allocated in kernel_init.c
     38
     39////////////////////////////////////////
     40char * dev_ioc_cmd_str( cmd_type_t cmd )
     41{
     42    if     ( cmd == IOC_READ       )  return "READ";
     43    else if( cmd == IOC_WRITE      )  return "WRITE";
     44    else if( cmd == IOC_SYNC_READ  )  return "SYNC_READ";
     45    else if( cmd == IOC_SYNC_WRITE )  return "SYNC_WRITE";
     46    else                              return "undefined";
     47}
    3848
    3949//////////////////////////////////
     
    192202////////////////////////////////////i/////////////////////////////////////////////
    193203error_t dev_ioc_sync_access( uint32_t   cmd_type,
    194                              uint8_t  * buffer,
     204                             xptr_t     buffer_xp,
    195205                             uint32_t   lba,
    196206                             uint32_t   count )
     
    202212    if( chdev_dir.iob )
    203213    {
    204         if (cmd_type == IOC_SYNC_READ) dev_mmc_inval( XPTR(local_cxy,buffer) , count<<9 );
    205         else                           dev_mmc_sync ( XPTR(local_cxy,buffer) , count<<9 );
     214        if (cmd_type == IOC_SYNC_READ) dev_mmc_inval( buffer_xp , count<<9 );
     215        else                           dev_mmc_sync ( buffer_xp , count<<9 );
    206216    }
    207217
     
    215225    this->ioc_cmd.dev_xp    = ioc_xp;
    216226    this->ioc_cmd.type      = cmd_type;
    217     this->ioc_cmd.buf_xp    = XPTR( local_cxy , buffer );
     227    this->ioc_cmd.buf_xp    = buffer_xp;
    218228    this->ioc_cmd.lba       = lba;
    219229    this->ioc_cmd.count     = count;
     
    241251    return this->ioc_cmd.error;
    242252
    243 }  // end ioc_sync_access()
    244 
    245 /////////////////////////////////////////////
    246 error_t dev_ioc_sync_read( uint8_t  * buffer,
     253}  // end dev_ioc_sync_access()
     254
     255////////////////////////////////////////////////
     256error_t dev_ioc_sync_read( xptr_t     buffer_xp,
    247257                           uint32_t   lba,
    248258                           uint32_t   count )
     
    253263uint32_t   cycle = (uint32_t)hal_get_cycles();
    254264if( DEBUG_DEV_IOC_RX < cycle )
    255 printk("\n[%s] thread[%x,%x] : lba  %x / buffer %x / cycle %d\n",
    256 __FUNCTION__ , this->process->pid, this->trdid, lba, buffer, cycle );
    257 #endif
    258 
    259     return dev_ioc_sync_access( IOC_SYNC_READ , buffer , lba , count );
     265printk("\n[%s] thread[%x,%x] : lba  %x / buffer(%x,%x) / count %d / cycle %d\n",
     266__FUNCTION__ , this->process->pid, this->trdid,
     267lba, GET_CXY(buffer_xp), GET_PTR(buffer_xp), count, cycle );
     268#endif
     269
     270    return dev_ioc_sync_access( IOC_SYNC_READ , buffer_xp , lba , count );
    260271}
    261272
    262 //////////////////////////////////////////////
    263 error_t dev_ioc_sync_write( uint8_t  * buffer,
     273/////////////////////////////////////////////////
     274error_t dev_ioc_sync_write( xptr_t     buffer_xp,
    264275                            uint32_t   lba,
    265276                            uint32_t   count )
    266277{
    267278
    268 #if DEBUG_DEV_IOC_RX
    269 thread_t * this  = CURRENT_THREAD;
    270 uint32_t   cycle = (uint32_t)hal_get_cycles();
    271 if( DEBUG_DEV_IOC_RX < cycle )
    272 printk("\n[%s] thread[%x,%x] enters / lba  %x / buffer %x / cycle %d\n",
    273 __FUNCTION__ , this->process->pid, this->trdid, lba, buffer, cycle );
    274 #endif
    275 
    276     return dev_ioc_sync_access( IOC_SYNC_WRITE , buffer , lba , count );
     279#if DEBUG_DEV_IOC_TX
     280thread_t * this  = CURRENT_THREAD;
     281uint32_t   cycle = (uint32_t)hal_get_cycles();
     282if( DEBUG_DEV_IOC_TX < cycle )
     283printk("\n[%s] thread[%x,%x] : lba  %x / buffer(%x,%x) / count %d / cycle %d\n",
     284__FUNCTION__ , this->process->pid, this->trdid,
     285lba, GET_CXY(buffer_xp), GET_PTR(buffer_xp), count, cycle );
     286#endif
     287
     288    return dev_ioc_sync_access( IOC_SYNC_WRITE , buffer_xp , lba , count );
    277289}
    278290
  • trunk/kernel/devices/dev_ioc.h

    r614 r626  
    22 * dev_ioc.h - IOC (Block Device Controler) generic device API definition.
    33 *
    4  * Author  Alain Greiner    (2016,2017,2018)
     4 * Author  Alain Greiner    (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    4444 * - SYNC_WRITE : move blocks from memory to device, with a busy waiting policy.
    4545
    46  * A READ or WRITE operation requires dynamic ressource allocation. The calling thread
     46 * The READ or WRITE operations require dynamic ressource allocation. The calling thread
    4747 * is descheduled, and the work is done by the server thread associated to IOC device.
    4848 * The general scenario is detailed below.
     
    6666 *
    6767 * The SYNC_READ and SYNC_WRITE operations are used by the kernel in the initialisation
    68  * phase. These operations do not not use the IOC device waiting queue, the server thread,
    69  * and the IOC IRQ, but implement a busy-waiting policy for the calling thread.
     68 * phase, to update the FAT (both the FAT mapper and the FAT on IOC device), or to update
     69 * a directory on IOC device when a new file is created.
     70 * - These synchronous operations do not not use the IOC device waiting queue,
     71 *   the server thread, and the IOC IRQ, but implement a busy-waiting policy
     72 *   for the calling thread.
     73 * - As the work
    7074 *****************************************************************************************/
    7175
     
    119123}
    120124ioc_command_t;
     125
     126/******************************************************************************************
     127 * This function returns a printable string for a IOC command type.
     128 ******************************************************************************************
     129 * @ cmd  : command type.
     130 * @ return pointer on string.
     131 *****************************************************************************************/
     132char * dev_ioc_cmd_str( cmd_type_t cmd );
    121133
    122134/******************************************************************************************
     
    138150 * registered in the device pending request queue, and the calling thread is descheduled,
    139151 * waiting on transfer completion. It will be resumed by the IRQ signaling completion.
    140  * It must be called in the client cluster.
     152 * It must be called by a local thread.
    141153 ******************************************************************************************
    142154 * @ buffer    : local pointer on target buffer in memory (must be block aligned).
    143155 * @ lba       : first block index on device.
    144156 * @ count     : number of blocks to transfer.
    145  * @ returns 0 if success / returns EINVAL if error.
     157 * @ returns 0 if success / returns -1 if error.
    146158 *****************************************************************************************/
    147159error_t dev_ioc_read( uint8_t      * buffer,
     
    154166 * registered in the device pending request queue, and the calling thread is descheduled,
    155167 * waiting on transfer completion. It will be resumed by the IRQ signaling completion.
    156  * It must be called in the client cluster.
     168 * It must be called by a local thread.
    157169 ******************************************************************************************
    158170 * @ buffer    : local pointer on source buffer in memory (must be block aligned).
    159171 * @ lba       : first block index on device.
    160172 * @ count     : number of blocks to transfer.
    161  * @ returns 0 if success / returns EINVAL if error.
     173 * @ returns 0 if success / returns -1 if error.
    162174 *****************************************************************************************/
    163175error_t dev_ioc_write( uint8_t      * buffer,
     
    167179/******************************************************************************************
    168180 * This blocking function moves one or several contiguous blocks of data
    169  * from the block device to a local memory buffer.
     181 * from the block device to a - possibly remote - memory buffer.
    170182 * It does  not uses the IOC device waiting queue and server thread, and does not use
    171183 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
    172184 * policy for the calling thread.
    173  * It must be called in the client cluster.
    174  ******************************************************************************************
    175  * @ buffer    : local pointer on target buffer in memory (must be block aligned).
    176  * @ lba       : first block index on device.
    177  * @ count     : number of blocks to transfer.
    178  * @ returns 0 if success / returns EINVAL if error.
    179  *****************************************************************************************/
    180 error_t dev_ioc_sync_read( uint8_t      * buffer,
     185 * It can be called by a thread running in any cluster.
     186 ******************************************************************************************
     187 * @ buffer_xp : extended pointer on target buffer in memory (must be block aligned).
     188 * @ lba       : first block index on device.
     189 * @ count     : number of blocks to transfer.
     190 * @ returns 0 if success / returns -1 if error.
     191 *****************************************************************************************/
     192error_t dev_ioc_sync_read( xptr_t         buffer_xp,
    181193                           uint32_t       lba,
    182194                           uint32_t       count );
     
    184196/******************************************************************************************
    185197 * This blocking function moves one or several contiguous blocks of data
    186  * from a local memory buffer to the block device.
     198 * from a - possibly remote - memory buffer to the block device.
    187199 * It does  not uses the IOC device waiting queue and server thread, and does not use
    188200 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting
    189201 * policy for the calling thread.
    190  * It must be called in the client cluster.
    191  ******************************************************************************************
    192  * @ buffer    : local pointer on source buffer in memory (must be block aligned).
    193  * @ lba       : first block index on device.
    194  * @ count     : number of blocks to transfer.
    195  * @ returns 0 if success / returns EINVAL if error.
    196  *****************************************************************************************/
    197 error_t dev_ioc_sync_write( uint8_t      * buffer,
     202 * It can be called by a thread running in any cluster.
     203 ******************************************************************************************
     204 * @ buffer_xp : extended pointer on source buffer in memory (must be block aligned).
     205 * @ lba       : first block index on device.
     206 * @ count     : number of blocks to transfer.
     207 * @ returns 0 if success / returns -1 if error.
     208 *****************************************************************************************/
     209error_t dev_ioc_sync_write( xptr_t         buffer_xp,
    198210                            uint32_t       lba,
    199211                            uint32_t       count );
  • trunk/kernel/devices/dev_mmc.c

    r605 r626  
    108108
    109109    // get buffer cluster and local pointer
    110     cxy_t  buf_cxy = GET_CXY( buf_xp );
    111     void * buf_ptr = GET_PTR( buf_xp );
     110    cxy_t     buf_cxy = GET_CXY( buf_xp );
     111    uint8_t * buf_ptr = GET_PTR( buf_xp );
    112112   
    113     assert( (((intptr_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) ,
    114              "buffer not aligned on cache line" );
     113    // force buffer align
     114    uint32_t  delta = (uint32_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE - 1);
     115    uint8_t * base  = buf_ptr - delta;
     116    uint32_t  size  = buf_size + delta;
    115117
    116118    // store command arguments in thread descriptor
    117119    this->mmc_cmd.dev_xp    = chdev_dir.mmc[buf_cxy];
    118120    this->mmc_cmd.type      = MMC_CC_INVAL;
    119     this->mmc_cmd.buf_ptr   = buf_ptr;
    120     this->mmc_cmd.buf_size  = buf_size;
     121    this->mmc_cmd.buf_ptr   = base;
     122    this->mmc_cmd.buf_size  = size;
    121123
    122124    // call MMC driver
     
    152154    void * buf_ptr = GET_PTR( buf_xp );
    153155   
    154     assert( (((intptr_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) ,
    155              "buffer not aligned on cache line" );
     156    // force buffer align
     157    uint32_t  delta = (uint32_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE - 1);
     158    uint8_t * base  = buf_ptr - delta;
     159    uint32_t  size  = buf_size + delta;
    156160
    157161    // store command arguments in thread descriptor
    158162    this->mmc_cmd.dev_xp    = chdev_dir.mmc[buf_cxy];
    159163    this->mmc_cmd.type      = MMC_CC_SYNC;
    160     this->mmc_cmd.buf_ptr   = buf_ptr;
    161     this->mmc_cmd.buf_size  = buf_size;
     164    this->mmc_cmd.buf_ptr   = base;
     165    this->mmc_cmd.buf_size  = size;
    162166
    163167    // call MMC driver
  • trunk/kernel/devices/dev_txt.c

    r619 r626  
    22 * dev_txt.c - TXT (Text Terminal) generic device API implementation.
    33 *
    4  * Author  Alain Greiner    (2016,2017,2018)
     4 * Author  Alain Greiner    (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/devices/dev_txt.h

    r565 r626  
    22 * dev_txt.h - TXT (Text Terminal) generic device API definition.
    33 *
    4  * Author  Alain Greiner    (2016)
     4 * Author  Alain Greiner    (2016,2017,2018,2019))
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    106106    const char * buffer;    /*! local pointer on characters array                        */
    107107    uint32_t     count;     /*! number of characters in buffer                           */
    108     uint32_t    channel;   /*! channel, aka which tty to write to                        */
     108    uint32_t     channel;   /*! channel, aka which tty to write to                       */
    109109}
    110110txt_sync_args_t;
    111111
    112112/******************************************************************************************
    113  * This function returns a printable string for the comman type.
     113 * This function returns a printable string for the command type.
    114114 ******************************************************************************************
    115115 * @ type     : command type (TXT_READ / TXT_WRITE / TXT_SYNC_WRITE)
     
    166166 * interfering with another possible TXT access to another terminal.
    167167 * As it is used for debug, the command arguments <buffer> and <count> are registerd
    168  * in a specific "dbg_cmd" field of the calling thread.
     168 * in a specific "txt_syc_args_t" structure passed to the driver "aux" function.
    169169 ****************************************************************************************
    170170 * @ buffer    : local pointer on source buffer containing the string.
Note: See TracChangeset for help on using the changeset viewer.