* [PATCH] sched: simplify is_cpu_allowed() code
@ 2021-05-18 12:54 Yejune Deng
2021-05-18 13:27 ` Peter Zijlstra
0 siblings, 1 reply; 3+ messages in thread
From: Yejune Deng @ 2021-05-18 12:54 UTC (permalink / raw)
To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
rostedt, bsegall, mgorman, bristot
Cc: linux-kernel, Yejune Deng
Combine multiple if statements that return the same value.
Signed-off-by: Yejune Deng <yejunedeng@gmail.com>
---
kernel/sched/core.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3ab28de..b9b4452 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2153,26 +2153,18 @@ static inline bool rq_has_pinned_tasks(struct rq *rq)
*/
static inline bool is_cpu_allowed(struct task_struct *p, int cpu)
{
- /* When not in the task's cpumask, no point in looking further. */
- if (!cpumask_test_cpu(cpu, p->cpus_ptr))
+ /*
+ * When not in the task's cpumask, no point in looking further.
+ * Regular kernel threads don't get to stay during offline.
+ *
+ */
+ if (!cpumask_test_cpu(cpu, p->cpus_ptr) || cpu_dying(cpu))
return false;
- /* migrate_disabled() must be allowed to finish. */
- if (is_migration_disabled(p))
- return cpu_online(cpu);
-
/* Non kernel threads are not allowed during either online or offline. */
if (!(p->flags & PF_KTHREAD))
return cpu_active(cpu);
- /* KTHREAD_IS_PER_CPU is always allowed. */
- if (kthread_is_per_cpu(p))
- return cpu_online(cpu);
-
- /* Regular kernel threads don't get to stay during offline. */
- if (cpu_dying(cpu))
- return false;
-
/* But are allowed during online. */
return cpu_online(cpu);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] sched: simplify is_cpu_allowed() code
2021-05-18 12:54 [PATCH] sched: simplify is_cpu_allowed() code Yejune Deng
@ 2021-05-18 13:27 ` Peter Zijlstra
2021-05-18 13:48 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2021-05-18 13:27 UTC (permalink / raw)
To: Yejune Deng
Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
bsegall, mgorman, bristot, linux-kernel, Yejune Deng
On Tue, May 18, 2021 at 08:54:46PM +0800, Yejune Deng wrote:
> Combine multiple if statements that return the same value.
This patch is not a nop; You now deny cpu_dying() for everyone, while we
explicitly allow it for kthread_is_per_cpu().
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sched: simplify is_cpu_allowed() code
2021-05-18 13:27 ` Peter Zijlstra
@ 2021-05-18 13:48 ` Steven Rostedt
0 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-05-18 13:48 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Yejune Deng, mingo, juri.lelli, vincent.guittot, dietmar.eggemann,
bsegall, mgorman, bristot, linux-kernel, Yejune Deng
On Tue, 18 May 2021 15:27:46 +0200
Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, May 18, 2021 at 08:54:46PM +0800, Yejune Deng wrote:
> > Combine multiple if statements that return the same value.
>
> This patch is not a nop; You now deny cpu_dying() for everyone, while we
> explicitly allow it for kthread_is_per_cpu().
Right. The patch is flawed in many ways. You don't combine if statements
just because they return the same value, if you are messing with the order
of the checks.
if (A)
return false;
if (B)
return true;
if (C)
return false;
is not the same as
if (A || C)
return false
if (B)
return true;
Please don't do that.
-- Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-18 13:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-18 12:54 [PATCH] sched: simplify is_cpu_allowed() code Yejune Deng
2021-05-18 13:27 ` Peter Zijlstra
2021-05-18 13:48 ` Steven Rostedt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.