Skip to contentSkip to conversation

rcu: Use per_cpu_ptr to get the pointer of per_cpu variable

PATCH Uladzislau Rezki 4 participants 8 messages Jun 30, 2021 – Jul 1, 2021 1 message not in the archive RCU

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Uladzislau Rezki

author maintainer Reviewed-by
#1 lore raw
Quoted 63 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

---
 kernel/rcu/tasks.h      | 2 +-
 kernel/rcu/tree.c       | 4 ++--
 kernel/rcu/tree_stall.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
kernel/rcu/tasks.h +1 -1
index 350ebf5051f9..0275217cb6e4 100644
@@ -875,7 +875,7 @@ static void trc_read_check_handler(void *t_in)
 	// Allow future IPIs to be sent on CPU and for task.
 	// Also order this IPI handler against any later manipulations of
 	// the intended task.
-	smp_store_release(&per_cpu(trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
+	smp_store_release(per_cpu_ptr(&trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
 	smp_store_release(&texp->trc_ipi_to_cpu, -1); // ^^^
 }
 
kernel/rcu/tree.c +2 -2
index 8e78b2430c16..5cab8e39a731 100644
@@ -399,7 +399,7 @@ bool rcu_eqs_special_set(int cpu)
 	int old;
 	int new;
 	int new_old;
-	struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
 
 	new_old = atomic_read(&rdp->dynticks);
 	do {
@@ -1333,7 +1333,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
 	 */
 	jtsq = READ_ONCE(jiffies_to_sched_qs);
 	ruqp = per_cpu_ptr(&rcu_data.rcu_urgent_qs, rdp->cpu);
-	rnhqp = &per_cpu(rcu_data.rcu_need_heavy_qs, rdp->cpu);
+	rnhqp = per_cpu_ptr(&rcu_data.rcu_need_heavy_qs, rdp->cpu);
 	if (!READ_ONCE(*rnhqp) &&
 	    (time_after(jiffies, rcu_state.gp_start + jtsq * 2) ||
 	     time_after(jiffies, rcu_state.jiffies_resched) ||
kernel/rcu/tree_stall.h +1 -1
index 59b95cc5cbdf..990fdb793d57 100644
@@ -349,7 +349,7 @@ static void rcu_dump_cpu_stacks(void)
 
 static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
 {
-	struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
 
 	sprintf(cp, "last_accelerate: %04lx/%04lx dyntick_enabled: %d",
 		rdp->last_accelerate & 0xffff, jiffies & 0xffff,
Signature · 1 line
2.20.1

To me it looks OK.

--
Vlad Rezki

Reviewed-by
#2 lore raw
In reply to a message not in the archive
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 25 lines
---
  kernel/rcu/tasks.h      | 2 +-
  kernel/rcu/tree.c       | 4 ++--
  kernel/rcu/tree_stall.h | 2 +-
  3 files changed, 4 insertions(+), 4 deletions(-)
kernel/rcu/tasks.h +1 -1
index 350ebf5051f9..0275217cb6e4 100644
@@ -875,7 +875,7 @@ static void trc_read_check_handler(void *t_in)
  	// Allow future IPIs to be sent on CPU and for task.
  	// Also order this IPI handler against any later manipulations of
  	// the intended task.
-	smp_store_release(&per_cpu(trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
+	smp_store_release(per_cpu_ptr(&trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
  	smp_store_release(&texp->trc_ipi_to_cpu, -1); // ^^^
  }
 
kernel/rcu/tree.c +0 -0
index 8e78b2430c16..5cab8e39a731 100644

kernel/rcu/tree.c bool rcu_eqs_special_set(int cpu) · line 402

Quoted 5 lines
kernel/rcu/tree.c +1 -1
@@ -399,7 +399,7 @@ bool rcu_eqs_special_set(int cpu)
  	int old;
  	int new;
  	int new_old;
-	struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);

rcu_eqs_special_set() does not exist in rcu dev branch [1]; so this might need rebase.

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git/tree/kernel/rcu/tree.c?h=dev

Quoted 18 lines
kernel/rcu/tree.c +1 -1
  	new_old = atomic_read(&rdp->dynticks);
  	do {
@@ -1333,7 +1333,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
  	 */
  	jtsq = READ_ONCE(jiffies_to_sched_qs);
  	ruqp = per_cpu_ptr(&rcu_data.rcu_urgent_qs, rdp->cpu);
-	rnhqp = &per_cpu(rcu_data.rcu_need_heavy_qs, rdp->cpu);
+	rnhqp = per_cpu_ptr(&rcu_data.rcu_need_heavy_qs, rdp->cpu);
  	if (!READ_ONCE(*rnhqp) &&
  	    (time_after(jiffies, rcu_state.gp_start + jtsq * 2) ||
  	     time_after(jiffies, rcu_state.jiffies_resched) ||
kernel/rcu/tree_stall.h +0 -0
index 59b95cc5cbdf..990fdb793d57 100644

kernel/rcu/tree_stall.h static void rcu_dump_cpu_stacks(void) · line 355

Quoted 8 lines
kernel/rcu/tree_stall.h +1 -1
@@ -349,7 +349,7 @@ static void rcu_dump_cpu_stacks(void)
 
  static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
  {
-	struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
 
  	sprintf(cp, "last_accelerate: %04lx/%04lx dyntick_enabled: %d",
  		rdp->last_accelerate & 0xffff, jiffies & 0xffff,

Thanks
Neeraj

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
maintainer Reviewed-by Uladzislau Rezki (Sony) Reviewed-by Neeraj Upadhyay
#3 lore raw
Quoted 13 lines · Neeraj Upadhyay
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 1 line

Applied with the usual wordsmithing, including adding words to this effect, so thank you all! I removed the obsolete chunk that Neeraj pointed out as well.

Please take a look and check to see if all is well.

Thanx, Paul

------------------------------------------------------------------------

commit 9a6b5a10785f4d9b4f073736e6648fa3851882bd

Author: Liu Song <[email protected]>
Date:   Wed Jun 30 22:08:02 2021 +0800

rcu: Use per_cpu_ptr to get the pointer of per_cpu variable

There are a few remaining locations in kernel/rcu that still use "&per_cpu()". This commit replaces them with "per_cpu_ptr(&)", and does not introduce any functional change..

kernel/rcu/tasks.h +1 -1
index f9f52daacd1c..806160c44b17 100644
@@ -923,7 +923,7 @@ static void trc_read_check_handler(void *t_in)
 	// Allow future IPIs to be sent on CPU and for task.
 	// Also order this IPI handler against any later manipulations of
 	// the intended task.
-	smp_store_release(&per_cpu(trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
+	smp_store_release(per_cpu_ptr(&trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
 	smp_store_release(&texp->trc_ipi_to_cpu, -1); // ^^^
 }
 
kernel/rcu/tree.c +1 -1
index a627a200a5ae..f42b98af3ed3 100644
@@ -1290,7 +1290,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
 	 */
 	jtsq = READ_ONCE(jiffies_to_sched_qs);
 	ruqp = per_cpu_ptr(&rcu_data.rcu_urgent_qs, rdp->cpu);
-	rnhqp = &per_cpu(rcu_data.rcu_need_heavy_qs, rdp->cpu);
+	rnhqp = per_cpu_ptr(&rcu_data.rcu_need_heavy_qs, rdp->cpu);
 	if (!READ_ONCE(*rnhqp) &&
 	    (time_after(jiffies, rcu_state.gp_start + jtsq * 2) ||
 	     time_after(jiffies, rcu_state.jiffies_resched) ||
kernel/rcu/tree_stall.h +1 -1
index a8d0fcf0826f..677ee3d8671b 100644
@@ -351,7 +351,7 @@ static void rcu_dump_cpu_stacks(void)
 
 static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
 {
-	struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
 
 	sprintf(cp, "last_accelerate: %04lx/%04lx dyntick_enabled: %d",
 		rdp->last_accelerate & 0xffff, jiffies & 0xffff,
#4 lore raw
Quoted 13 lines · Paul E. McKenney
Quoted 12 lines · Neeraj Upadhyay
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Applied with the usual wordsmithing, including adding words to this effect, so thank you all! I removed the obsolete chunk that Neeraj pointed out as well.

Please take a look and check to see if all is well.

Looks good to me

Thanks
Neeraj

Quoted 59 lines

Thanx, Paul

------------------------------------------------------------------------

commit 9a6b5a10785f4d9b4f073736e6648fa3851882bd

Author: Liu Song <[email protected]>
Date:   Wed Jun 30 22:08:02 2021 +0800

rcu: Use per_cpu_ptr to get the pointer of per_cpu variable

There are a few remaining locations in kernel/rcu that still use "&per_cpu()". This commit replaces them with "per_cpu_ptr(&)", and does not introduce any functional change..

kernel/rcu/tasks.h +1 -1
index f9f52daacd1c..806160c44b17 100644
@@ -923,7 +923,7 @@ static void trc_read_check_handler(void *t_in)
  	// Allow future IPIs to be sent on CPU and for task.
  	// Also order this IPI handler against any later manipulations of
  	// the intended task.
-	smp_store_release(&per_cpu(trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
+	smp_store_release(per_cpu_ptr(&trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
  	smp_store_release(&texp->trc_ipi_to_cpu, -1); // ^^^
  }
 
kernel/rcu/tree.c +1 -1
index a627a200a5ae..f42b98af3ed3 100644
@@ -1290,7 +1290,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
  	 */
  	jtsq = READ_ONCE(jiffies_to_sched_qs);
  	ruqp = per_cpu_ptr(&rcu_data.rcu_urgent_qs, rdp->cpu);
-	rnhqp = &per_cpu(rcu_data.rcu_need_heavy_qs, rdp->cpu);
+	rnhqp = per_cpu_ptr(&rcu_data.rcu_need_heavy_qs, rdp->cpu);
  	if (!READ_ONCE(*rnhqp) &&
  	    (time_after(jiffies, rcu_state.gp_start + jtsq * 2) ||
  	     time_after(jiffies, rcu_state.jiffies_resched) ||
kernel/rcu/tree_stall.h +1 -1
index a8d0fcf0826f..677ee3d8671b 100644
@@ -351,7 +351,7 @@ static void rcu_dump_cpu_stacks(void)
 
  static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
  {
-	struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
 
  	sprintf(cp, "last_accelerate: %04lx/%04lx dyntick_enabled: %d",
  		rdp->last_accelerate & 0xffff, jiffies & 0xffff,
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
author maintainer
#5 lore raw
Quoted 18 lines · Neeraj Upadhyay
Quoted 15 lines · Paul E. McKenney
Quoted 13 lines · Neeraj Upadhyay
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 1 line
Quoted 9 lines
Quoted 6 lines

Applied with the usual wordsmithing, including adding words to this effect, so thank you all! I removed the obsolete chunk that Neeraj pointed out as well.

Please take a look and check to see if all is well.

Looks good to me

Same to me. Looks good.

There are two dots though in the commit message: "change.." :)

--
Vlad Rezki

maintainer
#6 lore raw
Quoted 23 lines · Uladzislau Rezki
Quoted 22 lines · Neeraj Upadhyay
Quoted 19 lines · Paul E. McKenney
Quoted 13 lines · Neeraj Upadhyay
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 1 line

Applied with the usual wordsmithing, including adding words to this effect, so thank you all! I removed the obsolete chunk that Neeraj pointed out as well.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Please take a look and check to see if all is well.

Looks good to me

Same to me. Looks good.

There are two dots though in the commit message: "change.." :)

Good eyes, fixed, thank you!

Thanx, Paul

Reviewed-by
#7 lore raw
Quoted 28 lines · Paul E. McKenney
Quoted 26 lines · Uladzislau Rezki
Quoted 25 lines · Neeraj Upadhyay
Quoted 21 lines · Paul E. McKenney
Quoted 13 lines · Neeraj Upadhyay
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 1 line

Applied with the usual wordsmithing, including adding words to this effect, so thank you all! I removed the obsolete chunk that Neeraj pointed out as well.

Please take a look and check to see if all is well.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Looks good to me

Same to me. Looks good.

There are two dots though in the commit message: "change.." :)

Good eyes, fixed, thank you!

LGTM as well, thanks!

maintainer
#8 lore raw
Quoted 31 lines · Joel Fernandes
Quoted 30 lines · Paul E. McKenney
Quoted 28 lines · Uladzislau Rezki
Quoted 27 lines · Neeraj Upadhyay
Quoted 13 lines · Paul E. McKenney
Quoted 12 lines · Neeraj Upadhyay
Quoted 5 lines · Liu Song

From: Liu Song <[email protected]>

In rcu, most codes have used per_cpu_ptr to obtain per_cpu variable pointers. This patch adjusts a few codes that have not done so.

Minor: Can we also add below statement?
"This patch doesn't introduce any functional change."

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Applied with the usual wordsmithing, including adding words to this effect, so thank you all! I removed the obsolete chunk that Neeraj pointed out as well.

Please take a look and check to see if all is well.

Looks good to me

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Same to me. Looks good.

There are two dots though in the commit message: "change.." :)

Good eyes, fixed, thank you!

LGTM as well, thanks!

And one more. ;-)

Again, thank you all!

Thanx, Paul