Skip to content

Commit

Permalink
Merge pull request #47 from ToolmanP/main
Browse files Browse the repository at this point in the history
release: v24.09.1
  • Loading branch information
ToolmanP authored Oct 26, 2024
2 parents c339f0d + 289c3ba commit 8a01152
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: GitHub Pages
on:
push:
tags-ignore:
- '**'
paths:
- "Pages/**"
- "README.md"
- "CHANGELOG.md"
workflow_dispatch:

concurrency:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lab1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
paths:
- Lab1/**
tags-ignore:
- '**'
workflow_dispatch:
workflow_call:

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lab2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
paths:
- Lab2/**
tags-ignore:
- '**'
workflow_dispatch:
workflow_call:

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lab3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
paths:
- Lab3/**
tags-ignore:
- '**'
workflow_dispatch:
workflow_call:

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lab4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
paths:
- Lab4/**
tags-ignore:
- '**'
workflow_dispatch:
workflow_call:

permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lab5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
paths:
- Lab5/**
tags-ignore:
- '**'
workflow_dispatch:
workflow_call:

permissions:
contents: read
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release

on:
push:
tags:
- "*"

jobs:
lab1_check:
uses: ./.github/workflows/lab1.yml
lab2_check:
uses: ./.github/workflows/lab2.yml
lab3_check:
uses: ./.github/workflows/lab3.yml
lab4_check:
uses: ./.github/workflows/lab4.yml
lab5_check:
uses: ./.github/workflows/lab5.yml
create_release:
runs-on: ubuntu-latest
needs: [lab1_check, lab2_check, lab3_check, lab4_check, lab5_check]
steps:
- name: Checkout repository with submodules
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Download git-archive-all.sh script
run: |
curl -o git-archive-all.sh https://raw.githubusercontent.com/fabacab/git-archive-all.sh/master/git-archive-all.sh
chmod +x git-archive-all.sh
- name: Create archive with submodules
run: |
./git-archive-all.sh --prefix "${GITHUB_REPOSITORY##*/}/" --format tar.gz release.tar.gz
- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body_path: ./CHANGELOG.md

- name: Upload archive to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release.tar.gz
asset_name: "${{ github.event.repository.name }}-${{ github.ref_name }}.tar.gz"
asset_content_type: application/gzip
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# CHANGELOG
# v24.09 更新内容

- 集中化统一的目录统一
- 完成Lab1-Lab5的迁移设置
- 更新基于vscode的lab的开发环境
- 更新lsp设置
- 修复多个构建以及运行时问题
- 迁移文档至mdbook
4 changes: 2 additions & 2 deletions Lab3/scores.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"proposed": 20
},
{
"capture": "Hello userland!",
"capture": "Hello Userland!",
"msg": "Userland",
"proposed": 20,
"userland": true
Expand All @@ -22,7 +22,7 @@
"userland": true
},
{
"capture": "Hello ChCore",
"capture": "Hello ChCore!",
"msg": "Userland App",
"proposed": 20,
"userland": true
Expand Down
Binary file removed Lab4/kernel/ipc/connection.c.dbg.obj
Binary file not shown.
Binary file removed Lab4/kernel/ipc/connection.c.obj
Binary file not shown.
8 changes: 4 additions & 4 deletions Lab4/scores.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"capture": "Cooperative Scheduling Test Done!",
"msg": "Cooperative Scheduling",
"proposed": 20,
"userland": true
"userland": true
},
{
"capture": "Preemptive Scheduling Test Done!",
"msg": "Preemptive Scheduling",
"proposed": 20,
"userland": true
"msg": "Preemptive Scheduling",
"proposed": 20,
"userland": true
},
{
"capture": "Test IPC finished!",
Expand Down
4 changes: 2 additions & 2 deletions Lab4/user/system-services/system-servers/procmgr/procmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void *thread_routine1(void *arg)
printf("Hello from thread 2\n");
usys_yield();
}
printf("Cooperative Schedluing Test Done!\n");
printf("Cooperative Scheduling Test Done!\n");
return NULL;
}

Expand Down Expand Up @@ -729,7 +729,7 @@ void test_sched(void)
pthread_create(&tid, NULL, thread_routine2, NULL);
usys_yield();
printf("Thread 1 successfully regains the control!\n");
printf("Preemptive Schedluing Test Done!\n");
printf("Preemptive Scheduling Test Done!\n");
}

int main(int argc, char *argv[], char *envp[])
Expand Down
2 changes: 1 addition & 1 deletion Lab6/chbuild
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ _docker_run() {
docker run -i $use_tty --rm \
-u $(id -u ${USER}):$(id -g ${USER}) \
-v $(pwd):$(pwd) -w $(pwd) \
ipads/chcore_builder:v1.9.0 \
ipads/oslab:24.09 \
$self $@
fi
}
Expand Down
5 changes: 4 additions & 1 deletion Pages/Lab3/thread.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ ChCore 中仅使用了其中的两个异常级别:EL0 和 EL1。其中,EL1
> [!CODING] 练习题1
> `kernel/object/cap_group.c` 中完善 `sys_create_cap_group``create_root_cap_group` 函数。在完成填写之后,你可以通过 Cap create pretest 测试点。
> [!SUCCESS] CapGroup
> 完成`create_root_cap_group`函数后并通过测试后,你可以得到20分。
> [!HINT]
> 可以阅读 `kernel/object/capability.c` 中各个与 cap 机制相关的函数以及参考文档。
Expand Down Expand Up @@ -55,4 +58,4 @@ ChCore 中仅使用了其中的两个异常级别:EL0 和 EL1。其中,EL1
---

> [!SUCCESS]
> 以上为Lab3 Part1 的所有内容,完成后你将获得20分
> 以上为Lab3 Part1 的所有内容,完成后你将获得40分
16 changes: 8 additions & 8 deletions Pages/Lab4/IPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ ChCore的IPC接口不是传统的send/recv接口。其更像客户端/服务器
## 具体流程
为了实现ChCore IPC的功能,首先需要在Client与Server端创建起一个一对一的IPC Connection。该Connection保存了IPC Server的服务线程(即上图中IPC handler Thread)、Client与Server的共享内存(用于存放IPC通信的内容)。同一时刻,一个Connection只能有一个Client接入,并使用该Connection切换到Server的处理流程。ChCore提供了一系列机制,用于创建Connection以及创建每个Connection对应的服务线程。下面将以具体的IPC注册到调用的流程,详细介绍ChCore的IPC机制:

1. IPC服务器的主线程调用: `ipc_register_server` (user/chcore-libc/musl-libc/src/chcore-port/ipc.c中)来声明自己为IPC的服务器端。
1. IPC服务器的主线程调用: `ipc_register_server` (`user/chcore-libc/musl-libc/src/chcore-port/ipc.c`)来声明自己为IPC的服务器端。

* 参数包括server_handler和client_register_handler,其中server_handler为服务端用于提供服务的回调函数(比如上图中IPC handler Thread的入口函数`ipc_dispatcher`);client_register_handler为服务端提供的用于注册的回调函数,该函数会创建一个注册回调线程。

* 随后调用ChCore提供的的系统调用:`sys_register_server`该系统调用实现在kernel/ipc/connection.c当中,该系统调用会分配并初始化一个`struct ipc_server_config`和一个`struct ipc_server_register_cb_config`。之后将调用者线程(即主线程)的general_ipc_config字段设置为创建的`struct ipc_server_config`,其中记录了注册回调线程和IPC服务线程的入口函数(即图中的`ipc_dispatcher`)。将注册回调线程的general_ipc_config字段设置为创建的`struct ipc_server_register_cb_config`,其中记录了注册回调线程的入口函数和用户态栈地址等信息。
* 随后调用ChCore提供的的系统调用:`sys_register_server`该系统调用实现在`kernel/ipc/connection.c`当中,该系统调用会分配并初始化一个`struct ipc_server_config`和一个`struct ipc_server_register_cb_config`。之后将调用者线程(即主线程)的general_ipc_config字段设置为创建的`struct ipc_server_config`,其中记录了注册回调线程和IPC服务线程的入口函数(即图中的`ipc_dispatcher`)。将注册回调线程的general_ipc_config字段设置为创建的`struct ipc_server_register_cb_config`,其中记录了注册回调线程的入口函数和用户态栈地址等信息。

2. IPC客户端线程调用`ipc_register_client`定义在user/chcore-libc/musl-libc/src/chcore-port/ipc.c中)来申请建立IPC连接。
2. IPC客户端线程调用`ipc_register_client`定义在`user/chcore-libc/musl-libc/src/chcore-port/ipc.c`)来申请建立IPC连接。

* 该函数仅有一个参数,即IPC服务器的主线程在客户端进程cap_group中的capability。该函数会首先通过系统调用申请一块物理内存作为和服务器的共享内存(即图中的Shared Memory)。

* 随后调用`sys_register_client`系统调用。该系统调用实现在kernel/ipc/connection.c当中,该系统调用会将刚才申请的物理内存映射到客户端的虚拟地址空间中,然后调用`create_connection`创建并初始化一个`struct ipc_connection`类型的内核对象,该内核对象中的shm字段会记录共享内存相关的信息(包括大小,分别在客户端进程和服务器进程当中的虚拟地址和capability)。
* 随后调用`sys_register_client`系统调用。该系统调用实现在`kernel/ipc/connection.c`当中,该系统调用会将刚才申请的物理内存映射到客户端的虚拟地址空间中,然后调用`create_connection`创建并初始化一个`struct ipc_connection`类型的内核对象,该内核对象中的shm字段会记录共享内存相关的信息(包括大小,分别在客户端进程和服务器进程当中的虚拟地址和capability)。

* 之后会设置注册回调线程的栈地址、入口地址和第一个参数,并切换到注册回调线程运行。
3. 注册回调线程运行的入口函数为主线程调用`ipc_register_server`是提供的client_register_handler参数,一般会使用默认的`DEFAULT_CLIENT_REGISTER_HANDLER`宏定义的入口函数,即定义在user/chcore-libc/musl-libc/src/chcore-port/ipc.c中的`register_cb`
3. 注册回调线程运行的入口函数为主线程调用`ipc_register_server`是提供的client_register_handler参数,一般会使用默认的`DEFAULT_CLIENT_REGISTER_HANDLER`宏定义的入口函数,即定义在`user/chcore-libc/musl-libc/src/chcore-port/ipc.c`中的`register_cb`

* 该函数首先分配一个用来映射共享内存的虚拟地址,随后创建一个服务线程。

* 随后调用`sys_ipc_register_cb_return`系统调用进入内核,该系统调用将共享内存映射到刚才分配的虚拟地址上,补全`struct ipc_connection`内核对象中的一些元数据之后切换回客户端线程继续运行,客户端线程从`ipc_register_client`返回,完成IPC建立连接的过程。

4. IPC客户端线程调用`ipc_create_msg``ipc_set_msg_data`向IPC共享内存中填充数据,然后调用`ipc_call`(user/chcore-libc/musl-libc/src/chcore-port/ipc.c中)发起IPC请求。
4. IPC客户端线程调用`ipc_create_msg``ipc_set_msg_data`向IPC共享内存中填充数据,然后调用`ipc_call``user/chcore-libc/musl-libc/src/chcore-port/ipc.c`)发起IPC请求。

* `ipc_call`中会发起`sys_ipc_call`系统调用(定义在kernel/ipc/connection.c中),该系统调用将设置服务器端的服务线程的栈地址、入口地址、各个参数,然后迁移到该服务器端服务线程继续运行。由于当前的客户端线程需要等待服务器端的服务线程处理完毕,因此需要更新其状态为TS_WAITING,且不要加入等待队列。
* `ipc_call`中会发起`sys_ipc_call`系统调用(定义在`kernel/ipc/connection.c`),该系统调用将设置服务器端的服务线程的栈地址、入口地址、各个参数,然后迁移到该服务器端服务线程继续运行。由于当前的客户端线程需要等待服务器端的服务线程处理完毕,因此需要更新其状态为TS_WAITING,且不要加入等待队列。

5. IPC服务器端的服务线程在处理完IPC请求之后使用`ipc_return`返回。
* `ipc_return`会发起`sys_ipc_return`系统调用,该系统调用会迁移回到IPC客户端线程继续运行,IPC客户端线程从`ipc_call`中返回。

> [!CODING] 练习题 7
> 在user/chcore-libc/musl-libc/src/chcore-port/ipc.c与kernel/ipc/connection.c中实现了大多数IPC相关的代码,请根据注释补全kernel/ipc/connection.c中的代码。之后运行ChCore可以看到 “[TEST] Test IPC finished!” 输出,你可以通过 Test IPC 测试点。
> `user/chcore-libc/musl-libc/src/chcore-port/ipc.c与kernel/ipc/connection.c`中实现了大多数IPC相关的代码,请根据注释补全`kernel/ipc/connection.c`中的代码。之后运行ChCore可以看到 “[TEST] Test IPC finished!” 输出,你可以通过 Test IPC 测试点。
---

Expand Down
Loading

0 comments on commit 8a01152

Please sign in to comment.