Update donate_priority to only attempt to sort position of the donee that isn't waiting for a lock

This commit is contained in:
Themis Demetriades
2024-10-23 13:29:45 +01:00
parent d82176a2e2
commit a875d5fcb4
3 changed files with 24 additions and 7 deletions

View File

@@ -214,12 +214,17 @@ donate_priority (struct thread *donor, struct thread *donee) {
/* Also stop propagation of donation once a donee is reached with /* Also stop propagation of donation once a donee is reached with
no donees of its own (sink node in WFG). */ no donees of its own (sink node in WFG). */
if (donee->waiting_lock == NULL) if (donee->waiting_lock == NULL)
donee = NULL; {
/* Only the sink node of the WFG isn't waiting for a lock and
could be on the ready list. Thus, as its priority changed,
it must be reinserted into the list. */
ready_list_reinsert (donee);
donee = NULL;
}
else else
donee = donee->waiting_lock->holder; donee = donee->waiting_lock->holder;
} }
ready_list_reorder ();
} }
/* Acquires LOCK, sleeping until it becomes available if /* Acquires LOCK, sleeping until it becomes available if

View File

@@ -465,10 +465,22 @@ thread_get_recent_cpu (void)
return 0; return 0;
} }
/* Reinsert thread t into the ready list at its correct position
in descending order of priority. Used when this thread's priority
may have changed. */
void void
ready_list_reorder (void) ready_list_reinsert (struct thread *t)
{ {
list_sort (&ready_list, priority_more, NULL); enum intr_level old_level = intr_disable ();
/* If the thread isn't ready to run, do nothing. */
if (t->status == THREAD_READY)
{
list_remove (&t->elem);
list_insert_ordered (&ready_list, &t->elem, priority_more, NULL);
}
intr_set_level (old_level);
} }
/* Idle thread. Executes when no other thread is ready to run. /* Idle thread. Executes when no other thread is ready to run.
@@ -558,7 +570,7 @@ init_thread (struct thread *t, const char *name, int priority)
t->stack = (uint8_t *) t + PGSIZE; t->stack = (uint8_t *) t + PGSIZE;
t->base_priority = priority; t->base_priority = priority;
t->magic = THREAD_MAGIC; t->magic = THREAD_MAGIC;
list_init (&t->donors_list); list_init (&t->donors_list);
t->priority = t->base_priority; t->priority = t->base_priority;
t->waiting_lock = NULL; t->waiting_lock = NULL;

View File

@@ -151,6 +151,6 @@ void thread_set_nice (int);
int thread_get_recent_cpu (void); int thread_get_recent_cpu (void);
int thread_get_load_avg (void); int thread_get_load_avg (void);
void ready_list_reorder (void); void ready_list_reinsert (struct thread *t);
#endif /* threads/thread.h */ #endif /* threads/thread.h */