From patchwork Mon May 15 06:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Jia X-Patchwork-Id: 93901 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6721095vqo; Mon, 15 May 2023 00:04:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LHCFttFuhUeYz7KYUBstAW+rt7sANEXIzaj5hR16nuMaQ2T6Gl82xVzwcAhpgcTT9bhd2 X-Received: by 2002:a17:902:b288:b0:1a9:6d25:b2d2 with SMTP id u8-20020a170902b28800b001a96d25b2d2mr32297982plr.67.1684134270146; Mon, 15 May 2023 00:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684134270; cv=none; d=google.com; s=arc-20160816; b=X6hmkjtE+712EBSKrDBxjanwHSgUKbKw18AEYYyGE2Y32sd10nEncSl58Zr+Ke/xPY arhgwUV+b6VjlgqfyjZdga+N4BNq4GgnuoJK52b9x3vjA8jALWB8nv1h+ViKa72Gjt4k EfAk34lJMzN+qK1ALi+/elzPt/Hv98JnQr0FKZN7HrRBmoot7TQlxnjhLzay0+v30J/f vQHrrQUv33zkDfg/XwVjeH0F9RL8Boe4w4NJwyeNXJxs4Ex/h86qmUgtpFnjECdMcs21 D0UKrRmtYiAtUMDAYVYYCamv+pDd35ySHeajptOYv0+DCzYhkK/trUliXSxNGzrYopLt NKNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W70DiGj/q2nP8jtGasv9F9p6lMGC6Cif6Ya2AzHk0NQ=; b=I9hPOBRRpL2QGDcJ+FceJBXuc0TiUsf5GWH3P4HfkkZd8HrNER8yPVuIhgCpZOAJxg brGNK4/wRJy1cmcumvjchJozmgwdIgl6pX8F8VRUtk4M+3ZHJW7cmAh6clJ9DjB50kv/ SdYCX3W/ZbhRXgdbWNE63M1oJPHOq+0oY/b3G3IbUsGo6meQWT+YSsBeJ1gQhi7HDolR b2d+HpQqHSbL/7zSGnDa3mtTAcBZVZrzmXcPkJgT7jkg0aZf1cMaJlpCVdiFOT9pA11k hO/xu/nZQNzekAnxZK+ksU2dd6vQB9fOOgb4P+dYrkzvYZTgZlyx1sDM/OiquZS5T4KR 2BLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=SE71g8zH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a170902d88500b001ac7ea55768si15337311plz.499.2023.05.15.00.04.15; Mon, 15 May 2023 00:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=SE71g8zH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239954AbjEOGjK (ORCPT + 99 others); Mon, 15 May 2023 02:39:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbjEOGjI (ORCPT ); Mon, 15 May 2023 02:39:08 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48B77114 for ; Sun, 14 May 2023 23:39:06 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1aad5245571so84490045ad.1 for ; Sun, 14 May 2023 23:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684132746; x=1686724746; 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=W70DiGj/q2nP8jtGasv9F9p6lMGC6Cif6Ya2AzHk0NQ=; b=SE71g8zH4uEQnUiO+eEH/bgF9Hw2s0M0nKzDPCQ5MzGjcOL+bK+Y353hzsKMSnMvI3 /z7iqNfNNFRaPRdSnHk1uONT7hgpCOyZgkDdi43f00JSVIanIZi7nkAdZ2mqB5d1QvZI /NLcUYX0YQBXzDuVPiPk2eeJEmpWAefACnLxFBMAFlM6KPIeJU59oz6Pn+MbuHOkGUTd g6VU8NdiA21qzKtniVfvAq0zeH3LBPTzHp8YXIIn/OFBpohU8V+TVx8d/o01oijnrzZP 4hZ+InzPY1XcHts0s5Kl6PZIBFc5edTFBN0Caxm/0bCnkDj2Dtuc3biIKOjTGE0B1SFG VRDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684132746; x=1686724746; 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=W70DiGj/q2nP8jtGasv9F9p6lMGC6Cif6Ya2AzHk0NQ=; b=fzgBjWc9JRk1uUr1iPe1ImpQsOKN5lK8LW5xzokqnObfu8OwgOmvLvAWiGSp+5MoGH /UXpXHxrqMOqWkDqoS9o/P4qW+Vx3ZywfCOjzgtCf/MV15+QIV7PnoMZqdwNPnHAOQqx nLo0SZ7ev5XFtlm8HaDPU6ljOlK+D1FiuDOD7Gf343Rqi557hwUmHwQnga1KAUwK4eHu eEGGx4QMudboDNV2NTKWN4uqk/FIr2J+UBpK7mc80ecdMu+3VOjn8EFpJUI4uJdY5EXD tYY2t3moIPqKwhMQMbevWSOZZNYM52CbCxdEn5b2oC1j6u76AIFJkwJfEOhws2cGr4yB 9f5A== X-Gm-Message-State: AC+VfDxOl+8ugbp1NGjTgt8VXaue+e91jAppJhoudr/DBuE4t+qP/+dU QmIqd6EDpc0CQHbIkU0RVHDlDg== X-Received: by 2002:a17:903:120d:b0:1aa:f53a:5e47 with SMTP id l13-20020a170903120d00b001aaf53a5e47mr39324265plh.16.1684132745766; Sun, 14 May 2023 23:39:05 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id t1-20020a170902a5c100b001ab01598f40sm12608543plq.173.2023.05.14.23.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 23:39:05 -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 v3 1/4] sched/core: Fixed missing rq clock update before calling set_rq_offline() Date: Mon, 15 May 2023 14:38:45 +0800 Message-Id: <20230515063848.77947-2-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230515063848.77947-1-jiahao.os@bytedance.com> References: <20230515063848.77947-1-jiahao.os@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765942776465406954?= X-GMAIL-MSGID: =?utf-8?q?1765942776465406954?= This is triggered during cpu offline when CONFIG_CPU_FREQ is enabled and cpufreq is set to powersave: ------------[ 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 function 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 = NULL; - unsigned long flags; + struct rq_flags rf; - raw_spin_rq_lock_irqsave(rq, flags); + rq_lock_irqsave(rq, &rf); if (rq->rd) { old_rd = rq->rd; - 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); + } cpumask_clear_cpu(rq->cpu, old_rd->span); @@ -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); - raw_spin_rq_unlock_irqrestore(rq, flags); + rq_unlock_irqrestore(rq, &rf); if (old_rd) call_rcu(&old_rd->rcu, free_rootdomain); From patchwork Mon May 15 06:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Jia X-Patchwork-Id: 93893 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6720023vqo; Mon, 15 May 2023 00:02:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5c8YBjkAJVX7nq1Rey/VvUNZHhJ+sdSPpwj/BiHt3dJNuN6igigPQltU2lFg2uR05IF2+3 X-Received: by 2002:a17:90a:f8d:b0:250:85ba:6c3d with SMTP id 13-20020a17090a0f8d00b0025085ba6c3dmr24908318pjz.6.1684134157122; Mon, 15 May 2023 00:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684134157; cv=none; d=google.com; s=arc-20160816; b=sex7wPR4cQ9bfBQzkLtH7yZm5QOzlso4jWIiyJO2cyva4kNsI2xOrdLa26qZa3BZOG 1Ho5T9dfvEeBk6LNjteeO5GFsBS63ylBuj6tVUgwcxI9G4bKkylMm8x3k6ukbcOyqExC o+2N/nZhSc2e9nxNbaMEJSQDvgc18xwxR+5RdvmEOscp2oXuisiEQwVvf8qiZftpJWBt eHo6UHD9u7A78AwJpS7+ngp6/brdSQZQ8HQ9zlhUpnqSoc3848MuEfCpRqrcv5HThGUU ocihNIJy4gMitfNaeIGGFZuHfWS+XcmbkKVDETpGVM8udjlLMVr7W/citgsnbRGFSjZ4 scVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MbGpG4ZAOaq7Hlh8d6bFS/m3vJCuvL29YZwPCpli9B8=; b=bz3FOmz+dxL7US8/HB5bUryocgAw3uJ+NYDZyH2MMvZlPU2u+NvU4KO2fGt5emdwQU txHOl1lHVQ48uvPkOCViO+D7O61K+zP6KV8FMN8sFRx8GBMVpzUMR92G5JAMHJZ43dEB +wXMB63s8EA/fbuiL/kHBOy9/kvRFeKinwMnkAxruA1bYuM5D6H5mwz/5sqhiqJwmlYj qBi029I4PZTUQSa5cMEZoOkuk2oeUhHEscuDIu6mV77X5gfroNyRu4gm5vm/mczPQcV3 1ZZIhu0VycpqL5NssaKF/O6EBJElM2+4LDzsOjYxuk1F9phM/96lyNN/lC796ZpNlX6a QPEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=TmDtPDc6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pt6-20020a17090b3d0600b0022bbae722fcsi15780751pjb.1.2023.05.15.00.02.23; Mon, 15 May 2023 00:02:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=TmDtPDc6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240013AbjEOGjo (ORCPT + 99 others); Mon, 15 May 2023 02:39:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239976AbjEOGjg (ORCPT ); Mon, 15 May 2023 02:39:36 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41A6F1BE4 for ; Sun, 14 May 2023 23:39:12 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-52c690f7fa4so8421363a12.0 for ; Sun, 14 May 2023 23:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684132752; x=1686724752; 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=MbGpG4ZAOaq7Hlh8d6bFS/m3vJCuvL29YZwPCpli9B8=; b=TmDtPDc6nVDFKFdY0PRjJD3KjNUkAvZ/MFPGIZRevSxWptFajvFeIoBK2AmZdC0qMD wKGjXMjTq2bKBbovs8tI6qlAWuTS2oYndwwu+LXCvAzpAV4XUzV6cBAPWg6qTteyGOtZ oB1y0LDUJMcWmcnVCuQJxOf8UajkJqTqdV2VqD3xSUzygn7AZiCcaAyvCBuarO6S+rA1 TJ2ZG4PtNX6fIDF5cDwKPUSQFPJUHPV1daBPtT5g41QhQ8AIyXrMzkKW8DwCIqXeP8sC nIqeQqyhhZY8SX1Fa+AmQVTv6cNvHASROdvY3wMIFwGlCmOwfUQr5erweC/qWrL/MHJ9 0qKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684132752; x=1686724752; 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=MbGpG4ZAOaq7Hlh8d6bFS/m3vJCuvL29YZwPCpli9B8=; b=WXGhnurCWLeSCeK+AqgV/3y1UnyAm8DvdW6dEIjxqC/xLtONEY856Kmk2GbNIW8qvB uGNlBLrf/zu8dyaYGDdN6LhKDPibRZ0gXi7LpFu3irpT6NM2aHzVmFMPrmg4j0Yt6JCE 3dsnQX5J53dQSB60ErT0FS/CFsc1PTMQe/mezvCKc2JXCayRPeldaLq/cA+YzQA1ldS+ 9MK9Pv4zQ+QMoS19wy7EcoDnTeH9u2OXLF1wxyiyno0kSgv5ZgqdfABB45yZbZvKOFXc xOgiAdOT1/sCkNIERwMVVSIHHFrVPIWZguVmQZ/pMavC5JZjPYNvDIehOhgjYzL0TGKA Lv3g== X-Gm-Message-State: AC+VfDygKtI5GsPurw91nJ7hOe0wmfLIs5mS5kPsgJImFpvq4ap/LOpj NTHW4sZhnMlqnP+yaCClWOvHLQ== X-Received: by 2002:a17:902:b696:b0:1aa:f203:781c with SMTP id c22-20020a170902b69600b001aaf203781cmr28759823pls.44.1684132751752; Sun, 14 May 2023 23:39:11 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id t1-20020a170902a5c100b001ab01598f40sm12608543plq.173.2023.05.14.23.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 23:39:11 -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 v3 2/4] sched/core: Avoid double calling update_rq_clock() in __balance_push_cpu_stop() Date: Mon, 15 May 2023 14:38:46 +0800 Message-Id: <20230515063848.77947-3-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230515063848.77947-1-jiahao.os@bytedance.com> References: <20230515063848.77947-1-jiahao.os@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765942657866307356?= X-GMAIL-MSGID: =?utf-8?q?1765942657866307356?= The WARN_DOUBLE_CLOCK warning is triggered during cpu offline. ------------[ 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 944c3ae39861..2bcf6a8e71fc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2398,7 +2398,6 @@ static struct rq *__migrate_task(struct rq *rq, struct rq_flags *rf, if (!is_cpu_allowed(p, dest_cpu)) return rq; - update_rq_clock(rq); rq = move_queued_task(rq, rf, p, dest_cpu); return rq; @@ -2456,10 +2455,12 @@ static int migration_cpu_stop(void *data) goto out; } - if (task_on_rq_queued(p)) + if (task_on_rq_queued(p)) { + update_rq_clock(rq); rq = __migrate_task(rq, &rf, p, arg->dest_cpu); - else + } else { p->wake_cpu = arg->dest_cpu; + } /* * XXX __migrate_task() can fail, at which point we might end From patchwork Mon May 15 06:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Jia X-Patchwork-Id: 93918 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6727122vqo; Mon, 15 May 2023 00:16:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+EHga2URV1xW+iNTAd7qhQ0y1OYwxrkRbCtGIN/3s4S7ZwlU7NULVGD85VSt23EsN1uX1 X-Received: by 2002:a05:6a00:2189:b0:644:ad0e:ec3e with SMTP id h9-20020a056a00218900b00644ad0eec3emr35866136pfi.33.1684134983106; Mon, 15 May 2023 00:16:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684134983; cv=none; d=google.com; s=arc-20160816; b=xinbR7jCuhIE1OkQ4lnBYDPqx11CE/2aXkPfiNEGjgYutSOMWvcFmMypbGirtcCQCA BsUbV58FylXmI4CYqVGjxpIlzH7hGJCRhOJ4zHYBFxJ3tPauFULsg7xEnSSzFinT4s++ QXuv2ZkT2pG/Xl0fyVbrc3h4W4iH+RE2ma/zZQtaJga4WOcQrLMgD5EyDmcS5CwWFDq2 ztA0CKu108BphgkQCMYttKqbMluezzBBFMxTx9NU0Dr55efkFekLaCFBPnQZ6OOEO6a+ +db63Y/ZV5q6KXq2HHG4VRZ09fGulcMo1YPYfaitNTOnfNiAFcUkMt8NI7PY5XHERFGi dv7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5GG9RKNGEffPgJfkkoC15/sIpfFivs7YSYRYo8JcS/I=; b=msJdj5Kp8dKzZ8pj0hKUtYuXdk9j7/Ei6QONhx8CKLuVc5KFiHGZjMKQ4TTrRjhv6D O8/zbXkJN2IJn0atAG5xQuvewYAPzGH4Er6SyKO0AsalRemG8yAxcqT8ZfhdYt5DY0w/ atfkty1D0NYPpdEPMjcsmRqqIBiSG6UGqbN8shyiXySsDhW2W9EAseEwbZQeLq5/fVB4 i+RAZlvQqqd2g0c5iiCSd93nVSIxNERHVoHvniNTWNDHsjniKNpefbBSdINUrVRxnFxz /iHU85RxoFme9YuEahYWHoUX1TEiPvQqf/IceUYi+CxJTLt49070YPh6wvyVlIu5HPMq PJlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Xuhak8QG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v29-20020aa799dd000000b0063d270ccc12si16744144pfi.180.2023.05.15.00.16.10; Mon, 15 May 2023 00:16:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Xuhak8QG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239966AbjEOGjZ (ORCPT + 99 others); Mon, 15 May 2023 02:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbjEOGjX (ORCPT ); Mon, 15 May 2023 02:39:23 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A718E71 for ; Sun, 14 May 2023 23:39:19 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1aad5245632so87563485ad.3 for ; Sun, 14 May 2023 23:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684132758; x=1686724758; 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=5GG9RKNGEffPgJfkkoC15/sIpfFivs7YSYRYo8JcS/I=; b=Xuhak8QGNB33HHyzbiwgrCV89M2svRMI6Jf52IB8n8T5s8wXKOilZvXZ3d/cSfkxuN OWhrkIKBMoBo1k3RRIeZ77OrAQQPnYZUFL6aCT9CKsxHAAqsnmr0zw1jpmq85hm9Kdd4 9kmDYLhxzH7NOXhqOJ0lgiX4tDrm7fr/rwnt2RscD+qOBb6X7ZN5PAbPIMf8k7qF6/3W Muo7TR0hIDqc4dQlSnRXu9x2TSdSQhKts86LJp6jgUKvbfRiOHk1yAUFzSnVAW9QYVZ8 YVoAVALb5uc40s3m8AouRH5/bPXI/sLGqAka/NJWI/CQiD3qBS42eMmyB7c+sVqa+mqU IjAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684132758; x=1686724758; 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=5GG9RKNGEffPgJfkkoC15/sIpfFivs7YSYRYo8JcS/I=; b=DnEMj3HItDBBTsxIj55wdkyJK0Ab/OMRj/SSnjTQEwl4qNsmems5OjQEOJkc4cug42 TbVBHJRPJfJOusnoEhx62fqGAbMB4XvyKesGnZ8pzSYHIltuDkTEkQvFxJVzXS7ZfPCb dRtQFtj/lGzY/fHi2OFHvFB26Lp1btDUaEeGdSmU9vbZQslsCBPgZPSV4tTbf6BdSOra 2h3kNhK0jcDy5GDfwUNjSsb2niNCJ0E7tY0z5moawmQgwGk1HwxyXirGfITNk3FURh8g jUGP7V2/jpkrzb/U8ywBU+Hzl/hnVlnQ+ou81JL+dEYOew31ZDvL7K3MxUvKo7StUc1k A9Tg== X-Gm-Message-State: AC+VfDwjsfeJdXb4rWUvshAxgnwNAhLyZa4l/YWoPiuutXHSGEQLeXj5 en/EC1kmYy0GoieWN0OCBrRqAA== X-Received: by 2002:a17:902:f9cd:b0:1a5:1e7:86d7 with SMTP id kz13-20020a170902f9cd00b001a501e786d7mr30320465plb.52.1684132758643; Sun, 14 May 2023 23:39:18 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id t1-20020a170902a5c100b001ab01598f40sm12608543plq.173.2023.05.14.23.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 23:39:18 -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 v3 3/4] sched/core: Avoid multiple calling update_rq_clock() in __cfsb_csd_unthrottle() Date: Mon, 15 May 2023 14:38:47 +0800 Message-Id: <20230515063848.77947-4-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230515063848.77947-1-jiahao.os@bytedance.com> References: <20230515063848.77947-1-jiahao.os@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765943523892453546?= X-GMAIL-MSGID: =?utf-8?q?1765943523892453546?= 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. ------------[ 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) rq_lock(rq, &rf); + /* + * 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) rcu_read_unlock(); + rq_clock_stop_loop_update(rq); rq_unlock(rq, &rf); } 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 &= ~RQCF_REQ_SKIP; } +/* + * 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_update() + * 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 |= RQCF_ACT_SKIP; +} + +static inline void rq_clock_stop_loop_update(struct rq *rq) +{ + lockdep_assert_rq_held(rq); + rq->clock_update_flags &= ~RQCF_ACT_SKIP; +} + struct rq_flags { unsigned long flags; struct pin_cookie cookie; From patchwork Mon May 15 06:38:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Jia X-Patchwork-Id: 93895 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6720086vqo; Mon, 15 May 2023 00:02:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6n5aKnOWgBDcJmpgEaYmAAYGFNM6Q325MblvzQzqmplYhJLbgP26dS+u3XWOKPsAlJpPNa X-Received: by 2002:a05:6a20:42a5:b0:101:3046:8db3 with SMTP id o37-20020a056a2042a500b0010130468db3mr24832561pzj.22.1684134162693; Mon, 15 May 2023 00:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684134162; cv=none; d=google.com; s=arc-20160816; b=CO1zfEJ69bdl6MOQlORoEJNTFkYqHWYZvADMwUWxP1pg7Ll/KNkMQyPepB8J1m3rvk l17tmSm5jxN3R9fWBQrHrEvnOslXUM1fS5qNeobtsUfXk6kNu4kVjtjaaLpqfNeai4t+ /upjUnKrusiLOoulvAUgXoG5EvGPpBeAF5loH/zlErhIi2slqyjwQNA0u9jJZm55bOUU sNdMiROgNtUkapIBgHP41Q+bpvF3YF8OoA5GR63/NH1lYivXziUoA0yuudogW4VN/Qui EpL0MvgOAMsy/bL6RkDRrtoTJkTEMzESVAZYmugJnSshCsB6d/ClEcS+fKeNXUvfMyBL JYGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BFcJEKvFlaV29tECsJFbnfR2Mq9DuGUAZDWRZXZAow4=; b=kyCiFE+EKQcyyRfMfXkh239zOEn+35xdaLhY64XC8MKKwaK/KG955eCkZHvJrLUyKG DVK94TBSyXlW5c1i5f+EaYadvvotT1m2ivfxUlSxf3FcfCpdHoDGN56LHXvs4U3G3ti8 zlodf0ujBW4olIavz0ZCOiWJI49NFqMADsGOLoJ2vA4SO0SGUZNuwDQXHaeH+F8Z2q/C ap9Qo8lfvL4kKTSrO8Sr6v4RXodv8uCq1o9rHMsuRpS3d7AtI00dH8fOi2OVfkySJGAx +OsF/qiS9fSenoqAp3tsv4B0H2qpyXIZUvi4eTszBTRrRORN3PK7Ufi4aIHnbDFuH9XR /lEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=DGach8hc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv187-20020a632ec4000000b0050726756edesi14688002pgb.76.2023.05.15.00.02.30; Mon, 15 May 2023 00:02:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=DGach8hc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239986AbjEOGjz (ORCPT + 99 others); Mon, 15 May 2023 02:39:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240097AbjEOGjs (ORCPT ); Mon, 15 May 2023 02:39:48 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55AF0E54 for ; Sun, 14 May 2023 23:39:25 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-64a9335a8e7so18294833b3a.0 for ; Sun, 14 May 2023 23:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684132765; x=1686724765; 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=BFcJEKvFlaV29tECsJFbnfR2Mq9DuGUAZDWRZXZAow4=; b=DGach8hcIbmjALcZWCOjua9h8AAP0kcpM0lYtO03oqOMyG+KmL2Zz/Jy6cgdf/LU/h wVK2G45oppW+r9f1HQ8oNlr2Ny9PEGnU5uYweNqWl94msC4XgEiO+br3PjH9HeBYSXMw N/WcbNUyJPwG3LGxs0HznJHreo37AjGArhTpSOsqswLIgt5qqy8eQmB9ZNUgjTXjv4ES uRISkT1jiV91x5WdAaBRKj6T/hg963Kp3gjeF99a2AAHb21J1rABhMsfSXQRSn3M7H08 M7mfJf9JKS7VchWwimVfx6qXqSuvRJ1AeyFVP+7mNnlMfPxkNwDVfWWE+wbbF7WcR+Oi bCtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684132765; x=1686724765; 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=BFcJEKvFlaV29tECsJFbnfR2Mq9DuGUAZDWRZXZAow4=; b=hCAJ5/bOIsvtGmncvQijoDreznA6ShDjIpceQwIByIavTIgG1a+o1dpzyCjGoed9cp az12sFvf7o0DbaUUfOQwwOYTqNWaNjDNWIId/NAs0VOn5OFYjdHJP17TAYrf+C/aJBMa B9pocR4F752a1EMXm8ialyF/TL6pKVQDFhjKxWblzH6PmrddkVQ6rAqbhaj4FcWJoFP/ 057mbrjKy8vjXnPPvp6vQS4gfrCpb8lD8rPFd2eFNZrKtVCyqGhdlWsx9UtRtqZ1Phu1 6Hhxn4Xhvr8u02NmM1uTGGnFne/nK6Tbw9qVWBbA4jW6tDmRMdtQsuDfHL6ZfHmpK1OR l91g== X-Gm-Message-State: AC+VfDxd0Pkp4ndXMTDts0hVX4ySgeg7Ui7SbGrPAqFwy+jao02KMTM9 BQ/B2RFV+MBOPRA6gGPENAK7dQ== X-Received: by 2002:a17:903:2343:b0:1ac:85b0:1bd8 with SMTP id c3-20020a170903234300b001ac85b01bd8mr26414078plh.34.1684132764854; Sun, 14 May 2023 23:39:24 -0700 (PDT) Received: from C02G87K0MD6R.bytedance.net ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id t1-20020a170902a5c100b001ab01598f40sm12608543plq.173.2023.05.14.23.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 23:39:24 -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 v3 4/4] sched/core: Avoid multiple calling update_rq_clock() in unthrottle_offline_cfs_rqs() Date: Mon, 15 May 2023 14:38:48 +0800 Message-Id: <20230515063848.77947-5-jiahao.os@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230515063848.77947-1-jiahao.os@bytedance.com> References: <20230515063848.77947-1-jiahao.os@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765942663519282692?= X-GMAIL-MSGID: =?utf-8?q?1765942663519282692?= This WARN_DOUBLE_CLOCK warning is triggered during cpu offline. ------------[ 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_rqs(struct rq *rq) lockdep_assert_rq_held(rq); + /* + * 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 = 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); } #else /* CONFIG_CFS_BANDWIDTH */