10/14 10/8 OS作業

名稱
10/8 OS作業
日期
10/14
課程名稱
作業系統
指導教師
劉艾華
心得
1.Give two reasons why caches are useful.
first:It minimizes the miss match between the main memory and the processor
second:A cache exists to speed up the time that the processor takes to obtain a bit of data.

2.What problems do they solve?
ans:Cache solve the transfer problems by providing a buffer of intermediate speed between the components

3.What problems do they cause?
ans:The main problem of cache is to be updated, e.g: you must have noticed that if the websites you visited for the first time takes more time opening of sites you open daily, this is because computer catch the cache copy of that site, but if due to any reason you are unable to connect to your internet connection, and an error occurs, that error page is saved as cache copy for that site, it opens error page insist of going to actual site, even when your internet connection is working, (for that you have to update your cache or remove the data from cache).

4.If a cache can be made as large as the device for which it is caching
(for instance, a cache as large as a disk), why not make it that large and eliminate the device?
ans:Though the size of a cache has increased over time, so too has the size of hard disk. An economical comparison of cache versus hard disk space in a cost per MB analsysis will show that a cache would be significantly more expensive. Furthermore, cache in general is considered "temporary" or volatile storage which means that the contents of the storage device is lost when the system is powered off. A hard disk, on the other hand, is "long term" or non-volatile storage; when the system is powered off, the hard disk still safely holds the data stored on it.

5.What Is the purpose of interrupts? What are the differences between a trap and an interrupt?


A trap is an exception in a user process. It's caused by division by zero or invalid memory access. It's also the usual way to invoke a kernel routine (a system call) because those run with a higher priority than user code. Handling is synchronous (so the user code is suspended and continues afterwards). In a sense they are "active" - most of the time, the code expects the trap to happen and relies on this fact.

An interrupt is something generated by the hardware (devices like the hard disk, graphics card, I/O ports, etc). These are asynchronous (i.e. they don't happen at predictable places in the user code) or "passive" since the interrupt handler has to wait for them to happen eventually.
You can also see a trap as a kind of CPU-internal interrupt since the handler for trap handler looks like an interrupt handler (registers and stack pointers are saved, there is a context switch, execution can resume in some cases where it left off).

6.Can traps be generated intentionally by a user program?
If so, for what purpose?
yes,A trap can be used to call the OS routines or to catch arithmetic errors.
User programs create traps for debugging purposes.

7.Please tell the functional differences between CPU and device controller.
Is there any similarity between them?
ans: CPU The Central Processing Unit (CPU) is responsible for interpreting and executing most of the commands from the computer's hardware and software.
device controller functions as a bridge between the device and the operating system and receive signals from CPU.
So,the diffrences between them are the former is like a brain interpreting informations to device controller,where most calculations take place ,the later is like nervous system send commands to deviceA device's controller playing an important role in the operation of that device.
The similarity is that both of them can controls other hardware.

8.Please discuss, in your own words, the cycle of the handling of an interrupt.
there are usually two way to signal interrupt ,software and hardware.When the CPU is interrupted,it stops what it is doing and immediately transfers execution to a fixed location.The fixed location ususally contains the starting address where the service routine for the interrupt is located. The interrupt service routine executes,on completion ,the CPU resumes the interrupted computation .