ECS150 Discussion - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

ECS150 Discussion

Description:

Kernel is unaware of user-level threads ... Kernel can schedule threads on different processors in multiprocessor environment ... many as user threads as wishes ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 37
Provided by: csln
Category:

less

Transcript and Presenter's Notes

Title: ECS150 Discussion


1
ECS150 Discussion
  • 10/28/2004
  • Lynn Nguyen

2
TA Website
  • http//wwwcsif.cs.ucdavis.edu/nguyenly/

3
Announcement
  • Extra OH
  • T 100 430pm (Midterm question)
  • Th 100-400pm (Homework1 question)

4
Homework1 Help
  • System call setProcessPriority() must access the
    process table
  • Process table is located inside the kernel
  • Must go between user-space to server-space(MM),
    and then server-space(MM) to kernel-space to
    access the process table

5
System Call Control Flow
  • /usr/include/prioirity.h

setProcessPriority() library function Call
accessible from user space. Calls _syscall(MM,
SETPRIORITY, m) Function trapping to kernel.
User Process
MM
1. setProcessPrioirity (2, 100)
System
Kernel
6
  • priority.h setProcessPriority()
  • traps to kernel
  • /usr/src/lib/other/syscall.c _syscall()
  • - the syscall function determins the
  • message is for the MM and pass control to the
    MM


User Process
MM
1
2. _sendrec(MM, msg)
System
Kernel
7
  • priority.h setProcessPriority() traps
  • to kernel
  • /usr/src/lib/other/syscall.c sendrec()
  • directs message to MM
  • /usr/src/mm/table.c call_vec()
  • function receives message and dete-
  • mines which function to execute
  • /usr/src/mm/misc.c implements
  • function, e.g. do_setpriority, which
  • includes a call to systask defined
  • in /usr/src/kernel/system.c


User Process
MM
1
2
3. _taskcall(SYSTASK, SYS_SETPRIORITY, m)
System
Kernel
8
1. priority.h setProcessPriority() traps
to kernel 2 /usr/src/lib/other/syscall.c
sendrec() directs message to MM 3.
/usr/src/mm/misc.c invokes _taskcall
include ltminix/com.hgt here 4. sys_task()
receives message, dete- mines which function
to perform within kernel code, as defined in
/usr/include/minix/com.h this function has
access to the kernel globals and can update
values in proc table
User Process
MM
1
2
3
System
Kernel
4. do_syspriority(m)
9
1. priority.h setProcessPriority() traps
to kernel 2 /usr/src/lib/other/syscall.c
sendrec() directs message to MM 3.
/usr/src/kernel/misc.c invokes _taskcall 4.
/usr/src/kernel/system.c do_setpriority()
modifies kernel structures. 5. Returns value from
do_syspriority() function

User Process
MM
1
2
5. Return value
3
System
Kernel
4
10
1. priority.h setProcessPriority() traps
to kernel 2 /usr/src/lib/other/syscall.c
sendrec() directs message to MM 3.
/usr/src/kernel/misc.c invokes _taskcall 4.
/usr/src/kernel/system.c do_setpriority()
modifies kernel structures. 5. Returns value from
do_syspriority() function 6. Propagates return
value from do_setpriority() function

User Process
MM
1
2
5.
3
6. Return value
System
Kernel
4
11
1. priority.h setProcessPriority() traps
to kernel 2 /usr/src/lib/other/syscall.c
sendrec() directs message to MM 3.
/usr/src/kernel/misc.c invokes _taskcall 4.
/usr/src/kernel/system.c do_setpriority()
modifies kernel structures. 5. Returns value from
do_setpriority() function 6. Propagates return
value from do_setpriority() function 7.
Returns from syscall with the propagated
return value
User Process
MM
7. Return value
1
2
5.
3
6
System
Kernel
4
12
Adding MINIX System Call
13
Homework1 help
  • setProcessPriority( pid, priority)
  • sets the priority for the process to priority
  • setProcessPriority( pid, priority)
  • Should return the priority actually assigned
    to process pid

14
Proc Table
proc0
TASK_ADDR
procNR_TASKS
SERVER_ADDR
procNR_TASKS LOW_USER
USER_ADDR
USER_ADDR
Where we are interested in
procNR_TASKSNR_PROCS
15
Loop Through the Proc Table
  • define BEG_PROC_ADDR (proc0)
  • define END_PROC_ADDR (procNR_TASKS
    NR_PROCS)
  • define END_TASK_ADDR (procNR_TASKS)
  • define BEG_SERV_ADDR (procNR_TASKS)
  • define BEG_USER_ADDR (procNR_TASKS
    LOW_USER)
  • All defined in /usr/src/kernel/proc.c

16
List of files to modify
  • User space
  • /usr/include/unistd.h
  • Add prototype for system call
  • /usr/include/priority.h
  • Invoke _syscacll through message passing
  • /usr/include/minix/callnr.h
  • Set system call number
  • /usr/include/minix/com.h
  • add systask for SYSPRIORITY
  • /usr/include/minix/config.h
  • Turn on/off the debugger

17
List of files to modify
  • MM
  • /usr/src/fs/table.c
  • Put entry in call_vec
  • /usr/src/mm/table.c
  • Add entry to call_vec on mm side
  • /usr/src/mm/proto.h
  • Add prototype for do_setpriority
  • /usr/src/mm/misc.c
  • Implement MM side do_setpriority
  • Invoke _taskcall

18
List of files to modify
  • Kernel
  • /usr/src/kernel/main.c
  • ?? (for you)
  • /usr/src/kernel/proc.h
  • Add a field to proc table
  • /usr/src/kernel/proc.c
  • Implement the actual priority scheduling
  • Use LinkedList implementation by using
    rdy_headUSER_Q
  • rdy_tailUSER_Q, and p_nextready
  • /usr/src/kernel/system.c
  • Add kernel side do_syspriority
  • What else?

19
Midterm review
20
Chapter1 Chapter 3
  • System calls interface b/w process and OS
  • see page 66 for categories of system calls

21
Context Switching
22
Context Switch
  • Important
  • Context Switch time is pure over-head. The
    system does no useful work while switching.
  • One reason that we prefer threads over processes

23
User Threads vs. Kernel Threads
  • User Threads
  • Thread management done by user-level
  • No support/intervention from kernel
  • Kernel is unaware of user-level threads
  • Problem if the kernel is single-threaded, then
    any user-level thread performing a blocking
    system call will cause the entire process to
    block, even if other threads are available to run
    within the application

24
User Threads vs. Kernel Threads
  • Kernel Threads
  • Supported directly by the kernel
  • Thread management done in kernel-space
  • Kernel threads are slower to create manage
  • If a thread performs a blocking system call, the
    kernel can schedule another thread in the
    application for execution
  • Kernel can schedule threads on different
    processors in multiprocessor environment

25
Multithreading model
  • Many-to-one
  • pros efficient since thread management is done
    in user space
  • Cons
  • Entire process blocks if a thread makes a
    blocking system call
  • Multiple threads are unable to run in parallel on
    multiprocessors

26
Multithreading model
  • One-to-one model
  • Pros
  • More concurrency allowing another thread to run
    when a thread makes a blocking system call
  • Allow multiple threads to run in parallel on
    multiprocessors
  • Cons
  • Creating a user thread requires creating the
    corresponding kernel thread
  • Overhead restrict the number of threads supported
    by the system

27
Multithreading model
  • Many-to-many model
  • Pros
  • Can create as many as user threads as wishes
  • The corresponding kernel threads can run in
    parallel on a multiprocessor
  • When a thread performs a blocking system call,
    the kernel can schedule another thread for
    execution
  • Cons
  • True concurrency is not gained since the kernel
    can schedule only one thread at a time

28
CPU Scheduling
  • FCFS (nonpreemptive)
  • Pros
  • Easy to implement
  • Efficient-minimize context switching
  • Cons
  • Penalty ratio for short jobs much greater than
    for long jobs
  • Convoy effect all processes wait for the one
    big process to get off the CPU. Results in lower
    CPU and device utilization
  • Shortest Job first (nonpreemptive or preemptive)
  • Problem difficulty of knowing the length of the
    next CPU request

29
CPU scheduling
  • Priority (nonpreemptive or preemptive)
  • Major problem starvation
  • Solution aging. Gradually increase the
    priority of waiting process
  • Round Robin (preemptive)
  • Quantum to be large with respect to context
    switch time
  • If quantum is too large, RR becomes FCFS
  • Rule 80 of the CPU bursts should be shorter
    than the time quantum

30
CPU scheduling
  • Multilevel queue
  • Partition the ready queue into several separate
    queues
  • Multilevel feedback queue scheduling
  • Let a process move between queues.
  • Same as aging process waits too long in the low
    priority queue moves to higher.

31
CPU scheduling
  • Lottery Scheduling

2
34
50
10
23
1
6
15
3
1
24..26
38
11
2..2
9.23
If a random number 10 is generated, who will win
the lottery?
32
CPU scheduling
  • Lottery Scheduling

2
34
50
10
23
1
6
15
3
1
24..26
38
11
2..2
9.23
If a random number 10 is generated, who will win
the lottery?
PID 34
33
Semaphore
  • Wait(S)
  • S.Value --
  • If (S.value lt 0)
  • Add this process to the queue
  • block //suspend the process
  • Signal(S)
  • S.Value
  • If (S.value lt 0)
  • remove a process P from the queue
  • wakeup(P) //resume execution of Ps

34
Deadlock
  • P0 P1
  • wait(S) S-- wait(Q) Q--
  • wait(Q) wait(S)
  • Signal(S) Signal(Q)
  • Signal(Q) Signal(S)

S and Q are two semaphores initialize to 1
35
Is it safe?
  • Process 1
  • while(check1 TRUE)
  • check0 FALSE while(check1 TRUE)
  • check0 TRUE ltcritical sectiongt
    check0 FALSE ....
  • Process 2 .... while(check0 TRUE)
  • check1 FALSE while(check0 TRUE)
  • check1 TRUE ltcritical sectiongt check1
    FALSE ....

L1
L2
L3
L4
L5
L6
Check0
FALSE
UNSAFE
FALSE
Check1
36
Is it Deadlock free?
  • Process 1
  • while(check1 TRUE)
  • check0 FALSE while(check1 TRUE)
  • check0 TRUE ltcritical sectiongt
    check0 FALSE ....
  • Process 1 .... while(check0 TRUE)
  • check1 FALSE while(check0 TRUE)
  • check1 TRUE ltcritical sectiongt check1
    FALSE ....

L1
L2
L3
L4
L5
L6
Start Value
L4
L2
TRUE
FALSE
Check0
TRUE
DEADLOCK
Check1
TRUE
FALSE
TRUE
Write a Comment
User Comments (0)
About PowerShow.com