Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
TDDB68/TDDE47 Concurrent Programming and Operating
Systems
Lecture 1: Introduction, interrupts and system calls
Mikael Asplund
Copyright Notice: The lecture notes are partly based on Silberschatz’s, Galvin’s and Gagne’s book (“Operating System Concepts”, 7th ed., Wiley, 2005). No part of
the lecture notes may be reproduced in any form, due to the copyrights reserved by Wiley. These lecture notes should only be used for internal teaching purposes at the Linköping University.
Hardware
Hardware
Prog1
Hardware
Prog1 Prog2 Prog3 Prog4
Hardware
Operating System
Prog1 Prog2 Prog3 Prog4
1. Do this2. Do that3. Wait for X4. Send Y5. Do something6. Wait a while7. Do something else
1. Send Z2. Wait for X3. Do nothing4. Send something else5. Do this
1. Wait for query2. Connect to database3. Send db-query4. Wait for results5. Create web page6. Reply to request
Concurrency
In this course:
Focus on basic principles
Courses
● TDDB68: 6hp course for D + U + I + M.Sc. + Erasmus– C/C++ with pointers a prerequisite
● TDDE47: 8hp course for IT– More time and some PBL sessions for learning about
memory allocation and pointers
● TDDE47 and TDDB68 have the same exam and labs.
Course web
● TDDB68:– https://www.ida.liu.se/~TDDB68/
● TDDE47– https://www.ida.liu.se/~TDDE47/
● Same content – report if anything is strange
People
● Examiner: Mikael Asplund● Course assistant: Felipe Boeira● Lab assistants:
– TDDB68 Group A: Felipe Boeira– TDDB68 Group B: Rodrigo Saar Moraes– TDDB68 Group C: Jesper Jonsson– TDDB68 Group D: Anna Montelius– TDDB68 Group E: Nils Broman– TDDB68 Group F: Olivia Shamon– TDDE47 group: Erik Norrestam Held
Examination
● Labs 3hp for TDDB68, 5hp for TDDE47
● Written exam 3hp
● Bonus assignment 0hp– 3p bonus points on the exam– Pass all labs no later than 2021-03-11– Need to be first-time registered in VT1 2021
Labs
● Pintos– Stanford educational OS
● Challenging!
● Register in webreg today– Only new students!
Deadlines
● 2021-01-22 Sign up in webreg (new students)
● 2021-03-11 Lab deadline to get the bonus points on the exam
● 2021-03-29 Last chance to pass the labs in VT1
Lab feedback
● Promise: – No later than 2w from the soft deadline – Lab6 at least one chance to correct if you hand in on the 11th
● Soft deadlines:– Lab0: January 29– Lab1: February 5– Lab2: February 15– Lab3: February 21– Lab4: February 27– Lab5: March 4– Lab6: March 10
Time management
● Lectures 8*2h + 1*4h
● Lessons 3*2h (to prepare for labs)
● Labs 36h (42 for TDDE47)
● Self-study TDDB68: ~100h, TDDE47: ~145h
Time management
● Lectures 8*2h + 1*4h
● Lessons 3*2h (to prepare for labs)
● Labs 36h (42 for TDDE47)
● Self-study TDDB68: ~100h, TDDE47: ~145h
If you’re not spending 10+ hours/week of free timedoing labs
and studying for this course,you will be in trouble.
Do not cheat!
● Labs are hard and you might find solutions online
● It is not allowed to copy anyone else’s solution
● We are obliged to report suspected plagiarism to the disciplinary board
Course book
Exam
● Previous exams available (for 2020 only part C)
● Solutions not available
● Most likely: remote exam– Part A: multiple choice– Part B: basic questions– Part C: more advanced questions
For grade 3
→ For grade 4&5
Lectures vs. Labs
● Intentionally different scope
● Lectures provide an overview of a vast area
● Labs provide hands-on experience with a particular educational OS.
Results from Evaliuate
TDDB68 TDDE47
Two comments:
”Put more emphasis on telling the students to read the book. I didn't understand much during the lectures because I didn't read the book until the exam period. Had I read the pages before each lecture, the lectures would have been more productive.”
”... And the book was actually really good - I wish I had started reading it before the exam period.”
Planned changes
● Distance mode – Not by choice, but still quite time consuming
● Will add some exercises– Has been requested– Hopefully helps to study for exam
What does an operating system do?
Instruction Fetch
Instruction Decode
Instruction Execute
Update Program Counter
Program execution (von Neumann cycle) by a processor
1. Do this2. Do that3. Wait for X4. Send Y5. Do something6. Wait a while7. Do something else
1. Send Z2. Wait for X3. Do nothing4. Send something else5. Do this
1. Wait for query2. Connect to database3. Send db-query4. Wait for results5. Create web page6. Reply to request
How to do concurrency?
Interrupts
Instruction Fetch
Instruction Decode
Instruction Execute
Update Program Counter
Check for Interrupt
No
Yes
Execute interrupt service routine (ISR)
Restore processor state
Save processor state
Software Interrupts● A trap is a software-generated interrupt
caused either by an error or a user request.
– Examples: Division by zero; Request for OS service
An operating system is interrupt driven.
Why not just have a function API?
Dual Mode
Dual modeUser process Kernel CPU mode
User mode Kernel mode
Normal execution
System call(setting up)
System call(execution)
Trap!
Return
Normal execution
Types of System Calls● Process control
load, execute, end, abort, create, terminate, wait ...memory allocation and deallocation
● File managementopen, close, create, delete, read, write, get/set attributes...
● Device managementrequest / release device, read, write, ...
● Information maintenanceget / set time, date, system data, process / file attributes
● Communicationscreate / delete connection, send, receive, ...
Syscalls In Linux
(man syscalls)
Tracing system calls
Linux – ltraceMac OSX - dtrace
System Call API – OS Relationship
User mode
Kernel mode
System call interface
User processopen ( )
open ( )implementation of open ( ) system call…return
i
Hardware specific
Standard across different platforms
Example of a System Call API● ReadFile() function in Win32 API (function for reading from a file)
● Parameters passed to ReadFile():– file — the file to be read– buffer — a buffer where the data will be read into and written from– bytesToRead — the number of bytes to be read into the buffer– bytesRead — the number of bytes read during the last read– ovl — indicates if overlapped I/O is being used
System Call Parameter Passing● Three general methods used to pass parameters to
syscalls:– Parameters in registers– Parameters in a block in memory, and address to
block in a register ● This approach taken by Linux
– Parameters pushed onto the stack
● What are the advantages/disadvantages?
System Call Parameter Passing via Block
parameters for call
X:
System Programs● User's view of an Operating System
● Provide a convenient environment
– File management
– Program development
– Graphical user interface
– ...
Summary● Operating System = OS Kernel + System Programs
– Mediates all accesses to system resources– Interrupt-driven
● Error handling● Controlled access to system resources, e.g.
– I/O devices, DMA
– CPU time sharing
● …
● Dual-Mode (user mode, kernel mode)– System Call API for portability
Reading guidelines
● 9th edition– Chapter 1: Sections 1.1-1.7– Chapter 2: 2.3-2.5
● 10th edition– Chapter1: 1.1-1.5– Chapter2: 2.3-2.4
What's next?
● Today– Sign up in Webreg!– Get the book
● Tomorrow– 13-17 Introductory C lecture– Try some C programming
● Thursday– 8-10 lesson to introduce the labs
● Friday– First lab (lab0)