如果有,当然这只是种假设,因为中断处理程序都能很快的被执行,但如果出现意外,比如自旋,那么中断处理程序会一直占用CPU, 还是在自己的时间片用光后让出CPU?
但是,这时的内核是处于中断上下文中,中断处理程序让出CPU后又怎么会被再次调度呢?
如果没有,那么遇到前述的问题,系统是否就会崩溃?
5 个解决方案
#1
自旋锁是否关中断呢
#2
中断处理程序没有时间片一说,时间片是针对进程的。
#3
linux的驱动程序分两个部分实现:top-half和bottom-half。
top-half在运行时,不能被其他任何中断再次中断,也不能被其他进程中断,它通过对CPU内的中断屏蔽置位实现,而bottom-half则只对top-half开中断。
这样,系统就可以根据中断服务程序的访问特点,安排那些访问临界区的服务程序为top-half,其他中断服务程序为bottom-half。
每次离开中断处理程序,系统会执行schedule(),发生进程调度。
top-half在运行时,不能被其他任何中断再次中断,也不能被其他进程中断,它通过对CPU内的中断屏蔽置位实现,而bottom-half则只对top-half开中断。
这样,系统就可以根据中断服务程序的访问特点,安排那些访问临界区的服务程序为top-half,其他中断服务程序为bottom-half。
每次离开中断处理程序,系统会执行schedule(),发生进程调度。
#4
Sect "Spin Locks" of Chap9 in Linux Kernel Development 2nd
自旋锁可以在中断处理程序中使用,不过在获得锁之前,首先禁止本地中断(在当前处理器上的中断请求)。。。参见:
Spin locks can be used in interrupt handlers, whereas semaphores cannot be used because they sleep. If a lock is used in an interrupt handler, you must also disable local interrupts (interrupt requests on the current processor) before obtaining the lock. Otherwise, it is possible for an interrupt handler to interrupt kernel code while the lock is held and attempt to reacquire the lock. The interrupt handler spins, waiting for the lock to become available. The lock holder, however, does not run until the interrupt handler completes. This is an example of the double-acquire deadlock discussed in the previous chapter. Note that you need to disable interrupts only on the current processor. If an interrupt occurs on a different processor, and it spins on the same lock, it does not prevent the lock holder (which is on a different processor) from eventually releasing the lock.
还有,中断处理程序运行的时候,相应的中断线在所有处理器上都被屏蔽,以防同一中断线接受另一个新的中断,但通常情况下,其他的所有中断都是打开的。。。。。。,参见:
Section “Writing an Interrupt Handler”of Chap6,
Reentrancy and Interrupt Handlers
Interrupt handlers in Linux need not be reentrant. When a given interrupt handler is executing, the corresponding interrupt line is masked out on all processors, preventing another interrupt on the same line from being received. Normally all other interrupts are enabled, so other interrupts are serviced, but the current line is always disabled. Consequently, the same interrupt handler is never invoked concurrently to service a nested interrupt. This greatly simplifies writing your interrupt handler.
Sect “Interrupt Context”of Chap6,
永远牢记:中断处理程序打断了其他代码(甚至可能是打断了在其他中断线上的另一中断处理程序),参见:
always keep in mind that your interrupt handler has interrupted other code (possibly even another interrupt handler on a different line!).
#5
请问有最后的答案了吗?
这个是关键的问题,我也提了个单子,请回复一下
http://topic.csdn.net/u/20110310/11/03c7706a-6449-4c19-8a28-97edb6710aba.html
这个是关键的问题,我也提了个单子,请回复一下
http://topic.csdn.net/u/20110310/11/03c7706a-6449-4c19-8a28-97edb6710aba.html
#1
自旋锁是否关中断呢
#2
中断处理程序没有时间片一说,时间片是针对进程的。
#3
linux的驱动程序分两个部分实现:top-half和bottom-half。
top-half在运行时,不能被其他任何中断再次中断,也不能被其他进程中断,它通过对CPU内的中断屏蔽置位实现,而bottom-half则只对top-half开中断。
这样,系统就可以根据中断服务程序的访问特点,安排那些访问临界区的服务程序为top-half,其他中断服务程序为bottom-half。
每次离开中断处理程序,系统会执行schedule(),发生进程调度。
top-half在运行时,不能被其他任何中断再次中断,也不能被其他进程中断,它通过对CPU内的中断屏蔽置位实现,而bottom-half则只对top-half开中断。
这样,系统就可以根据中断服务程序的访问特点,安排那些访问临界区的服务程序为top-half,其他中断服务程序为bottom-half。
每次离开中断处理程序,系统会执行schedule(),发生进程调度。
#4
Sect "Spin Locks" of Chap9 in Linux Kernel Development 2nd
自旋锁可以在中断处理程序中使用,不过在获得锁之前,首先禁止本地中断(在当前处理器上的中断请求)。。。参见:
Spin locks can be used in interrupt handlers, whereas semaphores cannot be used because they sleep. If a lock is used in an interrupt handler, you must also disable local interrupts (interrupt requests on the current processor) before obtaining the lock. Otherwise, it is possible for an interrupt handler to interrupt kernel code while the lock is held and attempt to reacquire the lock. The interrupt handler spins, waiting for the lock to become available. The lock holder, however, does not run until the interrupt handler completes. This is an example of the double-acquire deadlock discussed in the previous chapter. Note that you need to disable interrupts only on the current processor. If an interrupt occurs on a different processor, and it spins on the same lock, it does not prevent the lock holder (which is on a different processor) from eventually releasing the lock.
还有,中断处理程序运行的时候,相应的中断线在所有处理器上都被屏蔽,以防同一中断线接受另一个新的中断,但通常情况下,其他的所有中断都是打开的。。。。。。,参见:
Section “Writing an Interrupt Handler”of Chap6,
Reentrancy and Interrupt Handlers
Interrupt handlers in Linux need not be reentrant. When a given interrupt handler is executing, the corresponding interrupt line is masked out on all processors, preventing another interrupt on the same line from being received. Normally all other interrupts are enabled, so other interrupts are serviced, but the current line is always disabled. Consequently, the same interrupt handler is never invoked concurrently to service a nested interrupt. This greatly simplifies writing your interrupt handler.
Sect “Interrupt Context”of Chap6,
永远牢记:中断处理程序打断了其他代码(甚至可能是打断了在其他中断线上的另一中断处理程序),参见:
always keep in mind that your interrupt handler has interrupted other code (possibly even another interrupt handler on a different line!).
#5
请问有最后的答案了吗?
这个是关键的问题,我也提了个单子,请回复一下
http://topic.csdn.net/u/20110310/11/03c7706a-6449-4c19-8a28-97edb6710aba.html
这个是关键的问题,我也提了个单子,请回复一下
http://topic.csdn.net/u/20110310/11/03c7706a-6449-4c19-8a28-97edb6710aba.html