2022-04-21 08:44:56

by Hao Jia

[permalink] [raw]
Subject: Re: [External] Re: [PATCH] sched/core: Avoid obvious double update_rq_clock warning



On 2022/4/21 Dietmar Eggemann wrote:
> On 20/04/2022 10:29, Hao Jia wrote:
>> On 4/19/22 6:48 PM, Peter Zijlstra wrote:
>>> On Mon, Apr 18, 2022 at 05:09:29PM +0800, Hao Jia wrote:
>
> [...]
>
>>> I'm really not sure about this part though. This is a bit of a mess. The
>>> balancer doesn't really need the pinning stuff. I realize you did that
>>> because we got the clock annotation mixed up with that, but urgh.
>>>
>>> Basically we want double_rq_lock() / double_lock_balance() to clear
>>> RQCF_UPDATED, right? Perhaps do that directly?
>>>
>>> (maybe with an inline helper and a wee comment?)
>>>
>>> The only immediate problem with this would appear to be that
>>> _double_rq_lock() behaves differently when it returns 0. Not sure that
>>> matters.
>>>
>>> Hmm?
>>
>> Thanks for your review comments.
>> As you have prompted, the WARN_DOUBLE_CLOCK warning is still triggered
>> when _double_rq_lock() returns 0.
>> Please review the solution below, and based on your review, I will
>> submit the v2 patch as soon as possible.
>> Thanks.
>
>
> [...]
>
> Maybe something like this:
>
> -->8--
>
> From: Dietmar Eggemann <[email protected]>
> Date: Wed, 20 Apr 2022 11:12:10 +0200
> Subject: [PATCH] sched/core: Clear RQCF_UPDATED in _double_lock_balance() &
> double_rq_lock()
>
> Signed-off-by: Dietmar Eggemann <[email protected]>
> ---
> kernel/sched/core.c | 6 +++---
> kernel/sched/sched.h | 20 ++++++++++++++++----
> 2 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 068c088e9584..f4cfe7eea861 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -610,10 +610,10 @@ void double_rq_lock(struct rq *rq1, struct rq *rq2)
> swap(rq1, rq2);
>
> raw_spin_rq_lock(rq1);
> - if (__rq_lockp(rq1) == __rq_lockp(rq2))
> - return;
> + if (__rq_lockp(rq1) != __rq_lockp(rq2))
> + raw_spin_rq_lock_nested(rq2, SINGLE_DEPTH_NESTING);
>
> - raw_spin_rq_lock_nested(rq2, SINGLE_DEPTH_NESTING);
> + rq_clock_clear_update(rq1, rq2);
> }
> #endif
>
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 58263f90c559..3a77b10d7cc4 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -2515,6 +2515,16 @@ static inline bool rq_order_less(struct rq *rq1, struct rq *rq2)
>
> extern void double_rq_lock(struct rq *rq1, struct rq *rq2);
>
> +#ifdef CONFIG_SCHED_DEBUG
> +static inline void rq_clock_clear_update(struct rq *rq1, struct rq *rq2)
> +{
> + rq1->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
> + rq2->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
> +}
> +#else
> +static inline void rq_clock_clear_update(struct rq *rq1, struct rq *rq2) {}
> +#endif
> +
> #ifdef CONFIG_PREEMPTION
>
> /*
> @@ -2549,14 +2559,15 @@ static inline int _double_lock_balance(struct rq *this_rq, struct rq *busiest)
> __acquires(busiest->lock)
> __acquires(this_rq->lock)
> {
> - if (__rq_lockp(this_rq) == __rq_lockp(busiest))
> - return 0;
> -
> - if (likely(raw_spin_rq_trylock(busiest)))
> + if (__rq_lockp(this_rq) == __rq_lockp(busiest) ||
> + likely(raw_spin_rq_trylock(busiest))) {
> + rq_clock_clear_update(this_rq, busiest);
> return 0;
> + }
>
> if (rq_order_less(this_rq, busiest)) {
> raw_spin_rq_lock_nested(busiest, SINGLE_DEPTH_NESTING);
> + rq_clock_clear_update(this_rq, busiest);
> return 0;
> }
>
> @@ -2650,6 +2661,7 @@ static inline void double_rq_lock(struct rq *rq1, struct rq *rq2)
> BUG_ON(rq1 != rq2);
> raw_spin_rq_lock(rq1);
> __acquire(rq2->lock); /* Fake it out ;) */
> + rq_clock_clear_update(rq1, rq2);

Thanks for your review.
This is very helpful to me.
If CONFIG_SMP is not enabled, should we just clear the RQCF_UPDATED of
one of rq1 and q2?

like this:
rq1->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);

Thanks.

> }
>
> /*


2022-04-22 22:19:17

by Dietmar Eggemann

[permalink] [raw]
Subject: Re: [External] Re: [PATCH] sched/core: Avoid obvious double update_rq_clock warning

On 21/04/2022 09:24, Hao Jia wrote:
> On 2022/4/21 Dietmar Eggemann wrote:
>> On 20/04/2022 10:29, Hao Jia wrote:
>>> On 4/19/22 6:48 PM, Peter Zijlstra wrote:
>>>> On Mon, Apr 18, 2022 at 05:09:29PM +0800, Hao Jia wrote:

[...]

> Thanks for your review.
> This is very helpful to me.
> If CONFIG_SMP is not enabled, should we just clear the RQCF_UPDATED of
> one of rq1 and q2?
>
> like this:
> rq1->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);

[...]

We could take care of that within rq_clock_clear_update() if really
needed?
Anyway, for !CONFIG_SMP builds rq_clock_clear_update() has to be defined
outside #ifdef CONFIG_SMP.

-->8--

diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 3a77b10d7cc4..614b822c667c 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2484,6 +2484,17 @@ unsigned long arch_scale_freq_capacity(int cpu)
}
#endif

+#ifdef CONFIG_SCHED_DEBUG
+static inline void rq_clock_clear_update(struct rq *rq1, struct rq *rq2)
+{
+ rq1->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
+#ifdef CONFIG_SMP
+ rq2->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
+#endif
+}
+#else
+static inline void rq_clock_clear_update(struct rq *rq1, struct rq *rq2) {}
+#endif

#ifdef CONFIG_SMP

@@ -2515,16 +2526,6 @@ static inline bool rq_order_less(struct rq *rq1, struct rq *rq2)

extern void double_rq_lock(struct rq *rq1, struct rq *rq2);

-#ifdef CONFIG_SCHED_DEBUG
-static inline void rq_clock_clear_update(struct rq *rq1, struct rq *rq2)
-{
- rq1->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
- rq2->clock_update_flags &= (RQCF_REQ_SKIP|RQCF_ACT_SKIP);
-}
-#else
-static inline void rq_clock_clear_update(struct rq *rq1, struct rq *rq2) {}
-#endif
-
#ifdef CONFIG_PREEMPTION

/*