Sunteți pe pagina 1din 5

CoE 135 Problem Set 1

Raphael Cyron Robles


Electrical and Electronics Engineering Institute
University of the Philippines Diliman
Quezon City, Philippines
cyron.robles@eee.upd.edu.ph

I pledge that I answered all the items in this Problem Time, Network, Parallel, Distributed, Clustered, Handheld.
Set to the best of my understanding, and with the aid of
properly cited resources and collaborators in problems I The batch operating system does not let the user
could not solve on my own. I made sure that I cited all interact with the computer directly. Instead, the user
resources and stated the names of all those who guided uses devices like punch cards which are then submitted
me in answering all the items along with their invaluable to the computer operator. The computer operator then
contributions. has to sort these programs into batches that share
similar needs in order to speed up processing. [2].
Raphael Cyron M. Robles
Interactive operating system, on the other hand,
2015-06938
allows the user to interact directly with the operating
system. It is done with the use of a user interface, be
I. P ROBLEMS
it graphical or command line, and allows interaction
1. During your Arch Linux installation procedure in with the OS while multiple progrums are running. [2]
Machine Exercise 1, you were required to set up the boot Time sharing enables multiple users to use the system
loader for Arch Linux. Why is that step required? Why does an to use the system effectively ’at the same time’. The time
Ubuntu installation not require the same procedure? Why do sharing operating system is optimized for responsiveness
we need boot loaders in general What is their role? Give two through frequent switching of the CPU between
examples of boot loaders, and compare their highlight features. multiple jobs. It uses scheduling and multiprogramming
to provide the users a small portion of time. [2]
Setting up the boot loader is required because the A real time operating system features the ability
boot loader is the first piece of software started by the BIOS to handle input data within little and guaranteed
or UEFI, responsible for loading the kernel and initial RAM response time. It must have a well defined and
disk with the wanted parameters and configurations. [1]. fixed time constraints, otherwise it would fail. [3]
Since the default installation of Arch Linux is a minimal The network operating system has the purpose of
base system, the user has to add and configure whatever is allowing file and device access to multiple computers
required, e.g. the boot loader. Ubuntu installation does not connected in a network. It runs on the server which
require the exact same procedure for configuring the boot has the capability to manage data, users, groups,
loader; however, it still requires the installation of a boot loader applications and other networking functions. [2]
which comes preconfigured, only prompting for the user’s Parallel operating systems are the interface between
input to which device the boot loader should be installed on. parallel computers and applications executed on them.
One of the most common bootloaders, and the one that It is designed to speed up program execution times by
comes preconfigured for Ubuntu, is GRUB(GRand Unified ’dividing’ the program and processing it simultaneously.
Bootloader). GRUB supports both UEFI and BIOS firmware, Distributed operating systems operates over a collection of
multi-booting, full support for ext4, ReiserFS v3, VFAT, independent, networked and separate nodes. Jobs are handled
XFS, and Btrfs without zstd compression. rEFInd is a UEFI and distributed along multiple CPUs accordingly. To do this,
boot loader designed to be platform-neutral and to simplify the processors communicate through various communication
booting multiple OSes, auto-detecting kernels and parameters lines(e.g. high speed buses, telephone lines). [3]
without explicit configuration and offers full support for A clustered operating system features multiple computers
VFAT, Btrfs without encryption and zstd compression, ext4 that share a common file system equally. It is used to
without encryption, ReiserFS v3 without tail-packing feature. maximize availability, where if a system fails, another
[1]. one from the cluster can take over, effectively using
multiple computers to acomplish a single task. [3]
Self Grade for Number 1: 4
Handheld operating systems are optimized
2. Discuss the essential properties of the following types of with features that are necessary for handheld
operating systems: Batch, Interactive, Time Sharing, Real devices(e.g. touchscreen interface, network connections).
Self Grade for Number 2: 4
3. mmap() is a system call that is always invoked whenever
our programs start executing according to the output of
our strace experiment in Machine Exercise 3. What are
the use cases of mmap(), including and aside from its
usage in your test programs for the lab? Provide at least
three code snippets that use mmap() in three different ways.

A common use case for mmap() is for dynamic/shared Fig. 3. Mapping with mprotect().
libraries. We mmap() the contents of the program in the
address space of the program if it has dynamic linkage [2].

Fig. 4. Reading a file from mmap.

4. We have two sets of API to perform file handling, the


standard version provided by <stdio.h> and the system call
file management API. When do we use one version over the
Fig. 1. Strace output for a simple hello world program. other? When should we use buffered I/O? When should we use
non-buffered I/O? Provide concrete examples for each case.

The system call file management API uses non-buffered


I/O and the standard version uses buffered I/O. We use the
non-buffered version when we need to ensure that the output
Fig. 2. Mapping ld.so.cache has been written before continuing, e.g. errors, and to avoid
having an extra copy into a second buffer when we have a large
From the strace output, the first usage of mmap() is
sequence of file ready to write to disk. The buffered version,
at line 7, highlighted at Fig.2, where it mmaps the file
on the other hand, accumulates writes to an intermediate
descriptor 3 obtained from /etc/ld.so.cache, returning
buffer, only sends it to the OS file system when enough
the starting address of the mapped file in memory.
data has accumulated or flush() is called to reduce the
Next usage from the output comes from the lines
number of file system calls. Hence, we use the non-buffered
shown in Fig. 3 where mmap() is called multiple
version when we need large buffers to send. We use the
times along with mprotect() to map libc.so.6 into
buffered I/O when we need to implement portable programs
the memory, this time with mprotect() protecting
since it has specific implementations on various host OSes.
certain memory portions as read only to prevent the
Generally, buffered I/O is faster but can be less reliable
program from writing to memory that is not mapped for it.
in certain circumstances. We would want to use the buffered
I/O when we will be limited by the hardware may be due to
Another sample usage for mmap is for reading files.
high latency or only permitting data to be accessed in chunks
Fig. 4 shows the code for a program that reads that file
and typically when we want to minimize the system calls
“myfile” int-by-int from the mmap.
used to improve speed which is generally the case for most
Self Grade for Number 3: 4 programs. Unbuffered I/O on the other hand would be useful
for applications where data is being changed randomly such
as multithreaded applications and using a buffered I/O would
result in a stale buffer, leading to incorrect results.

Self Grade for Number 4: 4


5. There are many ways to implement all the data structures
in general programming. How does the Linux Kernel
implement its data structures? What interface does the
Linux Kernel provide for Kernel Developers to make
use of its data structures? How can we implement
stacks and queues using the fundamental data structure
provided by the Linux Kernel as a base data structure?

Linux kernel implements its data structures through


its simplest and most common data structure, the linked
list. The implementation of the linked list in the Linux
kernel is unique to common linked list implementations. The
approach is to embed a linked list node in the structure. [5] Fig. 5. Block 1 tree.
The Linux kernel provides the developers the code for the
linked list data structure in the header file <linux/list.h>
Stacks and queues can be implemented in Linux using the code. Block 2 finishes with 15 processes as shown in Fig.6.
linked list. The two functions needed for the most basic
functionality of stacks ans queues are push and pop. Push Since block 1 finished with 10 processes, each of
and enqueue will have the same functionality for both stack those processes will enter block 2 therefore the total
and queues where it will add a new item at the end of the number of processes created can be computed by
linked list. Push and dequeue, on the other hand, will differ multilying 10 to the number of processes in block 2
with from where they remove the item from the list, dequeue giving a total of 150 processes created in the program.
removes the first item for the queue and pop removes the last
item for the stack.
Self Grade for Number 6: 4
Self Grade for Number 5: 4
7. Write a program that creates a parent an child process.
6. You are given the code snippet below: The parent process will take integer inputs. All integer
inputs greater than zero will be sent to its child process.
fork(); The child process will then compute the Collatz Sequence
fork() && fork() || fork(); of the received integer and shares the entire sequence to the
if (fork() || (!fork())) parent process. The sharing scheme must be implemented
if (fork() && (!fork())) using Message Passing API and Shared Memory API.
if (fork() || fork()) Hint: You *really* would want to work on this as a group.
fork();
printf("CoE 135"); Code for Collatz Sequence with sharing is shown in
Fig. 7. This item is answered in collaboration with John
How many processes are created? Why? Draw the Raphael Pascua.
tree diagram for the process tree created by this code
Self Grade for Number 7: 3
snippet. Tip for drawing: You can just scan/take a picture
+ use CamScanner or similar apps to submit your drawing. 8. Compare and contrast the behavior and
use cases of blocking and nonblocking func-
The code can be divided into two blocks, block 1 tions. Provide an example for each case.
which contains the first two blocks and block 2 with
everything else. Block 1 is pretty straightforward where Blocking functions, as the name suggests, blocks
the the and(&&) and or(||) operators does not really the execution of the code following it until the blocking
matter since it only affects the return value of the line. function finishes execution. It essentially creates a schedule
Block 1 finishes with 10 processes as shown in Fig. 5. for events by waiting for certain functions to finish first,
Block 2 introduces a series of conditional statements implementing synchronous activity. Nonblocking functions,
where some processes finishes ’forking’ because the condition on the other hand, calls the function and then proceeds
in the statement has not been satisfied and proceeds to finish to the succeeding lines and it does not matter if the
Fig. 6. Block 2 tree.

nonblocking function has finished execution or not. [6]


sleep(n) is an example of a blocking function.
It suspends the program for n seconds and it will only
continue executing the succeeding lines of code once n
seconds has passed or an interrupt is received. Another
example of blocking functions are scanf() and fgets()
where a user input is required to proceed with execution.
An example for a nonblocking function would be
select(). It can monitor different resources at the same
time and poll for network activity without blocking. [6]

Self Grade for Number 8: 4


9. One of the data structures used by the kernel is the
Process Control Block. The Process Control Block is used
to store all the information about a process. Upon close
inspection of the struct definition of the PCB, it heavily
makes use of macros. Give at least three examples of
macros used in Linux’s PCB, their meaning, and a brief
description of their purpose. Explain why the kernel makes
extensive use of macros and macro functions in general. Fig. 7. Collatz Sequence Program.
Hint: Try to avoid going in too deep into the Linux
PCB data structure for now. It’s quite a deep rabbit hole.

The Linux kernel is heavily reliant on the use of


macros to maintain easy porting and compatibility. It is
beneficial to use macros since it would make changing
necessary values(for adjustments for different architectures)
across the whole kernel system much more easier since
the kernel is basically one huge chunk of code. [7]
Some examples of macros used in Linux’s PCB
are __init, __nosavedata and __setup_param.
__init is used to mark functions or initialized data for
the kernel to be able to identify that it is only being used
for initialization process only and it can be freed afterwards.
__nosavedata is used to mark data not to be saved by
software suspend. __setup_param is used to force the
alignment so the compiler doesn’t space elements of the
obs kernel param ”array” too far apart in .init.setup. [8]
Self Grade for Number 9: 4
10. We can make use of mutexes and condition variables
to synchronise multiple threads. However we can also
make use of time and timer functions to synchronise
threads. When is forced synchronization via time and
timer functions applicable and not applicable? Provide
sample code for each case and explain why your provided
programs will synchronise and not synchronise using Fig. 8. Timer synchronized snippet
purely time and timer functions alone. Hint: Lecture :)

Synchronization using time functions would be applicable for multithreading or local two player games. Spawning
for multiple threads that each does not necessarily need multiple processes allows better throughput since it takes
a significant amount of time handling the resources(i.e. advantage of multiple cores, with the cost of using separate
you are sure that the program will finish modifying the memory space. An example for this case would be a web
resources before the timer functions, with reasonable wait browser, where a tab can be treated as a new separate process.
times, ends). It would not be applicable for applications
that would result in a highly varying amount of processing Self Grade for Number 11: 4
time(e.g. Fig. 8) where it would be better to synchronise
using mutexes and condition variables to prevent the case R EFERENCES
where threads will still use exclusive resources when [1] ArchWiki, “Category:Boot loaders - ArchWiki,” [Online]. Available:
the timer has already finished for cases that we cannot https://wiki.archlinux.org/index.php/Category:Boot loader [Accessed 20
Sep. 2018].
predict the execution time needed by the thread to finish. [2] TutorialsPoint, “Types of Operating System,” [Online]. Available:
https://www.tutorialspoint.com/operating system/os types.htm
[Accessed 26 Sep. 2018].
Self Grade for Number 10: 4 [3] TeachICT, “Category:Boot loaders - ArchWiki,”
[Online]. Available: http://www.teach-ict.com/
11. Programs tend to perform many I/O operations over as a2 ict new/ocr/A2 G063/332 designing systems/operating systems/
time. We have several methods to maximize CPU utilization miniweb/index.htm [Accessed 26 Sep. 2018].
[4] M.F. Wani, “What are some real world uses of mmap() Linux system
and user experience with I/O, namely, signal-driven I/O, call?,” [Online]. Available: https://www.quora.com/What-are-some-real-
multithreading, and spawning multiple processes. When is it world-uses-of-mmap-Linux-system-call [Accessed 25 Sep. 2018].
best to make use of signal-driven I/O? When is it best to make [5] Shichao’s Notes, “Chapter 6.Kernel Data Structures,” [Online].
Available: https://notes.shichao.io/lkd/ch6/#chapter-6-kernel-data-
use of multithreading? When is it best to make use of multiple structures [Accessed 21 Sep. 2018].
processes? Provide a real-world usage example for each case. [6] K-State, “Blocking and Nonblocking I/O,” [Online]. Available:
http://faculty.salina.k-state.edu/tim/ossg/Device/blocking.html
[Accessed 26 Sep. 2018].
Signal driven I/O is used to handle asynchronous [7] A. Gargi, A. Mujeeb, “Why does the Linux kernel define a lot of
events where the kernel sends a signal when something macros?,” [Online]. Available: https://www.quora.com/Why-does-the-
happens to a file descriptor. It is best used for system Linux-kernel-define-a-lot-of-macros [Accessed 26 Sep. 2018].
[8] B.P. Singh, “Linux kernel Macros and their meaning,” [On-
timers, keyboards, mice, controllers. Multithreading is line]. Available: https://www.linkedin.com/pulse/linux-kernel-macros-
best used for program has mutually independent tasks. meaning-bhanu-prakash-singh [Accessed 26 Sep. 2018].
It can improve the program with the introduction of
parallelism. Examples of use cases would be for really
long computational functions that would be optimized

S-ar putea să vă placă și