Changeset 733 for soft/giet_vm
- Timestamp:
- Dec 3, 2015, 4:33:02 PM (9 years ago)
- Location:
- soft/giet_vm/giet_kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/sys_handler.c
r725 r733 313 313 if ( found == 0 ) 314 314 { 315 316 _printf("@@@ _load_writable_segments() : .elf not found\n"); 317 315 _printf("\n[GIET ERROR] _load_writable_segments() : .elf not found\n"); 318 316 return 1; 319 317 } … … 322 320 if ( _fat_lseek( fd, 0, SEEK_SET ) < 0 ) 323 321 { 324 325 _printf("@@@ _load_writable_segments() : cannot seek\n"); 326 322 _printf("\n[GIET ERROR] _load_writable_segments() : cannot seek\n"); 327 323 _fat_close( fd ); 328 324 return 1; 329 330 325 } 331 326 if ( _fat_read( fd, (unsigned int)buf, 4096, 0 ) < 0 ) 332 327 { 333 334 _printf("@@@ _load_writable_segments() : cannot read\n"); 335 328 _printf("\n[GIET ERROR] _load_writable_segments() : cannot read\n"); 336 329 _fat_close( fd ); 337 330 return 1; … … 1146 1139 1147 1140 ////////////////////////////////////////////////// 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 1141 int _sys_coproc_alloc( unsigned int cluster_xy, 1142 unsigned int coproc_type, 1143 unsigned int* return_info ) 1144 { 1155 1145 mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; 1156 1146 mapping_cluster_t * cluster = _get_cluster_base(header); 1157 1147 mapping_periph_t * periph = _get_periph_base(header); 1158 1148 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); 1163 1152 unsigned int cluster_id = x * Y_SIZE + y; 1164 1153 … … 1180 1169 if ( found != NULL ) 1181 1170 { 1182 // get the lock (at most one coproc per cluster)1171 // get the lock 1183 1172 _simple_lock_acquire( &_coproc_lock[cluster_id] ); 1184 1173 … … 1191 1180 1192 1181 // 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]; 1198 1183 1199 1184 #if GIET_DEBUG_COPROC 1200 1185 _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 ); 1203 1188 #endif 1204 1189 return SYSCALL_OK; … … 1215 1200 1216 1201 //////////////////////////////////////////////////////// 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 ) 1202 int _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 ) 1226 1212 { 1227 1213 _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 ); 1229 1216 1230 1217 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1231 1218 } 1232 1219 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;1236 1220 unsigned int info = _coproc_info[cluster_id]; 1237 1221 unsigned int nb_to = info & 0xFF; … … 1240 1224 1241 1225 // 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 ); 1243 1227 for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ ) 1244 1228 { 1245 1229 _mwr_set_channel_register( cluster_xy , channel , MWR_CHANNEL_RUNNING , 0 ); 1246 1230 } 1247 1248 // deallocates coprocessor coordinates in thread context1249 _set_context_slot( CTX_COPROC_ID , 0xFFFFFFFF );1250 1231 1251 1232 // release coprocessor lock … … 1254 1235 #if GIET_DEBUG_COPROC 1255 1236 _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 ); 1257 1239 #endif 1258 1240 … … 1260 1242 } // end _sys_coproc_release() 1261 1243 1262 ////////////////////////////////////////////////////////////// 1263 int _sys_coproc_channel_init( unsigned int channel, 1244 //////////////////////////////////////////////////////////////// 1245 int _sys_coproc_channel_init( unsigned int cluster_xy, 1246 unsigned int coproc_type, 1247 unsigned int channel, 1264 1248 giet_coproc_channel_t* desc ) 1265 1249 { 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 ); 1276 1261 1277 1262 return SYSCALL_COPROCESSOR_NON_ALLOCATED; … … 1297 1282 unsigned int buffer_lsb; 1298 1283 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; 1302 1287 unsigned long long lock_paddr = 0; 1303 1288 unsigned int lock_lsb; … … 1320 1305 { 1321 1306 // 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); 1325 1310 1326 1311 // 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 ); 1329 1314 1330 1315 // compute lock physical address … … 1341 1326 _printf("\n[DEBUG COPROC] _sys_coproc_channel_init() at cycle %d\n" 1342 1327 "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", 1344 1330 _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 ); 1346 1333 #endif 1347 1334 … … 1349 1336 } // end _sys_coproc_channel_init() 1350 1337 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 ////////////////////////////////////////////// 1339 int _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 ); 1364 1353 1365 1354 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1366 1355 } 1367 1356 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;1371 1357 unsigned int info = _coproc_info[cluster_id]; 1372 1358 unsigned int nb_to = info & 0xFF; … … 1375 1361 unsigned int channel; 1376 1362 1377 // register coprocessor running mode1363 // check channels modes, and register coprocessor running mode 1378 1364 for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ ) 1379 1365 { … … 1388 1374 { 1389 1375 _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 ); 1391 1377 1392 1378 return SYSCALL_COPROCESSOR_ILLEGAL_MODE; … … 1405 1391 { 1406 1392 // start coprocessor 1407 _mwr_set_coproc_register( cluster_xy , coproc_reg_index, 1 );1393 _mwr_set_coproc_register( cluster_xy , 0 , 1 ); 1408 1394 1409 1395 #if GIET_DEBUG_COPROC 1410 1396 if ( mode == MODE_MWMR ) 1411 1397 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1412 "t hread %x starts coprocessor[%d,%d] inMODE_MWMR\n",1413 _get_proctime() , trdid , cx , cy );1398 "type = %d / cluster[%d,%d] / MODE_MWMR\n", 1399 _get_proctime() , coproc_type , x , y ); 1414 1400 else 1415 1401 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1416 "t hread %x starts coprocessor[%d,%d] inMODE_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 ); 1418 1404 #endif 1419 1405 … … 1423 1409 else // mode == MODE_DMA_IRQ => descheduling 1424 1410 { 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; 1432 1414 1433 1415 // enters critical section … … 1436 1418 1437 1419 // 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(); 1439 1422 unsigned int* ptr = &psched->context[ltid].slot[CTX_NORUN_ID]; 1440 1423 _atomic_or( ptr , NORUN_MASK_COPROC ); 1441 1424 1442 1425 // start coprocessor 1443 _mwr_set_coproc_register( cluster_xy , coproc_reg_index, 1 );1426 _mwr_set_coproc_register( cluster_xy , 0 , 1 ); 1444 1427 1445 1428 #if GIET_DEBUG_COPROC 1446 1429 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1447 "thread %x starts coprocessor [%d,%d] inMODE_DMA_IRQ\n",1448 _get_proctime() , trdid , c x , cy );1430 "thread %x starts coprocessor / type = %d / cluster[%d,%d] / MODE_DMA_IRQ\n", 1431 _get_proctime() , trdid , coproc_type , x , y ); 1449 1432 #endif 1450 1433 … … 1455 1438 _printf("\n[DEBUG COPROC] _sys_coproc_run() at cycle %d\n" 1456 1439 "thread %x resume after coprocessor[%d,%d] completion\n", 1457 _get_proctime() , trdid , cx , cy );1440 _get_proctime() , trdid , x , y ); 1458 1441 #endif 1459 1442 … … 1466 1449 } // end _sys_coproc_run() 1467 1450 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 //////////////////////////////////////////////////// 1452 int _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 ); 1481 1466 1482 1467 return SYSCALL_COPROCESSOR_NON_ALLOCATED; 1483 1468 } 1484 1469 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]; 1489 1471 1490 1472 // analyse possible errors … … 1527 1509 1528 1510 // 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 ); 1531 1512 1532 1513 } // end for channels … … 1541 1522 #if GIET_DEBUG_COPROC 1542 1523 _printf("\n[DEBUG COPROC] _sys_coproc_completed() at cycle %d\n" 1543 "coprocessor [%d,%d] successfullycompletes 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() ); 1545 1526 #endif 1546 1527 return SYSCALL_OK; … … 1550 1531 { 1551 1532 _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 ); 1553 1534 1554 1535 return SYSCALL_COPROCESSOR_ILLEGAL_MODE; … … 3146 3127 _cma_set_register( channel, CHBUF_DST_NBUFS, 1 ); 3147 3128 _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 ); 3149 3130 _cma_set_register( channel, CHBUF_RUN , MODE_NO_DST_SYNC ); 3150 3131 -
soft/giet_vm/giet_kernel/sys_handler.h
r725 r733 148 148 /////////////////////////////////////////////////////////////////////////////// 149 149 150 extern int _sys_coproc_alloc( unsigned int coproc_type, 151 unsigned int* coproc_info ); 152 153 extern int _sys_coproc_release( unsigned int coproc_reg_index ); 154 155 extern int _sys_coproc_channel_init( unsigned int channel, 150 extern int _sys_coproc_alloc( unsigned int cluster_xy, 151 unsigned int coproc_type, 152 unsigned int* return_info ); 153 154 extern int _sys_coproc_release( unsigned int cluster_xy, 155 unsigned int coproc_type ); 156 157 extern int _sys_coproc_channel_init( unsigned int cluster_xy, 158 unsigned int coproc_type, 159 unsigned int channel, 156 160 giet_coproc_channel_t* desc ); 157 161 158 extern int _sys_coproc_run( unsigned int coproc_reg_index ); 159 160 extern int _sys_coproc_completed(); 162 extern int _sys_coproc_run( unsigned int cluster_xy, 163 unsigned int coproc_type ); 164 165 extern int _sys_coproc_completed( unsigned int cluster_xy, 166 unsigned int coproc_type ); 161 167 162 168 ///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.