基于RISC-V原子指令重构并发模块 (Concurrency Module Refactoring Using RISC-V Atomic Instructions)#163
Open
FlandreLiao wants to merge 14 commits intorcore-os:ch8from
Open
基于RISC-V原子指令重构并发模块 (Concurrency Module Refactoring Using RISC-V Atomic Instructions)#163FlandreLiao wants to merge 14 commits intorcore-os:ch8from
FlandreLiao wants to merge 14 commits intorcore-os:ch8from
Conversation
- 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
Store in , not .
- Return val & (1 << bit)
- Move semaphore module from kernel to user lib - Delete semaphore syscalls
Now Semaphore is like to Zemaphore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
原来的并发模块严重依赖内核态的中断屏蔽机制,导致同步原语相关的系统调用多达数十个,不仅使内核与用户程序的 接口臃肿冗余,还大大增加了同步原语的性能开销。另外,同步原语的数据结构 只定义在于内核中,不对用户程序开放,使得用户程序只能使用语义不明的 ID 作为同步原语的句柄。

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