1]sapper是个内核进程;
2]什么时候开始有进程的概念,开始使用mm_init的内容和栈等?
start_kernel时肯定没有进程的概念?什么时候开始有的?
crash> ps 0
PID PPID CPU TASK ST %MEM VSZ RSS COMM
0 0 0 c06f2fd8 RU 0.0 0 0 [swapper/0]
crash> set 0
PID: 0
COMMAND: "swapper/0"
TASK: c06f2fd8 [THREAD_INFO: c06dc000]
CPU: 0
STATE: TASK_RUNNING
crash> bt
PID: 0 TASK: c06f2fd8 CPU: 0 COMMAND: "swapper/0"
#0 [<c0534ffc>] (__schedule) from [<c05355d0>]
#1 [<c0535550>] (schedule) from [<c05356c4>]
#2 [<c05356b8>] (schedule_preempt_disabled) from [<c000f734>]
#3 [<c000f654>] (cpu_idle) from [<c052a13c>]
#4 [<c052a0dc>] (rest_init) from [<c06ab8f0>]
#5 [<c06ab698>] (start_kernel) from [<80008040>]
/******************************************************/
inlude/linux/init_task.h
INIT_TASK(tsk)
{ \
.state = 0, \
.stack = &init_thread_info, \
.usage = ATOMIC_INIT(2), \
.flags = PF_KTHREAD, \
.prio = MAX_PRIO-20, \
.static_prio = MAX_PRIO-20, \
.normal_prio = MAX_PRIO-20, \
.policy = SCHED_NORMAL, \
.cpus_allowed = CPU_MASK_ALL, \
.mm = NULL, \
.active_mm = &init_mm, \
.se = { \
.group_node = LIST_HEAD_INIT(tsk.se.group_node), \
}, \
.rt = { \
.run_list = LIST_HEAD_INIT(tsk.rt.run_list), \
.time_slice = RR_TIMESLICE, \
.nr_cpus_allowed = NR_CPUS, \
}, \
.tasks = LIST_HEAD_INIT(tsk.tasks), \
INIT_PUSHABLE_TASKS(tsk) \
.ptraced = LIST_HEAD_INIT(tsk.ptraced), \
.ptrace_entry = LIST_HEAD_INIT(tsk.ptrace_entry), \
.real_parent = &tsk, \
.parent = &tsk, \
.children = LIST_HEAD_INIT(tsk.children), \
.sibling = LIST_HEAD_INIT(tsk.sibling), \
.group_leader = &tsk, \
RCU_INIT_POINTER(.real_cred, &init_cred), \
RCU_INIT_POINTER(.cred, &init_cred), \
.comm = INIT_TASK_COMM, \
.thread = INIT_THREAD, \
.fs = &init_fs, \
.files = &init_files, \
.signal = &init_signals, \
.sighand = &init_sighand, \
.nsproxy = &init_nsproxy, \
.pending = { \
.list = LIST_HEAD_INIT(tsk.pending.list), \
.signal = {{0}}}, \
.blocked = {{0}}, \
.alloc_lock = __SPIN_LOCK_UNLOCKED(tsk.alloc_lock), \
.journal_info = NULL, \
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
.pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
.timer_slack_ns = 50000, /* 50 usec default slack */ \
.pids = { \
[PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
[PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
[PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \
}, \
.thread_group = LIST_HEAD_INIT(tsk.thread_group), \
INIT_IDS \
INIT_PERF_EVENTS(tsk) \
INIT_TRACE_IRQFLAGS \
INIT_LOCKDEP \
INIT_FTRACE_GRAPH \
INIT_TRACE_RECURSION \
INIT_TASK_RCU_PREEMPT(tsk) \
INIT_CPUSET_SEQ \
}
thread_info
#define init_thread_info (init_thread_union.thread_info)
#define INIT_THREAD_INFO(tsk) \
{ \
.task = &tsk, \
.exec_domain = &default_exec_domain, \
.flags = 0, \
.preempt_count = INIT_PREEMPT_COUNT, \
.addr_limit = KERNEL_DS, \
.cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
.restart_block = { \
.fn = do_no_restart_syscall, \
}, \
}
union thread_union init_thread_union __init_task_data =
{ INIT_THREAD_INFO(init_task) };
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
crash> thread_union
union thread_union {
struct thread_info thread_info;
unsigned long stack[2048];
}
SIZE: 8192
crash> thread_info
struct thread_info {
unsigned long flags;
int preempt_count;
mm_segment_t addr_limit;
struct task_struct *task;
struct exec_domain *exec_domain;
__u32 cpu;
__u32 cpu_domain;
struct cpu_context_save cpu_context;
__u32 syscall;
__u8 used_cp[16];
unsigned long tp_value;
struct crunch_state crunchstate;
union fp_state fpstate;
union vfp_state vfpstate;
struct restart_block restart_block;
}
SIZE: 752
/*thread_struct 和 task_struct完全不是一样的东西,thread_struct应该是很少用到*/
struct thread_struct {
/* fault info */
unsigned long address;
unsigned long trap_no;
unsigned long error_code;
/* debugging */
struct debug_info debug;
};
有关信号
//指向进程信号描述符
struct signal_struct *signal;
//指向信号的处理描述符
struct sighand_struct *sighand;
#define INIT_SIGNALS(sig) { \
.nr_threads = 1, \
.wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
.shared_pending = { \
.list = LIST_HEAD_INIT(sig.shared_pending.list), \
.signal = {{0}}}, \
.posix_timers = LIST_HEAD_INIT(sig.posix_timers), \
.cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \
.rlim = INIT_RLIMITS, \
.cputimer = { \
.cputime = INIT_CPUTIME, \
.running = 0, \
.lock = __RAW_SPIN_LOCK_UNLOCKED(sig.cputimer.lock), \
}, \
.cred_guard_mutex = \
__MUTEX_INITIALIZER(sig.cred_guard_mutex), \
INIT_GROUP_RWSEM(sig) \
}
#define INIT_SIGHAND(sighand) { \
.count = ATOMIC_INIT(1), \
.action = { { { .sa_handler = SIG_DFL, } }, }, \
.siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \
.signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \
}
crash> struct sigpending
struct sigpending {
struct list_head list;
sigset_t signal;
}
/*有关文件的描述
.fs = &init_fs,
.files= &init_files,
*/
struct fs_struct init_fs = {
.users = 1,
.lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
.seq = SEQCNT_ZERO,
.umask = 0022,
};
struct files_struct init_files = {
.count = ATOMIC_INIT(1),
.fdt = &init_files.fdtab,
.fdtab = {
.max_fds = NR_OPEN_DEFAULT,
.fd = &init_files.fd_array[0],
.close_on_exec = init_files.close_on_exec_init,
.open_fds = init_files.open_fds_init,
},
.file_lock = __SPIN_LOCK_UNLOCKED(init_task.file_lock),
};
/*有关memory*/
.equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
其中KERNEL_RAM_VADDR == KERNEL_START,而KERNEL_START = 0xc0008000;
又 PG_DIR_SIZE = 0x4000,
所以:swapper_pg_dir = 0xc0008000 - 0x4000 = 0xc0004000,也就是kernel代码段
上面的16K
struct mm_struct init_mm = {
.mm_rb = RB_ROOT,
.pgd = swapper_pg_dir,
.mm_users = ATOMIC_INIT(2),
.mm_count = ATOMIC_INIT(1),
.mmap_sem = __RWSEM_INITIALIZER(init_mm.mmap_sem),
.page_table_lock = __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
.mmlist = LIST_HEAD_INIT(init_mm.mmlist),
INIT_MM_CONTEXT(init_mm)
};
swapper内核线程的创建没有使用内核函数,是怎么创建的那?只知道是静态变量从栈看:
当跳转到start_kernel都已经使用 swapper的栈了
c06ddfc0: 00000000 00000000 unknown_bootoption 00000000
c06ddfd0: 00000000 cmd_line 10c53c7d __machine_arch_type
c06ddfe0: __atags_pointer cr_alignment 00000000 init_thread_union+8184
c06ddff0: 80008040 start_kernel+12 00000000 00000000