mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hao Jia <jiahao.os@bytedance.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@redhat.com, mingo@kernel.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	bristot@redhat.com, vschneid@redhat.com,
	mgorman@techsingularity.net, linux-kernel@vger.kernel.org
Subject: Re: [External] Re: [PATCH] sched/core: Avoid WARN_DOUBLE_CLOCK warning when CONFIG_SCHED_CORE
Date: Tue, 31 Jan 2023 10:35:19 +0800	[thread overview]
Message-ID: <d99bae6c-ac53-d803-95d2-c2a7bcf0c89a@bytedance.com> (raw)
In-Reply-To: <Y8UyqnVRNTcBD/V7@hirez.programming.kicks-ass.net>



On 2023/1/16 Peter Zijlstra wrote:
> On Tue, Dec 06, 2022 at 03:05:50PM +0800, Hao Jia wrote:
>> When we need to call update_rq_clock() to update the rq clock of
>> other CPUs on the same core, before that we need to clear RQCF_UPDATED
>> of rq->clock_update_flags to avoid the WARN_DOUBLE_CLOCK warning.
>> Because at this time the rq->clock_update_flags of other CPUs
>> may be RQCF_UPDATED.
> 
> So you've found that the WARN_DOUBLE_CLOCK machinery doesn't work for
> core-sched -- but then instead of fixing that machinery, you put
> band-aids on it :/
> 
> 
Hi, Peter
Sorry for the late reply. I just finished my holiday.

I am trying to adapt WARN_DOUBLE_CLOCK machinery for core-sched.

If sched_core_enabled(), we will get a core wide rq->lock, so we can
safely clear RQCF_UPDATED of rq->clock_update_flags of all CPUs on this
core.
This avoids a WARN_DOUBLE_CLOCK warning when we call update_rq_clock()
to update the rq clock of other cpus on the same core.

We cannot clear rq->clock_update_flags of other cpus on the same core in
rq_pin_lock(). Because in some functions, we will temporarily give up
core wide rq->lock, and then use raw_spin_rq_lock() to obtain core wide
rq->lock, such as newidle_balance() and _double_lock_balance().


Thanks,
Hao

---

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index e838feb6adc5..f279912e30b3 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -435,6 +435,21 @@ sched_core_dequeue(struct rq *rq, struct 
task_struct *p, int flags) { }

  #endif /* CONFIG_SCHED_CORE */

+static inline void sched_core_rq_clock_clear_update(struct rq *rq)
+{
+#ifdef CONFIG_SCHED_DEBUG
+       const struct cpumask *smt_mask;
+       int i;
+       if (rq->core_enabled) {
+               smt_mask = cpu_smt_mask(rq->cpu);
+               for_each_cpu(i, smt_mask) {
+                       if (rq->cpu != i)
+                               cpu_rq(i)->clock_update_flags &= 
(RQCF_REQ_SKIP|RQCF_ACT_SKIP);
+               }
+       }
+#endif
+}
+
  /*
   * Serialization rules:
   *
@@ -546,6 +561,7 @@ void raw_spin_rq_lock_nested(struct rq *rq, int 
subclass)
                 if (likely(lock == __rq_lockp(rq))) {
                         /* preempt_count *MUST* be > 1 */
                         preempt_enable_no_resched();
+                       sched_core_rq_clock_clear_update(rq);
                         return;
                 }
                 raw_spin_unlock(lock);

      reply	other threads:[~2023-01-31  2:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06  7:05 Hao Jia
2023-01-03  7:44 ` Hao Jia
2023-01-16 11:19 ` Peter Zijlstra
2023-01-31  2:35   ` Hao Jia [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d99bae6c-ac53-d803-95d2-c2a7bcf0c89a@bytedance.com \
    --to=jiahao.os@bytedance.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mgorman@techsingularity.net \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®