{"id":263377,"date":"2023-02-01T22:05:50","date_gmt":"2023-02-01T14:05:50","guid":{"rendered":"https:\/\/lrxjmw.cn\/lnhsyqjblljl.html"},"modified":"2023-02-01T22:05:50","modified_gmt":"2023-02-01T14:05:50","slug":"lnhsyqjblljl","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lnhsyqjblljl.html","title":{"rendered":"Linux\u5185\u6838\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u6765\u8bb0\u5f55\u7cfb\u7edf\u4f7f\u7528\u5b9a\u65f6\u4e2d\u65ad\u6765\u8ba1\u65f6"},"content":{"rendered":"
\u6587\u7ae0\u76ee\u5f55<\/p>\n
1 \u5185\u6838\u5b9a\u65f6\u5668<\/p>\n
Linux<\/a> \u5185\u6838\u4e2d\u6709\u5927\u91cf\u7684\u51fd\u6570\u9700\u8981\u65f6\u95f4\u7ba1\u7406\uff0c\u6bd4\u5982\u5468\u671f\u6027\u7684\u8c03\u5ea6\u7a0b\u5e8f\u3001\u5ef6\u65f6\u7a0b\u5e8f\u7b49\u3002\u786c\u4ef6\u5b9a\u65f6\u5668\u63d0\u4f9b\u65f6\u949f\u6e90\u7ea2\u5e3d\u5b50linux\uff0c\u65f6\u949f\u6e90\u7684\u9891\u7387\u53ef\u4ee5\u8bbe\u7f6e\uff0c \u8bbe\u7f6e\u597d\u4ee5\u540e\u5c31\u5468\u671f\u6027\u7684\u4ea7\u751f\u5b9a\u65f6\u4e2d\u65ad\uff0c\u7cfb\u7edf<\/a>\u4f7f\u7528\u5b9a\u65f6\u4e2d\u65ad\u6765\u8ba1\u65f6\u3002<\/p>\n Linux \u5185\u6838\u5b9a\u65f6\u5668\u91c7\u7528\u7cfb\u7edf\u65f6\u949f\u6765\u5b9e\u73b0\uff0c\u5185\u6838\u4e2d\u914d\u7f6e<\/p>\n \n <\/p>\n \u9ad8\u8282\u62cd\u7387\u548c\u4f4e\u8282\u62cd\u7387\u7684\u4f18\u7f3a\u70b9\uff1a<\/p>\n \u2460\u3001\u9ad8\u8282\u62cd\u7387\u4f1a\u63d0\u9ad8\u7cfb\u7edf\u65f6\u95f4\u7cbe\u5ea6\uff0c\u5982\u679c\u91c7\u7528 100Hz \u7684\u8282\u62cd\u7387qq linux\uff0c\u65f6\u95f4\u7cbe\u5ea6\u5c31\u662f 10ms\uff0c\u91c7\u75281000Hz \u7684\u8bdd\u65f6\u95f4\u7cbe\u5ea6\u5c31\u662f 1mslinux \u5185\u6838\u5b9a\u65f6\u5668<\/strong>linux \u5185\u6838\u5b9a\u65f6\u5668<\/strong>\uff0c\u7cbe\u5ea6\u63d0\u9ad8\u4e86 10 \u500d\u3002\u9ad8\u7cbe\u5ea6\u65f6\u949f\u5bf9\u4e8e\u90a3\u4e9b\u5bf9\u65f6\u95f4\u8981\u6c42\u4e25\u683c\u7684\u51fd\u6570\u6765\u8bf4\uff0c\u80fd\u591f\u4ee5\u66f4\u9ad8\u7684\u7cbe\u5ea6\u8fd0\u884c\uff0c\u65f6\u95f4\u6d4b\u91cf\u4e5f\u66f4\u52a0\u51c6\u786e\u3002<\/p>\n \u2461\u3001\u9ad8\u8282\u62cd\u7387\u4f1a\u5bfc\u81f4\u4e2d\u65ad\u7684\u4ea7\u751f\u66f4\u52a0\u9891\u7e41\uff0c\u9891\u7e41\u7684\u4e2d\u65ad\u4f1a\u52a0\u5267\u7cfb\u7edf\u7684\u8d1f\u62c5\uff0c 1000Hz \u548c 100Hz\u7684\u7cfb\u7edf\u8282\u62cd\u7387\u76f8\u6bd4\uff0c\u7cfb\u7edf\u8981\u82b1\u8d39 10 \u500d\u7684\u8d44\u6e90\u53bb\u5904\u7406\u4e2d\u65ad\u3002<\/p>\n Linux \u5185\u6838\u4f7f\u7528\u5168\u5c40\u53d8\u91cf jiffies \u6765\u8bb0\u5f55\u7cfb\u7edf\u4ece\u542f\u52a8\u4ee5\u6765\u7684\u7cfb\u7edf\u8282\u62cd\u6570\uff0c\u7cfb\u7edf\u542f\u52a8\u7684\u65f6\u5019\u4f1a\u5c06 jiffies \u521d\u59cb\u5316\u4e3a 0<\/p>\n <\/p>\n 2 \u5b9a\u65f6\u5668\u6570\u636e\u7ed3\u6784<\/p>\n \n 3 \u5b9a\u65f6\u5668\u51fd\u6570 \u542b\u4e49\u51fd\u6570<\/p>\n \u521d\u59cb\u5316\u51fd\u6570<\/p>\n <\/p>\n void init_timer(struct timer_list *timer)<\/p>\n \u5411 Linux \u5185\u6838\u6ce8\u518c\u5b9a\u65f6\u5668<\/p>\n void add_timer(struct timer_list *timer)<\/p>\n \u4fee\u6539\u5b9a\u65f6\u503c<\/p>\n int mod_timer(struct timer_list *timer, unsigned long expires)<\/p>\n \u5220\u9664\u4e00\u4e2a\u5b9a\u65f6\u5668<\/p>\n int del_timer(struct timer_list * timer)<\/p>\n \u7b49\u5f85\u5176\u4ed6\u5904\u7406\u5668\u4f7f\u7528\u5b8c\u5b9a\u65f6\u5668\u518d\u5220\u9664<\/p>\n int del_timer_sync(struct timer_list *timer)<\/p>\n 4 \u7a0b\u5e8f\u6846\u67b6<\/p>\n \n <\/p>\nstruct<\/span> timer_dev<\/span>{<\/span>\n\tstruct<\/span> timer_list<\/span> timer;<\/span>\/* \u5b9a\u4e49\u4e00\u4e2a\u5b9a\u65f6\u5668*\/<\/span>\n\t.<\/span>.<\/span>.<\/span>\n}<\/span>;<\/span>\nstruct<\/span> timer_dev<\/span> timerdev;<\/span>\t\/* timer\u8bbe\u5907 *\/<\/span>\nstatic<\/span> int<\/span> timer_open<\/span>(<\/span>struct<\/span> inode<\/span> *<\/span>inode,<\/span> struct<\/span> file<\/span> *<\/span>filp)<\/span>\n{<\/span>\n\ttimerdev.<\/span>timeperiod =<\/span> 1000<\/span>;<\/span>\t\t\/* \u9ed8\u8ba4\u5468\u671f\u4e3a1s *\/<\/span>\n}<\/span>\n <\/p>\n\/* \u5b9a\u65f6\u5668\u56de\u8c03\u51fd\u6570 *\/<\/span>\nvoid<\/span> timer_function<\/span>(<\/span>unsigned<\/span> long<\/span> arg)<\/span>\n{<\/span>\n\t\/\/\u91cd\u65b0\u8bbe\u7f6e\u5b9a\u65f6\u5668\uff0c\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4<\/span>\n\tmod_timer<\/span>(<\/span>&<\/span>dev-><\/span>timertest,<\/span> jiffies +<\/span> msecs_to_jiffies<\/span>(<\/span>2000<\/span>)<\/span>)<\/span>;<\/span>\n }<\/span>\nstatic<\/span> int<\/span> __init timer_init<\/span>(<\/span>void<\/span>)<\/span>\n{<\/span>\n\t\/* \u521d\u59cb\u5316timer\uff0c\u8bbe\u7f6e\u5b9a\u65f6\u5668\u5904\u7406\u51fd\u6570,\u8fd8\u672a\u8bbe\u7f6e\u5468\u671f\uff0c\u6240\u6709\u4e0d\u4f1a\u6fc0\u6d3b\u5b9a\u65f6\u5668 *\/<\/span>\n\tinit_timer<\/span>(<\/span>&<\/span>timerdev.<\/span>timer)<\/span>;<\/span>\n <\/p>\n\ttimerdev.<\/span>timer.<\/span>function =<\/span> timer_function;<\/span>\/\/\u56de\u8c03\u51fd\u6570<\/span>\n\ttimerdev.<\/span>timer.<\/span>data =<\/span> (<\/span>unsigned<\/span> long<\/span>)<\/span>&<\/span>timerdev;<\/span>\n\treturn<\/span> 0<\/span>;<\/span>\n}<\/span>\nstatic<\/span> void<\/span> __exit timer_exit<\/span>(<\/span>void<\/span>)<\/span>\n{<\/span>\n\tdel_timer_sync<\/span>(<\/span>&<\/span>timerdev.<\/span>timer)<\/span>;<\/span>\t\t\/* \u5220\u9664timer *\/<\/span>\n}<\/span>\n<\/code><\/pre>\n<\/p>\n Linux \u5185\u6838\u5b9a\u65f6\u5668\uff0c\u53ea\u9700\u8981\u63d0\u4f9b\u8d85\u65f6\u65f6\u95f4\u548c\u5b9a\u65f6\u5904\u7406\u51fd\u6570\u5373\u53ef\uff0c\u5f53\u8d85\u65f6\u65f6\u95f4\u5230\u4e86\u4ee5\u540e\u8bbe\u7f6e\u7684\u5b9a\u65f6\u5904\u7406\u51fd\u6570\u5c31\u4f1a\u6267\u884c\u3002<\/p>\n \u6ce8\u610f\uff1a\u5185\u6838\u5b9a\u65f6\u5668\u5e76\u4e0d\u662f\u5468\u671f\u6027\u8fd0\u884c\u7684\uff0c\u8d85\u65f6\u4ee5\u540e\u5c31\u4f1a\u81ea\u52a8\u5173\u95ed\uff0c\u56e0\u6b64\u5982\u679c\u60f3\u8981\u5b9e\u73b0\u5468\u671f\u6027\u5b9a\u65f6\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u5728\u5b9a\u65f6\u5904\u7406\u51fd\u6570\u4e2d\u91cd\u65b0\u5f00\u542f\u5b9a\u65f6\u5668\uff08\u4f7f\u7528mod_timer\u51fd\u6570\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u5185\u6838\u5b9a\u65f6\u5668\u5185\u6838\u5b9a\u65f6\u5668\u91c7\u7528\u7cfb\u7edf\u65f6\u949f\u6765\u5b9e\u73b0\uff0c\u5185\u6838\u4e2d\u914d\u7f6e\u5b9a\u65f6\u5668\u6570\u636e\u7ed3\u6784\u5185\u6838\u6ce8\u518c\u5b9a\u65f6\u5668\u5220\u9664\u4e00\u4e2a\u5b9a\u65f6\u5668\u5185\u6838\u5b9a\u65f6\u5668\uff0c\u53ea\u9700\u8981\u63d0\u4f9b\u8d85\u65f6\u65f6\u95f4\u548c\u5b9a\u65f6\u5904\u7406\u51fd\u6570\u5373\u53ef\uff0c\u5f53\u8d85\u65f6\u65f6\u95f4\u5230\u4e86\u4ee5\u540e\u8bbe\u7f6e\u7684\u5b9a\u65f6\u5904\u7406\u51fd\u6570\u5c31\u4f1a\u6267\u884c\u3002\u6ce8\u610f\uff1a\u5185\u6838\u5b9a\u65f6\u5668\u5e76\u4e0d\u662f\u5468\u671f\u6027\u8fd0\u884c\u7684\uff0c\u8d85\u65f6\u4ee5\u540e\u5c31\u4f1a\u81ea\u52a8\u5173\u95ed\uff0c\u56e0\u6b64\u5982\u679c\u60f3\u8981\u5b9e\u73b0\u5468\u671f\u6027\u5b9a\u65f6\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u5728\u5b9a\u65f6\u5904\u7406\u51fd\u6570\u4e2d\u91cd\u65b0\u5f00\u542f\u5b9a\u65f6\u5668\uff08\u4f7f\u7528mod_timer\u51fd\u6570\uff09\u3002<\/p>\n","protected":false},"author":1,"featured_media":263378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-263377","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=263377"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263377\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/263378"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=263377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=263377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=263377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}-> Kernel Features\n\t\t-> Timer frequency ( [=y])\n<\/code><\/pre>\n<\/p>\n
struct<\/span> timer_list<\/span> {<\/span>\n\tstruct<\/span> list_head<\/span> entry;<\/span>\n\tunsigned<\/span> long<\/span> expires;<\/span> \/* \u5b9a\u65f6\u5668\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u662f\u8282\u62cd\u6570 *\/<\/span>\n\tstruct<\/span> tvec_base<\/span> *<\/span>base;<\/span>\n\tvoid<\/span> (<\/span>*<\/span>function)<\/span>(<\/span>unsigned<\/span> long<\/span>)<\/span>;<\/span> \/* \u5b9a\u65f6\u5904\u7406\u51fd\u6570 *\/<\/span>\n\tunsigned<\/span> long<\/span> data;<\/span> \/* \u8981\u4f20\u9012\u7ed9 function \u51fd\u6570\u7684\u53c2\u6570 *\/<\/span>\n\tint<\/span> slack;<\/span>\n}<\/span>;<\/span>\n<\/code><\/pre>\n<\/p>\n
\n\/* timer\u8bbe\u5907\u7ed3\u6784\u4f53 *\/<\/span>\n