Changeset 440 for trunk/user/init/init.c


Ignore:
Timestamp:
May 3, 2018, 5:51:22 PM (6 years ago)
Author:
alain
Message:

1/ Fix a bug in the Multithreaded "sort" applicationr:
The pthread_create() arguments must be declared as global variables.
2/ The exit syscall can be called by any thread of a process..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/init/init.c

    r438 r440  
    77// It uses the fork/exec syscalls to create N KSH child processes
    88// (one child process per user terminal).
    9 // It includes the hard_config.h file to get th NB_TXT_CHANNELS parameter.
    10 //
    11 // TODO : Register the PIDs for all KSH[i] in a ksh_pid[] array.
    129// Then calls the wait() function to block, and reactivate any child KSH process
    1310// that has been deleted, using a new fork/exec.
     11// It includes the hard_config.h file to get th NB_TXT_CHANNELS parameter.
    1412///////////////////////////////////////////////////////////////////////////////////////
    1513
     
    1917#include <stdio.h>
    2018#include <pthread.h>
     19
     20#define DEBUG_INIT 1
     21
     22// TODO make the cxy computation portable [AG]
     23#define CXY_FROM_XY( x , y )  ((x<<4) + y)
    2124
    2225//////////
     
    4346        {
    4447            // INIT display error message 
    45             snprintf( string , 64 , "INIT cannot fork child[%d] => suicide" , i );
     48            snprintf( string , 64 , "[INIT] cannot fork child[%d] => suicide" , i );
    4649            display_string( string );
    4750
     
    5861                // CHILD[i] display error message
    5962                snprintf( string , 64 ,
    60                 "CHILD[%d] cannot exec KSH[%d] / ret_exec = %d" , i , i , ret_exec );
     63                "[INIT ERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec );
    6164                display_string( string );
    6265            }
     
    6568        {
    6669             // INIT display CHILD[i] process PID
    67              snprintf( string , 64 , "INIT created KSH[%d] / pid = %x", i , ret_fork );
     70             snprintf( string , 64 , "[INIT] created KSH[%d] / pid = %x", i , ret_fork );
    6871             display_string( string );
    6972
     
    7275        }
    7376    }
     77 
     78#if DEBUG_INIT
    7479
    75 // INIT display processes and threads in clusters 0 & 1
    76 display_cluster_processes( 0 );
    77 display_sched( 0 , 0 );
    78 display_cluster_processes( 1 );
    79 display_sched( 1 , 0 );
     80    unsigned int  x_size;        // number of clusters in a row
     81    unsigned int  y_size;        // number of clusters in a column
     82    unsigned int  ncores;        // number of cores per cluster
     83    unsigned int  x;             // cluster x coordinate
     84    unsigned int  y;             // cluster y coordinate
     85    unsigned int  cxy;           // cluster identifier
     86    unsigned int  lid;           // core local index
     87
     88    // get hardware config
     89    get_config( &x_size , &y_size , &ncores );
     90   
     91    // INIT displays processes and threads in all clusters
     92    for( x = 0 ; x < x_size ; x++ )
     93    {
     94        for( y = 0 ; y < y_size ; y++ )
     95        {
     96            cxy = CXY_FROM_XY( x , y );
     97            display_cluster_processes( cxy );
     98            for( lid = 0 ; lid < ncores ; lid++ )
     99            {
     100                display_sched( cxy , lid );
     101            }
     102        }
     103    }
     104
     105#endif
    80106
    81107    // This loop detects the termination of the KSH[i] processes,
     
    89115        {
    90116            // display string to report unexpected KSH process block
    91             snprintf( string , 64 , "KSH process %x stopped => unblock it" , rcv_pid );
     117            snprintf( string , 64 , "[INIT] KSH process %x stopped => unblock it" , rcv_pid );
    92118            display_string( string );
    93119
    94             // TODO : unblock KSH
     120            // TODO : unblock KSH [AG]
    95121
    96122        }  // end KSH stopped handling
     
    99125        {
    100126            // display string to report KSH process termination
    101             snprintf( string , 64 , "KSH process %x terminated => recreate KSH", rcv_pid );
     127            snprintf( string , 64 , "[INIT] KSH process %x terminated => recreate", rcv_pid );
    102128            display_string( string );
    103129
     
    108134            {
    109135                // INIT display error message
    110                 snprintf( string , 64 , "INIT cannot fork child => suicide");
     136                snprintf( string , 64 , "[INIT ERROR] cannot fork child => suicide");
    111137                display_string( string );
    112138
     
    122148                {
    123149                    // CHILD display error message on TXT0 terminal
    124                     snprintf( string , 64 , "CHILD cannot exec KSH" );
     150                    snprintf( string , 64 , "[INIT ERROR] CHILD cannot exec KSH" );
    125151                    display_string( string );
    126152                }
     
    129155            {
    130156                // INIT display new CHILD process PID
    131                 snprintf( string , 64 , "INIT forked CHILD / pid = %x", ret_fork );
     157                snprintf( string , 64 , "[INIT] forked CHILD / pid = %x", ret_fork );
    132158                display_string( string );
    133159            }
    134160        } // end KSH kill handling
    135161
    136 // INIT wait a fixed delay
    137 for( delay = 0 ; delay < 50000 ; delay++ ) asm volatile( "nop" );
     162#if( DEBUG_INIT )
    138163
    139 // INIT display processes and threads in clusters 0 & 1
    140 display_cluster_processes( 0 );
    141 display_sched( 0 , 0 );
    142 display_cluster_processes( 1 );
    143 display_sched( 1 , 0 );
     164        // INIT displays processes and threads in all clusters
     165        for( x = 0 ; x < x_size ; x++ )
     166        {
     167            for( y = 0 ; y < y_size ; y++ )
     168            {
     169                cxy = CXY_FROM_XY( x , y );
     170                display_cluster_processes( cxy );
     171                for( lid = 0 ; lid < ncores ; lid++ )
     172                {
     173                    display_sched( cxy , lid );
     174                }
     175            }
     176        }
     177
     178#endif
    144179
    145180    }  // end while waiting KSH[i] termination
Note: See TracChangeset for help on using the changeset viewer.