Changeset 294 for soft/giet_vm/giet_kernel/ctx_handler.c
- Timestamp:
- Mar 26, 2014, 6:10:01 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/ctx_handler.c
r275 r294 1 ////////////////////////////////////////////////////////////////////////////////// ///////1 ////////////////////////////////////////////////////////////////////////////////// 2 2 // File : ctx_handler.c 3 3 // Date : 01/04/2012 4 4 // Authors : alain greiner & joel porquet 5 5 // 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 ////////////////////////////////////////////////////////////////////////////////// 16 7 17 8 #include <giet_config.h> … … 24 15 #include <sys_handler.h> 25 16 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 registers31 // - CP0 registers: EPC, SR, CR, BVAR32 // - CP2 registers : PTPR33 // It contains some general informations associated to the task:34 // - TTY : TTY channel global index35 // - NIC : NIC channel global index36 // - CMA : CMA channel global index37 // - HBA : HBA channel global index38 // - DMA : DMA channel local index39 // - TIM : TIM channel local index40 // - PTAB : page table virtual base address41 // - LTID : Task local index (in scheduler)42 // - VSID : Virtual space index43 // - 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]<- TTY47 // ctx[1]<- $1 |ctx[9] <- $9 |ctx[17]<- $17|ctx[25]<- $25|ctx[33]<- CR |ctx[41]<- DMA48 // ctx[2]<- $2 |ctx[10]<- $10|ctx[18]<- $18|ctx[26]<- LO |ctx[34]<- SR |ctx[42]<- NIC49 // ctx[3]<- $3 |ctx[11]<- $11|ctx[19]<- $19|ctx[27]<- HI |ctx[35]<- BVAR |ctx[43]<- TIM50 // ctx[4]<- $4 |ctx[12]<- $12|ctx[20]<- $20|ctx[28]<- $28|ctx[36]<- PTAB |ctx[44]<- HBA51 // ctx[5]<- $5 |ctx[13]<- $13|ctx[21]<- $21|ctx[29]<- SP |ctx[37]<- LTID |ctx[45]<- CMA52 // ctx[6]<- $6 |ctx[14]<- $14|ctx[22]<- $22|ctx[30]<- $30|ctx[38]<- VSID |ctx[46]<- GTID53 // ctx[7]<- $7 |ctx[15]<- $15|ctx[23]<- $23|ctx[31]<- RA |ctx[39]<- PTPR |ctx[47]<- RUN54 //55 // ctx[48]<- TRDID56 //////////////////////////////////////////////////////////////////////////////////////////57 58 17 extern void _task_switch(unsigned int *, unsigned int *); 59 18 60 19 ///////////////////////////////////////////////////////////////////////////////// 61 // _ctx_switch()62 20 // This function performs a context switch between the running task 63 21 // and another task, using a round-robin sheduling policy between all … … 66 24 // If the only runable task is the current task, return without context switch. 67 25 // If there is no runable task, the scheduler switch to the default "idle" task. 68 // 26 ///////////////////////////////////////////////////////////////////////////////// 69 27 // Implementation note 70 28 // The return address contained in $31 is saved in the current task context … … 74 32 void _ctx_switch() 75 33 { 34 unsigned int gpid = _get_procid(); 35 unsigned int cluster_xy = gpid / NB_PROCS_MAX; 36 unsigned int lpid = gpid % NB_PROCS_MAX; 37 76 38 // get scheduler address 77 39 static_scheduler_t* psched = (static_scheduler_t*)_get_sched(); … … 105 67 } 106 68 107 // no switch if no change108 if (curr_task_id != next_task_id)109 {110 69 #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 ); 70 unsigned int x = cluster_xy >> Y_WIDTH; 71 unsigned 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() ); 127 75 #endif 128 76 77 if (curr_task_id != next_task_id) // actual task switch required 78 { 129 79 unsigned int* curr_ctx_vaddr = &(psched->context[curr_task_id][0]); 130 80 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;134 81 135 // reset timer counter 82 // reset timer counter. In each cluster, 83 // the NB_PROCS_MAX timers are system timers (TICK) 84 136 85 #if USE_XICU 137 _xcu_timer_reset_cpt( cluster_id, NB_PROCS_MAX + local_id);86 _xcu_timer_reset_cpt( cluster_xy, lpid ); 138 87 #else 139 _timer_reset_cpt( cluster_id, NB_PROCS_MAX + local_id);88 _timer_reset_cpt( cluster_xy, lpid); 140 89 #endif 141 90 … … 153 102 void _idle_task() 154 103 { 155 unsigned int count = GIET_IDLE_TASK_PERIOD;156 104 while(1) 157 105 { 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; 167 107 108 // decounting loop 168 109 asm volatile( 169 110 "move $3, %0 \n" … … 176 117 : "$3" ); 177 118 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 179 129 } 180 130 } // end ctx_idle() … … 182 132 183 133 ///////////////////////////////////////////////////////////////////////////////// 184 // The address of this function is used to initialise the return address134 // The address of this function is used to initialise the return address 185 135 // in the "idle" task context. 186 136 /////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.