Skip to contentSkip to conversation

sched/core: Avoid _cond_resched() for PREEMPT=y

tip:sched/core Mikulas Patocka 3 participants 6 messages Sep 22, 2016 – Sep 23, 2016 1 message not in the archive

lore
Share & tools
lore

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

#1 lore raw

I've found a document that says that cond_resched() is needed on preemptible kernels to mark RCU quiescent states:

https://lwn.net/Articles/603252/

Paul, is cond_resched() still needed on current RCU implementation? Or not?

Mikulas

Quoted 62 lines · tip-bot for Peter Zijlstra
Commit-ID:  35a773a07926a22bf19d77ee00024522279c4e68
Gitweb:     http://git.kernel.org/tip/35a773a07926a22bf19d77ee00024522279c4e68
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Mon, 19 Sep 2016 12:57:53 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 22 Sep 2016 14:53:46 +0200

sched/core: Avoid _cond_resched() for PREEMPT=y

On fully preemptible kernels _cond_resched() is pointless, so avoid emitting any code for it.

Cc Linus Torvalds <[email protected]>
Cc Mikulas Patocka <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/sched.h | 4 ++++
 kernel/sched/core.c   | 2 ++
 2 files changed, 6 insertions(+)
include/linux/sched.h +4 -0
index f00ee8e..b99fcd1 100644
@@ -3209,7 +3209,11 @@ static inline int signal_pending_state(long state, struct task_struct *p)
  * cond_resched_lock() will drop the spinlock before scheduling,
  * cond_resched_softirq() will enable bhs before scheduling.
  */
+#ifndef CONFIG_PREEMPT
 extern int _cond_resched(void);
+#else
+static inline int _cond_resched(void) { return 0; }
+#endif
 
 #define cond_resched() ({			\
 	___might_sleep(__FILE__, __LINE__, 0);	\
kernel/sched/core.c +2 -0
index b2ec53c..d7babcc 100644
@@ -4883,6 +4883,7 @@ SYSCALL_DEFINE0(sched_yield)
 	return 0;
 }
 
+#ifndef CONFIG_PREEMPT
 int __sched _cond_resched(void)
 {
 	if (should_resched(0)) {
@@ -4892,6 +4893,7 @@ int __sched _cond_resched(void)
 	return 0;
 }
 EXPORT_SYMBOL(_cond_resched);
+#endif
 
 /*
  * __cond_resched_lock() - if a reschedule is pending, drop the given lock,
#2 lore raw
Quoted 6 lines · Mikulas Patocka

I've found a document that says that cond_resched() is needed on preemptible kernels to mark RCU quiescent states:

https://lwn.net/Articles/603252/

Paul, is cond_resched() still needed on current RCU implementation? Or not?

It can be if you loop in the kernel for a very long time.

But cond_resched_rcu_qs() is instead needed in cases where there is only one runnable non-idle non-nohz task on a given CPU.

Thanx, Paul

Quoted 69 lines

Mikulas

Quoted 62 lines · tip-bot for Peter Zijlstra
Commit-ID:  35a773a07926a22bf19d77ee00024522279c4e68
Gitweb:     http://git.kernel.org/tip/35a773a07926a22bf19d77ee00024522279c4e68
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Mon, 19 Sep 2016 12:57:53 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 22 Sep 2016 14:53:46 +0200

sched/core: Avoid _cond_resched() for PREEMPT=y

On fully preemptible kernels _cond_resched() is pointless, so avoid emitting any code for it.

Cc Linus Torvalds <[email protected]>
Cc Mikulas Patocka <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 include/linux/sched.h | 4 ++++
 kernel/sched/core.c   | 2 ++
 2 files changed, 6 insertions(+)
include/linux/sched.h +4 -0
index f00ee8e..b99fcd1 100644
@@ -3209,7 +3209,11 @@ static inline int signal_pending_state(long state, struct task_struct *p)
  * cond_resched_lock() will drop the spinlock before scheduling,
  * cond_resched_softirq() will enable bhs before scheduling.
  */
+#ifndef CONFIG_PREEMPT
 extern int _cond_resched(void);
+#else
+static inline int _cond_resched(void) { return 0; }
+#endif
 
 #define cond_resched() ({			\
 	___might_sleep(__FILE__, __LINE__, 0);	\
kernel/sched/core.c +2 -0
index b2ec53c..d7babcc 100644
@@ -4883,6 +4883,7 @@ SYSCALL_DEFINE0(sched_yield)
 	return 0;
 }
 
+#ifndef CONFIG_PREEMPT
 int __sched _cond_resched(void)
 {
 	if (should_resched(0)) {
@@ -4892,6 +4893,7 @@ int __sched _cond_resched(void)
 	return 0;
 }
 EXPORT_SYMBOL(_cond_resched);
+#endif
 
 /*
  * __cond_resched_lock() - if a reschedule is pending, drop the given lock,
#3 lore raw
In reply to Mikulas Patocka
Quoted 6 lines · Mikulas Patocka

I've found a document that says that cond_resched() is needed on preemptible kernels to mark RCU quiescent states:

https://lwn.net/Articles/603252/

Paul, is cond_resched() still needed on current RCU implementation? Or not?

No, we ripped that out. See 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU")

#4 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Mikulas Patocka

I've found a document that says that cond_resched() is needed on preemptible kernels to mark RCU quiescent states:

https://lwn.net/Articles/603252/

Paul, is cond_resched() still needed on current RCU implementation? Or not?

No, we ripped that out. See 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU")

I would instead say that we changed the algorithm to reduce the overhead in the common case, but yes, this commit did change things quite a bit.

Thanx, Paul

#5 lore raw
Quoted 7 lines · Paul E. McKenney
Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Mikulas Patocka

I've found a document that says that cond_resched() is needed on preemptible kernels to mark RCU quiescent states:

https://lwn.net/Articles/603252/

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Paul, is cond_resched() still needed on current RCU implementation? Or not?

No, we ripped that out. See 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU")

I would instead say that we changed the algorithm to reduce the overhead in the common case, but yes, this commit did change things quite a bit.

Sure, but critical point (for this discussion) is that cond_resched() no longer implies anything RCU, it really only is a voluntary reschedule point.

#6 lore raw
Quoted 13 lines · Peter Zijlstra
Quoted 12 lines · Paul E. McKenney
Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Mikulas Patocka

I've found a document that says that cond_resched() is needed on preemptible kernels to mark RCU quiescent states:

https://lwn.net/Articles/603252/

Paul, is cond_resched() still needed on current RCU implementation? Or not?

No, we ripped that out. See 4a81e8328d37 ("rcu: Reduce overhead of cond_resched() checks for RCU")

Quoted 6 lines
Quoted 2 lines

I would instead say that we changed the algorithm to reduce the overhead in the common case, but yes, this commit did change things quite a bit.

Sure, but critical point (for this discussion) is that cond_resched() no longer implies anything RCU, it really only is a voluntary reschedule point.

Agreed, cond_resched_rcu_qs() is what you use to do both a cond_resched() and an RCU quiescent state.

Thanx, Paul