(1) Which of the following instructions should be allowed only in kernel mode? W
ID: 3888287 • Letter: #
Question
(1) Which of the following instructions should be allowed only in kernel mode? Why? (a) Disable all interrupts. (b) Read the time-of-day clock. (c) Set the time-of-day clock. (d) Change the memory map (2) When a user program makes a system call to read or write a disk file. In the case of reading from the disk, obviously the caller will have to be blocked (because there is no data for i). What about the case of writing to the disk? Need the caller be blocking awaiting completion of the disk transfer? (3) What is the key difference between a trap and an interrupt? (4) On all modern computers, at least part of the interrupt handers are written in (5) The register set is a per-thread rather than a per-process item. Why? After all, (6) If a multi-threaded process forks, a problem occurs if the child gets copies of all the assembly language. Why? the machine has only one set of registers parents threads. Suppose that one of the original threads was waiting for keyboard input. Now two threads are writing for keyboard input, on in each process. Does this problem ever occur in single-threaded processes? (7) Why would a user thread ever voluntarily give up the CPU by calling thread yield? After all, since there is no periodic clock interrupt, it may never get the CPU back. (8) In this problem you are to compare reading a file using a single-threaded file server and a multithreaded server. It takes 15 msec to get a request for work, dispatch it and do the rest of the necessary processing, assuming that the data needed are in the block cache. If a disk operation is needed, as is the case one-third of the time an additional 75 msec is required, during which time the thread sleeps . How many requests/sec can the server handle if it is single threaded? If it is multi-threaded? (9) Consider a system in which threads are implemented entirely in user space, with the run-time system getting a clock interrupt once a second. Suppose that a clock interrupt occurs while some thread is executing in the run-time system. What problem might occur? Can you suggest a way to solve it? (10) In a system with threads, is there one stack per thread or one stack per proces when user-level threads are used? What about when kernel-level threads are used? ExplainExplanation / Answer
1)
a)disable all interupts :-This is done in kernel mode because interrupts are used in context switches or to notify the system when retrieving data from the hard disk
b)read the time of day clock :- user mode can do this
c)set the time of day clock :- user mode can do this
d)change the memory map :-This is done in kernel mode only because if you do it in user mode, a process could overwrite another process’ (or the kernel’s) memory
3)
A trap instruction switches from user mode to kernel mode.An interupt is used to save the state of a process during the context switch
4)
There are actions that happen while an interupt is being handled.These actions need to be written in assembly because they cannot be expressed in higher level languages
5)
when a thread is stopped,it has values in the register.They must be saved,just as when the process is stopped the register must be saved.Multiprogramming threads is no different that multiprogramming processes ,so each thread needs its own register save area
6)
No.If a single-threaded process is blocked on the keyboard,it cant be fork
9)
It could happen that the runtime system is precisely at the point of blocking or unblocking a thread,and is busy manipulating the scheduling queues.This would be a very inopputune moment for the clock interrupt handle to begin inspecting those queues to see if was time to thread switching,since they might be in an inconsistent state.One solution is to set a flag when the run-tune system is entered.The clock handler would see this and set its own flag ,then return.When the runtime system finised,it would check the clock flag,see that a clock interrupt occurred, and now run the clock handler
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.