Changeset 228 for soft/giet_vm/sys/ctx_handler.c
- Timestamp:
- Feb 12, 2013, 6:33:31 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/sys/ctx_handler.c
r218 r228 30 30 // - CP2 registers : PTPR 31 31 // It contains some general informations associated to the task: 32 // - TTY 33 // - FBDMA 34 // - NIC 32 // - TTY : terminal global index 33 // - FBDMA : DMA channel global index 34 // - NIC : NIC channel global index 35 35 // - TIMER : Timer global index 36 36 // - PTAB : page table virtual base address 37 // - LTID 37 // - LTID : Task local index (in scheduler) 38 38 // - VSID : Virtual space index 39 // - RUN 39 // - RUN : Task state (0 => sleeping / 1 => runable ) 40 40 // 41 41 // ctx[0]<- ***|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC |ctx[40]<- TTY … … 49 49 ////////////////////////////////////////////////////////////////////////////////////////// 50 50 51 extern void _task_switch(unsigned int *, unsigned int*);51 extern void _task_switch(unsigned int *, unsigned int *); 52 52 53 53 ///////////////////////////////////////////////////////////////////////////////// 54 // 54 // _ctx_switch() 55 55 // This function performs a context switch between the running task 56 56 // and another task, using a round-robin sheduling policy between all … … 68 68 // contained in the ctx[31] slot of the next task context. 69 69 ///////////////////////////////////////////////////////////////////////////////// 70 void _ctx_switch() 71 { 70 void _ctx_switch() { 72 71 // get scheduler physical address 73 static_scheduler_t * psched = (static_scheduler_t*)_get_sched();72 static_scheduler_t * psched = (static_scheduler_t *) _get_sched(); 74 73 75 74 // get number of tasks allocated to scheduler 76 unsigned int 75 unsigned int tasks = _get_tasks_number(); 77 76 78 77 // get current task index 79 unsigned int 78 unsigned int curr_task_id = _get_current_task_id(); 80 79 81 80 // select the next task using a round-robin policy 82 unsigned int 83 unsigned int 84 unsigned int 81 unsigned int next_task_id; 82 unsigned int tid; 83 unsigned int found = 0; 85 84 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++) { 90 86 next_task_id = tid % tasks; 91 87 92 88 // 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)) { 95 90 found = 1; 96 91 break; 97 92 } 98 93 } 99 94 100 95 // launch "idle" task if no runable task 101 if ( found == 0 ) 102 { 96 if (found == 0) { 103 97 next_task_id = IDLE_TASK_INDEX; 104 98 } 105 99 106 100 // 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]); 111 104 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); 114 109 115 110 #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); 132 127 #endif 133 128 … … 138 133 // This function is executed as the"idle" task when no other task can be executed 139 134 ///////////////////////////////////////////////////////////////////////////////////// 140 void _ctx_idle() 141 { 135 void _ctx_idle() { 142 136 unsigned int delay = 1000000; 143 137 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 153 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" ); 154 148 155 _get_lock( &_tty_put_lock);156 _puts( 157 _putd( _procid());158 _puts( 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()); 160 154 _puts("\n"); 161 _release_lock( &_tty_put_lock);162 155 _release_lock(&_tty_put_lock); 156 163 157 } 164 158 } // end ctx_idle() 159 165 160 166 161 ///////////////////////////////////////////////////////////////////////////////// … … 168 163 // in the "idle" task context. 169 164 ///////////////////////////////////////////////////////////////////////////////// 170 void _ctx_eret() 171 { 165 void _ctx_eret() { 172 166 asm volatile("eret"); 173 167 } 174 168 175 169 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.