OS Labs - PowerPoint PPT Presentation

About This Presentation
Title:

OS Labs

Description:

Clean simple abstractions, easily understandable in isolation ... Security. Multicore. Finding errors in OSes. Some Wednesdays; see schedule. Have fun! ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 19
Provided by: FransKa9
Learn more at: http://web.mit.edu
Category:
Tags: labs | oses

less

Transcript and Presenter's Notes

Title: OS Labs


1
OS Labs
  • 2/25/08
  • Frans Kaashoek
  • MIT
  • kaashoek_at_mit.edu

2
New labs for Tsinghua OS course
  • Operating systems can be misleadingly simple
  • Clean simple abstractions, easily understandable
    in isolation
  • Complexity is in how their implementations
    interact
  • Learn by doing, focus on interactions
  • How do hardware interrupts interact with kernel
    and user-level processes?
  • How to use virtual memory to solve many problems?
  • Labs build a complete OS from the ground up

3
Why might you care?
  • Perhaps you will build an OS
  • Perhaps you will design hardware
  • Or write a device driver, network stack, or a
    file system
  • Or need to diagnose application bugs or
    performance
  • Or you just want to know how computers work
  • Or you just want to have fun programming

4
Lab OS JOS
  • Labs based on MITs OS class (6.828)

sh
ls
fork
LibOS w. Unix API
LibOS w. Unix API
exofork
Small kernel with low-level API
  • JOS has an exokernel/hypervisor structure
  • Different than Linuxs organization
  • Forces you to see something else and think

5
The labs bottom up
  • Booting
  • Memory management
  • User-level environments
  • Preemptive multitasking
  • File system and spawn
  • A shell

required
optional
6
Development environment
  • Tools gcc, make, etc.
  • Target hardware platform x86 PC
  • For debugging bochs and qemu
  • Lab assigments come with tests
  • Details at course web pages

7
sh shell
  • Interactive command interpreter
  • Interface (the shell) to the operating system
  • Examples of shell commands
  • ls create process
  • ls gt tmp1 write output to file
  • sh lt script gt tmp1 run sh script
  • sort tmp uniq wc process communicate
    with pipe
  • compute-pi run program in background
  • .

OS ideas isolation, concurrency, communication,
synchronization
8
shell implementation
  • while (1)
  • printf()
  • readcommand(command, args)
  • pid fork() // new process
    concurrency
  • if (pid 0) // child?
  • exec (command, args, 0) // run command
  • else if (pid gt 0) // parent?
  • r wait (0) // wait until child is done
  • else
  • perror(Failed to fork\n)

9
Input/Output (I/O)
  • I/O through file descriptors
  • File descriptor may be for a file, terminal,
  • Example calls
  • read(fd, buf, sizeof(buf))
  • write(fd, buf, sizeof(buf))
  • Convention
  • 0 input
  • 1 output
  • 2 error
  • Child inherits open file descriptors from parents

10
I/O redirection
  • Example ls gt tmp1
  • Modify sh to insert before exec
  • close(1) // release fd 1
  • fd create(tmp1, 0666) // fd will be 1
  • No modifications to ls!
  • ls could be writing to file, terminal, etc.,
    but programmer of ls doesnt need to know

11
Pipe one-way communication
  • int fdarray2
  • char buf512
  • int n
  • pipe(fdarray) // returns 2 fds
  • write(fdarray1, hello, 5)
  • read(fdarray0, buf, sizeof(buf))
  • buf contains h, e, l, l, o

12
Pipe between parent child
  • int fdarray2
  • char buf512
  • int n, pid
  • pipe(fdarray)
  • pid fork()
  • if(pid gt 0)
  • write(fdarray1, "hello", 5)
  • else
  • n read(fdarray0, buf, sizeof(buf))
  • Synchronization between parent and child
  • read blocks until there is data
  • How does the shell implement a b?

13
Implementing shell pipelines
  • int fdarray2
  • if (pipe(fdarray) lt 0) panic ("error")
  • if ((pid fork ()) 0) // child (left end
    of pipe)
  • close (1)
  • tmp dup (fdarray1) // fdarray1 is the
    write end, tmp will be 1
  • close (fdarray0) // close read end
  • close (fdarray1) // close fdarray1
  • exec (command1, args1, 0)
  • else if (pid gt 0) // parent (right end
    of pipe)
  • close (0)
  • tmp dup (fdarray0) // fdarray0 is the
    read end, tmp will be 0
  • close (fdarray0)
  • close (fdarray1) // close write end
  • exec (command2, args2, 0)
  • else
  • printf ("Unable to fork\n")

14
OS abstractions and ideas
  • Processes (fork exec wait)
  • Files (open, create, read, write, close)
  • File descriptor (dup, ..)
  • Communication (pipe)
  • Also a number of OS ideas
  • Isolation between processes
  • Concurrency
  • Coordination/Synchronization
  • Your job implement abstractions and understand
    ideas

15
What will you know at the end?
  • Understand OS abstractions in detail
  • Intel x86
  • The PC platform
  • The C programming language
  • Unix abstractions
  • Experience with building system software
  • Handle complexity, concurrency, etc.

16
Lab lectures
  • Monday 3/3
  • Intel x86 introduction, assembly, stack
  • Helps with lab 1
  • Monday 3/17
  • Intel x86 memory management interrupts
  • Helps with lab 2 3

17
Bonus lectures special topics
  • OS architecture
  • Virtual machines
  • File systems
  • Security
  • Multicore
  • Finding errors in OSes
  • Some Wednesdays see schedule

18
Have fun!
Write a Comment
User Comments (0)
About PowerShow.com