Ignore:
Timestamp:
Dec 3, 2015, 4:33:02 PM (9 years ago)
Author:
alain
Message:

Modify the system functions associated to hardware coprocessors:
Introduce two explicit arguments "cluster_xy" and "cluster_type"
to allows any task to control a coprocessor located in any cluster.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/sys_handler.c

    r725 r733  
    313313    if ( found == 0 )
    314314    {
    315 
    316 _printf("@@@ _load_writable_segments() : .elf not found\n");
    317 
     315        _printf("\n[GIET ERROR] _load_writable_segments() : .elf not found\n");
    318316        return 1;
    319317    }
     
    322320    if ( _fat_lseek( fd, 0, SEEK_SET ) < 0 )
    323321    {
    324 
    325 _printf("@@@ _load_writable_segments() : cannot seek\n");
    326 
     322        _printf("\n[GIET ERROR] _load_writable_segments() : cannot seek\n");
    327323        _fat_close( fd );
    328324        return 1;
    329 
    330325    }
    331326    if ( _fat_read( fd, (unsigned int)buf, 4096, 0 ) < 0 )
    332327    {
    333 
    334 _printf("@@@ _load_writable_segments() : cannot read\n");
    335 
     328        _printf("\n[GIET ERROR] _load_writable_segments() : cannot read\n");
    336329        _fat_close( fd );
    337330        return 1;
     
    11461139
    11471140//////////////////////////////////////////////////
    1148 int _sys_coproc_alloc( unsigned int   coproc_type,
    1149                        unsigned int*  coproc_info )
    1150 {
    1151     // In this implementation, the allocation policy is constrained:
    1152     // the coprocessor must be in the same cluster as the calling thread,
    1153     // and there is at most one coprocessor per cluster
    1154 
     1141int _sys_coproc_alloc( unsigned int   cluster_xy,
     1142                       unsigned int   coproc_type,
     1143                       unsigned int*  return_info )
     1144{
    11551145    mapping_header_t  * header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
    11561146    mapping_cluster_t * cluster = _get_cluster_base(header);
    11571147    mapping_periph_t  * periph  = _get_periph_base(header);
    11581148
    1159     // get cluster coordinates and cluster global index
    1160     unsigned int procid     = _get_procid();
    1161     unsigned int x          = procid >> (Y_WIDTH + P_WIDTH);
    1162     unsigned int y          = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
     1149    // compute cluster coordinates and cluster index in mapping
     1150    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     1151    unsigned int x          = (cluster_xy>>Y_WIDTH) & ((1<<X_WIDTH)-1);
    11631152    unsigned int cluster_id = x * Y_SIZE + y;
    11641153 
     
    11801169    if ( found != NULL )
    11811170    {
    1182         // get the lock (at most one coproc per cluster)
     1171        // get the lock
    11831172        _simple_lock_acquire( &_coproc_lock[cluster_id] );
    11841173
     
    11911180
    11921181        // returns coprocessor info
    1193         *coproc_info = _coproc_info[cluster_id];
    1194 
    1195         // register coprocessor coordinates in thread context
    1196         unsigned int cluster_xy = (x<<Y_WIDTH) + y;
    1197         _set_context_slot( CTX_COPROC_ID , cluster_xy );
     1182        *return_info = _coproc_info[cluster_id];
    11981183
    11991184#if GIET_DEBUG_COPROC
    12001185_printf("\n[DEBUG COPROC] _sys_coproc_alloc() at cycle %d\n"
    1201         "coproc_info = %x / cluster_xy = %x\n",
    1202         _get_proctime() , *coproc_info , cluster_xy );
     1186        "type = %d in cluster[%d,%d] / coproc_info = %x\n",
     1187        _get_proctime() , coproc_type, x , y , *return_info );
    12031188#endif
    12041189        return SYSCALL_OK;
     
    12151200
    12161201////////////////////////////////////////////////////////
    1217 int _sys_coproc_release( unsigned int coproc_reg_index )
    1218 {
    1219     // get thread trdid
    1220     unsigned int trdid = _get_thread_trdid();
    1221 
    1222     // get coprocessor coordinates
    1223     unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
    1224 
    1225     if ( cluster_xy > 0xFF )
     1202int _sys_coproc_release( unsigned int cluster_xy,
     1203                         unsigned int coproc_type )
     1204{
     1205    // compute cluster coordinates and cluster index
     1206    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     1207    unsigned int x          = (cluster_xy>>Y_WIDTH) & ((1<<X_WIDTH)-1);
     1208    unsigned int cluster_id = x * Y_SIZE + y;
     1209
     1210    // check coprocessor type
     1211    if ( _coproc_type[cluster_id] != coproc_type )
    12261212    {
    12271213         _printf("\n[GIET_ERROR] in _sys_coproc_release(): "
    1228                  "no coprocessor allocated to thread %x\n", trdid );
     1214                 "no coprocessor of type %d allocated in cluster[%d,%d]\n",
     1215                 coproc_type, x , y );
    12291216
    12301217         return SYSCALL_COPROCESSOR_NON_ALLOCATED;
    12311218    }
    12321219
    1233     unsigned int cx         = cluster_xy >> Y_WIDTH;
    1234     unsigned int cy         = cluster_xy & ((1<<Y_WIDTH)-1);
    1235     unsigned int cluster_id = cx * Y_SIZE + cy;
    12361220    unsigned int info       = _coproc_info[cluster_id];
    12371221    unsigned int nb_to      = info & 0xFF;
     
    12401224
    12411225    // stops coprocessor and communication channels
    1242     _mwr_set_coproc_register( cluster_xy , coproc_reg_index , 0 );
     1226    _mwr_set_coproc_register( cluster_xy , 0 , 0 );
    12431227    for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ )
    12441228    {
    12451229        _mwr_set_channel_register( cluster_xy , channel , MWR_CHANNEL_RUNNING , 0 );
    12461230    }
    1247 
    1248     // deallocates coprocessor coordinates in thread context
    1249     _set_context_slot( CTX_COPROC_ID , 0xFFFFFFFF );
    12501231
    12511232    // release coprocessor lock
     
    12541235#if GIET_DEBUG_COPROC
    12551236_printf("\n[DEBUG COPROC] _sys_coproc_release() at cycle %d\n"
    1256         "thread %x release coprocessor in cluster[%d,%d]\n", cx, cy );
     1237        "type = %d in cluster[%d,%d]\n",
     1238        _get_proctime() , coproc_type , x , y );
    12571239#endif
    12581240
     
    12601242}  // end _sys_coproc_release()
    12611243
    1262 //////////////////////////////////////////////////////////////
    1263 int _sys_coproc_channel_init( unsigned int            channel,
     1244////////////////////////////////////////////////////////////////
     1245int _sys_coproc_channel_init( unsigned int            cluster_xy,
     1246                              unsigned int            coproc_type,
     1247                              unsigned int            channel,
    12641248                              giet_coproc_channel_t*  desc )
    12651249{
    1266     // get thread trdid
    1267     unsigned int trdid = _get_thread_trdid();
    1268 
    1269     // get coprocessor coordinates
    1270     unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
    1271 
    1272     if ( cluster_xy > 0xFF )
    1273     {
    1274          _printf("\n[GIET_ERROR] in _sys_coproc_channel_init(): "
    1275                  "no coprocessor allocated to thread %x\n", trdid );
     1250    // compute cluster coordinates and cluster index
     1251    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     1252    unsigned int x          = (cluster_xy>>Y_WIDTH) & ((1<<X_WIDTH)-1);
     1253    unsigned int cluster_id = x * Y_SIZE + y;
     1254
     1255    // check coprocessor type
     1256    if ( _coproc_type[cluster_id] != coproc_type )
     1257    {
     1258         _printf("\n[GIET_ERROR] in _sys_coproc_release(): "
     1259                 "no coprocessor of type %d allocated in cluster[%d,%d]\n",
     1260                 coproc_type, x , y );
    12761261
    12771262         return SYSCALL_COPROCESSOR_NON_ALLOCATED;
     
    12971282    unsigned int       buffer_lsb;
    12981283    unsigned int       buffer_msb;
    1299     unsigned long long mwmr_paddr = 0;
    1300     unsigned int       mwmr_lsb;
    1301     unsigned int       mwmr_msb;
     1284    unsigned long long status_paddr = 0;
     1285    unsigned int       status_lsb;
     1286    unsigned int       status_msb;
    13021287    unsigned long long lock_paddr = 0;
    13031288    unsigned int       lock_lsb;
     
    13201305    {
    13211306        // compute MWMR descriptor physical address
    1322         mwmr_paddr = _v2p_translate( desc->mwmr_vaddr , &flags );
    1323         mwmr_lsb = (unsigned int)mwmr_paddr;
    1324         mwmr_msb = (unsigned int)(mwmr_paddr>>32);
     1307        status_paddr = _v2p_translate( desc->status_vaddr , &flags );
     1308        status_lsb = (unsigned int)status_paddr;
     1309        status_msb = (unsigned int)(status_paddr>>32);
    13251310
    13261311        // call MWMR_DMA driver
    1327         _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MWMR_LSB, mwmr_lsb );
    1328         _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MWMR_MSB, mwmr_msb );
     1312        _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MWMR_LSB, status_lsb );
     1313        _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MWMR_MSB, status_msb );
    13291314
    13301315        // compute lock physical address
     
    13411326_printf("\n[DEBUG COPROC] _sys_coproc_channel_init() at cycle %d\n"
    13421327        "cluster[%d,%d] / channel = %d / mode = %d / buffer_size = %d\n"
    1343         " buffer_paddr = %l / mwmr_paddr = %l / lock_paddr = %l\n",
     1328        "buffer_vaddr = %x / status_vaddr = %x / lock_vaddr = %x\n"
     1329        "buffer_paddr = %l / status_paddr = %l / lock_paddr = %l\n",
    13441330        _get_proctime() , x , y , channel , mode , size ,
    1345         buffer_paddr, mwmr_paddr, lock_paddr );
     1331        desc->buffer_vaddr, desc->status_vaddr, desc->lock_vaddr,
     1332        buffer_paddr, status_paddr, lock_paddr );
    13461333#endif
    13471334       
     
    13491336} // end _sys_coproc_channel_init()
    13501337
    1351 ////////////////////////////////////////////////////
    1352 int _sys_coproc_run( unsigned int coproc_reg_index )
    1353 {
    1354     // get thread trdid
    1355     unsigned int trdid = _get_thread_trdid();
    1356 
    1357     // get coprocessor coordinates
    1358     unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
    1359 
    1360     if ( cluster_xy > 0xFF )
    1361     {
    1362          _printf("\n[GIET_ERROR] in _sys_coproc_run(): "
    1363                  "no coprocessor allocated to thread %d\n", trdid );
     1338//////////////////////////////////////////////
     1339int _sys_coproc_run( unsigned int  cluster_xy,
     1340                     unsigned int  coproc_type )
     1341{
     1342    // compute cluster coordinates and cluster index
     1343    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     1344    unsigned int x          = (cluster_xy>>Y_WIDTH) & ((1<<X_WIDTH)-1);
     1345    unsigned int cluster_id = x * Y_SIZE + y;
     1346
     1347    // check coprocessor type
     1348    if ( _coproc_type[cluster_id] != coproc_type )
     1349    {
     1350         _printf("\n[GIET_ERROR] in _sys_coproc_release(): "
     1351                 "no coprocessor of type %d allocated in cluster[%d,%d]\n",
     1352                 coproc_type, x , y );
    13641353
    13651354         return SYSCALL_COPROCESSOR_NON_ALLOCATED;
    13661355    }
    13671356
    1368     unsigned int cx         = cluster_xy >> Y_WIDTH;
    1369     unsigned int cy         = cluster_xy & ((1<<Y_WIDTH)-1);
    1370     unsigned int cluster_id = cx * Y_SIZE + cy;
    13711357    unsigned int info       = _coproc_info[cluster_id];
    13721358    unsigned int nb_to      = info & 0xFF;
     
    13751361    unsigned int channel;
    13761362
    1377     // register coprocessor running mode
     1363    // check channels modes, and register coprocessor running mode
    13781364    for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ )
    13791365    {
     
    13881374        {
    13891375            _printf("\n[GIET_ERROR] in _sys_coproc_run(): "
    1390                     "channels don't have same mode in coprocessor[%d,%d]\n", cx , cy );
     1376                    "channels don't have same mode in coprocessor[%d,%d]\n", x , y );
    13911377
    13921378            return SYSCALL_COPROCESSOR_ILLEGAL_MODE;
     
    14051391    {
    14061392        // start coprocessor
    1407         _mwr_set_coproc_register( cluster_xy , coproc_reg_index , 1 );
     1393        _mwr_set_coproc_register( cluster_xy , 0 , 1 );
    14081394
    14091395#if GIET_DEBUG_COPROC
    14101396if ( mode == MODE_MWMR )
    14111397_printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n"
    1412         "thread %x starts coprocessor[%d,%d] in MODE_MWMR\n",
    1413         _get_proctime() , trdid , cx , cy );
     1398        "type = %d / cluster[%d,%d] / MODE_MWMR\n",
     1399        _get_proctime() , coproc_type , x , y );
    14141400else
    14151401_printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n"
    1416         "thread %x starts coprocessor[%d,%d] in MODE_DMA_NO_IRQ\n",
    1417         _get_proctime() , trdid , cx , cy );
     1402        "type = %d / cluster[%d,%d] / MODE_DMA_NO_IRQ\n",
     1403        _get_proctime() , coproc_type , x , y );
    14181404#endif
    14191405
     
    14231409    else                                // mode == MODE_DMA_IRQ => descheduling
    14241410    {
    1425         // set _coproc_trdid
    1426         unsigned int gpid         = _get_procid();
    1427         unsigned int x            = gpid >> (Y_WIDTH+P_WIDTH);
    1428         unsigned int y            = (gpid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    1429         unsigned int p            = gpid & ((1<<P_WIDTH)-1);
    1430         unsigned int ltid         = _get_thread_ltid();
    1431         _coproc_trdid[cluster_id] = (x<<24) + (y<<16) + (p<<8) + ltid;
     1411        // register calling thread trdid
     1412        unsigned int trdid = _get_thread_trdid();
     1413        _coproc_trdid[cluster_id] = trdid;
    14321414
    14331415        // enters critical section
     
    14361418
    14371419        // set NORUN_MASK_COPROC bit
    1438         static_scheduler_t* psched  = (static_scheduler_t*)_schedulers[x][y][p];
     1420        static_scheduler_t* psched  = _get_sched();
     1421        unsigned int        ltid    = _get_thread_ltid();
    14391422        unsigned int*       ptr     = &psched->context[ltid].slot[CTX_NORUN_ID];
    14401423        _atomic_or( ptr , NORUN_MASK_COPROC );
    14411424
    14421425        // start coprocessor
    1443         _mwr_set_coproc_register( cluster_xy , coproc_reg_index , 1 );
     1426        _mwr_set_coproc_register( cluster_xy , 0 , 1 );
    14441427
    14451428#if GIET_DEBUG_COPROC
    14461429_printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n"
    1447         "thread %x starts coprocessor[%d,%d] in MODE_DMA_IRQ\n",
    1448         _get_proctime() , trdid , cx , cy );
     1430        "thread %x starts coprocessor / type = %d / cluster[%d,%d] / MODE_DMA_IRQ\n",
     1431        _get_proctime() , trdid , coproc_type , x , y );
    14491432#endif
    14501433
     
    14551438_printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n"
    14561439        "thread %x resume after coprocessor[%d,%d] completion\n",
    1457         _get_proctime() , trdid , cx , cy );
     1440        _get_proctime() , trdid , x , y );
    14581441#endif
    14591442
     
    14661449} // end _sys_coproc_run()
    14671450
    1468 ///////////////////////////
    1469 int _sys_coproc_completed()
    1470 {
    1471     // get thread trdid
    1472     unsigned int trdid = _get_thread_trdid();
    1473 
    1474     // get coprocessor coordinates
    1475     unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
    1476 
    1477     if ( cluster_xy > 0xFF )
    1478     {
    1479          _printf("\n[GIET_ERROR] in _sys_coproc_completed(): "
    1480                  "no coprocessor allocated to thread %x\n", trdid );
     1451////////////////////////////////////////////////////
     1452int _sys_coproc_completed( unsigned int  cluster_xy,
     1453                           unsigned int  coproc_type )
     1454{
     1455    // compute cluster coordinates and cluster index
     1456    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     1457    unsigned int x          = (cluster_xy>>Y_WIDTH) & ((1<<X_WIDTH)-1);
     1458    unsigned int cluster_id = x * Y_SIZE + y;
     1459
     1460    // check coprocessor type
     1461    if ( _coproc_type[cluster_id] != coproc_type )
     1462    {
     1463         _printf("\n[GIET_ERROR] in _sys_coproc_release(): "
     1464                 "no coprocessor of type %d allocated in cluster[%d,%d]\n",
     1465                 coproc_type, x , y );
    14811466
    14821467         return SYSCALL_COPROCESSOR_NON_ALLOCATED;
    14831468    }
    14841469
    1485     unsigned int cx         = cluster_xy >> Y_WIDTH;
    1486     unsigned int cy         = cluster_xy & ((1<<Y_WIDTH)-1);
    1487     unsigned int cluster_id = cx * Y_SIZE + cy;
    1488     unsigned int mode       = _coproc_mode[cluster_id];
     1470    unsigned int mode = _coproc_mode[cluster_id];
    14891471
    14901472    // analyse possible errors
     
    15271509
    15281510            // reset channel
    1529             _mwr_set_channel_register( cluster_xy, channel,
    1530                                        MWR_CHANNEL_RUNNING , 0 );
     1511            _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_RUNNING , 0 );
    15311512
    15321513        }  // end for channels
     
    15411522#if GIET_DEBUG_COPROC
    15421523_printf("\n[DEBUG COPROC] _sys_coproc_completed() at cycle %d\n"
    1543         "coprocessor[%d,%d] successfully completes operation for thread %d\n",
    1544         cx , cy , trdid );
     1524        "coprocessor type = %d / cluster[%d,%d] completes operation for thread %d\n",
     1525        _get_proctime() , coproc_type , x , y , _get_thread_trdid() );
    15451526#endif
    15461527            return SYSCALL_OK;
     
    15501531    {
    15511532        _printf("\n[GIET ERROR] in sys_coproc_completed(): "
    1552                 "coprocessor[%d,%d] is not running in MODE_DMA_NO_IRQ\n", cx , cy );
     1533                "coprocessor[%d,%d] is not running in MODE_DMA_NO_IRQ\n", x , y );
    15531534
    15541535        return SYSCALL_COPROCESSOR_ILLEGAL_MODE;
     
    31463127    _cma_set_register( channel, CHBUF_DST_NBUFS, 1 );
    31473128    _cma_set_register( channel, CHBUF_BUF_SIZE , FBUF_X_SIZE*FBUF_Y_SIZE );
    3148     _cma_set_register( channel, CHBUF_PERIOD   , 300 );
     3129    _cma_set_register( channel, CHBUF_PERIOD   , 1000 );
    31493130    _cma_set_register( channel, CHBUF_RUN      , MODE_NO_DST_SYNC );
    31503131
Note: See TracChangeset for help on using the changeset viewer.