diff --git a/lab4/.gdbinit b/lab4/.gdbinit index 8371cbe..38ac1f7 100644 --- a/lab4/.gdbinit +++ b/lab4/.gdbinit @@ -13,4 +13,4 @@ define add-symbol-file-auto end add-symbol-file-auto ./build/kernel.img -add-symbol-file-auto ./user/build/ramdisk/yield_multi_aff.bin +add-symbol-file-auto ./user/build/ramdisk/spawn_info.bin diff --git a/lab4/kernel/sched/policy_rr.c b/lab4/kernel/sched/policy_rr.c index 4e57fb9..2ea1e99 100644 --- a/lab4/kernel/sched/policy_rr.c +++ b/lab4/kernel/sched/policy_rr.c @@ -144,8 +144,8 @@ struct thread *rr_sched_choose_thread(void) return NULL; } - kdebug("[RR] Cpu #%d Select thread %lx, sp = %lx\n", - smp_get_cpu_id(), result->thread_ctx, result->thread_ctx->ec.reg[SP_EL0]); +// kdebug("[RR] Cpu #%d Select thread %lx, sp = %lx\n", +// smp_get_cpu_id(), result->thread_ctx, result->thread_ctx->ec.reg[SP_EL0]); return result; } @@ -179,7 +179,7 @@ int rr_sched(void) // 若非空闲线程,放入队列 if (current_thread->thread_ctx->type != TYPE_IDLE) { rr_sched_enqueue(current_thread); - kdebug("[RR] Cpu #%d yield thread %lx to queue\n", smp_get_cpu_id(), current_thread->thread_ctx); +// kdebug("[RR] Cpu #%d yield thread %lx to queue\n", smp_get_cpu_id(), current_thread->thread_ctx); } } diff --git a/lab4/user/lib/spawn.c b/lab4/user/lib/spawn.c index 501b779..72904cd 100644 --- a/lab4/user/lib/spawn.c +++ b/lab4/user/lib/spawn.c @@ -259,8 +259,8 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, * process. * You do not need to modify code in this scope */ - pmo_requests[0].size = LAB4_SPAWN_BLANK; - pmo_requests[0].type = LAB4_SPAWN_BLANK; + pmo_requests[0].size = MAIN_THREAD_STACK_SIZE; + pmo_requests[0].type = PMO_DATA; ret = usys_create_pmos((void *)pmo_requests, 1); if (ret != 0) { @@ -284,7 +284,7 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, * Transfer the capbilities (nr_caps) of current process to the * capbilities of child process */ - + // 将需要转移的 Caps 进行转移 if (nr_caps > 0) { /* usys_transfer_caps is used during process creation */ ret = usys_transfer_caps(new_process_cap, caps, nr_caps, @@ -302,7 +302,8 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, * Use the given pmo_mao_reqs to map the vmspace in the child * process */ - if (nr_pmo_map_reqs) { + // 将参数中需要映射子进程的 PMOs 进行映射,即可实现共享内存 + if (nr_pmo_map_reqs > 0) { ret = usys_map_pmos(new_process_cap, (void *)pmo_map_reqs, nr_pmo_map_reqs); @@ -329,13 +330,13 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, * thread's stack? * * For stack_offset, when the main thread gets - * to execute the first time, what's the virtual adress the sp + * to execute the first time, what's the virtual address the sp * register points to? * stack_offset is the offset from main thread's stack base to * that address. */ - stack_top = LAB4_SPAWN_BLANK; - stack_offset = LAB4_SPAWN_BLANK; + stack_top = MAIN_THREAD_STACK_BASE + MAIN_THREAD_STACK_SIZE; + stack_offset = MAIN_THREAD_STACK_SIZE - PAGE_SIZE; /* Construct the parameters on the top page of the stack */ construct_init_env(init_env, stack_top, &user_elf->elf_meta, @@ -364,9 +365,9 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, * map the the main thread stack's pmo in the new process. * Both VM_READ and VM_WRITE permission should be set. */ - pmo_map_requests[0].pmo_cap = LAB4_SPAWN_BLANK; - pmo_map_requests[0].addr = LAB4_SPAWN_BLANK; - pmo_map_requests[0].perm = LAB4_SPAWN_BLANK; + pmo_map_requests[0].pmo_cap = main_stack_cap; + pmo_map_requests[0].addr = MAIN_THREAD_STACK_BASE; + pmo_map_requests[0].perm = VM_READ | VM_WRITE; ret = usys_map_pmos(new_process_cap, (void *)pmo_map_requests, 1); @@ -384,7 +385,7 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, * create main thread in the new process. * Please fill the stack_va! */ - stack_va = LAB4_SPAWN_BLANK; + stack_va = MAIN_THREAD_STACK_BASE + stack_offset; main_thread_cap = usys_create_thread(new_process_cap, stack_va, pc, (u64) NULL, MAIN_THREAD_PRIO, aff); @@ -397,6 +398,12 @@ int launch_process_with_pmos_caps(struct user_elf *user_elf, { /* Step C: Output the child process & thread capabilities */ + if (child_process_cap != NULL) { + + } + if (child_main_thread_cap != NULL) { + + } } return 0; diff --git a/note.org b/note.org index c2349a2..20e017d 100644 --- a/note.org +++ b/note.org @@ -211,3 +211,9 @@ sys_yield 要注意必须手动调用切换上下文,不然不会有效果。 *** 练习8 否则将无法再次在该核上进行调度。 + +*** 练习15 + +Step A、B 的代码完全没有删干净,而且 A、B 描述都是反的。所以写完练习 14 就可以直接通过 spawn info 了。 + +我还以为乱码是我又映射错了,结果是代码真的是这么设计的,好吧。