Skip to contentSkip to conversation

rcu,alpha: avoid smp_read_barrier_depends in rcu_dereference when pointer==NULL

RFC PATCH In review Lai Jiangshan 3 participants 3 messages Jun 21, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 rcu,alpha: avoid smp_read_barrier_depends in rcu_dereference when pointer==NULL

Hi, Paul and Alpha hackers

memory barrier is expensive, I think it's worth that adding an if-statement to avoid it when pointer == NULL.

This patch change nothing in UP or in other architectures for compiler's optimization.

Thanks, Lai Jiangshan

---

include/linux/rcupdate.h +2 -1
index d42dbec..8979f29 100644
@@ -143,7 +143,8 @@ struct rcu_head {
 
 #define rcu_dereference(p)     ({ \
 				typeof(p) _________p1 = ACCESS_ONCE(p); \
-				smp_read_barrier_depends(); \
+				if (_________p1) \
+					smp_read_barrier_depends(); \
 				(_________p1); \
 				})
 
#1 lore raw
Quoted 7 lines · Lai Jiangshan

Hi, Paul and Alpha hackers

memory barrier is expensive, I think it's worth that adding an if-statement to avoid it when pointer == NULL.

This patch change nothing in UP or in other architectures for compiler's optimization.

I suspect this optimization is invalid in the case where the loaded value is used as an offset (either pointer or array index). But I'm afraid I'll have to defer to Paul for explanations..

Quoted 27 lines

Thanks, Lai Jiangshan

---

include/linux/rcupdate.h +2 -2
index d42dbec..8979f29 100644
@@ -143,7 +143,8 @@ struct rcu_head {
 
 #define rcu_dereference(p)     ({ \
 				typeof(p) _________p1 = ACCESS_ONCE(p); \
-				smp_read_barrier_depends(); \
+				if (_________p1) \
+					smp_read_barrier_depends(); \
 				(_________p1); \
 				})
 
 
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#2 lore raw
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Lai Jiangshan

Hi, Paul and Alpha hackers

memory barrier is expensive, I think it's worth that adding an if-statement to avoid it when pointer == NULL.

Quoted 6 lines
Quoted 2 lines

This patch change nothing in UP or in other architectures for compiler's optimization.

I suspect this optimization is invalid in the case where the loaded value is used as an offset (either pointer or array index). But I'm afraid I'll have to defer to Paul for explanations..

What Peter said!

There are cases where the argument to rcu_dereference() is an array index rather than a pointer. In that case, zero is a perfectly valid array index and requires a memory barrier on Alpha. Given that the smp_read_barrier_depends() primitive is very nearly (but not quite) a no-op on non-Alpha machines, it will also be necessary to carefully check the generated code to make sure that we are not slowing down the common non-Alpha machines to help out the very rare Alpha machines.

Some months ago, we attempted to add a similar check to rcu_assign_pointer(), but we were unable to find an approach that handled all the cases currently in the Linux kernel, even when we introduced a special-case primitive for array indexes. Please note that we did not prove it impossible, but rather decided that it was consuming more time and energy than was warranted.

Thanx, Paul

PS. I have not forgotten about your earlier patch to the list structures
used by classic RCU -- but I am still curious to know the results of the more-harsh testing that I suggested.

Quoted 28 lines
Quoted 27 lines

Thanks, Lai Jiangshan

---

include/linux/rcupdate.h +2 -2
index d42dbec..8979f29 100644
@@ -143,7 +143,8 @@ struct rcu_head {
 
 #define rcu_dereference(p)     ({ \
 				typeof(p) _________p1 = ACCESS_ONCE(p); \
-				smp_read_barrier_depends(); \
+				if (_________p1) \
+					smp_read_barrier_depends(); \
 				(_________p1); \
 				})
 
 
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/