Changeset 625 for trunk/user


Ignore:
Timestamp:
Apr 10, 2019, 10:09:39 AM (5 years ago)
Author:
alain
Message:

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

Location:
trunk/user
Files:
4 edited

Legend:

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

    r623 r625  
    7878        {
    7979            // INIT display CHILD[i] process PID
    80             snprintf( string , 64 , "[init] created KSH[%d] / pid = %x", i , ret_fork );
     80            snprintf( string , 64 , "[init] (pid 0x1) created ksh[%d] (pid %x)", i , ret_fork );
    8181            display_string( string );
    8282
  • trunk/user/ksh/ksh.c

    r624 r625  
    5454#define LOG_DEPTH      (32)     // max number of registered commands
    5555#define MAX_ARGS           (32)     // max number of arguments in a command
     56#define PATH_MAX_SIZE  (256)    // max number of characters in a pathname
    5657
    5758#define DEBUG_MAIN          0
    5859#define DEBUG_INTER         0
    59 #define DEBUG_PARSE         0
     60#define DEBUG_EXECUTE       0
    6061#define DEBUG_CMD_CAT       0
    6162#define DEBUG_CMD_CP        0
     
    9091//////////////////////////////////////////////////////////////////////////////////////////
    9192
    92 ksh_cmd_t       command[];                // array of supported commands
    93 
    94 log_entry_t     log_entries[LOG_DEPTH];   // array of registered commands
    95 
    96 unsigned int    ptw;                      // write pointer in log_entries[]
    97 unsigned int    ptr;                      // read pointer in log_entries[]
    98 
    99 pthread_attr_t  attr;                     // interactive thread attributes
    100 
    101 sem_t           semaphore;                // block interactive thread when zero
    102 
    103 pthread_t       trdid;                    // interactive thread identifier
     93ksh_cmd_t       command[];                  // array of supported commands
     94
     95log_entry_t     log_entries[LOG_DEPTH];     // array of registered commands
     96
     97unsigned int    ptw;                        // write pointer in log_entries[]
     98unsigned int    ptr;                        // read pointer in log_entries[]
     99
     100pthread_attr_t  attr;                       // interactive thread attributes
     101
     102sem_t           semaphore;                  // block interactive thread when zero
     103
     104pthread_t       trdid;                      // interactive thread identifier
     105
     106char            pathname[PATH_MAX_SIZE];    // pathname for a file
     107
     108char            pathnew[PATH_MAX_SIZE];     // used by the rename command
    104109 
    105110//////////////////////////////////////////////////////////////////////////////////////////
     
    110115static void cmd_cat( int argc , char **argv )
    111116{
    112         char         * path;
    113117    struct stat    st;
    114118    int            fd;
     
    128132    }
    129133
    130     path = argv[1];
     134    strcpy( pathname , argv[1] );
    131135
    132136    // open the file
    133     fd = open( path , O_RDONLY , 0 );
     137    fd = open( pathname , O_RDONLY , 0 );
    134138    if (fd < 0)
    135139    {
    136             printf("  error: cannot open file <%s>\n", path);
     140            printf("  error: cannot open file <%s>\n", pathname );
    137141
    138142        sem_post( &semaphore );
     
    141145
    142146#if DEBUG_CMD_CAT
    143 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, path );
     147snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, pathname );
    144148display_string( string );
    145149#endif
    146150
    147151    // get file stats
    148     if ( stat( path , &st ) == -1)
    149     {
    150             printf("  error: cannot stat <%s>\n", path);
     152    if ( stat( pathname , &st ) == -1)
     153    {
     154            printf("  error: cannot stat <%s>\n", pathname );
    151155
    152156            close(fd);
     
    157161        if ( S_ISDIR(st.st_mode) )
    158162    {
    159             printf("  error: <%s> is a directory\n", path);
     163            printf("  error: <%s> is a directory\n", pathname );
    160164
    161165            close(fd);
     
    174178    if( size == 0 )
    175179    {
    176             printf("  error: size = 0 for <%s>\n", path);
     180            printf("  error: size = 0 for <%s>\n", pathname );
    177181
    178182            close(fd);
     
    186190    if ( buf == NULL )
    187191    {
    188             printf("  error: cannot map file <%s>\n", path );
     192            printf("  error: cannot map file <%s>\n", pathname );
    189193
    190194            close(fd);
     
    196200snprintf( string , 64 , "[ksh] %s : maped file %d to buffer %x", __FUNCTION__, fd , buf );
    197201display_string( string );
    198 // unsigned int pid = getpid();
    199 // unsigned int cxy = pid >> 16;
    200 // display_vmm( cxy , pid );
    201202#endif
    202203
     
    207208    if( munmap( buf , size ) )
    208209    {
    209             printf("  error: cannot unmap file <%s>\n", path );
     210            printf("  error: cannot unmap file <%s>\n", pathname );
    210211    }
    211212
     
    213214snprintf( string , 64 , "[ksh] %s : unmaped file %d from buffer %x", __FUNCTION__, fd , buf );
    214215display_string( string );
    215 // display_vmm( cxy , pid );
    216216#endif
    217217
     
    219219        if( close( fd ) )
    220220    {
    221             printf("  error: cannot close file <%s>\n", path );
     221            printf("  error: cannot close file <%s>\n", pathname );
    222222    }
    223223
     
    230230static void cmd_cd( int argc , char **argv )
    231231{
    232         char * path;
    233 
    234232        if (argc != 2)
    235233    {
     
    238236    else
    239237    {
    240             path = argv[1];
     238            strcpy( pathname , argv[1] );
    241239
    242240        // call the relevant syscall
    243         if( chdir( path ) )
    244         {
    245             printf("  error: cannot found <%s> directory\n", path );
     241        if( chdir( pathname ) )
     242        {
     243            printf("  error: cannot found <%s> directory\n", pathname );
    246244        }
    247245    }
     
    257255        int          src_fd;
    258256    int          dst_fd;
    259         char       * srcpath;
    260     char       * dstpath;
    261257        int          size;          // source file size
    262258        int          bytes;         // number of transfered bytes
     
    276272        }
    277273
    278     srcpath = argv[1];
    279     dstpath = argv[2];
    280 
    281274    // open the src file
    282     src_fd = open( srcpath , O_RDONLY , 0 );
     275    strcpy( pathname , argv[1] );
     276    src_fd = open( pathname , O_RDONLY , 0 );
    283277
    284278    if ( src_fd < 0 )
    285279    {
    286280        dst_fd = -1;
    287             printf("  error: cannot open <%s>\n", srcpath );
     281            printf("  error: cannot open <%s>\n", argv[1] );
    288282            goto cmd_cp_exit;
    289283    }
    290284
    291285#if DEBUG_CMD_CP
    292 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, srcpath );
     286snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, argv[1] );
    293287display_string( string );
    294288#endif
    295289
    296290    // get file stats
    297     if ( stat( srcpath , &st ) )
     291    if ( stat( pathname , &st ) )
    298292    {
    299293        dst_fd = -1;
    300             printf("  error: cannot stat <%s>\n", srcpath);
     294            printf("  error: cannot stat <%s>\n", argv[1] );
    301295            goto cmd_cp_exit;
    302296    }
    303297
    304298#if DEBUG_CMD_CP
    305 snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, srcpath );
     299snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[1] );
    306300display_string( string );
    307301#endif
     
    310304    {
    311305        dst_fd = -1;
    312                 printf("  error: <%s> is a directory\n", srcpath);
     306                printf("  error: <%s> is a directory\n", argv[1] );
    313307                goto cmd_cp_exit;
    314308        }
     
    318312
    319313        // open the dst file
    320         dst_fd = open( dstpath , O_CREAT|O_TRUNC|O_RDWR , 0 );
     314    strcpy( pathname , argv[2] );
     315        dst_fd = open( pathname , O_CREAT|O_TRUNC|O_RDWR , 0 );
    321316
    322317        if ( dst_fd < 0 )
    323318    {
    324                 printf("  error: cannot open <%s>\n", dstpath );
     319                printf("  error: cannot open <%s>\n", argv[2] );
    325320                goto cmd_cp_exit;
    326321        }
    327322
    328323#if DEBUG_CMD_CP
    329 snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, dstpath );
    330 display_string( string );
    331 #endif
    332 
    333         if ( stat( dstpath , &st ) )
    334     {
    335                 printf("  error: cannot stat <%s>\n", dstpath );
     324snprintf( string , 64 , "[ksh] %s : file %s open", __FUNCTION__, argv[2] );
     325display_string( string );
     326#endif
     327
     328        if ( stat( pathname , &st ) )
     329    {
     330                printf("  error: cannot stat <%s>\n", argv[2] );
    336331                goto cmd_cp_exit;
    337332        }
    338333
    339334#if DEBUG_CMD_CP
    340 snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, dstpath );
     335snprintf( string , 64 , "[ksh] %s : got stats for %s", __FUNCTION__, argv[2] );
    341336display_string( string );
    342337#endif
     
    344339        if ( S_ISDIR(st.st_mode ) )
    345340    {
    346                 printf("  error: <%s> is a directory\n", dstpath );
     341                printf("  error: <%s> is a directory\n", argv[2] );
    347342                goto cmd_cp_exit;
    348343        }
     
    357352                if ( read( src_fd , buf , len ) != len )
    358353        {
    359                         printf("  error: cannot read from file <%s>\n", srcpath);
     354                        printf("  error: cannot read from file <%s>\n", argv[1] );
    360355                        goto cmd_cp_exit;
    361356                }
    362357
    363358#if DEBUG_CMD_CP
    364 snprintf( string , 64 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, srcpath );
     359snprintf( string , 64 , "[ksh] %s : read %d bytes from %s", __FUNCTION__, len, argv[1] );
    365360display_string( string );
    366361#endif
     
    369364                if ( write( dst_fd , buf , len ) != len )
    370365        {
    371                         printf("  error: cannot write to file <%s>\n", dstpath);
     366                        printf("  error: cannot write to file <%s>\n", argv[2] );
    372367                        goto cmd_cp_exit;
    373368                }
    374369
    375370#if DEBUG_CMD_CP
    376 snprintf( string , 64 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, dstpath );
     371snprintf( string , 64 , "[ksh] %s : write %d bytes to %s", __FUNCTION__, len, argv[2] );
    377372display_string( string );
    378373#endif
     
    662657        int                  ret_exec;           // return value from exec
    663658    unsigned int         ksh_pid;            // KSH process PID
    664         char               * pathname;           // path to .elf file
    665659    unsigned int         background;         // background execution if non zero
    666660    unsigned int         placement;          // placement specified if non zero
     
    677671    else
    678672    {
    679             pathname = argv[1];
     673            strcpy( pathname , argv[1] );
    680674
    681675        if( argc == 2 )
     
    707701        }
    708702
    709 /*
    710         // take semaphore to block the interactive thread
    711         if ( sem_wait( &semaphore ) )
    712         {
    713             printf("\n[ksh error] cannot found semafore\n" );
    714             exit( 1 );
    715         }
    716 */
    717703        // get KSH process PID
    718704        ksh_pid = getpid();
     
    767753display_string( string );
    768754#endif
     755            // when the new process is launched in background, the KSH process
     756            // takes the TXT ownership, and release the semaphore to get the next command.
     757            // Otherwise, the child process keep the TXT ownership, and the semaphore will
     758            // be released by the KSH main thread when the child process exit
    769759
    770760            if( background )    //  KSH must keep TXT ownership
     
    776766                sem_post( &semaphore );
    777767            }
    778             else                // KSH loosed TXT ownership
    779             {
    780                 // semaphore will be released by the KSH main thread
    781                 // when the loaded process exit
    782             }
    783768        }
    784769    }
     
    812797static void cmd_ls( int argc , char **argv )
    813798{
    814         char           * pathname = NULL;
    815799    struct dirent  * entry;
    816800    DIR            * dir;
     
    830814        // get target directory path
    831815        if ( argc == 1 ) strcpy( pathname , "." );
    832         else             pathname = argv[1];
     816        else             strcpy( pathname , argv[1] );
    833817
    834818        // open target directory
     
    874858static void cmd_mkdir( int argc , char **argv )
    875859{
    876         char * pathname;
    877 
    878860        if (argc != 2)
    879861    {
     
    882864    else
    883865    {
    884         pathname = argv[1];
     866        strcpy( pathname , argv[1] );
    885867
    886868        mkdir( pathname , 0x777 );
     
    895877static void cmd_mv( int argc , char **argv )
    896878{
    897         char * old_path;
    898     char * new_path;
    899 
    900879        if (argc != 3)
    901880    {
     
    904883    else
    905884    {
    906         old_path = argv[1];
    907         new_path = argv[2];
     885        strcpy( pathname , argv[1] );
     886        strcpy( pathnew  , argv[2] );
    908887
    909888        // call the relevant syscall
    910         if( rename( old_path , new_path ) )
    911         {
    912             printf("  error: unable to rename <%s> to <%s>\n", old_path, new_path );
     889        if( rename( pathname , pathnew ) )
     890        {
     891            printf("  error: unable to rename <%s> to <%s>\n", pathname , pathnew );
    913892        }
    914893    }
     
    967946static void cmd_pwd( int argc , char **argv )
    968947{
    969         char buf[1024];
    970 
    971948        if (argc != 1)
    972949    {
     
    975952    else
    976953    {
    977         if ( getcwd( buf , 1024 ) )
     954        if ( getcwd( pathname , PATH_MAX_SIZE ) )
    978955        {
    979956                    printf("  error: unable to get current directory\n");
     
    981958        else
    982959        {
    983                     printf("%s\n", buf);
     960                    printf("%s\n", pathname );
    984961            }
    985962    }
     
    993970static void cmd_rm( int argc , char **argv )
    994971{
    995         char * pathname;
    996 
    997972        if (argc != 2)
    998973    {
     
    1001976    else
    1002977    {
    1003             pathname = argv[1];
     978            strcpy( pathname , argv[1] );
    1004979
    1005980        if ( unlink( pathname ) )
     
    1018993{
    1019994    // same as cmd_rm()
    1020         cmd_rm(argc, argv);
     995        cmd_rm (argc , argv );
    1021996}
    1022997
     
    11031078// This function analyses one command (with arguments), executes it, and returns.
    11041079////////////////////////////////////////////////////////////////////////////////////
    1105 static void __attribute__ ((noinline)) parse( char * buf )
     1080static void __attribute__ ((noinline)) execute( char * buf )
    11061081{
    11071082        int    argc = 0;
     
    11101085        int    len = strlen(buf);
    11111086
    1112 #if DEBUG_PARSE
    1113 char string[64];
    1114 snprintf( string , 64 , "\n[ksh] %s : <%s>", __FUNCTION__ , buf );
    1115 display_string( string );
     1087#if DEBUG_EXECUTE
     1088printf("\n[ksh] %s : command <%s>\n",
     1089__FUNCTION__ , buf );
    11161090#endif
    11171091
     
    11341108        }
    11351109
    1136 #if DEBUG_PARSE
    1137 snprintf( string , 64 , "\n[ksh] %s : argc = %d for <%s>", __FUNCTION__ , argc , argv[0] );
    1138 display_string( string );
    1139 #endif
    1140 
    1141     // analyse command type
    1142         if (argc > 0)
    1143     {
    1144                 int found = 0;
    1145 
    1146                 // try to match typed command
    1147                 for ( i = 0 ; command[i].name ; i++ )
    1148         {
    1149                         if (strcmp(argv[0], command[i].name) == 0)
    1150             {
    1151                                 command[i].fn(argc, argv);
    1152                                 found = 1;
    1153                                 break;
    1154                         }
     1110    // check command
     1111        if (argc == 0)
     1112    {
     1113        // release semaphore to get next command
     1114        sem_post( &semaphore );
     1115    }
     1116
     1117#if DEBUG_EXECUTE
     1118printf("\n[ksh] %s : argc %d / arg0 %s / arg1 %s\n",
     1119__FUNCTION__ , argc , argv[0], argv[1] );
     1120#endif
     1121
     1122    // scan the list of commands to match typed command
     1123    int found = 0;
     1124    for ( i = 0 ; (command[i].name != NULL) && (found == 0) ; i++ )
     1125    {
     1126        if (strcmp(argv[0], command[i].name) == 0)
     1127        {
     1128                        command[i].fn(argc, argv);
     1129                        found = 1;
    11551130                }
    1156 
    1157                 if (!found)  // undefined command
    1158         {
    1159                         printf("  error : undefined command <%s>\n", argv[0]);
    1160 
    1161             // release semaphore to get next command
    1162             sem_post( &semaphore );
    1163                 }
    1164         }
    1165 }  // end parse()
     1131    }
     1132
     1133    // check undefined command
     1134        if (!found)
     1135    {   
     1136        printf("  error : undefined command <%s>\n", argv[0]);
     1137
     1138        // release semaphore to get next command
     1139        sem_post( &semaphore );
     1140        }
     1141}  // end execute()
    11661142
    11671143///////////////////////////////
     
    11771153
    11781154#if DEBUG_INTER
    1179 char string[64];
    1180 #endif
    1181 
    1182 /* To lauch one command without interactive mode
     1155char string[128];
     1156#endif
     1157
     1158/*
     1159// To lauch one or several commands without interactive mode
     1160
     1161// 1. first command
    11831162if( sem_wait( &semaphore ) )
    11841163{
     
    11881167else
    11891168{
    1190     printf("\n[ksh] load bin/user/sort.elf\n");
     1169    printf("\n[ksh] load bin/user/pgcd.elf\n");
    11911170}
    11921171
    1193 strcpy( cmd , "load bin/user/sort.elf" );
    1194 parse( cmd );
     1172strcpy( cmd , "load bin/user/pgcd.elf" );
     1173execute( cmd );
     1174
     1175// 2. second command
     1176if( sem_wait( &semaphore ) )
     1177{
     1178    printf("\n[ksh error] cannot found semafore\n" );
     1179    exit( 1 );
     1180}
     1181else
     1182{
     1183    printf("\n[ksh] ls home\n");
     1184}
     1185
     1186strcpy( cmd , "ls home" );
     1187execute( cmd );
     1188
     1189// end non-interactive mode
    11951190*/
    11961191
     
    12271222        {
    12281223            // initialize command buffer
    1229             memset( cmd, 0x20 , sizeof(cmd) );   // TODO useful ?
     1224            // memset( cmd , 0x20 , sizeof(cmd) );   // TODO useful ?
    12301225            count       = 0;
    12311226            state       = NORMAL;
     
    12341229#if DEBUG_INTER
    12351230unsigned int pid = getpid();
    1236 snprintf( string , 64 , "\n[ksh] %s : request a new command", __FUNCTION__ );
     1231snprintf( string , 128 , "\n[ksh] %s : request a new command", __FUNCTION__ );
    12371232display_string( string );
    12381233#endif
     
    12631258                                            cmd[count] = 0;
    12641259                        count++;
    1265 
    1266                         // register command in log
     1260#if DEBUG_INTER
     1261snprintf( string , 128 , "[ksh] %s : get command <%s> / &log = %x / ptw = %d / &ptw = %x",
     1262__FUNCTION__, cmd , log_entries[ptw].buf , ptw , &ptw );
     1263display_string( string );
     1264display_vmm( 0 , 2 );
     1265#endif
     1266                        // register command in log_entries[] array
    12671267                                            strncpy( log_entries[ptw].buf , cmd , count );
    12681268                                            log_entries[ptw].count = count;
     
    12711271
    12721272#if DEBUG_INTER
    1273 snprintf( string , 64 , "[ksh] %s : parse and execute <%s>", __FUNCTION__, cmd );
     1273snprintf( string , 128 , "[ksh] %s : execute <%s>", __FUNCTION__, cmd );
    12741274display_string( string );
    12751275#endif
     
    12771277                        putchar( c );
    12781278
    1279                                             // call parser to analyse and execute command
    1280                                             parse( cmd );
     1279                                            // execute command
     1280                                            execute( cmd );
    12811281                                    }
    12821282                    else                         // no command registered
     
    13911391
    13921392#if DEBUG_INTER
    1393 snprintf( string , 64 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd );
     1393snprintf( string , 128 , "\n[ksh] %s : complete <%s> command", __FUNCTION__, cmd );
    13941394display_string( string );
    13951395#endif
  • trunk/user/pgcd/pgcd.c

    r580 r625  
    2424    get_core( &cxy , &lid );
    2525
    26     printf( "\n\n[PGCD] starts on core[%x,%d] / cycle %d\n",
     26    printf( "\n\n[pgcd] starts on core[%x,%d] / cycle %d\n",
    2727    cxy , lid , (unsigned int)cycle );
    2828
  • trunk/user/sort/sort.c

    r624 r625  
    2929#include <hal_macros.h>
    3030
    31 #define ARRAY_LENGTH        1024       // number of items
     31#define ARRAY_LENGTH        256        // number of items
    3232#define MAX_THREADS         1024       // 16 * 16 * 4
    3333
     
    412412#endif
    413413
    414 #if CHECK_RESULT   
    415 int    success = 1;
    416 int*   res_array = ( (total_threads ==   2) ||
    417                      (total_threads ==   8) ||
    418                      (total_threads ==  32) ||
    419                      (total_threads == 128) ||
    420                      (total_threads == 512) ) ? array1 : array0;
    421 
    422 for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ )
    423 {
    424     if ( res_array[n] > res_array[n+1] )
    425     {
    426         printf("\n[sort] array[%d] = %d > array[%d] = %d\n",
    427         n , res_array[n] , n+1 , res_array[n+1] );
    428         success = 0;
    429         break;
    430     }
    431 }
    432 
    433 if ( success ) printf("\n[sort] success\n");
    434 else           printf("\n[sort] failure\n");
     414#if CHECK_RESULT
     415   
     416    int    success = 1;
     417    int *  res_array = ( (total_threads ==   2) ||
     418                         (total_threads ==   8) ||
     419                         (total_threads ==  32) ||
     420                         (total_threads == 128) ||
     421                         (total_threads == 512) ) ? array1 : array0;
     422
     423    for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ )
     424    {
     425        if ( res_array[n] > res_array[n+1] )
     426        {
     427            printf("\n[sort] array[%d] = %d > array[%d] = %d\n",
     428            n , res_array[n] , n+1 , res_array[n+1] );
     429            success = 0;
     430            break;
     431        }
     432    }
     433
     434    if ( success ) printf("\n[sort] success\n");
     435    else           printf("\n[sort] failure\n");
     436
    435437#endif
    436438
    437439#if INSTRUMENTATION
    438 char   name[64];
    439 char   path[128];
    440 
    441 // build a file name from n_items / n_clusters / n_cores
    442 if( USE_DQT_BARRIER ) snprintf( name , 64 , "sort_dqt_%d_%d_%d",
    443                       ARRAY_LENGTH, x_size * y_size, ncores );
    444 else                  snprintf( name , 64 , "sort_smp_%d_%d_%d",
    445                       ARRAY_LENGTH, x_size * y_size, ncores );
    446 
    447 // build file pathname
    448 snprintf( path , 128 , "home/%s" , name );
    449 
    450 // compute results
    451 unsigned int sequencial = (unsigned int)(seq_end_cycle - start_cycle);
    452 unsigned int parallel   = (unsigned int)(para_end_cycle - seq_end_cycle);
    453 
    454 // display results on process terminal
    455 printf("\n----- %s -----\n"
    456        " - sequencial : %d cycles\n"
    457        " - parallel   : %d cycles\n",
    458        name, sequencial, parallel );
    459 
    460 // open file
    461 FILE * stream = fopen( path , NULL );
    462 if( stream == NULL )
    463 {
    464     printf("\n[sort error] cannot open instrumentation file <%s>\n", name );
    465     exit(0);
    466 }
    467 
    468 // register results to file
    469 int ret = fprintf( stream , "\n----- %s -----\n"
    470                             " - sequencial : %d cycles\n"
    471                             " - parallel   : %d cycles\n", name, sequencial, parallel );
    472 if( ret < 0 )
    473 {
    474     printf("\n[sort error] cannot write to instrumentation file <%s>\n", name );
    475     exit(0);
    476 }
    477 
    478 // close instrumentation file
    479 if( fclose( stream ) )
    480 {
    481     printf("\n[sort error] cannot close instrumentation file <%s>\n", name );
    482     exit(0);
    483 }
     440
     441    char   name[64];
     442    char   path[128];
     443
     444    // build a file name from n_items / n_clusters / n_cores
     445    if( USE_DQT_BARRIER ) snprintf( name , 64 , "sort_dqt_%d_%d_%d",
     446                          ARRAY_LENGTH, x_size * y_size, ncores );
     447    else                  snprintf( name , 64 , "sort_smp_%d_%d_%d",
     448                          ARRAY_LENGTH, x_size * y_size, ncores );
     449
     450    // build file pathname
     451    snprintf( path , 128 , "home/%s" , name );
     452
     453    // compute results
     454    unsigned int sequencial = (unsigned int)(seq_end_cycle - start_cycle);
     455    unsigned int parallel   = (unsigned int)(para_end_cycle - seq_end_cycle);
     456
     457    // display results on process terminal
     458    printf("\n----- %s -----\n"
     459           " - sequencial : %d cycles\n"
     460           " - parallel   : %d cycles\n",
     461           name, sequencial, parallel );
     462
     463    // open file
     464    FILE * stream = fopen( path , NULL );
     465    if( stream == NULL )
     466    {
     467        printf("\n[sort error] cannot open instrumentation file <%s>\n", name );
     468        exit(0);
     469    }
     470
     471    printf("\n[sort] file %s successfully open\n", path);
     472
     473    // register results to file
     474    int ret = fprintf( stream , "\n----- %s -----\n"
     475                                " - sequencial : %d cycles\n"
     476                                " - parallel   : %d cycles\n", name, sequencial, parallel );
     477    if( ret < 0 )
     478    {
     479        printf("\n[sort error] cannot write to instrumentation file <%s>\n", name );
     480        exit(0);
     481    }
     482
     483    printf("\n[sort] file %s successfully written\n", path);
     484
     485    // close instrumentation file
     486
     487    if( fclose( stream ) )
     488    {
     489        printf("\n[sort error] cannot close the file <%s>\n", name );
     490        exit(0);
     491    }
     492
     493    printf("\n[sort] file %s successfully closed\n", path);
     494
    484495#endif
    485496
Note: See TracChangeset for help on using the changeset viewer.