Ignore:
Timestamp:
Mar 26, 2014, 6:10:01 PM (11 years ago)
Author:
alain
Message:

Introducing support for IOPIC component.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/ctx_handler.c

    r275 r294  
    1 /////////////////////////////////////////////////////////////////////////////////////////
     1//////////////////////////////////////////////////////////////////////////////////
    22// File     : ctx_handler.c
    33// Date     : 01/04/2012
    44// Authors  : alain greiner & joel porquet
    55// Copyright (c) UPMC-LIP6
    6 /////////////////////////////////////////////////////////////////////////////////////////
    7 // The ctx_handler.h and ctx_handler.c files are part of the GIET-VM nano-kernel.
    8 // This code is used to support context switch when several tasks are executing
    9 // in time multiplexing on a single processor.
    10 // The tasks are statically allocated to a processor in the boot phase, and
    11 // there is one private scheduler per processor. Each sheduler occupies 4K bytes,
    12 // and contains up to 14 task contexts (task_id is from 0 to 13).
    13 // The task context [14] is reserved for the "idle" task that does nothing, and
    14 // is launched by the scheduler when there is no other runable task.
    15 /////////////////////////////////////////////////////////////////////////////////////////
     6//////////////////////////////////////////////////////////////////////////////////
    167
    178#include <giet_config.h>
     
    2415#include <sys_handler.h>
    2516
    26 /////////////////////////////////////////////////////////////////////////////////////////
    27 // A task context is an array of 64 words = 256 bytes.
    28 // It contains copies of processor registers (when the task is preempted):
    29 // - GPR[i], generally stored in slot (i). $0, $26 & $27 are not saved.
    30 // - HI & LO registers
    31 // - CP0 registers: EPC, SR, CR, BVAR
    32 // - CP2 registers : PTPR
    33 // It contains some general informations associated to the task:
    34 // - TTY    : TTY channel global index
    35 // - NIC    : NIC channel global index
    36 // - CMA    : CMA channel global index
    37 // - HBA    : HBA channel global index
    38 // - DMA    : DMA channel local index
    39 // - TIM    : TIM channel local index
    40 // - PTAB   : page table virtual base address
    41 // - LTID   : Task local index (in scheduler)
    42 // - VSID   : Virtual space index
    43 // - RUN    : Task state (0 => sleeping / 1 => runnable )
    44 // - TRDID  : Thread ID index (in vspace)
    45 //
    46 // ctx[0]<- ***|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC  |ctx[40]<- TTY
    47 // ctx[1]<- $1 |ctx[9] <- $9 |ctx[17]<- $17|ctx[25]<- $25|ctx[33]<- CR   |ctx[41]<- DMA
    48 // ctx[2]<- $2 |ctx[10]<- $10|ctx[18]<- $18|ctx[26]<- LO |ctx[34]<- SR   |ctx[42]<- NIC
    49 // ctx[3]<- $3 |ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- BVAR |ctx[43]<- TIM
    50 // ctx[4]<- $4 |ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- PTAB |ctx[44]<- HBA
    51 // ctx[5]<- $5 |ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- LTID |ctx[45]<- CMA
    52 // ctx[6]<- $6 |ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- VSID |ctx[46]<- GTID
    53 // ctx[7]<- $7 |ctx[15]<- $15|ctx[23]<- $23|ctx[31]<- RA |ctx[39]<- PTPR |ctx[47]<- RUN
    54 //
    55 // ctx[48]<- TRDID
    56 //////////////////////////////////////////////////////////////////////////////////////////
    57 
    5817extern void _task_switch(unsigned int *, unsigned int *);
    5918
    6019/////////////////////////////////////////////////////////////////////////////////
    61 //    _ctx_switch()
    6220// This function performs a context switch between the running task
    6321// and  another task, using a round-robin sheduling policy between all
     
    6624// If the only runable task is the current task, return without context switch.
    6725// If there is no runable task, the scheduler switch to the default "idle" task.
    68 //
     26/////////////////////////////////////////////////////////////////////////////////
    6927// Implementation note
    7028// The return address contained in $31 is saved in the current task context
     
    7432void _ctx_switch()
    7533{
     34    unsigned int gpid       = _get_procid();
     35    unsigned int cluster_xy = gpid / NB_PROCS_MAX;
     36    unsigned int lpid       = gpid % NB_PROCS_MAX;
     37
    7638    // get scheduler address
    7739    static_scheduler_t* psched = (static_scheduler_t*)_get_sched();
     
    10567    }
    10668
    107     // no switch if no change
    108     if (curr_task_id != next_task_id)
    109     {
    11069#if GIET_DEBUG_SWITCH
    111 _tty_get_lock( 0 );
    112 _puts("\n[GIET DEBUG] Context switch for processor ");
    113 _putd(_get_procid());
    114 _puts(" at cycle ");
    115 _putd(_get_proctime());
    116 _puts("\n");
    117 _puts(" - tasks        = ");
    118 _putd(tasks);
    119 _puts("\n");
    120 _puts(" - curr_task_id = ");
    121 _putd( curr_task_id );
    122 _puts("\n");
    123 _puts(" - next_task_id = ");
    124 _putd(next_task_id);
    125 _puts("\n");
    126 _tty_release_lock(  0 );
     70unsigned int x = cluster_xy >> Y_WIDTH;
     71unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);
     72
     73_printf("\n[TASK SWITCH] (%d) -> (%d) on processor[%d,%d,%d] at cycle %d\n",
     74        curr_task_id, next_task_id, x, y , lpid, _get_proctime() );
    12775#endif
    12876
     77    if (curr_task_id != next_task_id)  // actual task switch required
     78    {
    12979        unsigned int* curr_ctx_vaddr = &(psched->context[curr_task_id][0]);
    13080        unsigned int* next_ctx_vaddr = &(psched->context[next_task_id][0]);
    131         unsigned int procid = _get_procid();
    132         unsigned int local_id = procid % NB_PROCS_MAX;
    133         unsigned int cluster_id = procid / NB_PROCS_MAX;
    13481
    135         // reset timer counter
     82        // reset timer counter. In each cluster,
     83        // the NB_PROCS_MAX timers are system timers (TICK)
     84
    13685#if USE_XICU
    137         _xcu_timer_reset_cpt(cluster_id, NB_PROCS_MAX + local_id);
     86        _xcu_timer_reset_cpt( cluster_xy, lpid );
    13887#else
    139         _timer_reset_cpt(cluster_id, NB_PROCS_MAX + local_id);
     88        _timer_reset_cpt( cluster_xy, lpid);
    14089#endif
    14190
     
    153102void _idle_task()
    154103{
    155     unsigned int count = GIET_IDLE_TASK_PERIOD;
    156104    while(1)
    157105    {
    158 #if GIET_IDLE_TASK_VERBOSITY == 1
    159         _tty_get_lock( 0 );
    160         _puts("\n[GIET WARNING] Processor ");
    161         _putd(_get_procid());
    162         _puts(" idle at cycle ");
    163         _putd(_get_proctime());
    164         _puts("\n");
    165         _tty_release_lock( 0 );
    166 #endif
     106        unsigned int count = GIET_IDLE_TASK_PERIOD;
    167107
     108        // decounting loop
    168109        asm volatile(
    169110                "move   $3,   %0              \n"
     
    176117                : "$3" );
    177118
    178          count = GIET_IDLE_TASK_PERIOD;
     119        // warning message
     120        unsigned int gpid       = _get_procid();
     121        unsigned int cluster_xy = gpid / NB_PROCS_MAX;
     122        unsigned int lpid       = gpid % NB_PROCS_MAX;
     123        unsigned int x          = cluster_xy >> Y_WIDTH;
     124        unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
     125
     126        _printf("\n[GIET WARNING] Processor[%d,%d,%d] still idle at cycle %d\n",
     127                x, y, lpid, _get_proctime() );
     128
    179129    }
    180130} // end ctx_idle()
     
    182132
    183133/////////////////////////////////////////////////////////////////////////////////
    184 // The address of this functionis used to initialise the return address
     134// The address of this function is used to initialise the return address
    185135// in the "idle" task context.
    186136/////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.