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

Last change on this file since 586 was 583, checked in by alain, 6 years ago

Improve signals.

File size: 22.6 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();
116if( DEBUG_CLUSTER_INIT < cycle )
117printk("\n[DBG] %s : thread %x in process %x enters for cluster %x / cycle %d\n",
118__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, local_cxy , cycle );
119#endif
120
121    // initialises embedded PPM
122        error = hal_ppm_init( info );
123
124    if( error )
125    {
126        printk("\n[ERROR] in %s : cannot initialize PPM in cluster %x\n",
127               __FUNCTION__ , local_cxy );
128        return ENOMEM;
129    }
130
131#if( DEBUG_CLUSTER_INIT & 1 )
132cycle = (uint32_t)hal_get_cycles();
133if( DEBUG_CLUSTER_INIT < cycle )
134printk("\n[DBG] %s : PPM initialized in cluster %x / cycle %d\n",
135__FUNCTION__ , local_cxy , cycle );
136#endif
137
138    // initialises embedded KHM
139        khm_init( &cluster->khm );
140
141#if( DEBUG_CLUSTER_INIT & 1 )
142cycle = (uint32_t)hal_get_cycles();
143if( DEBUG_CLUSTER_INIT < cycle )
144printk("\n[DBG] %s : KHM initialized in cluster %x at cycle %d\n",
145__FUNCTION__ , local_cxy , hal_get_cycles() );
146#endif
147
148    // initialises embedded KCM
149        kcm_init( &cluster->kcm , KMEM_KCM );
150
151#if( DEBUG_CLUSTER_INIT & 1 )
152cycle = (uint32_t)hal_get_cycles();
153if( DEBUG_CLUSTER_INIT < cycle )
154printk("\n[DBG] %s : KCM initialized in cluster %x at cycle %d\n",
155__FUNCTION__ , local_cxy , hal_get_cycles() );
156#endif
157
158    // initialises all cores descriptors
159        for( lid = 0 ; lid < cluster->cores_nr; lid++ )
160        {
161                core_init( &cluster->core_tbl[lid],    // target core descriptor
162                       lid,                        // local core index
163                       info->core[lid].gid );      // gid from boot_info_t
164        }
165
166#if( DEBUG_CLUSTER_INIT & 1 )
167cycle = (uint32_t)hal_get_cycles();
168if( DEBUG_CLUSTER_INIT < cycle )
169printk("\n[DBG] %s : cores initialized in cluster %x / cycle %d\n",
170__FUNCTION__ , local_cxy , cycle );
171#endif
172
173    // initialises RPC FIFOs
174        for( lid = 0 ; lid < cluster->cores_nr; lid++ )
175    {
176            remote_fifo_init( &cluster->rpc_fifo[lid] );
177        cluster->rpc_threads[lid] = 0;
178    }
179
180#if( DEBUG_CLUSTER_INIT & 1 )
181cycle = (uint32_t)hal_get_cycles();
182if( DEBUG_CLUSTER_INIT < cycle )
183printk("\n[DBG] %s : RPC fifo inialized in cluster %x at cycle %d\n",
184__FUNCTION__ , local_cxy , hal_get_cycles() );
185#endif
186
187    // initialise pref_tbl[] in process manager
188        queuelock_init( &cluster->pmgr.pref_lock , LOCK_CLUSTER_PREFTBL );
189    cluster->pmgr.pref_nr = 0;
190    cluster->pmgr.pref_tbl[0] = XPTR( local_cxy , &process_zero );
191    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
192    {
193        cluster->pmgr.pref_tbl[lpid] = XPTR_NULL;
194    }
195
196    // initialise local_list in process manager
197    xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) );
198    cluster->pmgr.local_nr = 0;
199        remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) ,
200                           LOCK_CLUSTER_LOCALS );
201
202    // initialise copies_lists in process manager
203    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
204    {
205        cluster->pmgr.copies_nr[lpid] = 0;
206        xlist_root_init( XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ) );
207            remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ),
208                               LOCK_CLUSTER_COPIES );
209    }
210
211#if DEBUG_CLUSTER_INIT
212cycle = (uint32_t)hal_get_cycles();
213if( DEBUG_CLUSTER_INIT < cycle )
214printk("\n[DBG] %s : thread %x in process %x exit for cluster %x / cycle %d\n",
215__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid , local_cxy , cycle );
216#endif
217
218    hal_fence();
219
220        return 0;
221} // end cluster_manager_init()
222
223///////////////////////////////////
224cxy_t cluster_random_select( void )
225{
226    uint32_t  index;
227    uint32_t  x;   
228    uint32_t  y;
229    cxy_t     cxy;
230
231    uint32_t  x_size    = LOCAL_CLUSTER->x_size;
232    uint32_t  y_size    = LOCAL_CLUSTER->y_size;
233
234    do 
235    {
236        index     = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size);
237        x         = index / y_size;
238        y         = index % y_size;
239        cxy       = HAL_CXY_FROM_XY( x , y );
240    }
241    while ( cluster_is_active( cxy ) == false );
242
243    return ( cxy );
244}
245
246////////////////////////////////////////
247bool_t cluster_is_undefined( cxy_t cxy )
248{
249    uint32_t  x_size = LOCAL_CLUSTER->x_size;
250    uint32_t  y_size = LOCAL_CLUSTER->y_size;
251
252    uint32_t  x      = HAL_X_FROM_CXY( cxy );
253    uint32_t  y      = HAL_Y_FROM_CXY( cxy );
254
255    if( x >= x_size ) return true;
256    if( y >= y_size ) return true;
257
258    return false;
259}
260
261//////////////////////////////////////
262bool_t cluster_is_active ( cxy_t cxy )
263{
264    uint32_t x = HAL_X_FROM_CXY( cxy );
265    uint32_t y = HAL_Y_FROM_CXY( cxy );
266
267    return ( LOCAL_CLUSTER->cluster_info[x][y] != 0 );
268}
269
270////////////////////////////////////////////////////////////////////////////////////
271//  Cores related functions
272////////////////////////////////////////////////////////////////////////////////////
273
274///////////////////////////////////////
275lid_t cluster_select_local_core( void )
276{
277    uint32_t      min = 1000;
278    lid_t         sel = 0;
279    uint32_t      nthreads;
280    lid_t         lid;
281    scheduler_t * sched;
282
283    cluster_t * cluster = LOCAL_CLUSTER;
284
285    for( lid = 0 ; lid < cluster->cores_nr ; lid++ )
286    {
287        sched    = &cluster->core_tbl[lid].scheduler;
288        nthreads = sched->u_threads_nr + sched->k_threads_nr;
289
290        if( nthreads < min )
291        {
292            min = nthreads;
293            sel = lid;
294        }
295    }
296    return sel;
297}
298
299////////////////////////////////////////////////////////////////////////////////////
300//  Process related functions
301////////////////////////////////////////////////////////////////////////////////////
302
303
304//////////////////////////////////////////////////////
305xptr_t cluster_get_process_from_pid_in_cxy( cxy_t cxy,
306                                            pid_t pid )
307{
308    xptr_t      root_xp;       // xptr on root of list of processes in owner cluster
309    xptr_t      lock_xp;       // xptr on lock protecting this list
310    xptr_t      iter_xp;       // iterator
311    xptr_t      current_xp;    // xptr on current process descriptor
312    bool_t      found;
313
314    cluster_t * cluster = LOCAL_CLUSTER;
315
316    // get owner cluster and lpid
317    cxy_t   owner_cxy = CXY_FROM_PID( pid );
318    lpid_t  lpid      = LPID_FROM_PID( pid );
319
320    // get lock & root of list of copies from owner cluster
321    root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
322    lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
323
324    // take the lock protecting the list of processes
325    remote_queuelock_acquire( lock_xp );
326
327    // scan list of processes
328    found = false;
329    XLIST_FOREACH( root_xp , iter_xp )
330    {
331        current_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
332
333        if( GET_CXY( current_xp ) == cxy )
334        {
335            found = true;
336            break;
337        }
338    }
339
340    // release the lock protecting the list of processes
341    remote_queuelock_release( lock_xp );
342
343    // return extended pointer on process descriptor in owner cluster
344    if( found ) return current_xp;
345    else        return XPTR_NULL;
346
347}  // end cluster_get_process_from_pid_in_cxy()
348
349
350//////////////////////////////////////////////////////
351xptr_t cluster_get_owner_process_from_pid( pid_t pid )
352{
353    xptr_t      root_xp;       // xptr on root of list of processes in owner cluster
354    xptr_t      lock_xp;       // xptr on lock protecting this list
355    xptr_t      iter_xp;       // iterator
356    xptr_t      current_xp;    // xptr on current process descriptor
357    process_t * current_ptr;   // local pointer on current process
358    pid_t       current_pid;   // current process identifier
359    bool_t      found;
360
361    cluster_t * cluster = LOCAL_CLUSTER;
362
363    // get owner cluster and lpid
364    cxy_t  owner_cxy = CXY_FROM_PID( pid );
365
366    // get lock & root of list of process in owner cluster
367    root_xp = XPTR( owner_cxy , &cluster->pmgr.local_root );
368    lock_xp = XPTR( owner_cxy , &cluster->pmgr.local_lock );
369
370    // take the lock protecting the list of processes
371    remote_queuelock_acquire( lock_xp );
372
373    // scan list of processes in owner cluster
374    found = false;
375    XLIST_FOREACH( root_xp , iter_xp )
376    {
377        current_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
378        current_ptr = GET_PTR( current_xp );
379        current_pid = hal_remote_l32( XPTR( owner_cxy , &current_ptr->pid ) );
380
381        if( current_pid == pid )
382        {
383            found = true;
384            break;
385        }
386    }
387
388    // release the lock protecting the list of processes
389    remote_queuelock_release( lock_xp );
390
391    // return extended pointer on process descriptor in owner cluster
392    if( found ) return current_xp;
393    else        return XPTR_NULL;
394
395}  // end cluster_get_owner_process_from_pid()
396
397
398//////////////////////////////////////////////////////////
399xptr_t cluster_get_reference_process_from_pid( pid_t pid )
400{
401    xptr_t ref_xp;   // extended pointer on reference process descriptor
402
403    cluster_t * cluster = LOCAL_CLUSTER;
404
405    // get owner cluster and lpid
406    cxy_t  owner_cxy = CXY_FROM_PID( pid );
407    lpid_t lpid      = LPID_FROM_PID( pid );
408
409    // Check valid PID
410    if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER )  return XPTR_NULL;
411
412    if( local_cxy == owner_cxy )   // local cluster is owner cluster
413    {
414        ref_xp = cluster->pmgr.pref_tbl[lpid];
415    }
416    else                              // use a remote_lwd to access owner cluster
417    {
418        ref_xp = (xptr_t)hal_remote_l64( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );
419    }
420
421    return ref_xp;
422}
423
424///////////////////////////////////////////////
425error_t cluster_pid_alloc( process_t * process,
426                           pid_t     * pid )
427{
428    lpid_t      lpid;
429    bool_t      found;
430
431#if DEBUG_CLUSTER_PID_ALLOC
432uint32_t cycle = (uint32_t)hal_get_cycles();
433if( DEBUG_CLUSTER_PID_ALLOC < cycle )
434printk("\n[DBG] %s : thread %x enters in cluster %x / cycle %d\n",
435__FUNCTION__ , CURRENT_THREAD , local_cxy , cycle );
436#endif
437
438    pmgr_t    * pm         = &LOCAL_CLUSTER->pmgr;
439
440    // get the lock protecting pref_tbl
441    queuelock_acquire( &pm->pref_lock );
442
443    // search an empty slot
444    found = false;
445    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
446    {
447        if( pm->pref_tbl[lpid] == XPTR_NULL )
448        {
449            found = true;
450            break;
451        }
452    }
453
454    if( found )
455    {
456        // register process in pref_tbl[]
457        pm->pref_tbl[lpid] = XPTR( local_cxy , process );
458        pm->pref_nr++;
459
460        // returns pid
461        *pid = PID( local_cxy , lpid );
462
463        // release the processs_manager lock
464        queuelock_release( &pm->pref_lock );
465
466        return 0;
467    }
468    else
469    {
470        // release the lock
471        queuelock_release( &pm->pref_lock );
472
473        return 0xFFFFFFFF;
474    }
475
476#if DEBUG_CLUSTER_PID_ALLOC
477cycle = (uint32_t)hal_get_cycles();
478if( DEBUG_CLUSTER_PID_ALLOC < cycle )
479printk("\n[DBG] %s : thread %x exit in cluster %x / pid %x / cycle %d\n",
480__FUNCTION__ , CURRENT_THREAD , local_cxy , *pid , cycle );
481#endif
482
483} // end cluster_pid_alloc()
484
485/////////////////////////////////////
486void cluster_pid_release( pid_t pid )
487{
488
489#if DEBUG_CLUSTER_PID_RELEASE
490uint32_t cycle = (uint32_t)hal_get_cycles();
491if( DEBUG_CLUSTER_PID_RELEASE < cycle )
492printk("\n[DBG] %s : thread %x enters in cluster %x / pid %x / cycle %d\n",
493__FUNCTION__ , CURRENT_THREAD , local_cxy , pid , cycle );
494#endif
495
496    cxy_t  owner_cxy  = CXY_FROM_PID( pid );
497    lpid_t lpid       = LPID_FROM_PID( pid );
498
499    pmgr_t  * pm = &LOCAL_CLUSTER->pmgr;
500
501    // check lpid
502    assert( (lpid < CONFIG_MAX_PROCESS_PER_CLUSTER),
503    "illegal LPID = %d" , lpid );
504
505    // check owner cluster
506    assert( (owner_cxy == local_cxy) ,
507    "local_cluster %x !=  owner_cluster %x" , local_cxy , owner_cxy );
508
509    // get the lock protecting pref_tbl
510    queuelock_acquire( &pm->pref_lock );
511
512    // remove process from pref_tbl[]
513    pm->pref_tbl[lpid] = XPTR_NULL;
514    pm->pref_nr--;
515
516    // release the processs_manager lock
517    queuelock_release( &pm->pref_lock );
518
519#if DEBUG_CLUSTER_PID_RELEASE
520cycle = (uint32_t)hal_get_cycles();
521if( DEBUG_CLUSTER_PID_RELEASE < cycle )
522printk("\n[DBG] %s : thread %x exit in cluster %x / cycle %d\n",
523__FUNCTION__ , CURRENT_THREAD , local_cxy , cycle );
524#endif
525
526} // end cluster_pid_release()
527
528///////////////////////////////////////////////////////////
529process_t * cluster_get_local_process_from_pid( pid_t pid )
530{
531    xptr_t         process_xp;
532    process_t    * process_ptr;
533    xptr_t         root_xp;
534    xptr_t         iter_xp;
535    bool_t         found;
536
537    found   = false;
538    root_xp = XPTR( local_cxy , &LOCAL_CLUSTER->pmgr.local_root );
539
540    XLIST_FOREACH( root_xp , iter_xp )
541    {
542        process_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
543        process_ptr = (process_t *)GET_PTR( process_xp );
544        if( process_ptr->pid == pid )
545        {
546            found = true;
547            break;
548        }
549    }
550
551    if (found ) return process_ptr;
552    else        return NULL;
553
554}  // end cluster_get_local_process_from_pid()
555
556//////////////////////////////////////////////////////
557void cluster_process_local_link( process_t * process )
558{
559    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
560
561    // get extended pointers on local process list root & lock
562    xptr_t root_xp = XPTR( local_cxy , &pm->local_root );
563    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
564
565    // get lock protecting the local list
566    remote_queuelock_acquire( lock_xp );
567
568    // register process in local list
569    xlist_add_last( root_xp , XPTR( local_cxy , &process->local_list ) );
570    pm->local_nr++;
571
572    // release lock protecting the local list
573    remote_queuelock_release( lock_xp );
574}
575
576////////////////////////////////////////////////////////
577void cluster_process_local_unlink( process_t * process )
578{
579    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
580
581    // get extended pointers on local process list lock
582    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
583
584    // get lock protecting the local list
585    remote_queuelock_acquire( lock_xp );
586
587    // remove process from local list
588    xlist_unlink( XPTR( local_cxy , &process->local_list ) );
589    pm->local_nr--;
590
591    // release lock protecting the local list
592    remote_queuelock_release( lock_xp );
593}
594
595///////////////////////////////////////////////////////
596void cluster_process_copies_link( process_t * process )
597{
598    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
599
600#if DEBUG_CLUSTER_PROCESS_COPIES
601uint32_t cycle = (uint32_t)hal_get_cycles();
602if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
603printk("\n[DBG] %s enters / cluster %x / process %x / cycle %d\n",
604__FUNCTION__ , local_cxy , process , cycle );
605#endif
606
607    // get owner cluster identifier CXY and process LPID
608    pid_t    pid        = process->pid;
609    cxy_t    owner_cxy  = CXY_FROM_PID( pid );
610    lpid_t   lpid       = LPID_FROM_PID( pid );
611
612    // get extended pointer on lock protecting copies_list[lpid]
613    xptr_t copies_lock  = XPTR( owner_cxy , &pm->copies_lock[lpid] );
614
615    // get extended pointer on the copies_list[lpid] root
616    xptr_t copies_root  = XPTR( owner_cxy , &pm->copies_root[lpid] );
617
618    // get extended pointer on the local copies_list entry
619    xptr_t copies_entry = XPTR( local_cxy , &process->copies_list );
620
621    // get lock protecting copies_list[lpid]
622    remote_queuelock_acquire( copies_lock );
623
624    // add copy to copies_list
625    xlist_add_first( copies_root , copies_entry );
626    hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , 1 );
627
628    // release lock protecting copies_list[lpid]
629    remote_queuelock_release( copies_lock );
630
631#if DEBUG_CLUSTER_PROCESS_COPIES
632cycle = (uint32_t)hal_get_cycles();
633if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
634printk("\n[DBG] %s exit / cluster %x / process %x / cycle %d\n",
635__FUNCTION__ , local_cxy , process , cycle );
636#endif
637
638}  // end cluster_process_copies_link()
639
640/////////////////////////////////////////////////////////
641void cluster_process_copies_unlink( process_t * process )
642{
643    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
644
645#if DEBUG_CLUSTER_PROCESS_COPIES
646uint32_t cycle = (uint32_t)hal_get_cycles();
647if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
648printk("\n[DBG] %s enters / cluster %x / process %x / cycle %d\n",
649__FUNCTION__ , local_cxy , process , cycle );
650#endif
651
652    // get owner cluster identifier CXY and process LPID
653    pid_t    pid        = process->pid;
654    cxy_t    owner_cxy  = CXY_FROM_PID( pid );
655    lpid_t   lpid       = LPID_FROM_PID( pid );
656
657    // get extended pointer on lock protecting copies_list[lpid]
658    xptr_t copies_lock  = XPTR( owner_cxy , &pm->copies_lock[lpid] );
659
660    // get extended pointer on the local copies_list entry
661    xptr_t copies_entry = XPTR( local_cxy , &process->copies_list );
662
663    // get lock protecting copies_list[lpid]
664    remote_queuelock_acquire( copies_lock );
665
666    // remove copy from copies_list
667    xlist_unlink( copies_entry );
668    hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , -1 );
669
670    // release lock protecting copies_list[lpid]
671    remote_queuelock_release( copies_lock );
672
673#if DEBUG_CLUSTER_PROCESS_COPIES
674cycle = (uint32_t)hal_get_cycles();
675if( DEBUG_CLUSTER_PROCESS_COPIES < cycle )
676printk("\n[DBG] %s exit / cluster %x / process %x / cycle %d\n",
677__FUNCTION__ , local_cxy , process , cycle );
678#endif
679
680}  // end cluster_process_copies_unlink()
681
682////////////////////////////////////////////
683void cluster_processes_display( cxy_t   cxy,
684                                bool_t  owned )
685{
686    xptr_t        root_xp;
687    xptr_t        lock_xp;
688    xptr_t        iter_xp;
689    xptr_t        process_xp;
690    process_t   * process_ptr;
691    cxy_t         process_cxy;
692    pid_t         pid;
693    cxy_t         txt0_cxy;
694    chdev_t     * txt0_ptr;
695    xptr_t        txt0_xp;
696    xptr_t        txt0_lock_xp;
697
698assert( (cluster_is_undefined( cxy ) == false), "illegal cluster index" );
699
700    // get extended pointer on root and lock for local process list in cluster
701    root_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_root );
702    lock_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_lock );
703
704    // get pointers on TXT0 chdev
705    txt0_xp  = chdev_dir.txt_tx[0];
706    txt0_cxy = GET_CXY( txt0_xp );
707    txt0_ptr = GET_PTR( txt0_xp );
708
709    // get extended pointer on TXT0 lock
710    txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
711
712    // get lock on local process list
713    remote_queuelock_acquire( lock_xp );
714
715    // get TXT0 lock
716    remote_busylock_acquire( txt0_lock_xp );
717     
718    // display header
719    nolock_printk("\n***** processes in cluster %x / cycle %d\n",
720    cxy , (uint32_t)hal_get_cycles() );
721
722    // loop on all processes in cluster cxy
723    XLIST_FOREACH( root_xp , iter_xp )
724    {
725        process_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
726        process_ptr = GET_PTR( process_xp );
727        process_cxy = GET_CXY( process_xp );
728
729        // get process PID
730        pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
731
732        if( owned )  // display only user & owned processes
733        {
734            if( (CXY_FROM_PID( pid ) == cxy) && (LPID_FROM_PID( pid ) != 0) )
735            {
736                process_display( process_xp );
737            }
738        }
739        else         // display all local processes
740        {
741            process_display( process_xp );
742        }
743    }
744
745    // release TXT0 lock
746    remote_busylock_release( txt0_lock_xp );
747
748    // release lock on local process list
749    remote_queuelock_release( lock_xp );
750
751}  // end cluster_processes_display()
752
753
Note: See TracBrowser for help on using the repository browser.