Changeset 172 for trunk


Ignore:
Timestamp:
Jul 11, 2017, 10:32:25 AM (7 years ago)
Author:
max@…
Message:

style

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/process.c

    r124 r172  
    11/*
    22 * process.c - process related management
    3  * 
     3 *
    44 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
    55 *          Mohamed Lamine Karaoui (2015)
     
    1010 * This file is part of ALMOS-MKH..
    1111 *
    12  * ALMOS-MKH. is free software; you can redistribute it and/or modify it
     12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1313 * under the terms of the GNU General Public License as published by
    1414 * the Free Software Foundation; version 2.0 of the License.
    1515 *
    16  * ALMOS-MKH. is distributed in the hope that it will be useful, but
     16 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1717 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    2020 *
    2121 * You should have received a copy of the GNU General Public License
    22  * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
     22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    2323 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2424 */
     
    9595    // get parent process cluster, local pointer, and pid
    9696    // for all processes other than process_zero
    97     if( process == &process_zero ) 
     97    if( process == &process_zero )
    9898    {
    9999        assert( (pid == 0) , __FUNCTION__ , "process_zero must have PID = 0\n");
     
    113113    if( pid ) vmm_init( process );
    114114
    115     // reset reference process file descriptors array 
     115    // reset reference process file descriptors array
    116116        process_fd_init( process );
    117117
     
    140140        xlist_add_first( root , entry );
    141141    }
    142    
     142
    143143    // reset th_tbl[] array as empty
    144144    uint32_t i;
     
    154154    process->ppid  = parent_pid;
    155155
    156     // set ref_xp field 
     156    // set ref_xp field
    157157    process->ref_xp = XPTR( local_cxy , process );
    158158
     
    163163    cluster_process_copies_link( process );
    164164
    165     // initalise signal manager TODO [AG]
     165    // initialize signal manager TODO [AG]
    166166
    167167        hal_fence();
     
    169169    process_dmsg("\n[INFO] %s : exit for process %x in cluster %x\n",
    170170                 __FUNCTION__ , pid );
    171 
    172 } // end process_reference_init()
     171}
    173172
    174173/////////////////////////////////////////////////////
     
    180179    process_t * ref_ptr = (process_t *)GET_PTR( reference_process_xp );
    181180
    182     // reset local process vmm 
     181    // reset local process vmm
    183182    vmm_init( local_process );
    184183
    185     // reset process file descriptors array 
     184    // reset process file descriptors array
    186185        process_fd_init( local_process );
    187186
     
    198197    // reset children list root (not used in a process descriptor copy)
    199198    xlist_root_init( XPTR( local_cxy , &local_process->children_root ) );
    200     local_process->children_nr   = 0;           
     199    local_process->children_nr   = 0;
    201200
    202201    // reset brothers list (not used in a process descriptor copy)
     
    224223    cluster_process_copies_link( local_process );
    225224
    226     // initalise signal manager TODO [AG]
     225    // initialize signal manager TODO [AG]
    227226
    228227        hal_fence();
    229228
    230229    return 0;
    231 
    232 }  // end process_copy_init()
     230}
    233231
    234232///////////////////////////////////////////
    235233void process_destroy( process_t * process )
    236234{
    237         if( process->th_nr != 0 ) 
     235        if( process->th_nr != 0 )
    238236    {
    239237            printk("\n[PANIC] in %s : process %x in cluster %x has still active threads\n",
     
    248246    remote_spinlock_lock( XPTR( local_cxy , &pmgr->local_lock ) );
    249247
    250     // remove the process descriptor from local_list in local cluster manager 
     248    // remove the process descriptor from local_list in local cluster manager
    251249    xlist_unlink( XPTR( local_cxy , &process->local_list ) );
    252250
     
    263261    xlist_unlink( XPTR( local_cxy , &process->copies_list ) );
    264262    remote_spinlock_unlock( copies_lock );
    265    
     263
    266264    // synchronize memory
    267265        hal_fence();
    268266
    269     // From this point, the process descriptor is unreachable 
     267    // From this point, the process descriptor is unreachable
    270268
    271269    // close all open files and update dirty TODO [AG]
     
    283281        process_dmsg("\n[INFO] %s for pid %d / page_faults = %d\n",
    284282                 __FUNCTION__ , process->pid, process->vmm.pgfault_nr );
    285 
    286 }  // end process_destroy()
     283}
    287284
    288285////////////////////////////////////////
     
    298295    // first loop on threads to send the THREAD_SIG_KILL signal to all process threads
    299296    // we use both "ltid" and "count" indexes, because it can exist "holes" in th_tbl
    300     for( ltid = 0 , count = 0  ; 
    301          (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ; 
     297    for( ltid = 0 , count = 0  ;
     298         (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ;
    302299         ltid++ )
    303300    {
     
    309306            count++;
    310307        }
    311     }   
    312    
     308    }
     309
    313310    volatile uint32_t ko;
    314311
    315312    // second loop on threads to wait acknowledge from scheduler,
    316313    // unlink thread from process and parent thread, and release thread descriptor
    317     for( ltid = 0 , count = 0  ; 
     314    for( ltid = 0 , count = 0  ;
    318315         (ltid < CONFIG_THREAD_MAX_PER_CLUSTER) && (count < process->th_nr) ;
    319316         ltid++ )
     
    327324
    328325            // unlink thread from brothers list if required
    329             if( (thread->flags & THREAD_FLAG_DETACHED) == 0 ) 
     326            if( (thread->flags & THREAD_FLAG_DETACHED) == 0 )
    330327            xlist_unlink( XPTR( local_cxy , &thread->brothers_list ) );
    331328
     
    345342    // release memory allocated for process descriptor
    346343    process_destroy( process );
    347 
    348 }  // end process_kill()
    349 
    350 
     344}
    351345
    352346///////////////////////////////////////////////
     
    354348{
    355349    error_t        error;
    356     process_t    * process_ptr;   // local pointer on process 
     350    process_t    * process_ptr;   // local pointer on process
    357351    xptr_t         process_xp;    // extended pointer on process
    358352    pid_t          process_pid;   // process identifier
     
    370364        process_xp  = XLIST_ELEMENT( iter , process_t , local_list );
    371365        process_ptr = (process_t *)GET_PTR( process_xp );
    372         process_pid = hal_remote_lw( XPTR( local_cxy , &process_ptr->pid ) ); 
     366        process_pid = hal_remote_lw( XPTR( local_cxy , &process_ptr->pid ) );
    373367        if( process_ptr->pid == pid )
    374368        {
     
    381375    remote_spinlock_unlock( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
    382376
    383     // allocate memory for a new local process descriptor 
     377    // allocate memory for a new local process descriptor
    384378    // and initialise it from reference cluster if required
    385379    if( !found )
     
    400394
    401395    return process_ptr;
    402 } // end process_get_local_copy()
    403 
     396}
    404397
    405398//////////////////////////////////////////////////////////////////////////////////////////
     
    423416}
    424417
    425 
    426418//////////////////////////////
    427419bool_t process_fd_array_full()
    428420{
    429     // get extended pointer on reference process 
     421    // get extended pointer on reference process
    430422    xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;
    431423
     
    437429    uint32_t current = hal_remote_lw( XPTR( ref_cxy , &ref_ptr->fd_array.current ) );
    438430
    439         return ( current >= CONFIG_PROCESS_FILE_MAX_NR ); 
     431        return ( current >= CONFIG_PROCESS_FILE_MAX_NR );
    440432}
    441433
    442434/////////////////////////////////////////////////
    443 error_t process_fd_register(  xptr_t     file_xp, 
     435error_t process_fd_register(  xptr_t     file_xp,
    444436                              uint32_t * file_id )
    445437{
     
    448440    xptr_t    xp;
    449441
    450     // get extended pointer on reference process 
     442    // get extended pointer on reference process
    451443    xptr_t ref_xp = CURRENT_THREAD->process->ref_xp;
    452444
     
    478470    if ( !found ) return EMFILE;
    479471    else          return 0;
    480 
    481 }  // end process_fd_register()
    482 
    483 ////////////////////////////////////////////////
     472}
     473
     474////////////////////////////////////////////////
    484475xptr_t process_fd_get_xptr( process_t * process,
    485476                            uint32_t    file_id )
     
    508499
    509500    return file_xp;
    510 
    511 }  // end process_fd_get_xptr()
     501}
    512502
    513503///////////////////////////////////////////
     
    529519        remote_spinlock_lock( XPTR( src_cxy , &src_ptr->lock ) );
    530520
    531     // loop on all entries in source process fd_array       
     521    // loop on all entries in source process fd_array
    532522    for( fd = 0 ; fd < CONFIG_PROCESS_FILE_MAX_NR ; fd++ )
    533523        {
     
    546536    // release lock on source process fd_array
    547537        remote_spinlock_unlock( XPTR( src_cxy , &src_ptr->lock ) );
    548 }
    549 
    550 
     538}
    551539
    552540////////////////////////////////////////////////////////////////////////////////////
     
    588576
    589577    return (found) ? 0 : ENOMEM;
    590 
    591 }  // process_register_thread()
    592    
     578}
    593579///////////////////////////////////////////////
    594580void process_remove_thread( thread_t * thread )
     
    599585        hal_core_sleep();
    600586    }
    601    
     587
    602588    process_t * process = thread->process;
    603589
     
    608594    process->th_tbl[ltid] = NULL;
    609595    process->th_nr--;
    610 
    611 }  // process_remove_thread()
    612 
     596}
    613597
    614598/////////////////////////////////////////////////////
     
    616600{
    617601    char           * path;                            // pathname to .elf file
    618     process_t      * process;                         // local pointer on new process 
     602    process_t      * process;                         // local pointer on new process
    619603    pid_t            pid;                             // new process pid
    620604    xptr_t           parent_xp;                       // extended pointer on parent process
     
    626610    core_t         * core;                            // pointer on selected core
    627611    lid_t            lid;                             // selected core local index
    628         error_t          error; 
     612        error_t          error;
    629613
    630614        // get parent and .elf pathname from exec_info
     
    636620    parent_ptr = (process_t *)GET_PTR( parent_xp );
    637621    parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    638    
     622
    639623    exec_dmsg("\n[INFO] %s enters in cluster %x for path = %s\n",
    640624                __FUNCTION__ , local_cxy , path );
     
    650634    }
    651635
    652     // get a pid from the local cluster 
     636    // get a pid from the local cluster
    653637    error = cluster_pid_alloc( XPTR( local_cxy , process ) , &pid );
    654638
    655639    if( error )
    656640    {
    657         printk("\n[ERROR] in %s : cannot get PID / cluster = %x / ppid = %x / path = %s\n", 
     641        printk("\n[ERROR] in %s : cannot get PID / cluster = %x / ppid = %x / path = %s\n",
    658642               __FUNCTION__ , local_cxy , parent_pid , path );
    659643                return ENOMEM;
    660644    }
    661  
     645
    662646    // initialize the process descriptor as the reference
    663647    process_reference_init( process , pid , parent_xp );
    664                                
     648
    665649    exec_dmsg("\n[INFO] %s created process %x cluster %x / path = %s\n",
    666650                __FUNCTION__, parent_pid , local_cxy , path );
    667651
    668     // initializes vfs_root and vfs_cwd from parent process
     652    // initialize vfs_root and vfs_cwd from parent process
    669653    xptr_t  vfs_root_xp = hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->vfs_root_xp ) );
    670654        vfs_file_count_up( vfs_root_xp );
     
    688672                __FUNCTION__ , local_cxy , pid , path );
    689673
    690     // register "code" and "data" vsegs as well a the process entry-point in VMM,
    691     // using informations contained in the elf file.
     674    // register "code" and "data" vsegs as well as the process entry-point in VMM,
     675    // using information contained in the elf file.
    692676        error = elf_load_process( path , process );
    693677
    694678        if( error )
    695679        {
    696                 printk("\n[ERROR] in %s : failed to access elf file for process %x / path = %s\n", 
     680                printk("\n[ERROR] in %s : failed to access elf file for process %x / path = %s\n",
    697681                       __FUNCTION__, pid , path );
    698682        process_destroy( process );
     
    722706    attr.lid        = lid;
    723707
    724     // create and initialise thread descriptor
     708    // create and initialize thread descriptor
    725709        error = thread_user_create( pid,
    726710                                (void *)process->vmm.entry_point,
    727711                                exec_info->args_pointers,
    728712                                &attr,
    729                                 &thread ); 
     713                                &thread );
    730714        if( error )
    731715        {
     
    741725        hal_remote_atomic_add( XPTR( parent_cxy , &parent_ptr->children_nr) , 1 );
    742726
    743         // Register thread in scheduler
     727        // register thread in scheduler
    744728        sched_register_thread( core , thread );
    745729
     
    747731               __FUNCTION__ , pid , core->lid , local_cxy );
    748732
    749     // activate new thread 
     733    // activate new thread
    750734        thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
    751735
    752736        return 0;
    753 
    754 } // end process_make_exec()
     737}
    755738
    756739//////////////////////////
     
    765748    xptr_t    stdout_xp;
    766749    xptr_t    stderr_xp;
    767     uint32_t  stdin_id; 
    768     uint32_t  stdout_id; 
    769     uint32_t  stderr_id; 
     750    uint32_t  stdin_id;
     751    uint32_t  stdout_id;
     752    uint32_t  stderr_id;
    770753
    771754        process_dmsg("\n[INFO] %s enters in cluster %x\n", __FUNCTION__ , local_cxy );
     
    816799               
    817800    hal_fence();
    818 
    819 } // end process_init_create()
    820 
    821 
     801}
     802
Note: See TracChangeset for help on using the changeset viewer.