Changeset 709 for soft/giet_vm/giet_kernel/irq_handler.c
- Timestamp:
- Oct 1, 2015, 4:20:46 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/irq_handler.c
r702 r709 26 26 #include <tty0.h> 27 27 28 //////////////////////////////////////////////////////////////////////////// 29 // Extern variables 30 //////////////////////////////////////////////////////////////////////////// 31 32 // allocated in sys_handler.c file 33 extern unsigned int _tty_channel_wti[NB_TTY_CHANNELS]; 34 extern unsigned int _tim_channel_wti[NB_TIM_CHANNELS]; 35 extern unsigned int _cma_channel_wti[NB_CMA_CHANNELS]; 36 extern unsigned int _nic_rx_channel_wti[NB_NIC_CHANNELS]; 37 extern unsigned int _nic_tx_channel_wti[NB_NIC_CHANNELS]; 38 28 39 ///////////////////////////////////////////////////////////////////////// 29 40 // Global variables … … 41 52 __attribute__((section(".kdata"))) 42 53 unsigned char _wti_alloc_ter[X_SIZE][Y_SIZE][NB_PROCS_MAX]; 54 55 #define MAX_RETRY 10000 43 56 44 57 ///////////////////////////////////////////////////////////////////////// … … 134 147 } // end _ext_irq_init() 135 148 136 //////////////////////////////////////////// 149 ///////////////////////////////////////////// 137 150 void _ext_irq_alloc( unsigned int isr_type, 138 151 unsigned int isr_channel, … … 143 156 unsigned int wti_addr; // WTI mailbox physical address (32 lsb bits) 144 157 145 // check arguments 158 unsigned int count = MAX_RETRY; 159 160 // check input arguments 146 161 if ( isr_type >= GIET_ISR_TYPE_MAX ) 147 162 { … … 163 178 164 179 // allocate a WTI mailbox to proc[x,y,p] (blocking until success) 180 165 181 while ( 1 ) 166 182 { 183 if ( count == 0 ) 184 { 185 unsigned int trdid = _get_context_slot( CTX_TRDID_ID ); 186 unsigned int vsid = _get_context_slot( CTX_VSID_ID ); 187 _printf("\n[GIET WARNING] thread %x in vspace %d " 188 "running on P[%d,%d,%d] still waiting in _ext_irq_alloc()\n", 189 trdid, vsid, x, y, p ); 190 count = MAX_RETRY; 191 } 192 167 193 if ( _wti_alloc_one[x][y][p] == 0 ) 168 194 { … … 183 209 break; 184 210 } 211 count--; 185 212 } 213 186 214 *wti_index = wti_id; 187 215 … … 196 224 197 225 #if GIET_DEBUG_IRQS 226 if ( _get_proctime() > GIET_DEBUG_IRQS ) 198 227 _printf("\n[DEBUG IRQS] _ext_irq_alloc() for P[%d,%d,%d] at cycle %d\n" 199 228 " wti_id = %d / isr_type = %s / channel = %d / pic_input = %d\n", … … 204 233 } // end ext_irq_alloc() 205 234 206 //////////////////////////////////////////// 235 //////////////////////////////////////////////// 207 236 void _ext_irq_release( unsigned int isr_type, 208 unsigned int isr_channel ) 209 { 210 unsigned int wti_id; // allocated WTI mailbox index in XCU 211 unsigned int irq_id; // external IRQ index in PIC (input) 212 213 // get processor coordinates [x,y,p] 214 unsigned int gpid = _get_procid(); 215 unsigned int cluster_xy = gpid >> P_WIDTH; 216 unsigned int x = cluster_xy >> Y_WIDTH; 217 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 218 unsigned int p = gpid & ((1<<P_WIDTH)-1); 219 220 // check arguments 237 unsigned int channel ) 238 { 239 // check input arguments 221 240 if ( isr_type >= GIET_ISR_TYPE_MAX ) 222 241 { 223 _printf("\n[GIET ERROR] in _ext_irq_release() illegal ISR type\n"); 224 _exit(); 225 } 226 if ( isr_channel >= GIET_ISR_CHANNEL_MAX ) 227 { 228 _printf("\n[GIET ERROR] in _ext_irq_release() : illegal ISR channel\n"); 229 _exit(); 230 } 231 232 // find WTI index 233 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); 234 for ( wti_id = 0 ; wti_id < 32 ; wti_id++ ) 235 { 236 if ( psched->wti_vector[wti_id] == (isr_channel<<16 | isr_type) ) 237 break; 238 } 239 if ( wti_id == 32 ) 240 { 241 _printf("\n[GIET ERROR] in _ext_irq_release() : isr not found\n"); 242 return; 243 } 244 242 _printf("\n[GIET ERROR] in _ext_irq_release() : " 243 "illegal ISR type %d\n", isr_type ); 244 _exit(); 245 } 246 if ( channel >= GIET_ISR_CHANNEL_MAX ) 247 { 248 _printf("\n[GIET ERROR] in _ext_irq_release() : " 249 "illegal ISR channel %d\n", channel ); 250 _exit(); 251 } 252 253 // analyse ISR type to get WTI index (wti), and coordinates 254 // of processor (x,y,p) that has been allocated the external IRQ 255 unsigned int wti = 0; 256 unsigned int x = 0; 257 unsigned int y = 0; 258 unsigned int p = 0; 259 260 if ( (isr_type == ISR_TTY_RX) || (isr_type == ISR_TTY_TX) ) 261 { 262 x = (_tty_channel_wti[channel]>>24) & 0xFF; 263 y = (_tty_channel_wti[channel]>>16) & 0xFF; 264 p = (_tty_channel_wti[channel]>> 8) & 0xFF; 265 wti = (_tty_channel_wti[channel] ) & 0xFF; 266 } 267 #if NB_TIM_CHANNELS 268 else if ( isr_type == ISR_TIMER ) 269 { 270 x = (_tim_channel_wti[channel]>>24) & 0xFF; 271 y = (_tim_channel_wti[channel]>>16) & 0xFF; 272 p = (_tim_channel_wti[channel]>> 8) & 0xFF; 273 wti = (_tim_channel_wti[channel] ) & 0xFF; 274 } 275 #endif 276 #if NB_CMA_CHANNELS 277 else if ( isr_type == ISR_CMA ) 278 { 279 x = (_cma_channel_wti[channel]>>24) & 0xFF; 280 y = (_cma_channel_wti[channel]>>16) & 0xFF; 281 p = (_cma_channel_wti[channel]>> 8) & 0xFF; 282 wti = (_cma_channel_wti[channel] ) & 0xFF; 283 } 284 #endif 285 #if NB_NIC_CHANNELS 286 else if ( isr_type == ISR_NIC_RX ) 287 { 288 x = (_nic_rx_channel_wti[channel]>>24) & 0xFF; 289 y = (_nic_rx_channel_wti[channel]>>16) & 0xFF; 290 p = (_nic_rx_channel_wti[channel]>> 8) & 0xFF; 291 wti = (_nic_rx_channel_wti[channel] ) & 0xFF; 292 } 293 else if ( isr_type == ISR_NIC_TX ) 294 { 295 x = (_nic_tx_channel_wti[channel]>>24) & 0xFF; 296 y = (_nic_tx_channel_wti[channel]>>16) & 0xFF; 297 p = (_nic_tx_channel_wti[channel]>> 8) & 0xFF; 298 wti = (_nic_tx_channel_wti[channel] ) & 0xFF; 299 } 300 #endif 301 else 302 { 303 _printf("\n[GIET ERROR] in _ext_irq_release() : " 304 "ISR type %s not supported / thread = %x\n", 305 _isr_type_str[isr_type] , _get_thread_trdid() ); 306 _exit(); 307 } 308 245 309 // desactivates dynamically allocated PIC entry 246 irq_id = _ext_irq_index[isr_type][isr_channel];310 unsigned int irq_id = _ext_irq_index[isr_type][channel]; 247 311 _pic_set_register( irq_id , IOPIC_MASK , 0 ); 248 312 249 313 // releases dynamically allocated WTI mailbox 250 if ( wti _id== p + NB_PROCS_MAX ) _wti_alloc_one[x][y][p] = 0;251 else if ( wti _id== p + 2*NB_PROCS_MAX ) _wti_alloc_two[x][y][p] = 0;252 else if ( wti _id== p + 3*NB_PROCS_MAX ) _wti_alloc_ter[x][y][p] = 0;314 if ( wti == p + NB_PROCS_MAX ) _wti_alloc_one[x][y][p] = 0; 315 else if ( wti == p + 2*NB_PROCS_MAX ) _wti_alloc_two[x][y][p] = 0; 316 else if ( wti == p + 3*NB_PROCS_MAX ) _wti_alloc_ter[x][y][p] = 0; 253 317 else 254 318 { 255 _printf("\n[GIET ERROR] in _ext_irq_release() : illegal WTI index\n"); 319 _printf("\n[GIET ERROR] in _ext_irq_release() : " 320 "WTI = %d / X = %d / Y = %d / P = %d\n", wti , x, y , p ); 256 321 _exit(); 257 322 } … … 294 359 295 360 #if GIET_DEBUG_IRQS // we don't take the TTY lock to avoid deadlocks 361 if ( _get_proctime() > GIET_DEBUG_IRQS ) 296 362 _nolock_printf("\n[DEBUG IRQS] _irq_demux() Processor[%d,%d,%d] enters at cycle %d\n" 297 363 " irq_type = %s / irq_id = %d / isr_type = %s / channel = %d\n", … … 360 426 361 427 unsigned int value; // WTI mailbox value 362 unsigned int save_sr; // save SR value in pre-empted t askstack363 364 unsigned int ltid = _get_ current_task_id();428 unsigned int save_sr; // save SR value in pre-empted thread stack 429 430 unsigned int ltid = _get_thread_ltid(); 365 431 366 432 if ( irq_type != IRQ_TYPE_WTI ) … … 375 441 _xcu_get_wti_value( cluster_xy, irq_id, &value ); 376 442 377 #if GIET_DEBUG_SWITCH 378 _printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_wakup() at cycle %d\n" 443 #if GIET_DEBUG_IRQS 444 if ( _get_proctime() > GIET_DEBUG_IRQS ) 445 _printf("\n[DEBUG IRQS] P[%d,%d,%d] enters _isr_wakup() at cycle %d\n" 379 446 " WTI index = %d / current ltid = %d / mailbox value = %x\n", 380 447 x , y , p , _get_proctime() , irq_id , ltid , value ); … … 382 449 383 450 // enter critical section and swich context (if required) 384 if ( (ltid == IDLE_T ASK_INDEX) || (value != 0) )451 if ( (ltid == IDLE_THREAD_INDEX) || (value != 0) ) 385 452 { 386 453 _it_disable( &save_sr ); … … 402 469 unsigned int p = gpid & ((1<<P_WIDTH)-1); 403 470 404 unsigned int save_sr; // save SR value in pre-empted t askstack471 unsigned int save_sr; // save SR value in pre-empted thread stack 405 472 406 473 if ( irq_type != IRQ_TYPE_PTI ) … … 415 482 _xcu_timer_reset_irq( cluster_xy, irq_id ); 416 483 417 #if (GIET_DEBUG_SWITCH & 0x1)418 unsigned int ltid = _get_ current_task_id();419 if ( _get_proctime() > GIET_DEBUG_ SWITCH)420 _printf("\n[DEBUG SWITCH] P[%d,%d,%d] enters _isr_tick() at cycle %d\n"484 #if GIET_DEBUG_IRQS 485 unsigned int ltid = _get_thread_ltid(); 486 if ( _get_proctime() > GIET_DEBUG_IRQS ) 487 _printf("\n[DEBUG IRQS] P[%d,%d,%d] enters _isr_tick() at cycle %d\n" 421 488 " WTI index = %d / current ltid = %d\n", 422 489 x , y , p , _get_proctime() , irq_id , ltid );
Note: See TracChangeset
for help on using the changeset viewer.