基于RISC-V原子指令重构并发模块 (Concurrency Module Refactoring Using RISC-V Atomic Instructions) #163
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 实现。
