http:^^cs.cornell.edu^info^courses^fall-95^cs415^qanda^qanda.html

来自「This data set contains WWW-pages collect」· HTML 代码 · 共 257 行

HTML
257
字号
MIME-Version: 1.0
Server: CERN/3.0
Date: Monday, 16-Dec-96 22:00:28 GMT
Content-Type: text/html
Content-Length: 11344
Last-Modified: Wednesday, 25-Oct-95 13:37:15 GMT

<TITLE> CS415 Questions and Answers </TITLE> <P> <STRONG> Phase 1 </STRONG><HR><DT> <STRONG> Question:</STRONG> We're having difficulty understanding the abstraction forprocess queues which we're asked to implement for phase one of theproject for cs415.  We don't understand what removeProc is supposed todo.  The specification says, "Remove the first element from theprocess queue whose tail-pointer (not tail) is pointed to by tp."  Arewe to scan down procTable for the first element which has atail-pointer (by which we assume you mean the element p_next of somestructure of type proc_t) identical to (*tp)? <P><DT><STRONG> Answer: </STRONG> Function RemoveProc should do preciselywhat the spec says.  Consider a queue q (A queue is a FIFO list with a"head" element and a "tail" element).  Consider a pointer to the tailelement of q. Let that pointer be p.  Consider now a pointer to p.Let's call it tp.  RemoveProc assumes that you know tp. Your goal isto remove from q the head element of q.  How you do it (namely, howyou devise a "smart" and efficient implementation of the queue datastructure that makes this task easy) it is up to you... :-)<HR><DT> <STRONG> Question: </STRONG> I cannot read files <EM> types.h</EM> and <EM> const.h </EM>. In particular, if I try to accessdirectory ~cs415/hoca/h I get back "Permission Denied". What should Ido?<DT> <STRONG> Answer: </STRONG> Don't try to cd to the directory -- you won't be able to do that.Instead, just use the UNIX "cp" command to copy the files from~cs415/hoca/h to your directory.The following will work, as I have just tried it on dahlia in theSunLab:<PRE>  dahlia% cd  dahlia% cp ~cs415/hoca/h/types.h types.h  dahlia% cp ~cs415/hoca/h/const.h const.h</PRE><HR><DT> <STRONG> Question: </STRONG> I believe the function on pg 10 should be outBlocked(semAdd,p) NOToutBlocked(p) as listed<DT> <STRONG> Answer: </STRONG> No, outBlocked really takes only p as a parameter. As you pointout, however, you do need to know the address of the semaphore, ifany, on which p is blocked. Maybe this is an instance in which addingfields to the given data structures is a good idea...   <HR><DT> <STRONG> Question: </STRONG> The assignment says that we can add to the fields of proc_t,semd_t to make them more efficient.  But since we are abstracting themin our module, how close to this implementation to we have to have?  Iask this because the "queue" implementation only has a pointer to thetail, not both the head and tail, as usual.  Thus removeProc() willinvolve a search along the whole list.  Does the "tail pointer" haveto point to something of type proc_t, or can it point to anintermediate type which points to the head and tail of the queue?<DT> <STRONG> Answer: </STRONG>Yes, you can add fields to the proc_t and semd_t structures.However, you should try to resist the temptation to add fields withouthaving first thought if a simpler and more efficient solution existsthat will not require you to do so. Implementing the queue abstraction,and taking care of function removeProc(), happens to be an instance inwhich adding fields to the structures would probably only serve tomake things more complex and less efficient. To be specific,removeProc() *can* be efficiently implemented with the structure fieldsthat you have already without involving a search along the whole list,as you suggest. Also, the tail pointer (which by the way must point tothe last element in the queue) does have to point to an element oftype proc_t.<HR><DT> <STRONG> Question: </STRONG>Is the C that pcc compiles for the "old-style" C?What does it expect for function declarations in export files?pcc keeps giving a core dump when we try to compile ourexport file.<DT> <STRONG> Answer: </STRONG>Indeed, pcc uses the "old" C syntax.As far as how to set up extern declarations in a .e file, you canrefer to the example in Appendix 1 of the HOCA documentation. (fileQueue.e).<HR><DT> <STRONG> Question: </STRONG>Hi!  We compiled our modules with gcc first (along with our owntester module), so that we could use the awesome debugging powerof gdb before moving on to the graphically pleasing but somewhatless powerful CHIP simulator.  We just thought others might benefitfrom this strategy, and we wonder<DT> <STRONG> Question: </STRONG>ed if you might pass it on viathe Web.<DT> <STRONG> Answer: </STRONG>Using gcc to compile and debug your modules is a good idea, if youknow how to use gdb. However, keep in mind that:<UL><LI> <STRONG> The executable compiled with gcc will not run in CHIP.</STRONG> Gcc produces executable for your SPARC, not for CHIP.<LI> Because of the above point, you will have to eventuallycompile your files using pcc. Remember that <STRONG> pcc is notANSI-compliant</STRONG>. If you used ANSI C in your gcc code, you willhave to change it back to pre-ANSI notation.<LI> Beginning with the next phase, gcc will probably be lessuseful, since you will need to look closely at what happens in CHIPregisters and memory. Your friendly CHIP interface will be glad to help:-)</UL><HR><STRONG> PHASE 2 </STRONG><HR><DT> <STRONG> Question: </STRONG>Is there an instruction called STIT in CHIP?  If not, does that mean that we can't read the value stored in IT?<DT> <STRONG> Answer: </STRONG>No, there is no instruction named STIT. You can infer what the valueof IT is by comparing the current time of day with the time of dayof the last time you loaded IT.<HR><DT> <STRONG> Question: </STRONG>Does sys6 return total CPU time(t1+t2) used by the process or thecurrently used cpu-time(t2)?that is<PRE>Process 1:   |-----t1-----|         |-----t2-----|process 2:                |---------|            |                                                 |                                                 |<-sys6 is called at here.</PRE><DT> <STRONG> Answer: </STRONG>SYS6 returns t1+t2<HR><DT> <STRONG> Question: </STRONG>Interrupt priority 0 is higher(or lower) than priority 5 ?<DT> <STRONG> Answer: </STRONG>I believe 5 is higher. But why do you care?<HR><DT> <STRONG> Question: </STRONG> To set the initial "running" area for the nucleus, we use STSTat some point.  How do we guarantee the processor will be in kernelmode before that?  <DT> <STRONG> Answer: </STRONG>Your program runs by default in kernel mode. So you can use STST withno problems.<HR><DT> <STRONG> Question: </STRONG>Could you please tell me how to get the value in the status register andthat in the length register for an IO device?  There is a table on page 17of the CHIP documentation, but that doesn't seem to help much.  Actually,when does the value in the length register need to be retrieved?  Furthermore, how am I supposed to pass those two values to the appropriate process when necessary?  Do I just save them in the corresponding entry in the process table?<DT> <STRONG> Answer: </STRONG>First of all when a device completes i/o  the values for the statusand length register are returned in the device registers for thatdevice. The device registers are located in CHIP's memory just belowthe interrupt area. As far as accessing that area, if you look in const.h you will findthe following definition:<PRE>#define BEGINDEVREG     01400   /* beginning of device registers */</PRE>that should be what you are looking for.The value in the lenght register need to be retrieved for the Terminaland Printer devices. (see sections 8.3 and 8.4)You are going to pass these values as follows:if there is a process waiting on the i/o semaphore for the device thatreturned the values, then you can simply copy the values in theregisters 2 and 3 of the process that is waiting. (you should alsounblock the process)if there is no process waiting, you should copy the returned value inthe buffer dedicated to the device (the one that you declared atinitialization time). The process which initiated i/o will eventuallyretrieve the values from there.<HR><DT><STRONG> Question: </STRONG>Why do we need to distinguish between caller and running inside a traphandler? What does really mean "passing up" a trap? And what is SYS5doing, anyway? <DT> <STRONG> Answer: </STRONG>Let me answer the question is reverse order.<PRE>* What is SYS5 doing, anyway? </PRE>SYS5 is called to initialize the old andnew trap areas that are kept by each process (as opposed to the trapareas kept by the nucleus in the low memory addresses).It is not your job (at least for now) to decide *how* to initializethose areas: you can just assume that they are initialized through thevalues passed in registers 2, 3, and 4. You can look at an example ofinitialization browsing through the test program.<PRE>* What does really mean to "pass up" a trap?</PRE>Passing up a trap really means invoking a trap handler that is not locatedin the nucleus, but rather in a higher layer of the operating system.Before a trap can be passed up, the appropriate old and new trap areasfor the calling process must be initialized (calling SYS5). If anattempt to pass up a trap is made before SYS5 for the invoked traptype has been executed, the calling process must be terminated.Passing up the trap involves copying the state of the callingprocess into the old area, and copying the state contained in the newtrap area in the calling process' state as it is maintained in theprocess table.A possible implementation of the "passing up mechanism" would callMOVBLK twice. The first time to copy running->p_s in the old traparea. The second time to copy the state stored in the new trap area intorunning->p_s.  As you can see, to "load" the new state we are notusing LDST.  Rather, we just modify the state of the running processin the proc table. With this implementation when the nucleus traphandler finishes, and the calling process gets to run again, it willactually run the higher level trap handler.<PRE>* Why do we need to distinguish between caller and running process?*</pre>You may or may not, depending on your implementation. In mine, the reason why the caller may be different from the running process iseasy to see if we consider the SYS trap handler, and we concentrate onSYS4, As a result of the P operation, the calling process may beblocked, and a new process elected to be the next to run. Using the caller vs running trick one can figure out withn the SYStrap handler if such an event has taken place, and load the IT for thenew running process with an appropriate value.It is less clear why the caller/running trick may be useful for prog,MM, or even SYS traps for SYS instructions greater than 8. After all, thesetraps are "passed up", a new state is loaded, and any instruction aftera call to passup will never be executed (this was the question thatNesheet asked today in class).In my implementation, the check that the trap areas have beeninitialized (i.e. the right SYS5 has been executed) is done within thecall to passup. If the caller process has not executed SYS5, the caller willbe terminated, and a new process will be designated as the next torun. In this case, control will indeed reach the code after passup, and the "caller!=running" check will allow to correctly reload theinterval timer.<HR>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?