Skip to contentSkip to conversation

rcu: Change use of __this_cpu ops on a bool type

RFC PATCH In review Pranith Kumar 2 participants 3 messages Sep 19, 2014 RCU

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 rcu: Change use of __this_cpu ops on a bool type

__this_cpu_{read/write}() uses sizeof() to determine the size of the variable. Using this operation on a bool type causes sparse to complain.

I checked the generated code and there is only a slight difference in instructions generated.

I am not sure this warning by sparse is really valid, but let us silence it anyways.

---
 kernel/rcu/tree.c        | 12 ++++++++----
 kernel/rcu/tree_plugin.h |  6 ++++--
 2 files changed, 12 insertions(+), 6 deletions(-)
kernel/rcu/tree.c +8 -4
index bc085e5..85f228a 100644
@@ -186,21 +186,25 @@ static int rcu_gp_in_progress(struct rcu_state *rsp)
  */
 void rcu_sched_qs(void)
 {
-	if (!__this_cpu_read(rcu_sched_data.passed_quiesce)) {
+	struct rcu_data *rdp = __this_cpu_ptr(&rcu_sched_data);
+
+	if (!rdp->passed_quiesce) {
 		trace_rcu_grace_period(TPS("rcu_sched"),
 				       __this_cpu_read(rcu_sched_data.gpnum),
 				       TPS("cpuqs"));
-		__this_cpu_write(rcu_sched_data.passed_quiesce, 1);
+		rdp->passed_quiesce = true;
 	}
 }
 
 void rcu_bh_qs(void)
 {
-	if (!__this_cpu_read(rcu_bh_data.passed_quiesce)) {
+	struct rcu_data *rdp = __this_cpu_ptr(&rcu_bh_data);
+
+	if (!rdp->passed_quiesce) {
 		trace_rcu_grace_period(TPS("rcu_bh"),
 				       __this_cpu_read(rcu_bh_data.gpnum),
 				       TPS("cpuqs"));
-		__this_cpu_write(rcu_bh_data.passed_quiesce, 1);
+		rdp->passed_quiesce = true;
 	}
 }
 
kernel/rcu/tree_plugin.h +4 -2
index 77f9376..98de303 100644
@@ -143,11 +143,13 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed);
  */
 static void rcu_preempt_qs(void)
 {
-	if (!__this_cpu_read(rcu_preempt_data.passed_quiesce)) {
+	struct rcu_data *rdp = __this_cpu_ptr(&rcu_preempt_data);
+
+	if (!rdp->passed_quiesce) {
 		trace_rcu_grace_period(TPS("rcu_preempt"),
 				       __this_cpu_read(rcu_preempt_data.gpnum),
 				       TPS("cpuqs"));
-		__this_cpu_write(rcu_preempt_data.passed_quiesce, 1);
+		rdp->passed_quiesce = true;
 		barrier(); /* Coordinate with rcu_preempt_check_callbacks(). */
 		current->rcu_read_unlock_special.b.need_qs = false;
 	}
Signature · 1 line
2.1.0
maintainer
#1 lore raw
Quoted 10 lines · Pranith Kumar

__this_cpu_{read/write}() uses sizeof() to determine the size of the variable. Using this operation on a bool type causes sparse to complain.

I checked the generated code and there is only a slight difference in instructions generated.

I am not sure this warning by sparse is really valid, but let us silence it anyways.

I believe this warning was actually fixed with current versions of Sparse; there was some discussion and a patch on the linux-sparse mailing list. Can you please recheck with the latest Sparse from git, and if it still breaks, please raise that on linux-sparse?

Quoted 61 lines
 kernel/rcu/tree.c        | 12 ++++++++----
 kernel/rcu/tree_plugin.h |  6 ++++--
 2 files changed, 12 insertions(+), 6 deletions(-)
kernel/rcu/tree.c +8 -4
index bc085e5..85f228a 100644
@@ -186,21 +186,25 @@ static int rcu_gp_in_progress(struct rcu_state *rsp)
  */
 void rcu_sched_qs(void)
 {
-	if (!__this_cpu_read(rcu_sched_data.passed_quiesce)) {
+	struct rcu_data *rdp = __this_cpu_ptr(&rcu_sched_data);
+
+	if (!rdp->passed_quiesce) {
 		trace_rcu_grace_period(TPS("rcu_sched"),
 				       __this_cpu_read(rcu_sched_data.gpnum),
 				       TPS("cpuqs"));
-		__this_cpu_write(rcu_sched_data.passed_quiesce, 1);
+		rdp->passed_quiesce = true;
 	}
 }
 
 void rcu_bh_qs(void)
 {
-	if (!__this_cpu_read(rcu_bh_data.passed_quiesce)) {
+	struct rcu_data *rdp = __this_cpu_ptr(&rcu_bh_data);
+
+	if (!rdp->passed_quiesce) {
 		trace_rcu_grace_period(TPS("rcu_bh"),
 				       __this_cpu_read(rcu_bh_data.gpnum),
 				       TPS("cpuqs"));
-		__this_cpu_write(rcu_bh_data.passed_quiesce, 1);
+		rdp->passed_quiesce = true;
 	}
 }
 
kernel/rcu/tree_plugin.h +4 -2
index 77f9376..98de303 100644
@@ -143,11 +143,13 @@ EXPORT_SYMBOL_GPL(rcu_batches_completed);
  */
 static void rcu_preempt_qs(void)
 {
-	if (!__this_cpu_read(rcu_preempt_data.passed_quiesce)) {
+	struct rcu_data *rdp = __this_cpu_ptr(&rcu_preempt_data);
+
+	if (!rdp->passed_quiesce) {
 		trace_rcu_grace_period(TPS("rcu_preempt"),
 				       __this_cpu_read(rcu_preempt_data.gpnum),
 				       TPS("cpuqs"));
-		__this_cpu_write(rcu_preempt_data.passed_quiesce, 1);
+		rdp->passed_quiesce = true;
 		barrier(); /* Coordinate with rcu_preempt_check_callbacks(). */
 		current->rcu_read_unlock_special.b.need_qs = false;
 	}
Signature · 1 line
2.1.0
#2 lore raw
Quoted 10 lines · Josh Triplett
Quoted 9 lines · Pranith Kumar

__this_cpu_{read/write}() uses sizeof() to determine the size of the variable. Using this operation on a bool type causes sparse to complain.

I checked the generated code and there is only a slight difference in instructions generated.

I am not sure this warning by sparse is really valid, but let us silence it anyways.

Quoted 7 lines
Quoted 1 line

I believe this warning was actually fixed with current versions of Sparse; there was some discussion and a patch on the linux-sparse mailing list. Can you please recheck with the latest Sparse from git, and if it still breaks, please raise that on linux-sparse?

Yup, looks like the latest version of sparse fixes this. Please ignore this patch. Thanks!

Signature · 1 line
Pranith