操作系统试题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Operating Systems Fall 2009 Midterm Examination
Name Student No. Score
Problem 1: Booting (4Points)
Turn on Bochs, and running JOS, JOS will first enter the 16-bit real mode. After execute several instructions, JOS will turn into 32-bit protected mode and fall into i386_init() function .
1. How does processor translate virtual address to physical address in
16-bits real mode, please give an example? (2’)
Real Mode: physical addr = 16 * segment + offset Example:
0xf000:0xe05b
16*0xf000+0x e05b = 0xf e05b
2. How does processor translate virtual address to physical address in
32-bits protected mode, please give an example? (2’)
Protected Mode: each segment is assigned an entry in a descriptor table. The index of the entry of the segment is the selector value that is stored in segment registers.
Example: (no paging) CS + base = 0x22 descriptor table[0x22] = 0x1000 Virtual address = 0x89014 Physical address = 0x1000 + 0x89014 = 0x 90014
CS + base Physical addr = Segment start addr + offset
The xv6’s system call stubs (sheet 27) are called by user-space C code as if they were ordinary C functions, so all callers are prepared for the stubs to not preserve caller-saved registers. The stubs invoke the INT instruction which vectors into kernel code that shortly jumps to alltraps (line 2755). alltraps and trapret save and restore all registers to and from a struct trapframe.
1.As we know, the return value is saved in %eax, how does the system
call return a value to user process through %eax? (2’)
cp−>tf−>eax = syscalls[num](); (sheet 27)
2.If the user process wants the kernel return a string of “Good Luck”, what
should user process provide and how does the kernel return certain string to user? (3’)
User process provide a buf[10] and transfer it to the kernel as a pointer. The kernel copies the “Good Luck” string into buf and returns a success. Then the user process can read the string in buf.
In the backtrace function, we can print out the back trace of the program. Suppose we have following call trace:
foo(int b) -> bar(int a) -> backtrace() The functions’ code address range list below.
A partial code and stack are as follows:
Fill in the blanks ([1-3], 2’ * 3) and answer the question. [1]
[2]
[3] . 1. What is the input argument of bar function? (2’) 13/0xd
2. What is %esp value after the backtrace function returns? (2’) 0xffffc9b8
0xffffc9c0
Current %ebp
Problem 4: Thread Libraries (19Points)
Thread is a useful concept to allow memory sharing among tasks. However, designing and implementing a thread library is fairly difficult. Read the following text and answer the questions:
1.What are the differences between a kernel and a user thread? (3’)
Kernel thread is a real execution context (it has cr3, kernel context, etc.). However, user thread is completely managed at the user level, from the kernel’s point of view, they exist in one process.
The mapping from kernel threads to user threads is an important choice in thread library. For example, GNU portable thread library maps N user threads onto one kernel thread.
2.What is the major advantage of choosing this mapping? (3’)
1st, the operations are all done in user level, without trapping to kernel. 2nd, the context switching is quite lightweight. Finally, user level thread scheduler allows flexible and highly customizable scheduling of the threads.
3.In what situation this mapping may become a bad choice, and why?
Please give at least one concrete example (i.e. scenario) to justify that this is a bad choice. (3’)
One thread calling into the kernel will block all other threads, even if some threads are ready to run.
4.Native POSIX Thread Library (NPTL) on Linux adopts a 1-1 mapping,
what are the pros and cons of this approach? (3’)
Pros:
1)Thread can directly calls system services (e.g. sleep), without
worrying about interfering with other threads.
2)Better system integration. (Compare to user threads that built upon
kernel threads)
Cons:
1)Extra trap to kernel on every thread operation.
2)The scheduling of kernel threads may interfere with user threads.
Kernel may schedule away a kernel thread associated with certain
user threads, while do not telling them. However, the user thread may be ready to run!
3)It is inflexible and inefficient to customize the scheduling of user
threads, since we must frequently invoke system calls to do that.