From 0419251cfc3339f38edbed73cac3a650db3e72a5 Mon Sep 17 00:00:00 2001 From: jethead71 Date: Sun, 18 Apr 2010 09:43:59 +0000 Subject: [PATCH] Threads of PRIORITY_REALTIME and above are no longer subject to being switched away based upon aging of lower priority threads. Now, recommend a thread switch in wakeup_thread of any thread of higher priority is ready to run. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25666 a1c6a512-1295-4272-9138-f99709370657 --- firmware/thread.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/firmware/thread.c b/firmware/thread.c index 7c2cfb23e..1e20181c7 100644 --- a/firmware/thread.c +++ b/firmware/thread.c @@ -2062,16 +2062,23 @@ void switch_thread(void) /* This ridiculously simple method of aging seems to work * suspiciously well. It does tend to reward CPU hogs (under - * yielding) but that's generally not desirable at all. On the - * plus side, it, relatively to other threads, penalizes excess - * yielding which is good if some high priority thread is - * performing no useful work such as polling for a device to be - * ready. Of course, aging is only employed when higher and lower - * priority threads are runnable. The highest priority runnable - * thread(s) are never skipped. */ + * yielding) but that's generally not desirable at all. On + * the plus side, it, relatively to other threads, penalizes + * excess yielding which is good if some high priority thread + * is performing no useful work such as polling for a device + * to be ready. Of course, aging is only employed when higher + * and lower priority threads are runnable. The highest + * priority runnable thread(s) are never skipped unless a + * lower-priority process has aged sufficiently. Priorities + * of REALTIME class are run strictly according to priority + * thus are not subject to switchout due to lower-priority + * processes aging; they must give up the processor by going + * off the run list. */ if (LIKELY(priority <= max) || IF_NO_SKIP_YIELD( thread->skip_count == -1 || ) - (diff = priority - max, ++thread->skip_count > diff*diff)) + (priority > PRIORITY_REALTIME && + (diff = priority - max, + ++thread->skip_count > diff*diff))) { cores[core].running = thread; break; @@ -2226,8 +2233,9 @@ unsigned int wakeup_thread(struct thread_entry **list) current = bl->wakeup_protocol(thread); } - if (current != NULL && thread->priority < current->priority - IF_COP( && thread->core == current->core )) + if (current != NULL && + IF_COP( thread->core == current->core && ) + find_first_set_bit(cores[current->core].rtr.mask) < current->priority) { /* Woken thread is higher priority and exists on the same CPU core; * recommend a task switch. Knowing if this is an interrupt call -- 2.11.4.GIT