mcpField
L
linux-kernel-architecture

linux-kernel-architecture

github.com/mohitmishra786开发269343 次安装18 周前更新
代码仓库

关于 linux-kernel-architecture

面向浏览 Linux 内核源码的架构指南,介绍启动流程、主要子系统、initcall 顺序和代码位置,帮助开发者追踪驱动、系统调用、中断及问题。

主要功能

  1. 01内核启动流程概览
  2. 02子系统路径与关键结构
  3. 03initcall 顺序参考
  4. 04源码与配置定位

适用场景

  1. 01查找内核功能的实现位置
  2. 02追踪启动到 init 或驱动 probe 的过程
  3. 03跟踪系统调用或中断路径

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill linux-kernel-architecture

安装后在 Claude Code 中输入/linux-kernel-architecture确认已加载。

详细介绍

Linux 内核架构

目的

帮助建立对 Linux 内核的整体认识:启动流程、主要子系统、关键数据结构,以及在源码中查找代码的位置——补充 skills/kernel/kernel-internals,为驱动和子系统开发提供架构层面的导航。

适用场景

  • 首次探索 linux.git 中的功能或 Bug
  • 了解启动如何进入 init 和驱动 probe
  • 跟踪系统调用或中断在各子系统中的传递过程
  • 在学习 skills/kernel-dev/platform-device-model 或驱动技能之前进行入门

工作流

1. 启动流程(简化版 x86/ARM64)
firmware/UEFI
├── arch/*/boot — decompress kernel, early setup
├── start_kernel() — mm, scheduler, timers, IRQ subsys
├── rest_init() → kernel_init → run_init_process
└── userspace init (systemd)

驱动的 module_init / device_initcall 会在 start_kernel 期间、init 之前运行。

2. 主要子系统
子系统路径(通常)关键结构体
调度器kernel/sched/task_struct、sched_entity
内存mm/struct page、mm_struct、vm_area_struct
VFSfs/inode、dentry、file、super_block
块设备block/request_queue、gendisk
网络net/sk_buff、net_device
驱动drivers/device、device_driver
系统调用kernel/、fs/、mm/SYSCALL_DEFINE*
3. Initcall 级别
/* include/linux/init.h — order matters */
early_initcall → core_initcall → postcore_initcall
→ arch_initcall → subsys_initcall → fs_initcall
→ device_initcall → late_initcall

平台驱动通常通过 subsys_initcall 或 module_init 注册。

4. 查找代码
# Locate symbol
grep -rn "platform_driver_register" drivers/

# Trace config
./scripts/config --state CONFIG_FOO

# File hierarchy docs
ls Documentation/admin-guide/
5. Agent 用法
/linux-kernel-architecture Where does page fault handling live and what calls it?

常见问题

症状原因修复方法
驱动 probe 过早Initcall 与 DT 顺序问题使用 deferred_probe 延迟处理
符号缺失构建为模块使用 modprobe,或通过内置的 CONFIG_* 配置
子系统错误drivers/ 中名称相似按照 struct bus_type 查找
启动挂起提前禁用了 printk使用 earlyprintk、initcall_debug

相关技能

  • skills/kernel/kernel-internals — 深入了解调度器、SLUB、VFS
  • skills/kernel-dev/kernel-memory-management — mm/ 详解
  • skills/kernel-dev/platform-device-model — 驱动模型
  • skills/kernel-dev/device-tree — 硬件描述
  • skills/low-level-programming/linux-kernel-modules — LKM 基础

评论

支持 Markdown