Ignore:
Timestamp:
Nov 10, 2018, 3:06:00 PM (6 years ago)
Author:
alain
Message:

1) Modify the devfs_user_move() function to support large user buffer transfer to/from TXT device.
2) Cosmetic: Improve debug.

File:
1 edited

Legend:

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

    r568 r598  
    104104
    105105#if DEBUG_DEVFS_INIT
    106 uint32_t cycle = (uint32_t)hal_get_cycles();
    107 if( DEBUG_DEVFS_INIT < cycle )
    108 printk("\n[DBG] %s : thread %x in process %x created <dev> inode / cycle %d\n",
    109 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ,cycle );
     106uint32_t   cycle = (uint32_t)hal_get_cycles();
     107thread_t * this  = CURRENT_THREAD;
     108if( DEBUG_DEVFS_INIT < cycle )
     109printk("\n[%s] thread[%x,%x] created <dev> inode / cycle %d\n",
     110__FUNCTION__, this->process->pid, this->trdid, cycle );
    110111#endif
    111112
     
    124125cycle = (uint32_t)hal_get_cycles();
    125126if( DEBUG_DEVFS_INIT < cycle )
    126 printk("\n[DBG] %s : thread %x in process %x created <external> inode / cycle %d\n",
    127 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid , cycle );
     127printk("\n[%s] thread[%x,%x] created <external> inode / cycle %d\n",
     128__FUNCTION__, this->process->pid, this->trdid, cycle );
    128129#endif
    129130
     
    152153                             devfs_internal_inode_xp );
    153154#if DEBUG_DEVFS_INIT
    154 uint32_t cycle = (uint32_t)hal_get_cycles();
    155 trdid_t  trdid = CURRENT_THREAD->trdid;
    156 pid_t    pid   = CURRENT_THREAD->process->pid;
    157 if( DEBUG_DEVFS_INIT < cycle )
    158 printk("\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 );
     155uint32_t   cycle = (uint32_t)hal_get_cycles();
     156thread_t * this  = CURRENT_THREAD;
     157if( DEBUG_DEVFS_INIT < cycle )
     158printk("\n[%s] thread[%x,%x] created <%s> inode in cluster %x / cycle %d\n",
     159__FUNCTION__, this->process->pid, this->trdid, node_name, local_cxy, cycle );
    160160#endif
    161161
     
    175175cycle = (uint32_t)hal_get_cycles();
    176176if( DEBUG_DEVFS_INIT < cycle )
    177 printk("\n[DBG] %s : thread %x in process %x created <mmc> inode in cluster %x\n",
    178 __FUNCTION__, trdid, pid, local_cxy, cycle );
     177printk("\n[%s] thread[%x,%x] created <mmc> inode in cluster %x\n",
     178__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
    179179#endif
    180180
     
    198198cycle = (uint32_t)hal_get_cycles();
    199199if( DEBUG_DEVFS_INIT < cycle )
    200 printk("\n[DBG] %s : thread %x in process %x created <dma[%d]> inode in cluster %x\n",
    201 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     200printk("\n[%s] thread [%x,%x] created <dma[%d]> inode in cluster %x\n",
     201__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    202202#endif
    203203        }
     
    222222cycle = (uint32_t)hal_get_cycles();
    223223if( DEBUG_DEVFS_INIT < cycle )
    224 printk("\n[DBG] %s : thread %x in process %x created <iob> inode in cluster %x\n",
    225 __FUNCTION__, trdid, pid, local_cxy, cycle );
     224printk("\n[%s] thread[%x,%x] created <iob> inode in cluster %x\n",
     225__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
    226226#endif
    227227        }
     
    246246cycle = (uint32_t)hal_get_cycles();
    247247if( DEBUG_DEVFS_INIT < cycle )
    248 printk("\n[DBG] %s : thread %x in process %x created <pic> inode in cluster %x\n",
    249 __FUNCTION__, trdid, pid, local_cxy, cycle );
     248printk("\n[%s] thread[%x,%x] created <pic> inode in cluster %x\n",
     249__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
    250250#endif
    251251        }
     
    272272cycle = (uint32_t)hal_get_cycles();
    273273if( DEBUG_DEVFS_INIT < cycle )
    274 printk("\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 );
     274printk("\n[%s] thread[%x,%x] created <txt_rx[%d]> inode in cluster %x\n",
     275__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    276276#endif
    277277            }
     
    299299cycle = (uint32_t)hal_get_cycles();
    300300if( DEBUG_DEVFS_INIT < cycle )
    301 printk("\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 );
     301printk("\n[%s] thread[%x,%x] created <txt_tx[%d]> inode in cluster %x\n",
     302__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    303303#endif
    304304            }
     
    326326cycle = (uint32_t)hal_get_cycles();
    327327if( DEBUG_DEVFS_INIT < cycle )
    328 printk("\n[DBG] %s : thread %x in process %x created <ioc[%d]> inode in cluster %x\n",
    329 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     328printk("\n[%s] thread[%x,%x] created <ioc[%d]> inode in cluster %x\n",
     329__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    330330#endif
    331331            }
     
    353353cycle = (uint32_t)hal_get_cycles();
    354354if( DEBUG_DEVFS_INIT < cycle )
    355 printk("\n[DBG] %s : thread %x in process %x created <fbf[%d]> inode in cluster %x\n",
    356 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     355printk("\n[%s] thread[%x,%x] created <fbf[%d]> inode in cluster %x\n",
     356__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    357357#endif
    358358            }
     
    380380cycle = (uint32_t)hal_get_cycles();
    381381if( DEBUG_DEVFS_INIT < cycle )
    382 printk("\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 );
     382printk("\n[%s] thread[%x,%x] created <nic_rx[%d]> inode in cluster %x\n",
     383__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    384384#endif
    385385            }
     
    407407cycle = (uint32_t)hal_get_cycles();
    408408if( DEBUG_DEVFS_INIT < cycle )
    409 printk("\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 );
     409printk("\n[%s] thread[%x,%x] created <nic_tx[%d]> inode in cluster %x\n",
     410__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    411411#endif
    412412            }
     
    418418int devfs_user_move( bool_t     to_buffer,
    419419                     xptr_t     file_xp,
    420                      void     * u_buf,
     420                     char     * u_buf,
    421421                     uint32_t   size )
    422422{
    423     assert( ( file_xp != XPTR_NULL ) , "file_xp == XPTR_NULL" );
    424 
    425     assert( ( size < CONFIG_TXT_KBUF_SIZE ) , "string size too large" );
    426 
    427     xptr_t             chdev_xp;
    428     cxy_t              chdev_cxy;
    429     chdev_t          * chdev_ptr;    // associated chdev type
    430     uint32_t           func;         // chdev functionnal type
    431     uint32_t           channel;      // chdev channel index
    432     error_t            error;
    433 
    434     char               k_buf[CONFIG_TXT_KBUF_SIZE];  // local kernel buffer
     423    xptr_t           chdev_xp;
     424    cxy_t            chdev_cxy;
     425    chdev_t        * chdev_ptr;                    // associated chdev type
     426    uint32_t         func;                         // chdev functionnal type
     427    uint32_t         channel;                      // chdev channel index
     428    uint32_t         burst;                        // number of bytes in a burst
     429    uint32_t         todo;                         // number of bytes not yet moved
     430    error_t          error;
     431    uint32_t         i;
     432
     433    char             k_buf[CONFIG_TXT_KBUF_SIZE];  // local kernel buffer
     434
     435assert( ( file_xp != XPTR_NULL ) , "file_xp == XPTR_NULL" );
    435436
    436437#if (DEBUG_SYS_READ & 1)
     
    443444
    444445#if DEBUG_DEVFS_MOVE
    445 uint32_t cycle = (uint32_t)hal_get_cycles();
     446uint32_t   cycle = (uint32_t)hal_get_cycles();
     447thread_t * this  = CURRENT_THREAD;
    446448if( DEBUG_DEVFS_MOVE < cycle )
    447 printk("\n[DBG] %s : thread %x enter / to_mem %d / cycle %d\n",
    448 __FUNCTION__ , CURRENT_THREAD , to_buffer , cycle );
     449printk("\n[%s] thread[%x,%x] enter / to_mem %d / cycle %d\n",
     450__FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle );
    449451#endif
    450452
     
    460462    channel = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    461463
    462     // action depends on "func" and "to_buffer"
    463     if( func == DEV_FUNC_TXT )
    464     {
    465         if( to_buffer )     // TXT read
    466         {
    467             uint32_t i;
    468             for( i = 0 ; i < size ; i++ )
     464assert( ( func == DEV_FUNC_TXT ) , __FUNCTION__, "illegal device func_type");
     465
     466    // initialise number of bytes to move
     467    todo = size;
     468
     469    /////////////// TXT read
     470    if( to_buffer )
     471    {
     472        while( todo )
     473        {
     474            // set burst size
     475            if( todo > CONFIG_TXT_KBUF_SIZE ) burst = CONFIG_TXT_KBUF_SIZE;
     476            else                              burst = todo;
     477
     478            // read burst bytes from TXT device to kernel buffer
     479            for( i = 0 ; i < burst ; i++ )
    469480            {
    470481                error = dev_txt_read( channel , &k_buf[i] );
    471482
    472                 if( error )
    473                 {
    474                     return -1;
    475                 }
    476                 else
    477                 {
    478                     hal_strcpy_to_uspace( u_buf , k_buf , size );
    479                 }
    480              }
     483                if( error )  return -1;
     484            }
     485
     486            // move burst bytes from k_buf to u_buf                   
     487            hal_strcpy_to_uspace( u_buf , k_buf , burst );
     488
     489            // update loop variables
     490            todo  -= burst;
     491            u_buf += burst;
     492        }
    481493
    482494#if DEBUG_DEVFS_MOVE
    483495cycle = (uint32_t)hal_get_cycles();
    484496if( DEBUG_DEVFS_MOVE < cycle )
    485 printk("\n[DBG] %s : thread %x exit / to_mem %d / cycle %d\n",
    486 __FUNCTION__ , CURRENT_THREAD , to_buffer / cycle );
     497printk("\n[%s] thread[%x,%x] exit / to_mem %d / cycle %d\n",
     498__FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle );
    487499#endif
    488500
     
    491503#endif
    492504            return size;
     505    }
     506    ///////////// TXT write 
     507    else               
     508    {
     509        while( todo )
     510        {
     511            // set burst size
     512            if( todo > CONFIG_TXT_KBUF_SIZE ) burst = CONFIG_TXT_KBUF_SIZE;
     513            else                              burst = todo;
     514
     515            // move burst bytes from u_buf to k_buf
     516            hal_strcpy_from_uspace( k_buf , u_buf , burst );
     517
     518            // write burst bytes from kernel buffer to TXT device
     519            error = dev_txt_write( channel , k_buf , burst );
     520
     521            if( error ) return -1;
     522
     523            // update loop variables
     524            todo  -= burst;
     525            u_buf += burst;
    493526        }
    494         else                // TXT write 
    495         {
    496             hal_strcpy_from_uspace( k_buf , u_buf , size );
    497 
    498             error = dev_txt_write( channel , k_buf , size );
    499             if( error )
    500             {
    501                 return -1;
    502             }
    503             else
    504             {
    505527
    506528#if DEBUG_DEVFS_MOVE
    507529cycle = (uint32_t)hal_get_cycles();
    508530if( DEBUG_DEVFS_MOVE < cycle )
    509 printk("\n[DBG] %s : thread %x exit / to_mem %d / cycle %d\n",
    510 __FUNCTION__ , CURRENT_THREAD , to_buffer / cycle );
     531printk("\n[%s] thread[%x,%x] exit / to_mem %d / cycle %d\n",
     532__FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle );
    511533#endif
    512534
     
    514536exit_devfs_write = hal_time_stamp();
    515537#endif
    516                 return size;
    517             }
    518         }
    519     }
    520     else
    521     {
    522         assert( false , "%s does not support direct user access",
    523           chdev_func_str(func) );
    524 
    525         return -1;
     538            return size;
    526539    }
    527540
Note: See TracChangeset for help on using the changeset viewer.