Skip to contentSkip to conversation

Issue with CONFIG_PREEMPT_VOLUNTARY

Xenomai New Gilles Chanteperdrix 2 participants 8 messages Oct 11, 2015 – Oct 12, 2015

lore
Share & tools
lore
#0 lore raw

Hi,

It seems commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0 in the I-pipe kernels cause a warning when CONFIG_PREEMPT_VOLUNTARY and CONFIG_IPIPE_DEBUG_INTERNAL are enabled. The culprit is the call to __ipipe_root_p.

The following patch avoids this warning:

kernel/ipipe/core.c +6 -4
index 0320453..a5e440d 100644
@@ -1730,17 +1730,19 @@ int notrace __ipipe_check_percpu_access(void)
 	if (raw_irqs_disabled_flags(flags))
 		goto out;
 
+	if (!IS_ENABLED(CONFIG_PREEMPT_COUNT))
+		goto out;
+
 	/*
 	 * Last chance: hw interrupts were enabled on entry while
 	 * running over the root domain, but the root stage might be
 	 * currently stalled, in which case preemption would be
 	 * disabled, and no migration could occur.
 	 */
-	if (this_domain == ipipe_root_domain) {
-		p = raw_cpu_ptr(&ipipe_percpu.root);
-		if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
+
+	p = raw_cpu_ptr(&ipipe_percpu.root);
+	if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
 			goto out;
-	}
 	/*
 	 * Our caller may end up accessing the wrong per-cpu variable
 	 * instance due to CPU migration; tell it to complain about
Signature · 2 lines
					    Gilles.
https://click-hack.org
#1 lore raw
Quoted 6 lines · Gilles Chanteperdrix

Hi,

It seems commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0 in the I-pipe kernels cause a warning when CONFIG_PREEMPT_VOLUNTARY and CONFIG_IPIPE_DEBUG_INTERNAL are enabled. The culprit is the call to __ipipe_root_p.

Compiler warning? Runtime warning? Which architecture? I assume that ftrace is on then, right?

Quoted 2 lines

The following patch avoids this warning:

How?

kernel/ipipe/core.c int notrace __ipipe_check_percpu_access(void) · line 1735

Quoted 12 lines
kernel/ipipe/core.c +3 -0
index 0320453..a5e440d 100644
@@ -1730,17 +1730,19 @@ int notrace __ipipe_check_percpu_access(void)
 	if (raw_irqs_disabled_flags(flags))
 		goto out;
 
+	if (!IS_ENABLED(CONFIG_PREEMPT_COUNT))
+		goto out;
+

This approach looks a bit odd, but I simply may not understand it yet. We need to know what it actually aims at, i.e. which line causes the error you see.

kernel/ipipe/core.c int notrace __ipipe_check_percpu_access(void) · line 1739

Quoted 7 lines
kernel/ipipe/core.c +0 -1
 	/*
 	 * Last chance: hw interrupts were enabled on entry while
 	 * running over the root domain, but the root stage might be
 	 * currently stalled, in which case preemption would be
 	 * disabled, and no migration could occur.
 	 */
-	if (this_domain == ipipe_root_domain) {

This test is indeed redundant, but removing it should be a separate patch with a commit log referring to the test that is not visible in the context.

kernel/ipipe/core.c int notrace __ipipe_check_percpu_access(void) · line 1745

Quoted 6 lines
kernel/ipipe/core.c +3 -2
-		p = raw_cpu_ptr(&ipipe_percpu.root);
-		if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
+
+	p = raw_cpu_ptr(&ipipe_percpu.root);
+	if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
 			goto out;

You probably want to adjust the indention of this line then.

kernel/ipipe/core.c int notrace __ipipe_check_percpu_access(void) · line 1748

Quoted 6 lines
kernel/ipipe/core.c +0 -1
-	}
 	/*
 	 * Our caller may end up accessing the wrong per-cpu variable
 	 * instance due to CPU migration; tell it to complain about

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 10 lines · Jan Kiszka
Quoted 6 lines · Gilles Chanteperdrix

Hi,

It seems commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0 in the I-pipe kernels cause a warning when CONFIG_PREEMPT_VOLUNTARY and CONFIG_IPIPE_DEBUG_INTERNAL are enabled. The culprit is the call to __ipipe_root_p.

Compiler warning? Runtime warning? Which architecture? I assume that ftrace is on then, right?

Yes. Because preempt_disable()/preempt_enable*() is a nop without CONFIG_PREEMPT_COUNT, __ipipe_root_p ends up being called without any protection, and __ipipe_check_percpu_access() emits the warning.

Quoted 5 lines
Quoted 3 lines

The following patch avoids this warning:

How?

It disables the test for preemption (the call to preempt_count()) in __ipipe_check_percpu_access() if CONFIG_PREEMPT_COUNT is disabled, because if it is disabled, you can not be preempted anywhere, so calling __ipipe_root_p without protection is valid. Or maybe not?

Signature · 2 lines
					    Gilles.
https://click-hack.org
#3 lore raw
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Gilles Chanteperdrix

Hi,

It seems commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0 in the I-pipe kernels cause a warning when CONFIG_PREEMPT_VOLUNTARY and CONFIG_IPIPE_DEBUG_INTERNAL are enabled. The culprit is the call to __ipipe_root_p.

Quoted 7 lines
Quoted 2 lines

Compiler warning? Runtime warning? Which architecture? I assume that ftrace is on then, right?

Yes. Because preempt_disable()/preempt_enable*() is a nop without CONFIG_PREEMPT_COUNT, __ipipe_root_p ends up being called without any protection, and __ipipe_check_percpu_access() emits the warning.

Makes sense.

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

The following patch avoids this warning:

How?

It disables the test for preemption (the call to preempt_count()) in __ipipe_check_percpu_access() if CONFIG_PREEMPT_COUNT is disabled, because if it is disabled, you can not be preempted anywhere, so calling __ipipe_root_p without protection is valid. Or maybe not?

Ah, ok. I was under the assumption preempt_count() would return a constant non-zero value under !CONFIG_PREEMPT. But on the other hand, that would be weird as well when triggering voluntary preemption then.

Anyway, it's correct that preemption cannot happen then in the middle of an instruction, so we can skip the test. Please make the test depend on CONFIG_PREEMPT and leave a corresponding comment in the code.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#4 lore raw
Quoted 31 lines · Jan Kiszka
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Gilles Chanteperdrix

Hi,

It seems commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0 in the I-pipe kernels cause a warning when CONFIG_PREEMPT_VOLUNTARY and CONFIG_IPIPE_DEBUG_INTERNAL are enabled. The culprit is the call to __ipipe_root_p.

Quoted 7 lines
Quoted 2 lines

Compiler warning? Runtime warning? Which architecture? I assume that ftrace is on then, right?

Yes. Because preempt_disable()/preempt_enable*() is a nop without CONFIG_PREEMPT_COUNT, __ipipe_root_p ends up being called without any protection, and __ipipe_check_percpu_access() emits the warning.

Makes sense.

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

The following patch avoids this warning:

How?

It disables the test for preemption (the call to preempt_count()) in __ipipe_check_percpu_access() if CONFIG_PREEMPT_COUNT is disabled, because if it is disabled, you can not be preempted anywhere, so calling __ipipe_root_p without protection is valid. Or maybe not?

Quoted 7 lines

Ah, ok. I was under the assumption preempt_count() would return a constant non-zero value under !CONFIG_PREEMPT. But on the other hand, that would be weird as well when triggering voluntary preemption then.

Anyway, it's correct that preemption cannot happen then in the middle of an instruction, so we can skip the test. Please make the test depend on CONFIG_PREEMPT and leave a corresponding comment in the code.

maybe we could use preemptible()?

it should test both the stall flag and preempt_count with CONFIG_PREEMPT_COUNT and returns 0 without CONFIG_PREEMPT_COUNT.

Signature · 2 lines
					    Gilles.
https://click-hack.org
#5 lore raw
Quoted 36 lines · Gilles Chanteperdrix
Quoted 35 lines · Jan Kiszka
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · Jan Kiszka
Quoted 6 lines · Gilles Chanteperdrix

Hi,

It seems commit fdb5d54d04b8c3b6b6a6ad7ac2b6248cf0b415e0 in the I-pipe kernels cause a warning when CONFIG_PREEMPT_VOLUNTARY and CONFIG_IPIPE_DEBUG_INTERNAL are enabled. The culprit is the call to __ipipe_root_p.

Quoted 7 lines
Quoted 2 lines

Compiler warning? Runtime warning? Which architecture? I assume that ftrace is on then, right?

Yes. Because preempt_disable()/preempt_enable*() is a nop without CONFIG_PREEMPT_COUNT, __ipipe_root_p ends up being called without any protection, and __ipipe_check_percpu_access() emits the warning.

Makes sense.

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

The following patch avoids this warning:

How?

It disables the test for preemption (the call to preempt_count()) in __ipipe_check_percpu_access() if CONFIG_PREEMPT_COUNT is disabled, because if it is disabled, you can not be preempted anywhere, so calling __ipipe_root_p without protection is valid. Or maybe not?

Ah, ok. I was under the assumption preempt_count() would return a constant non-zero value under !CONFIG_PREEMPT. But on the other hand, that would be weird as well when triggering voluntary preemption then.

Quoted 8 lines
Quoted 3 lines

Anyway, it's correct that preemption cannot happen then in the middle of an instruction, so we can skip the test. Please make the test depend on CONFIG_PREEMPT and leave a corresponding comment in the code.

maybe we could use preemptible()?

it should test both the stall flag and preempt_count with CONFIG_PREEMPT_COUNT and returns 0 without CONFIG_PREEMPT_COUNT.

Indeed, even better. And self-documenting.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
#6 lore raw

PATCH 1/2 ipipe: simplify __ipipe_check_perccpu_access()

by removing a redundant test.

---
 kernel/ipipe/core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
kernel/ipipe/core.c +4 -5
index 0320453..b02883d 100644
@@ -1736,11 +1736,10 @@ int notrace __ipipe_check_percpu_access(void)
 	 * currently stalled, in which case preemption would be
 	 * disabled, and no migration could occur.
 	 */
-	if (this_domain == ipipe_root_domain) {
-		p = raw_cpu_ptr(&ipipe_percpu.root);
-		if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
-			goto out;
-	}
+
+	p = raw_cpu_ptr(&ipipe_percpu.root);
+	if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
+		goto out;
 	/*
 	 * Our caller may end up accessing the wrong per-cpu variable
 	 * instance due to CPU migration; tell it to complain about
Signature · 1 line
1.8.4
#7 lore raw

PATCH 2/2 ipipe: fix __ipipe_check_percpu_access()

Use preemptible() instead of testing the preempt_count and the stall flags, since using preemptible() also works when CONFIG_PREEMPT_COUNT is not defined.

---
 kernel/ipipe/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/ipipe/core.c +1 -1
index b02883d..d7c8934 100644
@@ -1738,7 +1738,7 @@ int notrace __ipipe_check_percpu_access(void)
 	 */
 
 	p = raw_cpu_ptr(&ipipe_percpu.root);
-	if (test_bit(IPIPE_STALL_FLAG, &p->status) || preempt_count())
+	if (!preemptible())
 		goto out;
 	/*
 	 * Our caller may end up accessing the wrong per-cpu variable
Signature · 1 line
1.8.4