{"id":412,"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:25:59","modified_gmt":"2020-08-22T20:25:59","slug":"this-is-the-page-title-toplevel-245","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=412","title":{"rendered":"Bottom Half Handling"},"content":{"rendered":"\n<title>Bottom Half Handling<\/title>\n<img decoding=\"async\" src=\"bh.gif\"><br \/>\nFigure: Bottom Half Handling Data Structures<\/center>\n<p>\nThere are often times when you don&#8217;t want the <glossary>kernel<\/glossary> to do any work at all.\nA good example of this is during <glossary>interrupt<\/glossary> processing.\nWhen the interrupt was asserted, the processor stopped what it was doing\nand the operating system delivered the <glossary>interrupt<\/glossary> to the appropriate\ndevice driver.\nDevice drivers should not spend too much time handling interrupts as, during\nthis time, nothing else in the system can run.\nThere is often some work that could just as well be done later on.\nLinux&#8217;s bottom half handlers were invented so that <glossary>device driver<\/glossary>s and\nother parts of the Linux <glossary>kernel<\/glossary> could queue work to be done later on.\nThe figure above shows the kernel data structures associated with bottom\nhalf handling.\n<p>\nThere can be up to 32 different bottom half handlers, which are referenced\nthrough a vector of pointers called bh_base.  These pointers point to each of\nthe kernel&#8217;s bottom half handling routines.\nbh_active and bh_mask have their bits set according to what handlers have been installed and are\nactive. If bit N of bh_mask is set then the Nth element of bh_base contains the address of a bottom\nhalf routine. If bit N of bh_active is set then the Nth bottom half handler routine\nshould be called as soon as the scheduler deems reasonable.\nThese indices are statically defined. The timer bottom half handler (index 0)\nis the highest priority, the console bottom half handler (index 1) is next in\npriority and so on. Typically the bottom half handling routines have lists of\ntasks associated with them. For example, the <em>immediate<\/em> bottom half handler works its way\nthrough the immediate tasks <glossary>queue<\/glossary> (tq_immediate), which contains tasks that need\nto be performed immediately.\n<\/p>\n<p>\nSome of the <glossary>kernel<\/glossary>&#8216;s bottom half handers are device specific, but\nothers are more generic:\n<dl compact>\n<p>\n\t<dt><b>TIMER<\/b><\/dt><dd> This handler is marked as active each time the system&#8217;s\n        periodic timer interrupts and is used to drive the <glossary>kernel<\/glossary>&#8216;s\n        timer <glossary>queue<\/glossary> mechanisms,\n\t<dt><b>CONSOLE<\/b><\/dt><dd> This handler is used to process console messages,\n\t<dt><b>TQUEUE<\/b><\/dt><dd> This handler is used to process tty messages,\n\t<dt><b>NET<\/b><\/dt><dd> This handler handles general network processing,\n\t<dt><b>IMMEDIATE<\/b><\/dt><dd> This is a generic handler used by several device drivers\n\t\tto <glossary>queue<\/glossary> work to be done later.\n<\/dl>\n<p>\nWhenever a <glossary>device driver<\/glossary>, or some other part of the kernel, needs to\nschedule work to be done later, it adds work to the appropriate system <glossary>queue<\/glossary>, for example\nthe timer <glossary>queue<\/glossary>, and then signals the kernel that some bottom half handling needs to be\ndone.\nIt does this by setting the appropriate bit in bh_active.\nBit 8 is set if the driver has queued something on the immediate queue and wishes the\nimmediate bottom half handler to run and process it.\nThe bh_active bitmask is checked at the end of each system call, just before\ncontrol is returned to the calling process.\nIf it has any bits set, the bottom half handler routines that are active are called.\nBit 0 is checked first, then 1 and so on until bit 31.\n<p>\nThe bit in bh_active is cleared as each bottom half handling routine\nis called.\nbh_active  is transient; it only has meaning between calls to the scheduler and\nis a way of not calling bottom half handling routines when there is no work for them to\ndo.\n","protected":false},"excerpt":{"rendered":"<p>Bottom Half Handling Figure: Bottom Half Handling Data Structures There are often times when you don&#8217;t want the kernel to do any work at all. A good example of this is during interrupt processing. When the interrupt was asserted, the &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=412\">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-412","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/412","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=412"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/412\/revisions"}],"predecessor-version":[{"id":510,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/412\/revisions\/510"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}