summaryrefslogtreecommitdiff
path: root/doc/assignment1.md
blob: 42a630146f95b396aeb640521276d72b5b9f49ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# 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:

    ```bash
    モ 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.

    ```ruby
    #!/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.

    ```bash
    モ ruby lib/sigtrap.rb
    .....done
    ```

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

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

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

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

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

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

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

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

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

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

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

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

    ```
    [source][wiki-von-neumann]

    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][geeks-von-neumann]

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

    ```plaintext
    user
      [process] -> [system call]   [return from system call]
                       |                   |
                  (user mode)         (user mode)
    -------------------V------------------ A-----------------
    -------------------V------------------ A-----------------
    kernel             |                   |
                 (kernel mode)             |
                       |                   |
                     [execute system call]-|
    ```

1. 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:

    ```plaintext
    -------------
    |           |
    |           |
    | 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.

    ```plaintext
    -------------
    |           |           -------------
    |           |-----------|           |
    | 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:

* [Computerphile][computerphile-von-neumann]
* [Geeks for Geeks][geeks-von-neumann]
* [Operating System Concepts][os-book]
* [Wikipedia][wiki-von-neumann]

[wiki-von-neumann]: https://en.wikipedia.org/wiki/Von_Neumann_architecture
[geeks-von-neumann]: https://www.geeksforgeeks.org/computer-organization-von-neumann-architecture/
[computerphile-von-neumann]: https://www.youtube.com/watch?v=Ml3-kVYLNr8
[os-book]: https://www.os-book.com/OS10/index.html