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

Last change on this file since 471 was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 19.3 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
[317]39
40extern chdev_directory_t    chdev_dir;   // allocated in kernel_init.c
41
[438]42#if (DEBUG_SYS_READ & 1)
[435]43extern uint32_t enter_chdev_cmd_read;
44extern uint32_t exit_chdev_cmd_read;
45extern uint32_t enter_chdev_server_read;
46extern uint32_t exit_chdev_server_read;
[407]47#endif
[317]48
[438]49#if (DEBUG_SYS_WRITE & 1)
[435]50extern uint32_t enter_chdev_cmd_write;
51extern uint32_t exit_chdev_cmd_write;
52extern uint32_t enter_chdev_server_write;
53extern uint32_t exit_chdev_server_write;
54#endif
55
[5]56////////////////////////////////////////////
57char * chdev_func_str( uint32_t func_type ) 
58{
59        if     ( func_type == DEV_FUNC_RAM ) return "RAM";
60        else if( func_type == DEV_FUNC_ROM ) return "ROM";
61        else if( func_type == DEV_FUNC_FBF ) return "FBF";
62        else if( func_type == DEV_FUNC_IOB ) return "IOB";
63        else if( func_type == DEV_FUNC_IOC ) return "IOC";
64        else if( func_type == DEV_FUNC_MMC ) return "MMC";
65        else if( func_type == DEV_FUNC_DMA ) return "DMA";
66        else if( func_type == DEV_FUNC_NIC ) return "NIC";
67        else if( func_type == DEV_FUNC_TIM ) return "TIM";
68        else if( func_type == DEV_FUNC_TXT ) return "TXT";
69        else if( func_type == DEV_FUNC_ICU ) return "ICU";
70        else if( func_type == DEV_FUNC_PIC ) return "PIC";
[16]71    else                                 return "undefined";
[5]72}
73
74/////////////////////////////////////////
75chdev_t * chdev_create( uint32_t    func,
76                        uint32_t    impl,
77                        uint32_t    channel,
78                        uint32_t    is_rx,
79                        xptr_t      base )
80{
81    chdev_t    * chdev;
82    kmem_req_t   req;
83
84    // allocate memory for chdev
85    req.type   = KMEM_DEVICE;
86    req.flags  = AF_ZERO;
87    chdev      = (chdev_t *)kmem_alloc( &req );
88
89    if( chdev == NULL ) return NULL;
90
91    // initialize waiting threads queue and associated lock
92    remote_spinlock_init( XPTR( local_cxy , &chdev->wait_lock ) );
93    xlist_root_init( XPTR( local_cxy , &chdev->wait_root ) );
94
95    // initialize attributes
96    chdev->func    =  func;
97    chdev->impl    =  impl;
98    chdev->channel =  channel;
99    chdev->is_rx   =  is_rx;
100    chdev->base    =  base; 
101
102    return chdev;
103
104}  // end chdev_create()
105
106///////////////////////////////////
107void chdev_print( chdev_t * chdev )
108{
109    printk("\n - func      = %s"
110           "\n - channel   = %d"
111           "\n - base      = %l"
112           "\n - cmd       = %x"
113           "\n - isr       = %x"
114           "\n - chdev     = %x\n",
115           chdev_func_str(chdev->func),
116           chdev->channel,
117           chdev->base,
118           chdev->cmd,
119           chdev->isr,
120           chdev );
121}
122
[407]123//////////////////////////////////////////////////
124void chdev_register_command( xptr_t     chdev_xp )
[5]125{
[407]126    thread_t * server_ptr;    // local pointer on server thread associated to chdev
[440]127    xptr_t     server_xp;     // extended pointer on server thread
[407]128    core_t   * core_ptr;      // local pointer on core running the server thread
[457]129    uint32_t   server_lid;    // core running the server thread local index
[407]130    xptr_t     lock_xp;       // extended pointer on lock protecting the chdev queue
131    uint32_t   save_sr;       // for critical section
[5]132
[438]133#if (DEBUG_SYS_READ & 1)
[435]134enter_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]135#endif
136
[438]137#if (DEBUG_SYS_WRITE & 1)
[435]138enter_chdev_cmd_write = (uint32_t)hal_get_cycles();
139#endif
140
[407]141    thread_t * this = CURRENT_THREAD;
142
[440]143    // get chdev cluster and local pointer
[5]144    cxy_t     chdev_cxy = GET_CXY( chdev_xp );
[440]145    chdev_t * chdev_ptr = GET_PTR( chdev_xp );
[5]146
[440]147    // get local and extended pointers on server thread
148    server_ptr = (thread_t *)hal_remote_lpt( XPTR( chdev_cxy , &chdev_ptr->server) );
149    server_xp  = XPTR( chdev_cxy , server_ptr );
150
151    // get local pointer on core running the server thread
152    core_ptr   = (core_t *)hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->core ) );
153
154    // get server core local index
[457]155    server_lid = hal_remote_lw( XPTR( chdev_cxy , &core_ptr->lid ) );
[440]156
[438]157#if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX)
[437]158bool_t is_rx = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->is_rx ) );
159#endif
160   
[438]161#if DEBUG_CHDEV_CMD_RX
[437]162uint32_t rx_cycle = (uint32_t)hal_get_cycles();
[438]163if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[450]164printk("\n[DBG] %s : client_thread %x (%s) enter for RX / server = %x / cycle %d\n",
165__FUNCTION__, this, thread_type_str(this->type) , server_ptr, rx_cycle );
[437]166#endif
167
[438]168#if DEBUG_CHDEV_CMD_TX
[437]169uint32_t tx_cycle = (uint32_t)hal_get_cycles();
[438]170if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[450]171printk("\n[DBG] %s : client_thread %x (%s) enter for TX / server = %x / cycle %d\n",
172__FUNCTION__, this, thread_type_str(this->type) , server_ptr, tx_cycle );
[437]173#endif
174
[440]175    // build extended pointer on client thread xlist
176    xptr_t  list_xp    = XPTR( local_cxy , &this->wait_list );
[5]177
[440]178    // build extended pointer on chdev waiting queue root
179    xptr_t  root_xp    = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[5]180
[440]181    // build extended pointer on server thread blocked state
182    xptr_t  blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked );
183
184    // build extended pointer on lock protecting chdev waiting queue
[407]185    lock_xp = XPTR( chdev_cxy , &chdev_ptr->wait_lock );
186
[450]187    // critical section for the following sequence:
[440]188    // (1) take the lock protecting waiting queue
189    // (2) block the client thread
190    // (3) unblock the server thread if required
191    // (4) register client thread in server queue
192    // (5) send IPI to force server scheduling
193    // (6) release the lock protecting waiting queue
194    // (7) deschedule
195    // ... in this order
[407]196
[440]197    // enter critical section
198    hal_disable_irq( &save_sr );
[407]199
[446]200    // take the lock protecting chdev waiting queue
[440]201    remote_spinlock_lock( lock_xp );
[408]202
203    // block current thread
[436]204    thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO );
[408]205
[450]206#if (DEBUG_CHDEV_CMD_TX & 1)
207if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
208printk("\n[DBG] in %s : client thread %x blocked\n", __FUNCTION__, this );
209#endif
210
[457]211#if (DEBUG_CHDEV_CMD_RX & 1)
212if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
213printk("\n[DBG] in %s : client thread %x blocked\n", __FUNCTION__, this );
214#endif
215
[446]216    // unblock server thread if required
[440]217    if( hal_remote_lw( blocked_xp ) & THREAD_BLOCKED_IDLE )
218    thread_unblock( server_xp , THREAD_BLOCKED_IDLE );
219
[450]220#if (DEBUG_CHDEV_CMD_TX & 1)
221if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[457]222printk("\n[DBG] in %s : TX server thread %x unblocked\n", __FUNCTION__, server_ptr );
[450]223#endif
224
[457]225#if (DEBUG_CHDEV_CMD_RX & 1)
226if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
227printk("\n[DBG] in %s : RX server thread %x unblocked\n", __FUNCTION__, server_ptr );
228#endif
229
[5]230    // register client thread in waiting queue
[407]231    xlist_add_last( root_xp , list_xp );
[5]232
[450]233#if (DEBUG_CHDEV_CMD_TX & 1)
234if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
235printk("\n[DBG] in %s : thread %x registered write request in chdev\n", __FUNCTION__, this );
236#endif
237 
[457]238#if (DEBUG_CHDEV_CMD_RX & 1)
239if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
240printk("\n[DBG] in %s : thread %x registered read request in chdev\n", __FUNCTION__, this );
241#endif
242 
[440]243    // send IPI to core running the server thread when server != client
[457]244    if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) )
[450]245    {
[457]246        dev_pic_send_ipi( chdev_cxy , server_lid ); 
247
[450]248#if (DEBUG_CHDEV_CMD_TX & 1)
249if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[457]250printk("\n[DBG] in %s : client thread %x sent IPI to TX server thread %x\n",
[450]251__FUNCTION__, this, server_ptr );
252#endif
253
[457]254#if (DEBUG_CHDEV_CMD_RX & 1)
255if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
256printk("\n[DBG] in %s : client thread %x sent IPI to RX server thread %x\n",
257__FUNCTION__, this, server_ptr );
258#endif
259
[450]260    }
261 
[440]262    // release lock
263    remote_spinlock_unlock( lock_xp );
264
[408]265    // deschedule
266    assert( thread_can_yield( this ) , __FUNCTION__ , "illegal sched_yield\n" );
267    sched_yield("blocked on I/O");
[407]268
269    // exit critical section
270    hal_restore_irq( save_sr );
271
[438]272#if DEBUG_CHDEV_CMD_RX
[437]273rx_cycle = (uint32_t)hal_get_cycles();
[438]274if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[437]275printk("\n[DBG] %s : client_thread %x (%s) exit for RX / cycle %d\n",
276__FUNCTION__, this, thread_type_str(this->type) , rx_cycle );
[433]277#endif
278
[438]279#if DEBUG_CHDEV_CMD_TX
[437]280tx_cycle = (uint32_t)hal_get_cycles();
[438]281if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[437]282printk("\n[DBG] %s : client_thread %x (%s) exit for TX / cycle %d\n",
283__FUNCTION__, this, thread_type_str(this->type) , tx_cycle );
284#endif
285
[438]286#if (DEBUG_SYS_READ & 1)
[435]287exit_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]288#endif
289
[438]290#if (DEBUG_SYS_WRITE & 1)
[435]291exit_chdev_cmd_write = (uint32_t)hal_get_cycles();
292#endif
293
[5]294}  // end chdev_register_command()
295
296///////////////////////////////////////////////
297void chdev_sequencial_server( chdev_t * chdev )
298{
299    xptr_t          client_xp;    // extended pointer on waiting thread
300    cxy_t           client_cxy;   // cluster of client thread
301    thread_t      * client_ptr;   // local pointer on client thread
[407]302    thread_t      * server;       // local pointer on server thread
[5]303    xptr_t          root_xp;      // extended pointer on device waiting queue root
[407]304    xptr_t          lock_xp;      // extended pointer on lock ptotecting chdev queue
[5]305
306    server = CURRENT_THREAD;
307
[437]308    // get root and lock on command queue
[5]309    root_xp = XPTR( local_cxy , &chdev->wait_root );
[407]310    lock_xp = XPTR( local_cxy , &chdev->wait_lock );
[5]311
[407]312        // This infinite loop is executed by the DEV thread
313    // to handle commands registered in the chdev queue.
[5]314    while( 1 )
315    {
[407]316        // get the lock protecting the waiting queue
317        remote_spinlock_lock( lock_xp );
318
[5]319        // check waiting queue state
[407]320        if( xlist_is_empty( root_xp ) ) // waiting queue empty
[5]321        {
322            // release lock
[407]323            remote_spinlock_unlock( lock_xp );
[5]324
[440]325            // block
326            thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_IDLE ); 
327
[408]328            // deschedule
[440]329            assert( thread_can_yield( server ) , __FUNCTION__ , "illegal sched_yield\n" );
[408]330            sched_yield("I/O queue empty");
[5]331        } 
[407]332        else                            // waiting queue not empty
[5]333        {
[407]334            // get extended pointer on first client thread
335            client_xp = XLIST_FIRST_ELEMENT( root_xp , thread_t , wait_list );
[5]336
[440]337            // get client thread cluster and local pointer
[407]338            client_cxy = GET_CXY( client_xp );
[440]339            client_ptr = GET_PTR( client_xp );
[407]340
[440]341            // remove this first client thread from waiting queue
342            xlist_unlink( XPTR( client_cxy , &client_ptr->wait_list ) );
343
344            // release lock
345            remote_spinlock_unlock( lock_xp );
346
[438]347#if DEBUG_CHDEV_SERVER_RX
[437]348uint32_t rx_cycle = (uint32_t)hal_get_cycles();
[438]349if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[437]350printk("\n[DBG] %s : server_thread %x start RX / client %x / cycle %d\n",
351__FUNCTION__ , server , client_ptr , rx_cycle );
352#endif
353
[438]354#if DEBUG_CHDEV_SERVER_TX
[437]355uint32_t tx_cycle = (uint32_t)hal_get_cycles();
[438]356if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[437]357printk("\n[DBG] %s : server_thread %x start TX / client %x / cycle %d\n",
358__FUNCTION__ , server , client_ptr , tx_cycle );
359#endif
360
[438]361#if (DEBUG_SYS_READ & 1)
[437]362enter_chdev_server_read = (uint32_t)hal_get_cycles();
363#endif
364
[438]365#if (DEBUG_SYS_WRITE & 1)
[437]366enter_chdev_server_write = (uint32_t)hal_get_cycles();
367#endif
368
[407]369            // call driver command function to execute I/O operation
370            chdev->cmd( client_xp );
[5]371       
[418]372            // unblock client thread
373            thread_unblock( client_xp , THREAD_BLOCKED_IO );
374
[438]375#if DEBUG_CHDEV_SERVER_RX
[437]376rx_cycle = (uint32_t)hal_get_cycles();
[438]377if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[437]378printk("\n[DBG] %s : server_thread %x completes RX / client %x / cycle %d\n",
379__FUNCTION__ , server , client_ptr , rx_cycle );
[433]380#endif
[5]381
[438]382#if DEBUG_CHDEV_SERVER_TX
[437]383tx_cycle = (uint32_t)hal_get_cycles();
[438]384if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[437]385printk("\n[DBG] %s : server_thread %x completes TX / client %x / cycle %d\n",
386__FUNCTION__ , server , client_ptr , tx_cycle );
387#endif
388
[438]389#if (DEBUG_SYS_READ & 1)
[435]390exit_chdev_server_read = (uint32_t)hal_get_cycles();
[407]391#endif
392
[438]393#if (DEBUG_SYS_WRITE & 1)
[435]394exit_chdev_server_write = (uint32_t)hal_get_cycles();
395#endif
396
[407]397        }
[5]398    }  // end while
399}  // end chdev_sequencial_server()
400
[428]401////////////////////////////////////////
402xptr_t chdev_from_file( xptr_t file_xp )
403{
404    cxy_t         file_cxy;
405    vfs_file_t  * file_ptr;
406    uint32_t      inode_type;
407    vfs_inode_t * inode_ptr;
408    chdev_t     * chdev_ptr;
409
[440]410    assert( (file_xp != XPTR_NULL) , __FUNCTION__,
411    "file_xp == XPTR_NULL\n" );
412
[428]413    // get cluster and local pointer on remote file descriptor
414    // associated inode and chdev are stored in same cluster as the file desc.
415    file_cxy  = GET_CXY( file_xp );
416    file_ptr  = (vfs_file_t *)GET_PTR( file_xp );
417
418    // get inode type from file descriptor
419    inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
420    inode_ptr  = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
421
422    assert( (inode_type == INODE_TYPE_DEV) , __FUNCTION__ ,
[440]423    "inode type %d is not INODE_TYPE_DEV\n", inode_type );
[428]424
425    // get chdev local pointer from inode extension
426    chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) );
427
428    return XPTR( file_cxy , chdev_ptr );
429
430}  // end chdev_from_file()
431
[317]432////////////////////////
433void chdev_dir_display()
434{
[428]435    uint32_t  i;
436    cxy_t     cxy;
437    chdev_t * ptr;
438    uint32_t  base;
439    reg_t     save_sr;
[317]440
[428]441    // get pointers on TXT0 chdev
442    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
443    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
444    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
[317]445
[428]446    // get extended pointer on remote TXT0 chdev lock
447    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
[317]448
[428]449    // get TXT0 lock in busy waiting mode
450    remote_spinlock_lock_busy( lock_xp , &save_sr );
[317]451
[428]452    // header
453    nolock_printk("\n***** external chdevs directory *****\n");
[317]454
[428]455    // IOB
456    cxy  = GET_CXY( chdev_dir.iob );
457    ptr  = GET_PTR( chdev_dir.iob );
458    base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
459    nolock_printk("  - iob       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
[407]460
[428]461    // PIC
462    cxy  = GET_CXY( chdev_dir.pic );
463    ptr  = GET_PTR( chdev_dir.pic );
464    base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
465    nolock_printk("  - pic       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
[407]466
[428]467    // TXT
468    for( i = 0 ; i < LOCAL_CLUSTER->nb_txt_channels ; i++ )
469    {
470        cxy = GET_CXY( chdev_dir.txt_rx[i] );
471        ptr = GET_PTR( chdev_dir.txt_rx[i] );
472        base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
473        nolock_printk("  - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[407]474
[428]475        cxy = GET_CXY( chdev_dir.txt_tx[i] );
476        ptr = GET_PTR( chdev_dir.txt_tx[i] );
477        base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
478        nolock_printk("  - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
479    }
[317]480
[428]481    // IOC
482    for( i = 0 ; i < LOCAL_CLUSTER->nb_ioc_channels ; i++ )
483    {
484        cxy = GET_CXY( chdev_dir.ioc[i] );
485        ptr = GET_PTR( chdev_dir.ioc[i] );
486        base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
487        nolock_printk("  - ioc[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
488    }
[317]489
[428]490    // FBF
491    for( i = 0 ; i < LOCAL_CLUSTER->nb_fbf_channels ; i++ )
492    {
493        cxy  = GET_CXY( chdev_dir.fbf[i] );
494        ptr  = GET_PTR( chdev_dir.fbf[i] );
495        base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
496        nolock_printk("  - fbf[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
497    }
[317]498
[428]499    // NIC
500    for( i = 0 ; i < LOCAL_CLUSTER->nb_nic_channels ; i++ )
501    {
502        cxy = GET_CXY( chdev_dir.nic_rx[i] );
503        ptr = GET_PTR( chdev_dir.nic_rx[i] );
504        base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
505        nolock_printk("  - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[317]506
[428]507        cxy = GET_CXY( chdev_dir.nic_tx[i] );
508        ptr = GET_PTR( chdev_dir.nic_tx[i] );
509        base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) );
510        nolock_printk("  - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
511    }
[317]512
[428]513    // release lock
514    remote_spinlock_unlock_busy( lock_xp , save_sr );
515
[317]516}  // end chdev_dir_display()
517
[447]518///////////////////////////////////////////
519void chdev_queue_display( xptr_t chdev_xp )
520{
521    cxy_t       chdev_cxy;          // chdev cluster
522    chdev_t   * chdev_ptr;          // chdev local pointer
523    xptr_t      root_xp;            // extended pointer on waiting queuue root
524    char        name[16];           // local copie of chdev name
525    xptr_t      iter_xp;            // extended pointer on xlist_t field in waiting thread
526    xptr_t      thread_xp;          // extended pointer on thread registered in queue
527    cxy_t       thread_cxy;         // cluster identifier for waiting thread
528    thread_t  * thread_ptr;         // local pointer on waiting thread
529    trdid_t     trdid;              // waiting thread identifier
530    process_t * process;            // waiting thread process descriptor
531    pid_t       pid;                // waiting thread process identifier
532
533    // get cluster and local pointer on chdev
534    chdev_cxy = GET_CXY( chdev_xp );
535    chdev_ptr = GET_PTR( chdev_xp );
536
537    // get extended pointer on root of requests queue
[450]538    root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[447]539
540    // get chdev name
541    hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) );
542
543    // check queue empty
544    if( xlist_is_empty( root_xp ) )
545    {
546        printk("\n***** Waiting queue empty for chdev %s\n", name ); 
547    }
548    else
549    {
550        printk("\n***** Waiting queue for chdev %s\n", name ); 
551
552        // scan the waiting queue
553        XLIST_FOREACH( root_xp , iter_xp )
554        {
555            thread_xp  = XLIST_ELEMENT( iter_xp , thread_t , wait_list );
556            thread_cxy = GET_CXY( thread_xp );
557            thread_ptr = GET_PTR( thread_xp );
558            trdid      = hal_remote_lw ( XPTR( thread_cxy , &thread_ptr->trdid   ) );
559            process    = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) );
560                        pid        = hal_remote_lw ( XPTR( thread_cxy , &process->pid        ) );
561
[450]562            printk("- thread %X / cluster %X / trdid %X / pid %X\n",
563            thread_ptr, thread_cxy, trdid, pid );
[447]564        }
565    }
566}  // end chdev_queue_display()
567
Note: See TracBrowser for help on using the repository browser.