Changeset 741


Ignore:
Timestamp:
Dec 10, 2015, 12:16:18 PM (9 years ago)
Author:
alain
Message:

Remove the TG thread: The mjpeg strem dispatch is
directly done by the main thread.

Location:
soft/giet_vm/applications/mjpeg
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/mjpeg/Makefile

    r723 r741  
    99
    1010OBJS = mjpeg.o \
    11        tg.o    \
    1211       demux.o \
    1312       vld.o   \
     
    3130        $(CC)  $(INCLUDES) $(CFLAGS) -c -o  $@ $<
    3231
    33 tg.o: tg.c
    34         $(CC)  $(INCLUDES) $(CFLAGS) -c -o  $@ $<
    35 
    3632demux.o: demux.c
    3733        $(CC)  $(INCLUDES) $(CFLAGS) -c -o  $@ $<
  • soft/giet_vm/applications/mjpeg/demux.c

    r736 r741  
    9090
    9191    // initialise BUFIO for MWMR channel <in>
    92     mwmr_channel_t*   mwmr_in = tg_2_demux[index];
     92    mwmr_channel_t*   mwmr_in = main_2_demux[index];
    9393    mwmr_bufio_t      bufio_in;
    9494    uint8_t           in_buffer[64];
  • soft/giet_vm/applications/mjpeg/mjpeg.c

    r740 r741  
    1010// communications between threads uses MWMR channels,.
    1111// It uses the chained buffer DMA component to display the images on the graphic display.
    12 // It contains 6 types of threads (plus the "main" thread, that makes initialisation)
     12// It contains 5 types of threads, plus the "main" thread, that makes initialisation,
     13// dispatch the byte stream to the various pipelines, and makes instrumentation.
    1314// and 7 types of MWMR communication channels:
    14 // - the TG thread is only mapped in cluster[0,0], but all other threads
     15// - the main thread is only mapped in cluster[0,0], but all other threads
    1516//   (DEMUX, VLD, IQZZ, IDCT, LIBU) are replicated in all clusters.
    1617// - all MWMR channels are replicated in all clusters.
     
    4142
    4243// arrays of pointers on MWMR channels
    43 mwmr_channel_t*  tg_2_demux[256];         // one per cluster
     44mwmr_channel_t*  main_2_demux[256];       // one per cluster
    4445mwmr_channel_t*  demux_2_vld_data[256];   // one per cluster
    4546mwmr_channel_t*  demux_2_vld_huff[256];   // one per cluster
     
    5051
    5152// thread trdid ( for pthread_create() and pthread_join() )
    52 pthread_t   trdid_tg;
    5353pthread_t   trdid_demux[256];             // one per cluster
    5454pthread_t   trdid_vld[256];               // one per cluster
     
    7474////////////////////////////////////////////////
    7575
    76 extern void tg( );
    7776extern void demux( uint32_t index );
    7877extern void vld( uint32_t index );
     
    122121    uint32_t      image_width;
    123122    uint32_t      image_height;
     123    uint32_t      fd;                   // file descriptor
    124124
    125125    if ( INTERACTIVE_MODE )
     
    165165
    166166    // open file containing the MJPEG bit stream
    167     int fd = giet_fat_open( file_pathname , 0 );
     167    fd = giet_fat_open( file_pathname , 0 );
    168168
    169169    giet_pthread_assert( (fd >= 0),
     
    190190
    191191            // allocate MWMR channels in cluster[x][y]
    192             tg_2_demux[index]       = remote_malloc( sizeof( mwmr_channel_t ) , x , y );
    193             buffer                  = remote_malloc( 4 * TG_2_DEMUX_DEPTH , x , y );
    194             mwmr_init( tg_2_demux[index] , buffer , 1 , TG_2_DEMUX_DEPTH );
     192            main_2_demux[index]     = remote_malloc( sizeof( mwmr_channel_t ) , x , y );
     193            buffer                  = remote_malloc( 4 * MAIN_2_DEMUX_DEPTH , x , y );
     194            mwmr_init( main_2_demux[index] , buffer , 1 , MAIN_2_DEMUX_DEPTH );
    195195
    196196            demux_2_vld_data[index] = remote_malloc( sizeof( mwmr_channel_t ) , x , y );
     
    228228    giet_fbf_cma_start();
    229229
    230     mwmr_channel_t* ptr;
     230    mwmr_channel_t* pc;
    231231
    232232    for ( n = 0 ; n < x_size*y_size ; n++ )
    233233    {
    234         ptr = tg_2_demux[n];
    235         PRINTF(" - tg_2_demux[%d]  = %x / &lock = %x / &buf = %x / size = %d\n",
    236                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    237 
    238         ptr = demux_2_vld_data[n];
     234        pc = main_2_demux[n];
     235        PRINTF(" - main_2_demux[%d]  = %x / &lock = %x / &buf = %x / size = %d\n",
     236               n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 )
     237
     238        pc = demux_2_vld_data[n];
    239239        PRINTF(" - demux_2_vld[%d] = %x / &lock = %x / &buf = %x / size = %d\n",
    240                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    241 
    242         ptr = vld_2_iqzz[n];
     240               n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 )
     241
     242        pc = vld_2_iqzz[n];
    243243        PRINTF(" - vld_2_iqzz[%d]  = %x / &lock = %x / &buf = %x / size = %d\n",
    244                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    245 
    246         ptr = iqzz_2_idct[n];
     244               n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 )
     245
     246        pc = iqzz_2_idct[n];
    247247        PRINTF(" - iqzz_2_idct[%d] = %x / &lock = %x / &buf = %x / size = %d\n",
    248                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
    249 
    250         ptr = idct_2_libu[n];
     248               n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 )
     249
     250        pc = idct_2_libu[n];
    251251        PRINTF(" - idct_2_libu[%d] = %x / &lock = %x / &buf = %x / size = %d\n",
    252                n, ptr, (uint32_t)&ptr->lock, (uint32_t)ptr->data, ptr->depth<<2 )
     252               n, pc, (uint32_t)&pc->lock, (uint32_t)pc->data, pc->depth<<2 )
    253253    }
    254254
    255255    // launch all threads : precise mapping is defined in the mjpeg.py file
    256256    uint32_t index;
    257 
    258     if ( giet_pthread_create( &trdid_tg, NULL, &tg , NULL ) )
    259     giet_pthread_exit( "error launching thread tg\n");
    260257
    261258    for ( x = 0 ; x < x_size ; x++ )
     
    321318    }
    322319
     320    /////////////////////////////////////////////////////////////////////////////////////
     321    // dispatch the byte stream to the demux threads, one compressed image per cluster.
     322    // It transfer the stream from the file identified by the fd argument to a 1024
     323    // bytes local buffer. It analyses the stream to detect the End_of_Image markers.
     324    // All the bytes corresponding to a single image from the first byte, to the EOI
     325    // marker included, are written in the main_2_demux[index] channel, in increasing
     326    // order of the cluster index.
     327    /////////////////////////////////////////////////////////////////////////////////////
     328
     329    // allocate input buffer : 1024 bytes
     330    uint8_t        bufin[1024];
     331
     332    // allocate output bufio to access output MWMR channels : 64 bytes == 16 words
     333    mwmr_bufio_t  bufio;
     334    uint8_t       bufout[64];
     335    mwmr_bufio_init( &bufio , bufout , 64 , 0 , main_2_demux[0] );
     336
     337    uint32_t  image;           // image index
     338    uint32_t  cluster;         // cluster index / modulo x_size*y_size
     339    uint32_t  ptr;             // byte pointer in input buffer
     340    uint32_t  eoi_found;       // boolean : End-of-Image found
     341    uint32_t  ff_found;        // boolean : 0xFF value found
     342    uint32_t  bytes_count;     // mumber of bytes in compressed image
     343       
     344    // initialise image and cluster index, and bufin pointer
     345    image   = 0;
     346    cluster = 0;
     347    ptr     = 0;
     348
     349    while( image < MAX_IMAGES )  // one compressed image per iteration
     350    {
     351        // initialise image specific variables
     352        eoi_found   = 0;
     353        ff_found    = 0;
     354        bytes_count = 0;
     355       
     356        // re-initialise the destination buffer for each image
     357        bufio.mwmr = main_2_demux[cluster];
     358
     359        // scan bit stream until EOI found
     360        // transfer one byte per iteration from input buffer to output bufio
     361        while ( eoi_found == 0 )
     362        {
     363            // - tranfer 1024 bytes from file to input buffer when input buffer empty.
     364            // - return to first byte in input file when EOF found,
     365            //   to emulate an infinite stream of images.
     366            if ( ptr == 0 )
     367            {
     368                uint32_t r = giet_fat_read( fd , bufin , 1024 );
     369                if ( r < 1024 )
     370                {
     371                    giet_fat_lseek( fd , 0 , SEEK_SET );
     372                    giet_fat_read( fd , bufin + r , 1024 - r );
     373                }
     374            }
     375
     376            // transfer one byte from input buffer to output bufio
     377            mwmr_bufio_write_byte( &bufio , bufin[ptr] );
     378
     379            // analyse this byte to find EOI marker OxFFD8
     380            // flush the output buffer when EOI found
     381            if ( ff_found )  // possible End of Image
     382            {
     383                ff_found = 0;
     384                if ( bufin[ptr] == 0xD9 )   // End of Image found
     385                {
     386                    // exit current image
     387                    eoi_found = 1;
     388
     389                    // flush output bufio
     390                    mwmr_bufio_flush( &bufio );
     391                }
     392            }
     393            else           // test if first byte of a marker
     394            {
     395                if ( bufin[ptr] == 0xFF )  ff_found = 1;
     396            }       
     397
     398            // increment input buffer pointer modulo 1024
     399            ptr++;
     400            if ( ptr == 1024 ) ptr = 0;
     401               
     402            // increment bytes_count for current image
     403            bytes_count++;
     404
     405        } // end while (eoi)
     406 
     407#if DEBUG_MAIN
     408PRINTF("\nMAIN send image %d to cluster %d at cycle %d : %d bytes\n",
     409       image , cluster , giet_proctime() , bytes_count )
     410#endif
     411        // increment image index
     412        image++;
     413
     414        // increment cluster index modulo (x_size*y_size)   
     415        cluster++;
     416        if (cluster == x_size * y_size) cluster = 0;   
     417
     418    } // end while on images
     419
     420    /////////////////////////////////////////////////////////////////////////////////////
    323421    // wait all threads completion
    324 
    325     if ( giet_pthread_join( trdid_tg , NULL ) )
    326     { PRINTF("\n[MJPEG ERROR] calling giet_pthread_join() for tg\n" ) }
     422    /////////////////////////////////////////////////////////////////////////////////////
    327423
    328424    for ( x = 0 ; x < x_size ; x++ )
     
    359455    }
    360456
    361     // instrumentation
    362 
    363     uint32_t image;
     457    /////////////////////////////////////////////////////////////////////////////////////
     458    // makes instrumentation
     459    /////////////////////////////////////////////////////////////////////////////////////
     460
    364461    PRINTF("\n[MJPEG] Instumentation Results\n" )
    365462    for ( image = 0 ; image < MAX_IMAGES ; image++ )
  • soft/giet_vm/applications/mjpeg/mjpeg.h

    r736 r741  
    3030////////////////////////////////////////////////////////////////////////////////////////
    3131
    32 #define   TG_2_DEMUX_DEPTH          1024
     32#define   MAIN_2_DEMUX_DEPTH        1024
    3333#define   DEMUX_2_VLD_DATA_DEPTH    1024
    3434#define   DEMUX_2_VLD_HUFF_DEPTH    1024
     
    4545////////////////////////////////////////////////////////////////////////////////////////
    4646
    47 #define DEBUG_CLUSTER_INDEX   0xFFFFFFFF   // use 0xFFFFFFFF for all clusters
     47#define DEBUG_CLUSTER_INDEX   0xFFFFFFFF   // use 0xFFFFFFFF to trace all clusters
    4848
    49 #define DEBUG_TG              1
     49#define DEBUG_MAIN            1
    5050#define DEBUG_DEMUX           1
    5151#define DEBUG_VLD             1
     
    5858////////////////////////////////////////////////////////////////////////////////////////
    5959
    60 extern uint32_t         fd;    // file descriptor for the file containing MJPEG stream
    61 
    62 extern mwmr_channel_t*  tg_2_demux[256];         // one per cluster
     60extern mwmr_channel_t*  main_2_demux[256];       // one per cluster
    6361extern mwmr_channel_t*  demux_2_vld_data[256];   // one per cluster
    6462extern mwmr_channel_t*  demux_2_vld_huff[256];   // one per cluster
     
    6866extern mwmr_channel_t*  idct_2_libu[256];        // one per cluster
    6967
    70 extern pthread_t        trdid_tg;
    7168extern pthread_t        trdid_demux[256];        // one per cluster
    7269extern pthread_t        trdid_vld[256];          // one per cluster
  • soft/giet_vm/applications/mjpeg/mjpeg.py

    r736 r741  
    1212#
    1313#  The mapping of threads on processors is the following:
    14 #    - the "main" thread, on P[0,0,0] launches all others threads and exit.
    15 #    - the "tg" thread is only running on P[0,0,0].
     14#    - the "main" thread is running on P[0,0,0].
    1615#    - the "demux", "iqzz", "idct", "vld", and "libu" threads, implementing
    1716#      a block-level pipe-line, are replicated in all clusters.
     
    8382
    8483    # stacks vsegs: local (one stack per thread => 5 stacks per cluster)
    85     # ... plus main_stack and tg_stack in cluster[0][0]
     84    # ... plus main_stack in cluster[0][0]
    8685    base = stack_base
    8786    mapping.addVseg( vspace, 'mjpeg_main_stack',
     
    9291    base += stack_size
    9392
    94     mapping.addVseg( vspace, 'mjpeg_tg_stack',
    95                      base , stack_size, 'C_WU', vtype = 'BUFFER',
    96                      x = 0 , y = 0 , pseg = 'RAM',
    97                      local = True )
    98 
    99     base += stack_size
    100 
    10193    for x in xrange (x_size):
    10294        for y in xrange (y_size):
     
    139131
    140132    # threads mapping: demux, vld, iqzz, idct, libu replicated in all clusters
    141     # main & tg are mapped in cluster[0,0]
     133    # main mapped in cluster[0,0]
    142134    mapping.addThread( vspace, 'main', True, 0, 0, 0,
    143135                       'mjpeg_main_stack',
     
    145137                       0 )                      # index in start_vector
    146138
    147     if ( nprocs == 1 ):
    148         p_tg    = 0
    149         p_demux = 0
    150         p_vld   = 0
    151         p_iqzz  = 0
    152         p_idct  = 0
    153         p_libu  = 0
    154     elif ( nprocs == 2 ):
    155         p_tg    = 0
    156         p_demux = 1
    157         p_vld   = 1
    158         p_iqzz  = 1
    159         p_idct  = 1
    160         p_libu  = 1
    161     elif ( nprocs == 3 ):
    162         p_tg    = 0
    163         p_demux = 1
    164         p_vld   = 2
    165         p_iqzz  = 1
    166         p_idct  = 1
    167         p_libu  = 1
    168     elif ( nprocs == 4 ):
    169         p_tg    = 0
    170         p_demux = 1
    171         p_vld   = 3
    172         p_iqzz  = 2
    173         p_idct  = 3
    174         p_libu  = 2
     139    if ( x==0 and y==0 ):        # tasks mapping in cluster[0,0]
     140        if ( nprocs == 1 ):
     141            p_demux = 0
     142            p_vld   = 0
     143            p_iqzz  = 0
     144            p_idct  = 0
     145            p_libu  = 0
     146        elif ( nprocs == 2 ):
     147            p_demux = 1
     148            p_vld   = 1
     149            p_iqzz  = 1
     150            p_idct  = 1
     151            p_libu  = 1
     152        elif ( nprocs == 3 ):
     153            p_demux = 1
     154            p_vld   = 2
     155            p_iqzz  = 1
     156            p_idct  = 1
     157            p_libu  = 1
     158        elif ( nprocs == 4 ):
     159            p_demux = 1
     160            p_vld   = 2
     161            p_iqzz  = 1
     162            p_idct  = 3
     163            p_libu  = 1
     164    else:                        # tasks mapping in other clusters
     165        if ( nprocs == 1 ):
     166            p_demux = 0
     167            p_vld   = 0
     168            p_iqzz  = 0
     169            p_idct  = 0
     170            p_libu  = 0
     171        elif ( nprocs == 2 ):
     172            p_demux = 0
     173            p_vld   = 1
     174            p_iqzz  = 0
     175            p_idct  = 0
     176            p_libu  = 0
     177        elif ( nprocs == 3 ):
     178            p_demux = 0
     179            p_vld   = 1
     180            p_iqzz  = 0
     181            p_idct  = 2
     182            p_libu  = 1
     183        elif ( nprocs == 4 ):
     184            p_demux = 0
     185            p_vld   = 1
     186            p_iqzz  = 2
     187            p_idct  = 3
     188            p_libu  = 2
     189
    175190   
    176     mapping.addThread( vspace, 'tg', False, 0, 0, p_tg,
    177                        'mjpeg_tg_stack',
    178                        'mjpeg_heap_0_0',
    179                        1 )                      # index in start_vector
    180 
    181191    for x in xrange (x_size):
    182192        for y in xrange (y_size):
     
    186196                                   'mjpeg_demux_stack_%d_%d' % (x,y),
    187197                                   'mjpeg_heap_%d_%d' % (x,y),
    188                                    2 )   # start_index 
     198                                   1 )   # start_index 
    189199
    190200                mapping.addThread( vspace, 'vld_%d_%d' % (x,y), False , x, y, p_vld,
    191201                                   'mjpeg_vld_stack_%d_%d' % (x,y),
    192202                                   'mjpeg_heap_%d_%d' % (x,y),
    193                                    3 )   # start_index 
     203                                   2 )   # start_index 
    194204
    195205                mapping.addThread( vspace, 'iqzz_%d_%d' % (x,y), False , x, y, p_iqzz,
    196206                                   'mjpeg_iqzz_stack_%d_%d' % (x,y),
    197207                                   'mjpeg_heap_%d_%d' % (x,y),
    198                                    4 )   # start_index 
     208                                   3 )   # start_index 
    199209
    200210                mapping.addThread( vspace, 'idct_%d_%d' % (x,y), False , x, y, p_idct,
    201211                                   'mjpeg_idct_stack_%d_%d' % (x,y),
    202212                                   'mjpeg_heap_%d_%d' % (x,y),
    203                                    5 )   # start_index 
     213                                   4 )   # start_index 
    204214
    205215                mapping.addThread( vspace, 'libu_%d_%d' % (x,y), False , x, y, p_libu,
    206216                                   'mjpeg_libu_stack_%d_%d' % (x,y),
    207217                                   'mjpeg_heap_%d_%d' % (x,y),
    208                                    6 )   # start_index 
     218                                   5 )   # start_index 
    209219
    210220    # extend mapping name
Note: See TracChangeset for help on using the changeset viewer.