Syscalls Indranil Sen Gupta (odd section) and Mainack Mondal (even - - PowerPoint PPT Presentation

syscalls
SMART_READER_LITE
LIVE PREVIEW

Syscalls Indranil Sen Gupta (odd section) and Mainack Mondal (even - - PowerPoint PPT Presentation

Syscalls Indranil Sen Gupta (odd section) and Mainack Mondal (even section) CS39002 Spring 2019-20 The story so far A brief historical overview of OS Batch processing systems Multiprogramming Multitasking Some practice


slide-1
SLIDE 1

Syscalls

Indranil Sen Gupta (odd section) and Mainack Mondal (even section)

CS39002 Spring 2019-20

slide-2
SLIDE 2

The story so far

  • A brief historical overview of OS
  • Batch processing systems
  • Multiprogramming
  • Multitasking
  • Some practice problems
  • Today’s OS (multitasking, like Unix)
  • Dual mode of operation
  • Uses of timer
slide-3
SLIDE 3

Today’s class

  • System calls
  • Some practice problems
  • Start of processes
slide-4
SLIDE 4

System calls

slide-5
SLIDE 5

What are system calls?

  • The mechanism used by an application program to

request service from the operating system

  • So how does it work?
slide-6
SLIDE 6

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

slide-7
SLIDE 7

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

  • The handler routine was just an interrupt handler
slide-8
SLIDE 8

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

  • The handler routine was just an interrupt handler
  • Like interrupts, system calls are arranged in a table
slide-9
SLIDE 9

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

  • The handler routine was just an interrupt handler
  • Like interrupts, system calls are arranged in a table
  • Whenever a syscall (interrupt driven) came
slide-10
SLIDE 10

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

  • The handler routine was just an interrupt handler
  • Like interrupts, system calls are arranged in a table
  • Whenever a syscall (interrupt driven) came
  • Kernel selected syscall placing index in eax register
slide-11
SLIDE 11

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

  • The handler routine was just an interrupt handler
  • Like interrupts, system calls are arranged in a table
  • Whenever a syscall (interrupt driven) came
  • Kernel selected syscall placing index in eax register
  • Arguments go in the other registers
slide-12
SLIDE 12

Earlier days: interrupt

  • Originally, system calls issued using “int” instruction
  • Kernel creates an array of Interrupt descriptors in

memory, called Interrupt Descriptor Table, or IDT

  • The handler routine was just an interrupt handler
  • Like interrupts, system calls are arranged in a table
  • Whenever a syscall (interrupt driven) came
  • Kernel selected syscall placing index in eax register
  • Arguments go in the other registers
  • Return value goes in eax
slide-13
SLIDE 13

However it is slow

  • Today, Processors are totally pipelined
  • Pipeline stalls are very expensive
  • Cache misses can cause pipeline stalls
  • Now recall that IDT is in memory
  • May not be in cache
  • Makes it expensive
slide-14
SLIDE 14

Idea: new instruction

  • What if we cache the IDT entry for a system call in a

special CPU register?

  • No more cache misses for the IDT!
  • What is the cost?
slide-15
SLIDE 15

Idea: new instruction

  • What if we cache the IDT entry for a system call in a

special CPU register?

  • No more cache misses for the IDT!
  • What is the cost?
  • system calls should be frequent enough to be worth

the transistor budget

slide-16
SLIDE 16

How to leverage the new instruction?

  • There is a machine instruction (new architectures)
  • Essentially for asking your processor to perform task
  • Hardware specific
  • Can be called “syscall”, “trap”, “svc”, “swi”
  • For x86-64 architecture its called “syscall”
slide-17
SLIDE 17

Example: How are system calls used in kernel

  • syscall machine instruction takes operands
  • syscall 10 // integer number for x86

// some of these are fixed by intel

slide-18
SLIDE 18

Example: How are system calls used in kernel

  • syscall machine instruction takes operands
  • syscall 10 // integer number for x86

// some of these are fixed by intel

  • When we are writing programs in HLL (higher level

language, think C)

  • We think of syscalls in a somewhat higher level

context

slide-19
SLIDE 19

Example: How are system calls used in kernel

  • syscall machine instruction takes operands
  • syscall 10 // integer number for x86

// some of these are fixed by intel

  • When we are writing programs in HLL (higher level

language, think C)

  • We think of syscalls in a somewhat higher level

context

slide-20
SLIDE 20

Characteristics of system calls

  • Provide an interface to the services made available by an
  • perating system
slide-21
SLIDE 21

Characteristics of system calls

  • Provide an interface to the services made available by an
  • perating system
  • Typically executes hundreds of thousands time every

second

slide-22
SLIDE 22

Characteristics of system calls

  • Provide an interface to the services made available by an
  • perating system
  • Typically executes hundreds of thousands time every

second

  • User application programs do not see this level of

detail

slide-23
SLIDE 23

Characteristics of system calls

  • Provide an interface to the services made available by an
  • perating system
  • Typically executes hundreds of thousands time every

second

  • User application programs do not see this level of

detail

  • Use Application programming interface (API)
slide-24
SLIDE 24

Characteristics of system calls

  • Provide an interface to the services made available by an
  • perating system
  • Typically executes hundreds of thousands time every

second

  • User application programs do not see this level of

detail

  • Use Application programming interface (API)
  • fork, pipe, execvp etc.
slide-25
SLIDE 25

Characteristics of system calls

  • Provide an interface to the services made available by an
  • perating system
  • Typically executes hundreds of thousands time every

second

  • User application programs do not see this level of

detail

  • Use Application programming interface (API)
  • fork, pipe, execvp etc.
  • These APIs are also loosely termed as system calls
slide-26
SLIDE 26

More about system calls

  • System call numbers in linux for x86 - 64 :

https://github.com/torvalds/linux/blob/16f73eb02d7e176 5ccab3d2018e0bd98eb93d973/arch/x86/entry/syscalls/ syscall_64.tbl

  • System call numbers in linux for x86 :

https://github.com/torvalds/linux/blob/16f73eb02d7e176 5ccab3d2018e0bd98eb93d973/arch/x86/entry/syscalls/ syscall_32.tbl

  • System call implementations in x86-64 and x86

https://stackoverflow.com/questions/15168822/intel- x86-vs-x64-system-call

slide-27
SLIDE 27

Example of a system call API

  • There are no fopen, fgets, printf, and fclose system calls

in the Linux kernel but open, read, write, and close

  • http://man7.org/linux/man-pages/man2/read.2.html
slide-28
SLIDE 28

Example of a system call API

  • http://man7.org/linux/man-pages/man2/read.2.html
  • What are these function parameters?
  • What is the return values?
slide-29
SLIDE 29

How is read invoked?

  • Check the board
  • Demo: checking what syscalls are invoked in a process
  • Demo: checking assembly code in C (using gcc)
slide-30
SLIDE 30

Summary: The workflow

Functions we write in HLL (printf, scanf) Lower level standard C library call (read, write) syscall instruction

slide-31
SLIDE 31

Types of system calls

(From silberschatz’s slides)

slide-32
SLIDE 32

Types of System Calls

  • Pr

Proc

  • cess control (e.g., fork(

k(), exit(), wait() )

  • create process, terminate process (fork, exit)
  • end, abort
  • load, execute
  • get process attributes, set process attributes
  • wait for time
  • wait event, signal event
  • allocate and free memory
  • Dump memory if error
  • De

Debug ugger for determining bu bugs, single ste tep p execution

  • Locks

ks for managing access to share data between processes

slide-33
SLIDE 33

Types of System Calls (Cont.)

  • Fi

File ma manageme ment (e.g., open(), close(), read(), write())

  • create file, delete file
  • open, close file
  • read, write, reposition
  • get and set file attributes
  • De

Devic ice ma manageme ment (e.g., io ioctl(), (), read(), d(), wr write()) ())

  • request device, release device
  • read, write, reposition
  • get device attributes, set device attributes
  • logically attach or detach devices
slide-34
SLIDE 34

Types of System Calls (Cont.)

  • In

Inter er-Pr Process Commu mmunications (e.g., pipe(), se semget(), (), se semop(), (), sh shmget(), (), sh shmcat(), (), sh shmdt(), (), sh shmctl(), signal(), ki kill())

  • create, delete communication connection
  • send, receive messages if me

message passing mo model to ho host na name or pr process name

  • Sh

Shared-me memo mory y mo model create and gain access to memory regions

  • transfer status information
  • attach and detach remote devices
slide-35
SLIDE 35

Types of System Calls (Cont.)

  • Pr

Prot

  • tection

ion (ch chmod(), (), ch chown(), (), um umask())

  • Control access to resources
  • Get and set permissions
  • Allow and deny user access
slide-36
SLIDE 36

Today’s class

  • System calls
  • Some practice problems
  • Start of processes
slide-37
SLIDE 37

Announcement

  • The first practice problems sheet is up:

http://www.facweb.iitkgp.ac.in/~isg/OS/ASSIGN/ Assignment-1.pdf

slide-38
SLIDE 38