Skip to contentSkip to conversation

sched/wait: Collapse __wait_event macros -v5

PATCH In review Peter Zijlstra 5 participants 56 messages Oct 2, 2013 – Oct 11, 2013

Subsystems (9)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

cover sched/wait: Collapse __wait_event macros -v5

While poking at the cpu hotplug implementation I had a desire to use wait_event() with schedule_preempt_disabled() and found the ridiculous amount of duplication in linux/wait.h.

These patches cure all the bloat and inconsistencies of these macros that me and others noticed, while also making it 'trivial' to generate new variants.

Compile and boot tested on x86_64.

Changes since -v4:
- split up the big collapse patch into 11 separate patches

Changes since -v3:
- added LKML to the CC (D'0h!!)
- introduced ___wait_cond_timeout() to avoid double evaluation of 'condition'

Changes since -v2:
- removed ___wait_cmd_lock_irq(), ___wait_cmd_lock_irq_timo()
- renamed ___wait_cmd_test_timeout() to ___wait_test_timeout()
- renamed ___wait_cmd_schedule_timeout() to ___wait_sched_timeout()
- fixed schedule_timeout() invocations in patch 6; don't restart a schedule_timeout() at the total timeout; rather continue where we left off for a total fixed timeout.
- use 'long' return type for ___wait_event() so that timeout values for schedule_timeout() fit.
- fix wait_event_interruptible_lock_irq_timeout() and use long return type.

---
 arch/mips/kernel/rtlx.c         |   19 +-
 include/linux/tty.h             |   28 +---
 include/linux/wait.h            |  268 +++++++++++++---------------------------
 net/irda/af_irda.c              |    5 
 net/netfilter/ipvs/ip_vs_sync.c |    7 -
 5 files changed, 108 insertions(+), 219 deletions(-)
author maintainer
#1 lore raw

PATCH 1/16 sched/wait: Make the signal_pending() checks consistent

There's two patterns to check signals in the __wait_event*() macros:

  if (!signal_pending(current)) {
	schedule();
	continue;

}
ret = -ERESTARTSYS;
break;

And the more natural:

  if (signal_pending(current)) {
	ret = -ERESTARTSYS;
	break;

}
schedule();

Change them all into the latter form.

---
 include/linux/tty.h  |   13 ++++++-------
 include/linux/wait.h |   35 ++++++++++++++++-------------------
 2 files changed, 22 insertions(+), 26 deletions(-)
include/linux/tty.h +6 -7
@@ -686,14 +686,13 @@ do {									\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
 		if (condition)						\
 			break;						\
-		if (!signal_pending(current)) {				\
-			tty_unlock(tty);					\
-			schedule();					\
-			tty_lock(tty);					\
-			continue;					\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			break;						\
 		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
+		tty_unlock(tty);					\
+		schedule();						\
+		tty_lock(tty);						\
 	}								\
 	finish_wait(&wq, &__wait);					\
 } while (0)
include/linux/wait.h +16 -19
@@ -261,12 +261,11 @@ do {									\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
 		if (condition)						\
 			break;						\
-		if (!signal_pending(current)) {				\
-			schedule();					\
-			continue;					\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			break;						\
 		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
+		schedule();						\
 	}								\
 	finish_wait(&wq, &__wait);					\
 } while (0)
@@ -302,14 +301,13 @@ do {									\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
 		if (condition)						\
 			break;						\
-		if (!signal_pending(current)) {				\
-			ret = schedule_timeout(ret);			\
-			if (!ret)					\
-				break;					\
-			continue;					\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			break;						\
 		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
+		ret = schedule_timeout(ret);				\
+		if (!ret)						\
+			break;						\
 	}								\
 	if (!ret && (condition))					\
 		ret = 1;						\
@@ -439,14 +437,13 @@ do {									\
 			finish_wait(&wq, &__wait);			\
 			break;						\
 		}							\
-		if (!signal_pending(current)) {				\
-			schedule();					\
-			continue;					\
-		}							\
-		ret = -ERESTARTSYS;					\
-		abort_exclusive_wait(&wq, &__wait, 			\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			abort_exclusive_wait(&wq, &__wait, 		\
 				TASK_INTERRUPTIBLE, NULL);		\
-		break;							\
+			break;						\
+		}							\
+		schedule();						\
 	}								\
 } while (0)
 
#2 lore raw

[tip:sched/core] sched/wait: Make the signal_pending() checks consistent

sched/wait: Make the signal_pending() checks consistent
Commit-ID:  2f2a2b60adf368bacd6acd2116c01e32caf936c4
Gitweb:     http://git.kernel.org/tip/2f2a2b60adf368bacd6acd2116c01e32caf936c4
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:18 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:44 +0200

sched/wait: Make the signal_pending() checks consistent

There's two patterns to check signals in the __wait_event*() macros:

  if (!signal_pending(current)) {
	schedule();
	continue;

}
ret = -ERESTARTSYS;
break;

And the more natural:

  if (signal_pending(current)) {
	ret = -ERESTARTSYS;
	break;

}
schedule();

Change them all into the latter form.

---
 include/linux/tty.h  | 13 ++++++-------
 include/linux/wait.h | 35 ++++++++++++++++-------------------
 2 files changed, 22 insertions(+), 26 deletions(-)
include/linux/tty.h +6 -7
index 64f8646..0503729 100644
@@ -686,14 +686,13 @@ do {									\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
 		if (condition)						\
 			break;						\
-		if (!signal_pending(current)) {				\
-			tty_unlock(tty);					\
-			schedule();					\
-			tty_lock(tty);					\
-			continue;					\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			break;						\
 		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
+		tty_unlock(tty);					\
+		schedule();						\
+		tty_lock(tty);						\
 	}								\
 	finish_wait(&wq, &__wait);					\
 } while (0)
include/linux/wait.h +16 -19
index a67fc16..ccf0c52 100644
@@ -261,12 +261,11 @@ do {									\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
 		if (condition)						\
 			break;						\
-		if (!signal_pending(current)) {				\
-			schedule();					\
-			continue;					\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			break;						\
 		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
+		schedule();						\
 	}								\
 	finish_wait(&wq, &__wait);					\
 } while (0)
@@ -302,14 +301,13 @@ do {									\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
 		if (condition)						\
 			break;						\
-		if (!signal_pending(current)) {				\
-			ret = schedule_timeout(ret);			\
-			if (!ret)					\
-				break;					\
-			continue;					\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			break;						\
 		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
+		ret = schedule_timeout(ret);				\
+		if (!ret)						\
+			break;						\
 	}								\
 	if (!ret && (condition))					\
 		ret = 1;						\
@@ -439,14 +437,13 @@ do {									\
 			finish_wait(&wq, &__wait);			\
 			break;						\
 		}							\
-		if (!signal_pending(current)) {				\
-			schedule();					\
-			continue;					\
-		}							\
-		ret = -ERESTARTSYS;					\
-		abort_exclusive_wait(&wq, &__wait, 			\
+		if (signal_pending(current)) {				\
+			ret = -ERESTARTSYS;				\
+			abort_exclusive_wait(&wq, &__wait, 		\
 				TASK_INTERRUPTIBLE, NULL);		\
-		break;							\
+			break;						\
+		}							\
+		schedule();						\
 	}								\
 } while (0)
 
author maintainer
#3 lore raw

PATCH 2/16 sched/wait: Change timeout logic

In reply to Peter Zijlstra

Commit 4c663cf ("wait: fix false timeouts when using wait_event_timeout()") introduced an additional condition check after a timeout but there's a few issues;

- it forgot one site
- it put the check after the main loop; not at the actual timeout check.

Cure both; by wrapping the condition (as suggested by Oleg), this avoids double evaluation of 'condition' which could be quite big.

---
 include/linux/wait.h |   24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
include/linux/wait.h +11 -13
@@ -179,6 +179,14 @@ wait_queue_head_t *bit_waitqueue(void *,
 #define wake_up_interruptible_sync_poll(x, m)				\
 	__wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
 
+#define ___wait_cond_timeout(condition, ret)				\
+({									\
+ 	bool __cond = (condition);					\
+ 	if (__cond && !ret)						\
+ 		ret = 1;						\
+ 	__cond || !ret;							\
+})
+
 #define __wait_event(wq, condition) 					\
 do {									\
 	DEFINE_WAIT(__wait);						\
@@ -217,14 +225,10 @@ do {									\
 									\
 	for (;;) {							\
 		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (condition)						\
+		if (___wait_cond_timeout(condition, ret))		\
 			break;						\
 		ret = schedule_timeout(ret);				\
-		if (!ret)						\
-			break;						\
 	}								\
-	if (!ret && (condition))					\
-		ret = 1;						\
 	finish_wait(&wq, &__wait);					\
 } while (0)
 
@@ -299,18 +303,14 @@ do {									\
 									\
 	for (;;) {							\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
+		if (___wait_cond_timeout(condition, ret))		\
 			break;						\
 		if (signal_pending(current)) {				\
 			ret = -ERESTARTSYS;				\
 			break;						\
 		}							\
 		ret = schedule_timeout(ret);				\
-		if (!ret)						\
-			break;						\
 	}								\
-	if (!ret && (condition))					\
-		ret = 1;						\
 	finish_wait(&wq, &__wait);					\
 } while (0)
 
@@ -815,7 +815,7 @@ do {									\
 									\
 	for (;;) {							\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
+		if (___wait_cond_timeout(condition, ret))		\
 			break;						\
 		if (signal_pending(current)) {				\
 			ret = -ERESTARTSYS;				\
@@ -824,8 +824,6 @@ do {									\
 		spin_unlock_irq(&lock);					\
 		ret = schedule_timeout(ret);				\
 		spin_lock_irq(&lock);					\
-		if (!ret)						\
-			break;						\
 	}								\
 	finish_wait(&wq, &__wait);					\
 } while (0)
#4 lore raw

[tip:sched/core] sched/wait: Change timeout logic

sched/wait: Change timeout logic
Commit-ID:  2953ef246b058989657e1e77b36b67566ac06f7b
Gitweb:     http://git.kernel.org/tip/2953ef246b058989657e1e77b36b67566ac06f7b
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:19 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:44 +0200

sched/wait: Change timeout logic

Commit 4c663cf ("wait: fix false timeouts when using wait_event_timeout()") introduced an additional condition check after a timeout but there's a few issues;

- it forgot one site
- it put the check after the main loop; not at the actual timeout check.

Cure both; by wrapping the condition (as suggested by Oleg), this avoids double evaluation of 'condition' which could be quite big.

---
 include/linux/wait.h | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
include/linux/wait.h +11 -13
index ccf0c52..b2afd66 100644
@@ -179,6 +179,14 @@ wait_queue_head_t *bit_waitqueue(void *, int);
 #define wake_up_interruptible_sync_poll(x, m)				\
 	__wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
 
+#define ___wait_cond_timeout(condition, ret)				\
+({									\
+ 	bool __cond = (condition);					\
+ 	if (__cond && !ret)						\
+ 		ret = 1;						\
+ 	__cond || !ret;							\
+})
+
 #define __wait_event(wq, condition) 					\
 do {									\
 	DEFINE_WAIT(__wait);						\
@@ -217,14 +225,10 @@ do {									\
 									\
 	for (;;) {							\
 		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (condition)						\
+		if (___wait_cond_timeout(condition, ret))		\
 			break;						\
 		ret = schedule_timeout(ret);				\
-		if (!ret)						\
-			break;						\
 	}								\
-	if (!ret && (condition))					\
-		ret = 1;						\
 	finish_wait(&wq, &__wait);					\
 } while (0)
 
@@ -299,18 +303,14 @@ do {									\
 									\
 	for (;;) {							\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
+		if (___wait_cond_timeout(condition, ret))		\
 			break;						\
 		if (signal_pending(current)) {				\
 			ret = -ERESTARTSYS;				\
 			break;						\
 		}							\
 		ret = schedule_timeout(ret);				\
-		if (!ret)						\
-			break;						\
 	}								\
-	if (!ret && (condition))					\
-		ret = 1;						\
 	finish_wait(&wq, &__wait);					\
 } while (0)
 
@@ -815,7 +815,7 @@ do {									\
 									\
 	for (;;) {							\
 		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
+		if (___wait_cond_timeout(condition, ret))		\
 			break;						\
 		if (signal_pending(current)) {				\
 			ret = -ERESTARTSYS;				\
@@ -824,8 +824,6 @@ do {									\
 		spin_unlock_irq(&lock);					\
 		ret = schedule_timeout(ret);				\
 		spin_lock_irq(&lock);					\
-		if (!ret)						\
-			break;						\
 	}								\
 	finish_wait(&wq, &__wait);					\
 } while (0)
author maintainer
#5 lore raw

PATCH 3/16 sched/wait: Change the wait_exclusive control flow

In reply to Peter Zijlstra

Purely a preparatory patch; it changes the control flow to match what will soon be generated by generic code so that that patch can be a unity transform.

---
 include/linux/wait.h |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
include/linux/wait.h +5 -4
@@ -430,23 +430,24 @@ do {									\
 
 #define __wait_event_interruptible_exclusive(wq, condition, ret)	\
 do {									\
+	__label__ __out;						\
 	DEFINE_WAIT(__wait);						\
 									\
 	for (;;) {							\
 		prepare_to_wait_exclusive(&wq, &__wait,			\
 					TASK_INTERRUPTIBLE);		\
-		if (condition) {					\
-			finish_wait(&wq, &__wait);			\
+		if (condition)						\
 			break;						\
-		}							\
 		if (signal_pending(current)) {				\
 			ret = -ERESTARTSYS;				\
 			abort_exclusive_wait(&wq, &__wait, 		\
 				TASK_INTERRUPTIBLE, NULL);		\
-			break;						\
+			goto __out;					\
 		}							\
 		schedule();						\
 	}								\
+	finish_wait(&wq, &__wait);					\
+__out:	;								\
 } while (0)
 
 #define wait_event_interruptible_exclusive(wq, condition)		\
#6 lore raw

[tip:sched/core] sched/wait: Change the wait_exclusive control flow

sched/wait: Change the wait_exclusive control flow
Commit-ID:  bb632bc44970f75b66df102e831a4fc0692e9159
Gitweb:     http://git.kernel.org/tip/bb632bc44970f75b66df102e831a4fc0692e9159
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:20 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:45 +0200

sched/wait: Change the wait_exclusive control flow

Purely a preparatory patch; it changes the control flow to match what will soon be generated by generic code so that that patch can be a unity transform.

---
 include/linux/wait.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
include/linux/wait.h +5 -4
index b2afd66..7d7819d 100644
@@ -428,23 +428,24 @@ do {									\
 
 #define __wait_event_interruptible_exclusive(wq, condition, ret)	\
 do {									\
+	__label__ __out;						\
 	DEFINE_WAIT(__wait);						\
 									\
 	for (;;) {							\
 		prepare_to_wait_exclusive(&wq, &__wait,			\
 					TASK_INTERRUPTIBLE);		\
-		if (condition) {					\
-			finish_wait(&wq, &__wait);			\
+		if (condition)						\
 			break;						\
-		}							\
 		if (signal_pending(current)) {				\
 			ret = -ERESTARTSYS;				\
 			abort_exclusive_wait(&wq, &__wait, 		\
 				TASK_INTERRUPTIBLE, NULL);		\
-			break;						\
+			goto __out;					\
 		}							\
 		schedule();						\
 	}								\
+	finish_wait(&wq, &__wait);					\
+__out:	;								\
 } while (0)
 
 #define wait_event_interruptible_exclusive(wq, condition)		\
author maintainer
#7 lore raw

PATCH 4/16 sched/wait: Introduce ___wait_event()

In reply to Peter Zijlstra

There's far too much duplication in the __wait_event macros; in order to fix this introduce ___wait_event() a macro with the capability to replace most other macros.

With the previous patches changing the various __wait_event*() implementations to be more uniform; we can now collapse the lot without also changing generated code.

---
 include/linux/wait.h |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
include/linux/wait.h +36 -0
@@ -187,6 +187,42 @@ wait_queue_head_t *bit_waitqueue(void *,
  	__cond || !ret;							\
 })
 
+#define ___wait_signal_pending(state)					\
+	((state == TASK_INTERRUPTIBLE && signal_pending(current)) ||	\
+	 (state == TASK_KILLABLE && fatal_signal_pending(current)))
+
+#define ___wait_nop_ret		int ret __always_unused
+
+#define ___wait_event(wq, condition, state, exclusive, ret, cmd)	\
+do {									\
+	__label__ __out;						\
+	DEFINE_WAIT(__wait);						\
+									\
+	for (;;) {							\
+		if (exclusive)						\
+			prepare_to_wait_exclusive(&wq, &__wait, state); \
+		else							\
+			prepare_to_wait(&wq, &__wait, state);		\
+									\
+		if (condition)						\
+			break;						\
+									\
+		if (___wait_signal_pending(state)) {			\
+			ret = -ERESTARTSYS;				\
+			if (exclusive) {				\
+				abort_exclusive_wait(&wq, &__wait, 	\
+						     state, NULL); 	\
+				goto __out;				\
+			}						\
+			break;						\
+		}							\
+									\
+		cmd;							\
+	}								\
+	finish_wait(&wq, &__wait);					\
+__out:	;								\
+} while (0)
+
 #define __wait_event(wq, condition) 					\
 do {									\
 	DEFINE_WAIT(__wait);						\
#8 lore raw

[tip:sched/core] sched/wait: Introduce ___wait_event()

sched/wait: Introduce ___wait_event()
Commit-ID:  41a1431b178c3b731d6dfc40b987528b333dd93e
Gitweb:     http://git.kernel.org/tip/41a1431b178c3b731d6dfc40b987528b333dd93e
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:21 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:46 +0200

sched/wait: Introduce ___wait_event()

There's far too much duplication in the __wait_event macros; in order to fix this introduce ___wait_event() a macro with the capability to replace most other macros.

With the previous patches changing the various __wait_event*() implementations to be more uniform; we can now collapse the lot without also changing generated code.

---
 include/linux/wait.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
include/linux/wait.h +36 -0
index 7d7819d..29d0249 100644
@@ -187,6 +187,42 @@ wait_queue_head_t *bit_waitqueue(void *, int);
  	__cond || !ret;							\
 })
 
+#define ___wait_signal_pending(state)					\
+	((state == TASK_INTERRUPTIBLE && signal_pending(current)) ||	\
+	 (state == TASK_KILLABLE && fatal_signal_pending(current)))
+
+#define ___wait_nop_ret		int ret __always_unused
+
+#define ___wait_event(wq, condition, state, exclusive, ret, cmd)	\
+do {									\
+	__label__ __out;						\
+	DEFINE_WAIT(__wait);						\
+									\
+	for (;;) {							\
+		if (exclusive)						\
+			prepare_to_wait_exclusive(&wq, &__wait, state); \
+		else							\
+			prepare_to_wait(&wq, &__wait, state);		\
+									\
+		if (condition)						\
+			break;						\
+									\
+		if (___wait_signal_pending(state)) {			\
+			ret = -ERESTARTSYS;				\
+			if (exclusive) {				\
+				abort_exclusive_wait(&wq, &__wait, 	\
+						     state, NULL); 	\
+				goto __out;				\
+			}						\
+			break;						\
+		}							\
+									\
+		cmd;							\
+	}								\
+	finish_wait(&wq, &__wait);					\
+__out:	;								\
+} while (0)
+
 #define __wait_event(wq, condition) 					\
 do {									\
 	DEFINE_WAIT(__wait);						\
author maintainer
#9 lore raw

PATCH 5/16 sched/wait: Collapse __wait_event()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h |   13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
include/linux/wait.h +2 -11
@@ -224,17 +224,8 @@ __out:	;								\
 } while (0)
 
 #define __wait_event(wq, condition) 					\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		schedule();						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0,		\
+		      ___wait_nop_ret, schedule())
 
 /**
  * wait_event - sleep until a condition gets true
#10 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event()

sched/wait: Collapse __wait_event()
Commit-ID:  854267f4384243b19c03a2942e84f06f2beb0952
Gitweb:     http://git.kernel.org/tip/854267f4384243b19c03a2942e84f06f2beb0952
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:22 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:46 +0200

sched/wait: Collapse __wait_event()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
include/linux/wait.h +2 -11
index 29d0249..68e3a62 100644
@@ -224,17 +224,8 @@ __out:	;								\
 } while (0)
 
 #define __wait_event(wq, condition) 					\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		schedule();						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0,		\
+		      ___wait_nop_ret, schedule())
 
 /**
  * wait_event - sleep until a condition gets true
author maintainer
#11 lore raw

PATCH 6/16 sched/wait: Collapse __wait_event_timeout()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +3 -11
@@ -220,17 +247,9 @@ do {									\
 } while (0)
 
 #define __wait_event_timeout(wq, condition, ret)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (___wait_cond_timeout(condition, ret))		\
-			break;						\
-		ret = schedule_timeout(ret);				\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, ___wait_cond_timeout(condition, ret), 	\
+		      TASK_UNINTERRUPTIBLE, 0, ret,			\
+		      ret = schedule_timeout(ret))
 
 /**
  * wait_event_timeout - sleep until a condition gets true or a timeout elapses
#12 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_timeout()

sched/wait: Collapse __wait_event_timeout()
Commit-ID:  ddc1994b8217527e1818f690f17597fc9cedf81b
Gitweb:     http://git.kernel.org/tip/ddc1994b8217527e1818f690f17597fc9cedf81b
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:23 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:47 +0200

sched/wait: Collapse __wait_event_timeout()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
include/linux/wait.h +3 -11
index 68e3a62..546b94e 100644
@@ -247,17 +247,9 @@ do {									\
 } while (0)
 
 #define __wait_event_timeout(wq, condition, ret)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (___wait_cond_timeout(condition, ret))		\
-			break;						\
-		ret = schedule_timeout(ret);				\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, ___wait_cond_timeout(condition, ret), 	\
+		      TASK_UNINTERRUPTIBLE, 0, ret,			\
+		      ret = schedule_timeout(ret))
 
 /**
  * wait_event_timeout - sleep until a condition gets true or a timeout elapses
author maintainer
#13 lore raw

PATCH 7/16 sched/wait: Collapse __wait_event_interruptible()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +2 -15
@@ -258,21 +277,8 @@ do {									\
 })
 
 #define __wait_event_interruptible(wq, condition, ret)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		schedule();						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	\
+		      schedule())
 
 /**
  * wait_event_interruptible - sleep until a condition gets true
#14 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_interruptible( )

sched/wait: Collapse __wait_event_interruptible()
Commit-ID:  f13f4c41c9cf9cd61c896e46e4e7ba2687e2af9c
Gitweb:     http://git.kernel.org/tip/f13f4c41c9cf9cd61c896e46e4e7ba2687e2af9c
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:24 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:48 +0200

sched/wait: Collapse __wait_event_interruptible()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
include/linux/wait.h +2 -15
index 546b94e..39e4bbd 100644
@@ -277,21 +277,8 @@ do {									\
 })
 
 #define __wait_event_interruptible(wq, condition, ret)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		schedule();						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	\
+		      schedule())
 
 /**
  * wait_event_interruptible - sleep until a condition gets true
author maintainer
#15 lore raw

PATCH 8/16 sched/wait: Collapse __wait_event_interruptible_timeout()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +3 -15
@@ -298,21 +304,9 @@ do {									\
 })
 
 #define __wait_event_interruptible_timeout(wq, condition, ret)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (___wait_cond_timeout(condition, ret))		\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		ret = schedule_timeout(ret);				\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, ___wait_cond_timeout(condition, ret),		\
+		      TASK_INTERRUPTIBLE, 0, ret,			\
+		      ret = schedule_timeout(ret))
 
 /**
  * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
#16 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_interruptible_timeout()

sched/wait: Collapse __wait_event_interruptible_timeout()
Commit-ID:  c2ebb1fb4eddf3d1d66fe31d1e89e83ee211b81c
Gitweb:     http://git.kernel.org/tip/c2ebb1fb4eddf3d1d66fe31d1e89e83ee211b81c
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:25 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:49 +0200

sched/wait: Collapse __wait_event_interruptible_timeout()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
include/linux/wait.h +3 -15
index 39e4bbd..a79fb15 100644
@@ -304,21 +304,9 @@ do {									\
 })
 
 #define __wait_event_interruptible_timeout(wq, condition, ret)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (___wait_cond_timeout(condition, ret))		\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		ret = schedule_timeout(ret);				\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, ___wait_cond_timeout(condition, ret),		\
+		      TASK_INTERRUPTIBLE, 0, ret,			\
+		      ret = schedule_timeout(ret))
 
 /**
  * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
author maintainer
#17 lore raw

PATCH 9/16 sched/wait: Collapse __wait_event_interruptible_exclusive()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +2 -20
@@ -427,26 +421,8 @@ do {									\
 })
 
 #define __wait_event_interruptible_exclusive(wq, condition, ret)	\
-do {									\
-	__label__ __out;						\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait_exclusive(&wq, &__wait,			\
-					TASK_INTERRUPTIBLE);		\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			abort_exclusive_wait(&wq, &__wait, 		\
-				TASK_INTERRUPTIBLE, NULL);		\
-			goto __out;					\
-		}							\
-		schedule();						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-__out:	;								\
-} while (0)
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, ret,	\
+		      schedule())
 
 #define wait_event_interruptible_exclusive(wq, condition)		\
 ({									\
#18 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_interruptible_exclusive()

sched/wait: Collapse __wait_event_interruptible_exclusive()
Commit-ID:  48c2521717b39cb6904941ec2847d9775669207a
Gitweb:     http://git.kernel.org/tip/48c2521717b39cb6904941ec2847d9775669207a
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:26 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:49 +0200

sched/wait: Collapse __wait_event_interruptible_exclusive()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
include/linux/wait.h +2 -20
index a79fb15..c4ab172 100644
@@ -421,26 +421,8 @@ do {									\
 })
 
 #define __wait_event_interruptible_exclusive(wq, condition, ret)	\
-do {									\
-	__label__ __out;						\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait_exclusive(&wq, &__wait,			\
-					TASK_INTERRUPTIBLE);		\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			abort_exclusive_wait(&wq, &__wait, 		\
-				TASK_INTERRUPTIBLE, NULL);		\
-			goto __out;					\
-		}							\
-		schedule();						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-__out:	;								\
-} while (0)
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, ret,	\
+		      schedule())
 
 #define wait_event_interruptible_exclusive(wq, condition)		\
 ({									\
author maintainer
#19 lore raw

PATCH 10/16 sched/wait: Collapse __wait_event_lock_irq()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +6 -14
@@ -648,20 +609,12 @@ do {									\
 
 
 #define __wait_event_lock_irq(wq, condition, lock, cmd)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		spin_unlock_irq(&lock);					\
-		cmd;							\
-		schedule();						\
-		spin_lock_irq(&lock);					\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0,		\
+		      ___wait_nop_ret,					\
+		      spin_unlock_irq(&lock);				\
+		      cmd;						\
+		      schedule();					\
+		      spin_lock_irq(&lock))
 
 /**
  * wait_event_lock_irq_cmd - sleep until a condition gets true. The
#20 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_lock_irq()

sched/wait: Collapse __wait_event_lock_irq()
Commit-ID:  13cb5042a4b80396f77cf5d599d2c002c57b89dc
Gitweb:     http://git.kernel.org/tip/13cb5042a4b80396f77cf5d599d2c002c57b89dc
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:27 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:14:50 +0200

sched/wait: Collapse __wait_event_lock_irq()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
include/linux/wait.h +6 -14
index c4ab172..d64918e 100644
@@ -624,20 +624,12 @@ do {									\
 
 
 #define __wait_event_lock_irq(wq, condition, lock, cmd)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		spin_unlock_irq(&lock);					\
-		cmd;							\
-		schedule();						\
-		spin_lock_irq(&lock);					\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0,		\
+		      ___wait_nop_ret,					\
+		      spin_unlock_irq(&lock);				\
+		      cmd;						\
+		      schedule();					\
+		      spin_lock_irq(&lock))
 
 /**
  * wait_event_lock_irq_cmd - sleep until a condition gets true. The
author maintainer
#21 lore raw

PATCH 11/16 sched/wait: Collapse __wait_event_interruptible_lock_irq()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +6 -20
@@ -721,26 +674,12 @@ do {									\
 } while (0)
 
 
-#define __wait_event_interruptible_lock_irq(wq, condition,		\
-					    lock, ret, cmd)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		spin_unlock_irq(&lock);					\
-		cmd;							\
-		schedule();						\
-		spin_lock_irq(&lock);					\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+#define __wait_event_interruptible_lock_irq(wq, condition, lock, ret, cmd) \
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	   \
+		      spin_unlock_irq(&lock);				   \
+		      cmd;						   \
+		      schedule();					   \
+		      spin_lock_irq(&lock))
 
 /**
  * wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
#22 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_interruptible_lock_irq()

sched/wait: Collapse __wait_event_interruptible_lock_irq()
Commit-ID:  8fbd88fa1717601ef91ced49a32f24786b167065
Gitweb:     http://git.kernel.org/tip/8fbd88fa1717601ef91ced49a32f24786b167065
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:16:19 +0200

sched/wait: Collapse __wait_event_interruptible_lock_irq()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)
include/linux/wait.h +6 -20
index d64918e..a577a85 100644
@@ -689,26 +689,12 @@ do {									\
 } while (0)
 
 
-#define __wait_event_interruptible_lock_irq(wq, condition,		\
-					    lock, ret, cmd)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		spin_unlock_irq(&lock);					\
-		cmd;							\
-		schedule();						\
-		spin_lock_irq(&lock);					\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+#define __wait_event_interruptible_lock_irq(wq, condition, lock, ret, cmd) \
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	   \
+		      spin_unlock_irq(&lock);				   \
+		      cmd;						   \
+		      schedule();					   \
+		      spin_lock_irq(&lock))
 
 /**
  * wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
author maintainer
#23 lore raw

PATCH 12/16 sched/wait: Collapse __wait_event_interruptible_lock_irq_timeout()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/wait.h +6 -19
@@ -809,25 +748,12 @@ do {									\
 	__ret;								\
 })
 
-#define __wait_event_interruptible_lock_irq_timeout(wq, condition,	\
-						    lock, ret)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (___wait_cond_timeout(condition, ret))		\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		spin_unlock_irq(&lock);					\
-		ret = schedule_timeout(ret);				\
-		spin_lock_irq(&lock);					\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+#define __wait_event_interruptible_lock_irq_timeout(wq, condition, lock, ret) \
+	___wait_event(wq, ___wait_cond_timeout(condition, ret),		      \
+		      TASK_INTERRUPTIBLE, 0, ret,	      		      \
+		      spin_unlock_irq(&lock);				      \
+		      ret = schedule_timeout(ret);			      \
+		      spin_lock_irq(&lock));
 
 /**
  * wait_event_interruptible_lock_irq_timeout - sleep until a condition gets true or a timeout elapses.
#24 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_interruptible_lock_irq_timeout()

sched/wait: Collapse __wait_event_interruptible_lock_irq_timeout()
Commit-ID:  a1dc6852ac5eecdcd3122ae01703183a3e88e979
Gitweb:     http://git.kernel.org/tip/a1dc6852ac5eecdcd3122ae01703183a3e88e979
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:29 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:16:20 +0200

sched/wait: Collapse __wait_event_interruptible_lock_irq_timeout()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)
include/linux/wait.h +6 -19
index a577a85..5d5408b 100644
@@ -763,25 +763,12 @@ do {									\
 	__ret;								\
 })
 
-#define __wait_event_interruptible_lock_irq_timeout(wq, condition,	\
-						    lock, ret)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (___wait_cond_timeout(condition, ret))		\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		spin_unlock_irq(&lock);					\
-		ret = schedule_timeout(ret);				\
-		spin_lock_irq(&lock);					\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+#define __wait_event_interruptible_lock_irq_timeout(wq, condition, lock, ret) \
+	___wait_event(wq, ___wait_cond_timeout(condition, ret),		      \
+		      TASK_INTERRUPTIBLE, 0, ret,	      		      \
+		      spin_unlock_irq(&lock);				      \
+		      ret = schedule_timeout(ret);			      \
+		      spin_lock_irq(&lock));
 
 /**
  * wait_event_interruptible_lock_irq_timeout - sleep until a condition gets true or a timeout elapses.
author maintainer
#25 lore raw

PATCH 13/16 sched/wait: Collapse __wait_event_interruptible_tty()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h  |   21 +----
 include/linux/wait.h |  192 +++++++++++++++------------------------------------
 2 files changed, 63 insertions(+), 150 deletions(-)
include/linux/tty.h +4 -17
@@ -679,23 +679,10 @@ static inline void tty_wait_until_sent_f
 })
 
 #define __wait_event_interruptible_tty(tty, wq, condition, ret)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		tty_unlock(tty);					\
-		schedule();						\
-		tty_lock(tty);						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	\
+			tty_unlock(tty);				\
+			schedule();					\
+			tty_lock(tty))
 
 #ifdef CONFIG_PROC_FS
 extern void proc_tty_register_driver(struct tty_driver *);
#26 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_interruptible_tty()

sched/wait: Collapse __wait_event_interruptible_tty()
Commit-ID:  0d1e1c8a430450a3ce61a842cec64f9e2a9f3b05
Gitweb:     http://git.kernel.org/tip/0d1e1c8a430450a3ce61a842cec64f9e2a9f3b05
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:30 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:16:20 +0200

sched/wait: Collapse __wait_event_interruptible_tty()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/tty.h | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
include/linux/tty.h +4 -17
index 0503729..6e80329 100644
@@ -679,23 +679,10 @@ static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
 })
 
 #define __wait_event_interruptible_tty(tty, wq, condition, ret)		\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
-		if (condition)						\
-			break;						\
-		if (signal_pending(current)) {				\
-			ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
-		tty_unlock(tty);					\
-		schedule();						\
-		tty_lock(tty);						\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	\
+			tty_unlock(tty);				\
+			schedule();					\
+			tty_lock(tty))
 
 #ifdef CONFIG_PROC_FS
 extern void proc_tty_register_driver(struct tty_driver *);
author maintainer
#27 lore raw

PATCH 14/16 sched/wait: Collapse __wait_event_killable()

In reply to Peter Zijlstra

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---

include/linux/wait.h +1 -16
@@ -582,22 +582,7 @@ do {									\
 
 
 #define __wait_event_killable(wq, condition, ret)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_KILLABLE);		\
-		if (condition)						\
-			break;						\
-		if (!fatal_signal_pending(current)) {			\
-			schedule();					\
-			continue;					\
-		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_KILLABLE, 0, ret, schedule())
 
 /**
  * wait_event_killable - sleep until a condition gets true
#28 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_killable()

sched/wait: Collapse __wait_event_killable()
Commit-ID:  cf7361fd961b6f0510572af6cf8ca3ffba07018b
Gitweb:     http://git.kernel.org/tip/cf7361fd961b6f0510572af6cf8ca3ffba07018b
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:31 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:16:21 +0200

sched/wait: Collapse __wait_event_killable()

Reduce macro complexity by using the new ___wait_event() helper. No change in behaviour, identical generated code.

---
 include/linux/wait.h | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)
include/linux/wait.h +1 -16
index 5d5408b..ec3683e 100644
@@ -582,22 +582,7 @@ do {									\
 
 
 #define __wait_event_killable(wq, condition, ret)			\
-do {									\
-	DEFINE_WAIT(__wait);						\
-									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, TASK_KILLABLE);		\
-		if (condition)						\
-			break;						\
-		if (!fatal_signal_pending(current)) {			\
-			schedule();					\
-			continue;					\
-		}							\
-		ret = -ERESTARTSYS;					\
-		break;							\
-	}								\
-	finish_wait(&wq, &__wait);					\
-} while (0)
+	___wait_event(wq, condition, TASK_KILLABLE, 0, ret, schedule())
 
 /**
  * wait_event_killable - sleep until a condition gets true
author maintainer
#29 lore raw

PATCH 15/16 sched/wait: Collapse __wait_event_hrtimeout()

In reply to Peter Zijlstra

While not a whole-sale replacement like the others we can still reduce the size of __wait_event_hrtimeout() considerably by noting that the actual core of __wait_event_hrtimeout() is identical to what ___wait_event() generates.

---
 include/linux/wait.h |   15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
include/linux/wait.h +2 -13
@@ -338,7 +338,6 @@ do {									\
 #define __wait_event_hrtimeout(wq, condition, timeout, state)		\
 ({									\
 	int __ret = 0;							\
-	DEFINE_WAIT(__wait);						\
 	struct hrtimer_sleeper __t;					\
 									\
 	hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC,		\
@@ -349,25 +348,15 @@ do {									\
 				       current->timer_slack_ns,		\
 				       HRTIMER_MODE_REL);		\
 									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, state);			\
-		if (condition)						\
-			break;						\
-		if (state == TASK_INTERRUPTIBLE &&			\
-		    signal_pending(current)) {				\
-			__ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
+	___wait_event(wq, condition, state, 0, __ret,			\
 		if (!__t.task) {					\
 			__ret = -ETIME;					\
 			break;						\
 		}							\
-		schedule();						\
-	}								\
+		schedule());						\
 									\
 	hrtimer_cancel(&__t.timer);					\
 	destroy_hrtimer_on_stack(&__t.timer);				\
-	finish_wait(&wq, &__wait);					\
 	__ret;								\
 })
 
#30 lore raw

[tip:sched/core] sched/wait: Collapse __wait_event_hrtimeout()

sched/wait: Collapse __wait_event_hrtimeout()
Commit-ID:  ebdc195f2ec68576876216081035293e37318e86
Gitweb:     http://git.kernel.org/tip/ebdc195f2ec68576876216081035293e37318e86
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:32 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:16:22 +0200

sched/wait: Collapse __wait_event_hrtimeout()

While not a whole-sale replacement like the others we can still reduce the size of __wait_event_hrtimeout() considerably by noting that the actual core of __wait_event_hrtimeout() is identical to what ___wait_event() generates.

---
 include/linux/wait.h | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
include/linux/wait.h +2 -13
index ec3683e..c065e8a 100644
@@ -337,7 +337,6 @@ do {									\
 #define __wait_event_hrtimeout(wq, condition, timeout, state)		\
 ({									\
 	int __ret = 0;							\
-	DEFINE_WAIT(__wait);						\
 	struct hrtimer_sleeper __t;					\
 									\
 	hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC,		\
@@ -348,25 +347,15 @@ do {									\
 				       current->timer_slack_ns,		\
 				       HRTIMER_MODE_REL);		\
 									\
-	for (;;) {							\
-		prepare_to_wait(&wq, &__wait, state);			\
-		if (condition)						\
-			break;						\
-		if (state == TASK_INTERRUPTIBLE &&			\
-		    signal_pending(current)) {				\
-			__ret = -ERESTARTSYS;				\
-			break;						\
-		}							\
+	___wait_event(wq, condition, state, 0, __ret,			\
 		if (!__t.task) {					\
 			__ret = -ETIME;					\
 			break;						\
 		}							\
-		schedule();						\
-	}								\
+		schedule());						\
 									\
 	hrtimer_cancel(&__t.timer);					\
 	destroy_hrtimer_on_stack(&__t.timer);				\
-	finish_wait(&wq, &__wait);					\
 	__ret;								\
 })
 
author maintainer
#31 lore raw

PATCH 16/16 sched/wait: Make the __wait_event*() interface more friendly

In reply to Peter Zijlstra

Change all __wait_event*() implementations to match the corresponding wait_event*() signature for convenience.

In particular this does away with the weird 'ret' logic. Since there are __wait_event*() users this requires we update them too.

---
 arch/mips/kernel/rtlx.c         |   19 +++---
 include/linux/tty.h             |   10 +--
 include/linux/wait.h            |  113 +++++++++++++++++++---------------------
 net/irda/af_irda.c              |    5 -
 net/netfilter/ipvs/ip_vs_sync.c |    7 --
 5 files changed, 73 insertions(+), 81 deletions(-)
arch/mips/kernel/rtlx.c +9 -10
@@ -172,8 +172,9 @@ int rtlx_open(int index, int can_sleep)
 	if (rtlx == NULL) {
 		if( (p = vpe_get_shared(tclimit)) == NULL) {
 		    if (can_sleep) {
-			__wait_event_interruptible(channel_wqs[index].lx_queue,
-				(p = vpe_get_shared(tclimit)), ret);
+			ret = __wait_event_interruptible(
+					channel_wqs[index].lx_queue,
+					(p = vpe_get_shared(tclimit)));
 			if (ret)
 				goto out_fail;
 		    } else {
@@ -263,11 +264,10 @@ unsigned int rtlx_read_poll(int index, i
 	/* data available to read? */
 	if (chan->lx_read == chan->lx_write) {
 		if (can_sleep) {
-			int ret = 0;
-
-			__wait_event_interruptible(channel_wqs[index].lx_queue,
+			int ret = __wait_event_interruptible(
+				channel_wqs[index].lx_queue,
 				(chan->lx_read != chan->lx_write) ||
-				sp_stopping, ret);
+				sp_stopping);
 			if (ret)
 				return ret;
 
@@ -440,14 +440,13 @@ static ssize_t file_write(struct file *f
 
 	/* any space left... */
 	if (!rtlx_write_poll(minor)) {
-		int ret = 0;
+		int ret;
 
 		if (file->f_flags & O_NONBLOCK)
 			return -EAGAIN;
 
-		__wait_event_interruptible(channel_wqs[minor].rt_queue,
-					   rtlx_write_poll(minor),
-					   ret);
+		ret = __wait_event_interruptible(channel_wqs[minor].rt_queue,
+					   rtlx_write_poll(minor));
 		if (ret)
 			return ret;
 	}
include/linux/tty.h +5 -5
@@ -672,14 +672,14 @@ static inline void tty_wait_until_sent_f
 #define wait_event_interruptible_tty(tty, wq, condition)		\
 ({									\
 	int __ret = 0;							\
-	if (!(condition)) {						\
-		__wait_event_interruptible_tty(tty, wq, condition, __ret);	\
-	}								\
+	if (!(condition))						\
+		__ret = __wait_event_interruptible_tty(tty, wq,		\
+						       condition);	\
 	__ret;								\
 })
 
-#define __wait_event_interruptible_tty(tty, wq, condition, ret)		\
-	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	\
+#define __wait_event_interruptible_tty(tty, wq, condition)		\
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,		\
 			tty_unlock(tty);				\
 			schedule();					\
 			tty_lock(tty))
include/linux/wait.h +55 -58

239 lines not on this page · raw message

net/irda/af_irda.c +2 -3
@@ -2563,9 +2563,8 @@ static int irda_getsockopt(struct socket
 				  jiffies + msecs_to_jiffies(val));
 
 			/* Wait for IR-LMP to call us back */
-			__wait_event_interruptible(self->query_wait,
-			      (self->cachedaddr != 0 || self->errno == -ETIME),
-						   err);
+			err = __wait_event_interruptible(self->query_wait,
+			      (self->cachedaddr != 0 || self->errno == -ETIME));
 
 			/* If watchdog is still activated, kill it! */
 			del_timer(&(self->watchdog));
net/netfilter/ipvs/ip_vs_sync.c +2 -5
@@ -1637,12 +1637,9 @@ static int sync_thread_master(void *data
 			continue;
 		}
 		while (ip_vs_send_sync_msg(tinfo->sock, sb->mesg) < 0) {
-			int ret = 0;
-
-			__wait_event_interruptible(*sk_sleep(sk),
+			int ret = __wait_event_interruptible(*sk_sleep(sk),
 						   sock_writeable(sk) ||
-						   kthread_should_stop(),
-						   ret);
+						   kthread_should_stop());
 			if (unlikely(kthread_should_stop()))
 				goto done;
 		}
#32 lore raw

[tip:sched/core] sched/wait: Make the __wait_event*() interface more friendly

sched/wait: Make the __wait_event*() interface more friendly
Commit-ID:  35a2af94c7ce7130ca292c68b1d27fcfdb648f6b
Gitweb:     http://git.kernel.org/tip/35a2af94c7ce7130ca292c68b1d27fcfdb648f6b
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Wed, 2 Oct 2013 11:22:33 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Oct 2013 10:16:25 +0200

sched/wait: Make the __wait_event*() interface more friendly

Change all __wait_event*() implementations to match the corresponding wait_event*() signature for convenience.

In particular this does away with the weird 'ret' logic. Since there are __wait_event*() users this requires we update them too.

---
 arch/mips/kernel/rtlx.c         |  19 ++++---
 include/linux/tty.h             |  10 ++--
 include/linux/wait.h            | 113 +++++++++++++++++++---------------------
 net/irda/af_irda.c              |   5 +-
 net/netfilter/ipvs/ip_vs_sync.c |   7 +--
 5 files changed, 73 insertions(+), 81 deletions(-)
arch/mips/kernel/rtlx.c +9 -10
index d763f11..2c12ea1 100644
@@ -172,8 +172,9 @@ int rtlx_open(int index, int can_sleep)
 	if (rtlx == NULL) {
 		if( (p = vpe_get_shared(tclimit)) == NULL) {
 		    if (can_sleep) {
-			__wait_event_interruptible(channel_wqs[index].lx_queue,
-				(p = vpe_get_shared(tclimit)), ret);
+			ret = __wait_event_interruptible(
+					channel_wqs[index].lx_queue,
+					(p = vpe_get_shared(tclimit)));
 			if (ret)
 				goto out_fail;
 		    } else {
@@ -263,11 +264,10 @@ unsigned int rtlx_read_poll(int index, int can_sleep)
 	/* data available to read? */
 	if (chan->lx_read == chan->lx_write) {
 		if (can_sleep) {
-			int ret = 0;
-
-			__wait_event_interruptible(channel_wqs[index].lx_queue,
+			int ret = __wait_event_interruptible(
+				channel_wqs[index].lx_queue,
 				(chan->lx_read != chan->lx_write) ||
-				sp_stopping, ret);
+				sp_stopping);
 			if (ret)
 				return ret;
 
@@ -440,14 +440,13 @@ static ssize_t file_write(struct file *file, const char __user * buffer,
 
 	/* any space left... */
 	if (!rtlx_write_poll(minor)) {
-		int ret = 0;
+		int ret;
 
 		if (file->f_flags & O_NONBLOCK)
 			return -EAGAIN;
 
-		__wait_event_interruptible(channel_wqs[minor].rt_queue,
-					   rtlx_write_poll(minor),
-					   ret);
+		ret = __wait_event_interruptible(channel_wqs[minor].rt_queue,
+					   rtlx_write_poll(minor));
 		if (ret)
 			return ret;
 	}
include/linux/tty.h +5 -5
index 6e80329..633cac7 100644
@@ -672,14 +672,14 @@ static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
 #define wait_event_interruptible_tty(tty, wq, condition)		\
 ({									\
 	int __ret = 0;							\
-	if (!(condition)) {						\
-		__wait_event_interruptible_tty(tty, wq, condition, __ret);	\
-	}								\
+	if (!(condition))						\
+		__ret = __wait_event_interruptible_tty(tty, wq,		\
+						       condition);	\
 	__ret;								\
 })
 
-#define __wait_event_interruptible_tty(tty, wq, condition, ret)		\
-	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, ret,	\
+#define __wait_event_interruptible_tty(tty, wq, condition)		\
+	___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,		\
 			tty_unlock(tty);				\
 			schedule();					\
 			tty_lock(tty))
include/linux/wait.h +55 -58

239 lines not on this page · raw message

net/irda/af_irda.c +2 -3
index 0578d4f..0f67690 100644
@@ -2563,9 +2563,8 @@ bed:
 				  jiffies + msecs_to_jiffies(val));
 
 			/* Wait for IR-LMP to call us back */
-			__wait_event_interruptible(self->query_wait,
-			      (self->cachedaddr != 0 || self->errno == -ETIME),
-						   err);
+			err = __wait_event_interruptible(self->query_wait,
+			      (self->cachedaddr != 0 || self->errno == -ETIME));
 
 			/* If watchdog is still activated, kill it! */
 			del_timer(&(self->watchdog));
net/netfilter/ipvs/ip_vs_sync.c +2 -5
index f448471..f63c238 100644
@@ -1637,12 +1637,9 @@ static int sync_thread_master(void *data)
 			continue;
 		}
 		while (ip_vs_send_sync_msg(tinfo->sock, sb->mesg) < 0) {
-			int ret = 0;
-
-			__wait_event_interruptible(*sk_sleep(sk),
+			int ret = __wait_event_interruptible(*sk_sleep(sk),
 						   sock_writeable(sk) ||
-						   kthread_should_stop(),
-						   ret);
+						   kthread_should_stop());
 			if (unlikely(kthread_should_stop()))
 				goto done;
 		}
author maintainer
#33 lore raw
In reply to Peter Zijlstra

slightly related; do we want to do something like the following two patches?

---
Subject: sched: Move wait code
From: Peter Zijlstra <[email protected]>
Date: Fri Oct 4 17:24:35 CEST 2013

For some reason only the wait part of the wait api lives in kernel/wait.c and the wake part still lives in kernel/sched/core.c; ammend this.

---
 kernel/sched/core.c |  107 ----------------------------------------------------
 kernel/wait.c       |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 105 deletions(-)
kernel/sched/core.c +2 -105
@@ -2579,109 +2579,6 @@ int default_wake_function(wait_queue_t *
 }
 EXPORT_SYMBOL(default_wake_function);
 
-/*
- * The core wakeup function. Non-exclusive wakeups (nr_exclusive == 0) just
- * wake everything up. If it's an exclusive wakeup (nr_exclusive == small +ve
- * number) then we wake all the non-exclusive tasks and one exclusive task.
- *
- * There are circumstances in which we can try to wake a task which has already
- * started to run but is not in state TASK_RUNNING. try_to_wake_up() returns
- * zero in this (rare) case, and we handle it by continuing to scan the queue.
- */
-static void __wake_up_common(wait_queue_head_t *q, unsigned int mode,
-			int nr_exclusive, int wake_flags, void *key)
-{
-	wait_queue_t *curr, *next;
-
-	list_for_each_entry_safe(curr, next, &q->task_list, task_list) {
-		unsigned flags = curr->flags;
-
-		if (curr->func(curr, mode, wake_flags, key) &&
-				(flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
-			break;
-	}
-}
-
-/**
- * __wake_up - wake up threads blocked on a waitqueue.
- * @q: the waitqueue
- * @mode: which threads
- * @nr_exclusive: how many wake-one or wake-many threads to wake up
- * @key: is directly passed to the wakeup function
- *
- * It may be assumed that this function implies a write memory barrier before
- * changing the task state if and only if any tasks are woken up.
- */
-void __wake_up(wait_queue_head_t *q, unsigned int mode,
-			int nr_exclusive, void *key)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&q->lock, flags);
-	__wake_up_common(q, mode, nr_exclusive, 0, key);
-	spin_unlock_irqrestore(&q->lock, flags);
-}
-EXPORT_SYMBOL(__wake_up);
-
-/*
- * Same as __wake_up but called with the spinlock in wait_queue_head_t held.
- */
-void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr)
-{
-	__wake_up_common(q, mode, nr, 0, NULL);
-}
-EXPORT_SYMBOL_GPL(__wake_up_locked);
-
-void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key)
-{
-	__wake_up_common(q, mode, 1, 0, key);
-}
-EXPORT_SYMBOL_GPL(__wake_up_locked_key);
-
-/**
- * __wake_up_sync_key - wake up threads blocked on a waitqueue.
- * @q: the waitqueue
- * @mode: which threads
- * @nr_exclusive: how many wake-one or wake-many threads to wake up
- * @key: opaque value to be passed to wakeup targets
- *
- * The sync wakeup differs that the waker knows that it will schedule
- * away soon, so while the target thread will be woken up, it will not
- * be migrated to another CPU - ie. the two threads are 'synchronized'
- * with each other. This can prevent needless bouncing between CPUs.
- *
- * On UP it can prevent extra preemption.
- *
- * It may be assumed that this function implies a write memory barrier before
- * changing the task state if and only if any tasks are woken up.
- */
-void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode,
-			int nr_exclusive, void *key)
-{
-	unsigned long flags;
-	int wake_flags = WF_SYNC;
-
-	if (unlikely(!q))
-		return;
-
-	if (unlikely(nr_exclusive != 1))
-		wake_flags = 0;
-
-	spin_lock_irqsave(&q->lock, flags);
-	__wake_up_common(q, mode, nr_exclusive, wake_flags, key);
-	spin_unlock_irqrestore(&q->lock, flags);
-}
-EXPORT_SYMBOL_GPL(__wake_up_sync_key);
-
-/*
- * __wake_up_sync - see __wake_up_sync_key()
- */
-void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
-{
-	__wake_up_sync_key(q, mode, nr_exclusive, NULL);
-}
-EXPORT_SYMBOL_GPL(__wake_up_sync);	/* For internal use only */
-
 /**
  * complete: - signals a single thread waiting on this completion
  * @x:  holds the state of this particular completion
@@ -2700,7 +2597,7 @@ void complete(struct completion *x)
 
 	spin_lock_irqsave(&x->wait.lock, flags);
 	x->done++;
-	__wake_up_common(&x->wait, TASK_NORMAL, 1, 0, NULL);
+	__wake_up_locked_key(&x->wait, TASK_NORMAL, NULL);
 	spin_unlock_irqrestore(&x->wait.lock, flags);
 }
 EXPORT_SYMBOL(complete);
@@ -2720,7 +2617,7 @@ void complete_all(struct completion *x)
 
 	spin_lock_irqsave(&x->wait.lock, flags);
 	x->done += UINT_MAX/2;
-	__wake_up_common(&x->wait, TASK_NORMAL, 0, 0, NULL);
+	__wake_up_locked(&x->wait, TASK_NORMAL, 0);
 	spin_unlock_irqrestore(&x->wait.lock, flags);
 }
 EXPORT_SYMBOL(complete_all);
kernel/wait.c +103 -0

109 lines not on this page · raw message

author maintainer
#34 lore raw
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

and

---
Subject: sched: Move completion code
From: Peter Zijlstra <[email protected]>
Date: Fri Oct 4 22:06:53 CEST 2013

Completions already have their own header file: linux/completion.h Move the implementation out of kernel/sched/core.c and into its own
file: kernel/completion.c.

---
 kernel/Makefile     |    2 
 kernel/completion.c |  287 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched/core.c |  284 ---------------------------------------------------
 3 files changed, 288 insertions(+), 285 deletions(-)
kernel/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y     = fork.o exec_domain.o panic.o
 	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o groups.o lglock.o smpboot.o \
-	    rcusync.o
+	    rcusync.o completion.o
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace debug files and internal ftrace files
kernel/completion.c new file +287 -0

287 lines not on this page · raw message

kernel/sched/core.c +0 -284

290 lines not on this page · raw message

#35 lore raw
Quoted 6 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

kernel/completion.c line 3

Quoted 6 lines
kernel/completion.c new file +3 -0
@@ -0,0 +1,287 @@
+
+#include <linux/sched.h>
+#include <linux/completion.h>

Also, mind adding a small blurb at the top explaining what it's all about? Just one sentence or two.

Thanks,

Ingo

author maintainer
#36 lore raw
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Peter Zijlstra
Quoted 1 line · Peter Zijlstra
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

slightly related; do we want to do something like the following two patches?

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

Do you also want to suck in semaphore.c mutex.c rwsem.c spinlock.c etc? Or do you want to create something like kernel/locking/ for all that.

I don't really mind too much either way except that I think that wait.c and completion.c on their own make for a somewhat random split or primitives.

Quoted 9 lines

kernel/completion.c line 3

Quoted 6 lines
kernel/completion.c new file +3 -0
@@ -0,0 +1,287 @@
+
+#include <linux/sched.h>
+#include <linux/completion.h>

Also, mind adding a small blurb at the top explaining what it's all about? Just one sentence or two.

It got a bit longer:

+/*
+ * Generic wait-for-completion handler;
+ *
+ * It differs from semaphores in that their default case is the opposite,
+ * wait_for_completion default blocks whereas semaphore default non-block. The
+ * interface also makes it easy to 'complete' multiple waiting threads,
+ * something which isn't entirely natural for semaphores.
+ *
+ * But more importantly, the primitive documents the usage. Semaphores would
+ * typically be used for exclusion which gives rise to priority inversion.
+ * Waiting for completion is a typically sync point, but not an exclusion point.
+ */

#37 lore raw
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

Do you also want to suck in semaphore.c mutex.c rwsem.c spinlock.c etc? Or do you want to create something like kernel/locking/ for all that.

Yeah, I think kernel/locking/ would be a suitable place for those, and I'd move lockdep*.c there too. (Such things are best done near the end of a merge window, when there's not much pending, to not disrupt development.)

kernel/*.c is a pretty crowded place with 100+ files currently, I've been gradually working towards depopulating it slowly but surely for subsystems that I co-maintain or where I'm frequently active. We already have:

kernel/sched/
kernel/events/
kernel/irq/
kernel/time/
kernel/trace/

and the deeper kernel/*/* hierarchies already host another ~100 .c files. So the transition is half done already I suspect.

Thanks,

Ingo

#38 lore raw
Quoted 28 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

Do you also want to suck in semaphore.c mutex.c rwsem.c spinlock.c etc? Or do you want to create something like kernel/locking/ for all that.

Yeah, I think kernel/locking/ would be a suitable place for those, and I'd move lockdep*.c there too. (Such things are best done near the end of a merge window, when there's not much pending, to not disrupt development.)

kernel/*.c is a pretty crowded place with 100+ files currently, I've been gradually working towards depopulating it slowly but surely for subsystems that I co-maintain or where I'm frequently active. We already have:

Quoted 8 lines

kernel/sched/
kernel/events/
kernel/irq/
kernel/time/
kernel/trace/

and the deeper kernel/*/* hierarchies already host another ~100 .c files. So the transition is half done already I suspect.

Should I be thinking about making a kernel/rcu?

Thanx, Paul

#39 lore raw
Quoted 35 lines · Paul E. McKenney
Quoted 34 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

Do you also want to suck in semaphore.c mutex.c rwsem.c spinlock.c etc? Or do you want to create something like kernel/locking/ for all that.

Yeah, I think kernel/locking/ would be a suitable place for those, and I'd move lockdep*.c there too. (Such things are best done near the end of a merge window, when there's not much pending, to not disrupt development.)

kernel/*.c is a pretty crowded place with 100+ files currently, I've been gradually working towards depopulating it slowly but surely for subsystems that I co-maintain or where I'm frequently active. We already have:

kernel/sched/
kernel/events/
kernel/irq/
kernel/time/
kernel/trace/

Quoted 4 lines
Quoted 2 lines

and the deeper kernel/*/* hierarchies already host another ~100 .c files. So the transition is half done already I suspect.

Should I be thinking about making a kernel/rcu?

I wanted to raise it with you at the KS :-)

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

But it's really your call, this is something you should only do if you are comfortable with it.

Thanks,

Ingo

author maintainer
#40 lore raw
Quoted 8 lines · Ingo Molnar

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

But it's really your call, this is something you should only do if you are comfortable with it.

IFF we're going to restructure rcu; can we save the CPP some work and do away with rcu*_plugin.h ?

#41 lore raw
Quoted 4 lines · Peter Zijlstra
Quoted 3 lines · Ingo Molnar

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

Quoted 8 lines
Quoted 5 lines

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

But it's really your call, this is something you should only do if you are comfortable with it.

IFF we're going to restructure rcu; can we save the CPP some work and do away with rcu*_plugin.h ?

OK, I'll bite... Where did you want to put the code instead?

Thanx, Paul

author maintainer
#42 lore raw
Quoted 8 lines · Paul E. McKenney
Quoted 7 lines · Peter Zijlstra
Quoted 6 lines · Ingo Molnar

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

But it's really your call, this is something you should only do if you are comfortable with it.

IFF we're going to restructure rcu; can we save the CPP some work and do away with rcu*_plugin.h ?

OK, I'll bite... Where did you want to put the code instead?

Just about here:

kernel/rcutree.c:#include "rcutree_plugin.h"

and save the bother of inclusion.

#43 lore raw
Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · Paul E. McKenney
Quoted 12 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

But it's really your call, this is something you should only do if you are comfortable with it.

IFF we're going to restructure rcu; can we save the CPP some work and do away with rcu*_plugin.h ?

Quoted 7 lines
Quoted 1 line

OK, I'll bite... Where did you want to put the code instead?

Just about here:

kernel/rcutree.c:#include "rcutree_plugin.h"

and save the bother of inclusion.

I would be more likely to break rcutree_plugin.h into pieces (e.g., for preempt-rcu, RCU_FAST_NOHZ, NOCB, stall warnings, and so on than to merge it into rcutree.c.

Thanx, Paul

#44 lore raw
In reply to Ingo Molnar
Quoted 38 lines · Ingo Molnar
Quoted 35 lines · Paul E. McKenney
Quoted 34 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

Do you also want to suck in semaphore.c mutex.c rwsem.c spinlock.c etc? Or do you want to create something like kernel/locking/ for all that.

Yeah, I think kernel/locking/ would be a suitable place for those, and I'd move lockdep*.c there too. (Such things are best done near the end of a merge window, when there's not much pending, to not disrupt development.)

kernel/*.c is a pretty crowded place with 100+ files currently, I've been gradually working towards depopulating it slowly but surely for subsystems that I co-maintain or where I'm frequently active. We already have:

kernel/sched/
kernel/events/
kernel/irq/
kernel/time/
kernel/trace/

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

and the deeper kernel/*/* hierarchies already host another ~100 .c files. So the transition is half done already I suspect.

Should I be thinking about making a kernel/rcu?

I wanted to raise it with you at the KS :-)

Sorry for jumping the gun. ;-)

Quoted 5 lines

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

Ooh... I had better act fast! ;-)

Quoted 2 lines

But it's really your call, this is something you should only do if you are comfortable with it.

I have actually been thinking about it off and on for some time.

Thanx, Paul

#45 lore raw
Quoted 54 lines · Paul E. McKenney
Quoted 38 lines · Ingo Molnar
Quoted 35 lines · Paul E. McKenney
Quoted 34 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

slightly related; do we want to do something like the following two patches?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

and

Yeah, both look good to me - but I'd move them into kernel/sched/completion.c and kernel/sched/wait.c if no-one objects.

Do you also want to suck in semaphore.c mutex.c rwsem.c spinlock.c etc? Or do you want to create something like kernel/locking/ for all that.

Yeah, I think kernel/locking/ would be a suitable place for those, and I'd move lockdep*.c there too. (Such things are best done near the end of a merge window, when there's not much pending, to not disrupt development.)

kernel/*.c is a pretty crowded place with 100+ files currently, I've been gradually working towards depopulating it slowly but surely for subsystems that I co-maintain or where I'm frequently active. We already have:

kernel/sched/
kernel/events/
kernel/irq/
kernel/time/
kernel/trace/

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

and the deeper kernel/*/* hierarchies already host another ~100 .c files. So the transition is half done already I suspect.

Should I be thinking about making a kernel/rcu?

I wanted to raise it with you at the KS :-)

Sorry for jumping the gun. ;-)

Quoted 5 lines

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

Quoted 6 lines

Ooh... I had better act fast! ;-)

Quoted 2 lines

But it's really your call, this is something you should only do if you are comfortable with it.

I have actually been thinking about it off and on for some time.

And here is a first cut. Just the renaming and needed adjustments, no splitting or merging of files.

Thoughts?

Thanx, Paul

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

kernel/Makefile +3 -8
index 1ce47553fb02..f99d908b5550 100644
@@ -6,9 +6,9 @@ obj-y     = fork.o exec_domain.o panic.o \
 	    cpu.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
-	    rcupdate.o extable.o params.o posix-timers.o \
+	    extable.o params.o posix-timers.o \
 	    kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
-	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
+	    hrtimer.o rwsem.o nsproxy.o semaphore.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o groups.o lglock.o smpboot.o
 
@@ -27,6 +27,7 @@ obj-y += power/
 obj-y += printk/
 obj-y += cpu/
 obj-y += irq/
+obj-y += rcu/
 
 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
 obj-$(CONFIG_FREEZER) += freezer.o
@@ -81,12 +82,6 @@ obj-$(CONFIG_KGDB) += debug/
 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
 obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
 obj-$(CONFIG_SECCOMP) += seccomp.o
-obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
-obj-$(CONFIG_TREE_RCU) += rcutree.o
-obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o
-obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o
-obj-$(CONFIG_TINY_RCU) += rcutiny.o
-obj-$(CONFIG_TINY_PREEMPT_RCU) += rcutiny.o
 obj-$(CONFIG_RELAY) += relay.o
 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
kernel/rcu/Makefile new file +6 -0
new file mode 100644
index 000000000000..01e9ec37a3e3
@@ -0,0 +1,6 @@
+obj-y += update.o srcu.o
+obj-$(CONFIG_RCU_TORTURE_TEST) += torture.o
+obj-$(CONFIG_TREE_RCU) += tree.o
+obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o
+obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o
+obj-$(CONFIG_TINY_RCU) += tiny.o
kernel/rcu/rcu.h renamed from kernel/rcu.h +0 -0
similarity index 100%
rename from kernel/rcu.h
rename to kernel/rcu/rcu.h
kernel/rcu/srcu.c renamed from kernel/srcu.c +0 -0
similarity index 100%
rename from kernel/srcu.c
rename to kernel/rcu/srcu.c
kernel/rcu/tiny.c renamed from kernel/rcutiny.c +2 -2
similarity index 99%
rename from kernel/rcutiny.c
rename to kernel/rcu/tiny.c
index 312e9709713f..238bb39b71c6 100644
@@ -43,7 +43,7 @@
 
 #include "rcu.h"
 
-/* Forward declarations for rcutiny_plugin.h. */
+/* Forward declarations for tiny_plugin.h. */
 struct rcu_ctrlblk;
 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
 static void rcu_process_callbacks(struct softirq_action *unused);
@@ -53,7 +53,7 @@ static void __call_rcu(struct rcu_head *head,
 
 static long long rcu_dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
 
-#include "rcutiny_plugin.h"
+#include "tiny_plugin.h"
 
 /* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcutree.c. */
 static void rcu_idle_enter_common(long long newval)
kernel/rcu/tiny_plugin.h renamed from kernel/rcutiny_plugin.h +0 -0
similarity index 100%
rename from kernel/rcutiny_plugin.h
rename to kernel/rcu/tiny_plugin.h
kernel/rcu/torture.c renamed from kernel/rcutorture.c +0 -0
similarity index 100%
rename from kernel/rcutorture.c
rename to kernel/rcu/torture.c
kernel/rcu/tree.c renamed from kernel/rcutree.c +3 -3
similarity index 99%
rename from kernel/rcutree.c
rename to kernel/rcu/tree.c
index 240604aa3f70..52b67ee63a0b 100644
@@ -56,7 +56,7 @@
 #include <linux/ftrace_event.h>
 #include <linux/suspend.h>
 
-#include "rcutree.h"
+#include "tree.h"
 #include <trace/events/rcu.h>
 
 #include "rcu.h"
@@ -3298,7 +3298,7 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 
 /*
  * Compute the rcu_node tree geometry from kernel parameters.  This cannot
- * replace the definitions in rcutree.h because those are needed to size
+ * replace the definitions in tree.h because those are needed to size
  * the ->node array in the rcu_state structure.
  */
 static void __init rcu_init_geometry(void)
@@ -3393,4 +3393,4 @@ void __init rcu_init(void)
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
 }
 
-#include "rcutree_plugin.h"
+#include "tree_plugin.h"
kernel/rcu/tree.h renamed from kernel/rcutree.h +0 -0
similarity index 100%
rename from kernel/rcutree.h
rename to kernel/rcu/tree.h
kernel/rcu/tree_plugin.h renamed from kernel/rcutree_plugin.h +1 -1
similarity index 99%
rename from kernel/rcutree_plugin.h
rename to kernel/rcu/tree_plugin.h
index 8d85a5ce093a..8ca07e3d9f9b 100644
@@ -28,7 +28,7 @@
 #include <linux/gfp.h>
 #include <linux/oom.h>
 #include <linux/smpboot.h>
-#include "time/tick-internal.h"
+#include "../time/tick-internal.h"
 
 #define RCU_KTHREAD_PRIO 1
 
kernel/rcu/tree_trace.c renamed from kernel/rcutree_trace.c +1 -1
similarity index 99%
rename from kernel/rcutree_trace.c
rename to kernel/rcu/tree_trace.c
index cf6c17412932..3596797b7e46 100644
@@ -44,7 +44,7 @@
 #include <linux/seq_file.h>
 
 #define RCU_TREE_NONCORE
-#include "rcutree.h"
+#include "tree.h"
 
 static int r_open(struct inode *inode, struct file *file,
 					const struct seq_operations *op)
kernel/rcu/update.c renamed from kernel/rcupdate.c +0 -0
similarity index 100%
rename from kernel/rcupdate.c
rename to kernel/rcu/update.c
#46 lore raw
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Paul E. McKenney

On Tue, Oct 08, 2013 at 09:47:18PM +0200, Ingo Molnar wrote:

[ . . . ]

Quoted 17 lines
Quoted 17 lines
Quoted 3 lines
Quoted 1 line

Should I be thinking about making a kernel/rcu?

I wanted to raise it with you at the KS :-)

Sorry for jumping the gun. ;-)

Quoted 5 lines

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

Ooh... I had better act fast! ;-)

Quoted 2 lines

But it's really your call, this is something you should only do if you are comfortable with it.

Quoted 6 lines
Quoted 1 line

I have actually been thinking about it off and on for some time.

And here is a first cut. Just the renaming and needed adjustments, no splitting or merging of files.

Thoughts?

Wow! I rebased my commits destined for 3.14 on top of this, and "git rebase" did it with several protests, but with no manual intervention required.

Now if it actually still builds, boots, and runs... ;-)

Thanx, Paul

Reviewed-by
#47 lore raw
Quoted 25 lines · Paul E. McKenney
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Paul E. McKenney

On Tue, Oct 08, 2013 at 09:47:18PM +0200, Ingo Molnar wrote:

[ . . . ]

Quoted 19 lines
Quoted 18 lines
Quoted 3 lines
Quoted 1 line

Should I be thinking about making a kernel/rcu?

I wanted to raise it with you at the KS :-)

Sorry for jumping the gun. ;-)

Quoted 5 lines

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

Ooh... I had better act fast! ;-)

Quoted 2 lines

But it's really your call, this is something you should only do if you are comfortable with it.

I have actually been thinking about it off and on for some time.

Quoted 8 lines
Quoted 4 lines

And here is a first cut. Just the renaming and needed adjustments, no splitting or merging of files.

Thoughts?

Wow! I rebased my commits destined for 3.14 on top of this, and "git rebase" did it with several protests, but with no manual intervention required.

Git is cool!

Quoted 1 line

Now if it actually still builds, boots, and runs... ;-)

Booting is overrated! ;-)

Seriously, this is good stuff.

I'd definitely argue in favor of doing a mechanical move first, then any further reorganization separately.

(One minor detail I noticed: you'll probably need to update the RCU file patterns in MAINTAINERS as well.)

Thanks,

Ingo

#48 lore raw
Quoted 31 lines · Ingo Molnar
Quoted 28 lines · Paul E. McKenney
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Paul E. McKenney

On Tue, Oct 08, 2013 at 09:47:18PM +0200, Ingo Molnar wrote:

[ . . . ]

Quoted 22 lines
Quoted 12 lines
Quoted 3 lines
Quoted 1 line

Should I be thinking about making a kernel/rcu?

I wanted to raise it with you at the KS :-)

Sorry for jumping the gun. ;-)

Quoted 5 lines

To me it would sure look nice to have kernel/rcu/tree.c, kernel/rcu/tiny.c, kernel/rcu/core.c, etc.

[ ... and we would certainly also break new ground by introducing a
"torture.c" file, for the first time in Linux kernel history! ;-) ]

Quoted 6 lines

Ooh... I had better act fast! ;-)

Quoted 2 lines

But it's really your call, this is something you should only do if you are comfortable with it.

I have actually been thinking about it off and on for some time.

And here is a first cut. Just the renaming and needed adjustments, no splitting or merging of files.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Thoughts?

Wow! I rebased my commits destined for 3.14 on top of this, and "git rebase" did it with several protests, but with no manual intervention required.

Git is cool!

I have indeed learned to love it through a long series of experiences like this! ;-)

Quoted 3 lines
Quoted 1 line

Now if it actually still builds, boots, and runs... ;-)

Booting is overrated! ;-)

Well, some work is needed on this front, but will get there.

Quoted 3 lines

Seriously, this is good stuff.

Very good, I have added this.

Quoted 5 lines

I'd definitely argue in favor of doing a mechanical move first, then any further reorganization separately.

(One minor detail I noticed: you'll probably need to update the RCU file patterns in MAINTAINERS as well.)

Ah, good point, fixed!

Thanx, Paul

Reviewed-by Ingo Molnar
#49 lore raw
Quoted 1 line · Paul E. McKenney

On Wed, Oct 09, 2013 at 08:08:06AM +0200, Ingo Molnar wrote:

[ . . . ]

Quoted 12 lines
Quoted 3 lines
Quoted 1 line

Now if it actually still builds, boots, and runs... ;-)

Booting is overrated! ;-)

Well, some work is needed on this front, but will get there.

Quoted 3 lines

Seriously, this is good stuff.

Very good, I have added this.

Quoted 7 lines
Quoted 5 lines

I'd definitely argue in favor of doing a mechanical move first, then any further reorganization separately.

(One minor detail I noticed: you'll probably need to update the RCU file patterns in MAINTAINERS as well.)

Ah, good point, fixed!

And it now builds, boots, and passes short rcutorture tests, updated patch below.

One side-effect is the boot parameters, namely that what used to be rcutree.blimit=10 is now simply tree.blimit=10. Not a problem for me, I just made my test scripts probe the source tree and generate the corresponding format. But is there some straightforward way to get the name of the "rcu" directory involved? The obvious approach of "rcu.tree.blimit=10" does not work -- the kernel happily ignores any such parameter.

It looks like I should be able to do something like the following in kernel/rcu/tree.c to get back the old parameter names:

MODULE_ALIAS("rcutree");
#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
#define MODULE_PARAM_PREFIX "rcutree."

And similarly for rcu/update.c and rcu/torture.c.

In fact, it looks like I could make rcu/update.c also use either the "rcutree." or "rcutiny." prefix, depending on which was being built.

Any thoughts, cautions, or suggestions?

Thanx, Paul

 b/Documentation/DocBook/device-drivers.tmpl |    5 
 b/Documentation/RCU/stallwarn.txt           |    4 
 b/Documentation/kernel-parameters.txt       |  257 ++++++++++++++--------------
 b/MAINTAINERS                               |   11 -
 b/kernel/Makefile                           |   11 -
 b/kernel/rcu/Makefile                       |    6 
 b/kernel/rcu/tiny.c                         |    8 
 b/kernel/rcu/tree.c                         |    6 
 b/kernel/rcu/tree_plugin.h                  |    4 
 b/kernel/rcu/tree_trace.c                   |    2 
 10 files changed, 168 insertions(+), 146 deletions(-)

rcu: Move RCU-related source code to kernel/rcu directory

Documentation/DocBook/device-drivers.tmpl +4 -1
index fe397f90a34f..6c9d9d37c83a 100644
@@ -87,7 +87,10 @@ X!Iinclude/linux/kobject.h
 !Ekernel/printk/printk.c
 !Ekernel/panic.c
 !Ekernel/sys.c
-!Ekernel/rcupdate.c
+!Ekernel/rcu/srcu.c
+!Ekernel/rcu/tree.c
+!Ekernel/rcu/tree_plugin.h
+!Ekernel/rcu/update.c
      </sect1>
 
      <sect1><title>Device Resource Management</title>
Documentation/RCU/stallwarn.txt +2 -2
index 6f3a0057548e..934448acdfbe 100644
@@ -15,7 +15,7 @@ CONFIG_RCU_CPU_STALL_TIMEOUT
 	21 seconds.
 
 	This configuration parameter may be changed at runtime via the
-	/sys/module/rcutree/parameters/rcu_cpu_stall_timeout, however
+	/sys/module/tree/parameters/rcu_cpu_stall_timeout, however
 	this parameter is checked only at the beginning of a cycle.
 	So if you are 10 seconds into a 40-second stall, setting this
 	sysfs parameter to (say) five will shorten the timeout for the
@@ -24,7 +24,7 @@ CONFIG_RCU_CPU_STALL_TIMEOUT
 	timing of the next warning for the current stall.
 
 	Stall-warning messages may be enabled and disabled completely via
-	/sys/module/rcutree/parameters/rcu_cpu_stall_suppress.
+	/sys/module/tree/parameters/rcu_cpu_stall_suppress.
 
 CONFIG_RCU_CPU_STALL_VERBOSE
 
Documentation/kernel-parameters.txt +137 -120

281 lines not on this page · raw message

MAINTAINERS +6 -5
index e61c2e83fc2b..28f2478b6794 100644
@@ -6903,7 +6903,7 @@ M:	"Paul E. McKenney" <[email protected]>
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
 F:	Documentation/RCU/torture.txt
-F:	kernel/rcutorture.c
+F:	kernel/rcu/torture.c
 
 RDC R-321X SoC
 M:	Florian Fainelli <[email protected]>
@@ -6930,8 +6930,9 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
 F:	Documentation/RCU/
 X:	Documentation/RCU/torture.txt
 F:	include/linux/rcu*
-F:	kernel/rcu*
-X:	kernel/rcutorture.c
+X:	include/linux/srcu.h
+F:	kernel/rcu/
+X:	kernel/rcu/torture.c
 
 REAL TIME CLOCK (RTC) SUBSYSTEM
 M:	Alessandro Zummo <[email protected]>
@@ -7618,8 +7619,8 @@ M:	"Paul E. McKenney" <[email protected]>
 W:	http://www.rdrop.com/users/paulmck/RCU/
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
-F:	include/linux/srcu*
-F:	kernel/srcu*
+F:	include/linux/srcu.h
+F:	kernel/rcu/srcu.c
 
 SMACK SECURITY MODULE
 M:	Casey Schaufler <[email protected]>
kernel/Makefile +3 -8
index 1ce47553fb02..f99d908b5550 100644
@@ -6,9 +6,9 @@ obj-y     = fork.o exec_domain.o panic.o \
 	    cpu.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
-	    rcupdate.o extable.o params.o posix-timers.o \
+	    extable.o params.o posix-timers.o \
 	    kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
-	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
+	    hrtimer.o rwsem.o nsproxy.o semaphore.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o groups.o lglock.o smpboot.o
 
@@ -27,6 +27,7 @@ obj-y += power/
 obj-y += printk/
 obj-y += cpu/
 obj-y += irq/
+obj-y += rcu/
 
 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
 obj-$(CONFIG_FREEZER) += freezer.o
@@ -81,12 +82,6 @@ obj-$(CONFIG_KGDB) += debug/
 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
 obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
 obj-$(CONFIG_SECCOMP) += seccomp.o
-obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
-obj-$(CONFIG_TREE_RCU) += rcutree.o
-obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o
-obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o
-obj-$(CONFIG_TINY_RCU) += rcutiny.o
-obj-$(CONFIG_TINY_PREEMPT_RCU) += rcutiny.o
 obj-$(CONFIG_RELAY) += relay.o
 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
kernel/rcu/Makefile new file +6 -0
new file mode 100644
index 000000000000..01e9ec37a3e3
@@ -0,0 +1,6 @@
+obj-y += update.o srcu.o
+obj-$(CONFIG_RCU_TORTURE_TEST) += torture.o
+obj-$(CONFIG_TREE_RCU) += tree.o
+obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o
+obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o
+obj-$(CONFIG_TINY_RCU) += tiny.o
kernel/rcu/rcu.h renamed from kernel/rcu.h +0 -0
similarity index 100%
rename from kernel/rcu.h
rename to kernel/rcu/rcu.h
kernel/rcu/srcu.c renamed from kernel/srcu.c +0 -0
similarity index 100%
rename from kernel/srcu.c
rename to kernel/rcu/srcu.c
kernel/rcu/tiny.c renamed from kernel/rcutiny.c +4 -4
similarity index 97%
rename from kernel/rcutiny.c
rename to kernel/rcu/tiny.c
index 312e9709713f..0c9a934cfec1 100644
@@ -43,7 +43,7 @@
 
 #include "rcu.h"
 
-/* Forward declarations for rcutiny_plugin.h. */
+/* Forward declarations for tiny_plugin.h. */
 struct rcu_ctrlblk;
 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
 static void rcu_process_callbacks(struct softirq_action *unused);
@@ -53,7 +53,7 @@ static void __call_rcu(struct rcu_head *head,
 
 static long long rcu_dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
 
-#include "rcutiny_plugin.h"
+#include "tiny_plugin.h"
 
 /* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcutree.c. */
 static void rcu_idle_enter_common(long long newval)
@@ -67,7 +67,7 @@ static void rcu_idle_enter_common(long long newval)
 	RCU_TRACE(trace_rcu_dyntick(TPS("Start"),
 				    rcu_dynticks_nesting, newval));
 	if (!is_idle_task(current)) {
-		struct task_struct *idle = idle_task(smp_processor_id());
+		struct task_struct *idle __maybe_unused = idle_task(smp_processor_id());
 
 		RCU_TRACE(trace_rcu_dyntick(TPS("Entry error: not idle task"),
 					    rcu_dynticks_nesting, newval));
@@ -128,7 +128,7 @@ static void rcu_idle_exit_common(long long oldval)
 	}
 	RCU_TRACE(trace_rcu_dyntick(TPS("End"), oldval, rcu_dynticks_nesting));
 	if (!is_idle_task(current)) {
-		struct task_struct *idle = idle_task(smp_processor_id());
+		struct task_struct *idle __maybe_unused = idle_task(smp_processor_id());
 
 		RCU_TRACE(trace_rcu_dyntick(TPS("Exit error: not idle task"),
 			  oldval, rcu_dynticks_nesting));
kernel/rcu/tiny_plugin.h renamed from kernel/rcutiny_plugin.h +0 -0
similarity index 100%
rename from kernel/rcutiny_plugin.h
rename to kernel/rcu/tiny_plugin.h
kernel/rcu/torture.c renamed from kernel/rcutorture.c +0 -0
similarity index 100%
rename from kernel/rcutorture.c
rename to kernel/rcu/torture.c
kernel/rcu/tree.c renamed from kernel/rcutree.c +3 -3
similarity index 99%
rename from kernel/rcutree.c
rename to kernel/rcu/tree.c
index 240604aa3f70..52b67ee63a0b 100644
@@ -56,7 +56,7 @@
 #include <linux/ftrace_event.h>
 #include <linux/suspend.h>
 
-#include "rcutree.h"
+#include "tree.h"
 #include <trace/events/rcu.h>
 
 #include "rcu.h"
@@ -3298,7 +3298,7 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 
 /*
  * Compute the rcu_node tree geometry from kernel parameters.  This cannot
- * replace the definitions in rcutree.h because those are needed to size
+ * replace the definitions in tree.h because those are needed to size
  * the ->node array in the rcu_state structure.
  */
 static void __init rcu_init_geometry(void)
@@ -3393,4 +3393,4 @@ void __init rcu_init(void)
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
 }
 
-#include "rcutree_plugin.h"
+#include "tree_plugin.h"
kernel/rcu/tree.h renamed from kernel/rcutree.h +0 -0
similarity index 100%
rename from kernel/rcutree.h
rename to kernel/rcu/tree.h
kernel/rcu/tree_plugin.h renamed from kernel/rcutree_plugin.h +2 -2
similarity index 99%
rename from kernel/rcutree_plugin.h
rename to kernel/rcu/tree_plugin.h
index 8d85a5ce093a..3822ac0c4b27 100644
@@ -28,7 +28,7 @@
 #include <linux/gfp.h>
 #include <linux/oom.h>
 #include <linux/smpboot.h>
-#include "time/tick-internal.h"
+#include "../time/tick-internal.h"
 
 #define RCU_KTHREAD_PRIO 1
 
@@ -1133,7 +1133,7 @@ void exit_rcu(void)
 
 #ifdef CONFIG_RCU_BOOST
 
-#include "rtmutex_common.h"
+#include "../rtmutex_common.h"
 
 #ifdef CONFIG_RCU_TRACE
 
kernel/rcu/tree_trace.c renamed from kernel/rcutree_trace.c +1 -1
similarity index 99%
rename from kernel/rcutree_trace.c
rename to kernel/rcu/tree_trace.c
index cf6c17412932..3596797b7e46 100644
@@ -44,7 +44,7 @@
 #include <linux/seq_file.h>
 
 #define RCU_TREE_NONCORE
-#include "rcutree.h"
+#include "tree.h"
 
 static int r_open(struct inode *inode, struct file *file,
 					const struct seq_operations *op)
kernel/rcu/update.c renamed from kernel/rcupdate.c +0 -0
similarity index 100%
rename from kernel/rcupdate.c
rename to kernel/rcu/update.c
#50 lore raw
Quoted 10 lines · Paul E. McKenney

And it now builds, boots, and passes short rcutorture tests, updated patch below.

One side-effect is the boot parameters, namely that what used to be rcutree.blimit=10 is now simply tree.blimit=10. Not a problem for me, I just made my test scripts probe the source tree and generate the corresponding format. But is there some straightforward way to get the name of the "rcu" directory involved? The obvious approach of "rcu.tree.blimit=10" does not work -- the kernel happily ignores any such parameter.

Hm, that boot option parser attitude is a bit sad - more structure to boot parameters is IMHO a Good Thing.

Does it accept :

	rcu/tree/blimit=10

	rcu/tree.blimit=10

type of structure perhaps?

Quoted 9 lines

It looks like I should be able to do something like the following in kernel/rcu/tree.c to get back the old parameter names:

MODULE_ALIAS("rcutree");
#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
#define MODULE_PARAM_PREFIX "rcutree."

Yeah.

( To keep it simple, the undef should be unnecessary, it's not like anyone
can slip in a MODULE_PARAM_PREFIX without you noticing, right? )

Quoted 6 lines

And similarly for rcu/update.c and rcu/torture.c.

In fact, it looks like I could make rcu/update.c also use either the "rcutree." or "rcutiny." prefix, depending on which was being built.

Any thoughts, cautions, or suggestions?

Still looks nice to me!

Thanks,

Ingo

Reviewed-by Ingo Molnar Reviewed-by Ingo Molnar
#51 lore raw
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Paul E. McKenney

And it now builds, boots, and passes short rcutorture tests, updated patch below.

One side-effect is the boot parameters, namely that what used to be rcutree.blimit=10 is now simply tree.blimit=10. Not a problem for me, I just made my test scripts probe the source tree and generate the corresponding format. But is there some straightforward way to get the name of the "rcu" directory involved? The obvious approach of "rcu.tree.blimit=10" does not work -- the kernel happily ignores any such parameter.

Quoted 2 lines

Hm, that boot option parser attitude is a bit sad - more structure to boot parameters is IMHO a Good Thing.

No argument here!

Quoted 7 lines

Does it accept :

	rcu/tree/blimit=10

	rcu/tree.blimit=10

type of structure perhaps?

Unfortunately, no. :-(

Quoted 9 lines
Quoted 8 lines

It looks like I should be able to do something like the following in kernel/rcu/tree.c to get back the old parameter names:

MODULE_ALIAS("rcutree");
#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
#define MODULE_PARAM_PREFIX "rcutree."

Quoted 4 lines

Yeah.

( To keep it simple, the undef should be unnecessary, it's not like anyone
can slip in a MODULE_PARAM_PREFIX without you noticing, right? )

Works with the #undef, trying it without it... And it works, but I do get the following complaint from the compiler:

/home/paulmck/public_git/linux-rcu/kernel/rcu/tree.c:66:0: warning: "MODULE_PARAM_PREFIX" redefined [enabled by default] /home/paulmck/public_git/linux-rcu/include/linux/moduleparam.h:13:0: note: this is the location of the previous definition

The problem is that moduleparam.h contains the following:

#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."

So the #undef is ugly, but better than the compiler warning. :-(

Quoted 8 lines
Quoted 6 lines

And similarly for rcu/update.c and rcu/torture.c.

In fact, it looks like I could make rcu/update.c also use either the "rcutree." or "rcutiny." prefix, depending on which was being built.

Any thoughts, cautions, or suggestions?

Still looks nice to me!

Glad you like it! ;-)

Updated patch below. The prefix change thrash was useful, as it rubbed my face in the fact that I needed to update the kernel-parameter.txt file. Some times you get lucky!

Would you like this for the upcoming 3.13 merge window, or would it be better for 3.14?

Thanx, Paul

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

rcu: Move RCU-related source code to kernel/rcu directory

 b/Documentation/DocBook/device-drivers.tmpl |    5 +
 b/Documentation/kernel-parameters.txt       |   95 ++++++++++++++++------------
 b/MAINTAINERS                               |   11 +--
 b/kernel/Makefile                           |   11 ---
 b/kernel/rcu/Makefile                       |    6 +
 b/kernel/rcu/tiny.c                         |    8 +-
 b/kernel/rcu/torture.c                      |    6 +
 b/kernel/rcu/tree.c                         |   13 ++-
 b/kernel/rcu/tree_plugin.h                  |    4 -
 b/kernel/rcu/tree_trace.c                   |    2 
 b/kernel/rcu/update.c                       |    6 +
 11 files changed, 105 insertions(+), 62 deletions(-)

rcu: Move RCU-related source code to kernel/rcu directory

Documentation/DocBook/device-drivers.tmpl +4 -1
index fe397f90a34f..6c9d9d37c83a 100644
@@ -87,7 +87,10 @@ X!Iinclude/linux/kobject.h
 !Ekernel/printk/printk.c
 !Ekernel/panic.c
 !Ekernel/sys.c
-!Ekernel/rcupdate.c
+!Ekernel/rcu/srcu.c
+!Ekernel/rcu/tree.c
+!Ekernel/rcu/tree_plugin.h
+!Ekernel/rcu/update.c
      </sect1>
 
      <sect1><title>Device Resource Management</title>
Documentation/kernel-parameters.txt +57 -38

197 lines not on this page · raw message

MAINTAINERS +6 -5
index e61c2e83fc2b..28f2478b6794 100644
@@ -6903,7 +6903,7 @@ M:	"Paul E. McKenney" <[email protected]>
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
 F:	Documentation/RCU/torture.txt
-F:	kernel/rcutorture.c
+F:	kernel/rcu/torture.c
 
 RDC R-321X SoC
 M:	Florian Fainelli <[email protected]>
@@ -6930,8 +6930,9 @@ T:	git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
 F:	Documentation/RCU/
 X:	Documentation/RCU/torture.txt
 F:	include/linux/rcu*
-F:	kernel/rcu*
-X:	kernel/rcutorture.c
+X:	include/linux/srcu.h
+F:	kernel/rcu/
+X:	kernel/rcu/torture.c
 
 REAL TIME CLOCK (RTC) SUBSYSTEM
 M:	Alessandro Zummo <[email protected]>
@@ -7618,8 +7619,8 @@ M:	"Paul E. McKenney" <[email protected]>
 W:	http://www.rdrop.com/users/paulmck/RCU/
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
-F:	include/linux/srcu*
-F:	kernel/srcu*
+F:	include/linux/srcu.h
+F:	kernel/rcu/srcu.c
 
 SMACK SECURITY MODULE
 M:	Casey Schaufler <[email protected]>
kernel/Makefile +3 -8
index 1ce47553fb02..f99d908b5550 100644
@@ -6,9 +6,9 @@ obj-y     = fork.o exec_domain.o panic.o \
 	    cpu.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
 	    signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
-	    rcupdate.o extable.o params.o posix-timers.o \
+	    extable.o params.o posix-timers.o \
 	    kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
-	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
+	    hrtimer.o rwsem.o nsproxy.o semaphore.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o groups.o lglock.o smpboot.o
 
@@ -27,6 +27,7 @@ obj-y += power/
 obj-y += printk/
 obj-y += cpu/
 obj-y += irq/
+obj-y += rcu/
 
 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
 obj-$(CONFIG_FREEZER) += freezer.o
@@ -81,12 +82,6 @@ obj-$(CONFIG_KGDB) += debug/
 obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
 obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o
 obj-$(CONFIG_SECCOMP) += seccomp.o
-obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
-obj-$(CONFIG_TREE_RCU) += rcutree.o
-obj-$(CONFIG_TREE_PREEMPT_RCU) += rcutree.o
-obj-$(CONFIG_TREE_RCU_TRACE) += rcutree_trace.o
-obj-$(CONFIG_TINY_RCU) += rcutiny.o
-obj-$(CONFIG_TINY_PREEMPT_RCU) += rcutiny.o
 obj-$(CONFIG_RELAY) += relay.o
 obj-$(CONFIG_SYSCTL) += utsname_sysctl.o
 obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o
kernel/rcu/Makefile new file +6 -0
new file mode 100644
index 000000000000..01e9ec37a3e3
@@ -0,0 +1,6 @@
+obj-y += update.o srcu.o
+obj-$(CONFIG_RCU_TORTURE_TEST) += torture.o
+obj-$(CONFIG_TREE_RCU) += tree.o
+obj-$(CONFIG_TREE_PREEMPT_RCU) += tree.o
+obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o
+obj-$(CONFIG_TINY_RCU) += tiny.o
kernel/rcu/rcu.h renamed from kernel/rcu.h +0 -0
similarity index 100%
rename from kernel/rcu.h
rename to kernel/rcu/rcu.h
kernel/rcu/srcu.c renamed from kernel/srcu.c +0 -0
similarity index 100%
rename from kernel/srcu.c
rename to kernel/rcu/srcu.c
kernel/rcu/tiny.c renamed from kernel/rcutiny.c +4 -4
similarity index 97%
rename from kernel/rcutiny.c
rename to kernel/rcu/tiny.c
index 312e9709713f..0c9a934cfec1 100644
@@ -43,7 +43,7 @@
 
 #include "rcu.h"
 
-/* Forward declarations for rcutiny_plugin.h. */
+/* Forward declarations for tiny_plugin.h. */
 struct rcu_ctrlblk;
 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
 static void rcu_process_callbacks(struct softirq_action *unused);
@@ -53,7 +53,7 @@ static void __call_rcu(struct rcu_head *head,
 
 static long long rcu_dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
 
-#include "rcutiny_plugin.h"
+#include "tiny_plugin.h"
 
 /* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcutree.c. */
 static void rcu_idle_enter_common(long long newval)
@@ -67,7 +67,7 @@ static void rcu_idle_enter_common(long long newval)
 	RCU_TRACE(trace_rcu_dyntick(TPS("Start"),
 				    rcu_dynticks_nesting, newval));
 	if (!is_idle_task(current)) {
-		struct task_struct *idle = idle_task(smp_processor_id());
+		struct task_struct *idle __maybe_unused = idle_task(smp_processor_id());
 
 		RCU_TRACE(trace_rcu_dyntick(TPS("Entry error: not idle task"),
 					    rcu_dynticks_nesting, newval));
@@ -128,7 +128,7 @@ static void rcu_idle_exit_common(long long oldval)
 	}
 	RCU_TRACE(trace_rcu_dyntick(TPS("End"), oldval, rcu_dynticks_nesting));
 	if (!is_idle_task(current)) {
-		struct task_struct *idle = idle_task(smp_processor_id());
+		struct task_struct *idle __maybe_unused = idle_task(smp_processor_id());
 
 		RCU_TRACE(trace_rcu_dyntick(TPS("Exit error: not idle task"),
 			  oldval, rcu_dynticks_nesting));
kernel/rcu/tiny_plugin.h renamed from kernel/rcutiny_plugin.h +0 -0
similarity index 100%
rename from kernel/rcutiny_plugin.h
rename to kernel/rcu/tiny_plugin.h
kernel/rcu/torture.c renamed from kernel/rcutorture.c +6 -0
similarity index 99%
rename from kernel/rcutorture.c
rename to kernel/rcu/torture.c
index be63101c6175..3929cd451511 100644
@@ -52,6 +52,12 @@
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Paul E. McKenney <[email protected]> and Josh Triplett <[email protected]>");
 
+MODULE_ALIAS("rcutorture");
+#ifdef MODULE_PARAM_PREFIX
+#undef MODULE_PARAM_PREFIX
+#endif
+#define MODULE_PARAM_PREFIX "rcutorture."
+
 static int fqs_duration;
 module_param(fqs_duration, int, 0444);
 MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us), 0 to disable");
kernel/rcu/tree.c renamed from kernel/rcutree.c +10 -3
similarity index 99%
rename from kernel/rcutree.c
rename to kernel/rcu/tree.c
index 240604aa3f70..8a2c81e86dda 100644
@@ -41,6 +41,7 @@
 #include <linux/export.h>
 #include <linux/completion.h>
 #include <linux/moduleparam.h>
+#include <linux/module.h>
 #include <linux/percpu.h>
 #include <linux/notifier.h>
 #include <linux/cpu.h>
@@ -56,11 +57,17 @@
 #include <linux/ftrace_event.h>
 #include <linux/suspend.h>
 
-#include "rcutree.h"
+#include "tree.h"
 #include <trace/events/rcu.h>
 
 #include "rcu.h"
 
+MODULE_ALIAS("rcutree");
+#ifdef MODULE_PARAM_PREFIX
+#undef MODULE_PARAM_PREFIX
+#endif
+#define MODULE_PARAM_PREFIX "rcutree."
+
 /* Data structures. */
 
 static struct lock_class_key rcu_node_class[RCU_NUM_LVLS];
@@ -3298,7 +3305,7 @@ static void __init rcu_init_one(struct rcu_state *rsp,
 
 /*
  * Compute the rcu_node tree geometry from kernel parameters.  This cannot
- * replace the definitions in rcutree.h because those are needed to size
+ * replace the definitions in tree.h because those are needed to size
  * the ->node array in the rcu_state structure.
  */
 static void __init rcu_init_geometry(void)
@@ -3393,4 +3400,4 @@ void __init rcu_init(void)
 		rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
 }
 
-#include "rcutree_plugin.h"
+#include "tree_plugin.h"
kernel/rcu/tree.h renamed from kernel/rcutree.h +0 -0
similarity index 100%
rename from kernel/rcutree.h
rename to kernel/rcu/tree.h
kernel/rcu/tree_plugin.h renamed from kernel/rcutree_plugin.h +2 -2
similarity index 99%
rename from kernel/rcutree_plugin.h
rename to kernel/rcu/tree_plugin.h
index 8d85a5ce093a..3822ac0c4b27 100644
@@ -28,7 +28,7 @@
 #include <linux/gfp.h>
 #include <linux/oom.h>
 #include <linux/smpboot.h>
-#include "time/tick-internal.h"
+#include "../time/tick-internal.h"
 
 #define RCU_KTHREAD_PRIO 1
 
@@ -1133,7 +1133,7 @@ void exit_rcu(void)
 
 #ifdef CONFIG_RCU_BOOST
 
-#include "rtmutex_common.h"
+#include "../rtmutex_common.h"
 
 #ifdef CONFIG_RCU_TRACE
 
kernel/rcu/tree_trace.c renamed from kernel/rcutree_trace.c +1 -1
similarity index 99%
rename from kernel/rcutree_trace.c
rename to kernel/rcu/tree_trace.c
index cf6c17412932..3596797b7e46 100644
@@ -44,7 +44,7 @@
 #include <linux/seq_file.h>
 
 #define RCU_TREE_NONCORE
-#include "rcutree.h"
+#include "tree.h"
 
 static int r_open(struct inode *inode, struct file *file,
 					const struct seq_operations *op)
kernel/rcu/update.c renamed from kernel/rcupdate.c +6 -0
similarity index 98%
rename from kernel/rcupdate.c
rename to kernel/rcu/update.c
index c07af1c4e1bb..6cb3dff89e2b 100644
@@ -53,6 +53,12 @@
 
 #include "rcu.h"
 
+MODULE_ALIAS("rcupdate");
+#ifdef MODULE_PARAM_PREFIX
+#undef MODULE_PARAM_PREFIX
+#endif
+#define MODULE_PARAM_PREFIX "rcupdate."
+
 module_param(rcu_expedited, int, 0);
 
 #ifdef CONFIG_PREEMPT_RCU
#52 lore raw
Quoted 22 lines · Paul E. McKenney
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Paul E. McKenney

And it now builds, boots, and passes short rcutorture tests, updated patch below.

One side-effect is the boot parameters, namely that what used to be rcutree.blimit=10 is now simply tree.blimit=10. Not a problem for me, I just made my test scripts probe the source tree and generate the corresponding format. But is there some straightforward way to get the name of the "rcu" directory involved? The obvious approach of "rcu.tree.blimit=10" does not work -- the kernel happily ignores any such parameter.

Quoted 2 lines

Hm, that boot option parser attitude is a bit sad - more structure to boot parameters is IMHO a Good Thing.

No argument here!

Quoted 2 lines

Does it accept :

Quoted 7 lines
Quoted 5 lines
	rcu/tree/blimit=10

	rcu/tree.blimit=10

type of structure perhaps?

Unfortunately, no. :-(

So, I think this code lives within kernel/params.c. Might be fixable?

Quoted 18 lines
Quoted 10 lines
Quoted 9 lines

It looks like I should be able to do something like the following in kernel/rcu/tree.c to get back the old parameter names:

MODULE_ALIAS("rcutree");
#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
#define MODULE_PARAM_PREFIX "rcutree."

Quoted 4 lines

Yeah.

( To keep it simple, the undef should be unnecessary, it's not like anyone
can slip in a MODULE_PARAM_PREFIX without you noticing, right? )

Works with the #undef, trying it without it... And it works, but I do get the following complaint from the compiler:

Quoted 8 lines

/home/paulmck/public_git/linux-rcu/kernel/rcu/tree.c:66:0: warning: "MODULE_PARAM_PREFIX" redefined [enabled by default] /home/paulmck/public_git/linux-rcu/include/linux/moduleparam.h:13:0: note: this is the location of the previous definition

The problem is that moduleparam.h contains the following:

#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."

So the #undef is ugly, but better than the compiler warning. :-(

agreed.

Thanks,

Ingo

#53 lore raw
Quoted 27 lines · Ingo Molnar
Quoted 24 lines · Paul E. McKenney
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Paul E. McKenney

And it now builds, boots, and passes short rcutorture tests, updated patch below.

One side-effect is the boot parameters, namely that what used to be rcutree.blimit=10 is now simply tree.blimit=10. Not a problem for me, I just made my test scripts probe the source tree and generate the corresponding format. But is there some straightforward way to get the name of the "rcu" directory involved? The obvious approach of "rcu.tree.blimit=10" does not work -- the kernel happily ignores any such parameter.

Quoted 2 lines

Hm, that boot option parser attitude is a bit sad - more structure to boot parameters is IMHO a Good Thing.

No argument here!

Quoted 4 lines

Does it accept :

	rcu/tree/blimit=10
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
	rcu/tree.blimit=10

type of structure perhaps?

Unfortunately, no. :-(

So, I think this code lives within kernel/params.c. Might be fixable?

But of course! I was just trying to be lazy. ;-)

I could imagine adding a filename field to struct kernel_param that was initialized with __FILE__, then making something like parameq() that did the appropriate comparison allowing any match starting after a "/" and ignoring the trailing ".h" or ".c", and then calling that from parse_one() along with current parameq(). There doesn't seem to be any point for doing the same to do_early_param().

There would be a few surprises with this approach, for example, rcu_idle_gp_delay and rcu_idle_lazy_gp_delay, which are defined in kernel/rcu/tree_plugin.h, would be:

	tree_plugin.rcu_idle_gp_delay=4
	tree_plugin.rcu_idle_lazy_gp_delay=6000

or:

	rcu/tree_plugin.rcu_idle_gp_delay=4
	rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

or:

	kernel/rcu/tree_plugin.rcu_idle_gp_delay=4
	kernel/rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

or I suppose even:

linux-rcu/kernel/rcu/tree_plugin.rcu_idle_gp_delay=4 linux-rcu/kernel/rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

instead of (say):

	kernel/rcu/tree.rcu_idle_gp_delay=4
	kernel/rcu/tree.rcu_idle_lazy_gp_delay=6000

This could of course also be fixed by comparing the filename up to the last "/" followed by the current parameter name. Or, as Peter Zijlstra suggested, by manually expanding kernel/rcu/tree_plugin.h into kernel/rcu/tree.c.

Or I could use the non-standard __BASE_FILE__ instead of __FILE__, which expands to .../kernel/rcu/tree.c. LLVM seems to define this as well, so should be OK to use.

So it doesn't look too horrible. (Famous last words...)

Thoughts?

Quoted 37 lines
Quoted 17 lines
Quoted 9 lines
Quoted 8 lines

It looks like I should be able to do something like the following in kernel/rcu/tree.c to get back the old parameter names:

MODULE_ALIAS("rcutree");
#ifdef MODULE_PARAM_PREFIX
#undef MODULE_PARAM_PREFIX
#endif
#define MODULE_PARAM_PREFIX "rcutree."

Quoted 4 lines

Yeah.

( To keep it simple, the undef should be unnecessary, it's not like anyone
can slip in a MODULE_PARAM_PREFIX without you noticing, right? )

Works with the #undef, trying it without it... And it works, but I do get the following complaint from the compiler:

Quoted 8 lines

/home/paulmck/public_git/linux-rcu/kernel/rcu/tree.c:66:0: warning: "MODULE_PARAM_PREFIX" redefined [enabled by default] /home/paulmck/public_git/linux-rcu/include/linux/moduleparam.h:13:0: note: this is the location of the previous definition

The problem is that moduleparam.h contains the following:

#define MODULE_PARAM_PREFIX KBUILD_MODNAME "."

So the #undef is ugly, but better than the compiler warning. :-(

agreed.

Thanks,

Ingo
--
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/

#54 lore raw
Quoted 43 lines · Paul E. McKenney
Quoted 1 line

So, I think this code lives within kernel/params.c. Might be fixable?

But of course! I was just trying to be lazy. ;-)

I could imagine adding a filename field to struct kernel_param that was initialized with __FILE__, then making something like parameq() that did the appropriate comparison allowing any match starting after a "/" and ignoring the trailing ".h" or ".c", and then calling that from parse_one() along with current parameq(). There doesn't seem to be any point for doing the same to do_early_param().

There would be a few surprises with this approach, for example, rcu_idle_gp_delay and rcu_idle_lazy_gp_delay, which are defined in kernel/rcu/tree_plugin.h, would be:

	tree_plugin.rcu_idle_gp_delay=4
	tree_plugin.rcu_idle_lazy_gp_delay=6000

or:

	rcu/tree_plugin.rcu_idle_gp_delay=4
	rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

or:

	kernel/rcu/tree_plugin.rcu_idle_gp_delay=4
	kernel/rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

or I suppose even:

linux-rcu/kernel/rcu/tree_plugin.rcu_idle_gp_delay=4 linux-rcu/kernel/rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

instead of (say):

	kernel/rcu/tree.rcu_idle_gp_delay=4
	kernel/rcu/tree.rcu_idle_lazy_gp_delay=6000

This could of course also be fixed by comparing the filename up to the last "/" followed by the current parameter name. Or, as Peter Zijlstra suggested, by manually expanding kernel/rcu/tree_plugin.h into kernel/rcu/tree.c.

Quoted 5 lines

Or I could use the non-standard __BASE_FILE__ instead of __FILE__, which expands to .../kernel/rcu/tree.c. LLVM seems to define this as well, so should be OK to use.

So it doesn't look too horrible. (Famous last words...)

Hm, I'm not so sure about the long names, for the following reasons:
strings like 'kernel/rcu/tree_plugin.' might mean a lot to us kernel developers - less to sysadmins and users who would want to utilize them.

There's also a typo danger with overly long parameters and the parameter parser is not very intelligent about seeing the intent of the user.

So I think while rcu/tree.val would be useful syntax, going above that, especially with auto-generated file names (and file names can change) would be overdoing it a bit :-/

Thanks,

Ingo

#55 lore raw
Quoted 50 lines · Ingo Molnar
Quoted 47 lines · Paul E. McKenney
Quoted 1 line

So, I think this code lives within kernel/params.c. Might be fixable?

But of course! I was just trying to be lazy. ;-)

I could imagine adding a filename field to struct kernel_param that was initialized with __FILE__, then making something like parameq() that did the appropriate comparison allowing any match starting after a "/" and ignoring the trailing ".h" or ".c", and then calling that from parse_one() along with current parameq(). There doesn't seem to be any point for doing the same to do_early_param().

There would be a few surprises with this approach, for example, rcu_idle_gp_delay and rcu_idle_lazy_gp_delay, which are defined in kernel/rcu/tree_plugin.h, would be:

	tree_plugin.rcu_idle_gp_delay=4
	tree_plugin.rcu_idle_lazy_gp_delay=6000

or:

	rcu/tree_plugin.rcu_idle_gp_delay=4
	rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

or:

	kernel/rcu/tree_plugin.rcu_idle_gp_delay=4
	kernel/rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

or I suppose even:

linux-rcu/kernel/rcu/tree_plugin.rcu_idle_gp_delay=4 linux-rcu/kernel/rcu/tree_plugin.rcu_idle_lazy_gp_delay=6000

instead of (say):

	kernel/rcu/tree.rcu_idle_gp_delay=4
	kernel/rcu/tree.rcu_idle_lazy_gp_delay=6000

This could of course also be fixed by comparing the filename up to the last "/" followed by the current parameter name. Or, as Peter Zijlstra suggested, by manually expanding kernel/rcu/tree_plugin.h into kernel/rcu/tree.c.

Or I could use the non-standard __BASE_FILE__ instead of __FILE__, which expands to .../kernel/rcu/tree.c. LLVM seems to define this as well, so should be OK to use.

Quoted 5 lines
Quoted 1 line

So it doesn't look too horrible. (Famous last words...)

Hm, I'm not so sure about the long names, for the following reasons:
strings like 'kernel/rcu/tree_plugin.' might mean a lot to us kernel developers - less to sysadmins and users who would want to utilize them.

Good point!

Plus some people building kernels might not be so happy to have the full path names to their build trees hard-coded into the kernel. And the people wanting tiny kernels wouldn't be happy about that much useless text appearing in the kernel that many times.

Quoted 6 lines

There's also a typo danger with overly long parameters and the parameter parser is not very intelligent about seeing the intent of the user.

So I think while rcu/tree.val would be useful syntax, going above that, especially with auto-generated file names (and file names can change) would be overdoing it a bit :-/

Keeping rcutree.val is useful because there are systems that already use some of those boot parameters. I could use backslash as a wildcard that matches "/", "_", or nothingness, thus matching rcutree.val, rcu/tree.val, and rcu_tree.val, with something like the patch below, but I am not sure that it is really worthwhile.

Thanx, Paul

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

kernel/params.c +17 -2
index 81c4e78..2711c39 100644
@@ -70,10 +70,25 @@ static char dash2underscore(char c)
 bool parameqn(const char *a, const char *b, size_t n)
 {
 	size_t i;
+	size_t j = 0;
 
 	for (i = 0; i < n; i++) {
-		if (dash2underscore(a[i]) != dash2underscore(b[i]))
-			return false;
+		if (b[j] == '\\') {
+			j++;
+			if (a[i] == '/' || a[i] == '_')
+				continue;
+			/*
+			 * A backslash is permitted to match nothingness, so
+			 * skip it and try the input character against the next
+			 * pattern character.
+			 */
+			i--;
+			continue;
+		} else if (dash2underscore(a[i]) == dash2underscore(b[j])) {
+			j++;
+			continue;
+		}
+		return false;
 	}
 	return true;
 }
kernel/rcu/torture.c +1 -1
index 69a4ec8..b3ed1e0 100644
@@ -56,7 +56,7 @@ MODULE_ALIAS("rcutorture");
 #ifdef MODULE_PARAM_PREFIX
 #undef MODULE_PARAM_PREFIX
 #endif
-#define MODULE_PARAM_PREFIX "rcutorture."
+#define MODULE_PARAM_PREFIX "rcu\\torture."
 
 static int fqs_duration;
 module_param(fqs_duration, int, 0444);
kernel/rcu/tree.c +1 -1
index 875f2a0..3dc63ee 100644
@@ -66,7 +66,7 @@ MODULE_ALIAS("rcutree");
 #ifdef MODULE_PARAM_PREFIX
 #undef MODULE_PARAM_PREFIX
 #endif
-#define MODULE_PARAM_PREFIX "rcutree."
+#define MODULE_PARAM_PREFIX "rcu\\tree."
 
 /* Data structures. */
 
kernel/rcu/update.c +1 -1
index 6cb3dff..2439516 100644
@@ -57,7 +57,7 @@ MODULE_ALIAS("rcupdate");
 #ifdef MODULE_PARAM_PREFIX
 #undef MODULE_PARAM_PREFIX
 #endif
-#define MODULE_PARAM_PREFIX "rcupdate."
+#define MODULE_PARAM_PREFIX "rcu\\pdate."
 
 module_param(rcu_expedited, int, 0);