{"id":196,"date":"2010-04-18T00:26:59","date_gmt":"2010-04-18T09:26:59","guid":{"rendered":"\/blog\/?p=196"},"modified":"2023-09-21T09:39:12","modified_gmt":"2023-09-21T00:39:12","slug":"ddk-using-rules-of-spinlock","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=196","title":{"rendered":"[DDK] Using rules of SpinLock"},"content":{"rendered":"\n\uc2a4\ud540 \ub77d\uc740 \ucc38 \uc624\ubb18\ud55c \ubb38\uc81c\uc774\ub2e4. \ud558\uc9c0\ub9cc \uc54c\uace0 \ubcf4\uba74 \uac04\ub2e8\ud55c \ub85c\uc9c1\uc73c\ub85c \ud574\uacb0\ud560 \uc218 \uc788\ub2e4!!<br \/><br \/>&nbsp;\uc77c\ub2e8 \ub3d9\uae30\ud654 \ubb38\uc81c\uc5d0 \uc9c1\uba74\ud558\uac8c \ub418\uba74, ( \uba40\ud2f0 \n\ud504\ub85c\uc138\uc11c ) <br \/><br \/>\uc6b0\ub9ac\uac00 \uc775\ud788 \uc54c\uace0 \uc788\ub294 \uc138\ub9c8\ud3ec\uc5b4(Semaphore)\uac19\uc740 \ubc29\ubc95\uc744 \uc0ac\uc6a9\ud574\uc11c \ub77d\ud0b9(Locking)\uc744 \n\ud574\uc57c\ud55c\ub2e4.<br \/><br \/>\uc774\uac83\uc744 \uc81c\ub300\ub85c \ud574\uc8fc\uc9c0 \uc54a\ub294\ub2e4\uba74 <font color=\"#ff0000\">\ub370\ub4dc\ub77d(DeadLock)<\/font>\uc5d0 \n\ube60\uc9c0\uac8c\ub41c\ub2e4.<br \/><br \/>&nbsp;\ub370\ub4dc\ub77d\uc740 \uc6b4\uc601\uccb4\uc81c\ub54c \ub4e4\uc5c8\uc744 \uac83\uc774\ub2e4.<br \/><br \/>\uc5ec\ub7ec \uc2a4\ub808\ub4dc\uac00 \uc784\uacc4\uc601\uc5ed(Critical Section)\uc5d0 \ub4e4\uc5b4\uac00\uae30 \n\uc704\ud574\uc11c,<br \/><br \/>\uacbd\uc7c1\uc744 \ud560 \uac83\uc774\ub2e4. <br \/><br \/>&nbsp;\ud558\ub098\uc758 \uc2a4\ub808\ub4dc\uac00 \uc2a4\ud540\ub77d\uc744 \uc0ac\uc6a9\ud558\uace0 \uc788\uc744 \uacbd\uc6b0 \uc2a4\ud540 \ub77d\uc744 \uc0ac\uc6a9\ud558\uace0\uc790 \ud558\ub294 \ub2e4\ub978 \uc2a4\ub808\ub4dc\uac00 \n<br \/><br \/>\uc2a4\ud540 \ub77d\uc744 \uc0ac\uc6a9\ud558\uae30 \uc704\ud574 \uc2a4\ud540 \ub77d\uc744 \uc18c\uc720\ud558\uace0 \uc788\ub294 \uc2a4\ub808\ub4dc\uac00 \ud574\uc81c\ud560 \ub54c\uae4c\uc9c0 \uc5b4\ub5a4 \ub3d9\uc791\ub3c4 \uc2e4\ud589\ud558\uc9c0 \uc54a\ub294 \uac83\uc744<br \/><br \/><font color=\"#ff0000\">\ube44\uc9c0 \uc6e8\uc774\ud305(Busy-Waiting)<\/font> \uc0c1\ud0dc\ub77c \ud55c\ub2e4.<br \/><br \/>&nbsp;\ub124\ud2b8\uc6cc\ud06c\uc5d0\uc11c Selecting \uc774\ub098 \nPolling \ubc29\uc2dd\ub3c4 Busywaiting\uc5d0 \uc18d\ud55c\ub2e4. while loop\uac00 Cpu\ub97c \uc810\uc720\ud558\uac8c \ub41c\ub2e4.<br \/><br \/>\ub098\uc911\uc5d0 \uc5b4\ud50c\ub9ac\ucf00\uc774\uc158\uacfc \ub4dc\ub77c\uc774\ubc84\uac00 \n\uc2dc\uadf8\ub110\uc744 \uc8fc\uace0 \ubc1b\uc744\ub54c, \ub2e4\uc2dc Busy waiting\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcfc \uac83\uc774\ub2e4.<br \/><br \/>&nbsp;\uc774\uc81c \uc815\ud655\ud55c \uc0ac\uc6a9 \uaddc\uce59\uc744 \uc54c\uc544 \n\ubcf4\uc790,!<br \/><br \/>&nbsp;\uc77c\ub2e8 \uc2a4\ud540 \ub77d\uc740 <font color=\"#0000ff\">\ubc18\ub4dc\uc2dc \ub514\uc2a4\ud328\uce58 \ub808\ubca8(DISPATCH_LEVEL)\uc774\ub098 \uadf8 \n\uc544\ub798(PASSIVE_LEVEL, APC_LEVEL)<br \/><br \/>\uc758 IRQL\uc5d0\uc11c\ub9cc \uc694\uccad<\/font>\ud560 \uc218 \uc788\ub2e4.<br \/><br \/>&nbsp;\ub2e4\uc74c\ubc88\uc5d0\ub294 \nIRQL\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcfc \uac83\uc778\ub370, \uc21c\uc11c\uac00 \ub4a4\ubc14\ub080 \uac10\ub3c4 \uc788\uae34\ud558\ub2e4,,;<br \/><br \/>&nbsp;\uadf8\ub9ac\uace0 \ubaa8\ub4e0 \uc2a4\ud540 \ub77d\uc740 \uc790\uc2e0\uc758 IRQL\uc744 \uac00\uc9c0\uace0 \uc788\uace0, \uc774 \nIRQL\uc740 \uc801\uc5b4\ub3c4 \ub514\uc2a4\ud328\uce58 \ub808\ubca8\ubcf4\ub2e4 \ub192\uc9c0 \uc54a\uc544\uc57c \ud558\uae30 <br \/><br \/>\ub54c\ubb38\uc5d0 <font color=\"#ff0000\"><u>\ub514\uc2a4\ud328\uce58 \ub808\ubca8\uc774 \uc2a4\ud540 \ub77d\uc744 \n\uc5bb\uae30 \uc704\ud55c \uac00\uc7a5 \ub192\uc740 IRQL\uc5d0 \ud574\ub2f9<\/u><\/font>\ud55c\ub2e4.<br \/>&nbsp; <br \/>&nbsp;\uc774\ub54c \uadf8 IRQL\uc744 \ub192\uc5ec \uc8fc\ub294 \ubc29\ubc95\uc774 \uc788\uc744 \uc218\uac00 \uc788\ub2e4. \ub514\uc2a4\ud328\uce58 \n\ub808\ubca8\ub85c \uc62c\ub824\uc8fc\uba74\uc11c \uc2e4\ud589\ud560 \uc218 \ub3c4\uc788\ub294\ub370,<br \/>&nbsp;<br \/>KeAcquireInterruptSpinLock() \ud568\uc218\ub97c \uc0ac\uc6a9\ud574\uc11c IRQL\uc744 \uc99d\uac00 \uc2dc\ud0ac \n\uc218 \uc788\ub2e4.<br \/><br \/>\n<h1>KeAcquireInterruptSpinLock<\/h1>\n<p>The <b>KeAcquireInterruptSpinLock<\/b> routine acquires the spin lock \nassociated with an interrupt object.<\/p>\n<p style=\"padding: 2pt 4pt; background: rgb(221, 221, 221) none repeat scroll 0% 0%; font-family: Courier New,Courier,mono; font-style: normal; font-variant: normal; font-weight: normal; font-size: 100%; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; cursor: text;\" class=\"syntax\"><b>NTKERNELAPI<\/b><br \/><b>KIRQL<\/b><br \/><b>&nbsp; \nKeAcquireInterruptSpinLock (<\/b><br \/><b>&nbsp; &nbsp; IN PKINTERRUPT &nbsp;<\/b><i><a class=\"con_link\" href=\"\" target=\"_blank\" rel=\"noopener\">Interrupt<\/a><\/i><br \/><b>&nbsp; &nbsp; );<\/b><br \/><\/p>\n<h4>Comments<\/h4>\n<p>Drivers use the interrupt spin lock to synchronize access to memory shared \nwith the interrupt's ISR. The driver can release the spin lock by calling <a class=\"con_link\" href=\"\/\/MS.WDK.v10.6001.071213\/Kernel_r\/hh\/Kernel_r\/k105_673f3ed1-bb95-413b-b56b-e9fdea636e8f.xml.htm\" target=\"_blank\" rel=\"noopener\"><b>KeReleaseInterruptSpinLock<\/b><\/a>.<\/p>\n<p>Any code that executes while the interrupt spin lock is held does so at IRQL \n= DIRQL for the specified <i>Interrupt<\/i>, so it must execute very quickly. For \nmore information, see <mshelp:link tabindex=\"0\" keywords=\"Intrupts_05e5aa40-da4e-424d-a4fd-d58ce00e2486.xml\"><u><font color=\"#0000ff\">Using Critical Sections<\/font><\/u><\/mshelp:link>. <\/p>\n<p>It is generally faster to use <a class=\"con_link\" href=\"\/\/MS.WDK.v10.6001.071213\/Kernel_r\/hh\/Kernel_r\/k105_2abf2438-6849-4069-8571-7d24d348056f.xml.htm\" target=\"_blank\" rel=\"noopener\"><b>KeSynchronizeExecution<\/b><\/a> to synchronize access than to \nuse <b>KeAcquireInterruptSpinLock<\/b> and <b>KeReleaseInterruptSpinLock<\/b>.<\/p>\n<p><font color=\"#ff0000\">Callers must be running at IRQL &lt;= DIRQL for \n<i>Interrupt<\/i>.<\/font> (This is the value the driver passed as the \n<i>SynchronizeIrql<\/i> parameter of <a class=\"con_link\" href=\"\/\/MS.WDK.v10.6001.071213\/Kernel_r\/hh\/Kernel_r\/k104_efa094e0-ac29-491b-803a-8470ed39c915.xml.htm\" target=\"_blank\" rel=\"noopener\"><b>IoConnectInterrupt<\/b><\/a> when <i>Interrupt<\/i> is \ncreated.)<\/p>\n<h4><b>Requirements<\/b><\/h4>\n<p><b>IRQL: <\/b>&lt;=DIRQL (see Comments section)<\/p>\n<p><b>Headers: <\/b>Declared in <i>wdm.h<\/i>. Include <i>wdm.h<\/i>, \n<i>ntddk.h,<\/i> or <i>ntifs.h<\/i>.<\/p>\n<p><br \/>&nbsp;IRQL\uc744 \uc99d\uac00 \uc2dc\ud0a4\ub294 \uc774\uc720\uc5d0 \ub300\ud574\uc11c\ub294 \ub2e4\uc74c\uc5d0 \uac19\uc774 \uc54c\uc544\ubcfc \uac83\uc774\ub2e4,<br \/><br \/>\uadf8\ub9ac\uace0 \uc2a4\ud540 \ub77d\uc744 \uc0ac\uc6a9\ud560 \ub54c\ub294 <font color=\"#ff0000\">\ud398\uc774\uc9d5\uc744 \ud558\uba74 \uc548\ub41c\ub2e4<\/font>, \ub514\uc2a4\ud328\uce58 \ub808\ubca8\uc5d0\uc11c \ud398\uc774\uc9d5\uc774 \ub41c\ub2e4\uba74, \uc624\ub958\ub97c \ubc1c\uc0dd<br \/><br \/>\uc2dc\ud0a4\uac8c \ub41c\ub2e4, \uadf8\ub9ac\uace0 \n\uc2a4\ud540 \ub77d \ucf54\ub4dc \ub0b4\uc5d0\uc11c \ub2e4\ub978 \ud568\uc218 \ud638\ucd9c\uc2dc\uc5d0 \uadf8 \ud53c\ud638\ucd9c \ud568\uc218\ub294 \ud398\uc774\uc9d5\uc744 \ud558\uc9c0 \uc54a\uc544\uc57c\ud55c\ub2e4.<br \/><br \/>&nbsp;\uadf8\ub9ac\uace0 \uc2a4\ud540 \ub77d\uc758 \uc2dc\uac04\uc744 \ucd5c\ub300\ud55c \uc904\uc774\ub294 \uac83\uc774 \n\uc88b\ub2e4. <font color=\"#ff0000\">25 micro second\uc815\ub3c4\ub85c MS\uac00 \uad8c\uc7a5<\/font>\ud558\uace0 \uc788\ub2e4.<\/p>\n<p>&nbsp;<\/p>\n<p>\ucd9c\ucc98 : <a class=\"con_link\" href=\"http:\/\/ssmhz.tistory.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/ssmhz.tistory.com<\/a><br \/>\n<\/p><p><br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uc2a4\ud540 \ub77d\uc740 \ucc38 \uc624\ubb18\ud55c \ubb38\uc81c\uc774\ub2e4. \ud558\uc9c0\ub9cc \uc54c\uace0 \ubcf4\uba74 \uac04\ub2e8\ud55c \ub85c\uc9c1\uc73c\ub85c \ud574\uacb0\ud560 \uc218 \uc788\ub2e4!! &nbsp;\uc77c\ub2e8 \ub3d9\uae30\ud654 \ubb38\uc81c\uc5d0 \uc9c1\uba74\ud558\uac8c \ub418\uba74, ( \uba40\ud2f0 \ud504\ub85c\uc138\uc11c ) \uc6b0\ub9ac\uac00 \uc775\ud788 \uc54c\uace0 \uc788\ub294 \uc138\ub9c8\ud3ec\uc5b4(Semaphore)\uac19\uc740 \ubc29\ubc95\uc744 \uc0ac\uc6a9\ud574\uc11c \ub77d\ud0b9(Locking)\uc744 \ud574\uc57c\ud55c\ub2e4. \uc774\uac83\uc744 \uc81c\ub300\ub85c \ud574\uc8fc\uc9c0 \uc54a\ub294\ub2e4\uba74 \ub370\ub4dc\ub77d(DeadLock)\uc5d0 \ube60\uc9c0\uac8c\ub41c\ub2e4. &nbsp;\ub370\ub4dc\ub77d\uc740 \uc6b4\uc601\uccb4\uc81c\ub54c \ub4e4\uc5c8\uc744 \uac83\uc774\ub2e4. \uc5ec\ub7ec \uc2a4\ub808\ub4dc\uac00 \uc784\uacc4\uc601\uc5ed(Critical Section)\uc5d0 \ub4e4\uc5b4\uac00\uae30 \uc704\ud574\uc11c, \uacbd\uc7c1\uc744 \ud560 \uac83\uc774\ub2e4. &nbsp;\ud558\ub098\uc758 \uc2a4\ub808\ub4dc\uac00 \uc2a4\ud540\ub77d\uc744 \uc0ac\uc6a9\ud558\uace0 \uc788\uc744 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[24],"tags":[],"class_list":["post-196","post","type-post","status-publish","format-standard","hentry","category-development_winddk"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=196"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}