From f3e297d3ccf8c171231e63c0425f89bb8139cce1 Mon Sep 17 00:00:00 2001
From: tom
Date: Tue, 23 Jan 2024 19:16:02 +0800
Subject: [PATCH] Deployed 4ac57ca with MkDocs version: 1.5.3
---
404.html | 48 +-
arm/barrier/index.html | 48 +-
arm/index.html | 48 +-
cloud/index.html | 48 +-
index.html | 48 +-
linux/drivers/chardev/index.html | 48 +-
linux/drivers/dts/index.html | 48 +-
linux/drivers/framework/index.html | 48 +-
linux/drivers/index.html | 48 +-
linux/index.html | 48 +-
linux/kernel/index.html | 48 +-
linux/kernel/interrupt/index.html | 48 +-
linux/kernel/mm/index.html | 48 +-
linux/kernel/others/index.html | 48 +-
linux/kernel/sched/index.html | 48 +-
linux/kernel/synch/index.html | 48 +-
linux/kernel/vma/index.html | 48 +-
others/index.html | 50 +-
others/ld/index.html | 48 +-
pl/index.html | 48 +-
rtos/freertos/CMSIS/index.html | 48 +-
rtos/freertos/index.html | 48 +-
rtos/index.html | 48 +-
rtos/rt-thread/index.html | 48 +-
search/search_index.json | 2 +-
sitemap.xml | 10 +
sitemap.xml.gz | Bin 357 -> 368 bytes
tools/github/index.html | 58 +-
tools/index.html | 55 +-
tools/markdown/index.html | 1531 +++++++++++++++++++++++++
tools/vim/index.html | 1717 ++++++++++++++++++++++++++++
31 files changed, 4491 insertions(+), 36 deletions(-)
create mode 100644 tools/markdown/index.html
create mode 100644 tools/vim/index.html
diff --git a/404.html b/404.html
index 30347b2c..a9b57c6d 100644
--- a/404.html
+++ b/404.html
@@ -1206,6 +1206,10 @@
+
+
+
+
@@ -1262,7 +1266,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/arm/barrier/index.html b/arm/barrier/index.html
index 945542c9..50bd2ce9 100644
--- a/arm/barrier/index.html
+++ b/arm/barrier/index.html
@@ -1231,6 +1231,10 @@
+
+
+
+
@@ -1287,7 +1291,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/arm/index.html b/arm/index.html
index 85f4af48..166b3a58 100644
--- a/arm/index.html
+++ b/arm/index.html
@@ -1221,6 +1221,10 @@
+
+
+
+
@@ -1277,7 +1281,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/cloud/index.html b/cloud/index.html
index 5e2738ca..5f068c5c 100644
--- a/cloud/index.html
+++ b/cloud/index.html
@@ -1216,6 +1216,10 @@
+
+
+
+
@@ -1272,7 +1276,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/index.html b/index.html
index 18d60992..f17a8dd8 100644
--- a/index.html
+++ b/index.html
@@ -1280,6 +1280,10 @@
+
+
+
+
@@ -1336,7 +1340,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/drivers/chardev/index.html b/linux/drivers/chardev/index.html
index 6c02ca89..db8a73ce 100644
--- a/linux/drivers/chardev/index.html
+++ b/linux/drivers/chardev/index.html
@@ -1356,6 +1356,10 @@
+
+
+
+
@@ -1412,7 +1416,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/drivers/dts/index.html b/linux/drivers/dts/index.html
index 50a5ccab..4e72bc3d 100644
--- a/linux/drivers/dts/index.html
+++ b/linux/drivers/dts/index.html
@@ -1299,6 +1299,10 @@
+
+
+
+
@@ -1355,7 +1359,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/drivers/framework/index.html b/linux/drivers/framework/index.html
index ab4ec537..ed1eec6c 100644
--- a/linux/drivers/framework/index.html
+++ b/linux/drivers/framework/index.html
@@ -1287,6 +1287,10 @@
+
+
+
+
@@ -1343,7 +1347,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/drivers/index.html b/linux/drivers/index.html
index 1a4e6660..1cefa622 100644
--- a/linux/drivers/index.html
+++ b/linux/drivers/index.html
@@ -1223,6 +1223,10 @@
+
+
+
+
@@ -1279,7 +1283,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/index.html b/linux/index.html
index aacf64b7..87729f6d 100644
--- a/linux/index.html
+++ b/linux/index.html
@@ -1221,6 +1221,10 @@
+
+
+
+
@@ -1277,7 +1281,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/index.html b/linux/kernel/index.html
index ab2c3b8b..cfc80c49 100644
--- a/linux/kernel/index.html
+++ b/linux/kernel/index.html
@@ -1223,6 +1223,10 @@
+
+
+
+
@@ -1279,7 +1283,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/interrupt/index.html b/linux/kernel/interrupt/index.html
index b7149231..c6122382 100644
--- a/linux/kernel/interrupt/index.html
+++ b/linux/kernel/interrupt/index.html
@@ -1416,6 +1416,10 @@
+
+
+
+
@@ -1472,7 +1476,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/mm/index.html b/linux/kernel/mm/index.html
index 961d06ba..2fac32d2 100644
--- a/linux/kernel/mm/index.html
+++ b/linux/kernel/mm/index.html
@@ -1317,6 +1317,10 @@
+
+
+
+
@@ -1373,7 +1377,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/others/index.html b/linux/kernel/others/index.html
index f3da6f08..d0ddffb5 100644
--- a/linux/kernel/others/index.html
+++ b/linux/kernel/others/index.html
@@ -1356,6 +1356,10 @@
+
+
+
+
@@ -1412,7 +1416,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/sched/index.html b/linux/kernel/sched/index.html
index d38d168a..4d34f371 100644
--- a/linux/kernel/sched/index.html
+++ b/linux/kernel/sched/index.html
@@ -1467,6 +1467,10 @@
+
+
+
+
@@ -1523,7 +1527,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/synch/index.html b/linux/kernel/synch/index.html
index fd724d8a..d0c10419 100644
--- a/linux/kernel/synch/index.html
+++ b/linux/kernel/synch/index.html
@@ -1401,6 +1401,10 @@
+
+
+
+
@@ -1457,7 +1461,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/linux/kernel/vma/index.html b/linux/kernel/vma/index.html
index e8a2e44a..b3ad9b67 100644
--- a/linux/kernel/vma/index.html
+++ b/linux/kernel/vma/index.html
@@ -1323,6 +1323,10 @@
+
+
+
+
@@ -1379,7 +1383,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/others/index.html b/others/index.html
index 1561d071..b4e9bc72 100644
--- a/others/index.html
+++ b/others/index.html
@@ -15,7 +15,7 @@
-
+
@@ -1219,6 +1219,10 @@
+
+
+
+
@@ -1275,7 +1279,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/others/ld/index.html b/others/ld/index.html
index 161a37ec..b5d1da06 100644
--- a/others/ld/index.html
+++ b/others/ld/index.html
@@ -1217,6 +1217,10 @@
+
+
+
+
@@ -1273,7 +1277,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/pl/index.html b/pl/index.html
index 2a3fadd2..20c0d0f3 100644
--- a/pl/index.html
+++ b/pl/index.html
@@ -1221,6 +1221,10 @@
+
+
+
+
@@ -1277,7 +1281,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/rtos/freertos/CMSIS/index.html b/rtos/freertos/CMSIS/index.html
index 82202ea4..469b17eb 100644
--- a/rtos/freertos/CMSIS/index.html
+++ b/rtos/freertos/CMSIS/index.html
@@ -1333,6 +1333,10 @@
+
+
+
+
@@ -1389,7 +1393,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/rtos/freertos/index.html b/rtos/freertos/index.html
index 9ce99ce4..ee49761c 100644
--- a/rtos/freertos/index.html
+++ b/rtos/freertos/index.html
@@ -1223,6 +1223,10 @@
+
+
+
+
@@ -1279,7 +1283,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/rtos/index.html b/rtos/index.html
index 4684be42..e7513021 100644
--- a/rtos/index.html
+++ b/rtos/index.html
@@ -1221,6 +1221,10 @@
+
+
+
+
@@ -1277,7 +1281,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/rtos/rt-thread/index.html b/rtos/rt-thread/index.html
index b94da9f5..19aec947 100644
--- a/rtos/rt-thread/index.html
+++ b/rtos/rt-thread/index.html
@@ -1223,6 +1223,10 @@
+
+
+
+
@@ -1279,7 +1283,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
diff --git a/search/search_index.json b/search/search_index.json
index af067773..88fef47d 100644
--- a/search/search_index.json
+++ b/search/search_index.json
@@ -1 +1 @@
-{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":""},{"location":"#_1","title":"\u6b22\u8fce\u6765\u5230\u6211\u7684\u9891\u9053","text":"\u6ca1\u6709\u5b66\u672f\u7684\u6c11\u4e3b\u548c\u601d\u60f3\u7684\u81ea\u7531\uff0c\u79d1\u5b66\u5c31\u4e0d\u80fd\u7e41\u8363\u3002 \u2014\u2014\u2014\u20142003\u7248\u9ad8\u4e00\u7269\u7406\u5fc5\u4fee\u4e00\u8bfe\u672c
\u8fd9\u91cc\u4e3b\u8981\u5206\u4eab\u6211\u7684\u5b66\u4e60\u7b14\u8bb0\u548c\u5fc3\u5f97\u4f53\u4f1a\uff0c\u53c2\u8003\u8d44\u6599\u4e8e\u6bcf\u4e2a\u4e3b\u9875\u9762\u5217\u51fa\u3002
"},{"location":"#_2","title":"\u5feb\u901f\u5bfc\u822a","text":" Linux
RTOS
Arm
\u7f16\u7a0b\u8bed\u8a00
\u4e91\u539f\u751f
Tools
\u5176\u4ed6
"},{"location":"#inspired-by","title":"Inspired by:","text":" CS\u81ea\u5b66\u6307\u5357 \u4e0a\u6d77\u4ea4\u901a\u5927\u5b66\u751f\u5b58\u624b\u518c "},{"location":"arm/","title":"Arm\u5b66\u4e60\u7b14\u8bb0","text":""},{"location":"arm/barrier/","title":"\u5185\u5b58\u5c4f\u969c","text":""},{"location":"linux/","title":"\u5feb\u901f\u5165\u95e8","text":"Linux\u7684\u77e5\u8bc6\u4f53\u7cfb\u592a\u8fc7\u5e9e\u5927\uff0c\u4f46\u662f\u5165\u95e8\u5e76\u4e0d\u96be\uff0c\u4e13\u6ce8\u4e8e\u57fa\u7840\u547d\u4ee4\u548cLinux\u73af\u5883\u4e0b\u7684C\u7f16\u7a0b\uff0c\u5bf9\u4e8e\u6253\u4e0b\u57fa\u7840\u975e\u5e38\u91cd\u8981\u3002
\u9996\u5148\uff0c\u4f60\u9700\u8981\u4e00\u4e2a\u5b89\u88c5\u4e86ubuntu\u6216\u8005\u5176\u4ed6\u53d1\u884c\u7248\u7684\u865a\u62df\u673a\uff0c\u4f46\u6211\u66f4\u52a0\u63a8\u8350\u4f60\u7528\u4e91\u670d\u52a1\u5668\u6765\u5b66\u4e60Linux\uff0c\u56e0\u4e3a\uff1a
\u4e91\u670d\u52a1\u5668\u901a\u5e38\u4e0d\u63d0\u4f9b\u684c\u9762\u754c\u9762\uff0c\u8fd9\u53ef\u4ee5\u8feb\u4f7f\u4f60\u66f4\u6df1\u5165\u5730\u7406\u89e3\u5e76\u638c\u63e1\u5404\u79cd\u547d\u4ee4\u884c\u64cd\u4f5c\u3002 \u7531\u4e8e\u4e91\u670d\u52a1\u5668\u901a\u5e38\u9700\u8981\u4ed8\u8d39\uff0c\u4f60\u4f1a\u66f4\u52a0\u73cd\u60dc\u8fd9\u4e2a\u5b66\u4e60\u673a\u4f1a\uff0c\u5e76\u6295\u5165\u66f4\u591a\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u53bb\u5b66\u4e60\u3002 \u4e91\u670d\u52a1\u5668\u53ea\u9700\u8981\u4f60\u7535\u8111\u80fd\u8054\u7f51\u5c31\u53ef\u4ee5\u64cd\u4f5c\uff0c\u800c\u865a\u62df\u673a\u5bf9\u4e8e\u4e00\u822c\u7684\u8f7b\u8584\u672c\u6765\u8bf4\u662f\u4e2a\u4e0d\u5c0f\u7684\u8d1f\u62c5\u3002 \u4e91\u670d\u52a1\u5668\u5bf9\u4e8e\u7f51\u7edc\u73af\u5883\u505a\u4e86\u4f18\u5316\uff0c\u5e76\u4e14\u5404\u5927\u670d\u52a1\u5668\u5382\u5546\u63d0\u4f9b\u4e86\u4e00\u952e\u914d\u7f6e\u73af\u5883\u7684\u529f\u80fd\uff0c\u4f7f\u7528\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\u3002 \u5f53\u4f60\u8d2d\u4e70\u4e86\u4e91\u670d\u52a1\u5668\u4e4b\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7SSH\u8fdc\u7a0b\u8fde\u63a5\u5230\u670d\u52a1\u5668\uff0cVSCODE\u7684SSH\u63d2\u4ef6\u53ef\u4ee5\u8fdb\u884c\u8fdc\u7a0b\u5f00\u53d1\uff0c\u4f53\u9a8c\u4e0e\u672c\u5730\u5f00\u53d1\u65e0\u5f02\u3002\u5177\u4f53\u7684\u6b65\u9aa4\u4f60\u53ef\u4ee5\u53c2\u8003\u7f51\u4e0a\u7684\u76f8\u5173\u6559\u7a0b\u3002
\u4e00\u65e6\u4f60\u6210\u529f\u8fdb\u5165Linux\u73af\u5883\uff0c\u9996\u5148\u5e94\u8be5\u6267\u884c\u7684\u662fsudo apt update
\u548csudo apt upgrade
\u547d\u4ee4\uff0c\u4ee5\u66f4\u65b0\u4f60\u7684\u8f6f\u4ef6\u5305\u3002\u5b89\u88c5\u8f6f\u4ef6\u5305\u53ef\u4ee5\u4f7f\u7528sudo apt install [pkg_name]
\u547d\u4ee4\u3002\u5982\u679c\u4f60\u662f\u5728\u672c\u5730\u865a\u62df\u673a\u4e0a\u64cd\u4f5c\uff0c\u5efa\u8bae\u5728\u66f4\u65b0\u8f6f\u4ef6\u5305\u524d\u5c06\u8f6f\u4ef6\u6e90\u66f4\u6362\u4e3a\u56fd\u5185\u7684\u955c\u50cf\u6e90\uff0c\u4ee5\u83b7\u5f97\u66f4\u5feb\u7684\u4e0b\u8f7d\u901f\u5ea6\u3002
\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e0b\uff0c\u4f60\u9700\u8981\u719f\u7ec3\u638c\u63e1\u5927\u7ea6\u5341\u51e0\u4e2a\u57fa\u7840\u547d\u4ee4\uff0c\u5176\u4ed6\u547d\u4ee4\u53ef\u4ee5\u5728\u9700\u8981\u65f6\u518d\u67e5\u8be2\uff0c\u65e0\u9700\u4e13\u95e8\u8bb0\u5fc6\u3002\u540c\u65f6\uff0c\u4f60\u8fd8\u9700\u8981\u7406\u89e3\u7ba1\u9053\u548c\u91cd\u5b9a\u5411\u7684\u6982\u5ff5\u3002
\u4e3a\u4e86\u5728\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0b\u7f16\u8f91\u6587\u4ef6\uff0c\u4f60\u81f3\u5c11\u9700\u8981\u719f\u6089\u4e00\u79cd\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f8b\u5982VIM\u3002\u4f46\u4e0d\u8981\u671f\u671b\u4e00\u5f00\u59cb\u5c31\u80fd\u719f\u7ec3\u4f7f\u7528VIM\uff0c\u8fd9\u662f\u4e00\u4e2a\u9010\u6b65\u5b66\u4e60\u7684\u8fc7\u7a0b\u3002\u8bb0\u4f4f\uff0c\u5de5\u5177\u662f\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0c\u5982\u679c\u5b83\u964d\u4f4e\u4e86\u4f60\u7684\u6548\u7387\uff0c\u90a3\u4e48\u6682\u65f6\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6\u66f4\u9002\u5408\u4f60\u7684\u7f16\u8f91\u5668\u3002
\u8bf7\u505c\u6b62\u4f7f\u7528\u201cRUN\u201d\u6309\u94ae\u6765\u8fd0\u884c\u7a0b\u5e8f\uff0c\u800c\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u7f16\u8bd1\u4f60\u7684\u6e90\u4ee3\u7801\u3002\u4e86\u89e3GCC\u5982\u4f55\u5c06\u4f60\u7684\u4ee3\u7801\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u53ca\u591a\u4e2a\u6587\u4ef6\u662f\u5982\u4f55\u94fe\u63a5\u6210\u4e00\u4e2a\u7a0b\u5e8f\u7684\u8fc7\u7a0b\uff0c\u8fd9\u4e9b\u77e5\u8bc6\u5c06\u968f\u7740\u4f60\u7684\u6df1\u5165\u5b66\u4e60\u800c\u9010\u6e10\u638c\u63e1\u3002
\u968f\u7740\u6e90\u6587\u4ef6\u6570\u91cf\u7684\u589e\u52a0\u548c\u9879\u76ee\u5de5\u7a0b\u7684\u590d\u6742\u5316\uff0c\u624b\u52a8\u8f93\u5165\u5197\u957f\u7684GCC\u547d\u4ee4\u4f1a\u53d8\u5f97\u4f4e\u6548\u3002\u8fd9\u65f6\uff0c\u4f60\u9700\u8981\u4f7f\u7528Makefile\u6587\u4ef6\u6765\u7ec4\u7ec7\u4f60\u7684\u5de5\u7a0b\u3002\u4e3a\u4e86\u7f16\u5199Makefile\u6587\u4ef6\uff0c\u4f60\u9700\u8981\u4e86\u89e3\u5176\u57fa\u672c\u8bed\u6cd5\u3002\u4e0d\u8fc7\uff0c\u6211\u66f4\u63a8\u8350\u4f60\u4f7f\u7528CMake\u5de5\u5177\uff0c\u5b83\u80fd\u591f\u4e00\u952e\u751f\u6210Makefile\uff0c\u5e76\u4e14\u5176\u8bed\u6cd5\u66f4\u52a0\u76f4\u89c2\u6613\u61c2\uff0c\u7279\u522b\u9002\u5408\u7ba1\u7406\u5927\u578b\u9879\u76ee\u3002
\u5230\u8fbe\u8fd9\u4e00\u6b65\uff0c\u4f60\u5df2\u7ecf\u5bf9Linux\u73af\u5883\u4e0b\u7684C\u7f16\u7a0b\u6709\u4e86\u521d\u6b65\u7684\u8ba4\u8bc6\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u9700\u8981\u719f\u6089Linux\u63d0\u4f9b\u7684C\u5e93\u51fd\u6570\uff0c\u5305\u62ec\u6587\u4ef6\u64cd\u4f5c\u3001\u8f93\u5165\u8f93\u51fa\u3001\u8fdb\u7a0b\u63a7\u5236\u3001\u591a\u7ebf\u7a0b\u540c\u6b65\u7b49\u3002\u8fd9\u4e9b\u5185\u5bb9\u5728\u8bb8\u591a\u4e66\u7c4d\u548c\u89c6\u9891\u4e2d\u90fd\u6709\u8be6\u7ec6\u7684\u8bb2\u89e3\u3002
\u4ee5\u4e0a\u5185\u5bb9\u6784\u6210\u4e86Linux C\u5f00\u53d1\u7684\u57fa\u7840\u3002\u5bf9\u4e8e\u66f4\u6df1\u5165\u7684\u5b66\u4e60\uff0c\u8bf7\u6839\u636e\u4e2a\u4eba\u5174\u8da3\u548c\u9700\u6c42\u81ea\u884c\u67e5\u627e\u76f8\u5173\u8d44\u6599\u3002
"},{"location":"linux/#_2","title":"\u53c2\u8003\u8d44\u6599","text":" \u8da3\u8c08Linux\u64cd\u4f5c\u7cfb\u7edf
\u6df1\u5165Linux\u5185\u6838\u67b6\u6784
\u7cbe\u901a\u5d4c\u5165\u5f0fLinux\u7f16\u7a0b
\u6df1\u5165\u7406\u89e3LINUX\u5185\u6838(\u7b2c3\u7248)
Linux\u5185\u6838\u8bbe\u8ba1\u4e0e\u5b9e\u73b0(\u7b2c3\u7248)
UNIX\u73af\u5883\u9ad8\u7ea7\u7f16\u7a0b\uff08\u7b2c3\u7248)
Linux\u547d\u4ee4\u884c\u4e0eshell\u811a\u672c\u7f16\u7a0b\u5927\u5168\uff08\u7b2c4\u7248)
\u91ce\u706bLinux\u5f00\u53d1\u5b9e\u6218\u6307\u5357
\u8717\u58f3\u79d1\u6280
"},{"location":"linux/drivers/","title":"\u8bbe\u5907\u6a21\u578b","text":"\u7531\u4e8eLinux\u652f\u6301\u4e16\u754c\u4e0a\u51e0\u4e4e\u6240\u6709\u7684\u3001\u4e0d\u540c\u529f\u80fd\u7684\u786c\u4ef6\u8bbe\u5907\uff0c\u5bfc\u81f4Linux\u5185\u6838\u4e2d\u6709\u4e00\u534a\u7684\u4ee3\u7801\u90fd\u662f\u8bbe\u5907\u9a71\u52a8\u3002\u968f\u7740\u786c\u4ef6\u7684\u5feb\u901f\u8fed\u4ee3\uff0c\u8bbe\u5907\u9a71\u52a8\u7684\u4ee3\u7801\u4e5f\u5728\u5feb\u901f\u589e\u957f\u3002
\u4e3a\u4e86\u964d\u4f4e\u8bbe\u5907\u7684\u591a\u6837\u6027\u5e26\u6765\u7684\u9a71\u52a8\u5f00\u53d1\u7684\u590d\u6742\u5ea6\uff0cLinux\u63d0\u51fa\u4e86\u8bbe\u5907\u6a21\u578b\uff08device model\uff09\u7684\u6982\u5ff5\uff0c\u8be5\u6a21\u578b\u5c06\u8bbe\u5907\u548c\u9a71\u52a8\u5206\u5c42\uff0c\u628a\u6211\u4eec\u7f16\u5199\u7684\u9a71\u52a8\u4ee3\u7801\u5206\u6210\u4e86\u4e24\u5757\uff1a\u8bbe\u5907\u4e0e\u9a71\u52a8\u3002\u8bbe\u5907\u8d1f\u8d23\u63d0\u4f9b\u786c\u4ef6\u8d44\u6e90\u800c\u9a71\u52a8\u8d1f\u8d23\u53bb\u4f7f\u7528\u8bbe\u5907\u63d0\u4f9b\u7684\u786c\u4ef6\u8d44\u6e90\u3002\u4e8c\u8005\u7531\u603b\u7ebf\u5173\u8054\u8d77\u6765\u3002
\u8bbe\u5907\u6a21\u578b\u901a\u8fc7\u51e0\u4e2a\u6570\u636e\u7ed3\u6784\u6765\u53cd\u6620\u5f53\u524d\u7cfb\u7edf\u4e2d\u603b\u7ebf\u3001\u8bbe\u5907\u4ee5\u53ca\u9a71\u52a8\u5de5\u4f5c\u7684\u60c5\u51b5\uff1a
\u603b\u7ebf(bus)\uff1a\u603b\u7ebf\u662fCPU\u548c\u8bbe\u5907\u4e4b\u95f4\u4fe1\u606f\u4ea4\u4e92\u7684\u901a\u9053\uff0c\u6240\u6709\u7684\u8bbe\u5907\u90fd\u5e94\u8fde\u63a5\u5230\u603b\u7ebf\u4e0a\uff0c\u65e0\u8bba\u662fCPU\u5185\u90e8\u603b\u7ebf\u8fd8\u662f\u865a\u62df\u603b\u7ebf\u3002
\u7c7b\uff08class\uff09\uff1a\u9762\u5411\u5bf9\u8c61\u601d\u60f3\uff0c\u5c06\u76f8\u540c\u529f\u80fd\u7684\u8bbe\u5907\uff0c\u5f52\u7ed3\u5230\u4e00\u79cdclass\u7edf\u4e00\u7ba1\u7406\u3002
\u8bbe\u5907\uff08device\uff09\uff1a\u6302\u8f7d\u5728\u603b\u7ebf\u7684\u7269\u7406\u8bbe\u5907\u3002
\u9a71\u52a8\uff08driver\uff09\uff1a\u786c\u4ef6\u8bbe\u5907\u7684\u9a71\u52a8\u7a0b\u5e8f\uff0c\u8d1f\u8d23\u521d\u59cb\u5316\u8bbe\u5907\u4ee5\u53ca\u5b9e\u73b0\u8be5\u8bbe\u5907\u7684\u4e00\u4e9b\u63a5\u53e3\u51fd\u6570\u3002
platform bus\u662f\u5185\u6838\u4e2d\u7684\u4e00\u79cd\u865a\u62df\u603b\u7ebf\u7c7b\u578b\uff0c\u5b83\u4e0d\u662f\u7269\u7406\u4e0a\u5b58\u5728\u7684\u603b\u7ebf\uff0c\u800c\u662f\u4e00\u79cd\u62bd\u8c61\u7684\u603b\u7ebf\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4ee5\u4e00\u79cd\u6807\u51c6\u7684\u65b9\u5f0f\u6765\u63cf\u8ff0\u548c\u7ba1\u7406\u90a3\u4e9b\u4e0d\u901a\u8fc7\u4f20\u7edf\u7269\u7406\u603b\u7ebf\u8fde\u63a5\u7684\u8bbe\u5907\u3002
Linux\u5185\u6838\u4f7f\u7528sysfs\u6587\u4ef6\u7cfb\u7edf\u5c06\u5185\u6838\u7684\u8bbe\u5907\u9a71\u52a8\u5bfc\u51fa\u5230\u7528\u6237\u7a7a\u95f4\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee/sys\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff0c\u6765\u67e5\u770b\u751a\u81f3\u63a7\u5236\u5185\u6838\u7684\u4e00\u4e9b\u9a71\u52a8\u8bbe\u5907\u3002
/sys\u6587\u4ef6\u76ee\u5f55\u8bb0\u5f55\u4e86\u5404\u4e2a\u8bbe\u5907\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5176\u4e2d\uff0c/sys/bus\u76ee\u5f55\u4e0b\u7684\u6bcf\u4e2a\u5b50\u76ee\u5f55\u90fd\u662f\u5df2\u7ecf\u6ce8\u518c\u7684\u603b\u7ebf\u7c7b\u578b\u3002\u6bcf\u4e2a\u603b\u7ebf\u7c7b\u578b\u4e0b\u8fd8\u6709\u4e24\u4e2a\u6587\u4ef6\u5939\u2014\u2014devices\u548cdrivers\uff1bdevices\u662f\u8be5\u603b\u7ebf\u7c7b\u578b\u4e0b\u7684\u6240\u6709\u8bbe\u5907\uff0c\u4ee5\u7b26\u53f7\u94fe\u63a5\u7684\u5f62\u5f0f\u6307\u5411\u771f\u6b63\u7684\u8bbe\u5907\uff08/sys/devices/\uff09\u3002\u800cdrivers\u662f\u6240\u6709\u6ce8\u518c\u5728\u8fd9\u4e2a\u603b\u7ebf\u7c7b\u578b\u4e0a\u7684\u9a71\u52a8\u3002
/sys/devices\u76ee\u5f55\u4e0b\u662f\u5168\u5c40\u7684\u8bbe\u5907\u7ed3\u6784\u4f53\u7cfb\uff0c\u5305\u542b\u4e86\u6240\u6709\u6ce8\u518c\u5728\u5404\u7c7b\u603b\u7ebf\u4e0a\u7684\u7269\u7406\u8bbe\u5907\u3002\u6240\u6709\u7684\u7269\u7406\u8bbe\u5907\u4ee5\u603b\u7ebf\u62d3\u6251\u7684\u7ed3\u6784\u6765\u663e\u793a\u3002
/sys/class\u76ee\u5f55\u4e0b\u662f\u5305\u542b\u6240\u6709\u6ce8\u518c\u5728\u5185\u6838\u4e2d\u7684\u8bbe\u5907\u7c7b\u578b\uff0c\u6309\u7167\u8bbe\u5907\u7684\u529f\u80fd\u8fdb\u884c\u5206\u7c7b\u3002\u6bd4\u5982\u9f20\u6807\u7684\u529f\u80fd\u662f\u4f5c\u4e3a\u4eba\u673a\u4ea4\u4e92\u7684\u8f93\u5165\uff0c\u4e8e\u662f\u88ab\u5f52\u7c7b\u5230/sys/class/input\u76ee\u5f55\u4e0b\u3002
\u90a3\u4e48\u201c\u603b\u7ebf-\u8bbe\u5907-\u9a71\u52a8\u201d\u662f\u5982\u4f55\u914d\u5408\u5de5\u4f5c\u7684\u5462\uff1f
\u5728\u603b\u7ebf\u4e0a\u6302\u8f7d\u4e86\u4e24\u4e2a\u94fe\u8868\uff0c\u5206\u522b\u7ba1\u7406\u8bbe\u5907\u6a21\u578b\u548c\u9a71\u52a8\u6a21\u578b\u3002\u5f53\u6211\u4eec\u5411\u7cfb\u7edf\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\u65f6\uff0c\u4fbf\u4f1a\u5728\u8bbe\u5907\u7684\u94fe\u8868\u4e2d\u63d2\u5165\u65b0\u7684\u8bbe\u5907\u3002\u5728\u63d2\u5165\u7684\u540c\u65f6\u603b\u7ebf\u4f1a\u6267\u884cmatch()
\u65b9\u6cd5\u5bf9\u65b0\u63d2\u5165\u7684\u8bbe\u5907/\u9a71\u52a8\u8fdb\u884c\u914d\u5bf9\u3002\u82e5\u914d\u5bf9\u6210\u529f\u5219\u8c03\u7528probe()
\u65b9\u6cd5\u83b7\u53d6\u8bbe\u5907\u8d44\u6e90\uff0c\u5728\u79fb\u9664\u8bbe\u5907/\u9a71\u52a8\u65f6\uff0c\u8c03\u7528remove()
\u65b9\u6cd5\u3002
"},{"location":"linux/drivers/#kobjectktypekset","title":"kobject\u3001ktype\u548ckset","text":"kobject\u662fLinux\u8bbe\u5907\u6a21\u578b\u7684\u57fa\u7840\uff0c\u662f\u4e00\u79cd\u62bd\u8c61\u7684\u3001\u7edf\u4e00\u7684\u5bf9\u5927\u91cf\u786c\u4ef6\u8bbe\u5907\u7684\u63cf\u8ff0\u3002\u5b83\u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u529f\u80fd\uff1a
\u901a\u8fc7parent\u6307\u9488\uff0c\u5c06\u6240\u6709kobject\u4ee5\u6811\u72b6\u7ed3\u6784\u7684\u5f62\u5f0f\u7ec4\u5408\u8d77\u6765\u3002 \u4f7f\u7528\u5f15\u7528\u8ba1\u6570kref\uff0c\u6765\u8bb0\u5f55kobject\u88ab\u5f15\u7528\u7684\u6b21\u6570\uff0c\u5728\u8ba1\u6570\u4e3a0\u65f6\u91ca\u653e\u5b83\u3002 \u548csysfs\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u914d\u5408\uff0c\u5c06\u6bcf\u4e00\u4e2akobject\u7684\u7279\u6027\uff0c\u4ee5\u6587\u4ef6\u7684\u5f62\u5f0f\u5f00\u653e\u7ed9\u7528\u6237\u7a7a\u95f4\u67e5\u8be2\u3002 \u8bbe\u5907\u9a71\u52a8\u6a21\u578b\u7684\u57fa\u672c\u5143\u7d20\u6709\u4e09\u4e2a\uff1a
kobject\uff1asysfs\u4e2d\u7684\u4e00\u4e2a\u76ee\u5f55\uff0c\u8868\u793a\u57fa\u672c\u9a71\u52a8\u5bf9\u8c61\u3002 kset\uff1a\u4e00\u4e2a\u7279\u6b8a\u7684kobject\uff0c\u7528\u6765\u7ba1\u7406\u7c7b\u4f3c\u7684kobject\u3002 ktype\uff1a\u76ee\u5f55\u4e0bkobject\u5c5e\u6027\u6587\u4ef6\u64cd\u4f5c\u7684\u63a5\u53e3\u3002 kobject\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct kobject {\n const char *name;\n struct list_head entry;\n struct kobject *parent;\n struct kset *kset;\n struct kobj_type *ktype;\n struct kernfs_node *sd; /* sysfs directory entry */\n struct kref kref;\n unsigned int state_initialized:1;\n unsigned int state_in_sysfs:1;\n unsigned int state_add_uevent_sent:1;\n unsigned int state_remove_uevent_sent:1;\n unsigned int uevent_suppress:1;\n};\n
name\uff1akobject\u7684\u540d\u79f0\uff0c\u540c\u65f6\u4e5f\u662fsysfs\u4e2d\u7684\u76ee\u5f55\u540d\u79f0\u3002\u5f53kobject\u6dfb\u52a0\u5230\u5185\u6838\u65f6\uff0c\u9700\u8981\u6839\u636ename\u6ce8\u518c\u5230sysfs\u4e2d\u3002
entry\uff1a\u7528\u4e8e\u5c06kobject\u52a0\u5165\u5230\u94fe\u8868\u4e2d\u3002
parent\uff1a\u6307\u5411\u7236kobject\u7684\u6307\u9488\uff0c\u5728sysfs\u4e2d\u6839\u636e\u5c42\u6b21\u7ed3\u6784\u663e\u793a\u4e3a\u76ee\u5f55\u7ed3\u6784\u3002
kset\uff1a\u8be5kobject\u5c5e\u4e8e\u7684kset\u3002\u82e5\u8be5kobject\u672a\u6307\u5b9aparent\uff0c\u5219\u4f1a\u628akset\u4f5c\u4e3aparent\u3002
ktype\uff1a\u8be5kobject\u5c5e\u4e8e\u7684kobj_type\uff0c\u6bcf\u4e2akobject\u5fc5\u987b\u6709\u4e00\u4e2aktype\u3002
sd\uff1a\u8be5kobject\u5728sysfs\u4e2d\u7684\u5bf9\u5e94\u76ee\u5f55\u9879\u3002
kref\uff1a\u539f\u5b50\u5f15\u7528\u8ba1\u6570\u3002
state_initialized\uff1a\u6307\u793a\u8be5kobject\u662f\u5426\u5df2\u7ecf\u521d\u59cb\u5316\u3002
state_in_sysfs\uff1a\u6307\u793a\u8be5kobject\u662f\u5426\u5df2\u5728sysfs\u4e2d\u5efa\u7acb\u76ee\u5f55\u3002
state_add_uevent_sent/state_remove_uevent_sent\uff1a\u8bb0\u5f55\u662f\u5426\u5df2\u5411\u7528\u6237\u7a7a\u95f4\u53d1\u9001add uevent\u3002
uevent_suppress\uff1a\u5982\u679c\u8be5\u5b57\u6bb5\u4e3a1\uff0c\u5219\u8868\u793a\u5ffd\u7565\u6240\u6709\u4e0a\u62a5\u7684uevent\u4e8b\u4ef6\u3002
kobject\u6838\u5fc3\u673a\u5236\uff1a
\u5185\u5d4c\u5728\u522b\u7684\u6570\u636e\u7ed3\u6784\uff08\u6bd4\u5982device_driver\uff09\u4e2d\uff0c\u5f53kobject\u4e2d\u7684\u5f15\u7528\u8ba1\u6570\u5f52\u96f6\u65f6\uff0c\u91ca\u653ekobject\u6240\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u540c\u65f6\u901a\u8fc7ktype\u4e2d\u7684release()
\u56de\u8c03\u51fd\u6570\uff0c\u91ca\u653e\u5185\u5d4c\u6570\u636e\u7ed3\u6784\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u6bcf\u4e00\u4e2a\u5185\u5d4ckobject\u7684\u6570\u636e\u7ed3\u6784\u90fd\u9700\u8981\u81ea\u5df1\u5b9e\u73b0ktype\u4e2d\u7684\u56de\u8c03\u51fd\u6570\u3002
ktype\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct kobj_type {\n void (*release)(struct kobject *kobj);\n const struct sysfs_ops *sysfs_ops;\n const struct attribute_group **default_groups;\n /*\u7701\u7565\u5176\u4ed6\u6210\u5458*/ \n};\n
release\uff1a\u5f53kobject\u5f15\u7528\u8ba1\u6570\u5f52\u96f6\u65f6\u8c03\u7528\u8be5\u6790\u6784\u51fd\u6570\uff0c\u8d1f\u8d23\u91ca\u653ekobject\u7684\u5185\u5b58\u3002
sysfs_ops\uff1asysfs\u6587\u4ef6\u7cfb\u7edf\u8bfb\u5199\u65f6\u7684\u7279\u6027\u3002
default_groups\uff1a\u5b9a\u4e49\u4e86kobject\u7684\u5c5e\u6027\uff0c\u7531struct attritube\u548cstruct bin_attribute\u6784\u6210\u3002
ktype\u7684\u5b58\u5728\u662f\u4e3a\u4e86\u63cf\u8ff0\u4e00\u65cfkobject\u6240\u5177\u6709\u7684\u666e\u904d\u7279\u6027\u3002\u8fd9\u6837\u5c31\u4e0d\u9700\u8981\u6bcf\u4e2akobject\u5b9a\u4e49\u81ea\u5df1\u7684\u7279\u6027\uff0c\u800c\u662f\u5728ktype\u4e2d\u7edf\u4e00\u5b9a\u4e49\u3002
kset\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct kset {\n struct list_head list;\n spinlock_t list_lock;\n struct kobject kobj;\n const struct kset_uevent_ops *uevent_ops;\n};\n
list/list_lock\uff1a\u7528\u4e8e\u4fdd\u5b58\u8be5kset\u4e0b\u6240\u6709kobject\u5bf9\u8c61\u3002
kobj\uff1a\u8be5kset\u81ea\u5df1\u7684kobject\u3002
uevent_ops\uff1auevent\u662f\u7528\u6237\u7a7a\u95f4\u7684\u7f29\u5199\uff0c\u63d0\u4f9b\u4e86\u4e0e\u7528\u6237\u7a7a\u95f4\u70ed\u63d2\u62d4\u8fdb\u884c\u901a\u4fe1\u7684\u673a\u5236\u3002\u5f53\u4efb\u4f55kobject\u9700\u8981\u4e0a\u62a5uevent\u65f6\uff0c\u90fd\u8981\u8c03\u7528\u6240\u5c5e\u7684kset\u4e2duevent_ops\u4e2d\u7684\u51fd\u6570\u3002uevent\u7684\u6982\u5ff5\u7a0d\u540e\u8bf4\u660e\u3002
kset\u662fkobject\u5bf9\u8c61\u7684\u96c6\u5408\u4f53\u3002\u5b83\u4e0ektype\u7684\u533a\u522b\u5728\u4e8e\uff1a\u5177\u6709\u76f8\u540cktype\u7684kobject\u53ef\u4ee5\u88ab\u5206\u7ec4\u5230\u4e0d\u540c\u7684kset\u3002
"},{"location":"linux/drivers/#sysfs","title":"sysfs","text":"sysfs\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u4e2a\u5904\u4e8e\u5185\u5b58\u4e2d\u7684\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u63d0\u4f9b\u4e86kobject\u5bf9\u8c61\u7684\u5c42\u6b21\u7ed3\u6784\u89c6\u56fe\u3002\u7528\u6237\u67e5\u8be2\u7cfb\u7edf\u4e2d\u5404\u79cd\u8bbe\u5907\u7684\u62d3\u6251\u7ed3\u6784\uff0c\u5c31\u50cf\u67e5\u8be2\u6587\u4ef6\u76ee\u5f55\u4e00\u6837\u7b80\u5355\u3002\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5bfc\u51fa\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u5c06\u5185\u6838\u53d8\u91cf\u63d0\u4f9b\u7ed9\u7528\u6237\u8bfb\u53d6\u6216\u8005\u5199\u5165\u3002
sysfs\u7684\u6838\u5fc3\u662f\u628akobject\u5bf9\u8c61\u4e0e\u76ee\u5f55\u9879\uff08directory entries\uff09\u5173\u8054\u8d77\u6765\uff0c\u8fd9\u70b9\u662f\u901a\u8fc7kobject\u7ed3\u6784\u4f53\u4e2d\u7684dentry\u5b57\u6bb5\u5b9e\u73b0\u7684\u3002\u8fd9\u79cd\u5173\u8054\u5c06kobject\u5bf9\u8c61\u6620\u5c04\u5230\u8be5\u76ee\u5f55\u4e0a\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u67e5\u770b\u6302\u8f7d\u4e8e/sys\u76ee\u5f55\u4e0b\u7684\u6574\u4e2a\u6587\u4ef6\u7cfb\u7edf\u89c6\u56fe\u3002\u5411sysfs\u4e2d\u6dfb\u52a0kobject\uff0c\u53ef\u4ee5\u4f7f\u7528kobject_add()
\u548ckobject_create_and_add()
\u51fd\u6570\u3002
\u5728/sys\u76ee\u5f55\u4e0b\u6302\u8f7d\u4e86\u81f3\u5c1111\u4e2a\u76ee\u5f55\uff1ablock, bus, class, dev, devices, firmware, fs, hypervisor, kernel, module, power\u3002\u5176\u4e2d\u6700\u91cd\u8981\u7684\u76ee\u5f55\u662fdevices\uff0c\u8be5\u76ee\u5f55\u5c06\u8bbe\u5907\u6a21\u578b\u5bfc\u51fa\u5230\u7528\u6237\u7a7a\u95f4\u3002\u5176\u76ee\u5f55\u673a\u6784\u5c31\u662f\u7cfb\u7edf\u4e2d\u5b9e\u9645\u7684\u8bbe\u5907\u62d3\u6251\u7ed3\u6784\u3002\u5176\u4ed6\u76ee\u5f55\u4e2d\u7684\u8bb8\u591a\u6570\u636e\u90fd\u662f\u5c06devices\u76ee\u5f55\u4e0b\u7684\u6570\u636e\u52a0\u4ee5\u8f6c\u6362\u52a0\u5de5\u6240\u5f97\u3002
\u6211\u4eec\u5df2\u7ecf\u77e5\u9053kobject\u53ef\u4ee5\u88ab\u6620\u5c04\u4e3a\u67d0\u4e2a\u6587\u4ef6\u76ee\u5f55\uff0c\u4ec5\u6709\u5982\u6b64\u8fd8\u4e0d\u591f\u3002\u56e0\u4e3a\u8fd9\u6837\u7684sysfs\u4ec5\u4ec5\u53ea\u662f\u4e00\u9897\u6811\uff0c\u4f46\u6ca1\u6709\u63d0\u4f9b\u5b9e\u9645\u6570\u636e\u7684\u6587\u4ef6\u3002\u4e3a\u4e86\u80fd\u591f\u8bfb\u5199\u8fd9\u9897\u6811\uff0c\u5185\u6838\u63d0\u4f9b\u4e86attribute
\u548cbin_attribute
\u4e24\u79cd\u5c5e\u6027\u3002
\u5728ktype\u4e2d\u7528struct attribute_group
\u63cf\u8ff0\u8fd9\u4e24\u4e2a\u5c5e\u6027\uff1a
struct attribute_group {\n const char *name;\n struct attribute **attrs;\n struct bin_attribute **bin_attrs;\n};\n\n/*attribute\u548cbin_attribute\u7684\u5b9a\u4e49\u5982\u4e0b*/\n\nstruct attribute {\n const char *name;\n umode_t mode;\n};\n\nstruct bin_attribute {\n struct attribute attr;\n size_t size;\n void *private;\n struct address_space *(*f_mapping)(void);\n ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,\n char *, loff_t, size_t);\n ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,\n char *, loff_t, size_t);\n int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,\n struct vm_area_struct *vma);\n};\n
struct attribute
\u4e3a\u666e\u901a\u7684attribute\uff0c\u4f7f\u7528\u8be5attribute\u751f\u6210\u7684sysfs\u6587\u4ef6\uff0c\u53ea\u80fd\u7528\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u8bfb\u5199\u3002\u800cstruct bin_attribute
\u5728struct attribute
\u7684\u57fa\u7840\u4e0a\uff0c\u589e\u52a0\u4e86read()
\u3001write()
\u7b49\u51fd\u6570\uff0c\u56e0\u6b64\u5b83\u6240\u751f\u6210\u7684sysfs\u6587\u4ef6\u53ef\u4ee5\u7528\u4efb\u4f55\u65b9\u5f0f\u8bfb\u5199\u3002
"},{"location":"linux/drivers/#uevent","title":"uevent","text":"uevent\u662fkobject\u529f\u80fd\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u5728kobject\u72b6\u6001\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u6bd4\u5982\u6dfb\u52a0\u3001\u79fb\u9664\uff0c\u901a\u77e5\u7528\u6237\u7a7a\u95f4\u3002\u7528\u6237\u7a7a\u95f4\u6536\u5230\u8baf\u606f\u540e\uff0c\u505a\u51fa\u76f8\u5e94\u7684\u5904\u7406\u3002
\u8be5\u673a\u5236\u901a\u5e38\u662f\u7528\u6765\u652f\u6301\u70ed\u63d2\u62d4\uff08hotplug\uff09\u8bbe\u5907\u7684\uff0c\u4f8b\u5982\u5f53U\u76d8\u63d2\u5165\u540e\uff0cUSB\u76f8\u5173\u7684\u9a71\u52a8\u4f1a\u52a8\u6001\u521b\u5efa\u7528\u4e8e\u8868\u793a\u8be5U\u76d8\u7684device\u7ed3\u6784\uff0c\u5e76\u544a\u77e5\u7528\u6237\u7a7a\u95f4\u4e3a\u8be5U\u76d8\u52a8\u6001\u521b\u5efa/dev/\u76ee\u5f55\u4e0b\u7684\u8bbe\u5907\u8282\u70b9\u3002
uevent\u673a\u5236\u6bd4\u8f83\u7b80\u5355\uff0c\u5f53\u8bbe\u5907\u6a21\u578b\u4e2d\u4efb\u4f55\u8bbe\u5907\u6709\u4e8b\u4ef6\u9700\u8981\u4e0a\u62a5\u65f6\uff0c\u90fd\u4f1a\u89e6\u53d1uevent\u63d0\u4f9b\u7684\u63a5\u53e3\u3002uevent\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7\u4e24\u4e2a\u9014\u5f84\u628a\u4e8b\u4ef6\u4e0a\u62a5\u5230\u7528\u6237\u7a7a\u95f4\uff1a\u4e00\u79cd\u662f\u901a\u8fc7kmod\u6a21\u5757\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7netlink\u901a\u4fe1\u673a\u5236\u3002
uevent\u7684\u4ee3\u7801\u4e3b\u8981\u4f4d\u4e8ekobject.h\u548ckobject_uevent.c\u4e24\u4e2a\u6587\u4ef6\u3002
kobject_action
\u5b9a\u4e49\u4e86uevent\u7684\u7c7b\u578b\uff1a
enum kobject_action {\n KOBJ_ADD,\n KOBJ_REMOVE,\n KOBJ_CHANGE,\n KOBJ_MOVE,\n KOBJ_ONLINE,\n KOBJ_OFFLINE,\n KOBJ_BIND,\n KOBJ_UNBIND,\n};\n
ADD/REMOVE\uff1akobject\u7684\u6dfb\u52a0/\u79fb\u9664\u4e8b\u4ef6\u3002
CHANGE\uff1akobject\u72b6\u6001\u6216\u8005\u5185\u5bb9\u53d1\u751f\u6539\u53d8\u3002
MOVE\uff1akobject\u66f4\u6539\u540d\u79f0\u6216\u8005\u66f4\u6539\u4e86parent\u3002
ONLINE/OFFLINE\uff1akobject\u7684\u4e0a\u7ebf/\u4e0b\u7ebf\u4e8b\u4ef6
BIND/UNBIND\uff1akobject\u7684\u7ed1\u5b9a/\u89e3\u7ed1\u4e8b\u4ef6
kobj_uevent_env
\u5b9a\u4e49\u4e86\u4e8b\u4ef6\u4e0a\u62a5\u65f6\u7684\u73af\u5883\u53d8\u91cf\uff1a
struct kobj_uevent_env {\n char *argv[3];\n char *envp[UEVENT_NUM_ENVP];\n int envp_idx;\n char buf[UEVENT_BUFFER_SIZE];\n int buflen;\n};\n
argv\uff1a\u6307\u9488\u6570\u7ec4\uff0c\u53ef\u4ee5\u4fdd\u5b58\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u6700\u5927\u4e3a3\u4e2a\u3002
envp\uff1a\u6307\u9488\u6570\u7ec4\uff0c\u7528\u4e8e\u4fdd\u5b58\u6bcf\u4e2a\u73af\u5883\u53d8\u91cf\u7684\u5730\u5740\u3002
envp_idx\uff1a\u8bbf\u95eeenvp\u6570\u7ec4\u7684\u7d22\u5f15\u3002
buf\uff1a\u4fdd\u5b58uevent\u6d88\u606f\u7684\u7f13\u51b2\u533a
buflen\uff1a\u5b58\u50a8\u7f13\u51b2\u533a\u7684\u5927\u5c0f
kset_uevent_ops
\u5b9a\u4e49\u4e86kset\u7684uevent\u63a5\u53e3\u64cd\u4f5c\uff1a
struct kset_uevent_ops {\n int (* const filter)(struct kset *kset, struct kobject *kobj);\n const char *(* const name)(struct kset *kset, struct kobject *kobj);\n int (* const uevent)(struct kset *kset, struct kobject *kobj, struct kobj_uevent_env *env);\n};\n
filter\uff1a\u5f53kobject\u9700\u8981\u4e0a\u62a5uevent\u65f6\uff0c\u5b83\u6240\u5c5e\u7684kset\u53ef\u4ee5\u901a\u8fc7\u6b64\u63a5\u53e3\u8fc7\u6ee4\u6389\u4e0d\u5e0c\u671b\u4e0a\u62a5\u7684uevent\u3002
name\uff1a\u7528\u4e8e\u83b7\u53d6kset\u4e2dkobject\u7684uevent\u540d\u79f0\uff0c\u8fd9\u4e2a\u540d\u79f0\u901a\u5e38\u4e0euevent\u4e2d\u7684ACTION\u5b57\u6bb5\u76f8\u5bf9\u5e94\u3002
uevent\uff1a\u5f53\u4e00\u4e2akobject\u9700\u8981\u4e0a\u62a5uevent\u65f6\uff0cuevent\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff0c\u5b83\u53ef\u4ee5\u4e3auevent\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u3002
uevent\u7684\u4e00\u4e9b\u64cd\u4f5cAPI\uff1a
int kobject_uevent(struct kobject *kobj, enum kobject_action action);\nint kobject_uevent_env(struct kobject *kobj, enum kobject_action action, char *envp[]);\nint kobject_synth_uevent(struct kobject *kobj, const char *buf, size_t count);\nint add_uevent_var(struct kobj_uevent_env *env, const char *format, ...);\n
kobject_uevent_env\uff1a\u4ee5envp\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u4e0a\u62a5\u4e00\u4e2a\u6307\u5b9aaction\u7684uevent\u3002
kobject_synth_uevent\uff1a\u5141\u8bb8\u53d1\u9001\u4e00\u4e2a\u5408\u6210\u7684uevent\u3002
add_uevent_var\uff1a\u4ee5\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\uff0c\u5411uevent\u6dfb\u52a0\u65b0\u7684\u73af\u5883\u53d8\u91cf\u3002
"},{"location":"linux/drivers/#devicedevice_driver","title":"device\u548cdevice_driver","text":"device
\u548cdevice_driver
\u662fLinux\u9a71\u52a8\u5f00\u53d1\u7684\u57fa\u672c\u6982\u5ff5\u3002\u9a71\u52a8\u5f00\u53d1\uff0c\u5176\u5b9e\u5c31\u662f\u5f00\u53d1\u6307\u5b9a\u7684\u8f6f\u4ef6\uff08driver\uff09\u4ee5\u53ca\u9a71\u52a8\u6307\u5b9a\u7684\u8bbe\u5907\uff08device\uff09\u3002\u5185\u6838\u4e3a\u6b64\u5b9a\u4e49\u4e86\u4e24\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5206\u522b\u662fstruct device
\u548cstruct device_driver
\u3002
Linux\u8bbe\u5907\u6a21\u578b\u6846\u67b6\u4f53\u7cfb\u4e0b\u5f00\u53d1\uff0c\u4e3b\u8981\u5305\u62ec\u4e24\u4e2a\u6b65\u9aa4\uff1a
\u5206\u914d\u4e00\u4e2astruct device
\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u586b\u5145\u4fe1\u606f\uff0c\u7136\u540e\u5c06\u5176\u6ce8\u518c\u5230\u5185\u6838\u3002
\u5206\u914d\u4e00\u4e2astruct device_driver
\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u586b\u5145\u4fe1\u606f\uff0c\u7136\u540e\u5c06\u5176\u6ce8\u518c\u5230\u5185\u6838\u3002
\u8bbe\u5907\u9a71\u52a8\u7684\u6267\u884c\u903b\u8f91\uff0c\u7531\u56de\u8c03\u51fd\u6570\u5b9e\u73b0\u3002\u5f00\u53d1\u4eba\u5458\u53ea\u9700\u8981\u505a\u586b\u7a7a\u9898\u5373\u53ef\u3002
\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cLinux\u9a71\u52a8\u5f00\u53d1\u5f88\u5c11\u76f4\u63a5\u64cd\u4f5c\u4e0a\u9762\u4e24\u4e2a\u7ed3\u6784\u4f53\uff0c\u56e0\u4e3a\u5185\u6838\u53c8\u5c01\u88c5\u4e86\u4e00\u5c42\uff0c\u6bd4\u5982platform_device
\uff0c\u5c01\u88c5\u540e\u7684\u63a5\u53e3\u66f4\u4e3a\u7b80\u5355\u6613\u7528\u3002device
\u548cdevice_driver
\u5fc5\u987b\u6302\u5728\u5728\u540c\u4e00\u4e2abus\u4e4b\u4e0b\uff0c\u540d\u79f0\u4e5f\u5fc5\u987b\u4e00\u6837\uff0c\u5185\u6838\u624d\u80fd\u5b8c\u6210\u5339\u914d\u64cd\u4f5c\u3002
\u5982\u679c\u5b58\u5728\u76f8\u540c\u540d\u79f0\u7684device
\u548cdevice_driver
\uff0c\u5185\u6838\u5c31\u4f1a\u6267\u884cdevice_driver
\u4e2d\u7684probe()
\u56de\u8c03\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u662f\u6240\u6709driver
\u7684\u5165\u53e3\u51fd\u6570\uff0c\u7528\u6765\u6267\u884c\u8bf8\u5982\u786c\u4ef6\u8bbe\u5907\u521d\u59cb\u5316\u3001\u5b57\u7b26\u8bbe\u5907\u6ce8\u518c\u3001\u6587\u4ef6\u64cd\u4f5cops\u6ce8\u518c\u7b49\u52a8\u4f5c\uff08\u5bf9\u5e94remove()
\u51fd\u6570\uff09\u3002
"},{"location":"linux/drivers/#bus","title":"bus","text":"\u603b\u7ebf\u662f\u8fde\u63a5\u5904\u7406\u5668\u548c\u8bbe\u5907\u4e4b\u95f4\u7684\u901a\u9053\u3002\u4e3a\u4e86\u65b9\u4fbf\u8bbe\u5907\u6a21\u578b\u7684\u5b9e\u73b0\uff0c\u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a\u8bbe\u5907\u90fd\u9700\u8981\u8fde\u63a5\u5728\u4e00\u4e2a\u603b\u7ebf\u4e0a\uff0c\u8fd9\u4e2a\u603b\u7ebf\u53ef\u4ee5\u662f\u5185\u90e8\u603b\u7ebf\u3001\u865a\u62df\u603b\u7ebf\u6216\u8005\u662f\u5e73\u53f0\u603b\u7ebf\u3002
\u603b\u7ebf\u9a71\u52a8\u5219\u8d1f\u8d23\u5b9e\u73b0\u603b\u7ebf\u7684\u5404\u79cd\u884c\u4e3a\uff0c\u5176\u7ba1\u7406\u7740\u4e24\u4e2a\u94fe\u8868\uff0c\u5206\u522b\u662f\u6dfb\u52a0\u5230\u8be5\u603b\u7ebf\u7684\u8bbe\u5907\u94fe\u8868\u4ee5\u53ca\u6ce8\u518c\u5230\u8be5\u603b\u7ebf\u7684\u9a71\u52a8\u94fe\u8868\u3002\u5f53\u4f60\u5411\u603b\u7ebf\u6dfb\u52a0\uff08\u79fb\u9664\uff09\u4e00\u4e2a\u8bbe\u5907\uff08\u9a71\u52a8\uff09\u65f6\uff0c\u4fbf\u4f1a\u5728\u5bf9\u5e94\u7684\u5217\u8868\u4e0a\u6dfb\u52a0\u65b0\u7684\u8282\u70b9\uff0c \u540c\u65f6\u5bf9\u6302\u8f7d\u5728\u8be5\u603b\u7ebf\u7684\u9a71\u52a8\u4ee5\u53ca\u8bbe\u5907\u8fdb\u884c\u5339\u914d\uff0c\u5728\u5339\u914d\u8fc7\u7a0b\u4e2d\u4f1a\u5ffd\u7565\u6389\u90a3\u4e9b\u5df2\u7ecf\u6709\u9a71\u52a8\u5339\u914d\u7684\u8bbe\u5907\u3002
\u5185\u6838\u7528struct bus_type
\u7ed3\u6784\u4f53\u62bd\u8c61\u51fa\u603b\u7ebf\uff1a
struct bus_type {\n const char *name;\n const char *dev_name;\n\n int (*match)(struct device *dev, struct device_driver *drv);\n int (*uevent)(struct device *dev, struct kobj_uevent_env *env);\n int (*probe)(struct device *dev);\n int (*remove)(struct device *dev);\n\n struct subsys_private *p;\n};\n
\u6211\u4eec\u53d1\u73b0bus_type
\u7ed3\u6784\u4f53\u4e2d\u7684\u5927\u90e8\u5206\u6210\u5458\u90fd\u4e0edevice
\u6709\u5173\uff0c\u8bf4\u660e\u5b83\u4e3b\u8981\u8d1f\u8d23\u8bbe\u5907\u7684\u6ce8\u518c\u548c\u6ce8\u9500\u7b49\u64cd\u4f5c\u3002
name\uff1a\u8be5bus\u7684\u540d\u79f0\uff0c\u5728sysfs\u4e2d\u4ee5\u76ee\u5f55\u5f62\u5f0f\u5b58\u5728\uff0c\u6bd4\u5982platform bus\u8868\u73b0\u4e3a/sys/bus/platform\u3002
dev_name\uff1a\u6ce8\u518c\u5230bus\u7684\u8bbe\u5907\u540d\u79f0\u3002
match\uff1a\u5f53\u5c5e\u4e8e\u8be5bus\u7684device\u6216\u8005device_driver\u6dfb\u52a0\u5230\u5185\u6838\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u3002
uevent\uff1a\u5f53\u5c5e\u4e8e\u8be5bus\u7684device\uff0c\u53d1\u751f\u6dfb\u52a0\u3001\u79fb\u9664\u6216\u8005\u5176\u4ed6\u52a8\u4f5c\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u3002
probe\u3001remove\uff1a\u5f53\u5c5e\u4e8e\u8be5bus\u7684device\uff0c\u53d1\u751f\u521d\u59cb\u5316\u548c\u79fb\u9664\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u3002
p\uff1a\u4fdd\u5b58\u4e86bus\u6a21\u5757\u7684\u4e00\u4e9b\u79c1\u6709\u6570\u636e\u3002
bus\u6a21\u5757\u7684\u4e3b\u8981\u529f\u80fd\u662f\uff1a
bus\u7684\u6ce8\u518c\u548c\u6ce8\u9500 \u672cbus\u4e0b\u6709device\u6216\u8005device_driver\u6ce8\u518c\u5230\u5185\u6838\u65f6\u7684\u5904\u7406 \u672cbus\u4e0b\u6709device\u6216\u8005device_driver\u4ece\u5185\u6838\u6ce8\u9500\u65f6\u7684\u5904\u7406 device_driver\u7684probe \u7ba1\u7406bus\u4e0b\u6240\u6709\u7684device\u548cdevice_driver \u5185\u6838\u63d0\u4f9b\u4e86bus_register()
\u51fd\u6570\u6765\u6ce8\u518c\u603b\u7ebf\uff0cbus_unregister()
\u51fd\u6570\u6765\u6ce8\u9500\u603b\u7ebf\u3002
int bus_register(struct bus_type *bus);\n\nvoid bus_unregister(struct bus_type *bus);\n
\u5f53\u6211\u4eec\u6210\u529f\u6ce8\u518c\u603b\u7ebf\u65f6\uff0c\u4f1a\u5728/sys/bus/\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u76ee\u5f55\uff0c\u76ee\u5f55\u540d\u4e3a\u6211\u4eec\u65b0\u6ce8\u518c\u7684\u603b\u7ebf\u540d\u3002bus\u76ee\u5f55\u4e2d\u5305\u542b\u4e86\u5f53\u524d\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u6ce8\u518c\u4e86\u7684\u6240\u6709\u603b\u7ebf\uff0c\u4f8b\u5982i2c\uff0cspi\uff0cplatform\u7b49\u3002
"},{"location":"linux/drivers/#class","title":"class","text":"\u5728\u672c\u6587\u7684\u5f00\u5934\u6211\u4eec\u63d0\u5230\uff0cclass\u662f\u7528\u6765\u7edf\u4e00\u7ba1\u7406\u76f8\u540c\u529f\u80fd\u7684\u8bbe\u5907\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u6bcf\u4e2a\u8bbe\u5907\u9a71\u52a8\u5b9e\u73b0\u91cd\u590d\u7684\u529f\u80fd\u3002
struct class {\n const char *name;\n struct module *owner;\n\n const struct attribute_group **class_groups;\n const struct attribute_group **dev_groups;\n struct kobject *dev_kobj;\n\n int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);\n char *(*devnode)(struct device *dev, umode_t *mode);\n\n void (*class_release)(struct class *class);\n void (*dev_release)(struct device *dev);\n\n int (*shutdown_pre)(struct device *dev);\n\n const struct kobj_ns_type_operations *ns_type;\n const void *(*namespace)(struct device *dev);\n\n void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);\n\n const struct dev_pm_ops *pm;\n\n struct subsys_private *p;\n};\n
name\uff1aclass\u7684\u540d\u79f0\uff0c\u4f53\u73b0\u5728/sys/class\u76ee\u5f55\u4e0b\u3002
class_groups\uff1aclass\u5c5e\u6027\u3002
dev_groups\uff1adev\u5c5e\u6027\u3002
dev_uevent\uff1a\u8bbe\u5907\u7684uevent\u56de\u8c03\u51fd\u6570\u3002
class_release/dev_release\uff1arelease\u56de\u8c03\u51fd\u6570\u3002
pm\uff1a\u7535\u6e90\u7ba1\u7406\u7684\u56de\u8c03\u51fd\u6570\u3002
p\uff1a\u79c1\u6709\u6570\u636e\u3002
struct class_interface
\u5b9a\u4e49\u4e86\u5f53\u524dclass\u4e0b\u6709\u8bbe\u5907\u6dfb\u52a0\u6216\u8005\u79fb\u9664\u65f6\uff0c\u53ef\u4ee5\u8c03\u7528\u7684\u56de\u8c03\u51fd\u6570\uff1a
struct class_interface {\n struct list_head node;\n struct class *class;\n\n int (*add_dev) (struct device *, struct class_interface *);\n void (*remove_dev) (struct device *, struct class_interface *);\n};\n
class\u7684\u6ce8\u518c/\u6ce8\u9500\u51fd\u6570\u5982\u4e0b\uff1a
int __must_check __class_register(struct class *class, struct lock_class_key *key);\nvoid class_unregister(struct class *class);\n
class\u7684\u6982\u5ff5\u6bd4\u8f83\u62bd\u8c61\uff0c\u540e\u7eed\uff0c\u5728\u5404\u7c7b\u5b50\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u80fd\u770b\u5230\u8bb8\u591aclass\u7684\u7528\u4f8b\u3002
"},{"location":"linux/drivers/#_2","title":"\u5e73\u53f0\u8bbe\u5907\u9a71\u52a8","text":"\u5bf9\u4e8eI2C\u3001SPI\u3001USB\u8fd9\u4e9b\u5e38\u89c1\u7684\u8bbe\u5907\u6765\u8bf4\uff0cLinux\u5185\u6838\u90fd\u4f1a\u521b\u5efa\u4e0e\u4e4b\u76f8\u5bf9\u5e94\u7684\u9a71\u52a8\u603b\u7ebf\u3002\u4f46\u662f\u6709\u4e9b\u7ed3\u6784\u7b80\u5355\u7684\u8bbe\u5907\uff0c\u6bd4\u5982led\u3001rtc\u65f6\u949f\u3001\u8702\u9e23\u5668\u7b49\uff0c\u5185\u6838\u5c31\u4e0d\u4f1a\u81ea\u5df1\u521b\u5efa\u9a71\u52a8\u603b\u7ebf\u3002\u4e3a\u4e86\u4f7f\u8fd9\u90e8\u5206\u8bbe\u5907\u7684\u9a71\u52a8\u5f00\u53d1\u4e5f\u80fd\u9075\u5faa\u8bbe\u5907\u9a71\u52a8\u6a21\u578b\uff0cLinux\u5185\u6838\u5f15\u5165\u4e86\u865a\u62df\u7684\u603b\u7ebf\u2014\u2014\u5e73\u53f0\u603b\u7ebf\uff08platform bus\uff09\u3002\u5e73\u53f0\u603b\u7ebf\u7528\u4e8e\u7ba1\u7406\u548c\u6302\u8f7d\u90a3\u4e9b\u6ca1\u6709\u76f8\u5e94\u7269\u7406\u603b\u7ebf\u7684\u8bbe\u5907\uff0c\u8fd9\u4e9b\u8bbe\u5907\u88ab\u79f0\u4e3a\u5e73\u53f0\u8bbe\u5907\uff0c\u5bf9\u5e94\u7684\u8bbe\u5907\u9a71\u52a8\u88ab\u79f0\u4e3a\u5e73\u53f0\u9a71\u52a8\u3002\u5e73\u53f0\u8bbe\u5907\u5bf9\u4e8eLinux\u9a71\u52a8\u5de5\u7a0b\u5e08\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u4e3a\u5927\u591a\u6570\u7684\u9a71\u52a8\u4ee3\u7801\uff0c\u5b9e\u9645\u5c31\u662f\u4e3a\u4e86\u9a71\u52a8\u5e73\u53f0\u8bbe\u5907\u3002
Platform\u67b6\u6784\u56fe\u5982\u4e0b\u6240\u793a\uff1a
\u4ece\u56fe\u7247\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff1a
platform bus\uff1a\u7ee7\u627f\u81eabus\u6a21\u5757\uff0c\u7528\u4e8e\u6302\u8f7dplatform\u8bbe\u5907\u3002 platform device\uff1a\u7ee7\u627f\u81eadevice\u6a21\u5757\uff0c\u7528\u4e8e\u63cf\u8ff0platform\u8bbe\u5907\u3002 platform drvier\uff1a\u7ee7\u627f\u81eadevice_driver\u6a21\u5757\uff0c\u7528\u4e8e\u9a71\u52a8platform\u8bbe\u5907\u3002 "},{"location":"linux/drivers/#_3","title":"\u5e73\u53f0\u603b\u7ebf","text":"\u5728Linux\u5e73\u53f0\u8bbe\u5907\u9a71\u52a8\u6a21\u578b\u4e2d\uff0c\u603b\u7ebf\u662f\u6700\u91cd\u8981\u7684\u4e00\u73af\uff0c\u8d1f\u8d23\u5339\u914d\u8bbe\u5907\u548c\u9a71\u52a8\u3002\u5b83\u7ef4\u62a4\u7740\u4e24\u4e2a\u94fe\u8868\uff0c\u91cc\u9762\u8bb0\u5f55\u7740\u5404\u4e2a\u5df2\u7ecf\u6ce8\u518c\u7684\u5e73\u53f0\u8bbe\u5907\u548c\u5e73\u53f0\u9a71\u52a8\u3002\u6bcf\u5f53\u6709\u65b0\u7684\u8bbe\u5907\u6216\u8005\u662f\u9a71\u52a8\u52a0\u5165\u5230\u603b\u7ebf\u65f6\uff0c\u4fbf\u4f1a\u8c03\u7528platform_match()
\u51fd\u6570\u5bf9\u65b0\u589e\u7684\u8bbe\u5907\u6216\u9a71\u52a8\u8fdb\u884c\u914d\u5bf9\u3002\u5185\u6838\u4f7f\u7528struct bus_type platform_bus_type
\u6765\u63cf\u8ff0\u5e73\u53f0\u603b\u7ebf\uff0c\u8be5\u603b\u7ebf\u5728\u5185\u6838\u521d\u59cb\u5316\u7684\u65f6\u5019\u6ce8\u518c\uff1a
sturct bus_type platform_bus_type{\n .name = \"platform\",\n .dev_groups = platform_dev_groups,\n .match = platform_match,\n .uevent = platform_uevent,\n .pm = &platform_dev_pm_ops,\n};\n
\u5bf9platform_bus_typ
e\u7684\u521d\u59cb\u5316\u6765\u8bf4\uff0cmatch
\u51fd\u6570\u6307\u9488\u6700\u4e3a\u91cd\u8981\uff0c\u5b83\u6307\u5411\u7684\u51fd\u6570\u8d1f\u8d23\u5b9e\u73b0\u5e73\u53f0\u603b\u7ebf\u548c\u5e73\u53f0\u8bbe\u5907\u7684\u5339\u914d\u8fc7\u7a0b\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u9a71\u52a8\u603b\u7ebf\uff0c\u90fd\u5fc5\u987b\u5b9e\u4f8b\u5316\u8be5\u51fd\u6570\u6307\u9488\u3002
"},{"location":"linux/drivers/#_4","title":"\u5e73\u53f0\u8bbe\u5907","text":"\u5185\u6838\u4f7f\u7528platform_device
\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u5e73\u53f0\u8bbe\u5907\uff1a
struct platform_device {\n const char *name; //\u8bbe\u5907\u540d\u79f0\uff0c\u5339\u914d\u65f6\u4f1a\u6bd4\u8f83\u9a71\u52a8\u7684\u540d\u5b57\n int id; //\u5185\u6838\u5141\u8bb8\u5b58\u5728\u591a\u4e2a\n struct device dev; //\u7ee7\u627f\u7684device\u7ed3\u6784\u4f53\n u32 num_resources; //\u8bb0\u5f55\u8d44\u6e90\u7684\u6570\u76ee\n struct resource *resource; //\u5e73\u53f0\u8bbe\u5907\u63d0\u4f9b\u7ed9\u9a71\u52a8\u7684\u8d44\u6e90\n const struct platform_device_id *id_entry; \n };\n
\u5e73\u53f0\u8bbe\u5907\u7684\u5de5\u4f5c\u662f\u4e3a\u9a71\u52a8\u7a0b\u5e8f\u63d0\u4f9b\u8bbe\u5907\u4fe1\u606f,\u8bbe\u5907\u4fe1\u606f\u5305\u62ec\u786c\u4ef6\u4fe1\u606f\u548c\u8f6f\u4ef6\u4fe1\u606f\u4e24\u90e8\u5206\u3002
\u786c\u4ef6\u4fe1\u606f\uff1a\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528\u5230\u4ec0\u4e48\u5bc4\u5b58\u5668\uff0c\u5360\u7528\u54ea\u4e9b\u4e2d\u65ad\u53f7\u3001\u5185\u5b58\u8d44\u6e90\u3001IO\u53e3\u7b49\u7b49
\u8f6f\u4ef6\u4fe1\u606f\uff1a\u4ee5\u592a\u7f51\u5361\u8bbe\u5907\u4e2d\u7684MAC\u5730\u5740\u3001I2C\u8bbe\u5907\u4e2d\u7684\u8bbe\u5907\u5730\u5740\u3001SPI\u8bbe\u5907\u7684\u7247\u9009\u4fe1\u53f7\u7ebf\u7b49\u7b49
\u5bf9\u4e8e\u786c\u4ef6\u4fe1\u606f\uff0c\u4f7f\u7528\u7ed3\u6784\u4f53struct resource
\u6765\u4fdd\u5b58\u8bbe\u5907\u6240\u63d0\u4f9b\u7684\u8d44\u6e90\uff0c\u6bd4\u5982\u8bbe\u5907\u4f7f\u7528\u7684\u4e2d\u65ad\u7f16\u53f7\uff0c\u5bc4\u5b58\u5668\u7269\u7406\u5730\u5740\u7b49\uff0c\u7ed3\u6784\u4f53\u539f\u578b\u5982\u4e0b\uff1a
struct resource {\n resource_size_t start;\n resource_size_t end;\n const char *name;\n unsigned long flags;\n};\n
name\uff1a \u6307\u5b9a\u8d44\u6e90\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3aNULL\uff1b
start\u3001end\uff1a \u6307\u5b9a\u8d44\u6e90\u7684\u8d77\u59cb\u5730\u5740\u4ee5\u53ca\u7ed3\u675f\u5730\u5740
flags\uff1a \u7528\u4e8e\u6307\u5b9a\u8be5\u8d44\u6e90\u7684\u7c7b\u578b\uff0c\u5728Linux\u4e2d\uff0c\u8d44\u6e90\u5305\u62ecI/O\u3001Memory\u3001Register\u3001IRQ\u3001DMA\u3001Bus\u7b49\u591a\u79cd\u7c7b\u578b\uff0c\u6700\u5e38\u89c1\u7684\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a
\u8d44\u6e90\u5b8f\u5b9a\u4e49 \u63cf\u8ff0 IORESOURCE_IO \u7528\u4e8eIO\u5730\u5740\u7a7a\u95f4\uff0c\u5bf9\u5e94\u4e8eIO\u7aef\u53e3\u6620\u5c04\u65b9\u5f0f IORESOURCE_MEM \u7528\u4e8e\u5916\u8bbe\u7684\u53ef\u76f4\u63a5\u5bfb\u5740\u7684\u5730\u5740\u7a7a\u95f4 IORESOURCE_IRQ \u7528\u4e8e\u6307\u5b9a\u8be5\u8bbe\u5907\u4f7f\u7528\u67d0\u4e2a\u4e2d\u65ad IORESOURCE_DMA \u7528\u4e8e\u6307\u5b9a\u4f7f\u7528\u7684DMA\u901a\u9053 \u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u7684\u4e3b\u8981\u76ee\u7684\u662f\u64cd\u4f5c\u8bbe\u5907\u7684\u5bc4\u5b58\u5668\u3002\u4e0d\u540c\u67b6\u6784\u7684\u8ba1\u7b97\u673a\u63d0\u4f9b\u4e0d\u540c\u7684\u64cd\u4f5c\u63a5\u53e3\uff0c\u4e3b\u8981\u6709IO\u7aef\u53e3\u6620\u5c04\u548cIO\u5167\u5b58\u6620\u5c04\u4e24\u79cd\u65b9\u5f0f\u3002\u5bf9\u5e94\u4e8eIO\u7aef\u53e3\u6620\u5c04\u65b9\u5f0f\uff0c\u53ea\u80fd\u901a\u8fc7\u4e13\u95e8\u7684\u63a5\u53e3\u51fd\u6570\uff08\u5982inb\u3001outb\uff09\u624d\u80fd\u8bbf\u95ee\uff1b\u91c7\u7528IO\u5185\u5b58\u6620\u5c04\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u50cf\u8bbf\u95ee\u5185\u5b58\u4e00\u6837\uff0c\u53bb\u8bfb\u5199\u5bc4\u5b58\u5668\u3002\u5728\u5d4c\u5165\u5f0f\u4e2d\uff0c\u57fa\u672c\u4e0a\u6ca1\u6709IO\u5730\u5740\u7a7a\u95f4\uff0c\u6240\u4ee5\u901a\u5e38\u4f7f\u7528IORESOURCE_MEM\u3002
\u5728\u8d44\u6e90\u7684\u8d77\u59cb\u5730\u5740\u548c\u7ed3\u675f\u5730\u5740\u4e2d\uff0c\u5bf9\u4e8eIORESOURCE_IO\u6216\u8005\u662fIORESOURCE_MEM\uff0c\u4ed6\u4eec\u8868\u793a\u8981\u4f7f\u7528\u7684\u5185\u5b58\u7684\u8d77\u59cb\u4f4d\u7f6e\u4ee5\u53ca\u7ed3\u675f\u4f4d\u7f6e\uff1b\u82e5\u662f\u53ea\u7528\u4e00\u4e2a\u4e2d\u65ad\u5f15\u811a\u6216\u8005\u662f\u4e00\u4e2a\u901a\u9053\uff0c\u5219\u5b83\u4eec\u7684start\u548cend\u6210\u5458\u503c\u5fc5\u987b\u662f\u76f8\u7b49\u7684\u3002
\u6ce8\u518c/\u6ce8\u9500\u5e73\u53f0\u8bbe\u5907\u7528\u5230\u7684\u51fd\u6570\u5982\u4e0b\uff1a
int platform_device_register(struct platform_device *pdev);\nvoid platform_device_unregister(struct platform_device *pdev);\n
"},{"location":"linux/drivers/#_5","title":"\u5e73\u53f0\u9a71\u52a8","text":"\u5185\u6838\u4f7f\u7528platform_driver
\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u5e73\u53f0\u9a71\u52a8\uff1a
struct platform_driver {\n int (*probe)(struct platform_device *);\n int (*remove)(structg platform_device *);\n int (*suspend)(struct platform_device *, pm_message_t state);\n int (*resume)(struct platform_device *);\n struct device_driver driver;\n const struct platform_device_id *id_table;\n};\n
\u9664\u4e86\u63d0\u4f9b\u4e00\u4e9b\u56de\u8c03\u51fd\u6570\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2aid_table
\u7684\u6307\u9488\u3002\u8fd9\u4e2a\u6307\u9488\u7528\u6765\u8868\u793a\u8be5\u9a71\u52a8\u80fd\u591f\u517c\u5bb9\u7684\u8bbe\u5907\u7c7b\u578b\uff0c\u5f53\u8bbe\u5907\u8c03\u7528probe()
\u51fd\u6570\u65f6\uff0c\u5c31\u4f1a\u5230\u8fd9\u4e2a\u6570\u7ec4\u91cc\u68c0\u67e5\u662f\u5426\u5339\u914d\u3002
\u6211\u4eec\u770b\u4e00\u4e0bstruct platform_device_id
\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\uff1a
struct platform_device_id {\n char name[PLATFORM_NAME_SIZE];\n kernel_ulong_t driver_data;\n};\n
name\u7528\u4e8e\u6307\u5b9a\u9a71\u52a8\u7684\u540d\u79f0\uff0c\u603b\u7ebf\u8fdb\u884c\u5339\u914d\u65f6\uff0c\u4f1a\u6839\u636e\u8be5name\u6210\u5458\u4e0eplatform_device
\u4e2d\u7684name\u8fdb\u884c\u5339\u914d\u3002driver_data\u7528\u6765\u4fdd\u5b58\u8bbe\u5907\u7684\u914d\u7f6e\u3002\u4e3a\u4e86\u51cf\u5c11\u4ee3\u7801\u7684\u5197\u4f59\uff0c\u4e00\u4e2a\u9a71\u52a8\u53ef\u4ee5\u5339\u914d\u591a\u4e2a\u8bbe\u5907\u3002
\u6ce8\u518c/\u6ce8\u9500\u5e73\u53f0\u9a71\u52a8\u7684\u51fd\u6570\u5982\u4e0b\uff1a
int platform_driver_register(struct platform_device *drv);\nvoid platform_driver_unregister(struct platform_device *drv);\n
\u5728\u5e73\u53f0\u8bbe\u5907\u4e2d\uff0cstruct resource
\u7ed3\u6784\u4f53\u7528\u6765\u8868\u793a\u786c\u4ef6\u4fe1\u606f\uff0c\u800c\u8f6f\u4ef6\u4fe1\u606f\u5219\u53ef\u4ee5\u7528\u8bbe\u5907\u7ed3\u6784\u4f53device
\u4e2d\u7684\u6210\u5458platform_data\u6765\u4fdd\u5b58\u3002
platform_get_resource()
\u51fd\u6570\u901a\u5e38\u4f1a\u5728\u9a71\u52a8\u7684probe()
\u51fd\u6570\u4e2d\u6267\u884c\uff0c\u7528\u4e8e\u83b7\u53d6\u5e73\u53f0\u8bbe\u5907\u63d0\u4f9b\u7684\u8d44\u6e90\u7ed3\u6784\u4f53\uff0c\u6700\u7ec8\u8fd4\u56de\u4e00\u4e2astruct resource
\u7684\u6307\u9488\uff1a
struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num);\n
dev\uff1a\u6307\u5b9a\u8981\u83b7\u53d6\u7684\u5e73\u53f0\u8bbe\u5907\u3002
type\uff1a\u6307\u5b9a\u83b7\u53d6\u8d44\u6e90\u7684\u7c7b\u578b\uff0c\u6bd4\u5982IORESOURCE_IO\u3002
num\uff1a\u6307\u5b9a\u8981\u83b7\u53d6\u7684\u8d44\u6e90\u7f16\u53f7\u3002
\u5982\u679c\u8d44\u6e90\u7c7b\u578b\u662fIORESOURCE_IRQ\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u63a5\u53e3\u8fd8\u83b7\u53d6\u4e2d\u65ad\u5f15\u811a\uff1a
int platform_get_irq(struct platform_device *pdev, unsigned int num);\n
\u5bf9\u4e8e\u5b58\u653e\u5728device
\u7ed3\u6784\u4f53\u4e2dplatform_data\u7684\u8f6f\u4ef6\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528dev_get_platdata()
\u51fd\u6570\u6765\u83b7\u53d6\uff1a
static inline void *dev_get_platdata(const struct device *dev)\n{\n return dev->platform_data;\n}\n
\u603b\u7ed3\u4e00\u4e0b\u5e73\u53f0\u9a71\u52a8\uff1a\u9700\u8981\u5b9e\u73b0probe()
\u51fd\u6570\uff0c\u5f53\u5e73\u53f0\u603b\u7ebf\u6210\u529f\u5339\u914d\u9a71\u52a8\u548c\u8bbe\u5907\u65f6\uff0c\u5219\u4f1a\u8c03\u7528\u9a71\u52a8\u7684probe()
\u51fd\u6570\uff0c\u5728\u8be5\u51fd\u6570\u4e2d\u4f7f\u7528\u4e0a\u8ff0\u7684\u51fd\u6570\u63a5\u53e3\u6765\u83b7\u53d6\u8d44\u6e90\uff0c\u4ee5\u521d\u59cb\u5316\u8bbe\u5907\uff0c\u6700\u540e\u586b\u5145\u7ed3\u6784\u4f53platform_driver
\uff0c\u8c03\u7528platform_driver_register()
\u8fdb\u884c\u6ce8\u518c\u3002
"},{"location":"linux/drivers/chardev/","title":"\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f","text":"\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6846\u67b6\u5982\u56fe\u6240\u793a\uff1a
\u5728\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907\u7684\u65f6\u5019\uff0c\u9996\u5148\u5e94\u8be5\u5411\u5185\u6838\u7533\u8bf7\u4e00\u4e2a\u8bbe\u5907\u53f7\u3002\u62ff\u5230\u8bbe\u5907\u53f7\u4e4b\u540e\uff0c\u9700\u8981\u624b\u52a8\u5b9e\u73b0file_operation\u7ed3\u6784\u4f53\u4e2d\u7684\u51fd\u6570\u6307\u9488\uff0c\u5e76\u4fdd\u5b58\u5230cdev\u7ed3\u6784\u4f53\u4e2d\u3002\u7136\u540e\u4f7f\u7528cdev_add()
\u51fd\u6570\u6ce8\u518ccdev\u3002
\u6ce8\u9500\u8bbe\u5907\u65f6\u9700\u8981\u91ca\u653e\u5185\u6838\u4e2d\u7684cdev\uff0c\u5e76\u4e14\u5f52\u8fd8\u7533\u8bf7\u7684\u8bbe\u5907\u53f7\u3002
"},{"location":"linux/drivers/chardev/#_2","title":"\u5feb\u901f\u53c2\u8003","text":"#include <linux/types.h>\n\ndev_t devID\n\nint MAJOR(dev_t dev)\n\nint MINOR(dev_t dev)\n\ndev_t MKDEV(unsigned int major, unsigned int minor)\n
#include <linux/fs.h>\n\nint register_chrdev_region(dev_t first, unsigned int count, char *name)\n\nint alloc_chrdev_region(dev_t *dev, unsigned int firstminor, unsigned int count, char *name)\n\nvoid unregister_chrdev_region(dev_t first, unsigned int count)\n\nint register_chrdev(unsigned int major, const char *name, struct file_operations *fops)\n\nint unregister_chrdev(unsigned int major, const char *name)\n\nstruct file_operations\n\nstruct file\n\nstruct inode\n
#include <linux/cdev.h>\n\nstruct cdev *cdev_alloc(void)\n\nvoid cdev_init(struct cdev *dev, dev_t num, unsigned int count)\n\nint cdev_add(struct cdev *cdev, dev_t num, unsigned int count)\n\nvoid cdev_del(struct cdev *dev)\n
#include <linux/kernel.h>\n\ncontainer_of(pointer, type, field)\n\n#include <asm/uaccess.h>\n\nunsigned long copy_from_user(void *to, const void *from, unsigned long count)\n\nunsigned long copy_to_user(void *to, const void *from, unsigned long count)\n
"},{"location":"linux/drivers/chardev/#_3","title":"\u8bbe\u5907\u53f7\u521d\u59cb\u5316","text":""},{"location":"linux/drivers/chardev/#_4","title":"\u8bbe\u5907\u53f7\u7684\u6ce8\u518c\u4e0e\u5378\u8f7d(\u4e0d\u63a8\u8350\u7684\u505a\u6cd5)","text":" \u8fd9\u4e2a\u65b9\u6cd5\u5728\u6ce8\u518c\u65f6\u9700\u8981\u624b\u52a8\u6307\u5b9a\u4e3b\u8bbe\u5907\u53f7\uff0c\u56e0\u6b64\u4f60\u5fc5\u987b\u4e8b\u5148\u77e5\u9053\u54ea\u4e2a\u4e3b\u8bbe\u5907\u53f7\u6ca1\u6709\u88ab\u5360\u7528\uff0c\u8fd9\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u96be\u4ee5\u63a8\u5e7f\uff0c\u5e76\u4e14\u8be5\u51fd\u6570\u8fd8\u4e00\u6b21\u6027\u5360\u7528\u4e86\u4e3b\u8bbe\u5907\u53f7\u4e0b\u7684\u5168\u90e8\u6b21\u8bbe\u5907\u53f7\u3002
"},{"location":"linux/drivers/chardev/#_5","title":"\u8bbe\u5907\u53f7\u7684\u6ce8\u518c\u4e0e\u5378\u8f7d(\u63a8\u8350\u7684\u505a\u6cd5)","text":" int register_chrdev_region(dev_t first, unsigned count, const char *name)\n
first\u662f\u8981\u5206\u914d\u7684\u8bbe\u5907\u7f16\u53f7\u7684\u8d77\u59cb\u503c\uff0ccount\u662f\u6240\u8bf7\u6c42\u7684\u8fde\u7eed\u8bbe\u5907\u7f16\u53f7\u7684\u4e2a\u6570\uff0cname\u662f\u548c\u8be5\u7f16\u53f7\u8303\u56f4\u5173\u8054\u7684\u8bbe\u5907\u540d\u79f0\uff0c\u5b83\u5c06\u51fa\u73b0\u5728/proc/devices\u548csysfs\u4e2d\u3002
\u5982\u679c\u6211\u4eec\u63d0\u524d\u77e5\u9053\u6240\u9700\u8981\u7684\u8bbe\u5907\u7f16\u53f7\uff0c\u90a3\u4e48\u4f7f\u7528register_chrdev_region()
\u5c31\u591f\u4e86\u3002\u4f46\u662f\u5728\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff0c\u4e0d\u63a8\u8350\u8fd9\u4e48\u505a\uff0c\u800c\u5e94\u8be5\u4f7f\u7528\u52a8\u6001\u5206\u914d\u51fd\u6570\uff1a
int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name)\n
dev\u7528\u6765\u4fdd\u5b58\u4f60\u8981\u7533\u8bf7\u7684\u90a3\u4e2a\u8bbe\u5907\u53f7\u53d8\u91cf\uff0c baseminor\u662f\u6b21\u8bbe\u5907\u53f7\u7684\u8d77\u59cb\u503c\uff0c\u901a\u5e38\u662f0\u3002
\u9a71\u52a8\u7a0b\u5e8f\u5e94\u8be5\u59cb\u7ec8\u4f7f\u7528alloc_chrdev_region
\u800c\u4e0d\u662fregister_chrdev_region
\u2014\u2014\u2014\u2014\u300aLinux\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8fP50\u300b
\u4e0a\u9762\u4e24\u79cd\u65b9\u6cd5\u6ce8\u518c\u7684\u8bbe\u5907\u7edf\u4e00\u7528\u4ee5\u4e0b\u51fd\u6570\u5378\u8f7d\u3002
void unregister_chrdev_region(dev_t first, unsigned count)\n
\u8be5\u51fd\u6570\u901a\u5e38\u5728\u6e05\u9664\u51fd\u6570\u4e2d\u8c03\u7528\u3002
\u8fd9\u91cc\u6211\u4eec\u7ed9\u51fa\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u5047\u8bbe\u6211\u4eec\u9700\u8981\u6ce8\u518c\u4e00\u4e2a\u540d\u5b57\u4e3a\"test\"\u7684\u8bbe\u5907\u3002
int major;\nint minor;\ndev_t devid;\n\nif(major){\n devid = MKDEV(major, 0);\n register_chrdev_region(devid, 1, \"test\");\n}else {\n alloc_chrdev_region(&devid, 0, 1, \"test\");\n major = MAJOR(devid);\n minor = MINOR(devid);\n}\n
\u5bf9\u8bbe\u5907\u53f7\u64cd\u4f5c\u65f6\uff0c\u4f7f\u7528\u5230\u4e86\u4e09\u4e2a\u5b8f\u5b9a\u4e49\uff0cMKDEV, MAJOR, MINOR\u3002\u5f53\u7ed9\u5b9a\u4e3b\u8bbe\u5907\u53f7\u65f6\uff0c\u4f7f\u7528MKDEV\u6765\u6784\u5efa\u5b8c\u6574\u7684devID\uff0c\u6b21\u8bbe\u5907\u53f7\u5219\u4e00\u822c\u9009\u62e90\u3002
\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0cmajor\u53ef\u4ee5\u7528\u4e00\u4e2a\u5b8f\u5b9a\u4e49\u53d6\u4ee3\uff0c\u9ed8\u8ba4\u53d60\uff0c\u5373\u8d70else\u5206\u652f\u9009\u62e9\u201c\u52a8\u6001\u5206\u914d\u201d\u3002\u7528\u6237\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u9ed8\u8ba4\u503c\u5373\u52a8\u6001\u5206\u914d\u7684\u65b9\u5f0f\uff0c\u6216\u8005\u81ea\u5b9a\u4e49\u7279\u5b9a\u7684\u8bbe\u5907\u53f7\u2014\u2014\u53ea\u8981\u5728\u7f16\u8bd1\u524d\u4fee\u6539\u5b8f\u5b9a\u4e49\u4e3a\u8bbe\u5907\u53f7\uff0c\u6216\u8005\u5728insmod\u65f6\u6307\u5b9a\u5373\u53ef\u3002
"},{"location":"linux/drivers/chardev/#_6","title":"\u5b57\u7b26\u8bbe\u5907\u7684\u6ce8\u518c","text":"\u5185\u6838\u4f7f\u7528struct cdev\u7ed3\u6784\u6765\u8868\u793a\u5b57\u7b26\u8bbe\u5907\uff0c\u5f53\u6211\u4eec\u81ea\u5df1\u5b9e\u73b0file_operations\u7ed3\u6784\u4f53\u4e2d\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528cdev_init()
\u51fd\u6570\u6765\u5c06\u6587\u4ef6\u64cd\u4f5c\u6307\u9488\u4e0e\u5b57\u7b26\u8bbe\u5907\u76f8\u5173\u8054\u3002
void cdev_init(struct cdev *cdev, const struct file_operations *fops)\n
cdev_add()
\u51fd\u6570\u7528\u4e8e\u5411\u5185\u6838\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u8bbe\u5907\uff0ccdev_del()
\u51fd\u6570\u7528\u6765\u5220\u9664\u3002
int cdev_add(struct cdev *p, dev_t dev, unsigned count)\nvoid cdev_del(struct cdev *p)\n
"},{"location":"linux/drivers/chardev/#_7","title":"\u5185\u5b58\u6620\u5c04","text":""},{"location":"linux/drivers/chardev/#_8","title":"\u9a71\u52a8\u5c42\u7684\u64cd\u4f5c","text":"\u7531\u4e8eLinux\u6709MMU\u6a21\u5757\uff0c\u56e0\u6b64\u65e0\u6cd5\u8bbf\u95ee\u771f\u5b9e\u7684\u7269\u7406\u5730\u5740\uff0c\u53ea\u80fd\u901a\u8fc7\u865a\u62df\u5730\u5740\u8bbf\u95ee\u786c\u4ef6\u5916\u8bbe\u3002\u6240\u4ee5\u9700\u8981\u6709\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u5728\u7269\u7406\u5730\u5740\u548c\u865a\u62df\u5730\u5740\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u3002
\u5173\u4e8e\u5982\u4f55\u83b7\u53d6\u786c\u4ef6\u7684\u7269\u7406\u5730\u5740\uff0c\u8bf7\u53c2\u8003\u8bbe\u5907\u6811\u3002
\u5730\u5740\u6620\u5c04\u51fd\u6570\u5982\u4e0b\uff1a
void __iomem *ioremap(phys_addr_t paddr, unsigned long size)\n
\u5176\u4e2daddr\u5c31\u662f\u4f60\u8981\u8bbf\u95ee\u7684\u76f4\u63a5\u7269\u7406\u5730\u5740\uff0csize\u662f\u9700\u8981\u8f6c\u5316\u7684\u5927\u5c0f\uff0c\u8fd4\u56de\u503c\u5c31\u662f\u865a\u62df\u5730\u5740\uff0c\u8fd9\u4e2a\u865a\u62df\u5730\u5740\u6211\u4eec\u9700\u8981\u4e13\u95e8\u7684\u6570\u636e\u7c7b\u578b\u53bb\u63a5\u6536\u3002
\u53d6\u6d88\u5730\u5740\u6620\u5c04\u51fd\u6570\uff1a
void iounmap(void *addr)\n
"},{"location":"linux/drivers/chardev/#io","title":"I/O\u5185\u5b58\u8bbf\u95ee\u51fd\u6570","text":"\u4f7f\u7528ioremap\u51fd\u6570\u5c06\u5bc4\u5b58\u5668\u7269\u7406\u5730\u5740\u6620\u5c04\u5230\u865a\u62df\u5730\u5740\u540e\uff0cLinux\u63a8\u8350\u4f7f\u7528\u5185\u6838\u81ea\u5e26\u7684\u8bfb\u5199\u64cd\u4f5c\u51fd\u6570\u5bf9\u6620\u5c04\u540e\u7684\u5185\u5b58\u8fdb\u884c\u8bfb\u5199\u3002
unsigned int ioread8(void __iomem *addr)\nunsigned int iorea16(void __iomem *addr)\nunsigned int ioread32(void __iomem *addr)\n\nvoid iowrite8(u8 b, void __iomem *addr)\nvoid iowrite16(u16 b, void __iomem *addr)\nvoid iowrite32(u32 b, void __iomem *addr)\n
\u5bf9\u4e8e\u8bfbI/O\u800c\u8a00\uff0c\u8f93\u5165\u53c2\u6570\u4e3a__iomem\u7c7b\u578b\u7684\u6307\u9488\uff0c\u6307\u5411\u88ab\u6620\u5c04\u540e\u7684\u5730\u5740\uff0c\u8fd4\u56de\u503c\u4e3a\u8bfb\u53d6\u5230\u7684\u6570\u636e\uff1b\u5bf9\u4e8e\u5199I/O\u800c\u8a00\uff0c\u8f93\u5165\u53c2\u6570\u7b2c\u4e00\u4e2a\u4e3a\u8981\u5199\u5165\u7684\u6570\u636e\uff0c\u7b2c\u4e8c\u4e2a\u4e3a\u8981\u5199\u5165\u7684\u5730\u5740\uff0c\u8fd4\u56de\u503c\u4e3a\u7a7a\u3002
\u4e0b\u9762\u4e00\u6bb5\u4ee3\u7801\u6f14\u793a\u4e86\u5730\u5740\u6620\u5c04\u7684\u76f8\u5173\u64cd\u4f5c\uff1a
unsigned long pa_dr = 0x20A8000 + 0x00;\nunsigned int __iomem *va_dr;\nunsigned int val;\nva_dr = ioremap(pa_dr, 4);\nval = ioread32(va_dr);\nval &= ~(0x01 << 19);\niowrite32(val, va_dr);\n
"},{"location":"linux/drivers/chardev/#_9","title":"\u5e94\u7528\u5c42\u7684\u64cd\u4f5c","text":"\u7531\u4e8eLinux\u5185\u6838\u7981\u6b62\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u76f4\u63a5\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\uff0c\u6211\u4eec\u53ea\u80fd\u901a\u8fc7\u5185\u6838\u63d0\u4f9b\u7684API\u51fd\u6570\u8fdb\u884c\u3002
unsigned long copy_from_user(void *to, const void *from, unsigned long count)\n\nunsigned long copy_to_user(void *to, const void *from, unsigned long count)\n
"},{"location":"linux/drivers/dts/","title":"\u8bbe\u5907\u6811","text":""},{"location":"linux/drivers/dts/#_2","title":"\u4e3a\u4ec0\u4e48\u9700\u8981\u8bbe\u5907\u6811","text":"\u8d77\u56e0\u662f\u5728<arch/arm/mach-xxx>\u76ee\u5f55\u4e0b\u5145\u65a5\u7740\u5927\u91cf\u91cd\u590d\u7684board specific\u7684\u4ee3\u7801\uff0c\u6bcf\u6b21Linux\u5185\u6838merge window\u671f\u95f4\uff0cARM\u7684\u4ee3\u7801\u53d8\u5316\u5360\u6574\u4e2aarch\u76ee\u5f55\u7684\u4e00\u534a\u4ee5\u4e0a\uff0c\u5bfc\u81f4\u5185\u6838\u5341\u5206\u7684\u81c3\u80bf\u3002\u7ecf\u8fc7\u793e\u533a\u8ba8\u8bba\u540e\u51b3\u5b9a\uff1a
ARM\u7684\u6838\u5fc3\u4ee3\u7801\u4ecd\u7136\u4fdd\u5b58\u5728<arch/arm>\u76ee\u5f55\u4e0b ARM SOC\u5468\u8fb9\u5916\u8bbe\u6a21\u5757\u7684\u9a71\u52a8\u4ee3\u7801\u4fdd\u5b58\u5728drivers\u76ee\u5f55\u4e0b ARM SOC board specific\u7684\u4ee3\u7801\u88ab\u79fb\u9664\uff0c\u7531Device Tree\u673a\u5236\u6765\u8d1f\u8d23\u4f20\u9012\u786c\u4ef6\u8d44\u6e90\u4fe1\u606f\u3002 \u672c\u8d28\u4e0a\uff0cDevice Tree\u6539\u53d8\u4e86\u539f\u6765\u7528hardcode\u65b9\u5f0f\u5c06\u786c\u4ef6\u914d\u7f6e\u4fe1\u606f\u5d4c\u5165\u5230\u5185\u6838\u4ee3\u7801\u7684\u65b9\u6cd5\u3002\u5bf9\u4e8e\u5d4c\u5165\u5f0f\u7cfb\u7edf\uff0c\u5728\u7cfb\u7edf\u542f\u52a8\u9636\u6bb5\uff0c\u7531bootloader\u901a\u8fc7bootm\u547d\u4ee4\u5c06\u8bbe\u5907\u6811\u4fe1\u606f\u4f20\u9012\u7ed9\u5185\u6838\uff0c\u7136\u540e\u7531\u5185\u6838\u6765\u8bc6\u522b\uff0c\u5e76\u6839\u636e\u5b83\u5c55\u5f00\u51fa\u5185\u6838\u4e2d\u7684platform_device\u3001i2c_client\u3001spi_device\u7b49\u8bbe\u5907\uff0c\u8fd9\u4e9b\u8bbe\u5907\u7528\u5230\u7684\u5185\u5b58\u3001IRQ\u7b49\u8d44\u6e90\u4e5f\u4f1a\u88ab\u4f20\u9012\u7ed9\u5185\u6838\u3002
\u8bbe\u5907\u6811\u6587\u4ef6.dts\u7528\u6765\u63cf\u8ff0\u786c\u4ef6\u4fe1\u606f\u3002\u4e00\u4e2aSOC\u53ef\u4ee5\u5236\u4f5c\u5f88\u591a\u5f00\u53d1\u677f\uff0c\u5c06\u8fd9\u4e9b\u5f00\u53d1\u677f\u7684\u901a\u7528\u4fe1\u606f\u63d0\u53d6\u51fa\u6765\uff0c\u53d8\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684.dtsi\u6587\u4ef6\u3002\u5176\u4ed6\u7684.dts\u53ef\u4ee5\u76f4\u63a5\u5f15\u7528\u901a\u7528\u6587\u4ef6\uff0c\u5c31\u50cfC\u8bed\u8a00\u4e2d\u7684\u5934\u6587\u4ef6\u3002
\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c.dtsi\u63cf\u8ff0SOC\u4fe1\u606f\uff0c\u6bd4\u5982CPU\u67b6\u6784\uff0c\u4e3b\u9891\u3002.dts\u6587\u4ef6\u63cf\u8ff0\u677f\u7ea7\u4fe1\u606f\uff0c\u6bd4\u5982\u5f00\u53d1\u677f\u4e0a\u6709\u54ea\u4e9bIIC\u8bbe\u5907\u3001SPI\u8bbe\u5907\u7b49\u3002
"},{"location":"linux/drivers/dts/#dtsdtbdtc","title":"DTS\u3001DTB\u548cDTC\u7684\u5173\u7cfb","text":".dts\u662f\u8bbe\u5907\u6811\u6e90\u7801\u6587\u4ef6\uff0cDTC\u8d1f\u8d23\u5c06.dts\u7f16\u8bd1\u6210.dtb\u3002\u800c.dtb\u5c31\u662f\u8d1f\u8d23\u4f20\u9012\u7ed9\u5185\u6838\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002
make dtbs\u4f1a\u7f16\u8bd1\u6240\u6709\u7684dts\u6587\u4ef6\uff0c\u5982\u679c\u8981\u7f16\u8bd1\u6307\u5b9a\u7684dtb\uff0c\u8bf7\u4f7f\u7528make board_name.dtb\u3002
\u5728arch/arm/boot/dts/Makefile\u4e2d\uff0c\u5982\u679c\u9009\u4e2d\u4e86\u67d0\u79cdSOC\uff0c\u5219\u8be5SOC\u4e0b\u7684\u6240\u6709\u76f8\u5173dtb\u6587\u4ef6\u90fd\u5c06\u88ab\u7f16\u8bd1\u51fa\u6765\u3002
\u5982\u679c\u6211\u4eec\u4f7f\u7528\u4e86I.MX6ULL\u65b0\u505a\u4e86\u4e00\u4e2a\u677f\u5b50\uff0c\u53ea\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u5bf9\u5e94\u7684.dts\u6587\u4ef6\uff0c\u5e76\u4e14\u5c06\u5bf9\u5e94\u7684.dtb\u6587\u4ef6\u6dfb\u52a0\u5230dtb-${CONFIG_SOC_IMX6ULL}\u4e0b\u3002
"},{"location":"linux/drivers/dts/#dts","title":"DTS\u57fa\u672c\u8bed\u6cd5","text":"\u8bbe\u5907\u6811\u7684\u6bcf\u4e2a\u8282\u70b9\u6309\u7167\u4ee5\u4e0b\u89c4\u5219\u547d\u540d\uff1a
label:node-name@unit-address{\n \u5c5e\u60271 = ...\n \u5c5e\u60272 = ...\n \u5c5e\u60273 = ...\n \u5b50\u8282\u70b9...\n}\n
device tree\u7684\u57fa\u672c\u5355\u5143\u662fnode\uff0c\u8fd9\u4e9bnode\u88ab\u7ec4\u7ec7\u6210\u6811\u72b6\u7ed3\u6784\u3002\u9664\u4e86root node\uff0c\u6bcf\u4e2anode\u90fd\u6709\u4e00\u4e2aparent node\u3002\u4e00\u4e2adevice tree\u6587\u4ef6\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2aroot node\u3002\u6bcf\u4e2anode\u4e2d\u90fd\u5305\u542b\u4e86property: value\u6765\u63cf\u8ff0\u8be5node\u7684\u4e00\u4e9b\u4fe1\u606f\u3002
label
\u7528\u6765\u6307\u5b9a\u6807\u7b7e\u540d\uff0c\u65b9\u4fbf\u5f15\u7528\u3002node-name
\u7528\u4e8e\u6307\u5b9a\u8282\u70b9\u7684\u540d\u79f0\uff0cunit-address
\u7528\u4e8e\u6307\u5b9a\u5730\u5740\uff0c\u5176\u503c\u8981\u4e0e\u8282\u70b9reg
\u5c5e\u6027\u7684\u7b2c\u4e00\u4e2a\u5730\u5740\u4e00\u81f4\u3002
\u5c5e\u6027\u503c\u6807\u8bc6\u4e86\u8bbe\u5907\u7684\u7279\u6027\uff0c\u5b83\u7684\u503c\u53ef\u4ee5\u662f\u4ee5\u4e0b\u51e0\u79cd\uff1a
\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e5f\u5c31\u662f\u6ca1\u6709\u503c\u7684\u5b9a\u4e49\u3002 \u53ef\u80fd\u662f\u4e00\u4e2au32\u3001u64\u7684\u6570\u503c\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u3002 \u53ef\u80fd\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u662fstring list\u3002 \u5728\u6839\u8282\u70b9\u4e0b\u6709\u4e24\u4e2a\u7279\u6b8a\u7684\u8282\u70b9\uff1aaliases
\u548cchosen
aliases\uff1a\u7528\u4e8e\u7ed9\u8282\u70b9\u5b9a\u4e49\u522b\u540d\uff0c\u65b9\u4fbf\u5bf9\u8282\u70b9\u7684\u5f15\u7528\u3002 chosen\uff1a\u865a\u62df\u8282\u70b9\uff0c\u53ef\u4ee5\u5728chosen\u4e2d\u8bbe\u7f6ebootargs\uff0c\u7531bootloader\u8bfb\u53d6\uff0c\u4f20\u9012\u7ed9\u5185\u6838\u4f5c\u4e3a\u542f\u52a8\u53c2\u6570\u3002 \u8fd8\u6709\u4e00\u4e2a\u6240\u6709\u8bbe\u5907\u6811\u6587\u4ef6\u5fc5\u987b\u8981\u6709\u7684\u8282\u70b9\u662fmemory device node
\uff0c\u5b83\u5b9a\u4e49\u4e86\u7cfb\u7edf\u7269\u7406\u5185\u5b58\u7684layout\u3002device_type
\u5c5e\u6027\u5b9a\u4e49\u4e86\u8be5node\u7684\u8bbe\u5907\u7c7b\u578b\uff0c\u4f8b\u5982cpu\u3001serial\u7b49\u3002\u5bf9\u4e8ememory node\uff0c\u5176device_type
\u5fc5\u987b\u7b49\u4e8ememory\u3002reg
\u5c5e\u6027\u5b9a\u4e49\u4e86\u8bbf\u95ee\u8be5device node\u7684\u5730\u5740\u4fe1\u606f\u2014\u2014\u8d77\u59cb\u5730\u5740\u548c\u957f\u5ea6\u3002
\u8282\u70b9\u7531\u4e00\u5806\u5c5e\u6027\u7ec4\u6210\uff0c\u8282\u70b9\u662f\u5177\u4f53\u7684\u8bbe\u5907\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u8bbe\u5907\u6709\u4e0d\u540c\u7684\u5c5e\u6027\uff0c\u4e0d\u8fc7\u6709\u4e00\u4e9b\u662f\u6807\u51c6\u5c5e\u6027\u3002
1.compatible
\u5c5e\u6027
compatible
\u5c5e\u6027\u7684\u503c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u7528\u4e8e\u5c06\u8bbe\u5907\u548c\u5bf9\u5e94\u7684\u9a71\u52a8\u7ed1\u5b9a\u8d77\u6765\u3002\u5b57\u7b26\u4e32\u5217\u8868\u7528\u4e8e\u8868\u793a\u8bbe\u5907\u6240\u8981\u4f7f\u7528\u7684\u9a71\u52a8\u7a0b\u5e8f\u3002compatible
\u5c5e\u6027\u662f\u7528\u6765\u67e5\u627e\u8282\u70b9\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4f8b\u5982\u7cfb\u7edf\u521d\u59cb\u5316platform\u603b\u7ebf\u4e0a\u7684\u8bbe\u5907\u65f6\uff0c\u6839\u636e\u8bbe\u5907\u8282\u70b9compatible
\u5c5e\u6027\u548c\u9a71\u52a8\u4e2dof_match_table
\u5bf9\u5e94\u7684\u503c\uff0c\u5339\u914d\u4e86\u5c31\u52a0\u8f7d\u5bf9\u5e94\u7684\u9a71\u52a8\u3002compatible
\u5c5e\u6027\u7684\u683c\u5f0f\u5982\u4e0b\uff1a
\"manufacturer, model\"\n
manufacturer\u8868\u793a\u5382\u5546\uff0cmodel\u8868\u793a\u5bf9\u5e94\u9a71\u52a8\u7684\u540d\u5b57\u3002\u800c\u6839\u8282\u70b9\u7684compatible
\u8868\u793a\u786c\u4ef6\u8bbe\u5907\u540d\uff0cSOC\u540d\u3002Linux\u5185\u6838\u4f1a\u901a\u8fc7\u6839\u8282\u70b9\u7684compatible
\u5c5e\u6027\u67e5\u770b\u662f\u5426\u652f\u6301\u6b64\u8bbe\u5907\uff0c\u5982\u679c\u652f\u6301\u8bbe\u5907\u5c31\u4f1a\u542f\u52a8\u5185\u6838\u3002
compatible
\u4e5f\u53ef\u4ee5\u6709\u591a\u4e2a\u5c5e\u6027\u503c\uff0c\u6309\u7167\u4f18\u5148\u7ea7\u67e5\u627e\u3002
2.model
\u5c5e\u6027
model
\u5c5e\u6027\u7528\u6765\u63cf\u8ff0\u8bbe\u5907\u7684\u751f\u4ea7\u5382\u5546\u548c\u578b\u53f7\u3002\u6bd4\u5982model=\"samsung, s3c24xx\"\u2014\u2014\u751f\u4ea7\u5382\u5546\u662f\u4e09\u661f\uff0cSOC\u662fs3c24xx\u3002
3.status
\u5c5e\u6027
status
\u5c5e\u6027\u7684\u503c\u4e0e\u8bbe\u5907\u72b6\u6001\u6709\u5173\uff0c\u901a\u8fc7\u8bbe\u7f6estatus
\u5c5e\u6027\u53ef\u4ee5\u7981\u7528\u6216\u8005\u542f\u7528\u8bbe\u5907\u3002
4.reg
\u5c5e\u6027
reg
\u5c5e\u6027\u7684\u503c\u4e00\u822c\u662f(address, length)\u5bf9\u3002\u7528\u4e8e\u63cf\u8ff0\u8bbe\u5907\u8d44\u6e90\u5728\u5176\u7236\u603b\u7ebf\u5b9a\u4e49\u7684\u5730\u5740\u7a7a\u95f4\u5185\u7684\u5730\u5740\u3002
reg = <0x4000e000 0x400> //\u8d77\u59cb\u5730\u5740+\u5927\u5c0f\n
5.#address-cells
\u548c#size-cells
\u5c5e\u6027
\u5982\u679c\u4e00\u4e2adevice node
\u7684sub node\u6709\u5bfb\u5740\u9700\u6c42\uff08\u5373\u9700\u8981\u5b9a\u4e49reg
\u5c5e\u6027\uff09\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5c5e\u6027\u5c31\u5fc5\u987b\u8981\u5b9a\u4e49\uff0c\u7528\u4e8e\u63cf\u8ff0sub node\u7684reg
\u5c5e\u6027\u7684\u4fe1\u606f\u3002
#address-cells: \u51b3\u5b9a\u4e86\u5b50\u8282\u70b9reg\u5c5e\u6027\u7684\u5730\u5740\u4fe1\u606f\u6240\u5360\u7528\u7684\u5b57\u957f\n#size-cells\uff1a\u51b3\u5b9a\u4e86\u5b50\u8282\u70b9reg\u5c5e\u6027\u4e2d\u957f\u5ea6\u4fe1\u606f\u6240\u5360\u7684\u5b57\u957f\n
6.ranges
\u5c5e\u6027
ranges
\u5c5e\u6027\u7684\u503c\u6309\u7167(child-bus-address, parent-bus-address, lenght)\u683c\u5f0f\u7f16\u5199\u3002ranges
\u5c5e\u6027\u7528\u6765\u6307\u5b9a\u67d0\u4e2a\u8bbe\u5907\u7684\u5730\u5740\u8303\u56f4\u6216\u8005IO\u8303\u56f4\uff0c\u8fd9\u662f\u5bf9\u8bbe\u5907\u8fdb\u884c\u5bfb\u5740\u7684\u91cd\u8981\u4fe1\u606f\u3002\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7ranges
\u5c5e\u6027\u83b7\u77e5\u54ea\u4e9b\u5185\u5b58\u533a\u57df\u6216\u8005IO\u7aef\u53e3\u662f\u88ab\u786c\u4ef6\u8bbe\u5907\u6240\u5360\u7528\u7684\u3002
child-bus-address\uff1a\u5b50\u603b\u7ebf\u5730\u5740\u7a7a\u95f4\u7684\u7269\u7406\u5730\u5740\uff0c\u7531\u7236\u8282\u70b9\u7684#address-cells\u786e\u5b9a\u6b64\u7269\u7406\u5730\u5740\u5360\u7528\u7684\u5b57\u957f parent-bus-address\uff1a\u7236\u603b\u7ebf\u5730\u5740\u7a7a\u95f4\u7684\u7269\u7406\u5730\u5740\uff0c\u540c\u6837\u7531\u7236\u8282\u70b9\u7684#address-cells\u786e\u5b9a\u6b64\u7269\u7406\u5730\u5740\u5360\u7528\u7684\u5b57\u957f length\uff1a\u5b50\u5730\u5740\u7a7a\u95f4\u7684\u957f\u5ea6\uff0c\u7531\u7236\u8282\u70b9\u7684#size-cells\u786e\u5b9a\u6b64\u5730\u5740\u957f\u5ea6\u5360\u7528\u7684\u5b57\u957f \u5982\u679cranges
\u5c5e\u6027\u4e3a\u7a7a\uff0c\u5219\u8bf4\u660e\u5b50\u5730\u5740\u7a7a\u95f4\u548c\u7236\u5730\u5740\u7a7a\u95f4\u76f8\u540c\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u8f6c\u6362\u3002
Arm\u4f53\u7cfb\u6b64\u5c5e\u6027\u8bbe\u7f6e\u4e3a\u7a7a\u3002
7.intc
\u5c5e\u6027
\u7528\u4e8e\u8868\u793a\u4e2d\u65ad\u63a7\u5236\u5668\u7684\u76f8\u5173\u4fe1\u606f\u3002
interrupt-controller\uff1a interrupt-cells\uff1a interrupt-parent\uff1a interrupts\uff1a \u6839\u8282\u70b9\u5fc5\u987b\u8981\u6709\u7684\u5c5e\u6027\u6709\uff1a
#address-cells:\u5b50\u8282\u70b9reg\u5c5e\u6027\u4e2d\uff0c\u7528\u591a\u5c11\u4e2au32\u6574\u6570\u6765\u63cf\u8ff0\u5730\u5740\n#size-cells\uff1a\u5b50\u8282\u70b9reg\u5c5e\u6027\u4e2d\uff0c\u7528\u591a\u5c11\u4e2au32\u6574\u6570\u6765\u63cf\u8ff0\u5927\u5c0f\ncompatible\uff1a\u6307\u5b9a\u677f\u5b50\u517c\u5bb9\u7684\u5e73\u53f0\nmodel\uff1a\u677f\u5b50\u540d\u79f0\n
"},{"location":"linux/drivers/dts/#_3","title":"\u5185\u6838\u64cd\u4f5c\u8bbe\u5907\u6811","text":"\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\u6765\u64cd\u4f5c\u8bbe\u5907\u6811\u4e2d\u7684\u8282\u70b9\u548c\u5c5e\u6027\u4fe1\u606f\uff0c\u8fd9\u4e9b\u51fd\u6570\u7edf\u4e00\u4ee5of
\u5f00\u5934\u3002
\u8282\u70b9\u64cd\u4f5c\u51fd\u6570
\u5185\u6838\u4f7f\u7528device_node
\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u4e00\u4e2a\u8282\u70b9
struct device_node{\n const char *name; //\u8bbe\u5907\u540d\u79f0\n const char *type; //\u8bbe\u5907\u7c7b\u578b\n cont char *full_name; //\u8bbe\u5907\u7684\u5b8c\u6574\u540d\u79f0\n ...\n struct device_node *parent; //\u7236\u8282\u70b9\u6307\u9488\n struct device_node *child; //\u5b50\u8282\u70b9\u6307\u9488\n struct device_node *sibling; //\u540c\u7ea7\u8282\u70b9\u6307\u9488\n struct kobject kobj; //kobject\u7ed3\u6784\u4f53\u662f\u5185\u6838\u5bf9\u8c61\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u8ddf\u8e2a\u6b64\u8282\u70b9\n unsigned long _flags; //\u8868\u793a\u8282\u70b9\u7684\u5c5e\u6027\n void *data; //\u6307\u5411\u4efb\u610f\u6570\u636e\u7684\u6307\u9488\n};\n
\u4e0e\u67e5\u627e\u8282\u70b9\u76f8\u5173\u7684of
\u51fd\u6570\u67095\u4e2a\uff1a 1.\u901a\u8fc7\u8282\u70b9\u540d\u5b57\u67e5\u627e\u6307\u5b9a\u8282\u70b9
struct device_node *of_find_node_by_name(struct device_node *from, const char *name);\n
from\uff1a\u5f00\u59cb\u67e5\u627e\u7684\u8282\u70b9\uff0cNULL\u5219\u8868\u793a\u4ece\u6839\u8282\u70b9\u5f00\u59cb\u67e5\u627e name\uff1a\u8981\u67e5\u627e\u7684\u8282\u70b9\u540d \u8fd4\u56de\u503c\uff1a\u627e\u5230\u7684\u8282\u70b9\uff0cNULL\u8868\u793a\u5931\u8d25 2.\u901a\u8fc7device_type
\u5c5e\u6027\u67e5\u627e\u6307\u5b9a\u8282\u70b9\uff08X\uff09
struct device_node *of_find_node_by_type(struct device_node *from, const char *type)\n
type\uff1a\u8981\u67e5\u627e\u7684\u8282\u70b9\u7684device_type\u5c5e\u6027\u503c \u7531\u4e8edevice_type
\u5df2\u7ecf\u88ab\u5e9f\u5f03\uff0c\u6240\u4ee5\u8fd9\u4e2a\u51fd\u6570\u5df2\u7ecf\u4e0d\u7528\u4e86\u3002
3.\u901a\u8fc7device_type
\u548ccompatible
\u4e24\u4e2a\u5c5e\u6027\u6765\u67e5\u627e\u6307\u5b9a\u8282\u70b9
struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compatible)\n
4.\u901a\u8fc7of_device_id
\u5339\u914d\u8868\u6765\u67e5\u627e\u6307\u5b9a\u8282\u70b9
struct device_node *of_find_matching_node_and_match(struct device_node *from, const struct of_device_id *matches, const struct of_device_id **match)\n
5.\u901a\u8fc7\u8def\u5f84\u6765\u67e5\u627e\u6307\u5b9a\u8282\u70b9
inline struct device_node *of_find_node_by_path(const char *path)\n
path\uff1a\u5e26\u6709\u5168\u8def\u5f84\u7684\u8282\u70b9\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\u8282\u70b9\u7684\u522b\u540d \u63a8\u8350\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u6765\u67e5\u627e\u8282\u70b9\u3002
\u8282\u70b9\u7684\u5c5e\u6027\u4fe1\u606f\u91cc\u4fdd\u5b58\u4e86\u9a71\u52a8\u6240\u9700\u8981\u7684\u5185\u5bb9\uff0c\u5185\u6838\u4e2d\u4f7f\u7528\u7ed3\u6784\u4f53property
\u8868\u793a\u5c5e\u6027\u3002
struct property{\n char *name; //\u5c5e\u6027\u540d\n int length; //\u5c5e\u6027\u503c\u7684\u957f\u5ea6\n void *value; //\u6307\u5411\u5c5e\u6027\u503c\u7684\u6307\u9488\n struct property *next; //\u6307\u5411\u4e0b\u4e00\u4e2a\u5c5e\u6027\u7684\u6307\u9488\n unsigned long _flags; //\u8868\u793a\u5c5e\u6027\u7684\u7c7b\u522b\n unsigned int unique_id; //\u6807\u8bc6\u8bbe\u5907\u7684\u552f\u4e00\u5c5e\u6027\n struct bin_attribute attr; //\u8868\u793a\u5c5e\u6027\u7684\u4e00\u4e9b\u5143\u6570\u636e\n};\n
\u5185\u6838\u63d0\u4f9b\u4e86\u67e5\u627e\u7236\u5b50\u8282\u70b9\u7684of
\u51fd\u6570\u3002
struct device_node *of_get_parent(const struct device_node *node)\n\nstruct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev)\n
\u540c\u65f6\u5185\u6838\u4e5f\u63d0\u4f9b\u4e86\u63d0\u53d6\u5c5e\u6027\u503c\u7684of
\u51fd\u6570\u3002
1.\u67e5\u627e\u6307\u5b9a\u7684\u5c5e\u6027
property *of_find_property(const struct device_node *np, const char *name, int *lenp)\n
np\uff1a\u8bbe\u5907\u8282\u70b9 name\uff1a\u5c5e\u6027\u540d\u5b57 lenp\uff1a\u5c5e\u6027\u503c\u7684\u5b57\u8282\u6570 2.\u83b7\u53d6\u5c5e\u6027\u4e2d\u5143\u7d20\u7684\u6570\u91cf
int of_property_count_elems_of_size(const struct device_node *np, const char *propname, int elem_size)\n
3.\u4ece\u5c5e\u6027\u4e2d\u83b7\u53d6\u6307\u5b9a\u6807\u53f7\u7684u32\u7c7b\u578b\u6570\u636e
int of_property_read_u32_index(const struct device_node *np, const char *propname, u32 index, u32 *out_value)\n
propname\uff1a\u8981\u8bfb\u53d6\u7684\u5c5e\u6027\u540d index\uff1a\u8981\u8bfb\u53d6\u7684\u503c\u6807\u53f7 out_value\uff1a\u8bfb\u53d6\u5230\u7684\u503c 4.\u8bfb\u53d6u8\u3001u16\u3001u32\u3001u64\u7c7b\u578b\u7684\u6570\u7ec4\u6570\u636e
int of_property_read_u8_array(const struct device_node *np, const char *propname, u8 *out_values, size_t sz)\n
\u5c06\u51fd\u6570\u540d\u4e2d\u7684u8\u66ff\u6362\u6210\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u5373\u53ef\u3002
5.\u8bfb\u53d6u8\u3001u16\u3001u32\u3001u64\u7c7b\u578b\u5c5e\u6027\u503c
int of_property_read_u8(const struct device_node *np, const char *propname, u8 *out_value)\n
6.\u8bfb\u53d6\u5c5e\u6027\u4e2d\u5b57\u7b26\u4e32\u7684\u503c
int of_property_read_string(struct device_node *np, const char *propname, const char **out_string)\n
\u8fd9\u4e2a\u51fd\u6570\u4f7f\u7528\u6bd4\u8f83\u7e41\u7410\uff0c\u5efa\u8bae\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\uff1a
int of_property_read_string_index(const struct device_node *np,const char *propname, int index,const char **out_string)\n
\u76f8\u6bd4\u524d\u9762\u7684\u51fd\u6570\u589e\u52a0\u4e86\u53c2\u6570index\uff0c\u5b83\u7528\u4e8e\u6307\u5b9a\u8bfb\u53d6\u5c5e\u6027\u503c\u4e2d\u7b2c\u51e0\u4e2a\u5b57\u7b26\u4e32\uff0cindex\u4ece\u96f6\u5f00\u59cb\u8ba1\u6570\u3002 \u7b2c\u4e00\u4e2a\u51fd\u6570\u53ea\u80fd\u5f97\u5230\u5c5e\u6027\u503c\u6240\u5728\u5730\u5740\uff0c\u4e5f\u5c31\u662f\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5730\u5740\uff0c\u5176\u4ed6\u5b57\u7b26\u4e32\u9700\u8981\u6211\u4eec\u624b\u52a8\u4fee\u6539\u79fb\u52a8\u5730\u5740\uff0c\u975e\u5e38\u9ebb\u70e6\uff0c\u63a8\u8350\u4f7f\u7528\u7b2c\u4e8c\u4e2a\u51fd\u6570\u3002
\u73b0\u5728\u5185\u6838\u63d0\u4f9b\u4e86\u5185\u5b58\u6620\u5c04\u76f8\u5173\u7684of
\u51fd\u6570\uff0c\u53ef\u4ee5\u81ea\u52a8\u5b8c\u6210\u7269\u7406\u5730\u5740\u5230\u865a\u62df\u5730\u5740\u7684\u8f6c\u6362\uff1a
void __iomem *of_iomap(struct device_node *np, int index)\n
"},{"location":"linux/drivers/framework/","title":"\u9a71\u52a8\u6846\u67b6","text":"\u9a71\u52a8\u6846\u67b6\u4e0b\u5404\u7c7b\u5b50\u7cfb\u7edf\u7684\u4ecb\u7ecd\uff0c\u9700\u8981\u6709\u8bbe\u5907\u6811\u7684\u77e5\u8bc6\u3002
"},{"location":"linux/drivers/framework/#pinctrl","title":"Pinctrl\u5b50\u7cfb\u7edf","text":"\u901a\u8fc7\u5bc4\u5b58\u5668\u6620\u5c04\u6765\u64cd\u4f5c\u5916\u8bbe\u7684\u7f16\u7a0b\u65b9\u5f0f\uff0c\u5728\u9a71\u52a8\u5f00\u53d1\u4e2d\u662f\u4e0d\u5efa\u8bae\u7684\uff0c\u56e0\u4e3a\u6bcf\u5f53\u82af\u7247\u7684\u5bc4\u5b58\u5668\u53d1\u751f\u53d8\u5316\uff0c\u90a3\u4e48\u5e95\u5c42\u7684\u9a71\u52a8\u4ee3\u7801\u5c31\u5f97\u63a8\u7ffb\u91cd\u5199\u3002\u5728\u9a71\u52a8\u5f00\u53d1\u4e2d\uff0c\u6709\u6ca1\u6709\u529e\u6cd5\u53ef\u4ee5\u4e0d\u6d89\u53ca\u5230\u5177\u4f53\u7684\u5bc4\u5b58\u5668\u64cd\u4f5c\u5462\uff1f\u5bf9\u4e8e\u6709\u4e9b\u5916\u8bbe\uff0c\u662f\u5177\u5907\u62bd\u8c61\u6761\u4ef6\u7684\uff0cPintrl\u5b50\u7cfb\u7edf\u5c31\u662f\u5176\u4e2d\u4e4b\u4e00\u3002
Pinctrl\uff1aPin Controller\uff0c\u5f15\u811a\u63a7\u5236\uff1a
\u5f15\u811a\u679a\u4e3e\u4e0e\u547d\u540d \u5f15\u811a\u590d\u7528\uff1a\u4e00\u4e2a\u5f15\u811a\u53ef\u4ee5\u7528\u4f5cGPIO\uff0c\u4e5f\u53ef\u4ee5\u7528\u4f5cI2C\u6216UART \u5f15\u811a\u914d\u7f6e\uff1a\u6bd4\u5982\u4e0a\u62c9\u3001\u4e0b\u62c9 Pinctrl\u9a71\u52a8\u7531\u82af\u7247\u5382\u5bb6BSP\u5de5\u7a0b\u5e08\u63d0\u4f9b\uff0c\u4e00\u822c\u7684\u9a71\u52a8\u5de5\u7a0b\u5e08\u53ea\u9700\u8981\u5728\u8bbe\u5907\u6811\u91cc\u63cf\u8ff0\u5373\u53ef\uff1a
\u6307\u660e\u4f7f\u7528\u54ea\u4e9b\u5f15\u811a \u590d\u7528\u4e3a\u4ec0\u4e48\u529f\u80fd \u914d\u7f6e\u4e3a\u4ec0\u4e48\u72b6\u6001 "},{"location":"linux/drivers/framework/#pinctrl_1","title":"Pinctrl\u4e3b\u8981\u6570\u636e\u7ed3\u6784","text":"pinctrl\u53ef\u4ee5\u7528\u4e00\u4e2a\u7ed3\u6784\u4f53\u6765\u8868\u793a\u5b83\uff1apinctrl_dev
\u3002\u800cpinctrl_dev
\u53ef\u4ee5\u7528pinctrl_desc
\u7ed3\u6784\u4f53\u63cf\u8ff0\uff0c\u7136\u540e\u8c03\u7528pinctrl_register()
\u51fd\u6570\u6765\u6ce8\u518c\u5b83\uff0c\u5176\u8fd4\u56de\u503c\u5c31\u662f\u4e00\u4e2apinctrl_dev
\u7684\u7ed3\u6784\u4f53\uff1a
struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, struct device *dev, void *driver_data);\n
pinctrl_desc:
struct pinctrl_pin_desc {\n unsigned number;\n const char *name;\n void *drv_data;\n};\n
pinctrl_ops\uff1a
struct pinctrl_ops {\n int (*get_groups_count) (struct pinctrl_dev *pctldev);\n const char *(*get_group_name) (struct pinctrl_dev *pctldev,\n unsigned selector);\n int (*get_group_pins) (struct pinctrl_dev *pctldev,\n unsigned selector,\n const unsigned **pins,\n unsigned *num_pins);\n void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,\n unsigned offset);\n int (*dt_node_to_map) (struct pinctrl_dev *pctldev,\n struct device_node *np_config,\n struct pinctrl_map **map, unsigned *num_maps);\n void (*dt_free_map) (struct pinctrl_dev *pctldev,\n struct pinctrl_map *map, unsigned num_maps);\n};\n
pinmux_pos\uff1a
struct pinmux_ops {\n int (*request) (struct pinctrl_dev *pctldev, unsigned offset);\n int (*free) (struct pinctrl_dev *pctldev, unsigned offset);\n int (*get_functions_count) (struct pinctrl_dev *pctldev);\n const char *(*get_function_name) (struct pinctrl_dev *pctldev,\n unsigned selector);\n int (*get_function_groups) (struct pinctrl_dev *pctldev,\n unsigned selector,\n const char * const **groups,\n unsigned *num_groups);\n int (*set_mux) (struct pinctrl_dev *pctldev, unsigned func_selector,\n unsigned group_selector);\n int (*gpio_request_enable) (struct pinctrl_dev *pctldev,\n struct pinctrl_gpio_range *range,\n unsigned offset);\n void (*gpio_disable_free) (struct pinctrl_dev *pctldev,\n struct pinctrl_gpio_range *range,\n unsigned offset);\n int (*gpio_set_direction) (struct pinctrl_dev *pctldev,\n struct pinctrl_gpio_range *range,\n unsigned offset,\n bool input);\n bool strict;\n};\n
pinconf_ops\uff1a
struct pinconf_ops {\n#ifdef CONFIG_GENERIC_PINCONF\n bool is_generic;\n#endif\n int (*pin_config_get) (struct pinctrl_dev *pctldev,\n unsigned pin,\n unsigned long *config);\n int (*pin_config_set) (struct pinctrl_dev *pctldev,\n unsigned pin,\n unsigned long *configs,\n unsigned num_configs);\n int (*pin_config_group_get) (struct pinctrl_dev *pctldev,\n unsigned selector,\n unsigned long *config);\n int (*pin_config_group_set) (struct pinctrl_dev *pctldev,\n unsigned selector,\n unsigned long *configs,\n unsigned num_configs);\n void (*pin_config_dbg_show) (struct pinctrl_dev *pctldev,\n struct seq_file *s,\n unsigned offset);\n void (*pin_config_group_dbg_show) (struct pinctrl_dev *pctldev,\n struct seq_file *s,\n unsigned selector);\n void (*pin_config_config_dbg_show) (struct pinctrl_dev *pctldev,\n struct seq_file *s,\n unsigned long config);\n};\n
"},{"location":"linux/kernel/","title":"\u5185\u6838\u57fa\u7840\u77e5\u8bc6","text":""},{"location":"linux/kernel/#_2","title":"\u5185\u6838\u6e90\u7801","text":"\u8981\u83b7\u53d6\u5185\u6838\u6e90\u7801\uff0c\u8bf7\u4f7f\u7528git
\u3002
git clone git://git.ernel.org/pub/scm/linux/kernel/git/torvalds/[linux\u7248\u672c\u53f7].git\n
\u5185\u6838\u6e90\u7801\u6811\u7531\u8bb8\u591a\u76ee\u5f55\u7ec4\u6210\uff0c\u4e00\u4e9b\u6bd4\u8f83\u91cd\u8981\u7684\u76ee\u5f55\u7684\u63cf\u8ff0\u5982\u4e0b\uff1a
\u76ee\u5f55\u540d \u63cf\u8ff0 arch \u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u4ee3\u7801 block \u5757\u8bbe\u5907I/O\u5c42 drivers \u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f fs \u6587\u4ef6\u7cfb\u7edf include \u5185\u6838\u5934\u6587\u4ef6 init \u521d\u59cb\u5316\u4ee3\u7801 ipc \u8fdb\u7a0b\u95f4\u901a\u4fe1\u4ee3\u7801 kernel \u5185\u6838\u6838\u5fc3\u4ee3\u7801 lib \u5185\u6838\u5e93\u51fd\u6570 mm \u5185\u5b58\u7ba1\u7406 net \u7f51\u7edc\u7cfb\u7edf \u8981\u7f16\u8bd1\u5185\u6838\uff0c\u8bf7\u4f7f\u7528make menuconfig\u3002\u5185\u6838\u7684\u5404\u79cd\u914d\u7f6e\uff0c\u4ee5CONFIG_FEATURE\u7684\u5f62\u5f0f\u5199\u5165.config\u6587\u4ef6\u3002\u914d\u7f6e\u9009\u9879\u6709\u4e09\u79cd\uff1ayes\u3001no\u6216module\u3002\u5206\u522b\u5bf9\u5e94\u7f16\u8bd1\u3001\u4e0d\u7f16\u8bd1\u3001\u4ee5\u6a21\u5757\u5f62\u5f0f\u7f16\u8bd1\u3002
\u5185\u6838\u5f00\u53d1\u7684\u7279\u70b9\u5982\u4e0b\uff1a
\u4e0d\u80fd\u4f7f\u7528\u6807\u51c6C\u5e93\u5934\u6587\u4ef6\uff0c\u53ea\u80fd\u4f7f\u7528\u5185\u6838\u63d0\u4f9b\u7684\u5934\u6587\u4ef6\u3002\u4e0e\u4f53\u7cfb\u7ed3\u6784\u65e0\u5173\u7684\u5934\u6587\u4ef6\u4f4d\u4e8e\u5185\u6838\u6e90\u7801\u6839\u76ee\u5f55\u4e0b\u7684include\u76ee\u5f55\u3002\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u5934\u6587\u4ef6\u4f4d\u4e8e<arch/architecture/include/asm>\u76ee\u5f55\uff0c\u5185\u6838\u4ee3\u7801\u4ee5asm\u524d\u7f00\u7684\u5f62\u5f0f\u5305\u542b\u8fd9\u4e9b\u5934\u6587\u4ef6\u3002
\u5fc5\u987b\u4f7f\u7528GNU C\u3002gcc\u7f16\u8bd1\u5668\u652f\u6301\u4ee5asm()\u6307\u4ee4\u5f00\u5934\u5d4c\u5165\u6c47\u7f16\u4ee3\u7801\u3002
\u6ca1\u6709\u5185\u5b58\u4fdd\u62a4\u673a\u5236\u3002\u5982\u679c\u662f\u5185\u6838\u8bbf\u95ee\u4e86\u975e\u6cd5\u5185\u5b58\uff0c\u540e\u679c\u4e0d\u582a\u8bbe\u60f3\u3002
\u65e0\u6cd5\u6267\u884c\u6d6e\u70b9\u8fd0\u7b97\u3002\u5185\u6838\u5bf9\u4e8e\u6d6e\u70b9\u8fd0\u7b97\u7684\u652f\u6301\u5ea6\u4e0d\u591f\u3002
\u5fc5\u987b\u8003\u8651\u540c\u6b65\u4e0e\u5e76\u53d1\u3002Linux\u5185\u6838\u662f\u62a2\u5360\u5f0f\u591a\u4efb\u52a1\u5904\u7406\u7cfb\u7edf\uff0c\u5f53\u524d\u4efb\u52a1\u968f\u65f6\u6709\u53ef\u80fd\u88ab\u53e6\u4e00\u4e2a\u4efb\u52a1\u62a2\u5360\u3002
\u5fc5\u987b\u8003\u8651\u53ef\u79fb\u690d\u6027\u3002\u6bd4\u5982\u4fdd\u6301\u5b57\u8282\u5e8f\u300164 \u4f4d\u5bf9\u9f50\u3001\u4e0d\u5047\u5b9a\u5b57\u957f\u548c\u9875\u9762\u957f\u5ea6\u7b49\u4e00\u7cfb\u5217\u51c6\u5219\u3002
"},{"location":"linux/kernel/interrupt/","title":"\u4e2d\u65ad\u548c\u4e2d\u65ad\u5904\u7406","text":"\u4e2d\u65ad\u662f\u4e00\u79cd\u4e8b\u4ef6\uff0c\u8be5\u4e8b\u4ef6\u6539\u53d8\u5904\u7406\u5668\u6267\u884c\u6307\u4ee4\u7684\u987a\u5e8f\u3002\u8fd9\u79cd\u65b9\u5f0f\u6709\u540c\u6b65\u548c\u5f02\u6b65\u4e4b\u5206\u3002\u540c\u6b65\u4e2d\u65ad\u4e5f\u88ab\u79f0\u4e3a\u5f02\u5e38\u3002\u5728\u5904\u7406\u5668\u6267\u884c\u5230\u7531\u4e8e\u7f16\u7a0b\u5931\u8bef\u800c\u5bfc\u81f4\u7684\u9519\u8bef\u6307\u4ee4\uff08\u6bd4\u5982\u9664\u4ee50\uff09\u7684\u65f6\u5019\uff0c\u6216\u8005\u662f\u5728\u6267\u884c\u671f\u95f4\u51fa\u73b0\u7279\u6b8a\u60c5\u51b5\uff08\u6bd4\u5982\u7f3a\u9875\uff09\uff0c\u5fc5\u987b\u9760\u5185\u6838\u5904\u7406\u7684\u65f6\u5019\uff0c\u5904\u7406\u5668\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2a\u5f02\u5e38\u3002\u5f02\u6b65\u4e2d\u65ad\u5219\u662f\u7531\u786c\u4ef6\u5f15\u8d77\u7684\u3002
\u4e2d\u65ad\u53c8\u53ef\u4ee5\u5206\u4e3a\u53ef\u5c4f\u853d\u4e2d\u65ad\u548c\u4e0d\u53ef\u5c4f\u853d\u4e2d\u65ad\u3002\u901a\u5e38\uff0cI/O\u8bbe\u5907\u53d1\u51fa\u7684\u6240\u6709\u4e2d\u65ad\u8bf7\u6c42\u90fd\u662f\u53ef\u5c4f\u853d\u7684\uff0c\u800c\u90e8\u5206\u5371\u6025\u4e8b\u4ef6\uff08\u6bd4\u5982\u786c\u4ef6\u6545\u969c\uff09\u662f\u4e0d\u53ef\u5c4f\u853d\u7684\u3002\u6bcf\u4e2a\u4e2d\u65ad\u548c\u5f02\u5e38\u90fd\u662f\u75310 ~ 255\u4e4b\u95f4\u7684\u4e00\u4e2a\u6570\u6765\u6807\u8bc6\uff0c\u8fd9\u4e2a\u6570\u88ab\u79f0\u4f5c\u4e3a\u662f\u5411\u91cf\uff08vector\uff09\u3002\u4e0d\u53ef\u5c4f\u853d\u4e2d\u65ad\u7684\u5411\u91cf\u662f\u56fa\u5b9a\u7684\uff0c\u800c\u53ef\u5c4f\u853d\u4e2d\u65ad\u7684\u5411\u91cf\u53ef\u4ee5\u901a\u8fc7\u5bf9\u4e2d\u65ad\u63a7\u5236\u5668\u7684\u7f16\u7a0b\u6765\u6539\u53d8\u3002
\u663e\u7136\uff0c\u4e2d\u65ad\u4fe1\u53f7\u63d0\u4f9b\u4e86\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u5f0f\uff0c\u8ba9\u5904\u7406\u5668\u53bb\u6267\u884c\u6b63\u5e38\u8fd0\u884c\u4ee3\u7801\u4e4b\u5916\u7684\u903b\u8f91\u3002\u5f53\u4e00\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u5230\u6765\u65f6\uff0cCPU\u5fc5\u987b\u505c\u4e0b\u5b83\u5f53\u524d\u6b63\u5728\u505a\u7684\u4e8b\u60c5\uff0c\u8f6c\u800c\u53bb\u5904\u7406\u4e2d\u65ad\u4ee3\u7801\u3002\u4e3a\u4e86\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u5c31\u9700\u8981\u5728\u5185\u6838\u6001\u5806\u6808\u4fdd\u5b58\u5f53\u524d\u4e0a\u4e0b\u6587\u73af\u5883\uff0c\u5e76\u4e14\u628a\u89e6\u53d1\u4e86\u4f55\u79cd\u4e2d\u65ad\u4e5f\u653e\u8fdb\u5bc4\u5b58\u5668\u4e2d\u3002
\u4f60\u53ef\u80fd\u4f1a\u628a\u4e2d\u65ad\u5904\u7406\u4e0e\u8fdb\u7a0b\u5207\u6362\u8054\u7cfb\u8d77\u6765\u3002\u786e\u5b9e\u8fd9\u4e24\u8005\u6709\u90e8\u5206\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u662f\u4e2d\u65ad\u6267\u884c\u7684\u4ee3\u7801\u4e0d\u662f\u8fdb\u7a0b\u73af\u5883\u3002\u5b83\u662f\u4e00\u4e2a\u5185\u6838\u63a7\u5236\u7684\u7279\u6b8a\u8def\u5f84\uff0c\u5fc5\u987b\u5feb\u901f\u5904\u7406\uff0c\u4e0d\u80fd\u505c\u7559\u3002\u7531\u4e8e\u4e2d\u65ad\u5904\u7406\u662f\u5185\u6838\u6700\u4e3a\u654f\u611f\u7684\u4efb\u52a1\u4e4b\u4e00\uff0c\u4e3a\u4e86\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\uff0c\u5b83\u5fc5\u987b\u6709\u4ee5\u4e0b\u7ea6\u675f\uff1a
\u4e2d\u65ad\u5fc5\u987b\u5c3d\u53ef\u80fd\u5feb\u5730\u5904\u7406\u3002\u4e3a\u6b64\uff0c\u4e2d\u65ad\u5904\u7406\u901a\u5e38\u5206\u4e3a\u4e24\u90e8\u5206\uff1a\u5173\u952e\u800c\u7d27\u6025\u7684\u90e8\u5206\uff0c\u5185\u6838\u7acb\u5373\u6267\u884c\uff1b\u5176\u4f59\u90e8\u5206\u63a8\u8fdf\u6267\u884c\u3002
\u4e2d\u65ad\u5fc5\u987b\u53ef\u4ee5\u5d4c\u5957\u6267\u884c\u3002\u7531\u4e8e\u4e2d\u65ad\u968f\u65f6\u4f1a\u5230\u6765\uff0c\u5728\u5185\u6838\u5904\u7406\u5176\u4e2d\u4e00\u4e2a\u4e2d\u65ad\u65f6\uff0c\u53e6\u4e00\u4e2a\u4e2d\u65ad\u4e5f\u4f1a\u53d1\u751f\u3002\u5f53\u4e2d\u65ad\u5904\u7406\u5b8c\u6210\u540e\uff0c\u5185\u6838\u5fc5\u987b\u80fd\u6062\u590d\u88ab\u4e2d\u65ad\u8fdb\u7a0b\u7684\u6267\u884c\u3002
\u5728\u4e34\u754c\u533a\u4e2d\uff0c\u4e2d\u65ad\u5fc5\u987b\u88ab\u7981\u6b62\u3002
"},{"location":"linux/kernel/interrupt/#_2","title":"\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f","text":"\u5728\u54cd\u5e94\u4e00\u4e2a\u7279\u5b9a\u7684\u4e2d\u65ad\u65f6\uff0c\u5185\u6838\u4f1a\u6267\u884c\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u53eb\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff08interrupt handler\uff09\u6216\u4e2d\u65ad\u670d\u52a1\u4f8b\u7a0b\uff08interrupt service routine, ISR\uff09\u3002\u4ea7\u751f\u4e2d\u65ad\u7684\u6bcf\u4e2a\u8bbe\u5907\u90fd\u6709\u4e00\u4e2a\u54cd\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u4e00\u4e2a\u8bbe\u5907\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u662f\u5b83\u9a71\u52a8\u7a0b\u5e8f\u7684\u4e00\u90e8\u5206\u3002
\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5904\u4e8e\u7279\u6b8a\u7684\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e2d\u3002\u5728\u89e3\u91ca\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u56de\u5fc6\u4e00\u4e0b\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u3002\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u65f6\u4e00\u79cd\u5185\u6838\u6240\u5904\u7684\u64cd\u4f5c\u6a21\u5f0f\uff0c\u6b64\u65f6\u8fdb\u7a0b\u4ee3\u8868\u8fdb\u7a0b\u6267\u884c\u3002\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528current
\u5b8f\u5173\u8054\u5f53\u524d\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u7761\u7720\uff0c\u4e5f\u53ef\u4ee5\u8c03\u7528\u8c03\u5ea6\u7a0b\u5e8f\u3002\u4e0e\u4e4b\u76f8\u53cd\uff0c\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e0e\u8fdb\u7a0b\u6ca1\u6709\u4ec0\u4e48\u5173\u8054\u3002\u56e0\u4e3a\u4e2d\u65ad\u7684\u89e6\u53d1\u662f\u968f\u65f6\u5230\u6765\u7684\uff0c\u5e76\u4e0d\u77e5\u9053\u5f53\u524d\u5904\u4e8e\u54ea\u4e2a\u8fdb\u7a0b\u3002\u56e0\u4e3a\u6ca1\u6709\u540e\u5907\u8fdb\u7a0b\uff0c\u6240\u4ee5\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e0d\u53ef\u7761\u7720\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u4efb\u4f55\u53ef\u4ee5\u5f15\u8d77\u7761\u7720\u7684\u51fd\u6570\u3002\u4e2d\u65ad\u4e0a\u4e0b\u6587\u7684\u4ee3\u7801\u5fc5\u987b\u5feb\u901f\u4e14\u7b80\u6d01\u3002
\u4e2d\u65ad\u968f\u65f6\u6709\u53ef\u80fd\u53d1\u751f\uff0c\u56e0\u6b64\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5fc5\u987b\u5feb\u901f\u6267\u884c\u3002\u4f46\u662f\uff0c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5f80\u5f80\u8fd8\u8981\u5b8c\u6210\u5927\u91cf\u5176\u4ed6\u7684\u5de5\u4f5c\u3002\u6bd4\u5982\u4e00\u4e2a\u7f51\u7edc\u8bbe\u5907\uff0c\u9664\u4e86\u5bf9\u786c\u4ef6\u5e94\u7b54\u4e4b\u5916\uff0c\u8fd8\u9700\u8981\u628a\u6765\u81ea\u786c\u4ef6\u7684\u7f51\u7edc\u6570\u636e\u62f7\u8d1d\u5230\u5185\u5b58\u3002\u663e\u7136\u8fd9\u79cd\u5de5\u4f5c\u91cf\u4e0d\u4f1a\u5c0f\u3002
\u53c8\u60f3\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u5f97\u5feb\uff0c\u53c8\u8981\u5176\u5b8c\u6210\u7684\u5de5\u4f5c\u591a\u3002\u9274\u4e8e\u8fd9\u4e24\u8005\u4e4b\u95f4\u7684\u77db\u76fe\u5173\u7cfb\uff0c\u6211\u4eec\u4e00\u822c\u628a\u4e2d\u65ad\u5904\u7406\u7684\u8fc7\u7a0b\u5207\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\uff1a\u4e0a\u534a\u90e8\u548c\u4e0b\u534a\u90e8\u3002\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u662f\u4e0a\u534a\u90e8\u2014\u2014\u5f53\u63a5\u6536\u5230\u4e00\u4e2a\u4e2d\u65ad\u540e\uff0c\u5b83\u7acb\u523b\u88ab\u6267\u884c\uff0c\u4f46\u53ea\u505a\u6709\u4e25\u683c\u65f6\u9650\u7684\u5de5\u4f5c\u3002\u4f8b\u5982\u5bf9\u63a5\u6536\u5230\u7684\u4e2d\u65ad\u8fdb\u884c\u5e94\u7b54\u3002\u800c\u7a0d\u540e\u9700\u8981\u5b8c\u6210\u7684\u5de5\u4f5c\u5219\u4f1a\u88ab\u63a8\u8fdf\u5230\u4e0b\u534a\u90e8\u53bb\uff0c\u5728\u5408\u9002\u7684\u65f6\u673a\u6267\u884c\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u591a\u79cd\u4e0b\u534a\u90e8\u7684\u673a\u5236\uff0c\u7a0d\u540e\u4f1a\u505a\u8bf4\u660e\u3002
\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7request_irq()
\u51fd\u6570\u6ce8\u518c\u4e00\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u4e14\u6fc0\u6d3b\u7ed9\u5b9a\u7684\u4e2d\u65ad\u7ebf\uff1a
int request_irq(unsigned int irq,\n irq_handler_t handler,\n unsigned long flags,\n const char *name,\n void *dev)\n
\u7b2c\u4e00\u4e2a\u53c2\u6570irq\u8868\u793a\u8981\u5206\u914d\u7684\u4e2d\u65ad\u53f7\u3002 \u7b2c\u4e8c\u4e2a\u53c2\u6570handler\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u6307\u5411\u5904\u7406\u8fd9\u4e2a\u4e2d\u65ad\u7684\u5b9e\u9645\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002
typedef irqreturn_t (*irq_handler_t)(int, void*);\n
\u7b2c\u4e09\u4e2a\u53c2\u6570flags\u53ef\u4ee5\u4e3a0\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e0b\u5217\u4e00\u4e2a\u6216\u591a\u4e2a\u6807\u5fd7\u7684\u4f4d\u63a9\u7801\uff1a
IRQF_DISABLED\u2014\u2014\u7981\u6b62\u6240\u6709\u5176\u4ed6\u4e2d\u65ad\uff0c\u65b0\u5185\u6838\u5df2\u79fb\u9664\u3002 IRQF_TIMER\u2014\u2014\u7cfb\u7edf\u5b9a\u65f6\u5668\u6807\u5fd7 IRQF_SHARED\u2014\u2014\u5728\u591a\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e4b\u95f4\u5171\u4eab\u4e2d\u65ad\u7ebf\u3002\u5982\u679c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5728\u540c\u4e00\u6761\u7ebf\u4e0a\u6ce8\u518c\uff0c\u90a3\u4e48\u5fc5\u987b\u6307\u5b9a\u8fd9\u4e2a\u6807\u5fd7\u3002 \u7b2c\u56db\u4e2a\u53c2\u6570name\u662f\u4e0e\u4e2d\u65ad\u76f8\u5173\u7684\u8bbe\u5907\u7684ASCII\u6587\u672c\u8868\u793a\u3002\u8fd9\u4e9b\u540d\u5b57\u4f1a\u88ab/proc/irq\u548c/proc/interrupts\u6587\u4ef6\u4f7f\u7528\u3002
\u7b2c\u4e94\u4e2a\u53c2\u6570dev\u7528\u4e8e\u786e\u5b9a\u5171\u4eab\u4e2d\u65ad\u7ebf\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002\u5f53\u591a\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5171\u4eab\u67d0\u6761\u4e2d\u65ad\u7ebf\uff0c\u5176\u4e2d\u67d0\u4e2a\u9700\u8981\u91ca\u653e\u65f6\uff0cdev\u5c06\u63d0\u4f9b\u552f\u4e00\u7684\u6807\u5fd7\u4fe1\u606f\u4ee5\u4fbf\u786e\u5b9a\u662f\u54ea\u4e2a\u7a0b\u5e8f\u9700\u8981\u5220\u9664\u3002
request_irq()
\u6210\u529f\u8fd4\u56de0\uff0c\u9519\u8bef\u8fd4\u56de\u975e0\u3002\u6700\u5e38\u89c1\u7684\u9519\u8bef\u662f-EBUSY\uff0c\u8868\u793a\u7ed9\u5b9a\u7684\u4e2d\u65ad\u7ebf\u5df2\u7ecf\u88ab\u4f7f\u7528\u3002
request_irq()
\u53ef\u80fd\u4f1a\u7761\u7720\uff0c\u56e0\u6b64\u4e0d\u80fd\u5728\u4e0d\u5141\u8bb8\u963b\u585e\u4ee3\u7801\u4e2d\u8c03\u7528\u8be5\u51fd\u6570\u3002
\u5378\u8f7d\u9a71\u52a8\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u6ce8\u9500\u54cd\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u91ca\u653e\u4e2d\u65ad\u7ebf\uff1a
void free_irq(unsigned int irq, void *dev)\n
\u5982\u679c\u6307\u5b9a\u7684\u4e2d\u65ad\u7ebf\u4e0d\u662f\u5171\u4eab\u7684\uff0c\u90a3\u4e48\u8be5\u51fd\u6570\u5220\u9664\u5904\u7406\u7a0b\u5e8f\u7684\u540c\u65f6\u5c06\u7981\u7528\u8fd9\u6761\u4e2d\u65ad\u7ebf\u3002\u5982\u679c\u662f\u5171\u4eab\u7684\uff0c\u90a3\u4e48\u4ec5\u5220\u9664\u6240\u5bf9\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u800c\u8fd9\u6761\u4e2d\u65ad\u7ebf\u53ea\u6709\u5728\u5220\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u65f6\u624d\u4f1a\u88ab\u7981\u7528\u3002
\u8981\u7f16\u5199\u81ea\u5df1\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u9700\u8981\u7528\u5230\u4ee5\u4e0b\u51fd\u6570\uff1a
static irqreturn_t intr_handler(int irq, void *dev)\n
\u53c2\u6570irq\u5df2\u7ecf\u6ca1\u6709\u4ec0\u4e48\u7528\u4e86\uff0c\u53c2\u6570dev\u7528\u6765\u5411\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4f20\u9012\u6570\u636e\u7ed3\u6784\u3002
Linux\u4e0a\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u65e0\u9700\u8981\u6c42\u53ef\u91cd\u5165\u3002\u56e0\u4e3a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u65f6\u76f8\u5e94\u4e2d\u65ad\u7ebf\u4e0a\u7684\u4e2d\u65ad\u662f\u5c4f\u853d\u7684\uff0c\u4e5f\u5c31\u662f\u4e0d\u4f1a\u53d1\u751f\u76f8\u540c\u4e2d\u65ad\u7684\u5d4c\u5957\u3002\u4f46\u4e0d\u540c\u4e2d\u65ad\u7684\u5d4c\u5957\u6709\u53ef\u80fd\u53d1\u751f\u3002
\u5bf9\u4e8e\u5171\u4eab\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u9664\u4e86\u8981\u6307\u5b9arequest_irq()
\u51fd\u6570\u4e2d\u7684\u53c2\u6570flags\u4e3aIRQF_SHARED\u6807\u5fd7\uff0c\u8fd8\u9700\u8981\u4fdd\u8bc1\u53c2\u6570dev\u7684\u552f\u4e00\u6027\u3002\u5f53\u5185\u6838\u63a5\u6536\u4e00\u4e2a\u4e2d\u65ad\u540e\uff0c\u5b83\u5c06\u4f9d\u6b21\u8c03\u7528\u5728\u8be5\u4e2d\u65ad\u7ebf\u4e0a\u6ce8\u518c\u7684\u6bcf\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u3002\u56e0\u6b64\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u5fc5\u987b\u77e5\u9053\u5b83\u662f\u5426\u8be5\u4e3a\u8fd9\u4e2a\u4e2d\u65ad\u8d1f\u8d23\uff0c\u5982\u679c\u4e0d\u662f\u5c31\u8981\u7acb\u5373\u9000\u51fa\u3002
"},{"location":"linux/kernel/interrupt/#_3","title":"\u4e2d\u65ad\u5904\u7406\u673a\u5236","text":"\u4e2d\u65ad\u5904\u7406\u7cfb\u7edf\u5728Linux\u4e2d\u7684\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u4f53\u7cfb\u7ed3\u6784\u3002\u4e0a\u56fe\u662f\u4e2d\u65ad\u4ece\u786c\u4ef6\u5230\u5185\u6838\u6267\u884c\u7684\u8fc7\u7a0b\u3002\u5f53\u4e00\u4e2a\u8bbe\u5907\u4ea7\u751f\u4e2d\u65ad\u540e\uff0c\u901a\u8fc7\u603b\u7ebf\u628a\u7535\u4fe1\u53f7\u53d1\u9001\u7ed9\u4e2d\u65ad\u63a7\u5236\u5668\u3002\u5982\u679c\u4e2d\u65ad\u7ebf\u662f\u6fc0\u6d3b\u7684\uff0c\u90a3\u4e48\u4e2d\u65ad\u63a7\u5236\u5668\u5c31\u4f1a\u628a\u4e2d\u65ad\u53d1\u9001\u7ed9\u5904\u7406\u5668\u3002\u5728\u5927\u591a\u6570\u4f53\u7cfb\u7ed3\u6784\u4e2d\uff0c\u8fd9\u4e2a\u5de5\u4f5c\u5c31\u662f\u901a\u8fc7\u7535\u4fe1\u53f7\u7ed9\u5904\u7406\u5668\u7684\u7279\u5b9a\u7ba1\u811a\u53d1\u9001\u4e00\u4e2a\u4fe1\u53f7\u3002\u9664\u975e\u5904\u7406\u5668\u7981\u6b62\u4e86\u8be5\u4e2d\u65ad\uff0c\u5426\u5219\u5b83\u4f1a\u7acb\u523b\u505c\u4e0b\u5f53\u524d\u6267\u884c\u7684\u4ee3\u7801\uff0c\u5173\u95ed\u4e2d\u65ad\u7cfb\u7edf\uff0c\u7136\u540e\u8df3\u5230\u5185\u5b58\u4e2d\u9884\u5b9a\u4e49\u7684\u4f4d\u7f6e\u5f00\u59cb\u6267\u884c\u90a3\u91cc\u7684\u4ee3\u7801\u3002\u8fd9\u4e2a\u9884\u5b9a\u4e49\u7684\u4f4d\u7f6e\u7531\u5185\u6838\u8bbe\u7f6e\uff0c\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002
\u5bf9\u4e8e\u6bcf\u6761\u4e2d\u65ad\u7ebf\uff0c\u5904\u7406\u5668\u90fd\u4f1a\u8df3\u5230\u5bf9\u5e94\u7684\u4e00\u4e2a\u552f\u4e00\u7684\u4f4d\u7f6e\u3002\u8fd9\u6837\uff0c\u5185\u6838\u5c31\u53ef\u4ee5\u77e5\u9053\u6240\u63a5\u6536\u4e2d\u65ad\u7684IRQ\u53f7\u4e86\u3002\u521d\u59cb\u5165\u53e3\u70b9\u5728\u6808\u4e2d\u4fdd\u5b58IRQ\u53f7\uff0c\u5e76\u5b58\u653e\u5f53\u524d\u5bc4\u5b58\u5668\u7684\u503c\uff08\u8fd9\u4e9b\u503c\u5c5e\u4e8e\u88ab\u4e2d\u65ad\u7684\u4efb\u52a1\uff09\u3002\u7136\u540e\uff0c\u7531\u5185\u6838\u8c03\u7528do_IRQ()
\u51fd\u6570\uff1a
unsigned int do_IRQ(struct pt_regs *regs)\n
\u7531\u4e8e\u521d\u59cb\u5165\u53e3\u70b9\u5df2\u7ecf\u5c06IRQ\u53f7\u548c\u5bc4\u5b58\u5668\u7684\u503c\u4fdd\u5b58\u5728\u6808\u4e2d\u4e86\uff0c\u6240\u4ee5\u51fd\u6570do_IRQ()
\u53ef\u4ee5\u76f4\u63a5\u63d0\u53d6\u6808\u4e2d\u7684\u53c2\u6570\u3002
do_IRQ()
\u6267\u884c\u5b8c\u4e2d\u65ad\u670d\u52a1\u5668\u7a0b\u5e8f\u540e\uff0c\u4f1a\u68c0\u67e5\u662f\u5426\u9700\u8981\u91cd\u65b0\u8c03\u5ea6\uff08need_resched\u6807\u5fd7\u4f4d\uff09\uff0c\u7136\u540e\u5224\u65ad\u8fd4\u56de\u54ea\u4e2a\u7a7a\u95f4\uff1a
\u8fd4\u56de\u7528\u6237\u7a7a\u95f4\uff1a\u8c03\u7528schedule()
\u51fd\u6570\u3002
\u8fd4\u56de\u5185\u6838\u7a7a\u95f4\uff1a\u5982\u679cpreempt_count\u6807\u5fd7\u4e3a0\uff0c\u8c03\u7528schedule()
\u51fd\u6570\uff0c\u5426\u5219\u4e0d\u4f1a\u89e6\u53d1\u8c03\u5ea6\u3002
procfs\u662f\u4e00\u4e2a\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bfb/proc/interrupts\u6587\u4ef6\u8bfb\u53d6\u7cfb\u7edf\u4e2d\u4e0e\u4e2d\u65ad\u76f8\u5173\u7684\u7edf\u8ba1\u4fe1\u606f\u3002
"},{"location":"linux/kernel/interrupt/#_4","title":"\u4e2d\u65ad\u63a7\u5236","text":"Linux\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7ec4\u63a5\u53e3\u7528\u4e8e\u64cd\u4f5c\u673a\u5668\u4e0a\u7684\u4e2d\u65ad\u72b6\u6001\u3002\u8fd9\u4e9b\u63a5\u53e3\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u80fd\u591f\u7981\u6b62\u5f53\u524d\u5904\u7406\u5668\u7684\u4e2d\u65ad\u7cfb\u7edf\uff0c\u6216\u5c4f\u853d\u6389\u6574\u4e2a\u673a\u5668\u7684\u4e00\u6761\u4e2d\u65ad\u7ebf\u7684\u80fd\u529b\u3002\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u662f\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u63a7\u5236\u4e2d\u65ad\u7cfb\u7edf\u7684\u539f\u56e0\u5f52\u6839\u5230\u5e95\u662f\u9700\u8981\u540c\u6b65\u3002\u901a\u8fc7\u7981\u6b62\u4e2d\u65ad\uff0c\u53ef\u4ee5\u786e\u4fdd\u67d0\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e0d\u4f1a\u88ab\u62a2\u5360\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u7981\u6b62\u5185\u6838\u62a2\u5360\u3002
\u7981\u6b62\u548c\u6fc0\u6d3b\u672c\u5730\u4e2d\u65ad\u7684\u51fd\u6570\u4e3a\uff1a
local_irq_disable();\n\nlocal_irq_enable();\n
\u5982\u679c\u5728\u8c03\u7528local_irq_disable()
\u51fd\u6570\u524d\u5df2\u7ecf\u7981\u6b62\u4e86\u4e2d\u65ad\uff0c\u90a3\u4e48\u8be5\u64cd\u4f5c\u4f1a\u5e26\u6765\u6f5c\u5728\u7684\u5371\u9669\u3002\u540c\u6837\uff0clocal_irq_enable()
\u51fd\u6570\u4e5f\u5b58\u5728\u5371\u9669\uff0c\u56e0\u4e3a\u5b83\u4f1a\u65e0\u6761\u4ef6\u6fc0\u6d3b\u4e2d\u65ad\u3002\u5f53\u5185\u6838\u4ee3\u7801\u53d8\u5f97\u590d\u6742\u65f6\uff0c\u6211\u4eec\u5e76\u4e0d\u77e5\u9053\u5f53\u524d\u5904\u7406\u5668\u4e2d\u65ad\u72b6\u6001\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u79cd\u673a\u5236\uff0c\u4ec5\u4ec5\u65f6\u628a\u4e2d\u65ad\u6062\u590d\u5230\u4ee5\u524d\u7684\u72b6\u6001\u800c\u4e0d\u662f\u7b80\u5355\u5730\u7981\u6b62\u6216\u8005\u662f\u6fc0\u6d3b\u3002
unsigned long flags;\nlocal_irq_save(flags);\nlocal_irq_restore(flags);\n
\u5728\u524d\u9762\u7684\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u77e5\u9053\u4e86\u7981\u6b62\u6574\u4e2a\u5904\u7406\u5668\u4e0a\u6240\u6709\u4e2d\u65ad\u7684\u51fd\u6570\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u7981\u6b62\u7279\u5b9a\u7684\u4e2d\u65ad\u7ebf\u3002\u76f8\u5173\u51fd\u6570\u5982\u4e0b\uff1a
void disable_irq(unsigned int irq);\nvoid disable_irq_nosync(unsigned int irq);\nvoid enable_irq(unsigned int irq);\nvoid synchronize_irq(unsigned int irq);\n
\u7531\u4e8e\u73b0\u4ee3\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5f80\u5f80\u5171\u4eab\u67d0\u4e2a\u4e2d\u65ad\u7ebf\uff0c\u7981\u6b62\u4e86\u67d0\u6761\u4e2d\u65ad\u7ebf\u4e5f\u5c31\u7981\u6b62\u4e86\u8fd9\u6761\u7ebf\u4e0a\u6240\u6709\u8bbe\u5907\u7684\u4e2d\u65ad\u4f20\u9012\u3002\u56e0\u6b64\u8fd9\u4e9b\u63a5\u53e3\u51fd\u6570\u4e0d\u5e94\u8be5\u88ab\u4f7f\u7528\u3002
"},{"location":"linux/kernel/interrupt/#_5","title":"\u4e0b\u534a\u90e8\u673a\u5236","text":"\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u6709\u4e00\u4e2a\u5feb\u901f\u3001\u5f02\u6b65\u4e14\u7b80\u5355\u7684\u673a\u5236\u8d1f\u8d23\u5bf9\u786c\u4ef6\u8fc5\u901f\u505a\u51fa\u76f8\u5e94\u5e76\u5b8c\u6210\u90a3\u4e9b\u65f6\u95f4\u8981\u6c42\u5f88\u4e25\u683c\u7684\u64cd\u4f5c\u3002\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5f88\u9002\u5408\u4e8e\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\u3002\u800c\u5bf9\u4e8e\u90a3\u4e9b\u65f6\u95f4\u8981\u6c42\u76f8\u5bf9\u5bbd\u677e\u7684\u4efb\u52a1\uff0c\u5e94\u5f53\u653e\u5230\u4e0b\u534a\u90e8\u53bb\u5904\u7406\u3002
\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6700\u597d\u8ba9\u6240\u6709\u7684\u5de5\u4f5c\u90fd\u4ea4\u7ed9\u4e0b\u534a\u90e8\u53bb\u5904\u7406\u3002\u4f46\u662f\uff0c\u603b\u6709\u4e00\u4e9b\u5de5\u4f5c\u9700\u8981\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u6765\u5b8c\u6210\uff0c\u6bd4\u5982\u5bf9\u4e2d\u65ad\u7684\u5230\u8fbe\u8fdb\u884c\u786e\u8ba4\uff0c\u4ece\u786c\u4ef6\u62f7\u8d1d\u6570\u636e\u7b49\u3002\u5982\u4f55\u533a\u5206\u4e0a\u534a\u90e8\u548c\u4e0b\u534a\u90e8\uff0c\u5b8c\u5168\u7531\u9a71\u52a8\u7a0b\u5e8f\u5f00\u53d1\u8005\u81ea\u884c\u5224\u65ad\u3002\u5982\u679c\u4efb\u52a1\u6ee1\u8db3\u4ee5\u4e0b\u8981\u6c42\uff0c\u5219\u9002\u5408\u653e\u5230\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u6267\u884c\u3002
\u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u5bf9\u65f6\u95f4\u975e\u5e38\u654f\u611f\u3002 \u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u548c\u786c\u4ef6\u76f8\u5173\u3002 \u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u4e0d\u80fd\u88ab\u5176\u4ed6\u4e2d\u65ad\u6253\u65ad\u3002 \u5176\u4ed6\u6240\u6709\u4efb\u52a1\uff0c\u8003\u8651\u653e\u5728\u4e0b\u534a\u90e8\u6267\u884c\u3002
"},{"location":"linux/kernel/interrupt/#_6","title":"\u8f6f\u4e2d\u65ad","text":"\u8f6f\u4e2d\u65ad\u7684\u82f1\u6587\u540d\u662fsoftirq\uff0c\u4e0e\u8f6f\u4ef6\u4e2d\u65ad\uff08software irq\uff09\u6ca1\u6709\u5173\u7cfb\u3002
\u8f6f\u4e2d\u65ad\u4f7f\u7528\u6bd4\u8f83\u5c11\uff0ctasklet\u662f\u4e0b\u534a\u90e8\u66f4\u5e38\u7528\u8fc7\u7684\u4e00\u79cd\u5f62\u5f0f\u3002\u4f46\u662f\uff0c\u7531\u4e8etasklet\u662f\u901a\u8fc7\u8f6f\u4e2d\u65ad\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u4e5f\u6709\u5fc5\u8981\u5148\u7814\u7a76\u8f6f\u4e2d\u65ad\u3002
"},{"location":"linux/kernel/interrupt/#_7","title":"\u8f6f\u4e2d\u65ad\u7684\u5b9e\u73b0","text":"\u8f6f\u4e2d\u65ad\u5728\u7f16\u8bd1\u671f\u95f4\u9759\u6001\u5206\u914d\uff0c\u7531softirq_action
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct softirq_action{\n void (*action)(struct softirq_action*);\n};\n
\u5728<kernel/softirq.c>\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5305\u542b\u670932\u4e2a\u8be5\u7ed3\u6784\u4f53\u7684\u6570\u7ec4\uff1a
static struct softirq_action softirq_vec[NR_SOFTIRQS];\n
\u6bcf\u4e2a\u88ab\u6ce8\u518c\u7684\u8f6f\u4e2d\u65ad\u90fd\u5360\u636e\u8be5\u6570\u7ec4\u7684\u4e00\u9879\uff0c\u56e0\u6b64\u6700\u5927\u670932\u4e2a\u8f6f\u4e2d\u65ad\u3002
\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8faction\u7684\u51fd\u6570\u539f\u578b\u5982\u4e0b\uff1a
void softirq_handler(struct softirq_action *)\n
\u5f53\u5185\u6838\u8fd0\u884c\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u65f6\uff0c\u5c31\u4f1a\u6267\u884c\u8fd9\u4e2aaction\u51fd\u6570\uff0c\u5176\u552f\u4e00\u7684\u53c2\u6570\u662f\u6307\u5411\u76f8\u5e94softirq_action
\u7ed3\u6784\u4f53\u7684\u6307\u9488\u3002\u4f8b\u5982\uff0c\u5982\u679cmy_softirq\u6307\u5411softirq_vec\u6570\u7ec4\u7684\u67d0\u9879\uff0c\u90a3\u4e48\u5185\u6838\u5c31\u4f1a\u7528\u5982\u4e0b\u7684\u65b9\u5f0f\u8c03\u7528\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\u7684\u51fd\u6570\uff1a
my_softirq->action(my_softirq);\n
\u4e00\u4e2a\u6ce8\u518c\u7684\u8f6f\u4e2d\u65ad\u5fc5\u987b\u5728\u88ab\u6807\u8bb0\u540e\u624d\u4f1a\u6267\u884c\uff0c\u8fd9\u88ab\u79f0\u4e3a\u89e6\u53d1\u8f6f\u4e2d\u65ad\uff08raising the softirq\uff09\u3002\u901a\u5e38\uff0c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4f1a\u5728\u8fd4\u56de\u524d\u6807\u8bb0\u5b83\u7684\u8f6f\u4e2d\u65ad\uff0c\u4f7f\u5176\u5728\u7a0d\u540e\u88ab\u6267\u884c\u3002do_softirq()
\u51fd\u6570\u4f1a\u68c0\u67e5softirq_vec\u6570\u7ec4\u4e2d\u6240\u6709\u5f85\u5904\u7406\u7684\u8f6f\u4e2d\u65ad\uff0c\u8c03\u7528\u5b83\u4eec\u7684\u5904\u7406\u7a0b\u5e8f\u3002
"},{"location":"linux/kernel/interrupt/#_8","title":"\u4f7f\u7528\u8f6f\u4e2d\u65ad","text":"\u8f6f\u4e2d\u65ad\u4fdd\u7559\u7ed9\u7cfb\u7edf\u4e2d\u5bf9\u65f6\u95f4\u8981\u6c42\u6700\u4e25\u683c\u4ee5\u53ca\u6700\u91cd\u8981\u7684\u4e0b\u534a\u90e8\u4f7f\u7528\u3002\u5185\u6838\u5728<linux/interrupt.h>\u4e2d\u5df2\u7ecf\u5b9a\u4e49\u4e86\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b\u6765\u9759\u6001\u5730\u58f0\u660e\u8f6f\u4e2d\u65ad\uff0c\u7d22\u5f15\u53f7\u8868\u793a\u5176\u4f18\u5148\u7ea7\u3002\u8981\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u8f6f\u4e2d\u65ad\u5fc5\u987b\u5728\u6b64\u679a\u4e3e\u7c7b\u578b\u4e2d\u52a0\u5165\u65b0\u7684\u9879\uff0c\u800c\u4e14\u4f60\u5fc5\u987b\u6839\u636e\u5b83\u7684\u4f18\u5148\u7ea7\u6765\u51b3\u5b9a\u52a0\u5165\u7684\u4f4d\u7f6e\u3002\u4e0b\u8868\u5217\u51fa\u4e86\u5df2\u6709\u7684tasklet\u7c7b\u578b\u3002
tasklet \u4f18\u5148\u7ea7 \u8f6f\u4e2d\u65ad\u63cf\u8ff0 HI_SOFTIRQ 0 \u4f18\u5148\u7ea7\u9ad8\u7684tasklets TIMER_SOFTIRQ 1 \u5b9a\u65f6\u5668\u7684\u4e0b\u534a\u90e8 NET_TX_SOFTIRQ 2 \u53d1\u9001\u7f51\u7edc\u6570\u636e\u5305 NET_RX_SOFTIRQ 3 \u63a5\u6536\u7f51\u7edc\u6570\u636e\u5305 BLOCK_SOFTIRQ 4 BLOCK\u88c5\u7f6e TASKLET_SOFTIRQ 5 \u6b63\u5e38\u4f18\u5148\u6743\u7684tasklets SCHED_SOFTIRQ 6 \u8c03\u5ea6\u7a0b\u5e8f HRTIMER_SOFTIRQ 7 \u9ad8\u5206\u8fa8\u7387\u5b9a\u65f6\u5668 RCU_SOFTIRQ 8 RCU\u9501\u5b9a \u63a5\u7740\uff0c\u5728\u8fd0\u884c\u65f6\u901a\u8fc7\u8c03\u7528open_softirq()
\u51fd\u6570\u6ce8\u518c\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u8be5\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u8f6f\u4e2d\u65ad\u7d22\u5f15\u53f7\u548c\u5904\u7406\u51fd\u6570\uff1a
open_softirq(NET_TX_SOFTIRQ, net_tx_action)\n
\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u6267\u884c\u7684\u65f6\u5019\uff0c\u5141\u8bb8\u54cd\u5e94\u4e2d\u65ad\uff0c\u4f46\u5b83\u81ea\u5df1\u4e0d\u80fd\u4f11\u7720\u3002\u5728\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u5f53\u524d\u5904\u7406\u5668\u4e0a\u7684\u8f6f\u4e2d\u65ad\u88ab\u7981\u6b62\u3002\u4f46\u5176\u4ed6\u5904\u7406\u5668\u4ecd\u7136\u53ef\u4ee5\u6267\u884c\u522b\u7684\u8f6f\u4e2d\u65ad\u3002\u8fd9\u610f\u5473\u7740\u5171\u4eab\u6570\u636e\u9700\u8981\u9501\u7684\u4fdd\u62a4\u3002\u56e0\u6b64\u5927\u90e8\u5206\u8f6f\u4e2d\u65ad\u5904\u7406\uff0c\u90fd\u901a\u8fc7\u91c7\u53d6\u5355\u5904\u7406\u5668\u6570\u636e\u6765\u907f\u514d\u52a0\u9501\uff0c\u4ece\u800c\u63d0\u4f9b\u66f4\u51fa\u8272\u7684\u6027\u80fd\u3002
\u5728\u6ce8\u518c\u5b8c\u4e4b\u540e\uff0c\u65b0\u7684\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5c31\u80fd\u591f\u8fd0\u884c\u3002raise_softirq()
\u51fd\u6570\u53ef\u4ee5\u5c06\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u8bbe\u7f6e\u4e3a\u6302\u8d77\u72b6\u6001\uff0c\u8ba9\u5b83\u5728\u4e0b\u6b21\u8c03\u7528do_softirq()
\u51fd\u6570\u65f6\u6295\u5165\u8fd0\u884c\u3002
\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\u89e6\u53d1\u8f6f\u4e2d\u65ad\u662f\u6700\u5e38\u89c1\u7684\u5f62\u5f0f\u3002\u5185\u6838\u5728\u6267\u884c\u5b8c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e4b\u540e\uff0c\u9a6c\u4e0a\u5c31\u4f1a\u8c03\u7528do_softirq()
\u51fd\u6570\uff0c\u4e8e\u662f\u8f6f\u4e2d\u65ad\u5f00\u59cb\u6267\u884c\u7ed9\u5b9a\u7684\u4efb\u52a1\u3002
"},{"location":"linux/kernel/interrupt/#tasklet","title":"tasklet","text":"tasklet\u662f\u5229\u7528\u8f6f\u4e2d\u65ad\u5b9e\u73b0\u7684\u4e00\u79cd\u4e0b\u534a\u90e8\u673a\u5236\uff0c\u4f46\u662f\u5b83\u7684\u63a5\u53e3\u66f4\u7b80\u5355\uff0c\u9501\u4fdd\u62a4\u8981\u6c42\u8f83\u4f4e\u3002\u5927\u591a\u6570\u60c5\u51b5\u90fd\u53ef\u4ee5\u4f7f\u7528tasklet\u6765\u5b8c\u6210\u4f60\u9700\u8981\u7684\u5de5\u4f5c\u3002
"},{"location":"linux/kernel/interrupt/#tasklet_1","title":"tasklet\u7684\u5b9e\u73b0","text":"tasklet\u7531\u4e24\u7c7b\u8f6f\u4e2d\u65ad\u4ee3\u8868\uff1aHI_SOFTIRQ\u548cTASKLET_SOFTIRQ\u3002\u524d\u8005\u4f18\u5148\u7ea7\u6bd4\u540e\u8005\u9ad8\u3002
tasklet\u7ed3\u6784\u4f53\u5982\u4e0b\uff1a
struct tasklet_struct {\n struct tasklet_struct *next; //\u94fe\u8868\u4e2d\u4e0b\u4e00\u4e2atasklet\n unsigned long state; //tasklet\u7684\u72b6\u6001\n atomic_t count; //\u5f15\u7528\u8ba1\u6570\u5668\n void (*func)(unsigned long); //\u5904\u7406\u51fd\u6570\n unsigned long data; //\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570\n};\n
state\u6210\u5458\u53ea\u80fd\u57280\u3001TASKLET_STATE_SCHED\u548cTASKLET_STATE_RUN\u4e4b\u95f4\u53d6\u503cTASKLET_STATE_SCHED\u8868\u660e tasklet\u5df2\u88ab\u8c03\u5ea6\uff0c\u6b63\u51c6\u5907\u6295\u4eba\u8fd0\u884c\uff0cTASKLET_STATE_RUN\u8868\u660e\u8be5tasklet\u6b63\u5728\u8fd0\u884c\u3002TASKLET_STATE_RUN\u53ea\u6709\u5728\u591a\u5904\u7406\u5668\u7684\u7cfb\u7edf\u4e0a\u624d\u4f1a\u4f5c\u4e3a\u4e00\u79cd\u4f18\u5316\u6765\u4f7f\u7528\uff0c\u5355\u5904\u7406\u5668\u7cfb\u7edf\u4efb\u4f55\u65f6\u5019\u90fd\u6e05\u695a\u5355\u4e2atasklet\u662f\u4e0d\u662f\u6b63\u5728\u8fd0\u884c(\u5b83\u8981\u4e48\u5c31\u662f\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\uff0c\u8981\u4e48\u4e0d\u662f)\u3002
count\u6210\u5458\u662ftasklet\u7684\u5f15\u7528\u8ba1\u6570\u5668\u3002\u5982\u679c\u5b83\u4e0d\u4e3a0\uff0c\u5219tasklet\u88ab\u7981\u6b62\uff1b\u53ea\u6709\u5f53\u5b83\u4e3a0\u65f6\uff0ctasklet\u624d\u88ab\u6fc0\u6d3b\u3002
\u5df2\u8c03\u5ea6\uff08\u6216\u8005\u53eb\u5df2\u6fc0\u6d3b\uff09\u7684tasklet\u5b58\u653e\u5728tasklet_vec\uff08\u666e\u901atasklet\uff09\u548ctasklet_hi_vec\uff08\u9ad8\u4f18\u5148\u7ea7\u7684tasklet\uff09\u6570\u7ec4\u4e2d\u3002\u8fd9\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u90fd\u662f\u7531tasklet_struct
\u7ed3\u6784\u4f53\u6784\u6210\u7684\u94fe\u8868\uff0c\u94fe\u8868\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4e00\u4e2a\u4e0d\u540c\u7684tasklet\u3002
tasklet\u7531tasklet_schedule()
\u548ctasklet_hi_schedule()
\u51fd\u6570\u8fdb\u884c\u8c03\u5ea6\uff0c\u5b83\u4eec\u63a5\u53d7\u4e00\u4e2a\u6307\u5411tasklet_struct
\u7ed3\u6784\u7684\u6307\u9488\u4f5c\u4e3a\u53c2\u6570\u3002
"},{"location":"linux/kernel/interrupt/#tasklet_2","title":"\u4f7f\u7528tasklet","text":"\u5982\u679c\u662f\u9759\u6001\u521b\u5efa\u4e00\u4e2atasklet\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u4e2a\u5b8f\u4e2d\u7684\u4e00\u4e2a\uff1a
DECLARE_TASKLET(name, func, data)\nDECLARE_TASKLET_DISABLED(name, func, data)\n
\u8fd9\u4e24\u4e2a\u5b8f\u90fd\u80fd\u9759\u6001\u521b\u5efa\u4e00\u4e2atasklet_struct
\u7ed3\u6784\uff0c\u533a\u522b\u5728\u4e8e\u5f15\u7528\u8ba1\u6570count\u7684\u521d\u59cb\u503c\u4e0d\u540c\u3002\u7b2c\u4e00\u4e2a\u8bbe\u4e3a0\uff0c\u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001\uff1b\u7b2c\u4e8c\u4e2a\u8bbe\u4e3a1\uff0c\u5904\u4e8e\u7981\u6b62\u72b6\u6001\u3002
\u5982\u679c\u662f\u52a8\u6001\u521b\u5efa\uff1a
tasklet_init(t, tasklet_handler, dev);\n
\u7f16\u5199\u81ea\u5df1\u7684tasklet\u5904\u7406\u7a0b\u5e8f\uff1a
void tasklet_handler(unsigned long data)\n
tasklet\u4e0d\u80fd\u7761\u7720\uff0c\u4e24\u4e2a\u76f8\u540c\u7684tasklet\u4e0d\u4f1a\u540c\u65f6\u6267\u884c\uff0c\u4f46\u5982\u679c\u4e0e\u5176\u4ed6tasklet\u6216\u8005\u662f\u8f6f\u4e2d\u65ad\u5171\u4eab\u4e86\u6570\u636e\uff0c\u90a3\u4e48\u5fc5\u987b\u8fdb\u884c\u9501\u4fdd\u62a4\u3002
\u901a\u8fc7\u8c03\u7528tasklet_schedule()
\u51fd\u6570\u5e76\u4f20\u9012\u7ed9\u5b83\u76f8\u5e94\u7684tasklet_struct
\u6307\u9488\uff0c\u8be5tasklet\u5c31\u4f1a\u88ab\u8c03\u5ea6\u4ee5\u4fbf\u6267\u884c\uff1a
tasklet_schedule(&my_tasklet);\n
\u4e00\u4e2atasklet\u603b\u662f\u5728\u8c03\u5ea6\u5b83\u7684\u5904\u7406\u5668\u4e0a\u8fd0\u884c\u3002\u8981\u7981\u6b62/\u4f7f\u80fdtasklet\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7684\u51fd\u6570\uff1a
tasklet_disable(&my_tasklet); //\u7b49\u5f85tasklet\u6267\u884c\u5b8c\u6bd5\ntasklet_disable_nosync(&my_tasklet); //\u4e0d\u4f1a\u7b49\u5f85tasklet\ntasklet_enable(&my_tasklet); //\u6fc0\u6d3btasklet\ntasklet_kill(&my_tasklet); //\u79fb\u9664\u5df2\u8c03\u5ea6\u7684tasklet\n
"},{"location":"linux/kernel/interrupt/#ksoftirqd","title":"ksoftirqd","text":"\u6bcf\u4e2a\u5904\u7406\u5668\u90fd\u6709\u4e00\u7ec4\u8f85\u52a9\u5904\u7406\u8f6f\u4e2d\u65ad\uff08\u548ctasklet\uff09\u7684\u5185\u6838\u7ebf\u7a0b\u3002\u5f53\u5185\u6838\u4e2d\u51fa\u73b0\u5927\u91cf\u8f6f\u4e2d\u65ad\u7684\u65f6\u5019\uff0c\u5185\u6838\u7ebf\u7a0b\u5c31\u4f1a\u9009\u62e9\u5408\u9002\u7684\u65f6\u673a\u6765\u5904\u7406\u8f6f\u4e2d\u65ad\u3002
\u5728\u5927\u6d41\u91cf\u7684\u7f51\u7edc\u901a\u4fe1\u4e2d\uff0c\u8f6f\u4e2d\u65ad\u7684\u89e6\u53d1\u9891\u7387\u53ef\u80fd\u5f88\u9ad8\uff0c\u751a\u81f3\u8fd8\u4f1a\u81ea\u884c\u91cd\u590d\u89e6\u53d1\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u7528\u6237\u7a7a\u95f4\u7684\u8fdb\u7a0b\u65e0\u6cd5\u83b7\u5f97\u8db3\u591f\u7684\u5904\u7406\u5668\u65f6\u95f4\u3002\u5982\u679c\u8f6f\u4e2d\u65ad\u548c\u91cd\u590d\u89e6\u53d1\u7684\u8f6f\u4e2d\u65ad\u90fd\u88ab\u7acb\u5373\u5904\u7406\uff0c\u90a3\u4e48\u5f53\u8d1f\u8f7d\u5f88\u9ad8\u7684\u65f6\u5019\uff0c\u7cfb\u7edf\u5c31\u4f1a\u51fa\u73b0\u660e\u663e\u7684\u5361\u987f\u73b0\u8c61\u3002\u5982\u679c\u9009\u62e9\u4e0d\u5904\u7406\u91cd\u65b0\u89e6\u53d1\u7684\u8f6f\u4e2d\u65ad\uff0c\u53c8\u4f1a\u6d6a\u8d39\u95f2\u7f6e\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u5bfc\u81f4\u8f6f\u4e2d\u65ad\u51fa\u73b0\u9965\u997f\u73b0\u8c61\u3002
\u5185\u6838\u4e2d\u7684\u65b9\u6848\u65f6\u4e0d\u4f1a\u7acb\u5373\u5904\u7406\u91cd\u590d\u89e6\u53d1\u7684\u8f6f\u4e2d\u65ad\u3002\u5f53\u5927\u91cf\u8f6f\u4e2d\u65ad\u51fa\u73b0\u7684\u65f6\u5019\uff0c\u5185\u6838\u4f1a\u5524\u9192\u4e00\u7ec4\u5185\u6838\u7ebf\u7a0b\u6765\u5904\u7406\u8fd9\u4e9b\u8d1f\u8f7d\u3002\u8fd9\u4e9b\u7ebf\u7a0b\u5728\u6700\u4f4e\u4f18\u5148\u7ea7\uff08nice=19\uff09\u8fd0\u884c\uff0c\u907f\u514d\u4e0e\u5176\u4ed6\u4efb\u52a1\u62a2\u5360\u8d44\u6e90\u3002
\u6bcf\u4e2a\u5904\u7406\u5668\u90fd\u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u7ebf\u7a0b\uff0c\u540d\u5b57\u4e3aksoftirqd/n\uff0cn\u4e3a\u5904\u7406\u5668\u7f16\u53f7\u3002\u53ea\u8981\u6709\u5f85\u5904\u7406\u7684\u8f6f\u4e2d\u65ad\uff0cksoftirqd\u5c31\u4f1a\u8c03\u7528do_softirq()
\u51fd\u6570\u6765\u5904\u7406\u5b83\u4eec\u3002
"},{"location":"linux/kernel/interrupt/#_9","title":"\u5de5\u4f5c\u961f\u5217","text":"\u5de5\u4f5c\u961f\u5217\u662f\u4e00\u79cd\u5ef6\u540e\u6267\u884c\u7684\u673a\u5236\uff0c\u53ef\u4ee5\u5c06\u540e\u7eed\u7684\u5de5\u4f5c\u4ea4\u7ed9\u4e00\u4e2a\u5185\u6838\u7ebf\u7a0b\u6267\u884c\u2014\u2014\u8fd9\u4e2a\u4e0b\u534a\u90e8\u5206\u603b\u662f\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u6267\u884c\u3002\u8fd9\u6837\uff0c\u901a\u8fc7\u5de5\u4f5c\u961f\u5217\u5b9e\u73b0\u7684\u4ee3\u7801\u5c31\u80fd\u4eab\u53d7\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u7684\u6240\u6709\u4f18\u52bf\uff0c\u6bd4\u5982\u53ef\u4ee5\u91cd\u65b0\u8c03\u5ea6\u751a\u81f3\u662f\u7761\u7720\u3002
\u5982\u679c\u63a8\u540e\u6267\u884c\u7684\u4efb\u52a1\u9700\u8981\u7761\u7720\uff0c\u90a3\u4e48\u5c31\u9009\u62e9\u5de5\u4f5c\u961f\u5217\u3002\u5426\u5219\u5c31\u9009\u62e9\u8f6f\u4e2d\u65ad\u6216tasklet\u3002\u5de5\u4f5c\u961f\u5217\u5728\u4f60\u9700\u8981\u83b7\u5f97\u5927\u91cf\u5185\u5b58\u65f6\uff0c\u9700\u8981\u83b7\u53d6\u4fe1\u53f7\u91cf\u65f6\uff0c\u9700\u8981\u6267\u884c\u963b\u585e\u5f0f\u7684I/O\u64cd\u4f5c\u65f6\uff0c\u5b83\u90fd\u4f1a\u975e\u5e38\u6709\u7528\u3002
"},{"location":"linux/kernel/interrupt/#_10","title":"\u5de5\u4f5c\u961f\u5217\u7684\u5b9e\u73b0","text":"\u5de5\u4f5c\u961f\u5217\u5b50\u7cfb\u7edf\u63d0\u4f9b\u4e86\u7f3a\u7701\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\uff08worker thread\uff09\u6765\u5904\u7406\u9700\u8981\u63a8\u540e\u7684\u5de5\u4f5c\u3002\u7f3a\u7701\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u53eb\u505aevents/n\uff0cn\u4e3a\u5904\u7406\u5668\u7684\u7f16\u53f7\u3002\u4f60\u53ef\u4ee5\u521b\u5efa\u81ea\u5df1\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\uff0c\u4e0d\u8fc7\u4e00\u822c\u4f7f\u7528\u7f3a\u7701\u7ebf\u7a0b\u5373\u53ef\u3002\u7136\u800c\uff0c\u5982\u679c\u4e00\u4e2a\u4efb\u52a1\u9700\u8981\u7279\u522b\u7684\u5904\u7406\uff0c\u6216\u8005\u5b83\u5bf9\u6027\u80fd\u6709\u975e\u5e38\u4e25\u683c\u7684\u8981\u6c42\uff0c\u90a3\u4e48\u521b\u5efa\u4e00\u4e2a\u4e13\u7528\u7684\u5185\u6838\u7ebf\u7a0b\u53ef\u80fd\u5c31\u662f\u5fc5\u8981\u7684\u3002\u4e13\u7528\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u53ef\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u548c\u4f18\u5316\u4efb\u52a1\u7684\u6267\u884c\uff0c\u4f46\u4e5f\u9700\u8981\u66f4\u591a\u7684\u8d44\u6e90\u548c\u7ba1\u7406\u5f00\u9500\u3002
\u5de5\u4f5c\u8005\u7ebf\u7a0b\u7528workqueue_struct
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct workqueue_struct {\n struct cpu_workqueue_struct cpu_wq[NR_CPUS]\uff1b\n struct list_head list;\n const char *name;\n int singlethread;\n int freezeable;\n int rt;\n};\n
\u8be5\u7ed3\u6784\u4f53\u5185\u6709\u4e00\u4e2acpu_workqueue_struct
\u7ed3\u6784\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u6bcf\u4e00\u9879\u5bf9\u5e94\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u5904\u7406\u5668\u3002\u4e5f\u5c31\u662f\u8bf4\u7cfb\u7edf\u4e2d\u6bcf\u4e2a\u5904\u7406\u5668\u5bf9\u5e94\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u3002
\u5de5\u4f5c\u7531work_struct
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct work_struct {\n atomic_long_t data;\n struct list_head entry;\n work_func_t func;\n};\n
\u8fd9\u4e9b\u7ed3\u6784\u4f53\u88ab\u8fde\u63a5\u6210\u94fe\u8868\uff0c\u6bcf\u4e2a\u5904\u7406\u5668\u4e0a\u7684\u6bcf\u79cd\u7c7b\u578b\u7684\u961f\u5217\u90fd\u5bf9\u5e94\u8fd9\u6837\u4e00\u4e2a\u94fe\u8868\u3002\u5f53\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u88ab\u5524\u9192\u65f6\uff0c\u5b83\u4f1a\u6267\u884c\u94fe\u8868\u4e0a\u7684\u6240\u6709\u5de5\u4f5c\uff0c\u5f53\u6ca1\u6709\u5269\u4f59\u7684\u64cd\u4f5c\u65f6\uff0c\u5b83\u5c31\u4f1a\u7ee7\u7eed\u4f11\u7720\u3002
"},{"location":"linux/kernel/interrupt/#_11","title":"\u4f7f\u7528\u5de5\u4f5c\u961f\u5217","text":"\u9759\u6001\u521b\u5efa\u4e00\u4e2awork_struct
\u7ed3\u6784\u4f53\uff1a
DECLARE_WORK(name, void(*func)(void *), void *data);\n
\u5982\u679c\u662f\u52a8\u6001\u521b\u5efa\uff1a
INIT_WORK(struct work_struct *work, void (*func)(void *), void *data);\n
\u5de5\u4f5c\u961f\u5217\u5904\u7406\u51fd\u6570\u7684\u539f\u578b\u662f\uff1a
void work_handler(void *data)\n
\u8fd9\u4e2a\u51fd\u6570\u7531\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u6267\u884c\uff0c\u56e0\u6b64\u5904\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5141\u8bb8\u76f8\u5e94\u4e2d\u65ad\uff0c\u5e76\u4e14\u4e0d\u6301\u6709\u4efb\u4f55\u9501\u3002\u5c3d\u7ba1\u5904\u7406\u51fd\u6570\u4f4d\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\uff0c\u4f46\u662f\u5b83\u4e0d\u53ef\u4ee5\u8bbf\u95ee\u7528\u6237\u7a7a\u95f4\uff0c\u56e0\u4e3a\u5185\u6838\u7ebf\u7a0b\u5728\u7528\u6237\u7a7a\u95f4\u6ca1\u6709\u76f8\u5173\u7684\u5185\u5b58\u6620\u5c04\u3002
\u5bf9\u5de5\u4f5c\u8fdb\u884c\u8c03\u5ea6\uff0c\u628a\u7ed9\u5b9a\u5de5\u4f5c\u7684\u5904\u7406\u51fd\u6570\u63d0\u4ea4\u7ed9\u7f3a\u7701\u7684events\u5de5\u4f5c\u7ebf\u7a0b\uff1a
schedule_work(&work);\n
\u4e00\u65e6\u5176\u6240\u5728\u5904\u7406\u5668\u4e0a\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u88ab\u5524\u9192\uff0c\u5c31\u4f1a\u7acb\u523b\u6267\u884c\u3002\u5982\u679c\u9700\u8981\u5de5\u4f5c\u5ef6\u8fdf\u6267\u884c\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\uff1a
schedule_delayed_work(&work, delay);\n
&work\u6307\u5411\u7684work_struct
\u5219\u4f1a\u7b49\u5f85delay\u4e2a\u65f6\u949f\u8282\u62cd\u624d\u4f1a\u6267\u884c\u3002
\u5982\u679c\u7f3a\u7701\u7684\u961f\u5217\u4e0d\u80fd\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u961f\u5217\u548c\u4e0e\u4e4b\u76f8\u5e94\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u3002\u8fd9\u4e48\u505a\u4f1a\u5728\u6bcf\u4e2a\u5904\u7406\u5668\u4e0a\u90fd\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u3002\u9664\u975e\u4f60\u786e\u5b9a\u5fc5\u987b\u8981\u9760\u81ea\u5df1\u7684\u7ebf\u7a0b\u624d\u80fd\u63d0\u9ad8\u6027\u80fd\uff0c\u5426\u5219\u4e0d\u8981\u8fd9\u4e48\u505a\uff1a
struct workqueue_struct *create_workqueue(const char *name);\n
"},{"location":"linux/kernel/interrupt/#_12","title":"\u4e0b\u534a\u90e8\u7684\u540c\u6b65","text":"\u5728\u4f7f\u7528\u4e0b\u534a\u90e8\u673a\u5236\u65f6\uff0c\u5373\u4fbf\u662f\u4e00\u4e2a\u5355\u5904\u7406\u5668\uff0c\u907f\u514d\u5171\u4eab\u6570\u636e\u88ab\u540c\u65f6\u8bbf\u95ee\u4e5f\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4f7f\u7528tasklet\u7684\u597d\u5904\u662f\uff1a\u4e24\u4e2a\u76f8\u540c\u7c7b\u578b\u7684tasklet\u4e0d\u5141\u8bb8\u540c\u65f6\u6267\u884c\uff0c\u5373\u4fbf\u662f\u4e0d\u540c\u7684\u5904\u7406\u5668\u4e5f\u4e0d\u884c\u3002tasklet\u4e4b\u95f4\u7684\u540c\u6b65\uff08\u5373\u4e0d\u540c\u7c7b\u578b\u7684tasklet\u5171\u4eab\u540c\u4e00\u6570\u636e\uff09\uff0c\u6b63\u786e\u4f7f\u7528\u9501\u673a\u5236\u5373\u53ef\u3002
\u5982\u679c\u662f\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u548c\u4e0b\u534a\u90e8\u5171\u4eab\u6570\u636e\uff0c\u5728\u8bbf\u95ee\u8fd9\u4e9b\u6570\u636e\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u7981\u6b62\u4e0b\u534a\u90e8\u7684\u5904\u7406\u5e76\u83b7\u5f97\u9501\u7684\u4f7f\u7528\u6743\uff0c\u4ee5\u9632\u6b62\u6b7b\u9501\u7684\u51fa\u73b0\u3002
\u5982\u679c\u662f\u4e2d\u65ad\u4e0a\u4e0b\u6587\u548c\u4e0b\u534a\u90e8\u5171\u4eab\u6570\u636e\uff0c\u5728\u8bbf\u95ee\u8fd9\u4e9b\u6570\u636e\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u7981\u6b62\u4e2d\u65ad\u5e76\u83b7\u5f97\u9501\u7684\u4f7f\u7528\u6743\uff0c\u4e5f\u662f\u4e3a\u4e86\u9632\u6b62\u6b7b\u9501\u7684\u51fa\u73b0\u3002
\u4efb\u4f55\u5728\u5de5\u4f5c\u961f\u5217\u4e2d\u88ab\u5171\u4eab\u7684\u6570\u636e\u4e5f\u9700\u8981\u4f7f\u7528\u9501\u673a\u5236\u3002
\u4e00\u822c\u5355\u7eaf\u7981\u6b62\u4e0b\u534a\u90e8\u662f\u4e0d\u591f\u7684\uff0c\u66f4\u5e38\u89c1\u7684\u505a\u6cd5\u662f\u5148\u83b7\u5f97\u4e00\u4e2a\u9501\u518d\u7981\u6b62\u4e0b\u534a\u90e8\u7684\u5904\u7406\u3002\u5982\u679c\u9700\u8981\u7981\u6b62\u6240\u6709\u4e0b\u534a\u90e8\u7684\u5904\u7406\uff0c\u53ef\u4ee5\u8c03\u7528local_bh_disable()
\u51fd\u6570\u3002\u5141\u8bb8\u4e0b\u534a\u90e8\u5904\u7406\uff0c\u8c03\u7528local_bh_enable()
\u51fd\u6570\u3002\u51fd\u6570\u901a\u8fc7preempt_count
\uff08\u5185\u6838\u62a2\u5360\u4e5f\u662f\u8fd9\u4e2a\u8ba1\u6570\u5668\uff09\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u7ef4\u62a4\u4e00\u4e2a\u8ba1\u6570\u5668\u3002\u5f53\u8ba1\u6570\u5668\u4e3a0\u65f6\uff0c\u624d\u53ef\u4ee5\u5904\u7406\u4e0b\u534a\u90e8\u3002
"},{"location":"linux/kernel/mm/","title":"\u7269\u7406\u5185\u5b58\u7ba1\u7406","text":"\u8fd9\u90e8\u5206\u5185\u5bb9\u8981\u548c\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u7ed3\u5408\u8d77\u6765\u770b\u3002
"},{"location":"linux/kernel/mm/#_2","title":"\u9875\u548c\u533a","text":"\u5185\u6838\u5c06\u7269\u7406\u5185\u5b58\u5212\u5206\u4e3a\u4f17\u591a\u56fa\u5b9a\u5927\u5c0f\u7684\u9875\uff0c\u6bcf\u9875\u901a\u5e38\u5305\u542b4KB\u7684\u5b58\u50a8\u7a7a\u95f4\u3002\u8fd9\u79cd\u5206\u9875\u673a\u5236\u6781\u5927\u5730\u63d0\u5347\u4e86\u5185\u6838\u5728\u5185\u5b58\u5206\u914d\u548c\u56de\u6536\u65b9\u9762\u7684\u6548\u7387\uff0c\u540c\u65f6\u4e5f\u4e3a\u865a\u62df\u5185\u5b58\u7ba1\u7406\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002\u901a\u8fc7\u5c06\u5185\u5b58\u5212\u5206\u4e3a\u4e00\u81f4\u5927\u5c0f\u7684\u5355\u5143\uff0c\u5185\u6838\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\u5730\u5904\u7406\u5185\u5b58\u8bf7\u6c42\uff0c\u4f18\u5316\u8d44\u6e90\u5206\u914d\uff0c\u5e76\u7b80\u5316\u4e86\u5185\u5b58\u5bfb\u5740\u548c\u6620\u5c04\u7684\u8fc7\u7a0b\u3002struct page
\u7ed3\u6784\u4f53\u8868\u793a\u9875\uff0c\u8be5\u5b9a\u4e49\u7684\u7b80\u5316\u7248\u5982\u4e0b\uff1a
struct page {\n unsigned long flags;\n atomic_t _count;\n atomic_t _mapcount;\n unsigned long private;\n struct address_space *mapping;\n pgoff_t index;\n struct list_head lru;\n void *virtual;\n};\n
flags\uff1a\u5b58\u653e\u9875\u7684\u72b6\u6001\uff0c\u662f\u4e0d\u662f\u810f\u9875\uff0c\u662f\u4e0d\u662f\u9501\u5b9a\u5728\u5185\u5b58\u4e2d\u7b49\u3002
_count\uff1a\u5b58\u653e\u9875\u7684\u5f15\u7528\u8ba1\u6570\uff0c\u5f53\u9875\u88ab\u5206\u914d\u7ed9\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u8fd9\u4e2a\u8ba1\u6570\u5668\u4f1a\u589e\u52a0\u3002\u5f53\u9875\u88ab\u91ca\u653e\u65f6\uff0c\u8ba1\u6570\u5668\u51cf\u5c11\u3002\u76f4\u5230\u8ba1\u6570\u5668\u964d\u81f30\uff0c\u9875\u624d\u80fd\u88ab\u56de\u6536\u3002
_mapcount\uff1a\u7528\u4e8e\u8bb0\u5f55\u9875\u8868\u9879\u6620\u5c04\u5230\u8be5\u7269\u7406\u9875\u7684\u6b21\u6570\u3002\u8fd9\u901a\u5e38\u7528\u4e8e\u5171\u4eab\u5185\u5b58\u9875\uff0c\u591a\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u7269\u7406\u9875\u3002
mapping\uff1a\u6307\u5411\u4e00\u4e2aaddress_space\u7ed3\u6784\u7684\u6307\u9488\uff0c\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7528\u4e8e\u63cf\u8ff0\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u5185\u5b58\u6620\u5c04\u4fe1\u606f\u3002\u5982\u679c\u9875\u5c5e\u4e8e\u6587\u4ef6\u7f13\u5b58\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u5c06\u6307\u5411\u76f8\u5e94\u7684address_space\u7ed3\u6784\u3002
index\uff1a\u8868\u793a\u9875\u5728\u6620\u5c04\u7684\u6587\u4ef6\u4e2d\u7684\u504f\u79fb\u91cf\uff0c\u5373\u9875\u5728\u6587\u4ef6\u4e2d\u7684\u7d22\u5f15\u53f7\u3002
lru\uff1a\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u8282\u70b9\uff0c\u7528\u4e8e\u5c06\u9875\u94fe\u5165\u5230\u5404\u79cd\u94fe\u8868\u4e2d\uff0c\u6bd4\u5982\u6d3b\u8dc3\u94fe\u8868\u3001\u4e0d\u6d3b\u8dc3\u94fe\u8868\u7b49\u3002\u8fd9\u662f\u5185\u6838\u5b9e\u73b0\u9875\u7f6e\u6362\u7b97\u6cd5\uff08\u5982LRU\uff09\u7684\u4e00\u90e8\u5206\u3002
virtual\uff1a\u9875\u5728\u865a\u62df\u5185\u5b58\u4e2d\u7684\u5730\u5740\u3002
\u4e3a\u4e86\u66f4\u597d\u5730\u7ba1\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u5185\u5b58\u548c\u4f18\u5316\u5185\u5b58\u5206\u914d\u7b56\u7565\uff0c\u5185\u6838\u5c06\u9875\u5212\u5206\u4e3a\u4e0d\u540c\u7684\u533a(zone)\uff0c\u901a\u5e38\u5212\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u533a\uff1a
ZONE_DMA\uff1a\u7528\u4e8eDMA\u64cd\u4f5c\u7684\u5185\u5b58\u533a\uff0c\u901a\u5e38\u4f4d\u4e8e\u7269\u7406\u5185\u5b58\u7684\u4f4e\u5730\u5740\u90e8\u5206\u3002
ZONE_DMA32\uff1a\u4e0eZONE_DMA\u7c7b\u4f3c\uff0c\u4f46\u9002\u7528\u4e8e32\u4f4d\u5730\u5740\u7684DMA\u64cd\u4f5c\u3002
ZONE_NORMAL\uff1a\u666e\u901a\u7684\u5185\u5b58\u533a\uff0c\u53ef\u4ee5\u7531\u5185\u6838\u548c\u7528\u6237\u7a7a\u95f4\u8fdb\u7a0b\u4f7f\u7528\u3002
ZONE_HIGHMEM\uff1a\u9ad8\u7aef\u5185\u5b58\u533a\uff0c\u7528\u4e8e\u5904\u7406\u8d85\u8fc7\u76f4\u63a5\u6620\u5c04\u8303\u56f4\u7684\u5185\u5b58\u3002
\u533a\u7684\u4f7f\u7528\u548c\u5206\u5e03\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\uff0c\u5185\u6838\u5c06\u9875\u5212\u5206\u4e3a\u533a\uff0c\u5c31\u53ef\u4ee5\u6839\u636e\u7528\u9014\u8fdb\u884c\u5206\u914d\u3002\u533a\u7684\u5212\u5206\u6ca1\u6709\u7269\u7406\u610f\u4e49\uff0c\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406\u800c\u91c7\u53d6\u7684\u4e00\u79cd\u903b\u8f91\u5206\u7ec4\u3002
"},{"location":"linux/kernel/mm/#_3","title":"\u9875\u64cd\u4f5c","text":"\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u4e9b\u83b7\u5f97\u9875\u548c\u91ca\u653e\u9875\u7684\u64cd\u4f5c\uff0c\u8fd9\u91cc\u4e0d\u505a\u8be6\u7ec6\u8bf4\u660e\u3002
\u51fd\u6570 \u63cf\u8ff0 alloc_page(gfp_mask) \u53ea\u5206\u914d\u4e00\u9875\uff0c\u8fd4\u56de\u6307\u5411\u9875\u7684\u6307\u9488 alloc_pages(gfp_mask, order) \u5206\u914d2order \u4e2a\u9875\uff0c\u8fd4\u56de\u6307\u5411\u7b2c\u4e00\u9875\u7684\u6307\u9488 __get_free_page(gfp_mask) \u53ea\u5206\u914d\u4e00\u9875\uff0c\u8fd4\u56de\u6307\u5411\u5176\u903b\u8f91\u5730\u5740\u7684\u6307\u9488 __get_free_pages(gfp_mask, order) \u5206\u914d2order \u4e2a\u9875\uff0c\u8fd4\u56de\u6307\u5411\u7b2c\u4e00\u9875\u903b\u8f91\u5730\u5740\u7684\u6307\u9488 get_zero_page(gfp_mask) \u53ea\u5206\u914d\u4e00\u9875\uff0c\u586b\u5145\u4e3a0\uff0c\u8fd4\u56de\u6307\u5411\u5176\u903b\u8f91\u5730\u5740\u7684\u6307\u9488 __free_pages(page, order) \u4f20\u5165\u9875\u7684\u6307\u9488\uff0c\u91ca\u653e2order \u4e2a\u9875 free_pages(addr, order) \u4f20\u5165\u7b2c\u4e00\u9875\u7684\u903b\u8f91\u5730\u5740\uff0c\u91ca\u653e2order \u4e2a\u9875 free_page(addr) \u91ca\u653e\u5355\u5f20\u9875 \u91ca\u653e\u9875\u65f6\u8981\u8c28\u614e\uff0c\u4e00\u65e6\u4f20\u9012\u4e86\u9519\u8bef\u7684page\u6216\u8005address\uff0c\u7cfb\u7edf\u5c31\u4f1a\u5d29\u6e83\u3002\u5728\u83b7\u5f97\u9875\u4e4b\u540e\uff0c\u9700\u8981\u5bf9\u8fd4\u56de\u503c\u8fdb\u884c\u68c0\u67e5\u4ee5\u786e\u8ba4\u5185\u6838\u6b63\u786e\u5730\u5206\u914d\u4e86\u9875\u3002
\u5bf9\u4e8e\u5e38\u7528\u7684\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\u5185\u5b58\u5206\u914d\u6765\u8bf4\uff0c\u5185\u6838\u63d0\u4f9b\u7684\u51fd\u6570\u662fkmalloc()
\u3002
"},{"location":"linux/kernel/mm/#kmalloc","title":"kmalloc()","text":"kmalloc()
\u4e0e\u7528\u6237\u7a7a\u95f4\u7684malloc()
\u7c7b\u4f3c\uff0c\u90fd\u662f\u5206\u914d\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\u4e00\u5757\u5185\u5b58\uff0c\u533a\u522b\u5728\u4e8ekmalloc()
\u591a\u4e86\u4e00\u4e2aflags\u53c2\u6570\uff1a
\u6ce8\u610f\uff1a\u4f7f\u7528kmalloc()
\u51fd\u6570\u5206\u914d\u7684\u5185\u5b58\u53ea\u80fd\u4f7f\u7528kfree()
\u51fd\u6570\u91ca\u653e\u3002
void *kmalloc(size_t size, gfp_t flags)\n
\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u5185\u5b58\u5757\u7684\u6307\u9488\uff0c\u81f3\u5c11\u6709size\u5927\u5c0f\u3002\u6240\u5206\u914d\u7684\u5185\u5b58\u533a\u5728\u7269\u7406\u4e0a\u662f\u8fde\u7eed\u7684\u3002\u9664\u975e\u6ca1\u6709\u8db3\u591f\u7684\u5185\u5b58\u53ef\u7528\uff0c\u5426\u5219\u5185\u6838\u603b\u80fd\u5206\u914d\u6210\u529f\u3002\u5f53\u7136\uff0c\u5728\u5bf9kmalloc()
\u8c03\u7528\u4e4b\u540e\uff0c\u4f60\u8fd8\u662f\u9700\u8981\u68c0\u67e5\u8fd4\u56de\u503c\u662f\u5426\u4e3aNULL\uff1a
struct dog *p;\np = kmalloc(sizeof(struct dog), GFP_KERNEL)\uff1b\nif(!p)\n /*\u5904\u7406\u9519\u8bef*/\n
\u4e0d\u7ba1\u662f\u5728\u9875\u5206\u914d\u51fd\u6570\u8fd8\u662f\u5728kmalloc()
\u4e2d\uff0c\u90fd\u7528\u5230\u4e86\u5206\u914d\u5668\u6807\u5fd7\u3002\u6807\u5fd7\u5206\u4e3a\u4e09\u7c7b\uff1a\u884c\u4e3a\u4fee\u9970\u7b26\u3001\u533a\u4fee\u9970\u7b26\u548c\u7c7b\u578b\u6807\u5fd7\u3002\u7c7b\u578b\u6807\u5fd7\u7ec4\u5408\u4e86\u524d\u4e24\u8005\uff0c\u7b80\u5316\u4e86\u4fee\u9970\u7b26\u7684\u4f7f\u7528\uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053\u7c7b\u578b\u6807\u5fd7\u5373\u53ef\u3002\u5185\u6838\u4e2d\u6700\u5e38\u7528\u7684\u5c31\u662fGFP_KERNEL\u3002\u8fd9\u79cd\u5206\u914d\u65b9\u5f0f\u53ef\u80fd\u4f1a\u5f15\u8d77\u7761\u7720\uff0c\u6240\u4ee5\u53ea\u80fd\u7528\u5728\u53ef\u4ee5\u91cd\u65b0\u5b89\u5168\u8c03\u5ea6\u7684\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u3002\u53e6\u4e00\u4e2a\u622a\u7136\u76f8\u53cd\u7684\u6807\u5fd7\u662fGFP_ATOMIC\uff0c\u8fd9\u4e2a\u6807\u5fd7\u8868\u793a\u4e0d\u80fd\u7761\u7720\u7684\u5185\u5b58\u5206\u914d\u3002\u4e0eGFP_KERNEL\u76f8\u6bd4\uff0c\u5b83\u5206\u914d\u6210\u529f\u7684\u673a\u4f1a\u8f83\u5c0f\uff0c\u4f46\u662f\u5728\u4e00\u4e9b\u65e0\u6cd5\u7761\u7720\u7684\u4ee3\u7801\u4e2d\uff0c\u4e5f\u53ea\u80fd\u9009\u62e9GFP_ATOMIC\u3002GFP_DMA\u6807\u5fd7\u8868\u793a\u5206\u914d\u5668\u5fc5\u987b\u6ee1\u8db3\u4eceZONE_DMA\u8fdb\u884c\u5206\u914d\u7684\u8bf7\u6c42\uff0c\u8be5\u6807\u5fd7\u7528\u5728\u9700\u8981DMA\u7684\u5185\u5b58\u7684\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u4e2d\u3002\u5728\u7f16\u5199\u7684\u7edd\u5927\u591a\u6570\u4ee3\u7801\u4e2d\uff0c\u8981\u4e48\u662fGFP_KERNEL\uff0c\u8981\u4e48\u662fGFP_ATOMIC\uff0c\u5176\u4ed6\u6807\u5fd7\u7528\u5230\u7684\u60c5\u51b5\u6781\u5c11\uff0c\u5c31\u4e0d\u505a\u8bf4\u660e\u4e86\u3002\u4e0b\u9762\u8fd9\u5f20\u8868\u683c\u603b\u7ed3\u4e86\u6807\u5fd7\u7684\u4f7f\u7528\u573a\u666f\u3002
\u60c5\u5f62 \u76f8\u5e94\u6807\u5fd7 \u53ef\u4ee5\u7761\u7720\u7684\u8fdb\u7a0b\u4e0a\u4e0b\u6587 GFP_KERNEL \u4e0d\u53ef\u4ee5\u7761\u7720\u7684\u8fdb\u7a0b\u4e0a\u4e0b\u6587 GFP_ATOMIC \u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f GFP_ATOMIC \u8f6f\u4e2d\u65ad GFP_ATOMIC tasklet GFP_ATOMIC \u53ef\u4ee5\u7761\u7720\u7684DMA\u5185\u5b58 \uff08GFP_DMA | GFP_KERNEL\uff09 \u4e0d\u53ef\u4ee5\u7761\u7720\u7684DMA\u5185\u5b58 \uff08GFP_DMA\uff09| GFP_ATOMIC"},{"location":"linux/kernel/mm/#vmalloc","title":"vmalloc()","text":"vmalloc()
\u51fd\u6570\u4e0ekmalloc()
\u51fd\u6570\u5728\u5185\u5b58\u5206\u914d\u65b9\u9762\u5177\u6709\u76f8\u4f3c\u7684\u529f\u80fd\uff0c\u4f46\u5b83\u4eec\u5728\u7269\u7406\u5730\u5740\u8fde\u7eed\u6027\u65b9\u9762\u6709\u6240\u4e0d\u540c\u3002\u4e0ekmalloc()
\u4fdd\u8bc1\u5206\u914d\u7684\u5185\u5b58\u9875\u5728\u7269\u7406\u5730\u5740\u4e0a\u8fde\u7eed\u4e0d\u540c\uff0cvmalloc()
\u5206\u914d\u7684\u5185\u5b58\u9875\u5728\u7269\u7406\u5730\u5740\u4e0a\u53ef\u4ee5\u662f\u4e0d\u8fde\u7eed\u7684\u3002\u8fd9\u79cd\u73b0\u8c61\u4e0e\u7528\u6237\u7a7a\u95f4\u5185\u5b58\u5206\u914d\u51fd\u6570malloc()
\u7c7b\u4f3c\uff0cmalloc()
\u8fd4\u56de\u7684\u9875\u5728\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e2d\u662f\u8fde\u7eed\u7684\uff0c\u4f46\u5e76\u4e0d\u4fdd\u8bc1\u8fd9\u4e9b\u9875\u5728\u7269\u7406\u5730\u5740\u4e0a\u4e5f\u662f\u8fde\u7eed\u7684\u3002
\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u786c\u4ef6\u8bbe\u5907\u9700\u8981\u8bbf\u95ee\u7269\u7406\u5730\u5740\u8fde\u7eed\u7684\u5185\u5b58\u9875\u3002\u8fd9\u662f\u56e0\u4e3a\u8bb8\u591a\u4f53\u7cfb\u7ed3\u6784\u7684\u786c\u4ef6\u8bbe\u5907\u5b58\u5728\u4e8e\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff08MMU\uff09\u4e4b\u5916\uff0c\u5b83\u4eec\u65e0\u6cd5\u5904\u7406\u865a\u62df\u5730\u5740\u3002\u56e0\u6b64\uff0c\u786c\u4ef6\u8bbe\u5907\u6240\u4f7f\u7528\u7684\u4efb\u4f55\u5185\u5b58\u533a\u57df\u90fd\u5fc5\u987b\u662f\u7269\u7406\u4e0a\u8fde\u7eed\u7684\u5185\u5b58\u5757\u3002
\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u8f6f\u4ef6\u4f7f\u7528\u7684\u5185\u5b58\u5757\u5219\u6ca1\u6709\u8fd9\u6837\u7684\u4e25\u683c\u8981\u6c42\u3002\u8f6f\u4ef6\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u865a\u62df\u5730\u5740\u6765\u8bbf\u95ee\u5185\u5b58\uff0c\u5373\u4f7f\u8fd9\u4e9b\u865a\u62df\u5730\u5740\u5bf9\u5e94\u7684\u7269\u7406\u5185\u5b58\u4e0d\u662f\u8fde\u7eed\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u9875\u8868\u7ba1\u7406\u673a\u5236\uff0c\u53ef\u4ee5\u5c06\u4e0d\u8fde\u7eed\u7684\u7269\u7406\u5185\u5b58\u6620\u5c04\u5230\u8fde\u7eed\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e2d\u3002\u8fd9\u79cd\u673a\u5236\u4f7f\u5f97\u8f6f\u4ef6\u53ef\u4ee5\u9ad8\u6548\u5730\u4f7f\u7528\u5206\u6563\u7684\u7269\u7406\u5185\u5b58\u8d44\u6e90\uff0c\u800c\u65e0\u9700\u5173\u5fc3\u5185\u5b58\u7684\u7269\u7406\u5e03\u5c40\u3002
\u7531\u4e8evmalloc()
\u9700\u8981\u5bf9\u4e0d\u8fde\u7eed\u7684\u9875\u8fdb\u884c\u4e13\u95e8\u7684\u6620\u5c04\u5904\u7406\uff0c\u6240\u4ee5\u5176\u6027\u80fd\u4e0d\u5982kmalloc()
\u3002\u4ec5\u5728\u4e0d\u5f97\u5df2\u7684\u60c5\u5f62\u4e0b\u624d\u4f1a\u4f7f\u7528\uff0c\u6bd4\u5982\u4e3a\u4e86\u83b7\u5f97\u5927\u5757\u5185\u5b58\u65f6\u3002\u56e0\u4e3akmalloc()
\u5206\u914d\u7684\u5185\u5b58\u5757\u662f\u8fde\u7eed\u7684\uff0c\u5f53\u7cfb\u7edf\u4e2d\u7684\u5185\u5b58\u788e\u7247\u8f83\u591a\u65f6\uff0c\u5c1d\u8bd5\u5206\u914d\u5927\u5757\u5185\u5b58\u53ef\u80fd\u4f1a\u5931\u8d25\uff0c\u800cvmalloc()
\u5219\u4e0d\u4f1a\u3002
vmalloc()
\u7684\u5206\u914d\u548c\u91ca\u653e\u63a5\u53e3\u5982\u4e0b\uff1a
void *vmalloc(unsinged long size)\n\nvoid vfree(const void *addr)\n
\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u4f1a\u7761\u7720\uff0c\u56e0\u6b64\u4e0d\u80fd\u5728\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u3002
"},{"location":"linux/kernel/mm/#_4","title":"\u4f19\u4f34\u7cfb\u7edf","text":"\u4f19\u4f34\u7cfb\u7edf\uff08Buddy System\uff09\u662f\u4e00\u79cd\u5185\u5b58\u5206\u914d\u7b97\u6cd5\uff0c\u5b83\u88ab\u7528\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u5b58\u7ba1\u7406\u3002\u5728\u8fd9\u79cd\u7cfb\u7edf\u4e2d\uff0c\u5185\u5b58\u88ab\u5206\u6210\u591a\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u5757\uff0c\u6bcf\u4e2a\u5757\u7684\u5927\u5c0f\u90fd\u662f2\u7684\u5e42\u6b21\u65b9\u3002\u8fd9\u4e9b\u5757\u88ab\u7ec4\u7ec7\u6210\u4e00\u9897\u6811\u7ed3\u6784\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5757\u90fd\u662f\u53e6\u4e00\u4e2a\u5757\u7684\u201c\u4f19\u4f34\u201d\u3002
\u5185\u6838\u628a\u6240\u6709\u7684\u7a7a\u95f2\u9875\u5206\u7ec4\u4e3a11\u4e2a\u9875\u5757\u94fe\u8868\uff0c\u6bcf\u4e2a\u5757\u94fe\u8868\u5206\u522b\u5305\u542b\u5f88\u591a\u4e2a\u5927\u5c0f\u7684\u9875\u5757\uff0c\u6709 1\u30012\u30014\u30018\u300116\u300132\u300164\u3001128\u3001256\u3001512 \u548c 1024 \u4e2a\u8fde\u7eed\u9875\u7684\u9875\u5757\u3002\u6700\u5927\u53ef\u4ee5\u7533\u8bf71024\u4e2a\u8fde\u7eed\u9875\uff0c\u5bf9\u5e94 4MB\u5927\u5c0f\u7684\u8fde\u7eed\u5185\u5b58\u3002
\u5f53\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u5206\u914d\u5185\u5b58\u65f6\uff0c\u5b83\u4f1a\u6839\u636e\u8bf7\u6c42\u7684\u5927\u5c0f\u627e\u5230\u6700\u63a5\u8fd1\u7684\u4e14\u5927\u5c0f\u8db3\u591f\u7684\u5757\u8fdb\u884c\u5206\u914d\u3002\u5982\u679c\u5206\u914d\u7684\u5757\u6bd4\u6240\u9700\u7684\u5927\u5c0f\u5927\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5757\u4f1a\u88ab\u5206\u6210\u4e24\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u5b50\u5757\uff0c\u5176\u4e2d\u4e00\u4e2a\u5b50\u5757\u88ab\u7528\u6765\u6ee1\u8db3\u5185\u5b58\u5206\u914d\u8bf7\u6c42\uff0c\u800c\u53e6\u4e00\u4e2a\u5219\u6210\u4e3a\u5b83\u7684\u201c\u4f19\u4f34\u201d\u3002
\u5728\u4f19\u4f34\u7cfb\u7edf\u4e2d\uff0c\u5f53\u9700\u8981\u5206\u914d\u4e00\u4e2a\u7279\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u5757\u65f6\uff0c\u7cfb\u7edf\u4f1a\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a
\u9996\u5148\uff0c\u786e\u5b9a\u6240\u9700\u5185\u5b58\u5757\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u9700\u8981128\u4e2a\u9875\u7684\u5757\uff0c\u7cfb\u7edf\u4f1a\u68c0\u67e5128\u4e2a\u9875\u7684\u7a7a\u95f2\u5757\u94fe\u8868\u3002
\u5982\u679c\u5728128\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u6ca1\u6709\u627e\u5230\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u5bfb\u627e\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u5185\u5b58\u5757\u5c3a\u5bf8\uff0c\u5373256\u4e2a\u9875\u7684\u5757\u3002
\u5982\u679c\u5728256\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u627e\u5230\u4e86\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u5c06\u8fd9\u4e2a\u5757\u5206\u6210\u4e24\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u5757\uff0c\u6bcf\u4e2a\u5757\u5305\u542b128\u4e2a\u9875\u3002\u5176\u4e2d\u4e00\u4e2a\u5757\u88ab\u5206\u914d\u7ed9\u8bf7\u6c42\u8005\uff0c\u53e6\u4e00\u4e2a\u5757\u4f5c\u4e3a\u65b0\u7684\u7a7a\u95f2\u5757\u63d2\u5165\u5230128\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u3002
\u5982\u679c256\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u4e5f\u6ca1\u6709\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u7ee7\u7eed\u68c0\u67e5\u66f4\u5927\u7684\u5757\uff0c\u6bd4\u5982512\u4e2a\u9875\u7684\u5757\u3002
\u5982\u679c\u5728512\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u627e\u5230\u4e86\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u5c06\u8fd9\u4e2a\u5757\u5206\u88c2\u6210\u4e09\u4e2a\u5757\uff1a\u4e24\u4e2a128\u4e2a\u9875\u7684\u5757\u548c\u4e00\u4e2a256\u4e2a\u9875\u7684\u5757\u3002\u5176\u4e2d\u4e00\u4e2a128\u4e2a\u9875\u7684\u5757\u88ab\u5206\u914d\u51fa\u53bb\uff0c\u5176\u4f59\u4e24\u4e2a\u5757\u5206\u522b\u63d2\u5165\u5230\u76f8\u5e94\u7684\u94fe\u8868\u4e2d\u3002 \u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f19\u4f34\u7cfb\u7edf\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u5185\u5b58\uff0c\u786e\u4fdd\u5185\u5b58\u5206\u914d\u65e2\u9ad8\u6548\u53c8\u7075\u6d3b\u3002
\u5f53\u5185\u5b58\u5757\u88ab\u91ca\u653e\u65f6\uff0c\u7cfb\u7edf\u4f1a\u68c0\u67e5\u662f\u5426\u6709\u76f8\u90bb\u7684\u4f19\u4f34\u5757\u540c\u6837\u7a7a\u95f2\uff0c\u5982\u679c\u4e24\u8005\u90fd\u662f\u7a7a\u95f2\u7684\uff0c\u5b83\u4eec\u4f1a\u88ab\u5408\u5e76\u56de\u539f\u6765\u7684\u5927\u5757\uff0c\u4ece\u800c\u51cf\u5c11\u5185\u5b58\u788e\u7247\u3002
"},{"location":"linux/kernel/mm/#slab","title":"slab\u5206\u914d\u5668","text":"\u5728\u5185\u6838\u7f16\u7a0b\u4e2d\uff0c\u5206\u914d\u548c\u91ca\u653e\u6570\u636e\u7ed3\u6784\u662f\u4e00\u9879\u6781\u4e3a\u5e38\u89c1\u7684\u5de5\u4f5c\u3002\u4e3a\u4e86\u9ad8\u6548\u5730\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u7684\u9891\u7e41\u5206\u914d\u4e0e\u56de\u6536\uff0c\u5f00\u53d1\u8005\u4eec\u901a\u5e38\u4f1a\u5229\u7528\u7a7a\u95f2\u94fe\u8868\u6765\u4f18\u5316\u8fd9\u4e00\u8fc7\u7a0b\u3002\u7a7a\u95f2\u94fe\u8868\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u9884\u5148\u5206\u914d\u7684\u6570\u636e\u7ed3\u6784\u5757\u7684\u96c6\u5408\uff0c\u8fd9\u4e9b\u5757\u90fd\u5904\u4e8e\u53ef\u7528\u72b6\u6001\u3002\u5f53\u7cfb\u7edf\u9700\u8981\u65b0\u7684\u6570\u636e\u7ed3\u6784\u5b9e\u4f8b\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u4ece\u7a7a\u95f2\u94fe\u8868\u4e2d\u83b7\u53d6\u4e00\u4e2a\u73b0\u6210\u7684\u5757\uff0c\u8fd9\u6837\u5c31\u907f\u514d\u4e86\u5b9e\u65f6\u5185\u5b58\u5206\u914d\u7684\u6d88\u8017\u3002\u4f7f\u7528\u5b8c\u6bd5\u540e\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u5b9e\u4f8b\u88ab\u5f52\u8fd8\u5230\u7a7a\u95f2\u94fe\u8868\u4e2d\uff0c\u800c\u4e0d\u662f\u88ab\u76f4\u63a5\u91ca\u653e\u3002\u5728\u8fd9\u79cd\u673a\u5236\u4e0b\uff0c\u7a7a\u95f2\u94fe\u8868\u5145\u5f53\u4e86\u4e00\u79cd\u7279\u6b8a\u7684\u5bf9\u8c61\u9ad8\u901f\u7f13\u5b58\uff0c\u5b83\u80fd\u591f\u5feb\u901f\u5730\u5b58\u50a8\u548c\u63d0\u4f9b\u90a3\u4e9b\u7ecf\u5e38\u88ab\u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\u7c7b\u578b\u3002\u8fd9\u6837\u7684\u8bbe\u8ba1\u4e0d\u4ec5\u63d0\u5347\u4e86\u5185\u5b58\u7ba1\u7406\u7684\u6548\u7387\uff0c\u8fd8\u51cf\u5c11\u4e86\u5185\u5b58\u788e\u7247\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u5b9e\u7528\u7684\u7f16\u7a0b\u6280\u5de7\u3002
Linux\u5185\u6838\u63d0\u4f9b\u4e86slab\u5206\u914d\u5668\uff0c\u5b83\u901a\u8fc7\u5c06\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u7ec4\u7ec7\u5230\u5404\u81ea\u7684\u9ad8\u901f\u7f13\u5b58\u7ec4\u4e2d\uff0c\u6765\u4f18\u5316\u8fd9\u4e9b\u5bf9\u8c61\u7684\u5206\u914d\u548c\u56de\u6536\u3002\u6bcf\u4e2a\u9ad8\u901f\u7f13\u5b58\u7ec4\u4e13\u95e8\u7528\u4e8e\u5b58\u50a8\u4e00\u79cd\u7279\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u9ad8\u901f\u7f13\u5b58\u53ef\u80fd\u7528\u4e8e\u7ba1\u7406\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff08task_struct
\u7ed3\u6784\uff09\uff0c\u800c\u53e6\u4e00\u4e2a\u5219\u7528\u4e8e\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\uff08struct inode
\uff09\u3002
slab\u53ef\u4ee5\u5904\u4e8e\u4e09\u79cd\u72b6\u6001\u4e4b\u4e00\uff1a\u6ee1\u3001\u90e8\u5206\u6ee1\u6216\u7a7a\u3002\u6ee1\u7684slab\u610f\u5473\u7740\u6240\u6709\u5bf9\u8c61\u90fd\u5df2\u5206\u914d\u51fa\u53bb\uff0c\u7a7a\u7684slab\u5219\u8868\u793a\u6240\u6709\u5bf9\u8c61\u90fd\u672a\u88ab\u5206\u914d\uff0c\u800c\u90e8\u5206\u6ee1\u7684slab\u5219\u5305\u542b\u4e86\u5df2\u5206\u914d\u548c\u672a\u5206\u914d\u7684\u5bf9\u8c61\u3002\u5f53\u5185\u6838\u8bf7\u6c42\u65b0\u5bf9\u8c61\u65f6\uff0c\u4f18\u5148\u4ece\u90e8\u5206\u6ee1\u7684slab\u4e2d\u5206\u914d\u3002\u5982\u679c\u6ca1\u6709\uff0c\u5219\u4ece\u7a7a\u7684slab\u4e2d\u5206\u914d\u3002\u5982\u679c\u8fde\u7a7a\u7684slab\u90fd\u6ca1\u6709\uff0c\u5c31\u4f1a\u521b\u5efa\u65b0\u7684slab\u3002
"},{"location":"linux/kernel/others/","title":"\u5176\u4ed6","text":"\u8fd9\u91cc\u4e3b\u8981\u653e\u4e00\u4e9b\u96f6\u788e\u7684\u5185\u5bb9\u3002
"},{"location":"linux/kernel/others/#_2","title":"\u7cfb\u7edf\u8c03\u7528","text":"\u5f53\u4f60\u7684\u7a0b\u5e8f\u8c03\u7528open, read, write, close\u7b49\u51fd\u6570\u65f6\uff0c\u5c31\u4f1a\u89e6\u53d1\u7cfb\u7edf\u8c03\u7528\uff08syscall\uff09\u3002\u7cfb\u7edf\u8c03\u7528\u672c\u8d28\u662f\u7528\u6237\u6001\u8fdb\u7a0b\u4e0e\u786c\u4ef6\u8bbe\u5907\u4ea4\u4e92\u7684\u63a5\u53e3\uff0c\u5185\u6838\u8d1f\u8d23\u68c0\u67e5\u7cfb\u7edf\u8c03\u7528\u7684\u6b63\u786e\u6027\uff0c\u7136\u540e\u53d1\u51fa\u6307\u4ee4\u7ed9\u786c\u4ef6\u3002\u4f5c\u4e3a\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u8005\uff0c\u4e0d\u7528\u5173\u5fc3\u5e95\u5c42\u786c\u4ef6\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u800c\u53ea\u9700\u8981\u8c03\u7528\u666e\u901a\u51fd\u6570\u5c31\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u8c03\u7528\u4e86\u3002glibc\u5e93\u8fdb\u4e00\u6b65\u5c01\u88c5\u4e86\u7ec6\u8282\uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u9700\u8981\u4f7f\u7528glibc\u5e93\u66b4\u9732\u7684API\u5373\u53ef\u3002
x86\u4f53\u7cfb\u8fdb\u5165\u548c\u9000\u51fa\u7cfb\u7edf\u8c03\u7528\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a
int $0x80 \u548c iret sysenter \u548c sysexit \u7b2c\u4e8c\u79cd\u88ab\u79f0\u4e3a\u5feb\u901f\u7cfb\u7edf\u8c03\u7528\u3002
\u65e0\u8bba\u54ea\u79cd\u65b9\u5f0f\uff0c\u6700\u7ec8\u7ed3\u679c\u90fd\u662f\u8df3\u8f6c\u5230\u7cfb\u7edf\u8c03\u7528\u5904\u7406\u51fd\u6570\uff08system call handler\uff09\u3002\u7531\u4e8e\u5185\u6838\u5b9e\u73b0\u4e86\u5f88\u591a\u4e0d\u540c\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u56e0\u6b64\u8fdb\u7a0b\u5fc5\u987b\u4f20\u9012\u4e00\u4e2a\u540d\u4e3a\u7cfb\u7edf\u8c03\u7528\u53f7\uff08system call number\uff09\u7684\u53c2\u6570\u6765\u8bc6\u522b\u6240\u9700\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u8fd9\u4e2a\u53c2\u6570\u5b58\u653e\u5728eax\u5bc4\u5b58\u5668\u4e2d\u3002\u6267\u884c\u5b8c\u7cfb\u7edf\u8c03\u7528\u540e\u7684\u8fd4\u56de\u503c\u4e5f\u653e\u5728eax\u5bc4\u5b58\u5668\u4e2d\uff0c\u5176\u4e2d\u6b63\u6570\u62160\u8868\u793a\u7cfb\u7edf\u8c03\u7528\u6210\u529f\uff0c\u8d1f\u6570\u8868\u793a\u51fa\u9519\uff0c\u5b58\u653e\u4e8eerrno
\u5168\u5c40\u53d8\u91cf\u4e2d\u3002
\u7cfb\u7edf\u8c03\u7528\u5904\u7406\u6d41\u7a0b\u662f\uff1a
\u5c06\u7cfb\u7edf\u8c03\u7528\u7684\u53c2\u6570\u5199\u5165CPU\u5bc4\u5b58\u5668 \u68c0\u67e5\u6240\u6709\u7684\u7cfb\u7edf\u8c03\u7528\u53c2\u6570 \u5c06CPU\u4e2d\u7684\u53c2\u6570\u62f7\u8d1d\u81f3\u5185\u6838\u6001\u5806\u6808 \u8c03\u7528\u540d\u4e3a\u7cfb\u7edf\u8c03\u7528\u670d\u52a1\u4f8b\u7a0b\uff08system call service routine\uff09\u7684C\u51fd\u6570\u6765\u5904\u7406\u7cfb\u7edf\u8c03\u7528 \u9000\u51fa\u7cfb\u7edf\u8c03\u7528\u5904\u7406\u7a0b\u5e8f\uff0c\u5c06\u5185\u6838\u6808\u4e2d\u7684\u503c\u52a0\u8f7d\u81f3\u5bc4\u5b58\u5668\uff0c\u5e76\u4ece\u5185\u6838\u6001\u5207\u6362\u56de\u7528\u6237\u6001 \u4e3a\u4e86\u5c06\u7cfb\u7edf\u8c03\u7528\u53f7\u4e0e\u5bf9\u5e94\u7684\u670d\u52a1\u4f8b\u7a0b\u8054\u7cfb\u8d77\u6765\uff0c\u5185\u6838\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u5206\u6d3e\u8868\uff08system call dispatch table\uff09\uff0c\u8fd9\u4e2a\u8868\u5b58\u653e\u5728sys_call_table
\u6570\u7ec4\u4e2d\u3002\u5185\u6838\u62ff\u5230\u7cfb\u7edf\u8c03\u7528\u53f7\u4e4b\u540e\uff0c\u5c31\u53bbsys_call_table
\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u7cfb\u7edf\u8c03\u7528\u5b9e\u73b0\u51fd\u6570\u53bb\u6267\u884c\u3002\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u4f7f\u7528\u8fd4\u56de\u6307\u4ee4\u4ece\u5185\u6838\u6001\u8fd4\u56de\u81f3\u7528\u6237\u6001\u3002
\u5185\u6838\u5728\u6267\u884c\u7cfb\u7edf\u8c03\u7528\u7684\u65f6\u5019\u5904\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u3002current
\u6307\u9488\u6307\u5411\u5f53\u524d\u4efb\u52a1\uff0c\u5373\u5f15\u53d1\u7cfb\u7edf\u8c03\u7528\u7684\u90a3\u4e2a\u8fdb\u7a0b\u3002\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\uff0c\u5185\u6838\u53ef\u4ee5\u4f11\u7720\u5e76\u4e14\u53ef\u4ee5\u88ab\u62a2\u5360\u3002\u56e0\u6b64\u5fc5\u987b\u4fdd\u8bc1\u7cfb\u7edf\u8c03\u7528\u65f6\u53ef\u91cd\u5165\u7684\uff0c\u56e0\u4e3a\u65b0\u7684\u8fdb\u7a0b\u53ef\u80fd\u4f1a\u4f7f\u7528\u76f8\u540c\u7684\u7cfb\u7edf\u8c03\u7528\u3002
"},{"location":"linux/kernel/others/#_3","title":"\u4fe1\u53f7","text":"\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u4e3a\u4e86\u54cd\u5e94\u5404\u79cd\u4e8b\u4ef6\u5b9a\u4e49\u4e86\u975e\u5e38\u591a\u7684\u4fe1\u53f7\u3002\u6bd4\u5982\u5f53\u6211\u4eec\u53d1\u9001kill -9 ${pid}
\u65f6\uff0c\u5176\u5b9e\u5c31\u662f\u53d1\u9001SIGKILL\u4fe1\u53f7\u7ed9\u6307\u5b9a\u8fdb\u7a0b\uff0c\u5c06\u5b83\u6740\u6b7b\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7kill -l
\u547d\u4ee4\u67e5\u770b\u6240\u6709\u7684\u4fe1\u53f7\u3002\u6bcf\u4e2a\u4fe1\u53f7\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684ID\u548c\u5bf9\u5e94\u7684\u9ed8\u8ba4\u64cd\u4f5c\u3002
\u8fdb\u7a0b\u5bf9\u4fe1\u53f7\u7684\u5904\u7406\u65b9\u5f0f\u6709\u4e09\u79cd\uff1a
\u6267\u884c\u9ed8\u8ba4\u64cd\u4f5c\u3002 \u81ea\u5b9a\u4e49\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002 \u5ffd\u7565\u4fe1\u53f7\u3002\u6ce8\u610f\uff0cSIGKILL\u548cSIGSTOP\u65e0\u6cd5\u5ffd\u7565\u3002 Linux\u63a8\u8350\u4f7f\u7528sigaction()
\u51fd\u6570\u6765\u81ea\u5b9a\u4e49\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);\n
\u800csigaction\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
struct sigaction {\n __sighandler_t sa_handler;\n unsigned long sa_flags;\n __sigrestore_t sa_restorer;\n sigset_t sa_mask; \n};\n
\u5176\u4e2dsa_handler
\u5c31\u662f\u4f60\u8981\u5b9a\u4e49\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002
\u53d1\u9001\u4fe1\u53f7\u7531\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u53d1\u9001\u7ed9\u6574\u4e2a\u7ebf\u7a0b\u7ec4\u7684\uff0c\u8fd8\u6709\u4e00\u79cd\u662f\u53d1\u9001\u7ed9\u67d0\u4e2a\u5355\u72ec\u7ebf\u7a0b\u7684\u3002\u4fe1\u53f7\u5206\u4e3a\u4e0d\u53ef\u9760\u4fe1\u53f7\u548c\u53ef\u9760\u4fe1\u53f7\u3002\u5728task_struct
\u4e2d\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53sigpending
\uff0c\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
struct sigpending{\n struct list_head list;\n sigset_t signal;\n};\n
\u5bf9\u4e8e\u4e0d\u53ef\u9760\u4fe1\u53f7\uff0c\u4e5f\u5c31\u662f\u7f16\u53f7\u5c0f\u4e8e32\u7684\u4fe1\u53f7\uff0c\u4f1a\u653e\u5728sigset_t
\u96c6\u5408\u4e2d\uff0c\u4e0d\u8bba\u53d1\u9001\u591a\u5c11\u6b21\uff0c\u5728\u88ab\u5904\u7406\u524d\u90fd\u53ea\u4f1a\u4fdd\u7559\u4e00\u4efd\u3002\u5bf9\u4e8e\u53ef\u9760\u4fe1\u53f7\uff0c\u5219\u4f1a\u6302\u5728struct sigpending
\u7684\u94fe\u8868\u4e2d\u6328\u4e2a\u5904\u7406\u3002
"},{"location":"linux/kernel/others/#_4","title":"\u5b9a\u65f6\u5668","text":"\u5185\u6838\u4e2d\u6709\u5927\u91cf\u7684\u51fd\u6570\u662f\u57fa\u4e8e\u65f6\u95f4\u9a71\u52a8\u7684\u3002\u6709\u4e9b\u51fd\u6570\u9700\u8981\u5468\u671f\u6027\u6267\u884c\uff0c\u6709\u4e9b\u51fd\u6570\u9700\u8981\u7b49\u5f85\u4e00\u4e2a\u76f8\u5bf9\u65f6\u95f4\u540e\u624d\u8fd0\u884c\u3002\u5468\u671f\u6027\u7684\u4e8b\u4ef6\u7531\u7cfb\u7edf\u5b9a\u65f6\u5668\u9a71\u52a8\u3002\u7cfb\u7edf\u5b9a\u65f6\u5668\u80fd\u4ee5\u56fa\u5b9a\u7684\u9891\u7387\u4ea7\u751f\u4e2d\u65ad\uff0c\u8fd9\u79cd\u4e2d\u65ad\u88ab\u79f0\u4e3a\u5b9a\u65f6\u5668\u4e2d\u65ad\uff0c\u5b83\u6240\u5bf9\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8d1f\u8d23\u66f4\u65b0\u7cfb\u7edf\u65f6\u95f4\u548c\u6267\u884c\u5468\u671f\u6027\u4efb\u52a1\u3002
\u7cfb\u7edf\u5b9a\u65f6\u5668\u7684\u9891\u7387\u88ab\u79f0\u4e3a\u8282\u62cd\u7387\uff08tick rate\uff09\uff0c\u4ea7\u751f\u7684\u4e24\u6b21\u65f6\u949f\u4e2d\u65ad\u7684\u95f4\u9694\u5c31\u88ab\u79f0\u4e3a\u8282\u62cd\uff08tick\uff09\uff0c\u5b83\u7b49\u4e8e\u8282\u62cd\u7387\u5206\u4e4b\u4e00\u79d2\u3002\u5185\u6838\u901a\u8fc7\u65f6\u949f\u4e2d\u65ad\u95f4\u9694\u6765\u8ba1\u7b97\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\u3002\u65f6\u949f\u4e2d\u65ad\u9700\u8981\u6267\u884c\u7684\u64cd\u4f5c\u6709\uff1a
\u66f4\u65b0\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4 \u66f4\u65b0\u5b9e\u9645\u65f6\u95f4 \u5728smp\u7cfb\u7edf\u4e0a\uff0c\u5747\u8861\u8c03\u5ea6\u7a0b\u5e8f\u4e2d\u5404\u5904\u7406\u5668\u4e0a\u7684\u8fd0\u884c\u961f\u5217 \u68c0\u67e5\u5f53\u524d\u8fdb\u7a0b\u662f\u5426\u7528\u5c3d\u4e86\u81ea\u5df1\u7684\u65f6\u95f4\u7247 \u8fd0\u884c\u8d85\u65f6\u7684\u52a8\u6001\u5b9a\u65f6\u5668 \u66f4\u65b0\u8d44\u6e90\u6d88\u8017\u548c\u5904\u7406\u5668\u65f6\u95f4\u7684\u7edf\u8ba1\u503c "},{"location":"linux/kernel/others/#jiffies","title":"\u8282\u62cd\u7387\u548cjiffies\u53d8\u91cf","text":"\u7cfb\u7edf\u5b9a\u65f6\u5668\u9891\u7387\u662f\u901a\u8fc7\u9759\u6001\u9884\u5904\u7406\u5b9a\u4e49\u7684\uff0c\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u6309\u7167HZ\u7684\u503c\u5bf9\u786c\u4ef6\u8fdb\u884c\u8bbe\u7f6e\uff0c\u8be5\u503c\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u3002\u5185\u6838\u5728<asm/param.h>\u6587\u4ef6\u4e2d\u5b9a\u4e49\u3002\u5728x86\u4f53\u7cfb\u7ed3\u6784\u4e2d\uff0c\u7cfb\u7edf\u5b9a\u65f6\u5668\u9891\u7387\u9ed8\u8ba4\u4e3a100\u3002\u4e5f\u5c31\u662f\u8bf4x86\u7684\u65f6\u949f\u4e2d\u65ad\u9891\u7387\u4e3a100HZ\uff0c\u5373\u6bcf\u79d2\u4e2d\u65ad100\u6b21\uff08\u6bcf10ms\u4ea7\u751f\u4e00\u6b21\uff09\u3002
\u65f6\u949f\u4e2d\u65ad\u9891\u7387\u5e94\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u7406\u60f3\u7684\u503c\uff0c\u9ad8HZ\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\uff0c\u4f7f\u5f97\u7531\u65f6\u95f4\u9a71\u52a8\u7684\u4e8b\u4ef6\u66f4\u4e3a\u7cbe\u786e\u3002\u4f46\u540c\u65f6\u4e5f\u5e26\u6765\u4e86\u989d\u5916\u7684\u7cfb\u7edf\u8d1f\u62c5\uff0c\u56e0\u4e3a\u5904\u7406\u5668\u4f1a\u88ab\u66f4\u9891\u7e41\u5730\u6253\u65ad\u53bb\u6267\u884c\u65f6\u949f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002
\u5168\u5c40\u53d8\u91cfjiffies
\u7528\u6765\u8bb0\u5f55\u7cfb\u7edf\u542f\u52a8\u4ee5\u6765\u4ea7\u751f\u7684\u8282\u62cd\u603b\u6570\u3002\u5185\u6838\u5728\u542f\u52a8\u65f6\u5c06\u8be5\u53d8\u91cf\u521d\u59cb\u5316\u4e3a0\uff0c\u6b64\u540e\u6bcf\u4ea7\u751f\u4e00\u6b21\u65f6\u949f\u4e2d\u65ad\u8be5\u503c\u5c31+1\u3002\u56e0\u4e3a\u4e00\u79d2\u5185\u65f6\u949f\u4e2d\u65ad\u7684\u6b21\u6570\u7b49\u4e8eHZ\uff0c\u6240\u4ee5jiffies
\u4e00\u79d2\u5185\u589e\u52a0\u7684\u503c\u4e5f\u5c31\u4e3aHZ\u3002\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\u4ee5\u79d2\u4e3a\u8ba1\uff0c\u5176\u503c\u7b49\u4e8ejiffies/HZ\u3002
jiffies
\u53d8\u91cf\u88ab\u5b9a\u4e49\u4e3aunsigned long\u7c7b\u578b\u3002\u572832\u4f4d\u4f53\u7cfb\u7ed3\u6784\u4e0a\u662f32\u4f4d\u3002\u5982\u679c\u65f6\u949f\u9891\u7387\u4e3a100HZ\uff0c\u90a3\u4e48497\u5929\u540e\u4f1a\u6ea2\u51fa\u3002\u5982\u679c\u662f64\u4f4d\u4f53\u7cfb\u7ed3\u6784\uff0c\u4efb\u4f55\u4eba\u90fd\u522b\u6307\u671b\u4f1a\u770b\u5230\u5b83\u6ea2\u51fa\u3002
\u5f53jiffies
\u53d8\u91cf\u7684\u503c\u8d85\u8fc7\u5b83\u7684\u6700\u5927\u5b58\u653e\u8303\u56f4\u540e\u5c31\u4f1a\u53d1\u751f\u6ea2\u51fa\uff0c\u6b64\u65f6\u518d\u7ee7\u7eed\u589e\u52a0\u7684\u8bdd\uff0c\u5b83\u4f1a\u56de\u7ed5\u81f30\u3002\u4e3a\u4e86\u89e3\u51b3jiffies
\u53d8\u91cf\u7684\u6ea2\u51fa\u95ee\u9898\uff0c\u5185\u6838\u5f15\u5165\u4e86jiffies_64
\u53d8\u91cf\uff0c\u8fd9\u662f\u4e00\u4e2a64\u4f4d\u7684\u65e0\u7b26\u53f7\u6574\u6570\u3002
"},{"location":"linux/kernel/others/#_5","title":"\u52a8\u6001\u5b9a\u65f6\u5668","text":"\u5b9a\u65f6\u5668\u7684\u4f7f\u7528\u5f88\u7b80\u5355\u3002\u4f60\u53ea\u9700\u8981\u6267\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u5de5\u4f5c\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u6307\u5b9a\u8d85\u65f6\u53d1\u751f\u540e\u9700\u8981\u6267\u884c\u7684\u51fd\u6570\uff0c\u7136\u540e\u6fc0\u6d3b\u5b9a\u65f6\u5668\u5c31\u53ef\u4ee5\u4e86\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7ec4\u4e0e\u5b9a\u65f6\u5668\u76f8\u5173\u7684\u63a5\u53e3\u7528\u6765\u7b80\u5316\u5b9a\u65f6\u5668\u7684\u64cd\u4f5c\u3002
\u521b\u5efa\u5b9a\u65f6\u5668\uff1a
struct timer_list my_timer;\n
\u521d\u59cb\u5316\u5b9a\u65f6\u5668\uff1a
init_timer(&my_timer);\n
\u586b\u5145\u5b9a\u65f6\u5668\u7ed3\u6784\u4e2d\u7684\u503c\uff1a
my_timer.expires = jiffies + delay; //\u5b9a\u65f6\u5668\u8d85\u65f6\u8282\u62cd\u6570\nmy_timer.data = 0; //\u5b9a\u65f6\u5668\u5904\u7406\u51fd\u6570\u4f20\u5165\u7684\u503c\nmy_timer.function = my_function; //\u5b9a\u65f6\u5668\u8d85\u65f6\u56de\u8c03\u51fd\u6570\n
\u5982\u679c\u5f53\u524djiffies
\u8ba1\u6570\u5927\u4e8e\u6216\u7b49\u4e8emy_timer.expires\u7684\u503c\uff0c\u90a3\u4e48my_timer.function\u6307\u5411\u7684\u5904\u7406\u51fd\u6570\u5c31\u4f1a\u88ab\u6267\u884c\u3002\u5904\u7406\u51fd\u6570\u5fc5\u987b\u7b26\u5408\u4ee5\u4e0b\u7c7b\u578b\uff1a
void my_function(unsigned long data);\n
\u5176\u4e2ddata\u53c2\u6570\u4f7f\u4f60\u53ef\u4ee5\u5229\u7528\u540c\u4e00\u4e2a\u5904\u7406\u51fd\u6570\u6ce8\u518c\u591a\u4e2a\u5b9a\u65f6\u5668\uff0c\u53ea\u9700\u8981\u901a\u8fc7\u8be5\u53c2\u6570\u5c31\u53ef\u4ee5\u533a\u522b\u5bf9\u5f85\u5b83\u4eec\u3002\u5982\u679c\u4f60\u4e0d\u9700\u8981\u8fd9\u4e2a\u53c2\u6570\uff0c\u76f4\u63a5\u4f200\u5373\u53ef\u3002
\u6700\u540e\uff0c\u4f60\u5fc5\u987b\u624b\u52a8\u6fc0\u6d3b\u5b9a\u65f6\u5668\uff1a
add_timer(&my_timer);\n
\u4e00\u822c\u6765\u8bf4\uff0c\u5b9a\u65f6\u5668\u90fd\u4f1a\u5728\u8d85\u65f6\u540e\u9a6c\u4e0a\u6267\u884c\uff0c\u4f46\u4e5f\u6709\u53ef\u80fd\u4f1a\u63a8\u8fdf\u5230\u4e0b\u4e00\u4e2a\u65f6\u949f\u8282\u62cd\u65f6\u624d\u8fd0\u884c\uff0c\u6240\u4ee5\u4e0d\u80fd\u7528\u5b9a\u65f6\u5668\u6765\u5b9e\u73b0\u4efb\u4f55\u786c\u5b9e\u65f6\u7684\u4efb\u52a1\u3002\u5982\u679c\u9700\u8981\u4fee\u6539\u5b9a\u65f6\u5668\u8d85\u65f6\u65f6\u95f4\uff0c\u53ef\u4ee5\u901a\u8fc7mod_timer()
\u51fd\u6570\u6765\u5b9e\u73b0\uff1a
mod_timer(&my_timer, jiffies + new_delay);\n
\u5982\u679c\u5728\u5b9a\u65f6\u5668\u8d85\u65f6\u524d\u505c\u6b62\u5b9a\u65f6\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528del_timer()
\u51fd\u6570\uff1a
del_timer(&my_timer);\n
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u591a\u5904\u7406\u5668\u7cfb\u7edf\u4e2d\uff0c\u5220\u9664\u5b9a\u65f6\u5668\u65f6\u53ef\u80fd\u9700\u8981\u7b49\u5f85\u5728\u5176\u4ed6\u5904\u7406\u5668\u4e0a\u8fd0\u884c\u7684\u5b9a\u65f6\u5668\u5904\u7406\u7a0b\u5e8f\u90fd\u9000\u51fa\uff0c\u8fd9\u65f6\u9700\u8981\u7528\u5230del_timer_syn()
\u51fd\u6570\u6765\u6267\u884c\u5220\u9664\u5de5\u4f5c\u3002
"},{"location":"linux/kernel/others/#_6","title":"\u5ef6\u8fdf\u6267\u884c","text":"\u5185\u6838\u4ee3\u7801\u5f80\u5f80\u9700\u8981\u63a8\u8fdf\u67d0\u4e9b\u4efb\u52a1\u7684\u6267\u884c\uff0c\u8fd9\u79cd\u63a8\u8fdf\u901a\u5e38\u53d1\u751f\u5728\u7b49\u5f85\u786c\u4ef6\u5b8c\u6210\u67d0\u4e9b\u5de5\u4f5c\uff0c\u800c\u4e14\u7b49\u5f85\u65f6\u95f4\u5f80\u5f80\u975e\u5e38\u77ed\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u591a\u79cd\u5ef6\u8fdf\u65b9\u6cd5\u6765\u5904\u7406\u5ef6\u8fdf\u8bf7\u6c42\u3002
\u6700\u7b80\u5355\u7684\u5ef6\u8fdf\u65b9\u6cd5\u5c31\u662f\u5fd9\u7b49\u5f85\u3002\u8be5\u65b9\u6cd5\u4ec5\u4ec5\u5728\u60f3\u8981\u5ef6\u8fdf\u7684\u65f6\u95f4\u662f\u8282\u62cd\u7684\u6574\u6570\u500d\uff0c\u6216\u8005\u7cbe\u786e\u7387\u8981\u6c42\u4e0d\u9ad8\u7684\u60c5\u51b5\u4e0b\u624d\u53ef\u4ee5\u4f7f\u7528\u3002\u5fd9\u7b49\u5f85\u7684\u5b9e\u73b0\u975e\u5e38\u7b80\u5355\u2014\u2014\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u4e0d\u65ad\u7b49\u5f85\u76f4\u5230\u5e0c\u671b\u7684\u65f6\u949f\u8282\u62cd\u6570\u8017\u5c3d\uff0c\u6bd4\u5982\uff1a
unsigned long timeout = jiffies + 10; //\u7b49\u5f8510\u4e2a\u8282\u62cd\nwhile(time_before(jiffies, timeout))\n{}\n
\u8be5\u5faa\u73af\u5c06\u4e0d\u65ad\u6267\u884c\uff0c\u76f4\u5230jiffies
\u5927\u4e8edelay\u4e3a\u6b62\u3002\u8fd9\u662f\u4e00\u79cd\u4f4e\u6548\u7684\u529e\u6cd5\uff0c \u56e0\u4e3a\u5904\u7406\u5668\u9664\u4e86\u7b49\u5f85\u4e0d\u4f1a\u505a\u4efb\u4f55\u4e8b\u60c5\uff0c\u66f4\u597d\u7684\u65b9\u6848\u662f\u5728\u7b49\u5f85\u65f6\uff0c\u5141\u8bb8\u5185\u6838\u91cd\u65b0\u8c03\u5ea6\u6267\u884c\u5176\u4ed6\u4efb\u52a1\u3002
\u57fa\u4e8ejiffies
\u7684\u5ef6\u8fdf\u65b9\u6cd5\u53d7\u9650\u4e8e\u65f6\u949f\u8282\u62cd\uff0c\u65e0\u6cd5\u63d0\u4f9b\u66f4\u77ed\u3001\u66f4\u7cbe\u786e\u7684\u5ef6\u8fdf\u8981\u6c42\u3002\u4e3a\u6b64\uff0c\u5185\u6838\u63d0\u4f9b\u4e86\u4e09\u4e2a\u53ef\u4ee5\u5904\u7406us\u3001ns\u548cms\u7ea7\u522b\u7684\u5ef6\u8fdf\u51fd\u6570\uff1a
void udelay(unsigned long usecs)\nvoid ndelay(unsigned long nsecs)\nvoid mdelay(unsigned long msecs)\n
\u66f4\u7406\u60f3\u7684\u5ef6\u8fdf\u6267\u884c\u65b9\u6cd5\u662f\u4f7f\u7528schedule_timeout()
\u51fd\u6570\uff0c\u8be5\u65b9\u6cd5\u8ba9\u9700\u8981\u5ef6\u8fdf\u6267\u884c\u7684\u4efb\u52a1\u7761\u7720\u5230\u6307\u5b9a\u5ef6\u8fdf\u65f6\u95f4\u8017\u5c3d\u540e\u518d\u91cd\u65b0\u8fd0\u884c\u3002\u5176\u7528\u6cd5\u5982\u4e0b\uff1a
set_current_state(TASK_INTERRUPTIBLE);\nschedule_timeout(s * HZ);\n
\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5f53\u524d\u4efb\u52a1\u63a8\u5165\u53ef\u4e2d\u65ad\u7761\u7720\u961f\u5217\uff0c\u7761\u7720s\u79d2\u540e\u5524\u9192\u3002\u6ce8\u610f\uff0c\u7531\u4e8eschedule_timeout()
\u51fd\u6570\u9700\u8981\u8c03\u7528\u8c03\u5ea6\u7a0b\u5e8f\uff0c\u6240\u4ee5\u8c03\u7528\u5b83\u7684\u4ee3\u7801\u5fc5\u987b\u4fdd\u8bc1\u80fd\u591f\u7761\u7720\u3002\u4e5f\u5c31\u662f\u8c03\u7528\u51fd\u6570\u5fc5\u987b\u4f4d\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\uff0c\u4e14\u4e0d\u80fd\u6301\u6709\u9501\u3002
\u5f53\u4efb\u52a1\u88ab\u91cd\u65b0\u8c03\u5ea6\u65f6\uff0c\u5c06\u8fd4\u56de\u4ee3\u7801\u8fdb\u5165\u7761\u7720\u524d\u7684\u4f4d\u7f6e\u7ee7\u7eed\u6267\u884c\u3002\u5982\u679c\u4efb\u52a1\u63d0\u524d\u88ab\u5524\u9192\uff0c\u90a3\u4e48\u5b9a\u65f6\u5668\u88ab\u64a4\u9500\u3002
"},{"location":"linux/kernel/others/#_7","title":"\u9875\u9ad8\u901f\u7f13\u5b58\u4e0e\u9875\u56de\u5199","text":"\u9875\u9ad8\u901f\u7f13\u5b58\u662f\u4e00\u79cd\u628a\u78c1\u76d8\u7684\u6570\u636e\u7f13\u5b58\u5230\u7269\u7406\u5185\u5b58\u4e2d\u7684\u673a\u5236\uff0c\u4f7f\u5f97\u5bf9\u78c1\u76d8\u7684\u8bbf\u95ee\u53d8\u4e3a\u5bf9\u7269\u7406\u5185\u5b58\u7684\u8bbf\u95ee\u3002\u9ad8\u901f\u7f13\u5b58\u7684\u91cd\u8981\u6027\u4f53\u73b0\u5728\uff1a
\u8bbf\u95ee\u78c1\u76d8\u7684\u901f\u5ea6\u8fdc\u8fdc\u4f4e\u4e8e\u8bbf\u95ee\u5185\u5b58\u7684\u901f\u5ea6\u3002
\u6570\u636e\u4e00\u65e6\u88ab\u8bbf\u95ee\uff0c\u5c31\u5f88\u6709\u53ef\u80fd\u5728\u77ed\u671f\u5185\u518d\u6b21\u88ab\u8bbf\u95ee\u3002\u8fd9\u5c31\u662f\u5c40\u90e8\u6027\u539f\u7406\u3002
\u5f53\u5185\u6838\u5f00\u59cb\u4e00\u4e2a\u8bfb\u64cd\u4f5c\uff0c\u5b83\u9996\u5148\u4f1a\u68c0\u67e5\u9700\u8981\u7684\u6570\u636e\u662f\u5426\u5728\u9875\u9ad8\u901f\u7f13\u5b58\u4e2d\u3002\u5982\u679c\u5728\uff0c\u653e\u5f03\u8bbf\u95ee\u78c1\u76d8\uff0c\u800c\u76f4\u63a5\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u3002\u8fd9\u4e2a\u884c\u4e3a\u79f0\u4e3a\u7f13\u5b58\u547d\u4e2d\uff08cache hit\uff09\u3002\u5426\u5219\u79f0\u4e3a\u7f13\u5b58\u672a\u547d\u4e2d\uff08cache miss\uff09\uff0c\u90a3\u4e48\u5185\u6838\u5fc5\u987b\u8c03\u5ea6\u5757I/O\u64cd\u4f5c\u53bb\u78c1\u76d8\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u7136\u540e\u5c06\u6570\u636e\u653e\u5165\u9875\u7f13\u5b58\u4e2d\u3002\u5185\u6838\u91c7\u7528\u9884\u8bfb\u673a\u5236\uff1a\u5373\u5f53\u4ece\u78c1\u76d8\u4e2d\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u7531\u4e8e\u78c1\u76d8\u7684\u8bfb\u5199\u5355\u4f4d\u4e3ablock\uff084KB\uff09\uff0c\u51fa\u4e8e\u7a7a\u95f4\u5c40\u90e8\u6027\u539f\u7406\uff0c\u5185\u6838\u4f1a\u5c06\u591a\u4e2ablock\u7684\u6570\u636e\u90fd\u52a0\u5165\u5230\u7f13\u5b58\u4e2d\u3002
"},{"location":"linux/kernel/others/#_8","title":"\u5199\u7f13\u5b58\u7b56\u7565","text":"\u5728\u8fdb\u7a0b\u5199\u78c1\u76d8\u65f6\uff0c\u7f13\u5b58\u7684\u4f7f\u7528\u4e00\u822c\u6709\u4ee5\u4e0b\u4e09\u79cd\uff1a
\u4e0d\u7f13\u5b58\uff1a\u4e5f\u5c31\u662f\u8bf4\u9ad8\u901f\u7f13\u5b58\u4e0d\u7f13\u5b58\u4efb\u4f55\u5199\u64cd\u4f5c\uff0c\u800c\u662f\u76f4\u63a5\u5199\u5165\u78c1\u76d8\u3002\u8fd9\u79cd\u65b9\u5f0f\u5f88\u5c11\u91c7\u7528\uff0c\u56e0\u4e3a\u6027\u80fd\u975e\u5e38\u5dee\u3002
\u5199\u64cd\u4f5c\u81ea\u52a8\u66f4\u65b0\u7f13\u5b58\uff0c\u540c\u65f6\u4e5f\u66f4\u65b0\u78c1\u76d8\u6587\u4ef6\uff1a\u8fd9\u79cd\u7b56\u7565\u5bf9\u7f13\u5b58\u4e00\u81f4\u6027\u975e\u5e38\u6709\u6548\uff0c\u56e0\u4e3a\u5185\u5b58\u7f13\u5b58\u59cb\u7ec8\u548c\u78c1\u76d8\u4e00\u81f4\u3002
Linux\u91c7\u7528\u7684\u2014\u2014\u56de\u5199\uff1a\u5199\u64cd\u4f5c\u5199\u5165\u7f13\u5b58\uff0c\u4f46\u662f\u78c1\u76d8\u5e76\u4e0d\u7acb\u523b\u66f4\u65b0\uff0c\u800c\u662f\u5c06\u9875\u9ad8\u901f\u7f13\u5b58\u4e2d\u88ab\u5199\u5165\u7684\u9875\u9762\u6807\u8bb0\u4e3a\u201c\u810f\u201d\uff0c\u7136\u540e\u52a0\u5165\u5230\u810f\u9875\u5217\u8868\u4e2d\u3002\u7531\u4e00\u4e2a\u56de\u5199\u8fdb\u7a0b\u5468\u671f\u6027\u7684\u5c06\u810f\u9875\u94fe\u8868\u4e2d\u7684\u9875\u56de\u5199\u81f3\u78c1\u76d8\uff0c\u6700\u540e\u6e05\u7406\u810f\u9875\u6807\u8bc6\u3002
"},{"location":"linux/kernel/others/#_9","title":"\u7f13\u5b58\u56de\u6536\u7b56\u7565","text":"\u7531\u4e8e\u5927\u91cf\u7684\u9875\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\uff0c\u5fc5\u7136\u5bfc\u81f4\u53ef\u7528\u5185\u5b58\u7684\u4e0b\u964d\u3002\u4e3a\u4e86\u4fdd\u8bc1\u5185\u5b58\u7684\u6b63\u5e38\u4f7f\u7528\uff0c\u5fc5\u987b\u6709\u4e00\u79cd\u673a\u5236\u53ef\u4ee5\u56de\u6536\u7f13\u5b58\u3002Linux\u7684\u7f13\u5b58\u56de\u6536\u662f\u5979\u901a\u8fc7\u9009\u62e9\u5e72\u51c0\u9875\u8fdb\u884c\u7b80\u5355\u66ff\u6362\u3002\u5982\u679c\u7f13\u5b58\u4e2d\u6ca1\u6709\u8db3\u591f\u7684\u5e72\u51c0\u9875\uff0c\u5185\u6838\u5c06\u5f3a\u5236\u6027\u7684\u8fdb\u884c\u56de\u5199\u64cd\u4f5c\uff0c\u4ee5\u817e\u51fa\u66f4\u591a\u7684\u5e72\u51c0\u9875\u4f7f\u7528\u3002
\u4e00\u79cd\u56de\u6536\u7b56\u7565\u88ab\u79f0\u4e3a\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7b97\u6cd5\uff0c\u7b80\u79f0LRU\uff08Least Recently Used\uff09\u3002LRU\u7b97\u6cd5\u4e00\u822c\u662f\u7528\u94fe\u8868\u4f5c\u4e3a\u6570\u636e\u7ed3\u6784\u6765\u5b9e\u73b0\u7684\uff0c\u94fe\u8868\u5934\u90e8\u7684\u6570\u636e\u662f\u6700\u8fd1\u4f7f\u7528\u7684\uff0c\u800c\u94fe\u8868\u672b\u5c3e\u7684\u6570\u636e\u662f\u6700\u4e45\u6ca1\u88ab\u4f7f\u7528\u7684\u3002\u5f53\u7a7a\u95f4\u4e0d\u591f\u65f6\uff0c\u5c31\u6dd8\u6c70\u6700\u4e45\u6ca1\u88ab\u4f7f\u7528\u7684\u8282\u70b9\uff0c\u4e5f\u5c31\u662f\u94fe\u8868\u672b\u5c3e\u7684\u6570\u636e\uff0c\u4ece\u800c\u817e\u51fa\u5185\u5b58\u7a7a\u95f4\u3002\u4f20\u7edf\u7684LRU\u7b97\u6cd5\u5bf9\u4e8e\u90a3\u4e9b\u53ea\u4f1a\u88ab\u8bbf\u95ee\u4e00\u6b21\u7684\u6587\u4ef6\u6548\u679c\u5c24\u5176\u5dee\u3002
Linux\u5185\u6838\u5bf9LRU\u7b97\u6cd5\u8fdb\u884c\u4e86\u6539\u8fdb\uff0c\u88ab\u79f0\u4e3a\u53cc\u94fe\u7b56\u7565\u2014\u2014\u7ef4\u62a4\u4e24\u4e2a\u94fe\u8868\uff1a\u6d3b\u8dc3\u94fe\u8868\uff08active list\uff09\u548c\u4e0d\u6d3b\u8dc3\u94fe\u8868\uff08inactive list\uff09\u3002\u5904\u4e8e\u6d3b\u8dc3\u94fe\u8868\u4e0a\u7684\u9875\u88ab\u8ba4\u4e3a\u662f\u201c\u70ed\u201d\u7684\u4e14\u4e0d\u4f1a\u6362\u51fa\uff0c\u5904\u4e8e\u4e0d\u6d3b\u8dc3\u94fe\u8868\u4e0a\u7684\u9875\u88ab\u8ba4\u4e3a\u662f\u201c\u51b7\u201d\u7684\u53ef\u4ee5\u88ab\u6362\u51fa\u3002\u9875\u9762\u4ece\u5c3e\u90e8\u52a0\u5165\uff0c\u4ece\u5934\u90e8\u79fb\u9664\uff0c\u5c31\u50cf\u961f\u5217\u4e00\u6837\u3002\u6709\u4e86\u8fd9\u4e24\u4e2aLRU\u94fe\u8868\u540e\uff0c\u9884\u8bfb\u9875\u5c31\u53ea\u9700\u8981\u52a0\u5165\u5230\u4e0d\u6d3b\u8dc3\u94fe\u8868\u7684\u5934\u90e8\uff0c\u5f53\u9875\u88ab\u771f\u6b63\u8bbf\u95ee\u7684\u65f6\u5019\uff0c\u624d\u5c06\u9875\u63d2\u5165\u5230\u6d3b\u8dc3\u94fe\u8868\u7684\u5934\u90e8\u3002\u5982\u679c\u9884\u8bfb\u7684\u9875\u4e00\u76f4\u6ca1\u6709\u88ab\u8bbf\u95ee\uff0c\u5c31\u4f1a\u4ece\u4e0d\u6d3b\u8dc3\u94fe\u8868\u4e2d\u79fb\u9664\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5f71\u54cd\u6d3b\u8dc3\u94fe\u8868\u4e2d\u7684\u70ed\u6570\u636e\u3002
"},{"location":"linux/kernel/sched/","title":"\u8fdb\u7a0b\u7ba1\u7406\u4e0e\u8c03\u5ea6","text":"\u8fdb\u7a0b\u5c31\u662f\u5904\u4e8e\u6267\u884c\u671f\u7684\u7a0b\u5e8f\uff0c\u5f53\u6211\u4eec\u5c06\u4ee3\u7801\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u65f6\uff0c\u8f93\u5165./a.out\uff0c\u6211\u4eec\u5c31\u5f00\u542f\u4e86\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u3002\u8fdb\u7a0b\u4ece\u78c1\u76d8\u52a0\u8f7d\u5230\u5185\u5b58\u7684\u8fc7\u7a0b\u8bf7\u53c2\u8003\u7a0b\u5e8f\u7684\u88c5\u8f7d\u3002
\u53ef\u4ee5\u628a\u4e00\u4e2a\u8fdb\u7a0b\u60f3\u8c61\u6210\u4e00\u4e2a\u5e9e\u5927\u7684\u9879\u76ee\u7ec4\uff0c\u5b83\u5305\u542b\u4e86\u5404\u79cd\u8d44\u6e90\uff0c\u4f8b\u5982\u6253\u5f00\u7684\u6587\u4ef6\u3001\u5360\u7528\u7684\u5185\u5b58\u3001\u5904\u7406\u5668\u7684\u72b6\u6001\u7b49\u3002\u800c\u7ebf\u7a0b\uff0c\u5c31\u50cf\u662f\u9879\u76ee\u7ec4\u4e2d\u8d1f\u8d23\u6267\u884c\u5177\u4f53\u4efb\u52a1\u7684\u4e2a\u4eba\u3002\u6b63\u5982\u6bcf\u4e2a\u9879\u76ee\u7ec4\u81f3\u5c11\u9700\u8981\u4e00\u4e2a\u4eba\u6765\u6267\u884c\u4efb\u52a1\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u5fc5\u987b\u6709\u4e00\u4e2a\u4e3b\u7ebf\u7a0b\u3002\u4f60\u53ef\u4ee5\u9009\u62e9\u5c06\u6240\u6709\u4efb\u52a1\u90fd\u4ea4\u7ed9\u4e3b\u7ebf\u7a0b\u6765\u5b8c\u6210\uff0c\u4f46\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f1a\u628a\u4e00\u4e2a\u5927\u7684\u4efb\u52a1\u5206\u89e3\u6210\u591a\u4e2a\u5c0f\u4efb\u52a1\uff0c\u5e76\u521b\u5efa\u989d\u5916\u7684\u7ebf\u7a0b\u6765\u5e76\u884c\u5904\u7406\u8fd9\u4e9b\u5c0f\u4efb\u52a1\u3002\u90a3\u4e48\uff0c\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u521b\u5efa\u66f4\u591a\u7684\u8fdb\u7a0b\u6765\u5904\u7406\u8fd9\u4e9b\u4efb\u52a1\u5462\uff1f\u4ece\u6280\u672f\u4e0a\u6765\u8bf4\uff0c\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u8fd9\u901a\u5e38\u5e76\u4e0d\u662f\u6700\u4f73\u9009\u62e9\u3002\u9996\u5148\uff0c\u8fdb\u7a0b\u5360\u7528\u7684\u8d44\u6e90\u6bd4\u7ebf\u7a0b\u591a\uff0c\u800c\u7ebf\u7a0b\u662f\u8f7b\u91cf\u7ea7\u7684\uff0c\u521b\u5efa\u7684\u901f\u5ea6\u8981\u5feb\u5f97\u591a\u3002\u5176\u6b21\uff0c\u8fdb\u7a0b\u4e4b\u95f4\u7684\u8d44\u6e90\u5171\u4eab\u76f8\u5bf9\u590d\u6742\uff0c\u800c\u7ebf\u7a0b\u7531\u4e8e\u5171\u4eab\u540c\u4e00\u8fdb\u7a0b\u7684\u8d44\u6e90\uff0c\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u8bbf\u95ee\u8fd9\u4e9b\u8d44\u6e90\u3002\u8fd9\u5c31\u50cf\u662f\u5728\u4e00\u4e2a\u516c\u53f8\u7684\u4e0d\u540c\u9879\u76ee\u7ec4\u4e4b\u95f4\u8fdb\u884c\u5de5\u4f5c\u4ea4\u63a5\u53ef\u80fd\u4f1a\u5f88\u9ebb\u70e6\uff0c\u4f46\u5982\u679c\u5927\u5bb6\u90fd\u5c5e\u4e8e\u540c\u4e00\u4e2a\u9879\u76ee\u7ec4\uff0c\u5408\u4f5c\u5c31\u4f1a\u987a\u7545\u5f97\u591a\u3002
"},{"location":"linux/kernel/sched/#_2","title":"\u8fdb\u7a0b\u63cf\u8ff0\u7b26","text":"\u4e3a\u4e86\u7ba1\u7406\u8fdb\u7a0b\uff0c\u5185\u6838\u5fc5\u987b\u6e05\u6670\u5730\u63cf\u8ff0\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u3002\u5728Linux\u7cfb\u7edf\u4e0b\uff0c\u4e0d\u7ba1\u662f\u8fdb\u7a0b\u8fd8\u662f\u7ebf\u7a0b\uff0c\u5185\u6838\u7edf\u4e00\u7528task_struct
\u7ed3\u6784\u4f53\u7ba1\u7406\u3002
"},{"location":"linux/kernel/sched/#_3","title":"\u5185\u6838\u6808","text":"void *stack;\n
\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e00\u4e2a\u4e13\u7528\u7684\u5185\u6838\u6808\uff0c\u7528\u4e8e\u4fdd\u5b58\u8fdb\u7a0b\u5728\u5185\u6838\u6001\u6267\u884c\u65f6\u7684\u4e34\u65f6\u6570\u636e\u548c\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u5f53\u521b\u5efa\u65b0\u8fdb\u7a0b\u65f6\uff0c\u5185\u6838\u4f1a\u4e3a\u5176\u5206\u914d\u4e00\u4e2a\u5408\u9002\u5927\u5c0f\u7684\u5185\u6838\u6808\u7a7a\u95f4\uff0c\u5e76\u5c06\u5176\u5730\u5740\u8d4b\u7ed9task_struct
\u4e2d\u7684stack\u6210\u5458\u3002
"},{"location":"linux/kernel/sched/#_4","title":"\u7ebf\u7a0b\u63cf\u8ff0\u7b26","text":"\u7ebf\u7a0b\u63cf\u8ff0\u7b26thread_info
\u662f\u4e00\u4e2a\u7528\u4e8e\u5b58\u653e\u7ebf\u7a0b\u76f8\u5173\u4fe1\u606f\u7684\u7ed3\u6784\u4f53\uff0c\u5b83\u5305\u542b\u4e86\u5f88\u591a\u4e0e\u7ebf\u7a0b\u76f8\u5173\u7684\u5b57\u6bb5\uff0c\u5176\u4e2d\u6700\u91cd\u8981\u7684\u662ftask_struct *task
\uff0c\u5b83\u6307\u5411\u5f53\u524d\u7ebf\u7a0b\u6240\u5c5e\u7684\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u3002\u4e3a\u4e86\u65b9\u4fbf\u8bbf\u95ee\u5f53\u524dCPU\u4e0a\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u7684task_struct
\u7ed3\u6784\uff0c\u5185\u6838\u63d0\u4f9b\u4e86current
\u5b8f\uff0c\u8be5\u5b8f\u672c\u8d28\u4e0a\u7b49\u4e8e\uff1a
current_thread_info()->task\n
\u4e0a\u8ff0\u4ee3\u7801\u8fd4\u56de\u5f53\u524dtask_struct
\u7684\u5730\u5740\u3002
"},{"location":"linux/kernel/sched/#_5","title":"\u8fdb\u7a0b\u72b6\u6001","text":"\u5728task_struct
\u4e2d\uff0c\u6d89\u53ca\u5230\u8fdb\u7a0b\u72b6\u6001\u7684\u662f\u8fd9\u51e0\u4e2a\u6210\u5458\uff1a
volatile long state; \n int exit_state;\n unsigned int flags;\n
state\u53ef\u4ee5\u53d6\u7684\u503c\u6709\uff1a
/* Used in tsk->state: */\n#define TASK_RUNNING 0\n#define TASK_INTERRUPTIBLE 1\n#define TASK_UNINTERRUPTIBLE 2\n#define __TASK_STOPPED 4\n#define __TASK_TRACED 8\n/* Used in tsk->exit_state: */\n#define EXIT_DEAD 16\n#define EXIT_ZOMBIE 32\n#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD)\n/* Used in tsk->state again: */\n#define TASK_DEAD 64\n#define TASK_WAKEKILL 128\n#define TASK_WAKING 256\n#define TASK_PARKED 512\n#define TASK_NOLOAD 1024\n#define TASK_NEW 2048\n#define TASK_STATE_MAX 4096\n
state\u5b57\u6bb5\u7684\u503c\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u8d4b\u503c\u8bed\u53e5\u8bbe\u7f6e\u3002
p->state = TASK_RUNNING;\n
\u4e5f\u53ef\u4ee5\u4f7f\u7528set_task_state
\u548cset_current_state
\u5b8f\uff1a\u5b83\u4eec\u5206\u522b\u8bbe\u7f6e\u6307\u5b9a\u8fdb\u7a0b\u7684\u72b6\u6001\u548c\u5f53\u524d\u6267\u884c\u8fdb\u7a0b\u7684\u72b6\u6001\u3002
TASK_RUNNING\u8868\u793a\u8fdb\u7a0b\u6b63\u5728\u6267\u884c\u6216\u8005\u51c6\u5907\u6267\u884c\u3002
\u5f53\u8fdb\u7a0b\u8fdb\u5165\u7761\u7720\u540e\uff0c\u6709\u4e24\u79cd\u72b6\u6001\uff1a
TASK_INTERRUPTIBLE\u8868\u793a\u8fdb\u7a0b\u53ef\u4ee5\u54cd\u5e94\u4fe1\u53f7\u3002\u4e5f\u5c31\u662f\u5f53\u4e00\u4e2a\u4fe1\u53f7\u6765\u4e34\u65f6\uff0c\u5524\u9192\u8be5\u8fdb\u7a0b\uff0c\u7136\u540e\u6267\u884c\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002
TASK_UNINTERRUPTIBLE\u8868\u793a\u8fdb\u7a0b\u4e0d\u53ef\u4ee5\u54cd\u5e94\u4fe1\u53f7\u3002\u5f53\u8fdb\u7a0b\u7b49\u5f85\u67d0\u4e2a\u4e8b\u4ef6\u5b8c\u6210\u800c\u8fdb\u5165\u6df1\u5ea6\u7761\u7720\u72b6\u6001\u65f6\uff0c\u5982\u679c\u8be5\u4e8b\u4ef6\u56e0\u4e3a\u67d0\u79cd\u539f\u56e0\u65e0\u6cd5\u5b8c\u6210\uff0c\u90a3\u4e48\u8fd9\u4e2a\u8fdb\u7a0b\u4e5f\u5c06\u6c38\u8fdc\u7761\u7720\u4e0b\u53bb\u3002
\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u5371\u9669\u7684\u4e8b\u60c5\uff0c\u9664\u975e\u5f88\u6709\u628a\u63e1\u4e0d\u7136\u4e0d\u4f1a\u8ba9\u8fdb\u7a0b\u8fdb\u5165\u6df1\u5ea6\u7761\u7720\u6001\u3002
\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u4e86\u4e00\u79cd\u65b0\u7684\u72b6\u6001\uff1aTASK_KILLABLE\uff0c\u53ef\u4ee5\u7ec8\u6b62\u7684\u6df1\u5ea6\u7761\u7720\u6001\u3002\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNITERRUPTIBLE)\n
\u5176\u4e2dTASK_WAKEKILL\u8868\u793a\u5728\u63a5\u6536\u5230\u81f4\u547d\u4fe1\u53f7\u65f6\uff0c\u5524\u9192\u8fdb\u7a0b\u3002
TASK_STOPPED\u8868\u793a\u8fdb\u7a0b\u88ab\u6682\u505c\uff0c\u5f53\u63a5\u6536\u5230SIGSTOP\u3001SIGTSTP\u3001SIGTTIN\u6216SIGTTOU\u4fe1\u53f7\u540e\uff0c\u8fdb\u5165\u8be5\u72b6\u6001\u3002
TASK_TRACED\u8868\u793a\u8fdb\u7a0b\u88ab\u8ddf\u8e2a\u3002\u8fd9\u5f80\u5f80\u662f\u8c03\u8bd5\u7a0b\u5e8f\u6682\u65f6\u7ec8\u6b62\u4e86\u8fdb\u7a0b\u7684\u8fd0\u884c\u3002
\u5185\u6838\u7ecf\u5e38\u9700\u8981\u8c03\u6574\u5f53\u524d\u8fdb\u7a0b\u7684\u72b6\u6001\uff0c\u53ef\u4ee5\u4f7f\u7528set_task_state(task, state)
\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u6307\u5b9a\u8fdb\u7a0b\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u72b6\u6001\u3002
exit_state\u7684\u53d6\u503c\u6709\u4e24\u79cd\uff1a
EXIT_ZOMBIE\u8868\u793a\u50f5\u6b7b\u72b6\u6001\u3002\u4e00\u4e2a\u8fdb\u7a0b\u6267\u884c\u88ab\u7ec8\u6b62\uff0c\u4f46\u662f\u5176\u7236\u8fdb\u7a0b\u8fd8\u6ca1\u6709\u8c03\u7528wait4()
\u6216\u8005waitpid()
\u7cfb\u7edf\u8c03\u7528\u6765\u56de\u6536\u8d44\u6e90\u65f6\uff0c\u8fdb\u5165\u8be5\u72b6\u6001\u3002
EXIT_DEAD\u662f\u8fdb\u7a0b\u7684\u6700\u7ec8\u72b6\u6001\u3002\u7236\u8fdb\u7a0b\u56de\u6536\u5b50\u8fdb\u7a0b\u8d44\u6e90\u4e4b\u540e\uff0c\u8fdb\u7a0b\u7531\u7cfb\u7edf\u5220\u9664\u3002
\u8fdb\u7a0b\u7684\u4e00\u4e9b\u5176\u4ed6\u72b6\u6001\u4fe1\u606f\u7531flags
\u63a7\u5236\uff0c\u4f7f\u7528\u4f4d\u63a9\u7801\u6765\u8868\u793a\u4e0d\u540c\u7684\u6807\u8bb0\u3002\u4e00\u4e9b\u5e38\u89c1\u7684\u6807\u8bb0\u5305\u62ec\uff1a
\u4efb\u52a1\u72b6\u6001\uff1a\u4f8b\u5982\u662f\u5426\u6b63\u5728\u8fd0\u884c\u3001\u505c\u6b62\u7b49 \u8c03\u5ea6\u5668\u76f8\u5173\uff1a\u4f8b\u5982\u8c03\u5ea6\u7b56\u7565\u3001\u4f18\u5148\u7ea7\u7b49 \u4fe1\u53f7\u5904\u7406\uff1a\u4f8b\u5982\u6302\u8d77\u4fe1\u53f7\u96c6 \u8fdb\u7a0b\u7279\u6027\uff1a\u662f\u5426\u4e3a\u5b88\u62a4\u8fdb\u7a0b\u3001\u662f\u5426\u5141\u8bb8\u88ab\u8ffd\u8e2a\u7b49 flags\u6210\u5458\u7684\u4e00\u4e9b\u53d6\u503c\u4e3e\u4f8b\u5982\u4e0b\uff0c\u8fd9\u4e9b\u5b8f\u4ee5PF\u5f00\u5934\uff1a
#define PF_EXITING 0x00000004 //getting shut down\n#define PF_WQ_WORKER 0x00000020 //I'm a workqueue worker\n#define PF_KTHREAD 0x00200000 //I'm a kernel thread\n
"},{"location":"linux/kernel/sched/#_6","title":"\u8fdb\u7a0b\u6807\u8bc6","text":"Linux\u7cfb\u7edf\u4f7f\u7528PID\u6765\u6807\u8bc6\u4e00\u4e2a\u8fdb\u7a0b\uff0cPID\u88ab\u987a\u5e8f\u7f16\u53f7\uff0c\u65b0\u521b\u5efa\u7684\u8fdb\u7a0b\u7684PID\u901a\u5e38\u662f\u524d\u4e00\u4e2a\u8fdb\u7a0b+1\u3002\u4f46\u662fPID\u7684\u503c\u6709\u4e00\u4e2a\u4e0a\u9650\uff0c\u7cfb\u7edf\u7ba1\u7406\u5458\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539/proc/sys/kernel/pid_max\u6587\u4ef6\u7684\u503c\u6765\u6539\u53d8\u8fd9\u4e2a\u4e0a\u9650\u3002\u8fd9\u4e48\u4e00\u770b\u4f3c\u4e4e\u4e00\u4e2aPID\u6765\u552f\u4e00\u6807\u8bc6\u4e00\u4e2a\u8fdb\u7a0b\u5c31\u591f\u4e86\uff0c\u4f46\u662f\u5728task_struct
\u4e2d\uff0c\u6d89\u53ca\u5230\u8fdb\u7a0b\u6807\u8bc6\u7684\u6709\u4ee5\u4e0b\u51e0\u4e2a\u6210\u5458\u3002
pid_t pid;\npid_t tgid;\nstruct task_struct *group_leader; \n
\u4f60\u53ef\u80fd\u4f1a\u7591\u60d1\uff0c\u552f\u4e00\u6807\u8bc6\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u4e3a\u4ec0\u4e48\u9700\u8981\u7528\u5230\u8fd9\u4e48\u591a\u53d8\u91cf\uff1f\u8fd9\u662f\u56e0\u4e3a\u4e4b\u524d\u63d0\u5230\uff0c\u5728Linux\u7cfb\u7edf\u4e0b\uff0c\u8fdb\u7a0b\u4e0e\u7ebf\u7a0b\u5e76\u4e0d\u7279\u522b\u533a\u5206\uff0c\u90fd\u662f\u4e00\u4e2atask_struct
\u7ed3\u6784\u4f53\u3002\u8fd9\u5c31\u7ed9\u7ba1\u7406\u5e26\u6765\u4e86\u4e00\u4e9b\u9ebb\u70e6\u3002\u6bd4\u5982\u6211\u4eec\u5e0c\u671b\u540c\u5c5e\u4e8e\u4e00\u4e2a\u8fdb\u7a0b\u7ec4\u7684\u7ebf\u7a0b\u62e5\u6709\u5171\u540c\u7684pid\u3002\u5f53\u6211\u4eec\u53d1\u9001\u4e00\u4e2a\u4fe1\u53f7\u7ed9\u6307\u5b9apid\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u8fd9\u4e2a\u4fe1\u53f7\u80fd\u4f5c\u7528\u4e8e\u8be5\u7ec4\u4e2d\u7684\u6240\u6709\u7ebf\u7a0b\u3002\u5f53\u6740\u6b7b\u67d0\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u5f53\u7136\u662f\u8fde\u540c\u8be5\u8fdb\u7a0b\u4e0b\u7684\u6240\u6709\u7ebf\u7a0b\u4e00\u8d77\u6740\u6b7b\uff0c\u800c\u4e0d\u662f\u53ea\u6740\u6b7b\u4e86\u4e3b\u8fdb\u7a0b\uff0c\u5176\u4ed6\u7ebf\u7a0b\u8fd8\u5728\u5de5\u4f5c\uff0c\u8fd9\u663e\u7136\u4e0d\u5408\u5e38\u7406\u3002\u4e8b\u5b9e\u4e0a\uff0cPOSIX\u6807\u51c6\u4e5f\u89c4\u5b9a\u4e00\u4e2a\u591a\u7ebf\u7a0b\u5e94\u7528\u7a0b\u5e8f\u7684\u6240\u6709\u7ebf\u7a0b\u5fc5\u987b\u4eab\u6709\u5171\u540c\u7684pid\u3002
\u9075\u7167\u8fd9\u4e2a\u6807\u51c6\uff0cLinux\u5f15\u5165\u4e86\u7ebf\u7a0b\u7ec4\u7684\u6982\u5ff5\u3002\u4e00\u4e2a\u7ebf\u7a0b\u7ec4\u4e2d\u6240\u6709\u7ebf\u7a0b\u4f7f\u7528\u548c\u8be5\u7ebf\u7a0b\u7ec4\u9886\u5934\u7ebf\u7a0b\uff08thread group leader\uff09\u76f8\u540c\u7684pid\uff0c\u5b83\u88ab\u5b58\u5165task_struct
\u7684tgid\u5b57\u6bb5\u3002\u5f53\u6211\u4eec\u4f7f\u7528getpid()
\u7cfb\u7edf\u8c03\u7528\u8fd4\u56de\u5f53\u524d\u8fdb\u7a0b\u7684pid\u65f6\uff0c\u8fd4\u56de\u7684\u4e5f\u662ftgid\u7684\u503c\u3002\u4efb\u4f55\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u5982\u679c\u53ea\u6709\u4e3b\u7ebf\u7a0b\uff0c\u90a3\u4e48pid = tgid\uff0c group_leader\u6307\u5411\u7684\u5c31\u662f\u81ea\u5df1\u3002\u5982\u679c\u4e3b\u7ebf\u7a0b\u521b\u5efa\u4e86\u5176\u4ed6\u7ebf\u7a0b\uff0c\u90a3\u4e48\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u81ea\u5df1\u7684pid\uff0c\u4f46\u662ftgid\u4ecd\u7136\u662f\u4e3b\u7ebf\u7a0b\u3002
"},{"location":"linux/kernel/sched/#_7","title":"\u8fdb\u7a0b\u95f4\u5173\u7cfb","text":"Linux\u7cfb\u7edf\u4e2d\u6240\u6709\u7684\u8fdb\u7a0b\u90fd\u662fPID\u4e3a1\u7684init\u8fdb\u7a0b\u7684\u540e\u4ee3\uff0c\u5185\u6838\u5728\u7cfb\u7edf\u542f\u52a8\u7684\u6700\u540e\u9636\u6bb5\u542f\u52a8init\u8fdb\u7a0b\u3002\u8be5\u8fdb\u7a0b\u8bfb\u53d6\u7cfb\u7edf\u7684\u521d\u59cb\u5316\u811a\u672c\u5e76\u6267\u884c\u5176\u4ed6\u7684\u76f8\u5173\u7a0b\u5e8f\uff0c\u6700\u540e\u5b8c\u6210\u6574\u4e2a\u7cfb\u7edf\u7684\u542f\u52a8\u3002
\u6bcf\u4e2a\u8fdb\u7a0b\u5fc5\u6709\u4e00\u4e2a\u7236\u8fdb\u7a0b\uff0c\u5982\u679c\u4e00\u4e2a\u8fdb\u7a0b\u521b\u5efa\u4e86\u591a\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u90a3\u4e48\u5b50\u8fdb\u7a0b\u4e4b\u95f4\u8fd8\u6709\u5144\u5f1f\u5173\u7cfb\u3002\u5728task_struct
\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u5b57\u6bb5\u6765\u8868\u793a\u4eb2\u7f18\u5173\u7cfb\uff1a
struct task_struct __rcu *real_parent; /* real parent process */\nstruct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */\nstruct list_head children; /* list of my children */\nstruct list_head sibling; /* linkage in my parent's children list */\n
\u8fd9\u4e9b\u5b57\u6bb5\u6839\u636e\u540d\u5b57\u5c31\u80fd\u731c\u5230\u662f\u4ec0\u4e48\u610f\u601d\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u901a\u5e38\u60c5\u51b5\u4e0breal_parent\u548cparent\u662f\u4e00\u6837\u7684\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u542f\u52a8GDB\u76d1\u89c6\u67d0\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u8be5\u8fdb\u7a0b\u7684real_parent\u4e0d\u53d8\uff0c\u4f46\u662fparent\u53d8\u6210\u4e86GDB\u3002
\u8fdb\u7a0b\u4e4b\u95f4\u8fd8\u6709\u5176\u4ed6\u5173\u7cfb\uff0c\u8fd9\u91cc\u4e0d\u8be6\u7ec6\u5c55\u5f00\u3002
"},{"location":"linux/kernel/sched/#_8","title":"\u8fd0\u884c\u7edf\u8ba1","text":"u64 utime;//\u7528\u6237\u6001\u6d88\u8017\u7684CPU\u65f6\u95f4\nu64 stime;//\u5185\u6838\u6001\u6d88\u8017\u7684CPU\u65f6\u95f4\nunsigned long nvcsw;//\u81ea\u613f(voluntary)\u4e0a\u4e0b\u6587\u5207\u6362\u8ba1\u6570\nunsigned long nivcsw;//\u975e\u81ea\u613f(involuntary)\u4e0a\u4e0b\u6587\u5207\u6362\u8ba1\u6570\nu64 start_time;//\u8fdb\u7a0b\u542f\u52a8\u65f6\u95f4\uff0c\u4e0d\u5305\u542b\u7761\u7720\u65f6\u95f4\nu64 real_start_time;//\u8fdb\u7a0b\u542f\u52a8\u65f6\u95f4\uff0c\u5305\u542b\u7761\u7720\u65f6\u95f4\n
"},{"location":"linux/kernel/sched/#_9","title":"\u5185\u5b58\u7ba1\u7406","text":"struct mm_struct *mm; \nstruct mm_struct *active_mm; \n
"},{"location":"linux/kernel/sched/#_10","title":"\u6587\u4ef6\u4e0e\u6587\u4ef6\u7cfb\u7edf","text":"/* Filesystem information: */\nstruct fs_struct *fs;\n/* Open file information: */\nstruct files_struct *files;\n
"},{"location":"linux/kernel/sched/#_11","title":"\u8fdb\u7a0b\u7ec4\u7ec7\u5f62\u5f0f","text":"\u8981\u660e\u767d\u8fdb\u7a0b\u4e4b\u95f4\u662f\u5982\u4f55\u7ec4\u7ec7\u7684\uff0c\u9996\u5148\u8981\u77e5\u9053\u53cc\u5411\u94fe\u8868\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u3002\u53cc\u5411\u94fe\u8868\u5c31\u662f\u540c\u65f6\u6709prev\u548cnext\u6307\u9488\u7684\u94fe\u8868\uff0c\u5206\u522b\u6307\u5411\u524d\u4e00\u4e2a\u548c\u540e\u4e00\u4e2a\u5143\u7d20\u3002Linux\u4f7f\u7528\u53cc\u5411\u94fe\u8868\u5c06\u6240\u6709\u8fdb\u7a0b\u7684\u63cf\u8ff0\u7b26\u5168\u90e8\u8fde\u63a5\u8d77\u6765\u3002
"},{"location":"linux/kernel/sched/#_12","title":"\u8fd0\u884c\u961f\u5217","text":"\u5f53\u5185\u6838\u9700\u8981\u5bfb\u627e\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u8fd0\u884c\u65f6\uff0c\u5fc5\u987b\u53ea\u8003\u8651\u5df2\u5904\u4e8eTASK_RUNNING\u72b6\u6001\u7684\u8fdb\u7a0b\uff0c\u4e8e\u662f\u5c31\u6709\u4e86\u8fd0\u884c\u961f\u5217\u3002\u4e3a\u4e86\u63d0\u9ad8\u8c03\u5ea6\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6\uff0c\u5185\u6838\u4e3a\u6bcf\u4e2a\u4f18\u5148\u7ea7\u90fd\u7ef4\u62a4\u4e86\u4e00\u4e2a\u94fe\u8868\u3002\u5728\u591a\u5904\u7406\u5668\u4e2d\uff0c\u6bcf\u4e2aCPU\u90fd\u6709\u81ea\u5df1\u7684\u8fd0\u884c\u961f\u5217\u3002\u8fd0\u884c\u961f\u5217\u662fLinux\u8c03\u5ea6\u7b97\u6cd5\u7684\u57fa\u7840\u3002\u66f4\u8be6\u7ec6\u7684\u5185\u5bb9\u8bf7\u53c2\u8003\u8fdb\u7a0b\u8c03\u5ea6\u3002
"},{"location":"linux/kernel/sched/#_13","title":"\u7b49\u5f85\u961f\u5217","text":"\u7b49\u5f85\u961f\u5217\u5728\u5185\u6838\u4e2d\u6709\u5f88\u591a\u7528\u9014\uff0c\u5c24\u5176\u65f6\u7528\u5728\u4e2d\u65ad\u5904\u7406\u3001\u8fdb\u7a0b\u540c\u6b65\u3002\u8fd0\u884c\u4e2d\u7684\u8fdb\u7a0b\u5f80\u5f80\u9700\u8981\u7b49\u5f85\u67d0\u4e9b\u4e8b\u4ef6\u7684\u53d1\u751f\uff0c\u5e0c\u671b\u7b49\u5f85\u7279\u5b9a\u4e8b\u4ef6\u7684\u8fdb\u7a0b\u5c06\u81ea\u5df1\u653e\u5165\u5408\u9002\u7684\u7b49\u5f85\u961f\u5217\uff0c\u7136\u540e\u8fdb\u5165\u7761\u7720\u72b6\u6001\u3002\u5f53\u4e8b\u4ef6\u53d1\u751f\u540e\uff0c\u7531\u5185\u6838\u8d1f\u8d23\u5524\u9192\u5b83\u4eec\u3002
\u7b49\u5f85\u961f\u5217\u7531\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\uff0c\u6bcf\u4e2a\u7b49\u5f85\u961f\u5217\u90fd\u6709\u4e00\u4e2a\u7b49\u5f85\u961f\u5217\u5934\uff08wait queue head\uff09\uff0c\u4e00\u4e2a\u7c7b\u578b\u4e3await_queue_head_t
\u7684\u6570\u636e\u7ed3\u6784\uff1a
struct __wait_queue_head {\n spinlock_t lock;\n struct list_head task_list;\n};\n\ntypedef struct __wait_queue_head wait_queue_head_t;\n
\u56e0\u4e3a\u7b49\u5f85\u961f\u5217\u4e3b\u8981\u662f\u7531\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u548c\u5185\u6838\u51fd\u6570\u4fee\u6539\u7684\uff0c\u56e0\u6b64\u5fc5\u987b\u6709\u9501\u52a0\u4ee5\u4fdd\u62a4\u3002\u7b49\u5f85\u961f\u5217\u94fe\u8868\u4e2d\u7684\u5143\u7d20\u4e3a\uff1a
struct __wait_queue {\n unsigned int flags;\n struct task_struct *task;\n wait_queue_func_t func;\n struct list_head task_list;\n};\ntypedef struct __wait_queue wait_queue_t;\n
\u7b49\u5f85\u961f\u5217\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u4ee3\u8868\u4e00\u4e2a\u7761\u7720\u4e2d\u7684\u8fdb\u7a0b\uff0c\u5b83\u7684\u63cf\u8ff0\u7b26\u5b58\u5165task\u5b57\u6bb5\u4e2d\u3002task_list\u8d1f\u8d23\u5c06\u6bcf\u4e00\u4e2a\u5143\u7d20\u94fe\u63a5\u5230\u94fe\u8868\u4e2d\u3002func\u8868\u793a\u7b49\u5f85\u961f\u5217\u4e2d\u7761\u7720\u8fdb\u7a0b\u5e94\u8be5\u7528\u4ec0\u4e48\u65b9\u5f0f\u5524\u9192\u3002flags\u8868\u793a\u8be5\u8fdb\u7a0b\u662f\u4e92\u65a5\u8fdb\u7a0b\u8fd8\u662f\u975e\u4e92\u65a5\u8fdb\u7a0b\u3002\u4e92\u65a5\u8fdb\u7a0b\u8868\u793a\u591a\u4e2a\u8fdb\u7a0b\u5728\u7b49\u5f85\u76f8\u540c\u7684\u4e8b\u4ef6\uff0c\u56e0\u6b64\u4ea7\u751f\u4e86\u7ade\u4e89\u5173\u7cfb\uff0c\u6b64\u65f6\u5185\u6838\u53ea\u9700\u8981\u5524\u9192\u5176\u4e2d\u4e00\u4e2a\u8fdb\u7a0b\u5373\u53ef\u3002\u800c\u975e\u4e92\u65a5\u8fdb\u7a0b\u5728\u53d1\u751f\u6307\u5b9a\u4e8b\u4ef6\u540e\u603b\u662f\u88ab\u5524\u9192\u3002
\u7b49\u5f85\u961f\u5217\u7684\u64cd\u4f5c\u6bd4\u8f83\u590d\u6742\uff0c\u8fd9\u91cc\u4e0d\u8be6\u7ec6\u5c55\u5f00\uff0c\u53ea\u8bb2\u4e00\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u51fd\u6570sleep_on()
\uff1a\u8fd9\u4e2a\u51fd\u6570\u5c06\u5f53\u524d\u8fdb\u7a0b\u52a0\u5165\u7b49\u5f85\u961f\u5217\uff0c\u5e76\u542f\u52a8\u8c03\u5ea6\u7a0b\u5e8f\u3002
void sleep_on(wait_queue_head_t *wq)\n{\n wait_queue_t wait; //\u58f0\u660e\u4e00\u4e2a\u7b49\u5f85\u961f\u5217\u5143\u7d20\n init_waiqueue_entry(&wait, current); //\u5c06current\u5f53\u524d\u8fdb\u7a0b\u52a0\u5165\u5230wait\u4e2d\n current->state = TAKS_UNINTERRUPTIBLE; //\u8bbe\u7f6e\u5f53\u524d\u8fdb\u7a0b\u4e3a\u6df1\u5ea6\u7761\u7720\u6001\n add_wait_queue(wq, &wait); //\u5c06wait\u52a0\u5165\u5230\u7b49\u5f85\u961f\u5217wq\u4e2d\n schedule(); //\u542f\u52a8\u8c03\u5ea6\u7a0b\u5e8f\n remove_wait_queue(wq, &wait); //\u628a\u5f53\u524d\u8fdb\u7a0b\u4ece\u7b49\u5f85\u961f\u5217\u4e2d\u5220\u9664\n}\n
\u6ce8\u610f\uff1a\u5728\u542f\u52a8\u8c03\u5ea6\u7a0b\u5e8f\u4e4b\u524d\uff0c\u8c03\u5ea6\u5668\u4f1a\u8bb0\u5f55\u5f53\u524d\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u5e76\u4fdd\u5b58\u81f3\u5bc4\u5b58\u5668\u4e2d\uff0c\u5f53\u8be5\u7761\u7720\u8fdb\u7a0b\u88ab\u5524\u9192\u65f6\uff0c\u8c03\u5ea6\u7a0b\u5e8f\u4ecesleep_on()
\u51fd\u6570\u4e4b\u524d\u505c\u6b62\u7684\u4f4d\u7f6e\u7ee7\u7eed\u6267\u884c\u2014\u2014\u628a\u8be5\u8fdb\u7a0b\u4ece\u7b49\u5f85\u961f\u5217\u5220\u9664\u3002
"},{"location":"linux/kernel/sched/#_14","title":"\u8fdb\u7a0b\u751f\u547d\u5468\u671f","text":"\u8fd9\u91cc\u7ed9\u51fa\u4e00\u5f20\u793a\u610f\u56fe\u65b9\u4fbf\u7406\u89e3\u3002
"},{"location":"linux/kernel/sched/#_15","title":"\u8fdb\u7a0b\u521b\u5efa","text":"Linux\u7684\u8fdb\u7a0b\u521b\u5efa\u6d89\u53ca\u5230\u4e24\u4e2a\u51fd\u6570\uff1afork()
\u548cexec()
\u3002fork()
\u62f7\u8d1d\u5f53\u524d\u8fdb\u7a0b\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u3002exec()
\u8d1f\u8d23\u8bfb\u53d6\u53ef\u6267\u884c\u6587\u4ef6\u5e76\u5c06\u5176\u8f7d\u5165\u5730\u5740\u7a7a\u95f4\u5f00\u59cb\u8fd0\u884c\u3002
Linux\u7684fork()
\u4f7f\u7528\u4e86\u5199\u65f6\u62f7\u8d1d\uff08copy-on-write\uff09\u673a\u5236\u3002\u8fd9\u610f\u5473\u7740\u5728\u521b\u5efa\u8fdb\u7a0b\u65f6\uff0c\u5185\u6838\u5e76\u4e0d\u590d\u5236\u6574\u4e2a\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\uff0c\u800c\u662f\u8ba9\u7236\u5b50\u8fdb\u7a0b\u5171\u4eab\u3002\u53ea\u6709\u5728\u9700\u8981\u5199\u5165\u65f6\uff0c\u6570\u636e\u624d\u4f1a\u88ab\u590d\u5236\uff0c\u4ece\u800c\u4f7f\u5f97\u5404\u4e2a\u8fdb\u7a0b\u62e5\u6709\u81ea\u5df1\u7684\u5730\u5740\u7a7a\u95f4\u3002\u8fd9\u79cd\u4f18\u5316\u53ef\u4ee5\u907f\u514d\u5927\u91cf\u6839\u672c\u5c31\u4e0d\u4f1a\u88ab\u4f7f\u7528\u7684\u6570\u636e\uff0c\u4ece\u800c\u4f7f\u5f97\u8fdb\u7a0b\u7684\u521b\u5efa\u975e\u5e38\u8fc5\u901f\u3002
fork()
\u51fd\u6570\u7531clone()
\u7cfb\u7edf\u8c03\u7528\u5b9e\u73b0\u3002\u8be5\u7cfb\u7edf\u8c03\u7528\u901a\u8fc7\u4e00\u7cfb\u5217CLONE_FLAGS\u53c2\u6570\u6765\u6307\u660e\u7236\u5b50\u8fdb\u7a0b\u9700\u8981\u5171\u4eab\u7684\u8d44\u6e90\u3002Linux\u4e2d\u8fdb\u7a0b\u4e0e\u7ebf\u7a0b\u7684\u533a\u522b\u4e3b\u8981\u662f\u5728\u6267\u884cclone()
\u7cfb\u7edf\u8c03\u7528\u65f6\u6307\u5b9a\u7684\u5171\u4eab\u8d44\u6e90\u6709\u6240\u4e0d\u540c\u800c\u5df2\u3002\u7ebf\u7a0b\u5728\u521b\u5efa\u65f6\u4f20\u9012\u7684\u53c2\u6570\u5982\u4e0b\uff1a
clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);\n
\u4e0a\u8ff0\u4ee3\u7801\u6307\u660e\u4e86\u521b\u5efa\u7ebf\u7a0b\u65f6\u9700\u8981\u5171\u4eab\u5730\u5740\u7a7a\u95f4\u3001\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u3002
\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u4e00\u4e2a\u666e\u901a\u7684fork()
\u7684\u5b9e\u73b0\uff1a
clone(SIGCHLD, 0);\n
"},{"location":"linux/kernel/sched/#_16","title":"\u8fdb\u7a0b\u7ec8\u7ed3","text":"\u4e00\u4e2a\u8fdb\u7a0b\u7ec8\u7ed3\u65f6\uff0c\u5185\u6838\u5fc5\u987b\u91ca\u653e\u5b83\u6240\u5360\u7528\u7684\u8d44\u6e90\u5e76\u4e14\u544a\u77e5\u7236\u8fdb\u7a0b\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u8fdb\u7a0b\u7684\u7ec8\u7ed3\u662f\u81ea\u8eab\u5f15\u8d77\u7684\uff0c\u4e5f\u53ef\u80fd\u662f\u63a5\u6536\u4e86\u4e00\u4e2a\u4e0d\u53ef\u5ffd\u7565\u7684\u4fe1\u53f7\u6216\u8005\u662f\u5f02\u5e38\u3002
\u5f53\u8fdb\u7a0b\u76f8\u5173\u8054\u7684\u6240\u6709\u8d44\u6e90\u90fd\u88ab\u91ca\u653e\u540e\uff0c\u5b83\u5904\u4e8eEXIT_ZOMBIE\u72b6\u6001\u3002\u8be5\u72b6\u6001\u4e5f\u88ab\u79f0\u4e3a\u50f5\u6b7b\u72b6\u6001\uff0c\u5b83\u7684\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u88ab\u4fdd\u7559\uff0c\u7b49\u5f85\u7236\u8fdb\u7a0b\u4f7f\u7528wait()
\u7cfb\u5217\u51fd\u6570\u56de\u6536\u3002
\u4f46\u662f\uff0c\u5982\u679c\u7236\u8fdb\u7a0b\u5728\u5b50\u8fdb\u7a0b\u4e4b\u524d\u5c31\u9000\u51fa\u4e86\uff0c\u90a3\u4e48\u5fc5\u987b\u6709\u4e00\u4e2a\u673a\u5236\u6765\u4fdd\u8bc1\u5b50\u8fdb\u7a0b\u627e\u5230\u4e00\u4e2a\u65b0\u7684\u7236\u8fdb\u7a0b\uff0c\u5426\u5219\u8fd9\u4e9b\u5b64\u513f\u8fdb\u7a0b\u4f1a\u6c38\u8fdc\u5904\u4e8e\u50f5\u6b7b\u72b6\u6001\uff0c\u767d\u767d\u8017\u8d39\u5185\u5b58\u3002\u5185\u6838\u7684\u89e3\u51b3\u529e\u6cd5\u662f\u5728\u5f53\u524d\u7ebf\u7a0b\u7ec4\u5185\u627e\u4e00\u4e2a\u7ebf\u7a0b\u4f5c\u4e3a\u7236\u8fdb\u7a0b\uff0c\u5982\u679c\u4e0d\u884c\uff0c\u5c31\u8ba9init\u8fdb\u7a0b\u505a\u7236\u8fdb\u7a0b\u3002
"},{"location":"linux/kernel/sched/#_17","title":"\u8fdb\u7a0b\u5207\u6362","text":"\u4e3a\u4e86\u63a7\u5236\u8fdb\u7a0b\u7684\u8fd0\u884c\uff0c\u5185\u6838\u5fc5\u987b\u6709\u80fd\u529b\u6302\u8d77\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u6216\u8005\u6062\u590d\u4ee5\u524d\u6302\u8d77\u7684\u8fdb\u7a0b\u3002\u8fd9\u79cd\u884c\u4e3a\u88ab\u79f0\u4e3a\u8fdb\u7a0b\u5207\u6362\uff08process switch\uff09\u6216\u4e0a\u4e0b\u6587\u5207\u6362\uff08context switch\uff09\u3002\u7406\u89e3\u4e86\u8fdb\u7a0b\u5207\u6362\uff0c\u624d\u6709\u53ef\u80fd\u7406\u89e3\u5185\u6838\u662f\u5982\u4f55\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u8c03\u5ea6\u7684\u3002
"},{"location":"linux/kernel/sched/#_18","title":"\u786c\u4ef6\u4e0a\u4e0b\u6587","text":"\u5c3d\u7ba1\u6bcf\u4e2a\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\uff0c\u4f46\u6240\u6709\u8fdb\u7a0b\u90fd\u5171\u4eabCPU\u7684\u5bc4\u5b58\u5668\uff0c\u56e0\u6b64\u5728\u6062\u590d\u4e00\u4e2a\u8fdb\u7a0b\u6267\u884c\u4e4b\u524d\uff0c\u5185\u6838\u5fc5\u987b\u4fdd\u8bc1\u5bc4\u5b58\u5668\u88c5\u5165\u4e86\u6302\u8d77\u8fdb\u7a0b\u65f6\u7684\u503c\u3002\u8fdb\u7a0b\u6062\u590d\u6267\u884c\u524d\u5fc5\u987b\u88c5\u5165\u5bc4\u5b58\u5668\u7684\u4e00\u7ec4\u6570\u636e\u79f0\u4e3a\u786c\u4ef6\u4e0a\u4e0b\u6587\uff08hardware context\uff09\u3002\u786c\u4ef6\u4e0a\u4e0b\u6587\u662f\u8fdb\u7a0b\u6267\u884c\u4e0a\u4e0b\u6587\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u56e0\u4e3a\u6267\u884c\u4e0a\u4e0b\u6587\u5305\u542b\u8fdb\u7a0b\u6267\u884c\u9700\u8981\u7684\u6240\u6709\u4fe1\u606f\u3002
"},{"location":"linux/kernel/sched/#thread","title":"thread\u5b57\u6bb5","text":"\u6bcf\u4e2a\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u5305\u542b\u4e00\u4e2a\u7c7b\u578b\u4e3athread_struct\u7684thread\u5b57\u6bb5\uff0c\u53ea\u8981\u8fdb\u7a0b\u88ab\u5207\u6362\u51fa\u53bb\uff0c\u5185\u6838\u5c31\u628a\u5176\u786c\u4ef6\u4e0a\u4e0b\u6587\u4fdd\u5b58\u5728\u8fd9\u4e2a\u7ed3\u6784\u4e2d\u3002\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u5305\u542b\u4e86\u5927\u91cfCPU\u5bc4\u5b58\u5668\u4fe1\u606f\u3002
"},{"location":"linux/kernel/sched/#_19","title":"\u6267\u884c\u8fdb\u7a0b\u5207\u6362","text":"\u8fdb\u7a0b\u5207\u6362\u53ea\u4f1a\u53d1\u751f\u5728\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\uff1a
\u4e3b\u52a8\u653e\u5f03CPU\uff0c\u8c03\u7528schedule()
\u51fd\u6570\u3002 \u6b63\u5728\u8fd0\u884c\u65f6\uff0c\u88ab\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u62a2\u5360\u3002 \u4ece\u672c\u8d28\u4e0a\u6765\u8bf4\uff0c\u8fdb\u7a0b\u5207\u6362\u6709\u4e24\u4e2a\u6b65\u9aa4\uff1a
\u5207\u6362\u9875\u5168\u5c40\u76ee\u5f55\u4ee5\u5b89\u88c5\u4e00\u4e2a\u65b0\u7684\u5730\u5740\u7a7a\u95f4\u3002 \u5207\u6362\u5185\u6838\u6001\u5806\u6808\u548c\u786c\u4ef6\u4e0a\u4e0b\u6587\u3002 \u8fdb\u7a0b\u5207\u6362\u7531switch_to
\u5b8f\u6267\u884c\u3002\u8be5\u5b8f\u5b9a\u4e49\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\u3002
"},{"location":"linux/kernel/sched/#_20","title":"\u8fdb\u7a0b\u8c03\u5ea6\u7b97\u6cd5","text":""},{"location":"linux/kernel/synch/","title":"\u5185\u6838\u540c\u6b65","text":"\u53ea\u8981\u6709\u5171\u4eab\u8d44\u6e90\u7684\u5730\u65b9\uff0c\u7a0b\u5e8f\u5458\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u5c31\u9700\u8981\u7279\u522b\u6ce8\u610f\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\uff0c\u9632\u6b62\u5e76\u53d1\u8bbf\u95ee\u65f6\u9020\u6210\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u591a\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u8bbf\u95ee\u5171\u4eab\u6570\u636e\u662f\u9020\u6210\u7cfb\u7edf\u4e0d\u7a33\u5b9a\u7684\u4e00\u7c7b\u9690\u60a3\uff0c\u800c\u8fd9\u7c7b\u9690\u60a3\u5f80\u5f80\u96be\u4ee5\u8ddf\u8e2a\u548c\u8c03\u8bd5\u3002\u8981\u505a\u5230\u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u4fdd\u62a4\u76f8\u5f53\u56f0\u96be\u3002\u65e9\u5e74\uff0cLinux\u8fd8\u4e0d\u652f\u6301SMP\uff08\u5bf9\u79f0\u591a\u5904\u7406\u5668\uff09\uff0c\u907f\u514d\u5e76\u53d1\u8bbf\u95ee\u6570\u636e\u8fd8\u6bd4\u8f83\u5bb9\u6613\u3002\u5728\u5355\u4e00\u5904\u7406\u5668\u65f6\uff0c\u53ea\u6709\u5728\u4e2d\u65ad\u53d1\u751f\u7684\u65f6\u5019\uff0c\u6216\u8005\u7a0b\u5e8f\u660e\u786e\u8bf7\u6c42\u91cd\u65b0\u8c03\u5ea6\uff08scheduler\uff09\u7684\u65f6\u5019\uff0c\u6570\u636e\u624d\u6709\u53ef\u80fd\u88ab\u5e76\u53d1\u8bbf\u95ee\u3002\u4e8e\u662f\u5728\u65e9\u671f\u7684\u5355CPU\u67b6\u6784\u4e0b\uff0c\u7b80\u5355\u7684\u7981\u6b62\u4e2d\u65ad\u5373\u53ef\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u3002\u4f46\u662f\u591a\u5904\u7406\u5668\u65f6\u4ee3\u8fd9\u4e00\u65b9\u6cd5\u4e0d\u518d\u6709\u6548\u4e86\uff0c\u56e0\u4e3a\u7981\u6b62\u4e2d\u65ad\u53ea\u80fd\u7981\u6b62\u672c\u5730\u7684\u4e2d\u65ad\uff0c\u4f46\u662f\u65e0\u6cd5\u963b\u6b62\u5176\u4ed6CPU\u5e76\u53d1\u5730\u8bbf\u95ee\u6570\u636e\u3002\u968f\u77402.6\u5185\u6838\u7248\u672c\u7684\u51fa\u73b0\uff0cLinux\u5185\u6838\u5df2\u7ecf\u53d1\u5c55\u6210\u62a2\u5360\u5f0f\u5185\u6838\u3002\u8fd9\u610f\u5473\u7740\u8c03\u5ea6\u7a0b\u5e8f\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u523b\u62a2\u5360\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\uff0c\u91cd\u65b0\u8c03\u5ea6\u5176\u4ed6\u7684\u8fdb\u7a0b\u6267\u884c\uff0c\u8fd9\u5bf9\u6570\u636e\u7684\u540c\u6b65\u63d0\u51fa\u4e86\u66f4\u9ad8\u7684\u8981\u6c42\u3002\u5177\u4f53\u8bf7\u770b\u8fdb\u7a0b\u8c03\u5ea6\u3002
\u5185\u6838\u4e2d\u5e76\u53d1\u6267\u884c\u7684\u539f\u56e0\u6709\uff1a
\u4e2d\u65ad\u2014\u2014\u4e2d\u65ad\u662f\u5f02\u6b65\u7684\uff0c\u51e0\u4e4e\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u523b\u53d1\u751f\uff0c\u4e5f\u5c31\u6709\u53ef\u80fd\u5728\u4efb\u4f55\u65f6\u523b\u6253\u65ad\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\u3002 \u8f6f\u4e2d\u65ad\u548ctasklet\u2014\u2014\u5185\u6838\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u523b\u5524\u9192\u6216\u8c03\u5ea6\u8f6f\u4e2d\u65ad\u548ctasklet\u3002 \u62a2\u5360\u2014\u2014\u5185\u6838\u662f\u62a2\u5360\u6027\u8d28\u7684\uff0c\u6b63\u5728\u6267\u884c\u7684\u4efb\u52a1\u53ef\u80fd\u4f1a\u88ab\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u62a2\u5360\u3002 \u7761\u7720\u2014\u2014\u5728\u5185\u6838\u6267\u884c\u7684\u8fdb\u7a0b\u53ef\u80fd\u7761\u7720\uff0c\u8fd9\u4f1a\u5524\u9192\u8c03\u5ea6\u7a0b\u5e8f\uff0c\u4ece\u800c\u8c03\u5ea6\u53e6\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u3002 SMP\u2014\u2014\u591a\u4e2aCPU\u53ef\u4ee5\u540c\u65f6\u6267\u884c\u4ee3\u7801\u3002 "},{"location":"linux/kernel/synch/#_2","title":"\u540c\u6b65\u7684\u6982\u5ff5","text":""},{"location":"linux/kernel/synch/#_3","title":"\u4e34\u754c\u533a","text":"\u6240\u8c13\u4e34\u754c\u533a\u5c31\u662f\u8bbf\u95ee\u548c\u64cd\u4f5c\u5171\u4eab\u6570\u636e\u7684\u4ee3\u7801\u6bb5\u3002\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u4e34\u754c\u533a\u4ee3\u7801\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u56e0\u6b64\u4e34\u754c\u533a\u4ee3\u7801\u5fc5\u987b\u4ee5\u539f\u5b50\u5730\u65b9\u5f0f\u6267\u884c\u3002\u8003\u8651\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u60c5\u51b5\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5168\u5c40\u53d8\u91cfi\uff0c\u64cd\u4f5c\u4ec5\u4ec5\u662f\u5bf9\u5176\u52a01\u3002
i++;\n
\u5982\u6b64\u7b80\u5355\u7684\u64cd\u4f5c\u5728CPU\u6267\u884c\u7684\u65f6\u5019\u9700\u8981\u4e09\u6761\u6c47\u7f16\u6307\u4ee4\uff1a
\u4ece\u5185\u5b58\u4e2d\u8bfb\u51fa\u53d8\u91cfi\u7684\u503c\u5e76\u653e\u5728\u4e00\u4e2a\u5bc4\u5b58\u5668\u5185\u3002 \u5c06\u5bc4\u5b58\u5668\u4e2d\u7684\u503c+1\u3002 \u628ai\u7684\u503c\u5199\u56de\u5230\u5185\u5b58\u3002 \u5b9e\u9645\u4e0a\uff0c\u5728\u591a\u7ebf\u7a0b\u5e76\u53d1\u7684\u60c5\u51b5\u4e0b\uff0c\u5176\u4ed6\u7ebf\u7a0b\u6709\u53ef\u80fd\u5728\u8fd9\u4e09\u6761\u6307\u4ee4\u95f4\u9699\u7684\u4efb\u610f\u65f6\u523b\u201c\u63d2\u961f\u201d\u3002\u8fd9\u79cd\u6982\u7387\u867d\u7136\u5f88\u5c0f\uff0c\u4f46\u662f\u8ba1\u7b97\u673a\u6bcf\u79d2\u8fd0\u884c\u4e0a\u767e\u4e07\u6761\u6307\u4ee4\uff0c\u201c\u63d2\u961f\u201d\u53ef\u80fd\u6bcf\u8fc7\u51e0\u79d2\u5c31\u53d1\u751f\u4e00\u6b21\u3002\u5047\u8bbe\u6709\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u64cd\u4f5c\u8fd9\u4e2a\u5168\u5c40\u53d8\u91cf\uff0c\u82e5i\u7684\u521d\u59cb\u503c\u4e3a1\uff0c\u90a3\u4e48\u6211\u4eec\u671f\u671b\u7684\u6700\u7ec8\u7ed3\u679c\u5e94\u8be5\u662f3\u3002\u4f46\u662f\u5047\u5982\u7b2c\u4e8c\u4e2a\u7ebf\u7a0b\u5728\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u6700\u540e\u4e00\u6b65\u4e4b\u524d\u5c31\u53bb\u5185\u5b58\u4e2d\u8bfb\u53d6\u4e86i\u7684\u503c\uff08\u6b64\u65f6i\u7684\u503c\u4ecd\u7136\u662f1\uff09\uff0c\u6211\u4eec\u6700\u540e\u5f97\u5230\u7684i\u7684\u503c\u5c31\u662f2\u800c\u4e0d\u662f3\uff0c\u8fd9\u4e0e\u6211\u4eec\u9884\u671f\u7684\u503c\u4e0d\u7b26\u3002
#include <stdio.h>\n#include <pthread.h>\n\nint i = 0;\n\nvoid *thread_func(void *arg)\n{\n for(int j = 0 ;j < 1000000; j++)\n {\n i++;\n }\n\n}\n\nint main(int argc, char *argv[])\n{\n\n pthread_t tid1, tid2;\n pthread_create(&tid1, NULL, thread_func, NULL);\n pthread_create(&tid2, NULL, thread_func, NULL);\n\n pthread_join(tid1, NULL);\n pthread_join(tid2, NULL);\n\n printf(\"i = %d\\n\", i);\n return 0;\n}\n
\u4ee5\u4e0a\u662f\u4e00\u6bb5\u793a\u4f8b\u4ee3\u7801\uff0c\u5728\u7f16\u8bd1\u65f6\u8bf7\u52a0\u4e0a-lpthread\uff0c\u4ee5\u94fe\u63a5\u6b63\u786e\u7684\u5e93\u3002\u591a\u6b21\u6267\u884c\u8be5\u7a0b\u5e8f\u540e\u4f60\u4f1a\u53d1\u73b0\u6700\u7ec8\u7684\u7ed3\u679c\u662f\u4e0d\u786e\u5b9a\u7684\u3002
\u8fd9\u662f\u6700\u7b80\u5355\u7684\u4e34\u754c\u533a\u4f8b\u5b50\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u7b80\u5355\u7684\u7ade\u4e89\u6761\u4ef6\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u7528\u5230\u590d\u6742\u7684\u9501\u673a\u5236\uff0c\u56e0\u4e3a\u9501\u5bf9\u4e8eCPU\u7684\u6027\u80fd\u6709\u5f88\u5927\u7684\u5f71\u54cd\u3002\u591a\u6570\u5904\u7406\u5668\u90fd\u63d0\u4f9b\u4e86\u6307\u4ee4\u6765\u539f\u5b50\u5730\u8bfb\u3001\u5199\u53d8\u91cf\u3002\u6211\u4eec\u79f0\u4e4b\u4e3a\u539f\u5b50\u6307\u4ee4\u3002\u4f7f\u7528\u539f\u5b50\u6307\u4ee4\u53ef\u4ee5\u89e3\u51b3\u4e00\u4e9b\u7b80\u5355\u7684\u5e76\u53d1\u95ee\u9898\u3002\u4e24\u6761\u539f\u5b50\u6307\u4ee4\u4e0d\u53ef\u80fd\u4ea4\u9519\u6267\u884c\uff0c\u56e0\u4e3a\u5904\u7406\u5668\u4f1a\u4ece\u786c\u4ef6\u4e0a\u7981\u6b62\u8fd9\u79cd\u53ef\u80fd\u6027\u3002
"},{"location":"linux/kernel/synch/#_4","title":"\u52a0\u9501","text":"\u5f53\u5171\u4eab\u8d44\u6e90\u662f\u4e00\u4e2a\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u800c\u4e0d\u662f\u7b80\u5355\u7684i++\u65f6\uff0c\u539f\u5b50\u6307\u4ee4\u5c31\u65e0\u80fd\u4e3a\u529b\u4e86\u3002\u6b64\u65f6\u6211\u4eec\u5fc5\u987b\u5f15\u5165\u9501\u673a\u5236\u6765\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u7684\u8bbf\u95ee\u3002\u540c\u4e00\u65f6\u523b\uff0c\u6211\u4eec\u53ea\u5141\u8bb8\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\u9501\uff0c\u5176\u4ed6\u7ebf\u7a0b\u7684\u8bbf\u95ee\u5fc5\u987b\u7b49\u5f85\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\u4e4b\u540e\u624d\u80fd\u8fdb\u884c\u3002\u9501\u6709\u591a\u79cd\u591a\u6837\u7684\u5f62\u5f0f\uff0c\u9501\u7684\u7c92\u5ea6\u4e5f\u5404\u4e0d\u76f8\u540c\u3002Linux\u5185\u6838\u63d0\u4f9b\u4e86\u591a\u79cd\u4e0d\u540c\u7684\u9501\u673a\u5236\uff0c\u4ed6\u4eec\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\uff1a\u5f53\u9501\u88ab\u5176\u4ed6\u7ebf\u7a0b\u6301\u6709\u800c\u4e0d\u53ef\u7528\u65f6\u7684\u8868\u73b0\u5f62\u5f0f\u2014\u2014\u6709\u4e00\u4e9b\u9501\u4f1a\u5728\u539f\u5730\u7b49\u5f85\uff0c\u800c\u6709\u4e00\u4e9b\u9501\u4f1a\u76f4\u63a5\u7761\u7720\u3002\u9501\u6ca1\u6709\u4f18\u52a3\u4e4b\u5206\uff0c\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7528\u4e0d\u540c\u7684\u9501\u662f\u7a0b\u5e8f\u5458\u5fc5\u5907\u7684\u6280\u80fd\u3002
\u5f53\u4e00\u4e2a\u9501\u6b63\u5728\u88ab\u5360\u7528\u65f6\uff0c\u6709\u5176\u4ed6\u7ebf\u7a0b\u8bd5\u56fe\u83b7\u5f97\u8be5\u9501\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a\u9501\u7684\u4e89\u7528\u3002\u7531\u4e8e\u9501\u662f\u8ba9\u7a0b\u5e8f\u4ee5\u4e32\u884c\u7684\u65b9\u5f0f\u5bf9\u8d44\u6e90\u8fdb\u884c\u8bbf\u95ee\uff0c\u88ab\u957f\u65f6\u95f4\u6301\u6709\u7684\u9501\u65e0\u7591\u4f1a\u964d\u4f4e\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u4e8e\u662f\u52a0\u9501\u7c92\u5ea6\u5c31\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u5982\u679c\u662f\u4e00\u6bb5\u52a0\u9501\u7684\u4ee3\u7801\u88ab\u9891\u7e41\u7684\u8c03\u7528\uff0c\u8fd9\u5f80\u5f80\u4f1a\u6210\u4e3a\u7cfb\u7edf\u6027\u80fd\u7684\u74f6\u9888\u3002\u5728\u4e00\u4e9b\u5927\u578b\u673a\u5668\u4e0a\u53ef\u80fd\u8868\u73b0\u4e0d\u662f\u90a3\u4e48\u660e\u663e\uff0c\u4f46\u662f\u5728\u4e00\u4e9b\u5c0f\u578b\u673a\u5668\u4e0a\uff0c\u8fc7\u7c97\u7684\u9501\u7684\u7c92\u5ea6\u4f1a\u4e25\u91cd\u62d6\u7d2f\u7cfb\u7edf\u7684\u6027\u80fd\u3002
"},{"location":"linux/kernel/synch/#_5","title":"\u6b7b\u9501","text":"\u6b7b\u9501\u662f\u7f16\u5199\u540c\u6b65\u4ee3\u7801\u65f6\u7ecf\u5e38\u4f1a\u9047\u5230\u7684\u95ee\u9898\uff0c\u4e24\u4e2a\u6216\u591a\u4e2a\u7ebf\u7a0b\u56e0\u4e3a\u4e89\u593a\u8d44\u6e90\u800c\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u5728\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\u6216\u8d44\u6e90\u3002\u5982\u679c\u6ca1\u6709\u5916\u529b\u5e72\u6d89\uff0c\u8fd9\u4e9b\u7ebf\u7a0b\u5c06\u6c38\u8fdc\u5904\u4e8e\u7b49\u5f85\u72b6\u6001\u3002
\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u6b7b\u9501\u4f8b\u5b50\u5c31\u662f\u81ea\u6b7b\u9501\uff1a\u5982\u679c\u4e00\u4e2a\u7ebf\u7a0b\u8bd5\u56fe\u53bb\u83b7\u5f97\u4e00\u4e2a\u81ea\u5df1\u5df2\u7ecf\u6301\u6709\u7684\u9501\uff0c\u90a3\u4e48\u5b83\u5c06\u6c38\u8fdc\u7b49\u5f85\u4e0b\u53bb\u3002 \u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u4f8b\u5b50\u53ebABBA\u6b7b\u9501\uff1a\u7ebf\u7a0b1\u6301\u6709\u9501A\uff0c\u7ebf\u7a0b2\u6301\u6709\u9501B\uff0c\u7ebf\u7a0b1\u8bd5\u56fe\u53bb\u83b7\u5f97\u9501B\uff0c\u800c\u7ebf\u7a0b2\u8bd5\u56fe\u53bb\u83b7\u5f97\u9501A\uff0c\u7531\u4e8e\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u5728\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\uff0c\u4f46\u662f\u8c01\u90fd\u4e0d\u60f3\u91ca\u653e\u81ea\u5df1\u7684\u9501\uff0c\u4e8e\u662f\u5c31\u9020\u6210\u4e86\u6b7b\u9501\u3002\u9884\u9632\u6b7b\u9501\u7684\u53d1\u751f\u975e\u5e38\u91cd\u8981\uff0c\u867d\u7136\u4f60\u4e0d\u77e5\u9053\u81ea\u5df1\u7684\u4ee3\u7801\u4f1a\u4e0d\u4f1a\u53d1\u751f\u6b7b\u9501\uff0c\u4f46\u662f\u9075\u5faa\u4e00\u4e9b\u7b80\u5355\u7684\u89c4\u5219\u5bf9\u4e8e\u907f\u514d\u6b7b\u9501\u5927\u6709\u5e2e\u52a9\uff1a
\u6309\u987a\u5e8f\u52a0\u9501\u3002\u4f7f\u7528\u591a\u4e2a\u9501\u65f6\u5fc5\u987b\u4fdd\u8bc1\u4ee5\u76f8\u540c\u7684\u987a\u5e8f\u83b7\u53d6\u9501\uff0c\u5426\u5219\u5c31\u6709\u53ef\u80fd\u9020\u6210ABBA\u6b7b\u9501\u3002 \u9632\u6b62\u9965\u997f\u3002 \u4e0d\u8981\u91cd\u590d\u8bf7\u6c42\u540c\u4e00\u4e2a\u9501\u3002 \u8bbe\u8ba1\u8d8a\u7b80\u5355\u8d8a\u597d\u3002 "},{"location":"linux/kernel/synch/#_6","title":"\u540c\u6b65\u7684\u65b9\u6cd5","text":""},{"location":"linux/kernel/synch/#_7","title":"\u539f\u5b50\u64cd\u4f5c","text":"\u539f\u5b50\u64cd\u4f5c\u53ef\u4ee5\u4fdd\u8bc1\u6307\u4ee4\u4ee5\u4e0d\u53ef\u5206\u5272\u7684\u5f62\u5f0f\u6267\u884c\u2014\u2014\u2014\u2014\u6267\u884c\u8fc7\u7a0b\u4e0d\u53ef\u88ab\u6253\u65ad\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u4e24\u7ec4\u539f\u5b50\u64cd\u4f5c\u63a5\u53e3\u2014\u2014\u2014\u2014\u4e00\u7ec4\u9488\u5bf9\u6574\u6570\uff0c\u4e00\u7ec4\u9488\u5bf9\u5355\u72ec\u7684\u4f4d\u3002\u5728Linux\u652f\u6301\u7684\u6240\u6709\u4f53\u7cfb\u7ed3\u6784\u4e0a\u90fd\u5b9e\u73b0\u4e86\u8fd9\u4e24\u7ec4\u63a5\u53e3\u3002\u867d\u7136\u5728\u4e0d\u540c\u4f53\u7cfb\u7ed3\u6784\u4e0a\u5b9e\u73b0\u7684\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\uff0c\u4f46\u662f\u63a5\u53e3\u90fd\u662f\u7edf\u4e00\u7684\u3002
\u6709\u7684\u65f6\u5019\u6211\u4eec\u4f1a\u8981\u6c42\u67d0\u4e9b\u6307\u4ee4\u6309\u7167\u7279\u5b9a\u7684\u987a\u5e8f\u6267\u884c\uff0c\u8fd9\u88ab\u79f0\u4e3a\u987a\u5e8f\u6027\uff0c\u4ee5\u5c4f\u969c\uff08barrier\uff09\u6307\u4ee4\u6765\u5b9e\u73b0\u3002
1.\u539f\u5b50\u6574\u6570\u64cd\u4f5c
\u9488\u5bf9\u6574\u6570\u7684\u539f\u5b50\u64cd\u4f5c\u4f7f\u7528\u4e00\u4e2a\u7279\u6b8a\u7684atomic_t
\u7c7b\u578b\u7684\u6570\u636e\u3002\u5b83\u7684\u5b9a\u4e49\u5728<linux/types.h>\u4e2d\uff1a
typedef struct{\n volatile int counter;\n}atomic_t;\n
\u4f7f\u7528\u539f\u5b50\u6574\u6570\u64cd\u4f5c\u7684\u58f0\u660e\u5728<asm/atomic.h>\u4e2d\u5b9a\u4e49\u3002\u6709\u4e9b\u4f53\u7cfb\u7ed3\u6784\u4f1a\u63d0\u4f9b\u4e00\u4e9b\u989d\u5916\u7684\u539f\u5b50\u64cd\u4f5c\uff0c\u4f46\u662f\u5185\u6838\u7684\u63a5\u53e3\u5728\u6240\u6709\u4f53\u7cfb\u7ed3\u6784\u4e0a\u90fd\u5b9e\u73b0\u4e86\u3002
\u4e00\u4e9b\u7b80\u5355\u7684\u64cd\u4f5c\u6bd4\u5982\uff1a
atomic_t v; //\u5b9a\u4e49v\natomic_t u = ATOMIC_INIT(0); //\u5b9a\u4e49u\u5e76\u521d\u59cb\u5316\u4e3a0\natomic_set(&v, 4); //\u8bbe\u7f6ev\u7684\u503c\u4e3a4\natomic_add(2, &v); //\u5c06v\u7684\u503c\u589e\u52a02\nint w = atomic_read(&v); //\u5c06\u539f\u5b50\u53d8\u91cfv\u8f6c\u53d8\u4e3aint\u53d8\u91cf\n
\u539f\u5b50\u64cd\u4f5c\u7684\u63a5\u53e3\u975e\u5e38\u7b80\u5355\u6613\u8bfb\uff0c\u6ca1\u6709\u5fc5\u8981\u5355\u72ec\u53bb\u8bb0\uff0c\u7528\u5230\u4ec0\u4e48\u5c31\u5b66\u4ec0\u4e48\u3002
\u539f\u5b50\u64cd\u4f5c\u901a\u5e38\u662f\u5185\u8054\u51fd\u6570\uff0c\u4e14\u662f\u7528\u5185\u5d4c\u6c47\u7f16\u6307\u4ee4\u6765\u5b9e\u73b0\u7684\u3002ARM\u4f53\u7cfb\u8bf7\u53c2\u8003\uff1aARM GCC Inline Assembler\u3002
atomic64_t
\u7c7b\u578b\u662f64\u4f4d\u7684\u539f\u5b50\u53d8\u91cf\uff0c\u5176\u529f\u80fd\u548c32\u4f4d\u4e00\u81f4\uff0c\u51fd\u6570\u63a5\u53e3\u4ee5atomic64\u524d\u7f00\u547d\u540d\u3002
typedef struct {\n volatile long counter;\n}atomic64_t;\n
2.\u539f\u5b50\u4f4d\u64cd\u4f5c
atomic_t
\u7c7b\u578b\u5bf9\u6574\u6570\u7b97\u672f\u6765\u8bb2\u6bd4\u8f83\u6709\u7528\u3002\u4f46\u662f\u5f53\u9700\u8981\u4ee5\u539f\u5b50\u5f62\u5f0f\u6765\u64cd\u4f5c\u5355\u4e2a\u7684\u4f4d\u65f6\uff0c\u8fd9\u79cd\u7c7b\u578b\u5c31\u65e0\u6cd5\u6d3e\u4e0a\u7528\u573a\u4e86\u3002Linux\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7ec4\u5bf9\u4f4d\u7684\u539f\u5b50\u64cd\u4f5c\u3002
\u539f\u5b50\u4f4d\u7684\u64cd\u4f5c\u975e\u5e38\u5feb\uff0c\u53ea\u8981\u786c\u4ef6\u5e95\u5c42\u786c\u4ef6\u652f\u6301\uff0c\u8fd9\u79cd\u64cd\u4f5c\u53ef\u4ee5\u4f7f\u7528\u5355\u4e2a\u673a\u5668\u6307\u4ee4\u6765\u6267\u884c\u3002\u8fd9\u4e9b\u51fd\u6570\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\uff0c\u5b9a\u4e49\u5728<asm/bitops.h>\u4e2d\u3002\u5373\u4f7f\u662f\u5728SMP\u8ba1\u7b97\u673a\u4e0a\uff0c\u8fd9\u4e9b\u51fd\u6570\u4f9d\u65e7\u53ef\u4ee5\u786e\u4fdd\u662f\u539f\u5b50\u7684\u3002\u539f\u5b50\u4f4d\u7684\u53c2\u6570\u662f\u4e00\u4e2a\u4f4d\u53f7+\u6307\u9488\u3002\u53ef\u7528\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a
void set_bit(nr, void *addr); //\u8bbe\u7f6eaddr\u6307\u5411\u7684\u7b2cnr\u4f4d\nvoid clear_bit(nr, void *addr); //\u6e05\u9664addr\u6307\u5411\u7684\u7b2cnr\u4f4d\nvoid change_bit(nr, void *addr); //\u5207\u6362addr\u6307\u5411\u7684\u7b2cnr\u4f4d\ntest_bit(nr, void *addr); //\u8fd4\u56de\u6307\u5b9a\u4f4d\u7684\u5f53\u524d\u503c\n
"},{"location":"linux/kernel/synch/#_8","title":"\u81ea\u65cb\u9501","text":"\u539f\u5b50\u64cd\u4f5c\u53ea\u80fd\u9488\u5bf9\u4e00\u4e9b\u7b80\u5355\u7684\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u4fdd\u62a4\uff0c\u73b0\u5b9e\u60c5\u51b5\u91cc\uff0c\u4e00\u4e2a\u4e34\u754c\u533a\u91cc\u751a\u81f3\u6709\u591a\u4e2a\u51fd\u6570\u3002\u6bd4\u5982\u6211\u4eec\u6709\u8fd9\u6837\u4e00\u4e2a\u60c5\u51b5\uff1a\u4ece\u67d0\u4e2a\u51fd\u6570\u4e2d\u8bfb\u53d6\u67d0\u4e2astruct\u7c7b\u578b\u7684\u6570\u636e\uff0c\u7136\u540e\u6539\u53d8\u5176\u4e2d\u67d0\u4e2a\u6210\u5458\u7684\u503c\uff0c\u6700\u540e\u518d\u628a\u66f4\u65b0\u7684\u503c\u8d4b\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u3002\u6574\u4e2a\u6267\u884c\u8fc7\u7a0b\u5fc5\u987b\u662f\u4e0d\u53ef\u5206\u5272\u7684\uff0c\u5728\u6570\u636e\u66f4\u65b0\u5b8c\u6bd5\u524d\uff0c\u7edd\u5bf9\u4e0d\u5141\u8bb8\u4efb\u4f55\u5176\u4ed6\u7684\u4ee3\u7801\u8bfb\u53d6\u8fd9\u4e9b\u6570\u636e\u3002\u663e\u7136\uff0c\u6211\u4eec\u4e0d\u53ef\u80fd\u8981\u6c42\u6bcf\u4e2a\u4f53\u7cfb\u90fd\u652f\u6301\u5982\u6b64\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u7528\u5230\u66f4\u590d\u6742\u7684\u540c\u6b65\u65b9\u6cd5\u2014\u2014\u9501\u6765\u63d0\u4f9b\u4fdd\u62a4\u3002
Linux\u5185\u6838\u4e2d\u6700\u5e38\u89c1\u7684\u9501\u662f\u81ea\u65cb\u9501\uff08spin lock\uff09\u3002\u81ea\u65cb\u9501\u53ea\u80fd\u540c\u65f6\u88ab\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\uff0c\u5982\u679c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u8bd5\u56fe\u83b7\u5f97\u4e00\u4e2a\u5df2\u7ecf\u88ab\u5360\u7528\u7684\u81ea\u65cb\u9501\uff0c\u90a3\u4e48\u8be5\u7ebf\u7a0b\u5c06\u4f1a\u8fdb\u5165\u5fd9\u7b49\u5f85\uff0c\u76f4\u5230\u9501\u53ef\u7528\u3002\u901a\u4fd7\u7684\u89e3\u91ca\u5c31\u662f\u4e00\u6247\u95e8\u5bf9\u5e94\u4e00\u628a\u94a5\u5319\uff0c\u8981\u8fdb\u5165\u8fd9\u6247\u95e8\u5fc5\u987b\u5148\u68c0\u67e5\u95e8\u4e0a\u6709\u6ca1\u6709\u94a5\u5319\uff0c\u5982\u679c\u6ca1\u6709\u5c31\u53ea\u80fd\u5728\u5916\u9762\u7b49\u5f85\u76f4\u5230\u91cc\u9762\u7684\u4eba\u51fa\u6765\u3002\u7531\u4e8e\u81ea\u65cb\u4f1a\u4e00\u76f4\u5bfc\u81f4\u7ebf\u7a0b\u5fd9\u7b49\u5f85\uff0c\u767d\u767d\u5360\u7528\u4e86CPU\u8d44\u6e90\u800c\u4e0d\u4f1a\u53bb\u505a\u522b\u7684\u4e8b\u60c5\uff0c\u56e0\u6b64\u7279\u522b\u6d6a\u8d39\u8d44\u6e90\uff0c\u6240\u4ee5\u81ea\u65cb\u9501\u4e0d\u5e94\u8be5\u88ab\u957f\u65f6\u95f4\u5360\u6709\u3002\u4e8b\u5b9e\u4e0a\uff0c\u4f7f\u7528\u81ea\u65cb\u9501\u65f6\u4f60\u5fc5\u987b\u4fdd\u8bc1\u4e34\u754c\u533a\u4ee3\u7801\u6267\u884c\u8db3\u591f\u77ed\uff0c\u5426\u5219\u4f1a\u4e25\u91cd\u5f71\u54cd\u7cfb\u7edf\u7684\u6027\u80fd\u3002
\u81ea\u65cb\u9501\u7684\u5b9e\u73b0\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\uff0c\u4ee3\u7801\u5f80\u5f80\u901a\u8fc7\u6c47\u7f16\u5b9e\u73b0\u3002\u5176\u5b9a\u4e49\u5728<asm/spinlock.h>\u4e2d\uff0c\u5b9e\u9645\u7684\u63a5\u53e3\u5b9a\u4e49\u5728<linux/spinlock.h>\u3002\u81ea\u65cb\u9501\u7684\u57fa\u672c\u4f7f\u7528\u5982\u4e0b\uff1a
DEFINE_SPINLOCK(sp_lock);\nspin_lock(&sp_lock);\n/*\u4e34\u754c\u533a\u4ee3\u7801*/\nspin_unlock(&sp_lock);\n
\u5728\u5355\u5904\u7406\u5668\u4e0a\uff0c\u5982\u679c\u7981\u6b62\u5185\u6838\u62a2\u5360\uff0c\u90a3\u4e48\u81ea\u65cb\u9501\u4e0d\u4f1a\u88ab\u7f16\u8bd1\u8fdb\u5185\u6838\u3002
\u81ea\u65cb\u9501\u53ef\u4ee5\u4f7f\u7528\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0c\u4f46\u83b7\u53d6\u9501\u4e4b\u524d\uff0c\u5fc5\u987b\u8981\u7981\u6b62\u672c\u5730\u4e2d\u65ad\uff0c\u5426\u5219\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4f1a\u6253\u65ad\u5f53\u524d\u6301\u6709\u9501\u7684\u4ee3\u7801\u3002\u7531\u4e8e\u9501\u7684\u6301\u6709\u548c\u91ca\u653e\u5fc5\u987b\u662f\u539f\u5b50\u7684\uff0c\u5982\u679c\u88ab\u6253\u65ad\u53ef\u80fd\u4f1a\u5f71\u54cd\u9501\u7684\u4e00\u81f4\u6027\uff0c\u8fd9\u4f1a\u5f15\u8d77\u4e0d\u53ef\u9884\u6d4b\u7684\u540e\u679c\u3002\u751a\u81f3\uff0c\u5982\u679c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u53bb\u4e89\u7528\u8fd9\u4e2a\u5df2\u7ecf\u88ab\u6301\u6709\u7684\u9501\uff0c\u90a3\u4e48\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002\u6ce8\u610f\uff0c\u8981\u5173\u95ed\u7684\u53ea\u662f\u5f53\u524d\u5904\u7406\u5668\u7684\u4e2d\u65ad\uff0c\u5176\u4ed6\u5904\u7406\u5668\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u81ea\u65cb\u5e76\u4e0d\u4f1a\u59a8\u788d\u5f53\u524d\u5904\u7406\u5668\u91ca\u653e\u9501\u3002
\u5185\u6838\u63d0\u4f9b\u4e86\u7981\u6b62\u4e2d\u65ad\u540c\u65f6\u8bf7\u6c42\u9501\u7684\u63a5\u53e3\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a
DEFINE_SPINLOCK(sp_lock);\nunsigned long flags;\nspin_lock_irqsave(&sp_lock, flags);\nspin_unlock_irqrestore(&sp_lock, flags);\n
\u51fd\u6570spin_lock_irqsave()
\u4fdd\u5b58\u4e2d\u65ad\u72b6\u6001\uff0c\u5e76\u7981\u6b62\u672c\u5730\u4e2d\u65ad\uff0c\u7136\u540e\u518d\u53bb\u83b7\u53d6\u9501\u3002\u53cd\u8fc7\u6765spin_unlock_irqrestore()
\u89e3\u9501\uff0c\u5e76\u8ba9\u4e2d\u65ad\u6062\u590d\u5230\u52a0\u9501\u524d\u7684\u72b6\u6001\u3002\u6240\u4ee5\u5373\u4fbf\u662f\u52a0\u9501\u524d\u4e2d\u65ad\u5df2\u7ecf\u88ab\u7981\u6b62\u4e86\uff0c\u4ee3\u7801\u4e5f\u4e0d\u4f1a\u9519\u8bef\u5730\u6fc0\u6d3b\u4e2d\u65ad\uff0c\u800c\u662f\u8ba9\u4e2d\u65ad\u4fdd\u6301\u7981\u6b62\u72b6\u6001\u3002
\u5982\u679c\u4f60\u80fd\u786e\u5b9a\u4e2d\u65ad\u5728\u52a0\u9501\u524d\u662f\u6fc0\u6d3b\u7684\uff0c\u90a3\u4e48\u53ef\u4ee5\u914d\u5bf9\u4f7f\u7528spin_lock_irq()
\u548cspin_unlock_irq()
\uff0c\u4ece\u800c\u5728\u89e3\u9501\u65f6\u76f4\u63a5\u6fc0\u6d3b\u4e2d\u65ad\u3002\u4f46\u662f\u5185\u6838\u7684\u5e9e\u5927\u6027\u5f80\u5f80\u8ba9\u4eba\u5f88\u96be\u641e\u6e05\u695a\u4e2d\u65ad\u5728\u5f53\u524d\u6267\u884c\u4ee3\u7801\u524d\u662f\u5426\u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001\uff0c\u6240\u4ee5\u8be5\u65b9\u6cd5\u5e76\u4e0d\u63d0\u5021\u3002
\u7531\u4e8e\u4e2d\u65ad\u4e0b\u534a\u90e8\u53ef\u4ee5\u62a2\u5360\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u7684\u4ee3\u7801\uff0c\u56e0\u6b64\u52a0\u9501\u7684\u540c\u65f6\u8fd8\u9700\u8981\u7981\u6b62\u4e0b\u534a\u90e8\u6267\u884c\u3002\u51fd\u6570spin_lock_bh()
\u53ef\u4ee5\u505a\u5230\u8fd9\u4e00\u70b9\u3002\u540c\u6837\uff0c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u53ef\u4ee5\u62a2\u5360\u4e0b\u534a\u90e8\uff0c\u56e0\u6b64\u5982\u679c\u4e0b\u534a\u90e8\u6709\u9700\u8981\u548c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5171\u4eab\u7684\u6570\u636e\u65f6\uff0c\u4e5f\u5fc5\u987b\u7981\u6b62\u4e2d\u65ad\u3002
\u4e2d\u65ad\u5904\u7406\u662f\u53e6\u4e00\u4e2a\u8bdd\u9898\uff0c\u8bf7\u53c2\u8003\u4e2d\u65ad\u548c\u4e2d\u65ad\u5904\u7406\u3002
"},{"location":"linux/kernel/synch/#_9","title":"\u8bfb/\u5199\u81ea\u65cb\u9501","text":"\u6709\u65f6\uff0c\u9501\u7684\u7528\u9014\u53ef\u4ee5\u660e\u786e\u5730\u5206\u4e3a\u8bfb\u548c\u5199\u4e24\u4e2a\u573a\u666f\uff0c\u5c24\u5176\u662f\u90a3\u4e9b\u9700\u8981\u5927\u91cf\u8bfb\u64cd\u4f5c\uff0c\u800c\u5199\u64cd\u4f5c\u5f88\u5c11\u7684\u60c5\u51b5\u65f6\uff0c\u5f15\u5165\u8bfb\u5199\u9501\u53ef\u4ee5\u5f88\u5927\u5730\u6539\u5584\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u8bfb\u5199\u9501\u7684\u57fa\u672c\u903b\u8f91\u662f\uff1a\u8bfb\u6a21\u5f0f\u662f\u5171\u4eab\u7684\uff0c\u5199\u6a21\u5f0f\u662f\u72ec\u5360\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\u5f53\u8fdb\u884c\u5199\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u53ea\u80fd\u7531\u5355\u4e2a\u4efb\u52a1\u8fdb\u884c\u3002\u800c\u8fdb\u884c\u8bfb\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5e76\u53d1\u7684\u6267\u884c\u800c\u4e0d\u7528\u62c5\u5fc3\u5b89\u5168\u95ee\u9898\u3002\u8bfb/\u5199\u9501\u7684\u57fa\u672c\u65b9\u6cd5\u5982\u4e0b\uff1a
DEFINE_RWLOCK(rw_lock);\n//\u8bfb\u64cd\u4f5c\nread_lock(&rw_lock);\nread_unlock(&rw_lock);\n//\u5199\u64cd\u4f5c\nwrite_lock(&rw_lock);\nwrite_unlock(&rw_lock);\n
\u901a\u5e38\uff0c\u8bfb\u5199\u64cd\u4f5c\u5e94\u5904\u4e8e\u5b8c\u5168\u5206\u5272\u5f00\u7684\u4ee3\u7801\u5206\u652f\u4e2d\uff0c\u5982\u679c\u8bfb\u5199\u64cd\u4f5c\u4e0d\u80fd\u6e05\u6670\u5730\u8fa8\u522b\uff0c\u4e0d\u8981\u4f7f\u7528\u8bfb\u5199\u9501\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002\u4f8b\u5982\u5728\u6267\u884c\u8bfb\u64cd\u4f5c\u4ee3\u7801\u65f6\uff0c\u4e5f\u52a0\u5165\u4e86\u5199\u64cd\u4f5c\u3002
\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0c\u5982\u679c\u53ea\u6709\u8bfb\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7b80\u5355\u5730\u4f7f\u7528read_lock()
\u6765\u4fdd\u62a4\u8bfb\u64cd\u4f5c\uff0c\u800c\u4e0d\u9700\u8981\u7981\u6b62\u4e2d\u65ad\u4e86\u3002\u4f46\u662f\uff0c\u5199\u64cd\u4f5c\u7684\u4e2d\u65ad\u5fc5\u987b\u7981\u6b62\uff0c\u5426\u5219\u5c31\u4f1a\u9020\u6210\u6b7b\u9501\u3002\u56e0\u4e3a\u5199\u64cd\u4f5c\u9700\u8981\u7b49\u5f85\u8bfb\u64cd\u4f5c\u91ca\u653e\u9501\uff0c\u800c\u8bfb\u64cd\u4f5c\u9700\u8981\u7b49\u5f85\u5199\u64cd\u4f5c\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8fd4\u56de\u3002
\u5728\u4f7f\u7528\u8bfb\u5199\u9501\u7684\u65f6\u5019\u9700\u8981\u6ce8\u610f\uff0c\u5f53\u8bfb\u9501\u88ab\u6301\u6709\u65f6\uff0c\u5199\u9501\u53ea\u80fd\u7b49\u5f85\u3002\u7136\u800c\u8bfb\u9501\u5374\u53ef\u4ee5\u7ee7\u7eed\u6210\u529f\u5730\u5360\u7528\u9501\u3002\u8fd9\u4f1a\u9020\u6210\u5199\u9501\u9965\u997f\u73b0\u8c61\u3002
\u5982\u679c\u52a0\u9501\u65f6\u95f4\u5f88\u957f\u6216\u8005\u4ee3\u7801\u5728\u6301\u6709\u9501\u65f6\u6709\u53ef\u80fd\u7761\u7720\uff0c\u90a3\u4e48\u6700\u597d\u4f7f\u7528\u4fe1\u53f7\u91cf\u6765\u5904\u7406\u3002
"},{"location":"linux/kernel/synch/#_10","title":"\u4fe1\u53f7\u91cf","text":"Linux\u4e2d\u7684\u4fe1\u53f7\u91cf\u662f\u4e00\u79cd\u7761\u7720\u9501\u3002\u5f53\u6709\u4e00\u4e2a\u4efb\u52a1\u8bd5\u56fe\u83b7\u5f97\u4e00\u4e2a\u5df2\u7ecf\u88ab\u5360\u7528\u7684\u4fe1\u53f7\u91cf\u65f6\uff0c\u8be5\u4efb\u52a1\u4f1a\u52a0\u5165\u7b49\u5f85\u961f\u5217\uff0c\u7136\u540e\u7761\u7720\u3002\u7531\u4e8e\u91ca\u653e\u4e86\u8d44\u6e90\u5904\u7406\u5668\u53ef\u4ee5\u53bb\u6267\u884c\u5176\u4ed6\u7684\u4ee3\u7801\u3002\u5f53\u6301\u6709\u7684\u4fe1\u53f7\u91cf\u88ab\u91ca\u653e\u65f6\uff0c\u5904\u4e8e\u7b49\u5f85\u961f\u5217\u4e2d\u7684\u90a3\u4e2a\u4efb\u52a1\u4f1a\u88ab\u5524\u9192\uff0c\u5e76\u83b7\u5f97\u8be5\u4fe1\u53f7\u91cf\u3002
\u5b9e\u9645\u4e0a\uff0cLinux\u63d0\u4f9b\u4e24\u79cd\u4fe1\u53f7\u91cf\uff1a
\u5185\u6838\u4fe1\u53f7\u91cf\uff0c\u7531\u5185\u6838\u6001\u4f7f\u7528 System V IPC\u4fe1\u53f7\u91cf\uff0c\u7531\u7528\u6237\u6001\u4f7f\u7528 \u7531\u4e8e\u4fe1\u53f7\u91cf\u4f1a\u7761\u7720\uff0c\u56e0\u6b64\u6709\u4ee5\u4e0b\u7ed3\u8bba\uff1a
\u4fe1\u53f7\u91cf\u9002\u7528\u4e8e\u9501\u4f1a\u88ab\u957f\u65f6\u95f4\u5360\u6709\u7684\u573a\u666f\u3002 \u4fe1\u53f7\u91cf\u53ea\u80fd\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\uff0c\u56e0\u4e3a\u4e2d\u65ad\u4e0a\u4e0b\u6587\u7981\u6b62\u7761\u7720\u3002 \u591a\u4e2a\u8fdb\u7a0b\u8bd5\u56fe\u83b7\u5f97\u4fe1\u53f7\u91cf\u4e0d\u4f1a\u6b7b\u9501\u3002 \u5982\u679c\u5df2\u7ecf\u5360\u7528\u4e86\u4fe1\u53f7\u91cf\uff0c\u4e0d\u80fd\u518d\u4f7f\u7528\u81ea\u65cb\u9501\uff0c\u56e0\u4e3a\u81ea\u65cb\u9501\u7981\u6b62\u7761\u7720\u3002 \u4fe1\u53f7\u91cf\u76f8\u6bd4\u81ea\u65cb\u9501\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u5730\u65b9\uff0c\u5c31\u662f\u5b83\u5185\u90e8\u7ef4\u62a4\u4e86\u4e00\u4e2acount
\u503c\uff0c\u8be5count
\u503c\u7b49\u540c\u4e8e\u540c\u4e00\u65f6\u95f4\u80fd\u591f\u6301\u6709\u4fe1\u53f7\u91cf\u7684\u6570\u91cf\u3002\u5982\u679c\u8fd9\u4e2a\u503c\u662f1\uff0c\u90a3\u4e48\u4fe1\u53f7\u91cf\u53c8\u88ab\u79f0\u4e3a\u4e92\u65a5\u4fe1\u53f7\u91cf\u3002\u4fe1\u53f7\u91cf\u652f\u6301\u4e24\u4e2a\u64cd\u4f5c\uff1adown()
\u64cd\u4f5c\u901a\u8fc7\u5bf9\u4fe1\u53f7\u91cf\u8ba1\u6570\u51cf1\u6765\u83b7\u5f97\u5b83\uff0c\u800cup()
\u64cd\u4f5c\u52a01\u6765\u91ca\u653e\u5b83\u3002
\u4fe1\u53f7\u91cf\u662f\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\uff0c\u5b9a\u4e49\u5728<asm/semaphore.h>\u4e2d\u3002\u521b\u5efa\u65b9\u6cd5\u5982\u4e0b\uff1a
struct semaphore name;\nsema_init(&name, count);\n
\u51fd\u6570down_interruptible()
\u8bd5\u56fe\u83b7\u53d6\u6307\u5b9a\u7684\u4fe1\u53f7\u91cf\uff0c\u5982\u679c\u4e0d\u53ef\u7528\uff0c\u5219\u5c06\u8fdb\u7a0b\u8bbe\u7f6e\u4e3aTASK_INTERRUPTIBLE\u3002\u8fd9\u79cd\u8fdb\u7a0b\u72b6\u6001\u610f\u5473\u7740\u4efb\u52a1\u53ef\u4ee5\u88ab\u4fe1\u53f7\u5524\u9192\u3002\u4f7f\u7528down_trylock()
\u51fd\u6570\uff0c\u5728\u4fe1\u53f7\u91cf\u5df2\u7ecf\u88ab\u5360\u7528\u65f6\uff0c\u7acb\u5373\u8fd4\u56de\u800c\u4e0d\u662f\u8ba9\u8fdb\u7a0b\u7761\u7720\u3002
"},{"location":"linux/kernel/synch/#_11","title":"\u4e92\u65a5\u4f53","text":"\u5728\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4fe1\u53f7\u91cf\u53ea\u662f\u4f5c\u4e3a\u4e00\u4e2a\u8ba1\u6570\u4e3a1\u7684\u5141\u8bb8\u7761\u7720\u7684\u81ea\u65cb\u9501\u5b58\u5728\u3002\u4e3a\u4e86\u627e\u5230\u4e00\u4e2a\u66f4\u7b80\u5355\u4e14\u53ef\u4ee5\u7761\u7720\u7684\u9501\uff0c\u5f00\u53d1\u8005\u4eec\u5f15\u5165\u4e86\u4e92\u65a5\u4f53\uff08mutex\uff09\u3002\u5176\u884c\u4e3a\u548c\u8ba1\u6570\u4e3a1\u7684\u4fe1\u53f7\u91cf\u7c7b\u4f3c\uff0c\u4f46\u662f\u64cd\u4f5c\u7684\u63a5\u53e3\u66f4\u7b80\u5355\uff0c\u5b9e\u73b0\u4e5f\u66f4\u9ad8\u6548\u3002\u57fa\u672c\u9002\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a
DEFINE_MUTEX(mutex);\nmutex_init(&mutex);\nmutex_lock(&mutex);\nmutex_unlock(&mutex);\n
mutex\u7684\u7b80\u4ecb\u4e0e\u9ad8\u6548\u6e90\u4e8e\u76f8\u6bd4\u4f7f\u7528\u4fe1\u53f7\u91cf\u66f4\u591a\u7684\u53d7\u9650\u6027\uff1a
\u4efb\u4f55\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a\u4efb\u52a1\u6301\u6709mutex\u3002 \u5fc5\u987b\u7531\u4e0a\u9501\u8005\u89e3\u9501\u2014\u2014\u8fd9\u610f\u5473\u7740\u4f60\u4e0d\u80fd\u5728\u4e00\u4e2a\u7ebf\u7a0b\u4e0a\u9501\uff0c\u800c\u5728\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u89e3\u9501\u3002 \u9012\u5f52\u5730\u4e0a\u9501\u548c\u89e3\u9501\u65f6\u4e0d\u88ab\u5141\u8bb8\u7684\u3002 \u5f53\u6301\u6709\u4e00\u4e2amutex\u65f6\uff0c\u8fdb\u7a0b\u4e0d\u80fd\u9000\u51fa\u3002 mutex\u4e0d\u80fd\u5728\u4e2d\u65ad\u6216\u8005\u4e0b\u534a\u90e8\u4e2d\u4f7f\u7528\u3002 \u9700\u6c42 \u5efa\u8bae\u7684\u52a0\u9501\u65b9\u5f0f \u4f4e\u5f00\u9500\u52a0\u9501 \u4f18\u5148\u4f7f\u7528\u81ea\u65cb\u9501 \u77ed\u671f\u52a0\u9501 \u4f18\u5148\u4f7f\u7528\u81ea\u65cb\u9501 \u957f\u671f\u52a0\u9501 \u4f18\u5148\u4f7f\u7528\u4e92\u65a5\u4f53 \u4e2d\u65ad\u4e0a\u4e0b\u6587\u52a0\u9501 \u4f7f\u7528\u81ea\u65cb\u9501 \u6301\u6709\u9501\u9700\u8981\u7761\u7720 \u4f7f\u7528\u4e92\u65a5\u4f53"},{"location":"linux/kernel/synch/#_12","title":"\u5b8c\u6210\u53d8\u91cf","text":"\u5982\u679c\u5728\u5185\u6838\u4e2d\u4e00\u4e2a\u4efb\u52a1\u9700\u8981\u53d1\u9001\u4fe1\u53f7\u901a\u77e5\u53e6\u4e00\u4e2a\u4efb\u52a1\u53d1\u751f\u4e86\u67d0\u79cd\u7279\u5b9a\u4e8b\u4ef6\uff0c\u6b64\u65f6\u53ef\u4ee5\u7528\u5b8c\u6210\u53d8\u91cf\uff08completion variable\uff09\u3002\u5f53\u67d0\u4e2a\u4efb\u52a1\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u4f1a\u4f7f\u7528\u5b8c\u6210\u53d8\u91cf\u53bb\u5524\u9192\u6b63\u5728\u7b49\u5f85\u7684\u4efb\u52a1\u3002
\u5b8c\u6210\u53d8\u91cf\u7531\u7ed3\u6784\u4f53completion\u8868\u793a\uff0c\u5b9a\u4e49\u5728<linux/completion.h>\u4e2d\u3002\u5176\u521b\u5efa\u65b9\u6cd5\u5982\u4e0b\uff1a
DECLARE_COMPLETION(comp);\n
\u6216\u8005\u4f7f\u7528init_completion()
\u52a8\u6001\u521b\u5efa\u3002\u9700\u8981\u7b49\u5f85\u7684\u4efb\u52a1\u8c03\u7528wait_for_completion()
\u6765\u7b49\u5f85\u7279\u5b9a\u4e8b\u4ef6\u3002\u5f53\u4e8b\u4ef6\u53d1\u751f\u540e\uff0c\u4ea7\u751f\u4e8b\u4ef6\u7684\u4efb\u52a1\u8c03\u7528complete()
\u6765\u53d1\u9001\u4fe1\u53f7\u5524\u9192\u6b63\u5728\u7b49\u5f85\u7684\u4efb\u52a1\u3002
"},{"location":"linux/kernel/synch/#rcu","title":"RCU\u673a\u5236","text":"\u8bfb\u53d6-\u590d\u5236-\u66f4\u65b0\uff08read-copy-update\uff09\u662f\u4e00\u79cd\u9ad8\u7ea7\u4e92\u65a5\u673a\u5236\uff0c\u4e00\u822c\u7528\u4e0d\u5230\u4f46\u662f\u6211\u4eec\u5bf9\u8fd9\u4e2a\u6982\u5ff5\u5f97\u6709\u4e00\u4e2a\u57fa\u672c\u7684\u4e86\u89e3\u3002RCU\u673a\u5236\u4e3b\u8981\u9488\u5bf9\u8bfb\u53d6\u7ecf\u5e38\u53d1\u751f\u3001\u4f46\u662f\u5199\u5165\u5f88\u5c11\u7684\u60c5\u51b5\u3002\u5728\u9700\u8981\u4fee\u6539\u6570\u636e\u65f6\uff0c\u5199\u5165\u7ebf\u7a0b\u9996\u5148\u590d\u5236\u4e00\u4efd\uff0c\u7136\u540e\u4fee\u6539\u526f\u672c\u3002\u5176\u4ed6\u7ebf\u7a0b\u5728\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u4ecd\u7136\u6307\u5411\u539f\u59cb\u7684\u5171\u4eab\u6570\u636e\u5730\u5740\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u5728\u5199\u64cd\u4f5c\u53d1\u751f\u524d\uff0c\u5176\u4ed6\u7ebf\u7a0b\u4ecd\u7136\u53ef\u4ee5\u8bfb\u53d6\u5230\u4e00\u81f4\u7684\u6570\u636e\u3002\u76f4\u5230\u66f4\u65b0\u7ebf\u7a0b\u5b8c\u6210\u4e86\u6570\u636e\u7684\u4fee\u6539\uff0c\u5e76\u901a\u8fc7\u7279\u5b9a\u7684API\u5c06\u66f4\u65b0\u540e\u7684\u6570\u636e\u6307\u9488\u8d4b\u503c\u56de\u539f\u6765\u7684\u5171\u4eab\u6570\u636e\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u79f0\u4e3a\u201c\u66f4\u65b0\u5b8c\u6210\u201d\u3002\u5185\u5b58\u5c4f\u969c\u6307\u4ee4\u7528\u4e8e\u4fdd\u8bc1\u53ea\u6709\u5728\u6570\u636e\u7ed3\u6784\u88ab\u4fee\u6539\u4e4b\u540e\uff0c\u5df2\u66f4\u65b0\u7684\u6307\u9488\u624d\u5bf9\u5176\u4ed6CPU\u53ef\u89c1\u3002\u8bfb\u53d6\u7aef\u7684\u4ee3\u7801\u5fc5\u987b\u653e\u7f6e\u4e8ercu_read_lock()
\u548crcu_read_unlock()
\u4e4b\u95f4\u3002
\u4f7f\u7528RCU\u6280\u672f\u7684\u96be\u70b9\u5728\u4e8e\uff1a\u5199\u5165\u7aef\u4fee\u6539\u6307\u9488\u65f6\u4e0d\u80fd\u7acb\u523b\u91ca\u653e\u6570\u636e\u7ed3\u6784\u7684\u65e7\u6307\u9488\uff0c\u56e0\u4e3a\u8fd8\u6709\u5176\u4ed6\u7684\u8bfb\u53d6\u7aef\u5728\u4f7f\u7528\u3002\u53ea\u6709\u5f53\u6240\u6709\u7684\u8bfb\u53d6\u7aef\u6267\u884c\u5b8c\u5b8frcu_read_unlcok()
\u4e4b\u540e\uff0c\u624d\u53ef\u4ee5\u91ca\u653e\u65e7\u6307\u9488\u3002\u5199\u5165\u7aef\u8c03\u7528\u51fd\u6570call_rcu()
\u6765\u91ca\u653e\u65e7\u6307\u9488\u3002
"},{"location":"linux/kernel/synch/#_13","title":"\u7981\u6b62\u62a2\u5360","text":"Linux\u662f\u62a2\u5360\u5f0f\u5185\u6838\uff0c\u5176\u4e3b\u8981\u7279\u70b9\u662f\uff1a\u4e00\u4e2a\u5728\u5185\u6838\u6001\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u53ef\u80fd\u5728\u6267\u884c\u5185\u6838\u6001\u51fd\u6570\u671f\u95f4\u88ab\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b\u62a2\u5360\u3002\u5728\u8fdb\u7a0bA\u6267\u884c\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u65f6\uff08\u6b21\u5403\u4f4d\u4e8e\u5185\u6838\u6001\uff09\uff0c\u4e00\u4e2a\u66f4\u6709\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0bB\u53d8\u4e3a\u53ef\u6267\u884c\u72b6\u6001\u3002\u5982\u679c\u5185\u6838\u662f\u53ef\u62a2\u5360\u7684\uff0c\u5c31\u4f1a\u53d1\u751f\u5f3a\u5236\u6027\u4efb\u52a1\u5207\u6362\uff0c\u8ba9B\u53d6\u4ee3A\u3002\u518d\u6bd4\u5982\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u5df2\u7ecf\u7528\u5b8c\u4e86\u5b83\u7684\u65f6\u95f4\u7247\u914d\u989d\uff0c\u62a2\u5360\u5f0f\u5185\u6838\u4f1a\u7acb\u523b\u8ba9\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u53d6\u4ee3\u5b83\u3002
\u5185\u6838\u4f7f\u7528thread_info
\u4e2d\u7684preempt_count
\u5b57\u6bb5\u8868\u793a\u62a2\u5360\u8ba1\u6570\u3002\u5f53\u8fd9\u4e2a\u503c\u5927\u4e8e0\u65f6\uff0c\u5c31\u7981\u6b62\u5185\u6838\u62a2\u5360\u3002\u5b83\u5728\u4ee5\u4e0b\u4efb\u4f55\u4e00\u79cd\u60c5\u51b5\u53d1\u751f\u65f6\uff0c\u53d6\u503c\u90fd\u5927\u4e8e0\uff1a
\u5185\u6838\u6b63\u5728\u6267\u884c\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u3002
\u53ef\u5ef6\u8fdf\u51fd\u6570\u88ab\u7981\u6b62\uff08\u5f53\u5185\u6838\u6b63\u5728\u6267\u884c\u8f6f\u4e2d\u65ad\u6216tasklet\uff09\u3002
\u663e\u793a\u8bbe\u7f6e\u62a2\u5360\u8ba1\u6570\u5668\u4e3a\u6b63\u6570\u3002
\u5b8f \u8bf4\u660e preempt_count() \u8fd4\u56de\u62a2\u5360\u8ba1\u6570\u503c preempt_disable() \u4f7f\u62a2\u5360\u8ba1\u6570+1 preempt_enable() \u4f7f\u62a2\u5360\u8ba1\u6570-1\uff0c\u5e76\u68c0\u67e5TIF_NEED_RESCHED\u6807\u5fd7 preempt_enable_no_resched() \u4f7f\u62a2\u5360\u8ba1\u6570-1 \u4e0a\u9762\u7b2c\u4e09\u4e2a\u5b8f\u9700\u8981\u8bf4\u660e\u4e00\u4e0b\u3002preempt_enable()
\u5b8f\u9996\u5148\u9012\u51cf\u62a2\u5360\u8ba1\u6570\u5668\uff0c\u5e76\u4e14\u68c0\u67e5TIF_NEED_RESCHED\u6807\u5fd7\u662f\u5426\u88ab\u8bbe\u7f6e\u3002\u5f53\u8fd9\u4e2a\u6807\u5fd7\u4e3a1\u65f6\u8868\u793a\u9700\u8981\u6267\u884c\u8c03\u5ea6\u7a0b\u5e8f\u3002\u4e8e\u662f\u6211\u4eec\u8fd8\u4f1a\u8c03\u7528preempt_schedule()
\u6765\u8c03\u7528schedule()
\u9009\u62e9\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b\u8fd0\u884c\u3002
"},{"location":"linux/kernel/synch/#_14","title":"\u987a\u5e8f\u4e0e\u5c4f\u969c","text":"\u4e3a\u4ec0\u4e48\u9700\u8981\u987a\u5e8f\u548c\u5c4f\u969c\u6307\u4ee4\uff1f
\u9632\u6b62\u7f16\u8bd1\u5668\u4f18\u5316\u5bfc\u81f4\u7684\u91cd\u6392\uff1a\u73b0\u4ee3\u7f16\u8bd1\u5668\u4f1a\u8fdb\u884c\u5404\u79cd\u4f18\u5316\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u5305\u62ec\u6307\u4ee4\u91cd\u6392\u3002\u5728\u4e0d\u8003\u8651\u5185\u5b58\u64cd\u4f5c\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u6539\u53d8\u6307\u4ee4\u7684\u6267\u884c\u987a\u5e8f\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u7684\u884c\u4e3a\u4e0e\u9884\u671f\u4e0d\u7b26\u3002\u901a\u8fc7\u4f7f\u7528\u987a\u5e8f\u548c\u5c4f\u969c\u6307\u4ee4\uff0c\u53ef\u4ee5\u9650\u5236\u7f16\u8bd1\u5668\u5bf9\u67d0\u4e9b\u5173\u952e\u4ee3\u7801\u6bb5\u7684\u4f18\u5316\u3002
\u4fdd\u8bc1\u5e76\u53d1\u64cd\u4f5c\u7684\u4e00\u81f4\u6027\uff1a\u5728\u591a\u6838\u5904\u7406\u5668\u548c\u591a\u7ebf\u7a0b\u7f16\u7a0b\u4e2d\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u64cd\u4f5c\u7cfb\u7edf\u7684\u8c03\u5ea6\u5668\u53ef\u80fd\u4f1a\u5728\u4e0d\u540c\u7684\u5904\u7406\u5668\u6838\u5fc3\u4e0a\u5e76\u884c\u6267\u884c\u591a\u4e2a\u7ebf\u7a0b\u3002\u4e3a\u4e86\u4fdd\u6301\u4e00\u81f4\u6027\uff0c\u9700\u8981\u786e\u4fdd\u6240\u6709\u6838\u5fc3\u4e0a\u7684\u5185\u5b58\u64cd\u4f5c\u90fd\u6309\u7167\u7a0b\u5e8f\u6307\u5b9a\u7684\u987a\u5e8f\u6267\u884c\u3002
\u89e3\u51b3CPU\u7f13\u5b58\u4e00\u81f4\u6027\u95ee\u9898\uff1aCPU\u7f13\u5b58\u662f\u5904\u7406\u5668\u901f\u5ea6\u7684\u5173\u952e\u90e8\u5206\uff0c\u4f46\u5b83\u7684\u5b58\u5728\u4e5f\u5e26\u6765\u4e86\u7f13\u5b58\u4e00\u81f4\u6027\u7684\u95ee\u9898\u3002\u5f53\u4e00\u4e2aCPU\u6838\u5fc3\u5199\u5165\u6570\u636e\uff0c\u800c\u8fd9\u4e2a\u6570\u636e\u53c8\u88ab\u53e6\u4e00\u4e2a\u6838\u5fc3\u7684\u7f13\u5b58\u6240\u7f13\u5b58\u65f6\uff0c\u6ca1\u6709\u5c4f\u969c\u7684\u8bdd\uff0c\u53e6\u4e00\u4e2a\u6838\u5fc3\u53ef\u80fd\u4f1a\u8bfb\u53d6\u5230\u65e7\u7684\u6570\u636e\u7248\u672c\u3002\u5185\u5b58\u5c4f\u969c\u80fd\u591f\u786e\u4fdd\u6240\u6709\u6838\u5fc3\u770b\u5230\u5185\u5b58\u64cd\u4f5c\u7684\u6700\u7ec8\u4e00\u81f4\u6027\u3002
Linux\u4e2d\u7684\u5185\u5b58\u5c4f\u969c\u6307\u4ee4\uff1a
\u5b8f \u8bf4\u660e mb() \u9002\u7528\u4e8eMP\u548cUP\u7684\u5185\u5b58\u5c4f\u969c rmb() \u9002\u7528\u4e8eMP\u548cUP\u7684\u8bfb\u5185\u5b58\u5c4f\u969c wmb() \u9002\u7528\u4e8eMP\u548cUP\u7684\u5199\u5185\u5b58\u5c4f\u969c smp_mb() \u4ec5\u9002\u7528\u4e8eMP\u7684\u5185\u5b58\u5c4f\u969c smp_rmb() \u4ec5\u9002\u7528\u4e8eMP\u7684\u8bfb\u5185\u5b58\u5c4f\u969c smp_wmb() \u4ec5\u9002\u7528\u4e8eMP\u7684\u5199\u5185\u5b58\u5c4f\u969c \u6b64\u7c7b\u6307\u4ee4\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\uff0c\u8bf7\u53c2\u8003ARM\u5185\u5b58\u5c4f\u969c\u6307\u4ee4\u3002
"},{"location":"linux/kernel/vma/","title":"\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4","text":"\u5185\u6838\u9664\u4e86\u7ba1\u7406\u672c\u8eab\u7684\u5185\u5b58\u5916\uff0c\u8fd8\u5fc5\u987b\u7ba1\u7406\u7528\u6237\u7a7a\u95f4\u4e2d\u8fdb\u7a0b\u7684\u5185\u5b58\u3002\u6211\u4eec\u79f0\u8fd9\u4e2a\u5185\u5b58\u4e3a\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u3002Linux\u64cd\u4f5c\u7cfb\u7edf\u91c7\u7528\u865a\u62df\u5185\u5b58\u6280\u672f\uff0c\u5bf9\u4e00\u4e2a\u8fdb\u7a0b\u800c\u8a00\uff0c\u5b83\u4ee5\u865a\u62df\u7684\u65b9\u5f0f\u8bbf\u95ee\u6574\u4e2a\u7cfb\u7edf\u7684\u6240\u6709\u7269\u7406\u5185\u5b58\uff0c\u751a\u81f3\u5176\u865a\u62df\u7a7a\u95f4\u53ef\u4ee5\u8fdc\u8fdc\u5927\u4e8e\u7269\u7406\u5185\u5b58\u3002
\u4e3a\u4ec0\u4e48\u8981\u6709\u865a\u62df\u5185\u5b58\uff1f
\u5728\u8003\u8651\u4e24\u4e2a\u7a0b\u5e8f\u540c\u65f6\u64cd\u4f5c\u7269\u7406\u5185\u5b58\u7684\u573a\u666f\u65f6\uff0c\u6211\u4eec\u5fc5\u987b\u8c28\u614e\u5730\u4e3a\u5b83\u4eec\u5206\u914d\u5185\u5b58\u5730\u5740\uff0c\u5e76\u786e\u4fdd\u6bcf\u4e2a\u7a0b\u5e8f\u4ec5\u8bbf\u95ee\u5176\u88ab\u5206\u914d\u7684\u5185\u5b58\u533a\u57df\uff0c\u9632\u6b62\u5730\u5740\u51b2\u7a81\u3002\u624b\u52a8\u7ba1\u7406\u5185\u5b58\u5730\u5740\u4f1a\u6781\u5927\u5730\u589e\u52a0\u7f16\u7a0b\u7684\u590d\u6742\u6027\u3002\u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u80fd\u591f\u5b9e\u73b0\u4e00\u79cd\u673a\u5236\uff0c\u5b83\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u63d0\u4f9b\u4e00\u5957\u9694\u79bb\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c06\u4e3a\u8fd9\u4e9b\u865a\u62df\u5730\u5740\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\uff0c\u4e14\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u72ec\u7acb\u4e8e\u5176\u4ed6\u8fdb\u7a0b\u64cd\u4f5c\uff0c\u90a3\u4e48\u8fd9\u5c06\u6781\u5927\u5730\u7b80\u5316\u7f16\u7a0b\u5de5\u4f5c\u3002\u8fd9\u79cd\u673a\u5236\u5c31\u662f\u865a\u62df\u5185\u5b58\u7ba1\u7406\uff0c\u800c\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff08MMU\uff09\u5219\u8d1f\u8d23\u5c06\u865a\u62df\u5730\u5740\u8f6c\u6362\u4e3a\u7269\u7406\u5730\u5740\u3002
Linux\u91c7\u7528\u4e86\u57fa\u4e8e\u5206\u9875\u7684\u865a\u62df\u5185\u5b58\u7ba1\u7406\u673a\u5236\uff0c\u5176\u4e2d\u5185\u5b58\u88ab\u5212\u5206\u4e3a\u5927\u5c0f\u56fa\u5b9a\u7684\u9875\uff0c\u6bcf\u4e00\u9875\u901a\u5e38\u662f4KB\u3002\u8fd9\u79cd\u5206\u9875\u673a\u5236\u4f7f\u5f97\u5185\u5b58\u7ba1\u7406\u66f4\u52a0\u7075\u6d3b\u548c\u9ad8\u6548\u3002\u5728Linux\u4e2d\uff0c\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u8f6c\u6362\u662f\u901a\u8fc7\u591a\u7ea7\u9875\u8868\u6765\u5b9e\u73b0\u7684\uff0c\u8fd9\u79cd\u5206\u7ea7\u7ed3\u6784\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u5927\u578b\u5730\u5740\u7a7a\u95f4\uff0c\u540c\u65f6\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002\u4e3a\u4e86\u63d0\u9ad8\u5730\u5740\u8f6c\u6362\u7684\u901f\u5ea6\uff0c\u73b0\u4ee3CPU\u8bbe\u8ba1\u901a\u5e38\u5305\u62ec\u4e00\u4e2a\u79f0\u4e3a\u8f6c\u6362\u540e\u63f4\u7f13\u51b2\u5668\uff08TLB\uff09\u7684\u786c\u4ef6\u7f13\u5b58\u3002TLB\u7f13\u5b58\u4e86\u6700\u8fd1\u4f7f\u7528\u8fc7\u7684\u9875\u8868\u9879\uff0c\u8fd9\u6837\u5f53CPU\u9700\u8981\u8bbf\u95ee\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u65f6\uff0c\u5b83\u9996\u5148\u68c0\u67e5TLB\uff0c\u5982\u679c\u627e\u5230\u4e86\u5339\u914d\u7684\u6761\u76ee\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u88ab\u79f0\u4e3aTLB\u547d\u4e2d\uff0c\u53ef\u4ee5\u5feb\u901f\u5b8c\u6210\u5730\u5740\u8f6c\u6362\uff0c\u907f\u514d\u8bbf\u95ee\u4e3b\u5185\u5b58\u4e2d\u7684\u9875\u8868\uff0c\u4ece\u800c\u663e\u8457\u63d0\u5347\u6027\u80fd\u3002\u5f53\u53d1\u751fTLB\u672a\u547d\u4e2d\u7684\u60c5\u51b5\u65f6\uff0cCPU\u5fc5\u987b\u8bbf\u95ee\u4e3b\u5185\u5b58\u4e2d\u7684\u9875\u8868\u6765\u83b7\u53d6\u6b63\u786e\u7684\u7269\u7406\u5730\u5740\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u8f83\u5927\u7684\u6027\u80fd\u5f00\u9500\u3002\u56e0\u6b64\uff0c\u64cd\u4f5c\u7cfb\u7edf\u548c\u786c\u4ef6\u8bbe\u8ba1\u8005\u90fd\u4f1a\u5c3d\u91cf\u4f18\u5316TLB\u7684\u547d\u4e2d\u7387\uff0c\u4ee5\u51cf\u5c11\u8fd9\u79cd\u5f00\u9500\u3002
"},{"location":"linux/kernel/vma/#_2","title":"\u5730\u5740\u7a7a\u95f4\u7684\u6982\u5ff5","text":"\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u7531\u53ef\u5bfb\u5740\u7684\u865a\u62df\u5185\u5b58\u7ec4\u6210\uff0c\u572832\u4f4d\u4f53\u7cfb\u4e2d\uff08\u53ea\u8ba8\u8bba32\u4f4d\u67b6\u6784\uff0c64\u4f4d\u7c7b\u4f3c\uff09\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u53ef\u5bfb\u57404GB\u7684\u865a\u62df\u5185\u5b58\uff0c\u5176\u4e2d1GB\u5206\u914d\u7ed9\u5185\u6838\u7a7a\u95f4\uff0c\u5269\u4e0b3GB\u5206\u914d\u7ed9\u7528\u6237\u7a7a\u95f4\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u8bbf\u95ee\u6709\u6548\u5185\u5b58\u533a\u57df\u5185\u7684\u5185\u5b58\u5730\u5740\uff0c\u90e8\u5206\u5730\u5740\u662f\u975e\u6cd5\u7684\uff0c\u4e00\u65e6\u8bbf\u95ee\uff0c\u5c31\u4f1a\u7acb\u523b\u89e6\u53d1\u6bb5\u9519\u8bef\uff0c\u7531\u5185\u6838\u7ec8\u6b62\u8be5\u8fdb\u7a0b\u3002\u6bcf\u4e2a\u5185\u5b58\u533a\u57df\u4e5f\u6709\u76f8\u5173\u7684\u6743\u9650\uff0c\u6bd4\u5982\u53ef\u8bfb\u53ef\u5199\u53ef\u6267\u884c\u7b49\u3002
\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u7a7a\u95f4\u5206\u5e03\u5982\u4e0b\u56fe\u6240\u793a\uff1a
\u4ece\u4e0a\u56fe\u4e2d\u6211\u4eec\u770b\u5230\uff0c0x0000 0000\u52300x0804 8000\u8fd9\u6bb5\u7a7a\u95f4\u662f\u4e0d\u53ef\u8bbf\u95ee\u7684\u4fdd\u7559\u533a\uff0c\u5728\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6570\u503c\u6bd4\u8f83\u5c0f\u7684\u5730\u5740\u662f\u975e\u6cd5\u5730\u5740\uff0c\u4e0d\u5141\u8bb8\u8bbf\u95ee\u7684\u3002\u6bd4\u5982NULL\u6307\u9488\u5c31\u4f1a\u6307\u5411\u8fd9\u7247\u533a\u57df\u3002
0x0804 8000\u81f30xC000 0000\u662f\u7528\u6237\u6001\u7a7a\u95f4\u5730\u5740\uff0c\u518d\u7f51\u4e0a\u5c31\u662f\u6240\u8c13\u7684\u9ad8\u7aef\u5730\u5740\u2014\u2014\u4f9b\u5185\u6838\u4f7f\u7528\u3002\u5185\u6838\u6001\u4e0e\u7528\u6237\u6001\u7684\u5206\u754c\u7ebf\u7531\u6210\u5458\u53d8\u91cftask_size\u5b9a\u4e49\u3002
\u4fdd\u7559\u533a\u4e0a\u65b9\u662f\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5\uff0c\u5b83\u4eec\u662f\u4ece\u53ef\u6267\u884c\u6587\u4ef6\u76f4\u63a5\u52a0\u8f7d\u8fdb\u6765\u7684\u3002\u7f16\u8bd1\u540e\u7684\u4ee3\u7801\u653e\u5728\u4ee3\u7801\u6bb5\uff0c\u6570\u636e\u6bb5\u7528\u6765\u5b58\u653e\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u3002
BSS\u6bb5\u7528\u6765\u5b58\u653e\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u4ee50\u586b\u5145\u3002
BSS\u6bb5\u4e0a\u65b9\u662f\u5806\u7a7a\u95f4\uff0c\u5730\u5740\u7684\u589e\u957f\u65b9\u5411\u662f\u4ece\u4f4e\u5230\u9ad8\u3002\u5185\u6838\u4f7f\u7528start_brk
\u6807\u8bc6\u5806\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0cbrk
\u6807\u8bc6\u5806\u5f53\u524d\u7684\u7ed3\u675f\u4f4d\u7f6e\u3002\u5f53\u5806\u7533\u8bf7\u4e00\u5757\u5f88\u5c0f\u7684\u5185\u5b58\uff08128K\u4ee5\u5185\uff09\uff0c\u53ea\u9700\u8981\u5c06brk
\u6307\u9488\u589e\u52a0\u5bf9\u5e94\u7684\u5927\u5c0f\u5373\u53ef\u3002\u5806\u5185\u5b58\u7684\u7ba1\u7406\u6bd4\u8f83\u590d\u6742\uff0c\u5806\u5185\u5b58\u6700\u5927\u7684\u56f0\u96be\u5c31\u662f\u9891\u7e41\u5730\u5206\u914d\u548c\u91ca\u653e\u4f1a\u9020\u6210\u5185\u5b58\u788e\u7247\u3002\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u4e2a\u95ee\u9898\uff0c\u5185\u6838\u91c7\u7528\u4e86\u57fa\u4e8e\u4f19\u4f34\u7cfb\u7edf\u7684\u5185\u5b58\u5206\u914d\u7b97\u6cd5\u3002
\u5806\u7a7a\u95f4\u4e0a\u65b9\u662f\u5f85\u5206\u914d\u533a\u57df\uff0c\u7528\u6765\u6269\u5c55\u5806\u7a7a\u95f4\u7684\u4f7f\u7528\u3002\u63a5\u4e0b\u6765\u662f\u5185\u5b58\u6620\u5c04\u533a\u57df\u3002\u4efb\u4f55\u5e94\u7528\u7a0b\u5e8f\u90fd\u53ef\u4ee5\u901a\u8fc7mmap()
\u7cfb\u7edf\u8c03\u7528\u6620\u5c04\u81f3\u6b64\u533a\u57df\u3002\u5185\u5b58\u6620\u5c04\u53ef\u4ee5\u7528\u6765\u52a0\u8f7d\u52a8\u6001\u5e93\uff0c\u6bd4\u5982 ld-linux.so \u5c31\u88ab\u52a0\u8f7d\u4e8e\u6b64\uff0c\u53e6\u5916\uff0c\u5982\u679c\u4f60\u901a\u8fc7malloc()
\u7533\u8bf7\u4e86\u8d85\u8fc7128K\u5185\u5b58\uff0c\u5185\u6838\u5c06\u76f4\u63a5\u4e3a\u4f60\u5206\u914d\u4e00\u5757\u6620\u5c04\u533a\u57df\u4f5c\u4e3a\u5185\u5b58\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u5806\u5185\u5b58\u3002
\u6700\u540e\u4e00\u5757\u533a\u57df\u662f\u6808\u7a7a\u95f4\uff0c\u5728\u8fd9\u91cc\u4fdd\u5b58\u51fd\u6570\u8fd0\u884c\u8fc7\u7a0b\u9700\u8981\u7684\u5c40\u90e8\u53d8\u91cf\u4ee5\u53ca\u51fd\u6570\u53c2\u6570\u7b49\u4fe1\u606f\u3002\u6808\u7a7a\u95f4\u7684\u5730\u5740\u662f\u4ece\u9ad8\u5230\u4f4e\u589e\u957f\u7684\u3002\u5185\u6838\u4f7f\u7528start_stack
\u6807\u8bc6\u6808\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002SP\u5bc4\u5b58\u5668\u4fdd\u5b58\u6808\u9876\u6307\u9488\uff0cBP\u5bc4\u5b58\u5668\u4fdd\u5b58\u6808\u57fa\u5730\u5740\u3002
"},{"location":"linux/kernel/vma/#mm_struct","title":"\u5185\u5b58\u63cf\u8ff0\u7b26mm_struct","text":"mm_struct
\u7528\u6765\u8868\u793a\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u7684\u4fe1\u606f\uff0c\u5b9a\u4e49\u5728\u6587\u4ef6<linux/mm_types.h>\u4e2d\uff1a
struct mm_struct {\n atomic_t mm_users;\n atomic_t mm_count;\n struct vm_area_struct *mmap;\n struct rb_root mm_rb;\n struct list_head mmlist;\n\n unsigned long start_code, end_code; //\u4ee3\u7801\u6bb5\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long start_data, end_data; //\u6570\u636e\u6bb5\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long start_brk, brk, //\u5806\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long start_stack; //\u6808\u7684\u8d77\u59cb\u5730\u5740\n unsigned long arg_start, arg_end, //\u547d\u4ee4\u884c\u53c2\u6570\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long env_start, env_end; //\u73af\u5883\u53d8\u91cf\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long mmap_base; //\u5185\u5b58\u6620\u5c04\u533a\u7684\u8d77\u59cb\u5730\u5740\n unsigned long total_vm; //\u603b\u5171\u6620\u5c04\u7684\u9875\u6570\u76ee\n unsigned long locked_vm; //\u88ab\u9501\u5b9a\u4e0d\u80fd\u6362\u51fa\u7684\u9875\u6570\u76ee\n unsigned long pinned_vm; //\u65e2\u4e0d\u80fd\u6362\u51fa\uff0c\u4e5f\u4e0d\u80fd\u79fb\u52a8\u7684\u9875\u6570\u76ee\n unsigned long data_vm; //\u6570\u636e\u6bb5\u4e2d\u6620\u5c04\u7684\u9875\u6570\u76ee\n unsigned long exec_vm; //\u4ee3\u7801\u6bb5\u4e2d\u53ef\u6267\u884c\u6587\u4ef6\u7684\u9875\u6570\u76ee\n unsigned long stack_vm; //\u6808\u4e2d\u6620\u5c04\u7684\u9875\u6570\u76ee\n};\n
mm_users\u8bb0\u5f55\u6b63\u5728\u4f7f\u7528\u8be5\u5730\u5740\u7684\u8fdb\u7a0b\u6570\u76ee\uff0c\u6bd4\u5982\u5982\u679c\u6709\u4e24\u4e2a\u7ebf\u7a0b\u5171\u4eab\u8be5\u5730\u5740\u7a7a\u95f4\uff0c\u90a3\u4e48mm_users\u7684\u503c\u4fbf\u7b49\u4e8e2\u3002mm_count\u662fmm_struct\u7ed3\u6784\u4f53\u7684\u4e3b\u5f15\u7528\u8ba1\u6570\uff0c\u5f53\u503c\u4e3a0\u65f6\uff0c\u8be5\u7ed3\u6784\u4f53\u4f1a\u88ab\u91ca\u653e\u3002
mmap\u4f7f\u7528\u5355\u72ec\u94fe\u8868\u8fde\u63a5\u6240\u6709\u7684\u5185\u5b58\u533a\u57df\u5bf9\u8c61\u3002\u6bcf\u4e00\u4e2avm_area_struct
\u7ed3\u6784\u4f53\u901a\u8fc7\u81ea\u8eab\u7684vm_next\u6307\u9488\u88ab\u8fde\u5165\u94fe\u8868\u3002mmap\u6307\u5411\u94fe\u8868\u4e2d\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002
mm_rb\u5219\u4f7f\u7528\u7ea2\u9ed1\u6811\u3002mm_rb\u6307\u5411\u6839\u8282\u70b9\uff0c\u6bcf\u4e00\u4e2avm_area_struc
\u7ed3\u6784\u4f53\u901a\u8fc7\u81ea\u8eab\u7684vm_rb\u8fde\u63a5\u5230\u6811\u4e2d\u3002
\u5728\u8fdb\u7a0b\u7ba1\u7406\u4e0e\u8c03\u5ea6\u4e2d\u6211\u4eec\u4ecb\u7ecd\u4e86mm\u53d8\u91cf\uff0c\u7528\u6765\u5b58\u653e\u8be5\u8fdb\u7a0b\u4f7f\u7528\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\uff0ccurrent->mm
\u5c31\u6307\u5411\u5f53\u524d\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002fork()
\u51fd\u6570\u5229\u7528copy_mm()
\u51fd\u6570\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002\u5982\u679c\u7236\u5b50\u8fdb\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4\uff0c\u5219\u5728\u8c03\u7528clone()
\u65f6\uff0c\u8bbe\u7f6eCLONE_VM\u6807\u5fd7\uff0c\u8fd9\u6837\u7684\u8fdb\u7a0b\u5c31\u662f\u7ebf\u7a0b\u3002\u5728Linux\u73af\u5883\u4e0b\uff0c\u662f\u5426\u5171\u4eab\u5730\u5740\u7a7a\u95f4\u51e0\u4e4e\u662f\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u672c\u8d28\u4e0a\u7684\u552f\u4e00\u533a\u522b\u3002\u5982\u679c\u6307\u5b9a\u4e86CLONE_VM,\u7ebf\u7a0b\u5c31\u4e0d\u9700\u8981\u53e6\u5916\u5206\u914d\u5730\u5740\u7a7a\u95f4\u4e86\uff0c\u800c\u662f\u76f4\u63a5\u5c06mm\u57df\u76f4\u63a5\u6307\u5411\u7236\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u5373\u53ef\u3002
\u5185\u6838\u7ebf\u7a0b\u6ca1\u6709\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\uff0c\u4e5f\u6ca1\u6709\u76f8\u5173\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\uff0c\u5176mm\u57df\u4e3aNULL\u3002\u5f53\u4e00\u4e2a\u5185\u6838\u7ebf\u7a0b\u88ab\u8c03\u5ea6\u65f6\uff0c\u5b83\u4f1a\u76f4\u63a5\u4f7f\u7528\u524d\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002
"},{"location":"linux/kernel/vma/#_3","title":"\u865a\u62df\u5185\u5b58\u533a\u57df","text":"\u865a\u62df\u5185\u5b58\u533a\u57df\uff08Virtual Memory Area, VMA\uff09\u5728\u5185\u6838\u4e2d\u7528vm_area_struct
\u7ed3\u6784\u4f53\u63cf\u8ff0\u3002\u6bcf\u4e2avm_area_struct
\u7ed3\u6784\u90fd\u5bf9\u5e94\u4e8e\u6307\u5b9a\u5730\u5740\u7a7a\u95f4\u4e0a\u67d0\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002vm_start\u6307\u5411\u4e86\u8fd9\u5757\u865a\u62df\u5185\u5b58\u533a\u57df\u7684\u8d77\u59cb\u5730\u5740\uff0cvm_end\u6307\u5411\u4e86\u8fd9\u5757\u865a\u62df\u5185\u5b58\u533a\u57df\u7684\u7ed3\u675f\u5730\u5740\u3002vm_area_struct
\u7ed3\u6784\u4f53\u63cf\u8ff0\u7684\u662f[vm_start\uff0cvm_end)\u8fd9\u6837\u4e00\u6bb5\u5de6\u95ed\u53f3\u5f00\u7684\u865a\u62df\u5185\u5b58\u533a\u57df\u3002
\u5185\u6838\u5c06\u6bcf\u4e2a\u5185\u5b58\u533a\u57df\u4f5c\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684\u5185\u5b58\u5bf9\u8c61\u7ba1\u7406\uff0c\u6bcf\u4e2a\u533a\u57df\u53c8\u4e00\u81f4\u7684\u5c5e\u6027\u548c\u64cd\u4f5c\uff0c\u4e0b\u9762\u7ed9\u51favm_area_struct
\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\uff1a
struct vm_area_struct {\n struct mm_struct *vm_mm; //\u76f8\u5173\u7684mm_struct\u7ed3\u6784\u4f53\n unsigned long vm_start; //\u533a\u95f4\u7684\u9996\u5730\u5740\n unsigned long vm_end; //\u533a\u95f4\u7684\u5c3e\u5730\u5740\n struct vm_area_struct *vm_next; //VMA\u94fe\u8868\n pgprot_t vm_page_prot; //\u8bbf\u95ee\u63a7\u5236\u6743\u9650\n unsigned long vm_flags; //\u6807\u5fd7\u4f4d\n struct rb_node vm_rb; //\u7ea2\u9ed1\u6811\u8282\u70b9\n struct anon_vma *anon_vma; //\u533f\u540dVMA\u5bf9\u8c61\n const struct vm_operations_struct *vm_ops; //VMA\u7684\u64cd\u4f5c\u51fd\u6570\n unsigned long vm_pgoff; //\u6587\u4ef6\u4e2d\u7684\u504f\u79fb\u91cf\n struct file *vm_file; //\u88ab\u6620\u5c04\u7684\u6587\u4ef6\n void *vm_private_data; //\u79c1\u6709\u6570\u636e\n};\n
\u6bcf\u4e2a\u5185\u5b58\u63cf\u8ff0\u7b26\u5bf9\u5e94\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u4e2d\u7684\u552f\u4e00\u7a7a\u95f4\uff0c\u8303\u56f4\u662f[vm_start, vm_end)\u3002vm_mm\u6307\u5411\u4e0eVMA\u76f8\u5173\u7684mm_struct
\u7ed3\u6784\u4f53\uff0cvm_next\u8d1f\u8d23\u5c06VMA\u4e32\u8054\u6210\u94fe\u8868\u3002
"},{"location":"linux/kernel/vma/#vma","title":"VMA\u6807\u5fd7","text":"vm_flags\u5b9a\u4e49\u4e86VMA\u7684\u6807\u5fd7\uff0c\u5b83\u8868\u793a\u5185\u5b58\u533a\u57df\u7684\u884c\u4e3a\u548c\u4fe1\u606f\u3002\u4e00\u4e9b\u6bd4\u8f83\u91cd\u8981\u7684\u6807\u5fd7\u6bd4\u5982\uff1aVM_READ\u3001VM_WRITE\u548cVM_EXEC\u6807\u5fd7\u4e86\u5185\u5b58\u533a\u57df\u4e2d\u9875\u9762\u7684\u53ef\u8bfb\u3001\u53ef\u5199\u3001\u53ef\u6267\u884c\u6743\u9650\u3002\u5f53\u8bbf\u95eeVMA\u65f6\uff0c\u9700\u8981\u67e5\u770b\u5176\u8bbf\u95ee\u6743\u9650\u3002
VM_SHARED\u8868\u793a\u5185\u5b58\u533a\u57df\u5305\u542b\u7684\u6620\u5c04\u662f\u5426\u53ef\u4ee5\u5728\u591a\u8fdb\u7a0b\u4e4b\u95f4\u5171\u4eab\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86\u8be5\u6807\u5fd7\u4f4d\uff0c\u6211\u4eec\u79f0\u5176\u4f4d\u5171\u4eab\u6620\u5c04\uff0c\u5426\u5219\u5c31\u662f\u79c1\u6709\u6620\u5c04\u3002
VM_IO\u6807\u5fd7\u5185\u5b58\u533a\u57df\u4e2d\u5bf9\u8bbe\u5907I/O\u7a7a\u95f4\u7684\u6620\u5c04\u3002\u8be5\u6807\u5fd7\u901a\u5e38\u5728\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u6267\u884cmmap()
\u51fd\u6570\u65f6\u624d\u88ab\u8bbe\u7f6e\u3002VM_RESERVED\u6807\u5fd7\u89c4\u5b9a\u4e86\u5185\u5b58\u533a\u57df\u4e0d\u80fd\u88ab\u6362\u51fa\u3002
"},{"location":"linux/kernel/vma/#vma_1","title":"VMA\u64cd\u4f5c","text":"vm_ops\u57df\u6307\u5411\u4e0e\u5185\u5b58\u533a\u57df\u76f8\u5173\u7684\u64cd\u4f5c\u51fd\u6570\uff0c\u7531vm_operations_struct
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct vm_operations_struct {\n void (*open)(struct vm_area_struct *);\n void (*close)(sturct vm_area_struct *);\n int (*fault)(struct vm_area_struct *, struct vm_fault *);\n int (*page_mkwrite)(struct vm_area_struct *vma, struct vm_fault *vmf);\n int (*access)(struct vm_area_struct *, unsigned long, void *, int, int);\n};\n
"},{"location":"linux/kernel/vma/#malloc","title":"malloc()\u539f\u7406","text":"malloc()
\u662fC\u5e93\u91cc\u7684\u4e00\u4e2a\u52a8\u6001\u5206\u914d\u5185\u5b58\u7684\u51fd\u6570\uff0c\u7533\u8bf7\u5185\u5b58\u65f6\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a
\u65b9\u5f0f\u4e00\uff1a\u901a\u8fc7brk()
\u7cfb\u7edf\u8c03\u7528\u4ece\u5806\u5206\u914d\u5185\u5b58\u3002
\u65b9\u5f0f\u4e8c\uff1a\u901a\u8fc7mmap()
\u7cfb\u7edf\u8c03\u7528\u4ece\u6587\u4ef6\u6620\u5c04\u533a\u5206\u914d\u5185\u5b58\u3002
\u7b2c\u4e00\u79cd\u65b9\u5f0f\u5f88\u7b80\u5355\uff0c\u901a\u8fc7\u7b80\u5355\u5730\u8c03\u6574brk\u6307\u9488\u5411\u9ad8\u5730\u5740\u79fb\u52a8\uff0c\u5373\u5b8c\u6210\u4e86\u5185\u5b58\u5206\u914d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u76f4\u63a5\u5728\u6587\u4ef6\u6620\u5c04\u533a\u6620\u5c04\u4e00\u5757\u5185\u5b58\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
malloc()
\u6e90\u7801\u89c4\u5b9a\u4e86\u4e00\u4e2a\u9608\u503c\uff1a
\u5982\u679c\u5206\u914d\u7684\u5185\u5b58\u5c0f\u4e8e\u8fd9\u4e2a\u9608\u503c\uff0c\u5219\u901a\u8fc7brk()
\u7533\u8bf7\u5185\u5b58\u3002
\u5982\u679c\u5206\u914d\u7684\u5185\u5b58\u5927\u4e8e\u8fd9\u4e2a\u9608\u503c\uff0c\u5219\u901a\u8fc7mmap()
\u7533\u8bf7\u5185\u5b58\u3002
\u8bbe\u8ba1\u5185\u5b58\u5206\u914d\u7b56\u7565\u65f6\uff0c\u6838\u5fc3\u76ee\u6807\u662f\u5728\u6027\u80fd\u548c\u8d44\u6e90\u7ba1\u7406\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u5e73\u8861\u70b9\u3002\u5bf9\u4e8e\u5c0f\u5185\u5b58\u5757\u7684\u9891\u7e41\u5206\u914d\u4e0e\u91ca\u653e\u64cd\u4f5c\uff0cmalloc()
\u91c7\u7528 brk()
\u7cfb\u7edf\u8c03\u7528\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\u3002\u91ca\u653e\u7684\u5185\u5b58\u5e76\u4e0d\u4f1a\u7acb\u5373\u8fd4\u56de\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u800c\u662f\u88ab\u7f13\u5b58\u81f3\u5185\u5b58\u6c60\u4e2d\uff0c\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7684\u5206\u914d\u8bf7\u6c42\u80fd\u591f\u5feb\u901f\u91cd\u7528\u8fd9\u4e9b\u5df2\u91ca\u653e\u7684\u5185\u5b58\u5757\uff0c\u4ece\u800c\u51cf\u5c11\u7cfb\u7edf\u8c03\u7528\u7684\u6b21\u6570\u548c\u76f8\u5173\u7684\u6027\u80fd\u5f00\u9500\u3002
\u5bf9\u4e8e\u5927\u5185\u5b58\u5757\u7684\u5206\u914d\uff0cmalloc
\u5219\u53ef\u80fd\u4f7f\u7528 mmap()
\u7cfb\u7edf\u8c03\u7528\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u9996\u6b21\u8bbf\u95ee\u65f6\u53ef\u80fd\u4f1a\u89e6\u53d1\u7f3a\u9875\u4e2d\u65ad\uff0c\u56e0\u4e3a\u5206\u914d\u7684\u5185\u5b58\u521d\u59cb\u5904\u4e8e\u672a\u6620\u5c04\u72b6\u6001\uff0c\u9700\u8981\u64cd\u4f5c\u7cfb\u7edf\u4ecb\u5165\u4ee5\u5efa\u7acb\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04\u3002\u8fd9\u4e00\u673a\u5236\u76f8\u8f83\u4e8e brk()
\u7cfb\u7edf\u8c03\u7528\uff0c\u4f1a\u5e26\u6765\u66f4\u9ad8\u7684\u6027\u80fd\u6210\u672c\u3002
"},{"location":"others/","title":"\u4e0d\u592a\u597d\u5206\u7c7b\u7684\u653e\u8fd9","text":""},{"location":"others/#_2","title":"\u53c2\u8003\u8d44\u6599","text":" \u7a0b\u5e8f\u5458\u7684\u81ea\u6211\u4fee\u517b "},{"location":"others/ld/","title":"\u4ece\u4ee3\u7801\u5230\u53ef\u6267\u884c\u6587\u4ef6","text":""},{"location":"others/ld/#gcc","title":"gcc\u7f16\u8bd1\u6b65\u9aa4","text":""},{"location":"others/ld/#_2","title":"\u7a0b\u5e8f\u7684\u94fe\u63a5\u4e0e\u88c5\u8f7d","text":""},{"location":"others/ld/#_3","title":"\u7a0b\u5e8f\u7684\u4e8c\u8fdb\u5236\u683c\u5f0f","text":"\u7ecf\u8fc7\u9884\u5904\u7406\u3001\u7f16\u8bd1\u3001\u6c47\u7f16\u4ee5\u540e\uff0c.c\u6587\u4ef6\u88ab\u7f16\u8bd1\u6210\u4e86.o\u6587\u4ef6\uff0c\u53c8\u53eb\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\uff0c\u8fd9\u662fELF\u683c\u5f0f\u7684\u4e00\u79cd\u3002\u8fd9\u4e2a\u6587\u4ef6\u683c\u5f0f\u662f\u8fd9\u6837\u7684\u3002
\u5176\u4e2dELF Header\u8bb0\u5f55\u4e00\u4e2a\u4e2asection\u7684\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528readelf -h
\u67e5\u770b\u4e00\u4e2a.o\u6587\u4ef6\u7684Header\u4fe1\u606f\u3002\u8fd9\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\u91cc\u5b58\u653e\u7740\u7a0b\u5e8f\u7684\u4ee3\u7801\u4ee5\u53ca\u53d8\u91cf\u7b49\u7b49\u4fe1\u606f\u3002
.text\uff1a\u5b58\u653e\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u3002
.rodata\uff1a\u5b58\u653e\u53ea\u8bfb\u6570\u636e\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32\u5e38\u91cf\u3002
.data\uff1a\u5b58\u653e\u5df2\u7ecf\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u3002
.bss\uff1a\u5b58\u653e\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\uff0c\u5168\u90e8\u7f6e\u4e3a0.
.symtab\uff1a\u7b26\u53f7\u8868\uff0c\u5b58\u653e\u7684\u662f\u51fd\u6570\u548c\u53d8\u91cf\u7684\u7b26\u53f7\u4fe1\u606f\u3002
.rel.text\uff0c.rel.data\uff1a\u5b58\u653e\u9700\u8981\u91cd\u5b9a\u4f4d\u7684\u51fd\u6570\u548c\u53d8\u91cf\u3002
.strtab\uff1a\u5b57\u7b26\u4e32\u8868\uff0c\u6bd4\u5982\u51fd\u6570\u540d\u3001\u53d8\u91cf\u540d\u3002
\u8fd9\u4e9bsection\u7684\u6570\u636e\u4fe1\u606f\u4fdd\u5b58\u5728Section Header Table
\u91cc\u3002\u4e3a\u4ec0\u4e48\u53eb\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\uff0c\u56e0\u4e3a\u7f16\u8bd1\u6210.o\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u4e86\u4e00\u4e9b\u5916\u90e8\u51fd\u6570\u6216\u8005\u53d8\u91cf\uff0c\u6b64\u65f6\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e9b\u51fd\u6570\u6216\u53d8\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\uff0c\u6240\u4ee5\u9700\u8981\u5728.o\u6587\u4ef6\u4e2d\u8bf4\u660e\u8fd9\u4e9b\u7b26\u53f7\u5c06\u6765\u662f\u9700\u8981\u91cd\u65b0\u5b9a\u4f4d\u7684\u3002
"},{"location":"others/ld/#_4","title":"\u9759\u6001\u5e93\u4e0e\u52a8\u6001\u5e93","text":"\u6211\u4eec\u53ef\u4ee5\u5c06\u4e00\u4e2a\u4e2a.o\u6587\u4ef6\u6253\u5305\u6210\u5e93\u6587\u4ef6\u7684\u5f62\u5f0f\uff0c\u4f9b\u5176\u4ed6\u7a0b\u5e8f\u8c03\u7528\u3002\u5f62\u6210\u7684\u4e8c\u8fdb\u5236\u683c\u5f0f\u53eb\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u662fELF\u6587\u4ef6\u7684\u7b2c\u4e8c\u79cd\u5f62\u5f0f\u3002\u5b83\u7684\u7ed3\u6784\u5982\u4e0b\u3002
\u8fd9\u4e2a\u683c\u5f0f\u4e0e\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u5728\u94fe\u63a5\u7684\u8fc7\u7a0b\u4e2d\uff0c\u90e8\u5206section\u5408\u5e76\u4e86\u3002\u6bd4\u5982\u90fd\u662f\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u90a3\u5c31\u4e00\u8d77\u5408\u5e76\u5230.text\u6bb5\u4e2d\u53bb\u3002\u5c0f\u7684section\u5408\u5e76\u6210\u4e3a\u4e86\u5927\u7684segment\u3002\u5728ELF\u5934\u91cc\u9762\uff0c\u6709\u4e2a\u53ebe_entry\u7684\u865a\u62df\u5730\u5740\uff0c\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u5730\u5740\u3002\u5f53\u9759\u6001\u5e93\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u94fe\u63a5\u5728\u4e00\u8d77\u65f6\uff0c\u4f1a\u628a\u9759\u6001\u5e93\u7684\u4fe1\u606f\u5408\u5e76\u8fdb\u53bb\uff0c\u5f62\u6210\u4e00\u4e2a\u66f4\u5927\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8fd9\u6837\u7684\u597d\u5904\u5c31\u662f\u8be5\u7a0b\u5e8f\u6267\u884c\u7684\u65f6\u5019\u4e0d\u4f9d\u8d56\u4e8e\u9759\u6001\u5e93\u6587\u4ef6\u3002\u574f\u5904\u5c31\u662f\uff0c\u6709\u5176\u4ed6\u9700\u8981\u94fe\u63a5\u7684\u6587\u4ef6\uff0c\u540c\u6837\u4f1a\u590d\u5236\u4e00\u4efd\u4fe1\u606f\u5230\u5185\u5b58\uff0c\u9020\u6210\u4e86\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002\u5f53\u9759\u6001\u5e93\u66f4\u65b0\u540e\uff0c\u5982\u679c\u4e0d\u91cd\u65b0\u8fdb\u884c\u7f16\u8bd1\uff0c\u7a0b\u5e8f\u5c31\u65e0\u6cd5\u8fd0\u884c\u4e86\u3002\u4e3a\u4e86\u89e3\u51b3\u7a7a\u95f4\u6d6a\u8d39\u4ee5\u53ca\u7a0b\u5e8f\u6269\u5c55\u6027\u5dee\u7684\u95ee\u9898\uff0c\u52a8\u6001\u5e93\u5c31\u51fa\u73b0\u4e86\u3002\u52a8\u6001\u5e93\u4e5f\u662fELF\u6587\u4ef6\u7684\u7b2c\u4e09\u79cd\u5f62\u5f0f\u2014\u2014\u5171\u4eab\u5bf9\u8c61\u6587\u4ef6\u3002
\u5f53\u52a8\u6001\u5e93\u88ab\u94fe\u63a5\u5230\u7a0b\u5e8f\u4e2d\u53bb\u65f6\uff0c\u53ea\u4fdd\u7559\u4e86\u5bf9\u52a8\u6001\u5e93\u7684\u5f15\u7528\uff0c\u5e76\u4e14\u4e00\u4e2a\u52a8\u6001\u5e93\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5f15\u7528\u3002\u800c\u4e3a\u4e86\u5728\u8fd0\u884c\u65f6\u786e\u5b9a\u51fd\u6570\u4f4d\u7f6e\uff0c\u57fa\u4e8e\u52a8\u6001\u5e93\u94fe\u63a5\u7684.so\u6587\u4ef6\u591a\u4e86\u4e00\u4e9b\u4fe1\u606f\u3002\u9996\u5148\u662f\u4e00\u4e2a\u53eb.interp\u7684\u6bb5\uff0c\u8fd9\u91cc\u9762\u662fld-linux.so\uff0c\u8fd9\u662f\u52a8\u6001\u94fe\u63a5\u5668\uff0c\u8fd0\u884c\u65f6\u7684\u94fe\u63a5\u52a8\u4f5c\u90fd\u662f\u5b83\u505a\u7684\u3002\u53e6\u5916\u8fd8\u591a\u4e86\u4e24\u4e2asection\uff0c\u4e00\u4e2a\u662f.plt\uff0c\u8fc7\u7a0b\u94fe\u63a5\u8868\uff0c\u4e00\u4e2a\u662f.got\uff0c\u5168\u5c40\u504f\u79fb\u91cf\u8868\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u51fd\u6570func()
\u9700\u8981\u91cd\u5b9a\u4f4d\uff0c\u7531\u4e8e\u4ee3\u7801\u6bb5\u662f\u4e0d\u53ef\u5199\u7684\uff0c\u6240\u4ee5\u5728\u94fe\u63a5\u8fc7\u7a0b\u4e2d\uff0c\u65e0\u6cd5\u5c06\u5176\u5b9e\u9645\u5730\u5740\u5199\u5165\u3002\u89e3\u51b3\u529e\u6cd5\u662f\u7528\u4e86\u4e00\u4e2a\u5c0f\u6280\u5de7\uff0c\u5728\u6c47\u7f16\u6307\u4ee4\u4e2d\uff0c\u5f53\u6267\u884c\u5230func()
\u51fd\u6570\u65f6\uff0c\u544a\u8bc9\u7a0b\u5e8f\u4f60\u8981\u53bbPLT[x]\u4f4d\u7f6e\u5904\u53bb\u5bfb\u627efunc\u51fd\u6570\u7684\u4f4d\u7f6e\u3002\u800cPLT[X]\u53c8\u544a\u8bc9\u7a0b\u5e8f\u4f60\u8981\u53bbGOT[Y]\u7684\u5730\u65b9\u53bb\u627e\u51fd\u6570\u4f4d\u7f6e\u3002\u5f53\u7b2c\u4e00\u6b21\u6267\u884c\u65f6\uff0cGOT[Y]\u91cc\u7684\u4f4d\u7f6e\u4fe1\u606f\u662f\u7a7a\u7684\uff0c\u4e8e\u662fGOT\u544a\u8bc9PLT\uff0c\u6211\u8fd9\u91cc\u6ca1\u6709\u5b9a\u4f4d\u4fe1\u606f\u3002PLT\u6536\u5230\u8fd9\u4e2a\u4fe1\u606f\u4e4b\u540e\uff0c\u8c03\u7528PLT[0]\uff0cPLT[0]\u8f6c\u800c\u8c03\u7528GOT[2]\uff0c\u8fd9\u91cc\u9762\u4fdd\u5b58\u7684\u662f\u94fe\u63a5\u5668\u7684\u5165\u53e3\u5730\u5740\u3002\u94fe\u63a5\u5668\u4f1a\u627e\u5230func()
\u51fd\u6570\u7684\u5165\u53e3\u5730\u5740\uff0c\u7136\u540e\u628a\u8fd9\u4e2a\u5730\u5740\u5199\u5165\u5230GOT[Y]\u4e2d\uff0c\u90a3\u4e48\u4e0b\u6b21\u518d\u8c03\u7528func()
\u51fd\u6570\u65f6\uff0c\u5c31\u4e0d\u9700\u8981\u4ee5\u4e0a\u8fd9\u4e48\u9ebb\u70e6\u7684\u6b65\u9aa4\u4e86\uff0c\u56e0\u4e3a\u51fd\u6570\u7684\u5730\u5740\u5df2\u7ecf\u5199\u5728\u4e86GOT\u8868\u4e2d\u3002
"},{"location":"others/ld/#_5","title":"\u7a0b\u5e8f\u7684\u88c5\u8f7d","text":"\u901a\u8fc7execv()
\u7cfb\u7edf\u8c03\u7528\uff0c\u6267\u884cload_elf_binary()
\u51fd\u6570\uff0c\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u88c5\u8f7d\u5230\u5185\u5b58\u4e2d\u3002
\u5177\u4f53\u5b9e\u73b0\u7ec6\u8282\u5f85\u5b9a\u3002
"},{"location":"pl/","title":"\u7f16\u7a0b\u7684\u5fc3\u5f97\u4f53\u4f1a","text":""},{"location":"rtos/","title":"RTOS","text":"RTOS\u5b66\u4e60\u7b14\u8bb0\uff0c\u5305\u62ecFreeRTOS\u548cRT-Thread
"},{"location":"rtos/#_1","title":"\u53c2\u8003\u8d44\u6599","text":" freertos doc rt-thread\u6587\u6863\u4e2d\u5fc3 \u5d4c\u5165\u5f0f\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edfRT-Thread\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 "},{"location":"rtos/freertos/","title":"\u7b80\u660e\u5165\u95e8","text":"\u5927\u591a\u6570\u7684\u64cd\u4f5c\u7cfb\u7edf\u90fd\u80fd\u540c\u65f6\u6267\u884c\u591a\u4e2a\u7a0b\u5e8f\uff0c\u8fd9\u88ab\u79f0\u4e3a\u591a\u4efb\u52a1\u5904\u7406\u3002\u5b9e\u9645\u4e0a\uff0c\u6bcf\u4e2a\u5904\u7406\u5668\u6838\u5fc3\u5728\u7ed9\u5b9a\u65f6\u95f4\u7247\u5185\u53ea\u80fd\u8fd0\u884c\u5355\u4e2a\u4efb\u52a1\u3002CPU\u901a\u8fc7\u5feb\u901f\u5207\u6362\u65f6\u95f4\u7247\u9020\u6210\u591a\u4e2a\u4efb\u52a1\u540c\u65f6\u6267\u884c\u7684\u5047\u8c61\u3002 \u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf(RTOS)\u4e2d\u7684\u4efb\u52a1\u8c03\u5ea6\u5668\u65e8\u5728\u63d0\u4f9b\u53ef\u9884\u6d4b\u7684\u6267\u884c\u6a21\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u5bf9\u5d4c\u5165\u5f0f\u7cfb\u7edf\u610f\u4e49\u91cd\u5927\uff0c\u56e0\u4e3a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f80\u5f80\u6709\u5b9e\u65f6\u6027\u7684\u8981\u6c42\uff0c\u6bd4\u5982\u6211\u8981\u6c42\u57283\u79d2\u5185\u53d1\u51fa\u8b66\u62a5\u58f0\u3002
\u4f7f\u7528STM32CubeMX\u521b\u5efa\u7684FreeRTOS\u5de5\u7a0b\u4e2d\uff0c\u6e90\u7801\u4e3b\u8981\u6d89\u53ca\u4e24\u4e2a\u76ee\u5f55\uff1a
Core Inc\u76ee\u5f55\u4e0b\u7684FreeRTOSConfig.h\u662f\u914d\u7f6e\u6587\u4ef6 Src\u76ee\u5f55\u4e0b\u7684freertos.c\u662fSTM32CubeMX\u521b\u5efa\u7684\u9ed8\u8ba4\u4efb\u52a1 Middlewares/Thirt_Party/FreeRTOS/Source \u6839\u76ee\u5f55\u4e0b\u662f\u6838\u5fc3\u6587\u4ef6\uff0c\u8fd9\u4e9b\u6587\u4ef6\u662f\u901a\u7528\u7684 portable\u76ee\u5f55\u4e0b\u662f\u79fb\u690d\u65f6\u9700\u8981\u7684\u6587\u4ef6\uff1aport.c\u548cportmacro.h \u76ee\u5f55\u540d\u4e3a\uff1a[compiler]/[architecture] \u6bd4\u5982\uff1aRVDS/ARM-CM3\uff0c\u8fd9\u8868\u793acortexM3\u67b6\u6784\u5728RVDS\u5de5\u5177\u4e0a\u7684\u79fb\u690d\u6587\u4ef6 FreeRTOS/Srouce/ \u4f5c\u7528 tasks.c \u5fc5\u987b\uff0c\u4efb\u52a1\u64cd\u4f5c list.c \u5fc5\u987b\uff0c \u5217\u8868 queue.c \u57fa\u672c\u5fc5\u987b\uff0c\u63d0\u4f9b\u961f\u5217\u64cd\u4f5c\u3001\u4fe1\u53f7\u91cf timer.c \u53ef\u9009\uff0c\u63d0\u4f9b\u5b9a\u65f6\u5668 event_groups.c \u53ef\u9009\uff0c\u63d0\u4f9bevent group\u529f\u80fd croutine.c \u53ef\u9009\uff0c\u5df2\u8fc7\u65f6 \u5934\u6587\u4ef6\u76ee\u5f55\u9700\u8981\u5305\u542b\uff1a
\u6570\u636e\u7c7b\u578b\uff1a
\u5728portmacro.h\u5934\u6587\u4ef6\u91cc\uff0c\u5b9a\u4e49\u4e86\u4e24\u4e2a\u6570\u636e\u7c7b\u578b\uff1a
TickType_t\uff1a FreeRTOS\u914d\u7f6e\u4e86\u4e00\u4e2a\u5468\u671f\u6027\u7684\u65f6\u949f\u4e2d\u65ad\uff1aTick Interrupt \u6bcf\u53d1\u751f\u4e00\u6b21\u4e2d\u65ad\uff0c\u4e2d\u65ad\u6b21\u6570\u7d2f\u52a0\uff0c\u8fd9\u88ab\u79f0\u4e3atick count tick count\u8fd9\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b\u5c31\u662fTickType_t TickType_t\u53ef\u4ee5\u662f16\u4f4d\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f32\u4f4d\u7684 FreeRTOSConfig.h\u4e2d\u5b9a\u4e49configUSE_16_BIT_TICKS\u65f6\uff0cTickType_t\u5c31\u662fuint16_t \u5426\u5219TickType_t\u5c31\u662fuint32_t \u5bf9\u4e8e32\u4f4d\u67b6\u6784\uff0c\u5efa\u8bae\u628aTickType_t\u914d\u7f6e\u4e3auint32_t BaseType_t\uff1a \u8fd9\u662f\u8be5\u67b6\u6784\u6700\u9ad8\u6548\u7684\u6570\u636e\u7c7b\u578b 32\u4f4d\u67b6\u6784\u4e2d\uff0c\u5b83\u5c31\u662fuint32_t 16\u4f4d\u67b6\u6784\u4e2d\uff0c\u5b83\u5c31\u662fuint16_t 8\u4f4d\u67b6\u6784\u4e2d\uff0c\u5b83\u5c31\u662fuint8_t BaseType_t\u901a\u5e38\u7528\u4f5c\u7b80\u5355\u7684\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u8fd8\u6709\u903b\u8f91\u503c\uff0c\u6bd4\u5982pdTRUE/pdFALSE \u547d\u540d\u89c4\u8303\uff1a
\u53d8\u91cf\u540d\u524d\u7f00 \u542b\u4e49 ul uint32_t us uint16_t uc uint8_t x \u975estdint\u7c7b\u578b\uff0c\u6bd4\u5982BaseType_t\u548cTickType_t\uff0c\u6216\u8005size_t ux UBaseType_t e enum p \u6307\u9488 c char \u51fd\u6570\u540d\u524d\u7f00 \u542b\u4e49 prv \u79c1\u6709\u51fd\u6570(file scope) v \u8fd4\u56de\u503cvoid task \u5b9a\u4e49\u5728task.c \u5b8f\u524d\u7f00 \u542b\u4e49 config \u5b9a\u4e49\u5728FreeRTOSConfig.h"},{"location":"rtos/freertos/#_2","title":"\u5185\u5b58\u7ba1\u7406","text":"\u6bcf\u6b21\u521b\u5efa\u4efb\u52a1\u3001\u961f\u5217\u3001\u4e92\u65a5\u9501\u3001\u8f6f\u4ef6\u5b9a\u65f6\u5668\u3001\u4fe1\u53f7\u91cf\u6216\u4e8b\u4ef6\u7ec4\u65f6\uff0c\u5185\u6838\u90fd\u9700\u8981RAM\uff0cRAM\u53ef\u4ee5\u7531RTOS\u5806\u52a8\u6001\u5206\u914d\uff0c\u4e5f\u53ef\u4ee5\u7531\u7f16\u5199\u8005\u624b\u52a8\u63d0\u4f9b\u3002
\u5c3d\u7ba1C\u5e93\u63d0\u4f9b\u4e86malloc()
\u548cfree()
\u51fd\u6570\uff0c\u4f46\u662f\uff1a 1. \u5b83\u4eec\u5e76\u4e0d\u603b\u662f\u9002\u7528\u4e8e\u5d4c\u5165\u5f0f\u7cfb\u7edf 2. \u5b83\u4eec\u8017\u8d39\u65f6\u95f4\u6bd4\u8f83\u957f 3. \u5b83\u4eec\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684 4. \u8fd0\u884c\u7ed3\u679c\u4e0d\u786e\u5b9a
\u56e0\u6b64freertos\u5b9e\u73b0\u4e86\u81ea\u5df1\u7684\u5185\u5b58\u5206\u914d\u63a5\u53e3\u51fd\u6570\u3002
freertos\u4e2d\u6709\u4e94\u79cd\u5806\u5185\u5b58\uff0c\u6587\u4ef6\u5b9a\u4e49\u5728Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang\u4e0b\u3002\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662fheap_4.c\uff0c\u5b83\u53ef\u4ee5\u5c06\u76f8\u90bb\u7684\u7a7a\u95f4\u5185\u5b58\u5757\u5408\u5e76\uff0c\u89e3\u51b3\u4e86\u5185\u5b58\u788e\u7247\u95ee\u9898\u3002\u800cheap_5.c\u5141\u8bb8\u591a\u4e2a\u4e0d\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002\u9700\u8981\u7528\u5230\u4ee5\u4e0b\u7ed3\u6784\u4f53\u8fdb\u884c\u4e0d\u540c\u5185\u5b58\u5757\u7684\u521d\u59cb\u5316\uff1a
typedef struct HeapRegion\n{\n uint8_t *pucStartAddress; //\u8d77\u59cb\u5730\u5740\n size_t xSizeInBytes; //\u5927\u5c0f\n}HeapRegion_t;\n
\u5f53\u6307\u5b9a\u591a\u5757\u5185\u5b58\u65f6\uff0c\u9700\u8981\u7528\u5230HeapRegion_t\u7c7b\u578b\u7684\u6570\u636e\uff0c\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u90fd\u662f\u4e00\u4e2aHeapRegion_t\u5143\u7d20\u3002\u8fd9\u4e2a\u6570\u7ec4\u4e2d\uff0c\u4f4e\u5730\u5740\u5728\u524d\uff0c\u9ad8\u5730\u5740\u5728\u540e\u3002
HeapRegion_t xHeapRegions[] = \n{\n {(uint8_t *)0x80000000UL, 0x10000}, //\u8d77\u59cb\u5730\u5740\u548c\u5927\u5c0f\n {(uint8_t *)0x90000000UL, 0x10000}, \n {NULL, 0} //\u8868\u793a\u6570\u7ec4\u7ed3\u675f\n};\n
\u5b9a\u4e49\u4e86\u5185\u5b58\u5757\u6570\u7ec4\u8fd8\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u521d\u59cb\u5316\uff1a
void vPortDefineHeapRegions(const HeapRegion_t *const pxHeapRegions);\n
Heap\u7684\u5206\u914d\u548c\u91ca\u653e\uff1a
void *pvPortMalloc(size_t xWantedSize);\nvoid vPortFree(void *pv);\n
\u83b7\u53d6\u5f53\u524d\u7a7a\u95f2\u5185\u5b58\u7a7a\u95f4\uff1a
size_t xPortGetFreeHeapSize(void);\n
\u83b7\u53d6\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7a7a\u95f2\u5185\u5b58\u7684\u6700\u5c0f\u503c\uff1a
size_t xPortGetMinimumEverFreeHeapSize(void);\n
"},{"location":"rtos/freertos/#_3","title":"\u4efb\u52a1\u7ba1\u7406","text":"\u4e00\u4e2a\u4efb\u52a1\u6700\u57fa\u672c\u7684\u5143\u7d20\u6709\uff1a
\u4efb\u52a1\u72b6\u6001\uff1a\u6bd4\u5982\u963b\u585e\uff0c\u5c31\u7eea\uff0c\u6302\u8d77\u7b49 \u4f18\u5148\u7ea7\uff1a\u6bcf\u4e2a\u4efb\u52a1\u90fd\u5206\u914d\u4e86\u4ece0\u5230configMAX_PRIORITIES-1\u7684\u4f18\u5148\u7ea7 \u6808\uff1a\u7528\u6765\u4fdd\u5b58\u4efb\u52a1\u7684\u5c40\u90e8\u6570\u636e \u4e8b\u4ef6\uff1a\u8868\u793a\u4efb\u52a1\u505a\u4e86\u4ec0\u4e48\u4e8b\u60c5 \u5bf9\u4e8e\u5355\u6838\u5904\u7406\u5668\u6765\u8bf4\uff0c\u4efb\u4f55\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a\u4efb\u52a1\u5f97\u5230\u8fd0\u884c\uff0c\u5f53\u8c03\u5ea6\u5668\u51b3\u5b9a\u5207\u6362\u4efb\u52a1\u65f6\uff0c\u9700\u8981\u5c06\u4e0a\u4e00\u4e2a\u4efb\u52a1\u7684\u4e0a\u4e0b\u6587\uff08\u5bc4\u5b58\u5668\uff0c\u6808\uff09\u4fdd\u5b58\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u4e00\u4e2a\u4efb\u52a1\u51fa\u73b0\u4e86\u6b7b\u5faa\u73af\u64cd\u4f5c\uff0c\u90a3\u4e48\u6bd4\u8fd9\u4e2a\u4efb\u52a1\u4f18\u5148\u7ea7\u4f4e\u7684\u4efb\u52a1\u90fd\u5c06\u65e0\u6cd5\u6267\u884c\u3002\u6240\u4ee5\u5728\u8bbe\u8ba1\u7684\u65f6\u5019\uff0c\u5e94\u8be5\u4fdd\u8bc1\u4efb\u52a1\u5728\u4e0d\u6d3b\u8dc3\u72b6\u6001\u65f6\u8fdb\u5165\u963b\u585e\u72b6\u6001\u4ee5\u8ba9\u51faCPU\u4f7f\u7528\u6743\uff0c\u4fdd\u8bc1\u5176\u4ed6\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u53ef\u4ee5\u6267\u884c\u3002
"},{"location":"rtos/freertos/#_4","title":"\u521b\u5efa\u4efb\u52a1","text":"\u5728FreeRTOS\u4e2d\uff0c\u4efb\u52a1\u51fd\u6570\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
void vATaskFunction(void *pvParameters)\n{\n for(;;)\n {\n //RTOS\u63a8\u8350\u91c7\u7528\u4e8b\u4ef6\u9a71\u52a8\u578b\u4efb\u52a1\n if(WaitForEvent(EventObject, Timeout) == pdPASS)\n {\n //\u5904\u7406\u4e8b\u4ef6\n }\n else\n {\n\n }\n }\n\n vTaskDelete(NULL); //\u6267\u884c\u5b8c\u6bd5\u5220\u9664\u81ea\u5df1\n}\n
\u52a8\u6001\u521b\u5efa\u4efb\u52a1\u4f7f\u7528\u7684\u51fd\u6570\u5982\u4e0b\uff1a BaseType_t xTaskCreate(TaskFunction_t pxTaskCode,\n const char *const pcName, \n const configSTACK_DEPTH_TYPE usStackDepth,\n void *const pvParameters,\n UBaseType_t uxPriority,\n TaskHandle_t *const pxCreatedTask);\n
\u53c2\u6570\u8bf4\u660e\uff1a
\u53c2\u6570 \u63cf\u8ff0 pvTaskCode \u4efb\u52a1\u51fd\u6570 pcName \u4efb\u52a1\u540d\u79f0 usStackDepth \u4efb\u52a1\u6808\u5927\u5c0f\uff0c\u5355\u4f4dword pvParameters \u4f20\u9012\u7ed9\u4efb\u52a1\u51fd\u6570\u7684\u53c2\u6570 uxPriority \u4efb\u52a1\u4f18\u5148\u7ea7 pxCreatedTask \u4efb\u52a1\u53e5\u67c4\uff0c\u7528\u6765\u64cd\u4f5c\u4efb\u52a1\u51fd\u6570 \u8fd4\u56de\u503c \u6210\u529f\u8fd4\u56depdPass\uff0c\u5931\u8d25\u901a\u5e38\u662f\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3 \u9759\u6001\u521b\u5efa\u4efb\u52a1\u4f7f\u7528\u7684\u51fd\u6570\u5982\u4e0b\uff1a
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,\n const char *const pcName,\n const uint32_t ulStackDepth,\n void *const pvParameters,\n UBaseType_t uxPriority,\n StackType_t *const puxStackBuffer,\n StaticTask_t *const pxTaskBuffer);\n
\u76f8\u5bf9\u4e8e\u52a8\u6001\u5206\u914d\uff0c\u6709\u4e24\u4e2a\u53c2\u6570\u4e0d\u540c\uff1a
\u53c2\u6570 \u63cf\u8ff0 puxStackBuffer \u6808\u6570\u7ec4\uff0c\u7d22\u5f15\u5fc5\u987b\u4e0d\u5c0f\u4e8eulStackDepth pxTaskBuffer \u6307\u5411StaticTask_t\u7684\u6307\u9488\uff0c\u7528\u6765\u4fdd\u5b58\u4efb\u52a1\u7ed3\u6784\u4f53 \u6bcf\u4e2a\u4efb\u52a1\u90fd\u9700\u8981RAM\u6765\u4fdd\u5b58\u4efb\u52a1\u72b6\u6001\uff0c\u5e76\u7531\u4efb\u52a1\u7528\u4f5c\u5176\u5806\u6808\u3002\u5982\u679c\u4f7f\u7528\u52a8\u6001\u521b\u5efa\uff0c\u5219\u4f1a\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4eceFreeRTOS\u5806\u4e2d\u81ea\u52a8\u5206\u914dRAM\u3002\u5982\u679c\u662f\u9759\u6001\u521b\u5efa\uff0cRAM\u7531\u7f16\u5199\u8005\u624b\u52a8\u63d0\u4f9b\uff0c\u4f46\u5728\u7f16\u8bd1\u65f6\u5c31\u5df2\u786e\u5b9a\u3002
"},{"location":"rtos/freertos/#tick","title":"Tick","text":"\u4efb\u52a1\u8fdb\u5165\u7761\u7720\u540e\u9700\u8981\u6307\u5b9a\u5524\u9192\u7684\u65f6\u95f4\uff0cFreeRTOS\u901a\u8fc7Tick\u53d8\u91cf\u6d4b\u91cf\u65f6\u95f4\u3002\u5b9a\u65f6\u5668\u4e2d\u65ad\u4ee5\u4e25\u683c\u7684\u65f6\u95f4\u7cbe\u5ea6\u589e\u52a0Tick count\u3002\u6bcf\u6b21Tick\u589e\u52a0\u65f6\uff0c\u5185\u6838\u5fc5\u987b\u68c0\u67e5\u73b0\u5728\u662f\u5426\u9700\u8981\u89e3\u9664\u963b\u585e\u6216\u8005\u5524\u9192\u4efb\u52a1\uff0c\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u5148\u88ab\u5524\u9192\u3002\u4efb\u52a1\u901a\u8fc7\u8c03\u7528vTaskDelay()
\u51fd\u6570\u6765\u4e3b\u52a8\u7b49\u5f85\u4e00\u5b9a\u7684\u65f6\u95f4\u3002\u5b8fpdMS_TO_TICKS()
\u5c06\u6beb\u79d2\u8f6c\u6362\u4e3aTick count\u3002
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u5185\u6838\u672c\u8eab\u7684\u4efb\u52a1\u5207\u6362\u9700\u8981\u65f6\u95f4\uff0c\u5f53\u6307\u5b9aN\u4e2aTick\u7684\u5ef6\u8fdf\u540e\uff0c\u5b9e\u9645\u5ef6\u8fdf\u65f6\u95f4\u5c06\u5728(N-1)~(N)\u4e2aTick\u4e4b\u95f4\u3002
"},{"location":"rtos/freertos/#_5","title":"\u4efb\u52a1\u72b6\u6001","text":"\u4efb\u52a1\u53ef\u4ee5\u6709\u4ee5\u4e0b\u72b6\u6001\uff1a
\u8fd0\u884c\uff1a\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u88ab\u6267\u884c
\u5c31\u7eea\uff1a\u80fd\u591f\u6267\u884c\uff0c\u7b49\u5f85\u8c03\u5ea6\u5668\u8c03\u5ea6
\u963b\u585e\uff1a\u6b63\u5728\u7b49\u5f85\u65f6\u95f4\u6216\u8005\u5916\u90e8\u4e8b\u4ef6
\u6302\u8d77\uff1a\u653e\u5f03CPU\u4f7f\u7528\u6743\uff0c\u4e0d\u53c2\u4e0e\u8c03\u5ea6\u3002
"},{"location":"rtos/freertos/#_6","title":"\u8c03\u5ea6\u7b97\u6cd5","text":"\u4e24\u4e2a\u6838\u5fc3\u6982\u5ff5\uff1a\u62a2\u5360\u548c\u8f6e\u8f6c\u3002\u901a\u8fc7\u914d\u7f6econfigUSE_PREEMPTION\u4f7f\u80fd\u62a2\u5360\uff0c\u5373\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u53ef\u4ee5\u62a2\u5360\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u914d\u7f6econfigUSE_TIME_SLICING\u4f7f\u80fd\u8f6e\u8f6c\uff0c\u5373\u76f8\u540c\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u8f6e\u6d41\u6267\u884c\u3002
"},{"location":"rtos/freertos/#_7","title":"\u7a7a\u95f2\u4efb\u52a1\u548c\u94a9\u5b50\u51fd\u6570","text":"\u5728\u6ca1\u6709\u5176\u4ed6\u4efb\u52a1\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u6267\u884c\u7a7a\u95f2\u4efb\u52a1\u3002vTaskStartScheduler()
\u51fd\u6570\u5185\u90e8\u4f1a\u521b\u5efa\u7a7a\u95f2\u4efb\u52a1\uff0c\u5b83\u7684\u4f18\u5148\u7ea7\u4e3a0\uff0c\u6c38\u8fdc\u4f4e\u4e8e\u7528\u6237\u4efb\u52a1\uff0c\u4e14\u8981\u4e48\u5904\u4e8e\u5c31\u7eea\u6001\uff0c\u8981\u4e48\u5904\u4e8e\u8fd0\u884c\u6001\u3002
\u6211\u4eec\u53ef\u4ee5\u5728\u7a7a\u95f2\u4efb\u52a1\u5185\u6dfb\u52a0\u4e00\u4e2a\u94a9\u5b50\u51fd\u6570\uff0c\u8fd9\u6837\u7a7a\u95f2\u4efb\u52a1\u6bcf\u6267\u884c\u4e00\u6b21\uff0c\u90fd\u4f1a\u8c03\u7528\u4e00\u6b21\u94a9\u5b50\u51fd\u6570\u3002\u94a9\u5b50\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff1a
\u6267\u884c\u4e00\u4e9b\u540e\u53f0\u4efb\u52a1 \u6d4b\u91cf\u7cfb\u7edf\u7a7a\u95f2\u65f6\u95f4 \u4f7f\u7cfb\u7edf\u8fdb\u5165\u7701\u7535\u6a21\u5f0f \u8981\u6ce8\u610f\u7684\u662f\uff0c\u94a9\u5b50\u51fd\u6570\u4e0d\u80fd\u8c03\u7528\u4efb\u4f55\u4f7f\u5176\u5bfc\u81f4\u963b\u585e\u7684\u51fd\u6570\u3002\u7a7a\u95f2\u94a9\u5b50\u51fd\u6570\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
void vApplicationIdleHook(void);\n
"},{"location":"rtos/freertos/#_8","title":"\u4efb\u52a1\u540c\u6b65\u4e0e\u901a\u4fe1","text":"\u8fd9\u91cc\u9762\u7684\u5185\u5bb9\u4ee5\u7406\u89e3\u539f\u7406\u4e3a\u4e3b\uff0c\u6ca1\u6709\u5fc5\u8981\u53bb\u8bb0\u51fd\u6570\u63a5\u53e3\uff0c\u7528\u5230\u4ec0\u4e48\u5c31\u67e5\u4ec0\u4e48\u3002
"},{"location":"rtos/freertos/#_9","title":"\u6d88\u606f\u961f\u5217","text":"\u6d88\u606f\u961f\u5217\u7b80\u79f0\u4e3a\u961f\u5217\uff0c\u662f\u4e00\u79cd\u5148\u8fdb\u5148\u51fa\u7684\u6570\u636e\u7ed3\u6784\uff0c\u652f\u6301\u4efb\u52a1\u6216\u8005\u4e2d\u65ad\u7684\u8bfb\u5199\u3002\u5f53\u961f\u5217\u4e2d\u7684\u6d88\u606f\u4e3a\u7a7a\u65f6\uff0c\u8bfb\u53d6\u6d88\u606f\u7684\u4efb\u52a1\u5c06\u88ab\u963b\u585e\uff1b\u5f53\u961f\u5217\u5df2\u6ee1\uff0c\u53d1\u9001\u6d88\u606f\u7684\u4efb\u52a1\u5c06\u88ab\u963b\u585e\u3002\u53ef\u4ee5\u5c06\u4e00\u6761\u6216\u8005\u591a\u6761\u6d88\u606f\u653e\u5165\u961f\u5217\u4e2d\uff0c\u591a\u4e2a\u4efb\u52a1\u4e5f\u53ef\u4ee5\u4ece\u540c\u4e00\u4e2a\u6d88\u606f\u961f\u5217\u8bfb\u5199\u6d88\u606f\u3002\u5982\u679c\u662f\u7d27\u6025\u6d88\u606f\uff0c\u53ef\u4ee5\u53d1\u9001\u81f3\u961f\u5217\u5934\u4ece\u800c\u63d0\u524d\u88ab\u63a5\u6536\u3002
\u4e3a\u4e86\u5b9e\u73b0\u5148\u8fdb\u5148\u51fa\u7684\u673a\u5236\uff0c\u961f\u5217\u4f7f\u7528\u4e86\u963b\u585e\u7684\u673a\u5236\u3002\u5f53\u4efb\u52a1A\u5bf9\u67d0\u4e2a\u961f\u5217\u8fdb\u884c\u8bfb\u64cd\u4f5c\u65f6\uff0c\u5982\u679c\u961f\u5217\u6b64\u65f6\u4e3a\u7a7a\uff0c\u90a3\u4e48\u5b83\u53ef\u4ee5\u9009\u62e9\uff1a
\u76f4\u63a5\u653e\u5f03\u8bfb\u64cd\u4f5c\uff0c\u53bb\u5e72\u522b\u7684\u4e8b\u60c5\u3002 \u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u3002\u5982\u679c\u5728\u7b49\u5f85\u671f\u95f4\u6d88\u606f\u6765\u4e86\uff0c\u5c31\u53d8\u4e3a\u5c31\u7eea\u72b6\u6001\uff1b\u5982\u679c\u7b49\u5f85\u65f6\u95f4\u8fc7\u4e86\u6d88\u606f\u90fd\u6ca1\u6765\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de\u4e00\u4e2a\u672a\u6536\u5230\u6d88\u606f\u7684\u9519\u8bef\u7801\uff0c\u7136\u540e\u6267\u884c\u5176\u4ed6\u7a0b\u5e8f\u3002 \u6b7b\u7b49\u76f4\u5230\u6d88\u606f\u5230\u6765\u4e3a\u6b62\u3002 \u5199\u64cd\u4f5c\u7684\u963b\u585e\u673a\u5236\u7c7b\u4f3c\u3002
\u6ce8\u610f\uff1a\u7531\u4e8e\u4e2d\u65ad\u51fd\u6570\u4e5f\u53ef\u4ee5\u5bf9\u961f\u5217\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\uff0c\u4f46\u662f\u4e2d\u65ad\u51fd\u6570\u4e0d\u5141\u8bb8\u963b\u585e\uff0c\u56e0\u6b64\u5728\u4e2d\u65ad\u5904\u7406\u6d41\u7a0b\u4e2d\u5fc5\u987b\u4f7f\u7528\u7279\u6b8a\u7684\u8bfb\u5199\u51fd\u6570\u63a5\u53e3\u3002
"},{"location":"rtos/freertos/#_10","title":"\u4fe1\u53f7\u91cf","text":"\u4fe1\u53f7\u91cf\u5206\u4e3a\u4e8c\u503c\u4fe1\u53f7\u91cf\u548c\u8ba1\u6570\u4fe1\u53f7\u91cf\uff0c\u5176\u539f\u7406\u548cLinux\u5185\u6838\u76f8\u4f3c\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002
"},{"location":"rtos/freertos/#_11","title":"\u4e92\u65a5\u91cf","text":"\u4e92\u65a5\u91cf\u662f\u7279\u6b8a\u7684\u4e8c\u503c\u4fe1\u53f7\u91cf\uff0c\u6709\u7740\u9012\u5f52\u8bbf\u95ee\u548c\u9632\u6b62\u4f18\u5148\u7ea7\u53cd\u8f6c\u7684\u7279\u6027\uff0c\u4e3b\u8981\u7528\u4e8e\u4e34\u754c\u8d44\u6e90\u7684\u4fdd\u62a4\u3002\u4e92\u65a5\u91cf\u5177\u6709\u7279\u6b8a\u7684\u4f18\u5148\u7ea7\u7ee7\u627f\u7684\u673a\u5236\uff0c\u8981\u7406\u89e3\u8fd9\u4e2a\u673a\u5236\uff0c\u6211\u4eec\u9996\u5148\u8981\u89e3\u91ca\u4e0b\u4ec0\u4e48\u662f\u4f18\u5148\u7ea7\u53cd\u8f6c\u3002
\u5728\u4e00\u4e2a\u7b80\u5316\u8fc7\u7684\u573a\u666f\u4e2d\uff0c\u6709\u4e09\u4e2a\u4efb\u52a1H\u3001M\u3001L\uff0c\u5b83\u4eec\u7684\u4f18\u5148\u7ea7\u4f9d\u6b21\u4e3aH>M>L\u3002H\u4e0eL\u5171\u4eab\u67d0\u4e2a\u8d44\u6e90\uff0cM\u4e0d\u5171\u4eab\u3002\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u6700\u9ad8\u4f18\u5148\u7ea7\u7684H\u5e94\u8be5\u80fd\u591f\u4f18\u5148\u6267\u884c\uff0c\u5e76\u4e14\u6709\u6743\u9650\u6253\u65adM\u6216\u8005L\u7684\u6267\u884c\u72b6\u6001\u4ece\u800c\u62a2\u5360CPU\u7684\u63a7\u5236\u6743\u3002\u7136\u800c\u5b58\u5728\u4e00\u79cd\u60c5\u51b5,\u4f1a\u5bfc\u81f4H\u4e00\u76f4\u88ab\u963b\u585e\uff0c\u7b49\u5f85M\u548cL\u7684\u5b8c\u6210\u8fd0\u884c\uff1a
\u5728\u67d0\u4e00\u65f6\u523b\uff0cL\u5df2\u7ecf\u83b7\u53d6\u4e86\u5171\u4eab\u8d44\u6e90\u7684\u4f7f\u7528\u6743\uff0c\u6b63\u5728\u6267\u884c\u81ea\u5df1\u7684\u4efb\u52a1\u3002\u5982\u679c\u6b64\u65f6H\u88ab\u5524\u9192\uff0c\u7531\u4e8eH\u7684\u4f18\u5148\u7ea7\u5927\u4e8eL\uff0c\u5b83\u5c1d\u8bd5\u83b7\u53d6CPU\u7684\u63a7\u5236\u6743\u3002\u4f46\u662f\u7531\u4e8e\u5171\u4eab\u8d44\u6e90\u88abL\u5360\u7528\uff0cH\u4e0d\u5f97\u4e0d\u7b49\u5f85L\u91ca\u653e\u8d44\u6e90\u800c\u8fdb\u5165\u963b\u585e\u72b6\u6001\u3002\u6709\u8da3\u7684\u662f\uff0c\u5982\u679cM\u88ab\u5524\u9192\uff0c\u7531\u4e8eM\u4e0eL\u5e76\u4e0d\u5171\u4eab\u8d44\u6e90\u4e14\u4f18\u5148\u7ea7\u5927\u4e8eL\uff0c\u5b83\u5c06\u7acb\u523b\u4e2d\u65adL\u7684\u6267\u884c\uff0c\u83b7\u53d6CPU\u7684\u63a7\u5236\u6743\u3002\u53ea\u6709\u5f53M\u6267\u884c\u5b8c\u6bd5\u65f6\uff0c\u624d\u4f1a\u5c06CPU\u63a7\u5236\u6743\u5f52\u8fd8\u7ed9L\uff0c\u4f7f\u5176\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5269\u4f59\u7684\u4ee3\u7801\u3002\u4e00\u65e6L\u6267\u884c\u5b8c\u6bd5\u540e\u91ca\u653e\u4e86\u5171\u4eab\u8d44\u6e90\uff0cH\u4efb\u52a1\u624d\u80fd\u4ece\u963b\u585e\u72b6\u6001\u4e2d\u88ab\u5524\u9192\u3002\u6211\u4eec\u53d1\u73b0\uff0c\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1H\u53cd\u800c\u9700\u8981\u7b49\u5f85\u4e24\u4e2a\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u5148\u6267\u884c\u5b8c\u6bd5\uff0c\u5176\u963b\u585e\u65f6\u95f4\u7b49\u4e8eM\u548cL\u7684\u6267\u884c\u65f6\u95f4\u4e4b\u548c\u3002\u8fd9\u79cd\u73b0\u8c61\u88ab\u79f0\u4e3a\u201c\u4f18\u5148\u7ea7\u53cd\u8f6c\u201d\uff0c\u5728\u7cfb\u7edf\u4e2d\u53ef\u80fd\u5bfc\u81f4\u4e25\u91cd\u540e\u679c\uff0c\u751a\u81f3\u5d29\u6e83\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u8f86\u6c7d\u8f66\u7684\u5239\u8f66\u7cfb\u7edf\u662f\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\uff0c\u4f46\u9700\u8981\u7b49\u5f85\u5176\u4ed6\u4efb\u52a1\u6267\u884c\u5b8c\u6bd5\uff0c\u8fd9\u5c06\u5bfc\u81f4\u707e\u96be\u6027\u7684\u540e\u679c\u3002\u56e0\u6b64\u4e3a\u4e86\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u8fd0\u884c\uff0c\u5fc5\u987b\u89e3\u51b3\u4f18\u5148\u7ea7\u53cd\u8f6c\u95ee\u9898\u3002
\u4f46\u662f\u5047\u5982\u6211\u4eec\u5f15\u8fdb\u4e86\u4f18\u5148\u7ea7\u7ee7\u627f\u673a\u5236\u3002\u540c\u6837\u662fL\u83b7\u53d6\u5171\u4eab\u8d44\u6e90\uff0cH\u8fdb\u5165\u963b\u585e\u72b6\u6001\u3002\u7cfb\u7edf\u4e34\u65f6\u5c06L\u7684\u4f18\u5148\u7ea7\u63d0\u5347\u5230H\uff0c\u90a3\u4e48M\u5c31\u65e0\u6cd5\u6253\u65adL\u7684\u6267\u884c\u3002\u6240\u4ee5L\u6267\u884c\u5b8c\u5b83\u7684\u4efb\u52a1\u5c31\u4f1a\u7acb\u523b\u91ca\u653e\u8d44\u6e90\uff0c\u7136\u540e\u7531H\u6765\u62a2\u5360CPU\u7684\u4f7f\u7528\u6743\u3002\u5176\u963b\u585e\u65f6\u95f4\u4ec5\u4ec5\u662fL\u7684\u6267\u884c\u65f6\u95f4\uff0c\u8fd9\u5c06\u5927\u5927\u964d\u4f4e\u4f18\u5148\u7ea7\u53cd\u8f6c\u7684\u5371\u5bb3\u3002
"},{"location":"rtos/freertos/#_12","title":"\u4e8b\u4ef6\u7ec4","text":"\u4e8b\u4ef6\u7ec4\u4e3b\u8981\u7528\u6765\u5b9e\u73b0\u591a\u4efb\u52a1\u95f4\u7684\u540c\u6b65\uff0c\u53ea\u80fd\u7528\u6765\u4e8b\u4ef6\u7684\u901a\u4fe1\uff0c\u4e0d\u80fd\u7528\u6765\u53d1\u9001\u6570\u636e\u3002\u53ef\u4ee5\u662f\u4e00\u5bf9\u591a\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u5bf9\u4e00\u3002
\u4e8b\u4ef6\u7ec4\u7528\u4e00\u4e2aEventBits_t\u7c7b\u578b\u7684\u53d8\u91cf\u6765\u8868\u793a\uff0c\u5176\u4e2d\u9ad88\u4f4d\u7559\u7ed9\u5185\u6838\uff0c\u7528\u5176\u4ed6\u7684\u4f4d\u6765\u8868\u793a\u4e8b\u4ef6\u3002\u6bcf\u4e00\u4f4d\u90fd\u4ee3\u8868\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u542b\u4e49\u7531\u7f16\u5199\u8005\u51b3\u5b9a\uff0c\u6bd4\u5982\u7528bit0\u8868\u793a\u706f\u6ce1\u4eae\u706d\uff0cbit1\u8868\u793a\u6309\u952e\u662f\u5426\u6309\u4e0b\u3002\u8fd9\u4e9b\u4f4d\uff0c\u503c\u4e3a1\u8868\u793a\u4e8b\u4ef6\u53d1\u751f\uff0c\u503c\u4e3a0\u8868\u793a\u4e8b\u4ef6\u672a\u53d1\u751f\u3002\u4efb\u52a1\u901a\u8fc7\u201c\u903b\u8f91\u4e0e\u201d\u3001\u201c\u903b\u8f91\u6216\u201d\u4e0e\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u4e8b\u4ef6\u5efa\u7acb\u5173\u8054\u3002\u903b\u8f91\u4e0e\u8868\u793a\u4efb\u52a1\u611f\u5174\u8da3\u7684\u591a\u4e2a\u4e8b\u4ef6\u540c\u65f6\u53d1\u751f\u624d\u88ab\u5524\u9192\uff0c\u903b\u8f91\u6216\u8868\u793a\u4efb\u4e00\u4e8b\u4ef6\u53d1\u751f\u5373\u53ef\u88ab\u5524\u9192\u3002
\u4e8b\u4ef6\u7ec4\u7684\u64cd\u4f5c\u6d41\u7a0b\u5982\u4e0b\uff1a
\u521b\u5efa\u4e00\u4e2a\u4e8b\u4ef6\u7ec4 \u4efb\u52a1A\u3001B\u63a7\u5236\u4e8b\u4ef6\u4e2d\u7684\u67d0\u4e9b\u4f4d \u4efb\u52a1C\u3001D\u7b49\u5f85\u4e8b\u4ef6\u4e2d\u7684\u4f4d\uff0c\u5e76\u4e14\u51b3\u5b9a\u53d1\u751f\u4e8b\u4ef6\u540e\u7684\u64cd\u4f5c \u8fd9\u91cc\u5bf9\u4e24\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u51fd\u6570\u8bf4\u660e\u4e00\u4e0b\uff1a
\u7b49\u5f85\u4e8b\u4ef6\u51fd\u6570\uff1a
EventBits_t xEventGroupWaitBits(EventGroupsHandle_t xEventGroup,\n const EvetnBits_t uxBitsToWaitFor,\n const BaseType_t xClearOnExit,\n const BaseType_t xWaitForAllBits,\n TickType_t xTickToWait);\n
\u53c2\u6570 \u8bf4\u660e xEventGroup \u7b49\u5f85\u7684\u4e8b\u4ef6\u7ec4 uxBitsToWaitFor \u7b49\u5f85\u7684\u4f4d xClearOnExit pdTRUE:\u6e05\u9664\u4f4d xWaitForAllBits pdTRUE\uff1a\u7b49\u5f85\u7684\u4f4d\u5168\u90e8\u4e3a1\uff1bpdFALSE\uff1a\u67d0\u4e00\u4f4d\u4e3a1 xTicksToWait \u963b\u585e\u65f6\u95f4 \u4e3e\u4f8b\u8bf4\u660e\uff1a
\u4e8b\u4ef6\u7ec4\u7684\u503c uxBitsToWaitFor xWaitForAllBits \u8bf4\u660e 0100 0101 pdTrue \u671f\u671bbit0,bit2\u90fd\u4e3a1\uff0c\u4e0d\u6ee1\u8db3\u8fdb\u5165\u963b\u585e 0100 0110 pdFALSE \u671f\u671bbit0, bit2\u67d0\u4f4d\u4e3a1\uff0c\u6ee1\u8db3\u9000\u51fa \u540c\u6b65\u4e8b\u4ef6\u51fd\u6570\uff1a
EventBits_t xEventGroupSync(EventGroupHandle_t xEventGroup,\n const EventBits_t uxBitsToSet,\n const EventBits_t uxBitsToWaitFor,\n TickType_t xTicksToWait);\n
\u8be5\u51fd\u6570\u7528\u6765\u534f\u540c\u591a\u4e2a\u4efb\u52a1\uff0c\u5f53\u671f\u671b\u7684\u4e8b\u4ef6\u4e00\u8d77\u53d1\u751f\u540e\uff0c\u624d\u4f1a\u6210\u529f\u8fd4\u56de\u3002
"},{"location":"rtos/freertos/#_13","title":"\u4efb\u52a1\u901a\u77e5","text":"FreeRTOS\u4eceV8.2.0\u7248\u672c\u5f00\u59cb\u63d0\u4f9b\u4efb\u52a1\u901a\u77e5\u8fd9\u4e2a\u529f\u80fd\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4efb\u52a1\u901a\u77e5\u53ef\u4ee5\u66ff\u4ee3\u4fe1\u53f7\u91cf\u3001\u4e8b\u4ef6\u7ec4\uff0c\u4e5f\u53ef\u4ee5\u66ff\u4ee3\u957f\u5ea6\u4e3a1\u7684\u961f\u5217\u3002\u4efb\u52a1\u901a\u77e5\u66f4\u52a0\u7075\u6d3b\uff0c\u6267\u884c\u901f\u5ea6\u66f4\u5feb\uff0c\u5e76\u4e14\u66f4\u52a0\u8282\u7701RAM\u7a7a\u95f4\uff0c\u7f3a\u70b9\u662f\u4efb\u52a1\u901a\u77e5\u53ea\u80fd\u7531\u4e00\u4e2a\u4efb\u52a1\u6765\u63a5\u6536\u901a\u77e5\u6d88\u606f\u3002
FreeRTOS\u63d0\u4f9b\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u53d1\u9001\u901a\u77e5\u7ed9\u4efb\u52a1\uff1a
\u5982\u679c\u6709\u901a\u77e5\u672a\u8bfb\uff0c\u4e0d\u8986\u76d6\u901a\u77e5\u503c \u76f4\u63a5\u8986\u76d6\u901a\u77e5\u503c \u8bbe\u7f6e\u901a\u77e5\u503c\u7684\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u4f4d\uff0c\u7c7b\u4f3c\u4e8b\u4ef6\u7ec4 \u9012\u589e\u901a\u77e5\u503c\uff0c\u7c7b\u4f3c\u8ba1\u6570\u4fe1\u53f7\u91cf \u4efb\u52a1\u901a\u77e5\u662f\u4efb\u52a1\u63a7\u5236\u5757\u4e2d\u5b9a\u4e49\u7684\u4e00\u4e2a\u6210\u5458\u53d8\u91cf\uff0c\u56e0\u6b64\u4efb\u52a1\u5728\u88ab\u521b\u5efa\u7684\u65f6\u5019\uff0c\u4efb\u52a1\u901a\u77e5\u5c31\u5df2\u7ecf\u88ab\u521d\u59cb\u5316\u4e86\u3002\u4efb\u52a1\u901a\u77e5\u53ef\u4ee5\u7531\u4efb\u52a1\u53d1\u9001\uff0c\u4e5f\u53ef\u4ee5\u7531\u4e2d\u65ad\u53d1\u9001\u3002\u53ea\u6709\u5728\u4efb\u52a1\u4e2d\u624d\u53ef\u4ee5\u7b49\u5f85\u901a\u77e5\uff0c\u800c\u4e0d\u5141\u8bb8\u5728\u4e2d\u65ad\u4e2d\u7b49\u5f85\u901a\u77e5\u3002\u5982\u679c\u4efb\u52a1\u5728\u7b49\u5f85\u901a\u77e5\u7684\u65f6\u5019\u6682\u65f6\u65e0\u6548\uff0c\u5219\u4efb\u52a1\u4f1a\u6839\u636e\u7528\u6237\u6307\u5b9a\u7684\u963b\u585e\u65f6\u95f4\u5185\u8fdb\u5165\u963b\u585e\u72b6\u6001\u3002\u53ea\u8981\u6709\u4efb\u52a1\u6216\u8005\u4e2d\u65ad\u53d1\u9001\u4efb\u52a1\u901a\u77e5\uff0c\u4efb\u52a1\u5c31\u4f1a\u4ece\u963b\u585e\u72b6\u6001\u89e3\u9664\u3002
\u6bcf\u4e2a\u4efb\u52a1\u90fd\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53:TCB\uff08Task Control Block\uff09\uff0c\u91cc\u9762\u6709\u4e24\u4e2a\u6210\u5458\uff0c\u4e00\u4e2a\u7528\u6765\u8868\u793a\u901a\u77e5\u72b6\u6001\uff0c\u4e00\u4e2a\u7528\u6765\u8868\u793a\u901a\u77e5\u503c\u3002
typedef struct tskTaskControlBlock\n{\n ......\n /* configTASK_NOTIFICATION_ARRAY_ENTRIES = 1 */\n volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];\n volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];\n ......\n} tskTCB;\n
\u901a\u77e5\u72b6\u6001\u67093\u79cd\u53d6\u503c\uff1a
taskNOT_WAITING_NOTIFICATION\uff1a\u4efb\u52a1\u6ca1\u6709\u5728\u7b49\u5f85\u901a\u77e5 taskWAITING_NOTIFICATION\uff1a\u4efb\u52a1\u5728\u7b49\u5f85\u901a\u77e5 taskNOTIFICATION_RECEIVED\uff1a\u4efb\u52a1\u63a5\u6536\u5230\u4e86\u901a\u77e5 "},{"location":"rtos/freertos/#_14","title":"\u8f6f\u4ef6\u5b9a\u65f6\u5668","text":"\u8f6f\u4ef6\u5b9a\u65f6\u5668\u5c31\u662f\u201c\u95f9\u949f\u201d\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u95f9\u949f\uff1a\u65e9\u4e0a7\u70b9\u53eb\u9192\u4f60\uff1b\u6216\u8005\uff0c\u6bcf\u5de5\u4f5c\u4e00\u5c0f\u65f6\u5c31\u4f11\u606f\u4e00\u4f1a\u3002\u8f6f\u4ef6\u5b9a\u65f6\u5668\u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u662f\u5728\u672a\u6765\u67d0\u4e2a\u65f6\u95f4\u70b9\u89e6\u53d1\u67d0\u4e2a\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u5468\u671f\u6027\u5730\u8fd0\u884c\u51fd\u6570\u3002
\u8f6f\u4ef6\u5b9a\u65f6\u5668\u662f\u7531\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u4e00\u7c7b\u63a5\u53e3\uff0c\u5b83\u6784\u5efa\u5728\u786c\u4ef6\u5b9a\u65f6\u5668\u57fa\u7840\u4e4b\u4e0a\uff0c\u4ee5\u7cfb\u7edf\u8282\u62cd\u5468\u671f\u4e3a\u5355\u4f4d\u3002\u7cfb\u7edf\u8282\u62cd\u5c31\u662f\u7cfb\u7edf\u65f6\u949f\u7684\u9891\u7387\uff0c\u914d\u7f6e\u4e3aconfigTICK_RATE_HZ\uff0c\u9ed8\u8ba4\u4e3a1000\u3002\u4e5f\u5c31\u662f\u8bf41s\u8df3\u52a81000\u6b21\uff0c\u90a3\u4e48\u7cfb\u7edf\u8857\u62cd\u5468\u671f\u5c31\u662f1ms\u3002\u8f6f\u4ef6\u5b9a\u65f6\u5668\u7684\u5b9a\u65f6\u6570\u503c\u5fc5\u987b\u662f\u8fd9\u4e2a\u8282\u62cd\u5468\u671f\u7684\u6574\u6570\u500d\u3002\u5f53\u7136\uff0c\u7cfb\u7edf\u8282\u62cd\u7cbe\u5ea6\u8d8a\u9ad8\uff0c\u8f6f\u4ef6\u5b9a\u65f6\u5668\u6240\u80fd\u8bbe\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5c31\u8d8a\u5c0f\uff0c\u4f46\u662f\u7cfb\u7edf\u7684\u5f00\u9500\u4e5f\u4f1a\u53d8\u5927\u3002
FreeRTOS\u901a\u8fc7\u4e00\u4e2aprvTimerTask\u7684\u5b88\u62a4\u4efb\u52a1\u6765\u7ba1\u7406\u8f6f\u4ef6\u5b9a\u65f6\u5668\uff0c\u5b83\u662f\u5728\u542f\u52a8\u8c03\u5ea6\u5668\u65f6\u81ea\u52a8\u521b\u5efa\u7684\u3002\u5b88\u62a4\u4efb\u52a1\u4f1a\u5b9a\u671f\u68c0\u67e5\u7528\u6237\u7f16\u5199\u7684\u5b9a\u65f6\u5668\uff0c\u5e76\u8c03\u7528\u5176\u56de\u8c03\u51fd\u6570\u3002\u7528\u6237\u81ea\u5df1\u7f16\u5199\u7684\u4efb\u52a1\u51fd\u6570\u8981\u8c03\u7528\u5b9a\u65f6\u5668\u51fd\u6570\u65f6\uff0c\u662f\u901a\u8fc7\u201c\u5b9a\u65f6\u5668\u547d\u4ee4\u961f\u5217\u201d\u548c\u5b88\u62a4\u4efb\u52a1\u4ea4\u4e92\u7684\u3002\u5b88\u62a4\u4efb\u52a1\u7684\u4e3b\u8981\u5de5\u4f5c\u5c31\u662f\u4ece\u547d\u4ee4\u961f\u5217\u4e2d\u53d6\u51fa\u547d\u4ee4\u3001\u5904\u7406\uff0c\u6267\u884c\u5b9a\u65f6\u5668\u7684\u56de\u8c03\u51fd\u6570\u3002\u80fd\u5426\u53ca\u65f6\u5904\u7406\u5b9a\u65f6\u5668\u547d\u4ee4\uff0c\u53d6\u51b3\u4e8e\u5b88\u62a4\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u3002\u5176\u4f18\u5148\u7ea7\u9ed8\u8ba4\u4e3aconfiTIMER_TASK_PRIORITY\uff0c\u4e3a\u4e86\u66f4\u597d\u5730\u54cd\u5e94\uff0c\u8be5\u4f18\u5148\u7ea7\u5e94\u8bbe\u7f6e\u4e3a\u6240\u6709\u4efb\u52a1\u4e2d\u6700\u9ad8\u7684\u4f18\u5148\u7ea7\u3002
\u5b9a\u65f6\u5668\u56de\u8c03\u51fd\u6570\u7684\u539f\u578b\u5982\u4e0b\uff1a
void ATimerCallback(TimerHandler_t xTimer);\n
\u5b9a\u65f6\u5668\u7684\u56de\u8c03\u51fd\u6570\u662f\u5728\u5b88\u62a4\u4efb\u52a1\u4e2d\u88ab\u8c03\u7528\u7684\uff0c\u56e0\u6b64\u8be5\u51fd\u6570\u4e0d\u80fd\u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u4efb\u4f55\u4f1a\u5f15\u8d77\u963b\u585e\u7684\u51fd\u6570\u3002
\u5b9a\u65f6\u5668\u7684\u590d\u4f4d\uff1a
BaseType_t xTimerReset(TimerHandle_t xTimer, TickType_t xTicksToWait);\n
\u4f7f\u7528\u8be5\u51fd\u6570\u53ef\u4ee5\u8ba9\u5b9a\u65f6\u5668\u7684\u72b6\u6001\u4ece\u51ac\u7720\u6001\u53d8\u4e3a\u8fd0\u884c\u6001\uff0c\u5982\u679c\u5b9a\u65f6\u5668\u5df2\u7ecf\u8fd0\u884c\uff0c\u5219\u76f8\u5f53\u4e8e\u91cd\u65b0\u786e\u5b9a\u8d85\u65f6\u65f6\u95f4\u3002
\u4fee\u6539\u5468\u671f\uff1a
BaseType_t xTimerChangePeriod(TimerHandle_t xTimer, TickType_t xNewPeriod, TickType_t xTicksToWait);\n
"},{"location":"rtos/freertos/#_15","title":"\u4e2d\u65ad\u7ba1\u7406","text":"\u4e2d\u65ad\u5c5e\u4e8e\u5f02\u6b65\u5f02\u5e38\uff0c\u6765\u6e90\u4e8e\u5916\u90e8\u786c\u4ef6\u3002\u5f53\u6ca1\u6709\u4e2d\u65ad\u53d1\u751f\u65f6\uff0cCPU\u6267\u884c\u81ea\u5df1\u7684\u4efb\u52a1\u3002\u5f53\u4e2d\u65ad\u4ea7\u751f\u65f6\uff0cCPU\u5f53\u524d\u4efb\u52a1\u88ab\u6253\u65ad\uff0c\u8f6c\u800c\u53bb\u6267\u884c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002\u5916\u90e8\u8bbe\u5907\u4ea7\u751f\u4e00\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u5e76\u53d1\u9001\u81f3\u4e2d\u65ad\u63a7\u5236\u5668\uff0c\u7531\u4e2d\u65ad\u63a7\u5236\u5668\u5c06\u4fe1\u53f7\u518d\u8f6c\u53d1\u7ed9CPU\uff0cCPU\u54cd\u5e94\u4e2d\u65ad\u6e90\u7684\u8bf7\u6c42\u3002\u5f53\u4e2d\u65ad\u4ea7\u751f\u65f6\uff0c\u7cfb\u7edf\u9700\u8981\u4fdd\u5b58\u4e0a\u4e0b\u6587\u72b6\u6001\u3002
\u4e2d\u65ad\u7684\u73af\u5883\u6709\u4e24\u79cd\uff1a
\u4efb\u52a1\u4e0a\u4e0b\u6587\uff1a\u65e0\u8bba\u4e2d\u65ad\u7684\u4f18\u5148\u7ea7\u662f\u591a\u5927\uff0c\u90fd\u4f1a\u6253\u65ad\u5f53\u524d\u4efb\u52a1\u7684\u6267\u884c\u3002 \u4e2d\u65ad\u4e0a\u4e0b\u6587\uff1a\u4ec5\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u4e2d\u65ad\u53ef\u4ee5\u6253\u65ad\u5f53\u524d\u4e2d\u65ad\u7684\u6267\u884c\uff0c\u8fd9\u5fc5\u987b\u8981\u7cfb\u7edf\u652f\u6301\u4e2d\u65ad\u5d4c\u5957\u3002 "},{"location":"rtos/freertos/CMSIS/","title":"CMSIS\u6807\u51c6","text":"Cortex\u7cfb\u5217\u7684\u82af\u7247\u5185\u6838\u662f\u76f8\u540c\u7684\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u5382\u5546\u5728\u751f\u4ea7\u7684\u65f6\u5019\u5916\u8bbe\u4f1a\u6709\u533a\u522b\uff0c\u8fd9\u4e9b\u5dee\u5f02\u5bfc\u81f4\u8f6f\u4ef6\u5728\u540c\u5185\u6838\uff0c\u4e0d\u540c\u5916\u8bbe\u7684\u82af\u7247\u4e0a\u79fb\u690d\u56f0\u96be\u3002\u4e3a\u4e86\u89e3\u51b3\u4e0d\u540c\u82af\u7247\u5382\u5546\u751f\u4ea7\u7684\u517c\u5bb9\u6027\u95ee\u9898\uff0cARM\u4e0e\u5404\u82af\u7247\u5382\u5546\u5efa\u8bae\u4e86CMSIS\u6807\u51c6\u3002
\u6240\u8c13\u7684CMSIS\u6807\u51c6\uff0c\u5176\u5b9e\u5c31\u662f\u65b0\u5efa\u4e86\u4e00\u4e2a\u8f6f\u4ef6\u62bd\u8c61\u5c42\uff0c\u5c06\u4e0d\u540c\u7684RTOS\u7684\u63a5\u53e3\u7edf\u4e00\u8d77\u6765\uff0c\u63d0\u4f9bCMSIS\u7684\u63a5\u53e3\u4f9b\u4f7f\u7528\u8005\u4f7f\u7528\u3002
\u672c\u6587\u53ea\u7b80\u5355\u5217\u4e3e\u4e86\u90e8\u5206CMSIS\u6807\u51c6\u4e0b\u7684\u51fd\u6570\u63a5\u53e3\uff0c\u5176\u4ed6\u51fd\u6570\u53ca\u5176\u5b9e\u73b0\u7ec6\u8282\u8bf7\u53c2\u8003\uff1aCMSIS-RTOS2
"},{"location":"rtos/freertos/CMSIS/#_1","title":"\u4efb\u52a1\u7ba1\u7406","text":"osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); //\u521b\u5efa\u4efb\u52a1\nosThreadId_t osThreadGetId(void); //\u8fd4\u56de\u5f53\u524d\u4efb\u52a1ID\nosStatus_t osThreadSuspend(osThreadId_t thread_id); //\u6302\u8d77\u4efb\u52a1\nosStatus_t osThreadResume(osThreadId_t thread_id); //\u6062\u590d\u4efb\u52a1\nosStatus_t osThreadYield(void); //\u4e3b\u52a8\u8ba9\u51fa\u8d44\u6e90\nvoid osThreadExit(void) //\u7ec8\u6b62\u5f53\u524d\u4efb\u52a1\nosStatus_t osThreadTerminate(osThreadId_t thread_id); //\u7ec8\u6b62\u5176\u4ed6\u4efb\u52a1\nosStatus_t osDelay(uint32_t ticks); //\u5ef6\u65f6ticks\u65f6\u949f\u5468\u671f\n
"},{"location":"rtos/freertos/CMSIS/#_2","title":"\u6d88\u606f\u961f\u5217","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5730\u5740\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n void *mq_mem; //\u6570\u636e\u5b58\u50a8\u5730\u5740\n uint32_t mq_size; //\u6570\u636e\u5b58\u50a8\u5927\u5c0f\n}osMessageQueueAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); //\u521b\u5efa\nosStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id); //\u5220\u9664\nosStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); //\u53d1\u9001\u6d88\u606f\nosStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); //\u83b7\u53d6\u6d88\u606f\nosStatus_t osMessageQueueReset(osMessageQueueId_t mq_id); //\u91cd\u7f6e\u6d88\u606f\u961f\u5217\n
"},{"location":"rtos/freertos/CMSIS/#_3","title":"\u4fe1\u53f7\u91cf","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5730\u5740\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osSemaphoreAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); //\u521b\u5efa\nosStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout); //\u83b7\u53d6\nosStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id); //\u91ca\u653e\nuint32_t osSemaphoreGetCount(osSemaphoreID_t semaphore_id); //\u83b7\u53d6\u8ba1\u6570\u91cf\nosStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_4","title":"\u4e92\u65a5\u91cf","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //\u4e92\u65a5\u91cf\u7c7b\u578b\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5185\u5b58 \n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osMutexAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osMutexId_t osMutexNew(const osMutexAttr_t *attr); //\u521b\u5efa\nosStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout); //\u83b7\u53d6\nosStatus_t osMutexRelease(osMutexId_t mutex_id); //\u91ca\u653e\nosStatus_t osMutexDelete(osMutexId_t mutex_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_5","title":"\u4e8b\u4ef6","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5185\u5b58\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osEventFlagsAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr); //\u521b\u5efa\nuint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags); //\u8bbe\u7f6e\u4f4d\nuint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags); //\u6e05\u7a7a\u4f4d\nuint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); //\u7b49\u5f85\u4f4d\nosStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_6","title":"\u4efb\u52a1\u901a\u77e5","text":"CMSIS\u6807\u51c6\u6ca1\u6709\u63d0\u4f9b\u4efb\u52a1\u901a\u77e5\u7684API\uff0c\u5c5e\u4e8eFreeRTOS\u7684\u7279\u6027\u3002
"},{"location":"rtos/freertos/CMSIS/#_7","title":"\u5b9a\u65f6\u5668","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5185\u5b58\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osTimerAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); //\u521b\u5efa\nosStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks); //\u542f\u52a8\nosStatus_t osTimerStop(osTimerId_t timer_id); //\u505c\u6b62\nosStatus_t osTimerDelete(osTimerId_t timer_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_8","title":"\u5185\u5b58\u7ba1\u7406","text":"\u5e38\u7528\u51fd\u6570\uff1a
osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, unit32_t block_size, const osMemoryPoolAttr_t *attr); //\u521b\u5efa\nvoid *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, unit32_t timeout); //\u5206\u914d\nosStatut_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block); //\u91ca\u653e\nosStatus_t osMemoryPoolDelete(osMemoryPoolId_t mp_id); //\u5220\u9664\n
"},{"location":"rtos/rt-thread/","title":"rtt\u5185\u6838\u7b80\u4ecb","text":"\u7531\u4e8e\u4e0d\u540cRTOS\u7684\u5185\u6838\u5927\u5dee\u4e0d\u5dee\uff0c\u8fd9\u91cc\u53ea\u8bb0\u5f55\u4e0brtt\u5185\u6838\u6bd4\u8f83\u7279\u6b8a\u7684\u5730\u65b9\u3002
rtt\u5185\u6838\u67b6\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a
rtt\u5185\u6838\u6a21\u5757\u4e3b\u8981\u5206\u4e3a\uff1a
\u7ebf\u7a0b\u8c03\u5ea6 \u65f6\u949f\u7ba1\u7406 \u7ebf\u7a0b\u95f4\u540c\u6b65\u4e0e\u901a\u4fe1 \u5185\u5b58\u7ba1\u7406 \u4e2d\u65ad\u7ba1\u7406 I/O\u8bbe\u5907\u7ba1\u7406 \u5916\u8bbe\u63a5\u53e3 \u4e0b\u56fe\u663e\u793a\u4e86rtt\u4e2d\u5404\u7c7b\u5185\u6838\u5bf9\u8c61\u7684\u6d3e\u751f\u548c\u7ee7\u627f\u5173\u7cfb\u3002
\u5185\u6838\u5bf9\u8c61\u63a7\u5236\u5757\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct rt_object {\n char name[RT_NAME_MAX]; //\u5185\u6838\u5bf9\u8c61\u540d\u79f0\n rt_uint8_t type; //\u5185\u6838\u5bf9\u8c61\u7c7b\u578b\n rt_uint8_t flag; //\u5185\u6838\u5bf9\u8c61\u53c2\u6570\n rt_list_t list; //\u5185\u6838\u5bf9\u8c61\u7ba1\u7406\u94fe\u8868\n};\n
\u5185\u6838\u5bf9\u8c61\u5bb9\u5668\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct rt_object_information {\n enum rt_object_class_type type; //\u5bf9\u8c61\u7c7b\u578b\n rt_list_t object_list; //\u5bf9\u8c61\u94fe\u8868\n rt_size_t object_size; //\u5bf9\u8c61\u5927\u5c0f\n};\n
\u540c\u4e00\u7c7b\u5bf9\u8c61\u7531\u4e00\u4e2art_object_information\u7ed3\u6784\u4f53\u6765\u7ba1\u7406\uff0c\u8fd9\u7c7b\u5bf9\u8c61\u7684\u6bcf\u4e2a\u5b9e\u4f8b\u4ee5\u94fe\u8868\u7684\u5f62\u5f0f\u6302\u5728object_list\u94fe\u8868\u4e0a\u3002\u5f53\u67d0\u4e2a\u5185\u6838\u5bf9\u8c61\u88ab\u521d\u59cb\u5316\u540e\uff0c\u8be5\u5bf9\u8c61\u5c31\u88ab\u6dfb\u52a0\u5230\u5bf9\u5e94\u5bb9\u5668\u4e2d\u7ba1\u7406\u3002
"},{"location":"rtos/rt-thread/#_1","title":"\u7ebf\u7a0b\u7ba1\u7406","text":"rtt\u4e2d\u7ebf\u7a0b\u72b6\u6001\u591a\u4e86\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\uff0c\u5f53\u7ebf\u7a0b\u521b\u5efa\u5b8c\u6bd5\u8fd8\u6ca1\u5f00\u59cb\u8fd0\u884c\u65f6\u5c31\u5904\u4e8e\u521d\u59cb\u72b6\u6001\uff0c\u8be5\u72b6\u6001\u4e0b\u7ebf\u7a0b\u4e0d\u53c2\u4e0e\u8c03\u5ea6\uff0c\u5b8f\u5b9a\u4e49\u4e3aRT_THREAD_INIT\u3002\u521d\u59cb\u72b6\u6001\u7684\u7ebf\u7a0b\u9700\u8981\u8c03\u7528rt_thread_startup()
\u8fdb\u5165\u5c31\u7eea\u72b6\u6001\u3002
rtt\u6700\u5927\u652f\u6301256\u4e2a\u4f18\u5148\u7ea7\uff0c\u5bf9\u4e8eARM Cortex-M\u7cfb\u5217\u4e00\u822c\u91c7\u752832\u4e2a\u4f18\u5148\u7ea7\u3002
\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u65f6\u95f4\u7247\u53c2\u6570\uff0c\u65f6\u95f4\u7247\u4ec5\u5bf9\u4f18\u5148\u7ea7\u76f8\u540c\u7684\u5c31\u7eea\u72b6\u6001\u7ebf\u7a0b\u6709\u6548\uff08\u5373\u540c\u4f18\u5148\u7ea7\u53c2\u4e0e\u8c03\u5ea6\uff09\u3002\u65f6\u95f4\u7247\u7684\u5355\u4f4d\u662f\u4e00\u4e2a\u7cfb\u7edf\u8282\u62cd\uff0c\u5176\u610f\u4e49\u662f\u7ebf\u7a0b\u5355\u6b21\u8fd0\u884c\u7684\u65f6\u957f\u3002
\u4f7f\u7528rt_thread_create()
\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u52a8\u6001\u7ebf\u7a0b\uff0c\u4f7f\u7528rt_thread_delete()
\u51fd\u6570\u5220\u9664\u4e00\u4e2a\u52a8\u6001\u7ebf\u7a0b\u3002\u9759\u6001\u7ebf\u7a0b\u7684API\u5206\u522b\u662frt_thread_init()
\u51fd\u6570\u548crt_thread_detach()
\u51fd\u6570\u3002\u4f7f\u7528rt_thread_startup()
\u51fd\u6570\u542f\u52a8\u7ebf\u7a0b\uff0crt_thread_yield()
\u51fd\u6570\u8ba9\u51fa\u7ebf\u7a0b\u8d44\u6e90\uff0crt_thread_delay()
\u51fd\u6570\u4f7f\u7ebf\u7a0b\u7761\u7720\uff0crt_thread_resume()
\u51fd\u6570\u6062\u590d\u7ebf\u7a0b\u3002
"},{"location":"rtos/rt-thread/#_2","title":"\u65f6\u949f\u7ba1\u7406","text":"\u5168\u5c40\u53d8\u91cfrt_tick\u6bcf\u6b21\u7ecf\u8fc7\u4e00\u4e2a\u65f6\u949f\u8282\u62cd\uff0c\u503c\u5c31\u4f1a\u52a01\uff0c\u5b83\u8868\u793a\u7cfb\u7edf\u4ece\u542f\u52a8\u5f00\u59cb\u603b\u5171\u7ecf\u8fc7\u7684\u59cb\u7ec8\u8282\u62cd\u6570\u3002\u6b64\u5916\uff0crt_tick\u6bcf\u6b21\u52a01\u90fd\u4f1a\u68c0\u67e5\u5f53\u524d\u7ebf\u7a0b\u7684\u65f6\u95f4\u7247\u662f\u5426\u4f7f\u7528\u5b8c\uff0c\u4ee5\u53ca\u662f\u5426\u6709\u5b9a\u65f6\u5668\u8d85\u65f6\u3002
rtt\u7684\u5b9a\u65f6\u5668\u53ef\u4ee5\u5206\u4e3aHARD_TIMER\u6a21\u5f0f\u2014\u2014\u5728\u4e2d\u65ad\u73af\u5883\u4e2d\u6267\u884c\uff0c\u548cSOFT_TIMER\u6a21\u5f0f\u2014\u2014\u5728\u7ebf\u7a0b\u73af\u5883\u4e2d\u6267\u884c\u3002
\u65b0\u521b\u5efa\u5e76\u6fc0\u6d3b\u7684\u5b9a\u65f6\u5668\u90fd\u4f1a\u4ee5\u8d85\u65f6\u65f6\u95f4\u6392\u5e8f\u7684\u65b9\u5f0f\u63d2\u5165\u5230rt_timer_list\u94fe\u8868\u4e2d\u3002\u6240\u6709\u5b9a\u65f6\u5668\u5728\u5b9a\u65f6\u8d85\u65f6\u540e\u90fd\u4f1a\u4ece\u5b9a\u65f6\u5668\u94fe\u8868\u4e2d\u88ab\u79fb\u9664\uff0c\u800c\u5468\u671f\u6027\u5b9a\u65f6\u5668\u4f1a\u5728\u5b83\u518d\u6b21\u542f\u52a8\u65f6\u88ab\u52a0\u5165\u5b9a\u65f6\u5668\u94fe\u8868\u3002\u4e0e\u5b9a\u65f6\u5668\u6709\u5173\u7684\u64cd\u4f5c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
"},{"location":"rtos/rt-thread/#_3","title":"\u7ebf\u7a0b\u95f4\u540c\u6b65","text":""},{"location":"rtos/rt-thread/#_4","title":"\u4fe1\u53f7\u91cf","text":"\u4fe1\u53f7\u91cf\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
rtt\u5185\u6838\u5728\u521b\u5efa\u4fe1\u53f7\u91cf\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u901a\u8fc7flag\u53c2\u6570\u6307\u5b9a\u4fe1\u53f7\u91cf\u4e0d\u53ef\u7528\u65f6\u591a\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u7684\u6392\u961f\u65b9\u5f0f\u3002\u6bd4\u5982RT_IPC_FLAG_FIFO\u8868\u793a\u6309\u7167\u5148\u8fdb\u5148\u51fa\u7684\u65b9\u5f0f\u6392\u961f\uff0cRT_IPC_FLAG_PRIO\u8868\u793a\u6309\u7167\u4f18\u5148\u7ea7\u7684\u65b9\u5f0f\u8fdb\u884c\u6392\u961f\u3002\u4e00\u822c\u91c7\u7528\u4f18\u5148\u7ea7\u65b9\u5f0f\uff0c\u9664\u975e\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u5728\u610f\u5148\u6765\u540e\u5230\u3002
"},{"location":"rtos/rt-thread/#_5","title":"\u4e92\u65a5\u91cf","text":"\u4e92\u65a5\u91cf\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
\u4e92\u65a5\u91cf\u4e3b\u8981\u9002\u7528\u4e8e\u4ee5\u4e0b\u60c5\u51b5\uff1a
\u7ebf\u7a0b\u591a\u6b21\u6301\u6709\u4e92\u65a5\u91cf\uff0c\u4e92\u65a5\u91cf\u53ef\u4ee5\u9012\u5f52\u6301\u6709\u800c\u4fe1\u53f7\u91cf\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002 \u7531\u4e8e\u591a\u7ebf\u7a0b\u540c\u6b65\u800c\u9020\u6210\u4f18\u5148\u7ea7\u53cd\u8f6c\u95ee\u9898\u3002 "},{"location":"rtos/rt-thread/#_6","title":"\u4e8b\u4ef6\u7ec4","text":"rtt\u5b9a\u4e49\u7684\u4e8b\u4ef6\u96c6\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a
\u4e8b\u4ef6\u53ea\u4e0e\u7ebf\u7a0b\u76f8\u5173\uff0c\u4e8b\u4ef6\u95f4\u76f8\u4e92\u72ec\u7acb\uff1a\u6bcf\u4e2a\u7ebf\u7a0b\u53ef\u62e5\u670932\u4e2a\u4e8b\u4ef6\u6807\u5fd7\uff0c\u91c7\u7528\u4e00\u4e2a32bit\u65e0\u7b26\u53f7\u6574\u578b\u6570\u8fdb\u884c\u8bb0\u5f55\uff0c\u6bcf\u4e00\u4e2abit\u4ee3\u8868\u4e00\u4e2a\u4e8b\u4ef6\uff1b
\u4e8b\u4ef6\u4ec5\u7528\u4e8e\u540c\u6b65\uff0c\u4e0d\u63d0\u4f9b\u6570\u636e\u4f20\u8f93\u529f\u80fd\uff1b
\u4e8b\u4ef6\u65e0\u6392\u961f\u6027\uff0c\u5373\u591a\u6b21\u5411\u7ebf\u7a0b\u53d1\u9001\u540c\u4e00\u4e8b\u4ef6 (\u5982\u679c\u7ebf\u7a0b\u8fd8\u672a\u6765\u5f97\u53ca\u8bfb\u8d70)\uff0c\u5176\u6548\u679c\u7b49\u540c\u4e8e\u53ea\u53d1\u9001\u4e00\u6b21\u3002
\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u62e5\u6709\u4e00\u4e2a\u4e8b\u4ef6\u4fe1\u606f\u6807\u8bb0\uff0c\u5b83\u6709\u4e09\u4e2a\u5c5e\u6027\uff0c\u5206\u522b\u662fRT_EVENT_FLAG_AND(\u903b\u8f91\u4e0e)\uff0cRT_EVENT_FLAG_OR(\u903b\u8f91\u6216\uff09\u4ee5\u53caRT_EVENT_FLAG_CLEAR(\u6e05\u9664\u6807\u8bb0\uff09\u3002\u5f53\u7ebf\u7a0b\u7b49\u5f85\u4e8b\u4ef6\u540c\u6b65\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc732\u4e2a\u4e8b\u4ef6\u6807\u5fd7\u548c\u8fd9\u4e2a\u4e8b\u4ef6\u4fe1\u606f\u6807\u8bb0\u6765\u5224\u65ad\u5f53\u524d\u63a5\u6536\u7684\u4e8b\u4ef6\u662f\u5426\u6ee1\u8db3\u540c\u6b65\u6761\u4ef6\u3002
\u4e8b\u4ef6\u7ec4\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_7","title":"\u7ebf\u7a0b\u95f4\u901a\u4fe1","text":""},{"location":"rtos/rt-thread/#_8","title":"\u90ae\u7bb1","text":"\u90ae\u7bb1\u7684\u7279\u70b9\u662f\u5f00\u9500\u6bd4\u8f83\u4f4e\uff0c\u6548\u7387\u8f83\u9ad8\u3002\u90ae\u7bb1\u4e2d\u7684\u6bcf\u4e00\u5c01\u90ae\u4ef6\u53ea\u80fd\u5bb9\u7eb3\u56fa\u5b9a\u76844\u5b57\u8282\u5185\u5bb9\uff0c\u4e5f\u5c31\u662f\u8bf4\u90ae\u7bb1\u53ea\u80fd\u7528\u6765\u4f20\u8f93\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5bb9\u3002\u90ae\u7bb1\u4f7f\u7528\u4e00\u4e2a\u56fa\u5b9a\u7f13\u51b2\u533a\u5927\u5c0f\u6765\u5b58\u50a8\u90ae\u4ef6\uff0c\u5176\u5927\u5c0f\u5728\u521b\u5efa\u65f6\u88ab\u5b9a\u4e49\u3002
\u975e\u963b\u585e\u65b9\u5f0f\u7684\u90ae\u4ef6\u53d1\u9001\u8fc7\u7a0b\u80fd\u591f\u5b89\u5168\u7684\u5e94\u7528\u4e8e\u4e2d\u65ad\u670d\u52a1\u4e2d\uff0c\u662f\u7ebf\u7a0b\u3001\u4e2d\u65ad\u670d\u52a1\u3001\u5b9a\u65f6\u5668\u5411\u7ebf\u7a0b\u53d1\u9001\u6d88\u606f\u7684\u6709\u6548\u624b\u6bb5\u3002\u6839\u636e\u5bf9\u5e94\u7684\u60c5\u51b5\uff0c\u90ae\u7bb1\u7684\u6536\u53d6\u6216\u8005\u53d1\u9001\u90fd\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u8d85\u65f6\u963b\u585e\uff0c\u8fdb\u5165\u963b\u585e\u72b6\u6001\u7684\u7ebf\u7a0b\u5c06\u7761\u7720\uff0c\u7b49\u5f85\u5bf9\u5e94\u6761\u4ef6\u6ee1\u8db3\u540e\u5524\u9192\u3002
\u90ae\u7bb1\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_9","title":"\u6d88\u606f\u961f\u5217","text":"\u6d88\u606f\u961f\u5217\u662f\u90ae\u7bb1\u7684\u6269\u5c55\uff0c\u53ef\u4ee5\u7528\u6765\u4f20\u8f93\u4e0d\u56fa\u5b9a\u957f\u5ea6\u7684\u5185\u5bb9\u3002
\u6d88\u606f\u961f\u5217\u9700\u8981\u5c06\u6d88\u606f\u7f13\u5b58\u5728\u81ea\u5df1\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u56e0\u6b64\u5185\u5b58\u5360\u7528\u6bd4\u90ae\u7bb1\u8981\u5927\u3002\u591a\u4e2a\u7ebf\u7a0b\u80fd\u591f\u8bfb\u53d6\u540c\u4e00\u4e2a\u6d88\u606f\u961f\u5217\u3002\u800c\u5f53\u6d88\u606f\u961f\u5217\u662f\u7a7a\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u6302\u8d77\u8bfb\u53d6\u7ebf\u7a0b\u3002\u5f53\u6709\u65b0\u7684\u6d88\u606f\u5230\u8fbe\u65f6\uff0c\u6302\u8d77\u7684\u7ebf\u7a0b\u5c06\u88ab\u5524\u9192\u4ee5\u63a5\u6536\u5e76\u5904\u7406\u6d88\u606f\u3002\u6d88\u606f\u961f\u5217\u662f\u4e00\u79cd\u5f02\u6b65\u7684\u901a\u4fe1\u65b9\u5f0f\u3002
\u6d88\u606f\u961f\u5217\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_10","title":"\u4fe1\u53f7","text":"\u4fe1\u53f7\u5176\u5b9e\u662f\u7528\u6237\u5c42\u9762\u5bf9\u786c\u4ef6\u4e2d\u65ad\u7684\u4e00\u79cd\u6a21\u62df\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u6536\u5230\u4fe1\u53f7\u4e4b\u540e\u4f1a\u8f6c\u53bb\u5bf9\u5e94\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002rtt\u4e2d\u4f7f\u7528rt_sigset_t\u7c7b\u578b\u6765\u5b9a\u4e49\u4fe1\u53f7\u96c6\u3002
\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u6536\u5230\u4fe1\u53f7\u65f6\uff0c\u5982\u679c\u5b83\u5904\u4e8e\u6302\u8d77\u72b6\u6001\uff0c\u90a3\u4e48\u5b83\u4f1a\u6539\u4e3a\u5c31\u7eea\u72b6\u6001\u53bb\u5904\u7406\u5bf9\u5e94\u7684\u4fe1\u53f7\u3002
\u4fe1\u53f7\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
\u5728\u4fe1\u53f7\u7684\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u5148\u5b9a\u4e49\u7ebf\u7a0b\u9700\u8981\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\uff0c\u7136\u540e\u4f7f\u7528rt_signal_install()
\u51fd\u6570\u5c06signo\u4e0e\u5bf9\u5e94\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u76f8\u5173\u8054\u3002
"},{"location":"rtos/rt-thread/#_11","title":"\u5185\u5b58\u7ba1\u7406","text":"\u5b9e\u65f6\u7cfb\u7edf\u8981\u6c42\u5185\u5b58\u5757\u7684\u5206\u914d\u8fc7\u7a0b\u5728\u53ef\u9884\u6d4b\u7684\u65f6\u95f4\u5185\u5b8c\u6210\uff0c\u5426\u5219\u5b9e\u65f6\u4efb\u52a1\u5bf9\u5916\u90e8\u4e8b\u4ef6\u7684\u54cd\u5e94\u5c06\u53d8\u5f97\u4e0d\u786e\u5b9a\u3002rtt\u5185\u6838\u5728\u5185\u5b58\u5206\u914d\u7ba1\u7406\u7b97\u6cd5\u4e0a\uff0c\u63d0\u4f9b\u4e86\u4e24\u5927\u7c7b\uff1a\u5185\u5b58\u5806\u7ba1\u7406\u4e0e\u5185\u5b58\u6c60\u7ba1\u7406\u3002\u800c\u5185\u5b58\u5bf9\u7ba1\u7406\u53c8\u5212\u5206\u4e3a\u4e09\u79cd\u60c5\u51b5\uff1a\u5c0f\u5185\u5b58\u7ba1\u7406\u7b97\u6cd5\uff0cslab\u7ba1\u7406\u7b97\u6cd5\u548cmemheap\u7ba1\u7406\u7b97\u6cd5\u3002
"},{"location":"rtos/rt-thread/#_12","title":"\u5185\u5b58\u5806\u7ba1\u7406","text":"\u5c0f\u5185\u5b58\u7ba1\u7406\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5185\u5b58\u5206\u914d\u7b97\u6cd5\u3002\u521d\u59cb\u65f6\uff0c\u5b83\u662f\u4e00\u5757\u5927\u5185\u5b58\uff0c\u5f53\u9700\u8981\u5206\u914d\u5185\u5b58\u5757\u65f6\uff0c\u4ece\u8fd9\u5757\u5927\u5185\u5b58\u4e0a\u5206\u5272\u51fa\u54cd\u5e94\u7684\u5185\u5b58\u5757\uff0c\u7a7a\u95f2\u7684\u5185\u5b58\u5757\u5f52\u8fd8\u7ed9\u5806\u7ba1\u7406\u7cfb\u7edf\u3002\u6bcf\u4e2a\u5185\u5b58\u5757\u90fd\u7528\u53cc\u5411\u94fe\u8868\u7684\u65b9\u5f0f\u94fe\u63a5\u8d77\u6765\u3002\u901a\u8fc7*used\u6210\u5458\u53d8\u91cf\u6807\u8bb0\u5f53\u524d\u5185\u5b58\u5757\u662f\u5426\u5df2\u88ab\u4f7f\u7528\u3002
slab\u5206\u914d\u5668\u4f1a\u6839\u636e\u5bf9\u8c61\u7684\u5927\u5c0f\u5206\u6210\u591a\u4e2a\u533a\uff08zone\uff09\uff0c\u4e00\u4e2azone\u7684\u5927\u5c0f\u572832K\u5230128K\u5b57\u8282\u4e4b\u95f4\uff0c\u7cfb\u7edf\u4e2d\u7684zone\u6700\u591a\u5305\u62ec72\u79cd\u5bf9\u8c61\uff0c\u4e00\u6b21\u6027\u6700\u5927\u53ef\u4ee5\u5206\u914d16K\u7684\u7a7a\u95f4\u3002\u5982\u679c\u8d85\u51fa\u4e8616K\u5219\u76f4\u63a5\u4ece\u9875\u5206\u914d\u5668\u4e2d\u5206\u914d\u3002\u6bcf\u4e2azone\u4e0a\u90fd\u662f\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u5757\u94fe\u63a5\u5728\u4e00\u8d77\u3002\u800c72\u79cd\u5bf9\u8c61\u7684zone\u94fe\u8868\u5219\u653e\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7edf\u4e00\u7ba1\u7406\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
memheap\u7ba1\u7406\u7b97\u6cd5\u9002\u7528\u4e8e\u7cfb\u7edf\u6709\u591a\u4e2a\u4e0d\u53ef\u8fde\u7eed\u5730\u5740\u7684\u5185\u5b58\u5806\u3002\u7528\u6237\u53ea\u9700\u8981\u5728\u7cfb\u7edf\u521d\u59cb\u5316\u65f6\u5c06\u591a\u4e2a\u6240\u9700\u7684memheap\u521d\u59cb\u5316\uff0c\u5e76\u5f00\u542fmemheap\u529f\u80fd\u5c31\u53ef\u4ee5\u5c06\u591a\u4e2amemheap\u7c98\u5408\u8d77\u6765\u7edf\u4e00\u7528\u4f5c\u5185\u5b58\u5206\u914d\u3002
\u5728\u4f7f\u7528\u5185\u5b58\u5806\u65f6\uff0c\u5fc5\u987b\u5728\u7cfb\u7edf\u521d\u59cb\u5316\u7684\u65f6\u5019\u8fdb\u884c\u5806\u7684\u521d\u59cb\u5316\uff1a
void rt_system_heap_init(void *begin_addr, void *end_addr);\n
\u5185\u5b58\u5806\u7ba1\u7406\u7684\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_13","title":"\u5185\u5b58\u6c60\u7ba1\u7406","text":"\u9891\u7e41\u5730\u8c03\u7528\u5185\u5b58\u5206\u914d\u548c\u91ca\u653e\u51fd\u6570\u4f1a\u5bfc\u81f4\u5185\u5b58\u788e\u7247\uff0c\u56e0\u6b64rtt\u5f15\u8fdb\u4e86\u53e6\u5916\u4e00\u79cd\u5185\u5b58\u7ba1\u7406\u65b9\u6cd5\uff1a\u5185\u5b58\u6c60\u3002
\u5185\u5b58\u6c60\u7528\u4e8e\u5206\u914d\u5927\u91cf\u5927\u5c0f\u76f8\u540c\u7684\u5c0f\u5185\u5b58\u5757\uff0c\u5185\u5b58\u6c60\u5728\u521b\u5efa\u65f6\u5148\u5411\u7cfb\u7edf\u7533\u8bf7\u4e00\u5927\u5757\u5185\u5b58\uff0c\u7136\u540e\u5206\u6210\u540c\u6837\u5927\u5c0f\u7684\u591a\u4e2a\u5c0f\u5185\u5b58\u5757\uff0c\u5c0f\u5185\u5b58\u5757\u76f4\u63a5\u901a\u8fc7\u94fe\u8868\u8fde\u63a5\u8d77\u6765\uff08\u6b64\u94fe\u8868\u4e5f\u79f0\u4e3a\u7a7a\u95f2\u94fe\u8868\uff09\u3002\u6bcf\u6b21\u5206\u914d\u7684\u65f6\u5019\uff0c\u4ece\u7a7a\u95f2\u94fe\u8868\u4e2d\u53d6\u51fa\u94fe\u5934\u4e0a\u7b2c\u4e00\u4e2a\u5185\u5b58\u5757\uff0c\u63d0\u4f9b\u7ed9\u7533\u8bf7\u8005\u3002\u5185\u5b58\u6c60\u4e00\u65e6\u521d\u59cb\u5316\u5b8c\u6210\uff0c\u5185\u90e8\u7684\u5185\u5b58\u5757\u5927\u5c0f\u5c06\u4e0d\u80fd\u518d\u505a\u8c03\u6574\u3002
\u5185\u5b58\u6c60\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_14","title":"\u4e2d\u65ad\u7ba1\u7406","text":""},{"location":"tools/","title":"\u5de5\u5177\u7684\u4f7f\u7528","text":""},{"location":"tools/github/","title":"github\u7684\u4f7f\u7528","text":"\u7531\u4e8e\u4f17\u6240\u5468\u77e5\u7684\u539f\u56e0\uff0cgithub\u5728\u56fd\u5185\u7684\u8bbf\u95ee\u4e0d\u5c3d\u5982\u4eba\u610f\uff0c\u4f46\u662f\u56fd\u5916\u5f00\u6e90\u9879\u76ee\u51e0\u4e4e\u90fd\u90e8\u7f72\u5728github\u4e0a\uff0c\u4e0d\u5f97\u4e0d\u7528\u3002\u5982\u679c\u662f\u81ea\u5df1\u7684\u865a\u62df\u673a\u8fde\u63a5\u7f51\u901f\u6bd4\u8f83\u6162\uff0c\u5efa\u8bae\u5f00\u4e2a\u68af\u5b50\u7136\u540e\u914d\u7f6e\u4e0b\u6d41\u91cf\u4ee3\u7406\uff1a
git config --global http.proxy http://127.0.0.1:[\u7aef\u53e3\u53f7]\n\ngit config --global https.proxy http://127.0.0.1:[\u7aef\u53e3\u53f7]\n
\u8fd9\u4e24\u884c\u547d\u4ee4\u7684\u610f\u601d\u662f\u8ba9http\u548chttps\u534f\u8bae\u7684\u6d41\u91cf\u5168\u90e8\u8d70\u4f60\u68af\u5b50\u7684\u4ee3\u7406\uff0c\u7aef\u53e3\u53f7\u6839\u636e\u68af\u5b50\u7684\u914d\u7f6e\u81ea\u884c\u8f93\u5165\u3002\u914d\u7f6e\u5b8c\u4ee5\u540egit clone
\u5e94\u8be5\u4e0d\u4f1a\u5361\u4e86\u3002\u5982\u679c\u4f60\u8981\u53d6\u6d88\u5168\u5c40\u4ee3\u7406\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a
git config --global --unset http.proxy\n\ngit config --global --unset https.proxy\n
\u4e00\u822c\u6765\u8bf4\uff0cgithub\u7684SSH\u9ed8\u8ba4\u901a\u8fc7\u7aef\u53e322\u5efa\u7acb\u8fde\u63a5\uff0c\u9664\u975e\u4f60\u66f4\u6539\u4e86\u914d\u7f6e\u6587\u4ef6\u5f3a\u5236\u4f7f\u7528HTTPS\u7684443\u7aef\u53e3\u8fde\u63a5\u3002
\u8981\u6d4b\u8bd5\u901a\u8fc7HTTPS\u7aef\u53e3\u7684SSH\u8fde\u63a5\u662f\u5426\u53ef\u884c\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a
ssh -T -p 443 git@ssh.github.com\n\n> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.\n
\u5982\u679c\u8f93\u51fa\u4ee5\u4e0a\u5185\u5bb9\uff0c\u5219\u8bf4\u660e\u8fde\u63a5\u53ef\u884c\u3002\u4f60\u53ef\u4ee5\u66f4\u6539~/.ssh/config\u6587\u4ef6\uff0c\u5f3a\u5236\u4e0egithub\u7684\u8fde\u63a5\u90fd\u901a\u8fc7\u8be5\u670d\u52a1\u5668\u548c\u7aef\u53e3\uff1a Host github.com\nHostname ssh.github.com\nPort 443\nUser git\n
\u901a\u8fc7\u518d\u6b21\u8fde\u63a5\u5230github\u6765\u6d4b\u8bd5\u662f\u5426\u6709\u6548\uff0c\u6ce8\u610f\u8fd9\u65f6\u5c31\u4e0d\u9700\u8981\u6307\u5b9a\u7aef\u53e3\u53f7\u4e86\uff1a
ssh -T git@github.com\n\n> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.\n
\u6ce8\u610f\uff1aSSH\u901a\u8fc7\u516c\u94a5\u548c\u79c1\u94a5\u914d\u5bf9\u7684\u65b9\u5f0f\u6765\u9a8c\u8bc1\u8fde\u63a5\u662f\u5426\u5b89\u5168\uff0c\u5f53\u4f60\u7b2c\u4e00\u6b21\u901a\u8fc7SSH\u8fde\u63a5\u65f6\uff0c\u4f1a\u8be2\u95ee\u4f60\u662f\u5426\u4fe1\u4efb\u8be5\u670d\u52a1\u5668\uff0c\u8f93\u5165yes\u5373\u53ef\u3002
"},{"location":"tools/github/#ssh","title":"\u6dfb\u52a0SSH\u5bc6\u94a5","text":"\u6dfb\u52a0SSH\u5bc6\u94a5\u7684\u8fc7\u7a0b\u5f88\u7b80\u5355\uff0c\u6309\u7167\u6b65\u9aa4\u4e00\u6b65\u6b65\u6765\u5373\u53ef\u3002
1.\u9996\u5148\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u90ae\u4ef6\u5730\u5740\u6539\u4e3a\u4f60\u6ce8\u518cgithub\u7684\u90ae\u7bb1\uff1a
ssh-keygen -t ed25519 -C \"your_email@example.com\"\n
\u7cfb\u7edf\u4f1a\u8981\u6c42\u4f60\u8f93\u5165\u4e00\u4e9b\u4fe1\u606f\uff0c\u8fde\u7eed\u6309\u56de\u8f66\u8df3\u8fc7\u5373\u53ef\u3002
2.\u5c06SSH\u5bc6\u94a5\u6dfb\u52a0\u5230ssh-agent\uff1a
\u5148\u542f\u52a8ssh\u4ee3\u7406\uff1a
eval \"$(ssh-agent -s)\"\n
\u7136\u540e\u6dfb\u52a0\u79c1\u94a5\uff1a
ssh-add ~/.ssh/id_ed25519\n
3.\u5411\u4f60\u7684\u8d26\u6237\u6dfb\u52a0\u65b0\u7684SSH\u5bc6\u94a5
\u73b0\u5728\uff0c.ssh/\u76ee\u5f55\u4e0b\u6709\u4e24\u4e2a\u6587\u4ef6\uff0c\u4ee5pub\u7ed3\u5c3e\u7684\u5c31\u662f\u516c\u94a5\uff0c\u9700\u8981\u4f60\u4e0a\u4f20\u81f3github\u670d\u52a1\u5668\u3002
cat ~/.ssh/id_ed25519.pub\n
\u590d\u5236\u6253\u5370\u7684\u5185\u5bb9\uff0c\u7136\u540e\u5728github\u4e2a\u4eba\u8d44\u6599\u9762\u70b9\u51fb\u8bbe\u7f6e\uff0c\u627e\u5230SSH and GPG keys
\uff0c\u70b9\u51fbNew SSH key
\uff0c\u6700\u540e\u7c98\u8d34\u590d\u5236\u7684\u516c\u94a5\u5373\u53ef\u3002
"},{"location":"tools/github/#_1","title":"\u7ba1\u7406\u8fdc\u7a0b\u4ed3\u5e93","text":"\u8981\u6dfb\u52a0\u4e00\u4e2a\u8fdc\u7a0b\u4ed3\u5e93\u94fe\u63a5\uff0c\u4f7f\u7528git remote add
\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u9700\u8981\u4e24\u4e2a\u53c2\u6570\uff1a
\u8fdc\u7a0b\u4ed3\u5e93\u540d\uff0c\u6bd4\u5982origin
\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\uff0c\u6bd4\u5982https://github.com/OWNER/REPOSITORY.git
git remote add origin https://github.com/OWNER/REPOSITORY.git\n
\u5728\u6dfb\u52a0\u5b8c\u8fdc\u7a0b\u4ed3\u5e93\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528git remote -v
\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u4f60\u5f53\u524d\u6dfb\u52a0\u7684\u8fdc\u7a0b\u4ed3\u5e93\uff1a
git remote -v\n# Verify new remote\n> origin https://github.com/OWNER/REPOSITORY.git (fetch)\n> origin https://github.com/OWNER/REPOSITORY.git (push)\n
\u5982\u679c\u8981\u66f4\u6539\u8fde\u63a5\u8fdc\u7a0b\u4ed3\u5e93\u7684\u65b9\u5f0f\uff0c\u6bd4\u5982\u4eceHTTPS\u6539\u4e3aSSH\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528git remote set-url
\u547d\u4ee4\uff1a
git remote set-url origin git@github.com:OWNER/REPOSITORY.git\n
\u8fd9\u65f6\u8fdc\u7a0b\u4ed3\u5e93\u7684\u683c\u5f0f\u5e94\u8be5\u662f\uff1a
origin git@github.com:OWNER/REPOSITORY.git (fetch)\norigin git@github.com:OWNER/REPOSITORY.git (push)\n
"},{"location":"tools/github/#git","title":"git\u5e38\u7528\u547d\u4ee4","text":"\u9879\u76ee\u521d\u59cb\u5316\uff1a
git init\n
\u521d\u59cb\u5316\u4e2a\u4eba\u4fe1\u606f\uff1a
git config --global user.name \"\u4f60\u7684\u540d\u5b57\"\ngit config --global user.email \"\u4f60\u7684\u90ae\u7bb1\"\n
\u5c06\u53d8\u52a8\u7684\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff1a
git add --all\n
\u63d0\u4ea4\u4ee3\u7801\uff1a
git commit -m \"\u63d0\u4ea4\u4fe1\u606f\"\n
\u63a8\u9001\u4ee3\u7801\uff1a
git push origin main\n
origin\u66ff\u6362\u4e3a\u8fdc\u7a0b\u4ed3\u5e93\u7684\u540d\u79f0\uff0cmain\u66ff\u6362\u4e3a\u63d0\u4ea4\u7684\u5206\u652f\u540d
\u62c9\u53d6\u4ee3\u7801\u5230\u672c\u5730\uff1a
git push origin main\n
\u67e5\u770b\u5f53\u524dgit\u72b6\u6001\uff1a
git status\n
\u67e5\u770b\u63d0\u4ea4\u65e5\u5fd7\uff1a
git log\n
\u5207\u6362\u5206\u652f\uff1a
git check -b [\u65b0\u5206\u652f\u540d]\n
\u5408\u5e76\u4ee3\u7801\uff1a
git merge [\u53e6\u4e00\u4e2a\u5206\u652f\u540d]\n
"}]}
\ No newline at end of file
+{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":""},{"location":"#_1","title":"\u6b22\u8fce\u6765\u5230\u6211\u7684\u9891\u9053","text":"\u6ca1\u6709\u5b66\u672f\u7684\u6c11\u4e3b\u548c\u601d\u60f3\u7684\u81ea\u7531\uff0c\u79d1\u5b66\u5c31\u4e0d\u80fd\u7e41\u8363\u3002 \u2014\u2014\u2014\u20142003\u7248\u9ad8\u4e00\u7269\u7406\u5fc5\u4fee\u4e00\u8bfe\u672c
\u8fd9\u91cc\u4e3b\u8981\u5206\u4eab\u6211\u7684\u5b66\u4e60\u7b14\u8bb0\u548c\u5fc3\u5f97\u4f53\u4f1a\uff0c\u53c2\u8003\u8d44\u6599\u4e8e\u6bcf\u4e2a\u4e3b\u9875\u9762\u5217\u51fa\u3002
"},{"location":"#_2","title":"\u5feb\u901f\u5bfc\u822a","text":" Linux
RTOS
Arm
\u7f16\u7a0b\u8bed\u8a00
\u4e91\u539f\u751f
Tools
\u5176\u4ed6
"},{"location":"#inspired-by","title":"Inspired by:","text":" CS\u81ea\u5b66\u6307\u5357 \u4e0a\u6d77\u4ea4\u901a\u5927\u5b66\u751f\u5b58\u624b\u518c "},{"location":"arm/","title":"Arm\u5b66\u4e60\u7b14\u8bb0","text":""},{"location":"arm/barrier/","title":"\u5185\u5b58\u5c4f\u969c","text":""},{"location":"linux/","title":"\u5feb\u901f\u5165\u95e8","text":"Linux\u7684\u77e5\u8bc6\u4f53\u7cfb\u592a\u8fc7\u5e9e\u5927\uff0c\u4f46\u662f\u5165\u95e8\u5e76\u4e0d\u96be\uff0c\u4e13\u6ce8\u4e8e\u57fa\u7840\u547d\u4ee4\u548cLinux\u73af\u5883\u4e0b\u7684C\u7f16\u7a0b\uff0c\u5bf9\u4e8e\u6253\u4e0b\u57fa\u7840\u975e\u5e38\u91cd\u8981\u3002
\u9996\u5148\uff0c\u4f60\u9700\u8981\u4e00\u4e2a\u5b89\u88c5\u4e86ubuntu\u6216\u8005\u5176\u4ed6\u53d1\u884c\u7248\u7684\u865a\u62df\u673a\uff0c\u4f46\u6211\u66f4\u52a0\u63a8\u8350\u4f60\u7528\u4e91\u670d\u52a1\u5668\u6765\u5b66\u4e60Linux\uff0c\u56e0\u4e3a\uff1a
\u4e91\u670d\u52a1\u5668\u901a\u5e38\u4e0d\u63d0\u4f9b\u684c\u9762\u754c\u9762\uff0c\u8fd9\u53ef\u4ee5\u8feb\u4f7f\u4f60\u66f4\u6df1\u5165\u5730\u7406\u89e3\u5e76\u638c\u63e1\u5404\u79cd\u547d\u4ee4\u884c\u64cd\u4f5c\u3002 \u7531\u4e8e\u4e91\u670d\u52a1\u5668\u901a\u5e38\u9700\u8981\u4ed8\u8d39\uff0c\u4f60\u4f1a\u66f4\u52a0\u73cd\u60dc\u8fd9\u4e2a\u5b66\u4e60\u673a\u4f1a\uff0c\u5e76\u6295\u5165\u66f4\u591a\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u53bb\u5b66\u4e60\u3002 \u4e91\u670d\u52a1\u5668\u53ea\u9700\u8981\u4f60\u7535\u8111\u80fd\u8054\u7f51\u5c31\u53ef\u4ee5\u64cd\u4f5c\uff0c\u800c\u865a\u62df\u673a\u5bf9\u4e8e\u4e00\u822c\u7684\u8f7b\u8584\u672c\u6765\u8bf4\u662f\u4e2a\u4e0d\u5c0f\u7684\u8d1f\u62c5\u3002 \u4e91\u670d\u52a1\u5668\u5bf9\u4e8e\u7f51\u7edc\u73af\u5883\u505a\u4e86\u4f18\u5316\uff0c\u5e76\u4e14\u5404\u5927\u670d\u52a1\u5668\u5382\u5546\u63d0\u4f9b\u4e86\u4e00\u952e\u914d\u7f6e\u73af\u5883\u7684\u529f\u80fd\uff0c\u4f7f\u7528\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\u3002 \u5f53\u4f60\u8d2d\u4e70\u4e86\u4e91\u670d\u52a1\u5668\u4e4b\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7SSH\u8fdc\u7a0b\u8fde\u63a5\u5230\u670d\u52a1\u5668\uff0cVSCODE\u7684SSH\u63d2\u4ef6\u53ef\u4ee5\u8fdb\u884c\u8fdc\u7a0b\u5f00\u53d1\uff0c\u4f53\u9a8c\u4e0e\u672c\u5730\u5f00\u53d1\u65e0\u5f02\u3002\u5177\u4f53\u7684\u6b65\u9aa4\u4f60\u53ef\u4ee5\u53c2\u8003\u7f51\u4e0a\u7684\u76f8\u5173\u6559\u7a0b\u3002
\u4e00\u65e6\u4f60\u6210\u529f\u8fdb\u5165Linux\u73af\u5883\uff0c\u9996\u5148\u5e94\u8be5\u6267\u884c\u7684\u662fsudo apt update
\u548csudo apt upgrade
\u547d\u4ee4\uff0c\u4ee5\u66f4\u65b0\u4f60\u7684\u8f6f\u4ef6\u5305\u3002\u5b89\u88c5\u8f6f\u4ef6\u5305\u53ef\u4ee5\u4f7f\u7528sudo apt install [pkg_name]
\u547d\u4ee4\u3002\u5982\u679c\u4f60\u662f\u5728\u672c\u5730\u865a\u62df\u673a\u4e0a\u64cd\u4f5c\uff0c\u5efa\u8bae\u5728\u66f4\u65b0\u8f6f\u4ef6\u5305\u524d\u5c06\u8f6f\u4ef6\u6e90\u66f4\u6362\u4e3a\u56fd\u5185\u7684\u955c\u50cf\u6e90\uff0c\u4ee5\u83b7\u5f97\u66f4\u5feb\u7684\u4e0b\u8f7d\u901f\u5ea6\u3002
\u5728\u547d\u4ee4\u884c\u754c\u9762\u4e0b\uff0c\u4f60\u9700\u8981\u719f\u7ec3\u638c\u63e1\u5927\u7ea6\u5341\u51e0\u4e2a\u57fa\u7840\u547d\u4ee4\uff0c\u5176\u4ed6\u547d\u4ee4\u53ef\u4ee5\u5728\u9700\u8981\u65f6\u518d\u67e5\u8be2\uff0c\u65e0\u9700\u4e13\u95e8\u8bb0\u5fc6\u3002\u540c\u65f6\uff0c\u4f60\u8fd8\u9700\u8981\u7406\u89e3\u7ba1\u9053\u548c\u91cd\u5b9a\u5411\u7684\u6982\u5ff5\u3002
\u4e3a\u4e86\u5728\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0b\u7f16\u8f91\u6587\u4ef6\uff0c\u4f60\u81f3\u5c11\u9700\u8981\u719f\u6089\u4e00\u79cd\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f8b\u5982VIM\u3002\u4f46\u4e0d\u8981\u671f\u671b\u4e00\u5f00\u59cb\u5c31\u80fd\u719f\u7ec3\u4f7f\u7528VIM\uff0c\u8fd9\u662f\u4e00\u4e2a\u9010\u6b65\u5b66\u4e60\u7684\u8fc7\u7a0b\u3002\u8bb0\u4f4f\uff0c\u5de5\u5177\u662f\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0c\u5982\u679c\u5b83\u964d\u4f4e\u4e86\u4f60\u7684\u6548\u7387\uff0c\u90a3\u4e48\u6682\u65f6\u53ef\u4ee5\u9009\u62e9\u5176\u4ed6\u66f4\u9002\u5408\u4f60\u7684\u7f16\u8f91\u5668\u3002
\u8bf7\u505c\u6b62\u4f7f\u7528\u201cRUN\u201d\u6309\u94ae\u6765\u8fd0\u884c\u7a0b\u5e8f\uff0c\u800c\u662f\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u7f16\u8bd1\u4f60\u7684\u6e90\u4ee3\u7801\u3002\u4e86\u89e3GCC\u5982\u4f55\u5c06\u4f60\u7684\u4ee3\u7801\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u53ca\u591a\u4e2a\u6587\u4ef6\u662f\u5982\u4f55\u94fe\u63a5\u6210\u4e00\u4e2a\u7a0b\u5e8f\u7684\u8fc7\u7a0b\uff0c\u8fd9\u4e9b\u77e5\u8bc6\u5c06\u968f\u7740\u4f60\u7684\u6df1\u5165\u5b66\u4e60\u800c\u9010\u6e10\u638c\u63e1\u3002
\u968f\u7740\u6e90\u6587\u4ef6\u6570\u91cf\u7684\u589e\u52a0\u548c\u9879\u76ee\u5de5\u7a0b\u7684\u590d\u6742\u5316\uff0c\u624b\u52a8\u8f93\u5165\u5197\u957f\u7684GCC\u547d\u4ee4\u4f1a\u53d8\u5f97\u4f4e\u6548\u3002\u8fd9\u65f6\uff0c\u4f60\u9700\u8981\u4f7f\u7528Makefile\u6587\u4ef6\u6765\u7ec4\u7ec7\u4f60\u7684\u5de5\u7a0b\u3002\u4e3a\u4e86\u7f16\u5199Makefile\u6587\u4ef6\uff0c\u4f60\u9700\u8981\u4e86\u89e3\u5176\u57fa\u672c\u8bed\u6cd5\u3002\u4e0d\u8fc7\uff0c\u6211\u66f4\u63a8\u8350\u4f60\u4f7f\u7528CMake\u5de5\u5177\uff0c\u5b83\u80fd\u591f\u4e00\u952e\u751f\u6210Makefile\uff0c\u5e76\u4e14\u5176\u8bed\u6cd5\u66f4\u52a0\u76f4\u89c2\u6613\u61c2\uff0c\u7279\u522b\u9002\u5408\u7ba1\u7406\u5927\u578b\u9879\u76ee\u3002
\u5230\u8fbe\u8fd9\u4e00\u6b65\uff0c\u4f60\u5df2\u7ecf\u5bf9Linux\u73af\u5883\u4e0b\u7684C\u7f16\u7a0b\u6709\u4e86\u521d\u6b65\u7684\u8ba4\u8bc6\u3002\u63a5\u4e0b\u6765\uff0c\u4f60\u9700\u8981\u719f\u6089Linux\u63d0\u4f9b\u7684C\u5e93\u51fd\u6570\uff0c\u5305\u62ec\u6587\u4ef6\u64cd\u4f5c\u3001\u8f93\u5165\u8f93\u51fa\u3001\u8fdb\u7a0b\u63a7\u5236\u3001\u591a\u7ebf\u7a0b\u540c\u6b65\u7b49\u3002\u8fd9\u4e9b\u5185\u5bb9\u5728\u8bb8\u591a\u4e66\u7c4d\u548c\u89c6\u9891\u4e2d\u90fd\u6709\u8be6\u7ec6\u7684\u8bb2\u89e3\u3002
\u4ee5\u4e0a\u5185\u5bb9\u6784\u6210\u4e86Linux C\u5f00\u53d1\u7684\u57fa\u7840\u3002\u5bf9\u4e8e\u66f4\u6df1\u5165\u7684\u5b66\u4e60\uff0c\u8bf7\u6839\u636e\u4e2a\u4eba\u5174\u8da3\u548c\u9700\u6c42\u81ea\u884c\u67e5\u627e\u76f8\u5173\u8d44\u6599\u3002
"},{"location":"linux/#_2","title":"\u53c2\u8003\u8d44\u6599","text":" \u8da3\u8c08Linux\u64cd\u4f5c\u7cfb\u7edf
\u6df1\u5165Linux\u5185\u6838\u67b6\u6784
\u7cbe\u901a\u5d4c\u5165\u5f0fLinux\u7f16\u7a0b
\u6df1\u5165\u7406\u89e3LINUX\u5185\u6838(\u7b2c3\u7248)
Linux\u5185\u6838\u8bbe\u8ba1\u4e0e\u5b9e\u73b0(\u7b2c3\u7248)
UNIX\u73af\u5883\u9ad8\u7ea7\u7f16\u7a0b\uff08\u7b2c3\u7248)
Linux\u547d\u4ee4\u884c\u4e0eshell\u811a\u672c\u7f16\u7a0b\u5927\u5168\uff08\u7b2c4\u7248)
\u91ce\u706bLinux\u5f00\u53d1\u5b9e\u6218\u6307\u5357
\u8717\u58f3\u79d1\u6280
"},{"location":"linux/drivers/","title":"\u8bbe\u5907\u6a21\u578b","text":"\u7531\u4e8eLinux\u652f\u6301\u4e16\u754c\u4e0a\u51e0\u4e4e\u6240\u6709\u7684\u3001\u4e0d\u540c\u529f\u80fd\u7684\u786c\u4ef6\u8bbe\u5907\uff0c\u5bfc\u81f4Linux\u5185\u6838\u4e2d\u6709\u4e00\u534a\u7684\u4ee3\u7801\u90fd\u662f\u8bbe\u5907\u9a71\u52a8\u3002\u968f\u7740\u786c\u4ef6\u7684\u5feb\u901f\u8fed\u4ee3\uff0c\u8bbe\u5907\u9a71\u52a8\u7684\u4ee3\u7801\u4e5f\u5728\u5feb\u901f\u589e\u957f\u3002
\u4e3a\u4e86\u964d\u4f4e\u8bbe\u5907\u7684\u591a\u6837\u6027\u5e26\u6765\u7684\u9a71\u52a8\u5f00\u53d1\u7684\u590d\u6742\u5ea6\uff0cLinux\u63d0\u51fa\u4e86\u8bbe\u5907\u6a21\u578b\uff08device model\uff09\u7684\u6982\u5ff5\uff0c\u8be5\u6a21\u578b\u5c06\u8bbe\u5907\u548c\u9a71\u52a8\u5206\u5c42\uff0c\u628a\u6211\u4eec\u7f16\u5199\u7684\u9a71\u52a8\u4ee3\u7801\u5206\u6210\u4e86\u4e24\u5757\uff1a\u8bbe\u5907\u4e0e\u9a71\u52a8\u3002\u8bbe\u5907\u8d1f\u8d23\u63d0\u4f9b\u786c\u4ef6\u8d44\u6e90\u800c\u9a71\u52a8\u8d1f\u8d23\u53bb\u4f7f\u7528\u8bbe\u5907\u63d0\u4f9b\u7684\u786c\u4ef6\u8d44\u6e90\u3002\u4e8c\u8005\u7531\u603b\u7ebf\u5173\u8054\u8d77\u6765\u3002
\u8bbe\u5907\u6a21\u578b\u901a\u8fc7\u51e0\u4e2a\u6570\u636e\u7ed3\u6784\u6765\u53cd\u6620\u5f53\u524d\u7cfb\u7edf\u4e2d\u603b\u7ebf\u3001\u8bbe\u5907\u4ee5\u53ca\u9a71\u52a8\u5de5\u4f5c\u7684\u60c5\u51b5\uff1a
\u603b\u7ebf(bus)\uff1a\u603b\u7ebf\u662fCPU\u548c\u8bbe\u5907\u4e4b\u95f4\u4fe1\u606f\u4ea4\u4e92\u7684\u901a\u9053\uff0c\u6240\u6709\u7684\u8bbe\u5907\u90fd\u5e94\u8fde\u63a5\u5230\u603b\u7ebf\u4e0a\uff0c\u65e0\u8bba\u662fCPU\u5185\u90e8\u603b\u7ebf\u8fd8\u662f\u865a\u62df\u603b\u7ebf\u3002
\u7c7b\uff08class\uff09\uff1a\u9762\u5411\u5bf9\u8c61\u601d\u60f3\uff0c\u5c06\u76f8\u540c\u529f\u80fd\u7684\u8bbe\u5907\uff0c\u5f52\u7ed3\u5230\u4e00\u79cdclass\u7edf\u4e00\u7ba1\u7406\u3002
\u8bbe\u5907\uff08device\uff09\uff1a\u6302\u8f7d\u5728\u603b\u7ebf\u7684\u7269\u7406\u8bbe\u5907\u3002
\u9a71\u52a8\uff08driver\uff09\uff1a\u786c\u4ef6\u8bbe\u5907\u7684\u9a71\u52a8\u7a0b\u5e8f\uff0c\u8d1f\u8d23\u521d\u59cb\u5316\u8bbe\u5907\u4ee5\u53ca\u5b9e\u73b0\u8be5\u8bbe\u5907\u7684\u4e00\u4e9b\u63a5\u53e3\u51fd\u6570\u3002
platform bus\u662f\u5185\u6838\u4e2d\u7684\u4e00\u79cd\u865a\u62df\u603b\u7ebf\u7c7b\u578b\uff0c\u5b83\u4e0d\u662f\u7269\u7406\u4e0a\u5b58\u5728\u7684\u603b\u7ebf\uff0c\u800c\u662f\u4e00\u79cd\u62bd\u8c61\u7684\u603b\u7ebf\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4ee5\u4e00\u79cd\u6807\u51c6\u7684\u65b9\u5f0f\u6765\u63cf\u8ff0\u548c\u7ba1\u7406\u90a3\u4e9b\u4e0d\u901a\u8fc7\u4f20\u7edf\u7269\u7406\u603b\u7ebf\u8fde\u63a5\u7684\u8bbe\u5907\u3002
Linux\u5185\u6838\u4f7f\u7528sysfs\u6587\u4ef6\u7cfb\u7edf\u5c06\u5185\u6838\u7684\u8bbe\u5907\u9a71\u52a8\u5bfc\u51fa\u5230\u7528\u6237\u7a7a\u95f4\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee/sys\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff0c\u6765\u67e5\u770b\u751a\u81f3\u63a7\u5236\u5185\u6838\u7684\u4e00\u4e9b\u9a71\u52a8\u8bbe\u5907\u3002
/sys\u6587\u4ef6\u76ee\u5f55\u8bb0\u5f55\u4e86\u5404\u4e2a\u8bbe\u5907\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5176\u4e2d\uff0c/sys/bus\u76ee\u5f55\u4e0b\u7684\u6bcf\u4e2a\u5b50\u76ee\u5f55\u90fd\u662f\u5df2\u7ecf\u6ce8\u518c\u7684\u603b\u7ebf\u7c7b\u578b\u3002\u6bcf\u4e2a\u603b\u7ebf\u7c7b\u578b\u4e0b\u8fd8\u6709\u4e24\u4e2a\u6587\u4ef6\u5939\u2014\u2014devices\u548cdrivers\uff1bdevices\u662f\u8be5\u603b\u7ebf\u7c7b\u578b\u4e0b\u7684\u6240\u6709\u8bbe\u5907\uff0c\u4ee5\u7b26\u53f7\u94fe\u63a5\u7684\u5f62\u5f0f\u6307\u5411\u771f\u6b63\u7684\u8bbe\u5907\uff08/sys/devices/\uff09\u3002\u800cdrivers\u662f\u6240\u6709\u6ce8\u518c\u5728\u8fd9\u4e2a\u603b\u7ebf\u7c7b\u578b\u4e0a\u7684\u9a71\u52a8\u3002
/sys/devices\u76ee\u5f55\u4e0b\u662f\u5168\u5c40\u7684\u8bbe\u5907\u7ed3\u6784\u4f53\u7cfb\uff0c\u5305\u542b\u4e86\u6240\u6709\u6ce8\u518c\u5728\u5404\u7c7b\u603b\u7ebf\u4e0a\u7684\u7269\u7406\u8bbe\u5907\u3002\u6240\u6709\u7684\u7269\u7406\u8bbe\u5907\u4ee5\u603b\u7ebf\u62d3\u6251\u7684\u7ed3\u6784\u6765\u663e\u793a\u3002
/sys/class\u76ee\u5f55\u4e0b\u662f\u5305\u542b\u6240\u6709\u6ce8\u518c\u5728\u5185\u6838\u4e2d\u7684\u8bbe\u5907\u7c7b\u578b\uff0c\u6309\u7167\u8bbe\u5907\u7684\u529f\u80fd\u8fdb\u884c\u5206\u7c7b\u3002\u6bd4\u5982\u9f20\u6807\u7684\u529f\u80fd\u662f\u4f5c\u4e3a\u4eba\u673a\u4ea4\u4e92\u7684\u8f93\u5165\uff0c\u4e8e\u662f\u88ab\u5f52\u7c7b\u5230/sys/class/input\u76ee\u5f55\u4e0b\u3002
\u90a3\u4e48\u201c\u603b\u7ebf-\u8bbe\u5907-\u9a71\u52a8\u201d\u662f\u5982\u4f55\u914d\u5408\u5de5\u4f5c\u7684\u5462\uff1f
\u5728\u603b\u7ebf\u4e0a\u6302\u8f7d\u4e86\u4e24\u4e2a\u94fe\u8868\uff0c\u5206\u522b\u7ba1\u7406\u8bbe\u5907\u6a21\u578b\u548c\u9a71\u52a8\u6a21\u578b\u3002\u5f53\u6211\u4eec\u5411\u7cfb\u7edf\u6ce8\u518c\u4e00\u4e2a\u8bbe\u5907\u65f6\uff0c\u4fbf\u4f1a\u5728\u8bbe\u5907\u7684\u94fe\u8868\u4e2d\u63d2\u5165\u65b0\u7684\u8bbe\u5907\u3002\u5728\u63d2\u5165\u7684\u540c\u65f6\u603b\u7ebf\u4f1a\u6267\u884cmatch()
\u65b9\u6cd5\u5bf9\u65b0\u63d2\u5165\u7684\u8bbe\u5907/\u9a71\u52a8\u8fdb\u884c\u914d\u5bf9\u3002\u82e5\u914d\u5bf9\u6210\u529f\u5219\u8c03\u7528probe()
\u65b9\u6cd5\u83b7\u53d6\u8bbe\u5907\u8d44\u6e90\uff0c\u5728\u79fb\u9664\u8bbe\u5907/\u9a71\u52a8\u65f6\uff0c\u8c03\u7528remove()
\u65b9\u6cd5\u3002
"},{"location":"linux/drivers/#kobjectktypekset","title":"kobject\u3001ktype\u548ckset","text":"kobject\u662fLinux\u8bbe\u5907\u6a21\u578b\u7684\u57fa\u7840\uff0c\u662f\u4e00\u79cd\u62bd\u8c61\u7684\u3001\u7edf\u4e00\u7684\u5bf9\u5927\u91cf\u786c\u4ef6\u8bbe\u5907\u7684\u63cf\u8ff0\u3002\u5b83\u4e3b\u8981\u63d0\u4f9b\u4ee5\u4e0b\u529f\u80fd\uff1a
\u901a\u8fc7parent\u6307\u9488\uff0c\u5c06\u6240\u6709kobject\u4ee5\u6811\u72b6\u7ed3\u6784\u7684\u5f62\u5f0f\u7ec4\u5408\u8d77\u6765\u3002 \u4f7f\u7528\u5f15\u7528\u8ba1\u6570kref\uff0c\u6765\u8bb0\u5f55kobject\u88ab\u5f15\u7528\u7684\u6b21\u6570\uff0c\u5728\u8ba1\u6570\u4e3a0\u65f6\u91ca\u653e\u5b83\u3002 \u548csysfs\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u914d\u5408\uff0c\u5c06\u6bcf\u4e00\u4e2akobject\u7684\u7279\u6027\uff0c\u4ee5\u6587\u4ef6\u7684\u5f62\u5f0f\u5f00\u653e\u7ed9\u7528\u6237\u7a7a\u95f4\u67e5\u8be2\u3002 \u8bbe\u5907\u9a71\u52a8\u6a21\u578b\u7684\u57fa\u672c\u5143\u7d20\u6709\u4e09\u4e2a\uff1a
kobject\uff1asysfs\u4e2d\u7684\u4e00\u4e2a\u76ee\u5f55\uff0c\u8868\u793a\u57fa\u672c\u9a71\u52a8\u5bf9\u8c61\u3002 kset\uff1a\u4e00\u4e2a\u7279\u6b8a\u7684kobject\uff0c\u7528\u6765\u7ba1\u7406\u7c7b\u4f3c\u7684kobject\u3002 ktype\uff1a\u76ee\u5f55\u4e0bkobject\u5c5e\u6027\u6587\u4ef6\u64cd\u4f5c\u7684\u63a5\u53e3\u3002 kobject\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct kobject {\n const char *name;\n struct list_head entry;\n struct kobject *parent;\n struct kset *kset;\n struct kobj_type *ktype;\n struct kernfs_node *sd; /* sysfs directory entry */\n struct kref kref;\n unsigned int state_initialized:1;\n unsigned int state_in_sysfs:1;\n unsigned int state_add_uevent_sent:1;\n unsigned int state_remove_uevent_sent:1;\n unsigned int uevent_suppress:1;\n};\n
name\uff1akobject\u7684\u540d\u79f0\uff0c\u540c\u65f6\u4e5f\u662fsysfs\u4e2d\u7684\u76ee\u5f55\u540d\u79f0\u3002\u5f53kobject\u6dfb\u52a0\u5230\u5185\u6838\u65f6\uff0c\u9700\u8981\u6839\u636ename\u6ce8\u518c\u5230sysfs\u4e2d\u3002
entry\uff1a\u7528\u4e8e\u5c06kobject\u52a0\u5165\u5230\u94fe\u8868\u4e2d\u3002
parent\uff1a\u6307\u5411\u7236kobject\u7684\u6307\u9488\uff0c\u5728sysfs\u4e2d\u6839\u636e\u5c42\u6b21\u7ed3\u6784\u663e\u793a\u4e3a\u76ee\u5f55\u7ed3\u6784\u3002
kset\uff1a\u8be5kobject\u5c5e\u4e8e\u7684kset\u3002\u82e5\u8be5kobject\u672a\u6307\u5b9aparent\uff0c\u5219\u4f1a\u628akset\u4f5c\u4e3aparent\u3002
ktype\uff1a\u8be5kobject\u5c5e\u4e8e\u7684kobj_type\uff0c\u6bcf\u4e2akobject\u5fc5\u987b\u6709\u4e00\u4e2aktype\u3002
sd\uff1a\u8be5kobject\u5728sysfs\u4e2d\u7684\u5bf9\u5e94\u76ee\u5f55\u9879\u3002
kref\uff1a\u539f\u5b50\u5f15\u7528\u8ba1\u6570\u3002
state_initialized\uff1a\u6307\u793a\u8be5kobject\u662f\u5426\u5df2\u7ecf\u521d\u59cb\u5316\u3002
state_in_sysfs\uff1a\u6307\u793a\u8be5kobject\u662f\u5426\u5df2\u5728sysfs\u4e2d\u5efa\u7acb\u76ee\u5f55\u3002
state_add_uevent_sent/state_remove_uevent_sent\uff1a\u8bb0\u5f55\u662f\u5426\u5df2\u5411\u7528\u6237\u7a7a\u95f4\u53d1\u9001add uevent\u3002
uevent_suppress\uff1a\u5982\u679c\u8be5\u5b57\u6bb5\u4e3a1\uff0c\u5219\u8868\u793a\u5ffd\u7565\u6240\u6709\u4e0a\u62a5\u7684uevent\u4e8b\u4ef6\u3002
kobject\u6838\u5fc3\u673a\u5236\uff1a
\u5185\u5d4c\u5728\u522b\u7684\u6570\u636e\u7ed3\u6784\uff08\u6bd4\u5982device_driver\uff09\u4e2d\uff0c\u5f53kobject\u4e2d\u7684\u5f15\u7528\u8ba1\u6570\u5f52\u96f6\u65f6\uff0c\u91ca\u653ekobject\u6240\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u540c\u65f6\u901a\u8fc7ktype\u4e2d\u7684release()
\u56de\u8c03\u51fd\u6570\uff0c\u91ca\u653e\u5185\u5d4c\u6570\u636e\u7ed3\u6784\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u6bcf\u4e00\u4e2a\u5185\u5d4ckobject\u7684\u6570\u636e\u7ed3\u6784\u90fd\u9700\u8981\u81ea\u5df1\u5b9e\u73b0ktype\u4e2d\u7684\u56de\u8c03\u51fd\u6570\u3002
ktype\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct kobj_type {\n void (*release)(struct kobject *kobj);\n const struct sysfs_ops *sysfs_ops;\n const struct attribute_group **default_groups;\n /*\u7701\u7565\u5176\u4ed6\u6210\u5458*/ \n};\n
release\uff1a\u5f53kobject\u5f15\u7528\u8ba1\u6570\u5f52\u96f6\u65f6\u8c03\u7528\u8be5\u6790\u6784\u51fd\u6570\uff0c\u8d1f\u8d23\u91ca\u653ekobject\u7684\u5185\u5b58\u3002
sysfs_ops\uff1asysfs\u6587\u4ef6\u7cfb\u7edf\u8bfb\u5199\u65f6\u7684\u7279\u6027\u3002
default_groups\uff1a\u5b9a\u4e49\u4e86kobject\u7684\u5c5e\u6027\uff0c\u7531struct attritube\u548cstruct bin_attribute\u6784\u6210\u3002
ktype\u7684\u5b58\u5728\u662f\u4e3a\u4e86\u63cf\u8ff0\u4e00\u65cfkobject\u6240\u5177\u6709\u7684\u666e\u904d\u7279\u6027\u3002\u8fd9\u6837\u5c31\u4e0d\u9700\u8981\u6bcf\u4e2akobject\u5b9a\u4e49\u81ea\u5df1\u7684\u7279\u6027\uff0c\u800c\u662f\u5728ktype\u4e2d\u7edf\u4e00\u5b9a\u4e49\u3002
kset\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct kset {\n struct list_head list;\n spinlock_t list_lock;\n struct kobject kobj;\n const struct kset_uevent_ops *uevent_ops;\n};\n
list/list_lock\uff1a\u7528\u4e8e\u4fdd\u5b58\u8be5kset\u4e0b\u6240\u6709kobject\u5bf9\u8c61\u3002
kobj\uff1a\u8be5kset\u81ea\u5df1\u7684kobject\u3002
uevent_ops\uff1auevent\u662f\u7528\u6237\u7a7a\u95f4\u7684\u7f29\u5199\uff0c\u63d0\u4f9b\u4e86\u4e0e\u7528\u6237\u7a7a\u95f4\u70ed\u63d2\u62d4\u8fdb\u884c\u901a\u4fe1\u7684\u673a\u5236\u3002\u5f53\u4efb\u4f55kobject\u9700\u8981\u4e0a\u62a5uevent\u65f6\uff0c\u90fd\u8981\u8c03\u7528\u6240\u5c5e\u7684kset\u4e2duevent_ops\u4e2d\u7684\u51fd\u6570\u3002uevent\u7684\u6982\u5ff5\u7a0d\u540e\u8bf4\u660e\u3002
kset\u662fkobject\u5bf9\u8c61\u7684\u96c6\u5408\u4f53\u3002\u5b83\u4e0ektype\u7684\u533a\u522b\u5728\u4e8e\uff1a\u5177\u6709\u76f8\u540cktype\u7684kobject\u53ef\u4ee5\u88ab\u5206\u7ec4\u5230\u4e0d\u540c\u7684kset\u3002
"},{"location":"linux/drivers/#sysfs","title":"sysfs","text":"sysfs\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u4e2a\u5904\u4e8e\u5185\u5b58\u4e2d\u7684\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u63d0\u4f9b\u4e86kobject\u5bf9\u8c61\u7684\u5c42\u6b21\u7ed3\u6784\u89c6\u56fe\u3002\u7528\u6237\u67e5\u8be2\u7cfb\u7edf\u4e2d\u5404\u79cd\u8bbe\u5907\u7684\u62d3\u6251\u7ed3\u6784\uff0c\u5c31\u50cf\u67e5\u8be2\u6587\u4ef6\u76ee\u5f55\u4e00\u6837\u7b80\u5355\u3002\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5bfc\u51fa\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u5c06\u5185\u6838\u53d8\u91cf\u63d0\u4f9b\u7ed9\u7528\u6237\u8bfb\u53d6\u6216\u8005\u5199\u5165\u3002
sysfs\u7684\u6838\u5fc3\u662f\u628akobject\u5bf9\u8c61\u4e0e\u76ee\u5f55\u9879\uff08directory entries\uff09\u5173\u8054\u8d77\u6765\uff0c\u8fd9\u70b9\u662f\u901a\u8fc7kobject\u7ed3\u6784\u4f53\u4e2d\u7684dentry\u5b57\u6bb5\u5b9e\u73b0\u7684\u3002\u8fd9\u79cd\u5173\u8054\u5c06kobject\u5bf9\u8c61\u6620\u5c04\u5230\u8be5\u76ee\u5f55\u4e0a\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u67e5\u770b\u6302\u8f7d\u4e8e/sys\u76ee\u5f55\u4e0b\u7684\u6574\u4e2a\u6587\u4ef6\u7cfb\u7edf\u89c6\u56fe\u3002\u5411sysfs\u4e2d\u6dfb\u52a0kobject\uff0c\u53ef\u4ee5\u4f7f\u7528kobject_add()
\u548ckobject_create_and_add()
\u51fd\u6570\u3002
\u5728/sys\u76ee\u5f55\u4e0b\u6302\u8f7d\u4e86\u81f3\u5c1111\u4e2a\u76ee\u5f55\uff1ablock, bus, class, dev, devices, firmware, fs, hypervisor, kernel, module, power\u3002\u5176\u4e2d\u6700\u91cd\u8981\u7684\u76ee\u5f55\u662fdevices\uff0c\u8be5\u76ee\u5f55\u5c06\u8bbe\u5907\u6a21\u578b\u5bfc\u51fa\u5230\u7528\u6237\u7a7a\u95f4\u3002\u5176\u76ee\u5f55\u673a\u6784\u5c31\u662f\u7cfb\u7edf\u4e2d\u5b9e\u9645\u7684\u8bbe\u5907\u62d3\u6251\u7ed3\u6784\u3002\u5176\u4ed6\u76ee\u5f55\u4e2d\u7684\u8bb8\u591a\u6570\u636e\u90fd\u662f\u5c06devices\u76ee\u5f55\u4e0b\u7684\u6570\u636e\u52a0\u4ee5\u8f6c\u6362\u52a0\u5de5\u6240\u5f97\u3002
\u6211\u4eec\u5df2\u7ecf\u77e5\u9053kobject\u53ef\u4ee5\u88ab\u6620\u5c04\u4e3a\u67d0\u4e2a\u6587\u4ef6\u76ee\u5f55\uff0c\u4ec5\u6709\u5982\u6b64\u8fd8\u4e0d\u591f\u3002\u56e0\u4e3a\u8fd9\u6837\u7684sysfs\u4ec5\u4ec5\u53ea\u662f\u4e00\u9897\u6811\uff0c\u4f46\u6ca1\u6709\u63d0\u4f9b\u5b9e\u9645\u6570\u636e\u7684\u6587\u4ef6\u3002\u4e3a\u4e86\u80fd\u591f\u8bfb\u5199\u8fd9\u9897\u6811\uff0c\u5185\u6838\u63d0\u4f9b\u4e86attribute
\u548cbin_attribute
\u4e24\u79cd\u5c5e\u6027\u3002
\u5728ktype\u4e2d\u7528struct attribute_group
\u63cf\u8ff0\u8fd9\u4e24\u4e2a\u5c5e\u6027\uff1a
struct attribute_group {\n const char *name;\n struct attribute **attrs;\n struct bin_attribute **bin_attrs;\n};\n\n/*attribute\u548cbin_attribute\u7684\u5b9a\u4e49\u5982\u4e0b*/\n\nstruct attribute {\n const char *name;\n umode_t mode;\n};\n\nstruct bin_attribute {\n struct attribute attr;\n size_t size;\n void *private;\n struct address_space *(*f_mapping)(void);\n ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,\n char *, loff_t, size_t);\n ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,\n char *, loff_t, size_t);\n int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,\n struct vm_area_struct *vma);\n};\n
struct attribute
\u4e3a\u666e\u901a\u7684attribute\uff0c\u4f7f\u7528\u8be5attribute\u751f\u6210\u7684sysfs\u6587\u4ef6\uff0c\u53ea\u80fd\u7528\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u8bfb\u5199\u3002\u800cstruct bin_attribute
\u5728struct attribute
\u7684\u57fa\u7840\u4e0a\uff0c\u589e\u52a0\u4e86read()
\u3001write()
\u7b49\u51fd\u6570\uff0c\u56e0\u6b64\u5b83\u6240\u751f\u6210\u7684sysfs\u6587\u4ef6\u53ef\u4ee5\u7528\u4efb\u4f55\u65b9\u5f0f\u8bfb\u5199\u3002
"},{"location":"linux/drivers/#uevent","title":"uevent","text":"uevent\u662fkobject\u529f\u80fd\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u5728kobject\u72b6\u6001\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u6bd4\u5982\u6dfb\u52a0\u3001\u79fb\u9664\uff0c\u901a\u77e5\u7528\u6237\u7a7a\u95f4\u3002\u7528\u6237\u7a7a\u95f4\u6536\u5230\u8baf\u606f\u540e\uff0c\u505a\u51fa\u76f8\u5e94\u7684\u5904\u7406\u3002
\u8be5\u673a\u5236\u901a\u5e38\u662f\u7528\u6765\u652f\u6301\u70ed\u63d2\u62d4\uff08hotplug\uff09\u8bbe\u5907\u7684\uff0c\u4f8b\u5982\u5f53U\u76d8\u63d2\u5165\u540e\uff0cUSB\u76f8\u5173\u7684\u9a71\u52a8\u4f1a\u52a8\u6001\u521b\u5efa\u7528\u4e8e\u8868\u793a\u8be5U\u76d8\u7684device\u7ed3\u6784\uff0c\u5e76\u544a\u77e5\u7528\u6237\u7a7a\u95f4\u4e3a\u8be5U\u76d8\u52a8\u6001\u521b\u5efa/dev/\u76ee\u5f55\u4e0b\u7684\u8bbe\u5907\u8282\u70b9\u3002
uevent\u673a\u5236\u6bd4\u8f83\u7b80\u5355\uff0c\u5f53\u8bbe\u5907\u6a21\u578b\u4e2d\u4efb\u4f55\u8bbe\u5907\u6709\u4e8b\u4ef6\u9700\u8981\u4e0a\u62a5\u65f6\uff0c\u90fd\u4f1a\u89e6\u53d1uevent\u63d0\u4f9b\u7684\u63a5\u53e3\u3002uevent\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7\u4e24\u4e2a\u9014\u5f84\u628a\u4e8b\u4ef6\u4e0a\u62a5\u5230\u7528\u6237\u7a7a\u95f4\uff1a\u4e00\u79cd\u662f\u901a\u8fc7kmod\u6a21\u5757\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7netlink\u901a\u4fe1\u673a\u5236\u3002
uevent\u7684\u4ee3\u7801\u4e3b\u8981\u4f4d\u4e8ekobject.h\u548ckobject_uevent.c\u4e24\u4e2a\u6587\u4ef6\u3002
kobject_action
\u5b9a\u4e49\u4e86uevent\u7684\u7c7b\u578b\uff1a
enum kobject_action {\n KOBJ_ADD,\n KOBJ_REMOVE,\n KOBJ_CHANGE,\n KOBJ_MOVE,\n KOBJ_ONLINE,\n KOBJ_OFFLINE,\n KOBJ_BIND,\n KOBJ_UNBIND,\n};\n
ADD/REMOVE\uff1akobject\u7684\u6dfb\u52a0/\u79fb\u9664\u4e8b\u4ef6\u3002
CHANGE\uff1akobject\u72b6\u6001\u6216\u8005\u5185\u5bb9\u53d1\u751f\u6539\u53d8\u3002
MOVE\uff1akobject\u66f4\u6539\u540d\u79f0\u6216\u8005\u66f4\u6539\u4e86parent\u3002
ONLINE/OFFLINE\uff1akobject\u7684\u4e0a\u7ebf/\u4e0b\u7ebf\u4e8b\u4ef6
BIND/UNBIND\uff1akobject\u7684\u7ed1\u5b9a/\u89e3\u7ed1\u4e8b\u4ef6
kobj_uevent_env
\u5b9a\u4e49\u4e86\u4e8b\u4ef6\u4e0a\u62a5\u65f6\u7684\u73af\u5883\u53d8\u91cf\uff1a
struct kobj_uevent_env {\n char *argv[3];\n char *envp[UEVENT_NUM_ENVP];\n int envp_idx;\n char buf[UEVENT_BUFFER_SIZE];\n int buflen;\n};\n
argv\uff1a\u6307\u9488\u6570\u7ec4\uff0c\u53ef\u4ee5\u4fdd\u5b58\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u6700\u5927\u4e3a3\u4e2a\u3002
envp\uff1a\u6307\u9488\u6570\u7ec4\uff0c\u7528\u4e8e\u4fdd\u5b58\u6bcf\u4e2a\u73af\u5883\u53d8\u91cf\u7684\u5730\u5740\u3002
envp_idx\uff1a\u8bbf\u95eeenvp\u6570\u7ec4\u7684\u7d22\u5f15\u3002
buf\uff1a\u4fdd\u5b58uevent\u6d88\u606f\u7684\u7f13\u51b2\u533a
buflen\uff1a\u5b58\u50a8\u7f13\u51b2\u533a\u7684\u5927\u5c0f
kset_uevent_ops
\u5b9a\u4e49\u4e86kset\u7684uevent\u63a5\u53e3\u64cd\u4f5c\uff1a
struct kset_uevent_ops {\n int (* const filter)(struct kset *kset, struct kobject *kobj);\n const char *(* const name)(struct kset *kset, struct kobject *kobj);\n int (* const uevent)(struct kset *kset, struct kobject *kobj, struct kobj_uevent_env *env);\n};\n
filter\uff1a\u5f53kobject\u9700\u8981\u4e0a\u62a5uevent\u65f6\uff0c\u5b83\u6240\u5c5e\u7684kset\u53ef\u4ee5\u901a\u8fc7\u6b64\u63a5\u53e3\u8fc7\u6ee4\u6389\u4e0d\u5e0c\u671b\u4e0a\u62a5\u7684uevent\u3002
name\uff1a\u7528\u4e8e\u83b7\u53d6kset\u4e2dkobject\u7684uevent\u540d\u79f0\uff0c\u8fd9\u4e2a\u540d\u79f0\u901a\u5e38\u4e0euevent\u4e2d\u7684ACTION\u5b57\u6bb5\u76f8\u5bf9\u5e94\u3002
uevent\uff1a\u5f53\u4e00\u4e2akobject\u9700\u8981\u4e0a\u62a5uevent\u65f6\uff0cuevent\u51fd\u6570\u4f1a\u88ab\u8c03\u7528\uff0c\u5b83\u53ef\u4ee5\u4e3auevent\u6dfb\u52a0\u73af\u5883\u53d8\u91cf\u3002
uevent\u7684\u4e00\u4e9b\u64cd\u4f5cAPI\uff1a
int kobject_uevent(struct kobject *kobj, enum kobject_action action);\nint kobject_uevent_env(struct kobject *kobj, enum kobject_action action, char *envp[]);\nint kobject_synth_uevent(struct kobject *kobj, const char *buf, size_t count);\nint add_uevent_var(struct kobj_uevent_env *env, const char *format, ...);\n
kobject_uevent_env\uff1a\u4ee5envp\u4e3a\u73af\u5883\u53d8\u91cf\uff0c\u4e0a\u62a5\u4e00\u4e2a\u6307\u5b9aaction\u7684uevent\u3002
kobject_synth_uevent\uff1a\u5141\u8bb8\u53d1\u9001\u4e00\u4e2a\u5408\u6210\u7684uevent\u3002
add_uevent_var\uff1a\u4ee5\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\uff0c\u5411uevent\u6dfb\u52a0\u65b0\u7684\u73af\u5883\u53d8\u91cf\u3002
"},{"location":"linux/drivers/#devicedevice_driver","title":"device\u548cdevice_driver","text":"device
\u548cdevice_driver
\u662fLinux\u9a71\u52a8\u5f00\u53d1\u7684\u57fa\u672c\u6982\u5ff5\u3002\u9a71\u52a8\u5f00\u53d1\uff0c\u5176\u5b9e\u5c31\u662f\u5f00\u53d1\u6307\u5b9a\u7684\u8f6f\u4ef6\uff08driver\uff09\u4ee5\u53ca\u9a71\u52a8\u6307\u5b9a\u7684\u8bbe\u5907\uff08device\uff09\u3002\u5185\u6838\u4e3a\u6b64\u5b9a\u4e49\u4e86\u4e24\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5206\u522b\u662fstruct device
\u548cstruct device_driver
\u3002
Linux\u8bbe\u5907\u6a21\u578b\u6846\u67b6\u4f53\u7cfb\u4e0b\u5f00\u53d1\uff0c\u4e3b\u8981\u5305\u62ec\u4e24\u4e2a\u6b65\u9aa4\uff1a
\u5206\u914d\u4e00\u4e2astruct device
\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u586b\u5145\u4fe1\u606f\uff0c\u7136\u540e\u5c06\u5176\u6ce8\u518c\u5230\u5185\u6838\u3002
\u5206\u914d\u4e00\u4e2astruct device_driver
\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u586b\u5145\u4fe1\u606f\uff0c\u7136\u540e\u5c06\u5176\u6ce8\u518c\u5230\u5185\u6838\u3002
\u8bbe\u5907\u9a71\u52a8\u7684\u6267\u884c\u903b\u8f91\uff0c\u7531\u56de\u8c03\u51fd\u6570\u5b9e\u73b0\u3002\u5f00\u53d1\u4eba\u5458\u53ea\u9700\u8981\u505a\u586b\u7a7a\u9898\u5373\u53ef\u3002
\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cLinux\u9a71\u52a8\u5f00\u53d1\u5f88\u5c11\u76f4\u63a5\u64cd\u4f5c\u4e0a\u9762\u4e24\u4e2a\u7ed3\u6784\u4f53\uff0c\u56e0\u4e3a\u5185\u6838\u53c8\u5c01\u88c5\u4e86\u4e00\u5c42\uff0c\u6bd4\u5982platform_device
\uff0c\u5c01\u88c5\u540e\u7684\u63a5\u53e3\u66f4\u4e3a\u7b80\u5355\u6613\u7528\u3002device
\u548cdevice_driver
\u5fc5\u987b\u6302\u5728\u5728\u540c\u4e00\u4e2abus\u4e4b\u4e0b\uff0c\u540d\u79f0\u4e5f\u5fc5\u987b\u4e00\u6837\uff0c\u5185\u6838\u624d\u80fd\u5b8c\u6210\u5339\u914d\u64cd\u4f5c\u3002
\u5982\u679c\u5b58\u5728\u76f8\u540c\u540d\u79f0\u7684device
\u548cdevice_driver
\uff0c\u5185\u6838\u5c31\u4f1a\u6267\u884cdevice_driver
\u4e2d\u7684probe()
\u56de\u8c03\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u662f\u6240\u6709driver
\u7684\u5165\u53e3\u51fd\u6570\uff0c\u7528\u6765\u6267\u884c\u8bf8\u5982\u786c\u4ef6\u8bbe\u5907\u521d\u59cb\u5316\u3001\u5b57\u7b26\u8bbe\u5907\u6ce8\u518c\u3001\u6587\u4ef6\u64cd\u4f5cops\u6ce8\u518c\u7b49\u52a8\u4f5c\uff08\u5bf9\u5e94remove()
\u51fd\u6570\uff09\u3002
"},{"location":"linux/drivers/#bus","title":"bus","text":"\u603b\u7ebf\u662f\u8fde\u63a5\u5904\u7406\u5668\u548c\u8bbe\u5907\u4e4b\u95f4\u7684\u901a\u9053\u3002\u4e3a\u4e86\u65b9\u4fbf\u8bbe\u5907\u6a21\u578b\u7684\u5b9e\u73b0\uff0c\u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a\u8bbe\u5907\u90fd\u9700\u8981\u8fde\u63a5\u5728\u4e00\u4e2a\u603b\u7ebf\u4e0a\uff0c\u8fd9\u4e2a\u603b\u7ebf\u53ef\u4ee5\u662f\u5185\u90e8\u603b\u7ebf\u3001\u865a\u62df\u603b\u7ebf\u6216\u8005\u662f\u5e73\u53f0\u603b\u7ebf\u3002
\u603b\u7ebf\u9a71\u52a8\u5219\u8d1f\u8d23\u5b9e\u73b0\u603b\u7ebf\u7684\u5404\u79cd\u884c\u4e3a\uff0c\u5176\u7ba1\u7406\u7740\u4e24\u4e2a\u94fe\u8868\uff0c\u5206\u522b\u662f\u6dfb\u52a0\u5230\u8be5\u603b\u7ebf\u7684\u8bbe\u5907\u94fe\u8868\u4ee5\u53ca\u6ce8\u518c\u5230\u8be5\u603b\u7ebf\u7684\u9a71\u52a8\u94fe\u8868\u3002\u5f53\u4f60\u5411\u603b\u7ebf\u6dfb\u52a0\uff08\u79fb\u9664\uff09\u4e00\u4e2a\u8bbe\u5907\uff08\u9a71\u52a8\uff09\u65f6\uff0c\u4fbf\u4f1a\u5728\u5bf9\u5e94\u7684\u5217\u8868\u4e0a\u6dfb\u52a0\u65b0\u7684\u8282\u70b9\uff0c \u540c\u65f6\u5bf9\u6302\u8f7d\u5728\u8be5\u603b\u7ebf\u7684\u9a71\u52a8\u4ee5\u53ca\u8bbe\u5907\u8fdb\u884c\u5339\u914d\uff0c\u5728\u5339\u914d\u8fc7\u7a0b\u4e2d\u4f1a\u5ffd\u7565\u6389\u90a3\u4e9b\u5df2\u7ecf\u6709\u9a71\u52a8\u5339\u914d\u7684\u8bbe\u5907\u3002
\u5185\u6838\u7528struct bus_type
\u7ed3\u6784\u4f53\u62bd\u8c61\u51fa\u603b\u7ebf\uff1a
struct bus_type {\n const char *name;\n const char *dev_name;\n\n int (*match)(struct device *dev, struct device_driver *drv);\n int (*uevent)(struct device *dev, struct kobj_uevent_env *env);\n int (*probe)(struct device *dev);\n int (*remove)(struct device *dev);\n\n struct subsys_private *p;\n};\n
\u6211\u4eec\u53d1\u73b0bus_type
\u7ed3\u6784\u4f53\u4e2d\u7684\u5927\u90e8\u5206\u6210\u5458\u90fd\u4e0edevice
\u6709\u5173\uff0c\u8bf4\u660e\u5b83\u4e3b\u8981\u8d1f\u8d23\u8bbe\u5907\u7684\u6ce8\u518c\u548c\u6ce8\u9500\u7b49\u64cd\u4f5c\u3002
name\uff1a\u8be5bus\u7684\u540d\u79f0\uff0c\u5728sysfs\u4e2d\u4ee5\u76ee\u5f55\u5f62\u5f0f\u5b58\u5728\uff0c\u6bd4\u5982platform bus\u8868\u73b0\u4e3a/sys/bus/platform\u3002
dev_name\uff1a\u6ce8\u518c\u5230bus\u7684\u8bbe\u5907\u540d\u79f0\u3002
match\uff1a\u5f53\u5c5e\u4e8e\u8be5bus\u7684device\u6216\u8005device_driver\u6dfb\u52a0\u5230\u5185\u6838\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u3002
uevent\uff1a\u5f53\u5c5e\u4e8e\u8be5bus\u7684device\uff0c\u53d1\u751f\u6dfb\u52a0\u3001\u79fb\u9664\u6216\u8005\u5176\u4ed6\u52a8\u4f5c\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u3002
probe\u3001remove\uff1a\u5f53\u5c5e\u4e8e\u8be5bus\u7684device\uff0c\u53d1\u751f\u521d\u59cb\u5316\u548c\u79fb\u9664\u65f6\uff0c\u8c03\u7528\u8be5\u51fd\u6570\u3002
p\uff1a\u4fdd\u5b58\u4e86bus\u6a21\u5757\u7684\u4e00\u4e9b\u79c1\u6709\u6570\u636e\u3002
bus\u6a21\u5757\u7684\u4e3b\u8981\u529f\u80fd\u662f\uff1a
bus\u7684\u6ce8\u518c\u548c\u6ce8\u9500 \u672cbus\u4e0b\u6709device\u6216\u8005device_driver\u6ce8\u518c\u5230\u5185\u6838\u65f6\u7684\u5904\u7406 \u672cbus\u4e0b\u6709device\u6216\u8005device_driver\u4ece\u5185\u6838\u6ce8\u9500\u65f6\u7684\u5904\u7406 device_driver\u7684probe \u7ba1\u7406bus\u4e0b\u6240\u6709\u7684device\u548cdevice_driver \u5185\u6838\u63d0\u4f9b\u4e86bus_register()
\u51fd\u6570\u6765\u6ce8\u518c\u603b\u7ebf\uff0cbus_unregister()
\u51fd\u6570\u6765\u6ce8\u9500\u603b\u7ebf\u3002
int bus_register(struct bus_type *bus);\n\nvoid bus_unregister(struct bus_type *bus);\n
\u5f53\u6211\u4eec\u6210\u529f\u6ce8\u518c\u603b\u7ebf\u65f6\uff0c\u4f1a\u5728/sys/bus/\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u76ee\u5f55\uff0c\u76ee\u5f55\u540d\u4e3a\u6211\u4eec\u65b0\u6ce8\u518c\u7684\u603b\u7ebf\u540d\u3002bus\u76ee\u5f55\u4e2d\u5305\u542b\u4e86\u5f53\u524d\u7cfb\u7edf\u4e2d\u5df2\u7ecf\u6ce8\u518c\u4e86\u7684\u6240\u6709\u603b\u7ebf\uff0c\u4f8b\u5982i2c\uff0cspi\uff0cplatform\u7b49\u3002
"},{"location":"linux/drivers/#class","title":"class","text":"\u5728\u672c\u6587\u7684\u5f00\u5934\u6211\u4eec\u63d0\u5230\uff0cclass\u662f\u7528\u6765\u7edf\u4e00\u7ba1\u7406\u76f8\u540c\u529f\u80fd\u7684\u8bbe\u5907\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u6bcf\u4e2a\u8bbe\u5907\u9a71\u52a8\u5b9e\u73b0\u91cd\u590d\u7684\u529f\u80fd\u3002
struct class {\n const char *name;\n struct module *owner;\n\n const struct attribute_group **class_groups;\n const struct attribute_group **dev_groups;\n struct kobject *dev_kobj;\n\n int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);\n char *(*devnode)(struct device *dev, umode_t *mode);\n\n void (*class_release)(struct class *class);\n void (*dev_release)(struct device *dev);\n\n int (*shutdown_pre)(struct device *dev);\n\n const struct kobj_ns_type_operations *ns_type;\n const void *(*namespace)(struct device *dev);\n\n void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);\n\n const struct dev_pm_ops *pm;\n\n struct subsys_private *p;\n};\n
name\uff1aclass\u7684\u540d\u79f0\uff0c\u4f53\u73b0\u5728/sys/class\u76ee\u5f55\u4e0b\u3002
class_groups\uff1aclass\u5c5e\u6027\u3002
dev_groups\uff1adev\u5c5e\u6027\u3002
dev_uevent\uff1a\u8bbe\u5907\u7684uevent\u56de\u8c03\u51fd\u6570\u3002
class_release/dev_release\uff1arelease\u56de\u8c03\u51fd\u6570\u3002
pm\uff1a\u7535\u6e90\u7ba1\u7406\u7684\u56de\u8c03\u51fd\u6570\u3002
p\uff1a\u79c1\u6709\u6570\u636e\u3002
struct class_interface
\u5b9a\u4e49\u4e86\u5f53\u524dclass\u4e0b\u6709\u8bbe\u5907\u6dfb\u52a0\u6216\u8005\u79fb\u9664\u65f6\uff0c\u53ef\u4ee5\u8c03\u7528\u7684\u56de\u8c03\u51fd\u6570\uff1a
struct class_interface {\n struct list_head node;\n struct class *class;\n\n int (*add_dev) (struct device *, struct class_interface *);\n void (*remove_dev) (struct device *, struct class_interface *);\n};\n
class\u7684\u6ce8\u518c/\u6ce8\u9500\u51fd\u6570\u5982\u4e0b\uff1a
int __must_check __class_register(struct class *class, struct lock_class_key *key);\nvoid class_unregister(struct class *class);\n
class\u7684\u6982\u5ff5\u6bd4\u8f83\u62bd\u8c61\uff0c\u540e\u7eed\uff0c\u5728\u5404\u7c7b\u5b50\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u80fd\u770b\u5230\u8bb8\u591aclass\u7684\u7528\u4f8b\u3002
"},{"location":"linux/drivers/#_2","title":"\u5e73\u53f0\u8bbe\u5907\u9a71\u52a8","text":"\u5bf9\u4e8eI2C\u3001SPI\u3001USB\u8fd9\u4e9b\u5e38\u89c1\u7684\u8bbe\u5907\u6765\u8bf4\uff0cLinux\u5185\u6838\u90fd\u4f1a\u521b\u5efa\u4e0e\u4e4b\u76f8\u5bf9\u5e94\u7684\u9a71\u52a8\u603b\u7ebf\u3002\u4f46\u662f\u6709\u4e9b\u7ed3\u6784\u7b80\u5355\u7684\u8bbe\u5907\uff0c\u6bd4\u5982led\u3001rtc\u65f6\u949f\u3001\u8702\u9e23\u5668\u7b49\uff0c\u5185\u6838\u5c31\u4e0d\u4f1a\u81ea\u5df1\u521b\u5efa\u9a71\u52a8\u603b\u7ebf\u3002\u4e3a\u4e86\u4f7f\u8fd9\u90e8\u5206\u8bbe\u5907\u7684\u9a71\u52a8\u5f00\u53d1\u4e5f\u80fd\u9075\u5faa\u8bbe\u5907\u9a71\u52a8\u6a21\u578b\uff0cLinux\u5185\u6838\u5f15\u5165\u4e86\u865a\u62df\u7684\u603b\u7ebf\u2014\u2014\u5e73\u53f0\u603b\u7ebf\uff08platform bus\uff09\u3002\u5e73\u53f0\u603b\u7ebf\u7528\u4e8e\u7ba1\u7406\u548c\u6302\u8f7d\u90a3\u4e9b\u6ca1\u6709\u76f8\u5e94\u7269\u7406\u603b\u7ebf\u7684\u8bbe\u5907\uff0c\u8fd9\u4e9b\u8bbe\u5907\u88ab\u79f0\u4e3a\u5e73\u53f0\u8bbe\u5907\uff0c\u5bf9\u5e94\u7684\u8bbe\u5907\u9a71\u52a8\u88ab\u79f0\u4e3a\u5e73\u53f0\u9a71\u52a8\u3002\u5e73\u53f0\u8bbe\u5907\u5bf9\u4e8eLinux\u9a71\u52a8\u5de5\u7a0b\u5e08\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u56e0\u4e3a\u5927\u591a\u6570\u7684\u9a71\u52a8\u4ee3\u7801\uff0c\u5b9e\u9645\u5c31\u662f\u4e3a\u4e86\u9a71\u52a8\u5e73\u53f0\u8bbe\u5907\u3002
Platform\u67b6\u6784\u56fe\u5982\u4e0b\u6240\u793a\uff1a
\u4ece\u56fe\u7247\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff1a
platform bus\uff1a\u7ee7\u627f\u81eabus\u6a21\u5757\uff0c\u7528\u4e8e\u6302\u8f7dplatform\u8bbe\u5907\u3002 platform device\uff1a\u7ee7\u627f\u81eadevice\u6a21\u5757\uff0c\u7528\u4e8e\u63cf\u8ff0platform\u8bbe\u5907\u3002 platform drvier\uff1a\u7ee7\u627f\u81eadevice_driver\u6a21\u5757\uff0c\u7528\u4e8e\u9a71\u52a8platform\u8bbe\u5907\u3002 "},{"location":"linux/drivers/#_3","title":"\u5e73\u53f0\u603b\u7ebf","text":"\u5728Linux\u5e73\u53f0\u8bbe\u5907\u9a71\u52a8\u6a21\u578b\u4e2d\uff0c\u603b\u7ebf\u662f\u6700\u91cd\u8981\u7684\u4e00\u73af\uff0c\u8d1f\u8d23\u5339\u914d\u8bbe\u5907\u548c\u9a71\u52a8\u3002\u5b83\u7ef4\u62a4\u7740\u4e24\u4e2a\u94fe\u8868\uff0c\u91cc\u9762\u8bb0\u5f55\u7740\u5404\u4e2a\u5df2\u7ecf\u6ce8\u518c\u7684\u5e73\u53f0\u8bbe\u5907\u548c\u5e73\u53f0\u9a71\u52a8\u3002\u6bcf\u5f53\u6709\u65b0\u7684\u8bbe\u5907\u6216\u8005\u662f\u9a71\u52a8\u52a0\u5165\u5230\u603b\u7ebf\u65f6\uff0c\u4fbf\u4f1a\u8c03\u7528platform_match()
\u51fd\u6570\u5bf9\u65b0\u589e\u7684\u8bbe\u5907\u6216\u9a71\u52a8\u8fdb\u884c\u914d\u5bf9\u3002\u5185\u6838\u4f7f\u7528struct bus_type platform_bus_type
\u6765\u63cf\u8ff0\u5e73\u53f0\u603b\u7ebf\uff0c\u8be5\u603b\u7ebf\u5728\u5185\u6838\u521d\u59cb\u5316\u7684\u65f6\u5019\u6ce8\u518c\uff1a
sturct bus_type platform_bus_type{\n .name = \"platform\",\n .dev_groups = platform_dev_groups,\n .match = platform_match,\n .uevent = platform_uevent,\n .pm = &platform_dev_pm_ops,\n};\n
\u5bf9platform_bus_typ
e\u7684\u521d\u59cb\u5316\u6765\u8bf4\uff0cmatch
\u51fd\u6570\u6307\u9488\u6700\u4e3a\u91cd\u8981\uff0c\u5b83\u6307\u5411\u7684\u51fd\u6570\u8d1f\u8d23\u5b9e\u73b0\u5e73\u53f0\u603b\u7ebf\u548c\u5e73\u53f0\u8bbe\u5907\u7684\u5339\u914d\u8fc7\u7a0b\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u9a71\u52a8\u603b\u7ebf\uff0c\u90fd\u5fc5\u987b\u5b9e\u4f8b\u5316\u8be5\u51fd\u6570\u6307\u9488\u3002
"},{"location":"linux/drivers/#_4","title":"\u5e73\u53f0\u8bbe\u5907","text":"\u5185\u6838\u4f7f\u7528platform_device
\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u5e73\u53f0\u8bbe\u5907\uff1a
struct platform_device {\n const char *name; //\u8bbe\u5907\u540d\u79f0\uff0c\u5339\u914d\u65f6\u4f1a\u6bd4\u8f83\u9a71\u52a8\u7684\u540d\u5b57\n int id; //\u5185\u6838\u5141\u8bb8\u5b58\u5728\u591a\u4e2a\n struct device dev; //\u7ee7\u627f\u7684device\u7ed3\u6784\u4f53\n u32 num_resources; //\u8bb0\u5f55\u8d44\u6e90\u7684\u6570\u76ee\n struct resource *resource; //\u5e73\u53f0\u8bbe\u5907\u63d0\u4f9b\u7ed9\u9a71\u52a8\u7684\u8d44\u6e90\n const struct platform_device_id *id_entry; \n };\n
\u5e73\u53f0\u8bbe\u5907\u7684\u5de5\u4f5c\u662f\u4e3a\u9a71\u52a8\u7a0b\u5e8f\u63d0\u4f9b\u8bbe\u5907\u4fe1\u606f,\u8bbe\u5907\u4fe1\u606f\u5305\u62ec\u786c\u4ef6\u4fe1\u606f\u548c\u8f6f\u4ef6\u4fe1\u606f\u4e24\u90e8\u5206\u3002
\u786c\u4ef6\u4fe1\u606f\uff1a\u9a71\u52a8\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528\u5230\u4ec0\u4e48\u5bc4\u5b58\u5668\uff0c\u5360\u7528\u54ea\u4e9b\u4e2d\u65ad\u53f7\u3001\u5185\u5b58\u8d44\u6e90\u3001IO\u53e3\u7b49\u7b49
\u8f6f\u4ef6\u4fe1\u606f\uff1a\u4ee5\u592a\u7f51\u5361\u8bbe\u5907\u4e2d\u7684MAC\u5730\u5740\u3001I2C\u8bbe\u5907\u4e2d\u7684\u8bbe\u5907\u5730\u5740\u3001SPI\u8bbe\u5907\u7684\u7247\u9009\u4fe1\u53f7\u7ebf\u7b49\u7b49
\u5bf9\u4e8e\u786c\u4ef6\u4fe1\u606f\uff0c\u4f7f\u7528\u7ed3\u6784\u4f53struct resource
\u6765\u4fdd\u5b58\u8bbe\u5907\u6240\u63d0\u4f9b\u7684\u8d44\u6e90\uff0c\u6bd4\u5982\u8bbe\u5907\u4f7f\u7528\u7684\u4e2d\u65ad\u7f16\u53f7\uff0c\u5bc4\u5b58\u5668\u7269\u7406\u5730\u5740\u7b49\uff0c\u7ed3\u6784\u4f53\u539f\u578b\u5982\u4e0b\uff1a
struct resource {\n resource_size_t start;\n resource_size_t end;\n const char *name;\n unsigned long flags;\n};\n
name\uff1a \u6307\u5b9a\u8d44\u6e90\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3aNULL\uff1b
start\u3001end\uff1a \u6307\u5b9a\u8d44\u6e90\u7684\u8d77\u59cb\u5730\u5740\u4ee5\u53ca\u7ed3\u675f\u5730\u5740
flags\uff1a \u7528\u4e8e\u6307\u5b9a\u8be5\u8d44\u6e90\u7684\u7c7b\u578b\uff0c\u5728Linux\u4e2d\uff0c\u8d44\u6e90\u5305\u62ecI/O\u3001Memory\u3001Register\u3001IRQ\u3001DMA\u3001Bus\u7b49\u591a\u79cd\u7c7b\u578b\uff0c\u6700\u5e38\u89c1\u7684\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a
\u8d44\u6e90\u5b8f\u5b9a\u4e49 \u63cf\u8ff0 IORESOURCE_IO \u7528\u4e8eIO\u5730\u5740\u7a7a\u95f4\uff0c\u5bf9\u5e94\u4e8eIO\u7aef\u53e3\u6620\u5c04\u65b9\u5f0f IORESOURCE_MEM \u7528\u4e8e\u5916\u8bbe\u7684\u53ef\u76f4\u63a5\u5bfb\u5740\u7684\u5730\u5740\u7a7a\u95f4 IORESOURCE_IRQ \u7528\u4e8e\u6307\u5b9a\u8be5\u8bbe\u5907\u4f7f\u7528\u67d0\u4e2a\u4e2d\u65ad IORESOURCE_DMA \u7528\u4e8e\u6307\u5b9a\u4f7f\u7528\u7684DMA\u901a\u9053 \u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u7684\u4e3b\u8981\u76ee\u7684\u662f\u64cd\u4f5c\u8bbe\u5907\u7684\u5bc4\u5b58\u5668\u3002\u4e0d\u540c\u67b6\u6784\u7684\u8ba1\u7b97\u673a\u63d0\u4f9b\u4e0d\u540c\u7684\u64cd\u4f5c\u63a5\u53e3\uff0c\u4e3b\u8981\u6709IO\u7aef\u53e3\u6620\u5c04\u548cIO\u5167\u5b58\u6620\u5c04\u4e24\u79cd\u65b9\u5f0f\u3002\u5bf9\u5e94\u4e8eIO\u7aef\u53e3\u6620\u5c04\u65b9\u5f0f\uff0c\u53ea\u80fd\u901a\u8fc7\u4e13\u95e8\u7684\u63a5\u53e3\u51fd\u6570\uff08\u5982inb\u3001outb\uff09\u624d\u80fd\u8bbf\u95ee\uff1b\u91c7\u7528IO\u5185\u5b58\u6620\u5c04\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u50cf\u8bbf\u95ee\u5185\u5b58\u4e00\u6837\uff0c\u53bb\u8bfb\u5199\u5bc4\u5b58\u5668\u3002\u5728\u5d4c\u5165\u5f0f\u4e2d\uff0c\u57fa\u672c\u4e0a\u6ca1\u6709IO\u5730\u5740\u7a7a\u95f4\uff0c\u6240\u4ee5\u901a\u5e38\u4f7f\u7528IORESOURCE_MEM\u3002
\u5728\u8d44\u6e90\u7684\u8d77\u59cb\u5730\u5740\u548c\u7ed3\u675f\u5730\u5740\u4e2d\uff0c\u5bf9\u4e8eIORESOURCE_IO\u6216\u8005\u662fIORESOURCE_MEM\uff0c\u4ed6\u4eec\u8868\u793a\u8981\u4f7f\u7528\u7684\u5185\u5b58\u7684\u8d77\u59cb\u4f4d\u7f6e\u4ee5\u53ca\u7ed3\u675f\u4f4d\u7f6e\uff1b\u82e5\u662f\u53ea\u7528\u4e00\u4e2a\u4e2d\u65ad\u5f15\u811a\u6216\u8005\u662f\u4e00\u4e2a\u901a\u9053\uff0c\u5219\u5b83\u4eec\u7684start\u548cend\u6210\u5458\u503c\u5fc5\u987b\u662f\u76f8\u7b49\u7684\u3002
\u6ce8\u518c/\u6ce8\u9500\u5e73\u53f0\u8bbe\u5907\u7528\u5230\u7684\u51fd\u6570\u5982\u4e0b\uff1a
int platform_device_register(struct platform_device *pdev);\nvoid platform_device_unregister(struct platform_device *pdev);\n
"},{"location":"linux/drivers/#_5","title":"\u5e73\u53f0\u9a71\u52a8","text":"\u5185\u6838\u4f7f\u7528platform_driver
\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u5e73\u53f0\u9a71\u52a8\uff1a
struct platform_driver {\n int (*probe)(struct platform_device *);\n int (*remove)(structg platform_device *);\n int (*suspend)(struct platform_device *, pm_message_t state);\n int (*resume)(struct platform_device *);\n struct device_driver driver;\n const struct platform_device_id *id_table;\n};\n
\u9664\u4e86\u63d0\u4f9b\u4e00\u4e9b\u56de\u8c03\u51fd\u6570\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2aid_table
\u7684\u6307\u9488\u3002\u8fd9\u4e2a\u6307\u9488\u7528\u6765\u8868\u793a\u8be5\u9a71\u52a8\u80fd\u591f\u517c\u5bb9\u7684\u8bbe\u5907\u7c7b\u578b\uff0c\u5f53\u8bbe\u5907\u8c03\u7528probe()
\u51fd\u6570\u65f6\uff0c\u5c31\u4f1a\u5230\u8fd9\u4e2a\u6570\u7ec4\u91cc\u68c0\u67e5\u662f\u5426\u5339\u914d\u3002
\u6211\u4eec\u770b\u4e00\u4e0bstruct platform_device_id
\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\uff1a
struct platform_device_id {\n char name[PLATFORM_NAME_SIZE];\n kernel_ulong_t driver_data;\n};\n
name\u7528\u4e8e\u6307\u5b9a\u9a71\u52a8\u7684\u540d\u79f0\uff0c\u603b\u7ebf\u8fdb\u884c\u5339\u914d\u65f6\uff0c\u4f1a\u6839\u636e\u8be5name\u6210\u5458\u4e0eplatform_device
\u4e2d\u7684name\u8fdb\u884c\u5339\u914d\u3002driver_data\u7528\u6765\u4fdd\u5b58\u8bbe\u5907\u7684\u914d\u7f6e\u3002\u4e3a\u4e86\u51cf\u5c11\u4ee3\u7801\u7684\u5197\u4f59\uff0c\u4e00\u4e2a\u9a71\u52a8\u53ef\u4ee5\u5339\u914d\u591a\u4e2a\u8bbe\u5907\u3002
\u6ce8\u518c/\u6ce8\u9500\u5e73\u53f0\u9a71\u52a8\u7684\u51fd\u6570\u5982\u4e0b\uff1a
int platform_driver_register(struct platform_device *drv);\nvoid platform_driver_unregister(struct platform_device *drv);\n
\u5728\u5e73\u53f0\u8bbe\u5907\u4e2d\uff0cstruct resource
\u7ed3\u6784\u4f53\u7528\u6765\u8868\u793a\u786c\u4ef6\u4fe1\u606f\uff0c\u800c\u8f6f\u4ef6\u4fe1\u606f\u5219\u53ef\u4ee5\u7528\u8bbe\u5907\u7ed3\u6784\u4f53device
\u4e2d\u7684\u6210\u5458platform_data\u6765\u4fdd\u5b58\u3002
platform_get_resource()
\u51fd\u6570\u901a\u5e38\u4f1a\u5728\u9a71\u52a8\u7684probe()
\u51fd\u6570\u4e2d\u6267\u884c\uff0c\u7528\u4e8e\u83b7\u53d6\u5e73\u53f0\u8bbe\u5907\u63d0\u4f9b\u7684\u8d44\u6e90\u7ed3\u6784\u4f53\uff0c\u6700\u7ec8\u8fd4\u56de\u4e00\u4e2astruct resource
\u7684\u6307\u9488\uff1a
struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num);\n
dev\uff1a\u6307\u5b9a\u8981\u83b7\u53d6\u7684\u5e73\u53f0\u8bbe\u5907\u3002
type\uff1a\u6307\u5b9a\u83b7\u53d6\u8d44\u6e90\u7684\u7c7b\u578b\uff0c\u6bd4\u5982IORESOURCE_IO\u3002
num\uff1a\u6307\u5b9a\u8981\u83b7\u53d6\u7684\u8d44\u6e90\u7f16\u53f7\u3002
\u5982\u679c\u8d44\u6e90\u7c7b\u578b\u662fIORESOURCE_IRQ\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u63a5\u53e3\u8fd8\u83b7\u53d6\u4e2d\u65ad\u5f15\u811a\uff1a
int platform_get_irq(struct platform_device *pdev, unsigned int num);\n
\u5bf9\u4e8e\u5b58\u653e\u5728device
\u7ed3\u6784\u4f53\u4e2dplatform_data\u7684\u8f6f\u4ef6\u4fe1\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528dev_get_platdata()
\u51fd\u6570\u6765\u83b7\u53d6\uff1a
static inline void *dev_get_platdata(const struct device *dev)\n{\n return dev->platform_data;\n}\n
\u603b\u7ed3\u4e00\u4e0b\u5e73\u53f0\u9a71\u52a8\uff1a\u9700\u8981\u5b9e\u73b0probe()
\u51fd\u6570\uff0c\u5f53\u5e73\u53f0\u603b\u7ebf\u6210\u529f\u5339\u914d\u9a71\u52a8\u548c\u8bbe\u5907\u65f6\uff0c\u5219\u4f1a\u8c03\u7528\u9a71\u52a8\u7684probe()
\u51fd\u6570\uff0c\u5728\u8be5\u51fd\u6570\u4e2d\u4f7f\u7528\u4e0a\u8ff0\u7684\u51fd\u6570\u63a5\u53e3\u6765\u83b7\u53d6\u8d44\u6e90\uff0c\u4ee5\u521d\u59cb\u5316\u8bbe\u5907\uff0c\u6700\u540e\u586b\u5145\u7ed3\u6784\u4f53platform_driver
\uff0c\u8c03\u7528platform_driver_register()
\u8fdb\u884c\u6ce8\u518c\u3002
"},{"location":"linux/drivers/chardev/","title":"\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f","text":"\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6846\u67b6\u5982\u56fe\u6240\u793a\uff1a
\u5728\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907\u7684\u65f6\u5019\uff0c\u9996\u5148\u5e94\u8be5\u5411\u5185\u6838\u7533\u8bf7\u4e00\u4e2a\u8bbe\u5907\u53f7\u3002\u62ff\u5230\u8bbe\u5907\u53f7\u4e4b\u540e\uff0c\u9700\u8981\u624b\u52a8\u5b9e\u73b0file_operation\u7ed3\u6784\u4f53\u4e2d\u7684\u51fd\u6570\u6307\u9488\uff0c\u5e76\u4fdd\u5b58\u5230cdev\u7ed3\u6784\u4f53\u4e2d\u3002\u7136\u540e\u4f7f\u7528cdev_add()
\u51fd\u6570\u6ce8\u518ccdev\u3002
\u6ce8\u9500\u8bbe\u5907\u65f6\u9700\u8981\u91ca\u653e\u5185\u6838\u4e2d\u7684cdev\uff0c\u5e76\u4e14\u5f52\u8fd8\u7533\u8bf7\u7684\u8bbe\u5907\u53f7\u3002
"},{"location":"linux/drivers/chardev/#_2","title":"\u5feb\u901f\u53c2\u8003","text":"#include <linux/types.h>\n\ndev_t devID\n\nint MAJOR(dev_t dev)\n\nint MINOR(dev_t dev)\n\ndev_t MKDEV(unsigned int major, unsigned int minor)\n
#include <linux/fs.h>\n\nint register_chrdev_region(dev_t first, unsigned int count, char *name)\n\nint alloc_chrdev_region(dev_t *dev, unsigned int firstminor, unsigned int count, char *name)\n\nvoid unregister_chrdev_region(dev_t first, unsigned int count)\n\nint register_chrdev(unsigned int major, const char *name, struct file_operations *fops)\n\nint unregister_chrdev(unsigned int major, const char *name)\n\nstruct file_operations\n\nstruct file\n\nstruct inode\n
#include <linux/cdev.h>\n\nstruct cdev *cdev_alloc(void)\n\nvoid cdev_init(struct cdev *dev, dev_t num, unsigned int count)\n\nint cdev_add(struct cdev *cdev, dev_t num, unsigned int count)\n\nvoid cdev_del(struct cdev *dev)\n
#include <linux/kernel.h>\n\ncontainer_of(pointer, type, field)\n\n#include <asm/uaccess.h>\n\nunsigned long copy_from_user(void *to, const void *from, unsigned long count)\n\nunsigned long copy_to_user(void *to, const void *from, unsigned long count)\n
"},{"location":"linux/drivers/chardev/#_3","title":"\u8bbe\u5907\u53f7\u521d\u59cb\u5316","text":""},{"location":"linux/drivers/chardev/#_4","title":"\u8bbe\u5907\u53f7\u7684\u6ce8\u518c\u4e0e\u5378\u8f7d(\u4e0d\u63a8\u8350\u7684\u505a\u6cd5)","text":" \u8fd9\u4e2a\u65b9\u6cd5\u5728\u6ce8\u518c\u65f6\u9700\u8981\u624b\u52a8\u6307\u5b9a\u4e3b\u8bbe\u5907\u53f7\uff0c\u56e0\u6b64\u4f60\u5fc5\u987b\u4e8b\u5148\u77e5\u9053\u54ea\u4e2a\u4e3b\u8bbe\u5907\u53f7\u6ca1\u6709\u88ab\u5360\u7528\uff0c\u8fd9\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u96be\u4ee5\u63a8\u5e7f\uff0c\u5e76\u4e14\u8be5\u51fd\u6570\u8fd8\u4e00\u6b21\u6027\u5360\u7528\u4e86\u4e3b\u8bbe\u5907\u53f7\u4e0b\u7684\u5168\u90e8\u6b21\u8bbe\u5907\u53f7\u3002
"},{"location":"linux/drivers/chardev/#_5","title":"\u8bbe\u5907\u53f7\u7684\u6ce8\u518c\u4e0e\u5378\u8f7d(\u63a8\u8350\u7684\u505a\u6cd5)","text":" int register_chrdev_region(dev_t first, unsigned count, const char *name)\n
first\u662f\u8981\u5206\u914d\u7684\u8bbe\u5907\u7f16\u53f7\u7684\u8d77\u59cb\u503c\uff0ccount\u662f\u6240\u8bf7\u6c42\u7684\u8fde\u7eed\u8bbe\u5907\u7f16\u53f7\u7684\u4e2a\u6570\uff0cname\u662f\u548c\u8be5\u7f16\u53f7\u8303\u56f4\u5173\u8054\u7684\u8bbe\u5907\u540d\u79f0\uff0c\u5b83\u5c06\u51fa\u73b0\u5728/proc/devices\u548csysfs\u4e2d\u3002
\u5982\u679c\u6211\u4eec\u63d0\u524d\u77e5\u9053\u6240\u9700\u8981\u7684\u8bbe\u5907\u7f16\u53f7\uff0c\u90a3\u4e48\u4f7f\u7528register_chrdev_region()
\u5c31\u591f\u4e86\u3002\u4f46\u662f\u5728\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff0c\u4e0d\u63a8\u8350\u8fd9\u4e48\u505a\uff0c\u800c\u5e94\u8be5\u4f7f\u7528\u52a8\u6001\u5206\u914d\u51fd\u6570\uff1a
int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name)\n
dev\u7528\u6765\u4fdd\u5b58\u4f60\u8981\u7533\u8bf7\u7684\u90a3\u4e2a\u8bbe\u5907\u53f7\u53d8\u91cf\uff0c baseminor\u662f\u6b21\u8bbe\u5907\u53f7\u7684\u8d77\u59cb\u503c\uff0c\u901a\u5e38\u662f0\u3002 \u9a71\u52a8\u7a0b\u5e8f\u5e94\u8be5\u59cb\u7ec8\u4f7f\u7528alloc_chrdev_region
\u800c\u4e0d\u662fregister_chrdev_region
\u2014\u2014\u2014\u2014\u300aLinux\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8fP50\u300b
\u4e0a\u9762\u4e24\u79cd\u65b9\u6cd5\u6ce8\u518c\u7684\u8bbe\u5907\u7edf\u4e00\u7528\u4ee5\u4e0b\u51fd\u6570\u5378\u8f7d\u3002
void unregister_chrdev_region(dev_t first, unsigned count)\n
\u8be5\u51fd\u6570\u901a\u5e38\u5728\u6e05\u9664\u51fd\u6570\u4e2d\u8c03\u7528\u3002
\u8fd9\u91cc\u6211\u4eec\u7ed9\u51fa\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u5047\u8bbe\u6211\u4eec\u9700\u8981\u6ce8\u518c\u4e00\u4e2a\u540d\u5b57\u4e3a\"test\"\u7684\u8bbe\u5907\u3002
int major;\nint minor;\ndev_t devid;\n\nif(major){\n devid = MKDEV(major, 0);\n register_chrdev_region(devid, 1, \"test\");\n}else {\n alloc_chrdev_region(&devid, 0, 1, \"test\");\n major = MAJOR(devid);\n minor = MINOR(devid);\n}\n
\u5bf9\u8bbe\u5907\u53f7\u64cd\u4f5c\u65f6\uff0c\u4f7f\u7528\u5230\u4e86\u4e09\u4e2a\u5b8f\u5b9a\u4e49\uff0cMKDEV, MAJOR, MINOR\u3002\u5f53\u7ed9\u5b9a\u4e3b\u8bbe\u5907\u53f7\u65f6\uff0c\u4f7f\u7528MKDEV\u6765\u6784\u5efa\u5b8c\u6574\u7684devID\uff0c\u6b21\u8bbe\u5907\u53f7\u5219\u4e00\u822c\u9009\u62e90\u3002
\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0cmajor\u53ef\u4ee5\u7528\u4e00\u4e2a\u5b8f\u5b9a\u4e49\u53d6\u4ee3\uff0c\u9ed8\u8ba4\u53d60\uff0c\u5373\u8d70else\u5206\u652f\u9009\u62e9\u201c\u52a8\u6001\u5206\u914d\u201d\u3002\u7528\u6237\u53ef\u4ee5\u9009\u62e9\u4f7f\u7528\u9ed8\u8ba4\u503c\u5373\u52a8\u6001\u5206\u914d\u7684\u65b9\u5f0f\uff0c\u6216\u8005\u81ea\u5b9a\u4e49\u7279\u5b9a\u7684\u8bbe\u5907\u53f7\u2014\u2014\u53ea\u8981\u5728\u7f16\u8bd1\u524d\u4fee\u6539\u5b8f\u5b9a\u4e49\u4e3a\u8bbe\u5907\u53f7\uff0c\u6216\u8005\u5728insmod\u65f6\u6307\u5b9a\u5373\u53ef\u3002
"},{"location":"linux/drivers/chardev/#_6","title":"\u5b57\u7b26\u8bbe\u5907\u7684\u6ce8\u518c","text":"\u5185\u6838\u4f7f\u7528struct cdev\u7ed3\u6784\u6765\u8868\u793a\u5b57\u7b26\u8bbe\u5907\uff0c\u5f53\u6211\u4eec\u81ea\u5df1\u5b9e\u73b0file_operations\u7ed3\u6784\u4f53\u4e2d\u7684\u51fd\u6570\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528cdev_init()
\u51fd\u6570\u6765\u5c06\u6587\u4ef6\u64cd\u4f5c\u6307\u9488\u4e0e\u5b57\u7b26\u8bbe\u5907\u76f8\u5173\u8054\u3002
void cdev_init(struct cdev *cdev, const struct file_operations *fops)\n
cdev_add()
\u51fd\u6570\u7528\u4e8e\u5411\u5185\u6838\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u8bbe\u5907\uff0ccdev_del()
\u51fd\u6570\u7528\u6765\u5220\u9664\u3002
int cdev_add(struct cdev *p, dev_t dev, unsigned count)\nvoid cdev_del(struct cdev *p)\n
"},{"location":"linux/drivers/chardev/#_7","title":"\u5185\u5b58\u6620\u5c04","text":""},{"location":"linux/drivers/chardev/#_8","title":"\u9a71\u52a8\u5c42\u7684\u64cd\u4f5c","text":"\u7531\u4e8eLinux\u6709MMU\u6a21\u5757\uff0c\u56e0\u6b64\u65e0\u6cd5\u8bbf\u95ee\u771f\u5b9e\u7684\u7269\u7406\u5730\u5740\uff0c\u53ea\u80fd\u901a\u8fc7\u865a\u62df\u5730\u5740\u8bbf\u95ee\u786c\u4ef6\u5916\u8bbe\u3002\u6240\u4ee5\u9700\u8981\u6709\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u5728\u7269\u7406\u5730\u5740\u548c\u865a\u62df\u5730\u5740\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u3002
\u5173\u4e8e\u5982\u4f55\u83b7\u53d6\u786c\u4ef6\u7684\u7269\u7406\u5730\u5740\uff0c\u8bf7\u53c2\u8003\u8bbe\u5907\u6811\u3002
\u5730\u5740\u6620\u5c04\u51fd\u6570\u5982\u4e0b\uff1a
void __iomem *ioremap(phys_addr_t paddr, unsigned long size)\n
\u5176\u4e2daddr\u5c31\u662f\u4f60\u8981\u8bbf\u95ee\u7684\u76f4\u63a5\u7269\u7406\u5730\u5740\uff0csize\u662f\u9700\u8981\u8f6c\u5316\u7684\u5927\u5c0f\uff0c\u8fd4\u56de\u503c\u5c31\u662f\u865a\u62df\u5730\u5740\uff0c\u8fd9\u4e2a\u865a\u62df\u5730\u5740\u6211\u4eec\u9700\u8981\u4e13\u95e8\u7684\u6570\u636e\u7c7b\u578b\u53bb\u63a5\u6536\u3002
\u53d6\u6d88\u5730\u5740\u6620\u5c04\u51fd\u6570\uff1a
void iounmap(void *addr)\n
"},{"location":"linux/drivers/chardev/#io","title":"I/O\u5185\u5b58\u8bbf\u95ee\u51fd\u6570","text":"\u4f7f\u7528ioremap\u51fd\u6570\u5c06\u5bc4\u5b58\u5668\u7269\u7406\u5730\u5740\u6620\u5c04\u5230\u865a\u62df\u5730\u5740\u540e\uff0cLinux\u63a8\u8350\u4f7f\u7528\u5185\u6838\u81ea\u5e26\u7684\u8bfb\u5199\u64cd\u4f5c\u51fd\u6570\u5bf9\u6620\u5c04\u540e\u7684\u5185\u5b58\u8fdb\u884c\u8bfb\u5199\u3002
unsigned int ioread8(void __iomem *addr)\nunsigned int iorea16(void __iomem *addr)\nunsigned int ioread32(void __iomem *addr)\n\nvoid iowrite8(u8 b, void __iomem *addr)\nvoid iowrite16(u16 b, void __iomem *addr)\nvoid iowrite32(u32 b, void __iomem *addr)\n
\u5bf9\u4e8e\u8bfbI/O\u800c\u8a00\uff0c\u8f93\u5165\u53c2\u6570\u4e3a__iomem\u7c7b\u578b\u7684\u6307\u9488\uff0c\u6307\u5411\u88ab\u6620\u5c04\u540e\u7684\u5730\u5740\uff0c\u8fd4\u56de\u503c\u4e3a\u8bfb\u53d6\u5230\u7684\u6570\u636e\uff1b\u5bf9\u4e8e\u5199I/O\u800c\u8a00\uff0c\u8f93\u5165\u53c2\u6570\u7b2c\u4e00\u4e2a\u4e3a\u8981\u5199\u5165\u7684\u6570\u636e\uff0c\u7b2c\u4e8c\u4e2a\u4e3a\u8981\u5199\u5165\u7684\u5730\u5740\uff0c\u8fd4\u56de\u503c\u4e3a\u7a7a\u3002
\u4e0b\u9762\u4e00\u6bb5\u4ee3\u7801\u6f14\u793a\u4e86\u5730\u5740\u6620\u5c04\u7684\u76f8\u5173\u64cd\u4f5c\uff1a
unsigned long pa_dr = 0x20A8000 + 0x00;\nunsigned int __iomem *va_dr;\nunsigned int val;\nva_dr = ioremap(pa_dr, 4);\nval = ioread32(va_dr);\nval &= ~(0x01 << 19);\niowrite32(val, va_dr);\n
"},{"location":"linux/drivers/chardev/#_9","title":"\u5e94\u7528\u5c42\u7684\u64cd\u4f5c","text":"\u7531\u4e8eLinux\u5185\u6838\u7981\u6b62\u7528\u6237\u6001\u548c\u5185\u6838\u6001\u76f4\u63a5\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\uff0c\u6211\u4eec\u53ea\u80fd\u901a\u8fc7\u5185\u6838\u63d0\u4f9b\u7684API\u51fd\u6570\u8fdb\u884c\u3002
unsigned long copy_from_user(void *to, const void *from, unsigned long count)\n\nunsigned long copy_to_user(void *to, const void *from, unsigned long count)\n
"},{"location":"linux/drivers/dts/","title":"\u8bbe\u5907\u6811","text":""},{"location":"linux/drivers/dts/#_2","title":"\u4e3a\u4ec0\u4e48\u9700\u8981\u8bbe\u5907\u6811","text":"\u8d77\u56e0\u662f\u5728<arch/arm/mach-xxx>\u76ee\u5f55\u4e0b\u5145\u65a5\u7740\u5927\u91cf\u91cd\u590d\u7684board specific\u7684\u4ee3\u7801\uff0c\u6bcf\u6b21Linux\u5185\u6838merge window\u671f\u95f4\uff0cARM\u7684\u4ee3\u7801\u53d8\u5316\u5360\u6574\u4e2aarch\u76ee\u5f55\u7684\u4e00\u534a\u4ee5\u4e0a\uff0c\u5bfc\u81f4\u5185\u6838\u5341\u5206\u7684\u81c3\u80bf\u3002\u7ecf\u8fc7\u793e\u533a\u8ba8\u8bba\u540e\u51b3\u5b9a\uff1a
ARM\u7684\u6838\u5fc3\u4ee3\u7801\u4ecd\u7136\u4fdd\u5b58\u5728<arch/arm>\u76ee\u5f55\u4e0b ARM SOC\u5468\u8fb9\u5916\u8bbe\u6a21\u5757\u7684\u9a71\u52a8\u4ee3\u7801\u4fdd\u5b58\u5728drivers\u76ee\u5f55\u4e0b ARM SOC board specific\u7684\u4ee3\u7801\u88ab\u79fb\u9664\uff0c\u7531Device Tree\u673a\u5236\u6765\u8d1f\u8d23\u4f20\u9012\u786c\u4ef6\u8d44\u6e90\u4fe1\u606f\u3002 \u672c\u8d28\u4e0a\uff0cDevice Tree\u6539\u53d8\u4e86\u539f\u6765\u7528hardcode\u65b9\u5f0f\u5c06\u786c\u4ef6\u914d\u7f6e\u4fe1\u606f\u5d4c\u5165\u5230\u5185\u6838\u4ee3\u7801\u7684\u65b9\u6cd5\u3002\u5bf9\u4e8e\u5d4c\u5165\u5f0f\u7cfb\u7edf\uff0c\u5728\u7cfb\u7edf\u542f\u52a8\u9636\u6bb5\uff0c\u7531bootloader\u901a\u8fc7bootm\u547d\u4ee4\u5c06\u8bbe\u5907\u6811\u4fe1\u606f\u4f20\u9012\u7ed9\u5185\u6838\uff0c\u7136\u540e\u7531\u5185\u6838\u6765\u8bc6\u522b\uff0c\u5e76\u6839\u636e\u5b83\u5c55\u5f00\u51fa\u5185\u6838\u4e2d\u7684platform_device\u3001i2c_client\u3001spi_device\u7b49\u8bbe\u5907\uff0c\u8fd9\u4e9b\u8bbe\u5907\u7528\u5230\u7684\u5185\u5b58\u3001IRQ\u7b49\u8d44\u6e90\u4e5f\u4f1a\u88ab\u4f20\u9012\u7ed9\u5185\u6838\u3002
\u8bbe\u5907\u6811\u6587\u4ef6.dts\u7528\u6765\u63cf\u8ff0\u786c\u4ef6\u4fe1\u606f\u3002\u4e00\u4e2aSOC\u53ef\u4ee5\u5236\u4f5c\u5f88\u591a\u5f00\u53d1\u677f\uff0c\u5c06\u8fd9\u4e9b\u5f00\u53d1\u677f\u7684\u901a\u7528\u4fe1\u606f\u63d0\u53d6\u51fa\u6765\uff0c\u53d8\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684.dtsi\u6587\u4ef6\u3002\u5176\u4ed6\u7684.dts\u53ef\u4ee5\u76f4\u63a5\u5f15\u7528\u901a\u7528\u6587\u4ef6\uff0c\u5c31\u50cfC\u8bed\u8a00\u4e2d\u7684\u5934\u6587\u4ef6\u3002
\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c.dtsi\u63cf\u8ff0SOC\u4fe1\u606f\uff0c\u6bd4\u5982CPU\u67b6\u6784\uff0c\u4e3b\u9891\u3002.dts\u6587\u4ef6\u63cf\u8ff0\u677f\u7ea7\u4fe1\u606f\uff0c\u6bd4\u5982\u5f00\u53d1\u677f\u4e0a\u6709\u54ea\u4e9bIIC\u8bbe\u5907\u3001SPI\u8bbe\u5907\u7b49\u3002
"},{"location":"linux/drivers/dts/#dtsdtbdtc","title":"DTS\u3001DTB\u548cDTC\u7684\u5173\u7cfb","text":".dts\u662f\u8bbe\u5907\u6811\u6e90\u7801\u6587\u4ef6\uff0cDTC\u8d1f\u8d23\u5c06.dts\u7f16\u8bd1\u6210.dtb\u3002\u800c.dtb\u5c31\u662f\u8d1f\u8d23\u4f20\u9012\u7ed9\u5185\u6838\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002
make dtbs\u4f1a\u7f16\u8bd1\u6240\u6709\u7684dts\u6587\u4ef6\uff0c\u5982\u679c\u8981\u7f16\u8bd1\u6307\u5b9a\u7684dtb\uff0c\u8bf7\u4f7f\u7528make board_name.dtb\u3002
\u5728arch/arm/boot/dts/Makefile\u4e2d\uff0c\u5982\u679c\u9009\u4e2d\u4e86\u67d0\u79cdSOC\uff0c\u5219\u8be5SOC\u4e0b\u7684\u6240\u6709\u76f8\u5173dtb\u6587\u4ef6\u90fd\u5c06\u88ab\u7f16\u8bd1\u51fa\u6765\u3002
\u5982\u679c\u6211\u4eec\u4f7f\u7528\u4e86I.MX6ULL\u65b0\u505a\u4e86\u4e00\u4e2a\u677f\u5b50\uff0c\u53ea\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u5bf9\u5e94\u7684.dts\u6587\u4ef6\uff0c\u5e76\u4e14\u5c06\u5bf9\u5e94\u7684.dtb\u6587\u4ef6\u6dfb\u52a0\u5230dtb-${CONFIG_SOC_IMX6ULL}\u4e0b\u3002
"},{"location":"linux/drivers/dts/#dts","title":"DTS\u57fa\u672c\u8bed\u6cd5","text":"\u8bbe\u5907\u6811\u7684\u6bcf\u4e2a\u8282\u70b9\u6309\u7167\u4ee5\u4e0b\u89c4\u5219\u547d\u540d\uff1a
label:node-name@unit-address{\n \u5c5e\u60271 = ...\n \u5c5e\u60272 = ...\n \u5c5e\u60273 = ...\n \u5b50\u8282\u70b9...\n}\n
device tree\u7684\u57fa\u672c\u5355\u5143\u662fnode\uff0c\u8fd9\u4e9bnode\u88ab\u7ec4\u7ec7\u6210\u6811\u72b6\u7ed3\u6784\u3002\u9664\u4e86root node\uff0c\u6bcf\u4e2anode\u90fd\u6709\u4e00\u4e2aparent node\u3002\u4e00\u4e2adevice tree\u6587\u4ef6\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2aroot node\u3002\u6bcf\u4e2anode\u4e2d\u90fd\u5305\u542b\u4e86property: value\u6765\u63cf\u8ff0\u8be5node\u7684\u4e00\u4e9b\u4fe1\u606f\u3002
label
\u7528\u6765\u6307\u5b9a\u6807\u7b7e\u540d\uff0c\u65b9\u4fbf\u5f15\u7528\u3002node-name
\u7528\u4e8e\u6307\u5b9a\u8282\u70b9\u7684\u540d\u79f0\uff0cunit-address
\u7528\u4e8e\u6307\u5b9a\u5730\u5740\uff0c\u5176\u503c\u8981\u4e0e\u8282\u70b9reg
\u5c5e\u6027\u7684\u7b2c\u4e00\u4e2a\u5730\u5740\u4e00\u81f4\u3002
\u5c5e\u6027\u503c\u6807\u8bc6\u4e86\u8bbe\u5907\u7684\u7279\u6027\uff0c\u5b83\u7684\u503c\u53ef\u4ee5\u662f\u4ee5\u4e0b\u51e0\u79cd\uff1a
\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e5f\u5c31\u662f\u6ca1\u6709\u503c\u7684\u5b9a\u4e49\u3002 \u53ef\u80fd\u662f\u4e00\u4e2au32\u3001u64\u7684\u6570\u503c\uff0c\u4e5f\u53ef\u4ee5\u662f\u6570\u7ec4\u3002 \u53ef\u80fd\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6216\u8005\u662fstring list\u3002 \u5728\u6839\u8282\u70b9\u4e0b\u6709\u4e24\u4e2a\u7279\u6b8a\u7684\u8282\u70b9\uff1aaliases
\u548cchosen
aliases\uff1a\u7528\u4e8e\u7ed9\u8282\u70b9\u5b9a\u4e49\u522b\u540d\uff0c\u65b9\u4fbf\u5bf9\u8282\u70b9\u7684\u5f15\u7528\u3002 chosen\uff1a\u865a\u62df\u8282\u70b9\uff0c\u53ef\u4ee5\u5728chosen\u4e2d\u8bbe\u7f6ebootargs\uff0c\u7531bootloader\u8bfb\u53d6\uff0c\u4f20\u9012\u7ed9\u5185\u6838\u4f5c\u4e3a\u542f\u52a8\u53c2\u6570\u3002 \u8fd8\u6709\u4e00\u4e2a\u6240\u6709\u8bbe\u5907\u6811\u6587\u4ef6\u5fc5\u987b\u8981\u6709\u7684\u8282\u70b9\u662fmemory device node
\uff0c\u5b83\u5b9a\u4e49\u4e86\u7cfb\u7edf\u7269\u7406\u5185\u5b58\u7684layout\u3002device_type
\u5c5e\u6027\u5b9a\u4e49\u4e86\u8be5node\u7684\u8bbe\u5907\u7c7b\u578b\uff0c\u4f8b\u5982cpu\u3001serial\u7b49\u3002\u5bf9\u4e8ememory node\uff0c\u5176device_type
\u5fc5\u987b\u7b49\u4e8ememory\u3002reg
\u5c5e\u6027\u5b9a\u4e49\u4e86\u8bbf\u95ee\u8be5device node\u7684\u5730\u5740\u4fe1\u606f\u2014\u2014\u8d77\u59cb\u5730\u5740\u548c\u957f\u5ea6\u3002
\u8282\u70b9\u7531\u4e00\u5806\u5c5e\u6027\u7ec4\u6210\uff0c\u8282\u70b9\u662f\u5177\u4f53\u7684\u8bbe\u5907\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u8bbe\u5907\u6709\u4e0d\u540c\u7684\u5c5e\u6027\uff0c\u4e0d\u8fc7\u6709\u4e00\u4e9b\u662f\u6807\u51c6\u5c5e\u6027\u3002
1.compatible
\u5c5e\u6027
compatible
\u5c5e\u6027\u7684\u503c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u7528\u4e8e\u5c06\u8bbe\u5907\u548c\u5bf9\u5e94\u7684\u9a71\u52a8\u7ed1\u5b9a\u8d77\u6765\u3002\u5b57\u7b26\u4e32\u5217\u8868\u7528\u4e8e\u8868\u793a\u8bbe\u5907\u6240\u8981\u4f7f\u7528\u7684\u9a71\u52a8\u7a0b\u5e8f\u3002compatible
\u5c5e\u6027\u662f\u7528\u6765\u67e5\u627e\u8282\u70b9\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4f8b\u5982\u7cfb\u7edf\u521d\u59cb\u5316platform\u603b\u7ebf\u4e0a\u7684\u8bbe\u5907\u65f6\uff0c\u6839\u636e\u8bbe\u5907\u8282\u70b9compatible
\u5c5e\u6027\u548c\u9a71\u52a8\u4e2dof_match_table
\u5bf9\u5e94\u7684\u503c\uff0c\u5339\u914d\u4e86\u5c31\u52a0\u8f7d\u5bf9\u5e94\u7684\u9a71\u52a8\u3002compatible
\u5c5e\u6027\u7684\u683c\u5f0f\u5982\u4e0b\uff1a
\"manufacturer, model\"\n
manufacturer\u8868\u793a\u5382\u5546\uff0cmodel\u8868\u793a\u5bf9\u5e94\u9a71\u52a8\u7684\u540d\u5b57\u3002\u800c\u6839\u8282\u70b9\u7684compatible
\u8868\u793a\u786c\u4ef6\u8bbe\u5907\u540d\uff0cSOC\u540d\u3002Linux\u5185\u6838\u4f1a\u901a\u8fc7\u6839\u8282\u70b9\u7684compatible
\u5c5e\u6027\u67e5\u770b\u662f\u5426\u652f\u6301\u6b64\u8bbe\u5907\uff0c\u5982\u679c\u652f\u6301\u8bbe\u5907\u5c31\u4f1a\u542f\u52a8\u5185\u6838\u3002
compatible
\u4e5f\u53ef\u4ee5\u6709\u591a\u4e2a\u5c5e\u6027\u503c\uff0c\u6309\u7167\u4f18\u5148\u7ea7\u67e5\u627e\u3002
2.model
\u5c5e\u6027
model
\u5c5e\u6027\u7528\u6765\u63cf\u8ff0\u8bbe\u5907\u7684\u751f\u4ea7\u5382\u5546\u548c\u578b\u53f7\u3002\u6bd4\u5982model=\"samsung, s3c24xx\"\u2014\u2014\u751f\u4ea7\u5382\u5546\u662f\u4e09\u661f\uff0cSOC\u662fs3c24xx\u3002
3.status
\u5c5e\u6027
status
\u5c5e\u6027\u7684\u503c\u4e0e\u8bbe\u5907\u72b6\u6001\u6709\u5173\uff0c\u901a\u8fc7\u8bbe\u7f6estatus
\u5c5e\u6027\u53ef\u4ee5\u7981\u7528\u6216\u8005\u542f\u7528\u8bbe\u5907\u3002
4.reg
\u5c5e\u6027
reg
\u5c5e\u6027\u7684\u503c\u4e00\u822c\u662f(address, length)\u5bf9\u3002\u7528\u4e8e\u63cf\u8ff0\u8bbe\u5907\u8d44\u6e90\u5728\u5176\u7236\u603b\u7ebf\u5b9a\u4e49\u7684\u5730\u5740\u7a7a\u95f4\u5185\u7684\u5730\u5740\u3002
reg = <0x4000e000 0x400> //\u8d77\u59cb\u5730\u5740+\u5927\u5c0f\n
5.#address-cells
\u548c#size-cells
\u5c5e\u6027
\u5982\u679c\u4e00\u4e2adevice node
\u7684sub node\u6709\u5bfb\u5740\u9700\u6c42\uff08\u5373\u9700\u8981\u5b9a\u4e49reg
\u5c5e\u6027\uff09\uff0c\u90a3\u4e48\u8fd9\u4e24\u4e2a\u5c5e\u6027\u5c31\u5fc5\u987b\u8981\u5b9a\u4e49\uff0c\u7528\u4e8e\u63cf\u8ff0sub node\u7684reg
\u5c5e\u6027\u7684\u4fe1\u606f\u3002
#address-cells: \u51b3\u5b9a\u4e86\u5b50\u8282\u70b9reg\u5c5e\u6027\u7684\u5730\u5740\u4fe1\u606f\u6240\u5360\u7528\u7684\u5b57\u957f\n#size-cells\uff1a\u51b3\u5b9a\u4e86\u5b50\u8282\u70b9reg\u5c5e\u6027\u4e2d\u957f\u5ea6\u4fe1\u606f\u6240\u5360\u7684\u5b57\u957f\n
6.ranges
\u5c5e\u6027
ranges
\u5c5e\u6027\u7684\u503c\u6309\u7167(child-bus-address, parent-bus-address, lenght)\u683c\u5f0f\u7f16\u5199\u3002ranges
\u5c5e\u6027\u7528\u6765\u6307\u5b9a\u67d0\u4e2a\u8bbe\u5907\u7684\u5730\u5740\u8303\u56f4\u6216\u8005IO\u8303\u56f4\uff0c\u8fd9\u662f\u5bf9\u8bbe\u5907\u8fdb\u884c\u5bfb\u5740\u7684\u91cd\u8981\u4fe1\u606f\u3002\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7ranges
\u5c5e\u6027\u83b7\u77e5\u54ea\u4e9b\u5185\u5b58\u533a\u57df\u6216\u8005IO\u7aef\u53e3\u662f\u88ab\u786c\u4ef6\u8bbe\u5907\u6240\u5360\u7528\u7684\u3002
child-bus-address\uff1a\u5b50\u603b\u7ebf\u5730\u5740\u7a7a\u95f4\u7684\u7269\u7406\u5730\u5740\uff0c\u7531\u7236\u8282\u70b9\u7684#address-cells\u786e\u5b9a\u6b64\u7269\u7406\u5730\u5740\u5360\u7528\u7684\u5b57\u957f parent-bus-address\uff1a\u7236\u603b\u7ebf\u5730\u5740\u7a7a\u95f4\u7684\u7269\u7406\u5730\u5740\uff0c\u540c\u6837\u7531\u7236\u8282\u70b9\u7684#address-cells\u786e\u5b9a\u6b64\u7269\u7406\u5730\u5740\u5360\u7528\u7684\u5b57\u957f length\uff1a\u5b50\u5730\u5740\u7a7a\u95f4\u7684\u957f\u5ea6\uff0c\u7531\u7236\u8282\u70b9\u7684#size-cells\u786e\u5b9a\u6b64\u5730\u5740\u957f\u5ea6\u5360\u7528\u7684\u5b57\u957f \u5982\u679cranges
\u5c5e\u6027\u4e3a\u7a7a\uff0c\u5219\u8bf4\u660e\u5b50\u5730\u5740\u7a7a\u95f4\u548c\u7236\u5730\u5740\u7a7a\u95f4\u76f8\u540c\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u8f6c\u6362\u3002
Arm\u4f53\u7cfb\u6b64\u5c5e\u6027\u8bbe\u7f6e\u4e3a\u7a7a\u3002
7.intc
\u5c5e\u6027
\u7528\u4e8e\u8868\u793a\u4e2d\u65ad\u63a7\u5236\u5668\u7684\u76f8\u5173\u4fe1\u606f\u3002
interrupt-controller\uff1a interrupt-cells\uff1a interrupt-parent\uff1a interrupts\uff1a \u6839\u8282\u70b9\u5fc5\u987b\u8981\u6709\u7684\u5c5e\u6027\u6709\uff1a
#address-cells:\u5b50\u8282\u70b9reg\u5c5e\u6027\u4e2d\uff0c\u7528\u591a\u5c11\u4e2au32\u6574\u6570\u6765\u63cf\u8ff0\u5730\u5740\n#size-cells\uff1a\u5b50\u8282\u70b9reg\u5c5e\u6027\u4e2d\uff0c\u7528\u591a\u5c11\u4e2au32\u6574\u6570\u6765\u63cf\u8ff0\u5927\u5c0f\ncompatible\uff1a\u6307\u5b9a\u677f\u5b50\u517c\u5bb9\u7684\u5e73\u53f0\nmodel\uff1a\u677f\u5b50\u540d\u79f0\n
"},{"location":"linux/drivers/dts/#_3","title":"\u5185\u6838\u64cd\u4f5c\u8bbe\u5907\u6811","text":"\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\u6765\u64cd\u4f5c\u8bbe\u5907\u6811\u4e2d\u7684\u8282\u70b9\u548c\u5c5e\u6027\u4fe1\u606f\uff0c\u8fd9\u4e9b\u51fd\u6570\u7edf\u4e00\u4ee5of
\u5f00\u5934\u3002
\u8282\u70b9\u64cd\u4f5c\u51fd\u6570
\u5185\u6838\u4f7f\u7528device_node
\u7ed3\u6784\u4f53\u6765\u63cf\u8ff0\u4e00\u4e2a\u8282\u70b9
struct device_node{\n const char *name; //\u8bbe\u5907\u540d\u79f0\n const char *type; //\u8bbe\u5907\u7c7b\u578b\n cont char *full_name; //\u8bbe\u5907\u7684\u5b8c\u6574\u540d\u79f0\n ...\n struct device_node *parent; //\u7236\u8282\u70b9\u6307\u9488\n struct device_node *child; //\u5b50\u8282\u70b9\u6307\u9488\n struct device_node *sibling; //\u540c\u7ea7\u8282\u70b9\u6307\u9488\n struct kobject kobj; //kobject\u7ed3\u6784\u4f53\u662f\u5185\u6838\u5bf9\u8c61\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u8ddf\u8e2a\u6b64\u8282\u70b9\n unsigned long _flags; //\u8868\u793a\u8282\u70b9\u7684\u5c5e\u6027\n void *data; //\u6307\u5411\u4efb\u610f\u6570\u636e\u7684\u6307\u9488\n};\n
\u4e0e\u67e5\u627e\u8282\u70b9\u76f8\u5173\u7684of
\u51fd\u6570\u67095\u4e2a\uff1a 1.\u901a\u8fc7\u8282\u70b9\u540d\u5b57\u67e5\u627e\u6307\u5b9a\u8282\u70b9
struct device_node *of_find_node_by_name(struct device_node *from, const char *name);\n
from\uff1a\u5f00\u59cb\u67e5\u627e\u7684\u8282\u70b9\uff0cNULL\u5219\u8868\u793a\u4ece\u6839\u8282\u70b9\u5f00\u59cb\u67e5\u627e name\uff1a\u8981\u67e5\u627e\u7684\u8282\u70b9\u540d \u8fd4\u56de\u503c\uff1a\u627e\u5230\u7684\u8282\u70b9\uff0cNULL\u8868\u793a\u5931\u8d25 2.\u901a\u8fc7device_type
\u5c5e\u6027\u67e5\u627e\u6307\u5b9a\u8282\u70b9\uff08X\uff09
struct device_node *of_find_node_by_type(struct device_node *from, const char *type)\n
type\uff1a\u8981\u67e5\u627e\u7684\u8282\u70b9\u7684device_type\u5c5e\u6027\u503c \u7531\u4e8edevice_type
\u5df2\u7ecf\u88ab\u5e9f\u5f03\uff0c\u6240\u4ee5\u8fd9\u4e2a\u51fd\u6570\u5df2\u7ecf\u4e0d\u7528\u4e86\u3002
3.\u901a\u8fc7device_type
\u548ccompatible
\u4e24\u4e2a\u5c5e\u6027\u6765\u67e5\u627e\u6307\u5b9a\u8282\u70b9
struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compatible)\n
4.\u901a\u8fc7of_device_id
\u5339\u914d\u8868\u6765\u67e5\u627e\u6307\u5b9a\u8282\u70b9
struct device_node *of_find_matching_node_and_match(struct device_node *from, const struct of_device_id *matches, const struct of_device_id **match)\n
5.\u901a\u8fc7\u8def\u5f84\u6765\u67e5\u627e\u6307\u5b9a\u8282\u70b9
inline struct device_node *of_find_node_by_path(const char *path)\n
path\uff1a\u5e26\u6709\u5168\u8def\u5f84\u7684\u8282\u70b9\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\u8282\u70b9\u7684\u522b\u540d \u63a8\u8350\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u6765\u67e5\u627e\u8282\u70b9\u3002
\u8282\u70b9\u7684\u5c5e\u6027\u4fe1\u606f\u91cc\u4fdd\u5b58\u4e86\u9a71\u52a8\u6240\u9700\u8981\u7684\u5185\u5bb9\uff0c\u5185\u6838\u4e2d\u4f7f\u7528\u7ed3\u6784\u4f53property
\u8868\u793a\u5c5e\u6027\u3002
struct property{\n char *name; //\u5c5e\u6027\u540d\n int length; //\u5c5e\u6027\u503c\u7684\u957f\u5ea6\n void *value; //\u6307\u5411\u5c5e\u6027\u503c\u7684\u6307\u9488\n struct property *next; //\u6307\u5411\u4e0b\u4e00\u4e2a\u5c5e\u6027\u7684\u6307\u9488\n unsigned long _flags; //\u8868\u793a\u5c5e\u6027\u7684\u7c7b\u522b\n unsigned int unique_id; //\u6807\u8bc6\u8bbe\u5907\u7684\u552f\u4e00\u5c5e\u6027\n struct bin_attribute attr; //\u8868\u793a\u5c5e\u6027\u7684\u4e00\u4e9b\u5143\u6570\u636e\n};\n
\u5185\u6838\u63d0\u4f9b\u4e86\u67e5\u627e\u7236\u5b50\u8282\u70b9\u7684of
\u51fd\u6570\u3002
struct device_node *of_get_parent(const struct device_node *node)\n\nstruct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev)\n
\u540c\u65f6\u5185\u6838\u4e5f\u63d0\u4f9b\u4e86\u63d0\u53d6\u5c5e\u6027\u503c\u7684of
\u51fd\u6570\u3002
1.\u67e5\u627e\u6307\u5b9a\u7684\u5c5e\u6027
property *of_find_property(const struct device_node *np, const char *name, int *lenp)\n
np\uff1a\u8bbe\u5907\u8282\u70b9 name\uff1a\u5c5e\u6027\u540d\u5b57 lenp\uff1a\u5c5e\u6027\u503c\u7684\u5b57\u8282\u6570 2.\u83b7\u53d6\u5c5e\u6027\u4e2d\u5143\u7d20\u7684\u6570\u91cf
int of_property_count_elems_of_size(const struct device_node *np, const char *propname, int elem_size)\n
3.\u4ece\u5c5e\u6027\u4e2d\u83b7\u53d6\u6307\u5b9a\u6807\u53f7\u7684u32\u7c7b\u578b\u6570\u636e
int of_property_read_u32_index(const struct device_node *np, const char *propname, u32 index, u32 *out_value)\n
propname\uff1a\u8981\u8bfb\u53d6\u7684\u5c5e\u6027\u540d index\uff1a\u8981\u8bfb\u53d6\u7684\u503c\u6807\u53f7 out_value\uff1a\u8bfb\u53d6\u5230\u7684\u503c 4.\u8bfb\u53d6u8\u3001u16\u3001u32\u3001u64\u7c7b\u578b\u7684\u6570\u7ec4\u6570\u636e
int of_property_read_u8_array(const struct device_node *np, const char *propname, u8 *out_values, size_t sz)\n
\u5c06\u51fd\u6570\u540d\u4e2d\u7684u8\u66ff\u6362\u6210\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u5373\u53ef\u3002
5.\u8bfb\u53d6u8\u3001u16\u3001u32\u3001u64\u7c7b\u578b\u5c5e\u6027\u503c
int of_property_read_u8(const struct device_node *np, const char *propname, u8 *out_value)\n
6.\u8bfb\u53d6\u5c5e\u6027\u4e2d\u5b57\u7b26\u4e32\u7684\u503c
int of_property_read_string(struct device_node *np, const char *propname, const char **out_string)\n
\u8fd9\u4e2a\u51fd\u6570\u4f7f\u7528\u6bd4\u8f83\u7e41\u7410\uff0c\u5efa\u8bae\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\uff1a
int of_property_read_string_index(const struct device_node *np,const char *propname, int index,const char **out_string)\n
\u76f8\u6bd4\u524d\u9762\u7684\u51fd\u6570\u589e\u52a0\u4e86\u53c2\u6570index\uff0c\u5b83\u7528\u4e8e\u6307\u5b9a\u8bfb\u53d6\u5c5e\u6027\u503c\u4e2d\u7b2c\u51e0\u4e2a\u5b57\u7b26\u4e32\uff0cindex\u4ece\u96f6\u5f00\u59cb\u8ba1\u6570\u3002 \u7b2c\u4e00\u4e2a\u51fd\u6570\u53ea\u80fd\u5f97\u5230\u5c5e\u6027\u503c\u6240\u5728\u5730\u5740\uff0c\u4e5f\u5c31\u662f\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5730\u5740\uff0c\u5176\u4ed6\u5b57\u7b26\u4e32\u9700\u8981\u6211\u4eec\u624b\u52a8\u4fee\u6539\u79fb\u52a8\u5730\u5740\uff0c\u975e\u5e38\u9ebb\u70e6\uff0c\u63a8\u8350\u4f7f\u7528\u7b2c\u4e8c\u4e2a\u51fd\u6570\u3002
\u73b0\u5728\u5185\u6838\u63d0\u4f9b\u4e86\u5185\u5b58\u6620\u5c04\u76f8\u5173\u7684of
\u51fd\u6570\uff0c\u53ef\u4ee5\u81ea\u52a8\u5b8c\u6210\u7269\u7406\u5730\u5740\u5230\u865a\u62df\u5730\u5740\u7684\u8f6c\u6362\uff1a
void __iomem *of_iomap(struct device_node *np, int index)\n
"},{"location":"linux/drivers/framework/","title":"\u9a71\u52a8\u6846\u67b6","text":"\u9a71\u52a8\u6846\u67b6\u4e0b\u5404\u7c7b\u5b50\u7cfb\u7edf\u7684\u4ecb\u7ecd\uff0c\u9700\u8981\u6709\u8bbe\u5907\u6811\u7684\u77e5\u8bc6\u3002
"},{"location":"linux/drivers/framework/#pinctrl","title":"Pinctrl\u5b50\u7cfb\u7edf","text":"\u901a\u8fc7\u5bc4\u5b58\u5668\u6620\u5c04\u6765\u64cd\u4f5c\u5916\u8bbe\u7684\u7f16\u7a0b\u65b9\u5f0f\uff0c\u5728\u9a71\u52a8\u5f00\u53d1\u4e2d\u662f\u4e0d\u5efa\u8bae\u7684\uff0c\u56e0\u4e3a\u6bcf\u5f53\u82af\u7247\u7684\u5bc4\u5b58\u5668\u53d1\u751f\u53d8\u5316\uff0c\u90a3\u4e48\u5e95\u5c42\u7684\u9a71\u52a8\u4ee3\u7801\u5c31\u5f97\u63a8\u7ffb\u91cd\u5199\u3002\u5728\u9a71\u52a8\u5f00\u53d1\u4e2d\uff0c\u6709\u6ca1\u6709\u529e\u6cd5\u53ef\u4ee5\u4e0d\u6d89\u53ca\u5230\u5177\u4f53\u7684\u5bc4\u5b58\u5668\u64cd\u4f5c\u5462\uff1f\u5bf9\u4e8e\u6709\u4e9b\u5916\u8bbe\uff0c\u662f\u5177\u5907\u62bd\u8c61\u6761\u4ef6\u7684\uff0cPintrl\u5b50\u7cfb\u7edf\u5c31\u662f\u5176\u4e2d\u4e4b\u4e00\u3002
Pinctrl\uff1aPin Controller\uff0c\u5f15\u811a\u63a7\u5236\uff1a
\u5f15\u811a\u679a\u4e3e\u4e0e\u547d\u540d \u5f15\u811a\u590d\u7528\uff1a\u4e00\u4e2a\u5f15\u811a\u53ef\u4ee5\u7528\u4f5cGPIO\uff0c\u4e5f\u53ef\u4ee5\u7528\u4f5cI2C\u6216UART \u5f15\u811a\u914d\u7f6e\uff1a\u6bd4\u5982\u4e0a\u62c9\u3001\u4e0b\u62c9 Pinctrl\u9a71\u52a8\u7531\u82af\u7247\u5382\u5bb6BSP\u5de5\u7a0b\u5e08\u63d0\u4f9b\uff0c\u4e00\u822c\u7684\u9a71\u52a8\u5de5\u7a0b\u5e08\u53ea\u9700\u8981\u5728\u8bbe\u5907\u6811\u91cc\u63cf\u8ff0\u5373\u53ef\uff1a
\u6307\u660e\u4f7f\u7528\u54ea\u4e9b\u5f15\u811a \u590d\u7528\u4e3a\u4ec0\u4e48\u529f\u80fd \u914d\u7f6e\u4e3a\u4ec0\u4e48\u72b6\u6001 "},{"location":"linux/drivers/framework/#pinctrl_1","title":"Pinctrl\u4e3b\u8981\u6570\u636e\u7ed3\u6784","text":"pinctrl\u53ef\u4ee5\u7528\u4e00\u4e2a\u7ed3\u6784\u4f53\u6765\u8868\u793a\u5b83\uff1apinctrl_dev
\u3002\u800cpinctrl_dev
\u53ef\u4ee5\u7528pinctrl_desc
\u7ed3\u6784\u4f53\u63cf\u8ff0\uff0c\u7136\u540e\u8c03\u7528pinctrl_register()
\u51fd\u6570\u6765\u6ce8\u518c\u5b83\uff0c\u5176\u8fd4\u56de\u503c\u5c31\u662f\u4e00\u4e2apinctrl_dev
\u7684\u7ed3\u6784\u4f53\uff1a
struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, struct device *dev, void *driver_data);\n
pinctrl_desc:
struct pinctrl_pin_desc {\n unsigned number;\n const char *name;\n void *drv_data;\n};\n
pinctrl_ops\uff1a
struct pinctrl_ops {\n int (*get_groups_count) (struct pinctrl_dev *pctldev);\n const char *(*get_group_name) (struct pinctrl_dev *pctldev,\n unsigned selector);\n int (*get_group_pins) (struct pinctrl_dev *pctldev,\n unsigned selector,\n const unsigned **pins,\n unsigned *num_pins);\n void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,\n unsigned offset);\n int (*dt_node_to_map) (struct pinctrl_dev *pctldev,\n struct device_node *np_config,\n struct pinctrl_map **map, unsigned *num_maps);\n void (*dt_free_map) (struct pinctrl_dev *pctldev,\n struct pinctrl_map *map, unsigned num_maps);\n};\n
pinmux_pos\uff1a
struct pinmux_ops {\n int (*request) (struct pinctrl_dev *pctldev, unsigned offset);\n int (*free) (struct pinctrl_dev *pctldev, unsigned offset);\n int (*get_functions_count) (struct pinctrl_dev *pctldev);\n const char *(*get_function_name) (struct pinctrl_dev *pctldev,\n unsigned selector);\n int (*get_function_groups) (struct pinctrl_dev *pctldev,\n unsigned selector,\n const char * const **groups,\n unsigned *num_groups);\n int (*set_mux) (struct pinctrl_dev *pctldev, unsigned func_selector,\n unsigned group_selector);\n int (*gpio_request_enable) (struct pinctrl_dev *pctldev,\n struct pinctrl_gpio_range *range,\n unsigned offset);\n void (*gpio_disable_free) (struct pinctrl_dev *pctldev,\n struct pinctrl_gpio_range *range,\n unsigned offset);\n int (*gpio_set_direction) (struct pinctrl_dev *pctldev,\n struct pinctrl_gpio_range *range,\n unsigned offset,\n bool input);\n bool strict;\n};\n
pinconf_ops\uff1a
struct pinconf_ops {\n#ifdef CONFIG_GENERIC_PINCONF\n bool is_generic;\n#endif\n int (*pin_config_get) (struct pinctrl_dev *pctldev,\n unsigned pin,\n unsigned long *config);\n int (*pin_config_set) (struct pinctrl_dev *pctldev,\n unsigned pin,\n unsigned long *configs,\n unsigned num_configs);\n int (*pin_config_group_get) (struct pinctrl_dev *pctldev,\n unsigned selector,\n unsigned long *config);\n int (*pin_config_group_set) (struct pinctrl_dev *pctldev,\n unsigned selector,\n unsigned long *configs,\n unsigned num_configs);\n void (*pin_config_dbg_show) (struct pinctrl_dev *pctldev,\n struct seq_file *s,\n unsigned offset);\n void (*pin_config_group_dbg_show) (struct pinctrl_dev *pctldev,\n struct seq_file *s,\n unsigned selector);\n void (*pin_config_config_dbg_show) (struct pinctrl_dev *pctldev,\n struct seq_file *s,\n unsigned long config);\n};\n
"},{"location":"linux/kernel/","title":"\u5185\u6838\u57fa\u7840\u77e5\u8bc6","text":""},{"location":"linux/kernel/#_2","title":"\u5185\u6838\u6e90\u7801","text":"\u8981\u83b7\u53d6\u5185\u6838\u6e90\u7801\uff0c\u8bf7\u4f7f\u7528git
\u3002
git clone git://git.ernel.org/pub/scm/linux/kernel/git/torvalds/[linux\u7248\u672c\u53f7].git\n
\u5185\u6838\u6e90\u7801\u6811\u7531\u8bb8\u591a\u76ee\u5f55\u7ec4\u6210\uff0c\u4e00\u4e9b\u6bd4\u8f83\u91cd\u8981\u7684\u76ee\u5f55\u7684\u63cf\u8ff0\u5982\u4e0b\uff1a
\u76ee\u5f55\u540d \u63cf\u8ff0 arch \u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u4ee3\u7801 block \u5757\u8bbe\u5907I/O\u5c42 drivers \u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f fs \u6587\u4ef6\u7cfb\u7edf include \u5185\u6838\u5934\u6587\u4ef6 init \u521d\u59cb\u5316\u4ee3\u7801 ipc \u8fdb\u7a0b\u95f4\u901a\u4fe1\u4ee3\u7801 kernel \u5185\u6838\u6838\u5fc3\u4ee3\u7801 lib \u5185\u6838\u5e93\u51fd\u6570 mm \u5185\u5b58\u7ba1\u7406 net \u7f51\u7edc\u7cfb\u7edf \u8981\u7f16\u8bd1\u5185\u6838\uff0c\u8bf7\u4f7f\u7528make menuconfig\u3002\u5185\u6838\u7684\u5404\u79cd\u914d\u7f6e\uff0c\u4ee5CONFIG_FEATURE\u7684\u5f62\u5f0f\u5199\u5165.config\u6587\u4ef6\u3002\u914d\u7f6e\u9009\u9879\u6709\u4e09\u79cd\uff1ayes\u3001no\u6216module\u3002\u5206\u522b\u5bf9\u5e94\u7f16\u8bd1\u3001\u4e0d\u7f16\u8bd1\u3001\u4ee5\u6a21\u5757\u5f62\u5f0f\u7f16\u8bd1\u3002
\u5185\u6838\u5f00\u53d1\u7684\u7279\u70b9\u5982\u4e0b\uff1a
\u4e0d\u80fd\u4f7f\u7528\u6807\u51c6C\u5e93\u5934\u6587\u4ef6\uff0c\u53ea\u80fd\u4f7f\u7528\u5185\u6838\u63d0\u4f9b\u7684\u5934\u6587\u4ef6\u3002\u4e0e\u4f53\u7cfb\u7ed3\u6784\u65e0\u5173\u7684\u5934\u6587\u4ef6\u4f4d\u4e8e\u5185\u6838\u6e90\u7801\u6839\u76ee\u5f55\u4e0b\u7684include\u76ee\u5f55\u3002\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u5934\u6587\u4ef6\u4f4d\u4e8e<arch/architecture/include/asm>\u76ee\u5f55\uff0c\u5185\u6838\u4ee3\u7801\u4ee5asm\u524d\u7f00\u7684\u5f62\u5f0f\u5305\u542b\u8fd9\u4e9b\u5934\u6587\u4ef6\u3002
\u5fc5\u987b\u4f7f\u7528GNU C\u3002gcc\u7f16\u8bd1\u5668\u652f\u6301\u4ee5asm()\u6307\u4ee4\u5f00\u5934\u5d4c\u5165\u6c47\u7f16\u4ee3\u7801\u3002
\u6ca1\u6709\u5185\u5b58\u4fdd\u62a4\u673a\u5236\u3002\u5982\u679c\u662f\u5185\u6838\u8bbf\u95ee\u4e86\u975e\u6cd5\u5185\u5b58\uff0c\u540e\u679c\u4e0d\u582a\u8bbe\u60f3\u3002
\u65e0\u6cd5\u6267\u884c\u6d6e\u70b9\u8fd0\u7b97\u3002\u5185\u6838\u5bf9\u4e8e\u6d6e\u70b9\u8fd0\u7b97\u7684\u652f\u6301\u5ea6\u4e0d\u591f\u3002
\u5fc5\u987b\u8003\u8651\u540c\u6b65\u4e0e\u5e76\u53d1\u3002Linux\u5185\u6838\u662f\u62a2\u5360\u5f0f\u591a\u4efb\u52a1\u5904\u7406\u7cfb\u7edf\uff0c\u5f53\u524d\u4efb\u52a1\u968f\u65f6\u6709\u53ef\u80fd\u88ab\u53e6\u4e00\u4e2a\u4efb\u52a1\u62a2\u5360\u3002
\u5fc5\u987b\u8003\u8651\u53ef\u79fb\u690d\u6027\u3002\u6bd4\u5982\u4fdd\u6301\u5b57\u8282\u5e8f\u300164 \u4f4d\u5bf9\u9f50\u3001\u4e0d\u5047\u5b9a\u5b57\u957f\u548c\u9875\u9762\u957f\u5ea6\u7b49\u4e00\u7cfb\u5217\u51c6\u5219\u3002
"},{"location":"linux/kernel/interrupt/","title":"\u4e2d\u65ad\u548c\u4e2d\u65ad\u5904\u7406","text":"\u4e2d\u65ad\u662f\u4e00\u79cd\u4e8b\u4ef6\uff0c\u8be5\u4e8b\u4ef6\u6539\u53d8\u5904\u7406\u5668\u6267\u884c\u6307\u4ee4\u7684\u987a\u5e8f\u3002\u8fd9\u79cd\u65b9\u5f0f\u6709\u540c\u6b65\u548c\u5f02\u6b65\u4e4b\u5206\u3002\u540c\u6b65\u4e2d\u65ad\u4e5f\u88ab\u79f0\u4e3a\u5f02\u5e38\u3002\u5728\u5904\u7406\u5668\u6267\u884c\u5230\u7531\u4e8e\u7f16\u7a0b\u5931\u8bef\u800c\u5bfc\u81f4\u7684\u9519\u8bef\u6307\u4ee4\uff08\u6bd4\u5982\u9664\u4ee50\uff09\u7684\u65f6\u5019\uff0c\u6216\u8005\u662f\u5728\u6267\u884c\u671f\u95f4\u51fa\u73b0\u7279\u6b8a\u60c5\u51b5\uff08\u6bd4\u5982\u7f3a\u9875\uff09\uff0c\u5fc5\u987b\u9760\u5185\u6838\u5904\u7406\u7684\u65f6\u5019\uff0c\u5904\u7406\u5668\u5c31\u4f1a\u4ea7\u751f\u4e00\u4e2a\u5f02\u5e38\u3002\u5f02\u6b65\u4e2d\u65ad\u5219\u662f\u7531\u786c\u4ef6\u5f15\u8d77\u7684\u3002
\u4e2d\u65ad\u53c8\u53ef\u4ee5\u5206\u4e3a\u53ef\u5c4f\u853d\u4e2d\u65ad\u548c\u4e0d\u53ef\u5c4f\u853d\u4e2d\u65ad\u3002\u901a\u5e38\uff0cI/O\u8bbe\u5907\u53d1\u51fa\u7684\u6240\u6709\u4e2d\u65ad\u8bf7\u6c42\u90fd\u662f\u53ef\u5c4f\u853d\u7684\uff0c\u800c\u90e8\u5206\u5371\u6025\u4e8b\u4ef6\uff08\u6bd4\u5982\u786c\u4ef6\u6545\u969c\uff09\u662f\u4e0d\u53ef\u5c4f\u853d\u7684\u3002\u6bcf\u4e2a\u4e2d\u65ad\u548c\u5f02\u5e38\u90fd\u662f\u75310 ~ 255\u4e4b\u95f4\u7684\u4e00\u4e2a\u6570\u6765\u6807\u8bc6\uff0c\u8fd9\u4e2a\u6570\u88ab\u79f0\u4f5c\u4e3a\u662f\u5411\u91cf\uff08vector\uff09\u3002\u4e0d\u53ef\u5c4f\u853d\u4e2d\u65ad\u7684\u5411\u91cf\u662f\u56fa\u5b9a\u7684\uff0c\u800c\u53ef\u5c4f\u853d\u4e2d\u65ad\u7684\u5411\u91cf\u53ef\u4ee5\u901a\u8fc7\u5bf9\u4e2d\u65ad\u63a7\u5236\u5668\u7684\u7f16\u7a0b\u6765\u6539\u53d8\u3002
\u663e\u7136\uff0c\u4e2d\u65ad\u4fe1\u53f7\u63d0\u4f9b\u4e86\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u5f0f\uff0c\u8ba9\u5904\u7406\u5668\u53bb\u6267\u884c\u6b63\u5e38\u8fd0\u884c\u4ee3\u7801\u4e4b\u5916\u7684\u903b\u8f91\u3002\u5f53\u4e00\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u5230\u6765\u65f6\uff0cCPU\u5fc5\u987b\u505c\u4e0b\u5b83\u5f53\u524d\u6b63\u5728\u505a\u7684\u4e8b\u60c5\uff0c\u8f6c\u800c\u53bb\u5904\u7406\u4e2d\u65ad\u4ee3\u7801\u3002\u4e3a\u4e86\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u5c31\u9700\u8981\u5728\u5185\u6838\u6001\u5806\u6808\u4fdd\u5b58\u5f53\u524d\u4e0a\u4e0b\u6587\u73af\u5883\uff0c\u5e76\u4e14\u628a\u89e6\u53d1\u4e86\u4f55\u79cd\u4e2d\u65ad\u4e5f\u653e\u8fdb\u5bc4\u5b58\u5668\u4e2d\u3002
\u4f60\u53ef\u80fd\u4f1a\u628a\u4e2d\u65ad\u5904\u7406\u4e0e\u8fdb\u7a0b\u5207\u6362\u8054\u7cfb\u8d77\u6765\u3002\u786e\u5b9e\u8fd9\u4e24\u8005\u6709\u90e8\u5206\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u662f\u4e2d\u65ad\u6267\u884c\u7684\u4ee3\u7801\u4e0d\u662f\u8fdb\u7a0b\u73af\u5883\u3002\u5b83\u662f\u4e00\u4e2a\u5185\u6838\u63a7\u5236\u7684\u7279\u6b8a\u8def\u5f84\uff0c\u5fc5\u987b\u5feb\u901f\u5904\u7406\uff0c\u4e0d\u80fd\u505c\u7559\u3002\u7531\u4e8e\u4e2d\u65ad\u5904\u7406\u662f\u5185\u6838\u6700\u4e3a\u654f\u611f\u7684\u4efb\u52a1\u4e4b\u4e00\uff0c\u4e3a\u4e86\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\uff0c\u5b83\u5fc5\u987b\u6709\u4ee5\u4e0b\u7ea6\u675f\uff1a
\u4e2d\u65ad\u5fc5\u987b\u5c3d\u53ef\u80fd\u5feb\u5730\u5904\u7406\u3002\u4e3a\u6b64\uff0c\u4e2d\u65ad\u5904\u7406\u901a\u5e38\u5206\u4e3a\u4e24\u90e8\u5206\uff1a\u5173\u952e\u800c\u7d27\u6025\u7684\u90e8\u5206\uff0c\u5185\u6838\u7acb\u5373\u6267\u884c\uff1b\u5176\u4f59\u90e8\u5206\u63a8\u8fdf\u6267\u884c\u3002
\u4e2d\u65ad\u5fc5\u987b\u53ef\u4ee5\u5d4c\u5957\u6267\u884c\u3002\u7531\u4e8e\u4e2d\u65ad\u968f\u65f6\u4f1a\u5230\u6765\uff0c\u5728\u5185\u6838\u5904\u7406\u5176\u4e2d\u4e00\u4e2a\u4e2d\u65ad\u65f6\uff0c\u53e6\u4e00\u4e2a\u4e2d\u65ad\u4e5f\u4f1a\u53d1\u751f\u3002\u5f53\u4e2d\u65ad\u5904\u7406\u5b8c\u6210\u540e\uff0c\u5185\u6838\u5fc5\u987b\u80fd\u6062\u590d\u88ab\u4e2d\u65ad\u8fdb\u7a0b\u7684\u6267\u884c\u3002
\u5728\u4e34\u754c\u533a\u4e2d\uff0c\u4e2d\u65ad\u5fc5\u987b\u88ab\u7981\u6b62\u3002
"},{"location":"linux/kernel/interrupt/#_2","title":"\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f","text":"\u5728\u54cd\u5e94\u4e00\u4e2a\u7279\u5b9a\u7684\u4e2d\u65ad\u65f6\uff0c\u5185\u6838\u4f1a\u6267\u884c\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u53eb\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff08interrupt handler\uff09\u6216\u4e2d\u65ad\u670d\u52a1\u4f8b\u7a0b\uff08interrupt service routine, ISR\uff09\u3002\u4ea7\u751f\u4e2d\u65ad\u7684\u6bcf\u4e2a\u8bbe\u5907\u90fd\u6709\u4e00\u4e2a\u54cd\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u4e00\u4e2a\u8bbe\u5907\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u662f\u5b83\u9a71\u52a8\u7a0b\u5e8f\u7684\u4e00\u90e8\u5206\u3002
\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5904\u4e8e\u7279\u6b8a\u7684\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e2d\u3002\u5728\u89e3\u91ca\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u56de\u5fc6\u4e00\u4e0b\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u3002\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u65f6\u4e00\u79cd\u5185\u6838\u6240\u5904\u7684\u64cd\u4f5c\u6a21\u5f0f\uff0c\u6b64\u65f6\u8fdb\u7a0b\u4ee3\u8868\u8fdb\u7a0b\u6267\u884c\u3002\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528current
\u5b8f\u5173\u8054\u5f53\u524d\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u7761\u7720\uff0c\u4e5f\u53ef\u4ee5\u8c03\u7528\u8c03\u5ea6\u7a0b\u5e8f\u3002\u4e0e\u4e4b\u76f8\u53cd\uff0c\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e0e\u8fdb\u7a0b\u6ca1\u6709\u4ec0\u4e48\u5173\u8054\u3002\u56e0\u4e3a\u4e2d\u65ad\u7684\u89e6\u53d1\u662f\u968f\u65f6\u5230\u6765\u7684\uff0c\u5e76\u4e0d\u77e5\u9053\u5f53\u524d\u5904\u4e8e\u54ea\u4e2a\u8fdb\u7a0b\u3002\u56e0\u4e3a\u6ca1\u6709\u540e\u5907\u8fdb\u7a0b\uff0c\u6240\u4ee5\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e0d\u53ef\u7761\u7720\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u4efb\u4f55\u53ef\u4ee5\u5f15\u8d77\u7761\u7720\u7684\u51fd\u6570\u3002\u4e2d\u65ad\u4e0a\u4e0b\u6587\u7684\u4ee3\u7801\u5fc5\u987b\u5feb\u901f\u4e14\u7b80\u6d01\u3002
\u4e2d\u65ad\u968f\u65f6\u6709\u53ef\u80fd\u53d1\u751f\uff0c\u56e0\u6b64\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5fc5\u987b\u5feb\u901f\u6267\u884c\u3002\u4f46\u662f\uff0c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5f80\u5f80\u8fd8\u8981\u5b8c\u6210\u5927\u91cf\u5176\u4ed6\u7684\u5de5\u4f5c\u3002\u6bd4\u5982\u4e00\u4e2a\u7f51\u7edc\u8bbe\u5907\uff0c\u9664\u4e86\u5bf9\u786c\u4ef6\u5e94\u7b54\u4e4b\u5916\uff0c\u8fd8\u9700\u8981\u628a\u6765\u81ea\u786c\u4ef6\u7684\u7f51\u7edc\u6570\u636e\u62f7\u8d1d\u5230\u5185\u5b58\u3002\u663e\u7136\u8fd9\u79cd\u5de5\u4f5c\u91cf\u4e0d\u4f1a\u5c0f\u3002
\u53c8\u60f3\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u5f97\u5feb\uff0c\u53c8\u8981\u5176\u5b8c\u6210\u7684\u5de5\u4f5c\u591a\u3002\u9274\u4e8e\u8fd9\u4e24\u8005\u4e4b\u95f4\u7684\u77db\u76fe\u5173\u7cfb\uff0c\u6211\u4eec\u4e00\u822c\u628a\u4e2d\u65ad\u5904\u7406\u7684\u8fc7\u7a0b\u5207\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\uff1a\u4e0a\u534a\u90e8\u548c\u4e0b\u534a\u90e8\u3002\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u662f\u4e0a\u534a\u90e8\u2014\u2014\u5f53\u63a5\u6536\u5230\u4e00\u4e2a\u4e2d\u65ad\u540e\uff0c\u5b83\u7acb\u523b\u88ab\u6267\u884c\uff0c\u4f46\u53ea\u505a\u6709\u4e25\u683c\u65f6\u9650\u7684\u5de5\u4f5c\u3002\u4f8b\u5982\u5bf9\u63a5\u6536\u5230\u7684\u4e2d\u65ad\u8fdb\u884c\u5e94\u7b54\u3002\u800c\u7a0d\u540e\u9700\u8981\u5b8c\u6210\u7684\u5de5\u4f5c\u5219\u4f1a\u88ab\u63a8\u8fdf\u5230\u4e0b\u534a\u90e8\u53bb\uff0c\u5728\u5408\u9002\u7684\u65f6\u673a\u6267\u884c\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u591a\u79cd\u4e0b\u534a\u90e8\u7684\u673a\u5236\uff0c\u7a0d\u540e\u4f1a\u505a\u8bf4\u660e\u3002
\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7request_irq()
\u51fd\u6570\u6ce8\u518c\u4e00\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u4e14\u6fc0\u6d3b\u7ed9\u5b9a\u7684\u4e2d\u65ad\u7ebf\uff1a
int request_irq(unsigned int irq,\n irq_handler_t handler,\n unsigned long flags,\n const char *name,\n void *dev)\n
\u7b2c\u4e00\u4e2a\u53c2\u6570irq\u8868\u793a\u8981\u5206\u914d\u7684\u4e2d\u65ad\u53f7\u3002 \u7b2c\u4e8c\u4e2a\u53c2\u6570handler\u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u6307\u5411\u5904\u7406\u8fd9\u4e2a\u4e2d\u65ad\u7684\u5b9e\u9645\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002
typedef irqreturn_t (*irq_handler_t)(int, void*);\n
\u7b2c\u4e09\u4e2a\u53c2\u6570flags\u53ef\u4ee5\u4e3a0\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e0b\u5217\u4e00\u4e2a\u6216\u591a\u4e2a\u6807\u5fd7\u7684\u4f4d\u63a9\u7801\uff1a
IRQF_DISABLED\u2014\u2014\u7981\u6b62\u6240\u6709\u5176\u4ed6\u4e2d\u65ad\uff0c\u65b0\u5185\u6838\u5df2\u79fb\u9664\u3002 IRQF_TIMER\u2014\u2014\u7cfb\u7edf\u5b9a\u65f6\u5668\u6807\u5fd7 IRQF_SHARED\u2014\u2014\u5728\u591a\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e4b\u95f4\u5171\u4eab\u4e2d\u65ad\u7ebf\u3002\u5982\u679c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5728\u540c\u4e00\u6761\u7ebf\u4e0a\u6ce8\u518c\uff0c\u90a3\u4e48\u5fc5\u987b\u6307\u5b9a\u8fd9\u4e2a\u6807\u5fd7\u3002 \u7b2c\u56db\u4e2a\u53c2\u6570name\u662f\u4e0e\u4e2d\u65ad\u76f8\u5173\u7684\u8bbe\u5907\u7684ASCII\u6587\u672c\u8868\u793a\u3002\u8fd9\u4e9b\u540d\u5b57\u4f1a\u88ab/proc/irq\u548c/proc/interrupts\u6587\u4ef6\u4f7f\u7528\u3002
\u7b2c\u4e94\u4e2a\u53c2\u6570dev\u7528\u4e8e\u786e\u5b9a\u5171\u4eab\u4e2d\u65ad\u7ebf\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002\u5f53\u591a\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5171\u4eab\u67d0\u6761\u4e2d\u65ad\u7ebf\uff0c\u5176\u4e2d\u67d0\u4e2a\u9700\u8981\u91ca\u653e\u65f6\uff0cdev\u5c06\u63d0\u4f9b\u552f\u4e00\u7684\u6807\u5fd7\u4fe1\u606f\u4ee5\u4fbf\u786e\u5b9a\u662f\u54ea\u4e2a\u7a0b\u5e8f\u9700\u8981\u5220\u9664\u3002
request_irq()
\u6210\u529f\u8fd4\u56de0\uff0c\u9519\u8bef\u8fd4\u56de\u975e0\u3002\u6700\u5e38\u89c1\u7684\u9519\u8bef\u662f-EBUSY\uff0c\u8868\u793a\u7ed9\u5b9a\u7684\u4e2d\u65ad\u7ebf\u5df2\u7ecf\u88ab\u4f7f\u7528\u3002
request_irq()
\u53ef\u80fd\u4f1a\u7761\u7720\uff0c\u56e0\u6b64\u4e0d\u80fd\u5728\u4e0d\u5141\u8bb8\u963b\u585e\u4ee3\u7801\u4e2d\u8c03\u7528\u8be5\u51fd\u6570\u3002
\u5378\u8f7d\u9a71\u52a8\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u6ce8\u9500\u54cd\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u5e76\u91ca\u653e\u4e2d\u65ad\u7ebf\uff1a
void free_irq(unsigned int irq, void *dev)\n
\u5982\u679c\u6307\u5b9a\u7684\u4e2d\u65ad\u7ebf\u4e0d\u662f\u5171\u4eab\u7684\uff0c\u90a3\u4e48\u8be5\u51fd\u6570\u5220\u9664\u5904\u7406\u7a0b\u5e8f\u7684\u540c\u65f6\u5c06\u7981\u7528\u8fd9\u6761\u4e2d\u65ad\u7ebf\u3002\u5982\u679c\u662f\u5171\u4eab\u7684\uff0c\u90a3\u4e48\u4ec5\u5220\u9664\u6240\u5bf9\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u800c\u8fd9\u6761\u4e2d\u65ad\u7ebf\u53ea\u6709\u5728\u5220\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u65f6\u624d\u4f1a\u88ab\u7981\u7528\u3002
\u8981\u7f16\u5199\u81ea\u5df1\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u9700\u8981\u7528\u5230\u4ee5\u4e0b\u51fd\u6570\uff1a
static irqreturn_t intr_handler(int irq, void *dev)\n
\u53c2\u6570irq\u5df2\u7ecf\u6ca1\u6709\u4ec0\u4e48\u7528\u4e86\uff0c\u53c2\u6570dev\u7528\u6765\u5411\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4f20\u9012\u6570\u636e\u7ed3\u6784\u3002
Linux\u4e0a\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u65e0\u9700\u8981\u6c42\u53ef\u91cd\u5165\u3002\u56e0\u4e3a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u65f6\u76f8\u5e94\u4e2d\u65ad\u7ebf\u4e0a\u7684\u4e2d\u65ad\u662f\u5c4f\u853d\u7684\uff0c\u4e5f\u5c31\u662f\u4e0d\u4f1a\u53d1\u751f\u76f8\u540c\u4e2d\u65ad\u7684\u5d4c\u5957\u3002\u4f46\u4e0d\u540c\u4e2d\u65ad\u7684\u5d4c\u5957\u6709\u53ef\u80fd\u53d1\u751f\u3002
\u5bf9\u4e8e\u5171\u4eab\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u9664\u4e86\u8981\u6307\u5b9arequest_irq()
\u51fd\u6570\u4e2d\u7684\u53c2\u6570flags\u4e3aIRQF_SHARED\u6807\u5fd7\uff0c\u8fd8\u9700\u8981\u4fdd\u8bc1\u53c2\u6570dev\u7684\u552f\u4e00\u6027\u3002\u5f53\u5185\u6838\u63a5\u6536\u4e00\u4e2a\u4e2d\u65ad\u540e\uff0c\u5b83\u5c06\u4f9d\u6b21\u8c03\u7528\u5728\u8be5\u4e2d\u65ad\u7ebf\u4e0a\u6ce8\u518c\u7684\u6bcf\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u3002\u56e0\u6b64\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u5fc5\u987b\u77e5\u9053\u5b83\u662f\u5426\u8be5\u4e3a\u8fd9\u4e2a\u4e2d\u65ad\u8d1f\u8d23\uff0c\u5982\u679c\u4e0d\u662f\u5c31\u8981\u7acb\u5373\u9000\u51fa\u3002
"},{"location":"linux/kernel/interrupt/#_3","title":"\u4e2d\u65ad\u5904\u7406\u673a\u5236","text":"\u4e2d\u65ad\u5904\u7406\u7cfb\u7edf\u5728Linux\u4e2d\u7684\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u4f53\u7cfb\u7ed3\u6784\u3002\u4e0a\u56fe\u662f\u4e2d\u65ad\u4ece\u786c\u4ef6\u5230\u5185\u6838\u6267\u884c\u7684\u8fc7\u7a0b\u3002\u5f53\u4e00\u4e2a\u8bbe\u5907\u4ea7\u751f\u4e2d\u65ad\u540e\uff0c\u901a\u8fc7\u603b\u7ebf\u628a\u7535\u4fe1\u53f7\u53d1\u9001\u7ed9\u4e2d\u65ad\u63a7\u5236\u5668\u3002\u5982\u679c\u4e2d\u65ad\u7ebf\u662f\u6fc0\u6d3b\u7684\uff0c\u90a3\u4e48\u4e2d\u65ad\u63a7\u5236\u5668\u5c31\u4f1a\u628a\u4e2d\u65ad\u53d1\u9001\u7ed9\u5904\u7406\u5668\u3002\u5728\u5927\u591a\u6570\u4f53\u7cfb\u7ed3\u6784\u4e2d\uff0c\u8fd9\u4e2a\u5de5\u4f5c\u5c31\u662f\u901a\u8fc7\u7535\u4fe1\u53f7\u7ed9\u5904\u7406\u5668\u7684\u7279\u5b9a\u7ba1\u811a\u53d1\u9001\u4e00\u4e2a\u4fe1\u53f7\u3002\u9664\u975e\u5904\u7406\u5668\u7981\u6b62\u4e86\u8be5\u4e2d\u65ad\uff0c\u5426\u5219\u5b83\u4f1a\u7acb\u523b\u505c\u4e0b\u5f53\u524d\u6267\u884c\u7684\u4ee3\u7801\uff0c\u5173\u95ed\u4e2d\u65ad\u7cfb\u7edf\uff0c\u7136\u540e\u8df3\u5230\u5185\u5b58\u4e2d\u9884\u5b9a\u4e49\u7684\u4f4d\u7f6e\u5f00\u59cb\u6267\u884c\u90a3\u91cc\u7684\u4ee3\u7801\u3002\u8fd9\u4e2a\u9884\u5b9a\u4e49\u7684\u4f4d\u7f6e\u7531\u5185\u6838\u8bbe\u7f6e\uff0c\u662f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002
\u5bf9\u4e8e\u6bcf\u6761\u4e2d\u65ad\u7ebf\uff0c\u5904\u7406\u5668\u90fd\u4f1a\u8df3\u5230\u5bf9\u5e94\u7684\u4e00\u4e2a\u552f\u4e00\u7684\u4f4d\u7f6e\u3002\u8fd9\u6837\uff0c\u5185\u6838\u5c31\u53ef\u4ee5\u77e5\u9053\u6240\u63a5\u6536\u4e2d\u65ad\u7684IRQ\u53f7\u4e86\u3002\u521d\u59cb\u5165\u53e3\u70b9\u5728\u6808\u4e2d\u4fdd\u5b58IRQ\u53f7\uff0c\u5e76\u5b58\u653e\u5f53\u524d\u5bc4\u5b58\u5668\u7684\u503c\uff08\u8fd9\u4e9b\u503c\u5c5e\u4e8e\u88ab\u4e2d\u65ad\u7684\u4efb\u52a1\uff09\u3002\u7136\u540e\uff0c\u7531\u5185\u6838\u8c03\u7528do_IRQ()
\u51fd\u6570\uff1a
unsigned int do_IRQ(struct pt_regs *regs)\n
\u7531\u4e8e\u521d\u59cb\u5165\u53e3\u70b9\u5df2\u7ecf\u5c06IRQ\u53f7\u548c\u5bc4\u5b58\u5668\u7684\u503c\u4fdd\u5b58\u5728\u6808\u4e2d\u4e86\uff0c\u6240\u4ee5\u51fd\u6570do_IRQ()
\u53ef\u4ee5\u76f4\u63a5\u63d0\u53d6\u6808\u4e2d\u7684\u53c2\u6570\u3002
do_IRQ()
\u6267\u884c\u5b8c\u4e2d\u65ad\u670d\u52a1\u5668\u7a0b\u5e8f\u540e\uff0c\u4f1a\u68c0\u67e5\u662f\u5426\u9700\u8981\u91cd\u65b0\u8c03\u5ea6\uff08need_resched\u6807\u5fd7\u4f4d\uff09\uff0c\u7136\u540e\u5224\u65ad\u8fd4\u56de\u54ea\u4e2a\u7a7a\u95f4\uff1a
\u8fd4\u56de\u7528\u6237\u7a7a\u95f4\uff1a\u8c03\u7528schedule()
\u51fd\u6570\u3002
\u8fd4\u56de\u5185\u6838\u7a7a\u95f4\uff1a\u5982\u679cpreempt_count\u6807\u5fd7\u4e3a0\uff0c\u8c03\u7528schedule()
\u51fd\u6570\uff0c\u5426\u5219\u4e0d\u4f1a\u89e6\u53d1\u8c03\u5ea6\u3002
procfs\u662f\u4e00\u4e2a\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bfb/proc/interrupts\u6587\u4ef6\u8bfb\u53d6\u7cfb\u7edf\u4e2d\u4e0e\u4e2d\u65ad\u76f8\u5173\u7684\u7edf\u8ba1\u4fe1\u606f\u3002
"},{"location":"linux/kernel/interrupt/#_4","title":"\u4e2d\u65ad\u63a7\u5236","text":"Linux\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7ec4\u63a5\u53e3\u7528\u4e8e\u64cd\u4f5c\u673a\u5668\u4e0a\u7684\u4e2d\u65ad\u72b6\u6001\u3002\u8fd9\u4e9b\u63a5\u53e3\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u80fd\u591f\u7981\u6b62\u5f53\u524d\u5904\u7406\u5668\u7684\u4e2d\u65ad\u7cfb\u7edf\uff0c\u6216\u5c4f\u853d\u6389\u6574\u4e2a\u673a\u5668\u7684\u4e00\u6761\u4e2d\u65ad\u7ebf\u7684\u80fd\u529b\u3002\u8fd9\u4e9b\u64cd\u4f5c\u90fd\u662f\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u63a7\u5236\u4e2d\u65ad\u7cfb\u7edf\u7684\u539f\u56e0\u5f52\u6839\u5230\u5e95\u662f\u9700\u8981\u540c\u6b65\u3002\u901a\u8fc7\u7981\u6b62\u4e2d\u65ad\uff0c\u53ef\u4ee5\u786e\u4fdd\u67d0\u4e2a\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e0d\u4f1a\u88ab\u62a2\u5360\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u7981\u6b62\u5185\u6838\u62a2\u5360\u3002
\u7981\u6b62\u548c\u6fc0\u6d3b\u672c\u5730\u4e2d\u65ad\u7684\u51fd\u6570\u4e3a\uff1a
local_irq_disable();\n\nlocal_irq_enable();\n
\u5982\u679c\u5728\u8c03\u7528local_irq_disable()
\u51fd\u6570\u524d\u5df2\u7ecf\u7981\u6b62\u4e86\u4e2d\u65ad\uff0c\u90a3\u4e48\u8be5\u64cd\u4f5c\u4f1a\u5e26\u6765\u6f5c\u5728\u7684\u5371\u9669\u3002\u540c\u6837\uff0clocal_irq_enable()
\u51fd\u6570\u4e5f\u5b58\u5728\u5371\u9669\uff0c\u56e0\u4e3a\u5b83\u4f1a\u65e0\u6761\u4ef6\u6fc0\u6d3b\u4e2d\u65ad\u3002\u5f53\u5185\u6838\u4ee3\u7801\u53d8\u5f97\u590d\u6742\u65f6\uff0c\u6211\u4eec\u5e76\u4e0d\u77e5\u9053\u5f53\u524d\u5904\u7406\u5668\u4e2d\u65ad\u72b6\u6001\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u79cd\u673a\u5236\uff0c\u4ec5\u4ec5\u65f6\u628a\u4e2d\u65ad\u6062\u590d\u5230\u4ee5\u524d\u7684\u72b6\u6001\u800c\u4e0d\u662f\u7b80\u5355\u5730\u7981\u6b62\u6216\u8005\u662f\u6fc0\u6d3b\u3002
unsigned long flags;\nlocal_irq_save(flags);\nlocal_irq_restore(flags);\n
\u5728\u524d\u9762\u7684\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u77e5\u9053\u4e86\u7981\u6b62\u6574\u4e2a\u5904\u7406\u5668\u4e0a\u6240\u6709\u4e2d\u65ad\u7684\u51fd\u6570\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u7981\u6b62\u7279\u5b9a\u7684\u4e2d\u65ad\u7ebf\u3002\u76f8\u5173\u51fd\u6570\u5982\u4e0b\uff1a
void disable_irq(unsigned int irq);\nvoid disable_irq_nosync(unsigned int irq);\nvoid enable_irq(unsigned int irq);\nvoid synchronize_irq(unsigned int irq);\n
\u7531\u4e8e\u73b0\u4ee3\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5f80\u5f80\u5171\u4eab\u67d0\u4e2a\u4e2d\u65ad\u7ebf\uff0c\u7981\u6b62\u4e86\u67d0\u6761\u4e2d\u65ad\u7ebf\u4e5f\u5c31\u7981\u6b62\u4e86\u8fd9\u6761\u7ebf\u4e0a\u6240\u6709\u8bbe\u5907\u7684\u4e2d\u65ad\u4f20\u9012\u3002\u56e0\u6b64\u8fd9\u4e9b\u63a5\u53e3\u51fd\u6570\u4e0d\u5e94\u8be5\u88ab\u4f7f\u7528\u3002
"},{"location":"linux/kernel/interrupt/#_5","title":"\u4e0b\u534a\u90e8\u673a\u5236","text":"\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u6709\u4e00\u4e2a\u5feb\u901f\u3001\u5f02\u6b65\u4e14\u7b80\u5355\u7684\u673a\u5236\u8d1f\u8d23\u5bf9\u786c\u4ef6\u8fc5\u901f\u505a\u51fa\u76f8\u5e94\u5e76\u5b8c\u6210\u90a3\u4e9b\u65f6\u95f4\u8981\u6c42\u5f88\u4e25\u683c\u7684\u64cd\u4f5c\u3002\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5f88\u9002\u5408\u4e8e\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\u3002\u800c\u5bf9\u4e8e\u90a3\u4e9b\u65f6\u95f4\u8981\u6c42\u76f8\u5bf9\u5bbd\u677e\u7684\u4efb\u52a1\uff0c\u5e94\u5f53\u653e\u5230\u4e0b\u534a\u90e8\u53bb\u5904\u7406\u3002
\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6700\u597d\u8ba9\u6240\u6709\u7684\u5de5\u4f5c\u90fd\u4ea4\u7ed9\u4e0b\u534a\u90e8\u53bb\u5904\u7406\u3002\u4f46\u662f\uff0c\u603b\u6709\u4e00\u4e9b\u5de5\u4f5c\u9700\u8981\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u6765\u5b8c\u6210\uff0c\u6bd4\u5982\u5bf9\u4e2d\u65ad\u7684\u5230\u8fbe\u8fdb\u884c\u786e\u8ba4\uff0c\u4ece\u786c\u4ef6\u62f7\u8d1d\u6570\u636e\u7b49\u3002\u5982\u4f55\u533a\u5206\u4e0a\u534a\u90e8\u548c\u4e0b\u534a\u90e8\uff0c\u5b8c\u5168\u7531\u9a71\u52a8\u7a0b\u5e8f\u5f00\u53d1\u8005\u81ea\u884c\u5224\u65ad\u3002\u5982\u679c\u4efb\u52a1\u6ee1\u8db3\u4ee5\u4e0b\u8981\u6c42\uff0c\u5219\u9002\u5408\u653e\u5230\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u6267\u884c\u3002
\u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u5bf9\u65f6\u95f4\u975e\u5e38\u654f\u611f\u3002 \u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u548c\u786c\u4ef6\u76f8\u5173\u3002 \u5982\u679c\u8fd9\u4e2a\u4efb\u52a1\u4e0d\u80fd\u88ab\u5176\u4ed6\u4e2d\u65ad\u6253\u65ad\u3002 \u5176\u4ed6\u6240\u6709\u4efb\u52a1\uff0c\u8003\u8651\u653e\u5728\u4e0b\u534a\u90e8\u6267\u884c\u3002
"},{"location":"linux/kernel/interrupt/#_6","title":"\u8f6f\u4e2d\u65ad","text":"\u8f6f\u4e2d\u65ad\u7684\u82f1\u6587\u540d\u662fsoftirq\uff0c\u4e0e\u8f6f\u4ef6\u4e2d\u65ad\uff08software irq\uff09\u6ca1\u6709\u5173\u7cfb\u3002
\u8f6f\u4e2d\u65ad\u4f7f\u7528\u6bd4\u8f83\u5c11\uff0ctasklet\u662f\u4e0b\u534a\u90e8\u66f4\u5e38\u7528\u8fc7\u7684\u4e00\u79cd\u5f62\u5f0f\u3002\u4f46\u662f\uff0c\u7531\u4e8etasklet\u662f\u901a\u8fc7\u8f6f\u4e2d\u65ad\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u4e5f\u6709\u5fc5\u8981\u5148\u7814\u7a76\u8f6f\u4e2d\u65ad\u3002
"},{"location":"linux/kernel/interrupt/#_7","title":"\u8f6f\u4e2d\u65ad\u7684\u5b9e\u73b0","text":"\u8f6f\u4e2d\u65ad\u5728\u7f16\u8bd1\u671f\u95f4\u9759\u6001\u5206\u914d\uff0c\u7531softirq_action
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct softirq_action{\n void (*action)(struct softirq_action*);\n};\n
\u5728<kernel/softirq.c>\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5305\u542b\u670932\u4e2a\u8be5\u7ed3\u6784\u4f53\u7684\u6570\u7ec4\uff1a
static struct softirq_action softirq_vec[NR_SOFTIRQS];\n
\u6bcf\u4e2a\u88ab\u6ce8\u518c\u7684\u8f6f\u4e2d\u65ad\u90fd\u5360\u636e\u8be5\u6570\u7ec4\u7684\u4e00\u9879\uff0c\u56e0\u6b64\u6700\u5927\u670932\u4e2a\u8f6f\u4e2d\u65ad\u3002
\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8faction\u7684\u51fd\u6570\u539f\u578b\u5982\u4e0b\uff1a
void softirq_handler(struct softirq_action *)\n
\u5f53\u5185\u6838\u8fd0\u884c\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u65f6\uff0c\u5c31\u4f1a\u6267\u884c\u8fd9\u4e2aaction\u51fd\u6570\uff0c\u5176\u552f\u4e00\u7684\u53c2\u6570\u662f\u6307\u5411\u76f8\u5e94softirq_action
\u7ed3\u6784\u4f53\u7684\u6307\u9488\u3002\u4f8b\u5982\uff0c\u5982\u679cmy_softirq\u6307\u5411softirq_vec\u6570\u7ec4\u7684\u67d0\u9879\uff0c\u90a3\u4e48\u5185\u6838\u5c31\u4f1a\u7528\u5982\u4e0b\u7684\u65b9\u5f0f\u8c03\u7528\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\u7684\u51fd\u6570\uff1a
my_softirq->action(my_softirq);\n
\u4e00\u4e2a\u6ce8\u518c\u7684\u8f6f\u4e2d\u65ad\u5fc5\u987b\u5728\u88ab\u6807\u8bb0\u540e\u624d\u4f1a\u6267\u884c\uff0c\u8fd9\u88ab\u79f0\u4e3a\u89e6\u53d1\u8f6f\u4e2d\u65ad\uff08raising the softirq\uff09\u3002\u901a\u5e38\uff0c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4f1a\u5728\u8fd4\u56de\u524d\u6807\u8bb0\u5b83\u7684\u8f6f\u4e2d\u65ad\uff0c\u4f7f\u5176\u5728\u7a0d\u540e\u88ab\u6267\u884c\u3002do_softirq()
\u51fd\u6570\u4f1a\u68c0\u67e5softirq_vec\u6570\u7ec4\u4e2d\u6240\u6709\u5f85\u5904\u7406\u7684\u8f6f\u4e2d\u65ad\uff0c\u8c03\u7528\u5b83\u4eec\u7684\u5904\u7406\u7a0b\u5e8f\u3002
"},{"location":"linux/kernel/interrupt/#_8","title":"\u4f7f\u7528\u8f6f\u4e2d\u65ad","text":"\u8f6f\u4e2d\u65ad\u4fdd\u7559\u7ed9\u7cfb\u7edf\u4e2d\u5bf9\u65f6\u95f4\u8981\u6c42\u6700\u4e25\u683c\u4ee5\u53ca\u6700\u91cd\u8981\u7684\u4e0b\u534a\u90e8\u4f7f\u7528\u3002\u5185\u6838\u5728<linux/interrupt.h>\u4e2d\u5df2\u7ecf\u5b9a\u4e49\u4e86\u4e00\u4e2a\u679a\u4e3e\u7c7b\u578b\u6765\u9759\u6001\u5730\u58f0\u660e\u8f6f\u4e2d\u65ad\uff0c\u7d22\u5f15\u53f7\u8868\u793a\u5176\u4f18\u5148\u7ea7\u3002\u8981\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u8f6f\u4e2d\u65ad\u5fc5\u987b\u5728\u6b64\u679a\u4e3e\u7c7b\u578b\u4e2d\u52a0\u5165\u65b0\u7684\u9879\uff0c\u800c\u4e14\u4f60\u5fc5\u987b\u6839\u636e\u5b83\u7684\u4f18\u5148\u7ea7\u6765\u51b3\u5b9a\u52a0\u5165\u7684\u4f4d\u7f6e\u3002\u4e0b\u8868\u5217\u51fa\u4e86\u5df2\u6709\u7684tasklet\u7c7b\u578b\u3002
tasklet \u4f18\u5148\u7ea7 \u8f6f\u4e2d\u65ad\u63cf\u8ff0 HI_SOFTIRQ 0 \u4f18\u5148\u7ea7\u9ad8\u7684tasklets TIMER_SOFTIRQ 1 \u5b9a\u65f6\u5668\u7684\u4e0b\u534a\u90e8 NET_TX_SOFTIRQ 2 \u53d1\u9001\u7f51\u7edc\u6570\u636e\u5305 NET_RX_SOFTIRQ 3 \u63a5\u6536\u7f51\u7edc\u6570\u636e\u5305 BLOCK_SOFTIRQ 4 BLOCK\u88c5\u7f6e TASKLET_SOFTIRQ 5 \u6b63\u5e38\u4f18\u5148\u6743\u7684tasklets SCHED_SOFTIRQ 6 \u8c03\u5ea6\u7a0b\u5e8f HRTIMER_SOFTIRQ 7 \u9ad8\u5206\u8fa8\u7387\u5b9a\u65f6\u5668 RCU_SOFTIRQ 8 RCU\u9501\u5b9a \u63a5\u7740\uff0c\u5728\u8fd0\u884c\u65f6\u901a\u8fc7\u8c03\u7528open_softirq()
\u51fd\u6570\u6ce8\u518c\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\uff0c\u8be5\u51fd\u6570\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u8f6f\u4e2d\u65ad\u7d22\u5f15\u53f7\u548c\u5904\u7406\u51fd\u6570\uff1a
open_softirq(NET_TX_SOFTIRQ, net_tx_action)\n
\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u6267\u884c\u7684\u65f6\u5019\uff0c\u5141\u8bb8\u54cd\u5e94\u4e2d\u65ad\uff0c\u4f46\u5b83\u81ea\u5df1\u4e0d\u80fd\u4f11\u7720\u3002\u5728\u4e00\u4e2a\u5904\u7406\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u5f53\u524d\u5904\u7406\u5668\u4e0a\u7684\u8f6f\u4e2d\u65ad\u88ab\u7981\u6b62\u3002\u4f46\u5176\u4ed6\u5904\u7406\u5668\u4ecd\u7136\u53ef\u4ee5\u6267\u884c\u522b\u7684\u8f6f\u4e2d\u65ad\u3002\u8fd9\u610f\u5473\u7740\u5171\u4eab\u6570\u636e\u9700\u8981\u9501\u7684\u4fdd\u62a4\u3002\u56e0\u6b64\u5927\u90e8\u5206\u8f6f\u4e2d\u65ad\u5904\u7406\uff0c\u90fd\u901a\u8fc7\u91c7\u53d6\u5355\u5904\u7406\u5668\u6570\u636e\u6765\u907f\u514d\u52a0\u9501\uff0c\u4ece\u800c\u63d0\u4f9b\u66f4\u51fa\u8272\u7684\u6027\u80fd\u3002
\u5728\u6ce8\u518c\u5b8c\u4e4b\u540e\uff0c\u65b0\u7684\u8f6f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5c31\u80fd\u591f\u8fd0\u884c\u3002raise_softirq()
\u51fd\u6570\u53ef\u4ee5\u5c06\u4e00\u4e2a\u8f6f\u4e2d\u65ad\u8bbe\u7f6e\u4e3a\u6302\u8d77\u72b6\u6001\uff0c\u8ba9\u5b83\u5728\u4e0b\u6b21\u8c03\u7528do_softirq()
\u51fd\u6570\u65f6\u6295\u5165\u8fd0\u884c\u3002
\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\u89e6\u53d1\u8f6f\u4e2d\u65ad\u662f\u6700\u5e38\u89c1\u7684\u5f62\u5f0f\u3002\u5185\u6838\u5728\u6267\u884c\u5b8c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e4b\u540e\uff0c\u9a6c\u4e0a\u5c31\u4f1a\u8c03\u7528do_softirq()
\u51fd\u6570\uff0c\u4e8e\u662f\u8f6f\u4e2d\u65ad\u5f00\u59cb\u6267\u884c\u7ed9\u5b9a\u7684\u4efb\u52a1\u3002
"},{"location":"linux/kernel/interrupt/#tasklet","title":"tasklet","text":"tasklet\u662f\u5229\u7528\u8f6f\u4e2d\u65ad\u5b9e\u73b0\u7684\u4e00\u79cd\u4e0b\u534a\u90e8\u673a\u5236\uff0c\u4f46\u662f\u5b83\u7684\u63a5\u53e3\u66f4\u7b80\u5355\uff0c\u9501\u4fdd\u62a4\u8981\u6c42\u8f83\u4f4e\u3002\u5927\u591a\u6570\u60c5\u51b5\u90fd\u53ef\u4ee5\u4f7f\u7528tasklet\u6765\u5b8c\u6210\u4f60\u9700\u8981\u7684\u5de5\u4f5c\u3002
"},{"location":"linux/kernel/interrupt/#tasklet_1","title":"tasklet\u7684\u5b9e\u73b0","text":"tasklet\u7531\u4e24\u7c7b\u8f6f\u4e2d\u65ad\u4ee3\u8868\uff1aHI_SOFTIRQ\u548cTASKLET_SOFTIRQ\u3002\u524d\u8005\u4f18\u5148\u7ea7\u6bd4\u540e\u8005\u9ad8\u3002
tasklet\u7ed3\u6784\u4f53\u5982\u4e0b\uff1a
struct tasklet_struct {\n struct tasklet_struct *next; //\u94fe\u8868\u4e2d\u4e0b\u4e00\u4e2atasklet\n unsigned long state; //tasklet\u7684\u72b6\u6001\n atomic_t count; //\u5f15\u7528\u8ba1\u6570\u5668\n void (*func)(unsigned long); //\u5904\u7406\u51fd\u6570\n unsigned long data; //\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570\n};\n
state\u6210\u5458\u53ea\u80fd\u57280\u3001TASKLET_STATE_SCHED\u548cTASKLET_STATE_RUN\u4e4b\u95f4\u53d6\u503cTASKLET_STATE_SCHED\u8868\u660e tasklet\u5df2\u88ab\u8c03\u5ea6\uff0c\u6b63\u51c6\u5907\u6295\u4eba\u8fd0\u884c\uff0cTASKLET_STATE_RUN\u8868\u660e\u8be5tasklet\u6b63\u5728\u8fd0\u884c\u3002TASKLET_STATE_RUN\u53ea\u6709\u5728\u591a\u5904\u7406\u5668\u7684\u7cfb\u7edf\u4e0a\u624d\u4f1a\u4f5c\u4e3a\u4e00\u79cd\u4f18\u5316\u6765\u4f7f\u7528\uff0c\u5355\u5904\u7406\u5668\u7cfb\u7edf\u4efb\u4f55\u65f6\u5019\u90fd\u6e05\u695a\u5355\u4e2atasklet\u662f\u4e0d\u662f\u6b63\u5728\u8fd0\u884c(\u5b83\u8981\u4e48\u5c31\u662f\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\uff0c\u8981\u4e48\u4e0d\u662f)\u3002
count\u6210\u5458\u662ftasklet\u7684\u5f15\u7528\u8ba1\u6570\u5668\u3002\u5982\u679c\u5b83\u4e0d\u4e3a0\uff0c\u5219tasklet\u88ab\u7981\u6b62\uff1b\u53ea\u6709\u5f53\u5b83\u4e3a0\u65f6\uff0ctasklet\u624d\u88ab\u6fc0\u6d3b\u3002
\u5df2\u8c03\u5ea6\uff08\u6216\u8005\u53eb\u5df2\u6fc0\u6d3b\uff09\u7684tasklet\u5b58\u653e\u5728tasklet_vec\uff08\u666e\u901atasklet\uff09\u548ctasklet_hi_vec\uff08\u9ad8\u4f18\u5148\u7ea7\u7684tasklet\uff09\u6570\u7ec4\u4e2d\u3002\u8fd9\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u90fd\u662f\u7531tasklet_struct
\u7ed3\u6784\u4f53\u6784\u6210\u7684\u94fe\u8868\uff0c\u94fe\u8868\u4e2d\u6bcf\u4e2a\u5143\u7d20\u4ee3\u8868\u4e00\u4e2a\u4e0d\u540c\u7684tasklet\u3002
tasklet\u7531tasklet_schedule()
\u548ctasklet_hi_schedule()
\u51fd\u6570\u8fdb\u884c\u8c03\u5ea6\uff0c\u5b83\u4eec\u63a5\u53d7\u4e00\u4e2a\u6307\u5411tasklet_struct
\u7ed3\u6784\u7684\u6307\u9488\u4f5c\u4e3a\u53c2\u6570\u3002
"},{"location":"linux/kernel/interrupt/#tasklet_2","title":"\u4f7f\u7528tasklet","text":"\u5982\u679c\u662f\u9759\u6001\u521b\u5efa\u4e00\u4e2atasklet\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u4e2a\u5b8f\u4e2d\u7684\u4e00\u4e2a\uff1a
DECLARE_TASKLET(name, func, data)\nDECLARE_TASKLET_DISABLED(name, func, data)\n
\u8fd9\u4e24\u4e2a\u5b8f\u90fd\u80fd\u9759\u6001\u521b\u5efa\u4e00\u4e2atasklet_struct
\u7ed3\u6784\uff0c\u533a\u522b\u5728\u4e8e\u5f15\u7528\u8ba1\u6570count\u7684\u521d\u59cb\u503c\u4e0d\u540c\u3002\u7b2c\u4e00\u4e2a\u8bbe\u4e3a0\uff0c\u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001\uff1b\u7b2c\u4e8c\u4e2a\u8bbe\u4e3a1\uff0c\u5904\u4e8e\u7981\u6b62\u72b6\u6001\u3002
\u5982\u679c\u662f\u52a8\u6001\u521b\u5efa\uff1a
tasklet_init(t, tasklet_handler, dev);\n
\u7f16\u5199\u81ea\u5df1\u7684tasklet\u5904\u7406\u7a0b\u5e8f\uff1a
void tasklet_handler(unsigned long data)\n
tasklet\u4e0d\u80fd\u7761\u7720\uff0c\u4e24\u4e2a\u76f8\u540c\u7684tasklet\u4e0d\u4f1a\u540c\u65f6\u6267\u884c\uff0c\u4f46\u5982\u679c\u4e0e\u5176\u4ed6tasklet\u6216\u8005\u662f\u8f6f\u4e2d\u65ad\u5171\u4eab\u4e86\u6570\u636e\uff0c\u90a3\u4e48\u5fc5\u987b\u8fdb\u884c\u9501\u4fdd\u62a4\u3002
\u901a\u8fc7\u8c03\u7528tasklet_schedule()
\u51fd\u6570\u5e76\u4f20\u9012\u7ed9\u5b83\u76f8\u5e94\u7684tasklet_struct
\u6307\u9488\uff0c\u8be5tasklet\u5c31\u4f1a\u88ab\u8c03\u5ea6\u4ee5\u4fbf\u6267\u884c\uff1a
tasklet_schedule(&my_tasklet);\n
\u4e00\u4e2atasklet\u603b\u662f\u5728\u8c03\u5ea6\u5b83\u7684\u5904\u7406\u5668\u4e0a\u8fd0\u884c\u3002\u8981\u7981\u6b62/\u4f7f\u80fdtasklet\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7684\u51fd\u6570\uff1a
tasklet_disable(&my_tasklet); //\u7b49\u5f85tasklet\u6267\u884c\u5b8c\u6bd5\ntasklet_disable_nosync(&my_tasklet); //\u4e0d\u4f1a\u7b49\u5f85tasklet\ntasklet_enable(&my_tasklet); //\u6fc0\u6d3btasklet\ntasklet_kill(&my_tasklet); //\u79fb\u9664\u5df2\u8c03\u5ea6\u7684tasklet\n
"},{"location":"linux/kernel/interrupt/#ksoftirqd","title":"ksoftirqd","text":"\u6bcf\u4e2a\u5904\u7406\u5668\u90fd\u6709\u4e00\u7ec4\u8f85\u52a9\u5904\u7406\u8f6f\u4e2d\u65ad\uff08\u548ctasklet\uff09\u7684\u5185\u6838\u7ebf\u7a0b\u3002\u5f53\u5185\u6838\u4e2d\u51fa\u73b0\u5927\u91cf\u8f6f\u4e2d\u65ad\u7684\u65f6\u5019\uff0c\u5185\u6838\u7ebf\u7a0b\u5c31\u4f1a\u9009\u62e9\u5408\u9002\u7684\u65f6\u673a\u6765\u5904\u7406\u8f6f\u4e2d\u65ad\u3002
\u5728\u5927\u6d41\u91cf\u7684\u7f51\u7edc\u901a\u4fe1\u4e2d\uff0c\u8f6f\u4e2d\u65ad\u7684\u89e6\u53d1\u9891\u7387\u53ef\u80fd\u5f88\u9ad8\uff0c\u751a\u81f3\u8fd8\u4f1a\u81ea\u884c\u91cd\u590d\u89e6\u53d1\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u7528\u6237\u7a7a\u95f4\u7684\u8fdb\u7a0b\u65e0\u6cd5\u83b7\u5f97\u8db3\u591f\u7684\u5904\u7406\u5668\u65f6\u95f4\u3002\u5982\u679c\u8f6f\u4e2d\u65ad\u548c\u91cd\u590d\u89e6\u53d1\u7684\u8f6f\u4e2d\u65ad\u90fd\u88ab\u7acb\u5373\u5904\u7406\uff0c\u90a3\u4e48\u5f53\u8d1f\u8f7d\u5f88\u9ad8\u7684\u65f6\u5019\uff0c\u7cfb\u7edf\u5c31\u4f1a\u51fa\u73b0\u660e\u663e\u7684\u5361\u987f\u73b0\u8c61\u3002\u5982\u679c\u9009\u62e9\u4e0d\u5904\u7406\u91cd\u65b0\u89e6\u53d1\u7684\u8f6f\u4e2d\u65ad\uff0c\u53c8\u4f1a\u6d6a\u8d39\u95f2\u7f6e\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u5bfc\u81f4\u8f6f\u4e2d\u65ad\u51fa\u73b0\u9965\u997f\u73b0\u8c61\u3002
\u5185\u6838\u4e2d\u7684\u65b9\u6848\u65f6\u4e0d\u4f1a\u7acb\u5373\u5904\u7406\u91cd\u590d\u89e6\u53d1\u7684\u8f6f\u4e2d\u65ad\u3002\u5f53\u5927\u91cf\u8f6f\u4e2d\u65ad\u51fa\u73b0\u7684\u65f6\u5019\uff0c\u5185\u6838\u4f1a\u5524\u9192\u4e00\u7ec4\u5185\u6838\u7ebf\u7a0b\u6765\u5904\u7406\u8fd9\u4e9b\u8d1f\u8f7d\u3002\u8fd9\u4e9b\u7ebf\u7a0b\u5728\u6700\u4f4e\u4f18\u5148\u7ea7\uff08nice=19\uff09\u8fd0\u884c\uff0c\u907f\u514d\u4e0e\u5176\u4ed6\u4efb\u52a1\u62a2\u5360\u8d44\u6e90\u3002
\u6bcf\u4e2a\u5904\u7406\u5668\u90fd\u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u7ebf\u7a0b\uff0c\u540d\u5b57\u4e3aksoftirqd/n\uff0cn\u4e3a\u5904\u7406\u5668\u7f16\u53f7\u3002\u53ea\u8981\u6709\u5f85\u5904\u7406\u7684\u8f6f\u4e2d\u65ad\uff0cksoftirqd\u5c31\u4f1a\u8c03\u7528do_softirq()
\u51fd\u6570\u6765\u5904\u7406\u5b83\u4eec\u3002
"},{"location":"linux/kernel/interrupt/#_9","title":"\u5de5\u4f5c\u961f\u5217","text":"\u5de5\u4f5c\u961f\u5217\u662f\u4e00\u79cd\u5ef6\u540e\u6267\u884c\u7684\u673a\u5236\uff0c\u53ef\u4ee5\u5c06\u540e\u7eed\u7684\u5de5\u4f5c\u4ea4\u7ed9\u4e00\u4e2a\u5185\u6838\u7ebf\u7a0b\u6267\u884c\u2014\u2014\u8fd9\u4e2a\u4e0b\u534a\u90e8\u5206\u603b\u662f\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u6267\u884c\u3002\u8fd9\u6837\uff0c\u901a\u8fc7\u5de5\u4f5c\u961f\u5217\u5b9e\u73b0\u7684\u4ee3\u7801\u5c31\u80fd\u4eab\u53d7\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u7684\u6240\u6709\u4f18\u52bf\uff0c\u6bd4\u5982\u53ef\u4ee5\u91cd\u65b0\u8c03\u5ea6\u751a\u81f3\u662f\u7761\u7720\u3002
\u5982\u679c\u63a8\u540e\u6267\u884c\u7684\u4efb\u52a1\u9700\u8981\u7761\u7720\uff0c\u90a3\u4e48\u5c31\u9009\u62e9\u5de5\u4f5c\u961f\u5217\u3002\u5426\u5219\u5c31\u9009\u62e9\u8f6f\u4e2d\u65ad\u6216tasklet\u3002\u5de5\u4f5c\u961f\u5217\u5728\u4f60\u9700\u8981\u83b7\u5f97\u5927\u91cf\u5185\u5b58\u65f6\uff0c\u9700\u8981\u83b7\u53d6\u4fe1\u53f7\u91cf\u65f6\uff0c\u9700\u8981\u6267\u884c\u963b\u585e\u5f0f\u7684I/O\u64cd\u4f5c\u65f6\uff0c\u5b83\u90fd\u4f1a\u975e\u5e38\u6709\u7528\u3002
"},{"location":"linux/kernel/interrupt/#_10","title":"\u5de5\u4f5c\u961f\u5217\u7684\u5b9e\u73b0","text":"\u5de5\u4f5c\u961f\u5217\u5b50\u7cfb\u7edf\u63d0\u4f9b\u4e86\u7f3a\u7701\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\uff08worker thread\uff09\u6765\u5904\u7406\u9700\u8981\u63a8\u540e\u7684\u5de5\u4f5c\u3002\u7f3a\u7701\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u53eb\u505aevents/n\uff0cn\u4e3a\u5904\u7406\u5668\u7684\u7f16\u53f7\u3002\u4f60\u53ef\u4ee5\u521b\u5efa\u81ea\u5df1\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\uff0c\u4e0d\u8fc7\u4e00\u822c\u4f7f\u7528\u7f3a\u7701\u7ebf\u7a0b\u5373\u53ef\u3002\u7136\u800c\uff0c\u5982\u679c\u4e00\u4e2a\u4efb\u52a1\u9700\u8981\u7279\u522b\u7684\u5904\u7406\uff0c\u6216\u8005\u5b83\u5bf9\u6027\u80fd\u6709\u975e\u5e38\u4e25\u683c\u7684\u8981\u6c42\uff0c\u90a3\u4e48\u521b\u5efa\u4e00\u4e2a\u4e13\u7528\u7684\u5185\u6838\u7ebf\u7a0b\u53ef\u80fd\u5c31\u662f\u5fc5\u8981\u7684\u3002\u4e13\u7528\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u53ef\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u548c\u4f18\u5316\u4efb\u52a1\u7684\u6267\u884c\uff0c\u4f46\u4e5f\u9700\u8981\u66f4\u591a\u7684\u8d44\u6e90\u548c\u7ba1\u7406\u5f00\u9500\u3002
\u5de5\u4f5c\u8005\u7ebf\u7a0b\u7528workqueue_struct
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct workqueue_struct {\n struct cpu_workqueue_struct cpu_wq[NR_CPUS]\uff1b\n struct list_head list;\n const char *name;\n int singlethread;\n int freezeable;\n int rt;\n};\n
\u8be5\u7ed3\u6784\u4f53\u5185\u6709\u4e00\u4e2acpu_workqueue_struct
\u7ed3\u6784\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u6bcf\u4e00\u9879\u5bf9\u5e94\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u5904\u7406\u5668\u3002\u4e5f\u5c31\u662f\u8bf4\u7cfb\u7edf\u4e2d\u6bcf\u4e2a\u5904\u7406\u5668\u5bf9\u5e94\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u3002
\u5de5\u4f5c\u7531work_struct
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct work_struct {\n atomic_long_t data;\n struct list_head entry;\n work_func_t func;\n};\n
\u8fd9\u4e9b\u7ed3\u6784\u4f53\u88ab\u8fde\u63a5\u6210\u94fe\u8868\uff0c\u6bcf\u4e2a\u5904\u7406\u5668\u4e0a\u7684\u6bcf\u79cd\u7c7b\u578b\u7684\u961f\u5217\u90fd\u5bf9\u5e94\u8fd9\u6837\u4e00\u4e2a\u94fe\u8868\u3002\u5f53\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u88ab\u5524\u9192\u65f6\uff0c\u5b83\u4f1a\u6267\u884c\u94fe\u8868\u4e0a\u7684\u6240\u6709\u5de5\u4f5c\uff0c\u5f53\u6ca1\u6709\u5269\u4f59\u7684\u64cd\u4f5c\u65f6\uff0c\u5b83\u5c31\u4f1a\u7ee7\u7eed\u4f11\u7720\u3002
"},{"location":"linux/kernel/interrupt/#_11","title":"\u4f7f\u7528\u5de5\u4f5c\u961f\u5217","text":"\u9759\u6001\u521b\u5efa\u4e00\u4e2awork_struct
\u7ed3\u6784\u4f53\uff1a
DECLARE_WORK(name, void(*func)(void *), void *data);\n
\u5982\u679c\u662f\u52a8\u6001\u521b\u5efa\uff1a
INIT_WORK(struct work_struct *work, void (*func)(void *), void *data);\n
\u5de5\u4f5c\u961f\u5217\u5904\u7406\u51fd\u6570\u7684\u539f\u578b\u662f\uff1a
void work_handler(void *data)\n
\u8fd9\u4e2a\u51fd\u6570\u7531\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u6267\u884c\uff0c\u56e0\u6b64\u5904\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5141\u8bb8\u76f8\u5e94\u4e2d\u65ad\uff0c\u5e76\u4e14\u4e0d\u6301\u6709\u4efb\u4f55\u9501\u3002\u5c3d\u7ba1\u5904\u7406\u51fd\u6570\u4f4d\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\uff0c\u4f46\u662f\u5b83\u4e0d\u53ef\u4ee5\u8bbf\u95ee\u7528\u6237\u7a7a\u95f4\uff0c\u56e0\u4e3a\u5185\u6838\u7ebf\u7a0b\u5728\u7528\u6237\u7a7a\u95f4\u6ca1\u6709\u76f8\u5173\u7684\u5185\u5b58\u6620\u5c04\u3002
\u5bf9\u5de5\u4f5c\u8fdb\u884c\u8c03\u5ea6\uff0c\u628a\u7ed9\u5b9a\u5de5\u4f5c\u7684\u5904\u7406\u51fd\u6570\u63d0\u4ea4\u7ed9\u7f3a\u7701\u7684events\u5de5\u4f5c\u7ebf\u7a0b\uff1a
schedule_work(&work);\n
\u4e00\u65e6\u5176\u6240\u5728\u5904\u7406\u5668\u4e0a\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u88ab\u5524\u9192\uff0c\u5c31\u4f1a\u7acb\u523b\u6267\u884c\u3002\u5982\u679c\u9700\u8981\u5de5\u4f5c\u5ef6\u8fdf\u6267\u884c\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\uff1a
schedule_delayed_work(&work, delay);\n
&work\u6307\u5411\u7684work_struct
\u5219\u4f1a\u7b49\u5f85delay\u4e2a\u65f6\u949f\u8282\u62cd\u624d\u4f1a\u6267\u884c\u3002
\u5982\u679c\u7f3a\u7701\u7684\u961f\u5217\u4e0d\u80fd\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u961f\u5217\u548c\u4e0e\u4e4b\u76f8\u5e94\u7684\u5de5\u4f5c\u8005\u7ebf\u7a0b\u3002\u8fd9\u4e48\u505a\u4f1a\u5728\u6bcf\u4e2a\u5904\u7406\u5668\u4e0a\u90fd\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u8005\u7ebf\u7a0b\u3002\u9664\u975e\u4f60\u786e\u5b9a\u5fc5\u987b\u8981\u9760\u81ea\u5df1\u7684\u7ebf\u7a0b\u624d\u80fd\u63d0\u9ad8\u6027\u80fd\uff0c\u5426\u5219\u4e0d\u8981\u8fd9\u4e48\u505a\uff1a
struct workqueue_struct *create_workqueue(const char *name);\n
"},{"location":"linux/kernel/interrupt/#_12","title":"\u4e0b\u534a\u90e8\u7684\u540c\u6b65","text":"\u5728\u4f7f\u7528\u4e0b\u534a\u90e8\u673a\u5236\u65f6\uff0c\u5373\u4fbf\u662f\u4e00\u4e2a\u5355\u5904\u7406\u5668\uff0c\u907f\u514d\u5171\u4eab\u6570\u636e\u88ab\u540c\u65f6\u8bbf\u95ee\u4e5f\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4f7f\u7528tasklet\u7684\u597d\u5904\u662f\uff1a\u4e24\u4e2a\u76f8\u540c\u7c7b\u578b\u7684tasklet\u4e0d\u5141\u8bb8\u540c\u65f6\u6267\u884c\uff0c\u5373\u4fbf\u662f\u4e0d\u540c\u7684\u5904\u7406\u5668\u4e5f\u4e0d\u884c\u3002tasklet\u4e4b\u95f4\u7684\u540c\u6b65\uff08\u5373\u4e0d\u540c\u7c7b\u578b\u7684tasklet\u5171\u4eab\u540c\u4e00\u6570\u636e\uff09\uff0c\u6b63\u786e\u4f7f\u7528\u9501\u673a\u5236\u5373\u53ef\u3002
\u5982\u679c\u662f\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u548c\u4e0b\u534a\u90e8\u5171\u4eab\u6570\u636e\uff0c\u5728\u8bbf\u95ee\u8fd9\u4e9b\u6570\u636e\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u7981\u6b62\u4e0b\u534a\u90e8\u7684\u5904\u7406\u5e76\u83b7\u5f97\u9501\u7684\u4f7f\u7528\u6743\uff0c\u4ee5\u9632\u6b62\u6b7b\u9501\u7684\u51fa\u73b0\u3002
\u5982\u679c\u662f\u4e2d\u65ad\u4e0a\u4e0b\u6587\u548c\u4e0b\u534a\u90e8\u5171\u4eab\u6570\u636e\uff0c\u5728\u8bbf\u95ee\u8fd9\u4e9b\u6570\u636e\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u7981\u6b62\u4e2d\u65ad\u5e76\u83b7\u5f97\u9501\u7684\u4f7f\u7528\u6743\uff0c\u4e5f\u662f\u4e3a\u4e86\u9632\u6b62\u6b7b\u9501\u7684\u51fa\u73b0\u3002
\u4efb\u4f55\u5728\u5de5\u4f5c\u961f\u5217\u4e2d\u88ab\u5171\u4eab\u7684\u6570\u636e\u4e5f\u9700\u8981\u4f7f\u7528\u9501\u673a\u5236\u3002
\u4e00\u822c\u5355\u7eaf\u7981\u6b62\u4e0b\u534a\u90e8\u662f\u4e0d\u591f\u7684\uff0c\u66f4\u5e38\u89c1\u7684\u505a\u6cd5\u662f\u5148\u83b7\u5f97\u4e00\u4e2a\u9501\u518d\u7981\u6b62\u4e0b\u534a\u90e8\u7684\u5904\u7406\u3002\u5982\u679c\u9700\u8981\u7981\u6b62\u6240\u6709\u4e0b\u534a\u90e8\u7684\u5904\u7406\uff0c\u53ef\u4ee5\u8c03\u7528local_bh_disable()
\u51fd\u6570\u3002\u5141\u8bb8\u4e0b\u534a\u90e8\u5904\u7406\uff0c\u8c03\u7528local_bh_enable()
\u51fd\u6570\u3002\u51fd\u6570\u901a\u8fc7preempt_count
\uff08\u5185\u6838\u62a2\u5360\u4e5f\u662f\u8fd9\u4e2a\u8ba1\u6570\u5668\uff09\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u7ef4\u62a4\u4e00\u4e2a\u8ba1\u6570\u5668\u3002\u5f53\u8ba1\u6570\u5668\u4e3a0\u65f6\uff0c\u624d\u53ef\u4ee5\u5904\u7406\u4e0b\u534a\u90e8\u3002
"},{"location":"linux/kernel/mm/","title":"\u7269\u7406\u5185\u5b58\u7ba1\u7406","text":"\u8fd9\u90e8\u5206\u5185\u5bb9\u8981\u548c\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u7ed3\u5408\u8d77\u6765\u770b\u3002
"},{"location":"linux/kernel/mm/#_2","title":"\u9875\u548c\u533a","text":"\u5185\u6838\u5c06\u7269\u7406\u5185\u5b58\u5212\u5206\u4e3a\u4f17\u591a\u56fa\u5b9a\u5927\u5c0f\u7684\u9875\uff0c\u6bcf\u9875\u901a\u5e38\u5305\u542b4KB\u7684\u5b58\u50a8\u7a7a\u95f4\u3002\u8fd9\u79cd\u5206\u9875\u673a\u5236\u6781\u5927\u5730\u63d0\u5347\u4e86\u5185\u6838\u5728\u5185\u5b58\u5206\u914d\u548c\u56de\u6536\u65b9\u9762\u7684\u6548\u7387\uff0c\u540c\u65f6\u4e5f\u4e3a\u865a\u62df\u5185\u5b58\u7ba1\u7406\u63d0\u4f9b\u4e86\u4fbf\u5229\u3002\u901a\u8fc7\u5c06\u5185\u5b58\u5212\u5206\u4e3a\u4e00\u81f4\u5927\u5c0f\u7684\u5355\u5143\uff0c\u5185\u6838\u80fd\u591f\u66f4\u52a0\u7075\u6d3b\u5730\u5904\u7406\u5185\u5b58\u8bf7\u6c42\uff0c\u4f18\u5316\u8d44\u6e90\u5206\u914d\uff0c\u5e76\u7b80\u5316\u4e86\u5185\u5b58\u5bfb\u5740\u548c\u6620\u5c04\u7684\u8fc7\u7a0b\u3002struct page
\u7ed3\u6784\u4f53\u8868\u793a\u9875\uff0c\u8be5\u5b9a\u4e49\u7684\u7b80\u5316\u7248\u5982\u4e0b\uff1a
struct page {\n unsigned long flags;\n atomic_t _count;\n atomic_t _mapcount;\n unsigned long private;\n struct address_space *mapping;\n pgoff_t index;\n struct list_head lru;\n void *virtual;\n};\n
flags\uff1a\u5b58\u653e\u9875\u7684\u72b6\u6001\uff0c\u662f\u4e0d\u662f\u810f\u9875\uff0c\u662f\u4e0d\u662f\u9501\u5b9a\u5728\u5185\u5b58\u4e2d\u7b49\u3002
_count\uff1a\u5b58\u653e\u9875\u7684\u5f15\u7528\u8ba1\u6570\uff0c\u5f53\u9875\u88ab\u5206\u914d\u7ed9\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u8fd9\u4e2a\u8ba1\u6570\u5668\u4f1a\u589e\u52a0\u3002\u5f53\u9875\u88ab\u91ca\u653e\u65f6\uff0c\u8ba1\u6570\u5668\u51cf\u5c11\u3002\u76f4\u5230\u8ba1\u6570\u5668\u964d\u81f30\uff0c\u9875\u624d\u80fd\u88ab\u56de\u6536\u3002
_mapcount\uff1a\u7528\u4e8e\u8bb0\u5f55\u9875\u8868\u9879\u6620\u5c04\u5230\u8be5\u7269\u7406\u9875\u7684\u6b21\u6570\u3002\u8fd9\u901a\u5e38\u7528\u4e8e\u5171\u4eab\u5185\u5b58\u9875\uff0c\u591a\u4e2a\u8fdb\u7a0b\u53ef\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u7269\u7406\u9875\u3002
mapping\uff1a\u6307\u5411\u4e00\u4e2aaddress_space\u7ed3\u6784\u7684\u6307\u9488\uff0c\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7528\u4e8e\u63cf\u8ff0\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u5185\u5b58\u6620\u5c04\u4fe1\u606f\u3002\u5982\u679c\u9875\u5c5e\u4e8e\u6587\u4ef6\u7f13\u5b58\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u5c06\u6307\u5411\u76f8\u5e94\u7684address_space\u7ed3\u6784\u3002
index\uff1a\u8868\u793a\u9875\u5728\u6620\u5c04\u7684\u6587\u4ef6\u4e2d\u7684\u504f\u79fb\u91cf\uff0c\u5373\u9875\u5728\u6587\u4ef6\u4e2d\u7684\u7d22\u5f15\u53f7\u3002
lru\uff1a\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u8282\u70b9\uff0c\u7528\u4e8e\u5c06\u9875\u94fe\u5165\u5230\u5404\u79cd\u94fe\u8868\u4e2d\uff0c\u6bd4\u5982\u6d3b\u8dc3\u94fe\u8868\u3001\u4e0d\u6d3b\u8dc3\u94fe\u8868\u7b49\u3002\u8fd9\u662f\u5185\u6838\u5b9e\u73b0\u9875\u7f6e\u6362\u7b97\u6cd5\uff08\u5982LRU\uff09\u7684\u4e00\u90e8\u5206\u3002
virtual\uff1a\u9875\u5728\u865a\u62df\u5185\u5b58\u4e2d\u7684\u5730\u5740\u3002
\u4e3a\u4e86\u66f4\u597d\u5730\u7ba1\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u5185\u5b58\u548c\u4f18\u5316\u5185\u5b58\u5206\u914d\u7b56\u7565\uff0c\u5185\u6838\u5c06\u9875\u5212\u5206\u4e3a\u4e0d\u540c\u7684\u533a(zone)\uff0c\u901a\u5e38\u5212\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u533a\uff1a
ZONE_DMA\uff1a\u7528\u4e8eDMA\u64cd\u4f5c\u7684\u5185\u5b58\u533a\uff0c\u901a\u5e38\u4f4d\u4e8e\u7269\u7406\u5185\u5b58\u7684\u4f4e\u5730\u5740\u90e8\u5206\u3002
ZONE_DMA32\uff1a\u4e0eZONE_DMA\u7c7b\u4f3c\uff0c\u4f46\u9002\u7528\u4e8e32\u4f4d\u5730\u5740\u7684DMA\u64cd\u4f5c\u3002
ZONE_NORMAL\uff1a\u666e\u901a\u7684\u5185\u5b58\u533a\uff0c\u53ef\u4ee5\u7531\u5185\u6838\u548c\u7528\u6237\u7a7a\u95f4\u8fdb\u7a0b\u4f7f\u7528\u3002
ZONE_HIGHMEM\uff1a\u9ad8\u7aef\u5185\u5b58\u533a\uff0c\u7528\u4e8e\u5904\u7406\u8d85\u8fc7\u76f4\u63a5\u6620\u5c04\u8303\u56f4\u7684\u5185\u5b58\u3002
\u533a\u7684\u4f7f\u7528\u548c\u5206\u5e03\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\uff0c\u5185\u6838\u5c06\u9875\u5212\u5206\u4e3a\u533a\uff0c\u5c31\u53ef\u4ee5\u6839\u636e\u7528\u9014\u8fdb\u884c\u5206\u914d\u3002\u533a\u7684\u5212\u5206\u6ca1\u6709\u7269\u7406\u610f\u4e49\uff0c\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406\u800c\u91c7\u53d6\u7684\u4e00\u79cd\u903b\u8f91\u5206\u7ec4\u3002
"},{"location":"linux/kernel/mm/#_3","title":"\u9875\u64cd\u4f5c","text":"\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u4e9b\u83b7\u5f97\u9875\u548c\u91ca\u653e\u9875\u7684\u64cd\u4f5c\uff0c\u8fd9\u91cc\u4e0d\u505a\u8be6\u7ec6\u8bf4\u660e\u3002
\u51fd\u6570 \u63cf\u8ff0 alloc_page(gfp_mask) \u53ea\u5206\u914d\u4e00\u9875\uff0c\u8fd4\u56de\u6307\u5411\u9875\u7684\u6307\u9488 alloc_pages(gfp_mask, order) \u5206\u914d2order \u4e2a\u9875\uff0c\u8fd4\u56de\u6307\u5411\u7b2c\u4e00\u9875\u7684\u6307\u9488 __get_free_page(gfp_mask) \u53ea\u5206\u914d\u4e00\u9875\uff0c\u8fd4\u56de\u6307\u5411\u5176\u903b\u8f91\u5730\u5740\u7684\u6307\u9488 __get_free_pages(gfp_mask, order) \u5206\u914d2order \u4e2a\u9875\uff0c\u8fd4\u56de\u6307\u5411\u7b2c\u4e00\u9875\u903b\u8f91\u5730\u5740\u7684\u6307\u9488 get_zero_page(gfp_mask) \u53ea\u5206\u914d\u4e00\u9875\uff0c\u586b\u5145\u4e3a0\uff0c\u8fd4\u56de\u6307\u5411\u5176\u903b\u8f91\u5730\u5740\u7684\u6307\u9488 __free_pages(page, order) \u4f20\u5165\u9875\u7684\u6307\u9488\uff0c\u91ca\u653e2order \u4e2a\u9875 free_pages(addr, order) \u4f20\u5165\u7b2c\u4e00\u9875\u7684\u903b\u8f91\u5730\u5740\uff0c\u91ca\u653e2order \u4e2a\u9875 free_page(addr) \u91ca\u653e\u5355\u5f20\u9875 \u91ca\u653e\u9875\u65f6\u8981\u8c28\u614e\uff0c\u4e00\u65e6\u4f20\u9012\u4e86\u9519\u8bef\u7684page\u6216\u8005address\uff0c\u7cfb\u7edf\u5c31\u4f1a\u5d29\u6e83\u3002\u5728\u83b7\u5f97\u9875\u4e4b\u540e\uff0c\u9700\u8981\u5bf9\u8fd4\u56de\u503c\u8fdb\u884c\u68c0\u67e5\u4ee5\u786e\u8ba4\u5185\u6838\u6b63\u786e\u5730\u5206\u914d\u4e86\u9875\u3002
\u5bf9\u4e8e\u5e38\u7528\u7684\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\u5185\u5b58\u5206\u914d\u6765\u8bf4\uff0c\u5185\u6838\u63d0\u4f9b\u7684\u51fd\u6570\u662fkmalloc()
\u3002
"},{"location":"linux/kernel/mm/#kmalloc","title":"kmalloc()","text":"kmalloc()
\u4e0e\u7528\u6237\u7a7a\u95f4\u7684malloc()
\u7c7b\u4f3c\uff0c\u90fd\u662f\u5206\u914d\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\u4e00\u5757\u5185\u5b58\uff0c\u533a\u522b\u5728\u4e8ekmalloc()
\u591a\u4e86\u4e00\u4e2aflags\u53c2\u6570\uff1a
\u6ce8\u610f\uff1a\u4f7f\u7528kmalloc()
\u51fd\u6570\u5206\u914d\u7684\u5185\u5b58\u53ea\u80fd\u4f7f\u7528kfree()
\u51fd\u6570\u91ca\u653e\u3002
void *kmalloc(size_t size, gfp_t flags)\n
\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u5185\u5b58\u5757\u7684\u6307\u9488\uff0c\u81f3\u5c11\u6709size\u5927\u5c0f\u3002\u6240\u5206\u914d\u7684\u5185\u5b58\u533a\u5728\u7269\u7406\u4e0a\u662f\u8fde\u7eed\u7684\u3002\u9664\u975e\u6ca1\u6709\u8db3\u591f\u7684\u5185\u5b58\u53ef\u7528\uff0c\u5426\u5219\u5185\u6838\u603b\u80fd\u5206\u914d\u6210\u529f\u3002\u5f53\u7136\uff0c\u5728\u5bf9kmalloc()
\u8c03\u7528\u4e4b\u540e\uff0c\u4f60\u8fd8\u662f\u9700\u8981\u68c0\u67e5\u8fd4\u56de\u503c\u662f\u5426\u4e3aNULL\uff1a
struct dog *p;\np = kmalloc(sizeof(struct dog), GFP_KERNEL)\uff1b\nif(!p)\n /*\u5904\u7406\u9519\u8bef*/\n
\u4e0d\u7ba1\u662f\u5728\u9875\u5206\u914d\u51fd\u6570\u8fd8\u662f\u5728kmalloc()
\u4e2d\uff0c\u90fd\u7528\u5230\u4e86\u5206\u914d\u5668\u6807\u5fd7\u3002\u6807\u5fd7\u5206\u4e3a\u4e09\u7c7b\uff1a\u884c\u4e3a\u4fee\u9970\u7b26\u3001\u533a\u4fee\u9970\u7b26\u548c\u7c7b\u578b\u6807\u5fd7\u3002\u7c7b\u578b\u6807\u5fd7\u7ec4\u5408\u4e86\u524d\u4e24\u8005\uff0c\u7b80\u5316\u4e86\u4fee\u9970\u7b26\u7684\u4f7f\u7528\uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u9700\u8981\u77e5\u9053\u7c7b\u578b\u6807\u5fd7\u5373\u53ef\u3002\u5185\u6838\u4e2d\u6700\u5e38\u7528\u7684\u5c31\u662fGFP_KERNEL\u3002\u8fd9\u79cd\u5206\u914d\u65b9\u5f0f\u53ef\u80fd\u4f1a\u5f15\u8d77\u7761\u7720\uff0c\u6240\u4ee5\u53ea\u80fd\u7528\u5728\u53ef\u4ee5\u91cd\u65b0\u5b89\u5168\u8c03\u5ea6\u7684\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u3002\u53e6\u4e00\u4e2a\u622a\u7136\u76f8\u53cd\u7684\u6807\u5fd7\u662fGFP_ATOMIC\uff0c\u8fd9\u4e2a\u6807\u5fd7\u8868\u793a\u4e0d\u80fd\u7761\u7720\u7684\u5185\u5b58\u5206\u914d\u3002\u4e0eGFP_KERNEL\u76f8\u6bd4\uff0c\u5b83\u5206\u914d\u6210\u529f\u7684\u673a\u4f1a\u8f83\u5c0f\uff0c\u4f46\u662f\u5728\u4e00\u4e9b\u65e0\u6cd5\u7761\u7720\u7684\u4ee3\u7801\u4e2d\uff0c\u4e5f\u53ea\u80fd\u9009\u62e9GFP_ATOMIC\u3002GFP_DMA\u6807\u5fd7\u8868\u793a\u5206\u914d\u5668\u5fc5\u987b\u6ee1\u8db3\u4eceZONE_DMA\u8fdb\u884c\u5206\u914d\u7684\u8bf7\u6c42\uff0c\u8be5\u6807\u5fd7\u7528\u5728\u9700\u8981DMA\u7684\u5185\u5b58\u7684\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u4e2d\u3002\u5728\u7f16\u5199\u7684\u7edd\u5927\u591a\u6570\u4ee3\u7801\u4e2d\uff0c\u8981\u4e48\u662fGFP_KERNEL\uff0c\u8981\u4e48\u662fGFP_ATOMIC\uff0c\u5176\u4ed6\u6807\u5fd7\u7528\u5230\u7684\u60c5\u51b5\u6781\u5c11\uff0c\u5c31\u4e0d\u505a\u8bf4\u660e\u4e86\u3002\u4e0b\u9762\u8fd9\u5f20\u8868\u683c\u603b\u7ed3\u4e86\u6807\u5fd7\u7684\u4f7f\u7528\u573a\u666f\u3002
\u60c5\u5f62 \u76f8\u5e94\u6807\u5fd7 \u53ef\u4ee5\u7761\u7720\u7684\u8fdb\u7a0b\u4e0a\u4e0b\u6587 GFP_KERNEL \u4e0d\u53ef\u4ee5\u7761\u7720\u7684\u8fdb\u7a0b\u4e0a\u4e0b\u6587 GFP_ATOMIC \u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f GFP_ATOMIC \u8f6f\u4e2d\u65ad GFP_ATOMIC tasklet GFP_ATOMIC \u53ef\u4ee5\u7761\u7720\u7684DMA\u5185\u5b58 \uff08GFP_DMA | GFP_KERNEL\uff09 \u4e0d\u53ef\u4ee5\u7761\u7720\u7684DMA\u5185\u5b58 \uff08GFP_DMA\uff09| GFP_ATOMIC"},{"location":"linux/kernel/mm/#vmalloc","title":"vmalloc()","text":"vmalloc()
\u51fd\u6570\u4e0ekmalloc()
\u51fd\u6570\u5728\u5185\u5b58\u5206\u914d\u65b9\u9762\u5177\u6709\u76f8\u4f3c\u7684\u529f\u80fd\uff0c\u4f46\u5b83\u4eec\u5728\u7269\u7406\u5730\u5740\u8fde\u7eed\u6027\u65b9\u9762\u6709\u6240\u4e0d\u540c\u3002\u4e0ekmalloc()
\u4fdd\u8bc1\u5206\u914d\u7684\u5185\u5b58\u9875\u5728\u7269\u7406\u5730\u5740\u4e0a\u8fde\u7eed\u4e0d\u540c\uff0cvmalloc()
\u5206\u914d\u7684\u5185\u5b58\u9875\u5728\u7269\u7406\u5730\u5740\u4e0a\u53ef\u4ee5\u662f\u4e0d\u8fde\u7eed\u7684\u3002\u8fd9\u79cd\u73b0\u8c61\u4e0e\u7528\u6237\u7a7a\u95f4\u5185\u5b58\u5206\u914d\u51fd\u6570malloc()
\u7c7b\u4f3c\uff0cmalloc()
\u8fd4\u56de\u7684\u9875\u5728\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e2d\u662f\u8fde\u7eed\u7684\uff0c\u4f46\u5e76\u4e0d\u4fdd\u8bc1\u8fd9\u4e9b\u9875\u5728\u7269\u7406\u5730\u5740\u4e0a\u4e5f\u662f\u8fde\u7eed\u7684\u3002
\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u786c\u4ef6\u8bbe\u5907\u9700\u8981\u8bbf\u95ee\u7269\u7406\u5730\u5740\u8fde\u7eed\u7684\u5185\u5b58\u9875\u3002\u8fd9\u662f\u56e0\u4e3a\u8bb8\u591a\u4f53\u7cfb\u7ed3\u6784\u7684\u786c\u4ef6\u8bbe\u5907\u5b58\u5728\u4e8e\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff08MMU\uff09\u4e4b\u5916\uff0c\u5b83\u4eec\u65e0\u6cd5\u5904\u7406\u865a\u62df\u5730\u5740\u3002\u56e0\u6b64\uff0c\u786c\u4ef6\u8bbe\u5907\u6240\u4f7f\u7528\u7684\u4efb\u4f55\u5185\u5b58\u533a\u57df\u90fd\u5fc5\u987b\u662f\u7269\u7406\u4e0a\u8fde\u7eed\u7684\u5185\u5b58\u5757\u3002
\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u8f6f\u4ef6\u4f7f\u7528\u7684\u5185\u5b58\u5757\u5219\u6ca1\u6709\u8fd9\u6837\u7684\u4e25\u683c\u8981\u6c42\u3002\u8f6f\u4ef6\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u865a\u62df\u5730\u5740\u6765\u8bbf\u95ee\u5185\u5b58\uff0c\u5373\u4f7f\u8fd9\u4e9b\u865a\u62df\u5730\u5740\u5bf9\u5e94\u7684\u7269\u7406\u5185\u5b58\u4e0d\u662f\u8fde\u7eed\u7684\u3002\u8fd9\u662f\u56e0\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u901a\u8fc7\u9875\u8868\u7ba1\u7406\u673a\u5236\uff0c\u53ef\u4ee5\u5c06\u4e0d\u8fde\u7eed\u7684\u7269\u7406\u5185\u5b58\u6620\u5c04\u5230\u8fde\u7eed\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e2d\u3002\u8fd9\u79cd\u673a\u5236\u4f7f\u5f97\u8f6f\u4ef6\u53ef\u4ee5\u9ad8\u6548\u5730\u4f7f\u7528\u5206\u6563\u7684\u7269\u7406\u5185\u5b58\u8d44\u6e90\uff0c\u800c\u65e0\u9700\u5173\u5fc3\u5185\u5b58\u7684\u7269\u7406\u5e03\u5c40\u3002
\u7531\u4e8evmalloc()
\u9700\u8981\u5bf9\u4e0d\u8fde\u7eed\u7684\u9875\u8fdb\u884c\u4e13\u95e8\u7684\u6620\u5c04\u5904\u7406\uff0c\u6240\u4ee5\u5176\u6027\u80fd\u4e0d\u5982kmalloc()
\u3002\u4ec5\u5728\u4e0d\u5f97\u5df2\u7684\u60c5\u5f62\u4e0b\u624d\u4f1a\u4f7f\u7528\uff0c\u6bd4\u5982\u4e3a\u4e86\u83b7\u5f97\u5927\u5757\u5185\u5b58\u65f6\u3002\u56e0\u4e3akmalloc()
\u5206\u914d\u7684\u5185\u5b58\u5757\u662f\u8fde\u7eed\u7684\uff0c\u5f53\u7cfb\u7edf\u4e2d\u7684\u5185\u5b58\u788e\u7247\u8f83\u591a\u65f6\uff0c\u5c1d\u8bd5\u5206\u914d\u5927\u5757\u5185\u5b58\u53ef\u80fd\u4f1a\u5931\u8d25\uff0c\u800cvmalloc()
\u5219\u4e0d\u4f1a\u3002
vmalloc()
\u7684\u5206\u914d\u548c\u91ca\u653e\u63a5\u53e3\u5982\u4e0b\uff1a
void *vmalloc(unsinged long size)\n\nvoid vfree(const void *addr)\n
\u8fd9\u4e24\u4e2a\u51fd\u6570\u90fd\u4f1a\u7761\u7720\uff0c\u56e0\u6b64\u4e0d\u80fd\u5728\u4e2d\u65ad\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u3002
"},{"location":"linux/kernel/mm/#_4","title":"\u4f19\u4f34\u7cfb\u7edf","text":"\u4f19\u4f34\u7cfb\u7edf\uff08Buddy System\uff09\u662f\u4e00\u79cd\u5185\u5b58\u5206\u914d\u7b97\u6cd5\uff0c\u5b83\u88ab\u7528\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u5b58\u7ba1\u7406\u3002\u5728\u8fd9\u79cd\u7cfb\u7edf\u4e2d\uff0c\u5185\u5b58\u88ab\u5206\u6210\u591a\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u5757\uff0c\u6bcf\u4e2a\u5757\u7684\u5927\u5c0f\u90fd\u662f2\u7684\u5e42\u6b21\u65b9\u3002\u8fd9\u4e9b\u5757\u88ab\u7ec4\u7ec7\u6210\u4e00\u9897\u6811\u7ed3\u6784\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5757\u90fd\u662f\u53e6\u4e00\u4e2a\u5757\u7684\u201c\u4f19\u4f34\u201d\u3002
\u5185\u6838\u628a\u6240\u6709\u7684\u7a7a\u95f2\u9875\u5206\u7ec4\u4e3a11\u4e2a\u9875\u5757\u94fe\u8868\uff0c\u6bcf\u4e2a\u5757\u94fe\u8868\u5206\u522b\u5305\u542b\u5f88\u591a\u4e2a\u5927\u5c0f\u7684\u9875\u5757\uff0c\u6709 1\u30012\u30014\u30018\u300116\u300132\u300164\u3001128\u3001256\u3001512 \u548c 1024 \u4e2a\u8fde\u7eed\u9875\u7684\u9875\u5757\u3002\u6700\u5927\u53ef\u4ee5\u7533\u8bf71024\u4e2a\u8fde\u7eed\u9875\uff0c\u5bf9\u5e94 4MB\u5927\u5c0f\u7684\u8fde\u7eed\u5185\u5b58\u3002
\u5f53\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u5206\u914d\u5185\u5b58\u65f6\uff0c\u5b83\u4f1a\u6839\u636e\u8bf7\u6c42\u7684\u5927\u5c0f\u627e\u5230\u6700\u63a5\u8fd1\u7684\u4e14\u5927\u5c0f\u8db3\u591f\u7684\u5757\u8fdb\u884c\u5206\u914d\u3002\u5982\u679c\u5206\u914d\u7684\u5757\u6bd4\u6240\u9700\u7684\u5927\u5c0f\u5927\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5757\u4f1a\u88ab\u5206\u6210\u4e24\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u5b50\u5757\uff0c\u5176\u4e2d\u4e00\u4e2a\u5b50\u5757\u88ab\u7528\u6765\u6ee1\u8db3\u5185\u5b58\u5206\u914d\u8bf7\u6c42\uff0c\u800c\u53e6\u4e00\u4e2a\u5219\u6210\u4e3a\u5b83\u7684\u201c\u4f19\u4f34\u201d\u3002
\u5728\u4f19\u4f34\u7cfb\u7edf\u4e2d\uff0c\u5f53\u9700\u8981\u5206\u914d\u4e00\u4e2a\u7279\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u5757\u65f6\uff0c\u7cfb\u7edf\u4f1a\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a
\u9996\u5148\uff0c\u786e\u5b9a\u6240\u9700\u5185\u5b58\u5757\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u9700\u8981128\u4e2a\u9875\u7684\u5757\uff0c\u7cfb\u7edf\u4f1a\u68c0\u67e5128\u4e2a\u9875\u7684\u7a7a\u95f2\u5757\u94fe\u8868\u3002
\u5982\u679c\u5728128\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u6ca1\u6709\u627e\u5230\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u5bfb\u627e\u4e0b\u4e00\u4e2a\u66f4\u5927\u7684\u5185\u5b58\u5757\u5c3a\u5bf8\uff0c\u5373256\u4e2a\u9875\u7684\u5757\u3002
\u5982\u679c\u5728256\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u627e\u5230\u4e86\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u5c06\u8fd9\u4e2a\u5757\u5206\u6210\u4e24\u4e2a\u5927\u5c0f\u76f8\u7b49\u7684\u5757\uff0c\u6bcf\u4e2a\u5757\u5305\u542b128\u4e2a\u9875\u3002\u5176\u4e2d\u4e00\u4e2a\u5757\u88ab\u5206\u914d\u7ed9\u8bf7\u6c42\u8005\uff0c\u53e6\u4e00\u4e2a\u5757\u4f5c\u4e3a\u65b0\u7684\u7a7a\u95f2\u5757\u63d2\u5165\u5230128\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u3002
\u5982\u679c256\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u4e5f\u6ca1\u6709\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u7ee7\u7eed\u68c0\u67e5\u66f4\u5927\u7684\u5757\uff0c\u6bd4\u5982512\u4e2a\u9875\u7684\u5757\u3002
\u5982\u679c\u5728512\u4e2a\u9875\u7684\u94fe\u8868\u4e2d\u627e\u5230\u4e86\u7a7a\u95f2\u5757\uff0c\u7cfb\u7edf\u4f1a\u5c06\u8fd9\u4e2a\u5757\u5206\u88c2\u6210\u4e09\u4e2a\u5757\uff1a\u4e24\u4e2a128\u4e2a\u9875\u7684\u5757\u548c\u4e00\u4e2a256\u4e2a\u9875\u7684\u5757\u3002\u5176\u4e2d\u4e00\u4e2a128\u4e2a\u9875\u7684\u5757\u88ab\u5206\u914d\u51fa\u53bb\uff0c\u5176\u4f59\u4e24\u4e2a\u5757\u5206\u522b\u63d2\u5165\u5230\u76f8\u5e94\u7684\u94fe\u8868\u4e2d\u3002 \u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f19\u4f34\u7cfb\u7edf\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u5185\u5b58\uff0c\u786e\u4fdd\u5185\u5b58\u5206\u914d\u65e2\u9ad8\u6548\u53c8\u7075\u6d3b\u3002
\u5f53\u5185\u5b58\u5757\u88ab\u91ca\u653e\u65f6\uff0c\u7cfb\u7edf\u4f1a\u68c0\u67e5\u662f\u5426\u6709\u76f8\u90bb\u7684\u4f19\u4f34\u5757\u540c\u6837\u7a7a\u95f2\uff0c\u5982\u679c\u4e24\u8005\u90fd\u662f\u7a7a\u95f2\u7684\uff0c\u5b83\u4eec\u4f1a\u88ab\u5408\u5e76\u56de\u539f\u6765\u7684\u5927\u5757\uff0c\u4ece\u800c\u51cf\u5c11\u5185\u5b58\u788e\u7247\u3002
"},{"location":"linux/kernel/mm/#slab","title":"slab\u5206\u914d\u5668","text":"\u5728\u5185\u6838\u7f16\u7a0b\u4e2d\uff0c\u5206\u914d\u548c\u91ca\u653e\u6570\u636e\u7ed3\u6784\u662f\u4e00\u9879\u6781\u4e3a\u5e38\u89c1\u7684\u5de5\u4f5c\u3002\u4e3a\u4e86\u9ad8\u6548\u5730\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u7684\u9891\u7e41\u5206\u914d\u4e0e\u56de\u6536\uff0c\u5f00\u53d1\u8005\u4eec\u901a\u5e38\u4f1a\u5229\u7528\u7a7a\u95f2\u94fe\u8868\u6765\u4f18\u5316\u8fd9\u4e00\u8fc7\u7a0b\u3002\u7a7a\u95f2\u94fe\u8868\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u9884\u5148\u5206\u914d\u7684\u6570\u636e\u7ed3\u6784\u5757\u7684\u96c6\u5408\uff0c\u8fd9\u4e9b\u5757\u90fd\u5904\u4e8e\u53ef\u7528\u72b6\u6001\u3002\u5f53\u7cfb\u7edf\u9700\u8981\u65b0\u7684\u6570\u636e\u7ed3\u6784\u5b9e\u4f8b\u65f6\uff0c\u53ef\u4ee5\u76f4\u63a5\u4ece\u7a7a\u95f2\u94fe\u8868\u4e2d\u83b7\u53d6\u4e00\u4e2a\u73b0\u6210\u7684\u5757\uff0c\u8fd9\u6837\u5c31\u907f\u514d\u4e86\u5b9e\u65f6\u5185\u5b58\u5206\u914d\u7684\u6d88\u8017\u3002\u4f7f\u7528\u5b8c\u6bd5\u540e\uff0c\u8be5\u6570\u636e\u7ed3\u6784\u5b9e\u4f8b\u88ab\u5f52\u8fd8\u5230\u7a7a\u95f2\u94fe\u8868\u4e2d\uff0c\u800c\u4e0d\u662f\u88ab\u76f4\u63a5\u91ca\u653e\u3002\u5728\u8fd9\u79cd\u673a\u5236\u4e0b\uff0c\u7a7a\u95f2\u94fe\u8868\u5145\u5f53\u4e86\u4e00\u79cd\u7279\u6b8a\u7684\u5bf9\u8c61\u9ad8\u901f\u7f13\u5b58\uff0c\u5b83\u80fd\u591f\u5feb\u901f\u5730\u5b58\u50a8\u548c\u63d0\u4f9b\u90a3\u4e9b\u7ecf\u5e38\u88ab\u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\u7c7b\u578b\u3002\u8fd9\u6837\u7684\u8bbe\u8ba1\u4e0d\u4ec5\u63d0\u5347\u4e86\u5185\u5b58\u7ba1\u7406\u7684\u6548\u7387\uff0c\u8fd8\u51cf\u5c11\u4e86\u5185\u5b58\u788e\u7247\uff0c\u662f\u4e00\u79cd\u975e\u5e38\u5b9e\u7528\u7684\u7f16\u7a0b\u6280\u5de7\u3002
Linux\u5185\u6838\u63d0\u4f9b\u4e86slab\u5206\u914d\u5668\uff0c\u5b83\u901a\u8fc7\u5c06\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u7ec4\u7ec7\u5230\u5404\u81ea\u7684\u9ad8\u901f\u7f13\u5b58\u7ec4\u4e2d\uff0c\u6765\u4f18\u5316\u8fd9\u4e9b\u5bf9\u8c61\u7684\u5206\u914d\u548c\u56de\u6536\u3002\u6bcf\u4e2a\u9ad8\u901f\u7f13\u5b58\u7ec4\u4e13\u95e8\u7528\u4e8e\u5b58\u50a8\u4e00\u79cd\u7279\u5b9a\u7c7b\u578b\u7684\u5bf9\u8c61\u3002\u4f8b\u5982\uff0c\u4e00\u4e2a\u9ad8\u901f\u7f13\u5b58\u53ef\u80fd\u7528\u4e8e\u7ba1\u7406\u8fdb\u7a0b\u63cf\u8ff0\u7b26\uff08task_struct
\u7ed3\u6784\uff09\uff0c\u800c\u53e6\u4e00\u4e2a\u5219\u7528\u4e8e\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\uff08struct inode
\uff09\u3002
slab\u53ef\u4ee5\u5904\u4e8e\u4e09\u79cd\u72b6\u6001\u4e4b\u4e00\uff1a\u6ee1\u3001\u90e8\u5206\u6ee1\u6216\u7a7a\u3002\u6ee1\u7684slab\u610f\u5473\u7740\u6240\u6709\u5bf9\u8c61\u90fd\u5df2\u5206\u914d\u51fa\u53bb\uff0c\u7a7a\u7684slab\u5219\u8868\u793a\u6240\u6709\u5bf9\u8c61\u90fd\u672a\u88ab\u5206\u914d\uff0c\u800c\u90e8\u5206\u6ee1\u7684slab\u5219\u5305\u542b\u4e86\u5df2\u5206\u914d\u548c\u672a\u5206\u914d\u7684\u5bf9\u8c61\u3002\u5f53\u5185\u6838\u8bf7\u6c42\u65b0\u5bf9\u8c61\u65f6\uff0c\u4f18\u5148\u4ece\u90e8\u5206\u6ee1\u7684slab\u4e2d\u5206\u914d\u3002\u5982\u679c\u6ca1\u6709\uff0c\u5219\u4ece\u7a7a\u7684slab\u4e2d\u5206\u914d\u3002\u5982\u679c\u8fde\u7a7a\u7684slab\u90fd\u6ca1\u6709\uff0c\u5c31\u4f1a\u521b\u5efa\u65b0\u7684slab\u3002
"},{"location":"linux/kernel/others/","title":"\u5176\u4ed6","text":"\u8fd9\u91cc\u4e3b\u8981\u653e\u4e00\u4e9b\u96f6\u788e\u7684\u5185\u5bb9\u3002
"},{"location":"linux/kernel/others/#_2","title":"\u7cfb\u7edf\u8c03\u7528","text":"\u5f53\u4f60\u7684\u7a0b\u5e8f\u8c03\u7528open, read, write, close\u7b49\u51fd\u6570\u65f6\uff0c\u5c31\u4f1a\u89e6\u53d1\u7cfb\u7edf\u8c03\u7528\uff08syscall\uff09\u3002\u7cfb\u7edf\u8c03\u7528\u672c\u8d28\u662f\u7528\u6237\u6001\u8fdb\u7a0b\u4e0e\u786c\u4ef6\u8bbe\u5907\u4ea4\u4e92\u7684\u63a5\u53e3\uff0c\u5185\u6838\u8d1f\u8d23\u68c0\u67e5\u7cfb\u7edf\u8c03\u7528\u7684\u6b63\u786e\u6027\uff0c\u7136\u540e\u53d1\u51fa\u6307\u4ee4\u7ed9\u786c\u4ef6\u3002\u4f5c\u4e3a\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u8005\uff0c\u4e0d\u7528\u5173\u5fc3\u5e95\u5c42\u786c\u4ef6\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u800c\u53ea\u9700\u8981\u8c03\u7528\u666e\u901a\u51fd\u6570\u5c31\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u8c03\u7528\u4e86\u3002glibc\u5e93\u8fdb\u4e00\u6b65\u5c01\u88c5\u4e86\u7ec6\u8282\uff0c\u56e0\u6b64\u6211\u4eec\u53ea\u9700\u8981\u4f7f\u7528glibc\u5e93\u66b4\u9732\u7684API\u5373\u53ef\u3002
x86\u4f53\u7cfb\u8fdb\u5165\u548c\u9000\u51fa\u7cfb\u7edf\u8c03\u7528\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a
int $0x80 \u548c iret sysenter \u548c sysexit \u7b2c\u4e8c\u79cd\u88ab\u79f0\u4e3a\u5feb\u901f\u7cfb\u7edf\u8c03\u7528\u3002
\u65e0\u8bba\u54ea\u79cd\u65b9\u5f0f\uff0c\u6700\u7ec8\u7ed3\u679c\u90fd\u662f\u8df3\u8f6c\u5230\u7cfb\u7edf\u8c03\u7528\u5904\u7406\u51fd\u6570\uff08system call handler\uff09\u3002\u7531\u4e8e\u5185\u6838\u5b9e\u73b0\u4e86\u5f88\u591a\u4e0d\u540c\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u56e0\u6b64\u8fdb\u7a0b\u5fc5\u987b\u4f20\u9012\u4e00\u4e2a\u540d\u4e3a\u7cfb\u7edf\u8c03\u7528\u53f7\uff08system call number\uff09\u7684\u53c2\u6570\u6765\u8bc6\u522b\u6240\u9700\u7684\u7cfb\u7edf\u8c03\u7528\uff0c\u8fd9\u4e2a\u53c2\u6570\u5b58\u653e\u5728eax\u5bc4\u5b58\u5668\u4e2d\u3002\u6267\u884c\u5b8c\u7cfb\u7edf\u8c03\u7528\u540e\u7684\u8fd4\u56de\u503c\u4e5f\u653e\u5728eax\u5bc4\u5b58\u5668\u4e2d\uff0c\u5176\u4e2d\u6b63\u6570\u62160\u8868\u793a\u7cfb\u7edf\u8c03\u7528\u6210\u529f\uff0c\u8d1f\u6570\u8868\u793a\u51fa\u9519\uff0c\u5b58\u653e\u4e8eerrno
\u5168\u5c40\u53d8\u91cf\u4e2d\u3002
\u7cfb\u7edf\u8c03\u7528\u5904\u7406\u6d41\u7a0b\u662f\uff1a
\u5c06\u7cfb\u7edf\u8c03\u7528\u7684\u53c2\u6570\u5199\u5165CPU\u5bc4\u5b58\u5668 \u68c0\u67e5\u6240\u6709\u7684\u7cfb\u7edf\u8c03\u7528\u53c2\u6570 \u5c06CPU\u4e2d\u7684\u53c2\u6570\u62f7\u8d1d\u81f3\u5185\u6838\u6001\u5806\u6808 \u8c03\u7528\u540d\u4e3a\u7cfb\u7edf\u8c03\u7528\u670d\u52a1\u4f8b\u7a0b\uff08system call service routine\uff09\u7684C\u51fd\u6570\u6765\u5904\u7406\u7cfb\u7edf\u8c03\u7528 \u9000\u51fa\u7cfb\u7edf\u8c03\u7528\u5904\u7406\u7a0b\u5e8f\uff0c\u5c06\u5185\u6838\u6808\u4e2d\u7684\u503c\u52a0\u8f7d\u81f3\u5bc4\u5b58\u5668\uff0c\u5e76\u4ece\u5185\u6838\u6001\u5207\u6362\u56de\u7528\u6237\u6001 \u4e3a\u4e86\u5c06\u7cfb\u7edf\u8c03\u7528\u53f7\u4e0e\u5bf9\u5e94\u7684\u670d\u52a1\u4f8b\u7a0b\u8054\u7cfb\u8d77\u6765\uff0c\u5185\u6838\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7cfb\u7edf\u8c03\u7528\u5206\u6d3e\u8868\uff08system call dispatch table\uff09\uff0c\u8fd9\u4e2a\u8868\u5b58\u653e\u5728sys_call_table
\u6570\u7ec4\u4e2d\u3002\u5185\u6838\u62ff\u5230\u7cfb\u7edf\u8c03\u7528\u53f7\u4e4b\u540e\uff0c\u5c31\u53bbsys_call_table
\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u7cfb\u7edf\u8c03\u7528\u5b9e\u73b0\u51fd\u6570\u53bb\u6267\u884c\u3002\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u4f7f\u7528\u8fd4\u56de\u6307\u4ee4\u4ece\u5185\u6838\u6001\u8fd4\u56de\u81f3\u7528\u6237\u6001\u3002
\u5185\u6838\u5728\u6267\u884c\u7cfb\u7edf\u8c03\u7528\u7684\u65f6\u5019\u5904\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u3002current
\u6307\u9488\u6307\u5411\u5f53\u524d\u4efb\u52a1\uff0c\u5373\u5f15\u53d1\u7cfb\u7edf\u8c03\u7528\u7684\u90a3\u4e2a\u8fdb\u7a0b\u3002\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\uff0c\u5185\u6838\u53ef\u4ee5\u4f11\u7720\u5e76\u4e14\u53ef\u4ee5\u88ab\u62a2\u5360\u3002\u56e0\u6b64\u5fc5\u987b\u4fdd\u8bc1\u7cfb\u7edf\u8c03\u7528\u65f6\u53ef\u91cd\u5165\u7684\uff0c\u56e0\u4e3a\u65b0\u7684\u8fdb\u7a0b\u53ef\u80fd\u4f1a\u4f7f\u7528\u76f8\u540c\u7684\u7cfb\u7edf\u8c03\u7528\u3002
"},{"location":"linux/kernel/others/#_3","title":"\u4fe1\u53f7","text":"\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u4e3a\u4e86\u54cd\u5e94\u5404\u79cd\u4e8b\u4ef6\u5b9a\u4e49\u4e86\u975e\u5e38\u591a\u7684\u4fe1\u53f7\u3002\u6bd4\u5982\u5f53\u6211\u4eec\u53d1\u9001kill -9 ${pid}
\u65f6\uff0c\u5176\u5b9e\u5c31\u662f\u53d1\u9001SIGKILL\u4fe1\u53f7\u7ed9\u6307\u5b9a\u8fdb\u7a0b\uff0c\u5c06\u5b83\u6740\u6b7b\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7kill -l
\u547d\u4ee4\u67e5\u770b\u6240\u6709\u7684\u4fe1\u53f7\u3002\u6bcf\u4e2a\u4fe1\u53f7\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684ID\u548c\u5bf9\u5e94\u7684\u9ed8\u8ba4\u64cd\u4f5c\u3002
\u8fdb\u7a0b\u5bf9\u4fe1\u53f7\u7684\u5904\u7406\u65b9\u5f0f\u6709\u4e09\u79cd\uff1a
\u6267\u884c\u9ed8\u8ba4\u64cd\u4f5c\u3002 \u81ea\u5b9a\u4e49\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002 \u5ffd\u7565\u4fe1\u53f7\u3002\u6ce8\u610f\uff0cSIGKILL\u548cSIGSTOP\u65e0\u6cd5\u5ffd\u7565\u3002 Linux\u63a8\u8350\u4f7f\u7528sigaction()
\u51fd\u6570\u6765\u81ea\u5b9a\u4e49\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);\n
\u800csigaction\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
struct sigaction {\n __sighandler_t sa_handler;\n unsigned long sa_flags;\n __sigrestore_t sa_restorer;\n sigset_t sa_mask; \n};\n
\u5176\u4e2dsa_handler
\u5c31\u662f\u4f60\u8981\u5b9a\u4e49\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002
\u53d1\u9001\u4fe1\u53f7\u7531\u4e24\u79cd\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u53d1\u9001\u7ed9\u6574\u4e2a\u7ebf\u7a0b\u7ec4\u7684\uff0c\u8fd8\u6709\u4e00\u79cd\u662f\u53d1\u9001\u7ed9\u67d0\u4e2a\u5355\u72ec\u7ebf\u7a0b\u7684\u3002\u4fe1\u53f7\u5206\u4e3a\u4e0d\u53ef\u9760\u4fe1\u53f7\u548c\u53ef\u9760\u4fe1\u53f7\u3002\u5728task_struct
\u4e2d\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53sigpending
\uff0c\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
struct sigpending{\n struct list_head list;\n sigset_t signal;\n};\n
\u5bf9\u4e8e\u4e0d\u53ef\u9760\u4fe1\u53f7\uff0c\u4e5f\u5c31\u662f\u7f16\u53f7\u5c0f\u4e8e32\u7684\u4fe1\u53f7\uff0c\u4f1a\u653e\u5728sigset_t
\u96c6\u5408\u4e2d\uff0c\u4e0d\u8bba\u53d1\u9001\u591a\u5c11\u6b21\uff0c\u5728\u88ab\u5904\u7406\u524d\u90fd\u53ea\u4f1a\u4fdd\u7559\u4e00\u4efd\u3002\u5bf9\u4e8e\u53ef\u9760\u4fe1\u53f7\uff0c\u5219\u4f1a\u6302\u5728struct sigpending
\u7684\u94fe\u8868\u4e2d\u6328\u4e2a\u5904\u7406\u3002
"},{"location":"linux/kernel/others/#_4","title":"\u5b9a\u65f6\u5668","text":"\u5185\u6838\u4e2d\u6709\u5927\u91cf\u7684\u51fd\u6570\u662f\u57fa\u4e8e\u65f6\u95f4\u9a71\u52a8\u7684\u3002\u6709\u4e9b\u51fd\u6570\u9700\u8981\u5468\u671f\u6027\u6267\u884c\uff0c\u6709\u4e9b\u51fd\u6570\u9700\u8981\u7b49\u5f85\u4e00\u4e2a\u76f8\u5bf9\u65f6\u95f4\u540e\u624d\u8fd0\u884c\u3002\u5468\u671f\u6027\u7684\u4e8b\u4ef6\u7531\u7cfb\u7edf\u5b9a\u65f6\u5668\u9a71\u52a8\u3002\u7cfb\u7edf\u5b9a\u65f6\u5668\u80fd\u4ee5\u56fa\u5b9a\u7684\u9891\u7387\u4ea7\u751f\u4e2d\u65ad\uff0c\u8fd9\u79cd\u4e2d\u65ad\u88ab\u79f0\u4e3a\u5b9a\u65f6\u5668\u4e2d\u65ad\uff0c\u5b83\u6240\u5bf9\u5e94\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8d1f\u8d23\u66f4\u65b0\u7cfb\u7edf\u65f6\u95f4\u548c\u6267\u884c\u5468\u671f\u6027\u4efb\u52a1\u3002
\u7cfb\u7edf\u5b9a\u65f6\u5668\u7684\u9891\u7387\u88ab\u79f0\u4e3a\u8282\u62cd\u7387\uff08tick rate\uff09\uff0c\u4ea7\u751f\u7684\u4e24\u6b21\u65f6\u949f\u4e2d\u65ad\u7684\u95f4\u9694\u5c31\u88ab\u79f0\u4e3a\u8282\u62cd\uff08tick\uff09\uff0c\u5b83\u7b49\u4e8e\u8282\u62cd\u7387\u5206\u4e4b\u4e00\u79d2\u3002\u5185\u6838\u901a\u8fc7\u65f6\u949f\u4e2d\u65ad\u95f4\u9694\u6765\u8ba1\u7b97\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\u3002\u65f6\u949f\u4e2d\u65ad\u9700\u8981\u6267\u884c\u7684\u64cd\u4f5c\u6709\uff1a
\u66f4\u65b0\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4 \u66f4\u65b0\u5b9e\u9645\u65f6\u95f4 \u5728smp\u7cfb\u7edf\u4e0a\uff0c\u5747\u8861\u8c03\u5ea6\u7a0b\u5e8f\u4e2d\u5404\u5904\u7406\u5668\u4e0a\u7684\u8fd0\u884c\u961f\u5217 \u68c0\u67e5\u5f53\u524d\u8fdb\u7a0b\u662f\u5426\u7528\u5c3d\u4e86\u81ea\u5df1\u7684\u65f6\u95f4\u7247 \u8fd0\u884c\u8d85\u65f6\u7684\u52a8\u6001\u5b9a\u65f6\u5668 \u66f4\u65b0\u8d44\u6e90\u6d88\u8017\u548c\u5904\u7406\u5668\u65f6\u95f4\u7684\u7edf\u8ba1\u503c "},{"location":"linux/kernel/others/#jiffies","title":"\u8282\u62cd\u7387\u548cjiffies\u53d8\u91cf","text":"\u7cfb\u7edf\u5b9a\u65f6\u5668\u9891\u7387\u662f\u901a\u8fc7\u9759\u6001\u9884\u5904\u7406\u5b9a\u4e49\u7684\uff0c\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u6309\u7167HZ\u7684\u503c\u5bf9\u786c\u4ef6\u8fdb\u884c\u8bbe\u7f6e\uff0c\u8be5\u503c\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u3002\u5185\u6838\u5728<asm/param.h>\u6587\u4ef6\u4e2d\u5b9a\u4e49\u3002\u5728x86\u4f53\u7cfb\u7ed3\u6784\u4e2d\uff0c\u7cfb\u7edf\u5b9a\u65f6\u5668\u9891\u7387\u9ed8\u8ba4\u4e3a100\u3002\u4e5f\u5c31\u662f\u8bf4x86\u7684\u65f6\u949f\u4e2d\u65ad\u9891\u7387\u4e3a100HZ\uff0c\u5373\u6bcf\u79d2\u4e2d\u65ad100\u6b21\uff08\u6bcf10ms\u4ea7\u751f\u4e00\u6b21\uff09\u3002
\u65f6\u949f\u4e2d\u65ad\u9891\u7387\u5e94\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u7406\u60f3\u7684\u503c\uff0c\u9ad8HZ\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\uff0c\u4f7f\u5f97\u7531\u65f6\u95f4\u9a71\u52a8\u7684\u4e8b\u4ef6\u66f4\u4e3a\u7cbe\u786e\u3002\u4f46\u540c\u65f6\u4e5f\u5e26\u6765\u4e86\u989d\u5916\u7684\u7cfb\u7edf\u8d1f\u62c5\uff0c\u56e0\u4e3a\u5904\u7406\u5668\u4f1a\u88ab\u66f4\u9891\u7e41\u5730\u6253\u65ad\u53bb\u6267\u884c\u65f6\u949f\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002
\u5168\u5c40\u53d8\u91cfjiffies
\u7528\u6765\u8bb0\u5f55\u7cfb\u7edf\u542f\u52a8\u4ee5\u6765\u4ea7\u751f\u7684\u8282\u62cd\u603b\u6570\u3002\u5185\u6838\u5728\u542f\u52a8\u65f6\u5c06\u8be5\u53d8\u91cf\u521d\u59cb\u5316\u4e3a0\uff0c\u6b64\u540e\u6bcf\u4ea7\u751f\u4e00\u6b21\u65f6\u949f\u4e2d\u65ad\u8be5\u503c\u5c31+1\u3002\u56e0\u4e3a\u4e00\u79d2\u5185\u65f6\u949f\u4e2d\u65ad\u7684\u6b21\u6570\u7b49\u4e8eHZ\uff0c\u6240\u4ee5jiffies
\u4e00\u79d2\u5185\u589e\u52a0\u7684\u503c\u4e5f\u5c31\u4e3aHZ\u3002\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\u4ee5\u79d2\u4e3a\u8ba1\uff0c\u5176\u503c\u7b49\u4e8ejiffies/HZ\u3002
jiffies
\u53d8\u91cf\u88ab\u5b9a\u4e49\u4e3aunsigned long\u7c7b\u578b\u3002\u572832\u4f4d\u4f53\u7cfb\u7ed3\u6784\u4e0a\u662f32\u4f4d\u3002\u5982\u679c\u65f6\u949f\u9891\u7387\u4e3a100HZ\uff0c\u90a3\u4e48497\u5929\u540e\u4f1a\u6ea2\u51fa\u3002\u5982\u679c\u662f64\u4f4d\u4f53\u7cfb\u7ed3\u6784\uff0c\u4efb\u4f55\u4eba\u90fd\u522b\u6307\u671b\u4f1a\u770b\u5230\u5b83\u6ea2\u51fa\u3002
\u5f53jiffies
\u53d8\u91cf\u7684\u503c\u8d85\u8fc7\u5b83\u7684\u6700\u5927\u5b58\u653e\u8303\u56f4\u540e\u5c31\u4f1a\u53d1\u751f\u6ea2\u51fa\uff0c\u6b64\u65f6\u518d\u7ee7\u7eed\u589e\u52a0\u7684\u8bdd\uff0c\u5b83\u4f1a\u56de\u7ed5\u81f30\u3002\u4e3a\u4e86\u89e3\u51b3jiffies
\u53d8\u91cf\u7684\u6ea2\u51fa\u95ee\u9898\uff0c\u5185\u6838\u5f15\u5165\u4e86jiffies_64
\u53d8\u91cf\uff0c\u8fd9\u662f\u4e00\u4e2a64\u4f4d\u7684\u65e0\u7b26\u53f7\u6574\u6570\u3002
"},{"location":"linux/kernel/others/#_5","title":"\u52a8\u6001\u5b9a\u65f6\u5668","text":"\u5b9a\u65f6\u5668\u7684\u4f7f\u7528\u5f88\u7b80\u5355\u3002\u4f60\u53ea\u9700\u8981\u6267\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u5de5\u4f5c\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u6307\u5b9a\u8d85\u65f6\u53d1\u751f\u540e\u9700\u8981\u6267\u884c\u7684\u51fd\u6570\uff0c\u7136\u540e\u6fc0\u6d3b\u5b9a\u65f6\u5668\u5c31\u53ef\u4ee5\u4e86\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7ec4\u4e0e\u5b9a\u65f6\u5668\u76f8\u5173\u7684\u63a5\u53e3\u7528\u6765\u7b80\u5316\u5b9a\u65f6\u5668\u7684\u64cd\u4f5c\u3002
\u521b\u5efa\u5b9a\u65f6\u5668\uff1a
struct timer_list my_timer;\n
\u521d\u59cb\u5316\u5b9a\u65f6\u5668\uff1a
init_timer(&my_timer);\n
\u586b\u5145\u5b9a\u65f6\u5668\u7ed3\u6784\u4e2d\u7684\u503c\uff1a
my_timer.expires = jiffies + delay; //\u5b9a\u65f6\u5668\u8d85\u65f6\u8282\u62cd\u6570\nmy_timer.data = 0; //\u5b9a\u65f6\u5668\u5904\u7406\u51fd\u6570\u4f20\u5165\u7684\u503c\nmy_timer.function = my_function; //\u5b9a\u65f6\u5668\u8d85\u65f6\u56de\u8c03\u51fd\u6570\n
\u5982\u679c\u5f53\u524djiffies
\u8ba1\u6570\u5927\u4e8e\u6216\u7b49\u4e8emy_timer.expires\u7684\u503c\uff0c\u90a3\u4e48my_timer.function\u6307\u5411\u7684\u5904\u7406\u51fd\u6570\u5c31\u4f1a\u88ab\u6267\u884c\u3002\u5904\u7406\u51fd\u6570\u5fc5\u987b\u7b26\u5408\u4ee5\u4e0b\u7c7b\u578b\uff1a
void my_function(unsigned long data);\n
\u5176\u4e2ddata\u53c2\u6570\u4f7f\u4f60\u53ef\u4ee5\u5229\u7528\u540c\u4e00\u4e2a\u5904\u7406\u51fd\u6570\u6ce8\u518c\u591a\u4e2a\u5b9a\u65f6\u5668\uff0c\u53ea\u9700\u8981\u901a\u8fc7\u8be5\u53c2\u6570\u5c31\u53ef\u4ee5\u533a\u522b\u5bf9\u5f85\u5b83\u4eec\u3002\u5982\u679c\u4f60\u4e0d\u9700\u8981\u8fd9\u4e2a\u53c2\u6570\uff0c\u76f4\u63a5\u4f200\u5373\u53ef\u3002
\u6700\u540e\uff0c\u4f60\u5fc5\u987b\u624b\u52a8\u6fc0\u6d3b\u5b9a\u65f6\u5668\uff1a
add_timer(&my_timer);\n
\u4e00\u822c\u6765\u8bf4\uff0c\u5b9a\u65f6\u5668\u90fd\u4f1a\u5728\u8d85\u65f6\u540e\u9a6c\u4e0a\u6267\u884c\uff0c\u4f46\u4e5f\u6709\u53ef\u80fd\u4f1a\u63a8\u8fdf\u5230\u4e0b\u4e00\u4e2a\u65f6\u949f\u8282\u62cd\u65f6\u624d\u8fd0\u884c\uff0c\u6240\u4ee5\u4e0d\u80fd\u7528\u5b9a\u65f6\u5668\u6765\u5b9e\u73b0\u4efb\u4f55\u786c\u5b9e\u65f6\u7684\u4efb\u52a1\u3002\u5982\u679c\u9700\u8981\u4fee\u6539\u5b9a\u65f6\u5668\u8d85\u65f6\u65f6\u95f4\uff0c\u53ef\u4ee5\u901a\u8fc7mod_timer()
\u51fd\u6570\u6765\u5b9e\u73b0\uff1a
mod_timer(&my_timer, jiffies + new_delay);\n
\u5982\u679c\u5728\u5b9a\u65f6\u5668\u8d85\u65f6\u524d\u505c\u6b62\u5b9a\u65f6\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528del_timer()
\u51fd\u6570\uff1a
del_timer(&my_timer);\n
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u591a\u5904\u7406\u5668\u7cfb\u7edf\u4e2d\uff0c\u5220\u9664\u5b9a\u65f6\u5668\u65f6\u53ef\u80fd\u9700\u8981\u7b49\u5f85\u5728\u5176\u4ed6\u5904\u7406\u5668\u4e0a\u8fd0\u884c\u7684\u5b9a\u65f6\u5668\u5904\u7406\u7a0b\u5e8f\u90fd\u9000\u51fa\uff0c\u8fd9\u65f6\u9700\u8981\u7528\u5230del_timer_syn()
\u51fd\u6570\u6765\u6267\u884c\u5220\u9664\u5de5\u4f5c\u3002
"},{"location":"linux/kernel/others/#_6","title":"\u5ef6\u8fdf\u6267\u884c","text":"\u5185\u6838\u4ee3\u7801\u5f80\u5f80\u9700\u8981\u63a8\u8fdf\u67d0\u4e9b\u4efb\u52a1\u7684\u6267\u884c\uff0c\u8fd9\u79cd\u63a8\u8fdf\u901a\u5e38\u53d1\u751f\u5728\u7b49\u5f85\u786c\u4ef6\u5b8c\u6210\u67d0\u4e9b\u5de5\u4f5c\uff0c\u800c\u4e14\u7b49\u5f85\u65f6\u95f4\u5f80\u5f80\u975e\u5e38\u77ed\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u591a\u79cd\u5ef6\u8fdf\u65b9\u6cd5\u6765\u5904\u7406\u5ef6\u8fdf\u8bf7\u6c42\u3002
\u6700\u7b80\u5355\u7684\u5ef6\u8fdf\u65b9\u6cd5\u5c31\u662f\u5fd9\u7b49\u5f85\u3002\u8be5\u65b9\u6cd5\u4ec5\u4ec5\u5728\u60f3\u8981\u5ef6\u8fdf\u7684\u65f6\u95f4\u662f\u8282\u62cd\u7684\u6574\u6570\u500d\uff0c\u6216\u8005\u7cbe\u786e\u7387\u8981\u6c42\u4e0d\u9ad8\u7684\u60c5\u51b5\u4e0b\u624d\u53ef\u4ee5\u4f7f\u7528\u3002\u5fd9\u7b49\u5f85\u7684\u5b9e\u73b0\u975e\u5e38\u7b80\u5355\u2014\u2014\u5728\u4e00\u4e2a\u5faa\u73af\u4e2d\u4e0d\u65ad\u7b49\u5f85\u76f4\u5230\u5e0c\u671b\u7684\u65f6\u949f\u8282\u62cd\u6570\u8017\u5c3d\uff0c\u6bd4\u5982\uff1a
unsigned long timeout = jiffies + 10; //\u7b49\u5f8510\u4e2a\u8282\u62cd\nwhile(time_before(jiffies, timeout))\n{}\n
\u8be5\u5faa\u73af\u5c06\u4e0d\u65ad\u6267\u884c\uff0c\u76f4\u5230jiffies
\u5927\u4e8edelay\u4e3a\u6b62\u3002\u8fd9\u662f\u4e00\u79cd\u4f4e\u6548\u7684\u529e\u6cd5\uff0c \u56e0\u4e3a\u5904\u7406\u5668\u9664\u4e86\u7b49\u5f85\u4e0d\u4f1a\u505a\u4efb\u4f55\u4e8b\u60c5\uff0c\u66f4\u597d\u7684\u65b9\u6848\u662f\u5728\u7b49\u5f85\u65f6\uff0c\u5141\u8bb8\u5185\u6838\u91cd\u65b0\u8c03\u5ea6\u6267\u884c\u5176\u4ed6\u4efb\u52a1\u3002
\u57fa\u4e8ejiffies
\u7684\u5ef6\u8fdf\u65b9\u6cd5\u53d7\u9650\u4e8e\u65f6\u949f\u8282\u62cd\uff0c\u65e0\u6cd5\u63d0\u4f9b\u66f4\u77ed\u3001\u66f4\u7cbe\u786e\u7684\u5ef6\u8fdf\u8981\u6c42\u3002\u4e3a\u6b64\uff0c\u5185\u6838\u63d0\u4f9b\u4e86\u4e09\u4e2a\u53ef\u4ee5\u5904\u7406us\u3001ns\u548cms\u7ea7\u522b\u7684\u5ef6\u8fdf\u51fd\u6570\uff1a
void udelay(unsigned long usecs)\nvoid ndelay(unsigned long nsecs)\nvoid mdelay(unsigned long msecs)\n
\u66f4\u7406\u60f3\u7684\u5ef6\u8fdf\u6267\u884c\u65b9\u6cd5\u662f\u4f7f\u7528schedule_timeout()
\u51fd\u6570\uff0c\u8be5\u65b9\u6cd5\u8ba9\u9700\u8981\u5ef6\u8fdf\u6267\u884c\u7684\u4efb\u52a1\u7761\u7720\u5230\u6307\u5b9a\u5ef6\u8fdf\u65f6\u95f4\u8017\u5c3d\u540e\u518d\u91cd\u65b0\u8fd0\u884c\u3002\u5176\u7528\u6cd5\u5982\u4e0b\uff1a
set_current_state(TASK_INTERRUPTIBLE);\nschedule_timeout(s * HZ);\n
\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5f53\u524d\u4efb\u52a1\u63a8\u5165\u53ef\u4e2d\u65ad\u7761\u7720\u961f\u5217\uff0c\u7761\u7720s\u79d2\u540e\u5524\u9192\u3002\u6ce8\u610f\uff0c\u7531\u4e8eschedule_timeout()
\u51fd\u6570\u9700\u8981\u8c03\u7528\u8c03\u5ea6\u7a0b\u5e8f\uff0c\u6240\u4ee5\u8c03\u7528\u5b83\u7684\u4ee3\u7801\u5fc5\u987b\u4fdd\u8bc1\u80fd\u591f\u7761\u7720\u3002\u4e5f\u5c31\u662f\u8c03\u7528\u51fd\u6570\u5fc5\u987b\u4f4d\u4e8e\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\uff0c\u4e14\u4e0d\u80fd\u6301\u6709\u9501\u3002
\u5f53\u4efb\u52a1\u88ab\u91cd\u65b0\u8c03\u5ea6\u65f6\uff0c\u5c06\u8fd4\u56de\u4ee3\u7801\u8fdb\u5165\u7761\u7720\u524d\u7684\u4f4d\u7f6e\u7ee7\u7eed\u6267\u884c\u3002\u5982\u679c\u4efb\u52a1\u63d0\u524d\u88ab\u5524\u9192\uff0c\u90a3\u4e48\u5b9a\u65f6\u5668\u88ab\u64a4\u9500\u3002
"},{"location":"linux/kernel/others/#_7","title":"\u9875\u9ad8\u901f\u7f13\u5b58\u4e0e\u9875\u56de\u5199","text":"\u9875\u9ad8\u901f\u7f13\u5b58\u662f\u4e00\u79cd\u628a\u78c1\u76d8\u7684\u6570\u636e\u7f13\u5b58\u5230\u7269\u7406\u5185\u5b58\u4e2d\u7684\u673a\u5236\uff0c\u4f7f\u5f97\u5bf9\u78c1\u76d8\u7684\u8bbf\u95ee\u53d8\u4e3a\u5bf9\u7269\u7406\u5185\u5b58\u7684\u8bbf\u95ee\u3002\u9ad8\u901f\u7f13\u5b58\u7684\u91cd\u8981\u6027\u4f53\u73b0\u5728\uff1a
\u8bbf\u95ee\u78c1\u76d8\u7684\u901f\u5ea6\u8fdc\u8fdc\u4f4e\u4e8e\u8bbf\u95ee\u5185\u5b58\u7684\u901f\u5ea6\u3002
\u6570\u636e\u4e00\u65e6\u88ab\u8bbf\u95ee\uff0c\u5c31\u5f88\u6709\u53ef\u80fd\u5728\u77ed\u671f\u5185\u518d\u6b21\u88ab\u8bbf\u95ee\u3002\u8fd9\u5c31\u662f\u5c40\u90e8\u6027\u539f\u7406\u3002
\u5f53\u5185\u6838\u5f00\u59cb\u4e00\u4e2a\u8bfb\u64cd\u4f5c\uff0c\u5b83\u9996\u5148\u4f1a\u68c0\u67e5\u9700\u8981\u7684\u6570\u636e\u662f\u5426\u5728\u9875\u9ad8\u901f\u7f13\u5b58\u4e2d\u3002\u5982\u679c\u5728\uff0c\u653e\u5f03\u8bbf\u95ee\u78c1\u76d8\uff0c\u800c\u76f4\u63a5\u4ece\u5185\u5b58\u4e2d\u8bfb\u53d6\u3002\u8fd9\u4e2a\u884c\u4e3a\u79f0\u4e3a\u7f13\u5b58\u547d\u4e2d\uff08cache hit\uff09\u3002\u5426\u5219\u79f0\u4e3a\u7f13\u5b58\u672a\u547d\u4e2d\uff08cache miss\uff09\uff0c\u90a3\u4e48\u5185\u6838\u5fc5\u987b\u8c03\u5ea6\u5757I/O\u64cd\u4f5c\u53bb\u78c1\u76d8\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u7136\u540e\u5c06\u6570\u636e\u653e\u5165\u9875\u7f13\u5b58\u4e2d\u3002\u5185\u6838\u91c7\u7528\u9884\u8bfb\u673a\u5236\uff1a\u5373\u5f53\u4ece\u78c1\u76d8\u4e2d\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u7531\u4e8e\u78c1\u76d8\u7684\u8bfb\u5199\u5355\u4f4d\u4e3ablock\uff084KB\uff09\uff0c\u51fa\u4e8e\u7a7a\u95f4\u5c40\u90e8\u6027\u539f\u7406\uff0c\u5185\u6838\u4f1a\u5c06\u591a\u4e2ablock\u7684\u6570\u636e\u90fd\u52a0\u5165\u5230\u7f13\u5b58\u4e2d\u3002
"},{"location":"linux/kernel/others/#_8","title":"\u5199\u7f13\u5b58\u7b56\u7565","text":"\u5728\u8fdb\u7a0b\u5199\u78c1\u76d8\u65f6\uff0c\u7f13\u5b58\u7684\u4f7f\u7528\u4e00\u822c\u6709\u4ee5\u4e0b\u4e09\u79cd\uff1a
\u4e0d\u7f13\u5b58\uff1a\u4e5f\u5c31\u662f\u8bf4\u9ad8\u901f\u7f13\u5b58\u4e0d\u7f13\u5b58\u4efb\u4f55\u5199\u64cd\u4f5c\uff0c\u800c\u662f\u76f4\u63a5\u5199\u5165\u78c1\u76d8\u3002\u8fd9\u79cd\u65b9\u5f0f\u5f88\u5c11\u91c7\u7528\uff0c\u56e0\u4e3a\u6027\u80fd\u975e\u5e38\u5dee\u3002
\u5199\u64cd\u4f5c\u81ea\u52a8\u66f4\u65b0\u7f13\u5b58\uff0c\u540c\u65f6\u4e5f\u66f4\u65b0\u78c1\u76d8\u6587\u4ef6\uff1a\u8fd9\u79cd\u7b56\u7565\u5bf9\u7f13\u5b58\u4e00\u81f4\u6027\u975e\u5e38\u6709\u6548\uff0c\u56e0\u4e3a\u5185\u5b58\u7f13\u5b58\u59cb\u7ec8\u548c\u78c1\u76d8\u4e00\u81f4\u3002
Linux\u91c7\u7528\u7684\u2014\u2014\u56de\u5199\uff1a\u5199\u64cd\u4f5c\u5199\u5165\u7f13\u5b58\uff0c\u4f46\u662f\u78c1\u76d8\u5e76\u4e0d\u7acb\u523b\u66f4\u65b0\uff0c\u800c\u662f\u5c06\u9875\u9ad8\u901f\u7f13\u5b58\u4e2d\u88ab\u5199\u5165\u7684\u9875\u9762\u6807\u8bb0\u4e3a\u201c\u810f\u201d\uff0c\u7136\u540e\u52a0\u5165\u5230\u810f\u9875\u5217\u8868\u4e2d\u3002\u7531\u4e00\u4e2a\u56de\u5199\u8fdb\u7a0b\u5468\u671f\u6027\u7684\u5c06\u810f\u9875\u94fe\u8868\u4e2d\u7684\u9875\u56de\u5199\u81f3\u78c1\u76d8\uff0c\u6700\u540e\u6e05\u7406\u810f\u9875\u6807\u8bc6\u3002
"},{"location":"linux/kernel/others/#_9","title":"\u7f13\u5b58\u56de\u6536\u7b56\u7565","text":"\u7531\u4e8e\u5927\u91cf\u7684\u9875\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\uff0c\u5fc5\u7136\u5bfc\u81f4\u53ef\u7528\u5185\u5b58\u7684\u4e0b\u964d\u3002\u4e3a\u4e86\u4fdd\u8bc1\u5185\u5b58\u7684\u6b63\u5e38\u4f7f\u7528\uff0c\u5fc5\u987b\u6709\u4e00\u79cd\u673a\u5236\u53ef\u4ee5\u56de\u6536\u7f13\u5b58\u3002Linux\u7684\u7f13\u5b58\u56de\u6536\u662f\u5979\u901a\u8fc7\u9009\u62e9\u5e72\u51c0\u9875\u8fdb\u884c\u7b80\u5355\u66ff\u6362\u3002\u5982\u679c\u7f13\u5b58\u4e2d\u6ca1\u6709\u8db3\u591f\u7684\u5e72\u51c0\u9875\uff0c\u5185\u6838\u5c06\u5f3a\u5236\u6027\u7684\u8fdb\u884c\u56de\u5199\u64cd\u4f5c\uff0c\u4ee5\u817e\u51fa\u66f4\u591a\u7684\u5e72\u51c0\u9875\u4f7f\u7528\u3002
\u4e00\u79cd\u56de\u6536\u7b56\u7565\u88ab\u79f0\u4e3a\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u7b97\u6cd5\uff0c\u7b80\u79f0LRU\uff08Least Recently Used\uff09\u3002LRU\u7b97\u6cd5\u4e00\u822c\u662f\u7528\u94fe\u8868\u4f5c\u4e3a\u6570\u636e\u7ed3\u6784\u6765\u5b9e\u73b0\u7684\uff0c\u94fe\u8868\u5934\u90e8\u7684\u6570\u636e\u662f\u6700\u8fd1\u4f7f\u7528\u7684\uff0c\u800c\u94fe\u8868\u672b\u5c3e\u7684\u6570\u636e\u662f\u6700\u4e45\u6ca1\u88ab\u4f7f\u7528\u7684\u3002\u5f53\u7a7a\u95f4\u4e0d\u591f\u65f6\uff0c\u5c31\u6dd8\u6c70\u6700\u4e45\u6ca1\u88ab\u4f7f\u7528\u7684\u8282\u70b9\uff0c\u4e5f\u5c31\u662f\u94fe\u8868\u672b\u5c3e\u7684\u6570\u636e\uff0c\u4ece\u800c\u817e\u51fa\u5185\u5b58\u7a7a\u95f4\u3002\u4f20\u7edf\u7684LRU\u7b97\u6cd5\u5bf9\u4e8e\u90a3\u4e9b\u53ea\u4f1a\u88ab\u8bbf\u95ee\u4e00\u6b21\u7684\u6587\u4ef6\u6548\u679c\u5c24\u5176\u5dee\u3002
Linux\u5185\u6838\u5bf9LRU\u7b97\u6cd5\u8fdb\u884c\u4e86\u6539\u8fdb\uff0c\u88ab\u79f0\u4e3a\u53cc\u94fe\u7b56\u7565\u2014\u2014\u7ef4\u62a4\u4e24\u4e2a\u94fe\u8868\uff1a\u6d3b\u8dc3\u94fe\u8868\uff08active list\uff09\u548c\u4e0d\u6d3b\u8dc3\u94fe\u8868\uff08inactive list\uff09\u3002\u5904\u4e8e\u6d3b\u8dc3\u94fe\u8868\u4e0a\u7684\u9875\u88ab\u8ba4\u4e3a\u662f\u201c\u70ed\u201d\u7684\u4e14\u4e0d\u4f1a\u6362\u51fa\uff0c\u5904\u4e8e\u4e0d\u6d3b\u8dc3\u94fe\u8868\u4e0a\u7684\u9875\u88ab\u8ba4\u4e3a\u662f\u201c\u51b7\u201d\u7684\u53ef\u4ee5\u88ab\u6362\u51fa\u3002\u9875\u9762\u4ece\u5c3e\u90e8\u52a0\u5165\uff0c\u4ece\u5934\u90e8\u79fb\u9664\uff0c\u5c31\u50cf\u961f\u5217\u4e00\u6837\u3002\u6709\u4e86\u8fd9\u4e24\u4e2aLRU\u94fe\u8868\u540e\uff0c\u9884\u8bfb\u9875\u5c31\u53ea\u9700\u8981\u52a0\u5165\u5230\u4e0d\u6d3b\u8dc3\u94fe\u8868\u7684\u5934\u90e8\uff0c\u5f53\u9875\u88ab\u771f\u6b63\u8bbf\u95ee\u7684\u65f6\u5019\uff0c\u624d\u5c06\u9875\u63d2\u5165\u5230\u6d3b\u8dc3\u94fe\u8868\u7684\u5934\u90e8\u3002\u5982\u679c\u9884\u8bfb\u7684\u9875\u4e00\u76f4\u6ca1\u6709\u88ab\u8bbf\u95ee\uff0c\u5c31\u4f1a\u4ece\u4e0d\u6d3b\u8dc3\u94fe\u8868\u4e2d\u79fb\u9664\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5f71\u54cd\u6d3b\u8dc3\u94fe\u8868\u4e2d\u7684\u70ed\u6570\u636e\u3002
"},{"location":"linux/kernel/sched/","title":"\u8fdb\u7a0b\u7ba1\u7406\u4e0e\u8c03\u5ea6","text":"\u8fdb\u7a0b\u5c31\u662f\u5904\u4e8e\u6267\u884c\u671f\u7684\u7a0b\u5e8f\uff0c\u5f53\u6211\u4eec\u5c06\u4ee3\u7801\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u65f6\uff0c\u8f93\u5165./a.out\uff0c\u6211\u4eec\u5c31\u5f00\u542f\u4e86\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u3002\u8fdb\u7a0b\u4ece\u78c1\u76d8\u52a0\u8f7d\u5230\u5185\u5b58\u7684\u8fc7\u7a0b\u8bf7\u53c2\u8003\u7a0b\u5e8f\u7684\u88c5\u8f7d\u3002
\u53ef\u4ee5\u628a\u4e00\u4e2a\u8fdb\u7a0b\u60f3\u8c61\u6210\u4e00\u4e2a\u5e9e\u5927\u7684\u9879\u76ee\u7ec4\uff0c\u5b83\u5305\u542b\u4e86\u5404\u79cd\u8d44\u6e90\uff0c\u4f8b\u5982\u6253\u5f00\u7684\u6587\u4ef6\u3001\u5360\u7528\u7684\u5185\u5b58\u3001\u5904\u7406\u5668\u7684\u72b6\u6001\u7b49\u3002\u800c\u7ebf\u7a0b\uff0c\u5c31\u50cf\u662f\u9879\u76ee\u7ec4\u4e2d\u8d1f\u8d23\u6267\u884c\u5177\u4f53\u4efb\u52a1\u7684\u4e2a\u4eba\u3002\u6b63\u5982\u6bcf\u4e2a\u9879\u76ee\u7ec4\u81f3\u5c11\u9700\u8981\u4e00\u4e2a\u4eba\u6765\u6267\u884c\u4efb\u52a1\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u5fc5\u987b\u6709\u4e00\u4e2a\u4e3b\u7ebf\u7a0b\u3002\u4f60\u53ef\u4ee5\u9009\u62e9\u5c06\u6240\u6709\u4efb\u52a1\u90fd\u4ea4\u7ed9\u4e3b\u7ebf\u7a0b\u6765\u5b8c\u6210\uff0c\u4f46\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f1a\u628a\u4e00\u4e2a\u5927\u7684\u4efb\u52a1\u5206\u89e3\u6210\u591a\u4e2a\u5c0f\u4efb\u52a1\uff0c\u5e76\u521b\u5efa\u989d\u5916\u7684\u7ebf\u7a0b\u6765\u5e76\u884c\u5904\u7406\u8fd9\u4e9b\u5c0f\u4efb\u52a1\u3002\u90a3\u4e48\uff0c\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u521b\u5efa\u66f4\u591a\u7684\u8fdb\u7a0b\u6765\u5904\u7406\u8fd9\u4e9b\u4efb\u52a1\u5462\uff1f\u4ece\u6280\u672f\u4e0a\u6765\u8bf4\uff0c\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u8fd9\u901a\u5e38\u5e76\u4e0d\u662f\u6700\u4f73\u9009\u62e9\u3002\u9996\u5148\uff0c\u8fdb\u7a0b\u5360\u7528\u7684\u8d44\u6e90\u6bd4\u7ebf\u7a0b\u591a\uff0c\u800c\u7ebf\u7a0b\u662f\u8f7b\u91cf\u7ea7\u7684\uff0c\u521b\u5efa\u7684\u901f\u5ea6\u8981\u5feb\u5f97\u591a\u3002\u5176\u6b21\uff0c\u8fdb\u7a0b\u4e4b\u95f4\u7684\u8d44\u6e90\u5171\u4eab\u76f8\u5bf9\u590d\u6742\uff0c\u800c\u7ebf\u7a0b\u7531\u4e8e\u5171\u4eab\u540c\u4e00\u8fdb\u7a0b\u7684\u8d44\u6e90\uff0c\u53ef\u4ee5\u66f4\u5bb9\u6613\u5730\u8bbf\u95ee\u8fd9\u4e9b\u8d44\u6e90\u3002\u8fd9\u5c31\u50cf\u662f\u5728\u4e00\u4e2a\u516c\u53f8\u7684\u4e0d\u540c\u9879\u76ee\u7ec4\u4e4b\u95f4\u8fdb\u884c\u5de5\u4f5c\u4ea4\u63a5\u53ef\u80fd\u4f1a\u5f88\u9ebb\u70e6\uff0c\u4f46\u5982\u679c\u5927\u5bb6\u90fd\u5c5e\u4e8e\u540c\u4e00\u4e2a\u9879\u76ee\u7ec4\uff0c\u5408\u4f5c\u5c31\u4f1a\u987a\u7545\u5f97\u591a\u3002
"},{"location":"linux/kernel/sched/#_2","title":"\u8fdb\u7a0b\u63cf\u8ff0\u7b26","text":"\u4e3a\u4e86\u7ba1\u7406\u8fdb\u7a0b\uff0c\u5185\u6838\u5fc5\u987b\u6e05\u6670\u5730\u63cf\u8ff0\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u3002\u5728Linux\u7cfb\u7edf\u4e0b\uff0c\u4e0d\u7ba1\u662f\u8fdb\u7a0b\u8fd8\u662f\u7ebf\u7a0b\uff0c\u5185\u6838\u7edf\u4e00\u7528task_struct
\u7ed3\u6784\u4f53\u7ba1\u7406\u3002
"},{"location":"linux/kernel/sched/#_3","title":"\u5185\u6838\u6808","text":"void *stack;\n
\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e00\u4e2a\u4e13\u7528\u7684\u5185\u6838\u6808\uff0c\u7528\u4e8e\u4fdd\u5b58\u8fdb\u7a0b\u5728\u5185\u6838\u6001\u6267\u884c\u65f6\u7684\u4e34\u65f6\u6570\u636e\u548c\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u5f53\u521b\u5efa\u65b0\u8fdb\u7a0b\u65f6\uff0c\u5185\u6838\u4f1a\u4e3a\u5176\u5206\u914d\u4e00\u4e2a\u5408\u9002\u5927\u5c0f\u7684\u5185\u6838\u6808\u7a7a\u95f4\uff0c\u5e76\u5c06\u5176\u5730\u5740\u8d4b\u7ed9task_struct
\u4e2d\u7684stack\u6210\u5458\u3002
"},{"location":"linux/kernel/sched/#_4","title":"\u7ebf\u7a0b\u63cf\u8ff0\u7b26","text":"\u7ebf\u7a0b\u63cf\u8ff0\u7b26thread_info
\u662f\u4e00\u4e2a\u7528\u4e8e\u5b58\u653e\u7ebf\u7a0b\u76f8\u5173\u4fe1\u606f\u7684\u7ed3\u6784\u4f53\uff0c\u5b83\u5305\u542b\u4e86\u5f88\u591a\u4e0e\u7ebf\u7a0b\u76f8\u5173\u7684\u5b57\u6bb5\uff0c\u5176\u4e2d\u6700\u91cd\u8981\u7684\u662ftask_struct *task
\uff0c\u5b83\u6307\u5411\u5f53\u524d\u7ebf\u7a0b\u6240\u5c5e\u7684\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u3002\u4e3a\u4e86\u65b9\u4fbf\u8bbf\u95ee\u5f53\u524dCPU\u4e0a\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u7684task_struct
\u7ed3\u6784\uff0c\u5185\u6838\u63d0\u4f9b\u4e86current
\u5b8f\uff0c\u8be5\u5b8f\u672c\u8d28\u4e0a\u7b49\u4e8e\uff1a
current_thread_info()->task\n
\u4e0a\u8ff0\u4ee3\u7801\u8fd4\u56de\u5f53\u524dtask_struct
\u7684\u5730\u5740\u3002
"},{"location":"linux/kernel/sched/#_5","title":"\u8fdb\u7a0b\u72b6\u6001","text":"\u5728task_struct
\u4e2d\uff0c\u6d89\u53ca\u5230\u8fdb\u7a0b\u72b6\u6001\u7684\u662f\u8fd9\u51e0\u4e2a\u6210\u5458\uff1a
volatile long state; \n int exit_state;\n unsigned int flags;\n
state\u53ef\u4ee5\u53d6\u7684\u503c\u6709\uff1a
/* Used in tsk->state: */\n#define TASK_RUNNING 0\n#define TASK_INTERRUPTIBLE 1\n#define TASK_UNINTERRUPTIBLE 2\n#define __TASK_STOPPED 4\n#define __TASK_TRACED 8\n/* Used in tsk->exit_state: */\n#define EXIT_DEAD 16\n#define EXIT_ZOMBIE 32\n#define EXIT_TRACE (EXIT_ZOMBIE | EXIT_DEAD)\n/* Used in tsk->state again: */\n#define TASK_DEAD 64\n#define TASK_WAKEKILL 128\n#define TASK_WAKING 256\n#define TASK_PARKED 512\n#define TASK_NOLOAD 1024\n#define TASK_NEW 2048\n#define TASK_STATE_MAX 4096\n
state\u5b57\u6bb5\u7684\u503c\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u8d4b\u503c\u8bed\u53e5\u8bbe\u7f6e\u3002
p->state = TASK_RUNNING;\n
\u4e5f\u53ef\u4ee5\u4f7f\u7528set_task_state
\u548cset_current_state
\u5b8f\uff1a\u5b83\u4eec\u5206\u522b\u8bbe\u7f6e\u6307\u5b9a\u8fdb\u7a0b\u7684\u72b6\u6001\u548c\u5f53\u524d\u6267\u884c\u8fdb\u7a0b\u7684\u72b6\u6001\u3002
TASK_RUNNING\u8868\u793a\u8fdb\u7a0b\u6b63\u5728\u6267\u884c\u6216\u8005\u51c6\u5907\u6267\u884c\u3002
\u5f53\u8fdb\u7a0b\u8fdb\u5165\u7761\u7720\u540e\uff0c\u6709\u4e24\u79cd\u72b6\u6001\uff1a
TASK_INTERRUPTIBLE\u8868\u793a\u8fdb\u7a0b\u53ef\u4ee5\u54cd\u5e94\u4fe1\u53f7\u3002\u4e5f\u5c31\u662f\u5f53\u4e00\u4e2a\u4fe1\u53f7\u6765\u4e34\u65f6\uff0c\u5524\u9192\u8be5\u8fdb\u7a0b\uff0c\u7136\u540e\u6267\u884c\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002
TASK_UNINTERRUPTIBLE\u8868\u793a\u8fdb\u7a0b\u4e0d\u53ef\u4ee5\u54cd\u5e94\u4fe1\u53f7\u3002\u5f53\u8fdb\u7a0b\u7b49\u5f85\u67d0\u4e2a\u4e8b\u4ef6\u5b8c\u6210\u800c\u8fdb\u5165\u6df1\u5ea6\u7761\u7720\u72b6\u6001\u65f6\uff0c\u5982\u679c\u8be5\u4e8b\u4ef6\u56e0\u4e3a\u67d0\u79cd\u539f\u56e0\u65e0\u6cd5\u5b8c\u6210\uff0c\u90a3\u4e48\u8fd9\u4e2a\u8fdb\u7a0b\u4e5f\u5c06\u6c38\u8fdc\u7761\u7720\u4e0b\u53bb\u3002
\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u5371\u9669\u7684\u4e8b\u60c5\uff0c\u9664\u975e\u5f88\u6709\u628a\u63e1\u4e0d\u7136\u4e0d\u4f1a\u8ba9\u8fdb\u7a0b\u8fdb\u5165\u6df1\u5ea6\u7761\u7720\u6001\u3002
\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u4e86\u4e00\u79cd\u65b0\u7684\u72b6\u6001\uff1aTASK_KILLABLE\uff0c\u53ef\u4ee5\u7ec8\u6b62\u7684\u6df1\u5ea6\u7761\u7720\u6001\u3002\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
#define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNITERRUPTIBLE)\n
\u5176\u4e2dTASK_WAKEKILL\u8868\u793a\u5728\u63a5\u6536\u5230\u81f4\u547d\u4fe1\u53f7\u65f6\uff0c\u5524\u9192\u8fdb\u7a0b\u3002
TASK_STOPPED\u8868\u793a\u8fdb\u7a0b\u88ab\u6682\u505c\uff0c\u5f53\u63a5\u6536\u5230SIGSTOP\u3001SIGTSTP\u3001SIGTTIN\u6216SIGTTOU\u4fe1\u53f7\u540e\uff0c\u8fdb\u5165\u8be5\u72b6\u6001\u3002
TASK_TRACED\u8868\u793a\u8fdb\u7a0b\u88ab\u8ddf\u8e2a\u3002\u8fd9\u5f80\u5f80\u662f\u8c03\u8bd5\u7a0b\u5e8f\u6682\u65f6\u7ec8\u6b62\u4e86\u8fdb\u7a0b\u7684\u8fd0\u884c\u3002
\u5185\u6838\u7ecf\u5e38\u9700\u8981\u8c03\u6574\u5f53\u524d\u8fdb\u7a0b\u7684\u72b6\u6001\uff0c\u53ef\u4ee5\u4f7f\u7528set_task_state(task, state)
\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u6307\u5b9a\u8fdb\u7a0b\u8bbe\u7f6e\u4e3a\u6307\u5b9a\u72b6\u6001\u3002
exit_state\u7684\u53d6\u503c\u6709\u4e24\u79cd\uff1a
EXIT_ZOMBIE\u8868\u793a\u50f5\u6b7b\u72b6\u6001\u3002\u4e00\u4e2a\u8fdb\u7a0b\u6267\u884c\u88ab\u7ec8\u6b62\uff0c\u4f46\u662f\u5176\u7236\u8fdb\u7a0b\u8fd8\u6ca1\u6709\u8c03\u7528wait4()
\u6216\u8005waitpid()
\u7cfb\u7edf\u8c03\u7528\u6765\u56de\u6536\u8d44\u6e90\u65f6\uff0c\u8fdb\u5165\u8be5\u72b6\u6001\u3002
EXIT_DEAD\u662f\u8fdb\u7a0b\u7684\u6700\u7ec8\u72b6\u6001\u3002\u7236\u8fdb\u7a0b\u56de\u6536\u5b50\u8fdb\u7a0b\u8d44\u6e90\u4e4b\u540e\uff0c\u8fdb\u7a0b\u7531\u7cfb\u7edf\u5220\u9664\u3002
\u8fdb\u7a0b\u7684\u4e00\u4e9b\u5176\u4ed6\u72b6\u6001\u4fe1\u606f\u7531flags
\u63a7\u5236\uff0c\u4f7f\u7528\u4f4d\u63a9\u7801\u6765\u8868\u793a\u4e0d\u540c\u7684\u6807\u8bb0\u3002\u4e00\u4e9b\u5e38\u89c1\u7684\u6807\u8bb0\u5305\u62ec\uff1a
\u4efb\u52a1\u72b6\u6001\uff1a\u4f8b\u5982\u662f\u5426\u6b63\u5728\u8fd0\u884c\u3001\u505c\u6b62\u7b49 \u8c03\u5ea6\u5668\u76f8\u5173\uff1a\u4f8b\u5982\u8c03\u5ea6\u7b56\u7565\u3001\u4f18\u5148\u7ea7\u7b49 \u4fe1\u53f7\u5904\u7406\uff1a\u4f8b\u5982\u6302\u8d77\u4fe1\u53f7\u96c6 \u8fdb\u7a0b\u7279\u6027\uff1a\u662f\u5426\u4e3a\u5b88\u62a4\u8fdb\u7a0b\u3001\u662f\u5426\u5141\u8bb8\u88ab\u8ffd\u8e2a\u7b49 flags\u6210\u5458\u7684\u4e00\u4e9b\u53d6\u503c\u4e3e\u4f8b\u5982\u4e0b\uff0c\u8fd9\u4e9b\u5b8f\u4ee5PF\u5f00\u5934\uff1a
#define PF_EXITING 0x00000004 //getting shut down\n#define PF_WQ_WORKER 0x00000020 //I'm a workqueue worker\n#define PF_KTHREAD 0x00200000 //I'm a kernel thread\n
"},{"location":"linux/kernel/sched/#_6","title":"\u8fdb\u7a0b\u6807\u8bc6","text":"Linux\u7cfb\u7edf\u4f7f\u7528PID\u6765\u6807\u8bc6\u4e00\u4e2a\u8fdb\u7a0b\uff0cPID\u88ab\u987a\u5e8f\u7f16\u53f7\uff0c\u65b0\u521b\u5efa\u7684\u8fdb\u7a0b\u7684PID\u901a\u5e38\u662f\u524d\u4e00\u4e2a\u8fdb\u7a0b+1\u3002\u4f46\u662fPID\u7684\u503c\u6709\u4e00\u4e2a\u4e0a\u9650\uff0c\u7cfb\u7edf\u7ba1\u7406\u5458\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539/proc/sys/kernel/pid_max\u6587\u4ef6\u7684\u503c\u6765\u6539\u53d8\u8fd9\u4e2a\u4e0a\u9650\u3002\u8fd9\u4e48\u4e00\u770b\u4f3c\u4e4e\u4e00\u4e2aPID\u6765\u552f\u4e00\u6807\u8bc6\u4e00\u4e2a\u8fdb\u7a0b\u5c31\u591f\u4e86\uff0c\u4f46\u662f\u5728task_struct
\u4e2d\uff0c\u6d89\u53ca\u5230\u8fdb\u7a0b\u6807\u8bc6\u7684\u6709\u4ee5\u4e0b\u51e0\u4e2a\u6210\u5458\u3002
pid_t pid;\npid_t tgid;\nstruct task_struct *group_leader; \n
\u4f60\u53ef\u80fd\u4f1a\u7591\u60d1\uff0c\u552f\u4e00\u6807\u8bc6\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u4e3a\u4ec0\u4e48\u9700\u8981\u7528\u5230\u8fd9\u4e48\u591a\u53d8\u91cf\uff1f\u8fd9\u662f\u56e0\u4e3a\u4e4b\u524d\u63d0\u5230\uff0c\u5728Linux\u7cfb\u7edf\u4e0b\uff0c\u8fdb\u7a0b\u4e0e\u7ebf\u7a0b\u5e76\u4e0d\u7279\u522b\u533a\u5206\uff0c\u90fd\u662f\u4e00\u4e2atask_struct
\u7ed3\u6784\u4f53\u3002\u8fd9\u5c31\u7ed9\u7ba1\u7406\u5e26\u6765\u4e86\u4e00\u4e9b\u9ebb\u70e6\u3002\u6bd4\u5982\u6211\u4eec\u5e0c\u671b\u540c\u5c5e\u4e8e\u4e00\u4e2a\u8fdb\u7a0b\u7ec4\u7684\u7ebf\u7a0b\u62e5\u6709\u5171\u540c\u7684pid\u3002\u5f53\u6211\u4eec\u53d1\u9001\u4e00\u4e2a\u4fe1\u53f7\u7ed9\u6307\u5b9apid\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u8fd9\u4e2a\u4fe1\u53f7\u80fd\u4f5c\u7528\u4e8e\u8be5\u7ec4\u4e2d\u7684\u6240\u6709\u7ebf\u7a0b\u3002\u5f53\u6740\u6b7b\u67d0\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u5f53\u7136\u662f\u8fde\u540c\u8be5\u8fdb\u7a0b\u4e0b\u7684\u6240\u6709\u7ebf\u7a0b\u4e00\u8d77\u6740\u6b7b\uff0c\u800c\u4e0d\u662f\u53ea\u6740\u6b7b\u4e86\u4e3b\u8fdb\u7a0b\uff0c\u5176\u4ed6\u7ebf\u7a0b\u8fd8\u5728\u5de5\u4f5c\uff0c\u8fd9\u663e\u7136\u4e0d\u5408\u5e38\u7406\u3002\u4e8b\u5b9e\u4e0a\uff0cPOSIX\u6807\u51c6\u4e5f\u89c4\u5b9a\u4e00\u4e2a\u591a\u7ebf\u7a0b\u5e94\u7528\u7a0b\u5e8f\u7684\u6240\u6709\u7ebf\u7a0b\u5fc5\u987b\u4eab\u6709\u5171\u540c\u7684pid\u3002
\u9075\u7167\u8fd9\u4e2a\u6807\u51c6\uff0cLinux\u5f15\u5165\u4e86\u7ebf\u7a0b\u7ec4\u7684\u6982\u5ff5\u3002\u4e00\u4e2a\u7ebf\u7a0b\u7ec4\u4e2d\u6240\u6709\u7ebf\u7a0b\u4f7f\u7528\u548c\u8be5\u7ebf\u7a0b\u7ec4\u9886\u5934\u7ebf\u7a0b\uff08thread group leader\uff09\u76f8\u540c\u7684pid\uff0c\u5b83\u88ab\u5b58\u5165task_struct
\u7684tgid\u5b57\u6bb5\u3002\u5f53\u6211\u4eec\u4f7f\u7528getpid()
\u7cfb\u7edf\u8c03\u7528\u8fd4\u56de\u5f53\u524d\u8fdb\u7a0b\u7684pid\u65f6\uff0c\u8fd4\u56de\u7684\u4e5f\u662ftgid\u7684\u503c\u3002\u4efb\u4f55\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u5982\u679c\u53ea\u6709\u4e3b\u7ebf\u7a0b\uff0c\u90a3\u4e48pid = tgid\uff0c group_leader\u6307\u5411\u7684\u5c31\u662f\u81ea\u5df1\u3002\u5982\u679c\u4e3b\u7ebf\u7a0b\u521b\u5efa\u4e86\u5176\u4ed6\u7ebf\u7a0b\uff0c\u90a3\u4e48\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u81ea\u5df1\u7684pid\uff0c\u4f46\u662ftgid\u4ecd\u7136\u662f\u4e3b\u7ebf\u7a0b\u3002
"},{"location":"linux/kernel/sched/#_7","title":"\u8fdb\u7a0b\u95f4\u5173\u7cfb","text":"Linux\u7cfb\u7edf\u4e2d\u6240\u6709\u7684\u8fdb\u7a0b\u90fd\u662fPID\u4e3a1\u7684init\u8fdb\u7a0b\u7684\u540e\u4ee3\uff0c\u5185\u6838\u5728\u7cfb\u7edf\u542f\u52a8\u7684\u6700\u540e\u9636\u6bb5\u542f\u52a8init\u8fdb\u7a0b\u3002\u8be5\u8fdb\u7a0b\u8bfb\u53d6\u7cfb\u7edf\u7684\u521d\u59cb\u5316\u811a\u672c\u5e76\u6267\u884c\u5176\u4ed6\u7684\u76f8\u5173\u7a0b\u5e8f\uff0c\u6700\u540e\u5b8c\u6210\u6574\u4e2a\u7cfb\u7edf\u7684\u542f\u52a8\u3002
\u6bcf\u4e2a\u8fdb\u7a0b\u5fc5\u6709\u4e00\u4e2a\u7236\u8fdb\u7a0b\uff0c\u5982\u679c\u4e00\u4e2a\u8fdb\u7a0b\u521b\u5efa\u4e86\u591a\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u90a3\u4e48\u5b50\u8fdb\u7a0b\u4e4b\u95f4\u8fd8\u6709\u5144\u5f1f\u5173\u7cfb\u3002\u5728task_struct
\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u5b57\u6bb5\u6765\u8868\u793a\u4eb2\u7f18\u5173\u7cfb\uff1a
struct task_struct __rcu *real_parent; /* real parent process */\nstruct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */\nstruct list_head children; /* list of my children */\nstruct list_head sibling; /* linkage in my parent's children list */\n
\u8fd9\u4e9b\u5b57\u6bb5\u6839\u636e\u540d\u5b57\u5c31\u80fd\u731c\u5230\u662f\u4ec0\u4e48\u610f\u601d\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u901a\u5e38\u60c5\u51b5\u4e0breal_parent\u548cparent\u662f\u4e00\u6837\u7684\uff0c\u4f46\u662f\u5f53\u6211\u4eec\u542f\u52a8GDB\u76d1\u89c6\u67d0\u4e2a\u8fdb\u7a0b\u65f6\uff0c\u8be5\u8fdb\u7a0b\u7684real_parent\u4e0d\u53d8\uff0c\u4f46\u662fparent\u53d8\u6210\u4e86GDB\u3002
\u8fdb\u7a0b\u4e4b\u95f4\u8fd8\u6709\u5176\u4ed6\u5173\u7cfb\uff0c\u8fd9\u91cc\u4e0d\u8be6\u7ec6\u5c55\u5f00\u3002
"},{"location":"linux/kernel/sched/#_8","title":"\u8fd0\u884c\u7edf\u8ba1","text":"u64 utime;//\u7528\u6237\u6001\u6d88\u8017\u7684CPU\u65f6\u95f4\nu64 stime;//\u5185\u6838\u6001\u6d88\u8017\u7684CPU\u65f6\u95f4\nunsigned long nvcsw;//\u81ea\u613f(voluntary)\u4e0a\u4e0b\u6587\u5207\u6362\u8ba1\u6570\nunsigned long nivcsw;//\u975e\u81ea\u613f(involuntary)\u4e0a\u4e0b\u6587\u5207\u6362\u8ba1\u6570\nu64 start_time;//\u8fdb\u7a0b\u542f\u52a8\u65f6\u95f4\uff0c\u4e0d\u5305\u542b\u7761\u7720\u65f6\u95f4\nu64 real_start_time;//\u8fdb\u7a0b\u542f\u52a8\u65f6\u95f4\uff0c\u5305\u542b\u7761\u7720\u65f6\u95f4\n
"},{"location":"linux/kernel/sched/#_9","title":"\u5185\u5b58\u7ba1\u7406","text":"struct mm_struct *mm; \nstruct mm_struct *active_mm; \n
"},{"location":"linux/kernel/sched/#_10","title":"\u6587\u4ef6\u4e0e\u6587\u4ef6\u7cfb\u7edf","text":"/* Filesystem information: */\nstruct fs_struct *fs;\n/* Open file information: */\nstruct files_struct *files;\n
"},{"location":"linux/kernel/sched/#_11","title":"\u8fdb\u7a0b\u7ec4\u7ec7\u5f62\u5f0f","text":"\u8981\u660e\u767d\u8fdb\u7a0b\u4e4b\u95f4\u662f\u5982\u4f55\u7ec4\u7ec7\u7684\uff0c\u9996\u5148\u8981\u77e5\u9053\u53cc\u5411\u94fe\u8868\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u3002\u53cc\u5411\u94fe\u8868\u5c31\u662f\u540c\u65f6\u6709prev\u548cnext\u6307\u9488\u7684\u94fe\u8868\uff0c\u5206\u522b\u6307\u5411\u524d\u4e00\u4e2a\u548c\u540e\u4e00\u4e2a\u5143\u7d20\u3002Linux\u4f7f\u7528\u53cc\u5411\u94fe\u8868\u5c06\u6240\u6709\u8fdb\u7a0b\u7684\u63cf\u8ff0\u7b26\u5168\u90e8\u8fde\u63a5\u8d77\u6765\u3002
"},{"location":"linux/kernel/sched/#_12","title":"\u8fd0\u884c\u961f\u5217","text":"\u5f53\u5185\u6838\u9700\u8981\u5bfb\u627e\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u8fd0\u884c\u65f6\uff0c\u5fc5\u987b\u53ea\u8003\u8651\u5df2\u5904\u4e8eTASK_RUNNING\u72b6\u6001\u7684\u8fdb\u7a0b\uff0c\u4e8e\u662f\u5c31\u6709\u4e86\u8fd0\u884c\u961f\u5217\u3002\u4e3a\u4e86\u63d0\u9ad8\u8c03\u5ea6\u7a0b\u5e8f\u7684\u8fd0\u884c\u901f\u5ea6\uff0c\u5185\u6838\u4e3a\u6bcf\u4e2a\u4f18\u5148\u7ea7\u90fd\u7ef4\u62a4\u4e86\u4e00\u4e2a\u94fe\u8868\u3002\u5728\u591a\u5904\u7406\u5668\u4e2d\uff0c\u6bcf\u4e2aCPU\u90fd\u6709\u81ea\u5df1\u7684\u8fd0\u884c\u961f\u5217\u3002\u8fd0\u884c\u961f\u5217\u662fLinux\u8c03\u5ea6\u7b97\u6cd5\u7684\u57fa\u7840\u3002\u66f4\u8be6\u7ec6\u7684\u5185\u5bb9\u8bf7\u53c2\u8003\u8fdb\u7a0b\u8c03\u5ea6\u3002
"},{"location":"linux/kernel/sched/#_13","title":"\u7b49\u5f85\u961f\u5217","text":"\u7b49\u5f85\u961f\u5217\u5728\u5185\u6838\u4e2d\u6709\u5f88\u591a\u7528\u9014\uff0c\u5c24\u5176\u65f6\u7528\u5728\u4e2d\u65ad\u5904\u7406\u3001\u8fdb\u7a0b\u540c\u6b65\u3002\u8fd0\u884c\u4e2d\u7684\u8fdb\u7a0b\u5f80\u5f80\u9700\u8981\u7b49\u5f85\u67d0\u4e9b\u4e8b\u4ef6\u7684\u53d1\u751f\uff0c\u5e0c\u671b\u7b49\u5f85\u7279\u5b9a\u4e8b\u4ef6\u7684\u8fdb\u7a0b\u5c06\u81ea\u5df1\u653e\u5165\u5408\u9002\u7684\u7b49\u5f85\u961f\u5217\uff0c\u7136\u540e\u8fdb\u5165\u7761\u7720\u72b6\u6001\u3002\u5f53\u4e8b\u4ef6\u53d1\u751f\u540e\uff0c\u7531\u5185\u6838\u8d1f\u8d23\u5524\u9192\u5b83\u4eec\u3002
\u7b49\u5f85\u961f\u5217\u7531\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\uff0c\u6bcf\u4e2a\u7b49\u5f85\u961f\u5217\u90fd\u6709\u4e00\u4e2a\u7b49\u5f85\u961f\u5217\u5934\uff08wait queue head\uff09\uff0c\u4e00\u4e2a\u7c7b\u578b\u4e3await_queue_head_t
\u7684\u6570\u636e\u7ed3\u6784\uff1a
struct __wait_queue_head {\n spinlock_t lock;\n struct list_head task_list;\n};\n\ntypedef struct __wait_queue_head wait_queue_head_t;\n
\u56e0\u4e3a\u7b49\u5f85\u961f\u5217\u4e3b\u8981\u662f\u7531\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u548c\u5185\u6838\u51fd\u6570\u4fee\u6539\u7684\uff0c\u56e0\u6b64\u5fc5\u987b\u6709\u9501\u52a0\u4ee5\u4fdd\u62a4\u3002\u7b49\u5f85\u961f\u5217\u94fe\u8868\u4e2d\u7684\u5143\u7d20\u4e3a\uff1a
struct __wait_queue {\n unsigned int flags;\n struct task_struct *task;\n wait_queue_func_t func;\n struct list_head task_list;\n};\ntypedef struct __wait_queue wait_queue_t;\n
\u7b49\u5f85\u961f\u5217\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u4ee3\u8868\u4e00\u4e2a\u7761\u7720\u4e2d\u7684\u8fdb\u7a0b\uff0c\u5b83\u7684\u63cf\u8ff0\u7b26\u5b58\u5165task\u5b57\u6bb5\u4e2d\u3002task_list\u8d1f\u8d23\u5c06\u6bcf\u4e00\u4e2a\u5143\u7d20\u94fe\u63a5\u5230\u94fe\u8868\u4e2d\u3002func\u8868\u793a\u7b49\u5f85\u961f\u5217\u4e2d\u7761\u7720\u8fdb\u7a0b\u5e94\u8be5\u7528\u4ec0\u4e48\u65b9\u5f0f\u5524\u9192\u3002flags\u8868\u793a\u8be5\u8fdb\u7a0b\u662f\u4e92\u65a5\u8fdb\u7a0b\u8fd8\u662f\u975e\u4e92\u65a5\u8fdb\u7a0b\u3002\u4e92\u65a5\u8fdb\u7a0b\u8868\u793a\u591a\u4e2a\u8fdb\u7a0b\u5728\u7b49\u5f85\u76f8\u540c\u7684\u4e8b\u4ef6\uff0c\u56e0\u6b64\u4ea7\u751f\u4e86\u7ade\u4e89\u5173\u7cfb\uff0c\u6b64\u65f6\u5185\u6838\u53ea\u9700\u8981\u5524\u9192\u5176\u4e2d\u4e00\u4e2a\u8fdb\u7a0b\u5373\u53ef\u3002\u800c\u975e\u4e92\u65a5\u8fdb\u7a0b\u5728\u53d1\u751f\u6307\u5b9a\u4e8b\u4ef6\u540e\u603b\u662f\u88ab\u5524\u9192\u3002
\u7b49\u5f85\u961f\u5217\u7684\u64cd\u4f5c\u6bd4\u8f83\u590d\u6742\uff0c\u8fd9\u91cc\u4e0d\u8be6\u7ec6\u5c55\u5f00\uff0c\u53ea\u8bb2\u4e00\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u51fd\u6570sleep_on()
\uff1a\u8fd9\u4e2a\u51fd\u6570\u5c06\u5f53\u524d\u8fdb\u7a0b\u52a0\u5165\u7b49\u5f85\u961f\u5217\uff0c\u5e76\u542f\u52a8\u8c03\u5ea6\u7a0b\u5e8f\u3002
void sleep_on(wait_queue_head_t *wq)\n{\n wait_queue_t wait; //\u58f0\u660e\u4e00\u4e2a\u7b49\u5f85\u961f\u5217\u5143\u7d20\n init_waiqueue_entry(&wait, current); //\u5c06current\u5f53\u524d\u8fdb\u7a0b\u52a0\u5165\u5230wait\u4e2d\n current->state = TAKS_UNINTERRUPTIBLE; //\u8bbe\u7f6e\u5f53\u524d\u8fdb\u7a0b\u4e3a\u6df1\u5ea6\u7761\u7720\u6001\n add_wait_queue(wq, &wait); //\u5c06wait\u52a0\u5165\u5230\u7b49\u5f85\u961f\u5217wq\u4e2d\n schedule(); //\u542f\u52a8\u8c03\u5ea6\u7a0b\u5e8f\n remove_wait_queue(wq, &wait); //\u628a\u5f53\u524d\u8fdb\u7a0b\u4ece\u7b49\u5f85\u961f\u5217\u4e2d\u5220\u9664\n}\n
\u6ce8\u610f\uff1a\u5728\u542f\u52a8\u8c03\u5ea6\u7a0b\u5e8f\u4e4b\u524d\uff0c\u8c03\u5ea6\u5668\u4f1a\u8bb0\u5f55\u5f53\u524d\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u5e76\u4fdd\u5b58\u81f3\u5bc4\u5b58\u5668\u4e2d\uff0c\u5f53\u8be5\u7761\u7720\u8fdb\u7a0b\u88ab\u5524\u9192\u65f6\uff0c\u8c03\u5ea6\u7a0b\u5e8f\u4ecesleep_on()
\u51fd\u6570\u4e4b\u524d\u505c\u6b62\u7684\u4f4d\u7f6e\u7ee7\u7eed\u6267\u884c\u2014\u2014\u628a\u8be5\u8fdb\u7a0b\u4ece\u7b49\u5f85\u961f\u5217\u5220\u9664\u3002
"},{"location":"linux/kernel/sched/#_14","title":"\u8fdb\u7a0b\u751f\u547d\u5468\u671f","text":"\u8fd9\u91cc\u7ed9\u51fa\u4e00\u5f20\u793a\u610f\u56fe\u65b9\u4fbf\u7406\u89e3\u3002
"},{"location":"linux/kernel/sched/#_15","title":"\u8fdb\u7a0b\u521b\u5efa","text":"Linux\u7684\u8fdb\u7a0b\u521b\u5efa\u6d89\u53ca\u5230\u4e24\u4e2a\u51fd\u6570\uff1afork()
\u548cexec()
\u3002fork()
\u62f7\u8d1d\u5f53\u524d\u8fdb\u7a0b\u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u3002exec()
\u8d1f\u8d23\u8bfb\u53d6\u53ef\u6267\u884c\u6587\u4ef6\u5e76\u5c06\u5176\u8f7d\u5165\u5730\u5740\u7a7a\u95f4\u5f00\u59cb\u8fd0\u884c\u3002
Linux\u7684fork()
\u4f7f\u7528\u4e86\u5199\u65f6\u62f7\u8d1d\uff08copy-on-write\uff09\u673a\u5236\u3002\u8fd9\u610f\u5473\u7740\u5728\u521b\u5efa\u8fdb\u7a0b\u65f6\uff0c\u5185\u6838\u5e76\u4e0d\u590d\u5236\u6574\u4e2a\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\uff0c\u800c\u662f\u8ba9\u7236\u5b50\u8fdb\u7a0b\u5171\u4eab\u3002\u53ea\u6709\u5728\u9700\u8981\u5199\u5165\u65f6\uff0c\u6570\u636e\u624d\u4f1a\u88ab\u590d\u5236\uff0c\u4ece\u800c\u4f7f\u5f97\u5404\u4e2a\u8fdb\u7a0b\u62e5\u6709\u81ea\u5df1\u7684\u5730\u5740\u7a7a\u95f4\u3002\u8fd9\u79cd\u4f18\u5316\u53ef\u4ee5\u907f\u514d\u5927\u91cf\u6839\u672c\u5c31\u4e0d\u4f1a\u88ab\u4f7f\u7528\u7684\u6570\u636e\uff0c\u4ece\u800c\u4f7f\u5f97\u8fdb\u7a0b\u7684\u521b\u5efa\u975e\u5e38\u8fc5\u901f\u3002
fork()
\u51fd\u6570\u7531clone()
\u7cfb\u7edf\u8c03\u7528\u5b9e\u73b0\u3002\u8be5\u7cfb\u7edf\u8c03\u7528\u901a\u8fc7\u4e00\u7cfb\u5217CLONE_FLAGS\u53c2\u6570\u6765\u6307\u660e\u7236\u5b50\u8fdb\u7a0b\u9700\u8981\u5171\u4eab\u7684\u8d44\u6e90\u3002Linux\u4e2d\u8fdb\u7a0b\u4e0e\u7ebf\u7a0b\u7684\u533a\u522b\u4e3b\u8981\u662f\u5728\u6267\u884cclone()
\u7cfb\u7edf\u8c03\u7528\u65f6\u6307\u5b9a\u7684\u5171\u4eab\u8d44\u6e90\u6709\u6240\u4e0d\u540c\u800c\u5df2\u3002\u7ebf\u7a0b\u5728\u521b\u5efa\u65f6\u4f20\u9012\u7684\u53c2\u6570\u5982\u4e0b\uff1a
clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);\n
\u4e0a\u8ff0\u4ee3\u7801\u6307\u660e\u4e86\u521b\u5efa\u7ebf\u7a0b\u65f6\u9700\u8981\u5171\u4eab\u5730\u5740\u7a7a\u95f4\u3001\u6587\u4ef6\u7cfb\u7edf\u8d44\u6e90\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u548c\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u3002
\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u4e00\u4e2a\u666e\u901a\u7684fork()
\u7684\u5b9e\u73b0\uff1a
clone(SIGCHLD, 0);\n
"},{"location":"linux/kernel/sched/#_16","title":"\u8fdb\u7a0b\u7ec8\u7ed3","text":"\u4e00\u4e2a\u8fdb\u7a0b\u7ec8\u7ed3\u65f6\uff0c\u5185\u6838\u5fc5\u987b\u91ca\u653e\u5b83\u6240\u5360\u7528\u7684\u8d44\u6e90\u5e76\u4e14\u544a\u77e5\u7236\u8fdb\u7a0b\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u8fdb\u7a0b\u7684\u7ec8\u7ed3\u662f\u81ea\u8eab\u5f15\u8d77\u7684\uff0c\u4e5f\u53ef\u80fd\u662f\u63a5\u6536\u4e86\u4e00\u4e2a\u4e0d\u53ef\u5ffd\u7565\u7684\u4fe1\u53f7\u6216\u8005\u662f\u5f02\u5e38\u3002
\u5f53\u8fdb\u7a0b\u76f8\u5173\u8054\u7684\u6240\u6709\u8d44\u6e90\u90fd\u88ab\u91ca\u653e\u540e\uff0c\u5b83\u5904\u4e8eEXIT_ZOMBIE\u72b6\u6001\u3002\u8be5\u72b6\u6001\u4e5f\u88ab\u79f0\u4e3a\u50f5\u6b7b\u72b6\u6001\uff0c\u5b83\u7684\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u88ab\u4fdd\u7559\uff0c\u7b49\u5f85\u7236\u8fdb\u7a0b\u4f7f\u7528wait()
\u7cfb\u5217\u51fd\u6570\u56de\u6536\u3002
\u4f46\u662f\uff0c\u5982\u679c\u7236\u8fdb\u7a0b\u5728\u5b50\u8fdb\u7a0b\u4e4b\u524d\u5c31\u9000\u51fa\u4e86\uff0c\u90a3\u4e48\u5fc5\u987b\u6709\u4e00\u4e2a\u673a\u5236\u6765\u4fdd\u8bc1\u5b50\u8fdb\u7a0b\u627e\u5230\u4e00\u4e2a\u65b0\u7684\u7236\u8fdb\u7a0b\uff0c\u5426\u5219\u8fd9\u4e9b\u5b64\u513f\u8fdb\u7a0b\u4f1a\u6c38\u8fdc\u5904\u4e8e\u50f5\u6b7b\u72b6\u6001\uff0c\u767d\u767d\u8017\u8d39\u5185\u5b58\u3002\u5185\u6838\u7684\u89e3\u51b3\u529e\u6cd5\u662f\u5728\u5f53\u524d\u7ebf\u7a0b\u7ec4\u5185\u627e\u4e00\u4e2a\u7ebf\u7a0b\u4f5c\u4e3a\u7236\u8fdb\u7a0b\uff0c\u5982\u679c\u4e0d\u884c\uff0c\u5c31\u8ba9init\u8fdb\u7a0b\u505a\u7236\u8fdb\u7a0b\u3002
"},{"location":"linux/kernel/sched/#_17","title":"\u8fdb\u7a0b\u5207\u6362","text":"\u4e3a\u4e86\u63a7\u5236\u8fdb\u7a0b\u7684\u8fd0\u884c\uff0c\u5185\u6838\u5fc5\u987b\u6709\u80fd\u529b\u6302\u8d77\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u6216\u8005\u6062\u590d\u4ee5\u524d\u6302\u8d77\u7684\u8fdb\u7a0b\u3002\u8fd9\u79cd\u884c\u4e3a\u88ab\u79f0\u4e3a\u8fdb\u7a0b\u5207\u6362\uff08process switch\uff09\u6216\u4e0a\u4e0b\u6587\u5207\u6362\uff08context switch\uff09\u3002\u7406\u89e3\u4e86\u8fdb\u7a0b\u5207\u6362\uff0c\u624d\u6709\u53ef\u80fd\u7406\u89e3\u5185\u6838\u662f\u5982\u4f55\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u8c03\u5ea6\u7684\u3002
"},{"location":"linux/kernel/sched/#_18","title":"\u786c\u4ef6\u4e0a\u4e0b\u6587","text":"\u5c3d\u7ba1\u6bcf\u4e2a\u8fdb\u7a0b\u62e5\u6709\u72ec\u7acb\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\uff0c\u4f46\u6240\u6709\u8fdb\u7a0b\u90fd\u5171\u4eabCPU\u7684\u5bc4\u5b58\u5668\uff0c\u56e0\u6b64\u5728\u6062\u590d\u4e00\u4e2a\u8fdb\u7a0b\u6267\u884c\u4e4b\u524d\uff0c\u5185\u6838\u5fc5\u987b\u4fdd\u8bc1\u5bc4\u5b58\u5668\u88c5\u5165\u4e86\u6302\u8d77\u8fdb\u7a0b\u65f6\u7684\u503c\u3002\u8fdb\u7a0b\u6062\u590d\u6267\u884c\u524d\u5fc5\u987b\u88c5\u5165\u5bc4\u5b58\u5668\u7684\u4e00\u7ec4\u6570\u636e\u79f0\u4e3a\u786c\u4ef6\u4e0a\u4e0b\u6587\uff08hardware context\uff09\u3002\u786c\u4ef6\u4e0a\u4e0b\u6587\u662f\u8fdb\u7a0b\u6267\u884c\u4e0a\u4e0b\u6587\u7684\u4e00\u4e2a\u5b50\u96c6\uff0c\u56e0\u4e3a\u6267\u884c\u4e0a\u4e0b\u6587\u5305\u542b\u8fdb\u7a0b\u6267\u884c\u9700\u8981\u7684\u6240\u6709\u4fe1\u606f\u3002
"},{"location":"linux/kernel/sched/#thread","title":"thread\u5b57\u6bb5","text":"\u6bcf\u4e2a\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u5305\u542b\u4e00\u4e2a\u7c7b\u578b\u4e3athread_struct\u7684thread\u5b57\u6bb5\uff0c\u53ea\u8981\u8fdb\u7a0b\u88ab\u5207\u6362\u51fa\u53bb\uff0c\u5185\u6838\u5c31\u628a\u5176\u786c\u4ef6\u4e0a\u4e0b\u6587\u4fdd\u5b58\u5728\u8fd9\u4e2a\u7ed3\u6784\u4e2d\u3002\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u5305\u542b\u4e86\u5927\u91cfCPU\u5bc4\u5b58\u5668\u4fe1\u606f\u3002
"},{"location":"linux/kernel/sched/#_19","title":"\u6267\u884c\u8fdb\u7a0b\u5207\u6362","text":"\u8fdb\u7a0b\u5207\u6362\u53ea\u4f1a\u53d1\u751f\u5728\u4ee5\u4e0b\u4e24\u79cd\u60c5\u51b5\uff1a
\u4e3b\u52a8\u653e\u5f03CPU\uff0c\u8c03\u7528schedule()
\u51fd\u6570\u3002 \u6b63\u5728\u8fd0\u884c\u65f6\uff0c\u88ab\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0b\u62a2\u5360\u3002 \u4ece\u672c\u8d28\u4e0a\u6765\u8bf4\uff0c\u8fdb\u7a0b\u5207\u6362\u6709\u4e24\u4e2a\u6b65\u9aa4\uff1a
\u5207\u6362\u9875\u5168\u5c40\u76ee\u5f55\u4ee5\u5b89\u88c5\u4e00\u4e2a\u65b0\u7684\u5730\u5740\u7a7a\u95f4\u3002 \u5207\u6362\u5185\u6838\u6001\u5806\u6808\u548c\u786c\u4ef6\u4e0a\u4e0b\u6587\u3002 \u8fdb\u7a0b\u5207\u6362\u7531switch_to
\u5b8f\u6267\u884c\u3002\u8be5\u5b8f\u5b9a\u4e49\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\u3002
"},{"location":"linux/kernel/sched/#_20","title":"\u8fdb\u7a0b\u8c03\u5ea6\u7b97\u6cd5","text":""},{"location":"linux/kernel/synch/","title":"\u5185\u6838\u540c\u6b65","text":"\u53ea\u8981\u6709\u5171\u4eab\u8d44\u6e90\u7684\u5730\u65b9\uff0c\u7a0b\u5e8f\u5458\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u5c31\u9700\u8981\u7279\u522b\u6ce8\u610f\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\uff0c\u9632\u6b62\u5e76\u53d1\u8bbf\u95ee\u65f6\u9020\u6210\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u591a\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u8bbf\u95ee\u5171\u4eab\u6570\u636e\u662f\u9020\u6210\u7cfb\u7edf\u4e0d\u7a33\u5b9a\u7684\u4e00\u7c7b\u9690\u60a3\uff0c\u800c\u8fd9\u7c7b\u9690\u60a3\u5f80\u5f80\u96be\u4ee5\u8ddf\u8e2a\u548c\u8c03\u8bd5\u3002\u8981\u505a\u5230\u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u4fdd\u62a4\u76f8\u5f53\u56f0\u96be\u3002\u65e9\u5e74\uff0cLinux\u8fd8\u4e0d\u652f\u6301SMP\uff08\u5bf9\u79f0\u591a\u5904\u7406\u5668\uff09\uff0c\u907f\u514d\u5e76\u53d1\u8bbf\u95ee\u6570\u636e\u8fd8\u6bd4\u8f83\u5bb9\u6613\u3002\u5728\u5355\u4e00\u5904\u7406\u5668\u65f6\uff0c\u53ea\u6709\u5728\u4e2d\u65ad\u53d1\u751f\u7684\u65f6\u5019\uff0c\u6216\u8005\u7a0b\u5e8f\u660e\u786e\u8bf7\u6c42\u91cd\u65b0\u8c03\u5ea6\uff08scheduler\uff09\u7684\u65f6\u5019\uff0c\u6570\u636e\u624d\u6709\u53ef\u80fd\u88ab\u5e76\u53d1\u8bbf\u95ee\u3002\u4e8e\u662f\u5728\u65e9\u671f\u7684\u5355CPU\u67b6\u6784\u4e0b\uff0c\u7b80\u5355\u7684\u7981\u6b62\u4e2d\u65ad\u5373\u53ef\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u3002\u4f46\u662f\u591a\u5904\u7406\u5668\u65f6\u4ee3\u8fd9\u4e00\u65b9\u6cd5\u4e0d\u518d\u6709\u6548\u4e86\uff0c\u56e0\u4e3a\u7981\u6b62\u4e2d\u65ad\u53ea\u80fd\u7981\u6b62\u672c\u5730\u7684\u4e2d\u65ad\uff0c\u4f46\u662f\u65e0\u6cd5\u963b\u6b62\u5176\u4ed6CPU\u5e76\u53d1\u5730\u8bbf\u95ee\u6570\u636e\u3002\u968f\u77402.6\u5185\u6838\u7248\u672c\u7684\u51fa\u73b0\uff0cLinux\u5185\u6838\u5df2\u7ecf\u53d1\u5c55\u6210\u62a2\u5360\u5f0f\u5185\u6838\u3002\u8fd9\u610f\u5473\u7740\u8c03\u5ea6\u7a0b\u5e8f\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u523b\u62a2\u5360\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\uff0c\u91cd\u65b0\u8c03\u5ea6\u5176\u4ed6\u7684\u8fdb\u7a0b\u6267\u884c\uff0c\u8fd9\u5bf9\u6570\u636e\u7684\u540c\u6b65\u63d0\u51fa\u4e86\u66f4\u9ad8\u7684\u8981\u6c42\u3002\u5177\u4f53\u8bf7\u770b\u8fdb\u7a0b\u8c03\u5ea6\u3002
\u5185\u6838\u4e2d\u5e76\u53d1\u6267\u884c\u7684\u539f\u56e0\u6709\uff1a
\u4e2d\u65ad\u2014\u2014\u4e2d\u65ad\u662f\u5f02\u6b65\u7684\uff0c\u51e0\u4e4e\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u523b\u53d1\u751f\uff0c\u4e5f\u5c31\u6709\u53ef\u80fd\u5728\u4efb\u4f55\u65f6\u523b\u6253\u65ad\u6b63\u5728\u6267\u884c\u7684\u4ee3\u7801\u3002 \u8f6f\u4e2d\u65ad\u548ctasklet\u2014\u2014\u5185\u6838\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u523b\u5524\u9192\u6216\u8c03\u5ea6\u8f6f\u4e2d\u65ad\u548ctasklet\u3002 \u62a2\u5360\u2014\u2014\u5185\u6838\u662f\u62a2\u5360\u6027\u8d28\u7684\uff0c\u6b63\u5728\u6267\u884c\u7684\u4efb\u52a1\u53ef\u80fd\u4f1a\u88ab\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u62a2\u5360\u3002 \u7761\u7720\u2014\u2014\u5728\u5185\u6838\u6267\u884c\u7684\u8fdb\u7a0b\u53ef\u80fd\u7761\u7720\uff0c\u8fd9\u4f1a\u5524\u9192\u8c03\u5ea6\u7a0b\u5e8f\uff0c\u4ece\u800c\u8c03\u5ea6\u53e6\u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u3002 SMP\u2014\u2014\u591a\u4e2aCPU\u53ef\u4ee5\u540c\u65f6\u6267\u884c\u4ee3\u7801\u3002 "},{"location":"linux/kernel/synch/#_2","title":"\u540c\u6b65\u7684\u6982\u5ff5","text":""},{"location":"linux/kernel/synch/#_3","title":"\u4e34\u754c\u533a","text":"\u6240\u8c13\u4e34\u754c\u533a\u5c31\u662f\u8bbf\u95ee\u548c\u64cd\u4f5c\u5171\u4eab\u6570\u636e\u7684\u4ee3\u7801\u6bb5\u3002\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u4e34\u754c\u533a\u4ee3\u7801\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u56e0\u6b64\u4e34\u754c\u533a\u4ee3\u7801\u5fc5\u987b\u4ee5\u539f\u5b50\u5730\u65b9\u5f0f\u6267\u884c\u3002\u8003\u8651\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u60c5\u51b5\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5168\u5c40\u53d8\u91cfi\uff0c\u64cd\u4f5c\u4ec5\u4ec5\u662f\u5bf9\u5176\u52a01\u3002
i++;\n
\u5982\u6b64\u7b80\u5355\u7684\u64cd\u4f5c\u5728CPU\u6267\u884c\u7684\u65f6\u5019\u9700\u8981\u4e09\u6761\u6c47\u7f16\u6307\u4ee4\uff1a
\u4ece\u5185\u5b58\u4e2d\u8bfb\u51fa\u53d8\u91cfi\u7684\u503c\u5e76\u653e\u5728\u4e00\u4e2a\u5bc4\u5b58\u5668\u5185\u3002 \u5c06\u5bc4\u5b58\u5668\u4e2d\u7684\u503c+1\u3002 \u628ai\u7684\u503c\u5199\u56de\u5230\u5185\u5b58\u3002 \u5b9e\u9645\u4e0a\uff0c\u5728\u591a\u7ebf\u7a0b\u5e76\u53d1\u7684\u60c5\u51b5\u4e0b\uff0c\u5176\u4ed6\u7ebf\u7a0b\u6709\u53ef\u80fd\u5728\u8fd9\u4e09\u6761\u6307\u4ee4\u95f4\u9699\u7684\u4efb\u610f\u65f6\u523b\u201c\u63d2\u961f\u201d\u3002\u8fd9\u79cd\u6982\u7387\u867d\u7136\u5f88\u5c0f\uff0c\u4f46\u662f\u8ba1\u7b97\u673a\u6bcf\u79d2\u8fd0\u884c\u4e0a\u767e\u4e07\u6761\u6307\u4ee4\uff0c\u201c\u63d2\u961f\u201d\u53ef\u80fd\u6bcf\u8fc7\u51e0\u79d2\u5c31\u53d1\u751f\u4e00\u6b21\u3002\u5047\u8bbe\u6709\u4e24\u4e2a\u7ebf\u7a0b\u540c\u65f6\u64cd\u4f5c\u8fd9\u4e2a\u5168\u5c40\u53d8\u91cf\uff0c\u82e5i\u7684\u521d\u59cb\u503c\u4e3a1\uff0c\u90a3\u4e48\u6211\u4eec\u671f\u671b\u7684\u6700\u7ec8\u7ed3\u679c\u5e94\u8be5\u662f3\u3002\u4f46\u662f\u5047\u5982\u7b2c\u4e8c\u4e2a\u7ebf\u7a0b\u5728\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\u6267\u884c\u6700\u540e\u4e00\u6b65\u4e4b\u524d\u5c31\u53bb\u5185\u5b58\u4e2d\u8bfb\u53d6\u4e86i\u7684\u503c\uff08\u6b64\u65f6i\u7684\u503c\u4ecd\u7136\u662f1\uff09\uff0c\u6211\u4eec\u6700\u540e\u5f97\u5230\u7684i\u7684\u503c\u5c31\u662f2\u800c\u4e0d\u662f3\uff0c\u8fd9\u4e0e\u6211\u4eec\u9884\u671f\u7684\u503c\u4e0d\u7b26\u3002
#include <stdio.h>\n#include <pthread.h>\n\nint i = 0;\n\nvoid *thread_func(void *arg)\n{\n for(int j = 0 ;j < 1000000; j++)\n {\n i++;\n }\n\n}\n\nint main(int argc, char *argv[])\n{\n\n pthread_t tid1, tid2;\n pthread_create(&tid1, NULL, thread_func, NULL);\n pthread_create(&tid2, NULL, thread_func, NULL);\n\n pthread_join(tid1, NULL);\n pthread_join(tid2, NULL);\n\n printf(\"i = %d\\n\", i);\n return 0;\n}\n
\u4ee5\u4e0a\u662f\u4e00\u6bb5\u793a\u4f8b\u4ee3\u7801\uff0c\u5728\u7f16\u8bd1\u65f6\u8bf7\u52a0\u4e0a-lpthread\uff0c\u4ee5\u94fe\u63a5\u6b63\u786e\u7684\u5e93\u3002\u591a\u6b21\u6267\u884c\u8be5\u7a0b\u5e8f\u540e\u4f60\u4f1a\u53d1\u73b0\u6700\u7ec8\u7684\u7ed3\u679c\u662f\u4e0d\u786e\u5b9a\u7684\u3002
\u8fd9\u662f\u6700\u7b80\u5355\u7684\u4e34\u754c\u533a\u4f8b\u5b50\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u7b80\u5355\u7684\u7ade\u4e89\u6761\u4ef6\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u7528\u5230\u590d\u6742\u7684\u9501\u673a\u5236\uff0c\u56e0\u4e3a\u9501\u5bf9\u4e8eCPU\u7684\u6027\u80fd\u6709\u5f88\u5927\u7684\u5f71\u54cd\u3002\u591a\u6570\u5904\u7406\u5668\u90fd\u63d0\u4f9b\u4e86\u6307\u4ee4\u6765\u539f\u5b50\u5730\u8bfb\u3001\u5199\u53d8\u91cf\u3002\u6211\u4eec\u79f0\u4e4b\u4e3a\u539f\u5b50\u6307\u4ee4\u3002\u4f7f\u7528\u539f\u5b50\u6307\u4ee4\u53ef\u4ee5\u89e3\u51b3\u4e00\u4e9b\u7b80\u5355\u7684\u5e76\u53d1\u95ee\u9898\u3002\u4e24\u6761\u539f\u5b50\u6307\u4ee4\u4e0d\u53ef\u80fd\u4ea4\u9519\u6267\u884c\uff0c\u56e0\u4e3a\u5904\u7406\u5668\u4f1a\u4ece\u786c\u4ef6\u4e0a\u7981\u6b62\u8fd9\u79cd\u53ef\u80fd\u6027\u3002
"},{"location":"linux/kernel/synch/#_4","title":"\u52a0\u9501","text":"\u5f53\u5171\u4eab\u8d44\u6e90\u662f\u4e00\u4e2a\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u800c\u4e0d\u662f\u7b80\u5355\u7684i++\u65f6\uff0c\u539f\u5b50\u6307\u4ee4\u5c31\u65e0\u80fd\u4e3a\u529b\u4e86\u3002\u6b64\u65f6\u6211\u4eec\u5fc5\u987b\u5f15\u5165\u9501\u673a\u5236\u6765\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u7684\u8bbf\u95ee\u3002\u540c\u4e00\u65f6\u523b\uff0c\u6211\u4eec\u53ea\u5141\u8bb8\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\u9501\uff0c\u5176\u4ed6\u7ebf\u7a0b\u7684\u8bbf\u95ee\u5fc5\u987b\u7b49\u5f85\u7b2c\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\u4e4b\u540e\u624d\u80fd\u8fdb\u884c\u3002\u9501\u6709\u591a\u79cd\u591a\u6837\u7684\u5f62\u5f0f\uff0c\u9501\u7684\u7c92\u5ea6\u4e5f\u5404\u4e0d\u76f8\u540c\u3002Linux\u5185\u6838\u63d0\u4f9b\u4e86\u591a\u79cd\u4e0d\u540c\u7684\u9501\u673a\u5236\uff0c\u4ed6\u4eec\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\u5728\u4e8e\uff1a\u5f53\u9501\u88ab\u5176\u4ed6\u7ebf\u7a0b\u6301\u6709\u800c\u4e0d\u53ef\u7528\u65f6\u7684\u8868\u73b0\u5f62\u5f0f\u2014\u2014\u6709\u4e00\u4e9b\u9501\u4f1a\u5728\u539f\u5730\u7b49\u5f85\uff0c\u800c\u6709\u4e00\u4e9b\u9501\u4f1a\u76f4\u63a5\u7761\u7720\u3002\u9501\u6ca1\u6709\u4f18\u52a3\u4e4b\u5206\uff0c\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7528\u4e0d\u540c\u7684\u9501\u662f\u7a0b\u5e8f\u5458\u5fc5\u5907\u7684\u6280\u80fd\u3002
\u5f53\u4e00\u4e2a\u9501\u6b63\u5728\u88ab\u5360\u7528\u65f6\uff0c\u6709\u5176\u4ed6\u7ebf\u7a0b\u8bd5\u56fe\u83b7\u5f97\u8be5\u9501\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a\u9501\u7684\u4e89\u7528\u3002\u7531\u4e8e\u9501\u662f\u8ba9\u7a0b\u5e8f\u4ee5\u4e32\u884c\u7684\u65b9\u5f0f\u5bf9\u8d44\u6e90\u8fdb\u884c\u8bbf\u95ee\uff0c\u88ab\u957f\u65f6\u95f4\u6301\u6709\u7684\u9501\u65e0\u7591\u4f1a\u964d\u4f4e\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u4e8e\u662f\u52a0\u9501\u7c92\u5ea6\u5c31\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002\u5982\u679c\u662f\u4e00\u6bb5\u52a0\u9501\u7684\u4ee3\u7801\u88ab\u9891\u7e41\u7684\u8c03\u7528\uff0c\u8fd9\u5f80\u5f80\u4f1a\u6210\u4e3a\u7cfb\u7edf\u6027\u80fd\u7684\u74f6\u9888\u3002\u5728\u4e00\u4e9b\u5927\u578b\u673a\u5668\u4e0a\u53ef\u80fd\u8868\u73b0\u4e0d\u662f\u90a3\u4e48\u660e\u663e\uff0c\u4f46\u662f\u5728\u4e00\u4e9b\u5c0f\u578b\u673a\u5668\u4e0a\uff0c\u8fc7\u7c97\u7684\u9501\u7684\u7c92\u5ea6\u4f1a\u4e25\u91cd\u62d6\u7d2f\u7cfb\u7edf\u7684\u6027\u80fd\u3002
"},{"location":"linux/kernel/synch/#_5","title":"\u6b7b\u9501","text":"\u6b7b\u9501\u662f\u7f16\u5199\u540c\u6b65\u4ee3\u7801\u65f6\u7ecf\u5e38\u4f1a\u9047\u5230\u7684\u95ee\u9898\uff0c\u4e24\u4e2a\u6216\u591a\u4e2a\u7ebf\u7a0b\u56e0\u4e3a\u4e89\u593a\u8d44\u6e90\u800c\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u5728\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\u6216\u8d44\u6e90\u3002\u5982\u679c\u6ca1\u6709\u5916\u529b\u5e72\u6d89\uff0c\u8fd9\u4e9b\u7ebf\u7a0b\u5c06\u6c38\u8fdc\u5904\u4e8e\u7b49\u5f85\u72b6\u6001\u3002
\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u6b7b\u9501\u4f8b\u5b50\u5c31\u662f\u81ea\u6b7b\u9501\uff1a\u5982\u679c\u4e00\u4e2a\u7ebf\u7a0b\u8bd5\u56fe\u53bb\u83b7\u5f97\u4e00\u4e2a\u81ea\u5df1\u5df2\u7ecf\u6301\u6709\u7684\u9501\uff0c\u90a3\u4e48\u5b83\u5c06\u6c38\u8fdc\u7b49\u5f85\u4e0b\u53bb\u3002 \u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u4f8b\u5b50\u53ebABBA\u6b7b\u9501\uff1a\u7ebf\u7a0b1\u6301\u6709\u9501A\uff0c\u7ebf\u7a0b2\u6301\u6709\u9501B\uff0c\u7ebf\u7a0b1\u8bd5\u56fe\u53bb\u83b7\u5f97\u9501B\uff0c\u800c\u7ebf\u7a0b2\u8bd5\u56fe\u53bb\u83b7\u5f97\u9501A\uff0c\u7531\u4e8e\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u5728\u7b49\u5f85\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u91ca\u653e\u9501\uff0c\u4f46\u662f\u8c01\u90fd\u4e0d\u60f3\u91ca\u653e\u81ea\u5df1\u7684\u9501\uff0c\u4e8e\u662f\u5c31\u9020\u6210\u4e86\u6b7b\u9501\u3002\u9884\u9632\u6b7b\u9501\u7684\u53d1\u751f\u975e\u5e38\u91cd\u8981\uff0c\u867d\u7136\u4f60\u4e0d\u77e5\u9053\u81ea\u5df1\u7684\u4ee3\u7801\u4f1a\u4e0d\u4f1a\u53d1\u751f\u6b7b\u9501\uff0c\u4f46\u662f\u9075\u5faa\u4e00\u4e9b\u7b80\u5355\u7684\u89c4\u5219\u5bf9\u4e8e\u907f\u514d\u6b7b\u9501\u5927\u6709\u5e2e\u52a9\uff1a
\u6309\u987a\u5e8f\u52a0\u9501\u3002\u4f7f\u7528\u591a\u4e2a\u9501\u65f6\u5fc5\u987b\u4fdd\u8bc1\u4ee5\u76f8\u540c\u7684\u987a\u5e8f\u83b7\u53d6\u9501\uff0c\u5426\u5219\u5c31\u6709\u53ef\u80fd\u9020\u6210ABBA\u6b7b\u9501\u3002 \u9632\u6b62\u9965\u997f\u3002 \u4e0d\u8981\u91cd\u590d\u8bf7\u6c42\u540c\u4e00\u4e2a\u9501\u3002 \u8bbe\u8ba1\u8d8a\u7b80\u5355\u8d8a\u597d\u3002 "},{"location":"linux/kernel/synch/#_6","title":"\u540c\u6b65\u7684\u65b9\u6cd5","text":""},{"location":"linux/kernel/synch/#_7","title":"\u539f\u5b50\u64cd\u4f5c","text":"\u539f\u5b50\u64cd\u4f5c\u53ef\u4ee5\u4fdd\u8bc1\u6307\u4ee4\u4ee5\u4e0d\u53ef\u5206\u5272\u7684\u5f62\u5f0f\u6267\u884c\u2014\u2014\u2014\u2014\u6267\u884c\u8fc7\u7a0b\u4e0d\u53ef\u88ab\u6253\u65ad\u3002\u5185\u6838\u63d0\u4f9b\u4e86\u4e24\u7ec4\u539f\u5b50\u64cd\u4f5c\u63a5\u53e3\u2014\u2014\u2014\u2014\u4e00\u7ec4\u9488\u5bf9\u6574\u6570\uff0c\u4e00\u7ec4\u9488\u5bf9\u5355\u72ec\u7684\u4f4d\u3002\u5728Linux\u652f\u6301\u7684\u6240\u6709\u4f53\u7cfb\u7ed3\u6784\u4e0a\u90fd\u5b9e\u73b0\u4e86\u8fd9\u4e24\u7ec4\u63a5\u53e3\u3002\u867d\u7136\u5728\u4e0d\u540c\u4f53\u7cfb\u7ed3\u6784\u4e0a\u5b9e\u73b0\u7684\u65b9\u5f0f\u662f\u4e0d\u540c\u7684\uff0c\u4f46\u662f\u63a5\u53e3\u90fd\u662f\u7edf\u4e00\u7684\u3002
\u6709\u7684\u65f6\u5019\u6211\u4eec\u4f1a\u8981\u6c42\u67d0\u4e9b\u6307\u4ee4\u6309\u7167\u7279\u5b9a\u7684\u987a\u5e8f\u6267\u884c\uff0c\u8fd9\u88ab\u79f0\u4e3a\u987a\u5e8f\u6027\uff0c\u4ee5\u5c4f\u969c\uff08barrier\uff09\u6307\u4ee4\u6765\u5b9e\u73b0\u3002
1.\u539f\u5b50\u6574\u6570\u64cd\u4f5c
\u9488\u5bf9\u6574\u6570\u7684\u539f\u5b50\u64cd\u4f5c\u4f7f\u7528\u4e00\u4e2a\u7279\u6b8a\u7684atomic_t
\u7c7b\u578b\u7684\u6570\u636e\u3002\u5b83\u7684\u5b9a\u4e49\u5728<linux/types.h>\u4e2d\uff1a
typedef struct{\n volatile int counter;\n}atomic_t;\n
\u4f7f\u7528\u539f\u5b50\u6574\u6570\u64cd\u4f5c\u7684\u58f0\u660e\u5728<asm/atomic.h>\u4e2d\u5b9a\u4e49\u3002\u6709\u4e9b\u4f53\u7cfb\u7ed3\u6784\u4f1a\u63d0\u4f9b\u4e00\u4e9b\u989d\u5916\u7684\u539f\u5b50\u64cd\u4f5c\uff0c\u4f46\u662f\u5185\u6838\u7684\u63a5\u53e3\u5728\u6240\u6709\u4f53\u7cfb\u7ed3\u6784\u4e0a\u90fd\u5b9e\u73b0\u4e86\u3002
\u4e00\u4e9b\u7b80\u5355\u7684\u64cd\u4f5c\u6bd4\u5982\uff1a
atomic_t v; //\u5b9a\u4e49v\natomic_t u = ATOMIC_INIT(0); //\u5b9a\u4e49u\u5e76\u521d\u59cb\u5316\u4e3a0\natomic_set(&v, 4); //\u8bbe\u7f6ev\u7684\u503c\u4e3a4\natomic_add(2, &v); //\u5c06v\u7684\u503c\u589e\u52a02\nint w = atomic_read(&v); //\u5c06\u539f\u5b50\u53d8\u91cfv\u8f6c\u53d8\u4e3aint\u53d8\u91cf\n
\u539f\u5b50\u64cd\u4f5c\u7684\u63a5\u53e3\u975e\u5e38\u7b80\u5355\u6613\u8bfb\uff0c\u6ca1\u6709\u5fc5\u8981\u5355\u72ec\u53bb\u8bb0\uff0c\u7528\u5230\u4ec0\u4e48\u5c31\u5b66\u4ec0\u4e48\u3002
\u539f\u5b50\u64cd\u4f5c\u901a\u5e38\u662f\u5185\u8054\u51fd\u6570\uff0c\u4e14\u662f\u7528\u5185\u5d4c\u6c47\u7f16\u6307\u4ee4\u6765\u5b9e\u73b0\u7684\u3002ARM\u4f53\u7cfb\u8bf7\u53c2\u8003\uff1aARM GCC Inline Assembler\u3002
atomic64_t
\u7c7b\u578b\u662f64\u4f4d\u7684\u539f\u5b50\u53d8\u91cf\uff0c\u5176\u529f\u80fd\u548c32\u4f4d\u4e00\u81f4\uff0c\u51fd\u6570\u63a5\u53e3\u4ee5atomic64\u524d\u7f00\u547d\u540d\u3002
typedef struct {\n volatile long counter;\n}atomic64_t;\n
2.\u539f\u5b50\u4f4d\u64cd\u4f5c
atomic_t
\u7c7b\u578b\u5bf9\u6574\u6570\u7b97\u672f\u6765\u8bb2\u6bd4\u8f83\u6709\u7528\u3002\u4f46\u662f\u5f53\u9700\u8981\u4ee5\u539f\u5b50\u5f62\u5f0f\u6765\u64cd\u4f5c\u5355\u4e2a\u7684\u4f4d\u65f6\uff0c\u8fd9\u79cd\u7c7b\u578b\u5c31\u65e0\u6cd5\u6d3e\u4e0a\u7528\u573a\u4e86\u3002Linux\u5185\u6838\u63d0\u4f9b\u4e86\u4e00\u7ec4\u5bf9\u4f4d\u7684\u539f\u5b50\u64cd\u4f5c\u3002
\u539f\u5b50\u4f4d\u7684\u64cd\u4f5c\u975e\u5e38\u5feb\uff0c\u53ea\u8981\u786c\u4ef6\u5e95\u5c42\u786c\u4ef6\u652f\u6301\uff0c\u8fd9\u79cd\u64cd\u4f5c\u53ef\u4ee5\u4f7f\u7528\u5355\u4e2a\u673a\u5668\u6307\u4ee4\u6765\u6267\u884c\u3002\u8fd9\u4e9b\u51fd\u6570\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\uff0c\u5b9a\u4e49\u5728<asm/bitops.h>\u4e2d\u3002\u5373\u4f7f\u662f\u5728SMP\u8ba1\u7b97\u673a\u4e0a\uff0c\u8fd9\u4e9b\u51fd\u6570\u4f9d\u65e7\u53ef\u4ee5\u786e\u4fdd\u662f\u539f\u5b50\u7684\u3002\u539f\u5b50\u4f4d\u7684\u53c2\u6570\u662f\u4e00\u4e2a\u4f4d\u53f7+\u6307\u9488\u3002\u53ef\u7528\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a
void set_bit(nr, void *addr); //\u8bbe\u7f6eaddr\u6307\u5411\u7684\u7b2cnr\u4f4d\nvoid clear_bit(nr, void *addr); //\u6e05\u9664addr\u6307\u5411\u7684\u7b2cnr\u4f4d\nvoid change_bit(nr, void *addr); //\u5207\u6362addr\u6307\u5411\u7684\u7b2cnr\u4f4d\ntest_bit(nr, void *addr); //\u8fd4\u56de\u6307\u5b9a\u4f4d\u7684\u5f53\u524d\u503c\n
"},{"location":"linux/kernel/synch/#_8","title":"\u81ea\u65cb\u9501","text":"\u539f\u5b50\u64cd\u4f5c\u53ea\u80fd\u9488\u5bf9\u4e00\u4e9b\u7b80\u5355\u7684\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u4fdd\u62a4\uff0c\u73b0\u5b9e\u60c5\u51b5\u91cc\uff0c\u4e00\u4e2a\u4e34\u754c\u533a\u91cc\u751a\u81f3\u6709\u591a\u4e2a\u51fd\u6570\u3002\u6bd4\u5982\u6211\u4eec\u6709\u8fd9\u6837\u4e00\u4e2a\u60c5\u51b5\uff1a\u4ece\u67d0\u4e2a\u51fd\u6570\u4e2d\u8bfb\u53d6\u67d0\u4e2astruct\u7c7b\u578b\u7684\u6570\u636e\uff0c\u7136\u540e\u6539\u53d8\u5176\u4e2d\u67d0\u4e2a\u6210\u5458\u7684\u503c\uff0c\u6700\u540e\u518d\u628a\u66f4\u65b0\u7684\u503c\u8d4b\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u3002\u6574\u4e2a\u6267\u884c\u8fc7\u7a0b\u5fc5\u987b\u662f\u4e0d\u53ef\u5206\u5272\u7684\uff0c\u5728\u6570\u636e\u66f4\u65b0\u5b8c\u6bd5\u524d\uff0c\u7edd\u5bf9\u4e0d\u5141\u8bb8\u4efb\u4f55\u5176\u4ed6\u7684\u4ee3\u7801\u8bfb\u53d6\u8fd9\u4e9b\u6570\u636e\u3002\u663e\u7136\uff0c\u6211\u4eec\u4e0d\u53ef\u80fd\u8981\u6c42\u6bcf\u4e2a\u4f53\u7cfb\u90fd\u652f\u6301\u5982\u6b64\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u7528\u5230\u66f4\u590d\u6742\u7684\u540c\u6b65\u65b9\u6cd5\u2014\u2014\u9501\u6765\u63d0\u4f9b\u4fdd\u62a4\u3002
Linux\u5185\u6838\u4e2d\u6700\u5e38\u89c1\u7684\u9501\u662f\u81ea\u65cb\u9501\uff08spin lock\uff09\u3002\u81ea\u65cb\u9501\u53ea\u80fd\u540c\u65f6\u88ab\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\uff0c\u5982\u679c\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u8bd5\u56fe\u83b7\u5f97\u4e00\u4e2a\u5df2\u7ecf\u88ab\u5360\u7528\u7684\u81ea\u65cb\u9501\uff0c\u90a3\u4e48\u8be5\u7ebf\u7a0b\u5c06\u4f1a\u8fdb\u5165\u5fd9\u7b49\u5f85\uff0c\u76f4\u5230\u9501\u53ef\u7528\u3002\u901a\u4fd7\u7684\u89e3\u91ca\u5c31\u662f\u4e00\u6247\u95e8\u5bf9\u5e94\u4e00\u628a\u94a5\u5319\uff0c\u8981\u8fdb\u5165\u8fd9\u6247\u95e8\u5fc5\u987b\u5148\u68c0\u67e5\u95e8\u4e0a\u6709\u6ca1\u6709\u94a5\u5319\uff0c\u5982\u679c\u6ca1\u6709\u5c31\u53ea\u80fd\u5728\u5916\u9762\u7b49\u5f85\u76f4\u5230\u91cc\u9762\u7684\u4eba\u51fa\u6765\u3002\u7531\u4e8e\u81ea\u65cb\u4f1a\u4e00\u76f4\u5bfc\u81f4\u7ebf\u7a0b\u5fd9\u7b49\u5f85\uff0c\u767d\u767d\u5360\u7528\u4e86CPU\u8d44\u6e90\u800c\u4e0d\u4f1a\u53bb\u505a\u522b\u7684\u4e8b\u60c5\uff0c\u56e0\u6b64\u7279\u522b\u6d6a\u8d39\u8d44\u6e90\uff0c\u6240\u4ee5\u81ea\u65cb\u9501\u4e0d\u5e94\u8be5\u88ab\u957f\u65f6\u95f4\u5360\u6709\u3002\u4e8b\u5b9e\u4e0a\uff0c\u4f7f\u7528\u81ea\u65cb\u9501\u65f6\u4f60\u5fc5\u987b\u4fdd\u8bc1\u4e34\u754c\u533a\u4ee3\u7801\u6267\u884c\u8db3\u591f\u77ed\uff0c\u5426\u5219\u4f1a\u4e25\u91cd\u5f71\u54cd\u7cfb\u7edf\u7684\u6027\u80fd\u3002
\u81ea\u65cb\u9501\u7684\u5b9e\u73b0\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\uff0c\u4ee3\u7801\u5f80\u5f80\u901a\u8fc7\u6c47\u7f16\u5b9e\u73b0\u3002\u5176\u5b9a\u4e49\u5728<asm/spinlock.h>\u4e2d\uff0c\u5b9e\u9645\u7684\u63a5\u53e3\u5b9a\u4e49\u5728<linux/spinlock.h>\u3002\u81ea\u65cb\u9501\u7684\u57fa\u672c\u4f7f\u7528\u5982\u4e0b\uff1a
DEFINE_SPINLOCK(sp_lock);\nspin_lock(&sp_lock);\n/*\u4e34\u754c\u533a\u4ee3\u7801*/\nspin_unlock(&sp_lock);\n
\u5728\u5355\u5904\u7406\u5668\u4e0a\uff0c\u5982\u679c\u7981\u6b62\u5185\u6838\u62a2\u5360\uff0c\u90a3\u4e48\u81ea\u65cb\u9501\u4e0d\u4f1a\u88ab\u7f16\u8bd1\u8fdb\u5185\u6838\u3002
\u81ea\u65cb\u9501\u53ef\u4ee5\u4f7f\u7528\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0c\u4f46\u83b7\u53d6\u9501\u4e4b\u524d\uff0c\u5fc5\u987b\u8981\u7981\u6b62\u672c\u5730\u4e2d\u65ad\uff0c\u5426\u5219\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4f1a\u6253\u65ad\u5f53\u524d\u6301\u6709\u9501\u7684\u4ee3\u7801\u3002\u7531\u4e8e\u9501\u7684\u6301\u6709\u548c\u91ca\u653e\u5fc5\u987b\u662f\u539f\u5b50\u7684\uff0c\u5982\u679c\u88ab\u6253\u65ad\u53ef\u80fd\u4f1a\u5f71\u54cd\u9501\u7684\u4e00\u81f4\u6027\uff0c\u8fd9\u4f1a\u5f15\u8d77\u4e0d\u53ef\u9884\u6d4b\u7684\u540e\u679c\u3002\u751a\u81f3\uff0c\u5982\u679c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u53bb\u4e89\u7528\u8fd9\u4e2a\u5df2\u7ecf\u88ab\u6301\u6709\u7684\u9501\uff0c\u90a3\u4e48\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002\u6ce8\u610f\uff0c\u8981\u5173\u95ed\u7684\u53ea\u662f\u5f53\u524d\u5904\u7406\u5668\u7684\u4e2d\u65ad\uff0c\u5176\u4ed6\u5904\u7406\u5668\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u81ea\u65cb\u5e76\u4e0d\u4f1a\u59a8\u788d\u5f53\u524d\u5904\u7406\u5668\u91ca\u653e\u9501\u3002
\u5185\u6838\u63d0\u4f9b\u4e86\u7981\u6b62\u4e2d\u65ad\u540c\u65f6\u8bf7\u6c42\u9501\u7684\u63a5\u53e3\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a
DEFINE_SPINLOCK(sp_lock);\nunsigned long flags;\nspin_lock_irqsave(&sp_lock, flags);\nspin_unlock_irqrestore(&sp_lock, flags);\n
\u51fd\u6570spin_lock_irqsave()
\u4fdd\u5b58\u4e2d\u65ad\u72b6\u6001\uff0c\u5e76\u7981\u6b62\u672c\u5730\u4e2d\u65ad\uff0c\u7136\u540e\u518d\u53bb\u83b7\u53d6\u9501\u3002\u53cd\u8fc7\u6765spin_unlock_irqrestore()
\u89e3\u9501\uff0c\u5e76\u8ba9\u4e2d\u65ad\u6062\u590d\u5230\u52a0\u9501\u524d\u7684\u72b6\u6001\u3002\u6240\u4ee5\u5373\u4fbf\u662f\u52a0\u9501\u524d\u4e2d\u65ad\u5df2\u7ecf\u88ab\u7981\u6b62\u4e86\uff0c\u4ee3\u7801\u4e5f\u4e0d\u4f1a\u9519\u8bef\u5730\u6fc0\u6d3b\u4e2d\u65ad\uff0c\u800c\u662f\u8ba9\u4e2d\u65ad\u4fdd\u6301\u7981\u6b62\u72b6\u6001\u3002
\u5982\u679c\u4f60\u80fd\u786e\u5b9a\u4e2d\u65ad\u5728\u52a0\u9501\u524d\u662f\u6fc0\u6d3b\u7684\uff0c\u90a3\u4e48\u53ef\u4ee5\u914d\u5bf9\u4f7f\u7528spin_lock_irq()
\u548cspin_unlock_irq()
\uff0c\u4ece\u800c\u5728\u89e3\u9501\u65f6\u76f4\u63a5\u6fc0\u6d3b\u4e2d\u65ad\u3002\u4f46\u662f\u5185\u6838\u7684\u5e9e\u5927\u6027\u5f80\u5f80\u8ba9\u4eba\u5f88\u96be\u641e\u6e05\u695a\u4e2d\u65ad\u5728\u5f53\u524d\u6267\u884c\u4ee3\u7801\u524d\u662f\u5426\u5904\u4e8e\u6fc0\u6d3b\u72b6\u6001\uff0c\u6240\u4ee5\u8be5\u65b9\u6cd5\u5e76\u4e0d\u63d0\u5021\u3002
\u7531\u4e8e\u4e2d\u65ad\u4e0b\u534a\u90e8\u53ef\u4ee5\u62a2\u5360\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u7684\u4ee3\u7801\uff0c\u56e0\u6b64\u52a0\u9501\u7684\u540c\u65f6\u8fd8\u9700\u8981\u7981\u6b62\u4e0b\u534a\u90e8\u6267\u884c\u3002\u51fd\u6570spin_lock_bh()
\u53ef\u4ee5\u505a\u5230\u8fd9\u4e00\u70b9\u3002\u540c\u6837\uff0c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u53ef\u4ee5\u62a2\u5360\u4e0b\u534a\u90e8\uff0c\u56e0\u6b64\u5982\u679c\u4e0b\u534a\u90e8\u6709\u9700\u8981\u548c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u5171\u4eab\u7684\u6570\u636e\u65f6\uff0c\u4e5f\u5fc5\u987b\u7981\u6b62\u4e2d\u65ad\u3002
\u4e2d\u65ad\u5904\u7406\u662f\u53e6\u4e00\u4e2a\u8bdd\u9898\uff0c\u8bf7\u53c2\u8003\u4e2d\u65ad\u548c\u4e2d\u65ad\u5904\u7406\u3002
"},{"location":"linux/kernel/synch/#_9","title":"\u8bfb/\u5199\u81ea\u65cb\u9501","text":"\u6709\u65f6\uff0c\u9501\u7684\u7528\u9014\u53ef\u4ee5\u660e\u786e\u5730\u5206\u4e3a\u8bfb\u548c\u5199\u4e24\u4e2a\u573a\u666f\uff0c\u5c24\u5176\u662f\u90a3\u4e9b\u9700\u8981\u5927\u91cf\u8bfb\u64cd\u4f5c\uff0c\u800c\u5199\u64cd\u4f5c\u5f88\u5c11\u7684\u60c5\u51b5\u65f6\uff0c\u5f15\u5165\u8bfb\u5199\u9501\u53ef\u4ee5\u5f88\u5927\u5730\u6539\u5584\u7cfb\u7edf\u7684\u6027\u80fd\u3002\u8bfb\u5199\u9501\u7684\u57fa\u672c\u903b\u8f91\u662f\uff1a\u8bfb\u6a21\u5f0f\u662f\u5171\u4eab\u7684\uff0c\u5199\u6a21\u5f0f\u662f\u72ec\u5360\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\u5f53\u8fdb\u884c\u5199\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u53ea\u80fd\u7531\u5355\u4e2a\u4efb\u52a1\u8fdb\u884c\u3002\u800c\u8fdb\u884c\u8bfb\u64cd\u4f5c\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5e76\u53d1\u7684\u6267\u884c\u800c\u4e0d\u7528\u62c5\u5fc3\u5b89\u5168\u95ee\u9898\u3002\u8bfb/\u5199\u9501\u7684\u57fa\u672c\u65b9\u6cd5\u5982\u4e0b\uff1a
DEFINE_RWLOCK(rw_lock);\n//\u8bfb\u64cd\u4f5c\nread_lock(&rw_lock);\nread_unlock(&rw_lock);\n//\u5199\u64cd\u4f5c\nwrite_lock(&rw_lock);\nwrite_unlock(&rw_lock);\n
\u901a\u5e38\uff0c\u8bfb\u5199\u64cd\u4f5c\u5e94\u5904\u4e8e\u5b8c\u5168\u5206\u5272\u5f00\u7684\u4ee3\u7801\u5206\u652f\u4e2d\uff0c\u5982\u679c\u8bfb\u5199\u64cd\u4f5c\u4e0d\u80fd\u6e05\u6670\u5730\u8fa8\u522b\uff0c\u4e0d\u8981\u4f7f\u7528\u8bfb\u5199\u9501\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002\u4f8b\u5982\u5728\u6267\u884c\u8bfb\u64cd\u4f5c\u4ee3\u7801\u65f6\uff0c\u4e5f\u52a0\u5165\u4e86\u5199\u64cd\u4f5c\u3002
\u5728\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u4e2d\uff0c\u5982\u679c\u53ea\u6709\u8bfb\u64cd\u4f5c\uff0c\u53ef\u4ee5\u7b80\u5355\u5730\u4f7f\u7528read_lock()
\u6765\u4fdd\u62a4\u8bfb\u64cd\u4f5c\uff0c\u800c\u4e0d\u9700\u8981\u7981\u6b62\u4e2d\u65ad\u4e86\u3002\u4f46\u662f\uff0c\u5199\u64cd\u4f5c\u7684\u4e2d\u65ad\u5fc5\u987b\u7981\u6b62\uff0c\u5426\u5219\u5c31\u4f1a\u9020\u6210\u6b7b\u9501\u3002\u56e0\u4e3a\u5199\u64cd\u4f5c\u9700\u8981\u7b49\u5f85\u8bfb\u64cd\u4f5c\u91ca\u653e\u9501\uff0c\u800c\u8bfb\u64cd\u4f5c\u9700\u8981\u7b49\u5f85\u5199\u64cd\u4f5c\u7684\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u8fd4\u56de\u3002
\u5728\u4f7f\u7528\u8bfb\u5199\u9501\u7684\u65f6\u5019\u9700\u8981\u6ce8\u610f\uff0c\u5f53\u8bfb\u9501\u88ab\u6301\u6709\u65f6\uff0c\u5199\u9501\u53ea\u80fd\u7b49\u5f85\u3002\u7136\u800c\u8bfb\u9501\u5374\u53ef\u4ee5\u7ee7\u7eed\u6210\u529f\u5730\u5360\u7528\u9501\u3002\u8fd9\u4f1a\u9020\u6210\u5199\u9501\u9965\u997f\u73b0\u8c61\u3002
\u5982\u679c\u52a0\u9501\u65f6\u95f4\u5f88\u957f\u6216\u8005\u4ee3\u7801\u5728\u6301\u6709\u9501\u65f6\u6709\u53ef\u80fd\u7761\u7720\uff0c\u90a3\u4e48\u6700\u597d\u4f7f\u7528\u4fe1\u53f7\u91cf\u6765\u5904\u7406\u3002
"},{"location":"linux/kernel/synch/#_10","title":"\u4fe1\u53f7\u91cf","text":"Linux\u4e2d\u7684\u4fe1\u53f7\u91cf\u662f\u4e00\u79cd\u7761\u7720\u9501\u3002\u5f53\u6709\u4e00\u4e2a\u4efb\u52a1\u8bd5\u56fe\u83b7\u5f97\u4e00\u4e2a\u5df2\u7ecf\u88ab\u5360\u7528\u7684\u4fe1\u53f7\u91cf\u65f6\uff0c\u8be5\u4efb\u52a1\u4f1a\u52a0\u5165\u7b49\u5f85\u961f\u5217\uff0c\u7136\u540e\u7761\u7720\u3002\u7531\u4e8e\u91ca\u653e\u4e86\u8d44\u6e90\u5904\u7406\u5668\u53ef\u4ee5\u53bb\u6267\u884c\u5176\u4ed6\u7684\u4ee3\u7801\u3002\u5f53\u6301\u6709\u7684\u4fe1\u53f7\u91cf\u88ab\u91ca\u653e\u65f6\uff0c\u5904\u4e8e\u7b49\u5f85\u961f\u5217\u4e2d\u7684\u90a3\u4e2a\u4efb\u52a1\u4f1a\u88ab\u5524\u9192\uff0c\u5e76\u83b7\u5f97\u8be5\u4fe1\u53f7\u91cf\u3002
\u5b9e\u9645\u4e0a\uff0cLinux\u63d0\u4f9b\u4e24\u79cd\u4fe1\u53f7\u91cf\uff1a
\u5185\u6838\u4fe1\u53f7\u91cf\uff0c\u7531\u5185\u6838\u6001\u4f7f\u7528 System V IPC\u4fe1\u53f7\u91cf\uff0c\u7531\u7528\u6237\u6001\u4f7f\u7528 \u7531\u4e8e\u4fe1\u53f7\u91cf\u4f1a\u7761\u7720\uff0c\u56e0\u6b64\u6709\u4ee5\u4e0b\u7ed3\u8bba\uff1a
\u4fe1\u53f7\u91cf\u9002\u7528\u4e8e\u9501\u4f1a\u88ab\u957f\u65f6\u95f4\u5360\u6709\u7684\u573a\u666f\u3002 \u4fe1\u53f7\u91cf\u53ea\u80fd\u5728\u8fdb\u7a0b\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\uff0c\u56e0\u4e3a\u4e2d\u65ad\u4e0a\u4e0b\u6587\u7981\u6b62\u7761\u7720\u3002 \u591a\u4e2a\u8fdb\u7a0b\u8bd5\u56fe\u83b7\u5f97\u4fe1\u53f7\u91cf\u4e0d\u4f1a\u6b7b\u9501\u3002 \u5982\u679c\u5df2\u7ecf\u5360\u7528\u4e86\u4fe1\u53f7\u91cf\uff0c\u4e0d\u80fd\u518d\u4f7f\u7528\u81ea\u65cb\u9501\uff0c\u56e0\u4e3a\u81ea\u65cb\u9501\u7981\u6b62\u7761\u7720\u3002 \u4fe1\u53f7\u91cf\u76f8\u6bd4\u81ea\u65cb\u9501\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u5730\u65b9\uff0c\u5c31\u662f\u5b83\u5185\u90e8\u7ef4\u62a4\u4e86\u4e00\u4e2acount
\u503c\uff0c\u8be5count
\u503c\u7b49\u540c\u4e8e\u540c\u4e00\u65f6\u95f4\u80fd\u591f\u6301\u6709\u4fe1\u53f7\u91cf\u7684\u6570\u91cf\u3002\u5982\u679c\u8fd9\u4e2a\u503c\u662f1\uff0c\u90a3\u4e48\u4fe1\u53f7\u91cf\u53c8\u88ab\u79f0\u4e3a\u4e92\u65a5\u4fe1\u53f7\u91cf\u3002\u4fe1\u53f7\u91cf\u652f\u6301\u4e24\u4e2a\u64cd\u4f5c\uff1adown()
\u64cd\u4f5c\u901a\u8fc7\u5bf9\u4fe1\u53f7\u91cf\u8ba1\u6570\u51cf1\u6765\u83b7\u5f97\u5b83\uff0c\u800cup()
\u64cd\u4f5c\u52a01\u6765\u91ca\u653e\u5b83\u3002
\u4fe1\u53f7\u91cf\u662f\u4e0e\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\uff0c\u5b9a\u4e49\u5728<asm/semaphore.h>\u4e2d\u3002\u521b\u5efa\u65b9\u6cd5\u5982\u4e0b\uff1a
struct semaphore name;\nsema_init(&name, count);\n
\u51fd\u6570down_interruptible()
\u8bd5\u56fe\u83b7\u53d6\u6307\u5b9a\u7684\u4fe1\u53f7\u91cf\uff0c\u5982\u679c\u4e0d\u53ef\u7528\uff0c\u5219\u5c06\u8fdb\u7a0b\u8bbe\u7f6e\u4e3aTASK_INTERRUPTIBLE\u3002\u8fd9\u79cd\u8fdb\u7a0b\u72b6\u6001\u610f\u5473\u7740\u4efb\u52a1\u53ef\u4ee5\u88ab\u4fe1\u53f7\u5524\u9192\u3002\u4f7f\u7528down_trylock()
\u51fd\u6570\uff0c\u5728\u4fe1\u53f7\u91cf\u5df2\u7ecf\u88ab\u5360\u7528\u65f6\uff0c\u7acb\u5373\u8fd4\u56de\u800c\u4e0d\u662f\u8ba9\u8fdb\u7a0b\u7761\u7720\u3002
"},{"location":"linux/kernel/synch/#_11","title":"\u4e92\u65a5\u4f53","text":"\u5728\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4fe1\u53f7\u91cf\u53ea\u662f\u4f5c\u4e3a\u4e00\u4e2a\u8ba1\u6570\u4e3a1\u7684\u5141\u8bb8\u7761\u7720\u7684\u81ea\u65cb\u9501\u5b58\u5728\u3002\u4e3a\u4e86\u627e\u5230\u4e00\u4e2a\u66f4\u7b80\u5355\u4e14\u53ef\u4ee5\u7761\u7720\u7684\u9501\uff0c\u5f00\u53d1\u8005\u4eec\u5f15\u5165\u4e86\u4e92\u65a5\u4f53\uff08mutex\uff09\u3002\u5176\u884c\u4e3a\u548c\u8ba1\u6570\u4e3a1\u7684\u4fe1\u53f7\u91cf\u7c7b\u4f3c\uff0c\u4f46\u662f\u64cd\u4f5c\u7684\u63a5\u53e3\u66f4\u7b80\u5355\uff0c\u5b9e\u73b0\u4e5f\u66f4\u9ad8\u6548\u3002\u57fa\u672c\u9002\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a
DEFINE_MUTEX(mutex);\nmutex_init(&mutex);\nmutex_lock(&mutex);\nmutex_unlock(&mutex);\n
mutex\u7684\u7b80\u4ecb\u4e0e\u9ad8\u6548\u6e90\u4e8e\u76f8\u6bd4\u4f7f\u7528\u4fe1\u53f7\u91cf\u66f4\u591a\u7684\u53d7\u9650\u6027\uff1a
\u4efb\u4f55\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a\u4efb\u52a1\u6301\u6709mutex\u3002 \u5fc5\u987b\u7531\u4e0a\u9501\u8005\u89e3\u9501\u2014\u2014\u8fd9\u610f\u5473\u7740\u4f60\u4e0d\u80fd\u5728\u4e00\u4e2a\u7ebf\u7a0b\u4e0a\u9501\uff0c\u800c\u5728\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u89e3\u9501\u3002 \u9012\u5f52\u5730\u4e0a\u9501\u548c\u89e3\u9501\u65f6\u4e0d\u88ab\u5141\u8bb8\u7684\u3002 \u5f53\u6301\u6709\u4e00\u4e2amutex\u65f6\uff0c\u8fdb\u7a0b\u4e0d\u80fd\u9000\u51fa\u3002 mutex\u4e0d\u80fd\u5728\u4e2d\u65ad\u6216\u8005\u4e0b\u534a\u90e8\u4e2d\u4f7f\u7528\u3002 \u9700\u6c42 \u5efa\u8bae\u7684\u52a0\u9501\u65b9\u5f0f \u4f4e\u5f00\u9500\u52a0\u9501 \u4f18\u5148\u4f7f\u7528\u81ea\u65cb\u9501 \u77ed\u671f\u52a0\u9501 \u4f18\u5148\u4f7f\u7528\u81ea\u65cb\u9501 \u957f\u671f\u52a0\u9501 \u4f18\u5148\u4f7f\u7528\u4e92\u65a5\u4f53 \u4e2d\u65ad\u4e0a\u4e0b\u6587\u52a0\u9501 \u4f7f\u7528\u81ea\u65cb\u9501 \u6301\u6709\u9501\u9700\u8981\u7761\u7720 \u4f7f\u7528\u4e92\u65a5\u4f53"},{"location":"linux/kernel/synch/#_12","title":"\u5b8c\u6210\u53d8\u91cf","text":"\u5982\u679c\u5728\u5185\u6838\u4e2d\u4e00\u4e2a\u4efb\u52a1\u9700\u8981\u53d1\u9001\u4fe1\u53f7\u901a\u77e5\u53e6\u4e00\u4e2a\u4efb\u52a1\u53d1\u751f\u4e86\u67d0\u79cd\u7279\u5b9a\u4e8b\u4ef6\uff0c\u6b64\u65f6\u53ef\u4ee5\u7528\u5b8c\u6210\u53d8\u91cf\uff08completion variable\uff09\u3002\u5f53\u67d0\u4e2a\u4efb\u52a1\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u4f1a\u4f7f\u7528\u5b8c\u6210\u53d8\u91cf\u53bb\u5524\u9192\u6b63\u5728\u7b49\u5f85\u7684\u4efb\u52a1\u3002
\u5b8c\u6210\u53d8\u91cf\u7531\u7ed3\u6784\u4f53completion\u8868\u793a\uff0c\u5b9a\u4e49\u5728<linux/completion.h>\u4e2d\u3002\u5176\u521b\u5efa\u65b9\u6cd5\u5982\u4e0b\uff1a
DECLARE_COMPLETION(comp);\n
\u6216\u8005\u4f7f\u7528init_completion()
\u52a8\u6001\u521b\u5efa\u3002\u9700\u8981\u7b49\u5f85\u7684\u4efb\u52a1\u8c03\u7528wait_for_completion()
\u6765\u7b49\u5f85\u7279\u5b9a\u4e8b\u4ef6\u3002\u5f53\u4e8b\u4ef6\u53d1\u751f\u540e\uff0c\u4ea7\u751f\u4e8b\u4ef6\u7684\u4efb\u52a1\u8c03\u7528complete()
\u6765\u53d1\u9001\u4fe1\u53f7\u5524\u9192\u6b63\u5728\u7b49\u5f85\u7684\u4efb\u52a1\u3002
"},{"location":"linux/kernel/synch/#rcu","title":"RCU\u673a\u5236","text":"\u8bfb\u53d6-\u590d\u5236-\u66f4\u65b0\uff08read-copy-update\uff09\u662f\u4e00\u79cd\u9ad8\u7ea7\u4e92\u65a5\u673a\u5236\uff0c\u4e00\u822c\u7528\u4e0d\u5230\u4f46\u662f\u6211\u4eec\u5bf9\u8fd9\u4e2a\u6982\u5ff5\u5f97\u6709\u4e00\u4e2a\u57fa\u672c\u7684\u4e86\u89e3\u3002RCU\u673a\u5236\u4e3b\u8981\u9488\u5bf9\u8bfb\u53d6\u7ecf\u5e38\u53d1\u751f\u3001\u4f46\u662f\u5199\u5165\u5f88\u5c11\u7684\u60c5\u51b5\u3002\u5728\u9700\u8981\u4fee\u6539\u6570\u636e\u65f6\uff0c\u5199\u5165\u7ebf\u7a0b\u9996\u5148\u590d\u5236\u4e00\u4efd\uff0c\u7136\u540e\u4fee\u6539\u526f\u672c\u3002\u5176\u4ed6\u7ebf\u7a0b\u5728\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u4ecd\u7136\u6307\u5411\u539f\u59cb\u7684\u5171\u4eab\u6570\u636e\u5730\u5740\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u5728\u5199\u64cd\u4f5c\u53d1\u751f\u524d\uff0c\u5176\u4ed6\u7ebf\u7a0b\u4ecd\u7136\u53ef\u4ee5\u8bfb\u53d6\u5230\u4e00\u81f4\u7684\u6570\u636e\u3002\u76f4\u5230\u66f4\u65b0\u7ebf\u7a0b\u5b8c\u6210\u4e86\u6570\u636e\u7684\u4fee\u6539\uff0c\u5e76\u901a\u8fc7\u7279\u5b9a\u7684API\u5c06\u66f4\u65b0\u540e\u7684\u6570\u636e\u6307\u9488\u8d4b\u503c\u56de\u539f\u6765\u7684\u5171\u4eab\u6570\u636e\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u79f0\u4e3a\u201c\u66f4\u65b0\u5b8c\u6210\u201d\u3002\u5185\u5b58\u5c4f\u969c\u6307\u4ee4\u7528\u4e8e\u4fdd\u8bc1\u53ea\u6709\u5728\u6570\u636e\u7ed3\u6784\u88ab\u4fee\u6539\u4e4b\u540e\uff0c\u5df2\u66f4\u65b0\u7684\u6307\u9488\u624d\u5bf9\u5176\u4ed6CPU\u53ef\u89c1\u3002\u8bfb\u53d6\u7aef\u7684\u4ee3\u7801\u5fc5\u987b\u653e\u7f6e\u4e8ercu_read_lock()
\u548crcu_read_unlock()
\u4e4b\u95f4\u3002
\u4f7f\u7528RCU\u6280\u672f\u7684\u96be\u70b9\u5728\u4e8e\uff1a\u5199\u5165\u7aef\u4fee\u6539\u6307\u9488\u65f6\u4e0d\u80fd\u7acb\u523b\u91ca\u653e\u6570\u636e\u7ed3\u6784\u7684\u65e7\u6307\u9488\uff0c\u56e0\u4e3a\u8fd8\u6709\u5176\u4ed6\u7684\u8bfb\u53d6\u7aef\u5728\u4f7f\u7528\u3002\u53ea\u6709\u5f53\u6240\u6709\u7684\u8bfb\u53d6\u7aef\u6267\u884c\u5b8c\u5b8frcu_read_unlcok()
\u4e4b\u540e\uff0c\u624d\u53ef\u4ee5\u91ca\u653e\u65e7\u6307\u9488\u3002\u5199\u5165\u7aef\u8c03\u7528\u51fd\u6570call_rcu()
\u6765\u91ca\u653e\u65e7\u6307\u9488\u3002
"},{"location":"linux/kernel/synch/#_13","title":"\u7981\u6b62\u62a2\u5360","text":"Linux\u662f\u62a2\u5360\u5f0f\u5185\u6838\uff0c\u5176\u4e3b\u8981\u7279\u70b9\u662f\uff1a\u4e00\u4e2a\u5728\u5185\u6838\u6001\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u53ef\u80fd\u5728\u6267\u884c\u5185\u6838\u6001\u51fd\u6570\u671f\u95f4\u88ab\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b\u62a2\u5360\u3002\u5728\u8fdb\u7a0bA\u6267\u884c\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u65f6\uff08\u6b21\u5403\u4f4d\u4e8e\u5185\u6838\u6001\uff09\uff0c\u4e00\u4e2a\u66f4\u6709\u4f18\u5148\u7ea7\u7684\u8fdb\u7a0bB\u53d8\u4e3a\u53ef\u6267\u884c\u72b6\u6001\u3002\u5982\u679c\u5185\u6838\u662f\u53ef\u62a2\u5360\u7684\uff0c\u5c31\u4f1a\u53d1\u751f\u5f3a\u5236\u6027\u4efb\u52a1\u5207\u6362\uff0c\u8ba9B\u53d6\u4ee3A\u3002\u518d\u6bd4\u5982\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u5df2\u7ecf\u7528\u5b8c\u4e86\u5b83\u7684\u65f6\u95f4\u7247\u914d\u989d\uff0c\u62a2\u5360\u5f0f\u5185\u6838\u4f1a\u7acb\u523b\u8ba9\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u53d6\u4ee3\u5b83\u3002
\u5185\u6838\u4f7f\u7528thread_info
\u4e2d\u7684preempt_count
\u5b57\u6bb5\u8868\u793a\u62a2\u5360\u8ba1\u6570\u3002\u5f53\u8fd9\u4e2a\u503c\u5927\u4e8e0\u65f6\uff0c\u5c31\u7981\u6b62\u5185\u6838\u62a2\u5360\u3002\u5b83\u5728\u4ee5\u4e0b\u4efb\u4f55\u4e00\u79cd\u60c5\u51b5\u53d1\u751f\u65f6\uff0c\u53d6\u503c\u90fd\u5927\u4e8e0\uff1a
\u5185\u6838\u6b63\u5728\u6267\u884c\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u3002
\u53ef\u5ef6\u8fdf\u51fd\u6570\u88ab\u7981\u6b62\uff08\u5f53\u5185\u6838\u6b63\u5728\u6267\u884c\u8f6f\u4e2d\u65ad\u6216tasklet\uff09\u3002
\u663e\u793a\u8bbe\u7f6e\u62a2\u5360\u8ba1\u6570\u5668\u4e3a\u6b63\u6570\u3002
\u5b8f \u8bf4\u660e preempt_count() \u8fd4\u56de\u62a2\u5360\u8ba1\u6570\u503c preempt_disable() \u4f7f\u62a2\u5360\u8ba1\u6570+1 preempt_enable() \u4f7f\u62a2\u5360\u8ba1\u6570-1\uff0c\u5e76\u68c0\u67e5TIF_NEED_RESCHED\u6807\u5fd7 preempt_enable_no_resched() \u4f7f\u62a2\u5360\u8ba1\u6570-1 \u4e0a\u9762\u7b2c\u4e09\u4e2a\u5b8f\u9700\u8981\u8bf4\u660e\u4e00\u4e0b\u3002preempt_enable()
\u5b8f\u9996\u5148\u9012\u51cf\u62a2\u5360\u8ba1\u6570\u5668\uff0c\u5e76\u4e14\u68c0\u67e5TIF_NEED_RESCHED\u6807\u5fd7\u662f\u5426\u88ab\u8bbe\u7f6e\u3002\u5f53\u8fd9\u4e2a\u6807\u5fd7\u4e3a1\u65f6\u8868\u793a\u9700\u8981\u6267\u884c\u8c03\u5ea6\u7a0b\u5e8f\u3002\u4e8e\u662f\u6211\u4eec\u8fd8\u4f1a\u8c03\u7528preempt_schedule()
\u6765\u8c03\u7528schedule()
\u9009\u62e9\u53e6\u5916\u4e00\u4e2a\u8fdb\u7a0b\u8fd0\u884c\u3002
"},{"location":"linux/kernel/synch/#_14","title":"\u987a\u5e8f\u4e0e\u5c4f\u969c","text":"\u4e3a\u4ec0\u4e48\u9700\u8981\u987a\u5e8f\u548c\u5c4f\u969c\u6307\u4ee4\uff1f
\u9632\u6b62\u7f16\u8bd1\u5668\u4f18\u5316\u5bfc\u81f4\u7684\u91cd\u6392\uff1a\u73b0\u4ee3\u7f16\u8bd1\u5668\u4f1a\u8fdb\u884c\u5404\u79cd\u4f18\u5316\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u5305\u62ec\u6307\u4ee4\u91cd\u6392\u3002\u5728\u4e0d\u8003\u8651\u5185\u5b58\u64cd\u4f5c\u987a\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u6539\u53d8\u6307\u4ee4\u7684\u6267\u884c\u987a\u5e8f\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u7684\u884c\u4e3a\u4e0e\u9884\u671f\u4e0d\u7b26\u3002\u901a\u8fc7\u4f7f\u7528\u987a\u5e8f\u548c\u5c4f\u969c\u6307\u4ee4\uff0c\u53ef\u4ee5\u9650\u5236\u7f16\u8bd1\u5668\u5bf9\u67d0\u4e9b\u5173\u952e\u4ee3\u7801\u6bb5\u7684\u4f18\u5316\u3002
\u4fdd\u8bc1\u5e76\u53d1\u64cd\u4f5c\u7684\u4e00\u81f4\u6027\uff1a\u5728\u591a\u6838\u5904\u7406\u5668\u548c\u591a\u7ebf\u7a0b\u7f16\u7a0b\u4e2d\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u64cd\u4f5c\u7cfb\u7edf\u7684\u8c03\u5ea6\u5668\u53ef\u80fd\u4f1a\u5728\u4e0d\u540c\u7684\u5904\u7406\u5668\u6838\u5fc3\u4e0a\u5e76\u884c\u6267\u884c\u591a\u4e2a\u7ebf\u7a0b\u3002\u4e3a\u4e86\u4fdd\u6301\u4e00\u81f4\u6027\uff0c\u9700\u8981\u786e\u4fdd\u6240\u6709\u6838\u5fc3\u4e0a\u7684\u5185\u5b58\u64cd\u4f5c\u90fd\u6309\u7167\u7a0b\u5e8f\u6307\u5b9a\u7684\u987a\u5e8f\u6267\u884c\u3002
\u89e3\u51b3CPU\u7f13\u5b58\u4e00\u81f4\u6027\u95ee\u9898\uff1aCPU\u7f13\u5b58\u662f\u5904\u7406\u5668\u901f\u5ea6\u7684\u5173\u952e\u90e8\u5206\uff0c\u4f46\u5b83\u7684\u5b58\u5728\u4e5f\u5e26\u6765\u4e86\u7f13\u5b58\u4e00\u81f4\u6027\u7684\u95ee\u9898\u3002\u5f53\u4e00\u4e2aCPU\u6838\u5fc3\u5199\u5165\u6570\u636e\uff0c\u800c\u8fd9\u4e2a\u6570\u636e\u53c8\u88ab\u53e6\u4e00\u4e2a\u6838\u5fc3\u7684\u7f13\u5b58\u6240\u7f13\u5b58\u65f6\uff0c\u6ca1\u6709\u5c4f\u969c\u7684\u8bdd\uff0c\u53e6\u4e00\u4e2a\u6838\u5fc3\u53ef\u80fd\u4f1a\u8bfb\u53d6\u5230\u65e7\u7684\u6570\u636e\u7248\u672c\u3002\u5185\u5b58\u5c4f\u969c\u80fd\u591f\u786e\u4fdd\u6240\u6709\u6838\u5fc3\u770b\u5230\u5185\u5b58\u64cd\u4f5c\u7684\u6700\u7ec8\u4e00\u81f4\u6027\u3002
Linux\u4e2d\u7684\u5185\u5b58\u5c4f\u969c\u6307\u4ee4\uff1a
\u5b8f \u8bf4\u660e mb() \u9002\u7528\u4e8eMP\u548cUP\u7684\u5185\u5b58\u5c4f\u969c rmb() \u9002\u7528\u4e8eMP\u548cUP\u7684\u8bfb\u5185\u5b58\u5c4f\u969c wmb() \u9002\u7528\u4e8eMP\u548cUP\u7684\u5199\u5185\u5b58\u5c4f\u969c smp_mb() \u4ec5\u9002\u7528\u4e8eMP\u7684\u5185\u5b58\u5c4f\u969c smp_rmb() \u4ec5\u9002\u7528\u4e8eMP\u7684\u8bfb\u5185\u5b58\u5c4f\u969c smp_wmb() \u4ec5\u9002\u7528\u4e8eMP\u7684\u5199\u5185\u5b58\u5c4f\u969c \u6b64\u7c7b\u6307\u4ee4\u4e0e\u4f53\u7cfb\u7ed3\u6784\u5bc6\u5207\u76f8\u5173\uff0c\u8bf7\u53c2\u8003ARM\u5185\u5b58\u5c4f\u969c\u6307\u4ee4\u3002
"},{"location":"linux/kernel/vma/","title":"\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4","text":"\u5185\u6838\u9664\u4e86\u7ba1\u7406\u672c\u8eab\u7684\u5185\u5b58\u5916\uff0c\u8fd8\u5fc5\u987b\u7ba1\u7406\u7528\u6237\u7a7a\u95f4\u4e2d\u8fdb\u7a0b\u7684\u5185\u5b58\u3002\u6211\u4eec\u79f0\u8fd9\u4e2a\u5185\u5b58\u4e3a\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u3002Linux\u64cd\u4f5c\u7cfb\u7edf\u91c7\u7528\u865a\u62df\u5185\u5b58\u6280\u672f\uff0c\u5bf9\u4e00\u4e2a\u8fdb\u7a0b\u800c\u8a00\uff0c\u5b83\u4ee5\u865a\u62df\u7684\u65b9\u5f0f\u8bbf\u95ee\u6574\u4e2a\u7cfb\u7edf\u7684\u6240\u6709\u7269\u7406\u5185\u5b58\uff0c\u751a\u81f3\u5176\u865a\u62df\u7a7a\u95f4\u53ef\u4ee5\u8fdc\u8fdc\u5927\u4e8e\u7269\u7406\u5185\u5b58\u3002
\u4e3a\u4ec0\u4e48\u8981\u6709\u865a\u62df\u5185\u5b58\uff1f
\u5728\u8003\u8651\u4e24\u4e2a\u7a0b\u5e8f\u540c\u65f6\u64cd\u4f5c\u7269\u7406\u5185\u5b58\u7684\u573a\u666f\u65f6\uff0c\u6211\u4eec\u5fc5\u987b\u8c28\u614e\u5730\u4e3a\u5b83\u4eec\u5206\u914d\u5185\u5b58\u5730\u5740\uff0c\u5e76\u786e\u4fdd\u6bcf\u4e2a\u7a0b\u5e8f\u4ec5\u8bbf\u95ee\u5176\u88ab\u5206\u914d\u7684\u5185\u5b58\u533a\u57df\uff0c\u9632\u6b62\u5730\u5740\u51b2\u7a81\u3002\u624b\u52a8\u7ba1\u7406\u5185\u5b58\u5730\u5740\u4f1a\u6781\u5927\u5730\u589e\u52a0\u7f16\u7a0b\u7684\u590d\u6742\u6027\u3002\u7136\u800c\uff0c\u5982\u679c\u6211\u4eec\u80fd\u591f\u5b9e\u73b0\u4e00\u79cd\u673a\u5236\uff0c\u5b83\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u8fdb\u7a0b\u63d0\u4f9b\u4e00\u5957\u9694\u79bb\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5c06\u4e3a\u8fd9\u4e9b\u865a\u62df\u5730\u5740\u6620\u5c04\u5230\u7269\u7406\u5185\u5b58\uff0c\u4e14\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u72ec\u7acb\u4e8e\u5176\u4ed6\u8fdb\u7a0b\u64cd\u4f5c\uff0c\u90a3\u4e48\u8fd9\u5c06\u6781\u5927\u5730\u7b80\u5316\u7f16\u7a0b\u5de5\u4f5c\u3002\u8fd9\u79cd\u673a\u5236\u5c31\u662f\u865a\u62df\u5185\u5b58\u7ba1\u7406\uff0c\u800c\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u5185\u5b58\u7ba1\u7406\u5355\u5143\uff08MMU\uff09\u5219\u8d1f\u8d23\u5c06\u865a\u62df\u5730\u5740\u8f6c\u6362\u4e3a\u7269\u7406\u5730\u5740\u3002
Linux\u91c7\u7528\u4e86\u57fa\u4e8e\u5206\u9875\u7684\u865a\u62df\u5185\u5b58\u7ba1\u7406\u673a\u5236\uff0c\u5176\u4e2d\u5185\u5b58\u88ab\u5212\u5206\u4e3a\u5927\u5c0f\u56fa\u5b9a\u7684\u9875\uff0c\u6bcf\u4e00\u9875\u901a\u5e38\u662f4KB\u3002\u8fd9\u79cd\u5206\u9875\u673a\u5236\u4f7f\u5f97\u5185\u5b58\u7ba1\u7406\u66f4\u52a0\u7075\u6d3b\u548c\u9ad8\u6548\u3002\u5728Linux\u4e2d\uff0c\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u8f6c\u6362\u662f\u901a\u8fc7\u591a\u7ea7\u9875\u8868\u6765\u5b9e\u73b0\u7684\uff0c\u8fd9\u79cd\u5206\u7ea7\u7ed3\u6784\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u5927\u578b\u5730\u5740\u7a7a\u95f4\uff0c\u540c\u65f6\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002\u4e3a\u4e86\u63d0\u9ad8\u5730\u5740\u8f6c\u6362\u7684\u901f\u5ea6\uff0c\u73b0\u4ee3CPU\u8bbe\u8ba1\u901a\u5e38\u5305\u62ec\u4e00\u4e2a\u79f0\u4e3a\u8f6c\u6362\u540e\u63f4\u7f13\u51b2\u5668\uff08TLB\uff09\u7684\u786c\u4ef6\u7f13\u5b58\u3002TLB\u7f13\u5b58\u4e86\u6700\u8fd1\u4f7f\u7528\u8fc7\u7684\u9875\u8868\u9879\uff0c\u8fd9\u6837\u5f53CPU\u9700\u8981\u8bbf\u95ee\u4e00\u4e2a\u5185\u5b58\u5730\u5740\u65f6\uff0c\u5b83\u9996\u5148\u68c0\u67e5TLB\uff0c\u5982\u679c\u627e\u5230\u4e86\u5339\u914d\u7684\u6761\u76ee\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u88ab\u79f0\u4e3aTLB\u547d\u4e2d\uff0c\u53ef\u4ee5\u5feb\u901f\u5b8c\u6210\u5730\u5740\u8f6c\u6362\uff0c\u907f\u514d\u8bbf\u95ee\u4e3b\u5185\u5b58\u4e2d\u7684\u9875\u8868\uff0c\u4ece\u800c\u663e\u8457\u63d0\u5347\u6027\u80fd\u3002\u5f53\u53d1\u751fTLB\u672a\u547d\u4e2d\u7684\u60c5\u51b5\u65f6\uff0cCPU\u5fc5\u987b\u8bbf\u95ee\u4e3b\u5185\u5b58\u4e2d\u7684\u9875\u8868\u6765\u83b7\u53d6\u6b63\u786e\u7684\u7269\u7406\u5730\u5740\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u8f83\u5927\u7684\u6027\u80fd\u5f00\u9500\u3002\u56e0\u6b64\uff0c\u64cd\u4f5c\u7cfb\u7edf\u548c\u786c\u4ef6\u8bbe\u8ba1\u8005\u90fd\u4f1a\u5c3d\u91cf\u4f18\u5316TLB\u7684\u547d\u4e2d\u7387\uff0c\u4ee5\u51cf\u5c11\u8fd9\u79cd\u5f00\u9500\u3002
"},{"location":"linux/kernel/vma/#_2","title":"\u5730\u5740\u7a7a\u95f4\u7684\u6982\u5ff5","text":"\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u7531\u53ef\u5bfb\u5740\u7684\u865a\u62df\u5185\u5b58\u7ec4\u6210\uff0c\u572832\u4f4d\u4f53\u7cfb\u4e2d\uff08\u53ea\u8ba8\u8bba32\u4f4d\u67b6\u6784\uff0c64\u4f4d\u7c7b\u4f3c\uff09\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u53ef\u5bfb\u57404GB\u7684\u865a\u62df\u5185\u5b58\uff0c\u5176\u4e2d1GB\u5206\u914d\u7ed9\u5185\u6838\u7a7a\u95f4\uff0c\u5269\u4e0b3GB\u5206\u914d\u7ed9\u7528\u6237\u7a7a\u95f4\u3002\u4e00\u4e2a\u8fdb\u7a0b\u53ea\u80fd\u8bbf\u95ee\u6709\u6548\u5185\u5b58\u533a\u57df\u5185\u7684\u5185\u5b58\u5730\u5740\uff0c\u90e8\u5206\u5730\u5740\u662f\u975e\u6cd5\u7684\uff0c\u4e00\u65e6\u8bbf\u95ee\uff0c\u5c31\u4f1a\u7acb\u523b\u89e6\u53d1\u6bb5\u9519\u8bef\uff0c\u7531\u5185\u6838\u7ec8\u6b62\u8be5\u8fdb\u7a0b\u3002\u6bcf\u4e2a\u5185\u5b58\u533a\u57df\u4e5f\u6709\u76f8\u5173\u7684\u6743\u9650\uff0c\u6bd4\u5982\u53ef\u8bfb\u53ef\u5199\u53ef\u6267\u884c\u7b49\u3002
\u8fdb\u7a0b\u7684\u865a\u62df\u5185\u5b58\u7a7a\u95f4\u5206\u5e03\u5982\u4e0b\u56fe\u6240\u793a\uff1a
\u4ece\u4e0a\u56fe\u4e2d\u6211\u4eec\u770b\u5230\uff0c0x0000 0000\u52300x0804 8000\u8fd9\u6bb5\u7a7a\u95f4\u662f\u4e0d\u53ef\u8bbf\u95ee\u7684\u4fdd\u7559\u533a\uff0c\u5728\u5927\u591a\u6570\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u6570\u503c\u6bd4\u8f83\u5c0f\u7684\u5730\u5740\u662f\u975e\u6cd5\u5730\u5740\uff0c\u4e0d\u5141\u8bb8\u8bbf\u95ee\u7684\u3002\u6bd4\u5982NULL\u6307\u9488\u5c31\u4f1a\u6307\u5411\u8fd9\u7247\u533a\u57df\u3002
0x0804 8000\u81f30xC000 0000\u662f\u7528\u6237\u6001\u7a7a\u95f4\u5730\u5740\uff0c\u518d\u7f51\u4e0a\u5c31\u662f\u6240\u8c13\u7684\u9ad8\u7aef\u5730\u5740\u2014\u2014\u4f9b\u5185\u6838\u4f7f\u7528\u3002\u5185\u6838\u6001\u4e0e\u7528\u6237\u6001\u7684\u5206\u754c\u7ebf\u7531\u6210\u5458\u53d8\u91cftask_size\u5b9a\u4e49\u3002
\u4fdd\u7559\u533a\u4e0a\u65b9\u662f\u4ee3\u7801\u6bb5\u548c\u6570\u636e\u6bb5\uff0c\u5b83\u4eec\u662f\u4ece\u53ef\u6267\u884c\u6587\u4ef6\u76f4\u63a5\u52a0\u8f7d\u8fdb\u6765\u7684\u3002\u7f16\u8bd1\u540e\u7684\u4ee3\u7801\u653e\u5728\u4ee3\u7801\u6bb5\uff0c\u6570\u636e\u6bb5\u7528\u6765\u5b58\u653e\u5df2\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u3002
BSS\u6bb5\u7528\u6765\u5b58\u653e\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u4ee50\u586b\u5145\u3002
BSS\u6bb5\u4e0a\u65b9\u662f\u5806\u7a7a\u95f4\uff0c\u5730\u5740\u7684\u589e\u957f\u65b9\u5411\u662f\u4ece\u4f4e\u5230\u9ad8\u3002\u5185\u6838\u4f7f\u7528start_brk
\u6807\u8bc6\u5806\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0cbrk
\u6807\u8bc6\u5806\u5f53\u524d\u7684\u7ed3\u675f\u4f4d\u7f6e\u3002\u5f53\u5806\u7533\u8bf7\u4e00\u5757\u5f88\u5c0f\u7684\u5185\u5b58\uff08128K\u4ee5\u5185\uff09\uff0c\u53ea\u9700\u8981\u5c06brk
\u6307\u9488\u589e\u52a0\u5bf9\u5e94\u7684\u5927\u5c0f\u5373\u53ef\u3002\u5806\u5185\u5b58\u7684\u7ba1\u7406\u6bd4\u8f83\u590d\u6742\uff0c\u5806\u5185\u5b58\u6700\u5927\u7684\u56f0\u96be\u5c31\u662f\u9891\u7e41\u5730\u5206\u914d\u548c\u91ca\u653e\u4f1a\u9020\u6210\u5185\u5b58\u788e\u7247\u3002\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u4e2a\u95ee\u9898\uff0c\u5185\u6838\u91c7\u7528\u4e86\u57fa\u4e8e\u4f19\u4f34\u7cfb\u7edf\u7684\u5185\u5b58\u5206\u914d\u7b97\u6cd5\u3002
\u5806\u7a7a\u95f4\u4e0a\u65b9\u662f\u5f85\u5206\u914d\u533a\u57df\uff0c\u7528\u6765\u6269\u5c55\u5806\u7a7a\u95f4\u7684\u4f7f\u7528\u3002\u63a5\u4e0b\u6765\u662f\u5185\u5b58\u6620\u5c04\u533a\u57df\u3002\u4efb\u4f55\u5e94\u7528\u7a0b\u5e8f\u90fd\u53ef\u4ee5\u901a\u8fc7mmap()
\u7cfb\u7edf\u8c03\u7528\u6620\u5c04\u81f3\u6b64\u533a\u57df\u3002\u5185\u5b58\u6620\u5c04\u53ef\u4ee5\u7528\u6765\u52a0\u8f7d\u52a8\u6001\u5e93\uff0c\u6bd4\u5982 ld-linux.so \u5c31\u88ab\u52a0\u8f7d\u4e8e\u6b64\uff0c\u53e6\u5916\uff0c\u5982\u679c\u4f60\u901a\u8fc7malloc()
\u7533\u8bf7\u4e86\u8d85\u8fc7128K\u5185\u5b58\uff0c\u5185\u6838\u5c06\u76f4\u63a5\u4e3a\u4f60\u5206\u914d\u4e00\u5757\u6620\u5c04\u533a\u57df\u4f5c\u4e3a\u5185\u5b58\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u5806\u5185\u5b58\u3002
\u6700\u540e\u4e00\u5757\u533a\u57df\u662f\u6808\u7a7a\u95f4\uff0c\u5728\u8fd9\u91cc\u4fdd\u5b58\u51fd\u6570\u8fd0\u884c\u8fc7\u7a0b\u9700\u8981\u7684\u5c40\u90e8\u53d8\u91cf\u4ee5\u53ca\u51fd\u6570\u53c2\u6570\u7b49\u4fe1\u606f\u3002\u6808\u7a7a\u95f4\u7684\u5730\u5740\u662f\u4ece\u9ad8\u5230\u4f4e\u589e\u957f\u7684\u3002\u5185\u6838\u4f7f\u7528start_stack
\u6807\u8bc6\u6808\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002SP\u5bc4\u5b58\u5668\u4fdd\u5b58\u6808\u9876\u6307\u9488\uff0cBP\u5bc4\u5b58\u5668\u4fdd\u5b58\u6808\u57fa\u5730\u5740\u3002
"},{"location":"linux/kernel/vma/#mm_struct","title":"\u5185\u5b58\u63cf\u8ff0\u7b26mm_struct","text":"mm_struct
\u7528\u6765\u8868\u793a\u8fdb\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u7684\u4fe1\u606f\uff0c\u5b9a\u4e49\u5728\u6587\u4ef6<linux/mm_types.h>\u4e2d\uff1a
struct mm_struct {\n atomic_t mm_users;\n atomic_t mm_count;\n struct vm_area_struct *mmap;\n struct rb_root mm_rb;\n struct list_head mmlist;\n\n unsigned long start_code, end_code; //\u4ee3\u7801\u6bb5\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long start_data, end_data; //\u6570\u636e\u6bb5\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long start_brk, brk, //\u5806\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long start_stack; //\u6808\u7684\u8d77\u59cb\u5730\u5740\n unsigned long arg_start, arg_end, //\u547d\u4ee4\u884c\u53c2\u6570\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long env_start, env_end; //\u73af\u5883\u53d8\u91cf\u7684\u8d77\u59cb\u548c\u7ed3\u675f\u5730\u5740\n unsigned long mmap_base; //\u5185\u5b58\u6620\u5c04\u533a\u7684\u8d77\u59cb\u5730\u5740\n unsigned long total_vm; //\u603b\u5171\u6620\u5c04\u7684\u9875\u6570\u76ee\n unsigned long locked_vm; //\u88ab\u9501\u5b9a\u4e0d\u80fd\u6362\u51fa\u7684\u9875\u6570\u76ee\n unsigned long pinned_vm; //\u65e2\u4e0d\u80fd\u6362\u51fa\uff0c\u4e5f\u4e0d\u80fd\u79fb\u52a8\u7684\u9875\u6570\u76ee\n unsigned long data_vm; //\u6570\u636e\u6bb5\u4e2d\u6620\u5c04\u7684\u9875\u6570\u76ee\n unsigned long exec_vm; //\u4ee3\u7801\u6bb5\u4e2d\u53ef\u6267\u884c\u6587\u4ef6\u7684\u9875\u6570\u76ee\n unsigned long stack_vm; //\u6808\u4e2d\u6620\u5c04\u7684\u9875\u6570\u76ee\n};\n
mm_users\u8bb0\u5f55\u6b63\u5728\u4f7f\u7528\u8be5\u5730\u5740\u7684\u8fdb\u7a0b\u6570\u76ee\uff0c\u6bd4\u5982\u5982\u679c\u6709\u4e24\u4e2a\u7ebf\u7a0b\u5171\u4eab\u8be5\u5730\u5740\u7a7a\u95f4\uff0c\u90a3\u4e48mm_users\u7684\u503c\u4fbf\u7b49\u4e8e2\u3002mm_count\u662fmm_struct\u7ed3\u6784\u4f53\u7684\u4e3b\u5f15\u7528\u8ba1\u6570\uff0c\u5f53\u503c\u4e3a0\u65f6\uff0c\u8be5\u7ed3\u6784\u4f53\u4f1a\u88ab\u91ca\u653e\u3002
mmap\u4f7f\u7528\u5355\u72ec\u94fe\u8868\u8fde\u63a5\u6240\u6709\u7684\u5185\u5b58\u533a\u57df\u5bf9\u8c61\u3002\u6bcf\u4e00\u4e2avm_area_struct
\u7ed3\u6784\u4f53\u901a\u8fc7\u81ea\u8eab\u7684vm_next\u6307\u9488\u88ab\u8fde\u5165\u94fe\u8868\u3002mmap\u6307\u5411\u94fe\u8868\u4e2d\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002
mm_rb\u5219\u4f7f\u7528\u7ea2\u9ed1\u6811\u3002mm_rb\u6307\u5411\u6839\u8282\u70b9\uff0c\u6bcf\u4e00\u4e2avm_area_struc
\u7ed3\u6784\u4f53\u901a\u8fc7\u81ea\u8eab\u7684vm_rb\u8fde\u63a5\u5230\u6811\u4e2d\u3002
\u5728\u8fdb\u7a0b\u7ba1\u7406\u4e0e\u8c03\u5ea6\u4e2d\u6211\u4eec\u4ecb\u7ecd\u4e86mm\u53d8\u91cf\uff0c\u7528\u6765\u5b58\u653e\u8be5\u8fdb\u7a0b\u4f7f\u7528\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\uff0ccurrent->mm
\u5c31\u6307\u5411\u5f53\u524d\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002fork()
\u51fd\u6570\u5229\u7528copy_mm()
\u51fd\u6570\u590d\u5236\u7236\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002\u5982\u679c\u7236\u5b50\u8fdb\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4\uff0c\u5219\u5728\u8c03\u7528clone()
\u65f6\uff0c\u8bbe\u7f6eCLONE_VM\u6807\u5fd7\uff0c\u8fd9\u6837\u7684\u8fdb\u7a0b\u5c31\u662f\u7ebf\u7a0b\u3002\u5728Linux\u73af\u5883\u4e0b\uff0c\u662f\u5426\u5171\u4eab\u5730\u5740\u7a7a\u95f4\u51e0\u4e4e\u662f\u8fdb\u7a0b\u548c\u7ebf\u7a0b\u672c\u8d28\u4e0a\u7684\u552f\u4e00\u533a\u522b\u3002\u5982\u679c\u6307\u5b9a\u4e86CLONE_VM,\u7ebf\u7a0b\u5c31\u4e0d\u9700\u8981\u53e6\u5916\u5206\u914d\u5730\u5740\u7a7a\u95f4\u4e86\uff0c\u800c\u662f\u76f4\u63a5\u5c06mm\u57df\u76f4\u63a5\u6307\u5411\u7236\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u5373\u53ef\u3002
\u5185\u6838\u7ebf\u7a0b\u6ca1\u6709\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\uff0c\u4e5f\u6ca1\u6709\u76f8\u5173\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\uff0c\u5176mm\u57df\u4e3aNULL\u3002\u5f53\u4e00\u4e2a\u5185\u6838\u7ebf\u7a0b\u88ab\u8c03\u5ea6\u65f6\uff0c\u5b83\u4f1a\u76f4\u63a5\u4f7f\u7528\u524d\u4e00\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u63cf\u8ff0\u7b26\u3002
"},{"location":"linux/kernel/vma/#_3","title":"\u865a\u62df\u5185\u5b58\u533a\u57df","text":"\u865a\u62df\u5185\u5b58\u533a\u57df\uff08Virtual Memory Area, VMA\uff09\u5728\u5185\u6838\u4e2d\u7528vm_area_struct
\u7ed3\u6784\u4f53\u63cf\u8ff0\u3002\u6bcf\u4e2avm_area_struct
\u7ed3\u6784\u90fd\u5bf9\u5e94\u4e8e\u6307\u5b9a\u5730\u5740\u7a7a\u95f4\u4e0a\u67d0\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002vm_start\u6307\u5411\u4e86\u8fd9\u5757\u865a\u62df\u5185\u5b58\u533a\u57df\u7684\u8d77\u59cb\u5730\u5740\uff0cvm_end\u6307\u5411\u4e86\u8fd9\u5757\u865a\u62df\u5185\u5b58\u533a\u57df\u7684\u7ed3\u675f\u5730\u5740\u3002vm_area_struct
\u7ed3\u6784\u4f53\u63cf\u8ff0\u7684\u662f[vm_start\uff0cvm_end)\u8fd9\u6837\u4e00\u6bb5\u5de6\u95ed\u53f3\u5f00\u7684\u865a\u62df\u5185\u5b58\u533a\u57df\u3002
\u5185\u6838\u5c06\u6bcf\u4e2a\u5185\u5b58\u533a\u57df\u4f5c\u4e3a\u4e00\u4e2a\u5355\u72ec\u7684\u5185\u5b58\u5bf9\u8c61\u7ba1\u7406\uff0c\u6bcf\u4e2a\u533a\u57df\u53c8\u4e00\u81f4\u7684\u5c5e\u6027\u548c\u64cd\u4f5c\uff0c\u4e0b\u9762\u7ed9\u51favm_area_struct
\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\uff1a
struct vm_area_struct {\n struct mm_struct *vm_mm; //\u76f8\u5173\u7684mm_struct\u7ed3\u6784\u4f53\n unsigned long vm_start; //\u533a\u95f4\u7684\u9996\u5730\u5740\n unsigned long vm_end; //\u533a\u95f4\u7684\u5c3e\u5730\u5740\n struct vm_area_struct *vm_next; //VMA\u94fe\u8868\n pgprot_t vm_page_prot; //\u8bbf\u95ee\u63a7\u5236\u6743\u9650\n unsigned long vm_flags; //\u6807\u5fd7\u4f4d\n struct rb_node vm_rb; //\u7ea2\u9ed1\u6811\u8282\u70b9\n struct anon_vma *anon_vma; //\u533f\u540dVMA\u5bf9\u8c61\n const struct vm_operations_struct *vm_ops; //VMA\u7684\u64cd\u4f5c\u51fd\u6570\n unsigned long vm_pgoff; //\u6587\u4ef6\u4e2d\u7684\u504f\u79fb\u91cf\n struct file *vm_file; //\u88ab\u6620\u5c04\u7684\u6587\u4ef6\n void *vm_private_data; //\u79c1\u6709\u6570\u636e\n};\n
\u6bcf\u4e2a\u5185\u5b58\u63cf\u8ff0\u7b26\u5bf9\u5e94\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4\u4e2d\u7684\u552f\u4e00\u7a7a\u95f4\uff0c\u8303\u56f4\u662f[vm_start, vm_end)\u3002vm_mm\u6307\u5411\u4e0eVMA\u76f8\u5173\u7684mm_struct
\u7ed3\u6784\u4f53\uff0cvm_next\u8d1f\u8d23\u5c06VMA\u4e32\u8054\u6210\u94fe\u8868\u3002
"},{"location":"linux/kernel/vma/#vma","title":"VMA\u6807\u5fd7","text":"vm_flags\u5b9a\u4e49\u4e86VMA\u7684\u6807\u5fd7\uff0c\u5b83\u8868\u793a\u5185\u5b58\u533a\u57df\u7684\u884c\u4e3a\u548c\u4fe1\u606f\u3002\u4e00\u4e9b\u6bd4\u8f83\u91cd\u8981\u7684\u6807\u5fd7\u6bd4\u5982\uff1aVM_READ\u3001VM_WRITE\u548cVM_EXEC\u6807\u5fd7\u4e86\u5185\u5b58\u533a\u57df\u4e2d\u9875\u9762\u7684\u53ef\u8bfb\u3001\u53ef\u5199\u3001\u53ef\u6267\u884c\u6743\u9650\u3002\u5f53\u8bbf\u95eeVMA\u65f6\uff0c\u9700\u8981\u67e5\u770b\u5176\u8bbf\u95ee\u6743\u9650\u3002
VM_SHARED\u8868\u793a\u5185\u5b58\u533a\u57df\u5305\u542b\u7684\u6620\u5c04\u662f\u5426\u53ef\u4ee5\u5728\u591a\u8fdb\u7a0b\u4e4b\u95f4\u5171\u4eab\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86\u8be5\u6807\u5fd7\u4f4d\uff0c\u6211\u4eec\u79f0\u5176\u4f4d\u5171\u4eab\u6620\u5c04\uff0c\u5426\u5219\u5c31\u662f\u79c1\u6709\u6620\u5c04\u3002
VM_IO\u6807\u5fd7\u5185\u5b58\u533a\u57df\u4e2d\u5bf9\u8bbe\u5907I/O\u7a7a\u95f4\u7684\u6620\u5c04\u3002\u8be5\u6807\u5fd7\u901a\u5e38\u5728\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u6267\u884cmmap()
\u51fd\u6570\u65f6\u624d\u88ab\u8bbe\u7f6e\u3002VM_RESERVED\u6807\u5fd7\u89c4\u5b9a\u4e86\u5185\u5b58\u533a\u57df\u4e0d\u80fd\u88ab\u6362\u51fa\u3002
"},{"location":"linux/kernel/vma/#vma_1","title":"VMA\u64cd\u4f5c","text":"vm_ops\u57df\u6307\u5411\u4e0e\u5185\u5b58\u533a\u57df\u76f8\u5173\u7684\u64cd\u4f5c\u51fd\u6570\uff0c\u7531vm_operations_struct
\u7ed3\u6784\u4f53\u8868\u793a\uff1a
struct vm_operations_struct {\n void (*open)(struct vm_area_struct *);\n void (*close)(sturct vm_area_struct *);\n int (*fault)(struct vm_area_struct *, struct vm_fault *);\n int (*page_mkwrite)(struct vm_area_struct *vma, struct vm_fault *vmf);\n int (*access)(struct vm_area_struct *, unsigned long, void *, int, int);\n};\n
"},{"location":"linux/kernel/vma/#malloc","title":"malloc()\u539f\u7406","text":"malloc()
\u662fC\u5e93\u91cc\u7684\u4e00\u4e2a\u52a8\u6001\u5206\u914d\u5185\u5b58\u7684\u51fd\u6570\uff0c\u7533\u8bf7\u5185\u5b58\u65f6\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a
\u65b9\u5f0f\u4e00\uff1a\u901a\u8fc7brk()
\u7cfb\u7edf\u8c03\u7528\u4ece\u5806\u5206\u914d\u5185\u5b58\u3002
\u65b9\u5f0f\u4e8c\uff1a\u901a\u8fc7mmap()
\u7cfb\u7edf\u8c03\u7528\u4ece\u6587\u4ef6\u6620\u5c04\u533a\u5206\u914d\u5185\u5b58\u3002
\u7b2c\u4e00\u79cd\u65b9\u5f0f\u5f88\u7b80\u5355\uff0c\u901a\u8fc7\u7b80\u5355\u5730\u8c03\u6574brk\u6307\u9488\u5411\u9ad8\u5730\u5740\u79fb\u52a8\uff0c\u5373\u5b8c\u6210\u4e86\u5185\u5b58\u5206\u914d\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u76f4\u63a5\u5728\u6587\u4ef6\u6620\u5c04\u533a\u6620\u5c04\u4e00\u5757\u5185\u5b58\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
malloc()
\u6e90\u7801\u89c4\u5b9a\u4e86\u4e00\u4e2a\u9608\u503c\uff1a
\u5982\u679c\u5206\u914d\u7684\u5185\u5b58\u5c0f\u4e8e\u8fd9\u4e2a\u9608\u503c\uff0c\u5219\u901a\u8fc7brk()
\u7533\u8bf7\u5185\u5b58\u3002
\u5982\u679c\u5206\u914d\u7684\u5185\u5b58\u5927\u4e8e\u8fd9\u4e2a\u9608\u503c\uff0c\u5219\u901a\u8fc7mmap()
\u7533\u8bf7\u5185\u5b58\u3002
\u8bbe\u8ba1\u5185\u5b58\u5206\u914d\u7b56\u7565\u65f6\uff0c\u6838\u5fc3\u76ee\u6807\u662f\u5728\u6027\u80fd\u548c\u8d44\u6e90\u7ba1\u7406\u4e4b\u95f4\u627e\u5230\u6700\u4f73\u5e73\u8861\u70b9\u3002\u5bf9\u4e8e\u5c0f\u5185\u5b58\u5757\u7684\u9891\u7e41\u5206\u914d\u4e0e\u91ca\u653e\u64cd\u4f5c\uff0cmalloc()
\u91c7\u7528 brk()
\u7cfb\u7edf\u8c03\u7528\u8fdb\u884c\u5185\u5b58\u7ba1\u7406\u3002\u91ca\u653e\u7684\u5185\u5b58\u5e76\u4e0d\u4f1a\u7acb\u5373\u8fd4\u56de\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u800c\u662f\u88ab\u7f13\u5b58\u81f3\u5185\u5b58\u6c60\u4e2d\uff0c\u4ee5\u4fbf\u4e8e\u540e\u7eed\u7684\u5206\u914d\u8bf7\u6c42\u80fd\u591f\u5feb\u901f\u91cd\u7528\u8fd9\u4e9b\u5df2\u91ca\u653e\u7684\u5185\u5b58\u5757\uff0c\u4ece\u800c\u51cf\u5c11\u7cfb\u7edf\u8c03\u7528\u7684\u6b21\u6570\u548c\u76f8\u5173\u7684\u6027\u80fd\u5f00\u9500\u3002
\u5bf9\u4e8e\u5927\u5185\u5b58\u5757\u7684\u5206\u914d\uff0cmalloc
\u5219\u53ef\u80fd\u4f7f\u7528 mmap()
\u7cfb\u7edf\u8c03\u7528\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u9996\u6b21\u8bbf\u95ee\u65f6\u53ef\u80fd\u4f1a\u89e6\u53d1\u7f3a\u9875\u4e2d\u65ad\uff0c\u56e0\u4e3a\u5206\u914d\u7684\u5185\u5b58\u521d\u59cb\u5904\u4e8e\u672a\u6620\u5c04\u72b6\u6001\uff0c\u9700\u8981\u64cd\u4f5c\u7cfb\u7edf\u4ecb\u5165\u4ee5\u5efa\u7acb\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5185\u5b58\u7684\u6620\u5c04\u3002\u8fd9\u4e00\u673a\u5236\u76f8\u8f83\u4e8e brk()
\u7cfb\u7edf\u8c03\u7528\uff0c\u4f1a\u5e26\u6765\u66f4\u9ad8\u7684\u6027\u80fd\u6210\u672c\u3002
"},{"location":"others/","title":"\u4e0d\u592a\u597d\u5206\u7c7b\u7684\u653e\u8fd9","text":""},{"location":"others/#_2","title":"\u53c2\u8003\u8d44\u6599","text":" \u7a0b\u5e8f\u5458\u7684\u81ea\u6211\u4fee\u517b "},{"location":"others/ld/","title":"\u4ece\u4ee3\u7801\u5230\u53ef\u6267\u884c\u6587\u4ef6","text":""},{"location":"others/ld/#gcc","title":"gcc\u7f16\u8bd1\u6b65\u9aa4","text":""},{"location":"others/ld/#_2","title":"\u7a0b\u5e8f\u7684\u94fe\u63a5\u4e0e\u88c5\u8f7d","text":""},{"location":"others/ld/#_3","title":"\u7a0b\u5e8f\u7684\u4e8c\u8fdb\u5236\u683c\u5f0f","text":"\u7ecf\u8fc7\u9884\u5904\u7406\u3001\u7f16\u8bd1\u3001\u6c47\u7f16\u4ee5\u540e\uff0c.c\u6587\u4ef6\u88ab\u7f16\u8bd1\u6210\u4e86.o\u6587\u4ef6\uff0c\u53c8\u53eb\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\uff0c\u8fd9\u662fELF\u683c\u5f0f\u7684\u4e00\u79cd\u3002\u8fd9\u4e2a\u6587\u4ef6\u683c\u5f0f\u662f\u8fd9\u6837\u7684\u3002
\u5176\u4e2dELF Header\u8bb0\u5f55\u4e00\u4e2a\u4e2asection\u7684\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528readelf -h
\u67e5\u770b\u4e00\u4e2a.o\u6587\u4ef6\u7684Header\u4fe1\u606f\u3002\u8fd9\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\u91cc\u5b58\u653e\u7740\u7a0b\u5e8f\u7684\u4ee3\u7801\u4ee5\u53ca\u53d8\u91cf\u7b49\u7b49\u4fe1\u606f\u3002
.text\uff1a\u5b58\u653e\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u3002
.rodata\uff1a\u5b58\u653e\u53ea\u8bfb\u6570\u636e\uff0c\u6bd4\u5982\u5b57\u7b26\u4e32\u5e38\u91cf\u3002
.data\uff1a\u5b58\u653e\u5df2\u7ecf\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u3002
.bss\uff1a\u5b58\u653e\u672a\u521d\u59cb\u5316\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\uff0c\u5168\u90e8\u7f6e\u4e3a0.
.symtab\uff1a\u7b26\u53f7\u8868\uff0c\u5b58\u653e\u7684\u662f\u51fd\u6570\u548c\u53d8\u91cf\u7684\u7b26\u53f7\u4fe1\u606f\u3002
.rel.text\uff0c.rel.data\uff1a\u5b58\u653e\u9700\u8981\u91cd\u5b9a\u4f4d\u7684\u51fd\u6570\u548c\u53d8\u91cf\u3002
.strtab\uff1a\u5b57\u7b26\u4e32\u8868\uff0c\u6bd4\u5982\u51fd\u6570\u540d\u3001\u53d8\u91cf\u540d\u3002
\u8fd9\u4e9bsection\u7684\u6570\u636e\u4fe1\u606f\u4fdd\u5b58\u5728Section Header Table
\u91cc\u3002\u4e3a\u4ec0\u4e48\u53eb\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\uff0c\u56e0\u4e3a\u7f16\u8bd1\u6210.o\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u4f7f\u7528\u4e86\u4e00\u4e9b\u5916\u90e8\u51fd\u6570\u6216\u8005\u53d8\u91cf\uff0c\u6b64\u65f6\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e9b\u51fd\u6570\u6216\u53d8\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\uff0c\u6240\u4ee5\u9700\u8981\u5728.o\u6587\u4ef6\u4e2d\u8bf4\u660e\u8fd9\u4e9b\u7b26\u53f7\u5c06\u6765\u662f\u9700\u8981\u91cd\u65b0\u5b9a\u4f4d\u7684\u3002
"},{"location":"others/ld/#_4","title":"\u9759\u6001\u5e93\u4e0e\u52a8\u6001\u5e93","text":"\u6211\u4eec\u53ef\u4ee5\u5c06\u4e00\u4e2a\u4e2a.o\u6587\u4ef6\u6253\u5305\u6210\u5e93\u6587\u4ef6\u7684\u5f62\u5f0f\uff0c\u4f9b\u5176\u4ed6\u7a0b\u5e8f\u8c03\u7528\u3002\u5f62\u6210\u7684\u4e8c\u8fdb\u5236\u683c\u5f0f\u53eb\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u662fELF\u6587\u4ef6\u7684\u7b2c\u4e8c\u79cd\u5f62\u5f0f\u3002\u5b83\u7684\u7ed3\u6784\u5982\u4e0b\u3002
\u8fd9\u4e2a\u683c\u5f0f\u4e0e\u53ef\u91cd\u5b9a\u4f4d\u6587\u4ef6\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u5728\u94fe\u63a5\u7684\u8fc7\u7a0b\u4e2d\uff0c\u90e8\u5206section\u5408\u5e76\u4e86\u3002\u6bd4\u5982\u90fd\u662f\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u90a3\u5c31\u4e00\u8d77\u5408\u5e76\u5230.text\u6bb5\u4e2d\u53bb\u3002\u5c0f\u7684section\u5408\u5e76\u6210\u4e3a\u4e86\u5927\u7684segment\u3002\u5728ELF\u5934\u91cc\u9762\uff0c\u6709\u4e2a\u53ebe_entry\u7684\u865a\u62df\u5730\u5740\uff0c\u662f\u7a0b\u5e8f\u7684\u5165\u53e3\u5730\u5740\u3002\u5f53\u9759\u6001\u5e93\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u94fe\u63a5\u5728\u4e00\u8d77\u65f6\uff0c\u4f1a\u628a\u9759\u6001\u5e93\u7684\u4fe1\u606f\u5408\u5e76\u8fdb\u53bb\uff0c\u5f62\u6210\u4e00\u4e2a\u66f4\u5927\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u8fd9\u6837\u7684\u597d\u5904\u5c31\u662f\u8be5\u7a0b\u5e8f\u6267\u884c\u7684\u65f6\u5019\u4e0d\u4f9d\u8d56\u4e8e\u9759\u6001\u5e93\u6587\u4ef6\u3002\u574f\u5904\u5c31\u662f\uff0c\u6709\u5176\u4ed6\u9700\u8981\u94fe\u63a5\u7684\u6587\u4ef6\uff0c\u540c\u6837\u4f1a\u590d\u5236\u4e00\u4efd\u4fe1\u606f\u5230\u5185\u5b58\uff0c\u9020\u6210\u4e86\u7a7a\u95f4\u7684\u6d6a\u8d39\u3002\u5f53\u9759\u6001\u5e93\u66f4\u65b0\u540e\uff0c\u5982\u679c\u4e0d\u91cd\u65b0\u8fdb\u884c\u7f16\u8bd1\uff0c\u7a0b\u5e8f\u5c31\u65e0\u6cd5\u8fd0\u884c\u4e86\u3002\u4e3a\u4e86\u89e3\u51b3\u7a7a\u95f4\u6d6a\u8d39\u4ee5\u53ca\u7a0b\u5e8f\u6269\u5c55\u6027\u5dee\u7684\u95ee\u9898\uff0c\u52a8\u6001\u5e93\u5c31\u51fa\u73b0\u4e86\u3002\u52a8\u6001\u5e93\u4e5f\u662fELF\u6587\u4ef6\u7684\u7b2c\u4e09\u79cd\u5f62\u5f0f\u2014\u2014\u5171\u4eab\u5bf9\u8c61\u6587\u4ef6\u3002
\u5f53\u52a8\u6001\u5e93\u88ab\u94fe\u63a5\u5230\u7a0b\u5e8f\u4e2d\u53bb\u65f6\uff0c\u53ea\u4fdd\u7559\u4e86\u5bf9\u52a8\u6001\u5e93\u7684\u5f15\u7528\uff0c\u5e76\u4e14\u4e00\u4e2a\u52a8\u6001\u5e93\u53ef\u4ee5\u88ab\u591a\u4e2a\u7a0b\u5e8f\u5f15\u7528\u3002\u800c\u4e3a\u4e86\u5728\u8fd0\u884c\u65f6\u786e\u5b9a\u51fd\u6570\u4f4d\u7f6e\uff0c\u57fa\u4e8e\u52a8\u6001\u5e93\u94fe\u63a5\u7684.so\u6587\u4ef6\u591a\u4e86\u4e00\u4e9b\u4fe1\u606f\u3002\u9996\u5148\u662f\u4e00\u4e2a\u53eb.interp\u7684\u6bb5\uff0c\u8fd9\u91cc\u9762\u662fld-linux.so\uff0c\u8fd9\u662f\u52a8\u6001\u94fe\u63a5\u5668\uff0c\u8fd0\u884c\u65f6\u7684\u94fe\u63a5\u52a8\u4f5c\u90fd\u662f\u5b83\u505a\u7684\u3002\u53e6\u5916\u8fd8\u591a\u4e86\u4e24\u4e2asection\uff0c\u4e00\u4e2a\u662f.plt\uff0c\u8fc7\u7a0b\u94fe\u63a5\u8868\uff0c\u4e00\u4e2a\u662f.got\uff0c\u5168\u5c40\u504f\u79fb\u91cf\u8868\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u51fd\u6570func()
\u9700\u8981\u91cd\u5b9a\u4f4d\uff0c\u7531\u4e8e\u4ee3\u7801\u6bb5\u662f\u4e0d\u53ef\u5199\u7684\uff0c\u6240\u4ee5\u5728\u94fe\u63a5\u8fc7\u7a0b\u4e2d\uff0c\u65e0\u6cd5\u5c06\u5176\u5b9e\u9645\u5730\u5740\u5199\u5165\u3002\u89e3\u51b3\u529e\u6cd5\u662f\u7528\u4e86\u4e00\u4e2a\u5c0f\u6280\u5de7\uff0c\u5728\u6c47\u7f16\u6307\u4ee4\u4e2d\uff0c\u5f53\u6267\u884c\u5230func()
\u51fd\u6570\u65f6\uff0c\u544a\u8bc9\u7a0b\u5e8f\u4f60\u8981\u53bbPLT[x]\u4f4d\u7f6e\u5904\u53bb\u5bfb\u627efunc\u51fd\u6570\u7684\u4f4d\u7f6e\u3002\u800cPLT[X]\u53c8\u544a\u8bc9\u7a0b\u5e8f\u4f60\u8981\u53bbGOT[Y]\u7684\u5730\u65b9\u53bb\u627e\u51fd\u6570\u4f4d\u7f6e\u3002\u5f53\u7b2c\u4e00\u6b21\u6267\u884c\u65f6\uff0cGOT[Y]\u91cc\u7684\u4f4d\u7f6e\u4fe1\u606f\u662f\u7a7a\u7684\uff0c\u4e8e\u662fGOT\u544a\u8bc9PLT\uff0c\u6211\u8fd9\u91cc\u6ca1\u6709\u5b9a\u4f4d\u4fe1\u606f\u3002PLT\u6536\u5230\u8fd9\u4e2a\u4fe1\u606f\u4e4b\u540e\uff0c\u8c03\u7528PLT[0]\uff0cPLT[0]\u8f6c\u800c\u8c03\u7528GOT[2]\uff0c\u8fd9\u91cc\u9762\u4fdd\u5b58\u7684\u662f\u94fe\u63a5\u5668\u7684\u5165\u53e3\u5730\u5740\u3002\u94fe\u63a5\u5668\u4f1a\u627e\u5230func()
\u51fd\u6570\u7684\u5165\u53e3\u5730\u5740\uff0c\u7136\u540e\u628a\u8fd9\u4e2a\u5730\u5740\u5199\u5165\u5230GOT[Y]\u4e2d\uff0c\u90a3\u4e48\u4e0b\u6b21\u518d\u8c03\u7528func()
\u51fd\u6570\u65f6\uff0c\u5c31\u4e0d\u9700\u8981\u4ee5\u4e0a\u8fd9\u4e48\u9ebb\u70e6\u7684\u6b65\u9aa4\u4e86\uff0c\u56e0\u4e3a\u51fd\u6570\u7684\u5730\u5740\u5df2\u7ecf\u5199\u5728\u4e86GOT\u8868\u4e2d\u3002
"},{"location":"others/ld/#_5","title":"\u7a0b\u5e8f\u7684\u88c5\u8f7d","text":"\u901a\u8fc7execv()
\u7cfb\u7edf\u8c03\u7528\uff0c\u6267\u884cload_elf_binary()
\u51fd\u6570\uff0c\u5c06\u53ef\u6267\u884c\u6587\u4ef6\u88c5\u8f7d\u5230\u5185\u5b58\u4e2d\u3002
\u5177\u4f53\u5b9e\u73b0\u7ec6\u8282\u5f85\u5b9a\u3002
"},{"location":"pl/","title":"\u7f16\u7a0b\u7684\u5fc3\u5f97\u4f53\u4f1a","text":""},{"location":"rtos/","title":"RTOS","text":"RTOS\u5b66\u4e60\u7b14\u8bb0\uff0c\u5305\u62ecFreeRTOS\u548cRT-Thread
"},{"location":"rtos/#_1","title":"\u53c2\u8003\u8d44\u6599","text":" freertos doc rt-thread\u6587\u6863\u4e2d\u5fc3 \u5d4c\u5165\u5f0f\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edfRT-Thread\u8bbe\u8ba1\u4e0e\u5b9e\u73b0 "},{"location":"rtos/freertos/","title":"\u7b80\u660e\u5165\u95e8","text":"\u5927\u591a\u6570\u7684\u64cd\u4f5c\u7cfb\u7edf\u90fd\u80fd\u540c\u65f6\u6267\u884c\u591a\u4e2a\u7a0b\u5e8f\uff0c\u8fd9\u88ab\u79f0\u4e3a\u591a\u4efb\u52a1\u5904\u7406\u3002\u5b9e\u9645\u4e0a\uff0c\u6bcf\u4e2a\u5904\u7406\u5668\u6838\u5fc3\u5728\u7ed9\u5b9a\u65f6\u95f4\u7247\u5185\u53ea\u80fd\u8fd0\u884c\u5355\u4e2a\u4efb\u52a1\u3002CPU\u901a\u8fc7\u5feb\u901f\u5207\u6362\u65f6\u95f4\u7247\u9020\u6210\u591a\u4e2a\u4efb\u52a1\u540c\u65f6\u6267\u884c\u7684\u5047\u8c61\u3002 \u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf(RTOS)\u4e2d\u7684\u4efb\u52a1\u8c03\u5ea6\u5668\u65e8\u5728\u63d0\u4f9b\u53ef\u9884\u6d4b\u7684\u6267\u884c\u6a21\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u5bf9\u5d4c\u5165\u5f0f\u7cfb\u7edf\u610f\u4e49\u91cd\u5927\uff0c\u56e0\u4e3a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f80\u5f80\u6709\u5b9e\u65f6\u6027\u7684\u8981\u6c42\uff0c\u6bd4\u5982\u6211\u8981\u6c42\u57283\u79d2\u5185\u53d1\u51fa\u8b66\u62a5\u58f0\u3002
\u4f7f\u7528STM32CubeMX\u521b\u5efa\u7684FreeRTOS\u5de5\u7a0b\u4e2d\uff0c\u6e90\u7801\u4e3b\u8981\u6d89\u53ca\u4e24\u4e2a\u76ee\u5f55\uff1a
Core Inc\u76ee\u5f55\u4e0b\u7684FreeRTOSConfig.h\u662f\u914d\u7f6e\u6587\u4ef6 Src\u76ee\u5f55\u4e0b\u7684freertos.c\u662fSTM32CubeMX\u521b\u5efa\u7684\u9ed8\u8ba4\u4efb\u52a1 Middlewares/Thirt_Party/FreeRTOS/Source \u6839\u76ee\u5f55\u4e0b\u662f\u6838\u5fc3\u6587\u4ef6\uff0c\u8fd9\u4e9b\u6587\u4ef6\u662f\u901a\u7528\u7684 portable\u76ee\u5f55\u4e0b\u662f\u79fb\u690d\u65f6\u9700\u8981\u7684\u6587\u4ef6\uff1aport.c\u548cportmacro.h \u76ee\u5f55\u540d\u4e3a\uff1a[compiler]/[architecture] \u6bd4\u5982\uff1aRVDS/ARM-CM3\uff0c\u8fd9\u8868\u793acortexM3\u67b6\u6784\u5728RVDS\u5de5\u5177\u4e0a\u7684\u79fb\u690d\u6587\u4ef6 FreeRTOS/Srouce/ \u4f5c\u7528 tasks.c \u5fc5\u987b\uff0c\u4efb\u52a1\u64cd\u4f5c list.c \u5fc5\u987b\uff0c \u5217\u8868 queue.c \u57fa\u672c\u5fc5\u987b\uff0c\u63d0\u4f9b\u961f\u5217\u64cd\u4f5c\u3001\u4fe1\u53f7\u91cf timer.c \u53ef\u9009\uff0c\u63d0\u4f9b\u5b9a\u65f6\u5668 event_groups.c \u53ef\u9009\uff0c\u63d0\u4f9bevent group\u529f\u80fd croutine.c \u53ef\u9009\uff0c\u5df2\u8fc7\u65f6 \u5934\u6587\u4ef6\u76ee\u5f55\u9700\u8981\u5305\u542b\uff1a
\u6570\u636e\u7c7b\u578b\uff1a
\u5728portmacro.h\u5934\u6587\u4ef6\u91cc\uff0c\u5b9a\u4e49\u4e86\u4e24\u4e2a\u6570\u636e\u7c7b\u578b\uff1a
TickType_t\uff1a FreeRTOS\u914d\u7f6e\u4e86\u4e00\u4e2a\u5468\u671f\u6027\u7684\u65f6\u949f\u4e2d\u65ad\uff1aTick Interrupt \u6bcf\u53d1\u751f\u4e00\u6b21\u4e2d\u65ad\uff0c\u4e2d\u65ad\u6b21\u6570\u7d2f\u52a0\uff0c\u8fd9\u88ab\u79f0\u4e3atick count tick count\u8fd9\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b\u5c31\u662fTickType_t TickType_t\u53ef\u4ee5\u662f16\u4f4d\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f32\u4f4d\u7684 FreeRTOSConfig.h\u4e2d\u5b9a\u4e49configUSE_16_BIT_TICKS\u65f6\uff0cTickType_t\u5c31\u662fuint16_t \u5426\u5219TickType_t\u5c31\u662fuint32_t \u5bf9\u4e8e32\u4f4d\u67b6\u6784\uff0c\u5efa\u8bae\u628aTickType_t\u914d\u7f6e\u4e3auint32_t BaseType_t\uff1a \u8fd9\u662f\u8be5\u67b6\u6784\u6700\u9ad8\u6548\u7684\u6570\u636e\u7c7b\u578b 32\u4f4d\u67b6\u6784\u4e2d\uff0c\u5b83\u5c31\u662fuint32_t 16\u4f4d\u67b6\u6784\u4e2d\uff0c\u5b83\u5c31\u662fuint16_t 8\u4f4d\u67b6\u6784\u4e2d\uff0c\u5b83\u5c31\u662fuint8_t BaseType_t\u901a\u5e38\u7528\u4f5c\u7b80\u5355\u7684\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u8fd8\u6709\u903b\u8f91\u503c\uff0c\u6bd4\u5982pdTRUE/pdFALSE \u547d\u540d\u89c4\u8303\uff1a
\u53d8\u91cf\u540d\u524d\u7f00 \u542b\u4e49 ul uint32_t us uint16_t uc uint8_t x \u975estdint\u7c7b\u578b\uff0c\u6bd4\u5982BaseType_t\u548cTickType_t\uff0c\u6216\u8005size_t ux UBaseType_t e enum p \u6307\u9488 c char \u51fd\u6570\u540d\u524d\u7f00 \u542b\u4e49 prv \u79c1\u6709\u51fd\u6570(file scope) v \u8fd4\u56de\u503cvoid task \u5b9a\u4e49\u5728task.c \u5b8f\u524d\u7f00 \u542b\u4e49 config \u5b9a\u4e49\u5728FreeRTOSConfig.h"},{"location":"rtos/freertos/#_2","title":"\u5185\u5b58\u7ba1\u7406","text":"\u6bcf\u6b21\u521b\u5efa\u4efb\u52a1\u3001\u961f\u5217\u3001\u4e92\u65a5\u9501\u3001\u8f6f\u4ef6\u5b9a\u65f6\u5668\u3001\u4fe1\u53f7\u91cf\u6216\u4e8b\u4ef6\u7ec4\u65f6\uff0c\u5185\u6838\u90fd\u9700\u8981RAM\uff0cRAM\u53ef\u4ee5\u7531RTOS\u5806\u52a8\u6001\u5206\u914d\uff0c\u4e5f\u53ef\u4ee5\u7531\u7f16\u5199\u8005\u624b\u52a8\u63d0\u4f9b\u3002
\u5c3d\u7ba1C\u5e93\u63d0\u4f9b\u4e86malloc()
\u548cfree()
\u51fd\u6570\uff0c\u4f46\u662f\uff1a 1. \u5b83\u4eec\u5e76\u4e0d\u603b\u662f\u9002\u7528\u4e8e\u5d4c\u5165\u5f0f\u7cfb\u7edf 2. \u5b83\u4eec\u8017\u8d39\u65f6\u95f4\u6bd4\u8f83\u957f 3. \u5b83\u4eec\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684 4. \u8fd0\u884c\u7ed3\u679c\u4e0d\u786e\u5b9a
\u56e0\u6b64freertos\u5b9e\u73b0\u4e86\u81ea\u5df1\u7684\u5185\u5b58\u5206\u914d\u63a5\u53e3\u51fd\u6570\u3002
freertos\u4e2d\u6709\u4e94\u79cd\u5806\u5185\u5b58\uff0c\u6587\u4ef6\u5b9a\u4e49\u5728Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang\u4e0b\u3002\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662fheap_4.c\uff0c\u5b83\u53ef\u4ee5\u5c06\u76f8\u90bb\u7684\u7a7a\u95f4\u5185\u5b58\u5757\u5408\u5e76\uff0c\u89e3\u51b3\u4e86\u5185\u5b58\u788e\u7247\u95ee\u9898\u3002\u800cheap_5.c\u5141\u8bb8\u591a\u4e2a\u4e0d\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\u3002\u9700\u8981\u7528\u5230\u4ee5\u4e0b\u7ed3\u6784\u4f53\u8fdb\u884c\u4e0d\u540c\u5185\u5b58\u5757\u7684\u521d\u59cb\u5316\uff1a
typedef struct HeapRegion\n{\n uint8_t *pucStartAddress; //\u8d77\u59cb\u5730\u5740\n size_t xSizeInBytes; //\u5927\u5c0f\n}HeapRegion_t;\n
\u5f53\u6307\u5b9a\u591a\u5757\u5185\u5b58\u65f6\uff0c\u9700\u8981\u7528\u5230HeapRegion_t\u7c7b\u578b\u7684\u6570\u636e\uff0c\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u90fd\u662f\u4e00\u4e2aHeapRegion_t\u5143\u7d20\u3002\u8fd9\u4e2a\u6570\u7ec4\u4e2d\uff0c\u4f4e\u5730\u5740\u5728\u524d\uff0c\u9ad8\u5730\u5740\u5728\u540e\u3002
HeapRegion_t xHeapRegions[] = \n{\n {(uint8_t *)0x80000000UL, 0x10000}, //\u8d77\u59cb\u5730\u5740\u548c\u5927\u5c0f\n {(uint8_t *)0x90000000UL, 0x10000}, \n {NULL, 0} //\u8868\u793a\u6570\u7ec4\u7ed3\u675f\n};\n
\u5b9a\u4e49\u4e86\u5185\u5b58\u5757\u6570\u7ec4\u8fd8\u9700\u8981\u5bf9\u5176\u8fdb\u884c\u521d\u59cb\u5316\uff1a
void vPortDefineHeapRegions(const HeapRegion_t *const pxHeapRegions);\n
Heap\u7684\u5206\u914d\u548c\u91ca\u653e\uff1a
void *pvPortMalloc(size_t xWantedSize);\nvoid vPortFree(void *pv);\n
\u83b7\u53d6\u5f53\u524d\u7a7a\u95f2\u5185\u5b58\u7a7a\u95f4\uff1a
size_t xPortGetFreeHeapSize(void);\n
\u83b7\u53d6\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7a7a\u95f2\u5185\u5b58\u7684\u6700\u5c0f\u503c\uff1a
size_t xPortGetMinimumEverFreeHeapSize(void);\n
"},{"location":"rtos/freertos/#_3","title":"\u4efb\u52a1\u7ba1\u7406","text":"\u4e00\u4e2a\u4efb\u52a1\u6700\u57fa\u672c\u7684\u5143\u7d20\u6709\uff1a
\u4efb\u52a1\u72b6\u6001\uff1a\u6bd4\u5982\u963b\u585e\uff0c\u5c31\u7eea\uff0c\u6302\u8d77\u7b49 \u4f18\u5148\u7ea7\uff1a\u6bcf\u4e2a\u4efb\u52a1\u90fd\u5206\u914d\u4e86\u4ece0\u5230configMAX_PRIORITIES-1\u7684\u4f18\u5148\u7ea7 \u6808\uff1a\u7528\u6765\u4fdd\u5b58\u4efb\u52a1\u7684\u5c40\u90e8\u6570\u636e \u4e8b\u4ef6\uff1a\u8868\u793a\u4efb\u52a1\u505a\u4e86\u4ec0\u4e48\u4e8b\u60c5 \u5bf9\u4e8e\u5355\u6838\u5904\u7406\u5668\u6765\u8bf4\uff0c\u4efb\u4f55\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a\u4efb\u52a1\u5f97\u5230\u8fd0\u884c\uff0c\u5f53\u8c03\u5ea6\u5668\u51b3\u5b9a\u5207\u6362\u4efb\u52a1\u65f6\uff0c\u9700\u8981\u5c06\u4e0a\u4e00\u4e2a\u4efb\u52a1\u7684\u4e0a\u4e0b\u6587\uff08\u5bc4\u5b58\u5668\uff0c\u6808\uff09\u4fdd\u5b58\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u4e00\u4e2a\u4efb\u52a1\u51fa\u73b0\u4e86\u6b7b\u5faa\u73af\u64cd\u4f5c\uff0c\u90a3\u4e48\u6bd4\u8fd9\u4e2a\u4efb\u52a1\u4f18\u5148\u7ea7\u4f4e\u7684\u4efb\u52a1\u90fd\u5c06\u65e0\u6cd5\u6267\u884c\u3002\u6240\u4ee5\u5728\u8bbe\u8ba1\u7684\u65f6\u5019\uff0c\u5e94\u8be5\u4fdd\u8bc1\u4efb\u52a1\u5728\u4e0d\u6d3b\u8dc3\u72b6\u6001\u65f6\u8fdb\u5165\u963b\u585e\u72b6\u6001\u4ee5\u8ba9\u51faCPU\u4f7f\u7528\u6743\uff0c\u4fdd\u8bc1\u5176\u4ed6\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u53ef\u4ee5\u6267\u884c\u3002
"},{"location":"rtos/freertos/#_4","title":"\u521b\u5efa\u4efb\u52a1","text":"\u5728FreeRTOS\u4e2d\uff0c\u4efb\u52a1\u51fd\u6570\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
void vATaskFunction(void *pvParameters)\n{\n for(;;)\n {\n //RTOS\u63a8\u8350\u91c7\u7528\u4e8b\u4ef6\u9a71\u52a8\u578b\u4efb\u52a1\n if(WaitForEvent(EventObject, Timeout) == pdPASS)\n {\n //\u5904\u7406\u4e8b\u4ef6\n }\n else\n {\n\n }\n }\n\n vTaskDelete(NULL); //\u6267\u884c\u5b8c\u6bd5\u5220\u9664\u81ea\u5df1\n}\n
\u52a8\u6001\u521b\u5efa\u4efb\u52a1\u4f7f\u7528\u7684\u51fd\u6570\u5982\u4e0b\uff1a BaseType_t xTaskCreate(TaskFunction_t pxTaskCode,\n const char *const pcName, \n const configSTACK_DEPTH_TYPE usStackDepth,\n void *const pvParameters,\n UBaseType_t uxPriority,\n TaskHandle_t *const pxCreatedTask);\n
\u53c2\u6570\u8bf4\u660e\uff1a
\u53c2\u6570 \u63cf\u8ff0 pvTaskCode \u4efb\u52a1\u51fd\u6570 pcName \u4efb\u52a1\u540d\u79f0 usStackDepth \u4efb\u52a1\u6808\u5927\u5c0f\uff0c\u5355\u4f4dword pvParameters \u4f20\u9012\u7ed9\u4efb\u52a1\u51fd\u6570\u7684\u53c2\u6570 uxPriority \u4efb\u52a1\u4f18\u5148\u7ea7 pxCreatedTask \u4efb\u52a1\u53e5\u67c4\uff0c\u7528\u6765\u64cd\u4f5c\u4efb\u52a1\u51fd\u6570 \u8fd4\u56de\u503c \u6210\u529f\u8fd4\u56depdPass\uff0c\u5931\u8d25\u901a\u5e38\u662f\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3 \u9759\u6001\u521b\u5efa\u4efb\u52a1\u4f7f\u7528\u7684\u51fd\u6570\u5982\u4e0b\uff1a
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,\n const char *const pcName,\n const uint32_t ulStackDepth,\n void *const pvParameters,\n UBaseType_t uxPriority,\n StackType_t *const puxStackBuffer,\n StaticTask_t *const pxTaskBuffer);\n
\u76f8\u5bf9\u4e8e\u52a8\u6001\u5206\u914d\uff0c\u6709\u4e24\u4e2a\u53c2\u6570\u4e0d\u540c\uff1a
\u53c2\u6570 \u63cf\u8ff0 puxStackBuffer \u6808\u6570\u7ec4\uff0c\u7d22\u5f15\u5fc5\u987b\u4e0d\u5c0f\u4e8eulStackDepth pxTaskBuffer \u6307\u5411StaticTask_t\u7684\u6307\u9488\uff0c\u7528\u6765\u4fdd\u5b58\u4efb\u52a1\u7ed3\u6784\u4f53 \u6bcf\u4e2a\u4efb\u52a1\u90fd\u9700\u8981RAM\u6765\u4fdd\u5b58\u4efb\u52a1\u72b6\u6001\uff0c\u5e76\u7531\u4efb\u52a1\u7528\u4f5c\u5176\u5806\u6808\u3002\u5982\u679c\u4f7f\u7528\u52a8\u6001\u521b\u5efa\uff0c\u5219\u4f1a\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4eceFreeRTOS\u5806\u4e2d\u81ea\u52a8\u5206\u914dRAM\u3002\u5982\u679c\u662f\u9759\u6001\u521b\u5efa\uff0cRAM\u7531\u7f16\u5199\u8005\u624b\u52a8\u63d0\u4f9b\uff0c\u4f46\u5728\u7f16\u8bd1\u65f6\u5c31\u5df2\u786e\u5b9a\u3002
"},{"location":"rtos/freertos/#tick","title":"Tick","text":"\u4efb\u52a1\u8fdb\u5165\u7761\u7720\u540e\u9700\u8981\u6307\u5b9a\u5524\u9192\u7684\u65f6\u95f4\uff0cFreeRTOS\u901a\u8fc7Tick\u53d8\u91cf\u6d4b\u91cf\u65f6\u95f4\u3002\u5b9a\u65f6\u5668\u4e2d\u65ad\u4ee5\u4e25\u683c\u7684\u65f6\u95f4\u7cbe\u5ea6\u589e\u52a0Tick count\u3002\u6bcf\u6b21Tick\u589e\u52a0\u65f6\uff0c\u5185\u6838\u5fc5\u987b\u68c0\u67e5\u73b0\u5728\u662f\u5426\u9700\u8981\u89e3\u9664\u963b\u585e\u6216\u8005\u5524\u9192\u4efb\u52a1\uff0c\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u5148\u88ab\u5524\u9192\u3002\u4efb\u52a1\u901a\u8fc7\u8c03\u7528vTaskDelay()
\u51fd\u6570\u6765\u4e3b\u52a8\u7b49\u5f85\u4e00\u5b9a\u7684\u65f6\u95f4\u3002\u5b8fpdMS_TO_TICKS()
\u5c06\u6beb\u79d2\u8f6c\u6362\u4e3aTick count\u3002
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7531\u4e8e\u5185\u6838\u672c\u8eab\u7684\u4efb\u52a1\u5207\u6362\u9700\u8981\u65f6\u95f4\uff0c\u5f53\u6307\u5b9aN\u4e2aTick\u7684\u5ef6\u8fdf\u540e\uff0c\u5b9e\u9645\u5ef6\u8fdf\u65f6\u95f4\u5c06\u5728(N-1)~(N)\u4e2aTick\u4e4b\u95f4\u3002
"},{"location":"rtos/freertos/#_5","title":"\u4efb\u52a1\u72b6\u6001","text":"\u4efb\u52a1\u53ef\u4ee5\u6709\u4ee5\u4e0b\u72b6\u6001\uff1a
\u8fd0\u884c\uff1a\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u88ab\u6267\u884c
\u5c31\u7eea\uff1a\u80fd\u591f\u6267\u884c\uff0c\u7b49\u5f85\u8c03\u5ea6\u5668\u8c03\u5ea6
\u963b\u585e\uff1a\u6b63\u5728\u7b49\u5f85\u65f6\u95f4\u6216\u8005\u5916\u90e8\u4e8b\u4ef6
\u6302\u8d77\uff1a\u653e\u5f03CPU\u4f7f\u7528\u6743\uff0c\u4e0d\u53c2\u4e0e\u8c03\u5ea6\u3002
"},{"location":"rtos/freertos/#_6","title":"\u8c03\u5ea6\u7b97\u6cd5","text":"\u4e24\u4e2a\u6838\u5fc3\u6982\u5ff5\uff1a\u62a2\u5360\u548c\u8f6e\u8f6c\u3002\u901a\u8fc7\u914d\u7f6econfigUSE_PREEMPTION\u4f7f\u80fd\u62a2\u5360\uff0c\u5373\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u53ef\u4ee5\u62a2\u5360\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u3002\u901a\u8fc7\u914d\u7f6econfigUSE_TIME_SLICING\u4f7f\u80fd\u8f6e\u8f6c\uff0c\u5373\u76f8\u540c\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u8f6e\u6d41\u6267\u884c\u3002
"},{"location":"rtos/freertos/#_7","title":"\u7a7a\u95f2\u4efb\u52a1\u548c\u94a9\u5b50\u51fd\u6570","text":"\u5728\u6ca1\u6709\u5176\u4ed6\u4efb\u52a1\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u6267\u884c\u7a7a\u95f2\u4efb\u52a1\u3002vTaskStartScheduler()
\u51fd\u6570\u5185\u90e8\u4f1a\u521b\u5efa\u7a7a\u95f2\u4efb\u52a1\uff0c\u5b83\u7684\u4f18\u5148\u7ea7\u4e3a0\uff0c\u6c38\u8fdc\u4f4e\u4e8e\u7528\u6237\u4efb\u52a1\uff0c\u4e14\u8981\u4e48\u5904\u4e8e\u5c31\u7eea\u6001\uff0c\u8981\u4e48\u5904\u4e8e\u8fd0\u884c\u6001\u3002
\u6211\u4eec\u53ef\u4ee5\u5728\u7a7a\u95f2\u4efb\u52a1\u5185\u6dfb\u52a0\u4e00\u4e2a\u94a9\u5b50\u51fd\u6570\uff0c\u8fd9\u6837\u7a7a\u95f2\u4efb\u52a1\u6bcf\u6267\u884c\u4e00\u6b21\uff0c\u90fd\u4f1a\u8c03\u7528\u4e00\u6b21\u94a9\u5b50\u51fd\u6570\u3002\u94a9\u5b50\u51fd\u6570\u7684\u4f5c\u7528\u662f\uff1a
\u6267\u884c\u4e00\u4e9b\u540e\u53f0\u4efb\u52a1 \u6d4b\u91cf\u7cfb\u7edf\u7a7a\u95f2\u65f6\u95f4 \u4f7f\u7cfb\u7edf\u8fdb\u5165\u7701\u7535\u6a21\u5f0f \u8981\u6ce8\u610f\u7684\u662f\uff0c\u94a9\u5b50\u51fd\u6570\u4e0d\u80fd\u8c03\u7528\u4efb\u4f55\u4f7f\u5176\u5bfc\u81f4\u963b\u585e\u7684\u51fd\u6570\u3002\u7a7a\u95f2\u94a9\u5b50\u51fd\u6570\u7684\u5b9a\u4e49\u5982\u4e0b\uff1a
void vApplicationIdleHook(void);\n
"},{"location":"rtos/freertos/#_8","title":"\u4efb\u52a1\u540c\u6b65\u4e0e\u901a\u4fe1","text":"\u8fd9\u91cc\u9762\u7684\u5185\u5bb9\u4ee5\u7406\u89e3\u539f\u7406\u4e3a\u4e3b\uff0c\u6ca1\u6709\u5fc5\u8981\u53bb\u8bb0\u51fd\u6570\u63a5\u53e3\uff0c\u7528\u5230\u4ec0\u4e48\u5c31\u67e5\u4ec0\u4e48\u3002
"},{"location":"rtos/freertos/#_9","title":"\u6d88\u606f\u961f\u5217","text":"\u6d88\u606f\u961f\u5217\u7b80\u79f0\u4e3a\u961f\u5217\uff0c\u662f\u4e00\u79cd\u5148\u8fdb\u5148\u51fa\u7684\u6570\u636e\u7ed3\u6784\uff0c\u652f\u6301\u4efb\u52a1\u6216\u8005\u4e2d\u65ad\u7684\u8bfb\u5199\u3002\u5f53\u961f\u5217\u4e2d\u7684\u6d88\u606f\u4e3a\u7a7a\u65f6\uff0c\u8bfb\u53d6\u6d88\u606f\u7684\u4efb\u52a1\u5c06\u88ab\u963b\u585e\uff1b\u5f53\u961f\u5217\u5df2\u6ee1\uff0c\u53d1\u9001\u6d88\u606f\u7684\u4efb\u52a1\u5c06\u88ab\u963b\u585e\u3002\u53ef\u4ee5\u5c06\u4e00\u6761\u6216\u8005\u591a\u6761\u6d88\u606f\u653e\u5165\u961f\u5217\u4e2d\uff0c\u591a\u4e2a\u4efb\u52a1\u4e5f\u53ef\u4ee5\u4ece\u540c\u4e00\u4e2a\u6d88\u606f\u961f\u5217\u8bfb\u5199\u6d88\u606f\u3002\u5982\u679c\u662f\u7d27\u6025\u6d88\u606f\uff0c\u53ef\u4ee5\u53d1\u9001\u81f3\u961f\u5217\u5934\u4ece\u800c\u63d0\u524d\u88ab\u63a5\u6536\u3002
\u4e3a\u4e86\u5b9e\u73b0\u5148\u8fdb\u5148\u51fa\u7684\u673a\u5236\uff0c\u961f\u5217\u4f7f\u7528\u4e86\u963b\u585e\u7684\u673a\u5236\u3002\u5f53\u4efb\u52a1A\u5bf9\u67d0\u4e2a\u961f\u5217\u8fdb\u884c\u8bfb\u64cd\u4f5c\u65f6\uff0c\u5982\u679c\u961f\u5217\u6b64\u65f6\u4e3a\u7a7a\uff0c\u90a3\u4e48\u5b83\u53ef\u4ee5\u9009\u62e9\uff1a
\u76f4\u63a5\u653e\u5f03\u8bfb\u64cd\u4f5c\uff0c\u53bb\u5e72\u522b\u7684\u4e8b\u60c5\u3002 \u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u3002\u5982\u679c\u5728\u7b49\u5f85\u671f\u95f4\u6d88\u606f\u6765\u4e86\uff0c\u5c31\u53d8\u4e3a\u5c31\u7eea\u72b6\u6001\uff1b\u5982\u679c\u7b49\u5f85\u65f6\u95f4\u8fc7\u4e86\u6d88\u606f\u90fd\u6ca1\u6765\uff0c\u90a3\u4e48\u5c31\u8fd4\u56de\u4e00\u4e2a\u672a\u6536\u5230\u6d88\u606f\u7684\u9519\u8bef\u7801\uff0c\u7136\u540e\u6267\u884c\u5176\u4ed6\u7a0b\u5e8f\u3002 \u6b7b\u7b49\u76f4\u5230\u6d88\u606f\u5230\u6765\u4e3a\u6b62\u3002 \u5199\u64cd\u4f5c\u7684\u963b\u585e\u673a\u5236\u7c7b\u4f3c\u3002
\u6ce8\u610f\uff1a\u7531\u4e8e\u4e2d\u65ad\u51fd\u6570\u4e5f\u53ef\u4ee5\u5bf9\u961f\u5217\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\uff0c\u4f46\u662f\u4e2d\u65ad\u51fd\u6570\u4e0d\u5141\u8bb8\u963b\u585e\uff0c\u56e0\u6b64\u5728\u4e2d\u65ad\u5904\u7406\u6d41\u7a0b\u4e2d\u5fc5\u987b\u4f7f\u7528\u7279\u6b8a\u7684\u8bfb\u5199\u51fd\u6570\u63a5\u53e3\u3002
"},{"location":"rtos/freertos/#_10","title":"\u4fe1\u53f7\u91cf","text":"\u4fe1\u53f7\u91cf\u5206\u4e3a\u4e8c\u503c\u4fe1\u53f7\u91cf\u548c\u8ba1\u6570\u4fe1\u53f7\u91cf\uff0c\u5176\u539f\u7406\u548cLinux\u5185\u6838\u76f8\u4f3c\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002
"},{"location":"rtos/freertos/#_11","title":"\u4e92\u65a5\u91cf","text":"\u4e92\u65a5\u91cf\u662f\u7279\u6b8a\u7684\u4e8c\u503c\u4fe1\u53f7\u91cf\uff0c\u6709\u7740\u9012\u5f52\u8bbf\u95ee\u548c\u9632\u6b62\u4f18\u5148\u7ea7\u53cd\u8f6c\u7684\u7279\u6027\uff0c\u4e3b\u8981\u7528\u4e8e\u4e34\u754c\u8d44\u6e90\u7684\u4fdd\u62a4\u3002\u4e92\u65a5\u91cf\u5177\u6709\u7279\u6b8a\u7684\u4f18\u5148\u7ea7\u7ee7\u627f\u7684\u673a\u5236\uff0c\u8981\u7406\u89e3\u8fd9\u4e2a\u673a\u5236\uff0c\u6211\u4eec\u9996\u5148\u8981\u89e3\u91ca\u4e0b\u4ec0\u4e48\u662f\u4f18\u5148\u7ea7\u53cd\u8f6c\u3002
\u5728\u4e00\u4e2a\u7b80\u5316\u8fc7\u7684\u573a\u666f\u4e2d\uff0c\u6709\u4e09\u4e2a\u4efb\u52a1H\u3001M\u3001L\uff0c\u5b83\u4eec\u7684\u4f18\u5148\u7ea7\u4f9d\u6b21\u4e3aH>M>L\u3002H\u4e0eL\u5171\u4eab\u67d0\u4e2a\u8d44\u6e90\uff0cM\u4e0d\u5171\u4eab\u3002\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u6700\u9ad8\u4f18\u5148\u7ea7\u7684H\u5e94\u8be5\u80fd\u591f\u4f18\u5148\u6267\u884c\uff0c\u5e76\u4e14\u6709\u6743\u9650\u6253\u65adM\u6216\u8005L\u7684\u6267\u884c\u72b6\u6001\u4ece\u800c\u62a2\u5360CPU\u7684\u63a7\u5236\u6743\u3002\u7136\u800c\u5b58\u5728\u4e00\u79cd\u60c5\u51b5,\u4f1a\u5bfc\u81f4H\u4e00\u76f4\u88ab\u963b\u585e\uff0c\u7b49\u5f85M\u548cL\u7684\u5b8c\u6210\u8fd0\u884c\uff1a
\u5728\u67d0\u4e00\u65f6\u523b\uff0cL\u5df2\u7ecf\u83b7\u53d6\u4e86\u5171\u4eab\u8d44\u6e90\u7684\u4f7f\u7528\u6743\uff0c\u6b63\u5728\u6267\u884c\u81ea\u5df1\u7684\u4efb\u52a1\u3002\u5982\u679c\u6b64\u65f6H\u88ab\u5524\u9192\uff0c\u7531\u4e8eH\u7684\u4f18\u5148\u7ea7\u5927\u4e8eL\uff0c\u5b83\u5c1d\u8bd5\u83b7\u53d6CPU\u7684\u63a7\u5236\u6743\u3002\u4f46\u662f\u7531\u4e8e\u5171\u4eab\u8d44\u6e90\u88abL\u5360\u7528\uff0cH\u4e0d\u5f97\u4e0d\u7b49\u5f85L\u91ca\u653e\u8d44\u6e90\u800c\u8fdb\u5165\u963b\u585e\u72b6\u6001\u3002\u6709\u8da3\u7684\u662f\uff0c\u5982\u679cM\u88ab\u5524\u9192\uff0c\u7531\u4e8eM\u4e0eL\u5e76\u4e0d\u5171\u4eab\u8d44\u6e90\u4e14\u4f18\u5148\u7ea7\u5927\u4e8eL\uff0c\u5b83\u5c06\u7acb\u523b\u4e2d\u65adL\u7684\u6267\u884c\uff0c\u83b7\u53d6CPU\u7684\u63a7\u5236\u6743\u3002\u53ea\u6709\u5f53M\u6267\u884c\u5b8c\u6bd5\u65f6\uff0c\u624d\u4f1a\u5c06CPU\u63a7\u5236\u6743\u5f52\u8fd8\u7ed9L\uff0c\u4f7f\u5176\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c\u5269\u4f59\u7684\u4ee3\u7801\u3002\u4e00\u65e6L\u6267\u884c\u5b8c\u6bd5\u540e\u91ca\u653e\u4e86\u5171\u4eab\u8d44\u6e90\uff0cH\u4efb\u52a1\u624d\u80fd\u4ece\u963b\u585e\u72b6\u6001\u4e2d\u88ab\u5524\u9192\u3002\u6211\u4eec\u53d1\u73b0\uff0c\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1H\u53cd\u800c\u9700\u8981\u7b49\u5f85\u4e24\u4e2a\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u5148\u6267\u884c\u5b8c\u6bd5\uff0c\u5176\u963b\u585e\u65f6\u95f4\u7b49\u4e8eM\u548cL\u7684\u6267\u884c\u65f6\u95f4\u4e4b\u548c\u3002\u8fd9\u79cd\u73b0\u8c61\u88ab\u79f0\u4e3a\u201c\u4f18\u5148\u7ea7\u53cd\u8f6c\u201d\uff0c\u5728\u7cfb\u7edf\u4e2d\u53ef\u80fd\u5bfc\u81f4\u4e25\u91cd\u540e\u679c\uff0c\u751a\u81f3\u5d29\u6e83\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4e00\u8f86\u6c7d\u8f66\u7684\u5239\u8f66\u7cfb\u7edf\u662f\u6700\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\uff0c\u4f46\u9700\u8981\u7b49\u5f85\u5176\u4ed6\u4efb\u52a1\u6267\u884c\u5b8c\u6bd5\uff0c\u8fd9\u5c06\u5bfc\u81f4\u707e\u96be\u6027\u7684\u540e\u679c\u3002\u56e0\u6b64\u4e3a\u4e86\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u8fd0\u884c\uff0c\u5fc5\u987b\u89e3\u51b3\u4f18\u5148\u7ea7\u53cd\u8f6c\u95ee\u9898\u3002
\u4f46\u662f\u5047\u5982\u6211\u4eec\u5f15\u8fdb\u4e86\u4f18\u5148\u7ea7\u7ee7\u627f\u673a\u5236\u3002\u540c\u6837\u662fL\u83b7\u53d6\u5171\u4eab\u8d44\u6e90\uff0cH\u8fdb\u5165\u963b\u585e\u72b6\u6001\u3002\u7cfb\u7edf\u4e34\u65f6\u5c06L\u7684\u4f18\u5148\u7ea7\u63d0\u5347\u5230H\uff0c\u90a3\u4e48M\u5c31\u65e0\u6cd5\u6253\u65adL\u7684\u6267\u884c\u3002\u6240\u4ee5L\u6267\u884c\u5b8c\u5b83\u7684\u4efb\u52a1\u5c31\u4f1a\u7acb\u523b\u91ca\u653e\u8d44\u6e90\uff0c\u7136\u540e\u7531H\u6765\u62a2\u5360CPU\u7684\u4f7f\u7528\u6743\u3002\u5176\u963b\u585e\u65f6\u95f4\u4ec5\u4ec5\u662fL\u7684\u6267\u884c\u65f6\u95f4\uff0c\u8fd9\u5c06\u5927\u5927\u964d\u4f4e\u4f18\u5148\u7ea7\u53cd\u8f6c\u7684\u5371\u5bb3\u3002
"},{"location":"rtos/freertos/#_12","title":"\u4e8b\u4ef6\u7ec4","text":"\u4e8b\u4ef6\u7ec4\u4e3b\u8981\u7528\u6765\u5b9e\u73b0\u591a\u4efb\u52a1\u95f4\u7684\u540c\u6b65\uff0c\u53ea\u80fd\u7528\u6765\u4e8b\u4ef6\u7684\u901a\u4fe1\uff0c\u4e0d\u80fd\u7528\u6765\u53d1\u9001\u6570\u636e\u3002\u53ef\u4ee5\u662f\u4e00\u5bf9\u591a\uff0c\u4e5f\u53ef\u4ee5\u662f\u591a\u5bf9\u4e00\u3002
\u4e8b\u4ef6\u7ec4\u7528\u4e00\u4e2aEventBits_t\u7c7b\u578b\u7684\u53d8\u91cf\u6765\u8868\u793a\uff0c\u5176\u4e2d\u9ad88\u4f4d\u7559\u7ed9\u5185\u6838\uff0c\u7528\u5176\u4ed6\u7684\u4f4d\u6765\u8868\u793a\u4e8b\u4ef6\u3002\u6bcf\u4e00\u4f4d\u90fd\u4ee3\u8868\u4e00\u4e2a\u4e8b\u4ef6\uff0c\u542b\u4e49\u7531\u7f16\u5199\u8005\u51b3\u5b9a\uff0c\u6bd4\u5982\u7528bit0\u8868\u793a\u706f\u6ce1\u4eae\u706d\uff0cbit1\u8868\u793a\u6309\u952e\u662f\u5426\u6309\u4e0b\u3002\u8fd9\u4e9b\u4f4d\uff0c\u503c\u4e3a1\u8868\u793a\u4e8b\u4ef6\u53d1\u751f\uff0c\u503c\u4e3a0\u8868\u793a\u4e8b\u4ef6\u672a\u53d1\u751f\u3002\u4efb\u52a1\u901a\u8fc7\u201c\u903b\u8f91\u4e0e\u201d\u3001\u201c\u903b\u8f91\u6216\u201d\u4e0e\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u4e8b\u4ef6\u5efa\u7acb\u5173\u8054\u3002\u903b\u8f91\u4e0e\u8868\u793a\u4efb\u52a1\u611f\u5174\u8da3\u7684\u591a\u4e2a\u4e8b\u4ef6\u540c\u65f6\u53d1\u751f\u624d\u88ab\u5524\u9192\uff0c\u903b\u8f91\u6216\u8868\u793a\u4efb\u4e00\u4e8b\u4ef6\u53d1\u751f\u5373\u53ef\u88ab\u5524\u9192\u3002
\u4e8b\u4ef6\u7ec4\u7684\u64cd\u4f5c\u6d41\u7a0b\u5982\u4e0b\uff1a
\u521b\u5efa\u4e00\u4e2a\u4e8b\u4ef6\u7ec4 \u4efb\u52a1A\u3001B\u63a7\u5236\u4e8b\u4ef6\u4e2d\u7684\u67d0\u4e9b\u4f4d \u4efb\u52a1C\u3001D\u7b49\u5f85\u4e8b\u4ef6\u4e2d\u7684\u4f4d\uff0c\u5e76\u4e14\u51b3\u5b9a\u53d1\u751f\u4e8b\u4ef6\u540e\u7684\u64cd\u4f5c \u8fd9\u91cc\u5bf9\u4e24\u4e2a\u6bd4\u8f83\u91cd\u8981\u7684\u51fd\u6570\u8bf4\u660e\u4e00\u4e0b\uff1a
\u7b49\u5f85\u4e8b\u4ef6\u51fd\u6570\uff1a
EventBits_t xEventGroupWaitBits(EventGroupsHandle_t xEventGroup,\n const EvetnBits_t uxBitsToWaitFor,\n const BaseType_t xClearOnExit,\n const BaseType_t xWaitForAllBits,\n TickType_t xTickToWait);\n
\u53c2\u6570 \u8bf4\u660e xEventGroup \u7b49\u5f85\u7684\u4e8b\u4ef6\u7ec4 uxBitsToWaitFor \u7b49\u5f85\u7684\u4f4d xClearOnExit pdTRUE:\u6e05\u9664\u4f4d xWaitForAllBits pdTRUE\uff1a\u7b49\u5f85\u7684\u4f4d\u5168\u90e8\u4e3a1\uff1bpdFALSE\uff1a\u67d0\u4e00\u4f4d\u4e3a1 xTicksToWait \u963b\u585e\u65f6\u95f4 \u4e3e\u4f8b\u8bf4\u660e\uff1a
\u4e8b\u4ef6\u7ec4\u7684\u503c uxBitsToWaitFor xWaitForAllBits \u8bf4\u660e 0100 0101 pdTrue \u671f\u671bbit0,bit2\u90fd\u4e3a1\uff0c\u4e0d\u6ee1\u8db3\u8fdb\u5165\u963b\u585e 0100 0110 pdFALSE \u671f\u671bbit0, bit2\u67d0\u4f4d\u4e3a1\uff0c\u6ee1\u8db3\u9000\u51fa \u540c\u6b65\u4e8b\u4ef6\u51fd\u6570\uff1a
EventBits_t xEventGroupSync(EventGroupHandle_t xEventGroup,\n const EventBits_t uxBitsToSet,\n const EventBits_t uxBitsToWaitFor,\n TickType_t xTicksToWait);\n
\u8be5\u51fd\u6570\u7528\u6765\u534f\u540c\u591a\u4e2a\u4efb\u52a1\uff0c\u5f53\u671f\u671b\u7684\u4e8b\u4ef6\u4e00\u8d77\u53d1\u751f\u540e\uff0c\u624d\u4f1a\u6210\u529f\u8fd4\u56de\u3002
"},{"location":"rtos/freertos/#_13","title":"\u4efb\u52a1\u901a\u77e5","text":"FreeRTOS\u4eceV8.2.0\u7248\u672c\u5f00\u59cb\u63d0\u4f9b\u4efb\u52a1\u901a\u77e5\u8fd9\u4e2a\u529f\u80fd\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4efb\u52a1\u901a\u77e5\u53ef\u4ee5\u66ff\u4ee3\u4fe1\u53f7\u91cf\u3001\u4e8b\u4ef6\u7ec4\uff0c\u4e5f\u53ef\u4ee5\u66ff\u4ee3\u957f\u5ea6\u4e3a1\u7684\u961f\u5217\u3002\u4efb\u52a1\u901a\u77e5\u66f4\u52a0\u7075\u6d3b\uff0c\u6267\u884c\u901f\u5ea6\u66f4\u5feb\uff0c\u5e76\u4e14\u66f4\u52a0\u8282\u7701RAM\u7a7a\u95f4\uff0c\u7f3a\u70b9\u662f\u4efb\u52a1\u901a\u77e5\u53ea\u80fd\u7531\u4e00\u4e2a\u4efb\u52a1\u6765\u63a5\u6536\u901a\u77e5\u6d88\u606f\u3002
FreeRTOS\u63d0\u4f9b\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u53d1\u9001\u901a\u77e5\u7ed9\u4efb\u52a1\uff1a
\u5982\u679c\u6709\u901a\u77e5\u672a\u8bfb\uff0c\u4e0d\u8986\u76d6\u901a\u77e5\u503c \u76f4\u63a5\u8986\u76d6\u901a\u77e5\u503c \u8bbe\u7f6e\u901a\u77e5\u503c\u7684\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u4f4d\uff0c\u7c7b\u4f3c\u4e8b\u4ef6\u7ec4 \u9012\u589e\u901a\u77e5\u503c\uff0c\u7c7b\u4f3c\u8ba1\u6570\u4fe1\u53f7\u91cf \u4efb\u52a1\u901a\u77e5\u662f\u4efb\u52a1\u63a7\u5236\u5757\u4e2d\u5b9a\u4e49\u7684\u4e00\u4e2a\u6210\u5458\u53d8\u91cf\uff0c\u56e0\u6b64\u4efb\u52a1\u5728\u88ab\u521b\u5efa\u7684\u65f6\u5019\uff0c\u4efb\u52a1\u901a\u77e5\u5c31\u5df2\u7ecf\u88ab\u521d\u59cb\u5316\u4e86\u3002\u4efb\u52a1\u901a\u77e5\u53ef\u4ee5\u7531\u4efb\u52a1\u53d1\u9001\uff0c\u4e5f\u53ef\u4ee5\u7531\u4e2d\u65ad\u53d1\u9001\u3002\u53ea\u6709\u5728\u4efb\u52a1\u4e2d\u624d\u53ef\u4ee5\u7b49\u5f85\u901a\u77e5\uff0c\u800c\u4e0d\u5141\u8bb8\u5728\u4e2d\u65ad\u4e2d\u7b49\u5f85\u901a\u77e5\u3002\u5982\u679c\u4efb\u52a1\u5728\u7b49\u5f85\u901a\u77e5\u7684\u65f6\u5019\u6682\u65f6\u65e0\u6548\uff0c\u5219\u4efb\u52a1\u4f1a\u6839\u636e\u7528\u6237\u6307\u5b9a\u7684\u963b\u585e\u65f6\u95f4\u5185\u8fdb\u5165\u963b\u585e\u72b6\u6001\u3002\u53ea\u8981\u6709\u4efb\u52a1\u6216\u8005\u4e2d\u65ad\u53d1\u9001\u4efb\u52a1\u901a\u77e5\uff0c\u4efb\u52a1\u5c31\u4f1a\u4ece\u963b\u585e\u72b6\u6001\u89e3\u9664\u3002
\u6bcf\u4e2a\u4efb\u52a1\u90fd\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53:TCB\uff08Task Control Block\uff09\uff0c\u91cc\u9762\u6709\u4e24\u4e2a\u6210\u5458\uff0c\u4e00\u4e2a\u7528\u6765\u8868\u793a\u901a\u77e5\u72b6\u6001\uff0c\u4e00\u4e2a\u7528\u6765\u8868\u793a\u901a\u77e5\u503c\u3002
typedef struct tskTaskControlBlock\n{\n ......\n /* configTASK_NOTIFICATION_ARRAY_ENTRIES = 1 */\n volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];\n volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];\n ......\n} tskTCB;\n
\u901a\u77e5\u72b6\u6001\u67093\u79cd\u53d6\u503c\uff1a
taskNOT_WAITING_NOTIFICATION\uff1a\u4efb\u52a1\u6ca1\u6709\u5728\u7b49\u5f85\u901a\u77e5 taskWAITING_NOTIFICATION\uff1a\u4efb\u52a1\u5728\u7b49\u5f85\u901a\u77e5 taskNOTIFICATION_RECEIVED\uff1a\u4efb\u52a1\u63a5\u6536\u5230\u4e86\u901a\u77e5 "},{"location":"rtos/freertos/#_14","title":"\u8f6f\u4ef6\u5b9a\u65f6\u5668","text":"\u8f6f\u4ef6\u5b9a\u65f6\u5668\u5c31\u662f\u201c\u95f9\u949f\u201d\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u95f9\u949f\uff1a\u65e9\u4e0a7\u70b9\u53eb\u9192\u4f60\uff1b\u6216\u8005\uff0c\u6bcf\u5de5\u4f5c\u4e00\u5c0f\u65f6\u5c31\u4f11\u606f\u4e00\u4f1a\u3002\u8f6f\u4ef6\u5b9a\u65f6\u5668\u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u662f\u5728\u672a\u6765\u67d0\u4e2a\u65f6\u95f4\u70b9\u89e6\u53d1\u67d0\u4e2a\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u5468\u671f\u6027\u5730\u8fd0\u884c\u51fd\u6570\u3002
\u8f6f\u4ef6\u5b9a\u65f6\u5668\u662f\u7531\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u4e00\u7c7b\u63a5\u53e3\uff0c\u5b83\u6784\u5efa\u5728\u786c\u4ef6\u5b9a\u65f6\u5668\u57fa\u7840\u4e4b\u4e0a\uff0c\u4ee5\u7cfb\u7edf\u8282\u62cd\u5468\u671f\u4e3a\u5355\u4f4d\u3002\u7cfb\u7edf\u8282\u62cd\u5c31\u662f\u7cfb\u7edf\u65f6\u949f\u7684\u9891\u7387\uff0c\u914d\u7f6e\u4e3aconfigTICK_RATE_HZ\uff0c\u9ed8\u8ba4\u4e3a1000\u3002\u4e5f\u5c31\u662f\u8bf41s\u8df3\u52a81000\u6b21\uff0c\u90a3\u4e48\u7cfb\u7edf\u8857\u62cd\u5468\u671f\u5c31\u662f1ms\u3002\u8f6f\u4ef6\u5b9a\u65f6\u5668\u7684\u5b9a\u65f6\u6570\u503c\u5fc5\u987b\u662f\u8fd9\u4e2a\u8282\u62cd\u5468\u671f\u7684\u6574\u6570\u500d\u3002\u5f53\u7136\uff0c\u7cfb\u7edf\u8282\u62cd\u7cbe\u5ea6\u8d8a\u9ad8\uff0c\u8f6f\u4ef6\u5b9a\u65f6\u5668\u6240\u80fd\u8bbe\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5c31\u8d8a\u5c0f\uff0c\u4f46\u662f\u7cfb\u7edf\u7684\u5f00\u9500\u4e5f\u4f1a\u53d8\u5927\u3002
FreeRTOS\u901a\u8fc7\u4e00\u4e2aprvTimerTask\u7684\u5b88\u62a4\u4efb\u52a1\u6765\u7ba1\u7406\u8f6f\u4ef6\u5b9a\u65f6\u5668\uff0c\u5b83\u662f\u5728\u542f\u52a8\u8c03\u5ea6\u5668\u65f6\u81ea\u52a8\u521b\u5efa\u7684\u3002\u5b88\u62a4\u4efb\u52a1\u4f1a\u5b9a\u671f\u68c0\u67e5\u7528\u6237\u7f16\u5199\u7684\u5b9a\u65f6\u5668\uff0c\u5e76\u8c03\u7528\u5176\u56de\u8c03\u51fd\u6570\u3002\u7528\u6237\u81ea\u5df1\u7f16\u5199\u7684\u4efb\u52a1\u51fd\u6570\u8981\u8c03\u7528\u5b9a\u65f6\u5668\u51fd\u6570\u65f6\uff0c\u662f\u901a\u8fc7\u201c\u5b9a\u65f6\u5668\u547d\u4ee4\u961f\u5217\u201d\u548c\u5b88\u62a4\u4efb\u52a1\u4ea4\u4e92\u7684\u3002\u5b88\u62a4\u4efb\u52a1\u7684\u4e3b\u8981\u5de5\u4f5c\u5c31\u662f\u4ece\u547d\u4ee4\u961f\u5217\u4e2d\u53d6\u51fa\u547d\u4ee4\u3001\u5904\u7406\uff0c\u6267\u884c\u5b9a\u65f6\u5668\u7684\u56de\u8c03\u51fd\u6570\u3002\u80fd\u5426\u53ca\u65f6\u5904\u7406\u5b9a\u65f6\u5668\u547d\u4ee4\uff0c\u53d6\u51b3\u4e8e\u5b88\u62a4\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u3002\u5176\u4f18\u5148\u7ea7\u9ed8\u8ba4\u4e3aconfiTIMER_TASK_PRIORITY\uff0c\u4e3a\u4e86\u66f4\u597d\u5730\u54cd\u5e94\uff0c\u8be5\u4f18\u5148\u7ea7\u5e94\u8bbe\u7f6e\u4e3a\u6240\u6709\u4efb\u52a1\u4e2d\u6700\u9ad8\u7684\u4f18\u5148\u7ea7\u3002
\u5b9a\u65f6\u5668\u56de\u8c03\u51fd\u6570\u7684\u539f\u578b\u5982\u4e0b\uff1a
void ATimerCallback(TimerHandler_t xTimer);\n
\u5b9a\u65f6\u5668\u7684\u56de\u8c03\u51fd\u6570\u662f\u5728\u5b88\u62a4\u4efb\u52a1\u4e2d\u88ab\u8c03\u7528\u7684\uff0c\u56e0\u6b64\u8be5\u51fd\u6570\u4e0d\u80fd\u8fdb\u5165\u963b\u585e\u72b6\u6001\uff0c\u4e5f\u4e0d\u80fd\u8c03\u7528\u4efb\u4f55\u4f1a\u5f15\u8d77\u963b\u585e\u7684\u51fd\u6570\u3002
\u5b9a\u65f6\u5668\u7684\u590d\u4f4d\uff1a
BaseType_t xTimerReset(TimerHandle_t xTimer, TickType_t xTicksToWait);\n
\u4f7f\u7528\u8be5\u51fd\u6570\u53ef\u4ee5\u8ba9\u5b9a\u65f6\u5668\u7684\u72b6\u6001\u4ece\u51ac\u7720\u6001\u53d8\u4e3a\u8fd0\u884c\u6001\uff0c\u5982\u679c\u5b9a\u65f6\u5668\u5df2\u7ecf\u8fd0\u884c\uff0c\u5219\u76f8\u5f53\u4e8e\u91cd\u65b0\u786e\u5b9a\u8d85\u65f6\u65f6\u95f4\u3002
\u4fee\u6539\u5468\u671f\uff1a
BaseType_t xTimerChangePeriod(TimerHandle_t xTimer, TickType_t xNewPeriod, TickType_t xTicksToWait);\n
"},{"location":"rtos/freertos/#_15","title":"\u4e2d\u65ad\u7ba1\u7406","text":"\u4e2d\u65ad\u5c5e\u4e8e\u5f02\u6b65\u5f02\u5e38\uff0c\u6765\u6e90\u4e8e\u5916\u90e8\u786c\u4ef6\u3002\u5f53\u6ca1\u6709\u4e2d\u65ad\u53d1\u751f\u65f6\uff0cCPU\u6267\u884c\u81ea\u5df1\u7684\u4efb\u52a1\u3002\u5f53\u4e2d\u65ad\u4ea7\u751f\u65f6\uff0cCPU\u5f53\u524d\u4efb\u52a1\u88ab\u6253\u65ad\uff0c\u8f6c\u800c\u53bb\u6267\u884c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u3002\u5916\u90e8\u8bbe\u5907\u4ea7\u751f\u4e00\u4e2a\u4e2d\u65ad\u4fe1\u53f7\u5e76\u53d1\u9001\u81f3\u4e2d\u65ad\u63a7\u5236\u5668\uff0c\u7531\u4e2d\u65ad\u63a7\u5236\u5668\u5c06\u4fe1\u53f7\u518d\u8f6c\u53d1\u7ed9CPU\uff0cCPU\u54cd\u5e94\u4e2d\u65ad\u6e90\u7684\u8bf7\u6c42\u3002\u5f53\u4e2d\u65ad\u4ea7\u751f\u65f6\uff0c\u7cfb\u7edf\u9700\u8981\u4fdd\u5b58\u4e0a\u4e0b\u6587\u72b6\u6001\u3002
\u4e2d\u65ad\u7684\u73af\u5883\u6709\u4e24\u79cd\uff1a
\u4efb\u52a1\u4e0a\u4e0b\u6587\uff1a\u65e0\u8bba\u4e2d\u65ad\u7684\u4f18\u5148\u7ea7\u662f\u591a\u5927\uff0c\u90fd\u4f1a\u6253\u65ad\u5f53\u524d\u4efb\u52a1\u7684\u6267\u884c\u3002 \u4e2d\u65ad\u4e0a\u4e0b\u6587\uff1a\u4ec5\u66f4\u9ad8\u4f18\u5148\u7ea7\u7684\u4e2d\u65ad\u53ef\u4ee5\u6253\u65ad\u5f53\u524d\u4e2d\u65ad\u7684\u6267\u884c\uff0c\u8fd9\u5fc5\u987b\u8981\u7cfb\u7edf\u652f\u6301\u4e2d\u65ad\u5d4c\u5957\u3002 "},{"location":"rtos/freertos/CMSIS/","title":"CMSIS\u6807\u51c6","text":"Cortex\u7cfb\u5217\u7684\u82af\u7247\u5185\u6838\u662f\u76f8\u540c\u7684\uff0c\u4f46\u662f\u4e0d\u540c\u7684\u5382\u5546\u5728\u751f\u4ea7\u7684\u65f6\u5019\u5916\u8bbe\u4f1a\u6709\u533a\u522b\uff0c\u8fd9\u4e9b\u5dee\u5f02\u5bfc\u81f4\u8f6f\u4ef6\u5728\u540c\u5185\u6838\uff0c\u4e0d\u540c\u5916\u8bbe\u7684\u82af\u7247\u4e0a\u79fb\u690d\u56f0\u96be\u3002\u4e3a\u4e86\u89e3\u51b3\u4e0d\u540c\u82af\u7247\u5382\u5546\u751f\u4ea7\u7684\u517c\u5bb9\u6027\u95ee\u9898\uff0cARM\u4e0e\u5404\u82af\u7247\u5382\u5546\u5efa\u8bae\u4e86CMSIS\u6807\u51c6\u3002
\u6240\u8c13\u7684CMSIS\u6807\u51c6\uff0c\u5176\u5b9e\u5c31\u662f\u65b0\u5efa\u4e86\u4e00\u4e2a\u8f6f\u4ef6\u62bd\u8c61\u5c42\uff0c\u5c06\u4e0d\u540c\u7684RTOS\u7684\u63a5\u53e3\u7edf\u4e00\u8d77\u6765\uff0c\u63d0\u4f9bCMSIS\u7684\u63a5\u53e3\u4f9b\u4f7f\u7528\u8005\u4f7f\u7528\u3002
\u672c\u6587\u53ea\u7b80\u5355\u5217\u4e3e\u4e86\u90e8\u5206CMSIS\u6807\u51c6\u4e0b\u7684\u51fd\u6570\u63a5\u53e3\uff0c\u5176\u4ed6\u51fd\u6570\u53ca\u5176\u5b9e\u73b0\u7ec6\u8282\u8bf7\u53c2\u8003\uff1aCMSIS-RTOS2
"},{"location":"rtos/freertos/CMSIS/#_1","title":"\u4efb\u52a1\u7ba1\u7406","text":"osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); //\u521b\u5efa\u4efb\u52a1\nosThreadId_t osThreadGetId(void); //\u8fd4\u56de\u5f53\u524d\u4efb\u52a1ID\nosStatus_t osThreadSuspend(osThreadId_t thread_id); //\u6302\u8d77\u4efb\u52a1\nosStatus_t osThreadResume(osThreadId_t thread_id); //\u6062\u590d\u4efb\u52a1\nosStatus_t osThreadYield(void); //\u4e3b\u52a8\u8ba9\u51fa\u8d44\u6e90\nvoid osThreadExit(void) //\u7ec8\u6b62\u5f53\u524d\u4efb\u52a1\nosStatus_t osThreadTerminate(osThreadId_t thread_id); //\u7ec8\u6b62\u5176\u4ed6\u4efb\u52a1\nosStatus_t osDelay(uint32_t ticks); //\u5ef6\u65f6ticks\u65f6\u949f\u5468\u671f\n
"},{"location":"rtos/freertos/CMSIS/#_2","title":"\u6d88\u606f\u961f\u5217","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5730\u5740\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n void *mq_mem; //\u6570\u636e\u5b58\u50a8\u5730\u5740\n uint32_t mq_size; //\u6570\u636e\u5b58\u50a8\u5927\u5c0f\n}osMessageQueueAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); //\u521b\u5efa\nosStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id); //\u5220\u9664\nosStatus_t osMessageQueuePut(osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); //\u53d1\u9001\u6d88\u606f\nosStatus_t osMessageQueueGet(osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); //\u83b7\u53d6\u6d88\u606f\nosStatus_t osMessageQueueReset(osMessageQueueId_t mq_id); //\u91cd\u7f6e\u6d88\u606f\u961f\u5217\n
"},{"location":"rtos/freertos/CMSIS/#_3","title":"\u4fe1\u53f7\u91cf","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5730\u5740\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osSemaphoreAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); //\u521b\u5efa\nosStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout); //\u83b7\u53d6\nosStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id); //\u91ca\u653e\nuint32_t osSemaphoreGetCount(osSemaphoreID_t semaphore_id); //\u83b7\u53d6\u8ba1\u6570\u91cf\nosStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_4","title":"\u4e92\u65a5\u91cf","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //\u4e92\u65a5\u91cf\u7c7b\u578b\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5185\u5b58 \n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osMutexAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osMutexId_t osMutexNew(const osMutexAttr_t *attr); //\u521b\u5efa\nosStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout); //\u83b7\u53d6\nosStatus_t osMutexRelease(osMutexId_t mutex_id); //\u91ca\u653e\nosStatus_t osMutexDelete(osMutexId_t mutex_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_5","title":"\u4e8b\u4ef6","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5185\u5b58\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osEventFlagsAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr); //\u521b\u5efa\nuint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags); //\u8bbe\u7f6e\u4f4d\nuint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags); //\u6e05\u7a7a\u4f4d\nuint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); //\u7b49\u5f85\u4f4d\nosStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_6","title":"\u4efb\u52a1\u901a\u77e5","text":"CMSIS\u6807\u51c6\u6ca1\u6709\u63d0\u4f9b\u4efb\u52a1\u901a\u77e5\u7684API\uff0c\u5c5e\u4e8eFreeRTOS\u7684\u7279\u6027\u3002
"},{"location":"rtos/freertos/CMSIS/#_7","title":"\u5b9a\u65f6\u5668","text":"\u5b9a\u4e49\uff1a
typedef struct {\n const char *name; //\u540d\u5b57\n uint32_t attr_bits; //FreeRTOS\u672a\u4f7f\u7528\n void *cb_mem; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5185\u5b58\n uint32_t cb_size; //\u63a7\u5236\u5757\uff08\u9759\u6001\u521b\u5efa\uff09\u5927\u5c0f\n}osTimerAttr_t;\n
\u5e38\u7528\u51fd\u6570\uff1a
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); //\u521b\u5efa\nosStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks); //\u542f\u52a8\nosStatus_t osTimerStop(osTimerId_t timer_id); //\u505c\u6b62\nosStatus_t osTimerDelete(osTimerId_t timer_id); //\u5220\u9664\n
"},{"location":"rtos/freertos/CMSIS/#_8","title":"\u5185\u5b58\u7ba1\u7406","text":"\u5e38\u7528\u51fd\u6570\uff1a
osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, unit32_t block_size, const osMemoryPoolAttr_t *attr); //\u521b\u5efa\nvoid *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, unit32_t timeout); //\u5206\u914d\nosStatut_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block); //\u91ca\u653e\nosStatus_t osMemoryPoolDelete(osMemoryPoolId_t mp_id); //\u5220\u9664\n
"},{"location":"rtos/rt-thread/","title":"rtt\u5185\u6838\u7b80\u4ecb","text":"\u7531\u4e8e\u4e0d\u540cRTOS\u7684\u5185\u6838\u5927\u5dee\u4e0d\u5dee\uff0c\u8fd9\u91cc\u53ea\u8bb0\u5f55\u4e0brtt\u5185\u6838\u6bd4\u8f83\u7279\u6b8a\u7684\u5730\u65b9\u3002
rtt\u5185\u6838\u67b6\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a
rtt\u5185\u6838\u6a21\u5757\u4e3b\u8981\u5206\u4e3a\uff1a
\u7ebf\u7a0b\u8c03\u5ea6 \u65f6\u949f\u7ba1\u7406 \u7ebf\u7a0b\u95f4\u540c\u6b65\u4e0e\u901a\u4fe1 \u5185\u5b58\u7ba1\u7406 \u4e2d\u65ad\u7ba1\u7406 I/O\u8bbe\u5907\u7ba1\u7406 \u5916\u8bbe\u63a5\u53e3 \u4e0b\u56fe\u663e\u793a\u4e86rtt\u4e2d\u5404\u7c7b\u5185\u6838\u5bf9\u8c61\u7684\u6d3e\u751f\u548c\u7ee7\u627f\u5173\u7cfb\u3002
\u5185\u6838\u5bf9\u8c61\u63a7\u5236\u5757\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct rt_object {\n char name[RT_NAME_MAX]; //\u5185\u6838\u5bf9\u8c61\u540d\u79f0\n rt_uint8_t type; //\u5185\u6838\u5bf9\u8c61\u7c7b\u578b\n rt_uint8_t flag; //\u5185\u6838\u5bf9\u8c61\u53c2\u6570\n rt_list_t list; //\u5185\u6838\u5bf9\u8c61\u7ba1\u7406\u94fe\u8868\n};\n
\u5185\u6838\u5bf9\u8c61\u5bb9\u5668\u7684\u6570\u636e\u7ed3\u6784\u5982\u4e0b\uff1a
struct rt_object_information {\n enum rt_object_class_type type; //\u5bf9\u8c61\u7c7b\u578b\n rt_list_t object_list; //\u5bf9\u8c61\u94fe\u8868\n rt_size_t object_size; //\u5bf9\u8c61\u5927\u5c0f\n};\n
\u540c\u4e00\u7c7b\u5bf9\u8c61\u7531\u4e00\u4e2art_object_information\u7ed3\u6784\u4f53\u6765\u7ba1\u7406\uff0c\u8fd9\u7c7b\u5bf9\u8c61\u7684\u6bcf\u4e2a\u5b9e\u4f8b\u4ee5\u94fe\u8868\u7684\u5f62\u5f0f\u6302\u5728object_list\u94fe\u8868\u4e0a\u3002\u5f53\u67d0\u4e2a\u5185\u6838\u5bf9\u8c61\u88ab\u521d\u59cb\u5316\u540e\uff0c\u8be5\u5bf9\u8c61\u5c31\u88ab\u6dfb\u52a0\u5230\u5bf9\u5e94\u5bb9\u5668\u4e2d\u7ba1\u7406\u3002
"},{"location":"rtos/rt-thread/#_1","title":"\u7ebf\u7a0b\u7ba1\u7406","text":"rtt\u4e2d\u7ebf\u7a0b\u72b6\u6001\u591a\u4e86\u4e00\u4e2a\u521d\u59cb\u72b6\u6001\uff0c\u5f53\u7ebf\u7a0b\u521b\u5efa\u5b8c\u6bd5\u8fd8\u6ca1\u5f00\u59cb\u8fd0\u884c\u65f6\u5c31\u5904\u4e8e\u521d\u59cb\u72b6\u6001\uff0c\u8be5\u72b6\u6001\u4e0b\u7ebf\u7a0b\u4e0d\u53c2\u4e0e\u8c03\u5ea6\uff0c\u5b8f\u5b9a\u4e49\u4e3aRT_THREAD_INIT\u3002\u521d\u59cb\u72b6\u6001\u7684\u7ebf\u7a0b\u9700\u8981\u8c03\u7528rt_thread_startup()
\u8fdb\u5165\u5c31\u7eea\u72b6\u6001\u3002
rtt\u6700\u5927\u652f\u6301256\u4e2a\u4f18\u5148\u7ea7\uff0c\u5bf9\u4e8eARM Cortex-M\u7cfb\u5217\u4e00\u822c\u91c7\u752832\u4e2a\u4f18\u5148\u7ea7\u3002
\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u6709\u65f6\u95f4\u7247\u53c2\u6570\uff0c\u65f6\u95f4\u7247\u4ec5\u5bf9\u4f18\u5148\u7ea7\u76f8\u540c\u7684\u5c31\u7eea\u72b6\u6001\u7ebf\u7a0b\u6709\u6548\uff08\u5373\u540c\u4f18\u5148\u7ea7\u53c2\u4e0e\u8c03\u5ea6\uff09\u3002\u65f6\u95f4\u7247\u7684\u5355\u4f4d\u662f\u4e00\u4e2a\u7cfb\u7edf\u8282\u62cd\uff0c\u5176\u610f\u4e49\u662f\u7ebf\u7a0b\u5355\u6b21\u8fd0\u884c\u7684\u65f6\u957f\u3002
\u4f7f\u7528rt_thread_create()
\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u52a8\u6001\u7ebf\u7a0b\uff0c\u4f7f\u7528rt_thread_delete()
\u51fd\u6570\u5220\u9664\u4e00\u4e2a\u52a8\u6001\u7ebf\u7a0b\u3002\u9759\u6001\u7ebf\u7a0b\u7684API\u5206\u522b\u662frt_thread_init()
\u51fd\u6570\u548crt_thread_detach()
\u51fd\u6570\u3002\u4f7f\u7528rt_thread_startup()
\u51fd\u6570\u542f\u52a8\u7ebf\u7a0b\uff0crt_thread_yield()
\u51fd\u6570\u8ba9\u51fa\u7ebf\u7a0b\u8d44\u6e90\uff0crt_thread_delay()
\u51fd\u6570\u4f7f\u7ebf\u7a0b\u7761\u7720\uff0crt_thread_resume()
\u51fd\u6570\u6062\u590d\u7ebf\u7a0b\u3002
"},{"location":"rtos/rt-thread/#_2","title":"\u65f6\u949f\u7ba1\u7406","text":"\u5168\u5c40\u53d8\u91cfrt_tick\u6bcf\u6b21\u7ecf\u8fc7\u4e00\u4e2a\u65f6\u949f\u8282\u62cd\uff0c\u503c\u5c31\u4f1a\u52a01\uff0c\u5b83\u8868\u793a\u7cfb\u7edf\u4ece\u542f\u52a8\u5f00\u59cb\u603b\u5171\u7ecf\u8fc7\u7684\u59cb\u7ec8\u8282\u62cd\u6570\u3002\u6b64\u5916\uff0crt_tick\u6bcf\u6b21\u52a01\u90fd\u4f1a\u68c0\u67e5\u5f53\u524d\u7ebf\u7a0b\u7684\u65f6\u95f4\u7247\u662f\u5426\u4f7f\u7528\u5b8c\uff0c\u4ee5\u53ca\u662f\u5426\u6709\u5b9a\u65f6\u5668\u8d85\u65f6\u3002
rtt\u7684\u5b9a\u65f6\u5668\u53ef\u4ee5\u5206\u4e3aHARD_TIMER\u6a21\u5f0f\u2014\u2014\u5728\u4e2d\u65ad\u73af\u5883\u4e2d\u6267\u884c\uff0c\u548cSOFT_TIMER\u6a21\u5f0f\u2014\u2014\u5728\u7ebf\u7a0b\u73af\u5883\u4e2d\u6267\u884c\u3002
\u65b0\u521b\u5efa\u5e76\u6fc0\u6d3b\u7684\u5b9a\u65f6\u5668\u90fd\u4f1a\u4ee5\u8d85\u65f6\u65f6\u95f4\u6392\u5e8f\u7684\u65b9\u5f0f\u63d2\u5165\u5230rt_timer_list\u94fe\u8868\u4e2d\u3002\u6240\u6709\u5b9a\u65f6\u5668\u5728\u5b9a\u65f6\u8d85\u65f6\u540e\u90fd\u4f1a\u4ece\u5b9a\u65f6\u5668\u94fe\u8868\u4e2d\u88ab\u79fb\u9664\uff0c\u800c\u5468\u671f\u6027\u5b9a\u65f6\u5668\u4f1a\u5728\u5b83\u518d\u6b21\u542f\u52a8\u65f6\u88ab\u52a0\u5165\u5b9a\u65f6\u5668\u94fe\u8868\u3002\u4e0e\u5b9a\u65f6\u5668\u6709\u5173\u7684\u64cd\u4f5c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
"},{"location":"rtos/rt-thread/#_3","title":"\u7ebf\u7a0b\u95f4\u540c\u6b65","text":""},{"location":"rtos/rt-thread/#_4","title":"\u4fe1\u53f7\u91cf","text":"\u4fe1\u53f7\u91cf\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
rtt\u5185\u6838\u5728\u521b\u5efa\u4fe1\u53f7\u91cf\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u901a\u8fc7flag\u53c2\u6570\u6307\u5b9a\u4fe1\u53f7\u91cf\u4e0d\u53ef\u7528\u65f6\u591a\u4e2a\u7ebf\u7a0b\u7b49\u5f85\u7684\u6392\u961f\u65b9\u5f0f\u3002\u6bd4\u5982RT_IPC_FLAG_FIFO\u8868\u793a\u6309\u7167\u5148\u8fdb\u5148\u51fa\u7684\u65b9\u5f0f\u6392\u961f\uff0cRT_IPC_FLAG_PRIO\u8868\u793a\u6309\u7167\u4f18\u5148\u7ea7\u7684\u65b9\u5f0f\u8fdb\u884c\u6392\u961f\u3002\u4e00\u822c\u91c7\u7528\u4f18\u5148\u7ea7\u65b9\u5f0f\uff0c\u9664\u975e\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u5728\u610f\u5148\u6765\u540e\u5230\u3002
"},{"location":"rtos/rt-thread/#_5","title":"\u4e92\u65a5\u91cf","text":"\u4e92\u65a5\u91cf\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
\u4e92\u65a5\u91cf\u4e3b\u8981\u9002\u7528\u4e8e\u4ee5\u4e0b\u60c5\u51b5\uff1a
\u7ebf\u7a0b\u591a\u6b21\u6301\u6709\u4e92\u65a5\u91cf\uff0c\u4e92\u65a5\u91cf\u53ef\u4ee5\u9012\u5f52\u6301\u6709\u800c\u4fe1\u53f7\u91cf\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002 \u7531\u4e8e\u591a\u7ebf\u7a0b\u540c\u6b65\u800c\u9020\u6210\u4f18\u5148\u7ea7\u53cd\u8f6c\u95ee\u9898\u3002 "},{"location":"rtos/rt-thread/#_6","title":"\u4e8b\u4ef6\u7ec4","text":"rtt\u5b9a\u4e49\u7684\u4e8b\u4ef6\u96c6\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a
\u4e8b\u4ef6\u53ea\u4e0e\u7ebf\u7a0b\u76f8\u5173\uff0c\u4e8b\u4ef6\u95f4\u76f8\u4e92\u72ec\u7acb\uff1a\u6bcf\u4e2a\u7ebf\u7a0b\u53ef\u62e5\u670932\u4e2a\u4e8b\u4ef6\u6807\u5fd7\uff0c\u91c7\u7528\u4e00\u4e2a32bit\u65e0\u7b26\u53f7\u6574\u578b\u6570\u8fdb\u884c\u8bb0\u5f55\uff0c\u6bcf\u4e00\u4e2abit\u4ee3\u8868\u4e00\u4e2a\u4e8b\u4ef6\uff1b
\u4e8b\u4ef6\u4ec5\u7528\u4e8e\u540c\u6b65\uff0c\u4e0d\u63d0\u4f9b\u6570\u636e\u4f20\u8f93\u529f\u80fd\uff1b
\u4e8b\u4ef6\u65e0\u6392\u961f\u6027\uff0c\u5373\u591a\u6b21\u5411\u7ebf\u7a0b\u53d1\u9001\u540c\u4e00\u4e8b\u4ef6 (\u5982\u679c\u7ebf\u7a0b\u8fd8\u672a\u6765\u5f97\u53ca\u8bfb\u8d70)\uff0c\u5176\u6548\u679c\u7b49\u540c\u4e8e\u53ea\u53d1\u9001\u4e00\u6b21\u3002
\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u62e5\u6709\u4e00\u4e2a\u4e8b\u4ef6\u4fe1\u606f\u6807\u8bb0\uff0c\u5b83\u6709\u4e09\u4e2a\u5c5e\u6027\uff0c\u5206\u522b\u662fRT_EVENT_FLAG_AND(\u903b\u8f91\u4e0e)\uff0cRT_EVENT_FLAG_OR(\u903b\u8f91\u6216\uff09\u4ee5\u53caRT_EVENT_FLAG_CLEAR(\u6e05\u9664\u6807\u8bb0\uff09\u3002\u5f53\u7ebf\u7a0b\u7b49\u5f85\u4e8b\u4ef6\u540c\u6b65\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc732\u4e2a\u4e8b\u4ef6\u6807\u5fd7\u548c\u8fd9\u4e2a\u4e8b\u4ef6\u4fe1\u606f\u6807\u8bb0\u6765\u5224\u65ad\u5f53\u524d\u63a5\u6536\u7684\u4e8b\u4ef6\u662f\u5426\u6ee1\u8db3\u540c\u6b65\u6761\u4ef6\u3002
\u4e8b\u4ef6\u7ec4\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_7","title":"\u7ebf\u7a0b\u95f4\u901a\u4fe1","text":""},{"location":"rtos/rt-thread/#_8","title":"\u90ae\u7bb1","text":"\u90ae\u7bb1\u7684\u7279\u70b9\u662f\u5f00\u9500\u6bd4\u8f83\u4f4e\uff0c\u6548\u7387\u8f83\u9ad8\u3002\u90ae\u7bb1\u4e2d\u7684\u6bcf\u4e00\u5c01\u90ae\u4ef6\u53ea\u80fd\u5bb9\u7eb3\u56fa\u5b9a\u76844\u5b57\u8282\u5185\u5bb9\uff0c\u4e5f\u5c31\u662f\u8bf4\u90ae\u7bb1\u53ea\u80fd\u7528\u6765\u4f20\u8f93\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5bb9\u3002\u90ae\u7bb1\u4f7f\u7528\u4e00\u4e2a\u56fa\u5b9a\u7f13\u51b2\u533a\u5927\u5c0f\u6765\u5b58\u50a8\u90ae\u4ef6\uff0c\u5176\u5927\u5c0f\u5728\u521b\u5efa\u65f6\u88ab\u5b9a\u4e49\u3002
\u975e\u963b\u585e\u65b9\u5f0f\u7684\u90ae\u4ef6\u53d1\u9001\u8fc7\u7a0b\u80fd\u591f\u5b89\u5168\u7684\u5e94\u7528\u4e8e\u4e2d\u65ad\u670d\u52a1\u4e2d\uff0c\u662f\u7ebf\u7a0b\u3001\u4e2d\u65ad\u670d\u52a1\u3001\u5b9a\u65f6\u5668\u5411\u7ebf\u7a0b\u53d1\u9001\u6d88\u606f\u7684\u6709\u6548\u624b\u6bb5\u3002\u6839\u636e\u5bf9\u5e94\u7684\u60c5\u51b5\uff0c\u90ae\u7bb1\u7684\u6536\u53d6\u6216\u8005\u53d1\u9001\u90fd\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u8d85\u65f6\u963b\u585e\uff0c\u8fdb\u5165\u963b\u585e\u72b6\u6001\u7684\u7ebf\u7a0b\u5c06\u7761\u7720\uff0c\u7b49\u5f85\u5bf9\u5e94\u6761\u4ef6\u6ee1\u8db3\u540e\u5524\u9192\u3002
\u90ae\u7bb1\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_9","title":"\u6d88\u606f\u961f\u5217","text":"\u6d88\u606f\u961f\u5217\u662f\u90ae\u7bb1\u7684\u6269\u5c55\uff0c\u53ef\u4ee5\u7528\u6765\u4f20\u8f93\u4e0d\u56fa\u5b9a\u957f\u5ea6\u7684\u5185\u5bb9\u3002
\u6d88\u606f\u961f\u5217\u9700\u8981\u5c06\u6d88\u606f\u7f13\u5b58\u5728\u81ea\u5df1\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d\uff0c\u56e0\u6b64\u5185\u5b58\u5360\u7528\u6bd4\u90ae\u7bb1\u8981\u5927\u3002\u591a\u4e2a\u7ebf\u7a0b\u80fd\u591f\u8bfb\u53d6\u540c\u4e00\u4e2a\u6d88\u606f\u961f\u5217\u3002\u800c\u5f53\u6d88\u606f\u961f\u5217\u662f\u7a7a\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u6302\u8d77\u8bfb\u53d6\u7ebf\u7a0b\u3002\u5f53\u6709\u65b0\u7684\u6d88\u606f\u5230\u8fbe\u65f6\uff0c\u6302\u8d77\u7684\u7ebf\u7a0b\u5c06\u88ab\u5524\u9192\u4ee5\u63a5\u6536\u5e76\u5904\u7406\u6d88\u606f\u3002\u6d88\u606f\u961f\u5217\u662f\u4e00\u79cd\u5f02\u6b65\u7684\u901a\u4fe1\u65b9\u5f0f\u3002
\u6d88\u606f\u961f\u5217\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_10","title":"\u4fe1\u53f7","text":"\u4fe1\u53f7\u5176\u5b9e\u662f\u7528\u6237\u5c42\u9762\u5bf9\u786c\u4ef6\u4e2d\u65ad\u7684\u4e00\u79cd\u6a21\u62df\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u6536\u5230\u4fe1\u53f7\u4e4b\u540e\u4f1a\u8f6c\u53bb\u5bf9\u5e94\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u3002rtt\u4e2d\u4f7f\u7528rt_sigset_t\u7c7b\u578b\u6765\u5b9a\u4e49\u4fe1\u53f7\u96c6\u3002
\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u6536\u5230\u4fe1\u53f7\u65f6\uff0c\u5982\u679c\u5b83\u5904\u4e8e\u6302\u8d77\u72b6\u6001\uff0c\u90a3\u4e48\u5b83\u4f1a\u6539\u4e3a\u5c31\u7eea\u72b6\u6001\u53bb\u5904\u7406\u5bf9\u5e94\u7684\u4fe1\u53f7\u3002
\u4fe1\u53f7\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
\u5728\u4fe1\u53f7\u7684\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u5148\u5b9a\u4e49\u7ebf\u7a0b\u9700\u8981\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\uff0c\u7136\u540e\u4f7f\u7528rt_signal_install()
\u51fd\u6570\u5c06signo\u4e0e\u5bf9\u5e94\u7684\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u76f8\u5173\u8054\u3002
"},{"location":"rtos/rt-thread/#_11","title":"\u5185\u5b58\u7ba1\u7406","text":"\u5b9e\u65f6\u7cfb\u7edf\u8981\u6c42\u5185\u5b58\u5757\u7684\u5206\u914d\u8fc7\u7a0b\u5728\u53ef\u9884\u6d4b\u7684\u65f6\u95f4\u5185\u5b8c\u6210\uff0c\u5426\u5219\u5b9e\u65f6\u4efb\u52a1\u5bf9\u5916\u90e8\u4e8b\u4ef6\u7684\u54cd\u5e94\u5c06\u53d8\u5f97\u4e0d\u786e\u5b9a\u3002rtt\u5185\u6838\u5728\u5185\u5b58\u5206\u914d\u7ba1\u7406\u7b97\u6cd5\u4e0a\uff0c\u63d0\u4f9b\u4e86\u4e24\u5927\u7c7b\uff1a\u5185\u5b58\u5806\u7ba1\u7406\u4e0e\u5185\u5b58\u6c60\u7ba1\u7406\u3002\u800c\u5185\u5b58\u5bf9\u7ba1\u7406\u53c8\u5212\u5206\u4e3a\u4e09\u79cd\u60c5\u51b5\uff1a\u5c0f\u5185\u5b58\u7ba1\u7406\u7b97\u6cd5\uff0cslab\u7ba1\u7406\u7b97\u6cd5\u548cmemheap\u7ba1\u7406\u7b97\u6cd5\u3002
"},{"location":"rtos/rt-thread/#_12","title":"\u5185\u5b58\u5806\u7ba1\u7406","text":"\u5c0f\u5185\u5b58\u7ba1\u7406\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5185\u5b58\u5206\u914d\u7b97\u6cd5\u3002\u521d\u59cb\u65f6\uff0c\u5b83\u662f\u4e00\u5757\u5927\u5185\u5b58\uff0c\u5f53\u9700\u8981\u5206\u914d\u5185\u5b58\u5757\u65f6\uff0c\u4ece\u8fd9\u5757\u5927\u5185\u5b58\u4e0a\u5206\u5272\u51fa\u54cd\u5e94\u7684\u5185\u5b58\u5757\uff0c\u7a7a\u95f2\u7684\u5185\u5b58\u5757\u5f52\u8fd8\u7ed9\u5806\u7ba1\u7406\u7cfb\u7edf\u3002\u6bcf\u4e2a\u5185\u5b58\u5757\u90fd\u7528\u53cc\u5411\u94fe\u8868\u7684\u65b9\u5f0f\u94fe\u63a5\u8d77\u6765\u3002\u901a\u8fc7*used\u6210\u5458\u53d8\u91cf\u6807\u8bb0\u5f53\u524d\u5185\u5b58\u5757\u662f\u5426\u5df2\u88ab\u4f7f\u7528\u3002
slab\u5206\u914d\u5668\u4f1a\u6839\u636e\u5bf9\u8c61\u7684\u5927\u5c0f\u5206\u6210\u591a\u4e2a\u533a\uff08zone\uff09\uff0c\u4e00\u4e2azone\u7684\u5927\u5c0f\u572832K\u5230128K\u5b57\u8282\u4e4b\u95f4\uff0c\u7cfb\u7edf\u4e2d\u7684zone\u6700\u591a\u5305\u62ec72\u79cd\u5bf9\u8c61\uff0c\u4e00\u6b21\u6027\u6700\u5927\u53ef\u4ee5\u5206\u914d16K\u7684\u7a7a\u95f4\u3002\u5982\u679c\u8d85\u51fa\u4e8616K\u5219\u76f4\u63a5\u4ece\u9875\u5206\u914d\u5668\u4e2d\u5206\u914d\u3002\u6bcf\u4e2azone\u4e0a\u90fd\u662f\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u5757\u94fe\u63a5\u5728\u4e00\u8d77\u3002\u800c72\u79cd\u5bf9\u8c61\u7684zone\u94fe\u8868\u5219\u653e\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7edf\u4e00\u7ba1\u7406\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a
memheap\u7ba1\u7406\u7b97\u6cd5\u9002\u7528\u4e8e\u7cfb\u7edf\u6709\u591a\u4e2a\u4e0d\u53ef\u8fde\u7eed\u5730\u5740\u7684\u5185\u5b58\u5806\u3002\u7528\u6237\u53ea\u9700\u8981\u5728\u7cfb\u7edf\u521d\u59cb\u5316\u65f6\u5c06\u591a\u4e2a\u6240\u9700\u7684memheap\u521d\u59cb\u5316\uff0c\u5e76\u5f00\u542fmemheap\u529f\u80fd\u5c31\u53ef\u4ee5\u5c06\u591a\u4e2amemheap\u7c98\u5408\u8d77\u6765\u7edf\u4e00\u7528\u4f5c\u5185\u5b58\u5206\u914d\u3002
\u5728\u4f7f\u7528\u5185\u5b58\u5806\u65f6\uff0c\u5fc5\u987b\u5728\u7cfb\u7edf\u521d\u59cb\u5316\u7684\u65f6\u5019\u8fdb\u884c\u5806\u7684\u521d\u59cb\u5316\uff1a
void rt_system_heap_init(void *begin_addr, void *end_addr);\n
\u5185\u5b58\u5806\u7ba1\u7406\u7684\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_13","title":"\u5185\u5b58\u6c60\u7ba1\u7406","text":"\u9891\u7e41\u5730\u8c03\u7528\u5185\u5b58\u5206\u914d\u548c\u91ca\u653e\u51fd\u6570\u4f1a\u5bfc\u81f4\u5185\u5b58\u788e\u7247\uff0c\u56e0\u6b64rtt\u5f15\u8fdb\u4e86\u53e6\u5916\u4e00\u79cd\u5185\u5b58\u7ba1\u7406\u65b9\u6cd5\uff1a\u5185\u5b58\u6c60\u3002
\u5185\u5b58\u6c60\u7528\u4e8e\u5206\u914d\u5927\u91cf\u5927\u5c0f\u76f8\u540c\u7684\u5c0f\u5185\u5b58\u5757\uff0c\u5185\u5b58\u6c60\u5728\u521b\u5efa\u65f6\u5148\u5411\u7cfb\u7edf\u7533\u8bf7\u4e00\u5927\u5757\u5185\u5b58\uff0c\u7136\u540e\u5206\u6210\u540c\u6837\u5927\u5c0f\u7684\u591a\u4e2a\u5c0f\u5185\u5b58\u5757\uff0c\u5c0f\u5185\u5b58\u5757\u76f4\u63a5\u901a\u8fc7\u94fe\u8868\u8fde\u63a5\u8d77\u6765\uff08\u6b64\u94fe\u8868\u4e5f\u79f0\u4e3a\u7a7a\u95f2\u94fe\u8868\uff09\u3002\u6bcf\u6b21\u5206\u914d\u7684\u65f6\u5019\uff0c\u4ece\u7a7a\u95f2\u94fe\u8868\u4e2d\u53d6\u51fa\u94fe\u5934\u4e0a\u7b2c\u4e00\u4e2a\u5185\u5b58\u5757\uff0c\u63d0\u4f9b\u7ed9\u7533\u8bf7\u8005\u3002\u5185\u5b58\u6c60\u4e00\u65e6\u521d\u59cb\u5316\u5b8c\u6210\uff0c\u5185\u90e8\u7684\u5185\u5b58\u5757\u5927\u5c0f\u5c06\u4e0d\u80fd\u518d\u505a\u8c03\u6574\u3002
\u5185\u5b58\u6c60\u76f8\u5173\u63a5\u53e3\u51fd\u6570\u5982\u4e0b\uff1a
"},{"location":"rtos/rt-thread/#_14","title":"\u4e2d\u65ad\u7ba1\u7406","text":""},{"location":"tools/","title":"\u5de5\u5177","text":"\u4e3b\u8981\u5217\u4e3e\u4e00\u4e0b\u81ea\u5df1\u4f7f\u7528\u8fc7\u7684\u5de5\u5177\u3002
"},{"location":"tools/github/","title":"github","text":"\u7531\u4e8e\u4f17\u6240\u5468\u77e5\u7684\u539f\u56e0\uff0cgithub\u5728\u56fd\u5185\u7684\u8bbf\u95ee\u4e0d\u5c3d\u5982\u4eba\u610f\uff0c\u4f46\u662f\u56fd\u5916\u5f00\u6e90\u9879\u76ee\u51e0\u4e4e\u90fd\u90e8\u7f72\u5728github\u4e0a\uff0c\u4e0d\u5f97\u4e0d\u7528\u3002\u5982\u679c\u662f\u81ea\u5df1\u7684\u865a\u62df\u673a\u8fde\u63a5\u7f51\u901f\u6bd4\u8f83\u6162\uff0c\u5efa\u8bae\u5f00\u4e2a\u68af\u5b50\u7136\u540e\u914d\u7f6e\u4e0b\u6d41\u91cf\u4ee3\u7406\uff1a
git config --global http.proxy http://127.0.0.1:[\u7aef\u53e3\u53f7]\n\ngit config --global https.proxy http://127.0.0.1:[\u7aef\u53e3\u53f7]\n
\u8fd9\u4e24\u884c\u547d\u4ee4\u7684\u610f\u601d\u662f\u8ba9http\u548chttps\u534f\u8bae\u7684\u6d41\u91cf\u5168\u90e8\u8d70\u4f60\u68af\u5b50\u7684\u4ee3\u7406\uff0c\u7aef\u53e3\u53f7\u6839\u636e\u68af\u5b50\u7684\u914d\u7f6e\u81ea\u884c\u8f93\u5165\u3002\u914d\u7f6e\u5b8c\u4ee5\u540egit clone
\u5e94\u8be5\u4e0d\u4f1a\u5361\u4e86\u3002\u5982\u679c\u4f60\u8981\u53d6\u6d88\u5168\u5c40\u4ee3\u7406\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a
git config --global --unset http.proxy\n\ngit config --global --unset https.proxy\n
\u4e00\u822c\u6765\u8bf4\uff0cgithub\u7684SSH\u9ed8\u8ba4\u901a\u8fc7\u7aef\u53e322\u5efa\u7acb\u8fde\u63a5\uff0c\u9664\u975e\u4f60\u66f4\u6539\u4e86\u914d\u7f6e\u6587\u4ef6\u5f3a\u5236\u4f7f\u7528HTTPS\u7684443\u7aef\u53e3\u8fde\u63a5\u3002
\u8981\u6d4b\u8bd5\u901a\u8fc7HTTPS\u7aef\u53e3\u7684SSH\u8fde\u63a5\u662f\u5426\u53ef\u884c\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a
ssh -T -p 443 git@ssh.github.com\n\n> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.\n
\u5982\u679c\u8f93\u51fa\u4ee5\u4e0a\u5185\u5bb9\uff0c\u5219\u8bf4\u660e\u8fde\u63a5\u53ef\u884c\u3002\u4f60\u53ef\u4ee5\u66f4\u6539~/.ssh/config\u6587\u4ef6\uff0c\u5f3a\u5236\u4e0egithub\u7684\u8fde\u63a5\u90fd\u901a\u8fc7\u8be5\u670d\u52a1\u5668\u548c\u7aef\u53e3\uff1a Host github.com\nHostname ssh.github.com\nPort 443\nUser git\n
\u901a\u8fc7\u518d\u6b21\u8fde\u63a5\u5230github\u6765\u6d4b\u8bd5\u662f\u5426\u6709\u6548\uff0c\u6ce8\u610f\u8fd9\u65f6\u5c31\u4e0d\u9700\u8981\u6307\u5b9a\u7aef\u53e3\u53f7\u4e86\uff1a
ssh -T git@github.com\n\n> Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.\n
\u6ce8\u610f\uff1aSSH\u901a\u8fc7\u516c\u94a5\u548c\u79c1\u94a5\u914d\u5bf9\u7684\u65b9\u5f0f\u6765\u9a8c\u8bc1\u8fde\u63a5\u662f\u5426\u5b89\u5168\uff0c\u5f53\u4f60\u7b2c\u4e00\u6b21\u901a\u8fc7SSH\u8fde\u63a5\u65f6\uff0c\u4f1a\u8be2\u95ee\u4f60\u662f\u5426\u4fe1\u4efb\u8be5\u670d\u52a1\u5668\uff0c\u8f93\u5165yes\u5373\u53ef\u3002
"},{"location":"tools/github/#ssh","title":"\u6dfb\u52a0SSH\u5bc6\u94a5","text":"\u6dfb\u52a0SSH\u5bc6\u94a5\u7684\u8fc7\u7a0b\u5f88\u7b80\u5355\uff0c\u6309\u7167\u6b65\u9aa4\u4e00\u6b65\u6b65\u6765\u5373\u53ef\u3002
1.\u9996\u5148\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u90ae\u4ef6\u5730\u5740\u6539\u4e3a\u4f60\u6ce8\u518cgithub\u7684\u90ae\u7bb1\uff1a
ssh-keygen -t ed25519 -C \"your_email@example.com\"\n
\u7cfb\u7edf\u4f1a\u8981\u6c42\u4f60\u8f93\u5165\u4e00\u4e9b\u4fe1\u606f\uff0c\u8fde\u7eed\u6309\u56de\u8f66\u8df3\u8fc7\u5373\u53ef\u3002
2.\u5c06SSH\u5bc6\u94a5\u6dfb\u52a0\u5230ssh-agent\uff1a
\u5148\u542f\u52a8ssh\u4ee3\u7406\uff1a
eval \"$(ssh-agent -s)\"\n
\u7136\u540e\u6dfb\u52a0\u79c1\u94a5\uff1a
ssh-add ~/.ssh/id_ed25519\n
3.\u5411\u4f60\u7684\u8d26\u6237\u6dfb\u52a0\u65b0\u7684SSH\u5bc6\u94a5
\u73b0\u5728\uff0c.ssh/\u76ee\u5f55\u4e0b\u6709\u4e24\u4e2a\u6587\u4ef6\uff0c\u4ee5pub\u7ed3\u5c3e\u7684\u5c31\u662f\u516c\u94a5\uff0c\u9700\u8981\u4f60\u4e0a\u4f20\u81f3github\u670d\u52a1\u5668\u3002
cat ~/.ssh/id_ed25519.pub\n
\u590d\u5236\u6253\u5370\u7684\u5185\u5bb9\uff0c\u7136\u540e\u5728github\u4e2a\u4eba\u8d44\u6599\u9762\u70b9\u51fb\u8bbe\u7f6e\uff0c\u627e\u5230SSH and GPG keys
\uff0c\u70b9\u51fbNew SSH key
\uff0c\u6700\u540e\u7c98\u8d34\u590d\u5236\u7684\u516c\u94a5\u5373\u53ef\u3002
"},{"location":"tools/github/#_1","title":"\u7ba1\u7406\u8fdc\u7a0b\u4ed3\u5e93","text":"\u8981\u6dfb\u52a0\u4e00\u4e2a\u8fdc\u7a0b\u4ed3\u5e93\u94fe\u63a5\uff0c\u4f7f\u7528git remote add
\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u9700\u8981\u4e24\u4e2a\u53c2\u6570\uff1a
\u8fdc\u7a0b\u4ed3\u5e93\u540d\uff0c\u6bd4\u5982origin
\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\uff0c\u6bd4\u5982https://github.com/OWNER/REPOSITORY.git
git remote add origin https://github.com/OWNER/REPOSITORY.git\n
\u5728\u6dfb\u52a0\u5b8c\u8fdc\u7a0b\u4ed3\u5e93\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528git remote -v
\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u4f60\u5f53\u524d\u6dfb\u52a0\u7684\u8fdc\u7a0b\u4ed3\u5e93\uff1a
git remote -v\n# Verify new remote\n> origin https://github.com/OWNER/REPOSITORY.git (fetch)\n> origin https://github.com/OWNER/REPOSITORY.git (push)\n
\u5982\u679c\u8981\u66f4\u6539\u8fde\u63a5\u8fdc\u7a0b\u4ed3\u5e93\u7684\u65b9\u5f0f\uff0c\u6bd4\u5982\u4eceHTTPS\u6539\u4e3aSSH\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528git remote set-url
\u547d\u4ee4\uff1a
git remote set-url origin git@github.com:OWNER/REPOSITORY.git\n
\u8fd9\u65f6\u8fdc\u7a0b\u4ed3\u5e93\u7684\u683c\u5f0f\u5e94\u8be5\u662f\uff1a
origin git@github.com:OWNER/REPOSITORY.git (fetch)\norigin git@github.com:OWNER/REPOSITORY.git (push)\n
"},{"location":"tools/github/#git","title":"git\u5e38\u7528\u547d\u4ee4","text":"\u9879\u76ee\u521d\u59cb\u5316\uff1a
git init\n
\u521d\u59cb\u5316\u4e2a\u4eba\u4fe1\u606f\uff1a
git config --global user.name \"\u4f60\u7684\u540d\u5b57\"\ngit config --global user.email \"\u4f60\u7684\u90ae\u7bb1\"\n
\u5c06\u53d8\u52a8\u7684\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff1a
git add --all\n
\u63d0\u4ea4\u4ee3\u7801\uff1a
git commit -m \"\u63d0\u4ea4\u4fe1\u606f\"\n
\u63a8\u9001\u4ee3\u7801\uff1a
git push origin main\n
origin\u66ff\u6362\u4e3a\u8fdc\u7a0b\u4ed3\u5e93\u7684\u540d\u79f0\uff0cmain\u66ff\u6362\u4e3a\u63d0\u4ea4\u7684\u5206\u652f\u540d
\u62c9\u53d6\u4ee3\u7801\u5230\u672c\u5730\uff1a
git push origin main\n
\u67e5\u770b\u5f53\u524dgit\u72b6\u6001\uff1a
git status\n
\u67e5\u770b\u63d0\u4ea4\u65e5\u5fd7\uff1a
git log\n
\u5207\u6362\u5206\u652f\uff1a
git check -b [\u65b0\u5206\u652f\u540d]\n
\u5408\u5e76\u4ee3\u7801\uff1a
git merge [\u53e6\u4e00\u4e2a\u5206\u652f\u540d]\n
"},{"location":"tools/markdown/","title":"Markdown","text":"Markdown\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u6807\u8bb0\u8bed\u8a00\uff0c\u6392\u7248\u8bed\u6cd5\u7b80\u6d01\uff0c\u8ba9\u4eba\u4eec\u66f4\u591a\u5730\u5173\u6ce8\u5185\u5bb9\u672c\u8eab\u800c\u975e\u6392\u7248\u3002\u5b83\u4f7f\u7528\u6613\u8bfb\u6613\u5199\u7684\u7eaf\u6587\u672c\u683c\u5f0f\u7f16\u5199\u6587\u6863\uff0c\u53ef\u4e0eHTML\u6df7\u7f16\uff0c\u53ef\u5bfc\u51faHTML\u3001PDF\u4ee5\u53ca\u672c\u8eab\u7684.md\u683c\u5f0f\u7684\u6587\u4ef6\u3002\u56e0\u7b80\u6d01\u3001\u9ad8\u6548\u3001\u6613\u8bfb\u3001\u6613\u5199\uff0cMarkdown\u88ab\u5927\u91cf\u4f7f\u7528\uff0c\u5982Github\u3001Wikipedia\u3001\u7b80\u4e66\u7b49\u3002
\u53ef\u4ee5\u5148\u5728\u7ebf\u4f53\u9a8c\u4e00\u4e0bMarkdown\u5728\u7ebf\u7f16\u8f91\u5668\u3002
Markdown\u7684\u8bed\u6cd5\u5341\u5206\u7b80\u5355\uff0c\u534a\u5c0f\u65f6\u8db3\u4ee5\u638c\u63e1\u3002\u5b66\u5b8c\u4e4b\u540e\u53ef\u4ee5\u4e13\u5fc3\u4e8e\u5185\u5bb9\u8f93\u51fa\uff0c\u5927\u91cf\u63d0\u9ad8\u751f\u4ea7\u529b\uff0c\u975e\u5e38\u63a8\u8350\u3002
\u5b98\u65b9\u7f51\u7ad9\u7684\u5185\u5bb9\u5df2\u7ecf\u8db3\u591f\u8be6\u7ec6\uff0c\u8bf7\u76f4\u63a5\u67e5\u770b\u5b98\u65b9\u6587\u6863\u81ea\u5b66\uff1aMarkdown\u5b98\u65b9\u6559\u7a0b\u3002
"},{"location":"tools/vim/","title":"vim","text":"\u8fd9\u4e0d\u662f\u65b0\u624b\u6559\u7a0b\uff0c\u53ea\u8bb0\u5f55\u4e00\u4e9b\u5e38\u7528\u64cd\u4f5c\u3002
vim\u547d\u4ee4\u53ef\u4ee5\u7531\u64cd\u4f5c\u7b26 + \u6b21\u6570 + \u52a8\u4f5c\u6765\u7ec4\u6210\uff0c\u6bd4\u5982d3w\u8868\u793a\u5220\u96643\u4e2a\u5355\u8bcd\u3002
u\uff1a\u64a4\u9500\u4fee\u6539
CTRL + R\uff1a\u6062\u590d\u4fee\u6539
"},{"location":"tools/vim/#_1","title":"\u79fb\u52a8","text":"h, j, k, l\uff1a\u5de6\u4e0b\u4e0a\u53f3
e\uff1a\u8df3\u8f6c\u81f3\u4e0b\u4e00\u4e2a\u5355\u8bcd\u672b\u5c3e
b:\u8df3\u8f6c\u81f3\u4e0a\u4e00\u4e2a\u5355\u8bcd\u5f00\u5934
w\uff1a\u8df3\u8f6c\u81f3\u4e0b\u4e00\u4e2a\u5355\u8bcd\u5f00\u5934
$\uff1a\u8df3\u8f6c\u81f3\u884c\u672b
CTRL + O\uff1a\u8fd4\u56de\u4e0a\u6b21\u4f4d\u7f6e
CTRL + I\uff1a\u524d\u5f80\u4e0b\u6b21\u4f4d\u7f6e
0\uff1a\u8df3\u8f6c\u81f3\u884c\u9996
nG\uff1a\u8df3\u8f6c\u81f3\u7b2cn\u884c
GG\uff1a\u8df3\u8f6c\u81f3\u6587\u4ef6\u672b\u5c3e
gg\uff1a\u8df3\u8f6c\u81f3\u6587\u4ef6\u5f00\u5934
"},{"location":"tools/vim/#_2","title":"\u63d2\u5165","text":"a\uff1a\u5149\u6807\u540e\u63d2\u5165
A\uff1a\u884c\u5c3e\u63d2\u5165
i\uff1a\u5149\u6807\u524d\u63d2\u5165
I\uff1a\u884c\u9996\u63d2\u5165
o\uff1a\u4e0b\u4e00\u884c\u63d2\u5165
O\uff1a\u4e0a\u4e00\u884c\u63d2\u5165
"},{"location":"tools/vim/#_3","title":"\u5220\u9664","text":"x\uff1a\u5220\u9664\u5149\u6807\u5904\u5b57\u7b26
dd\uff1a\u5220\u9664\u6574\u884c
D\uff1a\u5220\u9664\u81f3\u884c\u672b
dw\uff1a\u4ece\u5f53\u524d\u5149\u6807\u4f4d\u7f6e\uff0c\u4e00\u76f4\u5220\u9664\u81f3\u4e0b\u4e00\u4e2a\u5355\u8bcd\u5f00\u5934
d$\uff1a\u4ece\u5f53\u524d\u5149\u6807\u4f4d\u7f6e\uff0c\u4e00\u76f4\u5220\u9664\u81f3\u884c\u672b
"},{"location":"tools/vim/#_4","title":"\u590d\u5236\u4e0e\u7c98\u8d34","text":"p\uff1a\u5728\u5149\u6807\u4e0b\u4e00\u884c\u4f4d\u7f6e\u590d\u5236
y\uff1a\u590d\u5236\u9009\u4e2d\u5185\u5bb9\uff0c\u9700\u8981\u914d\u5408visual mode
yy\uff1a\u590d\u5236\u5f53\u524d\u884c
yw\uff1a\u590d\u5236\u4e00\u4e2a\u5355\u8bcd
"},{"location":"tools/vim/#_5","title":"\u4fee\u6539\u4e0e\u66ff\u6362","text":"rx\uff1a\u5c06\u5f53\u524d\u5149\u6807\u5904\u5b57\u7b26\u4fee\u6539\u4e3ax
ce\uff1a\u4fee\u6539\u5355\u8bcd
:s/old/new/g\uff1a\u5c06\u5f53\u524d\u884c\u7684'old'\u5168\u90e8\u6539\u4e3a'new'
:%s/old/new/g\uff1a\u5c06\u5f53\u524d\u6587\u4ef6\u7684'old'\u5168\u90e8\u6539\u4e3a'new'
"},{"location":"tools/vim/#_6","title":"\u67e5\u627e","text":"\u6309/\u8fdb\u5165\u67e5\u627e\u6a21\u5f0f\uff0c\u8f93\u5165\u4f60\u8981\u641c\u5bfb\u7684\u5b57\u7b26\u4e32\uff0c\u7136\u540e\uff1a
n\uff1a\u67e5\u627e\u4e0b\u4e00\u4e2a
N\uff1a\u67e5\u627e\u4e0a\u4e00\u4e2a
%\uff1a\u641c\u5bfb\u4e0b\u4e00\u4e2a\u5339\u914d\u7684), ], }
"}]}
\ No newline at end of file
diff --git a/sitemap.xml b/sitemap.xml
index 15d560a0..fafd3342 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -125,4 +125,14 @@
2024-01-23
daily
+
+ https://tomsjtu.github.io/notes/tools/markdown/
+ 2024-01-23
+ daily
+
+
+ https://tomsjtu.github.io/notes/tools/vim/
+ 2024-01-23
+ daily
+
\ No newline at end of file
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
index bf6fad5f35178aaabaac0582d72475d3c1e7dc40..152f9d9a6265e318999c0ebc4d5e7d1dfaee914f 100644
GIT binary patch
literal 368
zcmV-$0gwJ4iwFqupRZ*C|8r?{Wo=<_E_iKh0M*v9Zi6ro2H-tUf!M($?a)?)43#Q%
z=#=&W9DD^gwvV0%2%4a5XCJnr-^=
z{*pbUyJ}VTWIS*(H9NmeTjuUbh;bZquNkcDe2&xzU$@i5i=`-v{4uRo$u#DG>)U0N
z2J320@ly<=^{J-fP%#5!0Rt~B%&y7)}M
z3$qLOm?uUbxNb^=n3&IR``3NoSmKOZ0vYhGVMOCY=UuCzE3KrX!qJ899P~fj+b$0e
OT>Sv2VdM+%5dZ+xuCxIF
literal 357
zcmV-r0h<0FiwFp3Dz9Y%|8r?{Wo=<_E_iKh0M*vLZi6ro2k<>lf!M($?a)?)43#Q%
z=#=&W9DKn}{6Wu0NZ!6CK~?5Tm25AD)A83&$hKT>&PHb^K(Cx#=gYFnGq9}_%69Ag
z>+`L6$~VoT9#DIrEHqoc&LvU*!q_;DrB?)o_r7%4G2hDY;@MneRr#DZi!6*O;P!MK
zwRUYYrT7p-&iDfjWv56EyHYu39f4;xo4W2l;+~8X&8k{G7S*y?J%pCIcGuQQZadf`
zd^dtCeW}@9<)&f3oWH<0nz(U0j;H|RMYh@vB3_~orqFd0>q)GM7+i%0(B%4IJRc&bfXceSTDAfiC9mD$19C}h0Z=5
z@xtsQKIV~}k6ahhASLGO$M$_2ITooPiNGV?HRPQ3vGZ=#|5sio57hhsK}K7;q!0iA
D7DuqU
diff --git a/tools/github/index.html b/tools/github/index.html
index f140490d..e91f8b3b 100644
--- a/tools/github/index.html
+++ b/tools/github/index.html
@@ -18,7 +18,7 @@
-
+
@@ -26,7 +26,7 @@
- github的使用 - 一只Tom的笔记本
+ github - 一只Tom的笔记本
@@ -107,7 +107,7 @@
@@ -1219,6 +1219,10 @@
+
+
+
+
@@ -1286,7 +1290,7 @@
- github的使用
+ github
@@ -1297,7 +1301,7 @@
- github的使用
+ github
@@ -1354,6 +1358,48 @@
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
+
+
+
+
+
+
+
+
+
@@ -1518,7 +1564,7 @@
-github的使用
+github
由于众所周知的原因,github在国内的访问不尽如人意,但是国外开源项目几乎都部署在github上,不得不用。如果是自己的虚拟机连接网速比较慢,建议开个梯子然后配置下流量代理:
git config --global http.proxy http://127.0.0.1:[ 端口号]
diff --git a/tools/index.html b/tools/index.html
index 9ea42999..72658211 100644
--- a/tools/index.html
+++ b/tools/index.html
@@ -26,7 +26,7 @@
- 工具的使用 - 一只Tom的笔记本
+ 工具 - 一只Tom的笔记本
@@ -107,7 +107,7 @@
@@ -1219,6 +1219,10 @@
+
+
+
+
@@ -1277,7 +1281,49 @@
- github的使用
+ github
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown
@@ -1416,7 +1462,8 @@
-工具的使用
+工具
+主要列举一下自己使用过的工具。
diff --git a/tools/markdown/index.html b/tools/markdown/index.html
new file mode 100644
index 00000000..694948a9
--- /dev/null
+++ b/tools/markdown/index.html
@@ -0,0 +1,1531 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Markdown - 一只Tom的笔记本
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Markdown
+Markdown是一种轻量级标记语言,排版语法简洁,让人们更多地关注内容本身而非排版。它使用易读易写的纯文本格式编写文档,可与HTML混编,可导出HTML、PDF以及本身的.md格式的文件。因简洁、高效、易读、易写,Markdown被大量使用,如Github、Wikipedia、简书等。
+可以先在线体验一下Markdown在线编辑器 。
+Markdown的语法十分简单,半小时足以掌握。学完之后可以专心于内容输出,大量提高生产力,非常推荐。
+官方网站的内容已经足够详细,请直接查看官方文档自学:Markdown官方教程 。
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back to top
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tools/vim/index.html b/tools/vim/index.html
new file mode 100644
index 00000000..dd0312ab
--- /dev/null
+++ b/tools/vim/index.html
@@ -0,0 +1,1717 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ vim - 一只Tom的笔记本
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+vim
+这不是新手教程,只记录一些常用操作。
+vim命令可以由操作符 + 次数 + 动作来组成,比如d3w表示删除3个单词。
+u:撤销修改
+CTRL + R:恢复修改
+移动
+h, j, k, l:左下上右
+e:跳转至下一个单词末尾
+b:跳转至上一个单词开头
+w:跳转至下一个单词开头
+$:跳转至行末
+CTRL + O:返回上次位置
+CTRL + I:前往下次位置
+0:跳转至行首
+nG:跳转至第n行
+GG:跳转至文件末尾
+gg:跳转至文件开头
+插入
+a:光标后插入
+A:行尾插入
+i:光标前插入
+I:行首插入
+o:下一行插入
+O:上一行插入
+删除
+x:删除光标处字符
+dd:删除整行
+D:删除至行末
+dw:从当前光标位置,一直删除至下一个单词开头
+d$:从当前光标位置,一直删除至行末
+复制与粘贴
+p:在光标下一行位置复制
+y:复制选中内容,需要配合visual mode
+yy:复制当前行
+yw:复制一个单词
+修改与替换
+rx:将当前光标处字符修改为x
+ce:修改单词
+:s/old/new/g:将当前行的'old'全部改为'new'
+:%s/old/new/g:将当前文件的'old'全部改为'new'
+查找
+按/进入查找模式,输入你要搜寻的字符串,然后:
+n:查找下一个
+N:查找上一个
+%:搜寻下一个匹配的), ], }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back to top
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file