当前位置:网站首页>Interrupt and polling

Interrupt and polling

2022-06-23 13:42:00 Little monster

introduction

serial interface ( Foreign name :Serial Interface, abbreviation : A serial port ) Is to use serial communication Mode extension interface , finger Data is transmitted bit by bit . The characteristic of serial interface is that the communication circuit is simple , As long as a pair of transmission lines can achieve two-way communication ( The telephone line can be directly used as the transmission line ), Thus greatly reducing the cost , special It is suitable for long distance communication , But the transmission speed is slow .

There are generally two ways for external devices to interact with the CPU : Interrupt and polling .

interrupt (Interrupt)

Interrupt is a kind of interrupt sent by hardware or software IRQ( Interrupt signal ), once CPU Received interrupt signal ,CPU The current task will be suspended , And keep the site , To respond to an interrupt request from a peripheral .
The interrupt notification mechanism asynchronously calls the attention of the processor through hardware signals , It solves the problem of resource waste caused by speed mismatch between external devices and processors .

polling (Polling)

quite a lot I/O Each device has a status register , Used to describe the current working state of the equipment , Whenever the state of the equipment changes , The device will modify the corresponding status register bits . By constantly querying the device's status register ,CPU You can know the status of the equipment , So as to carry out necessary I/O operation . In order to save CPU resources , Queries are often not continuous , But on a regular basis .
The polling method is simple 、 Easy to implement 、 Easy to control , There are a lot of applications in many small systems . Not very sensitive to those 、 Have a lot of CPU Resource system , Polling is widely used .
The disadvantages of the polling method :

  • Increase system overhead . Both task polling and timer polling need to consume corresponding system resources .
  • Unable to sense the change of equipment status in time . Changes in the state of the device within the polling interval can only be detected at the next poll , This will not meet the real-time sensitive application market .
  • waste CPU resources . Whether the state of the equipment changes or not , Polling is always on , In practice , The state of most devices usually changes less frequently , Polling will be wasted CPU Time slice .

The difference between interrupt and polling

  • Idling loss exists in polling mode , It is controllable and real-time . Consume a lot cpu The processing time of , Periodically and continuously detect the occurrence of external events .
  • The high priority and fast response requirements of interrupts will cause... Under extreme conditions “ Live lock ” effect . Various I / O devices operate in parallel through interrupt processing , Increase the number of interrupts , Can cause CPU Unable to respond to interrupt ; If an interrupt occurs after the buffer is full of data . So in the process of data transmission , There is more chance of interruption , Will consume a lot of CPU The processing time .
  • Interruption is not a protocol , It's a hardware mechanism ; Polling is the opposite .
  • The processor checks the interrupt register every instruction cycle , If the interrupt register is valid , That is, there is an interruption , that cpu Will perform a series of interrupt related operations . That is to say, interruption is also necessary CPU check. Interrupt and polling are not the exact opposite .
原网站

版权声明
本文为[Little monster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231256365999.html

随机推荐