关于RCU-protected array indexes的探究
在师兄的驱动代码中看到了几个和rcu index相关的代码在编译的时候报错,原因是现在的linux内核已经废除使用RCU-protected array indexes了。现在建议,用smp_load_acquire对rcu_dereference_index_check进行替换
参加文章内容:
Abolition of RCU-protected array indexes
The RCU API has long permitted RCU-protected array indexes, but it turned out that these were used only in one place in x86-specific code. Because x86 has relatively strong total store order (TSO) memory ordering, rcu_dereference_index_check()
may be replaced with smp_load_acquire()
on x86 with little or no performance penalty. In other words, in the only place using rcu_access_index()
and rcu_dereference_index_check()
, they were not helping much.
In addition, both rcu_dereference()
(and friends) and rcu_dereference_index_check()
rely on the compiler to preserve dependencies from those two invocations to any later dereferencing of the returned pointer. Neither the C nor the C++ standard make any sort of dependency-preservation guarantee, and compilers much more aggressively optimize integer expressions than pointer expressions, which means that dependencies carried by integers are more likely to be broken than those carried by pointers. The rules for preventing the compiler from breaking dependencies carried by pointers are complex enough, and so it seemed best to remove integers from the mix.