Changeset 659 for trunk/user/init


Ignore:
Timestamp:
Oct 10, 2020, 3:58:01 PM (4 years ago)
Author:
alain
Message:

euh...

File:
1 edited

Legend:

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

    r635 r659  
    66// This single thread application implement the "init" process for ALMOS-MKH.
    77// It uses the fork/exec syscalls to create N KSH child processes
    8 // (one child process per user terminal).
    9 // Then calls the wait() function to block, and reactivate any child KSH process
     8// (one child process per user TXT terminal).
     9// Then calls the wait() function to block, and recreate any child KSH process
    1010// that has been deleted, using a new fork/exec.
    11 // It includes the hard_config.h file to get th NB_TXT_CHANNELS parameter.
    1211///////////////////////////////////////////////////////////////////////////////////////
    1312
    14 #include <hard_config.h>
    1513#include <unistd.h>
    1614#include <stdlib.h>
     
    2018#include <hal_macros.h>
    2119#include <sys/wait.h>
     20#include <shared_syscalls.h>
    2221
    23 #define DEBUG_PROCESS_INIT    0
    24 
    25 // TODO improve the get_config() syscall to return nb_txt_channels
    26 // and avoid the hard_config include [AG]
     22#define DEBUG_PROCESS_INIT    1
    2723
    2824////////////////
    2925int main( void )
    3026{
    31     int           i;
     27    unsigned int  i;
    3228    int           ret_fork;      // fork return value 
    3329    int           ret_exec;      // exec return value 
     
    4036#endif
    4137
     38    // get Number of TXT channels from hard configuration
     39    hard_config_t config;     
     40    get_config( &config );
     41
     42    unsigned int  txt_channels = config.txt_channels;
     43    unsigned int  x_size       = config.x_size;
     44    unsigned int  y_size       = config.y_size;
     45    unsigned int  ncores       = config.ncores;
     46
    4247    // check number of TXT channels
    43     if( NB_TXT_CHANNELS < 2 )
     48    if( txt_channels < 2 )
    4449    {
    45         printf("\n[ERROR] in init process : number of TXT channels must be larger than 1\n");
     50        snprintf( string , 64 ,
     51        "\n[init ERROR] number of TXT channels must be larger than 1\n");
     52        display_string( string );
    4653        exit( EXIT_FAILURE );
    4754    }
    4855
    4956    // create the KSH processes (one per user terminal)
    50     for( i = 1 ; i <  NB_TXT_CHANNELS ; i++ )
     57    for( i = 1 ; i <  txt_channels ; i++ )
    5158    {
    5259        // INIT process fork process CHILD[i]
     
    5663        {
    5764            // INIT display error message 
    58             snprintf( string , 64 , "[init ERROR] cannot fork child[%d] => suicide" , i );
     65            snprintf( string , 64 ,
     66            "[init ERROR] cannot fork child[%d] => suicide" , i );
    5967            display_string( string );
    6068
    6169            // INIT suicide
    62             exit( 0 );
     70            exit( EXIT_FAILURE );
    6371        }
    6472        else if( ret_fork == 0 )                    // we are in CHILD[i] process
     
    7381                "[init ERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec );
    7482                display_string( string );
     83
     84                // CHILD[i] suicide
     85                exit( EXIT_FAILURE );
    7586            }
    7687        }
     
    7889        {
    7990            // INIT display CHILD[i] process PID
    80             snprintf( string , 64 , "[init] (pid 0x1) created ksh[%d] (pid %x)", i , ret_fork );
     91            snprintf( string , 64 ,
     92            "[init] (pid 0x1) created ksh[%d] (pid %x)", i , ret_fork );
    8193            display_string( string );
    8294
    83             // wait signal from KSH[i]
     95            // wait signal from KSH[i] before creating KSH[i+1]
    8496            pause();
    8597        }
     
    88100#if DEBUG_PROCESS_INIT
    89101{
    90     unsigned int  x_size;        // number of clusters in a row
    91     unsigned int  y_size;        // number of clusters in a column
    92     unsigned int  ncores;        // number of cores per cluster
    93102    unsigned int  x;             // cluster x coordinate
    94103    unsigned int  y;             // cluster y coordinate
    95104    unsigned int  cxy;           // cluster identifier
    96105    unsigned int  lid;           // core local index
    97 
    98     // get hardware config
    99     get_config( &x_size , &y_size , &ncores );
    100106
    101107    // INIT displays processes and threads in all clusters
Note: See TracChangeset for help on using the changeset viewer.