Ignore:
Timestamp:
Feb 12, 2013, 6:33:31 PM (12 years ago)
Author:
meunier
Message:

Added support for memspaces and const.
Added an interrupt masking to the "giet_context_switch" syscall
Corrected two bugs in boot/boot_init.c (one minor and one regarding barriers initialization)
Reformatted the code in all files.

File:
1 edited

Legend:

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

    r218 r228  
    3030// - CP2 registers : PTPR
    3131// It contains some general informations associated to the task:
    32 // - TTY        : terminal global index
    33 // - FBDMA      : DMA channel global index
    34 // - NIC        : NIC channel global index
     32// - TTY    : terminal global index
     33// - FBDMA    : DMA channel global index
     34// - NIC    : NIC channel global index
    3535// - TIMER  : Timer global index
    3636// - PTAB   : page table virtual base address
    37 // - LTID       : Task local index (in scheduler)
     37// - LTID    : Task local index (in scheduler)
    3838// - VSID   : Virtual space index
    39 // - RUN        : Task state (0 => sleeping / 1 => runable )
     39// - RUN    : Task state (0 => sleeping / 1 => runable )
    4040//
    4141// ctx[0]<- ***|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC  |ctx[40]<- TTY
     
    4949//////////////////////////////////////////////////////////////////////////////////////////
    5050
    51 extern void _task_switch(unsigned int*, unsigned int*);
     51extern void _task_switch(unsigned int *, unsigned int *);
    5252
    5353/////////////////////////////////////////////////////////////////////////////////
    54 //      _ctx_switch()
     54//    _ctx_switch()
    5555// This function performs a context switch between the running task
    5656// and  another task, using a round-robin sheduling policy between all
     
    6868//   contained in the ctx[31] slot of the next task context.
    6969/////////////////////////////////////////////////////////////////////////////////
    70 void _ctx_switch()
    71 {
     70void _ctx_switch() {
    7271    // get scheduler physical address
    73     static_scheduler_t* psched = (static_scheduler_t*)_get_sched();
     72    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
    7473
    7574    // get number of tasks allocated to scheduler
    76     unsigned int        tasks = _get_tasks_number();
     75    unsigned int tasks = _get_tasks_number();
    7776
    7877    // get current task index
    79     unsigned int        curr_task_id = _get_current_task_id();
     78    unsigned int curr_task_id = _get_current_task_id();
    8079
    8180    // select the next task using a round-robin policy
    82     unsigned int        next_task_id;
    83     unsigned int        tid;
    84     unsigned int        found = 0;
     81    unsigned int next_task_id;
     82    unsigned int tid;
     83    unsigned int found = 0;
    8584
    86     for ( tid = curr_task_id + 1 ;
    87           tid < curr_task_id + 1 + tasks ;
    88           tid++ )
    89     {
     85    for (tid = curr_task_id + 1; tid < curr_task_id + 1 + tasks; tid++) {
    9086        next_task_id = tid % tasks;
    9187
    9288        // test if the task is runable
    93         if ( _get_context_slot( next_task_id, CTX_RUN_ID ) )   
    94         {
     89        if (_get_context_slot(next_task_id, CTX_RUN_ID)) {
    9590            found = 1;
    96                 break;
     91            break;
    9792        }
    9893    }
    9994
    10095    // launch "idle" task if no runable task
    101     if ( found == 0 )
    102     {
     96    if (found == 0) {
    10397        next_task_id = IDLE_TASK_INDEX;
    10498    }
    10599
    106100    // no switch if no change
    107     if ( curr_task_id != next_task_id )
    108     {
    109         unsigned int*   curr_ctx_paddr = &(psched->context[curr_task_id][0]);
    110         unsigned int*   next_ctx_paddr = &(psched->context[next_task_id][0]);
     101    if (curr_task_id != next_task_id) {
     102        unsigned int * curr_ctx_paddr = &(psched->context[curr_task_id][0]);
     103        unsigned int * next_ctx_paddr = &(psched->context[next_task_id][0]);
    111104
    112         _set_current_task_id( next_task_id );
    113         _task_switch( curr_ctx_paddr, next_ctx_paddr );
     105        _set_current_task_id(next_task_id);
     106        //_timer_reset_irq_cpt(cluster_id, local_id); // commented until not properly supported in soclib
     107        // (the function is not yet present in drivers.c)
     108        _task_switch(curr_ctx_paddr, next_ctx_paddr);
    114109
    115110#if GIET_DEBUG_SWITCH
    116 _get_lock( &_tty_put_lock );
    117 _puts( "\n[GIET DEBUG] Context switch for processor ");
    118 _putd( _procid() );
    119 _puts( " at cycle ");
    120 _putd( _proctime() );
    121 _puts("\n");
    122 _puts( " - tasks        = ");
    123 _putd( tasks );
    124 _puts("\n");
    125 _puts( " - curr_task_id = ");
    126 _putd( curr_task_id );
    127 _puts("\n");
    128 _puts( " - next_task_id = ");
    129 _putd( next_task_id );
    130 _puts("\n");
    131 _release_lock( &_tty_put_lock );
     111        _get_lock(&_tty_put_lock);
     112        _puts("\n[GIET DEBUG] Context switch for processor ");
     113        _putd(_procid());
     114        _puts(" at cycle ");
     115        _putd(_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        _release_lock( &_tty_put_lock);
    132127#endif
    133128
     
    138133// This function is executed as the"idle" task when no other task can be executed
    139134/////////////////////////////////////////////////////////////////////////////////////
    140 void _ctx_idle()
    141 {
     135void _ctx_idle() {
    142136    unsigned int delay = 1000000;
    143137
    144     while(1)
    145     {
    146         asm volatile("move  $3,   %0            \n"
    147                      "loop:                                     \n"
    148                      "addi      $3, $3, -1              \n"
    149                      "bnez  $3, loop            \n"
    150                      "nop                                       \n"
    151                      :
    152                      : "r"(delay)
    153                      : "$3" );
     138    while (1) {
     139        asm volatile(
     140                "move   $3,   %0          \n"
     141                "loop:                    \n"
     142                "addi   $3,   $3,   -1    \n"
     143                "bnez   $3,   loop        \n"
     144                "nop                      \n"
     145                :
     146                : "r"(delay)
     147                : "$3" );
    154148
    155         _get_lock( &_tty_put_lock );
    156         _puts( "\n[GIET WARNING] Processor ");
    157         _putd( _procid() );
    158         _puts( " still idle at cycle ");
    159         _putd( _proctime() );
     149        _get_lock(&_tty_put_lock);
     150        _puts("\n[GIET WARNING] Processor ");
     151        _putd(_procid());
     152        _puts(" still idle at cycle ");
     153        _putd(_proctime());
    160154        _puts("\n");
    161         _release_lock( &_tty_put_lock );
    162    
     155        _release_lock(&_tty_put_lock);
     156
    163157    }
    164158} // end ctx_idle()
     159
    165160
    166161/////////////////////////////////////////////////////////////////////////////////
     
    168163// in the "idle" task context.
    169164/////////////////////////////////////////////////////////////////////////////////
    170 void _ctx_eret()
    171 {
     165void _ctx_eret() {
    172166    asm volatile("eret");
    173167}
    174168
    175169
     170// Local Variables:
     171// tab-width: 4
     172// c-basic-offset: 4
     173// c-file-offsets:((innamespace . 0)(inline-open . 0))
     174// indent-tabs-mode: nil
     175// End:
     176// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     177
Note: See TracChangeset for help on using the changeset viewer.