diff options
| author | manuel <manuel@mausz.at> | 2012-05-03 16:18:11 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-05-03 16:18:11 +0200 |
| commit | 3d1e18466b44b2de06dd7c00a85e78ed9340906d (patch) | |
| tree | 53a8f428518c3d9c367b9ad11c06242430d3a62a | |
| parent | cdb4c554387cfc2aeae98344b6585355a2fffcc9 (diff) | |
| download | progos-3d1e18466b44b2de06dd7c00a85e78ed9340906d.tar.gz progos-3d1e18466b44b2de06dd7c00a85e78ed9340906d.tar.bz2 progos-3d1e18466b44b2de06dd7c00a85e78ed9340906d.zip | |
initial commit of proj1
including the draft of our (yet empty) design document
and the first schedule code mostly submitted by karo and peter
| -rw-r--r-- | proj1.txt | 85 | ||||
| -rw-r--r-- | threads/thread.c | 24 |
2 files changed, 107 insertions, 2 deletions
diff --git a/proj1.txt b/proj1.txt new file mode 100644 index 0000000..274ef34 --- /dev/null +++ b/proj1.txt | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | +--------------------+ | ||
| 2 | | CS 140 | | ||
| 3 | | PROJECT 1: THREADS | | ||
| 4 | | DESIGN DOCUMENT | | ||
| 5 | +--------------------+ | ||
| 6 | |||
| 7 | ---- GROUP ---- | ||
| 8 | |||
| 9 | >> Fill in the names and email addresses of your group members. | ||
| 10 | |||
| 11 | Peter Ketscher <e9651415@mail.student.tuwien.ac.at> | ||
| 12 | Karoline Knoth <e0326266@student.tuwien.ac.at> | ||
| 13 | Manuel Mausz <manuel-uni@mausz.at> | ||
| 14 | |||
| 15 | ---- PRELIMINARIES ---- | ||
| 16 | |||
| 17 | >> If you have any preliminary comments on your submission, notes for the | ||
| 18 | >> TAs, or extra credit, please give them here. | ||
| 19 | |||
| 20 | >> Please cite any offline or online sources you consulted while | ||
| 21 | >> preparing your submission, other than the Pintos documentation, course | ||
| 22 | >> text, lecture notes, and course staff. | ||
| 23 | |||
| 24 | Stallings, W. - Operating Systems | ||
| 25 | http://en.wikipedia.org/wiki/Priority_inversion | ||
| 26 | http://hynek.me/studies/sched_ausarbeitung.pdf | ||
| 27 | |||
| 28 | PRIORITY SCHEDULING | ||
| 29 | =================== | ||
| 30 | |||
| 31 | ---- DATA STRUCTURES ---- | ||
| 32 | |||
| 33 | >> B1: Copy here the declaration of each new or changed `struct' or | ||
| 34 | >> `struct' member, global or static variable, `typedef', or | ||
| 35 | >> enumeration. Identify the purpose of each in 25 words or less. | ||
| 36 | |||
| 37 | >> B2: Explain the data structure used to track priority donation. | ||
| 38 | >> Use ASCII art to diagram a nested donation. (Alternately, submit a | ||
| 39 | >> .png file.) | ||
| 40 | |||
| 41 | ---- ALGORITHMS ---- | ||
| 42 | |||
| 43 | >> B3: How do you ensure that the highest priority thread waiting for | ||
| 44 | >> a lock, semaphore, or condition variable wakes up first? | ||
| 45 | |||
| 46 | >> B4: Describe the sequence of events when a call to lock_acquire() | ||
| 47 | >> causes a priority donation. How is nested donation handled? | ||
| 48 | |||
| 49 | >> B5: Describe the sequence of events when lock_release() is called | ||
| 50 | >> on a lock that a higher-priority thread is waiting for. | ||
| 51 | |||
| 52 | ---- SYNCHRONIZATION ---- | ||
| 53 | |||
| 54 | >> B6: Describe a potential race in thread_set_priority() and explain | ||
| 55 | >> how your implementation avoids it. Can you use a lock to avoid | ||
| 56 | >> this race? | ||
| 57 | |||
| 58 | ---- RATIONALE ---- | ||
| 59 | |||
| 60 | >> B7: Why did you choose this design? In what ways is it superior to | ||
| 61 | >> another design you considered? | ||
| 62 | |||
| 63 | SURVEY QUESTIONS | ||
| 64 | ================ | ||
| 65 | |||
| 66 | Answering these questions is optional, but it will help us improve the | ||
| 67 | course in future quarters. Feel free to tell us anything you | ||
| 68 | want--these questions are just to spur your thoughts. You may also | ||
| 69 | choose to respond anonymously in the course evaluations at the end of | ||
| 70 | the quarter. | ||
| 71 | |||
| 72 | >> In your opinion, was this assignment, or any one of the three problems | ||
| 73 | >> in it, too easy or too hard? Did it take too long or too little time? | ||
| 74 | |||
| 75 | >> Did you find that working on a particular part of the assignment gave | ||
| 76 | >> you greater insight into some aspect of OS design? | ||
| 77 | |||
| 78 | >> Is there some particular fact or hint we should give students in | ||
| 79 | >> future quarters to help them solve the problems? Conversely, did you | ||
| 80 | >> find any of our guidance to be misleading? | ||
| 81 | |||
| 82 | >> Do you have any suggestions for the TAs to more effectively assist | ||
| 83 | >> students, either for future quarters or the remaining projects? | ||
| 84 | |||
| 85 | >> Any other comments? | ||
diff --git a/threads/thread.c b/threads/thread.c index 845f059..3fefbd8 100644 --- a/threads/thread.c +++ b/threads/thread.c | |||
| @@ -71,6 +71,16 @@ static void schedule (void); | |||
| 71 | void thread_schedule_tail (struct thread *prev); | 71 | void thread_schedule_tail (struct thread *prev); |
| 72 | static tid_t allocate_tid (void); | 72 | static tid_t allocate_tid (void); |
| 73 | 73 | ||
| 74 | //TODO: should take donated priority into account | ||
| 75 | static bool | ||
| 76 | ready_list_cmp_less(const struct list_elem *a, const struct list_elem *b, | ||
| 77 | void *AUX UNUSED) | ||
| 78 | { | ||
| 79 | struct thread *t1 = list_entry (a, struct thread, elem); | ||
| 80 | struct thread *t2 = list_entry (b, struct thread, elem); | ||
| 81 | return (t1->priority > t2->priority); | ||
| 82 | } | ||
| 83 | |||
| 74 | /* Initializes the threading system by transforming the code | 84 | /* Initializes the threading system by transforming the code |
| 75 | that's currently running into a thread. This can't work in | 85 | that's currently running into a thread. This can't work in |
| 76 | general and it is possible in this case only because loader.S | 86 | general and it is possible in this case only because loader.S |
| @@ -212,6 +222,7 @@ thread_create (const char *name, int priority, | |||
| 212 | 222 | ||
| 213 | /* Add to run queue. */ | 223 | /* Add to run queue. */ |
| 214 | thread_unblock (t); | 224 | thread_unblock (t); |
| 225 | thread_yield (); | ||
| 215 | 226 | ||
| 216 | return tid; | 227 | return tid; |
| 217 | } | 228 | } |
| @@ -249,7 +260,8 @@ thread_unblock (struct thread *t) | |||
| 249 | 260 | ||
| 250 | old_level = intr_disable (); | 261 | old_level = intr_disable (); |
| 251 | ASSERT (t->status == THREAD_BLOCKED); | 262 | ASSERT (t->status == THREAD_BLOCKED); |
| 252 | list_push_back (&ready_list, &t->elem); | 263 | /* add thread to our ordered ready_list */ |
| 264 | list_insert_ordered (&ready_list, &t->elem, &ready_list_cmp_less, NULL); | ||
| 253 | t->status = THREAD_READY; | 265 | t->status = THREAD_READY; |
| 254 | intr_set_level (old_level); | 266 | intr_set_level (old_level); |
| 255 | } | 267 | } |
| @@ -320,7 +332,7 @@ thread_yield (void) | |||
| 320 | 332 | ||
| 321 | old_level = intr_disable (); | 333 | old_level = intr_disable (); |
| 322 | if (cur != idle_thread) | 334 | if (cur != idle_thread) |
| 323 | list_push_back (&ready_list, &cur->elem); | 335 | list_insert_ordered (&ready_list, &cur->elem, &ready_list_cmp_less, NULL); |
| 324 | cur->status = THREAD_READY; | 336 | cur->status = THREAD_READY; |
| 325 | schedule (); | 337 | schedule (); |
| 326 | intr_set_level (old_level); | 338 | intr_set_level (old_level); |
| @@ -348,6 +360,14 @@ void | |||
| 348 | thread_set_priority (int new_priority) | 360 | thread_set_priority (int new_priority) |
| 349 | { | 361 | { |
| 350 | thread_current ()->priority = new_priority; | 362 | thread_current ()->priority = new_priority; |
| 363 | |||
| 364 | /* compare priority with the highest priority in the list */ | ||
| 365 | if (!list_empty (&ready_list)) | ||
| 366 | { | ||
| 367 | struct thread *t = list_entry (list_front (&ready_list), struct thread, elem); | ||
| 368 | if (t->priority > thread_current ()->priority) | ||
| 369 | thread_yield(); | ||
| 370 | } | ||
| 351 | } | 371 | } |
| 352 | 372 | ||
| 353 | /* Returns the current thread's priority. */ | 373 | /* Returns the current thread's priority. */ |
