Changeset 594


Ignore:
Timestamp:
Nov 10, 2018, 2:33:26 PM (6 years ago)
Author:
alain
Message:

Fix various bugs in sys_stat() and sys_mmap() functions.
Improve debug in other functions.

Location:
trunk/kernel/syscalls
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_mman.h

    r445 r594  
    4343    MAP_ANON    = 0x00000001,  /*! map an anonymous vseg in local cluster                 */
    4444    MAP_REMOTE  = 0x00000002,  /*! map an anonymous vseg in remote cluster (cxy == fdid)  */
    45     MAP_PRIVATE = 0x00000010,  /*!                                                        */
    46     MAP_SHARED  = 0x00000020,  /*!                                                        */
    47     MAP_FIXED   = 0x00000100,  /*! non supported                                          */
     45    MAP_PRIVATE = 0x00000010,  /*! modifications are private to the calling process       */
     46    MAP_SHARED  = 0x00000020,  /*! modifications are shared                               */
     47    MAP_FIXED   = 0x00000100,  /*! non supported (user defined base address)              */
    4848}
    4949mmap_flags_t;
  • trunk/kernel/syscalls/shared_include/shared_stat.h

    r445 r594  
    3232typedef struct stat
    3333{
    34         unsigned int    dev;        /*! ID of device containing file                             */
    35         unsigned int    inum;       /*! inode number                                             */
    36         unsigned int    mode;       /*! protection                                               */
    37         unsigned int    nlink;      /*! number of hard links                                     */
    38         unsigned int    uid;        /*! user ID of owner                                         */
    39         unsigned int    gid;        /*! group ID of owner                                        */
    40         unsigned int    rdev;       /*! device ID (if special file)                              */
    41         unsigned int    size;       /*! total size, in bytes                                     */
    42         unsigned int    blksize;    /*! blocksize for file system I/O                            */
    43         unsigned int    blocks;     /*! number of 512B blocks allocated                          */
     34        unsigned int    st_dev;     /*! ID of device containing file                         */
     35        unsigned int    st_ino;     /*! inode number                                         */
     36        unsigned int    st_mode;    /*! bit vector defined below                             */
     37        unsigned int    st_nlink;   /*! number of hard links                                 */
     38        unsigned int    st_uid;     /*! user ID of owner                                     */
     39        unsigned int    st_gid;     /*! group ID of owner                                    */
     40        unsigned int    st_rdev;    /*! device ID (if special file)                          */
     41        unsigned int    st_size;    /*! total size, in bytes                                 */
     42        unsigned int    st_blksize; /*! blocksize for file system I/O                        */
     43        unsigned int    st_blocks;  /*! number of allocated blocks                           */
    4444}
    4545stat_t;
    4646
     47/******************************************************************************************
     48 * The st_mode field contains informations on both access rights and file types.
     49 * - access rights (defined by the inode <rights> field) are stored in st_mode[15:0]
     50 * - file types (defined by the inode <type> field) are stored in st_mode[19:16]
     51 * The following macros can be used to extract file type information.
     52 *
     53 * WARNING : these macros must be kept consistent with inode types in <vfs.h> file.
     54 *****************************************************************************************/
     55
     56#define  S_ISREG(x)   ((((x)>>16) & 0xF) == 0)    /*! it is a regular file               */
     57#define  S_ISDIR(x)   ((((x)>>16) & 0xF) == 1)    /*! it is a directory                  */
     58#define  S_ISFIFO(x)  ((((x)>>16) & 0xF) == 2)    /*! it is a named pipe                 */
     59#define  S_ISPIPE(x)  ((((x)>>16) & 0xF) == 3)    /*! it is an anonymous pipe            */
     60#define  S_ISSOCK(x)  ((((x)>>16) & 0xF) == 4)    /*! it is a socket                     */
     61#define  S_ISCHR(x)   ((((x)>>16) & 0xF) == 5)    /*! it is a character device           */
     62#define  S_ISLNK(x)   ((((x)>>16) & 0xF) == 6)    /*! it is a symbolic link              */
     63
    4764#endif /* _STAT_H_ */
  • trunk/kernel/syscalls/sys_close.c

    r506 r594  
    4141        process_t * process = this->process;
    4242
     43#if (DEBUG_SYS_CLOSE || CONFIG_INSTRUMENTATION_SYSCALLS)
     44uint64_t     tm_start = hal_get_cycles();
     45#endif
     46
    4347#if DEBUG_SYS_CLOSE
    44 uint32_t     tm_start;
    45 uint32_t     tm_end;
    46 tm_start = hal_get_cycles();
    4748if( DEBUG_SYS_CLOSE < tm_start )
    48 printk("\n[DBG] %s : thread %x in process %x enter / fdid %d / cycle %d\n",
    49 __FUNCTION__, this->trdid, process->pid, file_id, (uint32_t)tm_start );
     49printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n",
     50__FUNCTION__, process->pid, this->trdid, file_id, (uint32_t)tm_start );
    5051#endif
    5152 
     
    6465    if( file_xp == XPTR_NULL )
    6566    {
    66         printk("\n[ERROR] in %s : undefined file descriptor = %d\n",
    67                __FUNCTION__ , file_id );
    68                 this->errno = EBADFD;
     67
     68#if DEBUG_SYSCALLS_ERROR
     69printk("\n[ERROR] in %s : undefined file descriptor %d\n",
     70__FUNCTION__ , file_id );
     71#endif
     72        this->errno = EBADFD;
    6973                return -1;
    7074    }
     
    7579        if( error )
    7680        {
    77         printk("\n[ERROR] in %s : cannot close file descriptor = %d\n",
    78                __FUNCTION__ , file_id );
     81
     82#if DEBUG_SYSCALLS_ERROR
     83printk("\n[ERROR] in %s : cannot close file descriptor %d\n",
     84__FUNCTION__ , file_id );
     85#endif
    7986                this->errno = error;
    8087                return -1;
     
    8390        hal_fence();
    8491
     92#if (DEBUG_SYS_CLOSE || CONFIG_INSTRUMENTATION_SYSCALLS)
     93uint64_t     tm_end = hal_get_cycles();
     94#endif
     95
    8596#if DEBUG_SYS_CLOSE
    8697tm_end = hal_get_cycles();
    8798if( DEBUG_SYS_CLOSE < tm_start )
    88 printk("\n[DBG] %s : thread %x in process %x exit / cost %d / cycle %d\n",
    89 __FUNCTION__, this->trdid, process->pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_start );
     99printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
     100__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
    90101#endif
    91102 
     103#if CONFIG_INSTRUMENTATION_SYSCALLS
     104hal_atomic_add( &syscalls_cumul_cost[SYS_CLOSE] , tm_end - tm_start );
     105hal_atomic_add( &syscalls_occurences[SYS_CLOSE] , 1 );
     106#endif
     107
    92108        return 0;
    93109}
  • trunk/kernel/syscalls/sys_display.c

    r584 r594  
    6565    process_t * process = this->process;
    6666
     67#if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS)
     68uint64_t     tm_start = hal_get_cycles();
     69#endif
     70
    6771#if DEBUG_SYS_DISPLAY
    68 uint64_t    tm_start;
    69 uint64_t    tm_end;
    7072tm_start = hal_get_cycles();
    7173if( DEBUG_SYS_DISPLAY < tm_start )
    72 printk("\n[DBG] %s : thread %d enter / process %x / type  %s / cycle = %d\n",
    73 __FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start );
     74printk("\n[DBG] %s : thread[%x,%x] enter / type  %s / cycle = %d\n",
     75__FUNCTION__, process->pid, this->trdid, display_type_str(type), (uint32_t)tm_start );
    7476#endif
    7577
     
    257259    else if( type == DISPLAY_BUSYLOCKS )
    258260    {
    259         pid_t   pid   = (cxy_t)arg0;
     261        pid_t   pid   = (pid_t)arg0;
    260262        trdid_t trdid = (trdid_t)arg1;
    261263
     
    267269
    268270#if DEBUG_SYSCALLS_ERROR
    269 printk("\n[ERROR] in %s for BUSYLOCKS : thread %x in process %x not found\n",
    270 __FUNCTION__ , trdid , pid );
     271printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n",
     272__FUNCTION__ , pid, trdid );
    271273#endif
    272274            this->errno = EINVAL;
     
    288290    }
    289291
     292#if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS)
     293uint64_t     tm_end = hal_get_cycles();
     294#endif
     295
    290296#if DEBUG_SYS_DISPLAY
    291 tm_end = hal_get_cycles();
    292297if( DEBUG_SYS_DISPLAY < tm_end )
    293 printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
    294 __FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
     298printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     299__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
     300#endif
     301
     302#if CONFIG_INSTRUMENTATION_SYSCALLS
     303hal_atomic_add( &syscalls_cumul_cost[SYS_DISPLAY] , tm_end - tm_start );
     304hal_atomic_add( &syscalls_occurences[SYS_DISPLAY] , 1 );
    295305#endif
    296306
  • trunk/kernel/syscalls/sys_fork.c

    r584 r594  
    110110#if (DEBUG_SYS_FORK & 1 )
    111111if( DEBUG_SYS_FORK < tm_start )
    112 printk("\n[DBG] %s : thread[%x,%x] selected cluster %x\n",
     112printk("\n[%s] thread[%x,%x] selected cluster %x\n",
    113113__FUNCTION__, parent_pid, parent_thread_ptr->trdid, child_cxy );
    114114#endif
     
    167167#if DEBUG_SYS_FORK
    168168if( DEBUG_SYS_FORK < tm_end )
    169 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     169printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
    170170__FUNCTION__, current->process->pid, current->trdid, (uint32_t)tm_end );
    171171#endif
  • trunk/kernel/syscalls/sys_kill.c

    r584 r594  
    7474tm_start = hal_get_cycles();
    7575if( DEBUG_SYS_KILL < tm_start )
    76 printk("\n[DBG] %s : thread[%x,%x] enter / process %x / %s / cycle %d\n",
     76printk("\n[%s] thread[%x,%x] enter / process %x / %s / cycle %d\n",
    7777__FUNCTION__, this->process->pid, this->trdid, pid,
    7878sig_type_str(sig_id), (uint32_t)tm_start );
     
    8686#if (DEBUG_SYS_KILL & 1)
    8787if( DEBUG_SYS_KILL < tm_start )
    88 printk("\n[DBG] %s : thread[%x,%x] get owner process %x in cluster %x\n",
     88printk("\n[%s] thread[%x,%x] get owner process %x in cluster %x\n",
    8989__FUNCTION__ , this->process->pid, this->trdid, owner_ptr, owner_cxy );
    9090#endif
     
    108108#if (DEBUG_SYS_KILL & 1)
    109109if( DEBUG_SYS_KILL < tm_start )
    110 printk("\n[DBG] %s : thread[%x,%x] get parent process %x in cluster %x\n",
     110printk("\n[%x] thread[%x,%x] get parent process %x in cluster %x\n",
    111111__FUNCTION__ , this->process->pid, this->trdid, parent_ptr, parent_cxy );
    112112#endif
     
    135135            thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
    136136
     137            // calling thread deschedules when it is itself a target thread
     138            if( this->process->pid == pid ) sched_yield("block itself");
     139
    137140            break;
    138141        }
     
    214217#if DEBUG_SYS_KILL
    215218if( DEBUG_SYS_KILL < tm_end )
    216 printk("\n[DBG] %s : thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n",
     219printk("\n[%s] thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n",
    217220__FUNCTION__ , this->process->pid, this->trdid, pid,
    218221sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
  • trunk/kernel/syscalls/sys_mmap.c

    r566 r594  
    5151        process_t   * process = this->process;
    5252
     53#if (DEBUG_SYS_MMAP || CONFIG_INSTRUMENTATION_SYSCALLS)
     54uint64_t     tm_start = hal_get_cycles();
     55#endif
     56
    5357#if DEBUG_SYS_MMAP
    54 uint64_t      tm_start;
    55 uint64_t      tm_end;
    5658tm_start = hal_get_cycles();
    5759if ( DEBUG_SYS_MMAP < tm_start )
    58 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    59 __FUNCTION__, this, process->pid, (uint32_t)tm_start );
    60 #endif
    61 
    62     // check arguments in user space
     60printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
     61__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start );
     62#endif
     63
     64    // check user buffer (containing attributes) is mapped
    6365    error = vmm_get_vseg( process , (intptr_t)attr , &vseg );
    6466
    65     if ( error )
    66     {
    67 
    68 #if DEBUG_SYSCALLS_ERROR
    69 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",
    70 __FUNCTION__ , (intptr_t)attr , this->trdid , process->pid );
     67    if( error )
     68    {
     69
     70#if DEBUG_SYSCALLS_ERROR
     71printk("\n[ERROR] in %s : thread[%x,%x] / mmap attributes unmapped %x\n",
     72__FUNCTION__ , process->pid, this->trdid, (intptr_t)attr );
    7173vmm_display( process , false );
    7274#endif
     
    7577    }
    7678
    77     // copy arguments from uspace
     79    // copy attributes from user space to kernel space
    7880    hal_copy_from_uspace( &k_attr , attr , sizeof(mmap_attr_t) );
    7981
    80     // get fdid, offset, and length arguments
    81     uint32_t fdid   = k_attr.fdid;
    82     uint32_t offset = k_attr.offset;
    83     uint32_t length = k_attr.length;
     82    // get addr, fdid, offset, and length attributes
     83    uint32_t  fdid   = k_attr.fdid;
     84    uint32_t  offset = k_attr.offset;
     85    uint32_t  length = k_attr.length;
    8486
    8587    // get flags
     
    9597
    9698#if DEBUG_SYSCALLS_ERROR
    97 printk("\n[ERROR] in %s : MAP_FIXED not supported / thread %x / process %x\n",
    98 __FUNCTION__ , this->trdid , process->pid );
     99printk("\n[ERROR] in %s : thread[%x,%x] / MAP_FIXED not supported\n",
     100__FUNCTION__ , process->pid, this->trdid );
    99101#endif
    100102        this->errno = EINVAL;
     
    106108
    107109#if DEBUG_SYSCALLS_ERROR
    108 printk("\n[ERROR] in %s : MAP_SHARED == MAP_PRIVATE / thread %x / process %x\n",
    109 __FUNCTION__ , this->trdid , process->pid );
     110printk("\n[ERROR] in %s : thread[%x,%x] / MAP_SHARED == MAP_PRIVATE\n",
     111__FUNCTION__ , process->pid, this->trdid );
    110112#endif
    111113        this->errno = EINVAL;
     
    115117    // FIXME handle Copy_On_Write for MAP_PRIVATE...
    116118
    117     // get access rigths
    118     bool_t     prot_read   = ( (k_attr.prot & PROT_READ )   != 0 );
    119     bool_t     prot_write  = ( (k_attr.prot & PROT_WRITE)   != 0 );
    120 
    121119    // test mmap type : can be FILE / ANON / REMOTE
    122120
    123121    if( (map_anon == false) && (map_remote == false) )   // FILE
    124122    {
     123
     124#if (DEBUG_SYS_MMAP & 1)
     125if ( DEBUG_SYS_MMAP < tm_start )
     126printk("\n[%s] thread[%x,%x] map file : fdid %d / offset %d / %d bytes\n",
     127__FUNCTION__, process->pid, this->trdid, fdid, offset, length );
     128#endif
     129
    125130            // FIXME: handle concurent delete of file by another thread closing it
    126131
     
    129134
    130135#if DEBUG_SYSCALLS_ERROR
    131 printk("\n[ERROR] in %s: bad file descriptor %d / thread %x / process %x\n",
    132 __FUNCTION__ , fdid , this->trdid , process->pid );
     136printk("\n[ERROR] in %s : thread[%x,%x] / bad file descriptor %d\n",
     137__FUNCTION__ , process->pid , this->trdid , fdid );
    133138#endif
    134139            this->errno = EBADFD;
     
    143148
    144149#if DEBUG_SYSCALLS_ERROR
    145 printk("\n[ERROR] in %s: file %d not found / thread %x / process %x\n",
    146 __FUNCTION__ , fdid , this->trdid , process->pid );
     150printk("\n[ERROR] in %s : thread[%x,%x] / file descriptor %d not found\n",
     151__FUNCTION__  , this->trdid , process->pid , fdid );
    147152#endif
    148153            this->errno = EBADFD;
     
    154159        vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
    155160
    156         // get inode pointer, mapper pointer and file attributes
     161#if (DEBUG_SYS_MMAP & 1)
     162if ( DEBUG_SYS_MMAP < tm_start )
     163printk("\n[%s] thread[%x,%x] get file pointer %x in cluster %x\n",
     164__FUNCTION__, process->pid, this->trdid, file_ptr, file_cxy );
     165#endif
     166
     167        // get inode pointer & mapper pointer
    157168        vfs_inode_t * inode_ptr  = hal_remote_lpt(XPTR(file_cxy , &file_ptr->inode ));
    158         uint32_t      file_attr  = hal_remote_l32 (XPTR(file_cxy , &file_ptr->attr  ));
    159169        mapper_t    * mapper_ptr = hal_remote_lpt(XPTR(file_cxy , &file_ptr->mapper));
    160170
    161171        // get file size
    162172                uint32_t size = hal_remote_l32( XPTR( file_cxy , &inode_ptr->size ) );
     173
     174#if (DEBUG_SYS_MMAP & 1)
     175if ( DEBUG_SYS_MMAP < tm_start )
     176printk("\n[%s] thread[%x,%x] get file size : %d bytes\n",
     177__FUNCTION__, process->pid, this->trdid, size );
     178#endif
    163179
    164180        // chek offset and length arguments
     
    167183
    168184#if DEBUG_SYSCALLS_ERROR
    169 printk("\n[ERROR] in %s: offset(%d) + len(%d) >= file's size(%d) / thread %x / process %x\n",
    170 __FUNCTION__, k_attr.offset, k_attr.length, size, this->trdid, process->pid );
     185printk("\n[ERROR] in %s: thread[%x,%x] / offset(%d) + len(%d) >= file's size(%d)\n",
     186__FUNCTION__, process->pid, this->trdid, k_attr.offset, k_attr.length, size );
    171187#endif
    172188            this->errno = ERANGE;
    173189            return -1;
    174190                }
     191
     192/* TODO
     193        // chek access rigths
     194        uint32_t   file_attr  = hal_remote_l32(XPTR(file_cxy , &file_ptr->attr  ));
     195        bool_t     prot_read  = ( (k_attr.prot & PROT_READ )   != 0 );
     196        bool_t     prot_write = ( (k_attr.prot & PROT_WRITE)   != 0 );
    175197
    176198        // check access rights
     
    186208                        return -1;
    187209                }
     210*/
    188211
    189212                // increment file refcount
     
    194217        vseg_cxy  = file_cxy;
    195218    }
    196     else                                                // ANON or REMOTE
    197     {
    198         // no mapper for ANON or REMOTE
     219    else if ( map_anon )                                 // MAP_ANON
     220    {
    199221        mapper_xp = XPTR_NULL;
    200 
    201         if( map_anon )
     222        vseg_type = VSEG_TYPE_ANON;
     223        vseg_cxy  = local_cxy;
     224
     225#if (DEBUG_SYS_MMAP & 1)
     226if ( DEBUG_SYS_MMAP < tm_start )
     227printk("\n[%s] thread[%x,%x] map anon / %d bytes / cluster %x\n",
     228__FUNCTION__, process->pid, this->trdid, length, vseg_cxy );
     229#endif
     230
     231    }
     232    else                                                 // MAP_REMOTE
     233    {
     234        mapper_xp = XPTR_NULL;
     235        vseg_type = VSEG_TYPE_REMOTE;
     236        vseg_cxy  = k_attr.fdid;
     237
     238#if (DEBUG_SYS_MMAP & 1)
     239if ( DEBUG_SYS_MMAP < tm_start )
     240printk("\n[%s] thread[%x,%x] map remote / %d bytes / cluster %x\n",
     241__FUNCTION__, process->pid, this->trdid, length, vseg_cxy );
     242#endif
     243 
     244        if( cluster_is_undefined( vseg_cxy ) )
    202245        {
    203             vseg_type = VSEG_TYPE_ANON;
    204             vseg_cxy  = local_cxy;
    205         }
    206         else
    207         {
    208             vseg_type = VSEG_TYPE_REMOTE;
    209             vseg_cxy  = k_attr.fdid;
    210  
    211             if( cluster_is_undefined( vseg_cxy ) )
    212             {
    213 
    214 #if DEBUG_SYSCALLS_ERROR
    215 printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE / thread %x / process %x\n",
    216 __FUNCTION__, this->trdid , process->pid );
    217 #endif
    218                 this->errno = EINVAL;
    219                 return -1;
    220             }
     246
     247#if DEBUG_SYSCALLS_ERROR
     248printk("\n[ERROR] in %s : thread[%x,%x] / illegal cxy %x for REMOTE\n",
     249__FUNCTION__, this->trdid , process->pid, vseg_cxy );
     250#endif
     251            this->errno = EINVAL;
     252            return -1;
    221253        }
    222254    }
     
    228260    xptr_t      ref_xp  = process->ref_xp;
    229261    cxy_t       ref_cxy = GET_CXY( ref_xp );
    230     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     262    process_t * ref_ptr = GET_PTR( ref_xp );
    231263
    232264    // create the vseg in reference cluster
     
    235267        vseg = vmm_create_vseg( process,
    236268                                vseg_type,
    237                                 0,               // base address unused for mmap()
    238                                 length,
    239                                 offset,
    240                                 0,               // file_size unused for mmap()
     269                                0,               // vseg base (unused for mmap)
     270                                length,          // vseg size
     271                                offset,          // file offset
     272                                0,               // file_size (unused for mmap)
    241273                                mapper_xp,
    242274                                vseg_cxy );
     
    247279                                    ref_ptr,
    248280                                    vseg_type,
    249                                     0,            // base address unused for mmap()
    250                                     length,
    251                                     offset,
    252                                     0,            // file size unused for mmap()
     281                                    0,            // vseg base (unused for mmap)
     282                                    length,       // vseg size
     283                                    offset,       // file offset
     284                                    0,            // file size (unused for mmap)
    253285                                    mapper_xp,
    254286                                    vseg_cxy,
     
    263295
    264296#if DEBUG_SYSCALLS_ERROR
    265 printk("\n[ERROR] in %s : cannot create vseg / thread %x / process %x\n",
    266 __FUNCTION__, this->trdid , process->pid );
     297printk("\n[ERROR] in %s : thread[%x,%x] / cannot create vseg\n",
     298__FUNCTION__, process->pid, this->trdid );
    267299#endif
    268300        this->errno = ENOMEM;
     
    275307    hal_fence();
    276308
     309#if (DEBUG_SYS_MMAP || CONFIG_INSTRUMENTATION_SYSCALLS)
     310uint64_t     tm_end = hal_get_cycles();
     311#endif
     312
    277313#if DEBUG_SYS_MMAP
    278 tm_end = hal_get_cycles();
    279 if ( DEBUG_SYS_MMAP < tm_start )
    280 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n"
    281 "vseg %s / cluster %x / base %x / size %x / cost %d\n",
    282 __FUNCTION__, this, process->pid, (uint32_t)tm_end,
    283 vseg_type_str(vseg->type), vseg->cxy, vseg->min, length, (uint32_t)(tm_end - tm_start) );
     314if ( DEBUG_SYS_MMAP < tm_start )
     315printk("\n[%s] thread[%x,%x] exit / %s / cxy %x / base %x / size %d / cycle %d\n",
     316__FUNCTION__, process->pid, this->trdid,
     317vseg_type_str(vseg->type), vseg->cxy, vseg->min, length, (uint32_t)tm_end );
    284318#endif
    285319
  • trunk/kernel/syscalls/sys_open.c

    r566 r594  
    4747    process_t    * process  = this->process;
    4848
    49 #if DEBUG_SYS_OPEN
    50 uint32_t     tm_start;
    51 uint32_t     tm_end;
    52 tm_start = hal_get_cycles();
     49#if (DEBUG_SYS_OPEN || CONFIG_INSTRUMENTATION_SYSCALLS)
     50uint64_t     tm_start = hal_get_cycles();
    5351#endif
    54  
     52
    5553    // check fd_array not full
    5654    if( process_fd_array_full() )
     
    8179#if DEBUG_SYS_OPEN
    8280if( DEBUG_SYS_OPEN < tm_start )
    83 printk("\n[DBG] %s : thread %x in process %x enter / path %s / flags %x / cycle %d\n",
    84 __FUNCTION__, this->trdid, process->pid, kbuf, flags, (uint32_t)tm_start );
     81printk("\n[%s] thread[%x,%x] enter for <%s> / flags %x / cycle %d\n",
     82__FUNCTION__, process->pid, this->trdid, kbuf, flags, (uint32_t)tm_start );
    8583#endif
    8684 
     
    112110    }
    113111
     112    hal_fence;
     113
     114#if (DEBUG_SYS_OPEN || CONFIG_INSTRUMENTATION_SYSCALLS)
     115uint64_t     tm_end = hal_get_cycles();
     116#endif
     117
    114118#if DEBUG_SYS_OPEN
    115 tm_end = hal_get_cycles();
    116119if( DEBUG_SYS_OPEN < tm_start )
    117 printk("\n[DBG] %s : thread %x in process %x exit / cost %d / cycle %d\n",
    118 __FUNCTION__, this->trdid, process->pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_start );
     120printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n",
     121__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
    119122#endif
    120123 
     124#if CONFIG_INSTRUMENTATION_SYSCALLS
     125hal_atomic_add( &syscalls_cumul_cost[SYS_OPEN] , tm_end - tm_start );
     126hal_atomic_add( &syscalls_occurences[SYS_OPEN] , 1 );
     127#endif
     128
    121129    return file_id;
    122130}
  • trunk/kernel/syscalls/sys_read.c

    r584 r594  
    194194
    195195    }
    196     else
    197     {
    198         nbytes = 0;
    199         assert( false , "file type %d non supported yet\n", type );
     196    else    // not FILE and not DEV
     197    {
     198
     199#if DEBUG_SYSCALLS_ERROR
     200printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
     201__FUNCTION__, vfs_inode_type_str( type ) );
     202#endif
     203                this->errno = EBADFD;
     204                return -1;
    200205    }
    201206
     
    207212__FUNCTION__, process->pid, this->trdid, file_id );
    208213#endif
    209         this->errno = error;
     214        this->errno = EIO;
    210215        return -1;
    211216    }
  • trunk/kernel/syscalls/sys_stat.c

    r566 r594  
    3939{
    4040    error_t       error;
    41     vseg_t      * vseg;         // for user space checking
    42     struct stat   k_stat;       // kernel space
    43     xptr_t        file_xp;
     41    vseg_t      * vseg;                   // for user space checking
     42    struct stat   k_stat;                 // in kernel space
     43    xptr_t        inode_xp;               // extended pointer on target inode
     44
    4445    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4546       
    4647        thread_t  * this    = CURRENT_THREAD;
    4748        process_t * process = this->process;
     49
     50#if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS)
     51uint64_t     tm_start = hal_get_cycles();
     52#endif
    4853
    4954    // check stat structure in user space
     
    5459
    5560#if DEBUG_SYSCALLS_ERROR
    56 printk("\n[ERROR] in %s : stat structure unmapped %x / thread %x / process %x\n",
    57 __FUNCTION__ , (intptr_t)u_stat , this->trdid , process->pid );
     61printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n",
     62__FUNCTION__ , process->pid , this->trdid );
    5863vmm_display( process , false );
    5964#endif
     
    6570    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    6671    {
    67         printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     72
     73#if DEBUG_SYSCALLS_ERROR
     74printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n",
     75 __FUNCTION__ , process->pid , this->trdid );
     76#endif
    6877        this->errno = ENFILE;
    6978        return -1;
     
    7281    // copy pathname in kernel space
    7382    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     83
     84#if DEBUG_SYS_STAT
     85if( DEBUG_SYS_STAT < tm_start )
     86printk("\n[%s] thread[%x,%x] enter for file <%s> / cycle %d\n",
     87__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     88#endif
    7489
    7590    // get cluster and local pointer on reference process
     
    86101    // get extended pointer on remote file descriptor
    87102    error = vfs_lookup( cwd_xp,
    88                         pathname,
     103                        kbuf,
    89104                        0,
    90                         &file_xp );
     105                        &inode_xp );
    91106
    92107    // release the cwd lock
     
    95110    if( error )
    96111    {
    97         printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n",
    98                __FUNCTION__ , pathname , this->trdid , process->pid );
    99         this->errno = error;
     112
     113#if DEBUG_SYSCALLS_ERROR
     114printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n",
     115__FUNCTION__ , process->pid , this->trdid , pathname );
     116#endif
     117        this->errno = ENFILE;
    100118        return -1;
    101119    }
    102120
     121#if (DEBUG_SYS_STAT & 1)
     122if( DEBUG_SYS_STAT < tm_start )
     123printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n",
     124__FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf );
     125#endif
     126
    103127    // call VFS function to get stat info
    104     error = vfs_stat( file_xp,
     128    error = vfs_stat( inode_xp,
    105129                      &k_stat );
    106130    if( error )
    107131        {
    108         printk("\n[ERROR] in %s : cannot get stats for file %s\n",
    109                __FUNCTION__ , pathname );
    110                 this->errno = error;
     132
     133#if DEBUG_SYSCALLS_ERROR
     134printk("\n[ERROR] in %s / thread[%x,%x] : cannot get stats for inode <%s>\n",
     135__FUNCTION__ , process->pid , this->trdid , pathname );
     136#endif
     137                this->errno = ENFILE;
    111138                return -1;
    112139        }
    113140   
     141#if (DEBUG_SYS_STAT & 1)
     142if( DEBUG_SYS_STAT < tm_start )
     143printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n",
     144__FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode );
     145#endif
     146
    114147    // copy k_stat to u_stat
    115148    hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
     
    117150    hal_fence();
    118151
     152#if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS)
     153uint64_t     tm_end = hal_get_cycles();
     154#endif
     155
     156#if DEBUG_SYS_STAT
     157if( DEBUG_SYS_STAT < tm_end )
     158printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n",
     159__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
     160#endif
     161 
     162#if CONFIG_INSTRUMENTATION_SYSCALLS
     163hal_atomic_add( &syscalls_cumul_cost[SYS_STAT] , tm_end - tm_start );
     164hal_atomic_add( &syscalls_occurences[SYS_STAT] , 1 );
     165#endif
     166
    119167        return 0;
    120168
  • trunk/kernel/syscalls/sys_thread_create.c

    r566 r594  
    6262        process    = parent->process;
    6363
     64#if (DEBUG_SYS_THREAD_CREATE || CONFIG_INSTRUMENTATION_SYSCALLS)
     65uint64_t     tm_start = hal_get_cycles();
     66#endif
     67
    6468#if DEBUG_SYS_THREAD_CREATE
    65 uint64_t tm_start;
    66 uint64_t tm_end;
    6769tm_start = hal_get_cycles();
    6870if( DEBUG_SYS_THREAD_CREATE < tm_start )
    69 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
    70 __FUNCTION__, parent->trdid, process->pid, (uint32_t)tm_start );
     71printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
     72__FUNCTION__, process_pid, parent->trdid, (uint32_t)tm_start );
    7173#endif
    7274
     
    7880
    7981#if DEBUG_SYSCALLS_ERROR
    80 printk("\n[ERROR] in %s : thread %x in process %x / trdid buffer %x unmapped %x\n",
    81 __FUNCTION__, parent->trdid, process->pid, (intptr_t)trdid_ptr );
     82printk("\n[ERROR] in %s : thread[%x,%x] / trdid buffer %x unmapped %x\n",
     83__FUNCTION__, process->pid, parent->trdid, (intptr_t)trdid_ptr );
    8284vmm_display( process , false );
    8385#endif
     
    9597
    9698#if DEBUG_SYSCALLS_ERROR
    97 printk("\n[ERROR] in %s : thread %x in process %x / user_attr buffer unmapped %x\n",
    98 __FUNCTION__, parent->trdid, process->pid, (intptr_t)user_attr );
     99printk("\n[ERROR] in %s : thread[%x,%x] / user_attr buffer unmapped %x\n",
     100__FUNCTION__, process->pid, parent->trdid, (intptr_t)user_attr );
    99101vmm_display( process , false );
    100102#endif
     
    113115
    114116#if DEBUG_SYSCALLS_ERROR
    115 printk("\n[ERROR] in %s : thread %x in process %x / start_func unmapped %x\n",
    116 __FUNCTION__, parent->trdid, process->pid, (intptr_t)start_func );
     117printk("\n[ERROR] in %s : thread[%x,%x] / start_func unmapped %x\n",
     118__FUNCTION__, process->pid, parent->trdid, (intptr_t)start_func );
    117119vmm_display( process , false );
    118120#endif
     
    130132
    131133#if DEBUG_SYSCALLS_ERROR
    132 printk("\n[ERROR] in %s : thread %x in process %x / start_args buffer unmapped %x\n",
    133 __FUNCTION__, parent->trdid, process->pid, (intptr_t)start_args );
     134printk("\n[ERROR] in %s : thread[%x,%x] / start_args buffer unmapped %x\n",
     135__FUNCTION__, process->pid, parent->trdid, (intptr_t)start_args );
    134136vmm_display( process , false );
    135137#endif
     
    149151
    150152#if DEBUG_SYSCALLS_ERROR
    151 printk("\n[ERROR] in %s : thread %x in process %x / illegal target cluster %x\n",
    152 __FUNCTION__, parent->trdid, process->pid, kern_attr.cxy );
     153printk("\n[ERROR] in %s : thread[%x,%x] / illegal target cluster %x\n",
     154__FUNCTION__, process->pid, parent->trdid, kern_attr.cxy );
    153155#endif
    154156                            parent->errno = EINVAL;
     
    200202
    201203#if DEBUG_SYSCALLS_ERROR
    202 printk("\n[ERROR] in %s : thread %x in process %x cannot create new thread\n",
    203 __FUNCTION__ , parent->trdid, process->pid );
     204printk("\n[ERROR] in %s : thread[%x,%x] cannot create new thread\n",
     205__FUNCTION__ , process->pid, parent->trdid );
    204206#endif
    205207                parent->errno = ENOMEM;
     
    216218    hal_fence();
    217219
     220#if (DEBUG_SYS_THREAD_CREATE || CONFIG_INSTRUMENTATION_SYSCALLS)
     221uint64_t     tm_end = hal_get_cycles();
     222#endif
     223
    218224#if DEBUG_SYS_THREAD_CREATE
    219 tm_end = hal_get_cycles();
    220225if( DEBUG_SYS_THREAD_CREATE < tm_end )
    221 printk("\n[DBG] %s : thread %x in process %x created thread %x / cycle %d\n",
    222 __FUNCTION__, parent->trdid, process->pid, child_ptr->trdid, (uint32_t)tm_end );
     226printk("\n[%s] thread[%x,%x] created thread %x / cycle %d\n",
     227__FUNCTION__, process->pid, parent->trdid, child_ptr->trdid, (uint32_t)tm_end );
     228#endif
     229
     230#if CONFIG_INSTRUMENTATION_SYSCALLS
     231hal_atomic_add( &syscalls_cumul_cost[SYS_THREAD_CREATE] , tm_end - tm_start );
     232hal_atomic_add( &syscalls_occurences[SYS_THREAD_CREATE] , 1 );
    223233#endif
    224234
  • trunk/kernel/syscalls/sys_write.c

    r584 r594  
    153153                                count );
    154154    }
    155     else if( type == INODE_TYPE_DEV )  // check ownership & write to device
    156     {
    157         // check user buffer size for TXT_TX
    158         if( (type == INODE_TYPE_DEV) && (count >= CONFIG_TXT_KBUF_SIZE) )
    159         {
    160 
    161 #if DEBUG_SYSCALLS_ERROR
    162 printk("\n[ERROR] in %s : thread[%x,%x] user buffer size %x too large\n",
    163 __FUNCTION__ , process->pid, this->trdid, count );
    164 #endif
    165                     this->errno = EINVAL;
    166                     return -1;
    167         }
    168 
     155    else if( type == INODE_TYPE_DEV )  // write to TXT device
     156    {
    169157        // move count bytes to device
    170158        nbytes = devfs_user_move( false,             // from buffer to device
     
    175163    else  // not FILE and not DEV
    176164    {
    177         nbytes = 0;
    178         assert( false , "file type %d non supported\n", type );
     165
     166#if DEBUG_SYSCALLS_ERROR
     167printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
     168__FUNCTION__, vfs_inode_type_str( type ) );
     169#endif
     170                this->errno = EBADFD;
     171                return -1;
    179172    }
    180173
     
    186179__FUNCTION__ , process->pid, this->trdid, file_id );
    187180#endif
    188         this->errno = error;
     181        this->errno = EIO;
    189182        return -1;
    190183    }
  • trunk/kernel/syscalls/syscalls.h

    r584 r594  
    208208 * [13] This function map physical memory (or a file) in the calling thread virtual space.
    209209 * The <attr> argument is a pointer on a structure for arguments (see shared_syscalls.h).
     210 * The user defined virtual address (MAP_FIXED flag) is not supported.
     211 * TODO : the access rights checking is not implemented yet [AG]
     212 * TODO : the Copy on Write for MAP_PRIVATE is not implemented yet [AG]
    210213 ******************************************************************************************
    211214 * @ attr       : pointer on attributes structure.
     
    281284 * [19] This function creates in the calling thread cluster an unnamed pipe, and two
    282285 * (read and write) file descriptors.
    283  * TODO not implemented yet...
     286 * TODO not implemented yet [AG]
    284287 ******************************************************************************************
    285288 * @ file_id[0] : [out] read only file descriptor index.
     
    497500 * [38] This function  returns in the <stat> structure, defined in the "shared_syscalls.h"
    498501 * file, various informations on the file/directory identified by the <pathname> argument.
     502 * TODO only the <st_ino>, <st_mode>,<st_uid>,<st_gid>,<st_size> are set.
    499503 ******************************************************************************************
    500504 * @ pathname  : user pointer on file pathname.
Note: See TracChangeset for help on using the changeset viewer.