Changeset 596 for trunk


Ignore:
Timestamp:
Nov 10, 2018, 2:53:23 PM (5 years ago)
Author:
alain
Message:

Fix a big bug in ksh: wrong handling of illegal command, blocking ksh.

Location:
trunk/user
Files:
4 edited

Legend:

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

    r588 r596  
    8686// parameters
    8787
    88 #define DEFAULT_M               14              // 16 K data points
     88#define DEFAULT_M               12              // 4096 data points
    8989#define MODE                    COSIN
    9090#define CHECK                   0
    91 #define DEBUG_MAIN              0               // trace main() function (detailed if odd)
    92 #define DEBUG_SLAVE             0               // trace slave() function (detailed if odd)
    93 #define DEBUG_FFT1D             0               // trace FFT1D() function (detailed if odd)
     91#define DEBUG_MAIN              2               // trace main() function (detailed if odd)
     92#define DEBUG_SLAVE             2               // trace slave() function (detailed if odd)
     93#define DEBUG_FFT1D             2               // trace FFT1D() function (detailed if odd)
    9494#define DEBUG_ROW               0               // trace FFTRow() function (detailed if odd)
    9595#define PRINT_ARRAY             0
  • trunk/user/ksh/Makefile

    r588 r596  
    44
    55-include ../../params-soft.mk
    6 
    7 ifeq ($(ARCH_NAME),)
    8 $(error Please define in ARCH_NAME parameter in params-soft.mk!)
    9 endif
    106
    117OBJS = build/ksh.o
  • trunk/user/ksh/ksh.c

    r588 r596  
    2121//   the TXT terminal ownership.
    2222//
    23 // A semaphore is used to synchronize the two KSH threads. At each iteration,
     23// We use a semaphore to synchronize the two KSH threads. At each iteration,
    2424// the interactive thread check the semaphore (with a sem_wait). It blocks
    2525// and deschedules, if the KSH process loosed the TXT ownership (after a load,
     
    4646#include <semaphore.h>
    4747#include <hal_macros.h>
     48#include <sys/stat.h>
     49#include <sys/mman.h>
     50#include <fcntl.h>
    4851
    4952#define CMD_MAX_SIZE   (256)    // max number of characters in one command
     
    5356#define MAIN_DEBUG          0
    5457#define CMD_LOAD_DEBUG      0
     58#define CMD_CAT_DEBUG       1
    5559
    5660//////////////////////////////////////////////////////////////////////////////////////////
     
    99103{
    100104        char         * path;
     105    stat_t         st;      // stat structure
     106    int            fd;
     107    int            size;
     108    char         * buf;
    101109
    102110        if (argc != 2)
    103111    {
     112        fd   = -1;
     113        buf  = NULL;
     114        size = 0;
    104115                printf("  usage: cat pathname\n");
    105                 return;
    106         }
    107 
    108         path = argv[1];
    109 
    110     printf("  error: not implemented yet\n", argc, argv );
    111 
    112 /*
    113         // open the file
    114         fd = open( path , O_RDONLY , 0 );
    115         if (fd < 0)
    116     {
    117                 printf("  error: cannot open %s\n", path);
    118                 goto exit;
    119         }
    120 
    121         // get file size
    122         if (stat(path, &st) == -1)
    123     {
    124                 printf("  error: cannot stat %s\n", path);
    125                 goto exit;
    126         }
    127         if (S_ISDIR(st.st_mode)) {
    128                 printf("  error: %s is a directory\n", path);
    129                 goto exit;
    130         }
    131         size = st.st_size;
    132 
    133         // mmap the file
    134         buf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
    135         if (buf == NULL || buf == (char *)-1) {
    136                 printf("  error: cannot map %s\n", path);
    137                 goto exit;
    138         }
    139 
    140         // set terminating '0'
    141         buf[size-1] = 0;
    142 
    143         // display the file content
    144         printf("%s", buf);
     116        goto exit;
     117    }
     118
     119    path = argv[1];
     120
     121    // open the file
     122    fd = open( path , O_RDONLY , 0 );
     123    if (fd < 0)
     124    {
     125        buf  = NULL;
     126        size = 0;
     127            printf("  error: cannot open %s\n", path);
     128            goto exit;
     129    }
     130
     131#if CMD_CAT_DEBUG
     132long long unsigned cycle;
     133get_cycle( &cycle );
     134printf("\n[%s] file %s open / cycle %d\n",
     135__FUNCTION__ , path , (int)cycle );
     136#endif
     137
     138    // get file stats
     139    if ( stat( path , &st ) == -1)
     140    {
     141        buf  = NULL;
     142        size = 0;
     143            printf("  error: cannot stat %s\n", path);
     144            goto exit;
     145    }
     146
     147        if ( S_ISDIR(st.st_mode) )
     148    {
     149        buf  = NULL;
     150        size = 0;
     151            printf("  error: %s is a directory\n", path);
     152            goto exit;
     153    }
     154
     155    // get file size
     156    size = st.st_size;
     157
     158#if CMD_CAT_DEBUG
     159get_cycle( &cycle );
     160printf("\n[%s] get size %d / cycle %d\n",
     161__FUNCTION__ , size , (int)cycle );
     162#endif
     163
     164    // MAP_FILE is default type when MAP_ANON and MAP_REMOTE are not specified
     165    buf = mmap( NULL , size , PROT_READ|PROT_WRITE , MAP_PRIVATE , fd , 0 );
     166
     167    if ( buf == NULL )
     168    {
     169            printf("  error: cannot map %s\n", path );
     170            goto exit;
     171    }
     172
     173#if CMD_CAT_DEBUG
     174get_cycle( &cycle );
     175printf("\n[%s] map file %d to buffer %x / cycle %d\n",
     176__FUNCTION__ , fd , buf , (int)cycle );
     177display_vmm( 0 , getpid() );
     178#endif
     179
     180    // display the file content on TXT terminal
     181    write( 1 , buf , size );
     182
     183    // release semaphore to get next command
     184    sem_post( &semaphore );
     185
     186    return;
    145187
    146188exit:
     189
    147190        if (buf != NULL) munmap(buf, size);
    148191        if (fd >= 0) close(fd);
    149 */
    150192
    151193    // release semaphore to get next command
     
    162204    {
    163205                printf("  usage: cd pathname\n");
    164                 return;
    165         }
    166 
    167         path = argv[1];
    168 
    169     printf("  error: not implemented yet\n", argc, argv );
     206        }
     207    else
     208    {
     209            path = argv[1];
     210
     211        printf("  error: not implemented yet\n" );
     212    }
    170213
    171214    // release semaphore to get next command
     
    177220static void cmd_cp(int argc, char **argv)
    178221{
    179 //      int src_fd = -1, dst_fd = -1;
    180 //      char *srcpath, *dstpath;
    181 //      struct stat st;
    182 //      size_t size, i;
    183 //      char buf[1024];
     222        int    src_fd;
     223    int    dst_fd;
     224        char * srcpath;
     225    char * dstpath;
     226        int    size;          // source file size
     227        int    bytes;         // number of transfered bytes
     228        char   buf[1024];
     229        stat_t st;
    184230
    185231        if (argc != 3)
    186232    {
     233        src_fd = -1;
     234        dst_fd = -1;
    187235                printf("  usage: cp src_pathname dst_pathname\n");
    188                 return;
    189         }
    190 
    191     printf("  error: not implemented yet\n", argc, argv );
    192 
    193 /*
    194         srcpath = argv[1];
    195         dstpath = argv[2];
    196 
    197         // open the src file
    198         src_fd = open(srcpath, O_RDONLY, 0);
    199         if (src_fd < 0) {
    200                 printf("  error: cannot open %s / err = %d\n", srcpath, errno);
    201                 goto exit;
    202         }
    203 
    204         // get file size
    205         if (stat(srcpath, &st) == -1) {
    206                 printf("  error: cannot stat %s\n", srcpath);
    207                 goto exit;
    208         }
    209         if (S_ISDIR(st.st_mode)) {
     236        goto exit;
     237        }
     238
     239    srcpath = argv[1];
     240    dstpath = argv[2];
     241
     242    // open the src file
     243    src_fd = open( srcpath , O_RDONLY , 0 );
     244
     245    if ( src_fd < 0 )
     246    {
     247        dst_fd = -1;
     248            printf("  error: cannot open %s\n", srcpath );
     249            goto exit;
     250    }
     251
     252    // get file stats
     253    if ( stat( srcpath , &st ) )
     254    {
     255        dst_fd = -1;
     256            printf("  error: cannot stat %s\n", srcpath);
     257            goto exit;
     258    }
     259
     260        if ( S_ISDIR(st.st_mode) )
     261    {
     262        dst_fd = -1;
    210263                printf("  error: %s is a directory\n", srcpath);
    211264                goto exit;
    212265        }
     266
     267    // get src file size
    213268        size = st.st_size;
    214269
    215270        // open the dst file
    216         dst_fd = open(dstpath, O_CREAT|O_TRUNC|O_RDWR, 0);
    217         if (dst_fd < 0) {
    218                 printf("  error: cannot open %s / err = %d\n", dstpath, errno);
     271        dst_fd = open( dstpath , O_CREAT|O_TRUNC|O_RDWR , 0 );
     272
     273        if ( dst_fd < 0 )
     274    {
     275                printf("  error: cannot open %s\n", dstpath );
    219276                goto exit;
    220277        }
    221         if (stat(dstpath, &st) == -1) {
    222                 printf("  error: cannot stat %s\n", dstpath);
     278
     279        if ( stat( dstpath , &st ) )
     280    {
     281                printf("  error: cannot stat %s\n", dstpath );
    223282                goto exit;
    224283        }
    225         if (S_ISDIR(st.st_mode)) {
    226                 printf("  error: %s is a directory\n", dstpath);
     284
     285        if ( S_ISDIR(st.st_mode ) )
     286    {
     287                printf("  error: %s is a directory\n", dstpath );
    227288                goto exit;
    228289        }
    229290
    230         i = 0;
    231         while (i < size)
     291        bytes = 0;
     292
     293        while (bytes < size)
    232294        {
    233                 size_t rlen = (size - i < 1024 ? size - i : 1024);
    234                 size_t wlen;
    235                 ssize_t ret;
     295                int rlen = ((size - bytes) < 1024) ? (size - bytes) : 1024;
     296                int wlen;
     297                int ret;
    236298
    237299                // read the source
    238                 ret = read(src_fd, buf, rlen);
    239                 if (ret == -1) {
     300                ret = read( src_fd , buf , rlen );
     301                if (ret == -1)
     302        {
    240303                        printf("  error: cannot read from file %s\n", srcpath);
    241304                        goto exit;
    242305                }
    243                 rlen = (size_t)ret;
     306
     307                rlen = (int)ret;
    244308
    245309                // write to the destination
    246                 ret = write(dst_fd, buf, rlen);
    247                 if (ret == -1) {
     310                ret = write( dst_fd , buf , rlen );
     311                if (ret == -1)
     312        {
    248313                        printf("  error: cannot write to file %s\n", dstpath);
    249314                        goto exit;
    250315                }
    251                 wlen = (size_t)ret;
     316
     317                wlen = (int)ret;
    252318
    253319                // check
    254                 if (wlen != rlen) {
     320                if (wlen != rlen)
     321        {
    255322                        printf("  error: cannot write on device\n");
    256323                        goto exit;
    257324                }
    258325
    259                 i += rlen;
     326                bytes += rlen;
    260327        }
    261328
    262329exit:
     330
    263331        if (src_fd >= 0) close(src_fd);
    264332        if (dst_fd >= 0) close(dst_fd);
    265 */
    266333
    267334    // release semaphore to get next command
     
    273340static void cmd_display( int argc , char **argv )
    274341{
    275     unsigned int  cxy;
    276     unsigned int  lid;
    277     unsigned int  pid;
    278     unsigned int  txt_id;
    279 
    280     if( strcmp( argv[1] , "vmm" ) == 0 )
     342    if( argc < 2 )
     343    {
     344        printf("  usage: display  vmm      cxy  pid   \n"
     345               "         display  sched    cxy  lid   \n"             
     346               "         display  process  cxy        \n"             
     347               "         display  txt      txtid      \n"             
     348               "         display  vfs                 \n"             
     349               "         display  chdev               \n"             
     350               "         display  dqdt                \n"             
     351               "         display  locks    pid  trdid \n");
     352    }
     353    ////////////////////////////////////
     354    else if( strcmp( argv[1] , "vmm" ) == 0 )
    281355    {
    282356        if( argc != 4 )
    283357        {
    284358                    printf("  usage: display vmm cxy pid\n");
    285                     return;
    286             }
    287 
    288             cxy = atoi(argv[2]);
    289             pid = atoi(argv[3]);
    290 
    291         if( display_vmm( cxy , pid ) )
    292         {
    293             printf("  error: no process %x in cluster %x\n", pid , cxy );
    294         }
    295     }
     359            }
     360        else
     361        {
     362                unsigned int cxy = atoi(argv[2]);
     363                unsigned int pid = atoi(argv[3]);
     364
     365            if( display_vmm( cxy , pid ) )
     366            {
     367                printf("  error: no process %x in cluster %x\n", pid , cxy );
     368            }
     369        }
     370    }
     371    ///////////////////////////////////////////
    296372    else if( strcmp( argv[1] , "sched" ) == 0 )
    297373    {
     
    299375        {
    300376                    printf("  usage: display sched cxy lid\n");
    301                     return;
    302             }
    303 
    304             cxy = atoi(argv[2]);
    305             lid = atoi(argv[3]);
    306 
    307         if( display_sched( cxy , lid ) )
    308         {
    309             printf("  error: illegal arguments cxy = %x / lid = %d\n", cxy, lid );
    310         }
    311     }
     377            }
     378        else
     379        {
     380                unsigned int cxy = atoi(argv[2]);
     381                unsigned int lid = atoi(argv[3]);
     382
     383            if( display_sched( cxy , lid ) )
     384            {
     385                printf("  error: illegal arguments cxy = %x / lid = %d\n", cxy, lid );
     386            }
     387        }
     388    }
     389    /////////////////////////////////////////////
    312390    else if( strcmp( argv[1] , "process" ) == 0 )
    313391    {
     
    315393        {
    316394                    printf("  usage: display process cxy\n");
    317                     return;
    318             }
    319 
    320             cxy = atoi(argv[2]);
    321 
    322         if( display_cluster_processes( cxy , 0 ) )
    323         {
    324             printf("  error: illegal argument cxy = %x\n", cxy );
    325         }
    326     }
     395            }
     396        else
     397        {
     398                unsigned int cxy = atoi(argv[2]);
     399
     400            if( display_cluster_processes( cxy , 0 ) )
     401            {
     402                printf("  error: illegal argument cxy = %x\n", cxy );
     403            }
     404        }
     405    }
     406    /////////////////////////////////////////
    327407    else if( strcmp( argv[1] , "txt" ) == 0 )
    328408    {
     
    330410        {
    331411                    printf("  usage: display txt txt_id\n");
    332                     return;
    333             }
    334 
    335             txt_id = atoi(argv[2]);
    336 
    337         if( display_txt_processes( txt_id ) )
    338         {
    339             printf("  error: illegal argument txt_id = %d\n", txt_id );
    340         }
    341     }
     412            }
     413        else
     414        {
     415                unsigned int txtid = atoi(argv[2]);
     416
     417            if( display_txt_processes( txtid ) )
     418            {
     419                printf("  error: illegal argument txtid = %d\n", txtid );
     420            }
     421        }
     422    }
     423    /////////////////////////////////////////
    342424    else if( strcmp( argv[1] , "vfs" ) == 0 )
    343425    {
     
    345427        {
    346428                    printf("  usage: display vfs\n");
    347                     return;
    348             }
    349 
    350         display_vfs();
    351     }
     429            }
     430        else
     431        {
     432            display_vfs();
     433        }
     434    }
     435    //////////////////////////////////////////
    352436    else if( strcmp( argv[1] , "chdev" ) == 0 )
    353437    {
     
    355439        {
    356440                    printf("  usage: display chdev\n");
    357                     return;
    358             }
    359 
    360         display_chdev();
    361     }
     441            }
     442        else
     443        {
     444            display_chdev();
     445        }
     446    }
     447    //////////////////////////////////////////
    362448    else if( strcmp( argv[1] , "dqdt" ) == 0 )
    363449    {
     
    365451        {
    366452                    printf("  usage: display dqdt\n");
    367                     return;
    368             }
    369 
    370         display_dqdt();
    371     }
    372     else
    373     {
    374         printf("  usage: display (vmm/sched/process/vfs/chdev/txt) [arg2] [arg3]\n");
    375     }
     453            }
     454        else
     455        {
     456            display_dqdt();
     457        }
     458    }
     459    ///////////////////////////////////////////
     460    else if( strcmp( argv[1] , "locks" ) == 0 )
     461    {
     462        if( argc != 4 )
     463        {
     464                    printf("  usage: display locks pid trdid\n");
     465            }
     466        else
     467        {
     468                unsigned int pid   = atoi(argv[2]);
     469            unsigned int trdid = atoi(argv[3]);
     470
     471            if( display_busylocks( pid , trdid ) )
     472            {
     473                printf("  error: illegal arguments pid = %x / trdid = %x\n", pid, trdid );
     474            }
     475        }
     476    }
     477    else
     478    {
     479        printf("  error: undefined display request : %s\n", argv[1] );
     480    }       
    376481
    377482    // release semaphore to get next command
     
    388493    {
    389494                printf("  usage: %s pid\n", argv[0]);
    390                 return;
    391         }
    392 
    393     pid = atoi( argv[1] );   
    394 
    395     if( pid == 0 )
    396     {
    397                 printf("  error: PID cannot be 0\n" );
    398         }
    399 
    400     if( fg( pid ) )
    401     {
    402                 printf("  error: cannot find process %x\n", pid );
    403         }
     495        }
     496    else
     497    {
     498        pid = atoi( argv[1] );   
     499
     500        if( pid == 0 )
     501        { 
     502                    printf("  error: PID cannot be 0\n" );
     503            }
     504        else if( fg( pid ) )
     505        {
     506                    printf("  error: cannot find process %x\n", pid );
     507            }
     508    }
    404509
    405510    // release semaphore to get next command
     
    416521    {
    417522                printf("  usage: %s\n", argv[0]);
    418                 return;
    419         }
    420 
    421         printf("available commands:\n");
    422         for (i = 0 ; cmd[i].name ; i++)
    423     {
    424                 printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc);
    425         }
     523        }
     524    else
     525    {
     526            printf("available commands:\n");
     527            for (i = 0 ; cmd[i].name ; i++)
     528        {
     529                    printf("\t%s\t : %s\n", cmd[i].name , cmd[i].desc);
     530            }
     531    }
    426532
    427533    // release semaphore to get next command
     
    438544    {
    439545                printf("  usage: %s pid\n", argv[0]);
    440                 return;
    441         }
    442 
    443         pid = atoi( argv[1] );
    444 
    445     if( pid == 0 )
    446     {
    447                 printf("  error: kernel process 0 cannot be killed\n" );
    448         }
    449 
    450         if( kill( pid , SIGKILL ) )
    451     {
    452                 printf("  error: process %x cannot be killed\n", pid );
    453         }
     546        }
     547    else
     548    {
     549            pid = atoi( argv[1] );
     550
     551        if( pid == 0 )
     552        {
     553                    printf("  error: kernel process 0 cannot be killed\n" );
     554            }
     555
     556            else if( kill( pid , SIGKILL ) )
     557        {
     558                    printf("  error: process %x cannot be killed\n", pid );
     559            }
     560    }
    454561
    455562    // release semaphore to get next command
     
    472579    {
    473580                printf("  usage: %s pathname [cxy] [&]\n", argv[0] );
    474                 return;
    475         }
    476 
    477         pathname = argv[1];
    478 
    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;
     581        }
     582    else
     583    {
     584            pathname = argv[1];
     585
     586        if( argc == 2 )
     587        {
     588            background = 0;
    490589            placement  = 0;
    491590            cxy        = 0;
    492591        }
    493         else
    494         {
    495             background = 0;
     592        else if( argc == 3 )
     593        {
     594            if( (argv[2][0] == '&') && (argv[2][1] == 0) )
     595            {
     596                background = 1;
     597                placement  = 0;
     598                cxy        = 0;
     599            }
     600            else
     601            {
     602                background = 0;
     603                placement  = 1;
     604                cxy        = atoi( argv[2] );
     605            }
     606        }
     607        else  // argc == 4
     608        {
     609            background = ( (argv[3][0] == '&') && (argv[3][1] == 0) );
    496610            placement  = 1;
    497611            cxy        = atoi( argv[2] );
    498612        }
    499     }
    500     else  // argc == 4
    501     {
    502         background = ( (argv[3][0] == '&') && (argv[3][1] == 0) );
    503         placement  = 1;
    504         cxy        = atoi( argv[2] );
    505     }
    506 
    507     // get KSH process PID
    508     ksh_pid = getpid();
     613
     614        // get KSH process PID
     615        ksh_pid = getpid();
    509616
    510617#if CMD_LOAD_DEBUG
     
    515622#endif
    516623
    517     // set target cluster if required
    518     if( placement ) place_fork( cxy );
    519 
    520     // KSH process fork CHILD process
    521         ret_fork = fork();
    522 
    523     if ( ret_fork < 0 )     // it is a failure reported to KSH
    524     {
    525         printf("  error: ksh process unable to fork\n");
    526         return;
    527     }
    528     else if (ret_fork == 0) // it is the CHILD process
    529     {
     624        // set target cluster if required
     625        if( placement ) place_fork( cxy );
     626
     627        // KSH process fork CHILD process
     628            ret_fork = fork();
     629
     630        if ( ret_fork < 0 )     // it is a failure reported to KSH
     631        {
     632            printf("  error: ksh process unable to fork\n");
     633        }
     634        else if (ret_fork == 0) // it is the CHILD process
     635        {
    530636
    531637#if CMD_LOAD_DEBUG
     
    535641#endif
    536642
    537         // CHILD process exec NEW process
    538         ret_exec = execve( pathname , NULL , NULL );
     643            // CHILD process exec NEW process
     644            ret_exec = execve( pathname , NULL , NULL );
    539645
    540646#if CMD_LOAD_DEBUG
     
    544650#endif
    545651
    546         // this is only executed in case of exec failure
    547         if( ret_exec )
    548         {
    549             printf("  error: child process unable to exec <%s>\n", pathname );
    550             exit( 0 );
    551         }   
    552         }
    553     else                    // it is the KSH process : ret_fork is the new process PID
    554     {
     652            // this is only executed in case of exec failure
     653            if( ret_exec )
     654            {
     655                printf("  error: child process unable to exec <%s>\n", pathname );
     656                exit( 0 );
     657            }   
     658            }
     659        else                    // it is the KSH process : ret_fork is the new process PID
     660        {
    555661
    556662#if CMD_LOAD_DEBUG
     
    560666#endif
    561667
    562         if( background )    // child in background =>  KSH must keep TXT ownership
    563         {
    564             // execve() tranfered TXT ownership to child => give it back to KSH
    565             fg( ksh_pid );
    566 
    567             // release semaphore to get next command
    568             sem_post( &semaphore );
    569         }
    570     }
     668            if( background )    // child in background =>  KSH must keep TXT ownership
     669            {
     670                fg( ksh_pid );
     671            }
     672        }
     673    }
     674
     675    // release semaphore to get next command
     676    sem_post( &semaphore );
     677   
    571678}   // end cmd_load
    572679
     
    579686    {
    580687                printf("  usage: %s\n", argv[0], argc );
    581                 return;
    582         }
    583 
    584         printf("--- registered commands ---\n");
    585         for (i = 0; i < LOG_DEPTH; i++)
    586     {
    587                 printf(" - %d\t: %s\n", i, &log_entries[i].buf);
    588         }
     688        }
     689    else
     690    {
     691            printf("--- registered commands ---\n");
     692            for (i = 0; i < LOG_DEPTH; i++)
     693        {
     694                    printf(" - %d\t: %s\n", i, &log_entries[i].buf);
     695            }
     696    }
    589697
    590698    // release semaphore to get next command
     
    602710//  DIR *dir;
    603711
    604         if (argc == 1)
    605     {
    606                 path = ".";
    607         }
    608     else if (argc == 2)
    609     {
    610                 path = argv[1];
    611         }
    612     else
     712        if (argc > 2 )
    613713    {
    614714                printf("  usage: ls [path]\n");
    615                 return;
    616         }
    617 
    618     printf("  error: not implemented yet\n");
     715        }
     716    else
     717    {
     718        if ( argc == 1 ) path = ".";
     719        else             path = argv[1];
     720
     721        printf("  error: not implemented yet\n");
    619722/*
    620723        dir = opendir( path );
     
    625728        closedir(dir);
    626729*/
     730    }
    627731
    628732    // release semaphore to get next command
     
    639743    {
    640744                printf("  usage: mkdir pathname\n");
    641                 return;
    642         }
    643 
    644     pathname = argv[1];
    645 
    646     printf("  error: not implemented yet\n");
     745        }
     746    else
     747    {
     748        pathname = argv[1];
     749
     750        printf("  error: not implemented yet\n");
     751    }
    647752
    648753    // release semaphore to get next command
     
    657762        if (argc < 3)
    658763        {
    659                 printf("  usage : %s src_pathname dst_pathname\n", argv[0]);
    660                 return;
    661         }
    662 
    663     printf("  error: not implemented yet\n");
     764                printf("  usage : mv src_pathname dst_pathname\n");
     765        }
     766    else
     767    {
     768        printf("  error: not implemented yet\n");
     769    }
    664770   
    665771    // release semaphore to get next command
     
    681787    {
    682788                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
     789        }
     790    else
     791    {
     792        // get platform config
     793        get_config( &x_size , &y_size , &ncores );
     794
     795        // scan all clusters
     796        for( x = 0 ; x < x_size ; x++ )
     797        {
     798            for( y = 0 ; y < y_size ; y++ )
     799            {
     800                // display only owned processes
     801                display_cluster_processes( HAL_CXY_FROM_XY(x,y), 1 );
     802            }
    695803        }
    696804    }
     
    709817    {
    710818                printf("  usage: %s\n", argv[0]);
    711                 return;
    712         }
    713 
    714         if ( getcwd( buf , 1024 ) )
    715     {
    716                 printf("  error: unable to get current directory\n");
    717819        }
    718820    else
    719821    {
    720                 printf("%s\n", buf);
    721         }
     822        if ( getcwd( buf , 1024 ) )
     823        {
     824                    printf("  error: unable to get current directory\n");
     825            }
     826        else
     827        {
     828                    printf("%s\n", buf);
     829            }
     830    }
    722831
    723832    // release semaphore to get next command
     
    734843    {
    735844                printf("  usage: %s pathname\n", argv[0]);
    736                 return;
    737         }
    738 
    739         pathname = argv[1];
    740 
    741     printf("  error: not implemented yet\n");
     845        }
     846    else
     847    {
     848            pathname = argv[1];
     849
     850        printf("  error: not implemented yet\n");
     851    }
    742852
    743853    // release semaphore to get next command
     
    762872    {
    763873                printf("  usage: trace cxy lid \n");
    764                 return;
    765         }
    766 
    767     cxy = atoi(argv[1]);
    768     lid = atoi(argv[2]);
    769 
    770     if( trace( 1 , cxy , lid ) )
    771     {
    772         printf("  error: core[%x,%d] not found\n", cxy, lid );
     874        }
     875    else
     876    {
     877        cxy = atoi(argv[1]);
     878        lid = atoi(argv[2]);
     879
     880        if( trace( 1 , cxy , lid ) )
     881        {
     882            printf("  error: core[%x,%d] not found\n", cxy, lid );
     883        }
    773884    }
    774885
     
    787898    {
    788899                printf("  usage: untrace cxy lid \n");
    789                 return;
    790         }
    791 
    792     cxy = atoi(argv[1]);
    793     lid = atoi(argv[2]);
    794 
    795     if( trace( 0 , cxy , lid ) )
    796     {
    797         printf("  error: core[%x,%d] not found\n", cxy, lid );
     900        }
     901    else
     902    {
     903        cxy = atoi(argv[1]);
     904        lid = atoi(argv[2]);
     905
     906        if( trace( 0 , cxy , lid ) )
     907        {
     908            printf("  error: core[%x,%d] not found\n", cxy, lid );
     909        }
    798910    }
    799911
  • trunk/user/sort/sort.c

    r588 r596  
    2424#include <stdio.h>
    2525#include <stdlib.h>
     26#include <unistd.h>
    2627#include <pthread.h>
    2728#include <almosmkh.h>
     
    157158    /////////////////////////////////
    158159    pthread_barrier_wait( &barrier );
    159     printf("\n[SORT] thread[%d] exit barrier\n", thread_uid );
     160    printf("\n[SORT] thread[%d] exit barrier 0\n", thread_uid );
    160161
    161162    // the number of threads contributing to sort
     
    192193        /////////////////////////////////
    193194        pthread_barrier_wait( &barrier );
    194         printf("\n[SORT] thread[%d] exit barrier\n", thread_uid );
     195        printf("\n[SORT] thread[%d] exit barrier %d\n", thread_uid , i );
    195196
    196197    }
     
    223224    pthread_barrierattr_t  barrier_attr;       // barrier attributes
    224225
    225     // compute number of threads (one thread per proc)
     226    // compute number of threads (one thread per core)
    226227    get_config( &x_size , &y_size , &ncores );
    227228    threads = x_size * y_size * ncores;
     
    268269    for ( n = 0 ; n < ARRAY_LENGTH ; n++ )
    269270    {
    270         array0[n] = rand();
     271        array0[n] = ARRAY_LENGTH - n - 1;
    271272    }
    272273
     
    315316                    }
    316317                }
    317 
    318 #if INTERACTIVE_MODE
    319 idbg();
    320 #endif
    321318            }
    322319        }
Note: See TracChangeset for help on using the changeset viewer.