Ecs150 spring 2006 operating system 1 os architecture kernel process
This presentation is the property of its rightful owner.
Sponsored Links
1 / 139

ecs150 Spring 2006 : Operating System #1: OS Architecture, Kernel, & Process PowerPoint PPT Presentation


  • 87 Views
  • Uploaded on
  • Presentation posted in: General

ecs150 Spring 2006 : Operating System #1: OS Architecture, Kernel, & Process. Dr. S. Felix Wu Computer Science Department University of California, Davis http://www.cs.ucdavis.edu/~wu/ [email protected]

Download Presentation

ecs150 Spring 2006 : Operating System #1: OS Architecture, Kernel, & Process

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006:Operating System#1: OS Architecture, Kernel, & Process

Dr. S. Felix Wu

Computer Science Department

University of California, Davis

http://www.cs.ucdavis.edu/~wu/

[email protected]

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

VM/MVS, DOS, Win95/98/ME/2000/XP, Freebsd/Linux, MacOS-10, Mach, Minix, PalmOS, uCOS, TinyOS, …

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

….where applications meet Hardware!!!

Applications……..

OS

Hardware: CPU/Memory/HD/DVD/Wireless…

ecs150 Spring 2006


Information router

“Information Router”

  • One NIC a process’s user-level memory

  • One file another file

    • OS kernel layer

    • Hardware layer

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

….where applications meet Hardware!!!

Applications……..

OS

Hardware: CPU/Memory/HD/DVD/Wireless…

ecs150 Spring 2006


Virtualization

virtualization

Unmodified Applications

Unmodified OS (XP, Linux, Solaris, or, FreeBSD)

Standard Full Virtualization  e.g.,

VirtualPC

WindowXP

Hardware

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Programmable Virtualization

Unmodified Applications

Unmodified OS (XP, Linux, Solaris, or, FreeBSD)

“Programmable” Full Virtualization

API

DLVM

DLVM

Hardware

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

FreeBSD

Unmodified Applications

Unmodified OS (XP, Linux, Solaris, or, FreeBSD)

API

Virtual PC or VMware

Hardware

ecs150 Spring 2006


This quarter

This quarter….

  • The internals of OS

  • The basic design principles of OS

  • The skills to modify or implement an OS.

ecs150 Spring 2006


Operating system

Operating System

  • An interesting balance between:

    • Theories and Practical Experiences/Experiments

    • Architectural Concept and Detailed Design

    • Formal Verification and Empirical Validation

ecs150 Spring 2006


About the instructor

About the Instructor

  • S. Felix Wu

    • [email protected], x4-7070

  • Office: 3057 Engineering II

  • Office Hours:

    • 1-2 p.m. on Tuesday and Friday

    • by appointment

ecs150 Spring 2006


About the ta

About the TA

  • TA Valerie Szudziejka ([email protected])

    • Office Hours:TBA

    • Discussion:

ecs150 Spring 2006


About web site

about Web site

  • http://www.cs.ucdavis.edu/~wu/ecs150/

  • all lectures, notes, announcements, homework assignments, tools, papers will be there.

ecs150 Spring 2006


Textbook

Textbook

Reading this book itself is a major challenge!!

But, you really learn when you go through this process!

"The Design and Implementation of the FreeBSD Operating Systems" by Marshall Kirk McKusick and George V. Neville-NeilAddison Wesley Professional, 2005, ISBN 0-201-70245-2.

http://www.freebsd.org/

ecs150 Spring 2006


Prerequisites

Prerequisites

  • Programming Languages: C and assembly (ecs50)

  • Date Structure (ecs110) and basic Computer Architecture (ecs154a/eec70).

  • ecs40

  • Please talk to me if you have any concern.

ecs150 Spring 2006


Syllabus

Syllabus

  • Process/Kernel(09)

  • Memory Management (06)

  • midterm

  • IO & File Systems(10)

  • Others(03)

  • final

ecs150 Spring 2006


Os principles concepts

OS Principles/Concepts

  • What is “kernel”?

  • What is the difference between a process and a thread?

  • What is the difference between user-level and kernel-level threads?

  • What is the difference between a system call and a library function call?

  • What are SJF, RR, Lottery, LRU, TLB, Second Chance?

  • How to do Mutual Exclusion?

  • What is the difference between deadlock prevention and avoidance?

  • What are the differences among hardware interrupt, hardware trap, and software trap?

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

OS

  • Let’s examine OS concepts in a realistic context: “FreeBSD”

  • Then, we can re-think those concepts….

    • And, maybe you will realize later that some of the concepts are either “misleading” or “irrelevant” in certain context.

ecs150 Spring 2006


Principles vs practice

Principles vs. Practice

  • Ideas and Theories first, then we will go over some FreeBSD code segments.

  • You will need to learn FreeBSD internals for programming assignments!!

  • The first few discussion sessions will be dedicated to FreeBSD internals.

    • Most of the discussion sessions are very important and they will appear in the exams and homeworks.

ecs150 Spring 2006


Course requirements

Course Requirements

  • 48%: Programming Assignments

    • teamwork: 1~3 students

    • 3 Programming Assignments (12%, 18%, 18%)

    • HW#1 is out (check the website).

  • 16%: In-class open-book midterm

  • 32%: open-book final

  • 04%: Participation of Lectures and Discussion sessions.

    • Deducted if missed more than three sessions.

ecs150 Spring 2006


Grading

Grading

  • I will give +/- grades.

  • possible grading (not finalized):

    • A: >= 93A-: >= 90B+: >= 87

    • B: >= 84B-: >= 81C+: >= 78

    • C: >= 75C-: >= 72D : > 60

ecs150 Spring 2006


Freebsd

FreeBSD

  • Your team need to have access to a FreeBSD environment

    • I386, VMware, VirtualPC

ecs150 Spring 2006


The structure of os

The Structure of OS

  • The Kernel

  • Processes and Threads

  • The System Call Interface

ecs150 Spring 2006


What is kernel

What is “kernel”?

ecs150 Spring 2006


Kernel

Kernel

  • The basic OS services

  • Which services? What is it doing?

  • Let’s check a couple examples

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

….what are the basic services?

OS

ecs150 Spring 2006


Freebsd kernel services

FreeBSD Kernel: Services

  • Timer/clock, descriptor, process

  • Memory Management: paging/swapping

  • I/O control and terminal

  • File System

  • Inter-process communication

  • Networking

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Kernel of svr2 of at t unix

Kernel of SVR2 of AT&T Unix

User programs

Libraries

user

trap

System Call Interface

File subsys

Process

Control

Subsys.

Inter-Process

Communication

Buffer cache

kernel

Scheduler

Character block

device drivers

Memory

Management

Hardware Control

hardware

ecs150 Spring 2006


Kernel processes

Kernel & Processes

  • The concept of “application process”

ecs150 Spring 2006


Kernel and user space

Kernel and User Space

Memory

space for this

process

Process FOO

program

System call

(or trap into the kernel)

conceptually

Process FOO

in the Kernel

System Call

Kernel Resources

(disk or IO devices)

ecs150 Spring 2006


Processes

Processes

> ps

PID TTY TIME CMD

2910 pts/4 0:00 tcsh

> ps -ef

UID PID PPID C STIME TTY TIME CMD

root 0 0 0 Sep 25 ? 0:01 sched

root 1 0 0 Sep 25 ? 0:00 /etc/init -

root 2 0 0 Sep 25 ? 0:00 pageout

root 3 0 0 Sep 25 ? 0:01 fsflush

root 223 1 0 Sep 25 ? 0:00 /usr/lib/utmpd

root 179 1 0 Sep 25 ? 0:00 /usr/sbin/cron

root 273 1 0 Sep 25 ? 0:00 /usr/lib/saf/sac -t 300

root 56 1 0 Sep 25 ? 0:00 /usr/lib/devfsadm/devfseventd

root 58 1 0 Sep 25 ? 0:00 /usr/lib/devfsadm/devfsadmd

root 106 1 0 Sep 25 ? 0:00 /usr/sbin/rpcbind

root 197 1 0 Sep 25 ? 0:01 /usr/sbin/nscd

root 108 1 0 Sep 25 ? 0:00 /usr/sbin/keyserv

root 168 1 0 Sep 25 ? 0:00 /usr/sbin/syslogd

root 118 1 0 Sep 25 ? 0:00 /usr/lib/netsvc/yp/ypbind

root 159 1 0 Sep 25 ? 0:00 /usr/lib/autofs/automountd

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Memory structure

Memory Structure

heap

High

Arguments

String Growth

Return address

library

Prev. frame pointer

stack

Local variables

Stack Pointer

Stack Growth

Low

ecs150 Spring 2006


Memory structure1

Memory Structure

heap

High

foo

Arguments

String Growth

bar( )

{……}

foo( )

{ ……

call bar( );

……

}

Return address

bar

Prev. frame pointer

Local variables

Stack Pointer

Stack Growth

Low

ecs150 Spring 2006


Procedure call on the same user stack

Procedure Call on the sameUser Stack

Per-process

Kernel Stack

User-stack

Disk

Heap

Initialized data

Initialized data

text

text

a.out header

Memory

a.out magic number

ecs150 Spring 2006


System call on a different stack

System Call on a different stack

Per-process

Kernel Stack

User-stack

Disk

Heap

Initialized data

Initialized data

text

text

a.out header

Memory

a.out magic number

ecs150 Spring 2006


System calls

System Calls

  • Not a “normal” procedure call

  • It is a software trap “into” the kernel

    • Hardware interrupt

    • Hardware trap

    • Software trap

ecs150 Spring 2006


System entry

System Entry

  • Hardware interrupt

    • Asynchronous, might not relate to the context of the executing process

  • Hardware trap

    • Related to the current executing process, e.g., divided by zero

  • Software-initiated trap

    • Instructions, int

ecs150 Spring 2006


System entry vector

System Entry Vector

fork()

Trap

:

:

ecs150 Spring 2006


System entry vector1

System Entry Vector

fork()

Trap

Reserved for

loadable system calls

:

:

XYZ()

ecs150 Spring 2006


Kldload

kldload

fork()

Trap

XYZ()

:

:

ecs150 Spring 2006


Process

Process

  • Process – a program in execution

  • A process includes:

    • program counter

    • stack

    • data section

ecs150 Spring 2006


Context switching

Context Switching

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Running

Running

Running

Running

Blocked

Blocked

Blocked

Blocked

Ready

Ready

Ready

Ready

Scheduling &

Context Switching

ecs150 Spring 2006


States of a process

Running

Waiting

Ready

States of a Process

  • Running, Blocked, and Ready

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

1

RR

0

0

:

:

.

256 different priorities

64 scheduling classes

0~63bottom-half kernel (interrupt)

64~127 top-half kernel

128~159 real-time user

160~223 timeshare

224~255 idle

1

0

1

ecs150 Spring 2006


Kernel processes1

Kernel Processes

  • idle, swapper, vmdaemon, pagedaemon, pagezero, bufdaemon, syncer, ktrace, vnlru, random, g_event, g_up, g_down

/usr/src/sys/kern/kern_idle.c

/usr/src/sys/kern/init_main.c

/usr/src/sys/vm/vm_zeroidle.c

/usr/src/sys/kern_ktrace.c

/usr/src/sys/dev/random/randomsoft_dev.c

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

1

RR

0

0

:

:

.

256 different priorities

64 scheduling classes

0~63bottom-half kernel (interrupt)

64~127 top-half kernel

128~159 real-time user

160~223 timeshare

224~255 idle

1

0

1

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Running

Waiting

Ready

ecs150 Spring 2006


4 4bsd process structure usr src sys sys proc h

4.4BSD Process Structure(/usr/src/sys/sys/proc.h)

process group

session

process credential

user credential

VM space

region list

Process

Structure

file descriptors

file entries

resource limits

}

statistics

user structure

signal actions

machine-dependent

process information

process control block

process kernel stack

ecs150 Spring 2006


Freebsd user structure

FreeBSD User Structure

/*

* Per process structure containing data that isn’t needed in core when the

* process isn’t running (esp. when swapped out). This structure may or may not

* be at the same kernel address in all processes.

*/

struct user {

struct pcb u_pcb;

struct sigacts u_sigacts; /* p_sigacts points here (use it!) */

struct pstats u_stats; /* p_stats points here (use it!) */

/* Remaining fields only for core dump and/or ptrace—

not valid at other times! */

struct kinfo_proc u_kproc; /* proc + eproc */

struce md_coredump u_md; /* machine dependent glop */

}

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

5.x Kernel

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

1

RR

0

KSE:

Kernel Scheduling Entity

 kernel-level thread

0

:

:

.

256 different priorities

64 scheduling classes

0~63bottom-half kernel (interrupt)

64~127 top-half kernel

128~159 real-time user

160~223 timeshare

224~255 idle

1

0

1

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


What is a thread

What is a thread?

ecs150 Spring 2006


Process and thread abstraction and abstraction

Process and Thread(abstraction and abstraction)

  • An execution instance of a program.

  • Threads and resources

    • a thread is a control entity of the logical flow in the program.

    • A sequential program needs only one single thread because it only need to be controlled by one entity.

    • Can you distinguish a process and a thread?

  • User mode versus (trap into the) Kernel mode.

ecs150 Spring 2006


A program and threads

A Program and Threads

J=0;

(shared)

variables

If (j==0)

J=100

ecs150 Spring 2006


Threads

Threads

  • Heavy-weight Process versus Light-weight Thread

  • User-level versus Kernel-level

ecs150 Spring 2006


A process and a thread

a Process and a Thread

  • A tradition process contains one thread (i.e, one flow of control) and the resources (user or kernel).

Resources

No obvious concurrency within a process

ecs150 Spring 2006


Process and threads

Process and Threads

  • A Process can contain more than one threads sharing the resources (user or kernel).

Resources

ecs150 Spring 2006


Threads1

Threads

  • User-level

  • Kernel-level

ecs150 Spring 2006


Threads2

Threads

  • Blocking/Synchronous I/O

    • One thread blocks all others???

    • “Block one  block all”

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

CPU chip

register file

ALU

system bus

memory bus

main

memory

bus interface

I/O

bridge

I/O bus

Expansion slots for

other devices such

as network adapters.

USB

controller

graphics

adapter

disk

controller

mouse

keyboard

monitor

disk

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

CPU chip

register file

CPU initiates a disk read by writing a command, logical block number, and destination memory address to a port (address) associated with disk controller.

ALU

main

memory

bus interface

I/O bus

USB

controller

graphics

adapter

disk

controller

mouse

keyboard

monitor

disk

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

CPU chip

register file

Disk controller reads the sector and performs a direct memory access (DMA) transfer into main memory.

ALU

main

memory

bus interface

I/O bus

USB

controller

graphics

adapter

disk

controller

mouse

keyboard

monitor

disk

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

CPU chip

When the DMA transfer completes, the disk controller notifies the CPU with an interrupt (i.e., asserts a special “interrupt” pin on the CPU)

register file

ALU

main

memory

bus interface

I/O bus

USB

controller

graphics

adapter

disk

controller

mouse

keyboard

monitor

disk

ecs150 Spring 2006


Asynchronous i o

Asynchronous I/O

  • How to deal with multiple I/O operations concurrently?

    For example: wait for a keyboard input, a mouse click and input from a network connection.

  • Select system call

  • Poll system call (same idea, different implementation)

  • For more info see http://www.kegel.com/c10k.html

int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

int poll(struct pollfd *ufds, unsigned int nfds, int timeout);

struct pollfd { int fd; /* file descriptor */

short events; /* requested events */

short revents; /* returned events */

};

ecs150 Spring 2006


Usr src sys kern vfs aio c

/usr/src/sys/kern/vfs_aio.c

Solaris, Linux 2.6, FreeBSD pp230~231

  • POSIX P1003.4 Asynchronous I/O interface functions:

    • aio_cancel:cancel asynchronous read and/or write requests

    • aio_error:retrieve Asynchronous I/O error status

    • aio_fsync:asynchronously force I/O completion, and sets errno to ENOSYS

    • aio_read:begin asynchronous read

    • aio_return:retrieve return status of Asynchronous I/O operation

    • aio_suspend:suspend until Asynchronous I/O Completes

    • aio_write:begin asynchronous write

    • lio_listio:issue list of I/O requests

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Security Problem!!

ecs150 Spring 2006


User level threads

User-Level Threads

  • Now, you should get the basic idea about how to avoid “block one  block all”….

ecs150 Spring 2006


Threads3

Threads

  • User-level

    • Kernel is unaware of multiple threading within the same process. (Conceptually, the kernel pretends one “kernel” thread per process.)

  • Kernel-level

    • Kernel is fully aware of multiple kernel threads within the same process, and therefore, it will provide “related kernel services”.

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

User and Kernel Threads

  • One thread per process or multiple thread per process

UTS

UserLevelTs

KernelTs

KTS

KTS

Which approach is better???

ecs150 Spring 2006


User level threads1

User-Level Threads

  • A small OS in the user-space to manage the threads.

  • The kernel is totally unaware how many threads the process currently has.

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Why multiple threads

Why Multiple Threads??

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

  • Responsiveness

  • Resource Sharing

  • Economy

  • Utilization of MP Architectures

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Process A

Process B

Global

Variables

Global

Variables

Code

Code

Stack

Stack

fork()

fork()

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Parent

Child

Global

Variables

Global

Variables

Code

Code

Stack

Stack

fork()

execve()

Child

Global

Variables

Code

Stack

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Global

Variables

Code

Stack

pthread_create()

Process A

Thread 1

pthread_create()

Process A

Thread 2

Stack

ecs150 Spring 2006


Creation time difference

Creation Time Difference

  • Because threads are by definition lightweight, they can be created more quickly that “heavy” processes:

    • Sun Ultra5, 320 Meg Ram, 1 CPU

      • 94 forks()/second

      • 1,737 threads/second (18x faster)

    • Sun Sparc Ultra 1, 256 Meg Ram , 1 CPU

      • 67 forks()/second

      • 1,359 threads/second (20x faster)

    • Sun Enterprise 420R, 5 Gig Ram, 4 CPUs

      • 146 forks()/second

      • 35,640 threads/second (244x faster)

    • Linux 2.4 Kernel, .5 Gig Ram, 2 CPUs

      • 1,811 forks()/second

      • 227,611 threads/second (125x faster)

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


User threads

User Threads

  • Thread management done by user-level threads library

  • Examples

    - POSIX Pthreads

    - Mach C-threads

    - Solaris threads

ecs150 Spring 2006


Kernel threads

Kernel Threads

  • Supported by the Kernel

  • Examples

    - Windows 95/98/NT/2000

    - Solaris

    - Linux

ecs150 Spring 2006


Solaris 2 threads

Solaris 2 Threads

ecs150 Spring 2006


Linux threads

Linux Threads

  • Linux refers to them as tasks rather than threads.

  • Thread creation is done through clone() system call.

  • clone() allows a child task to share the address space of the parent task (process)

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Open new connection

Thread class: run

Lib call: pthread_create

System call: Clone

ecs150 Spring 2006


Kt vs ut

Threads

KT vs. UT

  • pros and cons?

  • BTW, how about FreeBSD?

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

ecs150 Spring 2006


Uts kts

Process

Process

Process

Scheduler

Scheduler

Scheduler

processor

processor

processor

UTS + KTS

  • Two independent schedulers:

User Space

OS Kernel

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

Process

Process

Process

Scheduler

processor

processor

processor

KTS

  • One single scheduler:

User Space

OS Kernel

ecs150 Spring 2006


Kt vs ut1

KT vs. UT

UTS

Kernel Interface

KTS

ecs150 Spring 2006


Solaris 2 threads1

Solaris 2 Threads

mapping but NOTcoordinating

ecs150 Spring 2006


Questions to ask

Questions to ask

  • Why do we need “coordination”?

    • kernel-support user-level threads

  • What do we need in this “K/U coordination”?

    • extended system call API

  • Is this only good for SMP?

    • How about single processor?

    • How about NPU? (e.g., IXP-2400)

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

UTS

Library

Notify I/O events

Notify new decision

Kernel

KTS

ecs150 Spring 2006


Ecs150 spring 2006 operating system 1 os architecture kernel process

syscall

I/O request

interrupt

Is this a problem?

User Space

Kernel Space

Hardware

I don’t know how many UT’s you have up there?

I can guess but I am not sure that is exactly what you want!

ecs150 Spring 2006


Scheduler activations

CPUtimewasted

syscall

User Space

I/O request

interrupt

Kernel Space

Hardware

CPU used

User Space

upcall

upcall

Kernel Space

Hardware

Scheduler Activations

I don’t know how many UT’s you have up there?

ecs150 Spring 2006


Scheduler activations1

Scheduler Activations

  • First proposed by [Anderson et al. 91]

  • Idea: cooperation between schedulers should take place in both directions

    • User scheduler uses system calls

    • Kernel scheduler should use upcalls!

  • Upcalls

    • Notify the user-level of kernel scheduling events

  • Activations

    • A new structure to support upcalls (~kernel thread)

    • As many running activations as processors

    • Kernel controls activation creation and destruction

  • ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    One Model (FreeBSD 5.x)

    UTS - threads

    Library

    SA

    SA

    Notify I/O events

    Notify new decision

    SA

    SA

    Kernel

    KTS – virtual CPU’s

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    I o happens for thread

    I/O happens for Thread

    User Program

    (2)

    (3)

    (1)

    User-Level

    Runtime System

    (4)

    (A)

    (B)

    Add

    Processor

    Add

    Processor

    Operating System Kernel

    Processors

    ecs150 Spring 2006


    A s thread has blocked on an i o request

    User Program

    A’s Thread has blocked on an I/O request

    (3)

    (2)

    (1)

    User-Level

    Runtime System

    (4)

    B

    (A)

    (B)

    ( C )

    Operating

    System Kernel

    A’s thread has blocked

    Processors

    ecs150 Spring 2006


    A s thread i o completed

    A’s Thread I/O completed

    User Program

    (2)

    (3)

    (4)

    (1)

    (1)

    User-Level

    Runtime System

    (A)

    (B)

    (D)

    A’s thread and B’s

    Thread can continue

    ( C )

    Operating

    System Kernel

    Processors

    “the upcall stack problem”

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    A’s Thread resumes on Scheduler Activation D

    User Program

    (2)

    (3)

    (4)

    (1)

    (1)

    User-Level

    Runtime System

    (D)

    A’s thread and B’s

    Thread can continue

    ( C )

    Operating

    System Kernel

    Processors

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    One Model (FreeBSD 5.x)

    UTS - threads

    Library

    SA

    SA

    Notify I/O events

    Notify new decision

    SA

    SA

    Kernel

    KTS – virtual CPU’s

    ecs150 Spring 2006


    Freebsd 5 x

    FreeBSD 5.x

    • Kernel Scheduling Entity (KSE)

      • a virtual CPU

      • When “anything” changes regarding the service of this KSE to the process, this KSE is “unassigned” as the kernel doesn’t know what other threads might be there!!

      • Upcall to the UTS (via KSE mailbox).

      • UTS uses both KSE mailbox and Thread mailbox to handle/decide.

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    #include <sys/types.h>

    #include <sys/kse.h>

    int kse_create(struct kse_mailbox *mbx,

    int newsgroup);

    int kse_exit(void);

    int kse_release(struct timespec *timeout);

    int kse_wakeup(struct kse_mailbox *mbx);

    int kse_thr_interrupt(struct

    kse_thr_mailbox

    *tmbx);

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    struct kse_mailbox {

    intkm_version;

    struct kse_thr_mailbox*km_curthread;

    struct kse_thr_mailbox*km_completed;

    sigset_tkm_sigscaught;

    unsigned intkm_flags;

    kse_func_t*km_func;/* UTS function */

    stack_tkm_stack;/* UTS context */

    void*km_udata; /* For use by the UTS */

    struct timespeckm_timeofday;/* Time of day */

    intkm_quantum;

    intkm_spare[8];

    };

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    struct kse_thr_mailbox {

    ucontext_ttm_context;/* User and machine context */

    unsigned inttm_flags;/* Thread flags */

    struct kse_thr_mailbox*tm_next;/* Next thread in list */

    void*tm_udata;/* For use by the UTS */

    unsigned inttm_uticks;

    unsigned inttm_sticks;

    inttm_spare[8];

    };

    ecs150 Spring 2006


    Upcalls

    upcalls

    • ksec_new

    • ksec_preempt

    • ksec_block

    • ksec_unblock

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    UTS

    Library

    ksec_new

    ksec_preempt

    ksec_block

    ksec_unblock

    kse_create

    kse_exit

    kse_release

    kse_wakeup

    kse_thr_interrupt

    Kernel

    KTS

    ecs150 Spring 2006


    Kse internal

    KSE Internal

    • KSE

    • KSEG

    • KSEC

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Linux vpi virtual processor interface

    Linux VPI(Virtual Processor Interface)

    • Experimental/Research Prototype

      • Benson/Butner/Padden/Fedosov

      • Scheduler activation in Linux Kernel 2.4.18

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    One Model (FreeBSD 5.x)

    UTS - threads

    Library

    SA

    SA

    Notify I/O events

    Notify new decision

    SA

    SA

    Kernel

    KTS – virtual CPU’s

    ecs150 Spring 2006


    Kernel processes table 3 1 page 50

    Kernel Processes(table 3.1 page 50)

    • idle, swapper, vmdaemon, pagedaemon, pagezero, bufdaemon, syncer, ktrace, vnlru, random, g_event, g_up, g_down

    • “Kernel processes execute code that is complied into the kernel’s load image and operate with the kernel’s privileged execution code.”

    ecs150 Spring 2006


    Freebsd kernel

    FreeBSD Kernel

    ecs150 Spring 2006


    Freebsd kernel1

    FreeBSD Kernel

    ecs150 Spring 2006


    Kernel and user space1

    Kernel and User Space

    Memory

    space for this

    process

    Process FOO

    program

    System call

    (or trap into the kernel)

    conceptually

    Process FOO

    in the Kernel

    System Call

    Kernel Resources

    (disk or IO devices)

    ecs150 Spring 2006


    What is micro kernel

    What is “micro-kernel”?

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ….what are the basic services?

    OS

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    An Alternative: Micro-Kernel

    Message Passing versus Optimized Procedure Calls

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    ecs150 Spring 2006


    Micro versus monolithic

    Micro versus Monolithic

    • What is the real difference between these two models??

    • First Brainstorming!!

    ecs150 Spring 2006


    Micro versus monolithic1

    Micro versus Monolithic

    • Is this really relevant?

    • Advantages of Micro Kernels

      • Modules (Architectural Cleanness), Adaptive, Small/Quick-to-Boot,…

    • We did learn some lessons

      • We have to consider the “users” & “applications”, and make a new engineering design decision.

    ecs150 Spring 2006


    Freebsd kernel size

    FreeBSD Kernel: Size

    • 689794 machine independent LOC

    • 108346 machine dependent LOC

    • 846525 device driver LOC

    • Comparing:

      • Windows 3.1 ~ 6M LOC

      • Windows 2000 ~ 30-50M LOC

      • Windows XP ~ 45M LOC

      • Netscape ~ 7M LOC

    ecs150 Spring 2006


    Os design

    OS Design

    • Architectural Design

      • how to organize the user and kernel resources?

    • Module Control Design

      • how to design a control mechanism to protect the OS resource integrity?

    • Interface Design

      • how to let user programs access the resources easier? (e.g., system call interface, multi-threaded interface).

    ecs150 Spring 2006


    Ecs150 spring 2006 operating system 1 os architecture kernel process

    • What is “Process”?

    • What is “System Call”?

    • What is “Kernel”?

    ecs150 Spring 2006


  • Login