Changeset 659 for trunk/user/init/init.c
- Timestamp:
- Oct 10, 2020, 3:58:01 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/init/init.c
r635 r659 6 6 // This single thread application implement the "init" process for ALMOS-MKH. 7 7 // 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 re activate any child KSH process8 // (one child process per user TXT terminal). 9 // Then calls the wait() function to block, and recreate any child KSH process 10 10 // that has been deleted, using a new fork/exec. 11 // It includes the hard_config.h file to get th NB_TXT_CHANNELS parameter.12 11 /////////////////////////////////////////////////////////////////////////////////////// 13 12 14 #include <hard_config.h>15 13 #include <unistd.h> 16 14 #include <stdlib.h> … … 20 18 #include <hal_macros.h> 21 19 #include <sys/wait.h> 20 #include <shared_syscalls.h> 22 21 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 27 23 28 24 //////////////// 29 25 int main( void ) 30 26 { 31 inti;27 unsigned int i; 32 28 int ret_fork; // fork return value 33 29 int ret_exec; // exec return value … … 40 36 #endif 41 37 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 42 47 // check number of TXT channels 43 if( NB_TXT_CHANNELS< 2 )48 if( txt_channels < 2 ) 44 49 { 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 ); 46 53 exit( EXIT_FAILURE ); 47 54 } 48 55 49 56 // 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++ ) 51 58 { 52 59 // INIT process fork process CHILD[i] … … 56 63 { 57 64 // 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 ); 59 67 display_string( string ); 60 68 61 69 // INIT suicide 62 exit( 0);70 exit( EXIT_FAILURE ); 63 71 } 64 72 else if( ret_fork == 0 ) // we are in CHILD[i] process … … 73 81 "[init ERROR] CHILD[%d] cannot exec KSH / ret_exec = %d" , i , ret_exec ); 74 82 display_string( string ); 83 84 // CHILD[i] suicide 85 exit( EXIT_FAILURE ); 75 86 } 76 87 } … … 78 89 { 79 90 // 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 ); 81 93 display_string( string ); 82 94 83 // wait signal from KSH[i] 95 // wait signal from KSH[i] before creating KSH[i+1] 84 96 pause(); 85 97 } … … 88 100 #if DEBUG_PROCESS_INIT 89 101 { 90 unsigned int x_size; // number of clusters in a row91 unsigned int y_size; // number of clusters in a column92 unsigned int ncores; // number of cores per cluster93 102 unsigned int x; // cluster x coordinate 94 103 unsigned int y; // cluster y coordinate 95 104 unsigned int cxy; // cluster identifier 96 105 unsigned int lid; // core local index 97 98 // get hardware config99 get_config( &x_size , &y_size , &ncores );100 106 101 107 // INIT displays processes and threads in all clusters
Note: See TracChangeset
for help on using the changeset viewer.