Skip to content

Commit

Permalink
Merge pull request #41 from ToolmanP/main
Browse files Browse the repository at this point in the history
feat: update lab4 and container links
  • Loading branch information
ToolmanP authored Oct 12, 2024
2 parents fa237c1 + 6bb20b9 commit e0bd241
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 94 deletions.
67 changes: 1 addition & 66 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Binary file modified Lab4/kernel/arch/aarch64/main.c.dbg.obj
Binary file not shown.
Binary file modified Lab4/kernel/arch/aarch64/main.c.obj
Binary file not shown.
3 changes: 1 addition & 2 deletions Lab4/kernel/arch/aarch64/plat/raspi3/irq/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Binary file modified Lab4/kernel/object/thread.c.dbg.obj
Binary file not shown.
Binary file modified Lab4/kernel/object/thread.c.obj
Binary file not shown.
2 changes: 1 addition & 1 deletion Lab4/kernel/sched/policy_rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ int rr_sched_init(void)

/* LAB 4 TODO END (exercise 1) */

test_scheduler_meta();
lab4_test_scheduler_meta();
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Lab4/kernel/tests/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../)
Binary file removed Lab4/kernel/tests/runtime/lab4.c.obj
Binary file not shown.
Binary file added Lab4/kernel/tests/runtime/tests.c.dbg.obj
Binary file not shown.
Binary file added Lab4/kernel/tests/runtime/tests.c.obj
Binary file not shown.
27 changes: 5 additions & 22 deletions Lab4/kernel/tests/runtime/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
35 changes: 35 additions & 0 deletions Lab4/scores.json
Original file line number Diff line number Diff line change
@@ -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
}
]
55 changes: 55 additions & 0 deletions Lab4/user/system-services/system-servers/procmgr/procmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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. */
Expand Down
11 changes: 10 additions & 1 deletion Pages/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (推荐)
Expand Down
2 changes: 1 addition & 1 deletion Scripts/chbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e0bd241

Please sign in to comment.