cs2106 lec1 intro

97
Lecture 1 Introduction 10 August, 2010 1

Upload: weitsang

Post on 09-Apr-2015

62 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CS2106 Lec1 Intro

Lecture 1

Introduction10 August, 2010

1

Page 3: CS2106 Lec1 Intro

Office HourThu 4 - 6pmAS6 05-14

(was Fri 2-4pm)3

Page 4: CS2106 Lec1 Intro

Required Textbook

$47.90

4

Page 5: CS2106 Lec1 Intro

Additional Reference Only

$47.00

5

Page 6: CS2106 Lec1 Intro

Average Weekly Workload(your milage may vary)

Preparation6 hr

Lab1 hr

Tutorial1 hr

Lecture2 hr

Note that NUS officially lists the workload as 2-1-1-0-4 which is a typo (it does not add up to 10!)

6

Page 7: CS2106 Lec1 Intro

Assessment

Midterm20%

Lab25%

Participation5%

Exam50%

7

Page 8: CS2106 Lec1 Intro

October 2010Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 910 11 12 13 14 15 1617 18 19 20 21 22 2324 25 26 27 28 29 3031

Important Dates

November 2010Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 1314 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30

midterm final

8

Page 9: CS2106 Lec1 Intro

midterm and final are semi-open book(one 2-sided A4 sheet)

9

Page 10: CS2106 Lec1 Intro

Lecture Format

1200-1400

0 20 40 60 80 100 120

1030535535

Lecture Break Lecture Break Lecture Dismiss

10

Page 11: CS2106 Lec1 Intro

slides will be posted1-2 days before lecture

but

11

Page 12: CS2106 Lec1 Intro

students are expected to take

notes during lecture

12

Page 13: CS2106 Lec1 Intro

students are expected to read the assigned readings

13

Page 14: CS2106 Lec1 Intro

no “model” answer will be posted

14

Page 15: CS2106 Lec1 Intro

Philosophy: light fire

not fill bucket - William Yeats

Flickr photo by danielygo Some rights reserved

Light a Fire

15

Page 16: CS2106 Lec1 Intro

Philosophy: light fire

not fill bucket - William Yeats

Flickr photo by danielygo Some rights reservedFlickr photo by peasap Some rights reservedNot Fill a Bucket

16

Page 17: CS2106 Lec1 Intro

blog.nus.edu.sg/cs2106

17

Page 18: CS2106 Lec1 Intro

your responsibility: check for update frequently

(hint: subscribe via email or RSS)

18

Page 19: CS2106 Lec1 Intro

do participate in online discussion

(and use your real name!)

19

Page 20: CS2106 Lec1 Intro

screencast will be posted

20

Page 21: CS2106 Lec1 Intro

what is

CS2106about?

21

Page 22: CS2106 Lec1 Intro

NOT about how to use Mac OS X, MS Windows,

Linux etc.

22

Page 23: CS2106 Lec1 Intro

about basic concepts and design principles

in OS

23

Page 24: CS2106 Lec1 Intro

why should I learn

OS ?

24

Page 25: CS2106 Lec1 Intro

I am not gonna write another OS!25

Page 26: CS2106 Lec1 Intro

complex software

26

Page 27: CS2106 Lec1 Intro

abstraction + interface design

27

Page 28: CS2106 Lec1 Intro

concurrency

28

Page 29: CS2106 Lec1 Intro

resource management

29

Page 30: CS2106 Lec1 Intro

performance trade-off

30

Page 31: CS2106 Lec1 Intro

what to learn from OS course (beside OS):

1. complex systems2. abstraction + interface design3. concurrency4. resource management5. performance trade-off

31

Page 32: CS2106 Lec1 Intro

after CS2106

32

Page 33: CS2106 Lec1 Intro

CS3221 OS Design and Pragmatics

33

Page 34: CS2106 Lec1 Intro

CS3211 Parallel and Concurrent

Programming

34

Page 35: CS2106 Lec1 Intro

CS4223 Parallel Computer Architecture

35

Page 36: CS2106 Lec1 Intro

CS4275 Programming Real-Time

Systems

36

Page 37: CS2106 Lec1 Intro

CS4344 Networked and Mobile

Gaming

37

Page 38: CS2106 Lec1 Intro

CS5222 Processor Architecture

38

Page 39: CS2106 Lec1 Intro

CS5223Distributed Systems

39

Page 40: CS2106 Lec1 Intro

CS5231Systems Security

40

Page 41: CS2106 Lec1 Intro

CS5248Systems Support for Continuous Media

41

Page 42: CS2106 Lec1 Intro

CS6270Virtual Machines

42

Page 43: CS2106 Lec1 Intro

OSOperating Systems

43

Page 44: CS2106 Lec1 Intro

operating system

compilers editors shell...

browser calendar media player...

machine language

microarchitecture

physical devices

44

Page 45: CS2106 Lec1 Intro

The OS is a layer of software that manages processors, storage and I/O devices and provide simple interfaces to the hardware to user programs.

45

Page 46: CS2106 Lec1 Intro

OS is everywhere

46

Page 47: CS2106 Lec1 Intro

phone, car, robot, router, media player, game console, ..

47

Page 48: CS2106 Lec1 Intro

48

Page 49: CS2106 Lec1 Intro

49

Page 50: CS2106 Lec1 Intro

1. read a number from a file2. print the number to screen

consider the simple program:

how to code in a world without OS?

50

Page 51: CS2106 Lec1 Intro

is the file on a CD, thumbdrive, harddisk..?

location of file on storage?

is another program writing to the file at the same time?

etc..51

Page 52: CS2106 Lec1 Intro

what graphics chip is the system using?

what is the display resolution?

is another process writing to the same location?

etc..

52

Page 53: CS2106 Lec1 Intro

OS as an extended

machine

53

Page 54: CS2106 Lec1 Intro

operating system

compilers editors shell...

browser calendar media player...

file display keyboard mouse printer battery socket

54

Page 55: CS2106 Lec1 Intro

operating system (a.k.a kernel)

compilers editors shell..

browser calendar media player..

file display keyboard mouse printer battery socket

user mode

kernel mode

55

Page 56: CS2106 Lec1 Intro

interfaces provided by OS are known as system calls

56

Page 57: CS2106 Lec1 Intro

Language libraries typically provide a 1-to-1 mapping between library calls and system calls.

e.g.: the function exit( ) calls system call _exit( ).

57

Page 58: CS2106 Lec1 Intro

Recall how a library procedure call works..

58

Page 59: CS2106 Lec1 Intro

CPU

programcounter

Memory

data

code

stackpointer

programstatus word

stackframepointer

59

Page 60: CS2106 Lec1 Intro

CPU

Memory

data

code

stack

function parameterslocal variables

saved frame pointerreturn address

programcounter

stackpointer

programstatus word

framepointer

CPU

60

Page 61: CS2106 Lec1 Intro

a system call is similar, except:

1.a special instruction sets the kernel mode bit in PSW before executing the system call

61

Page 62: CS2106 Lec1 Intro

2.a special instruction sets the user mode bit in PSW after executing the system call

62

Page 63: CS2106 Lec1 Intro

3. CPU executes the OS system call handler.

63

Page 64: CS2106 Lec1 Intro

In user mode, certain privileged instructions cannot be executed, certain addresses cannot be accessed etc.

In kernel mode, there is no restriction.

64

Page 65: CS2106 Lec1 Intro

Bad things happen in older OSes without dual mode operation.

65

Page 66: CS2106 Lec1 Intro

Bad things still happen if buggy code runs in kernel mode.

66

Page 67: CS2106 Lec1 Intro

operating system (a.k.a kernel)

compilers editors shell..

browser calendar media player..

file display keyboard mouse printer battery socket

user mode

kernel mode

67

Page 68: CS2106 Lec1 Intro

OS as a resource manager

68

Page 69: CS2106 Lec1 Intro

operating system

disk space RAM processor cycles

network bandwidth

screen estate

batterypower ....

69

Page 70: CS2106 Lec1 Intro

what if the computer runs one task at a time, always completing it before running another task ?

70

Page 71: CS2106 Lec1 Intro

a task always have full use of all resources.

not efficient since not all resources are fully utilized at all time (e.g., CPU is idle when I/O is performed).

71

Page 72: CS2106 Lec1 Intro

Suppose the computer keeps multiple tasks in the memory. When the running task is idle, switch to another task (multi-programming)

72

Page 73: CS2106 Lec1 Intro

now, resources are shared among the tasks.

how does CPU switch from one task to another?

how to prevent one task from corrupting the memory of another task?

73

Page 74: CS2106 Lec1 Intro

what if there are multiple users using the system, and there is one CPU intensive task?

74

Page 75: CS2106 Lec1 Intro

The computer keeps multiple tasks in the memory and switch between them frequently (regardless of whether the task is idle) (time-sharing)

75

Page 76: CS2106 Lec1 Intro

time-multiplexing: CPU, printer

space-multiplexing: memory, disk, screen

76

Page 77: CS2106 Lec1 Intro

OS is an extended machine

anda resource manager

77

Page 78: CS2106 Lec1 Intro

UNIX and C

78

Page 79: CS2106 Lec1 Intro

why UNIX?(Linux, Mac OS X, Sun OS etc.)

79

Page 80: CS2106 Lec1 Intro

many OS concepts are cleanly manifested in UNIX

80

Page 81: CS2106 Lec1 Intro

source code are available

81

Page 82: CS2106 Lec1 Intro

why C?

82

Page 83: CS2106 Lec1 Intro

UNIX is written (mostly) in C

83

Page 84: CS2106 Lec1 Intro

intermediate-level language (e.g., explicit memory allocation,

bits manipulation)

84

Page 85: CS2106 Lec1 Intro

A brief introduction to C and programming in

UNIX

85

Page 86: CS2106 Lec1 Intro

C vs Java

(highlights)

86

Page 87: CS2106 Lec1 Intro

Java: set of classes

C: set of functions + structures

87

Page 88: CS2106 Lec1 Intro

C: no byte datatypeno boolean datatypeno String class

(use char, int, and array of char respectively)

88

Page 89: CS2106 Lec1 Intro

Java: all variables are reference except boolean and numeric types

C: all variables are primitive types (holds the value of that exact type)

89

Page 90: CS2106 Lec1 Intro

C: no “new” operator

must explicit declare as pointer for reference variables

must explicitly malloc() and free() memory

90

Page 91: CS2106 Lec1 Intro

Java: all variables are reference except boolean and numeric types

C: all variables are primitive types (holds the value of that exact type)

91

Page 92: CS2106 Lec1 Intro

Java: external classes must be imported

C: external functions and types must be declared

(made easy with #include  statement)

92

Page 93: CS2106 Lec1 Intro

int  main(){    return  0;}

93

Page 94: CS2106 Lec1 Intro

#include  <stdio.h>

int  main(){    printf(“Hello  World!\n”);    return  0;  }

94

Page 95: CS2106 Lec1 Intro

gcc hello.c

gcc -o hello hello.c

gcc -g -o hello hello.c

gcc -Wall -g -o hello hello.c

to compile:

95

Page 96: CS2106 Lec1 Intro

#include  <stdio.h>#include  <stdlib.h>

void  say_hello(int  times){    int  i;    for  (i  =  0;  i  <  times;  i++)        printf(“Hello  World\n”);}

int  main(int  argc,  char  *argv[]){    say_hello(atoi(argv[1]));    return  0;  }

96

Page 97: CS2106 Lec1 Intro

*97