* [PATCH] sched: replace if (cond) BUG() with BUG_ON()
@ 2021-03-17 2:45 Jiapeng Chong
2021-03-17 8:39 ` Ingo Molnar
0 siblings, 1 reply; 8+ messages in thread
From: Jiapeng Chong @ 2021-03-17 2:45 UTC (permalink / raw)
To: mingo
Cc: peterz, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
bsegall, mgorman, bristot, linux-kernel, Jiapeng Chong
Fix the following coccicheck warnings:
./kernel/sched/core.c:8039:2-5: WARNING: Use BUG_ON instead of if
condition followed by BUG.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
kernel/sched/core.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9819121..7392bc0 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8035,8 +8035,7 @@ void __init sched_init_smp(void)
mutex_unlock(&sched_domains_mutex);
/* Move init over to a non-isolated CPU */
- if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
- BUG();
+ BUG(set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0);
sched_init_granularity();
init_sched_rt_class();
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
2021-03-17 2:45 [PATCH] sched: replace if (cond) BUG() with BUG_ON() Jiapeng Chong
@ 2021-03-17 8:39 ` Ingo Molnar
2021-03-17 8:41 ` Ingo Molnar
0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2021-03-17 8:39 UTC (permalink / raw)
To: Jiapeng Chong
Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, bristot, linux-kernel
* Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:
> Fix the following coccicheck warnings:
>
> ./kernel/sched/core.c:8039:2-5: WARNING: Use BUG_ON instead of if
> condition followed by BUG.
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> kernel/sched/core.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 9819121..7392bc0 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8035,8 +8035,7 @@ void __init sched_init_smp(void)
> mutex_unlock(&sched_domains_mutex);
>
> /* Move init over to a non-isolated CPU */
> - if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
> - BUG();
> + BUG(set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0);
The patch doesn't quite do what the title & changelog claims...
Thanks,
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
2021-03-17 8:39 ` Ingo Molnar
@ 2021-03-17 8:41 ` Ingo Molnar
2021-03-17 12:55 ` Arnd Bergmann
0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2021-03-17 8:41 UTC (permalink / raw)
To: Jiapeng Chong
Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, bristot, linux-kernel
* Ingo Molnar <mingo@kernel.org> wrote:
>
> * Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:
>
> > Fix the following coccicheck warnings:
> >
> > ./kernel/sched/core.c:8039:2-5: WARNING: Use BUG_ON instead of if
> > condition followed by BUG.
> >
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> > ---
> > kernel/sched/core.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 9819121..7392bc0 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -8035,8 +8035,7 @@ void __init sched_init_smp(void)
> > mutex_unlock(&sched_domains_mutex);
> >
> > /* Move init over to a non-isolated CPU */
> > - if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
> > - BUG();
> > + BUG(set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0);
>
> The patch doesn't quite do what the title & changelog claims...
More importantly, we use this pattern when we don't want !CONFIG_BUG
to remove the 'condition'.
I.e. the "side effect" here is important scheduler logic. It must
never be optimized out.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
2021-03-17 8:41 ` Ingo Molnar
@ 2021-03-17 12:55 ` Arnd Bergmann
2021-03-17 20:05 ` Ingo Molnar
0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2021-03-17 12:55 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jiapeng Chong, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Daniel Bristot de Oliveira, linux-kernel
On Wed, Mar 17, 2021 at 9:45 AM Ingo Molnar <mingo@kernel.org> wrote:
> * Ingo Molnar <mingo@kernel.org> wrote:
> > * Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:
> >
> > > Fix the following coccicheck warnings:
> > >
> > > ./kernel/sched/core.c:8039:2-5: WARNING: Use BUG_ON instead of if
> > > condition followed by BUG.
> > >
> > > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> > > ---
> > > kernel/sched/core.c | 3 +--
> > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > index 9819121..7392bc0 100644
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -8035,8 +8035,7 @@ void __init sched_init_smp(void)
> > > mutex_unlock(&sched_domains_mutex);
> > >
> > > /* Move init over to a non-isolated CPU */
> > > - if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
> > > - BUG();
> > > + BUG(set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0);
> >
> > The patch doesn't quite do what the title & changelog claims...
>
> More importantly, we use this pattern when we don't want !CONFIG_BUG
> to remove the 'condition'.
>
> I.e. the "side effect" here is important scheduler logic. It must
> never be optimized out.
This behavior for !CONFIG_BUG has changed a while ago, it is now safe
to rely on the side-effect of the BUG_ON() condition regardless of
CONFIG_BUG. When that option is disabled, running into the condition
just ends up in a "do {} while (1)" loop.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
2021-03-17 12:55 ` Arnd Bergmann
@ 2021-03-17 20:05 ` Ingo Molnar
2021-03-17 21:38 ` Arnd Bergmann
0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2021-03-17 20:05 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jiapeng Chong, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Daniel Bristot de Oliveira, linux-kernel
* Arnd Bergmann <arnd@kernel.org> wrote:
> On Wed, Mar 17, 2021 at 9:45 AM Ingo Molnar <mingo@kernel.org> wrote:
> > * Ingo Molnar <mingo@kernel.org> wrote:
> > > * Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:
> > >
> > > > Fix the following coccicheck warnings:
> > > >
> > > > ./kernel/sched/core.c:8039:2-5: WARNING: Use BUG_ON instead of if
> > > > condition followed by BUG.
> > > >
> > > > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > > > Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> > > > ---
> > > > kernel/sched/core.c | 3 +--
> > > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > > >
> > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > > > index 9819121..7392bc0 100644
> > > > --- a/kernel/sched/core.c
> > > > +++ b/kernel/sched/core.c
> > > > @@ -8035,8 +8035,7 @@ void __init sched_init_smp(void)
> > > > mutex_unlock(&sched_domains_mutex);
> > > >
> > > > /* Move init over to a non-isolated CPU */
> > > > - if (set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0)
> > > > - BUG();
> > > > + BUG(set_cpus_allowed_ptr(current, housekeeping_cpumask(HK_FLAG_DOMAIN)) < 0);
> > >
> > > The patch doesn't quite do what the title & changelog claims...
> >
> > More importantly, we use this pattern when we don't want !CONFIG_BUG
> > to remove the 'condition'.
> >
> > I.e. the "side effect" here is important scheduler logic. It must
> > never be optimized out.
>
> This behavior for !CONFIG_BUG has changed a while ago, it is now safe
> to rely on the side-effect of the BUG_ON() condition regardless of
> CONFIG_BUG. When that option is disabled, running into the condition
> just ends up in a "do {} while (1)" loop.
Dunno, I still think it's not a particularly clean pattern to 'hide'
significant side effects within a BUG_ON().
Thanks,
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
2021-03-17 20:05 ` Ingo Molnar
@ 2021-03-17 21:38 ` Arnd Bergmann
0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2021-03-17 21:38 UTC (permalink / raw)
To: Ingo Molnar
Cc: Jiapeng Chong, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Daniel Bristot de Oliveira, linux-kernel
On Wed, Mar 17, 2021 at 9:05 PM Ingo Molnar <mingo@kernel.org> wrote:
> * Arnd Bergmann <arnd@kernel.org> wrote:
> > On Wed, Mar 17, 2021 at 9:45 AM Ingo Molnar <mingo@kernel.org> wrote:
> > >
> > > More importantly, we use this pattern when we don't want !CONFIG_BUG
> > > to remove the 'condition'.
> > >
> > > I.e. the "side effect" here is important scheduler logic. It must
> > > never be optimized out.
> >
> > This behavior for !CONFIG_BUG has changed a while ago, it is now safe
> > to rely on the side-effect of the BUG_ON() condition regardless of
> > CONFIG_BUG. When that option is disabled, running into the condition
> > just ends up in a "do {} while (1)" loop.
>
> Dunno, I still think it's not a particularly clean pattern to 'hide'
> significant side effects within a BUG_ON().
Fair enough. Readability really is the key here, and I agree the current
version is easier to understand. The only architectures that even define
an optimized BUG_ON() are mips and powerpc, and saving a few cycles
is barely worth it in a fast path, which this is clearly not.
Arnd
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] sched: replace if (cond) BUG() with BUG_ON()
2021-03-17 6:45 Jiapeng Chong
@ 2021-03-17 7:00 ` Christophe Leroy
0 siblings, 0 replies; 8+ messages in thread
From: Christophe Leroy @ 2021-03-17 7:00 UTC (permalink / raw)
To: Jiapeng Chong, jk; +Cc: arnd, linux-kernel, paulus, linuxppc-dev
Le 17/03/2021 à 07:45, Jiapeng Chong a écrit :
> Fix the following coccicheck warnings:
>
> ./arch/powerpc/platforms/cell/spufs/sched.c:908:2-5: WARNING: Use BUG_ON
> instead of if condition followed by BUG.
Consider using WARN_ON() instead of BUG_ON() if relevant. If not, explain in the commit message why
we need to keep a BUG_ON().
See https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
> arch/powerpc/platforms/cell/spufs/sched.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
> index 3692064..139a6ec 100644
> --- a/arch/powerpc/platforms/cell/spufs/sched.c
> +++ b/arch/powerpc/platforms/cell/spufs/sched.c
> @@ -904,8 +904,7 @@ static noinline void spusched_tick(struct spu_context *ctx)
> struct spu_context *new = NULL;
> struct spu *spu = NULL;
>
> - if (spu_acquire(ctx))
> - BUG(); /* a kernel thread never has signals pending */
> + BUG_ON(spu_acquire(ctx)); /* a kernel thread never has signals pending */
>
> if (ctx->state != SPU_STATE_RUNNABLE)
> goto out;
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] sched: replace if (cond) BUG() with BUG_ON()
@ 2021-03-17 6:45 Jiapeng Chong
2021-03-17 7:00 ` Christophe Leroy
0 siblings, 1 reply; 8+ messages in thread
From: Jiapeng Chong @ 2021-03-17 6:45 UTC (permalink / raw)
To: jk; +Cc: arnd, mpe, benh, paulus, linuxppc-dev, linux-kernel, Jiapeng Chong
Fix the following coccicheck warnings:
./arch/powerpc/platforms/cell/spufs/sched.c:908:2-5: WARNING: Use BUG_ON
instead of if condition followed by BUG.
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
arch/powerpc/platforms/cell/spufs/sched.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 3692064..139a6ec 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -904,8 +904,7 @@ static noinline void spusched_tick(struct spu_context *ctx)
struct spu_context *new = NULL;
struct spu *spu = NULL;
- if (spu_acquire(ctx))
- BUG(); /* a kernel thread never has signals pending */
+ BUG_ON(spu_acquire(ctx)); /* a kernel thread never has signals pending */
if (ctx->state != SPU_STATE_RUNNABLE)
goto out;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-03-17 21:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 2:45 [PATCH] sched: replace if (cond) BUG() with BUG_ON() Jiapeng Chong
2021-03-17 8:39 ` Ingo Molnar
2021-03-17 8:41 ` Ingo Molnar
2021-03-17 12:55 ` Arnd Bergmann
2021-03-17 20:05 ` Ingo Molnar
2021-03-17 21:38 ` Arnd Bergmann
2021-03-17 6:45 Jiapeng Chong
2021-03-17 7:00 ` Christophe Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).