Skip to content

Commit

Permalink
150th
Browse files Browse the repository at this point in the history
  • Loading branch information
iamroot12a committed Mar 3, 2018
1 parent 56a1568 commit 6ab4049
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/arm/include/asm/idmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
/* Tag a function as requiring to be executed via an identity mapping. */
#define __idmap __section(.idmap.text) noinline notrace

/* IAMROOT-12:
* -------------
* early_initcall()로 등록한 init_static_idmap() 함수를 통해 페이지 테이블이
* 등록된다.
*/
init_static_idmap()
extern pgd_t *idmap_pgd;

void setup_mm_for_reboot(void);
Expand Down
6 changes: 6 additions & 0 deletions arch/arm/kernel/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ ENTRY(secondary_startup_arm)
THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
THUMB( .thumb ) @ switch to Thumb now.
THUMB(1: )

/* IAMROOT-12:
* -------------
* 세컨더리 cpu 시작 루틴
*/
ENTRY(secondary_startup)
/*
* Common entry point for secondary CPUs.
Expand Down Expand Up @@ -599,6 +604,7 @@ ENTRY(secondary_startup)
ldr r8, [r7, lr] @ get secondary_data.swapper_pg_dir
adr lr, BSYM(__enable_mmu) @ return address
mov r13, r12 @ __secondary_switched address

ARM( add pc, r10, #PROCINFO_INITFUNC ) @ initialise processor
@ (return control reg)
THUMB( add r12, r10, #PROCINFO_INITFUNC )
Expand Down
9 changes: 9 additions & 0 deletions arch/arm/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
{
int ret;

/* IAMROOT-12:
* -------------
* smp_ops에 등록된 smp_boot_secondary 후크 함수가 없으면 함수를 빠져나간다.
*/
if (!smp_ops.smp_boot_secondary)
return -ENOSYS;

Expand All @@ -125,6 +129,11 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle)
/*
* Now bring the CPU into our world.
*/
/* IAMROOT-12:
* -------------
* smp_ops에 등록된 smp_boot_secondary 후크 함수를 호출한다.
* rpi2: bcm2709_boot_secondary()
*/
ret = smp_ops.smp_boot_secondary(cpu, idle);
if (ret == 0) {
/*
Expand Down
4 changes: 4 additions & 0 deletions arch/arm/mach-bcm2709/bcm2709.c
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,10 @@ int __cpuinit bcm2709_boot_secondary(unsigned int cpu, struct task_struct *idle)
BUG_ON(readl(mbox_clr) != 0);
writel(secondary_boot, mbox_set);

/* IAMROOT-12:
* -------------
* 지정된 시간(timeout)만큼 spin하며 대기한다.
*/
while (--timeout > 0) {
t = readl(mbox_clr);
if (t == 0) break;
Expand Down
14 changes: 14 additions & 0 deletions arch/arm/mm/idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,24 @@ extern char __idmap_text_start[], __idmap_text_end[];

static int __init init_static_idmap(void)
{

/* IAMROOT-12:
* -------------
* 커널에서 사용하는 pgd 테이블을 복사한다. (유저 엔트리들을 제외하고
* 커널 엔트리들은 모두 복사해온다)
*/
idmap_pgd = pgd_alloc(&init_mm);
if (!idmap_pgd)
return -ENOMEM;

/* IAMROOT-12:
* -------------
* 1:1 identity 매핑을 추가한다.(__idmap_text_start ~ __idmap_text_end 까지)
*
* arm:
* 세컨더리 cpu들이 MMU를 켜기 위해 사용하는 함수인 __turn_mmu_on() 함수를
* 호출하기 위해 해당 함수가 1:1 identity 매핑이 되어 있어야 한다.
*/
identity_mapping_add(idmap_pgd, __idmap_text_start,
__idmap_text_end, 0);

Expand Down
9 changes: 9 additions & 0 deletions arch/arm/mm/pgd.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
if (!new_pgd)
goto no_pgd;

/* IAMROOT-12:
* -------------
* 유저쪽 엔트리들을 모두 0으로 초기화한다.
*/
memset(new_pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));

/*
* Copy over the kernel and IO PGD entries
*/

/* IAMROOT-12:
* -------------
* init_mm->pgd(=swapper_pgd)에 있는 커널쪽 엔트리만 복사한다.
*/
init_pgd = pgd_offset_k(0);
memcpy(new_pgd + USER_PTRS_PER_PGD, init_pgd + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
Expand Down
9 changes: 9 additions & 0 deletions include/linux/init_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ extern struct nsproxy init_nsproxy;

extern struct group_info init_groups;

/* IAMROOT-12:
* -------------
* 모든 cpu의 ilde 태스크가 사용하는 pid (nr 값이 0이다)
*/
#define INIT_STRUCT_PID { \
.count = ATOMIC_INIT(1), \
.tasks = { \
Expand Down Expand Up @@ -156,6 +160,11 @@ extern struct task_group root_task_group;
# define INIT_VTIME(tsk)
#endif


/* IAMROOT-12:
* -------------
* idle 태스크의 명칭으로 swapper/<cpu>
*/
#define INIT_TASK_COMM "swapper"

#ifdef CONFIG_RT_MUTEXES
Expand Down
104 changes: 104 additions & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,16 @@ static char *static_command_line;
/* Command line for per-initcall parameter parsing */
static char *initcall_command_line;

/* IAMROOT-12:
* -------------
* "init=" 지정된 문자열
*/
static char *execute_command;

/* IAMROOT-12:
* -------------
* "rdinit=" 지정된 문자열
*/
static char *ramdisk_execute_command;

/*
Expand Down Expand Up @@ -441,6 +450,11 @@ static noinline void __init_refok rest_init(void)
* The boot idle thread must execute schedule()
* at least once to get things moving:
*/

/* IAMROOT-12:
* -------------
* 부트업 cpu의 현재 init 태스크의 스케줄러를 idle로 교체한다.
*/
init_idle_bootup_task(current);
schedule_preempt_disabled();
/* Call into cpu_idle with preempt disabled */
Expand Down Expand Up @@ -863,6 +877,12 @@ asmlinkage __visible void __init start_kernel(void)
/* Call all constructor functions linked into the kernel. */
static void __init do_ctors(void)
{

/* IAMROOT-12:
* -------------
* CONFIG_CONSTRUCTORS 커널 설정이 동작되는 경우 커널 모듈의 constructor를
* 호출한다. (gcc가 만드는 constructor)
*/
#ifdef CONFIG_CONSTRUCTORS
ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;

Expand Down Expand Up @@ -1045,6 +1065,27 @@ static void __init do_initcalls(void)
{
int level;

/* IAMROOT-12:
* -------------
* 0레벨 부터 7레벨 까지로 등록한 함수들을 차례로 호출한다.
*
* pure_initcall(fn) - 0레벨
* core_initcall(fn) - 1레벨
* core_initcall_sync(fn)
* postcore_initcall(fn)
* postcore_initcall_sync(fn)
* arch_initcall(fn)
* arch_initcall_sync(fn)
* subsys_initcall(fn)
* subsys_initcall_sync(fn)
* fs_initcall(fn)
* fs_initcall_sync(fn)
* rootfs_initcall(fn)
* device_initcall(fn)
* device_initcall_sync(fn)
* late_initcall(fn) - 7레벨
* late_initcall_sync(fn) - "
*/
for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
do_initcall_level(level);
}
Expand All @@ -1059,12 +1100,28 @@ static void __init do_initcalls(void)
static void __init do_basic_setup(void)
{
cpuset_init_smp();

/* IAMROOT-12:
* -------------
* khelper 워크큐를 준비한다.
*/

usermodehelper_init();
shmem_init();
driver_init();
init_irq_proc();

/* IAMROOT-12:
* -------------
* 각 커널 모듈의 constructor를 호출한다.
*/
do_ctors();
usermodehelper_enable();

/* IAMROOT-12:
* -------------
* 0레벨부터 7레벨까지의 *_initcall 함수들을 차례로 호출한다.
*/
do_initcalls();
random_int_secret_init();
}
Expand Down Expand Up @@ -1138,16 +1195,39 @@ static int __ref kernel_init(void *unused)
{
int ret;

/* IAMROOT-12:
* -------------
* smp 관련 초기화 함수, early_initcall, 0~7레벨의 initcall 함수들을 호출한다.
*/
kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();

/* IAMROOT-12:
* -------------
* 더 이상 사용하지 않는 init 섹션의 커널 코드와 데이터를 제거한다.
*/
free_initmem();

/* IAMROOT-12:
* -------------
* CONFIG_DEBUG_RODATA 커널 옵션을 사용시 사용한다.
*/
mark_rodata_ro();

/* IAMROOT-12:
* -------------
* 부팅 상태 변경
*/
system_state = SYSTEM_RUNNING;
numa_default_policy();

flush_delayed_fput();

/* IAMROOT-12:
* -------------
* 1) "rdinit=" 지정된 문자열이 있는 경우
*/
if (ramdisk_execute_command) {
ret = run_init_process(ramdisk_execute_command);
if (!ret)
Expand All @@ -1162,13 +1242,24 @@ static int __ref kernel_init(void *unused)
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/

/* IAMROOT-12:
* -------------
* 2) "init=" 지정된 문자열이 있는 경우
*/

if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}

/* IAMROOT-12:
* -------------
* 3) 그 외 아래 디렉토리 순서대로 init 태스크를 호출한다.
*/
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
Expand Down Expand Up @@ -1223,12 +1314,25 @@ static noinline void __init kernel_init_freeable(void)
*/
smp_prepare_cpus(setup_max_cpus);

/* IAMROOT-12:
* -------------
* early_initcall() 매크로로 등록한 함수들을 모두 호출한다.
*/
do_pre_smp_initcalls();
lockup_detector_init();

smp_init();

/* IAMROOT-12:
* -------------
* 스케줄러와 관련된 smp 초기화
*/
sched_init_smp();

/* IAMROOT-12:
* -------------
* 0레벨부터 7레벨까지의 *_initcall 함수들을 차례로 호출한다.
*/
do_basic_setup();

/* Open the /dev/console on the rootfs, this should never fail */
Expand Down
11 changes: 11 additions & 0 deletions kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,17 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen)
if (ret)
goto out;

/* IAMROOT-12:
* -------------
* cpu가 on될 때 호출되는 함수들: (register_cpu_notifier() 함수로 등록)
* - timer_cpu_notify()
* - slab_cpuup_callback()
* - cpuup_callback()
* - arch_timer_cpu_notify()
* - bcm2836_arm_irqchip_cpu_notify()
* - cpu_callback()
* - hrtimer_cpu_notify()
*/
ret = __cpu_notify(CPU_UP_PREPARE | mod, hcpu, -1, &nr_calls);
if (ret) {
nr_calls--;
Expand Down
6 changes: 6 additions & 0 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,12 @@ static inline void init_idle_pids(struct pid_link *links)
struct task_struct *fork_idle(int cpu)
{
struct task_struct *task;

/* IAMROOT-12:
* -------------
* idle 태스크를 fork하고 초기화한다.
* (모든 cpu에서 idle 태스크가 사용하는 pid 번호는 0번을 공유하여 사용한다)
*/
task = copy_process(CLONE_VM, 0, 0, NULL, &init_struct_pid, 0);
if (!IS_ERR(task)) {
init_idle_pids(task->pids);
Expand Down
5 changes: 5 additions & 0 deletions kernel/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
static struct hlist_head *pid_hash;
static unsigned int pidhash_shift = 4;

/* IAMROOT-12:
* -------------
* 모든 cpu의 ilde 태스크가 사용하는 pid
*/
struct pid init_struct_pid = INIT_STRUCT_PID;

int pid_max = PID_MAX_DEFAULT;
Expand Down
Loading

0 comments on commit 6ab4049

Please sign in to comment.