source: trunk/kernel/kern/chdev.c @ 593

Last change on this file since 593 was 593, checked in by alain, 5 years ago

Cosmetic: improve debug.

File size: 21.7 KB
RevLine 
[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]43extern chdev_directory_t    chdev_dir;         // allocated in kernel_init.c
[317]44
[564]45
[438]46#if (DEBUG_SYS_READ & 1)
[435]47extern uint32_t enter_chdev_cmd_read;
48extern uint32_t exit_chdev_cmd_read;
49extern uint32_t enter_chdev_server_read;
50extern uint32_t exit_chdev_server_read;
[407]51#endif
[317]52
[438]53#if (DEBUG_SYS_WRITE & 1)
[435]54extern uint32_t enter_chdev_cmd_write;
55extern uint32_t exit_chdev_cmd_write;
56extern uint32_t enter_chdev_server_write;
57extern uint32_t exit_chdev_server_write;
58#endif
59
[5]60////////////////////////////////////////////
61char * 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/////////////////////////////////////////
82chdev_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///////////////////////////////////
116void 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//////////////////////////////////////////////////
133void 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]143enter_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]144#endif
145
[438]146#if (DEBUG_SYS_WRITE & 1)
[435]147enter_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)
[564]170bool_t is_rx = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->is_rx ) );
[437]171#endif
172   
[438]173#if DEBUG_CHDEV_CMD_RX
[437]174uint32_t rx_cycle = (uint32_t)hal_get_cycles();
[438]175if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]176printk("\n[%s] client[%x,%x] enter for RX / server[%x,%x] / cycle %d\n",
177__FUNCTION__, this->process->pid, this->trdid, server_ptr->process->pid, server_ptr->trdid, rx_cycle );
[437]178#endif
179
[438]180#if DEBUG_CHDEV_CMD_TX
[437]181uint32_t tx_cycle = (uint32_t)hal_get_cycles();
[438]182if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]183printk("\n[%s] client[%x,%x] enter for TX / server[%x,%x] / cycle %d\n",
184__FUNCTION__, this->process->pid, this->trdid, server_ptr->process->pid, server_ptr->trdid, tx_cycle );
[437]185#endif
186
[440]187    // build extended pointer on client thread xlist
188    xptr_t  list_xp    = XPTR( local_cxy , &this->wait_list );
[5]189
[440]190    // build extended pointer on chdev waiting queue root
191    xptr_t  root_xp    = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[5]192
[440]193    // build extended pointer on server thread blocked state
194    xptr_t  blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked );
195
196    // build extended pointer on lock protecting chdev waiting queue
[564]197    lock_xp            = XPTR( chdev_cxy , &chdev_ptr->wait_lock );
[407]198
[581]199    // TODO the hal_disable_irq() / hal_restore_irq()
200    // in the sequence below is probably useless, as it is
201    // already done by the busylock_acquire() / busylock_release()
202    // => remove it [AG] october 2018
203
[450]204    // critical section for the following sequence:
[564]205    // (1) take the lock protecting the chdev state
[440]206    // (2) block the client thread
207    // (3) unblock the server thread if required
208    // (4) register client thread in server queue
209    // (5) send IPI to force server scheduling
210    // (6) release the lock protecting waiting queue
211    // (7) deschedule
[407]212
[440]213    // enter critical section
214    hal_disable_irq( &save_sr );
[407]215
[564]216    // take the lock protecting chdev queue
217    remote_busylock_acquire( lock_xp );
[408]218
219    // block current thread
[436]220    thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO );
[408]221
[450]222#if (DEBUG_CHDEV_CMD_TX & 1)
223if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]224printk("\n[%s] client thread[%x,%x] blocked\n",
225__FUNCTION__, this->process_pid, this->trdid );
[450]226#endif
227
[457]228#if (DEBUG_CHDEV_CMD_RX & 1)
229if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]230printk("\n[%s] client thread[%x,%x] blocked\n",
231__FUNCTION__, this->process_pid, this->trdid );
[457]232#endif
233
[446]234    // unblock server thread if required
[564]235    if( hal_remote_l32( blocked_xp ) & THREAD_BLOCKED_IDLE )
[440]236    thread_unblock( server_xp , THREAD_BLOCKED_IDLE );
237
[450]238#if (DEBUG_CHDEV_CMD_TX & 1)
239if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]240printk("\n[%s] TX server thread[%x,%x] unblocked\n",
241__FUNCTION__, server_ptr->process->pid, server_ptr->trdid );
[450]242#endif
243
[457]244#if (DEBUG_CHDEV_CMD_RX & 1)
245if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]246printk("\n[%s] RX server thread[%x,%x] unblocked\n",
247__FUNCTION__, server_ptr->process->pid, server_ptr->trdid );
[457]248#endif
249
[5]250    // register client thread in waiting queue
[407]251    xlist_add_last( root_xp , list_xp );
[5]252
[450]253#if (DEBUG_CHDEV_CMD_TX & 1)
254if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]255printk("\n[%s] client thread[%x,%x] registered write request in chdev\n",
256__FUNCTION__, this->process->pid, this->trdid );
[450]257#endif
258 
[457]259#if (DEBUG_CHDEV_CMD_RX & 1)
260if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]261printk("\n[%s] client thread[%x,%x] registered read request in chdev\n",
262__FUNCTION__, this->process->pid, this->trdid );
[457]263#endif
264 
[564]265    // send IPI to core running the server thread when server core != client core
[457]266    if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) )
[450]267    {
[457]268        dev_pic_send_ipi( chdev_cxy , server_lid ); 
269
[450]270#if (DEBUG_CHDEV_CMD_TX & 1)
271if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]272printk("\n[%s] client thread[%x,%x] sent IPI to TX server thread[%x,%x]\n",
273__FUNCTION__, this->process->pid, this->trdid, server_ptr->process->pid, server_ptr->trdid );
[450]274#endif
275
[457]276#if (DEBUG_CHDEV_CMD_RX & 1)
277if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]278printk("\n[%s] client thread[%x,%x] sent IPI to RX server thread[%x,%x]\n",
279__FUNCTION__, this->process->pid, this->trdid, server_ptr->process->pid, server_ptr->trdid );
[457]280#endif
281
[450]282    }
283 
[564]284    // release lock protecting chdev queue
285    remote_busylock_release( lock_xp );
[440]286
[408]287    // deschedule
288    sched_yield("blocked on I/O");
[407]289
290    // exit critical section
291    hal_restore_irq( save_sr );
292
[438]293#if DEBUG_CHDEV_CMD_RX
[437]294rx_cycle = (uint32_t)hal_get_cycles();
[438]295if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]296printk("\n[%s] client_thread[%x,%x] exit for RX / cycle %d\n",
297__FUNCTION__, this->process->pid, this->trdid, rx_cycle );
[433]298#endif
299
[438]300#if DEBUG_CHDEV_CMD_TX
[437]301tx_cycle = (uint32_t)hal_get_cycles();
[438]302if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]303printk("\n[%s] client_thread[%x,%x] exit for TX / cycle %d\n",
304__FUNCTION__, this->process->pid, this->trdid, tx_cycle );
[437]305#endif
306
[438]307#if (DEBUG_SYS_READ & 1)
[435]308exit_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]309#endif
310
[438]311#if (DEBUG_SYS_WRITE & 1)
[435]312exit_chdev_cmd_write = (uint32_t)hal_get_cycles();
313#endif
314
[5]315}  // end chdev_register_command()
316
317///////////////////////////////////////////////
318void chdev_sequencial_server( chdev_t * chdev )
319{
320    xptr_t          client_xp;    // extended pointer on waiting thread
321    cxy_t           client_cxy;   // cluster of client thread
322    thread_t      * client_ptr;   // local pointer on client thread
[407]323    thread_t      * server;       // local pointer on server thread
[5]324    xptr_t          root_xp;      // extended pointer on device waiting queue root
[407]325    xptr_t          lock_xp;      // extended pointer on lock ptotecting chdev queue
[5]326
327    server = CURRENT_THREAD;
328
[564]329    // build extended pointer on root of client threads queue
[5]330    root_xp = XPTR( local_cxy , &chdev->wait_root );
[564]331
332    // build extended pointer on lock protecting client threads queue
[407]333    lock_xp = XPTR( local_cxy , &chdev->wait_lock );
[5]334
[407]335        // This infinite loop is executed by the DEV thread
336    // to handle commands registered in the chdev queue.
[5]337    while( 1 )
338    {
[564]339
340#if DEBUG_CHDEV_SERVER_RX
341uint32_t rx_cycle = (uint32_t)hal_get_cycles();
342if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[593]343printk("\n[%s] dev_thread[%x,%x] start RX / cycle %d\n",
344__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
[564]345#endif
346
347#if DEBUG_CHDEV_SERVER_TX
348uint32_t tx_cycle = (uint32_t)hal_get_cycles();
349if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[593]350printk("\n[%s] dev_thread[%x,%x] start TX / cycle %d\n",
351__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
[564]352#endif
353
[407]354        // get the lock protecting the waiting queue
[564]355        remote_busylock_acquire( lock_xp );
[407]356
[5]357        // check waiting queue state
[407]358        if( xlist_is_empty( root_xp ) ) // waiting queue empty
[5]359        {
[564]360
361#if DEBUG_CHDEV_SERVER_RX
362rx_cycle = (uint32_t)hal_get_cycles();
363if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[593]364printk("\n[%s] dev_thread[%x,%x] found RX queue empty => blocks / cycle %d\n",
365__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
[564]366#endif
367
368#if DEBUG_CHDEV_SERVER_TX
369tx_cycle = (uint32_t)hal_get_cycles();
370if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[593]371printk("\n[%s] dev_thread[%x,%x] found TX queue empty => blocks / cycle %d\n",
372__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
[564]373#endif
374
[5]375            // release lock
[564]376            remote_busylock_release( lock_xp );
[5]377
[440]378            // block
379            thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_IDLE ); 
380
[564]381// check server thread can yield
382assert( (server->busylocks == 0),
383"cannot yield : busylocks = %d\n", server->busylocks );
384
[408]385            // deschedule
386            sched_yield("I/O queue empty");
[5]387        } 
[407]388        else                            // waiting queue not empty
[5]389        {
[407]390            // get extended pointer on first client thread
[564]391            client_xp = XLIST_FIRST( root_xp , thread_t , wait_list );
[5]392
[440]393            // get client thread cluster and local pointer
[407]394            client_cxy = GET_CXY( client_xp );
[440]395            client_ptr = GET_PTR( client_xp );
[407]396
[440]397            // remove this first client thread from waiting queue
398            xlist_unlink( XPTR( client_cxy , &client_ptr->wait_list ) );
399
400            // release lock
[564]401            remote_busylock_release( lock_xp );
[440]402
[438]403#if DEBUG_CHDEV_SERVER_RX
[564]404rx_cycle = (uint32_t)hal_get_cycles();
[438]405if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[593]406printk("\n[%s] dev_thread[%x,%x] for RX get client thread[%x,%x] / cycle %d\n",
407__FUNCTION__, server->process->pid, server->trdid,
408client_ptr->process->pid, client_ptr->trdid, rx_cycle );
[437]409#endif
410
[438]411#if DEBUG_CHDEV_SERVER_TX
[564]412tx_cycle = (uint32_t)hal_get_cycles();
[438]413if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[593]414printk("\n[%s] dev_thread[%x,%x] for TX get client thread[%x,%x] / cycle %d\n",
415__FUNCTION__, server->process->pid, server->trdid,
416client_ptr->process->pid, client_ptr->trdid, tx_cycle );
[437]417#endif
418
[438]419#if (DEBUG_SYS_READ & 1)
[437]420enter_chdev_server_read = (uint32_t)hal_get_cycles();
421#endif
422
[438]423#if (DEBUG_SYS_WRITE & 1)
[437]424enter_chdev_server_write = (uint32_t)hal_get_cycles();
425#endif
426
[407]427            // call driver command function to execute I/O operation
428            chdev->cmd( client_xp );
[5]429       
[418]430            // unblock client thread
431            thread_unblock( client_xp , THREAD_BLOCKED_IO );
432
[438]433#if DEBUG_CHDEV_SERVER_RX
[437]434rx_cycle = (uint32_t)hal_get_cycles();
[438]435if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[593]436printk("\n[%s] dev_thread[%x,%x] completes RX for client thread[%x,%x] / cycle %d\n",
437__FUNCTION__, server->process->pid, server->trdid,
438client_ptr->process->pid, client_ptr->trdid, rx_cycle );
[433]439#endif
[5]440
[438]441#if DEBUG_CHDEV_SERVER_TX
[437]442tx_cycle = (uint32_t)hal_get_cycles();
[438]443if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[593]444printk("\n[%s] dev_thread[%x,%x] completes TX for client thread[%x,%x] / cycle %d\n",
445__FUNCTION__, server->process->pid, server->trdid,
446client_ptr->process->pid, client_ptr->trdid, tx_cycle );
[437]447#endif
448
[438]449#if (DEBUG_SYS_READ & 1)
[435]450exit_chdev_server_read = (uint32_t)hal_get_cycles();
[407]451#endif
452
[438]453#if (DEBUG_SYS_WRITE & 1)
[435]454exit_chdev_server_write = (uint32_t)hal_get_cycles();
455#endif
456
[407]457        }
[5]458    }  // end while
459}  // end chdev_sequencial_server()
460
[428]461////////////////////////////////////////
462xptr_t chdev_from_file( xptr_t file_xp )
463{
464    cxy_t         file_cxy;
465    vfs_file_t  * file_ptr;
466    uint32_t      inode_type;
467    vfs_inode_t * inode_ptr;
468    chdev_t     * chdev_ptr;
469
[492]470    assert( (file_xp != XPTR_NULL) ,
[440]471    "file_xp == XPTR_NULL\n" );
472
[428]473    // get cluster and local pointer on remote file descriptor
474    // associated inode and chdev are stored in same cluster as the file desc.
475    file_cxy  = GET_CXY( file_xp );
476    file_ptr  = (vfs_file_t *)GET_PTR( file_xp );
477
478    // get inode type from file descriptor
[564]479    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
[428]480    inode_ptr  = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
481
[492]482    assert( (inode_type == INODE_TYPE_DEV) ,
[440]483    "inode type %d is not INODE_TYPE_DEV\n", inode_type );
[428]484
485    // get chdev local pointer from inode extension
486    chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) );
487
488    return XPTR( file_cxy , chdev_ptr );
489
490}  // end chdev_from_file()
491
[564]492//////////////////////////////
[485]493void chdev_dir_display( void )
[317]494{
[428]495    uint32_t  i;
496    cxy_t     cxy;
497    chdev_t * ptr;
498    uint32_t  base;
[317]499
[428]500    // get pointers on TXT0 chdev
501    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
502    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
503    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
[317]504
[564]505    // get extended pointer on TXT0 lock
[428]506    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
[317]507
[564]508    // get TXT0 lock
509    remote_busylock_acquire( lock_xp );
[317]510
[428]511    // header
512    nolock_printk("\n***** external chdevs directory *****\n");
[317]513
[428]514    // IOB
[564]515    if (chdev_dir.iob != XPTR_NULL )
[545]516    {
517        cxy  = GET_CXY( chdev_dir.iob );
518        ptr  = GET_PTR( chdev_dir.iob );
[564]519        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[545]520        nolock_printk("  - iob       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
521    }
[407]522
[428]523    // PIC
524    cxy  = GET_CXY( chdev_dir.pic );
525    ptr  = GET_PTR( chdev_dir.pic );
[564]526    base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]527    nolock_printk("  - pic       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
[407]528
[428]529    // TXT
530    for( i = 0 ; i < LOCAL_CLUSTER->nb_txt_channels ; i++ )
531    {
532        cxy = GET_CXY( chdev_dir.txt_rx[i] );
533        ptr = GET_PTR( chdev_dir.txt_rx[i] );
[564]534        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]535        nolock_printk("  - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[407]536
[428]537        cxy = GET_CXY( chdev_dir.txt_tx[i] );
538        ptr = GET_PTR( chdev_dir.txt_tx[i] );
[564]539        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]540        nolock_printk("  - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
541    }
[317]542
[428]543    // IOC
544    for( i = 0 ; i < LOCAL_CLUSTER->nb_ioc_channels ; i++ )
545    {
546        cxy = GET_CXY( chdev_dir.ioc[i] );
547        ptr = GET_PTR( chdev_dir.ioc[i] );
[564]548        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]549        nolock_printk("  - ioc[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
550    }
[317]551
[428]552    // FBF
553    for( i = 0 ; i < LOCAL_CLUSTER->nb_fbf_channels ; i++ )
554    {
555        cxy  = GET_CXY( chdev_dir.fbf[i] );
556        ptr  = GET_PTR( chdev_dir.fbf[i] );
[564]557        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]558        nolock_printk("  - fbf[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
559    }
[317]560
[428]561    // NIC
562    for( i = 0 ; i < LOCAL_CLUSTER->nb_nic_channels ; i++ )
563    {
564        cxy = GET_CXY( chdev_dir.nic_rx[i] );
565        ptr = GET_PTR( chdev_dir.nic_rx[i] );
[564]566        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]567        nolock_printk("  - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[317]568
[428]569        cxy = GET_CXY( chdev_dir.nic_tx[i] );
570        ptr = GET_PTR( chdev_dir.nic_tx[i] );
[564]571        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]572        nolock_printk("  - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
573    }
[317]574
[428]575    // release lock
[564]576    remote_busylock_release( lock_xp );
[428]577
[317]578}  // end chdev_dir_display()
579
[447]580///////////////////////////////////////////
581void chdev_queue_display( xptr_t chdev_xp )
582{
583    cxy_t       chdev_cxy;          // chdev cluster
584    chdev_t   * chdev_ptr;          // chdev local pointer
585    xptr_t      root_xp;            // extended pointer on waiting queuue root
586    char        name[16];           // local copie of chdev name
587    xptr_t      iter_xp;            // extended pointer on xlist_t field in waiting thread
588    xptr_t      thread_xp;          // extended pointer on thread registered in queue
589    cxy_t       thread_cxy;         // cluster identifier for waiting thread
590    thread_t  * thread_ptr;         // local pointer on waiting thread
591    trdid_t     trdid;              // waiting thread identifier
592    process_t * process;            // waiting thread process descriptor
593    pid_t       pid;                // waiting thread process identifier
594
595    // get cluster and local pointer on chdev
596    chdev_cxy = GET_CXY( chdev_xp );
597    chdev_ptr = GET_PTR( chdev_xp );
598
599    // get extended pointer on root of requests queue
[450]600    root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[447]601
602    // get chdev name
603    hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) );
604
[564]605    // get pointers on TXT0 chdev
606    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
607    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
608    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
609
610    // get extended pointer on TXT0 lock
611    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
612
613    // get TXT0 lock
614    remote_busylock_acquire( lock_xp );
615
[447]616    // check queue empty
617    if( xlist_is_empty( root_xp ) )
618    {
[564]619        nolock_printk("\n***** Waiting queue empty for chdev %s\n", name ); 
[447]620    }
621    else
622    {
[564]623        nolock_printk("\n***** Waiting queue for chdev %s\n", name ); 
[447]624
625        // scan the waiting queue
626        XLIST_FOREACH( root_xp , iter_xp )
627        {
628            thread_xp  = XLIST_ELEMENT( iter_xp , thread_t , wait_list );
629            thread_cxy = GET_CXY( thread_xp );
630            thread_ptr = GET_PTR( thread_xp );
[564]631            trdid      = hal_remote_l32 ( XPTR( thread_cxy , &thread_ptr->trdid   ) );
[447]632            process    = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) );
[564]633                        pid        = hal_remote_l32 ( XPTR( thread_cxy , &process->pid        ) );
[447]634
[564]635            nolock_printk("- thread %X / cluster %X / trdid %X / pid %X\n",
[450]636            thread_ptr, thread_cxy, trdid, pid );
[447]637        }
638    }
[564]639
640    // release TXT0 lock
641    remote_busylock_release( lock_xp );
642
[447]643}  // end chdev_queue_display()
644
Note: See TracBrowser for help on using the repository browser.