mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-11-26 13:53:02 +08:00
docs: streamline BPF tutorial authoring skills
This commit is contained in:
@@ -11,71 +11,24 @@ Read the complete guidelines first:
|
||||
|
||||
Then read the English and Chinese versions of `47-cuda-events`, `48-energy`, and `49-hid` as style references. Learn their teaching rhythm and level of detail without copying their topic or wording.
|
||||
|
||||
## Document Structure (strictly follow guideline)
|
||||
## Let the topic choose the structure
|
||||
|
||||
For advanced tutorials (40+), follow this exact section order:
|
||||
Follow `scripts/guideline_advance.md` without turning its suggestions into ten mandatory headings. Use a direct title, a short opening, the background the example actually needs, a high-level flow, complete source with explanation, compilation and execution, a compact ending, and primary references. Choose section names that sound natural for the topic.
|
||||
|
||||
1. **Title**: `# eBPF 教程:[Topic Description]` or `# eBPF Tutorial by Example: [Topic Description]`
|
||||
|
||||
2. **Introduction**: Brief intro with a concrete problem scenario. Highlight significance and what readers will learn. Link to complete source once here.
|
||||
|
||||
3. **Background / Why This Approach**:
|
||||
- Explain WHY this approach is needed
|
||||
- List traditional/alternative approaches and their limitations (e.g., killing process, firewall rules, user-space tools)
|
||||
- Explain what eBPF/the new kernel feature enables that traditional approaches cannot
|
||||
- State when the feature entered Linux (kernel version + commit if relevant)
|
||||
|
||||
4. **High-Level Mechanism**:
|
||||
- Explain HOW the eBPF feature/tool works at a high level BEFORE showing code
|
||||
- Describe the overall flow: what happens in kernel, what happens in user space, how they interact
|
||||
- Use diagrams for complex flows with branches, waits, ownership transfers, or 3+ dependent states
|
||||
|
||||
5. **Code Implementation**:
|
||||
- First introduce the overall processing logic
|
||||
- Show complete source code for each component (header, BPF program, user-space loader)
|
||||
- After each complete code block, explain the key parts with paragraph style (not bullet lists)
|
||||
- Focus on logic and advanced features, not basic syntax
|
||||
|
||||
6. **Additional Concepts** (if needed): Deeper explanation of specific features, edge cases, or semantics
|
||||
|
||||
7. **Compilation and Execution** (AFTER code, not before):
|
||||
- Build commands
|
||||
- Run commands with examples
|
||||
- Expected output with explanation
|
||||
- Environment requirements table (kernel version, config, privileges, architecture)
|
||||
|
||||
8. **Summary**: Key points, scope boundaries, future extensions
|
||||
|
||||
9. **Call to Action**: Repository and website invitation (as blockquote)
|
||||
|
||||
10. **References**: Links to kernel commits, upstream selftests, documentation
|
||||
Introduce information at the point where the reader needs it. Compilation follows the code discussion. Extra concept sections, alternative approaches, requirements tables, and diagrams are useful when they clarify a real decision or a flow with several dependent states.
|
||||
|
||||
## Tell one useful story
|
||||
|
||||
- Open with a concrete situation that the example can reproduce and the question it answers.
|
||||
- Near the first mention of eBPF, use one natural sentence to say what eBPF is and why it fits this problem.
|
||||
- Open with the concrete question the tool answers. A short factual setup is often enough; avoid invented stories.
|
||||
- Near the first mention of eBPF, use one natural sentence to say that it runs verified programs at kernel hooks and can send selected state to user space.
|
||||
- Introduce the relevant kernel subsystem and new feature when the running example needs them. State when the feature entered Linux and what it enabled.
|
||||
- Follow one packet, event, task, or device interaction through kernel space and user space. Explain what happens, why it happens, and what the next step enables.
|
||||
- Present the whole flow before detailed code. A small diagram helps when the reader must track a branch, wait, retry, ownership transfer, or at least three dependent states.
|
||||
|
||||
## Explain the "Why" thoroughly
|
||||
|
||||
This is critical. The Background section must explain:
|
||||
- What problem you're solving
|
||||
- What traditional approaches exist (killing process, firewall rules, user-space tools like `ss --kill`, sampling, etc.)
|
||||
- Why each traditional approach doesn't work well (race conditions, incomplete coverage, performance overhead, etc.)
|
||||
- What the eBPF approach enables that wasn't possible before
|
||||
|
||||
Example pattern for the "Why" section:
|
||||
> **杀掉进程**是最直接的想法,但一个进程往往维护着多条连接,杀进程会中断所有业务流量。
|
||||
> **防火墙规则**可以阻止新连接,但对已建立的连接无能为力。
|
||||
> **用户态工具**如 `ss --kill` 依赖 `/proc/net/tcp` 遍历和注入 RST 报文,但这种方式有竞态问题。
|
||||
> **内核态方案**才能真正解决这个问题。BPF 迭代器可以在持有适当锁的情况下遍历内核的套接字表...
|
||||
- Present the whole flow before detailed code. Add a diagram only when it makes a branch, wait, retry, ownership transfer, or multi-stage path materially easier to follow.
|
||||
|
||||
## Sound like a tutorial
|
||||
|
||||
- Use familiar words, direct verbs, and connected paragraphs. Attraction comes from the problem and mechanism rather than promotional language.
|
||||
- Prefer positive descriptions of what the example does. Put remaining limits and safety boundaries in one short paragraph near the end.
|
||||
- Prefer positive descriptions of what the example does. Use negative constructions sparingly. Put the most relevant scope note in one short paragraph near the end.
|
||||
- Use prose for the main explanation and lists for genuinely parallel items.
|
||||
- Keep each paragraph focused on one job. Connect facts through cause, sequence, or contrast instead of listing them like a specification.
|
||||
- Write Chinese naturally from the same facts instead of translating English sentence by sentence. Use restrained punctuation and spaces between Chinese text and Latin letters or numbers.
|
||||
@@ -91,14 +44,14 @@ Use this Chinese paragraph only as a voice reference for connected rhythm, restr
|
||||
- Keep source byte-exact. Preserve comments and commands; use focused excerpts only after the complete block.
|
||||
- Use neither `<details>` nor HTML synchronization markers.
|
||||
- Link to the complete lesson once through its GitHub directory. Avoid an opening catalog of individual files.
|
||||
- Every Markdown link uses an absolute `https://github.com/...` target. Omit a link when no stable GitHub target exists.
|
||||
- Every Markdown link uses a stable absolute `https://` target. GitHub, kernel.org, and authoritative documentation sites are all valid; relative links are prohibited.
|
||||
- Public prose contains no local path, shared test repository, VM name, copy route, cache, prompt, model, agent, or trace detail.
|
||||
|
||||
## Finish the lesson
|
||||
|
||||
- Show copyable build and run commands, representative real output, and what that output proves.
|
||||
- State kernel, configuration, privilege, architecture, and hardware requirements that affect the example (use a table).
|
||||
- End with a compact scope boundary, summary, repository invitation, and primary references.
|
||||
- End with a compact summary, repository invitation, and primary references.
|
||||
- Keep the English and Chinese files aligned on structure, facts, source, commands, output, limits, and references while allowing each language to sound natural.
|
||||
|
||||
The final read should answer: what problem is solved, how one event moves through the system, which eBPF mechanism makes it possible, which code matters, how to run it, what success looks like, and where the example stops.
|
||||
|
||||
Reference in New Issue
Block a user