Ignore:
Timestamp:
Oct 4, 2018, 11:50:21 PM (6 years ago)
Author:
alain
Message:

Complete restructuration of kernel locks.

File:
1 edited

Legend:

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

    r506 r566  
    3535#include <kmem.h>
    3636#include <process.h>
    37 #include <spinlock.h>
    3837#include <dqdt.h>
    3938#include <rpc.h>
     
    4140#include <syscalls.h>
    4241
    43 ///////////////////////////////////////////////////
    44 int sys_thread_create(
    45   struct thread_s             * new_thread,
    46   const struct pthread_attr_s * user_attr,
    47   const void                  * start_func,
    48   const void                  * start_args )
     42/////////////////////////////////////////////////////////
     43int sys_thread_create( trdid_t               * trdid_ptr,
     44                       struct pthread_attr_s * user_attr,
     45                       void                  * start_func,
     46                       void                  * start_args )
    4947{
    5048        pthread_attr_t   kern_attr;        // copy of pthread attributes in kernel space
    5149        thread_t       * parent;           // pointer on thread executing the pthread_create
    52         xptr_t           parent_xp;        // extended pointer on created thread
     50        xptr_t           parent_xp;        // extended pointer on calling thread
     51    cxy_t            child_cxy;        // created child thread cluster identifier
    5352        thread_t       * child_ptr;        // pointer on created child thread
    5453        xptr_t           child_xp;         // extended pointer on created thread
     
    5655        process_t      * process;          // pointer on local process descriptor
    5756        vseg_t         * vseg;             // required for user space checking
    58     cxy_t            target_cxy;       // target cluster identifier
    5957        error_t          error;
    6058
     
    6967tm_start = hal_get_cycles();
    7068if( DEBUG_SYS_THREAD_CREATE < tm_start )
    71 printk("\n[DBG] %s : thread %x (cxy %x) enter / process %x / cycle %d\n",
    72 __FUNCTION__, parent, local_cxy, process->pid, (uint32_t)tm_start );
     69printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
     70__FUNCTION__, parent->trdid, process->pid, (uint32_t)tm_start );
    7371#endif
    7472
    7573    // check trdid buffer in user space
    76     error = vmm_get_vseg( process , (intptr_t)new_thread , &vseg );
     74    error = vmm_get_vseg( process , (intptr_t)trdid_ptr , &vseg );
    7775
    7876    if ( error )
     
    8078
    8179#if DEBUG_SYSCALLS_ERROR
    82 printk("\n[ERROR] in %s : trdid buffer unmapped %x / thread %x / process %x\n",
    83 __FUNCTION__ , (intptr_t)new_thread, parent->trdid, process->pid );
     80printk("\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 );
    8482vmm_display( process , false );
    8583#endif
     
    9795
    9896#if DEBUG_SYSCALLS_ERROR
    99 printk("\n[ERROR] in %s : user_attr buffer unmapped %x / thread %x / process %x\n",
    100 __FUNCTION__ , (intptr_t)user_attr , parent->trdid , process->pid );
     97printk("\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 );
    10199vmm_display( process , false );
    102100#endif
     
    115113
    116114#if DEBUG_SYSCALLS_ERROR
    117 printk("\n[ERROR] in %s : start_func unmapped %x / thread %x / process %x\n",
    118 __FUNCTION__ , (intptr_t)start_func , parent->trdid , process->pid );
     115printk("\n[ERROR] in %s : thread %x in process %x / start_func unmapped %x\n",
     116__FUNCTION__, parent->trdid, process->pid, (intptr_t)start_func );
    119117vmm_display( process , false );
    120118#endif
     
    132130
    133131#if DEBUG_SYSCALLS_ERROR
    134 printk("\n[ERROR] in %s : start_args buffer unmapped %x / thread %x / process %x\n",
    135 __FUNCTION__ , (intptr_t)start_args , parent->trdid , process->pid );
     132printk("\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 );
    136134vmm_display( process , false );
    137135#endif
     
    141139        }
    142140
    143     // define attributes and target_cxy
     141    // define attributes and child_cxy
    144142    if( user_attr != NULL )                      // user defined attributes
    145143    {
    146             // check / get target_cxy
     144            // check / get child_cxy
    147145            if( kern_attr.attributes & PT_ATTR_CLUSTER_DEFINED )
    148146            {
     
    151149
    152150#if DEBUG_SYSCALLS_ERROR
    153 printk("\n[ERROR] in %s : illegal target cluster = %x / thread %x / process %x\n",
    154 __FUNCTION__ , kern_attr.cxy, parent->trdid, process->pid );
     151printk("\n[ERROR] in %s : thread %x in process %x / illegal target cluster %x\n",
     152__FUNCTION__, parent->trdid, process->pid, kern_attr.cxy );
    155153#endif
    156154                            parent->errno = EINVAL;
    157155                            return -1;
    158156            }
    159             target_cxy = kern_attr.cxy;
     157            child_cxy = kern_attr.cxy;
    160158                }
    161159        else
    162160        {
    163             target_cxy = dqdt_get_cluster_for_process();
     161            child_cxy = dqdt_get_cluster_for_process();
    164162        }
    165163        }
     
    167165        {
    168166        kern_attr.attributes = PT_ATTR_DETACH | PT_ATTR_CLUSTER_DEFINED;
    169         target_cxy           = dqdt_get_cluster_for_process();
     167        child_cxy           = dqdt_get_cluster_for_process();
    170168        }
    171169
     
    173171        // this returns "error", "child_ptr", and "child_xp"
    174172
    175         if( target_cxy == local_cxy )                         // target cluster is local
     173        if( child_cxy == local_cxy )                         // target cluster is local
    176174        {
    177175                // create thread in local cluster
     
    186184        else                                                 // target cluster is remote
    187185        {
    188                 rpc_thread_user_create_client( target_cxy,
     186                rpc_thread_user_create_client( child_cxy,
    189187                                               process->pid,
    190188                                               start_func,
     
    202200
    203201#if DEBUG_SYSCALLS_ERROR
    204 printk("\n[ERROR] in %s : cannot create new thread / thread %x / process %x\n",
     202printk("\n[ERROR] in %s : thread %x in process %x cannot create new thread\n",
    205203__FUNCTION__ , parent->trdid, process->pid );
    206204#endif
     
    210208
    211209        // returns trdid to user space
    212         trdid = hal_remote_lw( XPTR( target_cxy , &child_ptr->trdid ) );
    213         hal_copy_to_uspace( new_thread , &trdid , sizeof(pthread_t) );
     210        trdid = hal_remote_l32( XPTR( child_cxy , &child_ptr->trdid ) );
     211        hal_copy_to_uspace( trdid_ptr , &trdid , sizeof(pthread_t) );
    214212
    215213    // activate new thread
     
    221219tm_end = hal_get_cycles();
    222220if( DEBUG_SYS_THREAD_CREATE < tm_end )
    223 printk("\n[DBG] %s : thread %x (cxy %x) created thread %x (cxy %x) / process %x / cycle %d\n",
    224 __FUNCTION__, parent, local_cxy, child_ptr, target_cxy, process->pid, (uint32_t)tm_end );
     221printk("\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 );
    225223#endif
    226224
Note: See TracChangeset for help on using the changeset viewer.