main

Assignment 1 - Computer Science 314: Operating Systems

This assignment should be submitted after you have finished Unit 1. It is worth 10% of your final grade.

Part 1: Concepts and Principles (60 marks; 5 marks each)

Instructions: Please answer the following questions in complete sentences. Your answer for each question should be about 150 words.

  1. Define the concepts interrupt and trap, and explain the purpose of an interrupt vector.

    An interrupt vector is a list or table of interrupts. Each interrupt has an address to the interrupt routine to execute when the interrupt is signaled. A trap is a way to capture a triggered signal to allow programs to respond to and handle the signal.

    Signals can be sent to a particular process via the kill program. A list of signals that can be sent are listed below:

    $ kill -L
    1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
    6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
    11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
    16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
    21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
    26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
    31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
    38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
    43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
    48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
    53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
    58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
    63) SIGRTMAX-1  64) SIGRTMAX
    

    Programs can also trap a signal and handle them. In the following example the Ruby program is trapping the SIGUSR1 signal to exit the program. file.

    #!/usr/bin/env ruby
    
    pid = fork do
      Signal.trap("USR1") do
        puts "done"
        exit 0
      end
    
      loop do
        print "."
        sleep 1
      end
    end
    
    Process.detach(pid)
    sleep 5
    Process.kill("USR1", pid)
    

    When this program is run it will print a ‘.’ 5 times and then exit.

    $ ruby lib/sigtrap.rb
    .....done
    
  2. How does a computer system with von Neumann architecture execute an instruction?

    The first step is to fetch the next instruction to execute and put it into memory. The instruction is given to the CPU and the program counter is incremented. The second step is for the CPU to decode the instruction and prepare to execute. The third step is to execute the instruction. This may require the CPU to utilize the ALU and control unit. The fourth step is to store the result in a register or memory.

    1. Fetch
    2. Decode
    3. Execute
    4. Store
  3. What role do device controllers and device drivers play in a computer system?

    Each device controller is in charge of a specific type of device. The device controller is responsible for moving the data between the peripheral devices that it controls and its local buffer storage. Operating systems have a device driver for each device controller. This device driver understands the device controller and presents a uniform interface to the device to the rest of the operating system.

    To start an I/O operation, the device driver loads the appropriate registers within the device controller. The device controller, in turn, examines the contents of these registers to determine what action to take. The controller starts the transfer of data from the device to its local buffer. Once the transfer of data is complete, the device controller informs the device driver via an interrupt that it has finished its operation. The device driver then returns control to the operating system, possibly returning the data or a pointer to the data if the operation was a read. For other operations, the device driver returns status information.

  4. Why do clustered systems provide what is considered high-availability service?

    Clustered systems gather together multiple CPUs to accomplish computational work. Clustered systems differ from multiprocessor systems in that they are composed of two or more individual systems joined together.

    Clusted computers share storage and are closely linked via a local area network.

    A high availability service will continue even if one or more systems in the cluster fail. HA is generally obtained by adding a level of redundancy in the system. A layer of cluster software runs on the cluster nodes. Each node can monitor one or more of the others. If the monitored machine fails, the monitoring machine can take ownership of its storage and restart applications that were running on the failed machine. The users and clients of the applications see only a brief interruption of service.

  5. Describe an operating system’s two modes of operation.

    • kernel mode: executes tasks on behalf of the operating system.
    • user mode: executes tasks on behalf of the user.

    Whenever the operating system gains control of the computer, it is in kernel mode. The dual modes of operation provides a way for protecting the operating system from malicious behaviour. Instructions that can cause harm are treated as privileged instructions. Privileged instructions can only be executed in kernel mode.

  6. Define cache, and explain cache coherency.

    The cache acts as a faster storage system that can store items on a temporary basis. When a piece of data is needed, the cache can be used to fetch the data once and stored in the cache. Subsequent attempts to access the same data can be fetched from the cache at a faster rate of access. Cache is meant to be temporary for fetching frequently used data quickly. However, the cache can become stale and out of sync with the backing storage from where the cache initially retrieved the data. Cache expiration is one of the hard problems in computer science.

    In a multitasking environment if several processes wish to access a piece of data then each process must access the current value of that piece of data. If that piece of data is stored in different caches it is possible for the same piece of data to have a different value if there isn’t a mechanism to synchronize each of the caches with any mutations made to the piece of data. Cache coherency ensures that the data stored in different layers of cache are synchronized and this is typically handled in the hardware layer.

  7. Describe why direct memory access (DMA) is considered an efficient mechanism for performing I/O.

    Reading data from different types of hardware can yield inconsistent I/O performance. It can also degrage harder at a faster rate due to increased usage. DMA allows for copying data from hardware into an in memory buffer that can be accessed directly. This allows read sequential pieces of data from the hardware less often and speeds up access to the data. One interrupt is generated per block rather than the one interrupt per byte of data read.

  8. Describe why multicore processing is more efficient than placing each processor on its own chip.

    On-chip communication is faster than between-chip communication. One chip with multiple cores uses less power than multiple single-core chips.

  9. Describe the relationship between an API, the system-call interface, and the operating system.

    • API: Application Programming Interface
    • System-call interface: The API provided by the operating system for executing privileged instructions.
    • Operating System: The system managing the interface between the hardware and software.

    The system-call interface is an API provided by the operating systems so that user programs can request access to perform functions like reading/writing to I/O devices etc.

  10. Describe some requirements and goals to consider when designing an operating system.

    When designing an operating system it is important to consider the needs of the runtime environment. Some questions to consider are:

    1. Will there be a need to run multiple programs simultaneously?
    2. Will there be a need to isolate programs from one another?
    3. Will there be a need to build user mode programs to access privileged instructions?
    4. Will there be a need for high availability and guaranteed uptime?
    5. What types of hardware will the operating system need to work with?

    These questions will help guide the design of a system call interface, compilers, linkers and other build tools. It will help identify the types of abstractions that the operating system may need to provide and whether or not it will need to process multiple tasks simultaneously or not. Finally, this will identify constraints for process and memory management.

  11. Explain why a modular kernel may be the best of the current operating system design techniques.

    The kernel has a set of core components and links in additional services either during boot time or during run time. Such a strategy uses dynamically loadable modules and is common in modern implementations of UNIX, such as Solaris, Linux and macOS.

    Solaris is organized around a core kernel with seven types of loadable kernel modules:

    1. Scheduling classes
    2. File systems
    3. Loadable system calls
    4. Executable formats
    5. STREAMS modules
    6. Miscellaneous
    7. Device and bus drivers
  12. Distinguish between virtualization and simulation.

    Virtualization makes guest operating systems and applications believe they are running on native hardware.

    Simulation in which the host system has one system architecture and the guest system was compiled for a different architecture. An emulator can translate instructions for the guest architecture into instructions for the host architecture.

Part 2: Design Considerations (40 marks)

Instructions: Please answer the following questions in about 1-2 pages each.

  1. Draw a typical computer organization figure that includes the main components of von Neumann architecture. Identify each component, and explain its function and interaction relative to other components. (15 marks)

                      -------------
                      | --------- |
                      | | CPU   | |
                      | | ----- | |
                      | | |CU | | |
                      | | ----- | |
      ----------      | | ----- | |       ----------
      | Input  |      | | |ALU| | | ----> | Output |
      | Device |----> | | ----- | |       | Device |
      ----------      | --------- |       ----------
                      |   |  A    |
                      |   V  |    |
                      | --------- |
                      | | MU    | |
                      | --------- |
                      -------------
    
    

    source

    In the von Neumann architecture an input device may trigger a signal to be handled by the operating system. The control unit will need to fetch the privileged instruction to place into a register or the memory unit to provide to the CPU to execute. The ALU will decode the instruction and then the instruction will be executed. The result is then stored in a register or the main memory unit to be written to the output device.

    • Input device: Includes keyboard, mouse, camera, microphone etc.
    • CPU: Contains the control unit, arithmetic logic unit and main memory
      • CU: Control unit handles all processor control signals. It directs I/O flow, fetches code for instructions and controls how data moves around.
      • ALU: The arithmetic logic unit is that part of the CPU that handles all the calculations the CPU may need. It performs logical, bit shifting and arithmetic operations.
    • MU: Main memory unit contains the accumulator, program counter, memory address register, memory data register, current instruction register and instruction buffer register.
    • Output device: Includes display, speakers, disk etc.

    source

  2. Define system call, and list the main types of system calls. Elaborate on how a system call interacts with a standard C library and hardware under a dual-mode operating system environment. (10 marks)

    The two types of systems call modes are kernel mode and user mode. With a mode bit we are able to determine if a task is being executed on behalf o the operating system or the user. A user may request a service from the operating system via a system call. In this case the system call will transition from user mode to kernel mode to perform the request then transition back to user mode once the request has been fulfilled.

    user
      [process] -> [system call]   [return from system call]
                       |                   |
                  (user mode)         (user mode)
    -------------------V------------------ A-----------------
    -------------------V------------------ A-----------------
    kernel             |                   |
                 (kernel mode)             |
                       |                   |
                     [execute system call]-|
    
  3. Describe the overall structure of virtual machines, and compare VMware and JVM. (15 marks)

    A virtual machine creates an abstraction over hardware to present the illusion that the guest operating system is running on bare metal hardware. The virtual machine provides an interface that looks the same as the hardware that the guest operating system thinks that it is interacting with. This capability allows a host operating system to run multiple guest operating systems on a single system.

    A regular system would usually have a single operating sytem like the following example:

    -------------
    |           |
    |           |
    | processes |
    |           |
    |           |
    -------------
    |  kernel   |
    -------------
    | hardware  |
    -------------
    

    Virtual machines allow multiple operating systems to run simultaneously while using the same hardware. Each guest operating system is unaware that it is sharing hardware with other guest operating systems.

    -------------
    |           |           -------------
    |           |-----------|           |
    | processes | processes | processes |
    |           |           |           |
    |-----------|-----------|-----------|
    | kernel    | kernel    | kernel    |
    |-----------|-----------|-----------|
    |   VM1     |    VM2    |    VM3    |
    -------------------------------------
    |            hypervisor             |
    -------------------------------------
    |             hardware              |
    -------------------------------------
    

    VMWare is a company that build virtual machine technology to allow multiple guest operating systems on a single machine.

    The JVM is the Java Virtual Machine which acts as a different type of virtual environment. The JVM takes bytecode and converts it into architecture specific instructions are run time using just in time compilation. This type of virtual machine allows programmers to write software in multiple languages that compile down to JVM bytecode. The same JVM bytecode can be used to conver it to architecture specific instructions for different platforms such as Microsoft Windows, Linux and macOS.

Sources: