-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
add atomic support. #6197
add atomic support. #6197
Conversation
赞! RISC-V计划啥时候上线? 关联 #1339 |
risc-v 好像有工具链内联函数哎 |
/* | ||
* atomic interfaces | ||
*/ | ||
void rt_atomic_add(rt_atomic_t *ptr, rt_atomic_t val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放这边吗?如果是这边,API前缀应该是rt_hw_
PR title是否也需要调整的,stomic or atomic? |
@GuEe-GUI 麻烦关注其中的aarch64实现情况; @Guozhanxin 对于ARM32来说,需要分别来多做验证,包括:arm7,arm cortex-m0/m3/../m7(后面几个估计都有对应的,前面的可能反而是麻烦的),arm cortex-a的情况。 |
建议增加以下接口: 使用频率较高的接口 rt_atomic_t rt_atomic_read(rt_atomic_t *ptr);
void rt_atomic_inc(rt_atomic_t *ptr);
void rt_atomic_dec(rt_atomic_t *ptr); 可能调用方想要知道独占的情况: rt_atomic_t rt_atomic_add_return(rt_atomic_t *ptr, rt_atomic_t val);
rt_atomic_t rt_atomic_sub_return(rt_atomic_t *ptr, rt_atomic_t val);
rt_atomic_t rt_atomic_inc_return(rt_atomic_t *ptr);
rt_atomic_t rt_atomic_dec_return(rt_atomic_t *ptr); |
rt_atomic_read 不应该本身就是原子的吗? |
读内存数据至少需要两条指令。 |
为什么会需要两条指令呢?地址不对齐? |
1.将目的地址加载入寄存器。 |
可是第一步“将目的地址加载入寄存器”,寄存器属于私有化的数据吧,不存在原子操作的说法吧。也不会有人再操作这个寄存器。 |
主要是屏障方面的问题,请参考:https://www.kernel.org/doc/html/v4.12/core-api/atomic_ops.html |
return result; | ||
} | ||
|
||
void rt_atomic_add(rt_atomic_t *ptr, rt_atomic_t val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
似乎不是这样支持的,针对add操作,似乎是这样:
libcpu等相关的,可以提供rt_hw_atomic_add
接口;
src/atomic.c可以提供rt_atomic_add
接口;
同时,针对没有机器级指令来确保atomic操作的,需要由函数实现的方式确保对应操作是原子话操作的,例如rt_atomic_add
操作,它由可能在一些或某些代码中被直接使用,而不会考虑底层硬件平台是否支持atomic操作。
v5.0建议重点推进这份 PR |
这里是一份无锁的rb,如果支持了atomic操作,也可以尝试下: |
最近在项目中有使用 |
坚决支持,尤其是基于无锁操作衍生的例如上面提到的无锁ringbuffer等上层基础无锁设施 |
参见 #6931 |
拉取/合并请求描述:(PR description)
[
添加 原子操作
性能测试
如何融合到内核中,提升内核性能?
]
以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up