{"id":4184,"date":"2022-12-20T17:39:39","date_gmt":"2022-12-20T20:39:39","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/init_bh-man9\/"},"modified":"2022-12-20T17:39:39","modified_gmt":"2022-12-20T20:39:39","slug":"init_bh-man9","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/init_bh-man9\/","title":{"rendered":"INIT_BH (man9)"},"content":{"rendered":"<h1 align=\"center\">INIT_BH<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#AVAILABILITY\">AVAILABILITY<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#BUGS\">BUGS<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">init_bh, remove_bh, mark_bh, disable_bh, enable_bh \u2212 split-half interrupt handling<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <linux\/interrupt.h><\/b><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"67%\">\n<p style=\"margin-top: 1em\"><b>void\u00a0init_bh(int<\/b> <i>nr<\/i><b>, void\u00a0(*<\/b><i>routine<\/i><b>)(void));<\/b><\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"67%\">\n<p style=\"margin-top: 1em\"><b>void\u00a0remove_bh(int\u00a0<\/b><i>nr<\/i><b>);<\/b><\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"67%\">\n<p style=\"margin-top: 1em\"><b>void\u00a0mark_bh(int\u00a0<\/b><i>nr<\/i><b>);<\/b><\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"67%\">\n<p style=\"margin-top: 1em\"><b>void\u00a0disable_bh(int\u00a0<\/b><i>nr<\/i><b>);<\/b><\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"67%\">\n<p style=\"margin-top: 1em\"><b>void\u00a0enable_bh(int\u00a0<\/b><i>nr<\/i><b>);<\/b><\/p>\n<\/td>\n<td width=\"22%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Theory<\/b> <br \/> Split-half handling is a means of dividing an interrupt handler into two sections, one of which (known as the \u2018top half\u2019) is time-critical and one of which (the \u2018bottom half\u2019) is not.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The top half (the handler registered with <b>request_irq<\/b>(9)) normally moves data between the device and a memory buffer, ensures that the device is in a sane state, and little else. While the top half of a handler is running, the IRQ is question is blocked; if it is a fast interrupt handler (i.e., it has <b>SA_INTERRUPT<\/b> set), all interrupts are disabled.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The bottom half does whatever remains to be done. Bottom halves run with interrupts enabled, although a locking mechanism ensures that only one bottom half will be running at a given time. Bottom halves are run by <b>do_bottom_half()<\/b>, which is called from <b>schedule()<\/b> and <b>ret_from_sys_call()<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Usage <br \/> init_bh()<\/b> installs <i>routine()<\/i> as bottom half number <i>nr<\/i>. It operates by adding an entry to the <b>bh_base[]<\/b> table, and setting the appropriate bit of the <b>bh_mask<\/b> vector. Rather than specifying a number explicitly, one should add an entry to the anonymous enum in <i>include\/linux\/interrupt.h<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>remove_bh()<\/b> removes bottom half number <i>nr<\/i> from the list of bottom halves. It removes the entry from <b>bh_base[]<\/b> and clears the appropriate bit of <b>bh_mask<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>mark_bh()<\/b> requests that the kernel run the specified bottom half at the first available opportunity. This function is normally called from the top half of an interrupt handler. It operates by setting the appropriate bit of the <b>bh_active<\/b> vector.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>disable_bh()<\/b> disables bottom half number <i>nr<\/i> by clearing the appropriate bit of <b>bh_mask<\/b>. This function also increments <b>bh_mask_count[<\/b><i>nr<\/i><b>]<\/b>, which is used to ensure that nested calls to <b>disable_bh()<\/b> must be matched by an equal number of calls to <b>enable_bh()<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>enable_bh()<\/b> enables a bottom half previously disabled by <b>disable_bh()<\/b>. This function decrements <b>bh_mask_count[<\/b><i>nr<\/i><b>]<\/b>. Then, if that value is zero, the specified bottom half is enabled by setting the appropriate bit of <b>bh_mask<\/b>.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">No value is returned.<\/p>\n<h2>AVAILABILITY <a name=\"AVAILABILITY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Linux 2.0+. <b>init_bh()<\/b> and <b>remove_bh()<\/b> were not present in older versions on Linux. Under those versions, <b>bh_base[]<\/b> and <b>bh_mask<\/b> must be modified by hand.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>request_irq<\/b>(9), <b>queue_task<\/b>(9)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>include\/asm*\/softirq.h<\/i>, <i>include\/linux\/interrupt.h<\/i>, <i>kernel\/softirq.c<\/i><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">\u201cKernel Korner\u201d in issue 26 of <i>The Linux Journal<\/i> includes a discussion of split-half interrupts under Linux. An online copy of this article can be found at <b>http:\/\/www.ssc.com\/lj\/issue26\/interrupt.html<\/b>.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Neil Moore <<i>amethyst@maxwell.ml.org<\/i>><\/p>\n<h2>BUGS <a name=\"BUGS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Only 32 bottom halves are allowed. Increasing this number requires changing the size of <b>bh_base[]<\/b> and <b>bh_mask_count[]<\/b> in <i>kernel\/softirq.c,<\/i> and changing <b>bh_active<\/b> and <b>bh_mask<\/b> (in the same file) to a larger type. A better solution, however, would be to consolidate multiple bottom halves into a single one by using task queues. See <b>queue_task<\/b>(9) for details.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  init_bh, remove_bh, mark_bh, disable_bh, enable_bh \u2212 split-half interrupt handling <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1222],"tags":[1226,1264,1223,1225],"class_list":["post-4184","post","type-post","status-publish","format-standard","hentry","category-9-rutinas-del-nucleo","tag-1226","tag-init_bh","tag-kernel","tag-man9"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4184"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4184\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}