Changeset 619 for trunk/kernel/syscalls


Ignore:
Timestamp:
Feb 12, 2019, 1:15:47 PM (6 years ago)
Author:
alain
Message:

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


Location:
trunk/kernel/syscalls
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_barrier.c

    r581 r619  
    2424#include <hal_kernel_types.h>
    2525#include <hal_special.h>
     26#include <hal_uspace.h>
    2627#include <errno.h>
    2728#include <thread.h>
     
    4344
    4445//////////////////////////////////
    45 int sys_barrier( void     * vaddr,
     46int sys_barrier( intptr_t  vaddr,
    4647                 uint32_t   operation,
    47                  uint32_t   count )
     48                 uint32_t   count,
     49                 intptr_t   attr )   
    4850{
    49         error_t      error;
    50     vseg_t     * vseg;
    51  
    52     thread_t   * this    = CURRENT_THREAD;
    53     process_t  * process = this->process;
     51        error_t                 error;
     52    vseg_t                * vseg;
     53    pthread_barrierattr_t   k_attr;
     54
     55    thread_t  * this    = CURRENT_THREAD;
     56    process_t * process = this->process;
    5457
    5558#if DEBUG_SYS_BARRIER
     
    5861tm_start = hal_get_cycles();
    5962if( DEBUG_SYS_BARRIER < tm_start )
    60 printk("\n[DBG] %s : thread %x in process %x enter for %s / count %d / cycle %d\n",
    61 __FUNCTION__, this->trdid, process->pid, sys_barrier_op_str(operation), count,
     63printk("\n[%s] thread[%x,%x] enters for %s / count %d / cycle %d\n",
     64__FUNCTION__, process->pid, this->trdid, sys_barrier_op_str(operation), count,
    6265(uint32_t)tm_start );
    6366#endif
    6467
    6568    // check vaddr in user vspace
    66         error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg );
    67 
     69        error = vmm_get_vseg( process , vaddr , &vseg );
    6870        if( error )
    6971    {
     
    7173#if DEBUG_SYSCALLS_ERROR
    7274printk("\n[ERROR] in %s : unmapped barrier %x / thread %x / process %x\n",
    73 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );
     75__FUNCTION__ , vaddr , this->trdid , process->pid );
    7476vmm_display( process , false );
    7577#endif
     
    8486            case BARRIER_INIT:
    8587        {
    86             error = remote_barrier_create( (intptr_t)vaddr , count );
    87    
     88            if( attr != 0 )   // QDT barrier required
     89            {
     90                error = vmm_get_vseg( process , attr , &vseg );
     91                if( error )
     92                {
     93
     94#if DEBUG_SYSCALLS_ERROR
     95printk("\n[ERROR] in %s : unmapped barrier attributes %x / thread %x / process %x\n",
     96__FUNCTION__ , attr , this->trdid , process->pid );
     97vmm_display( process , false );
     98#endif
     99                    this->errno = EINVAL;
     100                    return -1;
     101                }
     102 
     103                // copy barrier attributes into kernel space
     104                hal_copy_from_uspace( &k_attr , (void*)attr , sizeof(pthread_barrierattr_t) );
     105
     106                if ( count != k_attr.x_size * k_attr.y_size *k_attr.nthreads ) 
     107                {
     108
     109#if DEBUG_SYSCALLS_ERROR
     110printk("\n[ERROR] in %s : wrong arguments / count %d / x_size %d / y_size %d / nthreads %x\n",
     111__FUNCTION__, count, k_attr.x_size, k_attr.y_size, k_attr.nthreads );
     112#endif
     113                    this->errno = EINVAL;
     114                    return -1;
     115                }
     116 
     117
     118                // call relevant system function
     119                error = generic_barrier_create( vaddr , count , &k_attr );
     120            }
     121            else               // simple barrier required
     122            {
     123                error = generic_barrier_create( vaddr , count , NULL );
     124            }
     125
    88126                    if( error )
    89127            {
     
    91129#if DEBUG_SYSCALLS_ERROR
    92130printk("\n[ERROR] in %s : cannot create barrier %x / thread %x / process %x\n",
    93 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid );
     131__FUNCTION__ , vaddr , this->trdid , process->pid );
    94132#endif
    95                 this->errno = error;
     133                this->errno = ENOMEM;
    96134                return -1;
    97135            }
     
    101139            case BARRIER_WAIT:
    102140        {
    103             xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
     141            xptr_t barrier_xp = generic_barrier_from_ident( vaddr );
    104142
    105143            if( barrier_xp == XPTR_NULL )     // user error
     
    115153            else                          // success
    116154            {
    117                 remote_barrier_wait( barrier_xp );
     155                generic_barrier_wait( barrier_xp );
    118156            }
    119157            break;
     
    122160            case BARRIER_DESTROY:
    123161        {
    124             xptr_t barrier_xp = remote_barrier_from_ident( (intptr_t)vaddr );
     162            xptr_t barrier_xp = generic_barrier_from_ident( vaddr );
    125163
    126164            if( barrier_xp == XPTR_NULL )     // user error
     
    136174            else                          // success
    137175            {
    138                 remote_barrier_destroy( barrier_xp );
     176                generic_barrier_destroy( barrier_xp );
    139177            }
    140178            break;
     
    149187tm_end = hal_get_cycles();
    150188if( DEBUG_SYS_BARRIER < tm_end )
    151 printk("\n[DBG] %s : thread %x in process %x exit for %s / cost %d / cycle %d\n",
    152 __FUNCTION__, this->trdid, process->pid, sys_barrier_op_str(operation),
     189printk("\n[%s] thread[%x,%x] exit for %s / cost %d / cycle %d\n",
     190__FUNCTION__, process->pid, this->trdid, sys_barrier_op_str(operation),
    153191(uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    154192#endif
  • trunk/kernel/syscalls/sys_display.c

    r614 r619  
    7777tm_start = hal_get_cycles();
    7878if( DEBUG_SYS_DISPLAY < tm_start )
    79 printk("\n[DBG] %s : thread[%x,%x] enter / type  %s / cycle = %d\n",
     79printk("\n[%s] thread[%x,%x] enter / type  %s / cycle = %d\n",
    8080__FUNCTION__, process->pid, this->trdid, display_type_str(type), (uint32_t)tm_start );
    8181#endif
     
    8484    if( type == DISPLAY_STRING )
    8585    {
    86         char      kbuf[256];
     86        char      kbuf[512];
    8787        uint32_t  length;
    8888
     
    106106        length = hal_strlen_from_uspace( string );
    107107
    108         if( length >= 256 )
     108        if( length >= 512 )
    109109        {
    110110
     
    118118
    119119        // copy string to kernel space
    120         hal_strcpy_from_uspace( kbuf , string , 256 );
     120        hal_strcpy_from_uspace( kbuf , string , 512 );
    121121
    122122        // print message on TXT0 kernel terminal
     
    281281        }
    282282
    283         thread_display_busylocks( thread_xp );
     283        thread_display_busylocks( thread_xp , __FUNCTION__ );
    284284    }
    285285    /////////////////////////////////
     
    388388#if DEBUG_SYS_DISPLAY
    389389if( DEBUG_SYS_DISPLAY < tm_end )
    390 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     390printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
    391391__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
    392392#endif
  • trunk/kernel/syscalls/sys_exit.c

    r584 r619  
    5858tm_start = hal_get_cycles();
    5959if( DEBUG_SYS_EXIT < tm_start )
    60 printk("\n[DBG] %s : thread[%x,%x] enter / status %x / cycle %d\n",
     60printk("\n[%s] thread[%x,%x] enter / status %x / cycle %d\n",
    6161__FUNCTION__, process->pid, this->trdid , status , (uint32_t)tm_start );
    6262#endif
     
    6969#if (DEBUG_SYS_EXIT & 1)
    7070if( DEBUG_SYS_EXIT < tm_start )
    71 printk("\n[DBG] %s : thread[%x,%x] get owner process in cluster %x\n",
     71printk("\n[%s] thread[%x,%x] get owner process in cluster %x\n",
    7272__FUNCTION__, process->pid, this->trdid, owner_cxy );
    7373#endif
     
    8383#if (DEBUG_SYS_EXIT & 1)
    8484if( DEBUG_SYS_EXIT < tm_start )
    85 printk("\n[DBG] %s : thread[%x,%x] get parent process in cluster %x\n",
     85printk("\n[%s] thread[%x,%x] get parent process in cluster %x\n",
    8686__FUNCTION__, process->pid, this->trdid, parent_cxy );
    8787#endif
     
    9696#if( DEBUG_SYS_EXIT & 1)
    9797if( DEBUG_SYS_EXIT < tm_start )
    98 printk("\n[DBG] %s : thread[%x,%x] detached process from TXT\n",
     98printk("\n[%s] thread[%x,%x] detached process from TXT\n",
    9999__FUNCTION__, process->pid, this->trdid );
    100100#endif
     
    106106#if( DEBUG_SYS_EXIT & 1)
    107107if( DEBUG_SYS_EXIT < tm_start )
    108 printk("\n[DBG] %s : thread[%x,%x] deleted all threads but itself\n",
     108printk("\n[%s] thread[%x,%x] deleted all threads but itself\n",
    109109__FUNCTION__, process->pid, this->trdid );
    110110#endif
     
    116116#if( DEBUG_SYS_EXIT & 1)
    117117if( tm_start > DEBUG_SYS_EXIT )
    118 printk("\n[DBG] %s : thread[%x,%x] marked iself for delete\n",
     118printk("\n[%u] thread[%x,%x] marked iself for delete\n",
    119119__FUNCTION__, process->pid, this->trdid );
    120120#endif
     
    127127#if( DEBUG_SYS_EXIT & 1)
    128128if( tm_start > DEBUG_SYS_EXIT )
    129 printk("\n[DBG] %s : thread[%x,%x] blocked main thread\n",
     129printk("\n[%s] thread[%x,%x] blocked main thread\n",
    130130__FUNCTION__, process->pid, this->trdid );
    131131#endif
     
    138138#if( DEBUG_SYS_EXIT & 1)
    139139if( tm_start > DEBUG_SYS_EXIT )
    140 printk("\n[DBG] %s : thread[%x,%x] set exit status %x in owner process\n",
     140printk("\n[%s] thread[%x,%x] set exit status %x in owner process\n",
    141141__FUNCTION__, process->pid, this->trdid, term_state );
    142142#endif
     
    147147#if( DEBUG_SYS_EXIT & 1)
    148148if( tm_start > DEBUG_SYS_EXIT )
    149 printk("\n[DBG] %s : thread[%x,%x] unblocked parent main thread in process %x\n",
     149printk("\n[%s] thread[%x,%x] unblocked parent main thread in process %x\n",
    150150__FUNCTION__ , process->pid, this->trdid,
    151151hal_remote_l32( XPTR( parent_cxy , &parent_ptr->pid) ) );
     
    157157tm_end = hal_get_cycles();
    158158if( DEBUG_SYS_EXIT < tm_end )
    159 printk("\n[DBG] %s : thread[%x,%x] exit / status %x / cost = %d / cycle %d\n",
     159printk("\n[%s] thread[%x,%x] exit / status %x / cost = %d / cycle %d\n",
    160160__FUNCTION__, process->pid, this->trdid, status,
    161161(uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
  • trunk/kernel/syscalls/sys_thread_create.c

    r594 r619  
    7070if( DEBUG_SYS_THREAD_CREATE < tm_start )
    7171printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
    72 __FUNCTION__, process_pid, parent->trdid, (uint32_t)tm_start );
     72__FUNCTION__, process->pid, parent->trdid, (uint32_t)tm_start );
    7373#endif
    7474
  • trunk/kernel/syscalls/sys_thread_exit.c

    r584 r619  
    6464uint64_t     tm_start = hal_get_cycles();
    6565if( DEBUG_SYS_THREAD_EXIT < tm_start )
    66 printk("\n[DBG] %s : thread[%x,%x] / main => delete process / cycle %d\n",
     66printk("\n[%s] thread[%x,%x] / main => delete process / cycle %d\n",
    6767__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
    6868#endif
     
    7676uint64_t     tm_start = hal_get_cycles();
    7777if( DEBUG_SYS_THREAD_EXIT < tm_start )
    78 printk("\n[DBG] %s : thread[%x,%x] / not main => delete thread / cycle %d\n",
     78printk("\n[%s] thread[%x,%x] / not main => delete thread / cycle %d\n",
    7979__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
    8080#endif
  • trunk/kernel/syscalls/syscalls.h

    r611 r619  
    146146 * The code implementting the operations is defined in the remote_barrier.c file.
    147147 ******************************************************************************************
    148  * @ vaddr     : barrier virtual address in user space == identifier.
     148 * @ vaddr     : barrier address in user space == identifier.
    149149 * @ operation : BARRIER_INIT / BARRIER_DESTROY / BARRIER_WAIT.
    150  * @ count     : number of expected threads (only used by BARRIER_INIT operation).
    151  * @ return 0 if success / return -1 if failure.
    152  *****************************************************************************************/
    153 int sys_barrier( void     * vaddr,
     150 * @ count     : number of expected threads (only used by BARRIER_INIT).
     151 * @ attr      : barrier attributes address in user space (only used by BARRIER_INIT).
     152 * @ return 0 if success / return -1 if failure.
     153 *****************************************************************************************/
     154int sys_barrier( intptr_t   vaddr,
    154155                 uint32_t   operation,
    155                  uint32_t   count );
     156                 uint32_t   count,
     157                 intptr_t   attr );
    156158
    157159/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.