DOC PREVIEW
Princeton COS 318 - Project #4

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COS318 - Project #4OverviewReview - Processes and ThreadsReview - Processes and Threads cont’dOverview - Preemptive SchedulerOverview - System Call MechanismInterrupt Mechanism - In detailOverview - Context switchingOverview - Context switching cont’dContext Switching Details – MacrosContext Switching Details – ThreadsContext Switching Details – ProcessesContext Switching Details – Processes and ThreadsOverview - Thread SynchronizationOverview - Thread Synchronization cont’dOverview – Atomic ProcessesSlide 17Atomicity – DetailsAtomicity – Details cont’dAtomicity – Thread Synchronization FunctionsImplementation Details - Code FilesImplementation Details - Code Files cont’dImplementation Details - Extra Credit01/14/19 COS318 - Project #4Preemptive SchedulingFall 200201/14/19 OverviewImplement preemptive OS with:All the functionality of preview project’s OSAdditional thread synchronization:MESA style monitors (condition variables)Support for a preemptive scheduling:Implement the timed interrupt handler (irq0)Enforce all necessary atomicity01/14/19 Review -Processes and ThreadsThreads (trusted)Linked with the kernelCan share address space, variables, etc.Access kernel services (yield, exit, lock_*, condition_*,getpid(),*priority()) with direct calls to kernel functionsUse a single stack while running thread code and kernel code*Differences from previous project in italics01/14/19 Review -Processes and Threads cont’dProcesses (untrusted)Linked separately from kernelAppear after kernel in image file Cannot share address space, variables, etc.Access kernel services (yield, exit, getpid, *priority) via a unified system call mechanismUse a user stack while running process code and a kernel stack whilst running kernel level code*Differences from previous project in italics01/14/19 Overview -Preemptive SchedulerInitial proc/thread is dispatched at start timeProcesses voluntarily stop running by a system call interrupt invoking yield() or exit()Threads voluntarily stop running by a direct system call invoking yield(), exit() or block()block() is nested in lock_acquire() or condition_wait() Proc/threads involuntarily stop running due to a timer interrupt, irq0()Interrupt/Direct system calls invoke context savesScheduler is invoked to save kernel stack, select next available proc/thread from linked & dispatch*Differences from previous project in italics01/14/19 Overview -System Call MechanismThreads can call to system calls (yield(), exit(), lock_*(), condition_*(), getpid(), *priority()) directlyProcesses use system call interrupt mechanism to access system services (yield(), exit(), getpid(), *priority())Jump table, system_call_entry(), allows access to fixed set of kernel servicesAddress of jump table is specified in a Interrupt Descriptor Table (IDT)IDT’s location (in kernel) is specified to the CPUSoftware interrupt 48 (with desired service specified in eax) can then invoke system_call_entry()syslib.c maps system calls to int 48 with eax argument01/14/19 Interrupt Mechanism -In detail The following diagram shows how the interrupt mechanism works:0x1000 IDTInt 0Int 32Int 48system_call_entry()irq0()CPU*Every 10ms hardware interrupt IRQ0 invokes Int 3201/14/19 Overview -Context switching Contexts initialized for each PCB during startupUnique kernel and user stacks are assignedStarting addresses are storedContext (eflags and registers (including stack)) saved when execution is halted:For Threads At start of yield() call before call to schedule()At end of block() call before call to schedule()For Processes At start of system_call_entry() before potential call to _yield() (and hence to schedule())For BOTH:At start of irq0() before call to schedule()01/14/19 Overview -Context switching cont’dContext is swapped in by dispatcher but not as in the previous projectFirst time Set appropriate stack pointer and jump to starting address (as before)Subsequent times Restore the kernel_stack saved at start of schedule()Note that this is different from the stack saved as part of the context (regs.esp).Let dispatch() return so that the swapped in proc/thread returns from that schedule() call via return address stored on top of the saved stack. Context is restored by the code following said call to schedule().01/14/19 Context Switching Details –MacrosSAVE_GEN_REGS, RESTORE_GEN_REGSSaves and restores eax, ebx, ecx, edx, esi, edi, ebp, esp to current_running->regs.eax, ->regs.ebx, etc.Used in saving/restoring contextSAVE_EFLAGS, RESTORE_EFLAGSUses present stack to push and pop the processor status word to and from current_running->regs.eflagsUsed is saving/restoring thread context (interrupt mechanism automatically handles eflags for procs)SWITCH_TO_KERNEL_STACK, SAVE_KERNEL_STACKUses current_running->kernel_stack to restore and save the present stack, esp.Used in schedule()/dispatch(), system_call_entry(), and irq0() (for processes)01/14/19 Context Switching Details –Threadsyield()Context (eax,ebx,…,esp & eflags) saved.Schedule() is invoked and saves kernel_stack before moving to next proc/thread and dispatchingWhen swapped back in, dispatch returns to address on saved kernel stack, at point after schedule()Context (eax,ebx,…,esp & eflags) is restoredYield returns to address on top of stack (to point after yield call)block()PCB is enqueued on lock/condition linked listProceeds exactly as for yield()01/14/19 Context Switching Details –Processessystem_call_entry()eflags and eip are automatically saved because we enter via the interrupt mechanismContext (register set including esp) is saved.Switch to kernel stack.Invoke the desired system call.If scheduler is invoked (via _yield), it saves kernel_stack before moving to next proc/thread and dispatching (just as for threads)When swapped back in, dispatch returns to address on saved kernel stack, at point after schedule() in _yield()_yield() returns into system_call_entry()The kernel stack is savedContext (register set) is restored. ‘iret’ is invoked to restore eflags and return to eip automatically saved on stack upon interrupt entry.01/14/19 Context Switching Details –Processes and Threadsirq0() – What you must implement…eflags and eip are automatically saved


View Full Document

Princeton COS 318 - Project #4

Documents in this Course
Overview

Overview

25 pages

Deadlocks

Deadlocks

25 pages

lectute 2

lectute 2

28 pages

Lecturel

Lecturel

24 pages

Real mode

Real mode

49 pages

Lecture 2

Lecture 2

54 pages

lecture 5

lecture 5

27 pages

Load more
Download Project #4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Project #4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Project #4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?