利用在线Linux内核代码阅读分析网站linux kernel map分析CFS调度器代码调用链路
linux kernel map网址
https://makelinux.github.io/kernel/map/
源码分析
点击Scheduler标签内的kernel/sched/
左侧菜单,选择一个内核版本
Search Identifier搜索框输入要搜索的函数,回车执行搜索
结果列出了一处函数定义及两处引用
新窗口打开定义
可以看到该函数的源码
回到上个页面,点击一处引用,查看调用处
网页会自动显示到调用处,并有色块标注
点击do_sched_cfs_period_timer
网页跳转到该函数搜索结果页面,继续点击引用
依次循环,找出完整的调用链路
分支1:调用处
- kernel/sched/core.c, line 6056
void __init sched_init(void)
到达内核入口函数
asmlinkage __visible void __init start_kernel(void)
分支2:调用处
- kernel/sched/fair.c, line 10085
分支1:
- kernel/sched/autogroup.c, line 71
ksys_setsid分支2
- init/do_mounts_initrd.c, line 38
位于
static noinline void __init kernel_init_freeable(void)
到达kernel_init
ksys_setsid分支2
- kernel/sys.c, line 1190
宏定义
宏展开SYSCALL_DEFINED(setsid)
SYSCALL_METADATA(setsid, 0); \\
asmlinkage long sys_setsid(void); \\
ALLOW_ERROR_iNJECTION(sys_setsid, ERRNO); \\
asmlinkage long sys_setsid(void)
参考:
https://blog.csdn.net/hknaruto/article/details/129857542
利用gcc展开
gcc \\
-E \\
-Wp,-MD,kernel/.sys.o.d \\
-nostdinc \\
-isystem \\
/usr/lib/gcc/aarch64-linux-gnu/7.3.0/include \\
-I./arch/arm64/include \\
-I./arch/arm64/include/generated \\
-I./include \\
-I./arch/arm64/include/uapi \\
-I./arch/arm64/include/generated/uapi \\
-I./include/uapi \\
-I./include/generated/uapi \\
-include \\
./include/linux/kconfig.h \\
-include \\
./include/linux/compiler_types.h \\
-D__KERNEL__ \\
-mlittle-endian \\
-Wall \\
-Wundef \\
-Wstrict-prototypes \\
-Wno-trigraphs \\
-fno-strict-aliasing \\
-fno-common \\
-fshort-wchar \\
-Werror-implicit-function-declaration \\
-Wno-format-security \\
-std=gnu89 \\
-fno-PIE \\
-mgeneral-regs-only \\
-DCONFIG_AS_LSE=1 \\
-fno-asynchronous-unwind-tables \\
-Wno-psabi \\
-mabi=lp64 \\
-fno-delete-null-pointer-checks \\
-Wno-frame-address \\
-Wno-format-truncation \\
-Wno-format-overflow \\
-Wno-int-in-bool-context \\
-O2 \\
--param=allow-store-data-races=0 \\
-Wframe-larger-than=2048 \\
-fstack-protector-strong \\
-Wno-unused-but-set-variable \\
-Wno-unused-const-variable \\
-fno-omit-frame-pointer \\
-fno-optimize-sibling-calls \\
-fno-var-tracking-assignments \\
-g \\
-gdwarf-4 \\
-pg \\
-fno-inline-functions-called-once \\
-Wdeclaration-after-statement \\
-Wno-pointer-sign \\
-fno-strict-overflow \\
-fno-merge-all-constants \\
-fmerge-constants \\
-fno-stack-check \\
-fconserve-stack \\
-Werror=implicit-int \\
-Werror=strict-prototypes \\
-Werror=date-time \\
-Werror=incompatible-pointer-types \\
-Werror=designated-init \\
-DKBUILD_BASENAME=\\"sys\\" \\
-DKBUILD_MODNAME=\\"sys\\" \\
-o \\
/tmp/sys.E.c \\
"kernel/sys.c"
查看/tmp/sys.E.c
static const char *types__setsid[] = { }; static const char *args__setsid[] = { }; static struct syscall_metadata __syscall_meta__setsid; static struct trace_event_call __attribute__((__used__)) event_enter__setsid = { .class = &event_class_syscall_enter, { .name = "sys_enter"" _setsid", }, .event.funcs = &enter_syscall_print_funcs, .data = (void *)&__syscall_meta__setsid, .flags = TRACE_EVENT_FL_CAP_ANY, }; static struct trace_event_call __attribute__((__used__)) __attribute__((section("_ftrace_events"))) *__event_enter__setsid = &event_enter__setsid ;; static struct syscall_metadata __syscall_meta__setsid; static struct trace_event_call __attribute__((__used__)) event_exit__setsid = { .class = &event_class_syscall_exit, { .name = "sys_exit""_setsid", }, .event.funcs = &exit_syscall_print_funcs, .data = (void *)&__syscall_m eta__setsid, .flags = TRACE_EVENT_FL_CAP_ANY, }; static struct trace_event_call __attribute__((__used__)) __attribute__((section("_ftrace_events"))) *__event_exit__setsid = &event_exit__setsid;; static struct syscall_metadata __attribute__((__used__)) __syscall_meta__setsid = { .name = "sys""_setsid", .syscall_nr = -1, .nb_args = 0, .types = 0 ? types__setsid : ((void *)0), .args = 0 ? args__setsid : ((void *)0), .enter_event = &event_enter__setsid, .exit_event = &event_exit__setsid, .enter_fields = { &(__syscall_meta__setsid.enter_fields), &(__sysca ll_meta__setsid.enter_fields) }, }; static struct syscall_metadata __attribute__((__used__)) __attribute__((section("__syscalls_metadata"))) *__p_syscall_meta__setsid = &__syscall_meta__setsid;; long __arm64_sys_setsid(const struct pt_regs *__unused); ; long __arm64_sys_setsid( const struct pt_regs *__unused)
{return ksys_setsid();
}
最终生成的函数名long __arm64_sys_setsid( const struct pt_regs *__unused)
搜索不到结果,应该是宏修饰导致