Operating System

1. Q:What is the difference between trap and interrupt?

A0:

 

Definition and difference between Hardware interrupt, Software Interrupt, Exception, Trap and Signals?

Answer:

Interrupts can be categorized into two groups which are asynchronous interrupts (aka interrupt, hardware interrupt) andsynchronous interrupts (aka exception). The former may arrive anytime, typically IO interrupts, the latter may only arrive after the execution of an instruction, for example when the cpu try to divide a number by 0 or a page fault. So that’s the difference between interrupts and exception.

Exception includes trap, fault, abort.

A trap is a kind of exceptions, whose main purpose is for debugging (eg. notify the debugger that an instruction has been reached).

A software interrupt (aka Programmed Exceptions) occur at the request of the programmer. They are used to implement system calls. Software interrupt is a considered to be an exception (because they are synchronous). Note that as far as Linux is concerned, software interrupt are handled by the CPU as trap so you might see somewhere else that system calls are implemented by trap.

Signals (or at least UNIX signals) are part of the inter process communication (IPC). They are just like asynchronous message that one process can send to another one. So I would not consider them to be interrupt or exception.

 

陷阱:由 trap 指令引起,恢复后 CPU 执行下一条指令(Debug point, system call)

中断:由硬件电平引起,恢复后 CPU 执行下一条指令

异常:由软件指令引起,恢复后 CPU 重新执行该条指令(Divide a number by 0 or a page fault)

 

中断和异常有个比较大的共同点就是"不可预知性",所以是被迫的;而陷阱有"有意为之"的含义

中断、异常和陷阱产生时都需要切换当前进程上下文进入中断处理程序(IDT table).

 

A1:An interrupt is a hardware-generated event, usually caused by an I/O device requesting service. The interrupt signal causes a change of °ow within the system: an interrupt service routine (ISR) saves the CPU state, services the interrupt, then restores control to the interrupted process. A trap, on the other and, is a software-generated interrupt. Traps are caused by 1) system calls and 2) exceptional software conditions (e.g. divide by 0). Other than the source and function, processing of traps and interrupts is the same.

 

A2:

An interrupt is generally initiated by an I/O device, and causes the CPU to stop what it's doing, save its context, jump to the appropriate interrupt service routine, complete it, restore the context, and continue execution. For example, a serial device may assert the interrupt line and then place an interrupt vector number on the data bus. The CPU uses this to get the serial device interrupt service routine, which it then executes as above.
A trap is usually initiated by the CPU hardware. When ever the trap condition occurs (on arithmetic overflow, for example), the CPU stops what it's doing, saves the context, jumps to the appropriate trap routine, completes it, restores the context, and continues execution. For example, if overflow traps are enabled, adding two very large integers would cause the overflow bit to be set AND the overflow trap service routine to be initiated.
-------------------------------------------------------------------------------------------------------------------------------------------
2.Q: What is Real Time?
A1: Often used in a dedicated application , this system
reads information from sensors and must respond within a fixed
amount of time to ensure correct performance.

A2: A system is said to be  real-time if the total correctness of an operation depends not only upon its logical correctness, but also upon the time in which it is performed. The classical conception is that in a  hard real-time or  immediate real-time system, the completion of an operation after its deadline is considered useless - ultimately, this may cause a critical failure of the complete system. A  soft real-time system on the other hand will tolerate such lateness, and may respond with decreased service quality (e.g., omitting frames while displaying a video).

Thus, the goal of a hard real-time system is to ensure that all deadlines are met, but for soft real-time systems the goal becomes meeting a certain subset of deadlines in order to optimize some application specific criteria. The particular criteria optimized depends on the application, but some typical examples include maximizing the number of deadlines met, minimizing the lateness of tasks and maximizing the number of high priority tasks meeting their deadlines.

http://en.wikipedia.org/wiki/Real-time_computing

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值