Ignore:
Timestamp:
Jul 18, 2019, 2:06:55 PM (3 years ago)
Author:
alain
Message:

Introduce the non-standard pthread_parallel_create() system call
and re-write the <fft> and <sort> applications to improve the
intrinsic paralelism in applications.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/core/hal_uspace.c

    r626 r637  
    3232///////////////////////////////////////////////////////////////////////////////////////
    3333// This function moves <size> bytes from a source buffer in user virtual space,
    34 // defined by the <u_src> argument, to a destination kernel buffer, defined by the
    35 // <k_cxy> and <k_dst> arguments.
    36 // It works in a critical section, as it modifies briefly two CP2 registers:
     34// defined by the <u_src_ptr> argument, to a destination kernel buffer, defined by the
     35// <k_dst_xp> argument.
     36// It works in a critical section, as it modifies two CP2 registers:
    3737// It activates briefly the DATA_MMU by writing into the CP2_MODE register to access the
    3838// user buffer, and modifies the CP2_DATA_EXT register to access the kernel buffer.
     
    4141// If the buffers are not aligned, it moves all data byte per byte.
    4242///////////////////////////////////////////////////////////////////////////////////////
    43 // @ k_cxy    : cluster of destination kernel buffer
    44 // @ k_dst    : pointer on destination kernel buffer
    45 // @ u_src    : pointer on source user buffer
     43// @ k_dst_xp  : extended pointer on destination kernel buffer
     44// @ u_src_ptr : pointer on source user buffer
    4645// @ size     : number of bytes to move
    4746///////////////////////////////////////////////////////////////////////////////////////
    48 void hal_copy_from_uspace( cxy_t      k_cxy,
    49                            void     * k_dst,
    50                            void     * u_src,
     47void hal_copy_from_uspace( xptr_t     k_dst_xp,
     48                           void     * u_src_ptr,
    5149                           uint32_t   size ) 
    5250{
    5351    uint32_t save_sr;
    54         uint32_t words;                        // number of words (if buffers aligned)
    55     uint32_t src = (uint32_t)u_src;
    56     uint32_t dst = (uint32_t)k_dst;
     52        uint32_t words;                            // number of words (if buffers aligned)
     53    uint32_t src = (uint32_t)u_src_ptr;
     54    uint32_t dst = (uint32_t)GET_PTR( k_dst_xp );
     55    uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp );
     56   
    5757 
    5858#if DEBUG_HAL_USPACE
     
    6161if( cycle > DEBUG_HAL_USPACE )
    6262printk("\n[%s] thread[%x,%x] enter / %d bytes / u_buf(%x,%x) -> k_buf(%x,%x) / cycle %d\n",
    63 __FUNCTION__, this->process->pid, this->trdid, size, local_cxy, u_src, k_cxy, k_dst, cycle );
     63__FUNCTION__, this->process->pid, this->trdid, size, local_cxy, src, cxy, dst, cycle );
    6464#endif
    6565
     
    8080                  "ori    $13,   $12,   0x4       \n"   /* $13 <= MMU_MODE with DTLB  */
    8181
    82                   /* save old MMU_DATA_EXT and set k_cxy in it                    */
     82                  /* save old MMU_DATA_EXT and set cxy in it                      */
    8383                  "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT    */
    84                   "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= k_cxy      */
     84                  "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= cxy        */
    8585
    8686                  /* transfer one word per iteration in first loop if aligned     */
     
    118118                  ".set reorder               \n"
    119119                  :
    120                   : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(k_cxy)
     120                  : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(cxy)
    121121                  : "$8","$9","$10","$11","$12","$13","$14","$15","$16","memory" );
    122122
     
    128128if( cycle > DEBUG_HAL_USPACE )
    129129printk("\n[%s] thread[%x,%x] moved %d bytes / u_buf(%x,%x) -> k_buf(%x,%x) / cycle %d\n",
    130 __FUNCTION__, this->process->pid, this->trdid, size, local_cxy, u_src, k_cxy, k_dst, cycle );
     130__FUNCTION__, this->process->pid, this->trdid, size, local_cxy, src, cxy, dst, cycle );
    131131#endif
    132132
     
    135135///////////////////////////////////////////////////////////////////////////////////////
    136136// This function moves <size> bytes from a source kernel buffer, defined by the
    137 // <k_cxy> and <k_src> arguments, to a destination buffer in user virtual space,
    138 // defined by the <u_dst> argument.
    139 // It works in a critical section, as it modifies briefly two CP2 registers:
     137// <k_src_xp> argument, to a destination buffer in user virtual space, defined by
     138// the <u_dst_ptr> argument.
     139// It works in a critical section, as it modifies two CP2 registers:
    140140// It activates briefly the DATA_MMU by writing into the CP2_MODE register to access the
    141141// user buffer, and modifies the CP2_DATA_EXT register to access the kernel buffer.
     
    144144// If the buffers are not aligned, it moves all data byte per byte.
    145145///////////////////////////////////////////////////////////////////////////////////////
    146 // @ k_cxy    : cluster of destination kernel buffer
    147 // @ k_dst    : pointer on destination kernel buffer
    148 // @ u_src    : pointer on source user buffer
    149 // @ size     : number of bytes to move
    150 ///////////////////////////////////////////////////////////////////////////////////////
    151 void hal_copy_to_uspace( cxy_t      k_cxy,
    152                          void     * k_src,
    153                          void     * u_dst,
     146// @ u_dst_ptr : pointer on destination user buffer
     147// @ k_src_xp  : extended pointer on source kernel buffer
     148// @ size      : number of bytes to move
     149///////////////////////////////////////////////////////////////////////////////////////
     150void hal_copy_to_uspace( void     * u_dst_ptr,
     151                         xptr_t     k_src_xp,
    154152                         uint32_t   size )
    155153{
    156154    uint32_t save_sr;
    157         uint32_t words;                   // number of words (if buffers aligned)
    158     uint32_t src = (uint32_t)k_src;
    159     uint32_t dst = (uint32_t)u_dst;
     155        uint32_t words;                           // number of words (if buffers aligned)
     156    uint32_t dst = (uint32_t)u_dst_ptr;
     157    uint32_t src = (uint32_t)GET_PTR( k_src_xp );
     158    uint32_t cxy = (uint32_t)GET_CXY( k_src_xp );
    160159
    161160#if DEBUG_HAL_USPACE
     
    164163if( cycle > DEBUG_HAL_USPACE )
    165164printk("\n[%s] thread[%x,%x] enter / %d bytes / k_buf(%x,%x) -> u_buf(%x,%x) / cycle %d\n",
    166 __FUNCTION__, this->process->pid, this->trdid, size, k_cxy, k_src, local_cxy, u_dst, cycle );
     165__FUNCTION__, this->process->pid, this->trdid, size, cxy, src, local_cxy, dst, cycle );
    167166#endif
    168167
     
    183182                  "ori    $13,   $12,   0x4       \n"   /* $13 <= MMU_MODE with DTLB  */
    184183
    185                   /* save old MMU_DATA_EXT and set k_cxy in it                    */
     184                  /* save old MMU_DATA_EXT and set cxy in it                      */
    186185                  "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT    */
    187                   "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= k_cxy      */
     186                  "mtc2   %4,    $24          \n"   /* MMU_DATA_EXT <= cxy        */
    188187
    189188                  /* transfer one word per iteration in first loop if aligned     */
     
    221220                  ".set reorder               \n"
    222221                  :
    223                   : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(k_cxy)
     222                  : "r"(src) , "r"(dst) , "r"(words) , "r"(size) , "r"(cxy)
    224223                  : "$8","$9","$10","$11","$12","$13","$14","$15","$16","memory" );
    225224
     
    231230if( cycle > DEBUG_HAL_USPACE )
    232231printk("\n[%s] thread[%x,%x] moved %d bytes / k_buf(%x,%x) -> u_buf(%x,%x) / cycle %d\n",
    233 __FUNCTION__, this->process->pid, this->trdid, size, k_cxy, k_src, local_cxy, u_dst, cycle );
     232__FUNCTION__, this->process->pid, this->trdid, size, cxy, src, local_cxy, dst, cycle );
    234233#endif
    235234
    236235}  // end hal_copy_to_uspace()
    237236
    238 //////////////////////////////////////////////
    239 void hal_strcpy_from_uspace( char     * k_dst,
    240                              char     * u_src,
     237/////////////////////////////////////////////////
     238void hal_strcpy_from_uspace( xptr_t     k_dst_xp,
     239                             char     * u_src_ptr,
    241240                             uint32_t   size )
    242241{
    243242    uint32_t save_sr;
    244     uint32_t src = (uint32_t)u_src;
    245     uint32_t dst = (uint32_t)k_dst;
     243    uint32_t src = (uint32_t)u_src_ptr;
     244    uint32_t dst = (uint32_t)GET_PTR( k_dst_xp );
     245    uint32_t cxy = (uint32_t)GET_CXY( k_dst_xp );
    246246
    247247    hal_disable_irq( &save_sr );
    248248
    249249    // loop on characters while ( (character != NUL) and (count < size ) )
     250
    250251    asm volatile(
    251252        ".set noreorder             \n"
     253
     254        /* save old MMU_DATA_EXT and set cxy in it                          */
     255        "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT        */
     256        "mtc2   %3,    $24          \n"   /* MMU_DATA_EXT <= cxy            */
     257
    252258        "move   $11,   %0           \n"   /* $11 <= count == size           */
    253259        "move   $12,   %1           \n"   /* $12 <= u_src                   */
    254260        "move   $13,   %2           \n"   /* $13 <= k_dst                   */
    255         "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
    256         "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
     261        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
     262        "ori    $14,   $15,  0x4    \n"   /* $14 <= MMU_MODE / DTLB ON      */
     263
    257264        "1:                         \n"
    258265        "mtc2   $14,   $1                       \n"   /* MMU_MODE <= DTLB ON            */
    259266        "lb     $10,   0($12)       \n"   /* read char from user space      */
    260         "mtc2   $15,   $1                       \n"   /* restore DTLB and ITLB off      */
     267        "mtc2   $15,   $1                       \n"   /* MMU_MODE <= DTLB OFF           */
    261268            "sb     $10,   0($13)       \n"   /* store char to kernel space     */
    262269        "beq    $10,   $0,   2f     \n"   /* exit if char = 0               */
     
    268275        "2:                         \n"
    269276        "nop                        \n"
     277
     278        /* restore old MMU_DATA_EXT register                                */
     279        "mtc2   $16,   $24          \n"   /* MMU_DATA_EXT <= $16            */
     280
    270281        ".set reorder               \n"
    271282        :
    272         : "r"(size),"r"(src),"r"(dst)
    273         : "$10","$11","$12","$13","$14","$15" );
     283        : "r"(size) , "r"(src) , "r"(dst) , "r"(cxy)
     284        : "$10","$11","$12","$13","$14","$15","$16" );
    274285       
    275286    hal_restore_irq( save_sr );
     
    277288} // hal_strcpy_from_uspace()
    278289
    279 ////////////////////////////////////////////
    280 void hal_strcpy_to_uspace( char     * u_dst,
    281                            char     * k_src,
     290////////////////////////////////////////////////
     291void hal_strcpy_to_uspace( char     * u_dst_ptr,
     292                           xptr_t     k_src_xp,
    282293                           uint32_t   size )
    283294{
    284295    uint32_t save_sr;
    285     uint32_t src = (uint32_t)k_src;
    286     uint32_t dst = (uint32_t)u_dst;
     296    uint32_t dst = (uint32_t)u_dst_ptr;
     297    uint32_t src = (uint32_t)GET_PTR( k_src_xp );
     298    uint32_t cxy = (uint32_t)GET_CXY( k_src_xp );
    287299
    288300    hal_disable_irq( &save_sr );
    289301
    290302    // loop on characters while ( (character != NUL) and (count < size) )
     303
    291304    asm volatile(
    292305        ".set noreorder             \n"
     306
     307        /* save old MMU_DATA_EXT and set cxy in it                          */
     308        "mfc2   $16,   $24          \n"   /* $16 <= old MMU_DATA_EXT        */
     309        "mtc2   %3,    $24          \n"   /* MMU_DATA_EXT <= cxy            */
     310
    293311        "move   $11,   %0           \n"   /* $11 <= count == size           */
    294312        "move   $12,   %1           \n"   /* $12 <= k_src                   */
    295313        "move   $13,   %2           \n"   /* $13 <= u_dst                   */
    296         "mfc2   $15,   $1           \n"   /* $15 <= mode DTLB and ITLB off  */
    297         "ori    $14,   $15,  0x4    \n"   /* $14 <= mode DTLB on            */
     314        "mfc2   $15,   $1           \n"   /* $15 <= MMU_MODE                */
     315        "ori    $14,   $15,  0x4    \n"   /* $14 <= MMU_MODE modified       */
     316
    298317        "1:                         \n"
    299318        "lb     $10,   0($12)       \n"   /* read char from kernel space    */
    300319        "mtc2   $14,   $1                       \n"   /* MMU_MODE <= DTLB ON            */
    301320            "sb     $10,   0($13)       \n"   /* store char to user space       */
    302         "mtc2   $15,   $1                       \n"   /* restore DTLB and ITLB off      */
     321        "mtc2   $15,   $1                       \n"   /* MMU_MODE <= DTLB OFF           */
    303322        "beq    $10,   $0,   2f     \n"   /* exit if char == 0              */
    304323        "addi   $11,   $11, -1      \n"   /* decrement count                */
    305324        "addi   $12,   $12,  1      \n"   /* increment k_src pointer        */
    306         "beq    $11,   $0,   2f     \n"   /* exit if count == size          */
     325        "beq    $11,   $0,   2f     \n"   /* exit if count == 0             */
    307326        "addi   $13,   $13,  1      \n"   /* increment u_src pointer        */
    308327        "j                   1b     \n"   /* jump to next iteration         */
    309328        "2:                         \n"
    310329        "nop                        \n"
     330
     331        /* restore old MMU_DATA_EXT register                                */
     332        "mtc2   $16,   $24          \n"   /* MMU_DATA_EXT <= $16            */
     333
    311334        ".set reorder               \n"
    312335        :
    313         : "r"(size),"r"(src),"r"(dst)
    314         : "$10","$11","$12","$13","$14","$15" );
     336        : "r"(size) , "r"(src) , "r"(dst) , "r"(cxy)
     337        : "$10","$11","$12","$13","$14","$15","$16" );
    315338       
    316339    hal_restore_irq( save_sr );
Note: See TracChangeset for help on using the changeset viewer.