source: trunk/kernel/kern/cluster.c @ 600

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

Cosmetic: improve debug.

File size: 22.9 KB
Line 
1/*
2 * cluster.c - Cluster-Manager related operations
3 *
4 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *         Mohamed Lamine Karaoui (2015)
6 *         Alain Greiner (2016,2017,2018)
7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH..
11 *
12 * ALMOS-MKH. is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH. is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <kernel_config.h>
27#include <hal_kernel_types.h>
28#include <hal_atomic.h>
29#include <hal_special.h>
30#include <hal_ppm.h>
31#include <hal_macros.h>
32#include <remote_fifo.h>
33#include <printk.h>
34#include <errno.h>
35#include <queuelock.h>
36#include <core.h>
37#include <chdev.h>
38#include <scheduler.h>
39#include <list.h>
40#include <cluster.h>
41#include <boot_info.h>
42#include <bits.h>
43#include <ppm.h>
44#include <thread.h>
45#include <kmem.h>
46#include <process.h>
47#include <dqdt.h>
48
49/////////////////////////////////////////////////////////////////////////////////////
50// Extern global variables
51/////////////////////////////////////////////////////////////////////////////////////
52
53extern process_t           process_zero;     // allocated in kernel_init.c
54extern chdev_directory_t   chdev_dir;        // allocated in kernel_init.c
55
56
57
58///////////////////////////////////////////////////
59void cluster_info_init( struct boot_info_s * info )
60{
61    boot_device_t * dev;      // pointer on external peripheral
62    uint32_t        func;     // external peripheral functionnal type
63    uint32_t        x;
64    uint32_t        y;
65    uint32_t        i;   
66
67        cluster_t * cluster = LOCAL_CLUSTER;
68
69    // initialize cluster global parameters
70        cluster->paddr_width     = info->paddr_width;
71        cluster->x_width         = info->x_width;
72        cluster->y_width         = info->y_width;
73        cluster->x_size          = info->x_size;
74        cluster->y_size          = info->y_size;
75        cluster->io_cxy          = info->io_cxy;
76
77    // initialize the cluster_info[][] array
78    for (x = 0; x < CONFIG_MAX_CLUSTERS_X; x++) 
79    {
80        for (y = 0; y < CONFIG_MAX_CLUSTERS_Y;y++) 
81        {
82            cluster->cluster_info[x][y] = info->cluster_info[x][y];
83        }
84    }
85
86    // initialize external peripherals channels
87    for( i = 0 ; i < info->ext_dev_nr ; i++ )
88    {
89        dev  = &info->ext_dev[i];
90        func = FUNC_FROM_TYPE( dev->type );   
91        if( func == DEV_FUNC_TXT ) cluster->nb_txt_channels = dev->channels;
92        if( func == DEV_FUNC_NIC ) cluster->nb_nic_channels = dev->channels;
93        if( func == DEV_FUNC_IOC ) cluster->nb_ioc_channels = dev->channels;
94        if( func == DEV_FUNC_FBF ) cluster->nb_fbf_channels = dev->channels;
95    }
96
97    // initialize number of cores
98        cluster->cores_nr  = info->cores_nr;
99
100}  // end cluster_info_init()
101
102/////////////////////////////////////////////////////////
103error_t cluster_manager_init( struct boot_info_s * info )
104{
105    error_t         error;
106    lpid_t          lpid;     // local process_index
107    lid_t           lid;      // local core index
108
109        cluster_t * cluster = LOCAL_CLUSTER;
110
111    // initialize the lock protecting the embedded kcm allocator
112        busylock_init( &cluster->kcm_lock , LOCK_CLUSTER_KCM );
113
114#if DEBUG_CLUSTER_INIT
115uint32_t   cycle = (uint32_t)hal_get_cycles();
116thread_t * this  = CURRENT_THREAD;
117if( DEBUG_CLUSTER_INIT < cycle )
118printk("\n[%s] thread[%x,%x] enters for cluster %x / cycle %d\n",
119__FUNCTION__, this->process->pid, this->trdid, local_cxy , cycle );
120#endif
121
122    // initialises embedded PPM
123        error = hal_ppm_init( info );
124
125    if( error )
126    {
127        printk("\n[ERROR] in %s : cannot initialize PPM in cluster %x\n",
128               __FUNCTION__ , local_cxy );
129        return ENOMEM;
130    }
131
132#if( DEBUG_CLUSTER_INIT & 1 )
133cycle = (uint32_t)hal_get_cycles();
134if( DEBUG_CLUSTER_INIT < cycle )
135printk("\n[%s] PPM initialized in cluster %x / cycle %d\n",
136__FUNCTION__ , local_cxy , cycle );
137#endif
138
139    // initialises embedded KHM
140        khm_init( &cluster->khm );
141
142#if( DEBUG_CLUSTER_INIT & 1 )
143cycle = (uint32_t)hal_get_cycles();
144if( DEBUG_CLUSTER_INIT < cycle )
145printk("\n[%s] KHM initialized in cluster %x at cycle %d\n",
146__FUNCTION__ , local_cxy , hal_get_cycles() );
147#endif
148
149    // initialises embedded KCM
150        kcm_init( &cluster->kcm , KMEM_KCM );
151
152#if( DEBUG_CLUSTER_INIT & 1 )
153cycle = (uint32_t)hal_get_cycles();
154if( DEBUG_CLUSTER_INIT < cycle )
155printk("\n[%s] KCM initialized in cluster %x at cycle %d\n",
156__FUNCTION__ , local_cxy , hal_get_cycles() );
157#endif
158
159    // initialises all cores descriptors
160        for( lid = 0 ; lid < cluster->cores_nr; lid++ )
161        {
162                core_init( &cluster->core_tbl[lid],    // target core descriptor
163                       lid,                        // local core index
164                       info->core[lid].gid );      // gid from boot_info_t
165        }
166
167#if( DEBUG_CLUSTER_INIT & 1 )
168cycle = (uint32_t)hal_get_cycles();
169if( DEBUG_CLUSTER_INIT < cycle )
170printk("\n[%s] cores initialized in cluster %x / cycle %d\n",
171__FUNCTION__ , local_cxy , cycle );
172#endif
173
174    // initialises RPC FIFOs
175        for( lid = 0 ; lid < cluster->cores_nr; lid++ )
176    {
177            remote_fifo_init( &cluster->rpc_fifo[lid] );
178        cluster->rpc_threads[lid] = 0;
179    }
180
181#if( DEBUG_CLUSTER_INIT & 1 )
182cycle = (uint32_t)hal_get_cycles();
183if( DEBUG_CLUSTER_INIT < cycle )
184printk("\n[%s] RPC fifo inialized in cluster %x at cycle %d\n",
185__FUNCTION__ , local_cxy , hal_get_cycles() );
186#endif
187
188    // initialise pref_tbl[] in process manager
189        queuelock_init( &cluster->pmgr.pref_lock , LOCK_CLUSTER_PREFTBL );
190    cluster->pmgr.pref_nr = 0;
191    cluster->pmgr.pref_tbl[0] = XPTR( local_cxy , &process_zero );
192    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
193    {
194        cluster->pmgr.pref_tbl[lpid] = XPTR_NULL;
195    }
196
197    // initialise local_list in process manager
198    xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) );
199    cluster->pmgr.local_nr = 0;
200        remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) ,
201                           LOCK_CLUSTER_LOCALS );
202
203    // initialise copies_lists in process manager
204    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
205    {
206        cluster->pmgr.copies_nr[lpid] = 0;
207        xlist_root_init( XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ) );
208            remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ),
209                               LOCK_CLUSTER_COPIES );
210    }
211
212#if DEBUG_CLUSTER_INIT
213cycle = (uint32_t)hal_get_cycles();
214if( DEBUG_CLUSTER_INIT < cycle )
215printk("\n[%s] thread[%x,%x] exit for cluster %x / cycle %d\n",
216__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
217#endif
218
219    hal_fence();
220
221        return 0;
222} // end cluster_manager_init()
223
224///////////////////////////////////
225cxy_t cluster_random_select( void )
226{
227    uint32_t  index;
228    uint32_t  x;   
229    uint32_t  y;
230    cxy_t     cxy;
231
232    uint32_t  x_size    = LOCAL_CLUSTER->x_size;
233    uint32_t  y_size    = LOCAL_CLUSTER->y_size;
234
235    do 
236    {
237        index     = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size);
238        x         = index / y_size;
239        y         = index % y_size;
240        cxy       = HAL_CXY_FROM_XY( x , y );
241    }
242    while ( cluster_is_active( cxy ) == false );
243
244    return ( cxy );
245}
246
247////////////////////////////////////////
248bool_t cluster_is_undefined( cxy_t cxy )
249{
250    uint32_t  x_size = LOCAL_CLUSTER->x_size;
251    uint32_t  y_size = LOCAL_CLUSTER->y_size;
252
253    uint32_t  x      = HAL_X_FROM_CXY( cxy );
254    uint32_t  y      = HAL_Y_FROM_CXY( cxy );
255
256    if( x >= x_size ) return true;
257    if( y >= y_size ) return true;
258
259    return false;
260}
261
262//////////////////////////////////////
263bool_t cluster_is_active ( cxy_t cxy )
264{
265    uint32_t x = HAL_X_FROM_CXY( cxy );
266    uint32_t y = HAL_Y_FROM_CXY( cxy );
267
268    return ( LOCAL_CLUSTER->cluster_info[x][y] != 0 );
269}
270
271////////////////////////////////////////////////////////////////////////////////////
272//  Cores related functions
273////////////////////////////////////////////////////////////////////////////////////
274
275///////////////////////////////////////
276lid_t cluster_select_local_core( void )
277{
278    uint32_t      min = 1000;
279    lid_t         sel = 0;
280    uint32_t      nthreads;
281    lid_t         lid;
282    scheduler_t * sched;
283
284    cluster_t * cluster = LOCAL_CLUSTER;
285
286    for( lid = 0 ; lid < cluster->cores_nr ; lid++ )
287    {
288        sched    = &cluster->core_tbl[lid].scheduler;
289        nthreads = sched->u_threads_nr + sched->k_threads_nr;
290
291        if( nthreads < min )
292        {
293            min = nthreads;
294            sel = lid;
295        }
296    }
297    return sel;
298}
299
300////////////////////////////////////////////////////////////////////////////////////
301//  Process related functions
302////////////////////////////////////////////////////////////////////////////////////
303
304
305//////////////////////////////////////////////////////
306xptr_t cluster_get_process_from_pid_in_cxy( cxy_t cxy,
307                                            pid_t pid )
308{
309    xptr_t      root_xp;       // xptr on root of list of processes in owner cluster
310    xptr_t      lock_xp;       // xptr on lock protecting this list
311    xptr_t      iter_xp;       // iterator
312    xptr_t      current_xp;    // xptr on current process descriptor
313    bool_t      found;
314
315    cluster_t * cluster = LOCAL_CLUSTER;
316
317    // get owner cluster and lpid
318    cxy_t   owner_cxy = CXY_FROM_PID( pid );
319    lpid_t  lpid      = LPID_FROM_PID( pid );
320
321    // get lock & root of list of copies from owner cluster
322    root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
323    lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
324
325    // take the lock protecting the list of processes
326    remote_queuelock_acquire( lock_xp );
327
328    // scan list of processes
329    found = false;
330    XLIST_FOREACH( root_xp , iter_xp )
331    {
332        current_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
333
334        if( GET_CXY( current_xp ) == cxy )
335        {
336            found = true;
337            break;
338        }
339    }
340
341    // release the lock protecting the list of processes
342    remote_queuelock_release( lock_xp );
343
344    // return extended pointer on process descriptor in owner cluster
345    if( found ) return current_xp;
346    else        return XPTR_NULL;
347
348}  // end cluster_get_process_from_pid_in_cxy()
349
350
351//////////////////////////////////////////////////////
352xptr_t cluster_get_owner_process_from_pid( pid_t pid )
353{
354    xptr_t      root_xp;       // xptr on root of list of processes in owner cluster
355    xptr_t      lock_xp;       // xptr on lock protecting this list
356    xptr_t      iter_xp;       // iterator
357    xptr_t      current_xp;    // xptr on current process descriptor
358    process_t * current_ptr;   // local pointer on current process
359    pid_t       current_pid;   // current process identifier
360    bool_t      found;
361
362    cluster_t * cluster = LOCAL_CLUSTER;
363
364    // get owner cluster and lpid
365    cxy_t  owner_cxy = CXY_FROM_PID( pid );
366
367    // get lock & root of list of process in owner cluster
368    root_xp = XPTR( owner_cxy , &cluster->pmgr.local_root );
369    lock_xp = XPTR( owner_cxy , &cluster->pmgr.local_lock );
370
371    // take the lock protecting the list of processes
372    remote_queuelock_acquire( lock_xp );
373
374    // scan list of processes in owner cluster
375    found = false;
376    XLIST_FOREACH( root_xp , iter_xp )
377    {
378        current_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
379        current_ptr = GET_PTR( current_xp );
380        current_pid = hal_remote_l32( XPTR( owner_cxy , &current_ptr->pid ) );
381
382        if( current_pid == pid )
383        {
384            found = true;
385            break;
386        }
387    }
388
389    // release the lock protecting the list of processes
390    remote_queuelock_release( lock_xp );
391
392    // return extended pointer on process descriptor in owner cluster
393    if( found ) return current_xp;
394    else        return XPTR_NULL;
395
396}  // end cluster_get_owner_process_from_pid()
397
398
399//////////////////////////////////////////////////////////
400xptr_t cluster_get_reference_process_from_pid( pid_t pid )
401{
402    xptr_t ref_xp;   // extended pointer on reference process descriptor
403
404    cluster_t * cluster = LOCAL_CLUSTER;
405
406    // get owner cluster and lpid
407    cxy_t  owner_cxy = CXY_FROM_PID( pid );
408    lpid_t lpid      = LPID_FROM_PID( pid );
409
410    // Check valid PID
411    if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER )  return XPTR_NULL;
412
413    if( local_cxy == owner_cxy )   // local cluster is owner cluster
414    {
415        ref_xp = cluster->pmgr.pref_tbl[lpid];
416    }
417    else                              // use a remote_lwd to access owner cluster
418    {
419        ref_xp = (xptr_t)hal_remote_l64( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );
420    }
421
422    return ref_xp;
423}
424
425///////////////////////////////////////////////
426error_t cluster_pid_alloc( process_t * process,
427                           pid_t     * pid )
428{
429    lpid_t      lpid;
430    bool_t      found;
431
432#if DEBUG_CLUSTER_PID_ALLOC
433uint32_t   cycle = (uint32_t)hal_get_cycles();
434thread_t * this  = CURRENT_THREAD;
435if( DEBUG_CLUSTER_PID_ALLOC < cycle )
436printk("\n[%s] thread[%x,%x] enters in cluster %x / cycle %d\n",
437__FUNCTION__ , this->process->pid , this->trdid , local_cxy , cycle );
438#endif
439
440    pmgr_t    * pm         = &LOCAL_CLUSTER->pmgr;
441
442    // get the lock protecting pref_tbl
443    queuelock_acquire( &pm->pref_lock );
444
445    // search an empty slot
446    found = false;
447    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
448    {
449        if( pm->pref_tbl[lpid] == XPTR_NULL )
450        {
451            found = true;
452            break;
453        }
454    }
455
456    if( found )
457    {
458        // register process in pref_tbl[]
459        pm->pref_tbl[lpid] = XPTR( local_cxy , process );
460        pm->pref_nr++;
461
462        // returns pid
463        *pid = PID( local_cxy , lpid );
464
465        // release the processs_manager lock
466        queuelock_release( &pm->pref_lock );
467
468        return 0;
469    }
470    else
471    {
472        // release the lock
473        queuelock_release( &pm->pref_lock );
474
475        return 0xFFFFFFFF;
476    }
477
478#if DEBUG_CLUSTER_PID_ALLOC
479cycle = (uint32_t)hal_get_cycles();
480if( DEBUG_CLUSTER_PID_ALLOC < cycle )
481printk("\n[%s] thread[%x,%x] exit in cluster %x / cycle %d\n",
482__FUNCTION__ , this->process->pid , this->trdid , local_cxy , cycle );
483#endif
484
485} // end cluster_pid_alloc()
486
487/////////////////////////////////////
488void cluster_pid_release( pid_t pid )
489{
490
491#if DEBUG_CLUSTER_PID_RELEASE
492uint32_t   cycle = (uint32_t)hal_get_cycles();
493thread_t * this  = CURRENT_THREAD;
494if( DEBUG_CLUSTER_PID_ALLOC < cycle )
495printk("\n[%s] thread[%x,%x] enters in cluster %x / pid %x / cycle %d\n",
496__FUNCTION__ , this->process->pid , this->trdid , local_cxy , pid, cycle );
497#endif
498
499    cxy_t  owner_cxy  = CXY_FROM_PID( pid );
500    lpid_t lpid       = LPID_FROM_PID( pid );
501
502    pmgr_t  * pm = &LOCAL_CLUSTER->pmgr;
503
504    // check lpid
505    assert( (lpid < CONFIG_MAX_PROCESS_PER_CLUSTER),
506    "illegal LPID = %d" , lpid );
507
508    // check owner cluster
509    assert( (owner_cxy == local_cxy) ,
510    "local_cluster %x !=  owner_cluster %x" , local_cxy , owner_cxy );
511
512    // get the lock protecting pref_tbl
513    queuelock_acquire( &pm->pref_lock );
514
515    // remove process from pref_tbl[]
516    pm->pref_tbl[lpid] = XPTR_NULL;
517    pm->pref_nr--;
518
519    // release the processs_manager lock
520    queuelock_release( &pm->pref_lock );
521
522#if DEBUG_CLUSTER_PID_RELEASE
523cycle = (uint32_t)hal_get_cycles();
524if( DEBUG_CLUSTER_PID_ALLOC < cycle )
525printk("\n[%s] thread[%x,%x] exit in cluster %x / cycle %d\n",
526__FUNCTION__ , this->process->pid , this->trdid , local_cxy , cycle );
527#endif
528
529} // end cluster_pid_release()
530
531///////////////////////////////////////////////////////////
532process_t * cluster_get_local_process_from_pid( pid_t pid )
533{
534    xptr_t         process_xp;
535    process_t    * process_ptr;
536    xptr_t         root_xp;
537    xptr_t         iter_xp;
538    bool_t         found;
539
540    found   = false;
541    root_xp = XPTR( local_cxy , &LOCAL_CLUSTER->pmgr.local_root );
542
543    XLIST_FOREACH( root_xp , iter_xp )
544    {
545        process_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
546        process_ptr = (process_t *)GET_PTR( process_xp );
547        if( process_ptr->pid == pid )
548        {
549            found = true;
550            break;
551        }
552    }
553
554    if (found ) return process_ptr;
555    else        return NULL;
556
557}  // end cluster_get_local_process_from_pid()
558
559//////////////////////////////////////////////////////
560void cluster_process_local_link( process_t * process )
561{
562    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
563
564    // get extended pointers on local process list root & lock
565    xptr_t root_xp = XPTR( local_cxy , &pm->local_root );
566    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
567
568    // get lock protecting the local list
569    remote_queuelock_acquire( lock_xp );
570
571    // register process in local list
572    xlist_add_last( root_xp , XPTR( local_cxy , &process->local_list ) );
573    pm->local_nr++;
574
575    // release lock protecting the local list
576    remote_queuelock_release( lock_xp );
577}
578
579////////////////////////////////////////////////////////
580void cluster_process_local_unlink( process_t * process )
581{
582    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
583
584    // get extended pointers on local process list lock
585    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
586
587    // get lock protecting the local list
588    remote_queuelock_acquire( lock_xp );
589
590    // remove process from local list
591    xlist_unlink( XPTR( local_cxy , &process->local_list ) );
592    pm->local_nr--;
593
594    // release lock protecting the local list
595    remote_queuelock_release( lock_xp );
596}
597
598///////////////////////////////////////////////////////
599void cluster_process_copies_link( process_t * process )
600{
601    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
602
603#if DEBUG_CLUSTER_PROCESS_COPIES
604uint32_t   cycle = (uint32_t)hal_get_cycles();
605thread_t * this  = CURRENT_THREAD;
606if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
607printk("\n[%s] thread[%x,%x] enters for process %x / cycle %d\n",
608__FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle );
609#endif
610
611    // get owner cluster identifier CXY and process LPID
612    pid_t    pid        = process->pid;
613    cxy_t    owner_cxy  = CXY_FROM_PID( pid );
614    lpid_t   lpid       = LPID_FROM_PID( pid );
615
616    // get extended pointer on lock protecting copies_list[lpid]
617    xptr_t copies_lock  = XPTR( owner_cxy , &pm->copies_lock[lpid] );
618
619    // get extended pointer on the copies_list[lpid] root
620    xptr_t copies_root  = XPTR( owner_cxy , &pm->copies_root[lpid] );
621
622    // get extended pointer on the local copies_list entry
623    xptr_t copies_entry = XPTR( local_cxy , &process->copies_list );
624
625    // get lock protecting copies_list[lpid]
626    remote_queuelock_acquire( copies_lock );
627
628    // add copy to copies_list
629    xlist_add_first( copies_root , copies_entry );
630    hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , 1 );
631
632    // release lock protecting copies_list[lpid]
633    remote_queuelock_release( copies_lock );
634
635#if DEBUG_CLUSTER_PROCESS_COPIES
636cycle = (uint32_t)hal_get_cycles();
637if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
638printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n",
639__FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle );
640#endif
641
642}  // end cluster_process_copies_link()
643
644/////////////////////////////////////////////////////////
645void cluster_process_copies_unlink( process_t * process )
646{
647    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
648
649#if DEBUG_CLUSTER_PROCESS_COPIES
650uint32_t   cycle = (uint32_t)hal_get_cycles();
651thread_t * this  = CURRENT_THREAD;
652if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
653printk("\n[%s] thread[%x,%x] enters for process %x / cycle %d\n",
654__FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle );
655#endif
656
657    // get owner cluster identifier CXY and process LPID
658    pid_t    pid        = process->pid;
659    cxy_t    owner_cxy  = CXY_FROM_PID( pid );
660    lpid_t   lpid       = LPID_FROM_PID( pid );
661
662    // get extended pointer on lock protecting copies_list[lpid]
663    xptr_t copies_lock  = XPTR( owner_cxy , &pm->copies_lock[lpid] );
664
665    // get extended pointer on the local copies_list entry
666    xptr_t copies_entry = XPTR( local_cxy , &process->copies_list );
667
668    // get lock protecting copies_list[lpid]
669    remote_queuelock_acquire( copies_lock );
670
671    // remove copy from copies_list
672    xlist_unlink( copies_entry );
673    hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , -1 );
674
675    // release lock protecting copies_list[lpid]
676    remote_queuelock_release( copies_lock );
677
678#if DEBUG_CLUSTER_PROCESS_COPIES
679cycle = (uint32_t)hal_get_cycles();
680if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
681printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n",
682__FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle );
683#endif
684
685}  // end cluster_process_copies_unlink()
686
687////////////////////////////////////////////
688void cluster_processes_display( cxy_t   cxy,
689                                bool_t  owned )
690{
691    xptr_t        root_xp;
692    xptr_t        lock_xp;
693    xptr_t        iter_xp;
694    xptr_t        process_xp;
695    process_t   * process_ptr;
696    cxy_t         process_cxy;
697    pid_t         pid;
698    cxy_t         txt0_cxy;
699    chdev_t     * txt0_ptr;
700    xptr_t        txt0_xp;
701    xptr_t        txt0_lock_xp;
702
703assert( (cluster_is_undefined( cxy ) == false), "illegal cluster index" );
704
705    // get extended pointer on root and lock for local process list in cluster
706    root_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_root );
707    lock_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_lock );
708
709    // get pointers on TXT0 chdev
710    txt0_xp  = chdev_dir.txt_tx[0];
711    txt0_cxy = GET_CXY( txt0_xp );
712    txt0_ptr = GET_PTR( txt0_xp );
713
714    // get extended pointer on TXT0 lock
715    txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
716
717    // get lock on local process list
718    remote_queuelock_acquire( lock_xp );
719
720    // get TXT0 lock
721    remote_busylock_acquire( txt0_lock_xp );
722     
723    // display header
724    nolock_printk("\n***** processes in cluster %x / cycle %d\n",
725    cxy , (uint32_t)hal_get_cycles() );
726
727    // loop on all processes in cluster cxy
728    XLIST_FOREACH( root_xp , iter_xp )
729    {
730        process_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
731        process_ptr = GET_PTR( process_xp );
732        process_cxy = GET_CXY( process_xp );
733
734        // get process PID
735        pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
736
737        if( owned )  // display only user & owned processes
738        {
739            if( (CXY_FROM_PID( pid ) == cxy) && (LPID_FROM_PID( pid ) != 0) )
740            {
741                process_display( process_xp );
742            }
743        }
744        else         // display all local processes
745        {
746            process_display( process_xp );
747        }
748    }
749
750    // release TXT0 lock
751    remote_busylock_release( txt0_lock_xp );
752
753    // release lock on local process list
754    remote_queuelock_release( lock_xp );
755
756}  // end cluster_processes_display()
757
758
Note: See TracBrowser for help on using the repository browser.