From ccb13fe7d9d5a1d2a92ec16fd4d7b5521aaf67d4 Mon Sep 17 00:00:00 2001 From: Alfred Chen Date: Thu, 2 Sep 2021 16:19:32 +0000 Subject: [PATCH] sched/alt: Fix for v5.14-prjc-r0 fails on x86 UP build Mainline add some sched-core related api which cause below fails on x86 UP build, #30. --- kernel/sched/alt_core.c | 24 ++++++++++++++++++++++++ kernel/sched/alt_sched.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/kernel/sched/alt_core.c b/kernel/sched/alt_core.c index 5df1157a597cb9..bdff1c65e2e9d8 100644 --- a/kernel/sched/alt_core.c +++ b/kernel/sched/alt_core.c @@ -492,6 +492,30 @@ rq_unlock_irqrestore(struct rq *rq, struct rq_flags *rf) raw_spin_unlock_irqrestore(&rq->lock, rf->flags); } +void raw_spin_rq_lock_nested(struct rq *rq, int subclass) +{ + raw_spinlock_t *lock; + + /* Matches synchronize_rcu() in __sched_core_enable() */ + preempt_disable(); + + for (;;) { + lock = __rq_lockp(rq); + raw_spin_lock_nested(lock, subclass); + if (likely(lock == __rq_lockp(rq))) { + /* preempt_count *MUST* be > 1 */ + preempt_enable_no_resched(); + return; + } + raw_spin_unlock(lock); + } +} + +void raw_spin_rq_unlock(struct rq *rq) +{ + raw_spin_unlock(rq_lockp(rq)); +} + /* * RQ-clock updating methods: */ diff --git a/kernel/sched/alt_sched.h b/kernel/sched/alt_sched.h index 7a48809550bf5a..f03af9ab9123cd 100644 --- a/kernel/sched/alt_sched.h +++ b/kernel/sched/alt_sched.h @@ -443,6 +443,36 @@ this_rq_lock_irq(struct rq_flags *rf) return rq; } +extern void raw_spin_rq_lock_nested(struct rq *rq, int subclass); +extern void raw_spin_rq_unlock(struct rq *rq); + +static inline raw_spinlock_t *__rq_lockp(struct rq *rq) +{ + return &rq->lock; +} + +static inline raw_spinlock_t *rq_lockp(struct rq *rq) +{ + return __rq_lockp(rq); +} + +static inline void raw_spin_rq_lock(struct rq *rq) +{ + raw_spin_rq_lock_nested(rq, 0); +} + +static inline void raw_spin_rq_lock_irq(struct rq *rq) +{ + local_irq_disable(); + raw_spin_rq_lock(rq); +} + +static inline void raw_spin_rq_unlock_irq(struct rq *rq) +{ + raw_spin_rq_unlock(rq); + local_irq_enable(); +} + static inline int task_current(struct rq *rq, struct task_struct *p) { return rq->curr == p;