Ignore:
Timestamp:
Oct 1, 2015, 4:20:46 PM (9 years ago)
Author:
alain
Message:

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
File:
1 edited

Legend:

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

    r707 r709  
    66/////////////////////////////////////////////////////////////////////////////////
    77// 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
     8// This code is used to support context switch when several threads are executing
    99// in time multiplexing on a single processor.
    10 // The tasks are statically allocated to a processor in the boot phase, and
     10// The threads are statically allocated to a processor in the boot phase, and
    1111// there is one private scheduler per processor. Each sheduler occupies 8K bytes,
    12 // and contains up to 14 task contexts (task_id is from 0 to 13).
    13 // The task context [13] is reserved for the "idle" task that does nothing, and
    14 // is launched by the scheduler when there is no other runable task.
     12// and contains up to 14 thread contexts (thread_id is from 0 to 13).
     13// The thread context [13] is reserved for the "idle" thread that is
     14// launched by the scheduler when there is no other runable thread.
    1515/////////////////////////////////////////////////////////////////////////////////
    16 // A task context is an array of 64 uint32 words => 256 bytes.
    17 // It contains copies of processor registers (when the task is preempted)
    18 // and some general informations associated to a task, such as the private
    19 // peripheral channels allocated to the task, the vspace index, the various
    20 // task index (local / global / application), and the runnable status.
     16// A thread context is an array of 64 uint32 words => 256 bytes.
     17// It contains copies of processor registers (when the thread is preempted)
     18// and some general informations associated to a thread, such as the private
     19// peripheral channels allocated to the thread, the vspace index, the two
     20// thread index, and the runnable status.
    2121/////////////////////////////////////////////////////////////////////////////////
    2222// ctx[0] <- ***   |ctx[8] <- $8     |ctx[16]<- $16    |ctx[24]<- $24
     
    2424// ctx[2] <- $2    |ctx[10]<- $10    |ctx[18]<- $18    |ctx[26]<- LO
    2525// ctx[3] <- $3    |ctx[11]<- $11    |ctx[19]<- $19    |ctx[27]<- HI
    26 // ctx[4] <- $4    |ctx[12]<- $12    |ctx[20]<- $20    |ctx[28]<- $28
    27 // ctx[5] <- $5    |ctx[13]<- $13    |ctx[21]<- $21    |ctx[29]<- SP
    28 // ctx[6] <- $6    |ctx[14]<- $14    |ctx[22]<- $22    |ctx[30]<- $30
    29 // ctx[7] <- $7    |ctx[15]<- $15    |ctx[23]<- $23    |ctx[31]<- RA
     26// ctx[4] <- A0    |ctx[12]<- $12    |ctx[20]<- $20    |ctx[28]<- $28
     27// ctx[5] <- A1    |ctx[13]<- $13    |ctx[21]<- $21    |ctx[29]<- SP
     28// ctx[6] <- A2    |ctx[14]<- $14    |ctx[22]<- $22    |ctx[30]<- $30
     29// ctx[7] <- A3    |ctx[15]<- $15    |ctx[23]<- $23    |ctx[31]<- RA
    3030//
    3131// ctx[32]<- EPC   |ctx[40]<- TTY    |ctx[48]<- TRDID  |ctx[56]<- ***
    32 // ctx[33]<- CR    |ctx[41]<- CMA_FB |ctx[49]<- GTID   |ctx[57]<- ***
     32// ctx[33]<- CR    |ctx[41]<- CMA_FB |ctx[49]<- LTID   |ctx[57]<- ***
    3333// ctx[34]<- SR    |ctx[42]<- CMA_RX |ctx[50]<- NORUN  |ctx[58]<- ***
    3434// ctx[35]<- BVAR  |ctx[43]<- CMA_TX |ctx[51]<- COPROC |ctx[59]<- ***
    3535// ctx[36]<- PTAB  |ctx[44]<- NIC_RX |ctx[52]<- ENTRY  |ctx[60]<- ***
    36 // ctx[37]<- LTID  |ctx[45]<- NIC_TX |ctx[53]<- SIG    |ctx[61]<- ***
    37 // ctx[38]<- VSID  |ctx[46]<- TIM    |ctx[54]<- ***    |ctx[62]<- ***
    38 // ctx[39]<- PTPR  |ctx[47]<- HBA    |ctx[55]<- ***    |ctx[63]<- ***
     36// ctx[37]<- ***   |ctx[45]<- NIC_TX |ctx[53]<- SIGS   |ctx[61]<- ***
     37// ctx[38]<- ***   |ctx[46]<- TIM    |ctx[54]<- VSID   |ctx[62]<- ***
     38// ctx[39]<- PTPR  |ctx[47]<- HBA    |ctx[55]<- LOCKS  |ctx[63]<- ***
    3939/////////////////////////////////////////////////////////////////////////////////
    4040
     
    4545
    4646/////////////////////////////////////////////////////////////////////////////////
    47 //    Definition of the task context slots indexes
     47//    Definition of some thread context slots indexes
    4848/////////////////////////////////////////////////////////////////////////////////
     49
     50#define CTX_A0_ID        4     // Argument 0
     51#define CTX_A1_ID        5     // Argument 1
     52#define CTX_A2_ID        6     // Argument 2
     53#define CTX_A3_ID        7     // Argument 3
    4954
    5055#define CTX_SP_ID        29    // Stack Pointer
     
    5661#define CTX_BVAR_ID      35        // Bad Virtual Address Register (CP0)
    5762#define CTX_PTAB_ID      36    // Page Table Virtual address
    58 #define CTX_LTID_ID      37    // Local  Task Index (in scheduler)
    59 #define CTX_VSID_ID      38    // Vspace Index     
     63//                       37
     64//                       38
    6065#define CTX_PTPR_ID      39    // Page Table Pointer Register (PADDR>>13)
    6166
     
    6974#define CTX_HBA_ID       47    // private HBA channel index
    7075
    71 #define CTX_TRDID_ID     48    // Thread Task Index in vspace
    72 #define CTX_GTID_ID      49    // Global Task Index in all system
    73 #define CTX_NORUN_ID     50    // bit-vector : task runable if all zero
    74 #define CTX_COPROC_ID    51    // cluster_xy : coprocessor coordinates
    75 #define CTX_ENTRY_ID     52    // Virtual address of task entry point
    76 #define CTX_SIG_ID       53    // bit-vector : pending signals for task
     76#define CTX_TRDID_ID     48    // Global Thread Index ( x | y | p | ltid )
     77#define CTX_LTID_ID      49    // Local Thread Index in scheduler
     78#define CTX_NORUN_ID     50    // bit-vector : thread runable if all zero
     79#define CTX_COPROC_ID    51    // coprocessor coordinates (cluster_xy)
     80#define CTX_ENTRY_ID     52    // Virtual address of thread entry point
     81#define CTX_SIGS_ID      53    // bit-vector : pending signals
     82#define CTX_VSID_ID      54    // Vspace Index     
     83#define CTX_LOCKS_ID     55    // bit-vector : kernel locks taken
    7784
    7885/////////////////////////////////////////////////////////////////////////////////
     
    8087/////////////////////////////////////////////////////////////////////////////////
    8188
    82 #define NORUN_MASK_TASK       0x00000001   // Task not active 
     89#define NORUN_MASK_THREAD     0x00000001   // Task not active 
    8390#define NORUN_MASK_IOC        0x00000002   // Task blocked on IOC transfer
    8491#define NORUN_MASK_COPROC     0x00000004   // Task blocked on COPROC transfer
     92#define NORUN_MASK_TTY        0x00000008   // Task blocked on TTY_RX transfer
    8593
    8694/////////////////////////////////////////////////////////////////////////////////
    87 //    Definition of the SIG bit-vector masks
     95//    Definition of the SIGS bit-vector masks
    8896/////////////////////////////////////////////////////////////////////////////////
    8997
    90 #define SIG_MASK_KILL         0x00000001   // Task will be killed at next tick
     98#define SIGS_MASK_KILL        0x00000001   // Task desactivated at next tick
    9199
    92100/////////////////////////////////////////////////////////////////////////////////
    93 //    Definition of the scheduler structure
     101//    Definition of the LOCKS bit-vector masks
    94102/////////////////////////////////////////////////////////////////////////////////
    95103
    96 typedef struct static_scheduler_s
     104#define LOCKS_MASK_BDV        0x00000001   // BDV kernel lock taken
     105#define LOCKS_MASK_FAT        0x00000002   // FAT kernel lock taken
     106
     107/////////////////////////////////////////////////////////////////////////////////
     108//    Task context and  scheduler structures
     109/////////////////////////////////////////////////////////////////////////////////
     110
     111typedef struct thread_context_s             // 256 bytes
    97112{
    98     unsigned int context[14][64];      // at most 14 task (including idle_task)
    99     unsigned int tasks;                // actual number of tasks
    100     unsigned int current;              // current task index
    101     unsigned int hwi_vector[32];       // hardware interrupt vector
    102     unsigned int pti_vector[32];       // timer    interrupt vector
    103     unsigned int wti_vector[32];       // software interrupt vector
    104     unsigned int reserved[30];         // padding to 4 Kbytes
    105     unsigned int idle_stack[1024];     // private stack for idle stack (4Kbytes)
     113    unsigned int slot[64];     
     114} thread_context_t;
     115
     116
     117typedef struct static_scheduler_s           // 8 Kbytes
     118{
     119    thread_context_t  context[14];          // at most 14 threads (including idle_thread)
     120    unsigned int      threads;              // actual number of allocated threads
     121    unsigned int      current;              // current thread index
     122    unsigned int      hwi_vector[32];       // hardware interrupt vector
     123    unsigned int      pti_vector[32];       // timer    interrupt vector
     124    unsigned int      wti_vector[32];       // software interrupt vector
     125    unsigned int      reserved[30];         // padding to 4 Kbytes
     126    unsigned int      idle_stack[1024];     // private stack for idle stack (4Kbytes)
    106127} static_scheduler_t;
    107128
    108 #define IDLE_TASK_INDEX        13
     129#define IDLE_THREAD_INDEX        13
    109130
    110131
     
    114135
    115136/////////////////////////////////////////////////////////////////////////////////
    116 // This function performs a context switch between the running task
    117 // and  another task, using a round-robin sheduling policy between all
    118 // tasks allocated to a given processor (static allocation).
    119 // It selects the next runable task to resume execution.
    120 // If the only runable task is the current task, return without context switch.
    121 // If there is no runable task, the scheduler switch to the default "idle" task.
    122 // The return address contained in $31 is saved in the current task context
     137// This function performs a context switch between the running thread
     138// and  another thread, using a round-robin sheduling policy between all
     139// threads allocated to a given processor (static allocation).
     140// It selects the next runable thread to resume execution.
     141// If the only runable thread is the current thread, return without context switch.
     142// If there is no runable thread, the scheduler switch to the default "idle" thread.
     143// The return address contained in $31 is saved in the current thread context
    123144// (in the ctx[31] slot), and the function actually returns to the address
    124 // contained in the ctx[31] slot of the next task context.
     145// contained in the ctx[31] slot of the next thread context.
    125146/////////////////////////////////////////////////////////////////////////////////
    126147extern void _ctx_switch();
     
    128149/////////////////////////////////////////////////////////////////////////////////
    129150// The address of this function is used to initialise the return address
    130 // in the "idle" task context.
     151// in the "idle" thread context.
    131152/////////////////////////////////////////////////////////////////////////////////
    132153extern void _ctx_eret();
    133154
    134155/////////////////////////////////////////////////////////////////////////////////
    135 // This function is executed task when no other task can be executed.
     156// This function is executed thread when no other thread can be executed.
    136157/////////////////////////////////////////////////////////////////////////////////
    137 extern void _idle_task();
    138 
    139 /////////////////////////////////////////////////////////////////////////////////
    140 // This function displays the context of a task identified by the processor
    141 // coordinates (x,y,p), and by the local task index ltid.
    142 // The string argument can be used for debug.
    143 /////////////////////////////////////////////////////////////////////////////////
    144 extern void _ctx_display( unsigned int x,
    145                           unsigned int y,
    146                           unsigned int p,
    147                           unsigned int ltid,
    148                           char*        string );
     158extern void _idle_thread();
    149159
    150160#endif
Note: See TracChangeset for help on using the changeset viewer.