{"id":418,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:18","modified_gmt":"2020-08-22T20:26:18","slug":"this-is-the-page-title-toplevel-251","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=418","title":{"rendered":"Polling and Interrupts"},"content":{"rendered":"\n<title>Polling and Interrupts<\/title>\n<p>\nEach time the device is given a command, for example <em>&#8220;move the read head to\nsector 42 of the floppy disk&#8221;<\/em> the device driver has a choice as to how it finds\nout that the command has completed. The <glossary>device driver<\/glossary>s can either\npoll the device or they can use interrupts.\n<p>\nPolling the device usually means reading its status register every so often\nuntil the device&#8217;s status changes to indicate that it has completed the request.\nAs a device driver is part of the <glossary>kernel<\/glossary> it would be disasterous if a\ndriver were to poll, since nothing else in the kernel would run until the device had completed\nthe request. Instead polling <glossary>device driver<\/glossary>s use system timers to have\nthe kernel call a routine within the <glossary>device driver<\/glossary> at some later time.\nThis timer routine would check the status of the command and this is exactly how\nLinux&#8217;s floppy driver works.\nPolling by means of timers is at best approximate, a much more efficient method\nis to use interrupts.\n<p>\nAn interrupt driven <glossary>device driver<\/glossary> is one where the hardware device\nbeing controlled will raise a hardware interrupt whenever it needs to be serviced.\nFor example, an <glossary>ethernet<\/glossary>\n<glossary>device driver<\/glossary> would interrupt whenever it receives an ethernet packet\nfrom the network.\nThe Linux <glossary>kernel<\/glossary> needs to be able to deliver the interrupt from the hardware\ndevice to the correct device driver.\nThis is achieved by the device driver registering its usage of the interrupt\nwith the <glossary>kernel<\/glossary>.\nIt registers the address of an <glossary>interrupt<\/glossary> handling routine and the interrupt\nnumber that it wishes to own.\nYou can see which interrupts are being used by the device drivers, as well\nas how many of each type of interrupts there have been, by looking at\n\/proc\/interrupts:\n<pre>\n 0:     727432   timer\n 1:      20534   keyboard\n 2:          0   cascade\n 3:      79691 + serial\n 4:      28258 + serial\n 5:          1   sound blaster\n11:      20868 + aic7xxx\n13:          1   math error\n14:        247 + ide0\n15:        170 + ide1\n<\/pre>\n<p>\nThis requesting of <glossary>interrupt<\/glossary> resources is done at driver initialization time.\nSome of the interrupts in the system are fixed, this is a legacy of the IBM PC&#8217;s\narchitecture.\nSo, for example, the floppy disk controller always uses interrupt 6.\nOther interrupts, for example the interrupts from <glossary>PCI<\/glossary> devices are dynamically\nallocated at boot time.\nIn this case the <glossary>device driver<\/glossary> must first discover the <glossary>interrupt<\/glossary> number (IRQ) of\nthe device that it is controlling before it requests ownership of that\ninterrupt. For <glossary>PCI<\/glossary> interrupts Linux supports standard PCI BIOS callbacks to determine\ninformation about the devices in the system, including their IRQ numbers.\n<p>\nHow an interrupt is delivered to the <glossary>CPU<\/glossary> itself is architecture\ndependent but on most architectures the <glossary>interrupt<\/glossary> is delivered in\na special mode that stops other interrupts from happening in the system. A\n<glossary>device driver<\/glossary> should do as little as possible in its <glossary>interrupt<\/glossary>\nhandling routine so that the Linux kernel can dismiss the <glossary>interrupt<\/glossary> and\nreturn to what it was doing before it was <glossary>interrupted<\/glossary>.\nDevice drivers that need to do a lot of work as a result of receiving an interrupt\ncan use the <glossary>kernel<\/glossary>&#8216;s bottom half handlers or task queues to queue\nroutines to be called later on. Details of bottom half handlers can be found\n<site id=\"263\">here<\/site>.\n<p>\nInterrupts are not the only way the executing of a program can be stopped. This can aslo\noccur as the result of exceptions and traps. Details can be found <site id=\"86\">here<\/site>.\n<p>\n","protected":false},"excerpt":{"rendered":"<p>Polling and Interrupts Each time the device is given a command, for example &#8220;move the read head to sector 42 of the floppy disk&#8221; the device driver has a choice as to how it finds out that the command has &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=418\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-418","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=418"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/418\/revisions"}],"predecessor-version":[{"id":659,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/418\/revisions\/659"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}