Changeset 709 for soft/giet_vm/giet_drivers
- Timestamp:
- Oct 1, 2015, 4:20:46 PM (9 years ago)
- Location:
- soft/giet_vm/giet_drivers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_drivers/bdv_driver.c
r657 r709 37 37 spin_lock_t _bdv_lock __attribute__((aligned(64))); 38 38 39 // global index of the waiting t ask(only used in descheduling mode)39 // global index of the waiting thread (only used in descheduling mode) 40 40 __attribute__((section(".kdata"))) 41 unsigned int _bdv_ gtid;41 unsigned int _bdv_trdid; 42 42 43 43 // BDV peripheral status (only used in descheduling mode) … … 75 75 unsigned int count) 76 76 { 77 unsigned int procid = _get_procid(); 78 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 79 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH) - 1);80 unsigned int p = procid & ((1<<P_WIDTH)-1);81 82 #if GIET_DEBUG_IOC 77 78 #if GIET_DEBUG_IOC 79 unsigned int procid = _get_procid(); 80 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 81 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH) - 1); 82 unsigned int p = procid & ((1<<P_WIDTH)-1); 83 83 if ( _get_proctime() > GIET_DEBUG_IOC ) 84 84 _printf("\n[BDV DEBUG] P[%d,%d,%d] enters _bdv_access at cycle %d\n" … … 97 97 unsigned int status; 98 98 99 // get the lock protecting BDV 99 // get the BDV lock and register it in task context 100 static_scheduler_t* psched = _get_sched(); 101 unsigned int ltid = _get_thread_ltid(); 100 102 _spin_lock_acquire( &_bdv_lock ); 103 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_BDV ); 101 104 102 105 // set device registers … … 149 152 150 153 ///////////////////////////////////////////////////////////////// 151 // in descheduling mode, we deschedule the t ask152 // and use an interrupt to reschedule the t ask.154 // in descheduling mode, we deschedule the thread 155 // and use an interrupt to reschedule the thread. 153 156 // We need a critical section, because we must reset the RUN bit 154 157 // before to launch the transfer, and we don't want to be … … 158 161 { 159 162 unsigned int save_sr; 160 unsigned int ltid = _get_current_task_id();161 163 162 164 // activates BDV interrupt 163 165 _bdv_set_register( BLOCK_DEVICE_IRQ_ENABLE, 1 ); 164 166 165 // set _bdv_ gtid166 _bdv_ gtid = (procid<<16) + ltid;167 // set _bdv_trdid 168 _bdv_trdid = _get_thread_trdid(); 167 169 168 170 // enters critical section … … 170 172 171 173 // Set NORUN_MASK_IOC bit 172 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 173 _atomic_or( &psched->context[ltid][CTX_NORUN_ID] , NORUN_MASK_IOC ); 174 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 175 unsigned int ltid = psched->current; 176 _atomic_or( &psched->context[ltid].slot[CTX_NORUN_ID] , NORUN_MASK_IOC ); 174 177 175 178 // launch transfer … … 184 187 #endif 185 188 186 // deschedule t ask189 // deschedule thread 187 190 _ctx_switch(); 188 191 … … 201 204 } 202 205 203 // release lock206 // release BDV lock and clear task context 204 207 _spin_lock_release( &_bdv_lock ); 208 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_BDV ); 205 209 206 210 #if GIET_DEBUG_IOC … … 241 245 _bdv_status = status; 242 246 243 // identify task waiting on BDV 244 unsigned int procid = _bdv_gtid>>16; 245 unsigned int ltid = _bdv_gtid & 0xFFFF; 246 unsigned int cluster = procid >> P_WIDTH; 247 unsigned int x = cluster >> Y_WIDTH; 248 unsigned int y = cluster & ((1<<Y_WIDTH)-1); 249 unsigned int p = procid & ((1<<P_WIDTH)-1); 247 // identify thread waiting on BDV 248 unsigned int x = (_bdv_trdid >> 24) & 0xFF; 249 unsigned int y = (_bdv_trdid >> 16) & 0xFF; 250 unsigned int p = (_bdv_trdid >> 8) & 0xFF; 251 unsigned int ltid = (_bdv_trdid ) & 0xFF; 250 252 251 253 // Reset NORUN_MASK_IOC bit 252 254 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 253 unsigned int* ptr = &psched->context[ltid] [CTX_NORUN_ID];255 unsigned int* ptr = &psched->context[ltid].slot[CTX_NORUN_ID]; 254 256 _atomic_and( ptr , ~NORUN_MASK_IOC ); 255 257 256 // send a WAKUP WTI to processor running the sleeping t ask257 _xcu_send_wti( cluster,258 // send a WAKUP WTI to processor running the sleeping thread 259 _xcu_send_wti( (x<<Y_WIDTH) + y, 258 260 p, 259 261 0 ); // don't force context switch … … 266 268 if ( _get_proctime() > GIET_DEBUG_IOC ) 267 269 _printf("\n[BDV DEBUG] Processor[%d,%d,%d] enters _bdv_isr() at cycle %d\n" 268 " for t ask%d running on P[%d,%d,%d] / bdv_status = %x\n",270 " for thread %d running on P[%d,%d,%d] / bdv_status = %x\n", 269 271 c_x , c_y , c_p , _get_proctime() , 270 272 ltid , x , y , p , status ); -
soft/giet_vm/giet_drivers/bdv_driver.h
r529 r709 78 78 79 79 /////////////////////////////////////////////////////////////////////////////////// 80 // Access functions80 // Low level access function 81 81 /////////////////////////////////////////////////////////////////////////////////// 82 83 unsigned int _bdv_get_register( unsigned int index ); 84 85 void _bdv_set_register( unsigned int index, 86 unsigned int value ); 82 87 83 88 /////////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/giet_drivers/hba_driver.c
r657 r709 46 46 sqt_lock_t _hba_allocator_lock __attribute__((aligned(64))); 47 47 48 // state of each slot (allocated to a t askor not)48 // state of each slot (allocated to a thread or not) 49 49 // access must be protected by the allocator_lock in descheduling mode 50 50 __attribute__((section(".kdata"))) … … 56 56 unsigned int _hba_active_cmd[32]; 57 57 58 // global index of the t ask, for each entry in the command list59 __attribute__((section(".kdata"))) 60 unsigned int _hba_ gtid[32];58 // global index of the thread, for each entry in the command list 59 __attribute__((section(".kdata"))) 60 unsigned int _hba_trid[32]; 61 61 62 62 // status of HBA commands … … 97 97 98 98 /////////////////////////////////////////////////////////////////////////////// 99 // This blocking fonction allocates a free command index to the t ask.99 // This blocking fonction allocates a free command index to the thread. 100 100 // The hba_allocator_lock is not used in boot mode. 101 101 // It returns the allocated command index (between 0 and 31) … … 132 132 /////////////////////////////////////////////////////////////////////////////// 133 133 // This function releases the command index in the hba_allocated_cmd table. 134 // There is no need to take the lock because only the t askwhich owns the134 // There is no need to take the lock because only the thread which owns the 135 135 // command can release it. 136 136 // return 0 if success, -1 if error … … 281 281 282 282 ///////////////////////////////////////////////////////////////// 283 // in descheduling mode, we deschedule the t ask284 // and use an interrupt to reschedule the t ask.283 // in descheduling mode, we deschedule the thread 284 // and use an interrupt to reschedule the thread. 285 285 // We need a critical section, because we must set the NORUN bit 286 286 // before to launch the transfer, and we don't want to be … … 297 297 #endif 298 298 unsigned int save_sr; 299 unsigned int ltid = _get_ current_task_id();299 unsigned int ltid = _get_thread_ltid(); 300 300 301 301 // activates HBA interrupts 302 302 _hba_set_register( HBA_PXIE , 0x00000001 ); 303 303 304 // set _hba_ gtid[cmd_id]305 _hba_ gtid[cmd_id] = (procid<<16) + ltid;304 // set _hba_trid[cmd_id] 305 _hba_trid[cmd_id] = (x<<24) + (y<<16) + (p<<8) + ltid; 306 306 307 307 // enters critical section … … 310 310 // Set NORUN_MASK_IOC bit 311 311 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 312 unsigned int* ptr = &psched->context[ltid] [CTX_NORUN_ID];312 unsigned int* ptr = &psched->context[ltid].slot[CTX_NORUN_ID]; 313 313 _atomic_or( ptr , NORUN_MASK_IOC ); 314 314 … … 319 319 _hba_active_cmd[cmd_id] = 1; 320 320 321 // deschedule t ask321 // deschedule thread 322 322 _ctx_switch(); 323 323 324 324 #if GIET_DEBUG_IOC 325 325 if (_get_proctime() > GIET_DEBUG_IOC) 326 _printf("\n[DEBUG HBA] _hba_access() : t ask%d on P[%d,%d,%d] resume at cycle %d\n",326 _printf("\n[DEBUG HBA] _hba_access() : thread %d on P[%d,%d,%d] resume at cycle %d\n", 327 327 ltid , x , y , p , _get_proctime() ); 328 328 #endif … … 438 438 _hba_active_cmd[cmd_id] = 0; 439 439 440 // identify waiting task 441 unsigned int procid = _hba_gtid[cmd_id]>>16; 442 unsigned int ltid = _hba_gtid[cmd_id] & 0xFFFF; 443 unsigned int cluster = procid >> P_WIDTH; 444 unsigned int x = cluster >> Y_WIDTH; 445 unsigned int y = cluster & ((1<<Y_WIDTH)-1); 446 unsigned int p = procid & ((1<<P_WIDTH)-1); 440 // identify waiting thread 441 unsigned int x = (_hba_trid[cmd_id]>>24) & 0xFF; 442 unsigned int y = (_hba_trid[cmd_id]>>16) & 0xFF; 443 unsigned int p = (_hba_trid[cmd_id]>> 8) & 0xFF; 444 unsigned int ltid = (_hba_trid[cmd_id] ) & 0xFF; 447 445 448 446 // Reset NORUN_MASK_IOC bit 449 447 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 450 _atomic_and( &psched->context[ltid] [CTX_NORUN_ID] , ~NORUN_MASK_IOC );451 452 // send a WAKUP WTI to processor running the waiting t ask453 _xcu_send_wti( cluster ,448 _atomic_and( &psched->context[ltid].slot[CTX_NORUN_ID] , ~NORUN_MASK_IOC ); 449 450 // send a WAKUP WTI to processor running the waiting thread 451 _xcu_send_wti( (x<<Y_WIDTH) + y, 454 452 p , 455 453 0 ); // don't force context switch … … 458 456 if (_get_proctime() > GIET_DEBUG_IOC) 459 457 _printf("\n[DEBUG HBA] _hba_isr() : command %d completed at cycle %d\n" 460 " resume t ask%d running on P[%d,%d,%d]\n",458 " resume thread %d running on P[%d,%d,%d]\n", 461 459 cmd_id , _get_proctime() , 462 460 ltid , x , y , p ); -
soft/giet_vm/giet_drivers/mwr_driver.c
r668 r709 74 74 unsigned int _coproc_error[X_SIZE*Y_SIZE]; 75 75 76 // descheduled t ask gtid (for MODE_DMA_IRQ)77 __attribute__((section(".kdata"))) 78 unsigned int _coproc_ gtid[X_SIZE*Y_SIZE];76 // descheduled thread trdid (for MODE_DMA_IRQ) 77 __attribute__((section(".kdata"))) 78 unsigned int _coproc_trdid[X_SIZE*Y_SIZE]; 79 79 80 80 ///////////////////////////////////////////////////////////////////////////// … … 205 205 _coproc_error[cluster_id] = error; 206 206 207 // identify task waiting on coprocessor completion 208 // this task can run in a remote cluster 209 unsigned int r_gtid = _coproc_gtid[cluster_id]; 210 unsigned int r_procid = r_gtid>>16; 211 unsigned int r_ltid = r_gtid & 0xFFFF; 212 unsigned int r_cluster = r_procid >> P_WIDTH; 213 unsigned int r_x = r_cluster >> Y_WIDTH; 214 unsigned int r_y = r_cluster & ((1<<Y_WIDTH)-1); 215 unsigned int r_p = r_procid & ((1<<P_WIDTH)-1); 207 // identify thread waiting on coprocessor completion (can run in a remote cluster) 208 unsigned int r_x = (_coproc_trdid[cluster_id]>>24) & 0xFF; 209 unsigned int r_y = (_coproc_trdid[cluster_id]>>16) & 0xFF; 210 unsigned int r_p = (_coproc_trdid[cluster_id]>> 8) & 0xFF; 211 unsigned int r_ltid = (_coproc_trdid[cluster_id] ) & 0xFF; 216 212 217 213 // Reset NORUN_MASK_IOC bit 218 214 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[r_x][r_y][r_p]; 219 unsigned int* ptr = &psched->context[r_ltid] [CTX_NORUN_ID];215 unsigned int* ptr = &psched->context[r_ltid].slot[CTX_NORUN_ID]; 220 216 _atomic_and( ptr , ~NORUN_MASK_COPROC ); 221 217 222 // send a WAKUP WTI to processor running the sleeping t ask223 _xcu_send_wti( r_cluster,218 // send a WAKUP WTI to processor running the sleeping thread 219 _xcu_send_wti( (r_x<<Y_WIDTH) + r_y, 224 220 r_p, 225 221 0 ); // don't force context switch … … 228 224 unsigned int p = gpid & ((1<<P_WIDTH)-1); 229 225 _printf("\n[GIET DEBUG COPROC] P[%d,%d,%d] executes _mwr_isr() at cycle %d\n" 230 " for t ask%d running on P[%d,%d,%d] / error = %d\n",226 " for thread %d running on P[%d,%d,%d] / error = %d\n", 231 227 x , y , p , _get_proctime() , r_ltid , r_x , r_y , r_p , error ); 232 228 #endif -
soft/giet_vm/giet_drivers/sdc_driver.c
r657 r709 32 32 /////////////////////////////////////////////////////////////////////////////////// 33 33 34 // global index ot the t ask, for each entry in the command list35 __attribute__((section(".kdata"))) 36 unsigned int _ahci_ gtid[32];34 // global index ot the thread, for each entry in the command list 35 __attribute__((section(".kdata"))) 36 unsigned int _ahci_trdid[32]; 37 37 38 38 // status of the command, for each entry in the command list … … 406 406 407 407 ///////////////////////////////////////////////////////////////// 408 // in descheduling mode, we deschedule the t ask409 // and use an interrupt to reschedule the t ask.408 // in descheduling mode, we deschedule the thread 409 // and use an interrupt to reschedule the thread. 410 410 // We need a critical section, because we must set the NORUN bit 411 411 // before to launch the transfer, and we don't want to be … … 422 422 #endif 423 423 unsigned int save_sr; 424 unsigned int ltid = _get_ current_task_id();424 unsigned int ltid = _get_thread_ltid(); 425 425 426 426 // activates interrupt 427 427 _sdc_set_register( AHCI_PXIE , 0x00000001 ); 428 428 429 // set _ahci_ gtid[ptw]430 _ahci_ gtid[ptw] = (procid<<16) + ltid;429 // set _ahci_trdid[ptw] 430 _ahci_trdid[ptw] = (x<<24) + (y<<16) + (p<<8) + ltid; 431 431 432 432 // enters critical section … … 435 435 // Set NORUN_MASK_IOC bit 436 436 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 437 unsigned int* ptr = &psched->context[ltid] [CTX_NORUN_ID];437 unsigned int* ptr = &psched->context[ltid].slot[CTX_NORUN_ID]; 438 438 _atomic_or( ptr , NORUN_MASK_IOC ); 439 439 … … 441 441 _sdc_set_register( AHCI_PXCI, (1<<ptw) ); 442 442 443 // deschedule t ask443 // deschedule thread 444 444 _ctx_switch(); 445 445 446 446 #if GIET_DEBUG_IOC 447 447 if (_get_proctime() > GIET_DEBUG_IOC) 448 _printf("\n[DEBUG SDC] _sdc_access() : t ask%d on P[%d,%d,%d] resume at cycle %d\n",448 _printf("\n[DEBUG SDC] _sdc_access() : thread %d on P[%d,%d,%d] resume at cycle %d\n", 449 449 ltid , x , y , p , _get_proctime() ); 450 450 #endif … … 497 497 _sdc_set_register( AHCI_PXIS , 0 ); 498 498 499 // identify waiting task 500 unsigned int procid = _ahci_gtid[cmd_id]>>16; 501 unsigned int ltid = _ahci_gtid[cmd_id] & 0xFFFF; 502 unsigned int cluster = procid >> P_WIDTH; 503 unsigned int x = cluster >> Y_WIDTH; 504 unsigned int y = cluster & ((1<<Y_WIDTH)-1); 505 unsigned int p = procid & ((1<<P_WIDTH)-1); 506 499 // identify waiting thread 500 unsigned int x = (_ahci_trdid[cmd_id]>>24) & 0xFF; 501 unsigned int y = (_ahci_trdid[cmd_id]>>16) & 0xFF; 502 unsigned int p = (_ahci_trdid[cmd_id]>> 8) & 0xFF; 503 unsigned int ltid = (_ahci_trdid[cmd_id] ) & 0xFF; 504 507 505 // Reset NORUN_MASK_IOC bit 508 506 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 509 _atomic_and( &psched->context[ltid] [CTX_NORUN_ID] , ~NORUN_MASK_IOC );510 511 // send a WAKUP WTI to processor running the waiting t ask512 _xcu_send_wti( cluster ,507 _atomic_and( &psched->context[ltid].slot[CTX_NORUN_ID] , ~NORUN_MASK_IOC ); 508 509 // send a WAKUP WTI to processor running the waiting thread 510 _xcu_send_wti( (x<<Y_WIDTH) + y, 513 511 p , 514 512 0 ); // don't force context switch … … 517 515 if (_get_proctime() > GIET_DEBUG_IOC) 518 516 _printf("\n[DEBUG SDC] _sdc_isr() : command %d completed at cycle %d\n" 519 " resume t ask%d running on P[%d,%d,%d] / status = %x\n",517 " resume thread %d running on P[%d,%d,%d] / status = %x\n", 520 518 cmd_id , _get_proctime() , 521 519 ltid , x , y , p , _ahci_status[cmd_id] ); -
soft/giet_vm/giet_drivers/tty_driver.c
r605 r709 19 19 20 20 //////////////////////////////////////////////////////////////////////////////////// 21 // extern variables 22 //////////////////////////////////////////////////////////////////////////////////// 23 24 // This variable is allocated in kernel_init.c file 25 extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; 26 27 //////////////////////////////////////////////////////////////////////////////////// 21 28 // global variables 22 29 //////////////////////////////////////////////////////////////////////////////////// 23 30 31 __attribute__((section(".kdata"))) 32 tty_fifo_t _tty_rx_fifo[NB_TTY_CHANNELS]; 33 34 /* 24 35 __attribute__((section(".kdata"))) 25 36 unsigned int _tty_rx_buf[NB_TTY_CHANNELS]; … … 27 38 __attribute__((section(".kdata"))) 28 39 unsigned int _tty_rx_full[NB_TTY_CHANNELS]; 40 41 __attribute__((section(".kdata"))) 42 unsigned int _tty_rx_trdid[NB_TTY_CHANNELS]; 43 */ 29 44 30 45 //////////////////////////////////////////////////////////////////////////////////// … … 52 67 void _tty_init( unsigned int channel ) 53 68 { 54 _tty_rx_full[channel] = 0; 69 _tty_rx_fifo[channel].sts = 0; 70 _tty_rx_fifo[channel].ptr = 0; 71 _tty_rx_fifo[channel].ptw = 0; 55 72 } 56 73 … … 60 77 unsigned int channel ) // TTY channel 61 78 { 62 // transfer character to kernel buffer and acknowledge TTY IRQ63 _tty_rx_buf[channel] = _tty_get_register( channel, TTY_READ );79 // get pointer on TTY_RX FIFO 80 tty_fifo_t* fifo = &_tty_rx_fifo[channel]; 64 81 65 // flush pending memory writes66 asm volatile( "sync" );82 // get character from TTY_RX channel and acknowledge IRQ 83 unsigned int data = _tty_get_register( channel, TTY_READ ); 67 84 68 // set kernel buffer status 69 _tty_rx_full[channel] = 1; 85 // transfer character to FIFO if not full 86 // discard incoming character if full 87 if ( fifo->sts < TTY_FIFO_DEPTH ) 88 { 89 // store data into FIFO 90 fifo->data[fifo->ptw] = (char)data; 70 91 71 #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlock 72 unsigned int gpid = _get_procid(); 73 unsigned int cluster_xy = gpid >> P_WIDTH; 74 unsigned int x = cluster_xy >> Y_WIDTH; 75 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 76 unsigned int lpid = gpid & ((1<<P_WIDTH)-1); 77 _puts("\n[IRQS DEBUG] Processor["); 78 _putd(x ); 79 _puts(","); 80 _putd(y ); 81 _puts(","); 82 _putd(lpid ); 83 _puts("] enters _tty_rx_isr() at cycle "); 84 _putd(_get_proctime() ); 85 _puts("\n read byte = "); 86 _putx(_tty_rx_buf[channel] ); 87 _puts("\n"); 88 #endif 92 // avoid race 93 asm volatile( "sync" ); 89 94 95 // update FIFO state 96 fifo->ptw = (fifo->ptw + 1) % TTY_FIFO_DEPTH; 97 fifo->sts = fifo->sts + 1; 98 } 99 100 // get owner thread indexes 101 unsigned int trdid = fifo->trdid; 102 unsigned int x = (trdid >> 24) & 0xFF; 103 unsigned int y = (trdid >> 16) & 0xFF; 104 unsigned int p = (trdid >> 8) & 0xFF; 105 unsigned int ltid = (trdid ) & 0xFF; 106 107 // Reset NORUN_MASK_TTY bit 108 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 109 unsigned int* ptr = &psched->context[ltid].slot[CTX_NORUN_ID]; 110 _atomic_and( ptr , ~NORUN_MASK_TTY ); 90 111 } 91 112 … … 95 116 unsigned int channel ) // TTY channel 96 117 { 97 _p uts("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n");118 _printf("\n[GIET ERROR] the _tty_tx_isr() is not implemented\n"); 98 119 _exit(); 99 120 } -
soft/giet_vm/giet_drivers/tty_driver.h
r496 r709 27 27 #include "kernel_locks.h" 28 28 29 29 30 /////////////////////////////////////////////////////////////////////////////////// 30 31 // registers offsets … … 41 42 }; 42 43 44 45 ////////////////////////////////////////////////////////////////////////////////// 46 // struct tty_fifo_t 47 ////////////////////////////////////////////////////////////////////////////////// 48 49 #define TTY_FIFO_DEPTH 16 50 51 typedef struct tty_fifo_s // 32 bytes 52 { 53 char data[TTY_FIFO_DEPTH]; // one char per slot 54 unsigned int trdid; // owner thread trdid 55 unsigned int ptr; // next free slot index 56 unsigned int ptw; // next full slot index 57 unsigned int sts; // number of full slots 58 } tty_fifo_t; 59 43 60 ////////////////////////////////////////////////////////////////////////////////// 44 61 // access functions
Note: See TracChangeset
for help on using the changeset viewer.