Skip to contentSkip to conversation

rcu: Only boost rcu reader tasks with lower priority than boost kthreads

PATCH Superseded Zqiang 4 participants 8 messages Mar 4, 2022 – Mar 9, 2022 RCU

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zqiang

author
#0 lore raw

PATCH 1/1 rcu: Only boost rcu reader tasks with lower priority than boost kthreads

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

---
 kernel/rcu/tree_plugin.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +9 -1
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
  */
 
 #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
 static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
 {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
 	 * section.
 	 */
 	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+
 	rt_mutex_init_proxy_locked(&rnp->boost_mtx.rtmutex, t);
 	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
 	/* Lock only for side effect: boosts task t's priority. */
 	rt_mutex_lock(&rnp->boost_mtx);
 	rt_mutex_unlock(&rnp->boost_mtx);  /* Then keep lockdep happy. */
 	rnp->n_boosts++;
-
+end:
 	return READ_ONCE(rnp->exp_tasks) != NULL ||
 	       READ_ONCE(rnp->boost_tasks) != NULL;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 33 lines · Zqiang

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +6 -0
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;

kernel/rcu/tree_plugin.h static int rcu_boost(struct rcu_node *rnp) · line 1082

Quoted 10 lines
kernel/rcu/tree_plugin.h +3 -1
+	}
+
  	rt_mutex_init_proxy_locked(&rnp->boost_mtx.rtmutex, t);
  	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  	/* Lock only for side effect: boosts task t's priority. */
  	rt_mutex_lock(&rnp->boost_mtx);
  	rt_mutex_unlock(&rnp->boost_mtx);  /* Then keep lockdep happy. */
  	rnp->n_boosts++;
-
+end:

Nit: maybe rename the label to "skip_boost:" ?

Code looks fine; however, out of curiosity; given that the higher priority tasks, in general, would exit their read side critical section
quickly and boost the next blocking reader on exiting their read side section; do you see noticeable reduction in grace period timings with the change for certain type of workloads?

Thanks
Neeraj

Quoted 3 lines
kernel/rcu/tree_plugin.h +0 -0
  	return READ_ONCE(rnp->exp_tasks) != NULL ||
  	       READ_ONCE(rnp->boost_tasks) != NULL;
  }
#2 lore raw
Quoted 44 lines · Zqiang

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +9 -1
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+
  	rt_mutex_init_proxy_locked(&rnp->boost_mtx.rtmutex, t);
  	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  	/* Lock only for side effect: boosts task t's priority. */
  	rt_mutex_lock(&rnp->boost_mtx);
  	rt_mutex_unlock(&rnp->boost_mtx);  /* Then keep lockdep happy. */
  	rnp->n_boosts++;
-
+end:
Quoted 1 line
Quoted 7 lines
Quoted 7 lines

Nit: maybe rename the label to "skip_boost:" ?

Code looks fine; however, out of curiosity; given that the higher priority tasks, in general, would exit their read side critical section quickly and boost the next blocking reader on exiting their read side section; do you see noticeable reduction in grace period timings with the change for certain type of workloads?

Thanks for feedback , In preempt-RT systems, there will be many real-time threads (most
of them are created by users themselves ), their priority is higher or lower than boost kthreads (kthread_prio is set), for rt tasks with higher priority than boost kthreads, maybe it will exit read side critical quickly, maybe not, if it is preempted by a higher priority task, If try to boost operation, this increases the boosts kthread waiting time, as a result, the next blkd tasks cannot be boosted in time. of course, I don't deny it, there are also reasons that user priority setting is inappropriate.

Thanks
Zqiang

Quoted 8 lines
Quoted 4 lines

Thanks
Neeraj

  	return READ_ONCE(rnp->exp_tasks) != NULL ||
  	       READ_ONCE(rnp->boost_tasks) != NULL;
  }
maintainer
#3 lore raw
Quoted 9 lines · On Mon, Mar 07, 2022 at 02:03:17AM +0000, Zhang, Qiang1 wrote:
Quoted 8 lines · Zqiang

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

Adding to CC to get more eyes on this. I am not necessarily opposed to it, but I don't do that much RT work myself these days.

Thanx, Paul

Quoted 62 lines
Quoted 36 lines
---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +9 -1
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+
  	rt_mutex_init_proxy_locked(&rnp->boost_mtx.rtmutex, t);
  	raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  	/* Lock only for side effect: boosts task t's priority. */
  	rt_mutex_lock(&rnp->boost_mtx);
  	rt_mutex_unlock(&rnp->boost_mtx);  /* Then keep lockdep happy. */
  	rnp->n_boosts++;
-
+end:
Quoted 1 line
Quoted 7 lines
Quoted 7 lines

Nit: maybe rename the label to "skip_boost:" ?

Code looks fine; however, out of curiosity; given that the higher priority tasks, in general, would exit their read side critical section quickly and boost the next blocking reader on exiting their read side section; do you see noticeable reduction in grace period timings with the change for certain type of workloads?

Thanks for feedback , In preempt-RT systems, there will be many real-time threads (most
of them are created by users themselves ), their priority is higher or lower than boost kthreads (kthread_prio is set), for rt tasks with higher priority than boost kthreads, maybe it will exit read side critical quickly, maybe not, if it is preempted by a higher priority task, If try to boost operation, this increases the boosts kthread waiting time, as a result, the next blkd tasks cannot be boosted in time. of course, I don't deny it, there are also reasons that user priority setting is inappropriate.

Thanks
Zqiang

Quoted 8 lines
Quoted 4 lines

Thanks
Neeraj

  	return READ_ONCE(rnp->exp_tasks) != NULL ||
  	       READ_ONCE(rnp->boost_tasks) != NULL;
  }
maintainer
#4 lore raw
Quoted 30 lines · On Mon, Mar 07, 2022 at 02:03:17AM +0000, Zhang, Qiang1 wrote:
Quoted 9 lines · Zqiang
Quoted 8 lines

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

Adding to CC to get more eyes on this. I am not necessarily opposed to it, but I don't do that much RT work myself these days.

Thanx, Paul

Quoted 14 lines
Quoted 14 lines
---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +1 -0
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
kernel/rcu/tree_plugin.h +0 -0
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
Quoted 8 lines

kernel/rcu/tree_plugin.h static int rcu_boost(struct rcu_node *rnp) · line 1075

Quoted 8 lines
kernel/rcu/tree_plugin.h +7 -0
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+

Why do you bypass the expedited grace period and boost any tasks anyway? Same way the expedited gp can be blocked by higher prior tasks SCHED_DEADLINE or SCHED_FIFO.

Thanks!

--
Vlad Rezki

maintainer
#5 lore raw
Quoted 30 lines · Uladzislau Rezki
Quoted 30 lines · On Mon, Mar 07, 2022 at 02:03:17AM +0000, Zhang, Qiang1 wrote:
Quoted 9 lines · Zqiang
Quoted 8 lines

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

Adding to CC to get more eyes on this. I am not necessarily opposed to it, but I don't do that much RT work myself these days.

Thanx, Paul

Quoted 14 lines
Quoted 14 lines
---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +1 -0
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
kernel/rcu/tree_plugin.h +0 -0
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
Quoted 8 lines
Quoted 8 lines

kernel/rcu/tree_plugin.h static int rcu_boost(struct rcu_node *rnp) · line 1075

Quoted 8 lines
kernel/rcu/tree_plugin.h +7 -0
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+

Why do you bypass the expedited grace period and boost any tasks anyway? Same way the expedited gp can be blocked by higher prior tasks SCHED_DEADLINE or SCHED_FIFO.

Just to make sure that I understand...

Are you pointing out that a SCHED_DEADLINE task might have exhausted its budget, so that boosting might nonetheless be helpful?

Me, I honestly don't know what happens in that case, so I am just asking the question. And adding Juri on CC. ;-)

Thanx, Paul

maintainer
#6 lore raw
Quoted 48 lines · Paul E. McKenney
Quoted 30 lines · Uladzislau Rezki
Quoted 30 lines · On Mon, Mar 07, 2022 at 02:03:17AM +0000, Zhang, Qiang1 wrote:
Quoted 9 lines · Zqiang
Quoted 8 lines

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

Adding to CC to get more eyes on this. I am not necessarily opposed to it, but I don't do that much RT work myself these days.

Thanx, Paul

Quoted 14 lines
Quoted 14 lines
---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +1 -0
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
kernel/rcu/tree_plugin.h +0 -0
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
Quoted 8 lines
Quoted 8 lines

kernel/rcu/tree_plugin.h static int rcu_boost(struct rcu_node *rnp) · line 1075

Quoted 8 lines
kernel/rcu/tree_plugin.h +7 -0
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+

Why do you bypass the expedited grace period and boost any tasks anyway? Same way the expedited gp can be blocked by higher prior tasks SCHED_DEADLINE or SCHED_FIFO.

Quoted 5 lines

Just to make sure that I understand...

Are you pointing out that a SCHED_DEADLINE task might have exhausted its budget, so that boosting might nonetheless be helpful?

SCHED_DEADLINE we can not preempt nor stop it somehow(highest prio class), it has some budget it makes use of. If it is in critical section then it will leave asap, i do not take into account here IRQs and so on. I do not see a reason to boost it.

Quoted 4 lines

Me, I honestly don't know what happens in that case, so I am just asking the question. And adding Juri on CC. ;-)

Juri should know more :)

--
Vlad Rezki

#7 lore raw
In reply to Uladzislau Rezki
Quoted 10 lines · On Mon, Mar 07, 2022 at 02:03:17AM +0000, Zhang, Qiang1 wrote:
Quoted 8 lines · Zqiang
Quoted 7 lines

When RCU_BOOST is enabled, the boost kthreads will boosting readers who are blocking a given grace period, if the current reader tasks have a higher priority than boost kthreads(the boost kthreads priority not always 1, if the kthread_prio is set), boosting is useless, skip current task and select next task to boosting, reduce the time for a given grace period.

Quoted 36 lines
Quoted 1 line
Quoted 1 line

Adding to CC to get more eyes on this. I am not necessarily opposed to it, but I don't do that much RT work myself these days.

Thanx, Paul

Quoted 29 lines
Quoted 29 lines
---
  kernel/rcu/tree_plugin.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
kernel/rcu/tree_plugin.h +8 -0
index c3d212bc5338..d35b6da66bbd 100644
@@ -12,6 +12,7 @@
   */
 
  #include "../locking/rtmutex_common.h"
+#include <linux/sched/deadline.h>
 
  static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
  {
@@ -1065,13 +1066,20 @@ static int rcu_boost(struct rcu_node *rnp)
  	 * section.
  	 */
  	t = container_of(tb, struct task_struct, rcu_node_entry);
+	if (!rnp->exp_tasks && (dl_task(t) || t->prio <= current->prio)) {
+		tb = rcu_next_node_entry(t, rnp);
+		WRITE_ONCE(rnp->boost_tasks, tb);
+		raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
+		goto end;
+	}
+
Quoted 2 lines

Why do you bypass the expedited grace period and boost any tasks anyway?
Same way the expedited gp can be blocked by higher prior tasks SCHED_DEADLINE or SCHED_FIFO.

Thanks advice, it really ignores expedited grace period, may be
should generate 'boost_exp_tasks' pointer to point 'rnp->exp_tasks', do the same thing as normal grace period.

Thanks
Zqiang

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Thanks!

--
Vlad Rezki