Ignore:
Timestamp:
Dec 6, 2019, 12:07:51 PM (4 years ago)
Author:
alain
Message:

Fix several bugs in the FATFS and in the VFS,
related to the creation of big files requiring
more than 4 Kbytes (one cluster) on device.

File:
1 edited

Legend:

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

    r652 r656  
    6565
    6666#define VERBOSE_MAIN               1
    67 #define VERBOSE_EXEC               1
     67#define VERBOSE_EXEC               0
     68#define SUPER_VERBOSE              0
    6869
    6970#define X_MAX                      16
     
    159160/////////////////////////////////////////////////////////////////////////////////////
    160161
    161 void execute( pthread_parallel_work_args_t * args );
     162void * execute( void * args );
    162163
    163164void instrument( FILE * f , char * filename );
     
    173174
    174175    char         instru_name[32];               // instrumentation file name
    175     char         instru_path[64];              // instrumentation path name
     176    char         instru_path[64];               // instrumentation path name
    176177
    177178    /////////////////////////////////////////////////////////////////////////////////
     
    255256        // build instrumentation file name
    256257        if( USE_DQT_BARRIER )
    257         snprintf( instru_name , 32 , "conv_dqt_explicit_%d_%d_%d", x_size * y_size , ncores );
     258        snprintf( instru_name , 32 , "conv_dqt_explicit_%d_%d", x_size * y_size , ncores );
    258259        else
    259         snprintf( instru_name , 32 , "conv_smp_explicit_%d_%d_%d", x_size * y_size , ncores );
     260        snprintf( instru_name , 32 , "conv_smp_explicit_%d_%d", x_size * y_size , ncores );
    260261    }
    261262
     
    267268        // build instrumentation file name
    268269        if( USE_DQT_BARRIER )
    269         snprintf( instru_name , 32 , "conv_dqt_parallel_%d_%d_%d", x_size * y_size , ncores );
     270        snprintf( instru_name , 32 , "conv_dqt_parallel_%d_%d", x_size * y_size , ncores );
    270271        else
    271         snprintf( instru_name , 32 , "conv_smp_parallel_%d_%d_%d", x_size * y_size , ncores );
     272        snprintf( instru_name , 32 , "conv_smp_parallel_%d_%d", x_size * y_size , ncores );
    272273    }
    273274
     
    380381    /////////////////////////////////////////////////////////////////////////////////////
    381382
    382     //////////////////
    383     if( NO_PLACEMENT )
    384     {
    385         // the tid value for the main thread is always 0
    386         // main thread creates new threads with tid in [1,nthreads-1] 
    387         unsigned int tid;
    388         for ( tid = 0 ; tid < nthreads ; tid++ )
    389         {
    390             // register tid value in exec_args[tid] array
    391             exec_args[tid].tid = tid;
    392            
    393             // create other threads
    394             if( tid > 0 )
     383//////////////////
     384#if NO_PLACEMENT
     385{
     386    // the tid value for the main thread is always 0
     387    // main thread creates new threads with tid in [1,nthreads-1] 
     388    unsigned int tid;
     389    for ( tid = 0 ; tid < nthreads ; tid++ )
     390    {
     391        // register tid value in exec_args[tid] array
     392        exec_args[tid].tid = tid;
     393         
     394        // create other threads
     395        if( tid > 0 )
     396        {
     397            if ( pthread_create( &exec_trdid[tid],
     398                                 NULL,                  // no attribute
     399                                 &execute,
     400                                 &exec_args[tid] ) )
    395401            {
    396                 if ( pthread_create( &exec_trdid[tid],
    397                                      NULL,                  // no attribute
    398                                      &execute,
    399                                      &exec_args[tid] ) )
    400                 {
    401                     printf("\n[convol error] cannot create thread %d\n", tid );
    402                     exit( 0 );
    403                 }
     402                printf("\n[convol error] cannot create thread %d\n", tid );
     403                exit( 0 );
     404            }
    404405
    405406#if VERBOSE_MAIN
     
    407408#endif
    408409
     410        }
     411        else
     412        {
     413            tid_main = 0;
     414        }
     415    }  // end for tid
     416
     417    // main thread calls itself the execute() function
     418    execute( &exec_args[0] );
     419
     420    // main thread wait other threads completion
     421    for ( tid = 1 ; tid < nthreads ; tid++ )
     422    {
     423        unsigned int * status;
     424
     425        // main wait thread[tid] status
     426        if ( pthread_join( exec_trdid[tid], (void*)(&status)) )
     427        {
     428            printf("\n[convol error] main cannot join thread %d\n", tid );
     429            exit( 0 );
     430        }
     431       
     432        // check status
     433        if( *status != THREAD_EXIT_SUCCESS )
     434        {
     435            printf("\n[convol error] thread %x returned failure\n", tid );
     436            exit( 0 );
     437        }
     438
     439#if VERBOSE_MAIN
     440printf("\n[convol] main successfully joined thread %x\n", tid );
     441#endif
     442       
     443    }  // end for tid
     444
     445#endif // end no_placement
     446
     447//////////////////////
     448#if EXPLICIT_PLACEMENT
     449{
     450    // main thread places each other threads on a specific core[cxy][lid]
     451    // but the actual thread creation is sequencial
     452    unsigned int x;
     453    unsigned int y;
     454    unsigned int l;
     455    unsigned int cxy;                   // cluster identifier
     456    unsigned int tid;                   // thread continuous index
     457
     458    for( x = 0 ; x < x_size ; x++ )
     459    {
     460        for( y = 0 ; y < y_size ; y++ )
     461        {
     462            cxy = HAL_CXY_FROM_XY( x , y );
     463            for( l = 0 ; l < ncores ; l++ )
     464            {
     465                // compute thread continuous index
     466                tid = (((x  * y_size) + y) * ncores) + l;
     467
     468                // register tid value in exec_args[tid] array
     469                exec_args[tid].tid = tid;
     470
     471                // no thread created on the core running the main
     472                if( (cxy != cxy_main) || (l != lid_main) )
     473                {
     474                    // define thread attributes
     475                    exec_attr[tid].attributes = PT_ATTR_CLUSTER_DEFINED |
     476                                                PT_ATTR_CORE_DEFINED;
     477                    exec_attr[tid].cxy        = cxy;
     478                    exec_attr[tid].lid        = l;
     479 
     480                    // create thread[tid] on core[cxy][l]
     481                    if ( pthread_create( &exec_trdid[tid],   
     482                                         &exec_attr[tid],   
     483                                         &execute,
     484                                         &exec_args[tid] ) )       
     485                    {
     486                        printf("\n[convol error] cannot create thread %d\n", tid );
     487                        exit( 0 );
     488                    }
     489#if VERBOSE_MAIN
     490printf("\n[convol] main created thread[%d] on core[%x,%d]\n", tid, cxy, l );
     491#endif
     492                }
     493                else
     494                {
     495                    tid_main = tid;
     496                }
    409497            }
    410             else
    411             {
    412                 tid_main = 0;
    413             }
    414         }  // end for tid
    415 
    416         // main thread calls itself the execute() function
    417         execute( &exec_args[0] );
    418 
    419         // main thread wait other threads completion
    420         for ( tid = 1 ; tid < nthreads ; tid++ )
     498        }
     499    }
     500
     501    // main thread calls itself the execute() function
     502    execute( &exec_args[tid_main] );
     503
     504    // main thread wait other threads completion
     505    for( tid = 0 ; tid < nthreads ; tid++ )
     506    {
     507        // no other thread on the core running the main
     508        if( tid != tid_main )
    421509        {
    422510            unsigned int * status;
    423511
    424             // main wait thread[tid] status
    425             if ( pthread_join( exec_trdid[tid], (void*)(&status)) )
     512            // wait thread[tid]
     513            if( pthread_join( exec_trdid[tid] , (void*)(&status) ) )
    426514            {
    427515                printf("\n[convol error] main cannot join thread %d\n", tid );
    428516                exit( 0 );
    429517            }
    430       
     518     
    431519            // check status
    432520            if( *status != THREAD_EXIT_SUCCESS )
    433521            {
    434                 printf("\n[convol error] thread %x returned failure\n", tid );
     522                printf("\n[convol error] thread %d returned failure\n", tid );
    435523                exit( 0 );
    436524            }
    437 
    438 #if VERBOSE_MAIN
    439 printf("\n[convol] main successfully joined thread %x\n", tid );
    440 #endif
    441        
    442         }  // end for tid
    443 
    444     }  // end if no_placement
    445 
    446     ////////////////////////
    447     if( EXPLICIT_PLACEMENT )
    448     {
    449         // main thread places each other threads on a specific core[cxy][lid]
    450         // but the actual thread creation is sequencial
    451         unsigned int x;
    452         unsigned int y;
    453         unsigned int l;
    454         unsigned int cxy;                   // cluster identifier
    455         unsigned int tid;                   // thread continuous index
    456 
    457         for( x = 0 ; x < x_size ; x++ )
    458         {
    459             for( y = 0 ; y < y_size ; y++ )
    460             {
    461                 cxy = HAL_CXY_FROM_XY( x , y );
    462                 for( l = 0 ; l < ncores ; l++ )
    463                 {
    464                     // compute thread continuous index
    465                     tid = (((x  * y_size) + y) * ncores) + l;
    466 
    467                     // register tid value in exec_args[tid] array
    468                     exec_args[tid].tid = tid;
    469 
    470                     // no thread created on the core running the main
    471                     if( (cxy != cxy_main) || (l != lid_main) )
    472                     {
    473                         // define thread attributes
    474                         exec_attr[tid].attributes = PT_ATTR_CLUSTER_DEFINED |
    475                                                     PT_ATTR_CORE_DEFINED;
    476                         exec_attr[tid].cxy        = cxy;
    477                         exec_attr[tid].lid        = l;
    478  
    479                         // create thread[tid] on core[cxy][l]
    480                         if ( pthread_create( &exec_trdid[tid],   
    481                                              &exec_attr[tid],   
    482                                              &execute,
    483                                              &exec_args[tid] ) )       
    484                         {
    485                             printf("\n[convol error] cannot create thread %d\n", tid );
    486                             exit( 0 );
    487                         }
    488 #if VERBOSE_MAIN
    489 printf("\n[convol] main created thread[%d] on core[%x,%d]\n", tid, cxy, l );
    490 #endif
    491                     }
    492                     else
    493                     {
    494                         tid_main = tid;
    495                     }
    496                 }
    497             }
    498         }
    499 
    500         // main thread calls itself the execute() function
    501         execute( &exec_args[tid_main] );
    502 
    503         // main thread wait other threads completion
    504         for( tid = 0 ; tid < nthreads ; tid++ )
    505         {
    506             // no other thread on the core running the main
    507             if( tid != tid_main )
    508             {
    509                 unsigned int * status;
    510 
    511                 // wait thread[tid]
    512                 if( pthread_join( exec_trdid[tid] , (void*)(&status) ) )
    513                 {
    514                     printf("\n[convol error] main cannot join thread %d\n", tid );
    515                     exit( 0 );
    516                 }
    517        
    518                 // check status
    519                 if( *status != THREAD_EXIT_SUCCESS )
    520                 {
    521                     printf("\n[convol error] thread %d returned failure\n", tid );
    522                     exit( 0 );
    523                 }
    524525#if VERBOSE_MAIN
    525526printf("\n[convol] main joined thread %d on core[%x,%d]\n", tid , cxy , l );
    526527#endif
    527             }
    528         }
    529     }  // end if explicit_placement
    530 
    531     ////////////////////////
    532     if( PARALLEL_PLACEMENT )
    533     {
    534         // compute covering DQT size an level
    535         unsigned int z          = (x_size > y_size) ? x_size : y_size;
    536         unsigned int root_level = ((z == 1) ? 0 :
    537                                   ((z == 2) ? 1 :
    538                                   ((z == 4) ? 2 :
    539                                   ((z == 8) ? 3 : 4))));
    540 
    541         // create & execute the working threads
    542         if( pthread_parallel_create( root_level , &execute ) )
    543         {
    544             printf("\n[convol error] in %s\n", __FUNCTION__ );
    545             exit( 0 );
    546         }
    547     }  // end if parallel_placement
     528        }
     529    }
     530}
     531#endif   // end explicit_placement
     532
     533//////////////////////
     534#if PARALLEL_PLACEMENT
     535{
     536    // compute covering DQT size an level
     537    unsigned int z          = (x_size > y_size) ? x_size : y_size;
     538    unsigned int root_level = ((z == 1) ? 0 :
     539                              ((z == 2) ? 1 :
     540                              ((z == 4) ? 2 :
     541                              ((z == 8) ? 3 : 4))));
     542
     543    // create & execute the working threads
     544    if( pthread_parallel_create( root_level , &execute ) )
     545    {
     546        printf("\n[convol error] in %s\n", __FUNCTION__ );
     547        exit( 0 );
     548    }
     549}
     550#endif  // end parallel_placement
    548551
    549552    /////////////////////////////////////////////////////////////////////////////
     
    555558    instrument( f_instru , instru_name );
    556559
     560#if VERBOSE_MAIN
     561printf("\n[convol] main registered instrumentation info\n" );
     562#endif
     563
    557564    // main thread close input file
    558565    close( fd_in );
    559566
     567#if VERBOSE_MAIN
     568printf("\n[convol] main closed input file\n" );
     569#endif
     570
    560571    // main thread close output file
    561572    close( fd_out );
    562573
     574#if VERBOSE_MAIN
     575printf("\n[convol] main closed output file\n" );
     576#endif
     577
    563578    // main thread close instrumentation file
    564579    fclose( f_instru );
     580
     581#if VERBOSE_MAIN
     582printf("\n[convol] main closed instrumentation file\n" );
     583#endif
    565584
    566585    // main thread suicide
     
    574593
    575594
    576 ///////////////////////////////////////////////////
    577 void execute( pthread_parallel_work_args_t * args )
     595//////////////////////////////////
     596void * execute( void * arguments )
     597
    578598{
    579599    unsigned long long date;
     600
     601    pthread_parallel_work_args_t * args = (pthread_parallel_work_args_t *)arguments;
    580602
    581603    // Each thread initialises the convolution kernel parameters in local stack.
     
    610632unsigned int cxy;              // core cluster identifier
    611633unsigned int lpid;             // core local identifier
     634get_cycle( &date );
    612635get_core_id( &cxy , &lpid );
    613 printf("\n[convol] exec[%d] on core[%x,%d] enters parallel exec\n",
    614 tid , cxy , lpid );
     636printf("\n[convol] exec[%d] on core[%x,%d] enters parallel exec / cycle %d\n",
     637tid , cxy , lpid , (unsigned int)date );
    615638#endif
    616639
     
    639662
    640663    // Each thread[cid][0] allocates 5 local buffers,
    641     // shared by all threads that have the same cid
     664    // and registers these 5 pointers in the global arrays
    642665    if ( lid == 0 )
    643666    {
     
    656679
    657680#if VERBOSE_EXEC
    658 printf( "\n[convol] exec[%d] on core[%x,%d] allocated shared buffers\n"
    659 "### GA = %x\n"
    660 "### GB = %x\n"               
    661 "### GC = %x\n"               
    662 "### GD = %x\n"               
    663 "### GZ = %x\n",
    664 tid, cxy , lpid, GA[cid], GB[cid], GC[cid], GD[cid], GZ[cid] );
     681get_cycle( &date );
     682printf( "\n[convol] exec[%d] on core[%x,%d] allocated shared buffers / cycle %d\n"
     683" GA %x / GB %x / GC %x / GD %x / GZ %x\n",
     684tid, cxy , lpid, (unsigned int)date, GA[cid], GB[cid], GC[cid], GD[cid], GZ[cid] );
    665685#endif
    666686   
     
    700720#if VERBOSE_EXEC
    701721get_cycle( &date );
    702 printf( "\n[convol] thread %d on core[%x,%d] load input file in A[%d]\n",
    703 tid , cxy , lpid , cid );
     722printf( "\n[convol] exec[%d] on core[%x,%d] loaded input file in A[%d] / cycle %d\n",
     723tid , cxy , lpid , cid , (unsigned int)date);
    704724#endif
    705725
     
    729749                           NP*(l + (tid * lines_per_thread))))    // offset in FBF
    730750            {
    731                 printf("\n[convol error] in %s : thread[%x,%d] cannot access FBF\n",
    732                 __FUNCTION__ , cxy , lid );
     751                printf("\n[convol error] in %s : thread[%d] cannot access FBF\n",
     752                __FUNCTION__ , tid );
    733753                pthread_exit( &THREAD_EXIT_FAILURE );
    734754            }
     
    737757#if VERBOSE_EXEC
    738758get_cycle( &date );
    739 printf( "\n[convol] thread[%d] on core[%x,%d] completes initial display\n",
    740 tid , cxy , lpid );
     759printf( "\n[convol] exec[%d] on core[%x,%d] completed initial display / cycle %d\n",
     760tid , cxy , lpid , (unsigned int)date );
    741761#endif
    742762
     
    758778    H_BEG[cid][lid] = (unsigned int)date;
    759779
    760 #if VERBOSE_EXEC
    761 printf( "\n[convol] thread[%d] on core[%x,%d] starts horizontal filter\n",
    762 tid , cxy , lpid );
    763 #else
    764 if ( tid == tid_main )
    765 printf( "\n[convol] thread[%d] on core[%x,%d] starts horizontal filter\n",
    766 tid , cxy , lpid );
    767 #endif
    768 
    769780    // l = absolute line index / p = absolute pixel index 
    770781    // first & last define which lines are handled by a given thread
     
    833844
    834845#if VERBOSE_EXEC
    835 printf( "\n[convol] thread[%d] on core[%x,%d] completes horizontal filter\n",
    836 tid , cxy , lpid );
    837 #else
    838 if ( tid == tid_main )
    839 printf( "\n[convol] thread[%d] on core[%x,%d] completes horizontal filter\n",
    840 tid , cxy , lpid );
     846get_cycle( &date );
     847printf( "\n[convol] exec[%d] on core[%x,%d] completed horizontal filter / cycle %d\n",
     848tid , cxy , lpid , (unsigned int)date );
    841849#endif
    842850
     
    855863    get_cycle( &date );
    856864    V_BEG[cid][lid] = (unsigned int)date;
    857 
    858 #if VERBOSE_EXEC
    859 printf( "\n[convol] thread[%d] on core[%x,%d] starts vertical filter\n",
    860 tid , cxy , lpid );
    861 #else
    862 if ( tid == tid_main )
    863 printf( "\n[convol] thread[%d] on core[%x,%d] starts vertical filter\n",
    864 tid , cxy , lpid );
    865 #endif
    866865
    867866    // l = absolute line index / p = absolute pixel index
     
    947946
    948947#if VERBOSE_EXEC
    949 printf( "\n[convol] thread[%d] on core[%x,%d] completes vertical filter\n",
    950 tid , cxy , lid );
    951 #else
    952 if ( tid == tid_main )
    953 printf( "\n[convol] thread[%d] on core[%x,%d] completes vertical filter\n",
    954 tid , cxy , lid );
     948get_cycle( &date );
     949printf( "\n[convol] exec[%d] on core[%x,%d] completed vertical filter / cycle %d\n",
     950tid , cxy , lid , (unsigned int)date );
    955951#endif
    956952
     
    965961        get_cycle( &date );
    966962        D_BEG[cid][lid] = (unsigned int)date;
    967 
    968 #if VERBOSE_EXEC
    969 printf( "\n[convol] thread[%d] on core[%x,%d] starts final display\n",
    970 tid , cxy , lid );
    971 #else
    972 if ( tid == tid_main )
    973 printf( "\n[convol] thread[%d] on core[%x,%d] starts final display\n",
    974 tid , cxy , lid );
    975 #endif
    976963
    977964        unsigned int line;
     
    1002989
    1003990#if VERBOSE_EXEC
    1004 printf( "\n[convol] thread[%d] on core[%x,%d] completes final display\n",
    1005 tid , cxy , lid );
    1006 #else
    1007 if ( tid == tid_main )
    1008 printf( "\n[convol] thread[%d] on core[%x,%d] completes final display\n",
    1009 tid , cxy , lid );
    1010 #endif
    1011 
    1012     }
    1013 
    1014     // all threads (but the one executing main) exit
    1015     if ( tid != tid_main )
    1016     {
     991get_cycle( &date );
     992printf( "\n[convol] exec[%d] on core[%x,%d] completed final display / cycle %d\n",
     993tid , cxy , lid , (unsigned int)date );
     994#endif
     995
     996    }
     997
     998    // Each thread[cid,0] releases the 5 local buffers
     999    if( lid == 0 )
     1000    {
     1001        free( A[cid] );
     1002        free( B[cid] );
     1003        free( C[cid] );
     1004        free( D[cid] );
     1005        free( Z[cid] );
     1006    }
     1007
     1008    // thread termination depends on the placement policy
     1009    if( PARALLEL_PLACEMENT )   
     1010    {
     1011        // <exec> threads are runing in detached mode, and
     1012        // each thread must signal completion by calling barrier
     1013        // passed in arguments before exit
     1014
     1015        pthread_barrier_wait( args->barrier );
     1016
    10171017        pthread_exit( &THREAD_EXIT_SUCCESS );
    10181018    }
     1019    else
     1020    {
     1021        // <exec> threads are running in attached mode
     1022        // all threads (but the one executing main) exit
     1023        if ( tid != tid_main ) pthread_exit( &THREAD_EXIT_SUCCESS );
     1024    }
     1025
     1026    return NULL;
    10191027
    10201028} // end execute()
     
    11021110           min_d_end, max_d_end, (min_d_end+max_d_end)/2, max_d_end-min_d_end);
    11031111
    1104     printf( "\n General Scenario (Kcycles for each step)\n" );
     1112    printf( "\n General Scenario   (Kcycles)\n" );
    11051113    printf( " - LOAD IMAGE        = %d\n", (min_h_beg - min_start)/1000 );
    11061114    printf( " - H_FILTER          = %d\n", (max_h_end - min_h_beg)/1000 );
     
    11091117    printf( " - BARRIER VERT/DISP = %d\n", (min_d_beg - max_v_end)/1000 );
    11101118    printf( " - DISPLAY           = %d\n", (max_d_end - min_d_beg)/1000 );
    1111     printf( " \nSEQUENCIAL = %d / PARALLEL = %d\n", SEQUENCIAL_TIME, PARALLEL_TIME );
     1119    printf( " \nSEQUENCIAL = %d / PARALLEL = %d\n",
     1120            SEQUENCIAL_TIME/1000, PARALLEL_TIME/1000 );
    11121121
    11131122    // save on disk
     
    11421151    fprintf( f ,  " - BARRIER VERT/DISP = %d\n", (min_d_beg - max_v_end)/1000 );
    11431152    fprintf( f ,  " - DISPLAY           = %d\n", (max_d_end - min_d_beg)/1000 );
    1144     fprintf( f ,  " \nSEQUENCIAL = %d / PARALLEL = %d\n", SEQUENCIAL_TIME, PARALLEL_TIME );
     1153    fprintf( f ,  " \nSEQUENCIAL = %d / PARALLEL = %d\n",
     1154    SEQUENCIAL_TIME/1000, PARALLEL_TIME/1000 );
    11451155
    11461156} // end instrument()
Note: See TracChangeset for help on using the changeset viewer.