Changeset 588 for trunk/user/ksh/ksh.c


Ignore:
Timestamp:
Nov 1, 2018, 12:44:35 PM (6 years ago)
Author:
alain
Message:

Introduce a signal based synchro between INIT and KSH processes
to sequencialize multiple KSH[i] processes creation.

File:
1 edited

Legend:

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

    r574 r588  
    4545#include <almosmkh.h>
    4646#include <semaphore.h>
     47#include <hal_macros.h>
    4748
    4849#define CMD_MAX_SIZE   (256)    // max number of characters in one command
     
    319320            cxy = atoi(argv[2]);
    320321
    321         if( display_cluster_processes( cxy ) )
     322        if( display_cluster_processes( cxy , 0 ) )
    322323        {
    323324            printf("  error: illegal argument cxy = %x\n", cxy );
     
    465466        char               * pathname;           // path to .elf file
    466467    unsigned int         background;         // background execution if non zero
    467 
    468         if( (argc < 2) || (argc > 3) ) 
    469     {
    470                 printf("  usage: %s pathname [&] / argc = %d\n", argv[0], argc );  // @@@
     468    unsigned int         placement;          // placement specified if non zero
     469    unsigned int         cxy;                // target cluster if placement specified
     470
     471        if( (argc < 2) || (argc > 4) ) 
     472    {
     473                printf("  usage: %s pathname [cxy] [&]\n", argv[0] );
    471474                return;
    472475        }
     
    474477        pathname = argv[1];
    475478
    476     if( argc == 3 ) background = (argv[2][0] == '&');
    477     else            background = 0;
     479    if( argc == 2 )
     480    {
     481        background = 0;
     482        placement  = 0;
     483        cxy        = 0;
     484    }
     485    else if( argc == 3 )
     486    {
     487        if( (argv[2][0] == '&') && (argv[2][1] == 0) )
     488        {
     489            background = 1;
     490            placement  = 0;
     491            cxy        = 0;
     492        }
     493        else
     494        {
     495            background = 0;
     496            placement  = 1;
     497            cxy        = atoi( argv[2] );
     498        }
     499    }
     500    else  // argc == 4
     501    {
     502        background = ( (argv[3][0] == '&') && (argv[3][1] == 0) );
     503        placement  = 1;
     504        cxy        = atoi( argv[2] );
     505    }
    478506
    479507    // get KSH process PID
     
    483511long long unsigned cycle;
    484512get_cycle( &cycle );
    485 printf("\n@@@ %s : KSH PID %x before fork / path %s / background %d / cycle %d\n",
    486 __FUNCTION__, ksh_pid, argv[1], background, (int)cycle );
     513printf("\n[KSH] %s : ksh_pid %x / path %s / bg %d / place %d (%x) / cycle %d\n",
     514__FUNCTION__, ksh_pid, argv[1], background, placement, cxy, (int)cycle );
    487515#endif
     516
     517    // set target cluster if required
     518    if( placement ) place_fork( cxy );
    488519
    489520    // KSH process fork CHILD process
     
    500531#if CMD_LOAD_DEBUG
    501532get_cycle( &cycle );
    502 printf("\n@@@ %s : CHILD_PID %x after fork, before exec / cycle %d\n",
     533printf("\n[KSH] %s : child_pid %x after fork, before exec / cycle %d\n",
    503534__FUNCTION__ , getpid(), (int)cycle );
    504535#endif
     
    509540#if CMD_LOAD_DEBUG
    510541get_cycle( &cycle );
    511 printf("\n@@@ %s : CHILD_PID %x after exec / ret_exec %d / cycle %d\n",
     542printf("\n[KSH] %s : child_pid %x after exec / ret_exec %d / cycle %d\n",
    512543__FUNCTION__ , getpid(), ret_exec, (int)cycle );
    513544#endif
     
    525556#if CMD_LOAD_DEBUG
    526557get_cycle( &cycle );
    527 printf("\n@@@ %s : KSH_PID %x after fork / ret_fork %x / cycle %d\n",
     558printf("\n[KSH] %s : ksh_pid %x after fork / ret_fork %x / cycle %d\n",
    528559__FUNCTION__, getpid(), ret_fork, (int)cycle );
    529560#endif
     
    636667
    637668}  // end cmd_mv
     669
     670
     671////////////////////////////////////////////
     672static void cmd_ps( int argc , char **argv )
     673{
     674    unsigned int x_size;
     675    unsigned int y_size;
     676    unsigned int ncores;
     677    unsigned int x;
     678    unsigned int y;
     679
     680        if (argc != 1)
     681    {
     682                printf("  usage: %s\n", argv[0]);
     683                return;
     684        }
     685
     686    // get platform config
     687    get_config( &x_size , &y_size , &ncores );
     688
     689    // scan all clusers
     690    for( x = 0 ; x < x_size ; x++ )
     691    {
     692        for( y = 0 ; y < y_size ; y++ )
     693        {
     694            display_cluster_processes( HAL_CXY_FROM_XY(x,y), 1 );  // only owned processes
     695        }
     696    }
     697
     698    // release semaphore to get next command
     699    sem_post( &semaphore );
     700
     701}  // end cmd_ps()
    638702
    639703/////////////////////////////////////////////
     
    758822        { "mv",      "move a file in file system",                      cmd_mv      },
    759823        { "pwd",     "print current working directory",                 cmd_pwd     },
     824        { "ps",      "display all processes",                           cmd_ps      },
    760825        { "rm",      "remove a file from file system",                  cmd_rm      },
    761826        { "rmdir",   "remove a directory from file system",             cmd_rmdir   },
     
    830895        unsigned int   state;                   // escape sequence state
    831896
    832 /* This can be used to simplify debug, as it avoids interactive mode
    833 
    834 for( i=1 ; 1 ; i++ )
    835 {
    836     if( sem_wait( &semaphore ) )
    837     {
    838         printf("\n[ksh error] cannot found semafore\n" );
    839         exit( 1 );
    840     }
    841     else
    842     {
    843         printf("\n[ksh] %d for fft\n", i );
    844     }
    845     strcpy( buf , "load /bin/user/fft.elf" );
    846     parse( buf );
     897
     898/* To lauch one application without interactive mode
     899   
     900if( sem_wait( &semaphore ) )
     901{
     902    printf("\n[ksh error] cannot found semafore\n" );
     903    exit( 1 );
    847904}
     905else
     906{
     907    printf("\n[ksh] for fft\n");
     908}
     909
     910strcpy( buf , "load /bin/user/fft.elf" );
     911parse( buf );
    848912
    849913*/
     
    10811145printf("\n[ksh] main launched interactive thread => wait children termination\n" );
    10821146#endif
     1147
     1148    // signal INIT process
     1149    kill( 1 , SIGCONT );
    10831150   
    10841151    // enter infinite loop monitoring children processes termination
Note: See TracChangeset for help on using the changeset viewer.