2020-08-15 21:56:17

by Joel Fernandes

[permalink] [raw]
Subject: [PATCH RFC 12/12] sched/coresched: rq->core should be set only if not previously set

From: Vineeth Pillai <[email protected]>

During hotplug events, smt_mask would not contain all the CPUs in a core and
this can cause reassigning of rq->core, which breaks the core-wide counters
that are needed for tracking kernel-mode entry/exits.

This patch therefore makes sure that rq->core does not change once it is set.

Signed-off-by: Vineeth Pillai <[email protected]>
Signed-off-by: Joel Fernandes (Google) <[email protected]>
---
kernel/sched/core.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5da5b2317b21..464493f3a759 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7519,21 +7519,25 @@ int sched_cpu_starting(unsigned int cpu)
struct rq *rq, *core_rq = NULL;
int i;

- for_each_cpu(i, smt_mask) {
- rq = cpu_rq(i);
- if (rq->core && rq->core == rq)
- core_rq = rq;
- init_irq_work(&rq->core_irq_work, sched_core_irq_work);
- }
+ core_rq = cpu_rq(cpu)->core;
+
+ if (!core_rq) {
+ for_each_cpu(i, smt_mask) {
+ rq = cpu_rq(i);
+ if (rq->core && rq->core == rq)
+ core_rq = rq;
+ init_irq_work(&rq->core_irq_work, sched_core_irq_work);
+ }

- if (!core_rq)
- core_rq = cpu_rq(cpu);
+ if (!core_rq)
+ core_rq = cpu_rq(cpu);

- for_each_cpu(i, smt_mask) {
- rq = cpu_rq(i);
+ for_each_cpu(i, smt_mask) {
+ rq = cpu_rq(i);

- WARN_ON_ONCE(rq->core && rq->core != core_rq);
- rq->core = core_rq;
+ WARN_ON_ONCE(rq->core && rq->core != core_rq);
+ rq->core = core_rq;
+ }
}

printk("core: %d -> %d\n", cpu, cpu_of(core_rq));
--
2.28.0.220.ged08abb693-goog