Knowledge

Interrupt handler

Source đź“ť

251:(MMU). In these chips, the execution context of an interrupt handler will be essentially the same as the interrupted program, which typically runs on a small stack of fixed size (memory resources have traditionally been extremely scant at the low end). Nested interrupts are often provided, which exacerbates stack usage. A primary constraint on the interrupt handler in this programming endeavour is to not exceed the available stack in the worst-case condition, requiring the programmer to reason globally about the stack space requirement of every implemented interrupt handler and application task. 398:, since they must maintain a guarantee that execution of specific code will complete within an agreed amount of time. To reduce jitter and to reduce the potential for losing data from masked interrupts, programmers attempt to minimize the execution time of a FLIH, moving as much as possible to the SLIH. With the speed of modern computers, FLIHs may implement all device and platform-dependent handling, and use a SLIH for further platform-independent long-lived handling. 173:, are usually dispatched via a hard-coded table of interrupt vectors, asynchronously to the normal execution stream (as interrupt masking levels permit), often using a separate stack, and automatically entering into a different execution context (privilege level) for the duration of the interrupt handler's execution. In general, hardware interrupts and their handlers are used to handle high-priority conditions that require the interruption of the current code the 258:), this is not normally detected in hardware by chips of this class. If the stack is exceeded into another writable memory area, the handler will typically work as expected, but the application will fail later (sometimes much later) due to the handler's side effect of memory corruption. If the stack is exceeded into a non-writable (or protected) memory area, the failure will usually occur inside the handler itself (generally the easier case to later debug). 36: 223:
first opportunity, to permit higher priority interrupts to interrupt the current handler. It is also important for the interrupt handler to quell the current interrupt source by some method (often toggling a flag bit of some kind in a peripheral register) so that the current interrupt isn't immediately repeated on handler exit, resulting in an infinite loop.
308:
a full receive buffer) and then marks the back-half (or second level) for execution in the near future at the appropriate scheduling priority; once invoked, the back-half operates in its own process context with fewer restrictions and completes the handler's logical operation (such as conveying the newly received data to an operating system data queue).
207:. However, interrupt handlers have an unusual execution context, many harsh constraints in time and space, and their intrinsically asynchronous nature makes them notoriously difficult to debug by standard practice (reproducible test cases generally don't exist), thus demanding a specialized skillset—an important subset of 227:
mishandled edge case not occurring for weeks or months of continuous operation. Formal validation of interrupt handlers is tremendously difficult, while testing typically identifies only the most frequent failure modes, thus subtle, intermittent bugs in interrupt handlers often ship to end customers.
226:
Exiting an interrupt handler with the interrupt system in exactly the right state under every eventuality can sometimes be an arduous and exacting task, and its mishandling is the source of many serious bugs, of the kind that halt the system completely. These bugs are sometimes intermittent, with the
307:
A modern practice has evolved to divide hardware interrupt handlers into front-half and back-half elements. The front-half (or first level) receives the initial interrupt in the context of the running process, does the minimal work to restore the hardware to a less urgent condition (such as emptying
238:
For reasons of performance, the handler will typically be initiated in the memory and execution context of the running process, to which it has no special connection (the interrupt is essentially usurping the running context—process time accounting will often accrue time spent handling interrupts to
222:
Even in a CPU which supports nested interrupts, a handler is often reached with all interrupts globally masked by a CPU hardware operation. In this architecture, an interrupt handler would normally save the smallest amount of context necessary, and then reset the global interrupt disable flag at the
270:
configured such that stack overflow is trapped by the MMU, either as a system error (for debugging) or to remap memory to extend the space available. Memory resources at this level of microcontroller are typically far less constrained, so that stacks can be allocated with a generous safety margin.
269:
In a multitasking system, each thread of execution will typically have its own stack. If no special system stack is provided for interrupts, interrupts will consume stack space from whatever thread of execution is interrupted. These designs usually contain an MMU, and the user stacks are usually
265:
be overwritten, but never will be if the system operates correctly. It is common to regularly observe corruption of the stack guard with some kind of watch dog mechanism. This will catch the majority of stack overflow conditions at a point in time close to the offending operation.
180:
Later it was found convenient for software to be able to trigger the same mechanism by means of a software interrupt (a form of synchronous interrupt). Rather than using a hard-coded interrupt dispatch table at the hardware level, software interrupts are often implemented at the
286:
For many reasons, it is highly desired that the interrupt handler execute as briefly as possible, and it is highly discouraged (or forbidden) for a hardware interrupt to invoke potentially blocking system calls. In a system with multiple execution cores, considerations of
273:
In systems supporting high thread counts, it is better if the hardware interrupt mechanism switches the stack to a special system stack, so that none of the thread stacks need account for worst-case nested interrupt usage. Tiny CPUs as far back as the 8-bit
299:
issues can arise even with only a single CPU core. (It is not uncommon for a mid-tier microcontroller to lack protection levels and an MMU, but still provide a DMA engine with many channels; in this scenario, many interrupts are typically
401:
FLIHs which service hardware typically mask their associated interrupt (or keep it masked as the case may be) until they complete their execution. An (unusual) FLIH which unmasks its associated interrupt before it completes is called a
383:, and the code for the interrupt is loaded and executed. The job of a FLIH is to quickly service the interrupt, or to record platform-specific critical information which is only available at the time of the interrupt, and 433:
in the operating system until processor time is available for them to perform processing for the interrupt. SLIHs may have a long-lived execution time, and thus are typically scheduled similarly to threads and processes.
239:
the interrupted process). However, unlike the interrupted process, the interrupt is usually elevated by a hard-coded CPU mechanism to a privilege level high enough to access hardware resources directly.
192:
Interrupt handlers have a multitude of functions, which vary based on what triggered the interrupt and the speed at which the interrupt handler completes its task. For example, pressing a key on a
169:
The traditional form of interrupt handler is the hardware interrupt handler. Hardware interrupts arise from electrical conditions or low-level protocols implemented in
200:, triggers interrupts that call interrupt handlers which read the key, or the mouse's position, and copy the associated information into the computer's memory. 666: 219:
Unlike other event handlers, interrupt handlers are expected to set interrupt flags to appropriate values as part of their core functionality.
613: 468: 261:
In the writable case, one can implement a sentinel stack guard—a fixed value right beyond the end of the legal stack whose value
100: 72: 942: 913: 403: 79: 53: 17: 501: 119: 717: 661: 86: 636: 606: 537: 186: 154:
condition. Interrupt handlers are initiated by hardware interrupts, software interrupt instructions, or software
829: 727: 296: 57: 68: 1107: 656: 641: 485: 340:
and some other operating systems used in the past‍—‌interrupt handlers are divided into two parts: the
702: 687: 646: 235:
In a modern operating system, upon entry the execution context of a hardware interrupt handler is subtle.
868: 815: 883: 722: 599: 425:
A SLIH completes long interrupt processing tasks similarly to a process. SLIHs either have a dedicated
395: 918: 737: 697: 692: 651: 474: 426: 429:
thread for each handler, or are executed by a pool of kernel worker threads. These threads sit on a
961: 848: 712: 419: 707: 369: 174: 46: 304:
by the DMA engine itself, and the associated interrupt handler is expected to tread carefully.)
1095: 1034: 923: 903: 852: 810: 495: 463: 415: 411: 384: 288: 248: 93: 878: 844: 746: 682: 394:
in process execution. FLIHs also mask interrupts. Reducing the jitter is most important for
1133: 1075: 1049: 507: 449:. This is different from naming used in other Unix-like systems, where both are a part of 292: 8: 1128: 1044: 996: 873: 135: 981: 888: 208: 155: 1090: 1039: 971: 928: 769: 574: 480: 329: 193: 533: 422:
system, the FLIH also (briefly) masks other interrupts of equal or lesser priority.
1070: 622: 182: 565: 1014: 976: 947: 247:
In a low-level microcontroller, the chip might lack protection modes and have no
1100: 1024: 986: 858: 490: 407: 380: 255: 197: 1122: 1009: 966: 805: 759: 375:
A FLIH implements at minimum platform-specific interrupt handling similar to
275: 204: 170: 159: 893: 567: 566:
Jonathan Corbet; Alessandro Rubini; Greg Kroah-Hartman (January 27, 2005).
534:"The Linux Kernel Module Programming Guide, Chapter 12. Interrupt Handlers" 1019: 1001: 784: 774: 764: 163: 956: 863: 789: 754: 430: 151: 591: 35: 1085: 387:
the execution of a SLIH for further long-lived interrupt handling.
337: 211:—of software engineers who engage at the hardware interrupt layer. 1080: 779: 278:
from 1978 have provided separate system and user stack pointers.
391: 311: 254:
When allocated stack space is exceeded (a condition known as a
1029: 325: 317: 162:
or transitions between protected modes of operation, such as
333: 321: 1065: 291:
are also paramount. If the system provides for hardware
150:, is a special block of code associated with a specific 568:"Linux Device Drivers, Chapter 10. Interrupt Handling" 281: 203:An interrupt handler is a low-level counterpart of 60:. Unsourced material may be challenged and removed. 1120: 27:Computer systems programming special block code 607: 406:. Reentrant interrupt handlers might cause a 242: 528: 526: 524: 312:Divided handlers in modern operating systems 614: 600: 561: 559: 557: 555: 469:Advanced Programmable Interrupt Controller 379:. In response to an interrupt, there is a 521: 418:, and so they are usually avoided. In a 120:Learn how and when to remove this message 552: 14: 1121: 621: 595: 316:In several operating systems‍—‌ 230: 58:adding citations to reliable sources 29: 282:Constraints in time and concurrency 24: 214: 25: 1145: 502:Programmable Interrupt Controller 718:Object-oriented operating system 158:, and are used for implementing 34: 538:The Linux Documentation Project 350:Second-Level Interrupt Handlers 45:needs additional citations for 728:Supercomputer operating system 364:, and SLIHs are also known as 13: 1: 514: 486:Interrupts in 65xx processors 342:First-Level Interrupt Handler 703:Just enough operating system 688:Distributed operating system 366:slow/soft interrupt handlers 7: 816:User space and kernel space 456: 437:In Linux, FLIHs are called 404:reentrant interrupt handler 396:real-time operating systems 356:). FLIHs are also known as 10: 1150: 723:Real-time operating system 243:Stack space considerations 1058: 995: 941: 919:Multilevel feedback queue 914:Fixed-priority preemptive 902: 837: 828: 798: 745: 736: 698:Hobbyist operating system 693:Embedded operating system 675: 629: 475:Inter-processor interrupt 144:interrupt service routine 962:General protection fault 713:Network operating system 667:User features comparison 370:Deferred Procedure Calls 708:Mobile operating system 441:, and SLIHs are called 362:fast interrupt handlers 358:hard interrupt handlers 811:Loadable kernel module 496:Non-maskable interrupt 464:Interrupt vector table 249:memory management unit 879:Process control block 845:Computer multitasking 683:Disk operating system 1050:Virtual tape library 642:Forensic engineering 54:improve this article 1059:Supporting concepts 1045:Virtual file system 185:level as a form of 142:, also known as an 136:systems programming 69:"Interrupt handler" 982:Segmentation fault 830:Process management 420:priority interrupt 377:interrupt routines 209:system programming 18:Interrupt routines 1116: 1115: 972:Memory protection 943:Memory management 937: 936: 929:Shortest job next 824: 823: 623:Operating systems 481:Interrupt latency 330:Microsoft Windows 231:Execution context 194:computer keyboard 187:callback function 140:interrupt handler 130: 129: 122: 104: 16:(Redirected from 1141: 1071:Computer network 835: 834: 743: 742: 616: 609: 602: 593: 592: 586: 585: 583: 581: 572: 563: 550: 549: 547: 545: 530: 416:interrupt vector 196:, or moving the 183:operating system 125: 118: 114: 111: 105: 103: 62: 38: 30: 21: 1149: 1148: 1144: 1143: 1142: 1140: 1139: 1138: 1119: 1118: 1117: 1112: 1054: 1015:Defragmentation 1000: 991: 977:Protection ring 946: 933: 905: 898: 820: 794: 732: 671: 625: 620: 590: 589: 579: 577: 570: 564: 553: 543: 541: 532: 531: 522: 517: 512: 459: 314: 284: 245: 233: 217: 215:Interrupt flags 126: 115: 109: 106: 63: 61: 51: 39: 28: 23: 22: 15: 12: 11: 5: 1147: 1137: 1136: 1131: 1114: 1113: 1111: 1110: 1105: 1104: 1103: 1101:User interface 1098: 1088: 1083: 1078: 1073: 1068: 1062: 1060: 1056: 1055: 1053: 1052: 1047: 1042: 1037: 1032: 1027: 1025:File attribute 1022: 1017: 1012: 1006: 1004: 993: 992: 990: 989: 987:Virtual memory 984: 979: 974: 969: 964: 959: 953: 951: 939: 938: 935: 934: 932: 931: 926: 921: 916: 910: 908: 900: 899: 897: 896: 891: 886: 881: 876: 871: 866: 861: 859:Context switch 856: 841: 839: 832: 826: 825: 822: 821: 819: 818: 813: 808: 802: 800: 796: 795: 793: 792: 787: 782: 777: 772: 767: 762: 757: 751: 749: 740: 734: 733: 731: 730: 725: 720: 715: 710: 705: 700: 695: 690: 685: 679: 677: 673: 672: 670: 669: 664: 659: 654: 649: 644: 639: 633: 631: 627: 626: 619: 618: 611: 604: 596: 588: 587: 575:O'Reilly Media 551: 540:. May 18, 2007 519: 518: 516: 513: 511: 510: 505: 499: 493: 491:IRQL (Windows) 488: 483: 478: 472: 466: 460: 458: 455: 410:from multiple 408:stack overflow 381:context switch 313: 310: 283: 280: 256:stack overflow 244: 241: 232: 229: 216: 213: 205:event handlers 177:is executing. 160:device drivers 128: 127: 42: 40: 33: 26: 9: 6: 4: 3: 2: 1146: 1135: 1132: 1130: 1127: 1126: 1124: 1109: 1106: 1102: 1099: 1097: 1094: 1093: 1092: 1089: 1087: 1084: 1082: 1079: 1077: 1074: 1072: 1069: 1067: 1064: 1063: 1061: 1057: 1051: 1048: 1046: 1043: 1041: 1038: 1036: 1033: 1031: 1028: 1026: 1023: 1021: 1018: 1016: 1013: 1011: 1008: 1007: 1005: 1003: 998: 994: 988: 985: 983: 980: 978: 975: 973: 970: 968: 967:Memory paging 965: 963: 960: 958: 955: 954: 952: 949: 944: 940: 930: 927: 925: 922: 920: 917: 915: 912: 911: 909: 907: 901: 895: 892: 890: 887: 885: 882: 880: 877: 875: 872: 870: 867: 865: 862: 860: 857: 854: 850: 846: 843: 842: 840: 836: 833: 831: 827: 817: 814: 812: 809: 807: 806:Device driver 804: 803: 801: 797: 791: 788: 786: 783: 781: 778: 776: 773: 771: 768: 766: 763: 761: 758: 756: 753: 752: 750: 748: 747:Architectures 744: 741: 739: 735: 729: 726: 724: 721: 719: 716: 714: 711: 709: 706: 704: 701: 699: 696: 694: 691: 689: 686: 684: 681: 680: 678: 674: 668: 665: 663: 660: 658: 655: 653: 650: 648: 645: 643: 640: 638: 635: 634: 632: 628: 624: 617: 612: 610: 605: 603: 598: 597: 594: 576: 569: 562: 560: 558: 556: 539: 535: 529: 527: 525: 520: 509: 506: 503: 500: 497: 494: 492: 489: 487: 484: 482: 479: 476: 473: 470: 467: 465: 462: 461: 454: 452: 448: 444: 440: 435: 432: 428: 423: 421: 417: 413: 409: 405: 399: 397: 393: 388: 386: 382: 378: 373: 371: 367: 363: 359: 355: 351: 347: 343: 339: 335: 331: 327: 323: 319: 309: 305: 303: 298: 294: 290: 279: 277: 276:Motorola 6809 271: 267: 264: 259: 257: 252: 250: 240: 236: 228: 224: 220: 212: 210: 206: 201: 199: 195: 190: 188: 184: 178: 176: 172: 171:digital logic 167: 165: 161: 157: 153: 149: 145: 141: 137: 132: 124: 121: 113: 110:February 2015 102: 99: 95: 92: 88: 85: 81: 78: 74: 71: â€“  70: 66: 65:Find sources: 59: 55: 49: 48: 43:This article 41: 37: 32: 31: 19: 1002:file systems 894:Time-sharing 580:February 20, 578:. Retrieved 544:February 20, 542:. Retrieved 450: 446: 442: 438: 436: 424: 414:by the same 400: 390:FLIHs cause 389: 376: 374: 372:in Windows. 365: 361: 357: 353: 349: 345: 341: 315: 306: 301: 285: 272: 268: 262: 260: 253: 246: 237: 234: 225: 221: 218: 202: 191: 179: 168: 164:system calls 147: 143: 139: 134:In computer 133: 131: 116: 107: 97: 90: 83: 76: 64: 52:Please help 47:verification 44: 1134:Subroutines 1020:Device file 1010:Boot loader 924:Round-robin 849:Cooperative 785:Rump kernel 775:Multikernel 765:Microkernel 662:Usage share 451:bottom half 447:bottom half 412:preemptions 297:concurrency 1129:Interrupts 1123:Categories 950:protection 906:algorithms 904:Scheduling 853:Preemptive 799:Components 770:Monolithic 637:Comparison 515:References 443:lower half 439:upper half 348:) and the 289:reentrancy 156:exceptions 80:newspapers 1040:Partition 957:Bus error 884:Real-time 864:Interrupt 790:Unikernel 755:Exokernel 431:run queue 302:triggered 175:processor 152:interrupt 1086:Live USB 948:resource 838:Concepts 676:Variants 657:Timeline 508:Red zone 457:See also 385:schedule 338:DESQview 1081:Live CD 1035:Journal 999:access, 997:Storage 874:Process 780:vkernel 647:History 630:General 94:scholar 889:Thread 760:Hybrid 738:Kernel 471:(APIC) 427:kernel 392:jitter 96:  89:  82:  75:  67:  1091:Shell 1030:Inode 571:(PDF) 504:(PIC) 498:(NMI) 477:(IPI) 368:, or 326:macOS 318:Linux 198:mouse 138:, an 101:JSTOR 87:books 652:List 582:2015 546:2015 354:SLIH 346:FLIH 334:z/OS 322:Unix 73:news 1108:PXE 1096:CLI 1076:HAL 1066:API 869:IPC 445:or 360:or 293:DMA 263:can 148:ISR 146:or 56:by 1125:: 851:, 573:. 554:^ 536:. 523:^ 453:. 336:, 332:, 328:, 324:, 320:, 295:, 189:. 166:. 945:, 855:) 847:( 615:e 608:t 601:v 584:. 548:. 352:( 344:( 123:) 117:( 112:) 108:( 98:· 91:· 84:· 77:· 50:. 20:)

Index

Interrupt routines

verification
improve this article
adding citations to reliable sources
"Interrupt handler"
news
newspapers
books
scholar
JSTOR
Learn how and when to remove this message
systems programming
interrupt
exceptions
device drivers
system calls
digital logic
processor
operating system
callback function
computer keyboard
mouse
event handlers
system programming
memory management unit
stack overflow
Motorola 6809
reentrancy
DMA

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑