-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fs_inode:Change the type of i_crefs to atomic_int #13443
base: master
Are you sure you want to change the base?
Conversation
2eb25f6
to
2f854a4
Compare
Please check that all i_crefs are replaced correctly, eg: |
2f854a4
to
24170b6
Compare
24170b6
to
ca181c6
Compare
Ditto, please make sure to go through the code carefully |
acadd16
to
e5535a7
Compare
Done
Done |
75fbe24
to
b291fb2
Compare
c720470
to
4911fee
Compare
I found that some platforms have the following warning when using different compilers
In the current strategy, if the compiler itself does not support Atomic, Nuttx Base Atomic (low-performance version) will be used. So can we ignore it? |
4911fee
to
236d671
Compare
Summary: 1.Modified the i_crefs from int16_t to atomic_int 2.Modified the i_crefs add, delete, read, and initialize interfaces to atomic operations The purpose of this change is to avoid deadlock in cross-core scenarios, where A Core blocks B Core’s request for a write operation to A Core when A Core requests a read operation to B Core. Signed-off-by: chenrun1 <[email protected]>
236d671
to
3b6c346
Compare
Error: vfs/fs_epoll.c:126:3: error: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Werror,-Wdeprecated-pragma] ATOMIC_VAR_INIT(1), /* i_crefs */ ^ /Applications/Xcode_15.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/stdatomic.h:54:41: note: macro marked 'deprecated' here ^ 1 error generated. make[1]: *** [fs_epoll.o] Error 1 Error: socket/socket.c:78:3: error: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Werror,-Wdeprecated-pragma] ATOMIC_VAR_INIT(1), /* i_crefs */ Signed-off-by: chenrun1 <[email protected]>
…upport it Summary: Configuration/Tool: zp214xpa/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI 2024-09-14 06:11:00 ------------------------------------------------------------------------------------ Cleaning... Configuring... Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI Building NuttX... arm-none-eabi-ld: /github/workspace/sources/nuttx/staging/libfs.a(fs_inoderemove.o): in function `inode_remove': fs_inoderemove.c:(.text.inode_remove+0x94): undefined reference to `__sync_synchronize' arm-none-eabi-ld: fs_inoderemove.c:(.text.inode_remove+0x9c): undefined reference to `__sync_synchronize' make[1]: *** [Makefile:212: nuttx] Error 1 make: *** [tools/Unix.mk:548: nuttx] Error 2 make: Target 'all' not remade because of errors. Signed-off-by: chenrun1 <[email protected]>
e90852e
to
6b05d09
Compare
607130d
to
cf85911
Compare
d501da2
to
22ae464
Compare
When the toolchain does not support atomic, it will use the version implemented by NuttX (low performance version). This scenario is consistent with the original design, so we can ignore it. see bug here: https://bugs.llvm.org/show_bug.cgi?id=43603 Error: inode/fs_inodeaddref.c:50:7: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Werror,-Watomic-alignment] 50 | atomic_fetch_add(&inode->i_crefs, 1); | ^ /tools/clang-arm-none-eabi/lib/clang/17/include/stdatomic.h:152:43: note: expanded from macro 'atomic_fetch_add' 152 | #define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST) | ^ 1 error generated. make[1]: *** [Makefile:83: fs_inodeaddref.o] Error 1 Error: inode/fs_inodefind.c:74:7: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Werror,-Watomic-alignment] 74 | atomic_fetch_add(&node->i_crefs, 1); Signed-off-by: chenrun1 <[email protected]>
22ae464
to
bfc7828
Compare
@@ -90,6 +90,12 @@ extern "C++" | |||
# include <nuttx/lib/stdatomic.h> | |||
#endif | |||
|
|||
#if !(__clang__) |
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.
revert
@@ -123,7 +123,7 @@ static struct inode g_timerfd_inode = | |||
NULL, /* i_parent */ | |||
NULL, /* i_peer */ | |||
NULL, /* i_child */ | |||
ATOMIC_VAR_INIT(1), /* i_crefs */ | |||
ATOMIC_INIT(1), /* i_crefs */ |
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.
remove ATOMIC_VAR_INIT/ATOMIC_INIT
@@ -410,7 +411,7 @@ struct inode | |||
FAR struct inode *i_parent; /* Link to parent level inode */ | |||
FAR struct inode *i_peer; /* Link to same level inode */ | |||
FAR struct inode *i_child; /* Link to lower level inode */ | |||
int16_t i_crefs; /* References to inode */ | |||
atomic_int i_crefs; /* References to inode */ |
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.
atomic_short
@@ -185,21 +185,15 @@ static int shmfs_release(FAR struct inode *inode) | |||
* The inode is released after this call, hence checking if i_crefs <= 1. | |||
*/ | |||
|
|||
int ret = inode_lock(); | |||
if (ret >= 0) | |||
inode_lock(); |
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.
remove node_lock
int ret = inode_lock(); | ||
|
||
if (ret >= 0) | ||
inode_lock(); |
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.
remove inode_lock
@@ -353,26 +353,23 @@ static int pseudofile_munmap(FAR struct task_group_s *group, | |||
* The inode is released after this call, hence checking if i_crefs <= 1. | |||
*/ | |||
|
|||
int ret = inode_lock(); | |||
if (ret >= 0) | |||
inode_lock(); |
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.
remove too
Summary
Benefit from PR#13044, we can change the the inode->i_crefs to atomic. That we can avoid problems:
Deadlocks caused by the server requesting reads from the client and the client requesting writes from the server when operating a file system with multiple cores (e.g. RPMSGFS).
The main changes are as follows:
1.Modified the i_crefs from int16_t to atomic_int
2.Modified the i_crefs add, delete, read, and initialize interfaces to atomic operations
The main change of this PR is to change the i_crefs count of inode to atomic type and use atomic operations to maintain i_crefs.
Impact
Impact on user: NO, This is a change within VFS and should be transparent to external developers.
Impact on build: YES, This may affect compilation because the members of the inode structure have changed. Different compilers/platforms have different support for atomic, so some warnings are skipped.
Impact on compatibility: This implementation aims to be backward compatible. No existing functionality is expected to be broken.
Testing
Build Host(s): Linux x86
Target(s): sim/nsh
Basic operations on the file system can work normally