diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 435bb977..639a8044 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,72 +1,7 @@ -FROM ipads/chcore_builder:v1.9.0 +FROM ipads/oslab:24.09 ARG USERNAME=stu ARG USER_UID=1000 ARG USER_GID=$USER_UID -RUN sed -i "s/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list -RUN apt-get update && apt-get upgrade -y -RUN apt-get install -y sudo \ - binutils-dev \ - libgmp-dev \ - libmpfr-dev \ - curl \ - meson \ - python3 \ - python3-pip \ - python3-psutil \ - bear \ - cmake \ - git \ - pkgconf \ - clangd - -# We need to install a latest gdb to support cppdbg. -RUN curl -SLO https://ftp.gnu.org/gnu/gdb/gdb-13.2.tar.xz && \ - tar -xf gdb-13.2.tar.xz && \ - cd gdb-13.2 && \ - ./configure --prefix=/usr/local \ - --enable-targets=aarch64-linux-gnu,x86_64-linux-gnu \ - --enable-tui \ - --disable-sim \ - && \ - make -j$(nproc) && \ - make install && \ - cd .. && \ - rm -rf gdb-13.2 gdb-13.2.tar.xz - -# install tomli for .toml file required by qemu 9.1.x -RUN pip install tomli - -# we need to install >=glib-2.66.8 to support qemu 9.1.x -RUN curl -SLO https://download.gnome.org/sources/glib/2.66/glib-2.66.8.tar.xz && \ - tar -xvf glib-2.66.8.tar.xz && \ - cd glib-2.66.8 && \ - meson build --prefix /usr/local && \ - ninja -C build && \ - ninja -C build install && \ - cd .. && \ - rm -rf glib-2.66.8 glib-2.66.8.tar.xz - -# install latest supported qemu supported by ubuntu-20.04. -RUN curl -SLO https://download.qemu.org/qemu-9.1.0.tar.xz && \ - tar -xf qemu-9.1.0.tar.xz && \ - cd qemu-9.1.0 && \ - ./configure --prefix=/usr/local \ - --target-list=aarch64-softmmu,aarch64-linux-user && \ - make -j$(nproc) && \ - make install && \ - cd .. && \ - rm -rf qemu-9.1.0 qemu-9.1.0.tar.xz - -RUN apt-get install -y libglib2.0-dev -RUN apt-get clean - -# install repo -RUN curl -SL https://storage.googleapis.com/git-repo-downloads/repo -o /usr/local/bin/repo && \ - chmod +x /usr/local/bin/repo -RUN useradd -m -u $USER_UID -U -s /bin/bash stu -RUN usermod -aG sudo stu -RUN passwd -d stu -USER $USERNAME CMD ["/bin/bash"] diff --git a/Lab4/kernel/arch/aarch64/main.c.dbg.obj b/Lab4/kernel/arch/aarch64/main.c.dbg.obj index e4a1aa59..120a2a84 100644 Binary files a/Lab4/kernel/arch/aarch64/main.c.dbg.obj and b/Lab4/kernel/arch/aarch64/main.c.dbg.obj differ diff --git a/Lab4/kernel/arch/aarch64/main.c.obj b/Lab4/kernel/arch/aarch64/main.c.obj index 58b7e46a..3c731cf6 100644 Binary files a/Lab4/kernel/arch/aarch64/main.c.obj and b/Lab4/kernel/arch/aarch64/main.c.obj differ diff --git a/Lab4/kernel/arch/aarch64/plat/raspi3/irq/timer.c b/Lab4/kernel/arch/aarch64/plat/raspi3/irq/timer.c index bc117496..c843cd81 100644 --- a/Lab4/kernel/arch/aarch64/plat/raspi3/irq/timer.c +++ b/Lab4/kernel/arch/aarch64/plat/raspi3/irq/timer.c @@ -64,8 +64,7 @@ void plat_timer_init(void) /* Write timer_ctl to the control register (cntp_ctl_el0) */ /* LAB 4 TODO END (exercise 5) */ - - test_timer_init(); + lab4_test_timer_init(); return; } diff --git a/Lab4/kernel/object/thread.c.dbg.obj b/Lab4/kernel/object/thread.c.dbg.obj index ff7c88b7..3731393f 100644 Binary files a/Lab4/kernel/object/thread.c.dbg.obj and b/Lab4/kernel/object/thread.c.dbg.obj differ diff --git a/Lab4/kernel/object/thread.c.obj b/Lab4/kernel/object/thread.c.obj index 61f142c6..0d9add72 100644 Binary files a/Lab4/kernel/object/thread.c.obj and b/Lab4/kernel/object/thread.c.obj differ diff --git a/Lab4/kernel/sched/policy_rr.c b/Lab4/kernel/sched/policy_rr.c index 3b8f9151..ab070876 100644 --- a/Lab4/kernel/sched/policy_rr.c +++ b/Lab4/kernel/sched/policy_rr.c @@ -292,7 +292,7 @@ int rr_sched_init(void) /* LAB 4 TODO END (exercise 1) */ - test_scheduler_meta(); + lab4_test_scheduler_meta(); return 0; } diff --git a/Lab4/kernel/tests/runtime/CMakeLists.txt b/Lab4/kernel/tests/runtime/CMakeLists.txt index 8b168868..eaa8634e 100644 --- a/Lab4/kernel/tests/runtime/CMakeLists.txt +++ b/Lab4/kernel/tests/runtime/CMakeLists.txt @@ -8,5 +8,5 @@ # PURPOSE. # See the Mulan PSL v2 for more details. -target_sources(${kernel_target} PRIVATE lab4.c.obj) +chcore_target_precompile(${kernel_target} PRIVATE tests.c) target_include_directories(${kernel_target} PRIVATE ../) diff --git a/Lab4/kernel/tests/runtime/lab4.c.obj b/Lab4/kernel/tests/runtime/lab4.c.obj deleted file mode 100644 index fc5fd27a..00000000 Binary files a/Lab4/kernel/tests/runtime/lab4.c.obj and /dev/null differ diff --git a/Lab4/kernel/tests/runtime/tests.c.dbg.obj b/Lab4/kernel/tests/runtime/tests.c.dbg.obj new file mode 100644 index 00000000..24a7e194 Binary files /dev/null and b/Lab4/kernel/tests/runtime/tests.c.dbg.obj differ diff --git a/Lab4/kernel/tests/runtime/tests.c.obj b/Lab4/kernel/tests/runtime/tests.c.obj new file mode 100644 index 00000000..e1a36252 Binary files /dev/null and b/Lab4/kernel/tests/runtime/tests.c.obj differ diff --git a/Lab4/kernel/tests/runtime/tests.h b/Lab4/kernel/tests/runtime/tests.h index 81bc51e3..5d53f624 100644 --- a/Lab4/kernel/tests/runtime/tests.h +++ b/Lab4/kernel/tests/runtime/tests.h @@ -13,26 +13,9 @@ #ifndef KERNEL_TESTS_RUNTIME_TESTS_H #define KERNEL_TESTS_RUNTIME_TESTS_H -#define lab_check(expr, test_name) \ - do { \ - if (expr) { \ - printk("[TEST] %s: OK\n", test_name); \ - } else { \ - printk("[TEST] %s: FAIL, loc: %s:%d\n", \ - test_name, \ - __FILE__, \ - __LINE__); \ - } \ - } while (0) - -#define lab_assert(expr) \ - do { \ - ok = ok && (expr); \ - } while (0) - -void test_scheduler_meta(void); -void test_schedule_enqueue(struct thread *root_thread); -void test_schedule_dequeue(void); -void test_timer_init(void); - +#define TEST_SUITE(lab, name, ...) void lab##_##name(__VA_ARGS__) +TEST_SUITE(lab4, test_sched_enqueue, struct thread *root_thread); +TEST_SUITE(lab4, test_sched_dequeue, void); +TEST_SUITE(lab4, test_scheduler_meta, void); +TEST_SUITE(lab4, test_timer_init, void); #endif /* KERNEL_TESTS_RUNTIME_TESTS_H */ diff --git a/Lab4/scores.json b/Lab4/scores.json new file mode 100644 index 00000000..63aca615 --- /dev/null +++ b/Lab4/scores.json @@ -0,0 +1,35 @@ +[ + { + "capture": "test_scheduler_meta: OK", + "msg": "Scheduler Initialization", + "proposed": 10 + }, + { + "capture": "test_sched_enqueue: OK", + "msg": "Scheduler Enqueue", + "proposed": 10 + }, + { + "capture": "test_sched_dequeue: OK", + "msg": "Scheduler Dequeue", + "proposed": 10 + }, + { + "capture": "Cooperative Scheduling Test Done!", + "msg": "Cooperative Scheduling", + "proposed": 20, + "userland": true + }, + { + "capture": "Preemptive Scheduling Test Done!", + "msg": "Preemptive Scheduling", + "proposed": 20, + "userland": true + }, + { + "capture": "Test IPC finished!", + "msg": "Test IPC", + "proposed": 30, + "userland": true + } +] diff --git a/Lab4/user/system-services/system-servers/procmgr/procmgr.c b/Lab4/user/system-services/system-servers/procmgr/procmgr.c index 33628190..2bcb889d 100644 --- a/Lab4/user/system-services/system-servers/procmgr/procmgr.c +++ b/Lab4/user/system-services/system-servers/procmgr/procmgr.c @@ -678,6 +678,60 @@ void boot_default_apps(void) #endif } +static void bind_to_cpu(int cpu) +{ + cpu_set_t mask; + + CPU_ZERO(&mask); + CPU_SET(cpu, &mask); + sched_setaffinity(0, sizeof(mask), &mask); + + /* + * Invoke usys_yield to ensure current thread to run on the target CPU. + * If current thread is running on another CPU, it will be migrated to + * the specific CPU after setting affinity. + */ + usys_yield(); +} + +void *thread_routine1(void *arg) +{ + bind_to_cpu(0); + for (int i = 0; i < 3; ++i) { + printf("Hello from thread 2\n"); + usys_yield(); + } + printf("Cooperative Schedluing Test Done!\n"); + return NULL; +} + +void *thread_routine2(void *arg) +{ + printf("Hello, I am thread 3. I'm spinning.\n"); + + while (1) { + } + return 0; +} + +void test_sched(void) +{ + pthread_t tid; + pthread_create(&tid, NULL, thread_routine1, NULL); + usys_yield(); + for (int i = 0; i < 3; ++i) { + printf("Hello from thread 1\n"); + usys_yield(); + } + pthread_join(tid, NULL); + + printf("Thread 1 creates a spinning thread!\n"); + pthread_create(&tid, NULL, thread_routine2, NULL); + usys_yield(); + printf("Thread 1 successfully regains the control!\n"); + printf("Preemptive Schedluing Test Done!\n"); +} + int main(int argc, char *argv[], char *envp[]) { cap_t cap; @@ -694,6 +748,7 @@ int main(int argc, char *argv[], char *envp[]) init_root_proc_node(); + test_sched(); boot_default_servers(); /* Configure system servers, and boot some of them. */ diff --git a/Pages/Getting-started.md b/Pages/Getting-started.md index d935bfd2..c7011be6 100644 --- a/Pages/Getting-started.md +++ b/Pages/Getting-started.md @@ -8,7 +8,16 @@ 请按照Docker官方指示为你运行的操作系统安装对应的Docker发行版。 > [!IMPORTANT] 关于Docker -> 由于中国大陆地区的网络限制,请确保你的docker能够连接到docker-hub,测试方法可以使用 `docker pull nginx:latest`,如果无法访问,您可以依照[该文档](https://docs.docker.com/engine/daemon/)为你的docker daemon添加代理规则。 +> 由于中国大陆地区的网络限制,请确保你的docker能够连接到docker-hub,测试方法可以使用 `docker pull nginx:latest`,如果无法访问,您可以依照[该文档](https://docs.docker.com/engine/daemon/)为你的docker daemon添加代理规则。 +> 如果你缺少代理,你可以使用这个[链接(提取uwuv)](https://pan.baidu.com/s/1ipbMZ-C1Qk0S9PGDDMMy6w)下载压缩好的Docker镜像,镜像使用`zstd`进行压缩。你可以使用以下的命令解压后,再使用`docker`进行导入。 +> +> ``` +> zstd -d docker.ipads.oslab.yy.mm.tar.zstd +> docker load -i docker.ipads.oslab.yy.mm.tar +> ``` + +> [!IMPORTANT] 关于虚拟机 +> 如果你使用的是Windows/MacOS系统,如果不想手动安装docker以及下载镜像,我们也准备了基于VMWare 17的虚拟机镜像,你可以在这个[链接(提取uwuv)](https://pan.baidu.com/s/1ipbMZ-C1Qk0S9PGDDMMy6w)找到,你可以在解压之后导入vmware即可使用。用户stu 密码为123456 ### 使用Dev-Container (推荐) diff --git a/Scripts/chbuild b/Scripts/chbuild index 6949a8bd..4f9d859a 100755 --- a/Scripts/chbuild +++ b/Scripts/chbuild @@ -279,7 +279,7 @@ _docker_run() { -u $(id -u ${USER}):$(id -g ${USER}) \ -v ${LABROOT}:${LABROOT} -w $(pwd) \ --security-opt=seccomp:unconfined \ - ipads/chcore_builder:v1.9.0 \ + ipads/oslab:24.09 \ $self $@ fi }