Changeset 614 for trunk/kernel/libk


Ignore:
Timestamp:
Jan 15, 2019, 1:59:32 PM (5 years ago)
Author:
alain
Message:

1) introduce a dev_ioc_sync_write() function in IOC API,

to improve the DEVFS synchronous update.

2) fix a big bug in both the user_dir_create() and user_dir_destroy()

functions: add an extended pointer on the reference client process
in the function's arguments.

Location:
trunk/kernel/libk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/user_dir.c

    r613 r614  
    8080}  // end user_dir_from_ident()
    8181
    82 ///////////////////////////////////////////////////
    83 user_dir_t * user_dir_create( vfs_inode_t * inode )
     82//////////////////////////////////////////////////
     83user_dir_t * user_dir_create( vfs_inode_t * inode,
     84                              xptr_t        ref_xp )
    8485{
    8586    user_dir_t    * dir;               // local pointer on created user_dir_t
    8687    vseg_t        * vseg;              // local pointer on dirent array vseg
    8788    uint32_t        vseg_size;         // size of vseg in bytes
    88     process_t     * process;           // local pointer on calling process
    89     xptr_t          ref_xp;            // extended pointer on reference process
    9089    process_t     * ref_ptr;           // local pointer on reference process
    9190    cxy_t           ref_cxy;           // reference process cluster identifier
     91    pid_t           ref_pid;           // reference process PID
    9292    xptr_t          gpt_xp;            // extended pointer on reference process GPT
    9393    uint32_t        gpt_attributes;    // attributes for all mapped gpt entries
     
    109109    error_t         error;
    110110
    111     // get pointer on local process descriptor
    112     process = CURRENT_THREAD->process;
     111    // get cluster, local pointer, and pid of reference user process
     112    ref_cxy = GET_CXY( ref_xp );
     113    ref_ptr = GET_PTR( ref_xp );
     114    ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) );
    113115
    114116#if DEBUG_USER_DIR
     
    116118thread_t * this = CURRENT_THREAD;
    117119if( cycle > DEBUG_USER_DIR )
    118 printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) / cycle %d\n",
    119 __FUNCTION__, process->pid, this->trdid, local_cxy, inode, cycle );
     120printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) and process %x / cycle %d\n",
     121__FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, ref_pid, cycle );
    120122#endif
    121123
     
    128130    // initialise temporary list of pages
    129131    list_root_init( &root );
    130 
    131     // get pointers on reference process
    132     ref_xp  = process->ref_xp;
    133     ref_cxy = GET_CXY( ref_xp );
    134     ref_ptr = GET_PTR( ref_xp );
    135132
    136133    // allocate memory for a local user_dir descriptor
     
    207204    } // end while
    208205       
     206#if DEBUG_USER_DIR
     207if( cycle > DEBUG_USER_DIR )
     208printk("\n[%s] thread[%x,%x] initialised dirent array / %d entries\n",
     209__FUNCTION__, this->process->pid, this->trdid, total_dirents, cycle );
     210#endif
     211
    209212    // compute required vseg size for a 64 bytes dirent
    210213    vseg_size = total_dirents << 6;
     
    213216    if( local_cxy == ref_cxy )
    214217    {
    215         vseg = vmm_create_vseg( process,
     218        vseg = vmm_create_vseg( ref_ptr,
    216219                                VSEG_TYPE_ANON,
    217220                                0,                      // vseg base (unused)
     
    220223                                0,                      // file_size (unused)
    221224                                XPTR_NULL,              // mapper (unused)
    222                                 ref_cxy );
     225                                local_cxy );
    223226    }
    224227    else
     
    232235                                    0,                     // file size (unused)
    233236                                    XPTR_NULL,             // mapper (unused)
    234                                     ref_cxy,
     237                                    local_cxy,
    235238                                    &vseg );
    236239    }
     240
    237241    if( vseg == NULL )
    238242    {
    239         printk("\n[ERROR] in %s : cannot create vseg for DIR in cluster %x\n",
     243        printk("\n[ERROR] in %s : cannot create vseg for user_dir in cluster %x\n",
    240244        __FUNCTION__, ref_cxy);
    241245        goto user_dir_create_failure;
    242246    }
    243247
    244 #if (DEBUG_USER_DIR & 1)
     248#if DEBUG_USER_DIR
    245249if( cycle > DEBUG_USER_DIR )
    246250printk("\n[%s] thread[%x,%x] allocated vseg ANON / base %x / size %x\n",
    247 __FUNCTION__, process->pid, this->trdid, vseg->min, vseg->max - vseg->min );
     251__FUNCTION__, this->process->pid, this->trdid, vseg->min, vseg->max - vseg->min );
    248252#endif
    249253
     
    289293            desc.lid       = CURRENT_THREAD->core->lid;
    290294            desc.blocking  = true;
    291             desc.args[0]   = process->pid;
     295            desc.args[0]   = ref_pid;
    292296            desc.args[1]   = vpn << CONFIG_PPM_PAGE_SHIFT;
    293297            rpc_vmm_delete_vseg_client( ref_cxy , &desc );
     
    299303        }
    300304
    301 #if (DEBUG_USER_DIR & 1)
     305#if DEBUG_USER_DIR
    302306if( cycle > DEBUG_USER_DIR )
    303307printk("\n[%s] thread[%x,%x] mapped vpn %x to ppn %x\n",
    304 __FUNCTION__, process->pid, this->trdid, vpn + page_id, ppn );
     308__FUNCTION__, this->process->pid, this->trdid, vpn + page_id, ppn );
    305309#endif
    306310
     
    340344if( cycle > DEBUG_USER_DIR )
    341345printk("\n[%s] thread[%x,%x] created user_dir (%x,%x) / %d entries / cycle %d\n",
    342 __FUNCTION__, process->pid, this->trdid, local_cxy, dir, total_dirents, cycle );
     346__FUNCTION__, this->process->pid, this->trdid, local_cxy, dir, total_dirents, cycle );
    343347#endif
    344348
     
    365369}  // end user_dir_create()
    366370
    367 /////////////////////////////////////////
    368 void user_dir_destroy( user_dir_t * dir )
     371////////////////////////////////////////
     372void user_dir_destroy( user_dir_t * dir,
     373                       xptr_t       ref_xp )
    369374{
    370     process_t    * process;    // local pointer on client process
    371     thread_t     * this;       // local pointer on client thread
     375    thread_t     * this;       // local pointer on calling thread
     376    process_t    * process;    // local pointer on calling process
    372377    cluster_t    * cluster;    // local pointer on local cluster
    373378    intptr_t       ident;      // user pointer on dirent array
    374     xptr_t         ref_xp;     // extended pointer on reference process
     379    xptr_t         ref_pid;    // reference process PID
    375380    cxy_t          ref_cxy;    // reference process cluster identifier
    376381    process_t    * ref_ptr;    // local pointer on reference process
     
    379384    xptr_t         iter_xp;    // iteratot in xlist
    380385    reg_t          save_sr;    // for critical section
    381     pid_t          pid;        // process descriptor
    382386    cxy_t          owner_cxy;  // owner process cluster
    383387    lpid_t         lpid;       // process local index
    384388    rpc_desc_t     rpc;        // rpc descriptor
    385389     
    386     // get pointers on client process & thread
     390    // get pointers on calling process & thread
    387391    this    = CURRENT_THREAD;
    388392    process = this->process;
    389393    cluster = LOCAL_CLUSTER;
    390394
     395    // get cluster, local pointer, and PID of reference user process
     396    ref_cxy = GET_CXY( ref_xp );
     397    ref_ptr = GET_PTR( ref_xp );
     398    ref_pid = hal_remote_l32( XPTR( ref_cxy , &ref_ptr->pid ) );
     399
    391400#if DEBUG_USER_DIR
    392401uint32_t cycle = (uint32_t)hal_get_cycles();
    393402if( cycle > DEBUG_USER_DIR )
    394 printk("\n[%s] thread[%x,%x] enter for user_dir (%x,%x) / cycle %d\n",
    395 __FUNCTION__, process->pid, this->trdid, local_cxy, dir, cycle );
     403printk("\n[%s] thread[%x,%x] enter for user_dir (%x,%x) and process %x / cycle %d\n",
     404__FUNCTION__, process->pid, this->trdid, local_cxy, dir, ref_pid, cycle );
    396405#endif
    397406
    398407    // get user pointer on dirent array
    399408    ident = dir->ident;
    400 
    401     // get pointers on reference process
    402     ref_xp  = process->ref_xp;
    403     ref_cxy = GET_CXY( ref_xp );
    404     ref_ptr = GET_PTR( ref_xp );
    405409
    406410    // build extended pointer on lock protecting open directories list
     
    424428
    425429    // get owner cluster identifier and process lpid
    426     pid       = process->pid;
    427     owner_cxy = CXY_FROM_PID( pid );
    428     lpid      = LPID_FROM_PID( pid );
     430    owner_cxy = CXY_FROM_PID( ref_pid );
     431    lpid      = LPID_FROM_PID( ref_pid );
    429432
    430433    // get root of list of copies and lock from owner cluster
     
    444447    rpc.thread    = this;
    445448    rpc.lid       = this->core->lid;
    446     rpc.args[0]   = process->pid;
     449    rpc.args[0]   = ref_pid;
    447450    rpc.args[1]   = ident;
    448451
  • trunk/kernel/libk/user_dir.h

    r613 r614  
    7070 * in the reference process descriptor.
    7171 *****************************************************************************************
    72  * @ ident    : DIR virtual address, used as identifier.
     72 * @ ident    : [in] DIR virtual address, used as identifier.
    7373 * @ returns extended pointer on user_dir_t if success / returns XPTR_NULL if not found.
    7474 ****************************************************************************************/
     
    7777/*****************************************************************************************
    7878 * This function allocates memory and initializes a user_dir_t structure in the cluster
    79  * containing the directory inode identified by the <inode> argument.
     79 * containing the directory inode identified by the <inode> argument and map the
     80 * user accessible dirent array in the reference user process VMM, identified by the
     81 * <ref_xp> argument.
    8082 * It must be executed by a thread running in the cluster containing the target inode.
    8183 * Use the RPC_USER_DIR_CREATE when the client thread is remote.
    8284 * It makes the following actions:
    83  * - the allocation of one user_dir_t descriptor in reference cluster.
     85 * - the allocation of one user_dir_t descriptor in the directory inode cluster.
    8486 * - the allocation of one or several physical pages in reference cluster to store
    8587 *   all directory entries in an array of 64 bytes dirent structures,
    8688 * - the initialisation of this array from informations found in the Inode Tree.
    87  * - the creation of an user accessible vseg containing this dirent array, and the
    88  *   mapping of all relevant physical pages in this vseg.
     89 * - the creation of an ANON vseg containing this dirent array in reference process VMM,
     90 *   and the mapping of the relevant physical pages in this vseg.
    8991 * - the registration of the created user_dir_t structure in the xlist rooted
    9092 *   in the reference process,
    9193 * It returns a local pointer on the created user_dir_t structure.
    9294 *****************************************************************************************
    93  * @ inode    : local pointer on the directory inode.
     95 * @ inode    : [in] local pointer on the directory inode.
     96 * @ ref_xp   : [in] extended pointer on the reference user process descriptor.
    9497 * @ return local pointer on user_dir_t if success / return XPTR_NULL if failure.
    9598 ****************************************************************************************/
    96 user_dir_t * user_dir_create( struct vfs_inode_s * inode );
     99user_dir_t * user_dir_create( struct vfs_inode_s * inode,
     100                              xptr_t               ref_xp );
    97101
    98102/*****************************************************************************************
    99103 * This function removes a user_dir_t structure from the xlist of user_dir_t
    100  * structures rooted in the reference process descriptor, and release all memory
    101  * allocated for the user_dir_t struct in the directory inode cluster,
    102  * including the dirent array.
     104 * structures rooted in the reference process descriptor, release all memory
     105 * allocated for the user_dir_t struct in the directory inode cluster, including
     106 * the dirent array, and delete all ANON vseg copies in all process VMM copies,
     107 * using parallel RPCs.
    103108 * It must be executed by a thread running in the cluster containing the target inode.
    104109 * Use the RPC_USER_DIR_DESTROY when the client thread is remote.
    105110 *****************************************************************************************
    106  * @ dir  : local pointer on user_dir_t structure.
     111 * @ dir      : [in] local pointer on user_dir_t structure.
     112 * @ ref_xp   : [in] extended pointer on the reference user process descriptor.
    107113 ****************************************************************************************/
    108 void user_dir_destroy( struct user_dir_s * dir );
     114void user_dir_destroy( struct user_dir_s * dir,
     115                       xptr_t              ref_xp );
    109116
    110117
  • trunk/kernel/libk/xhtab.c

    r612 r614  
    4242// XHTAB_DENTRY_TYPE
    4343// This functions compute the hash index from the key, that is the directory entry name.
     44// In this implementation, the index value is simply the ASCII code of the first
     45// character, to provide an approximate lexicographic order.
    4446///////////////////////////////////////////////////////////////////////////////////////////
    4547// @ key      : local pointer on name.
     
    4951{
    5052        char     * name  = key;
    51         uint32_t   index = 0;
     53
     54        return (name[0] % XHASHTAB_SIZE);
     55/*
     56    uint32_t   index = 0;
    5257        while( *name )
    5358    {
     
    5560    }
    5661        return index % XHASHTAB_SIZE;
     62*/
     63
    5764}
    5865
  • trunk/kernel/libk/xhtab.h

    r611 r614  
    6161///////////////////////////////////////////////////////////////////////////////////////////
    6262
    63 #define XHASHTAB_SIZE    8   // number of subsets
     63#define XHASHTAB_SIZE    128   // number of subsets
    6464
    6565/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.