Blue-club / pintos_5

Other
0 stars 3 forks source link

[Project 1-2] Priority Scheduling(mywnajsldkf) #10

Open mywnajsldkf opened 1 year ago

mywnajsldkf commented 1 year ago

7. Priority Scheduling ๐Ÿ“…

โœ ๊ณผ์ œ ๋ฏธ์…˜

๐Ÿ‘พ ์ž‘์—…

Priority Scheduling

โญ๏ธ ์ƒ๊ฐํ•  ์ 


8. Priority Scheduling and Synchronization

โœ ๊ณผ์ œ ๋ฏธ์…˜

๐Ÿ‘พ ์ž‘์—…

Priority Scheduling-Synchronization

โญ๏ธ ์ƒ๊ฐํ•  ์ 

mywnajsldkf commented 1 year ago

7. Priority Scheduling ์‹คํ–‰ ๊ฒฐ๊ณผ

pintos/threads์—์„œ make check๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. Screenshot 2023-05-31 at 12 06 39 AM

๋ถ€๋ถ„๋งŒ ํ…Œ์ŠคํŠธํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, pintos/threads/build์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰ํ•œ๋‹ค.

pintos -v -k -T 60 -m 20 -- -q run priority-fifo < /dev/null 2> tests/threads/priority-fifo.errors > tests/threads/priority-fifo.output
perl -I../.. ../../tests/threads/priority-fifo.ck tests/threads/priority-fifo tests/threads/priority-fifo.result

Screenshot 2023-05-31 at 12 09 19 AM

mywnajsldkf commented 1 year ago

8. Priority Scheduling and Synchronization ์‹คํ–‰ ๊ฒฐ๊ณผ

Screenshot 2023-05-31 at 7 59 41 AM

์ฒซ๋ฒˆ์งธ ์‹œ๋„์—์„œ priority-codvar ํ…Œ์ŠคํŠธ ํ†ต๊ณผ๋ฅผ ํ•˜์ง€ ๋ชปํ–ˆ๋Š”๋ฐ, ํ™•์ธํ•ด๋ณด๋‹ˆ ์ง์ ‘ ๊ตฌํ˜„ํ•œ cmp_sem_priority ๋ฌธ์ œ์˜€๋‹ค. list_front ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ธ๋งˆํฌ์–ด wait list์˜ ์ฒซ๋ฒˆ์งธ ์Šค๋ ˆ๋“œ๋ฅผ ํ™•์ธํ–ˆ๋Š”๋ฐ, ๋งŒ์•ฝ wait list์— ์•„๋ฌด๊ฒƒ๋„ ์—†๋‹ค๋ฉด list_front์—์„œ list๊ฐ€ ๋นˆ์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” assert์— ๊ฑธ๋ฆด ๊ฒƒ์ด๋‹ค! ๋งŒ์•ฝ list_begin ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ด ๋ถ€๋ถ„์„ ๊ฑธ๋ฆฌ์ง€ ์•Š์„ํ…๋ฐ... ํ ,,, ์™œ ๋‘ ํ•จ์ˆ˜๋ฅผ ๊ตฌ๋ถ„ํ•ด๋‘์—ˆ๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค. ๐Ÿง ์ผ๋‹จ list_empty ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ๋น„์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ์‹์œผ๋กœ ์ˆ˜์ •ํ•˜๋‹ˆ ํ†ต๊ณผ๋˜์—ˆ๋‹ค.

struct list_elem *
list_front (struct list *list) {
    ASSERT (!list_empty (list));
    return list->head.next;
}
mywnajsldkf commented 1 year ago

cmp_sem_priority ์ง„ํ–‰ ์ค‘ ๋ฐœ์ƒํ•œ ์ฐธ์กฐ ๋ฌธ์ œ

bool
cmp_sem_priority (const struct list_elem *a, const struct list_elem *b, void *aux) {
    struct semaphore_elem *sa = list_entry(a, struct semaphore_elem, elem);
    struct semaphore_elem *sb = list_entry(b, struct semaphore_elem, elem);

    if (!list_empty(&(sa->semaphore.waiters)) && !list_empty(&(sb->semaphore.waiters)))
    {
        struct thread *a_thread = list_entry(list_front(&(sa->semaphore.waiters)), struct thread, elem);
        struct thread *b_thread = list_entry(list_front(&(sb->semaphore.waiters)), struct thread, elem);
        return a_thread->priority > b_thread->priority;
    }
}

์ด ์ฝ”๋“œ์— ๋ฌธ์ œ๊ฐ€ ์žˆ์„๊นŒ์š”? ๋‹ต์€ ์—†์Šต๋‹ˆ๋‹ค...

๊ทผ๋ฐ ์™œ ์•ˆ๋Œ์•„๊ฐ€๊ณ , ๊ณ„์† list_elem(semaphore_elem)์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ  ์—๋Ÿฌ์ฝ”๋“œ๋Š” ๋˜์ง€๊ณ  ์žˆ๋Š” ๊ฒƒ์ผ๊นŒ์š”??

์ผ๋‹จ,,, ๋‹ค๋ฅธ ์กฐ์›์ด ์ž‘์„ฑํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์†Œ์Šค ์ฝ”๋“œ ๊ฐ€์žฅ ๋ฐ‘์œผ๋กœ ์ด๋™์‹œ์ผฐ์Šต๋‹ˆ๋‹ค.

์Œ ์ผ๋‹จ ๋˜์ง€๋งŒ ์ฐ์ฐํ•ฉ๋‹ˆ๋‹ค...

๋ฌธ์ œ๊ฐ€ ๋ฌด์—‡์ผ๊นŒ์š”??

๊ทธ๊ฒƒ์€ ๋ฐ”๋กœ....

// ์•ฝ 160์ค„
bool
cmp_sem_priority (const struct list_elem *a, const struct list_elem *b, void *aux) {
    struct semaphore_elem *sa = list_entry(a, struct semaphore_elem, elem);
    struct semaphore_elem *sb = list_entry(b, struct semaphore_elem, elem);

    if (!list_empty(&(sa->semaphore.waiters)) && !list_empty(&(sb->semaphore.waiters)))
    {
        struct thread *a_thread = list_entry(list_front(&(sa->semaphore.waiters)), struct thread, elem);
        struct thread *b_thread = list_entry(list_front(&(sb->semaphore.waiters)), struct thread, elem);
        return a_thread->priority > b_thread->priority;
    }
}

... 

// ๋Œ€๋žต 250์ค„์—์„œ semaphore_elem์„ ๋งŒ๋‚  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค...
/* One semaphore in a list. */
struct semaphore_elem {
    struct list_elem elem;              /* List element. */
    struct semaphore semaphore;         /* This semaphore. */
};

์•Œ๊ณ ๋ณด๋‹ˆ! semaphore_elem ๊ตฌ์กฐ์ฒด ์„ ์–ธ ์ „์— semaphore_elem์„ ์ฐพ๊ณ  ์žˆ์—ˆ๋„ค์š”... ํ ,,, ์™œ ์ด๋ ‡๊ฒŒ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ–ˆ์„๊นŒ์š”? header ํŒŒ์ผ๋กœ ์ด๋™ํ•ด๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์€๋ฐ ๋ง์ด์ฃ ... ์˜๋„๊ฐ€ ์žˆ์„๊นŒ์š”?

์•”ํŠผ ์ด๊ฒƒ์„ ํ•ด๊ฒฐํ•˜๋Š”๋ฐ 1์‹œ๊ฐ„ 30๋ถ„์ด ๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค...

feat. ๊ฐ™์ด ๋จธ๋ฆฌ๋ฅผ ํ•จ๊ป˜ ๋ชจ์•„์ค€,,, 99์ฆˆ ํ”„๋ Œ์ฆˆ Thanks a lot!๐Ÿ‘ @KimCookieYa @chwangmin