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

Last change on this file since 574 was 564, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

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