Skip to contentSkip to conversation

Regression with wait_event_timeout in next-20140226

DISCUSSION Gregory CLEMENT 4 participants 7 messages Feb 26, 2014 – Apr 9, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

while testing next-20140226 I got an issue with the function wait_event_timeout. When this function timed out instead of returning 0, it returned the value of the timeout passed in parameter. I found that reverting "sched/wait: Suppress Sparse 'variable shadowing' warning" fixed this regression.

I got this issue in the driver drivers/i2c/busses/i2c-mv64xxx.c.

Thanks,

Gregory

Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
maintainer
#1 lore raw
Quoted 9 lines · Gregory CLEMENT

Hi,

while testing next-20140226 I got an issue with the function wait_event_timeout. When this function timed out instead of returning 0, it returned the value of the timeout passed in parameter. I found that reverting "sched/wait: Suppress Sparse 'variable shadowing' warning" fixed this regression.

I got this issue in the driver drivers/i2c/busses/i2c-mv64xxx.c.

Ah indeed. We actually rely on the shadowing for ___wait_cond_timeout().

We further used the __ret variable in __wait_event_timeout()'s cmd
argument: __ret = schedule_timeout(__ret). That now explicitly uses the wrong __ret.

Yeah, we need to pull that patch.

#2 lore raw
Quoted 11 lines · On Wed, 26 Feb 2014 17:50:43 +0100 Peter Zijlstra <[email protected]> wrote:
Quoted 9 lines · Gregory CLEMENT

Hi,

while testing next-20140226 I got an issue with the function wait_event_timeout. When this function timed out instead of returning 0, it returned the value of the timeout passed in parameter. I found that reverting "sched/wait: Suppress Sparse 'variable shadowing' warning" fixed this regression.

I got this issue in the driver drivers/i2c/busses/i2c-mv64xxx.c.

Quoted 7 lines

Ah indeed. We actually rely on the shadowing for ___wait_cond_timeout().

We further used the __ret variable in __wait_event_timeout()'s cmd
argument: __ret = schedule_timeout(__ret). That now explicitly uses the wrong __ret.

Yeah, we need to pull that patch.

Is there anything we can do to make all this clearer? Simply using a distinctive variable name ("__wait_var__"?) in place of __ret (and documenting it) would help a lot.

Some __ret's are long and some are int. Maybe that's a glitch, maybe it's because some __ret's are used for inter-macro communications and some are not, which just makes things worse.

I started to do a patch, got all confused and gave up. We've made quite a tangly mess in there, alas.

maintainer
#3 lore raw
Quoted 3 lines · Andrew Morton

Is there anything we can do to make all this clearer? Simply using a distinctive variable name ("__wait_var__"?) in place of __ret (and documenting it) would help a lot.

% s/\<__ret\>/__wait_var__/g should get you mostly there I suppose :-)

Although I'm not entirely sure __wait_var__ is a better name.

Quoted 1 line

Some __ret's are long and some are int. Maybe that's a glitch,

No that's on purpose.

The longs are needed to hold the timeout values, we truncate to an int where we only need to return errors.

Quoted 3 lines

maybe
it's because some __ret's are used for inter-macro communications and some are not, which just makes things worse.

The timeout related ones are the worst. The others aren't nearly as bad.

Quoted 2 lines

I started to do a patch, got all confused and gave up. We've made quite a tangly mess in there, alas.

Hehe, yes, made a lot of duplicated code go away though. Maybe we compressed too much, dunno.

maintainer
#4 lore raw
In reply to Andrew Morton
Quoted 10 lines · Andrew Morton

Is there anything we can do to make all this clearer? Simply using a distinctive variable name ("__wait_var__"?) in place of __ret (and documenting it) would help a lot.

Some __ret's are long and some are int. Maybe that's a glitch, maybe it's because some __ret's are used for inter-macro communications and some are not, which just makes things worse.

I started to do a patch, got all confused and gave up. We've made quite a tangly mess in there, alas.

Something like so?

---
Subject: wait: Explain the shadowing and type inconsistencies
From: Peter Zijlstra <[email protected]>
Date: Wed Apr 9 12:50:34 CEST 2014

Stick in a comment before someone else tries to fix the sparse warning this generates.

---
 include/linux/wait.h |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
include/linux/wait.h +13 -1
@@ -191,11 +191,23 @@ wait_queue_head_t *bit_waitqueue(void *,
 	(!__builtin_constant_p(state) ||				\
 		state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE)	\
 
+/*
+ * The below macro ___wait_event() has an explicit shadow of the __ret
+ * variable when used from the wait_event_*() macros.
+ *
+ * This is so that both can use the ___wait_cond_timeout() construct
+ * to wrap the condition.
+ *
+ * The type inconsistency of the wait_event_*() __ret variable is also
+ * on purpose; we use long where we can return timeout values and int
+ * otherwise.
+ */
+
 #define ___wait_event(wq, condition, state, exclusive, ret, cmd)	\
 ({									\
 	__label__ __out;						\
 	wait_queue_t __wait;						\
-	long __ret = ret;						\
+	long __ret = ret;	/* explicit shadow */			\
 									\
 	INIT_LIST_HEAD(&__wait.task_list);				\
 	if (exclusive)							\
#5 lore raw
Quoted 46 lines · On Wed, 9 Apr 2014 13:16:38 +0200 Peter Zijlstra <[email protected]> wrote:
Quoted 10 lines · Andrew Morton

Is there anything we can do to make all this clearer? Simply using a distinctive variable name ("__wait_var__"?) in place of __ret (and documenting it) would help a lot.

Some __ret's are long and some are int. Maybe that's a glitch, maybe it's because some __ret's are used for inter-macro communications and some are not, which just makes things worse.

I started to do a patch, got all confused and gave up. We've made quite a tangly mess in there, alas.

Something like so?

---
Subject: wait: Explain the shadowing and type inconsistencies
From: Peter Zijlstra <[email protected]>
Date: Wed Apr 9 12:50:34 CEST 2014

Stick in a comment before someone else tries to fix the sparse warning this generates.

---
 include/linux/wait.h |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
include/linux/wait.h +11 -0
@@ -191,11 +191,23 @@ wait_queue_head_t *bit_waitqueue(void *,
 	(!__builtin_constant_p(state) ||				\
 		state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE)	\
 
+/*
+ * The below macro ___wait_event() has an explicit shadow of the __ret
+ * variable when used from the wait_event_*() macros.
+ *
+ * This is so that both can use the ___wait_cond_timeout() construct
+ * to wrap the condition.
+ *
+ * The type inconsistency of the wait_event_*() __ret variable is also
+ * on purpose; we use long where we can return timeout values and int
+ * otherwise.
+ */

include/linux/wait.h wait_queue_head_t *bit_waitqueue(void *, · line 213

Quoted 10 lines
include/linux/wait.h +2 -1
+
 #define ___wait_event(wq, condition, state, exclusive, ret, cmd)	\
 ({									\
 	__label__ __out;						\
 	wait_queue_t __wait;						\
-	long __ret = ret;						\
+	long __ret = ret;	/* explicit shadow */			\
 									\
 	INIT_LIST_HEAD(&__wait.task_list);				\
 	if (exclusive)							\

Looks nice to me, thanks.

#6 lore raw
In reply to Peter Zijlstra

Hi Peter,

Quoted 11 lines · On Wed, 26 Feb 2014 17:50:43 +0100 Peter Zijlstra <[email protected]> wrote:
Quoted 8 lines · Gregory CLEMENT

while testing next-20140226 I got an issue with the function wait_event_timeout. When this function timed out instead of returning 0, it returned the value of the timeout passed in parameter. I found that reverting "sched/wait: Suppress Sparse 'variable shadowing' warning" fixed this regression.

I got this issue in the driver drivers/i2c/busses/i2c-mv64xxx.c.

Quoted 7 lines

Ah indeed. We actually rely on the shadowing for ___wait_cond_timeout().

We further used the __ret variable in __wait_event_timeout()'s cmd
argument: __ret = schedule_timeout(__ret). That now explicitly uses the wrong __ret.

Yeah, we need to pull that patch.

I have reverted that commit from linux-next for today pending some other resolution.

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]