diff --git a/README.md b/README.md index 30e5b730..7061ffac 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ English | [ไธญๆ](README_ZH.md) ## ๐ Roadmap -- [ ] add docs; - [ ] add performance [benchmark](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview); - [ ] cancel coroutine/task; @@ -194,7 +193,7 @@ fn main() { - [Coroutine Pool Overview](core/docs/en/coroutine-pool.md) - [Hook Overview](hook/docs/en/hook.md) -[ๆๆๆ ไบ,ไฝ ๆ้ ๅ?](https://github.com/acl-dev/open-coroutine-docs) +[Old Docs Here](https://github.com/acl-dev/open-coroutine-docs) ## ๐ Credits diff --git a/README_ZH.md b/README_ZH.md index 324686a7..d842c595 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -28,7 +28,6 @@ ## ๐ ๆชๆฅ่ฎกๅ -- [ ] ๅฎๅๆๆกฃ; - [ ] ๅขๅ ๆง่ฝ[ๅบๅๆต่ฏ](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview); - [ ] ๅๆถๅ็จ/ไปปๅก; @@ -185,7 +184,7 @@ fn main() { - [่ฏ็ไนๅ ](docs/cn/background.md) - [่ฏญ่จ้ๆฉ](docs/cn/why-rust.md) -[ๆๆๆ ไบ,ไฝ ๆ้ ๅ?](https://github.com/acl-dev/open-coroutine-docs) +[ๆง็ๆๆกฃๅจ่ฟ](https://github.com/acl-dev/open-coroutine-docs) ## ๐ ้ธฃ่ฐข diff --git a/core/docs/en/monitor.md b/core/docs/en/monitor.md index 12f3df94..a4636c0b 100644 --- a/core/docs/en/monitor.md +++ b/core/docs/en/monitor.md @@ -21,6 +21,9 @@ The `preemptive` feature currently supports the following targets: โ Tested and stable; โ ๏ธ Tested but unstable; โ Not supported. +โ ๏ธ If you want to use `preemptive` feature with `open-coroutine-core` not `open-coroutine`, you must learn +[Hook Overview](../../../hook/docs/en/hook.md). + ## Usage ```rust diff --git a/hook/docs/en/hook.md b/hook/docs/en/hook.md index 4d944060..0b4544c6 100644 --- a/hook/docs/en/hook.md +++ b/hook/docs/en/hook.md @@ -1 +1,81 @@ -todo \ No newline at end of file +--- +title: Hook Overview +date: 2025-01-20 10:00:00 +author: loongs-zhang +--- + +# Hook Overview + +## Why hook? + +After a `Coroutine::resume_with`, a coroutine may occupy the scheduling thread for a long time, thereby slowing down +other coroutines scheduled by that scheduling thread. To solve this problem, we introduce hook, which automatically +suspends coroutines entering syscall and allow other coroutines to execute. + +The coroutine occupies scheduling threads for a long time in two scenarios: getting stuck in heavy computing or syscall. +The following only solves the problem of getting stuck in syscall. + +Another problem is that `signals can interrupt the running syscall`, and the `preemptive` feature mechanism sends a +large +number of signals. In addition, most user code does not handle signals, if they directly use `open-routine-core` and +enabling preemptive will lead to `catastrophic consequences`. + +## What is hook? + +Hook can modify or extend the behavior of existing code by inserting custom code at runtime, and even monitor, +intercept, modify, and redirect system calls. Now, let's use an [example](https://github.com/loongs-zhang/link-example) +to visually experience it. + +Assuming we have the following test code: + +```rust +use std::time::{Duration, Instant}; + +#[test] +fn test_hook() { + let start = Instant::now(); + std::thread::sleep(Duration::MAX); + let cost = Instant::now().duration_since(start); + println!("cost: {:?}", cost); +} +``` + +If we don't hook, this test would almost never end due to `std::thread::sleep(Duration::MAX)`, but with hook, we +redirect the `nanosleep` syscall +to [our custom code](https://github.com/loongs-zhang/link-example/blob/master/dep/src/lib.rs) `without change the test +code`, and then the test +will [end soon](https://github.com/loongs-zhang/link-example/actions/runs/12862762378/job/35858206179). + +
+