Ignore:
Timestamp:
May 29, 2013, 1:24:09 AM (11 years ago)
Author:
alain
Message:

Major evolution to support physical addresses larger than 32 bits.
The map.xml format has been modified: the vsegs associated to schedulers
are now explicitely defined and mapped in the page tables.

File:
1 edited

Legend:

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

    r232 r238  
    2525// A task context is an array of 64 words = 256 bytes.
    2626// It contains copies of processor registers (when the task is preempted):
    27 // - GPR[i], generally stored in slot (i). $0, *26 & $27 are not saved.
     27// - GPR[i], generally stored in slot (i). $0, $26 & $27 are not saved.
    2828// - HI & LO registers
    2929// - CP0 registers: EPC, SR, CR, BVAR
    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
     32// - TTY    : TTY channel global index
    3433// - NIC    : NIC channel global index
    35 // - TIMER  : Timer global index
     34// - CMA    : CMA channel global index
     35// - IOC    : IOC channel global index
     36// - DMA    : DMA channel local index
     37// - TIM    : TIM channel local index
    3638// - PTAB   : page table virtual base address
    37 // - LTID    : Task local index (in scheduler)
     39// - LTID   : Task local index (in scheduler)
    3840// - VSID   : Virtual space index
    3941// - RUN    : Task state (0 => sleeping / 1 => runable )
     
    4244// ctx[1]<- $1 |ctx[9] <- $9 |ctx[17]<- $17|ctx[25]<- $25|ctx[33]<- CR   |ctx[41]<- DMA
    4345// ctx[2]<- $2 |ctx[10]<- $10|ctx[18]<- $18|ctx[26]<- LO |ctx[34]<- SR   |ctx[42]<- NIC
    44 // ctx[3]<- $3 |ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- BVAR |ctx[43]<- TIMER
    45 // ctx[4]<- $4 |ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- ***  |ctx[44]<- PTAB
    46 // ctx[5]<- $5 |ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- ***  |ctx[45]<- LTID
    47 // ctx[6]<- $6 |ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- ***  |ctx[46]<- VSID
     46// ctx[3]<- $3 |ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- BVAR |ctx[43]<- TIM
     47// ctx[4]<- $4 |ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- PTAB |ctx[44]<- IOC
     48// ctx[5]<- $5 |ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- LTID |ctx[45]<- CMA
     49// ctx[6]<- $6 |ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- VSID |ctx[46]<- GTID
    4850// ctx[7]<- $7 |ctx[15]<- $15|ctx[23]<- $23|ctx[31]<- RA |ctx[39]<- PTPR |ctx[47]<- RUN
    4951//////////////////////////////////////////////////////////////////////////////////////////
     
    6062// If there is no runable task, the scheduler switch to the default "idle" task.
    6163//
    62 // Implementation notes:
    63 // - As we only have the scheduler physical address (in CP0_SCHED register),
    64 //   this function must use specific assess functions to access the scheduler.
    65 // - All the context switch procedure is executed with interrupts masked.
    66 // - The return address contained in $31 is saved in the current task context
    67 //   (in the ctx[31] slot), and the function actually returns to the address
    68 //   contained in the ctx[31] slot of the next task context.
     64// Implementation note
     65// The return address contained in $31 is saved in the current task context
     66// (in the ctx[31] slot), and the function actually returns to the address
     67// contained in the ctx[31] slot of the next task context.
    6968/////////////////////////////////////////////////////////////////////////////////
    70 void _ctx_switch() {
    71     // get scheduler physical address
    72     static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     69void _ctx_switch()
     70{
     71    // get scheduler address
     72    static_scheduler_t* psched = _get_sched();
    7373
    7474    // get number of tasks allocated to scheduler
    75     unsigned int tasks = _get_tasks_number();
     75    unsigned int tasks = psched->tasks;
    7676
    7777    // get current task index
    78     unsigned int curr_task_id = _get_proc_task_id();
     78    unsigned int curr_task_id = psched->current;
    7979
    8080    // select the next task using a round-robin policy
     
    8383    unsigned int found = 0;
    8484
    85     for (tid = curr_task_id + 1; tid < curr_task_id + 1 + tasks; tid++) {
     85    for (tid = curr_task_id + 1; tid < curr_task_id + 1 + tasks; tid++)
     86    {
    8687        next_task_id = tid % tasks;
    87 
    8888        // test if the task is runable
    89         if (_get_context_slot(next_task_id, CTX_RUN_ID)) {
     89        if ( psched->context[next_task_id][CTX_RUN_ID] )
     90        {
    9091            found = 1;
    9192            break;
     
    9495
    9596    // launch "idle" task if no runable task
    96     if (found == 0) {
     97    if (found == 0)
     98    {
    9799        next_task_id = IDLE_TASK_INDEX;
    98100    }
    99101
    100102    // no switch if no change
    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]);
     103    if (curr_task_id != next_task_id)
     104    {
     105        unsigned int* curr_ctx_vaddr = &(psched->context[curr_task_id][0]);
     106        unsigned int* next_ctx_vaddr = &(psched->context[next_task_id][0]);
    104107
    105         _set_proc_task_id(next_task_id);
    106         //_timer_reset_irq_cpt(cluster_id, local_id); // commented until not properly supported in soclib
     108        // set current task index
     109        psched->current = next_task_id;
     110
     111        //_timer_reset_irq_cpt(cluster_id, local_id);
     112        // commented until not properly supported in soclib
    107113        // (the function is not yet present in drivers.c)
    108         _task_switch(curr_ctx_paddr, next_ctx_paddr);
     114
     115        _task_switch(curr_ctx_vaddr, next_ctx_vaddr);
    109116
    110117#if GIET_DEBUG_SWITCH
    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);
     118_get_lock(&_tty_put_lock);
     119_puts("\n[GIET DEBUG] Context switch for processor ");
     120_putd(_procid());
     121_puts(" at cycle ");
     122_putd(_proctime());
     123_puts("\n");
     124_puts(" - tasks        = ");
     125_putd(tasks);
     126_puts("\n");
     127_puts(" - curr_task_id = ");
     128_putd( curr_task_id );
     129_puts("\n");
     130_puts(" - next_task_id = ");
     131_putd(next_task_id);
     132_puts("\n");
     133_release_lock( &_tty_put_lock);
    127134#endif
    128135
     
    133140// This function is executed as the"idle" task when no other task can be executed
    134141/////////////////////////////////////////////////////////////////////////////////////
    135 void _ctx_idle() {
     142void _ctx_idle()
     143{
    136144    unsigned int delay = 1000000;
    137145
     
    164172// in the "idle" task context.
    165173/////////////////////////////////////////////////////////////////////////////////
    166 void _ctx_eret() {
     174void _ctx_eret()
     175{
    167176    asm volatile("eret");
    168177}
Note: See TracChangeset for help on using the changeset viewer.