COMP 252 Operating Systems - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

COMP 252 Operating Systems

Description:

Review questions week #6. Please refer to our course web ... stub locates the server and marshalls the parameters, where marshalling involves ... – PowerPoint PPT presentation

Number of Views:71
Avg rating:3.0/5.0
Slides: 36
Provided by: cse2
Category:

less

Transcript and Presenter's Notes

Title: COMP 252 Operating Systems


1
COMP 252Operating Systems
  • Lab 03

2
Outline
  • Review questions
  • Remote Procedure Calls
  • Nachos Threads
  • Nachos Thread Scheduling
  • Nachos Thread Switching
  • Project_1

3
Review questions week 6
  • Please refer to our course web
  • http//course.cse.ust.hk/comp252/web07fall/Lab3/la
    b03_review.pdf

4
Process
Process
  • Low switch overhead
  • Easy to communicate
  • Improve the response time

Code segment Stack segment Data segment Process
state Program counter Content of registers CPU
scheduling info. I/O status info
Code segment Data segment Process state Program
counter
GUI
Time consuming computation
Thread
Thread
Register set Stack Priority
Register set Stack Priority
5
Remote Procedure Calls
  • In client-server communication model, socket is a
    common technique and remote procedure call is
    another.
  • Remote procedure call (RPC) abstracts procedure
    calls between processes on networked systems.
  • Stubs client-side proxy for the actual
    procedure on the server.

6
Remote Procedure Calls
  • The client-side stub locates the server and
    marshalls the parameters, where marshalling
    involves packaging the parameters into a form
    that can be transmitted.
  • The server-side stub receives this message,
    unpacks the marshalled parameters, and performs
    the procedure on the server.
  • Also see textbook p800-801

7
Execution of RPC
8
Nachos Threads
  • In Nachos (and many systems) a process consists
    of
  • An address space, which is further broken down
    into
  • 1) Executable code
  • 2) Stack space for local variables
  • 3) Heap space for global variables and
    dynamically allocated memory

9
Nachos Threads
  • A single thread of control, e.g., the CPU
    executes instructions sequentially within the
    process
  • Other objects, such as open file descriptors

10
Nachos Threads
  • It is sometimes useful to allow multiple threads
    of control to execute concurrently within a
    single process.
  • These individual threads of control are called
    threads.
  • One big difference between threads and processes
    is that global variables are shared among all
    threads.

11
Nachos Threads
  • Nachos provides threads
  • Nachos threads execute and share the same code
    (the Nachos source code)
  • and share the same global variables
  • The Nachos scheduler maintains a data structure
    called a ready list, which keeps track of the
    threads that are ready to execute.

12
Nachos Threads
  • Threads on the ready list are ready to execute
    and can be selected for executing by the
    scheduler at any time.
  • Each thread has an associated state describing
    what the thread is currently doing.
  • Nachos' threads are in one of four states READY,
    RUNNING, BLOCKED, JUST_CREATED

13
Thread(name)
ThreadFork(Func,args)
JUST_CREATED
Ready
Add into ready list
Processor is available, Scheduler selects it out
from ready list
Resource available
Running
Blocked
Waiting for some resource Threadsleep()
14
Nachos Threads
  • READY
  • The thread is eligible to use the CPU (e.g., it's
    on the ready list), but another thread happens to
    be running.
  • When the scheduler selects a thread for
    execution, it removes it from the ready list and
    changes its state from READY to RUNNING.
  • Only threads in the READY state should be found
    on the ready list.

15
Nachos Threads
  • RUNNING
  • The thread is currently running.
  • Only one thread can be in the RUNNING state at a
    time.
  • In Nachos, the global variable currentThread
    always points to the currently running thread.

16
Nachos Threads
  • BLOCKED
  • The thread is blocked waiting for some external
    event it cannot execute until that event takes
    place.
  • Specifically, the thread has put itself to sleep
    via ThreadSleep().
  • It may be waiting on a condition variable,
    semaphore, etc.

17
Nachos Threads
  • JUST_CREATED
  • The thread exists, but has no stack yet.
  • This state is a temporary state used during
    thread creation.
  • The Thread constructor creates a thread, whereas
    ThreadFork() actually turns the thread into one
    that the CPU can execute (e.g., by placing it on
    the ready list).

18
Nachos Threads
  • Nachos does not maintain an explicit process
    table.
  • Instead, information associated with thread is
    maintained as (usually) private data of a Thread
    object instance.
  • To get at a specific thread's information, a
    pointer to the thread instance is needed.

19
Nachos Threads
  • The Nachos Thread object supports the following
    operations
  • Thread Thread(char debugName)
  • Fork(VoidFunctionPtr func, int arg)
  • void StackAllocate(VoidFunctionPtr func, int arg)
  • void Yield(), void Sleep(), void Finish()
  • More details on our course web (http//course.cse.
    ust.hk/comp252/web07fall/Lab3/nachos_threads.html)

20
Nachos Thread Scheduling
  • Threads that are ready to run are kept on the
    ready list.
  • A process is in the READY state only if it has
    all the resources it needs, other than the CPU
  • Processes blocked waiting for I/O, memory, etc.
    are generally stored in a queue associated with
    the resource being waited on.

21
Nachos Thread Scheduling
  • The scheduler decides which thread to run next.
  • The scheduler is invoked whenever the current
    thread wishes to give up the CPU.
  • e.g., the current thread may have initiated an
    I/O operation and must wait for it to complete
    before executing further.

22
Nachos Thread Scheduling
  • A simple scheduling policy threads reside on a
    single, unprioritized ready list, and threads are
    selected in a round-robin fashion.
  • That is, threads are always appended to the end
    of the ready list, and the scheduler always
    selects the thread at the front of the list.

23
Nachos Thread Scheduling
  • Alternatively, Nachos may preempt the current
    thread in order to prevent one thread from
    monopolizing the CPU.
  • Scheduling is handled by routines in the
    Scheduler object with the following operations
  • void ReadyToRun(Thread thread)
  • Thread FindNextToRun()
  • void Run(Thread nextThread)

24
Nachos Thread Scheduling
  • void ReadyToRun(Thread thread)
  • Make thread ready to run and place it on the
    ready list.
  • Note that ReadyToRun doesn't actually start
    running the thread it simply changes its state
    to READY and places it on the ready list.
  • The thread won't start executing until later,
    when the scheduler chooses it.

25
Nachos Thread Scheduling
  • Thread FindNextToRun()
  • Select a ready thread and return it.
  • For round-robin fashion, FindNextToRun simply
    returns the thread at the front of the ready
    list.

26
Nachos Thread Scheduling
  • void Run(Thread nextThread)
  • Do the dirty work of suspending the current
    thread and switching to the new one.
  • Note that it is the currently running thread that
    calls Run().
  • A thread calls this routine when it no longer
    wishes to execute.
  • More details on our course web (http//course.cse.
    ust.hk/comp252/web07fall/Lab3/nachos_thrsched.html
    )

27
Nachos Thread Switching
  • Switching the CPU from one thread to another
    involves
  • suspending the current thread
  • saving its state (e.g., registers)
  • then restoring the state of the thread being
    switched to

28
Nachos Thread Switching
  • The thread switch actually completes at the
    moment a new program counter is loaded into PC.
  • At that point, the CPU is no longer executing the
    thread switching code, it is executing code
    associated with the new thread.

29
Nachos Thread Switching
  • The routine Switch(oldThread, nextThread)
    actually performs a thread switch
  • Save all registers in oldThread's context block
    and suspend it
  • load new values into the registers from the
    context block of the nextThread
  • Once the saved PC is loaded, Switch() is no
    longer executing we are now executing
    instructions associated with the new thread

30
Nachos Thread Switching
  • After returning from Switch, the previous thread
    is no longer running. Thread nextThread is
    running now.
  • The routine Switch() is written in assembly
    language because it is a machine-depended
    routine.
  • It has to manipulate registers, look into the
    thread's stack, etc.

31
Nachos Thread Switching
  • More details on our course web (http//course.cse.
    ust.hk/comp252/web07fall/Lab3/nachos_thrswitch.htm
    l)

32
Project_1
  • Please download the Project_1 instruction from
    our course web
  • http//course.cse.ust.hk/comp252/web07fall/

33
The end.
34
deadlock
  • In the computing world deadlock refers to a
    specific condition when two or more processes are
    each waiting for another to release a resource,
    or more than two processes are waiting for
    resources in a circular chain (see Necessary
    conditions). Deadlock is a common problem in
    multiprocessing where many processes share a
    specific type of mutually exclusive resource
    known as a software, or soft, lock. Computers
    intended for the time-sharing and/or real-time
    markets are often equipped with a hardware lock
    (or hard lock) which guarantees exclusive access
    to processes, forcing serialization. Deadlocks
    are particularly troubling because there is no
    general solution to avoid (soft) deadlocks.

35
Remote procedure call (RPC)
  • Remote procedure call (RPC) is a technology that
    allows a computer program to cause a subroutine
    or procedure to execute in another address space
    (commonly on another computer on a shared
    network) without the programmer explicitly coding
    the details for this remote interaction. That is,
    the programmer would write essentially the same
    code whether the subroutine is local to the
    executing program, or remote.
Write a Comment
User Comments (0)
About PowerShow.com