Changeset 625 for trunk/kernel/kern/chdev.c
- Timestamp:
- Apr 10, 2019, 10:09:39 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/chdev.c
r619 r625 138 138 uint32_t server_lid; // core running the server thread local index 139 139 xptr_t lock_xp; // extended pointer on lock protecting the chdev state 140 uint32_t save_sr; // for critical section141 140 142 141 #if (DEBUG_SYS_READ & 1) … … 177 176 uint32_t rx_cycle = (uint32_t)hal_get_cycles(); 178 177 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) 179 printk("\n[%s] client [%x,%x] enter for RX / server[%x,%x] / cycle %d\n",178 printk("\n[%s] client thread[%x,%x] enter for RX / server[%x,%x] / cycle %d\n", 180 179 __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, rx_cycle ); 181 180 #endif … … 184 183 uint32_t tx_cycle = (uint32_t)hal_get_cycles(); 185 184 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) 186 printk("\n[%s] client [%x,%x] enter for TX / server[%x,%x] / cycle %d\n",185 printk("\n[%s] client thread[%x,%x] enter for TX / server[%x,%x] / cycle %d\n", 187 186 __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, tx_cycle ); 188 187 #endif … … 194 193 xptr_t root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root ); 195 194 196 // build extended pointer on server thread blocked state197 xptr_t blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked );198 199 195 // build extended pointer on lock protecting chdev waiting queue 200 196 lock_xp = XPTR( chdev_cxy , &chdev_ptr->wait_lock ); 201 197 202 // TODO the hal_disable_irq() / hal_restore_irq() 203 // in the sequence below is probably useless, as it is 204 // already done by the busylock_acquire() / busylock_release() 205 // => remove it [AG] october 2018 206 207 // critical section for the following sequence: 198 // The following actions execute in critical section, 199 // because the lock_acquire / lock_release : 208 200 // (1) take the lock protecting the chdev state 209 // (2) block the client thread 210 // (3) unblock the server thread if required 211 // (4) register client thread in server queue 212 // (5) send IPI to force server scheduling 213 // (6) release the lock protecting waiting queue 214 // (7) deschedule 215 216 // enter critical section 217 hal_disable_irq( &save_sr ); 218 219 // take the lock protecting chdev queue 201 // (2) register client thread in server queue 202 // (3) unblock the server thread and block client thread 203 // (4) send IPI to force server scheduling 204 // (5) release the lock protecting waiting queue 205 206 // 1. take the lock protecting chdev queue 220 207 remote_busylock_acquire( lock_xp ); 221 208 222 // block current thread 223 thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO ); 224 225 #if (DEBUG_CHDEV_CMD_TX & 1) 226 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) 227 printk("\n[%s] client thread[%x,%x] blocked\n", 228 __FUNCTION__, this->process->pid, this->trdid ); 229 #endif 230 231 #if (DEBUG_CHDEV_CMD_RX & 1) 232 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) 233 printk("\n[%s] client thread[%x,%x] blocked\n", 234 __FUNCTION__, this->process_pid, this->trdid ); 235 #endif 236 237 // unblock server thread if required 238 if( hal_remote_l32( blocked_xp ) & THREAD_BLOCKED_IDLE ) 239 thread_unblock( server_xp , THREAD_BLOCKED_IDLE ); 240 241 #if (DEBUG_CHDEV_CMD_TX & 1) 242 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) 243 printk("\n[%s] TX server thread[%x,%x] unblocked\n", 244 __FUNCTION__, server_pid, server_trdid ); 245 #endif 246 247 #if (DEBUG_CHDEV_CMD_RX & 1) 248 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) 249 printk("\n[%s] RX server thread[%x,%x] unblocked\n", 250 __FUNCTION__, server_pid, server_trdid ); 251 #endif 252 253 // register client thread in waiting queue 209 // 2. register client thread in waiting queue 254 210 xlist_add_last( root_xp , list_xp ); 255 211 … … 266 222 #endif 267 223 268 // send IPI to core running the server thread when server core != client core 224 // 3. client thread unblocks server thread and blocks itself 225 thread_unblock( server_xp , THREAD_BLOCKED_IDLE ); 226 thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO ); 227 228 #if (DEBUG_CHDEV_CMD_TX & 1) 229 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) 230 printk("\n[%s] client thread[%x,%x] unblock server thread[%x,%x] and block itsef\n", 231 __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid ); 232 #endif 233 234 #if (DEBUG_CHDEV_CMD_RX & 1) 235 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) 236 printk("\n[%s] client thread[%x,%x] unblock server thread[%x,%x] and block itsef\n", 237 __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid ); 238 #endif 239 240 // 4. send IPI to core running the server thread when server core != client core 269 241 if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) ) 270 242 { … … 285 257 } 286 258 287 // release lock protecting chdev queue259 // 5. release lock protecting chdev queue 288 260 remote_busylock_release( lock_xp ); 289 261 290 262 // deschedule 291 263 sched_yield("blocked on I/O"); 292 293 // exit critical section294 hal_restore_irq( save_sr );295 264 296 265 #if DEBUG_CHDEV_CMD_RX 297 266 rx_cycle = (uint32_t)hal_get_cycles(); 298 267 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) 299 printk("\n[%s] client _thread[%x,%x] exit for RX / cycle %d\n",268 printk("\n[%s] client thread[%x,%x] exit for RX / cycle %d\n", 300 269 __FUNCTION__, this->process->pid, this->trdid, rx_cycle ); 301 270 #endif … … 304 273 tx_cycle = (uint32_t)hal_get_cycles(); 305 274 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) 306 printk("\n[%s] client _thread[%x,%x] exit for TX / cycle %d\n",275 printk("\n[%s] client thread[%x,%x] exit for TX / cycle %d\n", 307 276 __FUNCTION__, this->process->pid, this->trdid, tx_cycle ); 308 277 #endif … … 344 313 uint32_t rx_cycle = (uint32_t)hal_get_cycles(); 345 314 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 346 printk("\n[%s] DEVthread[%x,%x] check TXT_RX channel %d / cycle %d\n",315 printk("\n[%s] server thread[%x,%x] check TXT_RX channel %d / cycle %d\n", 347 316 __FUNCTION__ , server->process->pid, server->trdid, chdev->channel, rx_cycle ); 348 317 #endif … … 370 339 rx_cycle = (uint32_t)hal_get_cycles(); 371 340 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 372 printk("\n[%s] thread[%x,%x] found RX queue empty => blocks / cycle %d\n",341 printk("\n[%s] server thread[%x,%x] found RX queue empty => blocks / cycle %d\n", 373 342 __FUNCTION__ , server->process->pid, server->trdid, rx_cycle ); 374 343 #endif … … 377 346 tx_cycle = (uint32_t)hal_get_cycles(); 378 347 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 379 printk("\n[%s] thread[%x,%x] found TX queue empty => blocks / cycle %d\n",348 printk("\n[%s] server thread[%x,%x] found TX queue empty => blocks / cycle %d\n", 380 349 __FUNCTION__ , server->process->pid, server->trdid, tx_cycle ); 381 350 #endif … … 407 376 rx_cycle = (uint32_t)hal_get_cycles(); 408 377 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 409 printk("\n[%s] thread[%x,%x] for RX getclient thread[%x,%x] / cycle %d\n",378 printk("\n[%s] server thread[%x,%x] get command from client thread[%x,%x] / cycle %d\n", 410 379 __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle ); 411 380 #endif … … 414 383 tx_cycle = (uint32_t)hal_get_cycles(); 415 384 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 416 printk("\n[%s] thread[%x,%x] for TX getclient thread[%x,%x] / cycle %d\n",385 printk("\n[%s] server thread[%x,%x] get command from client thread[%x,%x] / cycle %d\n", 417 386 __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tx_cycle ); 418 387 #endif … … 445 414 rx_cycle = (uint32_t)hal_get_cycles(); 446 415 if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) 447 printk("\n[%s] thread[%x,%x] completes RXfor client thread[%x,%x] / cycle %d\n",416 printk("\n[%s] thread[%x,%x] completes command for client thread[%x,%x] / cycle %d\n", 448 417 __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle ); 449 418 #endif … … 452 421 tx_cycle = (uint32_t)hal_get_cycles(); 453 422 if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) 454 printk("\n[%s] thread[%x,%x] completes TXfor client thread[%x,%x] / cycle %d\n",423 printk("\n[%s] thread[%x,%x] completes command for client thread[%x,%x] / cycle %d\n", 455 424 __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tX_cycle ); 456 425 #endif
Note: See TracChangeset
for help on using the changeset viewer.