[5] | 1 | /* |
---|
| 2 | * chdev.c - channel device descriptor operations implementation. |
---|
| 3 | * |
---|
| 4 | * Authors Alain Greiner (2016) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH.is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH.is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH.; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[14] | 24 | #include <kernel_config.h> |
---|
[457] | 25 | #include <hal_kernel_types.h> |
---|
[5] | 26 | #include <hal_special.h> |
---|
[447] | 27 | #include <hal_remote.h> |
---|
[407] | 28 | #include <hal_irqmask.h> |
---|
[16] | 29 | #include <printk.h> |
---|
[5] | 30 | #include <boot_info.h> |
---|
| 31 | #include <xlist.h> |
---|
| 32 | #include <kmem.h> |
---|
[407] | 33 | #include <scheduler.h> |
---|
[5] | 34 | #include <thread.h> |
---|
| 35 | #include <rpc.h> |
---|
| 36 | #include <chdev.h> |
---|
[23] | 37 | #include <devfs.h> |
---|
[5] | 38 | |
---|
[564] | 39 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
| 40 | // Extern global variables |
---|
| 41 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
[317] | 42 | |
---|
[564] | 43 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
[317] | 44 | |
---|
[564] | 45 | |
---|
[438] | 46 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 47 | extern uint32_t enter_chdev_cmd_read; |
---|
| 48 | extern uint32_t exit_chdev_cmd_read; |
---|
| 49 | extern uint32_t enter_chdev_server_read; |
---|
| 50 | extern uint32_t exit_chdev_server_read; |
---|
[407] | 51 | #endif |
---|
[317] | 52 | |
---|
[438] | 53 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 54 | extern uint32_t enter_chdev_cmd_write; |
---|
| 55 | extern uint32_t exit_chdev_cmd_write; |
---|
| 56 | extern uint32_t enter_chdev_server_write; |
---|
| 57 | extern uint32_t exit_chdev_server_write; |
---|
| 58 | #endif |
---|
| 59 | |
---|
[5] | 60 | //////////////////////////////////////////// |
---|
| 61 | char * chdev_func_str( uint32_t func_type ) |
---|
| 62 | { |
---|
[564] | 63 | switch ( func_type ) |
---|
| 64 | { |
---|
[583] | 65 | case DEV_FUNC_RAM: return "RAM"; |
---|
| 66 | case DEV_FUNC_ROM: return "ROM"; |
---|
| 67 | case DEV_FUNC_FBF: return "FBF"; |
---|
| 68 | case DEV_FUNC_IOB: return "IOB"; |
---|
| 69 | case DEV_FUNC_IOC: return "IOC"; |
---|
| 70 | case DEV_FUNC_MMC: return "MMC"; |
---|
| 71 | case DEV_FUNC_DMA: return "DMA"; |
---|
| 72 | case DEV_FUNC_NIC: return "NIC"; |
---|
| 73 | case DEV_FUNC_TIM: return "TIM"; |
---|
| 74 | case DEV_FUNC_TXT: return "TXT"; |
---|
| 75 | case DEV_FUNC_ICU: return "ICU"; |
---|
| 76 | case DEV_FUNC_PIC: return "PIC"; |
---|
| 77 | default: return "undefined"; |
---|
[527] | 78 | } |
---|
[5] | 79 | } |
---|
| 80 | |
---|
| 81 | ///////////////////////////////////////// |
---|
| 82 | chdev_t * chdev_create( uint32_t func, |
---|
| 83 | uint32_t impl, |
---|
| 84 | uint32_t channel, |
---|
| 85 | uint32_t is_rx, |
---|
| 86 | xptr_t base ) |
---|
| 87 | { |
---|
| 88 | chdev_t * chdev; |
---|
| 89 | kmem_req_t req; |
---|
| 90 | |
---|
| 91 | // allocate memory for chdev |
---|
| 92 | req.type = KMEM_DEVICE; |
---|
| 93 | req.flags = AF_ZERO; |
---|
| 94 | chdev = (chdev_t *)kmem_alloc( &req ); |
---|
| 95 | |
---|
| 96 | if( chdev == NULL ) return NULL; |
---|
| 97 | |
---|
[564] | 98 | // initialize lock |
---|
| 99 | remote_busylock_init( XPTR( local_cxy , &chdev->wait_lock ), LOCK_CHDEV_QUEUE ); |
---|
| 100 | |
---|
| 101 | // initialise waiting queue |
---|
[5] | 102 | xlist_root_init( XPTR( local_cxy , &chdev->wait_root ) ); |
---|
| 103 | |
---|
| 104 | // initialize attributes |
---|
| 105 | chdev->func = func; |
---|
| 106 | chdev->impl = impl; |
---|
| 107 | chdev->channel = channel; |
---|
| 108 | chdev->is_rx = is_rx; |
---|
| 109 | chdev->base = base; |
---|
| 110 | |
---|
| 111 | return chdev; |
---|
| 112 | |
---|
| 113 | } // end chdev_create() |
---|
| 114 | |
---|
| 115 | /////////////////////////////////// |
---|
| 116 | void chdev_print( chdev_t * chdev ) |
---|
| 117 | { |
---|
| 118 | printk("\n - func = %s" |
---|
| 119 | "\n - channel = %d" |
---|
| 120 | "\n - base = %l" |
---|
| 121 | "\n - cmd = %x" |
---|
| 122 | "\n - isr = %x" |
---|
| 123 | "\n - chdev = %x\n", |
---|
| 124 | chdev_func_str(chdev->func), |
---|
| 125 | chdev->channel, |
---|
| 126 | chdev->base, |
---|
| 127 | chdev->cmd, |
---|
| 128 | chdev->isr, |
---|
| 129 | chdev ); |
---|
| 130 | } |
---|
| 131 | |
---|
[407] | 132 | ////////////////////////////////////////////////// |
---|
| 133 | void chdev_register_command( xptr_t chdev_xp ) |
---|
[5] | 134 | { |
---|
[407] | 135 | thread_t * server_ptr; // local pointer on server thread associated to chdev |
---|
[440] | 136 | xptr_t server_xp; // extended pointer on server thread |
---|
[407] | 137 | core_t * core_ptr; // local pointer on core running the server thread |
---|
[457] | 138 | uint32_t server_lid; // core running the server thread local index |
---|
[564] | 139 | xptr_t lock_xp; // extended pointer on lock protecting the chdev state |
---|
[407] | 140 | uint32_t save_sr; // for critical section |
---|
[5] | 141 | |
---|
[438] | 142 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 143 | enter_chdev_cmd_read = (uint32_t)hal_get_cycles(); |
---|
[418] | 144 | #endif |
---|
| 145 | |
---|
[438] | 146 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 147 | enter_chdev_cmd_write = (uint32_t)hal_get_cycles(); |
---|
| 148 | #endif |
---|
| 149 | |
---|
[407] | 150 | thread_t * this = CURRENT_THREAD; |
---|
| 151 | |
---|
[440] | 152 | // get chdev cluster and local pointer |
---|
[5] | 153 | cxy_t chdev_cxy = GET_CXY( chdev_xp ); |
---|
[440] | 154 | chdev_t * chdev_ptr = GET_PTR( chdev_xp ); |
---|
[5] | 155 | |
---|
[581] | 156 | // check calling thread can yield |
---|
| 157 | thread_assert_can_yield( this , __FUNCTION__ ); |
---|
[564] | 158 | |
---|
[440] | 159 | // get local and extended pointers on server thread |
---|
| 160 | server_ptr = (thread_t *)hal_remote_lpt( XPTR( chdev_cxy , &chdev_ptr->server) ); |
---|
| 161 | server_xp = XPTR( chdev_cxy , server_ptr ); |
---|
| 162 | |
---|
| 163 | // get local pointer on core running the server thread |
---|
| 164 | core_ptr = (core_t *)hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->core ) ); |
---|
| 165 | |
---|
| 166 | // get server core local index |
---|
[564] | 167 | server_lid = hal_remote_l32( XPTR( chdev_cxy , &core_ptr->lid ) ); |
---|
[440] | 168 | |
---|
[438] | 169 | #if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX) |
---|
[619] | 170 | bool_t is_rx = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->is_rx ) ); |
---|
| 171 | trdid_t server_trdid = hal_remote_l32( XPTR( chdev_cxy , &server_ptr->trdid ) ); |
---|
| 172 | process_t * process_ptr = hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->process ) ); |
---|
| 173 | pid_t server_pid = hal_remote_l32( XPTR( chdev_cxy , &process_ptr->pid ) ); |
---|
[437] | 174 | #endif |
---|
| 175 | |
---|
[438] | 176 | #if DEBUG_CHDEV_CMD_RX |
---|
[437] | 177 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 178 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
[593] | 179 | printk("\n[%s] client[%x,%x] enter for RX / server[%x,%x] / cycle %d\n", |
---|
[619] | 180 | __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, rx_cycle ); |
---|
[437] | 181 | #endif |
---|
| 182 | |
---|
[438] | 183 | #if DEBUG_CHDEV_CMD_TX |
---|
[437] | 184 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 185 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
[593] | 186 | printk("\n[%s] client[%x,%x] enter for TX / server[%x,%x] / cycle %d\n", |
---|
[619] | 187 | __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, tx_cycle ); |
---|
[437] | 188 | #endif |
---|
| 189 | |
---|
[440] | 190 | // build extended pointer on client thread xlist |
---|
| 191 | xptr_t list_xp = XPTR( local_cxy , &this->wait_list ); |
---|
[5] | 192 | |
---|
[440] | 193 | // build extended pointer on chdev waiting queue root |
---|
| 194 | xptr_t root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root ); |
---|
[5] | 195 | |
---|
[440] | 196 | // build extended pointer on server thread blocked state |
---|
| 197 | xptr_t blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked ); |
---|
| 198 | |
---|
| 199 | // build extended pointer on lock protecting chdev waiting queue |
---|
[564] | 200 | lock_xp = XPTR( chdev_cxy , &chdev_ptr->wait_lock ); |
---|
[407] | 201 | |
---|
[581] | 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 | |
---|
[450] | 207 | // critical section for the following sequence: |
---|
[564] | 208 | // (1) take the lock protecting the chdev state |
---|
[440] | 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 |
---|
[407] | 215 | |
---|
[440] | 216 | // enter critical section |
---|
| 217 | hal_disable_irq( &save_sr ); |
---|
[407] | 218 | |
---|
[564] | 219 | // take the lock protecting chdev queue |
---|
| 220 | remote_busylock_acquire( lock_xp ); |
---|
[408] | 221 | |
---|
| 222 | // block current thread |
---|
[436] | 223 | thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO ); |
---|
[408] | 224 | |
---|
[450] | 225 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
| 226 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
[593] | 227 | printk("\n[%s] client thread[%x,%x] blocked\n", |
---|
[601] | 228 | __FUNCTION__, this->process->pid, this->trdid ); |
---|
[450] | 229 | #endif |
---|
| 230 | |
---|
[457] | 231 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
| 232 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
[593] | 233 | printk("\n[%s] client thread[%x,%x] blocked\n", |
---|
| 234 | __FUNCTION__, this->process_pid, this->trdid ); |
---|
[457] | 235 | #endif |
---|
| 236 | |
---|
[446] | 237 | // unblock server thread if required |
---|
[564] | 238 | if( hal_remote_l32( blocked_xp ) & THREAD_BLOCKED_IDLE ) |
---|
[440] | 239 | thread_unblock( server_xp , THREAD_BLOCKED_IDLE ); |
---|
| 240 | |
---|
[450] | 241 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
| 242 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
[593] | 243 | printk("\n[%s] TX server thread[%x,%x] unblocked\n", |
---|
[619] | 244 | __FUNCTION__, server_pid, server_trdid ); |
---|
[450] | 245 | #endif |
---|
| 246 | |
---|
[457] | 247 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
| 248 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
[593] | 249 | printk("\n[%s] RX server thread[%x,%x] unblocked\n", |
---|
[619] | 250 | __FUNCTION__, server_pid, server_trdid ); |
---|
[457] | 251 | #endif |
---|
| 252 | |
---|
[5] | 253 | // register client thread in waiting queue |
---|
[407] | 254 | xlist_add_last( root_xp , list_xp ); |
---|
[5] | 255 | |
---|
[450] | 256 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
| 257 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
[593] | 258 | printk("\n[%s] client thread[%x,%x] registered write request in chdev\n", |
---|
| 259 | __FUNCTION__, this->process->pid, this->trdid ); |
---|
[450] | 260 | #endif |
---|
| 261 | |
---|
[457] | 262 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
| 263 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
[593] | 264 | printk("\n[%s] client thread[%x,%x] registered read request in chdev\n", |
---|
| 265 | __FUNCTION__, this->process->pid, this->trdid ); |
---|
[457] | 266 | #endif |
---|
| 267 | |
---|
[564] | 268 | // send IPI to core running the server thread when server core != client core |
---|
[457] | 269 | if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) ) |
---|
[450] | 270 | { |
---|
[457] | 271 | dev_pic_send_ipi( chdev_cxy , server_lid ); |
---|
| 272 | |
---|
[450] | 273 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
| 274 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
[593] | 275 | printk("\n[%s] client thread[%x,%x] sent IPI to TX server thread[%x,%x]\n", |
---|
[619] | 276 | __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid ); |
---|
[450] | 277 | #endif |
---|
| 278 | |
---|
[457] | 279 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
| 280 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
[593] | 281 | printk("\n[%s] client thread[%x,%x] sent IPI to RX server thread[%x,%x]\n", |
---|
[619] | 282 | __FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid ); |
---|
[457] | 283 | #endif |
---|
| 284 | |
---|
[450] | 285 | } |
---|
| 286 | |
---|
[564] | 287 | // release lock protecting chdev queue |
---|
| 288 | remote_busylock_release( lock_xp ); |
---|
[440] | 289 | |
---|
[408] | 290 | // deschedule |
---|
| 291 | sched_yield("blocked on I/O"); |
---|
[407] | 292 | |
---|
| 293 | // exit critical section |
---|
| 294 | hal_restore_irq( save_sr ); |
---|
| 295 | |
---|
[438] | 296 | #if DEBUG_CHDEV_CMD_RX |
---|
[437] | 297 | rx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 298 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
[593] | 299 | printk("\n[%s] client_thread[%x,%x] exit for RX / cycle %d\n", |
---|
| 300 | __FUNCTION__, this->process->pid, this->trdid, rx_cycle ); |
---|
[433] | 301 | #endif |
---|
| 302 | |
---|
[438] | 303 | #if DEBUG_CHDEV_CMD_TX |
---|
[437] | 304 | tx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 305 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
[593] | 306 | printk("\n[%s] client_thread[%x,%x] exit for TX / cycle %d\n", |
---|
| 307 | __FUNCTION__, this->process->pid, this->trdid, tx_cycle ); |
---|
[437] | 308 | #endif |
---|
| 309 | |
---|
[438] | 310 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 311 | exit_chdev_cmd_read = (uint32_t)hal_get_cycles(); |
---|
[418] | 312 | #endif |
---|
| 313 | |
---|
[438] | 314 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 315 | exit_chdev_cmd_write = (uint32_t)hal_get_cycles(); |
---|
| 316 | #endif |
---|
| 317 | |
---|
[5] | 318 | } // end chdev_register_command() |
---|
| 319 | |
---|
[619] | 320 | ///////////////////////////////////////// |
---|
| 321 | void chdev_server_func( chdev_t * chdev ) |
---|
[5] | 322 | { |
---|
| 323 | xptr_t client_xp; // extended pointer on waiting thread |
---|
| 324 | cxy_t client_cxy; // cluster of client thread |
---|
| 325 | thread_t * client_ptr; // local pointer on client thread |
---|
[407] | 326 | thread_t * server; // local pointer on server thread |
---|
[5] | 327 | xptr_t root_xp; // extended pointer on device waiting queue root |
---|
[407] | 328 | xptr_t lock_xp; // extended pointer on lock ptotecting chdev queue |
---|
[5] | 329 | |
---|
| 330 | server = CURRENT_THREAD; |
---|
| 331 | |
---|
[564] | 332 | // build extended pointer on root of client threads queue |
---|
[5] | 333 | root_xp = XPTR( local_cxy , &chdev->wait_root ); |
---|
[564] | 334 | |
---|
| 335 | // build extended pointer on lock protecting client threads queue |
---|
[407] | 336 | lock_xp = XPTR( local_cxy , &chdev->wait_lock ); |
---|
[5] | 337 | |
---|
[407] | 338 | // This infinite loop is executed by the DEV thread |
---|
| 339 | // to handle commands registered in the chdev queue. |
---|
[5] | 340 | while( 1 ) |
---|
| 341 | { |
---|
[564] | 342 | |
---|
[619] | 343 | #if( DEBUG_CHDEV_SERVER_RX || DEBUG_CHDEV_SERVER_TX ) |
---|
[564] | 344 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
| 345 | if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) |
---|
[619] | 346 | printk("\n[%s] DEV thread[%x,%x] check TXT_RX channel %d / cycle %d\n", |
---|
| 347 | __FUNCTION__ , server->process->pid, server->trdid, chdev->channel, rx_cycle ); |
---|
[564] | 348 | #endif |
---|
| 349 | |
---|
| 350 | #if DEBUG_CHDEV_SERVER_TX |
---|
| 351 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
| 352 | if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) |
---|
[619] | 353 | printk("\n[%s] thread[%x,%x] check TXT_TX channel %d / cycle %d\n", |
---|
| 354 | __FUNCTION__ , server->process->pid, server->trdid, chdev->channel, tx_cycle ); |
---|
[564] | 355 | #endif |
---|
| 356 | |
---|
[601] | 357 | // check server thread can yield |
---|
| 358 | thread_assert_can_yield( server , __FUNCTION__ ); |
---|
| 359 | |
---|
[407] | 360 | // get the lock protecting the waiting queue |
---|
[564] | 361 | remote_busylock_acquire( lock_xp ); |
---|
[407] | 362 | |
---|
[5] | 363 | // check waiting queue state |
---|
[407] | 364 | if( xlist_is_empty( root_xp ) ) // waiting queue empty |
---|
[5] | 365 | { |
---|
[601] | 366 | // release lock protecting the waiting queue |
---|
| 367 | remote_busylock_release( lock_xp ); |
---|
[564] | 368 | |
---|
| 369 | #if DEBUG_CHDEV_SERVER_RX |
---|
| 370 | rx_cycle = (uint32_t)hal_get_cycles(); |
---|
| 371 | if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) |
---|
[601] | 372 | printk("\n[%s] thread[%x,%x] found RX queue empty => blocks / cycle %d\n", |
---|
[593] | 373 | __FUNCTION__ , server->process->pid, server->trdid, rx_cycle ); |
---|
[564] | 374 | #endif |
---|
| 375 | |
---|
| 376 | #if DEBUG_CHDEV_SERVER_TX |
---|
| 377 | tx_cycle = (uint32_t)hal_get_cycles(); |
---|
| 378 | if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) |
---|
[601] | 379 | printk("\n[%s] thread[%x,%x] found TX queue empty => blocks / cycle %d\n", |
---|
[593] | 380 | __FUNCTION__ , server->process->pid, server->trdid, tx_cycle ); |
---|
[564] | 381 | #endif |
---|
[440] | 382 | // block |
---|
| 383 | thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_IDLE ); |
---|
| 384 | |
---|
[408] | 385 | // deschedule |
---|
| 386 | sched_yield("I/O queue empty"); |
---|
[5] | 387 | } |
---|
[407] | 388 | else // waiting queue not empty |
---|
[5] | 389 | { |
---|
[601] | 390 | // release lock protecting the waiting queue |
---|
| 391 | remote_busylock_release( lock_xp ); |
---|
| 392 | |
---|
[407] | 393 | // get extended pointer on first client thread |
---|
[564] | 394 | client_xp = XLIST_FIRST( root_xp , thread_t , wait_list ); |
---|
[5] | 395 | |
---|
[440] | 396 | // get client thread cluster and local pointer |
---|
[407] | 397 | client_cxy = GET_CXY( client_xp ); |
---|
[440] | 398 | client_ptr = GET_PTR( client_xp ); |
---|
[407] | 399 | |
---|
[619] | 400 | #if( DEBUG_CHDEV_SERVER_TX || DEBUG_CHDEV_SERVER_RX ) |
---|
[601] | 401 | process_t * process = hal_remote_lpt( XPTR( client_cxy , &client_ptr->process ) ); |
---|
| 402 | pid_t client_pid = hal_remote_l32( XPTR( client_cxy , &process->pid ) ); |
---|
[619] | 403 | trdid_t client_trdid = hal_remote_l32( XPTR( client_cxy , &client_ptr->trdid ) ); |
---|
[601] | 404 | #endif |
---|
[440] | 405 | |
---|
[438] | 406 | #if DEBUG_CHDEV_SERVER_RX |
---|
[564] | 407 | rx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 408 | if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) |
---|
[601] | 409 | printk("\n[%s] thread[%x,%x] for RX get client thread[%x,%x] / cycle %d\n", |
---|
[619] | 410 | __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle ); |
---|
[437] | 411 | #endif |
---|
| 412 | |
---|
[438] | 413 | #if DEBUG_CHDEV_SERVER_TX |
---|
[564] | 414 | tx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 415 | if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) |
---|
[601] | 416 | printk("\n[%s] thread[%x,%x] for TX get client thread[%x,%x] / cycle %d\n", |
---|
[619] | 417 | __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tx_cycle ); |
---|
[437] | 418 | #endif |
---|
| 419 | |
---|
[438] | 420 | #if (DEBUG_SYS_READ & 1) |
---|
[437] | 421 | enter_chdev_server_read = (uint32_t)hal_get_cycles(); |
---|
| 422 | #endif |
---|
| 423 | |
---|
[438] | 424 | #if (DEBUG_SYS_WRITE & 1) |
---|
[437] | 425 | enter_chdev_server_write = (uint32_t)hal_get_cycles(); |
---|
| 426 | #endif |
---|
| 427 | |
---|
[601] | 428 | // call the (blocking) driver command function |
---|
| 429 | // to launch I/O operation AND wait completion |
---|
[407] | 430 | chdev->cmd( client_xp ); |
---|
[5] | 431 | |
---|
[601] | 432 | // unblock client thread when driver returns |
---|
[418] | 433 | thread_unblock( client_xp , THREAD_BLOCKED_IO ); |
---|
| 434 | |
---|
[601] | 435 | // get the lock protecting the waiting queue |
---|
| 436 | remote_busylock_acquire( lock_xp ); |
---|
| 437 | |
---|
| 438 | // remove this client thread from chdev waiting queue |
---|
| 439 | xlist_unlink( XPTR( client_cxy , &client_ptr->wait_list ) ); |
---|
| 440 | |
---|
| 441 | // release lock protecting the waiting queue |
---|
| 442 | remote_busylock_release( lock_xp ); |
---|
| 443 | |
---|
[438] | 444 | #if DEBUG_CHDEV_SERVER_RX |
---|
[437] | 445 | rx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 446 | if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) |
---|
[601] | 447 | printk("\n[%s] thread[%x,%x] completes RX for client thread[%x,%x] / cycle %d\n", |
---|
[619] | 448 | __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle ); |
---|
[433] | 449 | #endif |
---|
[5] | 450 | |
---|
[438] | 451 | #if DEBUG_CHDEV_SERVER_TX |
---|
[437] | 452 | tx_cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 453 | if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) |
---|
[601] | 454 | printk("\n[%s] thread[%x,%x] completes TX for client thread[%x,%x] / cycle %d\n", |
---|
[619] | 455 | __FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tX_cycle ); |
---|
[437] | 456 | #endif |
---|
| 457 | |
---|
[438] | 458 | #if (DEBUG_SYS_READ & 1) |
---|
[435] | 459 | exit_chdev_server_read = (uint32_t)hal_get_cycles(); |
---|
[407] | 460 | #endif |
---|
| 461 | |
---|
[438] | 462 | #if (DEBUG_SYS_WRITE & 1) |
---|
[435] | 463 | exit_chdev_server_write = (uint32_t)hal_get_cycles(); |
---|
| 464 | #endif |
---|
| 465 | |
---|
[407] | 466 | } |
---|
[5] | 467 | } // end while |
---|
[619] | 468 | } // end chdev_server_func() |
---|
[5] | 469 | |
---|
[428] | 470 | //////////////////////////////////////// |
---|
| 471 | xptr_t chdev_from_file( xptr_t file_xp ) |
---|
| 472 | { |
---|
| 473 | cxy_t file_cxy; |
---|
| 474 | vfs_file_t * file_ptr; |
---|
| 475 | uint32_t inode_type; |
---|
| 476 | vfs_inode_t * inode_ptr; |
---|
| 477 | chdev_t * chdev_ptr; |
---|
| 478 | |
---|
[492] | 479 | assert( (file_xp != XPTR_NULL) , |
---|
[440] | 480 | "file_xp == XPTR_NULL\n" ); |
---|
| 481 | |
---|
[428] | 482 | // get cluster and local pointer on remote file descriptor |
---|
| 483 | // associated inode and chdev are stored in same cluster as the file desc. |
---|
| 484 | file_cxy = GET_CXY( file_xp ); |
---|
| 485 | file_ptr = (vfs_file_t *)GET_PTR( file_xp ); |
---|
| 486 | |
---|
| 487 | // get inode type from file descriptor |
---|
[564] | 488 | inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); |
---|
[428] | 489 | inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); |
---|
| 490 | |
---|
[492] | 491 | assert( (inode_type == INODE_TYPE_DEV) , |
---|
[440] | 492 | "inode type %d is not INODE_TYPE_DEV\n", inode_type ); |
---|
[428] | 493 | |
---|
| 494 | // get chdev local pointer from inode extension |
---|
| 495 | chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) ); |
---|
| 496 | |
---|
| 497 | return XPTR( file_cxy , chdev_ptr ); |
---|
| 498 | |
---|
| 499 | } // end chdev_from_file() |
---|
| 500 | |
---|
[564] | 501 | ////////////////////////////// |
---|
[485] | 502 | void chdev_dir_display( void ) |
---|
[317] | 503 | { |
---|
[428] | 504 | uint32_t i; |
---|
| 505 | cxy_t cxy; |
---|
| 506 | chdev_t * ptr; |
---|
| 507 | uint32_t base; |
---|
[317] | 508 | |
---|
[428] | 509 | // get pointers on TXT0 chdev |
---|
| 510 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
| 511 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 512 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
[317] | 513 | |
---|
[564] | 514 | // get extended pointer on TXT0 lock |
---|
[428] | 515 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
[317] | 516 | |
---|
[564] | 517 | // get TXT0 lock |
---|
| 518 | remote_busylock_acquire( lock_xp ); |
---|
[317] | 519 | |
---|
[428] | 520 | // header |
---|
| 521 | nolock_printk("\n***** external chdevs directory *****\n"); |
---|
[317] | 522 | |
---|
[428] | 523 | // IOB |
---|
[564] | 524 | if (chdev_dir.iob != XPTR_NULL ) |
---|
[545] | 525 | { |
---|
| 526 | cxy = GET_CXY( chdev_dir.iob ); |
---|
| 527 | ptr = GET_PTR( chdev_dir.iob ); |
---|
[564] | 528 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[545] | 529 | nolock_printk(" - iob : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base); |
---|
| 530 | } |
---|
[407] | 531 | |
---|
[428] | 532 | // PIC |
---|
| 533 | cxy = GET_CXY( chdev_dir.pic ); |
---|
| 534 | ptr = GET_PTR( chdev_dir.pic ); |
---|
[564] | 535 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 536 | nolock_printk(" - pic : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base); |
---|
[407] | 537 | |
---|
[428] | 538 | // TXT |
---|
| 539 | for( i = 0 ; i < LOCAL_CLUSTER->nb_txt_channels ; i++ ) |
---|
| 540 | { |
---|
| 541 | cxy = GET_CXY( chdev_dir.txt_rx[i] ); |
---|
| 542 | ptr = GET_PTR( chdev_dir.txt_rx[i] ); |
---|
[564] | 543 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 544 | nolock_printk(" - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
[407] | 545 | |
---|
[428] | 546 | cxy = GET_CXY( chdev_dir.txt_tx[i] ); |
---|
| 547 | ptr = GET_PTR( chdev_dir.txt_tx[i] ); |
---|
[564] | 548 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 549 | nolock_printk(" - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
| 550 | } |
---|
[317] | 551 | |
---|
[428] | 552 | // IOC |
---|
| 553 | for( i = 0 ; i < LOCAL_CLUSTER->nb_ioc_channels ; i++ ) |
---|
| 554 | { |
---|
| 555 | cxy = GET_CXY( chdev_dir.ioc[i] ); |
---|
| 556 | ptr = GET_PTR( chdev_dir.ioc[i] ); |
---|
[564] | 557 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 558 | nolock_printk(" - ioc[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
| 559 | } |
---|
[317] | 560 | |
---|
[428] | 561 | // FBF |
---|
| 562 | for( i = 0 ; i < LOCAL_CLUSTER->nb_fbf_channels ; i++ ) |
---|
| 563 | { |
---|
| 564 | cxy = GET_CXY( chdev_dir.fbf[i] ); |
---|
| 565 | ptr = GET_PTR( chdev_dir.fbf[i] ); |
---|
[564] | 566 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 567 | nolock_printk(" - fbf[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
| 568 | } |
---|
[317] | 569 | |
---|
[428] | 570 | // NIC |
---|
| 571 | for( i = 0 ; i < LOCAL_CLUSTER->nb_nic_channels ; i++ ) |
---|
| 572 | { |
---|
| 573 | cxy = GET_CXY( chdev_dir.nic_rx[i] ); |
---|
| 574 | ptr = GET_PTR( chdev_dir.nic_rx[i] ); |
---|
[564] | 575 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 576 | nolock_printk(" - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
[317] | 577 | |
---|
[428] | 578 | cxy = GET_CXY( chdev_dir.nic_tx[i] ); |
---|
| 579 | ptr = GET_PTR( chdev_dir.nic_tx[i] ); |
---|
[564] | 580 | base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) ); |
---|
[428] | 581 | nolock_printk(" - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
| 582 | } |
---|
[317] | 583 | |
---|
[428] | 584 | // release lock |
---|
[564] | 585 | remote_busylock_release( lock_xp ); |
---|
[428] | 586 | |
---|
[317] | 587 | } // end chdev_dir_display() |
---|
| 588 | |
---|
[447] | 589 | /////////////////////////////////////////// |
---|
| 590 | void chdev_queue_display( xptr_t chdev_xp ) |
---|
| 591 | { |
---|
| 592 | cxy_t chdev_cxy; // chdev cluster |
---|
| 593 | chdev_t * chdev_ptr; // chdev local pointer |
---|
| 594 | xptr_t root_xp; // extended pointer on waiting queuue root |
---|
| 595 | char name[16]; // local copie of chdev name |
---|
| 596 | xptr_t iter_xp; // extended pointer on xlist_t field in waiting thread |
---|
| 597 | xptr_t thread_xp; // extended pointer on thread registered in queue |
---|
| 598 | cxy_t thread_cxy; // cluster identifier for waiting thread |
---|
| 599 | thread_t * thread_ptr; // local pointer on waiting thread |
---|
| 600 | trdid_t trdid; // waiting thread identifier |
---|
| 601 | process_t * process; // waiting thread process descriptor |
---|
| 602 | pid_t pid; // waiting thread process identifier |
---|
| 603 | |
---|
| 604 | // get cluster and local pointer on chdev |
---|
| 605 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
| 606 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
| 607 | |
---|
| 608 | // get extended pointer on root of requests queue |
---|
[450] | 609 | root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root ); |
---|
[447] | 610 | |
---|
| 611 | // get chdev name |
---|
| 612 | hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) ); |
---|
| 613 | |
---|
[564] | 614 | // get pointers on TXT0 chdev |
---|
| 615 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
| 616 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 617 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
| 618 | |
---|
| 619 | // get extended pointer on TXT0 lock |
---|
| 620 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
| 621 | |
---|
| 622 | // get TXT0 lock |
---|
| 623 | remote_busylock_acquire( lock_xp ); |
---|
| 624 | |
---|
[447] | 625 | // check queue empty |
---|
| 626 | if( xlist_is_empty( root_xp ) ) |
---|
| 627 | { |
---|
[564] | 628 | nolock_printk("\n***** Waiting queue empty for chdev %s\n", name ); |
---|
[447] | 629 | } |
---|
| 630 | else |
---|
| 631 | { |
---|
[564] | 632 | nolock_printk("\n***** Waiting queue for chdev %s\n", name ); |
---|
[447] | 633 | |
---|
| 634 | // scan the waiting queue |
---|
| 635 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
| 636 | { |
---|
| 637 | thread_xp = XLIST_ELEMENT( iter_xp , thread_t , wait_list ); |
---|
| 638 | thread_cxy = GET_CXY( thread_xp ); |
---|
| 639 | thread_ptr = GET_PTR( thread_xp ); |
---|
[564] | 640 | trdid = hal_remote_l32 ( XPTR( thread_cxy , &thread_ptr->trdid ) ); |
---|
[447] | 641 | process = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) ); |
---|
[564] | 642 | pid = hal_remote_l32 ( XPTR( thread_cxy , &process->pid ) ); |
---|
[447] | 643 | |
---|
[601] | 644 | nolock_printk("- thread[%x,%x]\n", pid, trdid ); |
---|
[447] | 645 | } |
---|
| 646 | } |
---|
[564] | 647 | |
---|
| 648 | // release TXT0 lock |
---|
| 649 | remote_busylock_release( lock_xp ); |
---|
| 650 | |
---|
[447] | 651 | } // end chdev_queue_display() |
---|
| 652 | |
---|