lecture 1 introduction - nus computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · average weekly...

104
Lecture 1 Introduction 12 August, 2011 1

Upload: truongxuyen

Post on 24-May-2018

219 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Lecture 1

Introduction

12 August, 2011

1

Page 3: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Office HourFri 4 - 6pmAS6 05-14

3

Page 4: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Required Textbook

$47.90

$52.20

4

Page 5: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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!)

pre-class activitiesreading lab exercisestutorial questionspreparing notesetc.

5

Page 6: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Assessment

Midterm20%

Lab30%

Exam50%

6

Page 7: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

October 2011Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31

Important Dates November 2011Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 25 2627 28 29 30

midterm final

7

Page 8: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

8

Page 9: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Lecture Format

1200-1400

0 20 40 60 80 100 120

2545545

Lecture Break Lecture Dismiss

9

Page 10: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

slides will be posted1-2 days before lecture

but

10

Page 11: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

no lecture notes will be provided

11

Page 12: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

students are expected to take

notes during lecture

12

Page 13: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

students are expected to read the assigned readings

13

Page 14: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

no “model” answer will be posted

14

Page 15: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

blog.nus.edu.sg/cs2106

15

Page 16: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

your responsibility: check for update frequently

(hint: subscribe via email or RSS)

16

Page 17: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

do participate in online discussion

(and use your real name!)

17

Page 18: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

screencast will be posted

18

Page 19: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

but expect 3-4 days delay and technical glitches do

occur

(not a good reason to skip lecture)

19

Page 20: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

pre-class activities

20

Page 21: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

simple activities for you to do / think about before attending lecture.

might help improve your understanding in class

online discussion only

21

Page 22: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

tutorials

22

Page 23: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

a set of questions asked each week

23

Page 24: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

you are expected to think through the answers

before the attending thetutorial sessions

24

Page 25: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

we will discuss your answers during tutorial sessions

we will conclude each discussion with the correct / best answer

25

Page 26: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

labs

26

Page 27: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

one lab exercise (almost) every week

27

Page 28: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

can do it at your own time

some are ungraded

28

Page 29: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

lab sessions:

1. lab TAs available for assistance

2. discuss lab answers from past labs

29

Page 30: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

some lab and tutorial questions are meant to let you discover

new knowledge yourself

(only if you think through the answers)

30

Page 31: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

warning: I am brutal in penalizing students who do not following instructions exactlyfor lab submissions

31

Page 32: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

feedbackwhat your seniors from 2010

think of CS2106

32

Page 33: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

31% find CS2106“Very Difficult”

Average is 14% for other 2000-level modules

33

Page 34: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

lots of stuff to learn

“The scope of the module is quite large.”

“Too much content in too little time.”

34

Page 35: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

the labs are difficult

“.. lab sessions can sometimes be really difficult hence time consuming.”

“The weekly labs can be quite stressful.”

35

Page 36: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

but useful for learning“weekly labs ensure that students really understand the concepts introduced in the lecture.”

“Labs are tough, but it is through the labs which I feel I learnt the most from”

“However the labs are also the real place that we actually learn”

36

Page 37: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

independent learning“The teaching material and most importantly style, is very conducive to independent learning”

“Also get chance to acquire independent learning through reading man page and google search”

“strengths: encourage a LOT of self-study”

37

Page 38: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

what is

CS2106about?

38

Page 39: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

Linux etc.

39

Page 40: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

about basic concepts and design principles

in OS

40

Page 41: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

many different variations: for different OS

and different architecture

41

Page 42: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

but same concepts and principles

42

Page 43: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

why should I learn

OS ?

43

Page 44: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

I am not going to write another OS!

44

Page 45: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

CS2106 is important because

45

Page 46: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

complex software

46

Page 47: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

abstraction + interface design

47

Page 48: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

concurrency

48

Page 49: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

resource management

49

Page 50: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

understand performance issues

50

Page 51: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

#define  SIZE  10000int  a[SIZE][SIZE];

for  (i  =  0;  i  <  size;  i++)    for  (j  =  0;  j  <  size;  j++)        a[i][j]  =  0;

51

Page 52: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

#define  SIZE  10000int  a[SIZE][SIZE];

for  (i  =  0;  i  <  size;  i++)    for  (j  =  0;  j  <  size;  j++)        a[j][i]  =  0;

52

Page 53: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

My computer is slow. Should I upgrade to

A. a faster CPUB. more CPU coreB. a faster harddiskC. a bigger harddiskD. more memoryE. faster memory

53

Page 54: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

what to learn from OS course (beside OS):

1. complex systems2. abstraction + interface design3. concurrency4. resource management5. performance issues

54

Page 55: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Assumed Background

55

Page 56: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

UNIX and C

56

Page 57: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

57

Page 58: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

need a concrete example for the concepts and principles

taught in CS2106

58

Page 59: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

many OS concepts are cleanly manifested in UNIX

59

Page 60: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

source code are available

60

Page 61: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

why C?

61

Page 62: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

UNIX is written (mostly) in C

62

Page 63: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

bits manipulation)

63

Page 64: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

CS2100Computer

Organization

64

Page 65: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

how a program is executed

a brief review

65

Page 66: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

to build and run a program:

linkpre-process load

foo.c

compile

foo.o a.out

memory

66

Page 67: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

CPU

programcounter

Memory

data

code

stack

67

Page 68: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

Loop:

1. fetch instruction located at PC2. decode instruction3. fetch data4. execute instruction and update PC

68

Page 69: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

int  main(){    int  x  =  1;    foo(x);    x  =  x  +  1;}

int  foo(int  x){        :        :}

69

Page 70: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

int  main(){    int  x  =  1;    foo(x);    x  =  x  +  1;}

int  foo(int  x){      int  y  =  x+1;      bar(y);}

int  bar(int  x){        :        :}

70

Page 71: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

CPU

programcounter

Memory

data

code

stack

71

Page 72: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

CPU

programcounter

Memory

stackpointer

framepointer

data

code

stack

72

Page 73: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

stack

data

code

CPU

Memory

function parameterslocal variables

saved frame pointerreturn address

CPU

programcounter

stackpointer

framepointer

73

Page 74: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

OSOperating Systems

74

Page 75: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

operating system

compilers editors shell...

browser calendar media player...

machine language

microarchitecture

physical devices

75

Page 76: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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.

76

Page 77: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

OS is everywhere

77

Page 78: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

78

Page 79: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

consider the simple program:

how to code in a world without OS?

79

Page 80: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

is the number stored on a CD, thumbdrive, harddisk..?

location of the number on the storage?

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

80

Page 81: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

what graphics chip is the system using?

what is the display resolution?

is another process displaying something at the same location?

81

Page 82: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

OS hides all these details from programmers

82

Page 83: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

x = read_number(“ file.txt ”);print(x);

83

Page 84: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

OS as an extended

machine

84

Page 85: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

operating system

compilers editors shell...

browser calendar media player...

file display keyboard mouse printer battery socket

85

Page 86: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

operating system (a.k.a kernel)

compilers editors shell..

browser calendar media player..

file display keyboard mouse printer battery socket

user mode

kernel mode

86

Page 87: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

interfaces provided by OS are known as system calls

87

Page 88: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

a bit in the program status word (PSW) keeps track of the current mode (user or kernel mode)

88

Page 89: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

a system call is similar to a procedure call except:

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

89

Page 90: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

90

Page 91: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

3. CPU executes the OS “system call handler” for a given system call

(more details later..)

91

Page 92: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

stack

data

code

CPU

Memory

function parameterslocal variables

saved frame pointerreturn address

CPU

programcounter

stackpointer

framepointer

kernel

programstatus word

92

Page 93: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

In kernel mode, there is no restriction.

93

Page 94: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

operating system (a.k.a kernel)

compilers editors shell..

browser calendar media player..

file display keyboard mouse printer battery socket

user mode

kernel mode

94

Page 95: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

OS as a resource manager

95

Page 96: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

operating system

disk space RAM processor cycles

network bandwidth

screen estate

batterypower ....

96

Page 97: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

suppose that

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

97

Page 98: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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).

98

Page 99: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

suppose that

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

99

Page 100: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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?

100

Page 101: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

101

Page 102: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

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

102

Page 103: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

time-multiplexing: CPU, printer

space-multiplexing: memory, disk, screen

103

Page 104: Lecture 1 Introduction - NUS Computingooiwt/cs2106/1112s1/cs2106-lec01-intro.pdf · Average Weekly Workload (your milage may vary) Preparation 6 hr Lab 1 hr Tutorial 1 hr Lecture

OS is an extended machine

anda resource manager

104