Skip to content

基于RISC-V原子指令重构并发模块 (Concurrency Module Refactoring Using RISC-V Atomic Instructions) #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: ch8
Choose a base branch
from

Conversation

FlandreLiao
Copy link

问题描述

原来的并发模块严重依赖内核态的中断屏蔽机制,导致同步原语相关的系统调用多达数十个,不仅使内核与用户程序的 接口臃肿冗余,还大大增加了同步原语的性能开销。另外,同步原语的数据结构 只定义在于内核中,不对用户程序开放,使得用户程序只能使用语义不明的 ID 作为同步原语的句柄。
原来的并发模块结构图 drawio

新的并发模块概述

用户态(或者说 user_lib 中)实现了 MutexSpin, Futex, Condvar, Semaphore 四种同步原语,内核态只实现了 MutexSpin

与原来的并发模块相比,新的并发模块的系统调用数量从 10 个削减到仅剩 1 个精简了内核接口。自旋锁基于原子指令实现,相比于中断屏蔽大大提高了性能;Futex 在用户态的检查操作同样基于原子指令,仅在必要时通过 sys_futex 进入内核态;Condvar 和 Futex 复用了 sys_futex;Semaphore 基于 MutexSpin 和 Condvar 实现。
新的并发模块结构图 drawio

- Refactor mutex module architecture
- Add new MutexSpin and Futex implementations using atomic instructions
- Introduce Futex support with following additions:
  * Atomic operations: increment/decrement/bit_test_set/add_and_compare
  * System Call: sys_futex
  * PCB member: futex_queues
  * MemorySet method: translation_va

Todo: test the correctness of new Mutex
- Copy MutexSpin to user lib
- Cut Futex from os/sync/mutex.rs to user lib
- delete some mutex syscalls

Todo: test the correctness of new Mutex
Todo: reconstruct Condvar
…ser crate

- Delete syscalls of Condvar
- Add new Condvar based on sys_futex to user lib

Todo: Examine correctness of Mutex and Condvar
- Return val & (1 << bit)
- Move semaphore module from kernel to user lib
- Delete semaphore syscalls
@FlandreLiao FlandreLiao changed the title 基于RISC-V原子指令重构并发模块 基于RISC-V原子指令重构并发模块 (Concurrency Module Refactoring Using RISC-V Atomic Instructions) Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant