From nobody Sun Feb 8 15:53:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30219C7EE23 for ; Thu, 8 Jun 2023 06:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234760AbjFHGeH (ORCPT ); Thu, 8 Jun 2023 02:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234720AbjFHGeA (ORCPT ); Thu, 8 Jun 2023 02:34:00 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48B252113 for ; Wed, 7 Jun 2023 23:33:33 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-53fbb3a013dso103599a12.1 for ; Wed, 07 Jun 2023 23:33:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686206013; x=1688798013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=miu0m+9Tm1uoegobE94Ng9PUSsisbRCvMO54PFQ9FXA=; b=J2eRYyxcjSLdIsZK45qLtsrvuNkwMWsQXmFlkud7KqjiXcUk1nY6DC8PGCcqy0nmMb DtwfQFWLrYgbw6KDqOCbMhibo2TKQWXsi8sO2pDPkteo9ffY8OKOVQBhjzw3WvvO+ufs iyl/iHuGyWeCSLwWlhNWDhs495TAZ6cOz1KHj5w35uN0+zqjYmt+UMvxWqoy8gwkJWC8 32HO5tLc9pjzbCTw24WrrAcMIR66NppqcoV/kWv+bPIsnVXfY2y/sCNyGHEveU5PXhMX ZzsFaUATXBOOxMEQSCdH0Cp3wtr54k6jl1Ld78N3k3/50OJER2d/qbeJ/nEETKjO/aEz y9xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686206013; x=1688798013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=miu0m+9Tm1uoegobE94Ng9PUSsisbRCvMO54PFQ9FXA=; b=JjBkK6P2pBf5JoCUwo3yBq5FR2fSf2o8nDbs2Oq9BYiPIYKvbeaHuaXP9K1BMP7/MA GhYzFJj7Pibe1f1LoU8ip8AbCVK9WP+ORpRXeXlv4PNZp/1oYk71yyR3AkSfOIahOy/Q KAIOMVlbsY1EKm1gLFmJbq7Cg7w16Py31rLO+N6ySLmEDVtwD10eyOCftDX4kvROqKjO /erbf6iL52KoiI3iRkEw5LoJC8e8gya0JSJ4aUW2x4BAnhFkP892FNcJhLHvQpfVGCxQ 2ABUgz78Tx/6NWT4XEEaetM+Sl59hOyntdyM7b5YlwYSRyrbgUp03CNw1gwuI05AcUIS EQ+Q== X-Gm-Message-State: AC+VfDyKDRWd4650J6cFRA+OZQbepkdlwwFabDAVAa5PlnzHcBE8TTqt cdBfL5Qe8grMrLa4U+R2PdMplA== X-Google-Smtp-Source: ACHHUZ7ItfOjl5dsrzp0GWRZLSS/iHwXakftJkx9kELNaxuK/TfqNPljoBUdN6vwzwB01SkyOVsZQQ== X-Received: by 2002:a17:90b:685:b0:256:87f4:432a with SMTP id m5-20020a17090b068500b0025687f4432amr6736938pjz.18.1686206012769; Wed, 07 Jun 2023 23:33:32 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id c15-20020a17090abf0f00b0025645d118adsm542039pjs.14.2023.06.07.23.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 23:33:32 -0700 (PDT) From: Hao Jia To: mingo@redhat.com, peterz@infradead.org, 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 Cc: linux-kernel@vger.kernel.org, Hao Jia Subject: [PATCH v4 1/4] sched/core: Fixed missing rq clock update before calling set_rq_offline() Date: Thu, 8 Jun 2023 14:33:09 +0800 Message-Id: <20230608063312.79440-2-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230608063312.79440-1-jiahao.os@bytedance.com> References: <20230608063312.79440-1-jiahao.os@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is triggered during cpu offline when CONFIG_CPU_FREQ is enabled and cpufreq is set to powersave: Reviewed-by: Vincent Guittot ------------[ cut here ]------------ rq->clock_update_flags < RQCF_ACT_SKIP WARNING: CPU: 24 PID: 754 at kernel/sched/sched.h:1496 enqueue_top_rt_rq+0x139/0x160 Call Trace: ? intel_pstate_update_util+0x3b0/0x3b0 rq_offline_rt+0x1b7/0x250 set_rq_offline.part.120+0x28/0x60 rq_attach_root+0xc4/0xd0 cpu_attach_domain+0x3dc/0x7f0 ? __schedule+0x65e/0x1310 partition_sched_domains_locked+0x2a5/0x3c0 rebuild_sched_domains_locked+0x477/0x830 ? percpu_rwsem_wait+0x140/0x140 rebuild_sched_domains+0x1b/0x30 cpuset_hotplug_workfn+0x2ca/0xc90 ? balance_push+0x56/0x120 ? _raw_spin_unlock+0x15/0x30 ? finish_task_switch+0x98/0x2f0 ? __switch_to+0x116/0x410 ? __schedule+0x65e/0x1310 ? internal_add_timer+0x42/0x60 ? _raw_spin_unlock_irqrestore+0x23/0x40 ? add_timer_on+0xd5/0x130 process_one_work+0x1bc/0x3d0 worker_thread+0x4c/0x380 ? preempt_count_add+0x56/0xa0 ? rescuer_thread+0x310/0x310 kthread+0xe6/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x1f/0x30 More detailed key function call graph: rq_offline_rt() __disable_runtime() sched_rt_rq_enqueue() enqueue_top_rt_rq() cpufreq_update_util() <-- depends on CONFIG_CPU_FREQ data->func(data, *rq_clock(rq)*, flags) intel_pstate_update_util() <-- powersave policy callback functi= on Before calling set_rq_offline() we need to update the rq clock to avoid using the old rq clock, and use rq_lock_irqsave()/rq_unlock_irqrestore() to replace raw_spin_rq_lock_irqsave()/raw_spin_rq_unlock_irqrestore() to ensure that rq->clock_update_flags are cleared before updating the rq clock. Steps to reproduce: 1. Enable CONFIG_SMP and CONFIG_CPU_FREQ when compiling the kernel 2. echo 1 > /sys/kernel/debug/clear_warn_once 3. cpupower -c all frequency-set -g powersave 4. Run some rt tasks e.g. Create 5*n rt (100% running) tasks (on a system with n CPUs) 5. Offline cpu one by one until the warninng is triggered Signed-off-by: Hao Jia Reviewed-by: Vincent Guittot --- kernel/sched/topology.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 6682535e37c8..b89497696880 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -487,15 +487,17 @@ static void free_rootdomain(struct rcu_head *rcu) void rq_attach_root(struct rq *rq, struct root_domain *rd) { struct root_domain *old_rd =3D NULL; - unsigned long flags; + struct rq_flags rf; =20 - raw_spin_rq_lock_irqsave(rq, flags); + rq_lock_irqsave(rq, &rf); =20 if (rq->rd) { old_rd =3D rq->rd; =20 - if (cpumask_test_cpu(rq->cpu, old_rd->online)) + if (cpumask_test_cpu(rq->cpu, old_rd->online)) { + update_rq_clock(rq); set_rq_offline(rq); + } =20 cpumask_clear_cpu(rq->cpu, old_rd->span); =20 @@ -515,7 +517,7 @@ void rq_attach_root(struct rq *rq, struct root_domain *= rd) if (cpumask_test_cpu(rq->cpu, cpu_active_mask)) set_rq_online(rq); =20 - raw_spin_rq_unlock_irqrestore(rq, flags); + rq_unlock_irqrestore(rq, &rf); =20 if (old_rd) call_rcu(&old_rd->rcu, free_rootdomain); --=20 2.37.0 (Apple Git-136) From nobody Sun Feb 8 15:53:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0B4DC7EE25 for ; Thu, 8 Jun 2023 06:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234729AbjFHGdn (ORCPT ); Thu, 8 Jun 2023 02:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234266AbjFHGdk (ORCPT ); Thu, 8 Jun 2023 02:33:40 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F78F270B for ; Wed, 7 Jun 2023 23:33:39 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so115633a12.1 for ; Wed, 07 Jun 2023 23:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686206019; x=1688798019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nwSmBGENtB9L+r5dkVtr2aEZeow7KKO4JZwDEcpVetc=; b=IEHwjTXzJVuYe7DYM3MMNxTEdlSl/A+mPuD9qso7opHwllbtTs1HRB7CkpqkgdJLYq zB+AvmDeMSnS/vMohpOGjFyxEG4+4lnIpqXql5aNQyRaRArkLbtZVtZ4OXGwgIkWRV3T elnobLx9QVU9+PLQ3xtgwLIJo1oboYZKE3U/HKNQJ16AnyZjQlV/4oqLNRE5Fux7Ho20 OjNUd6O6YlQO0RY2JNaBg5k0euSmsBFJcfqya/3OoQuL/UWrW9h0wFUg+aeY8QKwaRH0 6sS1iUkpASJIpRqLgeSErBuefw05ikTuyoZ4fn+N0I8mCEmkrWb2pNpH5Qlj2V3F5gc7 kkRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686206019; x=1688798019; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nwSmBGENtB9L+r5dkVtr2aEZeow7KKO4JZwDEcpVetc=; b=mEPkzN90wyGxsWUMPCx9iJl6Qsa1AFQg8pw35kwklbnKbOezWy322OfwLHLtoFOYB6 kbcNdhpoMX3wi04aVbdeyvG8KTxClPzYIF7Czhx0tfRizw/JTe/A9SY0x6dPpS2kYJwl BqVA9i5s7hz0qgY7Or3IJrB5P1OhxVPD/j7cr5Cg7H7GJZRy42sOPxzAX6KjfTdfNG9N reTPh8hjWJOsqafRH7CpxQtmECIl7uccdAVjEqQJ9p7F4h90gXuIgE5ClB4etbqnj6Jm M9poDB3RZhGZca8kR1bp20sp6MGktKTJUuuXM5Cek+NNXonnLHny1lq5izX1i0GsrrE0 +vyQ== X-Gm-Message-State: AC+VfDyGUQ5kDGTUGXqiTh+WgZTbKXreeL6/ce6mhloxacMNOKFhipqc aTrgqAn2vW5sOnOeK9k6Mdxfmg== X-Google-Smtp-Source: ACHHUZ4nloOJkDga2G1MXrbXuhlMwBysk/Y1/2p/Y17/8yja5JwUCBsJmbIDo0dRfLfuqmRLt447zA== X-Received: by 2002:a17:90a:9cd:b0:256:7000:3789 with SMTP id 71-20020a17090a09cd00b0025670003789mr7066599pjo.9.1686206019152; Wed, 07 Jun 2023 23:33:39 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id c15-20020a17090abf0f00b0025645d118adsm542039pjs.14.2023.06.07.23.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 23:33:38 -0700 (PDT) From: Hao Jia To: mingo@redhat.com, peterz@infradead.org, 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 Cc: linux-kernel@vger.kernel.org, Hao Jia Subject: [PATCH v4 2/4] sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop() Date: Thu, 8 Jun 2023 14:33:10 +0800 Message-Id: <20230608063312.79440-3-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230608063312.79440-1-jiahao.os@bytedance.com> References: <20230608063312.79440-1-jiahao.os@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The WARN_DOUBLE_CLOCK warning is triggered during cpu offline. Reviewed-by: Vincent Guittot ------------[ cut here ]------------ rq->clock_update_flags & RQCF_UPDATED WARNING: CPU: 17 PID: 138 at kernel/sched/core.c:741 update_rq_clock+0xaf/0x180 Call Trace: __balance_push_cpu_stop+0x146/0x180 ? migration_cpu_stop+0x2a0/0x2a0 cpu_stopper_thread+0xa3/0x140 smpboot_thread_fn+0x14f/0x210 ? sort_range+0x20/0x20 kthread+0xe6/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x1f/0x30 To avoid this warning, we remove update_rq_clock() from the __migrate_task() function. And in order to avoid missing rq clock update, add update_rq_clock() call before migration_cpu_stop() calls __migrate_task(). Signed-off-by: Hao Jia Reviewed-by: Vincent Guittot --- kernel/sched/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a68d1276bab0..1fd87657f521 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2398,7 +2398,6 @@ static struct rq *__migrate_task(struct rq *rq, struc= t rq_flags *rf, if (!is_cpu_allowed(p, dest_cpu)) return rq; =20 - update_rq_clock(rq); rq =3D move_queued_task(rq, rf, p, dest_cpu); =20 return rq; @@ -2456,10 +2455,12 @@ static int migration_cpu_stop(void *data) goto out; } =20 - if (task_on_rq_queued(p)) + if (task_on_rq_queued(p)) { + update_rq_clock(rq); rq =3D __migrate_task(rq, &rf, p, arg->dest_cpu); - else + } else { p->wake_cpu =3D arg->dest_cpu; + } =20 /* * XXX __migrate_task() can fail, at which point we might end --=20 2.37.0 (Apple Git-136) From nobody Sun Feb 8 15:53:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C48E5C7EE23 for ; Thu, 8 Jun 2023 06:34:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234766AbjFHGe1 (ORCPT ); Thu, 8 Jun 2023 02:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234801AbjFHGeO (ORCPT ); Thu, 8 Jun 2023 02:34:14 -0400 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CA342719 for ; Wed, 7 Jun 2023 23:33:47 -0700 (PDT) Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-39a505b901dso210753b6e.0 for ; Wed, 07 Jun 2023 23:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686206026; x=1688798026; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/kiXdCNBs7MsEGE9ZtEtEzwmLWhy0ZFEY2zGjq+a+7k=; b=jBkNXenyS2kesryvPlWkaWLS6/2hC0E5zpnPzGiZAkjy5PFLGag4X3ont4bH5nuZAq p0pDXr9UB2FswInisj31y5c9UkqT2PTWuVe1s/YuTiNCACmqk+qff9W2Rwq8IZYPHzk3 VWuGlhpMWNVW5HMrhjaUcXt98p0p7GXoRv96opweum/QZINdNhwi32zKChp+68FV+VUl EMBTiQAfPF9QVZPdSknLTKpmKsmAgdB4bztPvgfFbgNq/s+qDi9E7eaZ9VoEZH4n7Kvx bo5wAhz5kqfxUaaY+x98n7BotZ4tswgKAM8h+NDzsFB0J51Oslpie6APjkoEqpcE/FRs qEpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686206026; x=1688798026; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/kiXdCNBs7MsEGE9ZtEtEzwmLWhy0ZFEY2zGjq+a+7k=; b=fRlmZXL+7omOoYXt3mM65ALqqQYmsr0wXlBO7LxSi0or5X9pKqDjjhqx/I6UrRRR39 S69HHXsv9UrMLkcbrAZFYtDpwGy1hFHVONZ+r7c/Kw2tx4u4UXdmEmqQOqjLHM6MbWSg 4dY4qG1hwlsEoRQIr54exsh8tvG5PMEkO3YsUSzgXkNFUugsMT/j3jSI6xGCbMGASgAo rUH02TFSULj16LIcpJX7gZQorAHKY+fVOk+yHAhzdQkTiuMQAwcNPUSBBL46JTRQNTQV Pwc/Y+rDeuOXW4QUwlMwjWTOhwInKA7J7k8nLjkLG0xwWrw2Fn92wtcuAxP/ofANjytA qjTQ== X-Gm-Message-State: AC+VfDwXZrQFT8Vfb388efKasQfYiaXifGeVhcLgR8RDvZxoYrht5vFs DoRRevxI5p4Zivlbc3r83b4Z6w== X-Google-Smtp-Source: ACHHUZ6/LV/RADn2G+JJgrD8Z8aD2ZxU6Ozfo+so2z7Yyb0W0BrKEs1dVmgV+YUtzfocST7a+yOJwg== X-Received: by 2002:a05:6808:a88:b0:39a:98c3:f268 with SMTP id q8-20020a0568080a8800b0039a98c3f268mr7254306oij.49.1686206026388; Wed, 07 Jun 2023 23:33:46 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id c15-20020a17090abf0f00b0025645d118adsm542039pjs.14.2023.06.07.23.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 23:33:46 -0700 (PDT) From: Hao Jia To: mingo@redhat.com, peterz@infradead.org, 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 Cc: linux-kernel@vger.kernel.org, Hao Jia Subject: [PATCH v4 3/4] sched/core: Avoid multiple calling update_rq_clock() in __cfsb_csd_unthrottle() Date: Thu, 8 Jun 2023 14:33:11 +0800 Message-Id: <20230608063312.79440-4-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230608063312.79440-1-jiahao.os@bytedance.com> References: <20230608063312.79440-1-jiahao.os@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" After commit 8ad075c2eb1f ("sched: Async unthrottling for cfs bandwidth"), we may update the rq clock multiple times in the loop of __cfsb_csd_unthrottle(). At that time the following warning will be triggered. Reviewed-by: Vincent Guittot Suggested-by: Vincent Guittot ------------[ cut here ]------------ rq->clock_update_flags & RQCF_UPDATED WARNING: CPU: 54 PID: 0 at kernel/sched/core.c:741 update_rq_clock+0xaf/0x180 Call Trace: unthrottle_cfs_rq+0x4b/0x300 __cfsb_csd_unthrottle+0xe0/0x100 __flush_smp_call_function_queue+0xaf/0x1d0 flush_smp_call_function_queue+0x49/0x90 do_idle+0x17c/0x270 cpu_startup_entry+0x19/0x20 start_secondary+0xfa/0x120 secondary_startup_64_no_verify+0xce/0xdb Before the loop starts, we update the rq clock once and call rq_clock_start_loop_update() to prevent updating the rq clock multiple times. And call rq_clock_stop_loop_update() After the loop to clear rq->clock_update_flags. Fixes: 8ad075c2eb1f ("sched: Async unthrottling for cfs bandwidth") Suggested-by: Vincent Guittot Signed-off-by: Hao Jia Reviewed-by: Vincent Guittot --- kernel/sched/fair.c | 9 +++++++++ kernel/sched/sched.h | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 373ff5f55884..af9604f4b135 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5576,6 +5576,14 @@ static void __cfsb_csd_unthrottle(void *arg) =20 rq_lock(rq, &rf); =20 + /* + * Iterating over the list can trigger several call to + * update_rq_clock() in unthrottle_cfs_rq(). + * Do it once and skip the potential next ones. + */ + update_rq_clock(rq); + rq_clock_start_loop_update(rq); + /* * Since we hold rq lock we're safe from concurrent manipulation of * the CSD list. However, this RCU critical section annotates the @@ -5595,6 +5603,7 @@ static void __cfsb_csd_unthrottle(void *arg) =20 rcu_read_unlock(); =20 + rq_clock_stop_loop_update(rq); rq_unlock(rq, &rf); } =20 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index ec7b3e0a2b20..50446e401b9f 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1546,6 +1546,27 @@ static inline void rq_clock_cancel_skipupdate(struct= rq *rq) rq->clock_update_flags &=3D ~RQCF_REQ_SKIP; } =20 +/* + * During cpu offlining and rq wide unthrottling, we can trigger + * an update_rq_clock() for several cfs and rt runqueues (Typically + * when using list_for_each_entry_*) + * rq_clock_start_loop_update() can be called after updating the clock + * once and before iterating over the list to prevent multiple update. + * After the iterative traversal, we need to call rq_clock_stop_loop_updat= e() + * to clear RQCF_ACT_SKIP of rq->clock_update_flags. + */ +static inline void rq_clock_start_loop_update(struct rq *rq) +{ + lockdep_assert_rq_held(rq); + rq->clock_update_flags |=3D RQCF_ACT_SKIP; +} + +static inline void rq_clock_stop_loop_update(struct rq *rq) +{ + lockdep_assert_rq_held(rq); + rq->clock_update_flags &=3D ~RQCF_ACT_SKIP; +} + struct rq_flags { unsigned long flags; struct pin_cookie cookie; --=20 2.37.0 (Apple Git-136) From nobody Sun Feb 8 15:53:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3416DC7EE23 for ; Thu, 8 Jun 2023 06:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234732AbjFHGeD (ORCPT ); Thu, 8 Jun 2023 02:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234782AbjFHGd6 (ORCPT ); Thu, 8 Jun 2023 02:33:58 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 650511BE8 for ; Wed, 7 Jun 2023 23:33:53 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2565b864f9aso132241a91.1 for ; Wed, 07 Jun 2023 23:33:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686206033; x=1688798033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1YqsjZstkNId62swixNvbney3wfAymRF6traYgOxlKU=; b=VvAzPvj6ETKo1K1LNWU9SVbXwvfpAx1H6zx3BKkWoA7PyMTwrXW+LDqkF6ly951H/w rIKa0AF1kufFYHjUlDDTIr677+Twj+lu5cThh0IHA+/JDCSxq0ccn8A+ttolieNs2V7R wFK42BqwjHZsZyqJzb4aH/XpH6cSKIiXxGJxcOmXyD166sPLApKSuDglhUH+rEC6bY8L sCoYRB0tNTmEpUiSYxA9gbeEMgiiYixFpAIOvQlJoCHo3IK2aBvk0YbW5H19T/Gdfpjr odlKyORp3XTGOEVHGblNoI5XaJ300pMrs5CMl5i1wle6dPg2TNFlfqmK7GijpTvSolrb D4iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686206033; x=1688798033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1YqsjZstkNId62swixNvbney3wfAymRF6traYgOxlKU=; b=byN8YlPUHHc6apevOYb1oLfeUNtgLYvcOg3vTxjDQcKyXhGxZucGJ4c/764zrA0YGV XM5OYLtRnQhruQwK30qQqEqDj3I8FofUpYOaqxHAhqWN0nElIS54KvfJZne8UXO0aGlL JB5WiFfnUkQM4qSo7n8Tm63jYTdqhMmUaZokjz7TVpRbLpRVJUygcBgiyb9SWAp8sj8x hodnFqSyU+SjV3Low0FkuyOeNkFSleIloZ2RyR228xGt/f/JlgjNE5Eg59x6egQmQSDo n9rrSkqjTZLoUdfjhDbtR7kF2QzPGnucttEueidnpsRvdSSErmk2ziT2dAtHCQ33/NEG Arpg== X-Gm-Message-State: AC+VfDxbnmC1LO5SSWN+m+FBVm1SXo/6w7Tid2pnis+kXgE592mH4RKh SUxmQ+0Wom7KB8XhuNULokJuTg== X-Google-Smtp-Source: ACHHUZ5ZjZyJ1ghbLTjSbNlK3NgdDJ9G7hTbFf37+0CCB+RimOwK850659eXZoG5UnoGtO+zYo7xWA== X-Received: by 2002:a17:90a:c581:b0:256:16e:e9dd with SMTP id l1-20020a17090ac58100b00256016ee9ddmr4027769pjt.32.1686206032922; Wed, 07 Jun 2023 23:33:52 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id c15-20020a17090abf0f00b0025645d118adsm542039pjs.14.2023.06.07.23.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 23:33:52 -0700 (PDT) From: Hao Jia To: mingo@redhat.com, peterz@infradead.org, 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 Cc: linux-kernel@vger.kernel.org, Hao Jia Subject: [PATCH v4 4/4] sched/core: Avoid multiple calling update_rq_clock() in unthrottle_offline_cfs_rqs() Date: Thu, 8 Jun 2023 14:33:12 +0800 Message-Id: <20230608063312.79440-5-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230608063312.79440-1-jiahao.os@bytedance.com> References: <20230608063312.79440-1-jiahao.os@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This WARN_DOUBLE_CLOCK warning is triggered during cpu offline. Reviewed-by: Vincent Guittot Suggested-by: Vincent Guittot ------------[ cut here ]------------ rq->clock_update_flags & RQCF_UPDATED WARNING: CPU: 0 PID: 3323 at kernel/sched/core.c:741 update_rq_clock+0xaf/0x180 Call Trace: unthrottle_cfs_rq+0x4b/0x300 rq_offline_fair+0x89/0x90 set_rq_offline.part.118+0x28/0x60 rq_attach_root+0xc4/0xd0 cpu_attach_domain+0x3dc/0x7f0 partition_sched_domains_locked+0x2a5/0x3c0 rebuild_sched_domains_locked+0x477/0x830 rebuild_sched_domains+0x1b/0x30 cpuset_hotplug_workfn+0x2ca/0xc90 ? balance_push+0x56/0xf0 ? _raw_spin_unlock+0x15/0x30 ? finish_task_switch+0x98/0x2f0 ? __switch_to+0x291/0x410 ? __schedule+0x65e/0x1310 process_one_work+0x1bc/0x3d0 worker_thread+0x4c/0x380 ? preempt_count_add+0x92/0xa0 ? rescuer_thread+0x310/0x310 kthread+0xe6/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x1f/0x30 The rq clock has been updated before the set_rq_offline() function runs, so we don't need to call update_rq_clock() in unthrottle_offline_cfs_rqs(). We only need to call rq_clock_start_loop_update() before the loop starts and rq_clock_stop_loop_update() after the loop to avoid this warning. Suggested-by: Vincent Guittot Signed-off-by: Hao Jia Reviewed-by: Vincent Guittot --- kernel/sched/fair.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index af9604f4b135..9e961e0ec971 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6124,6 +6124,13 @@ static void __maybe_unused unthrottle_offline_cfs_rq= s(struct rq *rq) =20 lockdep_assert_rq_held(rq); =20 + /* + * The rq clock has already been updated before the + * set_rq_offline() runs, so we should skip updating + * the rq clock again in unthrottle_cfs_rq(). + */ + rq_clock_start_loop_update(rq); + rcu_read_lock(); list_for_each_entry_rcu(tg, &task_groups, list) { struct cfs_rq *cfs_rq =3D tg->cfs_rq[cpu_of(rq)]; @@ -6146,6 +6153,8 @@ static void __maybe_unused unthrottle_offline_cfs_rqs= (struct rq *rq) unthrottle_cfs_rq(cfs_rq); } rcu_read_unlock(); + + rq_clock_stop_loop_update(rq); } =20 #else /* CONFIG_CFS_BANDWIDTH */ --=20 2.37.0 (Apple Git-136)