Uploaded by Akash Subedi

Sample CS444 Mid-term Exam, Fall 2016

advertisement
Name: ________________________________________________
University of Massachusetts - Boston
Intro to Operating Systems
Dr. Ronald Cheung
CS 444 - Fall 2016
In-Class, Open Book Mid-term Examination
October 31, 2016
The work on this examination is to be your own and you are expected to adhere to the UMass-Boston honor system. All questions can
be answered by either circling the correct answer(s) or by one or two short sentences. In the latter case, brevity counts. Do not try to
make up for a lack of understanding by providing a rambling answer.
1.
(3 points) What is the disadvantage of using hardware ports
as compared to memory mapped in programming I/O
operations?
5.
(3 points) What is a zombie process?
2.
(3 points) Why do you need to turn off CPU’s interrupt when
configuring interrupt registers for hardware?
6.
(3 points) What do you do to convert a non-thread safe
library function into a thread safe one?
3.
(6 points) Name 2 advantages of using queues over ring
7.
(3 points) Why is multithreading performing higher than
multiprocessing?
8.
(6 points) To acknowledge an interrupt from a COM port, the
CPU has to do this in 2 places:
buffers:
a._______________________________________
_________________________________________
b._________________________________________
__________________________________________
4.
(3 points) What is priority inversion?
a. _______________________________________________
_________________________________________________
b. _______________________________________________
_________________________________________________
1 out of 3
University of Massachusetts - Boston
Intro to Operating Systems
Dr. Ronald Cheung
CS 444 - Fall 2016
9. (30 points) Circle (T)True or (F) False for each question. If the
question is ambiguous, write in your clarification.
10. (20 points) If the following syscall function is initialized
with eax =100; ebx=20; ecx=30; edx =40
.globl _syscallc, _syscall
T or F After invoking fork(), the parent process always
starts first.
_syscall:
T or F Each process has its own stack area.
Value of eax=
________________
T or F The ret instruction restores the EFLAGS register.
T or F Reading the UART’s IIR resets the TX interrupt.
pushl %eax
pushl %ebx
pushl %ecx
pushl %edx
call _syscallc
popl
popl
popl
popl
iret
%edx
%ecx
%ebx
%eax
and the syscallc program and function in C
are given as follows:
T or F There is no need to save context when switching
between threads.
void syscallc( int arg1, int arg2, int
arg3 , int arg4)
{
arg1 = add3( arg2, arg3, arg4);
}
int add3(int a1, int a2, int a3)
{
int out;
out = a1 + a2 - a3;
return out;
}
T or F Interrupts from a blocked process happen on a
currently running process
T or F Win 32 APIs are POSIX compliant.
arg1 = ___________
arg2 = ___________
arg3 = ___________
T or F For trap processing, the CPU gets the vector
number from PIC.
arg4 = ___________
T or F Interrupts can be serviced during a syscall trap
operation.
T or F To share parameters among different threads
within a process, you have to pass them around
using Inter-process Communication (IPC).
2 out of 3
University of Massachusetts - Boston
Intro to Operating Systems
Dr. Ronald Cheung
CS 444 - Fall 2016
11. (20 points) In the tty.c program, modify the TTY interrupt
handling routine to handle ctl-S (0x13) and ctl-Q (0x11)
processing. If the enqueued received character is a ctl-S, stop the
transmitter. After receiving ctl-Q, resume transmitting.
The following interrupt handling routine in tty.c program is
provided as a reference:
CS444 interrupt handler routine
void irqinthandc(int dev)
{
int ch, lsr;
struct tty *tty = (struct tty
*)(devtab[dev].dvdata);
int baseport =
devtab[dev].dvbaseport;
/* hardware i/o port */;
pic_end_int();
/*
notify PIC that its part is done */
if ((lsr = inpt(baseport+UART_LSR))
& UART_LSR_DR) { /* if read-ready */
ch = inpt(baseport+UART_RX);
/* read char, ack the device */
enqueue( &tty->rbuf, ch );
/* save char in read Q (if fits in Q) */
if (tty->echoflag){
/* if echoing wanted */
enqueue(&tty->ebuf,ch);
/* echo char (if fits in Q) */
if (queuecount( &tty->ebuf
)==1) /* if first char...*/
/* enable transmit interrupts also */
outpt( baseport+UART_IER,
UART_IER_RDI | UART_IER_THRI);
}
}
if (lsr & UART_LSR_THRE) {
/* if it's tx ready */
if (queuecount( &tty->ebuf ))
/* if there is char in echo Q output
it*/
outpt( baseport+UART_TX,
dequeue( &tty->ebuf ) );
/* ack tx dev */
else if (queuecount( &tty->tbuf ))
{
/* if there is char in tbuf Q output it
*/
outpt( baseport+UART_TX,
dequeue( &tty->tbuf ) );
/* ack tx dev */
kickout(baseport);
/* on VMWare, restart ints */
}
else
/* all done transmitting */
{
outpt( baseport+UART_IER,
UART_IER_RDI);
/* shut down tx ints */
}
}
}
/* for VMWare, severe form of transmit
interrupt enable */
void kickout(int baseport)
{
outpt(baseport+UART_IER,
UART_IER_RDI);
outpt(baseport+UART_IER,
UART_IER_RDI|UART_IER_THRI);
}
3 out of 3
University of Massachusetts - Boston
Intro to Operating Systems
Dr. Ronald Cheung
CS 444 - Fall 2016
11.
Answers to Mid-term Exam:
1.
2.
3.
Performing I/O using input/output ports requires 2
additional instructions. This increases the size of the
instruction set.
If an interrupt occurs before finishing the configuration
of the I/O device, unexpected behavior can occur. For
example, if the address of the ISR has not been set in the
IDT table, the computer may go to an erroneous location
for the ISR when an interrupt occurs.
a. Provides buffering for transmitter and receiver with
different speeds
void irq3inthandc()
{
pic_end_int();
irqinthandc(TTY1);
}
void irqinthandc(int dev)
{
int ch, lsr;
struct tty *tty = (struct tty *)(devtab[dev].dvdata);
int baseport = devtab[dev].dvbaseport; /* hardware i/o port */
if ((lsr = inpt(baseport+UART_LSR)) & UART_LSR_DR)
{
/* if read-ready */
ch = inpt(baseport+UART_RX);
/* read char, ack the device */
if (ch == 0x13)
/* if the incoming char is cntl-S */
outpt( baseport+UART_IER, UART_IER_RDI);
/* turn off transmitter interrupt */
else if (ch == 0x11)
/* if the incoming char is cntl-Q */
outpt( baseport+UART_IER, UART_IER_RDI|
UART_IER_THRI);
/* turn on transmitter interrupt */
else
enqueue( &tty->rbuf, ch );
/* save char in read Q (if fits in Q) */
}
if (lsr & UART_LSR_THRE)
{
/* if it's tx ready */
if (queuecount( &tty->tbuf ))
{
/* if there is char in tbuf Q output it */
outpt( baseport+UART_TX, dequeue( &tty->tbuf ) );
/* ack tx dev */
kickout(baseport);
/* on VMWare, restart interrupts */
} else /* all done transmitting */
outpt( baseport+UART_IER, UART_IER_RDI);
/* shut down tx ints */
}
b. Allows better management of insertion and deletion of
sequential data.
4.
Priority inversion happens when higher priority level
tasks get blocked because they are waiting for resources
held by lower priority tasks and other lower priority
tasks which are not dependent of the resources run ahead
of the higher priority ones.
5.
A zombie process is a process whose parent process has
exited.
6.
To convert a thread unsafe function to a thread safe
function, change all global or static variables into local
automatic variables and pass these variables back to the
calling function.
7.
Higher performance can be achieved with multithreading
because we reduce the expensive context switching
needed for multiprocessing.
8.
a. acknowledge the PIC using EOI.
b. acknowledge the COM port TX or RX interrupts.
9.
F T F T F
T
F
F
T
/* notify PIC that its part is done */
/* call handler for COM2 */
F
10.
}
Value of eax = -50
arg1 = -50
arg2=30 arg3=20 arg4=100
/* for VMWare, severe form of transmit interrupt enable */
void kickout(int baseport)
{
outpt(baseport+UART_IER, UART_IER_RDI);
outpt(baseport+UART_IER,
UART_IER_RDI|UART_IER_THRI);
}
4 out of 3
Download