freemyipod r595 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r594‎ | r595 | r596 >
Date:21:33, 12 February 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Only switch back to the same thread when yield() is called if there is no other ready thread
Modified paths:
  • /emcore/trunk/arm/contextswitch.S (modified) (history)
  • /emcore/trunk/target/ipodnano2g/timer.c (modified) (history)
  • /emcore/trunk/target/ipodnano3g/timer.c (modified) (history)
  • /emcore/trunk/target/ipodnano4g/timer.c (modified) (history)
  • /emcore/trunk/thread.c (modified) (history)
  • /emcore/trunk/thread.h (modified) (history)
  • /emcore/trunk/usb/usb.c (modified) (history)

Diff [purge]

Index: emcore/trunk/target/ipodnano2g/timer.c
@@ -46,5 +46,5 @@
4747 void INT_TIMERB(void)
4848 {
4949 TBCON = TBCON;
50 - scheduler_switch(NULL);
 50+ scheduler_switch(NULL, NULL);
5151 }
Index: emcore/trunk/target/ipodnano3g/timer.c
@@ -52,5 +52,5 @@
5353 void INT_TIMERB(void)
5454 {
5555 TBCON = TBCON;
56 - scheduler_switch(NULL);
 56+ scheduler_switch(NULL, NULL);
5757 }
Index: emcore/trunk/target/ipodnano4g/timer.c
@@ -53,5 +53,5 @@
5454 void INT_TIMERB(void)
5555 {
5656 TBCON = TBCON;
57 - scheduler_switch(NULL);
 57+ scheduler_switch(NULL, NULL);
5858 }
Index: emcore/trunk/arm/contextswitch.S
@@ -32,13 +32,15 @@
3333 msr cpsr_c, #0xdf
3434 ldr r0, =current_thread
3535 ldr r0, [r0]
36 - stmia r0!, {r0-r14}
37 - str lr, [r0], #4
38 - str r1, [r0]
 36+ stmia r0, {r0-r14}
 37+ str lr, [r0,#0x3c]
 38+ str r1, [r0,#0x40]
3939 msr cpsr_c, #0xd2
 40+ mov r4, r0
4041 bl scheduler_pause_accounting
4142 adr lr, resume_thread
42 - mov r0, #-1
 43+ mov r0, #0
 44+ mov r1, r4
4345 b scheduler_switch
4446 .size yield, .-yield
4547
@@ -80,7 +82,8 @@
8183 stmia r5, {r0-r4}
8284 bl scheduler_pause_accounting
8385 adr lr, resume_thread
84 - mov r0, #-1
 86+ mov r0, #0
 87+ mov r1, #0
8588 b scheduler_switch
8689 .size syscall_handler, .-syscall_handler
8790
Index: emcore/trunk/thread.c
@@ -258,7 +258,7 @@
259259 current_thread->startusec = USEC_TIMER;
260260 }
261261
262 -void scheduler_switch(struct scheduler_thread* thread)
 262+void scheduler_switch(struct scheduler_thread* thread, struct scheduler_thread* block)
263263 {
264264 struct scheduler_thread* t;
265265 uint32_t score, best;
@@ -273,7 +273,6 @@
274274 current_thread->block_type = THREAD_DEFUNCT_STKOV;
275275 wakeup_signal(&dbgwakeup);
276276 }
277 -
278277 if (usec - last_tick > SCHEDULER_TICK)
279278 {
280279 uint32_t diff = usec - last_tick;
@@ -300,8 +299,7 @@
301300 t->timeout = 0;
302301 }
303302
304 - if (thread && thread->state == THREAD_READY) current_thread = thread;
305 - else
 303+ if (!thread || thread->state != THREAD_READY)
306304 {
307305 thread = &idle_thread;
308306 best = 0xffffffff;
@@ -308,7 +306,8 @@
309307 for (t = head_thread; t; t = t->thread_next)
310308 if (t->state == THREAD_READY && t->priority)
311309 {
312 - score = t->cputime_current / t->priority;
 310+ if (t == block) score = 0xfffffffe;
 311+ else score = t->cputime_current / t->priority;
313312 if (score < best)
314313 {
315314 best = score;
Index: emcore/trunk/usb/usb.c
@@ -518,7 +518,7 @@
519519 break;
520520 case 16: // FREEZE SCHEDULER
521521 dbgsendbuf[1] = scheduler_freeze(dbgrecvbuf[1]);
522 - scheduler_switch(NULL);
 522+ scheduler_switch(NULL, NULL);
523523 dbgsendbuf[0] = 1;
524524 size = 16;
525525 break;
Index: emcore/trunk/thread.h
@@ -113,7 +113,7 @@
114114 void scheduler_init() INITCODE_ATTR;
115115 void scheduler_pause_accounting() ICODE_ATTR;
116116 void scheduler_resume_accounting() ICODE_ATTR;
117 -void scheduler_switch(struct scheduler_thread* thread) ICODE_ATTR;
 117+void scheduler_switch(struct scheduler_thread* thread, struct scheduler_thread* block) ICODE_ATTR;
118118 bool scheduler_freeze(bool value);
119119 struct scheduler_thread* thread_create(struct scheduler_thread* thread, const char* name,
120120 const void* code, void* stack, int stacksize,