source: trunk/kernel/kern/scheduler.c @ 619

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

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


File size: 25.7 KB
RevLine 
[1]1/*
2 * scheduler.c - Core scheduler implementation.
3 *
[564]4 * Author    Alain Greiner (2016,2017,2018)
[1]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>
[407]26#include <hal_switch.h>
[1]27#include <hal_irqmask.h>
28#include <hal_context.h>
29#include <printk.h>
30#include <list.h>
[619]31#include <rpc.h>
[1]32#include <core.h>
33#include <thread.h>
[296]34#include <chdev.h>
[1]35#include <scheduler.h>
36
[443]37
[296]38///////////////////////////////////////////////////////////////////////////////////////////
[564]39//         global variables
[296]40///////////////////////////////////////////////////////////////////////////////////////////
[1]41
[564]42extern chdev_directory_t    chdev_dir;          // allocated in kernel_init.c
[583]43extern process_t            process_zero;       // allocated in kernel_init.c
[296]44
[564]45///////////////////////////////////////////////////////////////////////////////////////////
46//         private functions
47///////////////////////////////////////////////////////////////////////////////////////////
[443]48
[1]49
[564]50////////////////////////////////////////////////////////////////////////////////////////////
51// This static function does NOT modify the scheduler state.
52// It just select a thread in the list of attached threads, implementing the following
53// three steps policy:
54// 1) It scan the list of kernel threads, from the next thread after the last executed one,
55//    and returns the first runnable found : not IDLE, not blocked, client queue not empty.
56//    It can be the current thread.
57// 2) If no kernel thread found, it scan the list of user thread, from the next thread after
58//    the last executed one, and returns the first runable found : not blocked.
59//    It can be the current thread.
60// 3) If no runable thread found, it returns the idle thread.
61////////////////////////////////////////////////////////////////////////////////////////////
62// @ sched   : local pointer on scheduler.
63// @ returns pointer on selected thread descriptor
64////////////////////////////////////////////////////////////////////////////////////////////
[408]65thread_t * sched_select( scheduler_t * sched )
[1]66{
[408]67    thread_t     * thread;
68    list_entry_t * current;
69    list_entry_t * last;
[437]70    list_entry_t * root;
71    bool_t         done;
[450]72    uint32_t       count;
[1]73
[437]74    // first : scan the kernel threads list if not empty
[279]75    if( list_is_empty( &sched->k_root ) == false )
[1]76    {
[437]77        root    = &sched->k_root;
[279]78        last    = sched->k_last;
[450]79        done    = false;
80        count   = 0;
[437]81        current = last;
82
83        while( done == false )
[279]84        {
[450]85
[564]86// check kernel threads list
[583]87assert( (count < sched->k_threads_nr), "bad kernel threads list" );
[564]88
[279]89            // get next entry in kernel list
[437]90            current = current->next;
[1]91
[437]92            // check exit condition
93            if( current == last ) done = true;
94
[279]95            // skip the root that does not contain a thread
[437]96            if( current == root ) continue;
[450]97            else                  count++;
[1]98
[279]99            // get thread pointer for this entry
100            thread = LIST_ELEMENT( current , thread_t , sched_list );
[1]101
[450]102            // select kernel thread if non blocked and non THREAD_IDLE
[564]103            if( (thread->blocked == 0)  && (thread->type != THREAD_IDLE) ) return thread;
104
[437]105        } // end loop on kernel threads
[450]106    } // end kernel threads
[437]107
108    // second : scan the user threads list if not empty
[279]109    if( list_is_empty( &sched->u_root ) == false )
[1]110    {
[437]111        root    = &sched->u_root;
[279]112        last    = sched->u_last;
[450]113        done    = false;
114        count   = 0;
[437]115        current = last;
116
117        while( done == false )
[279]118        {
[450]119
[564]120// check user threads list
[583]121assert( (count < sched->u_threads_nr), "bad user threads list" );
[564]122
[279]123            // get next entry in user list
[437]124            current = current->next;
[1]125
[437]126            // check exit condition
127            if( current == last ) done = true;
128
[279]129            // skip the root that does not contain a thread
[437]130            if( current == root ) continue;
[450]131            else                  count++;
[1]132
[279]133            // get thread pointer for this entry
134            thread = LIST_ELEMENT( current , thread_t , sched_list );
[1]135
[450]136            // select thread if non blocked
[564]137            if( thread->blocked == 0 )  return thread;
138
[437]139        } // end loop on user threads
[450]140    } // end user threads
[1]141
[437]142    // third : return idle thread if no other runnable thread
[1]143    return sched->idle;
144
[296]145}  // end sched_select()
[1]146
[564]147////////////////////////////////////////////////////////////////////////////////////////////
[592]148// This static function is the only function that can actually delete a thread,
[619]149// (and the associated process descriptor if required).
150// It is private, because it is only called by the sched_yield() public function.
[564]151// It scan all threads attached to a given scheduler, and executes the relevant
[583]152// actions for two types of pending requests:
[592]153//
[564]154// - REQ_ACK : it checks that target thread is blocked, decrements the response counter
155//   to acknowledge the client thread, and reset the pending request.
[583]156// - REQ_DELETE : it removes the target thread from the process th_tbl[], remove it
157//   from the scheduler list, and release the memory allocated to thread descriptor.
158//   For an user thread, it destroys the process descriptor it the target thread is
159//   the last thread in the local process descriptor.
160//
161// Implementation note:
162// We use a while to scan the threads in scheduler lists, because some threads can
163// be destroyed, and we want not use a LIST_FOREACH()
[564]164////////////////////////////////////////////////////////////////////////////////////////////
165// @ core    : local pointer on the core descriptor.
166////////////////////////////////////////////////////////////////////////////////////////////
167static void sched_handle_signals( core_t * core )
[1]168{
[437]169
[1]170    list_entry_t * iter;
[440]171    list_entry_t * root;
[1]172    thread_t     * thread;
[428]173    process_t    * process;
[564]174    scheduler_t  * sched;
[583]175    uint32_t       threads_nr;   // number of threads in scheduler list
176    ltid_t         ltid;         // thread local index
177    uint32_t       count;        // number of threads in local process
[409]178
[440]179    // get pointer on scheduler
[564]180    sched = &core->scheduler;
[1]181
[593]182    /////////////// scan user threads to handle both ACK and DELETE requests
[440]183    root = &sched->u_root;
184    iter = root->next;
185    while( iter != root )
[1]186    {
[440]187        // get pointer on thread
[1]188        thread = LIST_ELEMENT( iter , thread_t , sched_list );
189
[440]190        // increment iterator
191        iter = iter->next;
192
[416]193        // handle REQ_ACK
194        if( thread->flags & THREAD_FLAG_REQ_ACK )
[408]195        {
[564]196
197// check thread blocked
[592]198assert( (thread->blocked & THREAD_BLOCKED_GLOBAL) , "thread not blocked" );
[416]199 
200            // decrement response counter
201            hal_atomic_add( thread->ack_rsp_count , -1 );
[408]202
[416]203            // reset REQ_ACK in thread descriptor
204            thread_reset_req_ack( thread );
[408]205        }
[416]206
[564]207        // handle REQ_DELETE only if target thread != calling thread
208        if( (thread->flags & THREAD_FLAG_REQ_DELETE) && (thread != CURRENT_THREAD) )
[416]209        {
[428]210            // get thread process descriptor
211            process = thread->process;
[416]212
[583]213            // get thread ltid
214            ltid = LTID_FROM_TRDID( thread->trdid);
[416]215
[593]216            // take the lock protecting sheduler state
217            busylock_acquire( &sched->lock );
218
[564]219            // update scheduler state
[583]220            threads_nr = sched->u_threads_nr;
[428]221            sched->u_threads_nr = threads_nr - 1;
[416]222            list_unlink( &thread->sched_list );
[450]223            if( sched->u_last == &thread->sched_list )
224            {
225                if( threads_nr == 1 ) 
226                {
227                    sched->u_last = NULL;
228                }
229                else if( sched->u_root.next == &thread->sched_list )
230                {
231                    sched->u_last = sched->u_root.pred;
232                }
233                else
234                {
235                    sched->u_last = sched->u_root.next;
236                }
237            }
[416]238
[593]239            // release the lock protecting sheduler state
240            busylock_release( &sched->lock );
241
[583]242// check th_nr value
[592]243assert( (process->th_nr > 0) , "process th_nr cannot be 0\n" );
[583]244
245            // remove thread from process th_tbl[]
246            process->th_tbl[ltid] = NULL;
[593]247            count = hal_atomic_add( &process->th_nr , - 1 );
[583]248 
249            // release memory allocated for thread descriptor
250            thread_destroy( thread );
251
[593]252            hal_fence();
253
[438]254#if DEBUG_SCHED_HANDLE_SIGNALS
[440]255uint32_t cycle = (uint32_t)hal_get_cycles();
[438]256if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
[610]257printk("\n[%s] thread[%x,%x] on core[%x,%d] deleted / cycle %d\n",
[583]258__FUNCTION__ , process->pid , thread->trdid , local_cxy , thread->core->lid , cycle );
[433]259#endif
[583]260            // destroy process descriptor if last thread
261            if( count == 1 ) 
[428]262            {
263                // delete process   
264                process_destroy( process );
265
[438]266#if DEBUG_SCHED_HANDLE_SIGNALS
[433]267cycle = (uint32_t)hal_get_cycles();
[438]268if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
[610]269printk("\n[%s] process %x in cluster %x deleted / cycle %d\n",
[443]270__FUNCTION__ , process->pid , local_cxy , cycle );
[433]271#endif
[428]272            }
[416]273        }
[583]274    }  // end user threads
275
276    ////// scan kernel threads for DELETE only
277    root = &sched->k_root;
278    iter = root->next;
279    while( iter != root )
280    {
281        // get pointer on thread
282        thread = LIST_ELEMENT( iter , thread_t , sched_list );
283
284        // increment iterator
285        iter = iter->next;
286
287        // handle REQ_DELETE only if target thread != calling thread
288        if( (thread->flags & THREAD_FLAG_REQ_DELETE) && (thread != CURRENT_THREAD) )
289        {
290
291// check process descriptor is local kernel process
292assert( ( thread->process == &process_zero ) , "illegal process descriptor\n");
293
294            // get thread ltid
295            ltid = LTID_FROM_TRDID( thread->trdid);
296
[593]297            // take the lock protecting sheduler state
298            busylock_acquire( &sched->lock );
299
[583]300            // update scheduler state
301            threads_nr = sched->k_threads_nr;
302            sched->k_threads_nr = threads_nr - 1;
303            list_unlink( &thread->sched_list );
304            if( sched->k_last == &thread->sched_list )
305            {
306                if( threads_nr == 1 ) 
307                {
308                    sched->k_last = NULL;
309                }
310                else if( sched->k_root.next == &thread->sched_list )
311                {
312                    sched->k_last = sched->k_root.pred;
313                }
314                else
315                {
316                    sched->k_last = sched->k_root.next;
317                }
318            }
319
[593]320            // release the lock protecting sheduler state
321            busylock_release( &sched->lock );
322
[583]323            // get number of threads in local kernel process
324            count = process_zero.th_nr;
325
326// check th_nr value
[592]327assert( (process_zero.th_nr > 0) , "kernel process th_nr cannot be 0\n" );
[583]328
329            // remove thread from process th_tbl[]
330            process_zero.th_tbl[ltid] = NULL;
[592]331            hal_atomic_add( &process_zero.th_nr , - 1 );
[583]332 
333            // delete thread descriptor
334            thread_destroy( thread );
335
336#if DEBUG_SCHED_HANDLE_SIGNALS
337uint32_t cycle = (uint32_t)hal_get_cycles();
338if( DEBUG_SCHED_HANDLE_SIGNALS < cycle )
[610]339printk("\n[%s] thread[%x,%x] on core[%x,%d] deleted / cycle %d\n",
[583]340__FUNCTION__ , process_zero.pid , thread->trdid , local_cxy , thread->core->lid , cycle );
341#endif
342        }
[1]343    }
[564]344} // end sched_handle_signals()
[1]345
[564]346////////////////////////////////////////////////////////////////////////////////////////////
347// This static function is called by the sched_yield function when the RFC_FIFO
348// associated to the core is not empty.
[583]349// It search an idle RPC thread for this core, and unblock it if found.
350// It creates a new RPC thread if no idle RPC thread is found.
[564]351////////////////////////////////////////////////////////////////////////////////////////////
352// @ sched   : local pointer on scheduler.
353////////////////////////////////////////////////////////////////////////////////////////////
[582]354static void sched_rpc_activate( scheduler_t * sched )
[564]355{
356    error_t         error;
357    thread_t      * thread; 
358    list_entry_t  * iter;
359    lid_t           lid = CURRENT_THREAD->core->lid;
360    bool_t          found = false;
361
362    // search one IDLE RPC thread associated to the selected core   
363    LIST_FOREACH( &sched->k_root , iter )
364    {
365        thread = LIST_ELEMENT( iter , thread_t , sched_list );
[583]366
367        if( (thread->type == THREAD_RPC) && 
368            (thread->blocked == THREAD_BLOCKED_IDLE ) ) 
[564]369        {
370            found = true;
371            break;
372        }
373    }
374
375    if( found == false )     // create new RPC thread     
376    {
377        error = thread_kernel_create( &thread,
378                                      THREAD_RPC, 
[619]379                                              &rpc_server_func, 
[564]380                                      NULL,
381                                          lid );
382        // check memory
383        if ( error )
384        {
[583]385            printk("\n[ERROR] in %s : no memory to create a RPC thread in cluster %x\n",
[564]386            __FUNCTION__, local_cxy );
387        }
388        else
389        {
390            // unblock created RPC thread
391            thread->blocked = 0;
392
393            // update RPC threads counter 
394            hal_atomic_add( &LOCAL_CLUSTER->rpc_threads[lid] , 1 );
395
396#if DEBUG_SCHED_RPC_ACTIVATE
397uint32_t cycle = (uint32_t)hal_get_cycles();
398if( DEBUG_SCHED_RPC_ACTIVATE < cycle ) 
[610]399printk("\n[%s] new RPC thread %x created for core[%x,%d] / total %d / cycle %d\n",
[583]400__FUNCTION__, thread->trdid, local_cxy, lid, LOCAL_CLUSTER->rpc_threads[lid], cycle );
[564]401#endif
402        }
403    }
404    else                 // RPC thread found => unblock it
405    {
406        // unblock found RPC thread
407        thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_IDLE );
408
409#if DEBUG_SCHED_RPC_ACTIVATE
410uint32_t cycle = (uint32_t)hal_get_cycles();
411if( DEBUG_SCHED_RPC_ACTIVATE < cycle ) 
[610]412printk("\n[%s] idle RPC thread %x unblocked for core[%x,%d] / cycle %d\n",
[564]413__FUNCTION__, thread->trdid, local_cxy, lid, cycle );
414#endif
415
416    }
417
418} // end sched_rpc_activate()
419
420
421
422///////////////////////////////////////////////////////////////////////////////////////////
423//         public functions
424///////////////////////////////////////////////////////////////////////////////////////////
425
426////////////////////////////////
427void sched_init( core_t * core )
428{
429    scheduler_t * sched = &core->scheduler;
430
431    sched->u_threads_nr   = 0;
432    sched->k_threads_nr   = 0;
433
434    sched->current        = CURRENT_THREAD;
435    sched->idle           = NULL;               // initialized in kernel_init()
436    sched->u_last         = NULL;               // initialized in sched_register_thread()
437    sched->k_last         = NULL;               // initialized in sched_register_thread()
438
439    // initialise threads lists
440    list_root_init( &sched->u_root );
441    list_root_init( &sched->k_root );
442
443    // init lock
444    busylock_init( &sched->lock , LOCK_SCHED_STATE );
445
446    sched->req_ack_pending = false;             // no pending request
447    sched->trace           = false;             // context switches trace desactivated
448
449}  // end sched_init()
450
451////////////////////////////////////////////
452void sched_register_thread( core_t   * core,
453                            thread_t * thread )
454{
455    scheduler_t * sched = &core->scheduler;
456    thread_type_t type  = thread->type;
457
458    // take lock protecting sheduler state
459    busylock_acquire( &sched->lock );
460
461    if( type == THREAD_USER )
462    {
463        list_add_last( &sched->u_root , &thread->sched_list );
464        sched->u_threads_nr++;
465        if( sched->u_last == NULL ) sched->u_last = &thread->sched_list;
466    }
467    else // kernel thread
468    {
469        list_add_last( &sched->k_root , &thread->sched_list );
470        sched->k_threads_nr++;
471        if( sched->k_last == NULL ) sched->k_last = &thread->sched_list; 
472    }
473
[1]474    // release lock
[564]475    busylock_release( &sched->lock );
[1]476
[564]477}  // end sched_register_thread()
[416]478
[564]479//////////////////////////////////////
[470]480void sched_yield( const char * cause )
[1]481{
[564]482    thread_t      * next;
483    thread_t      * current = CURRENT_THREAD;
484    core_t        * core    = current->core;
485    lid_t           lid     = core->lid;
486    scheduler_t   * sched   = &core->scheduler;
487    remote_fifo_t * fifo    = &LOCAL_CLUSTER->rpc_fifo[lid]; 
[407]488 
[438]489#if (DEBUG_SCHED_YIELD & 0x1)
[614]490if( sched->trace )
491sched_display( lid );
[407]492#endif
[1]493
[614]494// This assert should never be false, as this check has been
495// done before, by any function that can possibly deschedule...
[564]496assert( (current->busylocks == 0),
[581]497"unexpected descheduling of thread holding %d busylocks = %d\n", current->busylocks ); 
[1]498
[564]499    // activate or create an RPC thread if RPC_FIFO non empty
500    if( remote_fifo_is_empty( fifo ) == false )  sched_rpc_activate( sched );
[408]501
[564]502    // disable IRQs / save SR in current thread descriptor
503    hal_disable_irq( &current->save_sr );
504
505    // take lock protecting sheduler state
506    busylock_acquire( &sched->lock );
507   
508    // select next thread
[408]509    next = sched_select( sched );
[1]510
[564]511// check next thread kernel_stack overflow
512assert( (next->signature == THREAD_SIGNATURE),
513"kernel stack overflow for thread %x on core[%x,%d] \n", next, local_cxy, lid );
[436]514
[564]515// check next thread attached to same core as the calling thread
516assert( (next->core == current->core),
517"next core %x != current core %x\n", next->core, current->core );
[296]518
[564]519// check next thread not blocked when type != IDLE
520assert( ((next->blocked == 0) || (next->type == THREAD_IDLE)) ,
521"next thread %x (%s) is blocked on core[%x,%d]\n", 
522next->trdid , thread_type_str(next->type) , local_cxy , lid );
[296]523
524    // switch contexts and update scheduler state if next != current
525        if( next != current )
[1]526    {
[296]527        // update scheduler
[408]528        sched->current = next;
529        if( next->type == THREAD_USER ) sched->u_last = &next->sched_list;
530        else                            sched->k_last = &next->sched_list;
[1]531
[407]532        // handle FPU ownership
[306]533            if( next->type == THREAD_USER )
[296]534        {
[407]535                if( next == current->core->fpu_owner )  hal_fpu_enable();
536                else                                    hal_fpu_disable();
[296]537        }
[1]538
[564]539        // release lock protecting scheduler state
540        busylock_release( &sched->lock );
541
542#if DEBUG_SCHED_YIELD
543if( sched->trace )
[610]544printk("\n[%s] core[%x,%d] / cause = %s\n"
[564]545"      thread %x (%s) (%x,%x) => thread %x (%s) (%x,%x) / cycle %d\n",
546__FUNCTION__, local_cxy, lid, cause, 
547current, thread_type_str(current->type), current->process->pid, current->trdid,next ,
548thread_type_str(next->type) , next->process->pid , next->trdid , (uint32_t)hal_get_cycles() );
549#endif
550
[435]551        // switch CPU from current thread context to new thread context
[407]552        hal_do_cpu_switch( current->cpu_context, next->cpu_context );
[296]553    }
554    else
555    {
[564]556        // release lock protecting scheduler state
557        busylock_release( &sched->lock );
[407]558
[583]559#if (DEBUG_SCHED_YIELD & 1)
[443]560if( sched->trace )
[610]561printk("\n[%s] core[%x,%d] / cause = %s\n"
[435]562"      thread %x (%s) (%x,%x) continue / cycle %d\n",
[564]563__FUNCTION__, local_cxy, lid, cause, current, thread_type_str(current->type),
[443]564current->process->pid, current->trdid, (uint32_t)hal_get_cycles() );
[428]565#endif
[407]566
[296]567    }
[408]568
[416]569    // handle pending requests for all threads executing on this core.
[433]570    sched_handle_signals( core );
[409]571
[435]572    // exit critical section / restore SR from current thread descriptor
573    hal_restore_irq( CURRENT_THREAD->save_sr );
[408]574
[1]575}  // end sched_yield()
576
[407]577
578///////////////////////////////
579void sched_display( lid_t lid )
[1]580{
[296]581    list_entry_t * iter;
582    thread_t     * thread;
[1]583
[564]584// check lid
585assert( (lid < LOCAL_CLUSTER->cores_nr), 
586"illegal core index %d\n", lid);
[407]587
588    core_t       * core    = &LOCAL_CLUSTER->core_tbl[lid];
[296]589    scheduler_t  * sched   = &core->scheduler;
590   
591    // get pointers on TXT0 chdev
[407]592    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
[296]593    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
594    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
[1]595
[564]596    // get extended pointer on remote TXT0 lock
[296]597    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
[1]598
[564]599    // get TXT0 lock
600    remote_busylock_acquire( lock_xp );
[296]601
[583]602    nolock_printk("\n***** threads on core[%x,%d] / current %x / rpc_threads %d / cycle %d\n",
603    local_cxy , core->lid, sched->current, LOCAL_CLUSTER->rpc_threads[lid],
604    (uint32_t)hal_get_cycles() );
[296]605
606    // display kernel threads
607    LIST_FOREACH( &sched->k_root , iter )
[1]608    {
[296]609        thread = LIST_ELEMENT( iter , thread_t , sched_list );
[408]610        if (thread->type == THREAD_DEV) 
611        {
[416]612            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X / %s\n",
[408]613            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
[416]614            thread, thread->blocked, thread->flags, thread->chdev->name );
[408]615        }
616        else
617        {
[437]618            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n",
[408]619            thread_type_str( thread->type ), thread->process->pid, thread->trdid,
[437]620            thread, thread->blocked, thread->flags );
[408]621        }
[1]622    }
623
[296]624    // display user threads
625    LIST_FOREACH( &sched->u_root , iter )
[1]626    {
[296]627        thread = LIST_ELEMENT( iter , thread_t , sched_list );
[416]628        nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n",
[408]629        thread_type_str( thread->type ), thread->process->pid, thread->trdid,
[416]630        thread, thread->blocked, thread->flags );
[1]631    }
632
[296]633    // release TXT0 lock
[564]634    remote_busylock_release( lock_xp );
[1]635
[296]636}  // end sched_display()
[1]637
[450]638/////////////////////////////////////
639void sched_remote_display( cxy_t cxy,
640                           lid_t lid )
641{
642    thread_t     * thread;
643
[564]644// check cxy
645assert( (cluster_is_undefined( cxy ) == false),
646"illegal cluster %x\n", cxy );
[450]647
[564]648assert( (lid < hal_remote_l32( XPTR( cxy , &LOCAL_CLUSTER->cores_nr ) ) ),
649"illegal core index %d\n", lid );
[450]650
651    // get local pointer on target scheduler
652    core_t      * core  = &LOCAL_CLUSTER->core_tbl[lid];
653    scheduler_t * sched = &core->scheduler;
654
655    // get local pointer on current thread in target scheduler
656    thread_t * current = hal_remote_lpt( XPTR( cxy, &sched->current ) );
657
658    // get local pointer on the first kernel and user threads list_entry
659    list_entry_t * k_entry = hal_remote_lpt( XPTR( cxy , &sched->k_root.next ) );
660    list_entry_t * u_entry = hal_remote_lpt( XPTR( cxy , &sched->u_root.next ) );
661   
662    // get pointers on TXT0 chdev
663    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
664    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
665    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
666
667    // get extended pointer on remote TXT0 chdev lock
668    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
669
[564]670    // get TXT0 lock
671    remote_busylock_acquire( lock_xp );
[450]672
[583]673    // get rpc_threads
674    uint32_t rpcs = hal_remote_l32( XPTR( cxy , &LOCAL_CLUSTER->rpc_threads[lid] ) );
675 
[450]676    // display header
[583]677    nolock_printk("\n***** threads on core[%x,%d] / current %x / rpc_threads %d / cycle %d\n",
678    cxy , lid, current, rpcs, (uint32_t)hal_get_cycles() );
[450]679
680    // display kernel threads
681    while( k_entry != &sched->k_root )
682    {
683        // get local pointer on kernel_thread
684        thread = LIST_ELEMENT( k_entry , thread_t , sched_list );
685
686        // get relevant thead info
[564]687        thread_type_t type    = hal_remote_l32 ( XPTR( cxy , &thread->type ) );
688        trdid_t       trdid   = hal_remote_l32 ( XPTR( cxy , &thread->trdid ) );
689        uint32_t      blocked = hal_remote_l32 ( XPTR( cxy , &thread->blocked ) );
690        uint32_t      flags   = hal_remote_l32 ( XPTR( cxy , &thread->flags ) );
[610]691        process_t *   process = hal_remote_lpt ( XPTR( cxy , &thread->process ) );
[564]692        pid_t         pid     = hal_remote_l32 ( XPTR( cxy , &process->pid ) );
[450]693
694        // display thread info
695        if (type == THREAD_DEV) 
696        {
697            char      name[16];
698            chdev_t * chdev = hal_remote_lpt( XPTR( cxy , &thread->chdev ) );
[610]699            hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( cxy , chdev->name ) );
[450]700
701            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X / %s\n",
702            thread_type_str( type ), pid, trdid, thread, blocked, flags, name );
703        }
704        else
705        {
706            nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n",
707            thread_type_str( type ), pid, trdid, thread, blocked, flags );
708        }
709
710        // get next remote kernel thread list_entry
711        k_entry = hal_remote_lpt( XPTR( cxy , &k_entry->next ) );
712    }
713
714    // display user threads
715    while( u_entry != &sched->u_root )
716    {
717        // get local pointer on user_thread
718        thread = LIST_ELEMENT( u_entry , thread_t , sched_list );
719
720        // get relevant thead info
[564]721        thread_type_t type    = hal_remote_l32 ( XPTR( cxy , &thread->type ) );
722        trdid_t       trdid   = hal_remote_l32 ( XPTR( cxy , &thread->trdid ) );
723        uint32_t      blocked = hal_remote_l32 ( XPTR( cxy , &thread->blocked ) );
724        uint32_t      flags   = hal_remote_l32 ( XPTR( cxy , &thread->flags ) );
[610]725        process_t *   process = hal_remote_lpt ( XPTR( cxy , &thread->process ) );
[564]726        pid_t         pid     = hal_remote_l32 ( XPTR( cxy , &process->pid ) );
[450]727
728        nolock_printk(" - %s / pid %X / trdid %X / desc %X / block %X / flags %X\n",
729        thread_type_str( type ), pid, trdid, thread, blocked, flags );
730
731        // get next user thread list_entry
732        u_entry = hal_remote_lpt( XPTR( cxy , &u_entry->next ) );
733    }
734
735    // release TXT0 lock
[564]736    remote_busylock_release( lock_xp );
[450]737
738}  // end sched_remote_display()
739
[564]740
Note: See TracBrowser for help on using the repository browser.