{"id":16492,"date":"2024-11-18T12:23:11","date_gmt":"2024-11-18T04:23:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/16492\/"},"modified":"2024-11-18T12:23:11","modified_gmt":"2024-11-18T04:23:11","slug":"linux%e9%a9%b1%e5%8a%a8%e4%b8%ad%e6%96%ad%e4%b8%8b%e5%8d%8a%e9%83%a8%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/16492\/","title":{"rendered":"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5"},"content":{"rendered":"<h2> <span><\/span><span style=\"padding: 2px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px\">\u4ec0\u4e48\u662f\u4e2d\u65ad\u4e0b\u534a\u90e8<\/span> <\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u5f53\u4ea7\u751f\u4e00\u4e2a\u4e2d\u65ad\u65f6\uff0c\u4f1a\u8fdb\u5165\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u4f46<strong>\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f<\/strong>\u5fc5\u987b\u5feb\u901f\u3001\u5f02\u6b65\u3001\u7b80\u5355\u7684\u5bf9\u786c\u4ef6\u505a\u51fa<strong>\u8fc5\u901f\u54cd\u5e94<\/strong>\u5e76\u5b8c\u6210\u90a3\u4e9b\u65f6\u95f4\u8981\u6c42\u5f88\u4e25\u683c\u7684\u64cd\u4f5c\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u56e0\u6b64\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u5176\u4ed6\u7684\u3001\u5bf9\u65f6\u95f4\u8981\u6c42\u76f8\u5bf9\u5bbd\u677e\u7684\u4efb\u52a1\uff0c\u5c31\u5e94\u8be5<strong>\u63a8\u540e<\/strong>\u5230\u4e2d\u65ad\u88ab\u6fc0\u6d3b\u4ee5\u540e\u518d\u53bb<strong>\u8fd0\u884c<\/strong>\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u8fd9\u6837\uff0c\u6574\u4e2a\u4e2d\u65ad\u5904\u7406\u6d41\u7a0b\u5c31\u88ab\u5206\u4e3a\u4e86<strong>\u4e24\u4e2a\u90e8\u5206<\/strong>\uff1a<\/p>\n<ul>\n<li> \u7b2c\u4e00\u4e2a\u90e8\u5206\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f( <strong>\u4e0a\u534a\u90e8<\/strong>)\uff0c\u5185\u6838\u901a\u8fc7\u5bf9\u5b83\u7684\u5f02\u6b65\u6267\u884c\u5b8c\u6210\u5bf9\u786c\u4ef6\u4e2d\u65ad\u7684\u5373\u65f6\u54cd\u5e94\u3002 <\/li>\n<li> \u4e2d\u65ad\u5904\u7406\u6d41\u7a0b\u4e2d\u7684\u53e6\u5916\u90a3\u4e00\u90e8\u5206\uff0c <strong>\u4e0b\u534a\u90e8<\/strong>(bottom half) <\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\"><strong>\u4e0b\u534a\u90e8\u7684\u4efb\u52a1\u4e3b\u8981\u662f\u6267\u884c\u4e0e\u4e2d\u65ad\u76f8\u5173\u7684\u5de5\u4f5c\uff0c\u8fd9\u4e9b\u5de5\u4f5c\u6ca1\u6709\u88ab\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u672c\u8eab\u5b8c\u6210<\/strong>\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/453610eaa4370f5a28a0c513250536da-0.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe\" \/> <\/p>\n<p style=\"max-width:90%\"><strong>\u4e0b\u534a\u90e8<\/strong>\u5e76\u4e0d\u9700\u8981\u6307\u660e\u4e00\u4e2a\u786e\u5207\u65f6\u95f4\uff0c\u53ea\u8981\u628a\u8fd9\u4e9b\u4efb\u52a1\u63a8\u8fdf\u4e00\u70b9\uff0c\u8ba9\u5b83\u4eec\u5728<strong>\u7cfb\u7edf\u4e0d\u592a\u7e41\u5fd9<\/strong>\u5e76\u4e14<strong>\u4e2d\u65ad\u6062\u590d\u540e<\/strong>\u6267\u884c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\"><strong>\u4e0a\u534a\u90e8\u548c\u4e0b\u534a\u90e8\u7684\u4e3b\u8981\u533a\u522b<\/strong>\uff1a<\/p>\n<ul>\n<li>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black\"><strong>\u4e0a\u534a\u90e8<\/strong>\u6307\u7684\u662f<strong>\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f<\/strong>\uff0c<strong>\u4e0b\u534a\u90e8<\/strong>\u5219\u6307\u7684\u662f\u4e00\u4e9b\u867d\u7136\u4e0e\u4e2d\u65ad\u6709\u76f8\u5173\u6027\u4f46\u662f<strong>\u53ef\u4ee5\u5ef6\u540e\u6267\u884c<\/strong>\u7684\u4efb\u52a1\u3002<\/p>\n<\/li>\n<li>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black\">\u4e0a\u534a\u90e8\u4e2d\u65ad\u4e0d\u80fd\u88ab\u76f8\u540c\u7c7b\u578b\u7684\u4e2d\u65ad\u6253\u65ad\uff0c\u800c<strong>\u4e0b\u534a\u90e8\u4f9d\u7136\u53ef\u4ee5\u88ab\u4e2d\u65ad\u6253\u65ad<\/strong>\u3002<\/p>\n<\/li>\n<li>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black\">\u901a\u5e38\u4e0b\u534a\u90e8\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e00\u8fd4\u56de\u5c31\u4f1a\u9a6c\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/li>\n<li>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black\"><strong>\u4e0a\u534a\u90e8\u5206\u7b80\u5355\u5feb\u901f<\/strong>\uff0c\u6267\u884c\u7684\u65f6\u5019\u7981\u6b62\u4e00\u4e9b\u6216\u8005\u5168\u90e8\u4e2d\u65ad\u3002<\/p>\n<\/li>\n<li>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: black\"><strong>\u4e0b\u534a\u90e8\u5206\u7a0d\u540e\u6267\u884c<\/strong>\uff0c\u800c\u4e14\u6267\u884c\u671f\u95f4\u53ef\u4ee5\u54cd\u5e94\u6240\u6709\u7684\u4e2d\u65ad\u3002<\/p>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">Linux\u4e2d\uff0c\u5bf9\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u5b9e\u73b0\u4e3b\u8981\u6709\u4e09\u79cd\uff1a<\/p>\n<ul>\n<li> <strong>\u8f6f\u4e2d\u65ad<\/strong> <\/li>\n<li> <strong>tasklet<\/strong> <\/li>\n<li> <strong>\u5de5\u4f5c\u961f\u5217<\/strong> <\/li>\n<\/ul>\n<h2> <span><\/span><span style=\"padding: 2px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px\">softirq<\/span><span style=\"vertical-align: bottom;border-bottom: 36px solid #efebe9;border-right: 20px solid transparent\"> <\/span> <\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">softirq\u5373\u8f6f\u4e2d\u65ad\uff0c\u4ee3\u7801\u4f4d\u4e8ekernel\/softirq.c\u6587\u4ef6\u4e2d\uff1b<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u6bcf\u4e2a\u8f6f\u4e2d\u65ad\u7531softirq_action\u7ed3\u6784\u8868\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/b22f370513bb14011ce70289a459a54b-1.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe1\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe1\" \/> <\/p>\n<p style=\"max-width:90%\">\u5728softirq.c\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u5411\u91cf\u6570\u7ec4softirq_vec\uff1a<\/p>\n<pre>static&nbsp;struct&nbsp;softirq_action&nbsp;softirq_vec[NR_SOFTIRQS]&nbsp;__cacheline_aligned_in_smp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;enum&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HI_SOFTIRQ=0,&nbsp;\/*\u7528\u4e8e\u9ad8\u4f18\u5148\u7ea7\u7684tasklet*\/&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIMER_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u5b9a\u65f6\u5668\u7684\u4e0b\u534a\u90e8*\/&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NET_TX_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u7f51\u7edc\u5c42\u53d1\u5305*\/&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NET_RX_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u7f51\u7edc\u5c42\u6536\u62a5*\/&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BLOCK_SOFTIRQ,&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BLOCK_IOPOLL_SOFTIRQ,&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TASKLET_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u4f4e\u4f18\u5148\u7ea7\u7684tasklet*\/&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SCHED_SOFTIRQ,&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HRTIMER_SOFTIRQ,&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RCU_SOFTIRQ,&nbsp;\/*&nbsp;Preferable&nbsp;RCU&nbsp;should&nbsp;always&nbsp;be&nbsp;the&nbsp;last&nbsp;softirq&nbsp;*\/&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NR_SOFTIRQS&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u6570\u7ec4\u7684\u6210\u5458\u6570\u7531NR_SOFTIRQS\u51b3\u5b9a\uff0c\u662f\u4e00\u4e2a\u679a\u4e3e\u5e38\u91cf\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u65b0\u589e\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u65f6\uff0c\u9700\u8981\u5728\u6587\u4ef6include\/\/interrupt.h \u4e2d\u6dfb\u52a0\u4e00\u4e2a\u679a\u4e3e\u5e38\u91cf\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\"><strong>\u8f6f\u4e2d\u65ad\u4f7f\u7528\u7684\u51e0\u4e2a\u8981\u70b9<\/strong>\uff1a<\/p>\n<ul>\n<li> \u4e00\u4e2a\u8f6f\u4e2d\u65ad\u4e0d\u4f1a\u62a2\u5360\u53e6\u5916\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u3002 <\/li>\n<li> \u60df\u4e00\u53ef\u4ee5\u62a2\u5360\u8f6f\u4e2d\u65ad\u7684\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002 <\/li>\n<li> \u5176\u4ed6\u7684\u8f6f\u4e2d\u65ad\u53ef\u4ee5\u5728\u5176\u4ed6\u5904\u7406\u5668\u4e0a\u540c\u65f6\u6267\u884c\u3002 <\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u76f8\u5173\u63a5\u53e3<\/p>\n<ul>\n<li> \u6ce8\u518c\u8f6f\u4e2d\u65ad <\/li>\n<\/ul>\n<pre>void&nbsp;open_softirq(int&nbsp;nr,&nbsp;void&nbsp;(*action)(struct&nbsp;softirq_action&nbsp;*))<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u5373\u6ce8\u518c\u5bf9\u5e94\u7c7b\u578b\u7684\u5904\u7406\u51fd\u6570\u5230\u5168\u5c40\u6570\u7ec4softirq_vec\u4e2d\u3002<\/p>\n<ul>\n<li> \u89e6\u53d1\u8f6f\u4e2d\u65ad <\/li>\n<\/ul>\n<pre>void&nbsp;raise_softirq(unsigned&nbsp;int&nbsp;nr)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u5b9e\u9645\u4e0a\u5373\u4ee5\u8f6f\u4e2d\u65ad\u7c7b\u578bnr\u4f5c\u4e3a\u504f\u79fb\u91cf\u4f1a\u7f6e\u4f4dirq_stat[cpu_id]\u7684\u6210\u5458\u53d8\u91cf__softirq_pending.<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">__softirq_pending\u5b57\u6bb5\u4e2d\u7684\u6bcf\u4e00\u4e2abit\uff0c\u5bf9\u5e94\u7740\u67d0\u4e00\u4e2a\u8f6f\u4e2d\u65ad\uff0c\u67d0\u4e2abit\u88ab\u7f6e\u4f4d\uff0c\u8bf4\u660e\u6709\u76f8\u5e94\u7684\u8f6f\u4e2d\u65ad\u7b49\u5f85\u5904\u7406\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u8fd9\u4e5f\u662f\u540c\u4e00\u7c7b\u578b\u8f6f\u4e2d\u65ad\u53ef\u4ee5\u5728\u591a\u4e2acpu\u4e0a\u5e76\u884c\u8fd0\u884c\u7684\u6839\u672c\u539f\u56e0\u3002<\/p>\n<h3> <span><\/span>\u8f6f\u4e2d\u65ad\u5b9e\u4f8b<span><\/span> <\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u4ee5\u4e00\u4e2a<strong>\u6309\u952e\u9a71\u52a8\u7684\u4e2d\u65ad\u5904\u7406<\/strong>\u4e3a\u4f8b\uff0c\u5c06\u6309\u952e\u9a71\u52a8\u7684\u4e2d\u65ad\u5904\u7406\u5206\u6210\u4e0a\u4e0b\u4e24\u90e8\u5206\uff1a<\/p>\n<ul>\n<li> <strong>\u4e0a\u534a\u90e8<\/strong>\uff1a\u8bfb\u53d6\u952e\u503c\uff0c\u89e6\u53d1\u8f6f\u4e2d\u65ad <\/li>\n<li> <strong>\u4e0b\u534a\u90e8<\/strong>\uff1a\u5524\u9192\u8fdb\u7a0b <\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/b22f370513bb14011ce70289a459a54b-2.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe2\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe2\" \/> <\/p>\n<p style=\"max-width:90%\">\u8f6f\u4e2d\u65ad\u7684\u6ce8\u518c\uff0c\u5728\u9a71\u52a8\u7684\u5165\u53e3\u51fd\u6570\uff0c\u6ce8\u518c\u8f6f\u4e2d\u65ad\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/ee3daae50d03192a258b5705ffd314ff-3.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe3\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe3\" \/> <\/p>\n<p style=\"max-width:90%\">\u6dfb\u52a0\u7684\u679a\u4e3e\u5e38\u91cf\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/ee3daae50d03192a258b5705ffd314ff-4.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe4\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe4\" \/> <\/p>\n<p style=\"max-width:90%\">\u53ef\u4ee5\u770b\u5230\uff0c\u4f7f\u7528\u8f6f\u4e2d\u65ad\u662f\u9700\u8981\u4fee\u6539\u5185\u6838\uff0c\u6dfb\u52a0\u4e00\u4e2a\u679a\u4e3e\u7684\uff0c\u6709\u4e9b\u7e41\u7410\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u6240\u4ee5\uff0c\u901a\u5e38\u6211\u4eec<strong>\u4e0d\u5efa\u8bae\u64c5\u81ea\u589e\u52a0\u8f6f\u4e2d\u65ad\u7684\u6570\u91cf<\/strong>\uff0c\u5982\u679c\u9700\u8981\u65b0\u7684\u8f6f\u4e2d\u65ad\uff0c\u5c3d\u53ef\u80fd\u628a\u5b83\u4eec\u5b9e\u73b0\u4e3a<strong>\u57fa\u4e8e\u8f6f\u4e2d\u65ad\u7684tasklet\u5f62\u5f0f\u3002<\/strong><\/p>\n<h2> <span><\/span><span style=\"padding: 2px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px\">tasklet<\/span><span style=\"vertical-align: bottom;border-bottom: 36px solid #efebe9;border-right: 20px solid transparent\"> <\/span> <\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\"><strong>tasklet<\/strong>\u662f\u5229\u7528<strong>\u8f6f\u4e2d\u65ad<\/strong>\u5b9e\u73b0\u7684\u4e00\u79cd<strong>\u4e0b\u534a\u90e8\u673a\u5236<\/strong>\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u90a3\u662f\u7528<strong>\u8f6f\u4e2d\u65ad<\/strong>\u8fd8\u662ftasklet\u597d\u5462\uff1f<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u9009\u62e9\u5230\u5e95\u662f\u7528<strong>\u8f6f\u4e2d\u65ad<\/strong>\u8fd8\u662ftasklet\u5176\u5b9e\u5f88\u7b80\u5355\uff1a<\/p>\n<ul>\n<li> <strong>\u901a\u5e38\u4f60\u5e94\u8be5\u7528tasklet\u3002<\/strong>\u5c31\u50cf\u6211\u4eec\u5728\u524d\u9762\u770b\u5230\u7684\uff0c\u8f6f\u4e2d\u65ad\u8d44\u6e90\u6709\u9650\uff0c\u4e5f\u9ebb\u70e6\uff0c\u800c\u4e14\u8f6f\u4e2d\u65ad\u7684\u4f7f\u7528\u8005\u5c48\u6307\u53ef\u6570\u3002\u5b83\u53ea\u5728\u90a3\u4e9b\u6267\u884c\u9891\u7387\u5f88\u9ad8\u548c\u8fde\u7eed\u6027\u8981\u6c42\u5f88\u9ad8\u7684\u60c5\u51b5\u4e0b\u624d\u9700\u8981\u3002 <\/li>\n<li> \u800c <strong>tasklet\u5374\u6709\u66f4\u5e7f\u6cdb\u7684\u7528\u9014<\/strong>\u3002\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u7528tasklet\u6548\u679c\u90fd\u4e0d\u9519\uff0c\u800c\u4e14\u5b83\u4eec\u8fd8\u975e\u5e38\u5bb9\u6613\u4f7f\u7528\u3002 <\/li>\n<li> \u56e0\u4e3a <strong>tasklet<\/strong>\u662f\u901a\u8fc7\u8f6f\u4e2d\u65ad\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u5b83\u4eec <strong>\u672c\u8eab\u4e5f\u662f\u8f6f\u4e2d\u65ad<\/strong>\u3002 <\/li>\n<\/ul>\n<h3> <span><\/span>tasklet\u4f7f\u7528<span><\/span> <\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">tasklet\u7684\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">1\u3001\u7f16\u5199tasklet\u5904\u7406\u51fd\u6570\uff08<strong>\u4e0b\u534a\u90e8<\/strong>\uff09<\/p>\n<pre>void&nbsp;my_tasklet_fun&nbsp;(unsigned&nbsp;long&nbsp;data)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">2\u3001\u58f0\u660etasklet<\/p>\n<pre>\/\/\u9759\u6001&nbsp;\nDECLARE_TASKLET(my_tasklet,my_tasklet_fun,data);&nbsp;\n\/\/\u52a8\u6001\nStruct&nbsp;&nbsp;tasklet_struct&nbsp;xxx;\ntasklet_init(&amp;amp;xxx,tasklet_handler,dev)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">3\u3001\u8c03\u5ea6 tasklet<\/p>\n<pre>tasklet_schedule(&amp;amp;my_tasklet);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u767b\u8bb0my_tasklet, \u7136\u540e\u5141\u8bb8\u7cfb\u7edf\u5728\u5408\u9002\u7684\u65f6\u95f4\u8c03\u5ea6\u5b83\u3002<\/p>\n<h3> <span><\/span>tasklet\u5b9e\u4f8b<span><\/span> <\/h3>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u4ee5\u6309\u952e\u4e2d\u65ad\u9a71\u52a8\u4e3a\u4f8b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/ee3daae50d03192a258b5705ffd314ff-5.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe5\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe5\" \/> <\/p>\n<p style=\"max-width:90%\">\u5148\u4f7f\u7528DECLARE_TASKLET\u9759\u6001\u58f0\u660e\u4e00\u4e2atasklet\uff0c\u6307\u5b9a\u5176\u4e0b\u534a\u90e8\u51fd\u6570\u4e3abtn_tasklet_func\uff0c\u5728\u4e2d\u65ad\u670d\u52a1\u51fd\u6570\uff08\u4e0a\u534a\u90e8\uff09\u83b7\u53d6\u6309\u952e\u503c\u540e\uff0c\u8c03\u7528tasklet_schedule\u8c03\u5ea6\u3002<\/p>\n<h2> <span><\/span><span style=\"padding: 2px 10px 1px;border-top-right-radius: 3px;border-top-left-radius: 3px;margin-right: 3px\">work queue<\/span><span style=\"vertical-align: bottom;border-bottom: 36px solid #efebe9;border-right: 20px solid transparent\"> <\/span> <\/h2>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">work queue\u5373<strong>\u5de5\u4f5c\u961f\u5217<\/strong>\uff0c\u4e5f\u662f\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e00\u79cd\u3002<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">Work queue\u5c06\u4e0b\u534a\u90e8\u5de5\u4f5c\u63a8\u8fdf\u7ed9\u4e00\u4e2a<strong>\u5185\u6838\u7ebf\u7a0b<\/strong>\u53bb\u6267\u884c \u2014\u2014work \u603b\u662f\u8fd0\u884c\u4e8e<strong>\u8fdb\u7a0b\u4e0a\u4e0b\u6587<\/strong>.<\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\"><strong>\u4e24\u4e2a\u8981\u70b9<\/strong>\uff1a<\/p>\n<ul>\n<li> \u5982\u679c\u63a8\u8fdf\u7684\u5de5\u4f5c\u9700\u8981 <strong>\u7761\u7720<\/strong>\uff0c\u5219\u4f7f\u7528work queues\u3002\u5426\u5219\u4f7f\u7528softirq\u6216tasklets. <\/li>\n<li> Work queues\u9002\u7528\u4e8e\u9700\u8981\u5206\u914d\u5927\u91cf\u7684\u5185\u5b58\uff0c\u83b7\u5f97\u4e00\u4e2a\u4fe1\u53f7\u91cf\uff0c\u6216\u8005\u6267\u884c\u963b\u585e\u7684I\/O\u7684\u60c5\u51b5. <\/li>\n<\/ul>\n<p style=\"padding-top: 8px;padding-bottom: 8px;line-height: 26px\">\u5de5\u4f5c\u961f\u5217\u7684\u76f8\u5173\u63a5\u53e3\u51fd\u6570\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/a646ac493edd704aa2635e5002dbaf44-6.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe6\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe6\" \/> <\/p>\n<p style=\"max-width:90%\">\u5728\u4f7f\u7528\u4e0a\uff0c<strong>\u5de5\u4f5c\u961f\u5217<\/strong>\u4e0etasklet\u662f\u7c7b\u4f3c\u7684\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/014\/a646ac493edd704aa2635e5002dbaf44-7.png\" class=\"aligncenter\" title=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe7\" alt=\"Linux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u63d2\u56fe7\" \/><br \/>\n <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fLinux\u9a71\u52a8\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u4e09\u79cd\u65b9\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u4e2d\u65ad\u4e0b\u534a\u90e8 \u5f53\u4ea7\u751f\u4e00\u4e2a\u4e2d\u65ad\u65f6\uff0c\u4f1a\u8fdb\u5165\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002 \u4f46\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5fc5\u987b\u5feb\u901f\u3001\u5f02\u6b65\u3001\u7b80\u5355\u7684\u5bf9\u786c\u4ef6\u505a\u51fa\u8fc5\u901f\u54cd\u5e94\u5e76\u5b8c\u6210\u90a3\u4e9b\u65f6\u95f4\u8981\u6c42\u5f88\u4e25\u683c\u7684\u64cd\u4f5c\u3002 \u56e0\u6b64\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u5176\u4ed6\u7684\u3001\u5bf9\u65f6\u95f4\u8981\u6c42\u76f8\u5bf9\u5bbd\u677e\u7684\u4efb\u52a1\uff0c\u5c31\u5e94\u8be5\u63a8\u540e\u5230\u4e2d\u65ad\u88ab\u6fc0\u6d3b\u4ee5\u540e\u518d\u53bb\u8fd0\u884c\u3002 \u8fd9\u6837\uff0c\u6574\u4e2a\u4e2d\u65ad\u5904\u7406\u6d41\u7a0b\u5c31\u88ab\u5206\u4e3a\u4e86\u4e24\u4e2a\u90e8\u5206\uff1a \u7b2c\u4e00\u4e2a\u90e8\u5206\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f( \u4e0a\u534a\u90e8)\uff0c\u5185\u6838\u901a\u8fc7\u5bf9\u5b83\u7684\u5f02\u6b65\u6267\u884c\u5b8c\u6210\u5bf9\u786c\u4ef6\u4e2d\u65ad\u7684\u5373\u65f6\u54cd\u5e94\u3002 \u4e2d\u65ad\u5904\u7406\u6d41\u7a0b\u4e2d\u7684\u53e6\u5916\u90a3\u4e00\u90e8\u5206\uff0c \u4e0b\u534a\u90e8(bottom half) \u4e0b\u534a\u90e8\u7684\u4efb\u52a1\u4e3b\u8981\u662f\u6267\u884c\u4e0e\u4e2d\u65ad\u76f8\u5173\u7684\u5de5\u4f5c\uff0c\u8fd9\u4e9b\u5de5\u4f5c\u6ca1\u6709\u88ab\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u672c\u8eab\u5b8c\u6210\u3002 \u4e0b\u534a\u90e8\u5e76\u4e0d\u9700\u8981\u6307\u660e\u4e00\u4e2a\u786e\u5207\u65f6\u95f4\uff0c\u53ea\u8981\u628a\u8fd9\u4e9b\u4efb\u52a1\u63a8\u8fdf\u4e00\u70b9\uff0c\u8ba9\u5b83\u4eec\u5728\u7cfb\u7edf\u4e0d\u592a\u7e41\u5fd9\u5e76\u4e14\u4e2d\u65ad\u6062\u590d\u540e\u6267\u884c\u5c31\u53ef\u4ee5\u4e86\u3002 \u4e0a\u534a\u90e8\u548c\u4e0b\u534a\u90e8\u7684\u4e3b\u8981\u533a\u522b\uff1a \u4e0a\u534a\u90e8\u6307\u7684\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u4e0b\u534a\u90e8\u5219\u6307\u7684\u662f\u4e00\u4e9b\u867d\u7136\u4e0e\u4e2d\u65ad\u6709\u76f8\u5173\u6027\u4f46\u662f\u53ef\u4ee5\u5ef6\u540e\u6267\u884c\u7684\u4efb\u52a1\u3002 \u4e0a\u534a\u90e8\u4e2d\u65ad\u4e0d\u80fd\u88ab\u76f8\u540c\u7c7b\u578b\u7684\u4e2d\u65ad\u6253\u65ad\uff0c\u800c\u4e0b\u534a\u90e8\u4f9d\u7136\u53ef\u4ee5\u88ab\u4e2d\u65ad\u6253\u65ad\u3002 \u901a\u5e38\u4e0b\u534a\u90e8\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e00\u8fd4\u56de\u5c31\u4f1a\u9a6c\u4e0a\u8fd0\u884c\u3002 \u4e0a\u534a\u90e8\u5206\u7b80\u5355\u5feb\u901f\uff0c\u6267\u884c\u7684\u65f6\u5019\u7981\u6b62\u4e00\u4e9b\u6216\u8005\u5168\u90e8\u4e2d\u65ad\u3002 \u4e0b\u534a\u90e8\u5206\u7a0d\u540e\u6267\u884c\uff0c\u800c\u4e14\u6267\u884c\u671f\u95f4\u53ef\u4ee5\u54cd\u5e94\u6240\u6709\u7684\u4e2d\u65ad\u3002 Linux\u4e2d\uff0c\u5bf9\u4e2d\u65ad\u4e0b\u534a\u90e8\u7684\u5b9e\u73b0\u4e3b\u8981\u6709\u4e09\u79cd\uff1a \u8f6f\u4e2d\u65ad tasklet \u5de5\u4f5c\u961f\u5217 softirq softirq\u5373\u8f6f\u4e2d\u65ad\uff0c\u4ee3\u7801\u4f4d\u4e8ekernel\/softirq.c\u6587\u4ef6\u4e2d\uff1b \u6bcf\u4e2a\u8f6f\u4e2d\u65ad\u7531softirq_action\u7ed3\u6784\u8868\u793a\uff1a \u5728softirq.c\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u5411\u91cf\u6570\u7ec4softirq_vec\uff1a static&nbsp;struct&nbsp;softirq_action&nbsp;softirq_vec[NR_SOFTIRQS]&nbsp;__cacheline_aligned_in_smp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;enum&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HI_SOFTIRQ=0,&nbsp;\/*\u7528\u4e8e\u9ad8\u4f18\u5148\u7ea7\u7684tasklet*\/&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIMER_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u5b9a\u65f6\u5668\u7684\u4e0b\u534a\u90e8*\/&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NET_TX_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u7f51\u7edc\u5c42\u53d1\u5305*\/&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NET_RX_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u7f51\u7edc\u5c42\u6536\u62a5*\/&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BLOCK_SOFTIRQ,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BLOCK_IOPOLL_SOFTIRQ,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TASKLET_SOFTIRQ,&nbsp;\/*\u7528\u4e8e\u4f4e\u4f18\u5148\u7ea7\u7684tasklet*\/&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SCHED_SOFTIRQ,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HRTIMER_SOFTIRQ,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RCU_SOFTIRQ,&nbsp;\/*&nbsp;Preferable&nbsp;RCU&nbsp;should&nbsp;always&nbsp;be&nbsp;the&nbsp;last&nbsp;softirq&nbsp;*\/&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NR_SOFTIRQS&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}; \u767b\u5f55\u540e\u590d\u5236 \u6570\u7ec4\u7684\u6210\u5458\u6570\u7531NR_SOFTIRQS\u51b3\u5b9a\uff0c\u662f\u4e00\u4e2a\u679a\u4e3e\u5e38\u91cf\u3002 \u65b0\u589e\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u65f6\uff0c\u9700\u8981\u5728\u6587\u4ef6include\/\/interrupt.h \u4e2d\u6dfb\u52a0\u4e00\u4e2a\u679a\u4e3e\u5e38\u91cf\u3002 \u8f6f\u4e2d\u65ad\u4f7f\u7528\u7684\u51e0\u4e2a\u8981\u70b9\uff1a \u4e00\u4e2a\u8f6f\u4e2d\u65ad\u4e0d\u4f1a\u62a2\u5360\u53e6\u5916\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u3002 \u60df\u4e00\u53ef\u4ee5\u62a2\u5360\u8f6f\u4e2d\u65ad\u7684\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002 \u5176\u4ed6\u7684\u8f6f\u4e2d\u65ad\u53ef\u4ee5\u5728\u5176\u4ed6\u5904\u7406\u5668\u4e0a\u540c\u65f6\u6267\u884c\u3002 \u76f8\u5173\u63a5\u53e3 \u6ce8\u518c\u8f6f\u4e2d\u65ad void&nbsp;open_softirq(int&nbsp;nr,&nbsp;void&nbsp;(*action)(struct&nbsp;softirq_action&nbsp;*)) \u767b\u5f55\u540e\u590d\u5236 \u5373\u6ce8\u518c\u5bf9\u5e94\u7c7b\u578b\u7684\u5904\u7406\u51fd\u6570\u5230\u5168\u5c40\u6570\u7ec4softirq_vec\u4e2d\u3002 \u89e6\u53d1\u8f6f\u4e2d\u65ad [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-16492","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/16492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=16492"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/16492\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=16492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=16492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=16492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}