Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp288750iog; Mon, 13 Jun 2022 02:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnw8trlWT7D2l4BTjdYwFTR+AdnQTRr4xJIgqbtkmfHh/5grzk5cMfjAn1Wyj4LWHZ0XCY X-Received: by 2002:a17:90b:224a:b0:1e6:7780:6c8c with SMTP id hk10-20020a17090b224a00b001e677806c8cmr14825234pjb.119.1655113464639; Mon, 13 Jun 2022 02:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655113464; cv=none; d=google.com; s=arc-20160816; b=jNz9GRqZFwpIphARsIYfb/tSRCm9Kebx6ArXwsgw/scpen1eOnepHOkPBL9/lr/8nE Gjk1FvwY7AilHEagDv9WAKyHJUUpdrC5by32A32TqJMaGA81J/b9XAAsUQ+kSuZdx0rw JgLcjM+jJDeZBPZHKkm4GECnnAaohyLFtRL9k20bJZ6AqzDAubfDECDr0lwLYqdn1dBE sYk302+BCTvYBA8QCQrMzLgYtlPToWa0rjdnCO83p65aYbqkFRdYyvW1ZdSBw5RmHLsr cHkx/NYv30VulV/5y1NU78O+EZwo1ZoG0zUJPS9Qziuy/JKCqyW5pXOuXp0XFvIwfOjc Eygw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=PHjuPIMbgdG2lR+qQVtbOKhjK916xLaRY2n9UJBw2Cs=; b=MEOaUw4Nwt1llNCcqrAdJZ3IRyOxS71HJXGsocNTYZW+eIHOGHnXtyYf/pVD+P4QZr akogvND0FBP2C+Cn5KldX3s5/Aq1QZ43sT4pLuEgQ3WYTZbTKqtOMdKD2KKxJtO6qwiS f9Cq+OWFnLppmCleJ+L3vnn7fzB4cJXxw2VrvLvgXbB02JjQGUqyF9V1PTfNubvXvxKc ZSO8DZkBYaCgeJwDAWkPl1C5m+3ZcWGrud+t2Pzh/XrNeTvZKblm4tva6yVNhP4zZUAD ijHUoh17aO7ILVK5FZdALLMbnrACDFGYdyAjEvllBpGoeHD5/tG9LMB4TxWKcxn9F1bz zRJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3n1AJdDx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="N6P2/Y+g"; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be9-20020a170902aa0900b00161888ee6fesi8519950plb.474.2022.06.13.02.44.11; Mon, 13 Jun 2022 02:44:24 -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=@linutronix.de header.s=2020 header.b=3n1AJdDx; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b="N6P2/Y+g"; 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=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239150AbiFMIz3 (ORCPT + 99 others); Mon, 13 Jun 2022 04:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239397AbiFMIn0 (ORCPT ); Mon, 13 Jun 2022 04:43:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15E97C45; Mon, 13 Jun 2022 01:43:26 -0700 (PDT) Date: Mon, 13 Jun 2022 08:43:23 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1655109804; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PHjuPIMbgdG2lR+qQVtbOKhjK916xLaRY2n9UJBw2Cs=; b=3n1AJdDxkYWxTvX4BubnRkoE5gGX5CHyTSD3JnTUGC5/C2IO2BOzvvIWwQk9S3zsDOiZF5 rD3S7SRmDKRBNueFnmMfszfZMYOtQ4XrSZvzpNqp7/DkmGAnq5tM13l5gnHuwxY2WZNchW RXsfsCjj/HWOqJjWQF+OcUON16++oT5E4wFfkV9rQMbgezp2L0fYGPJDWa2M0wyXD5pN3o eOD1IfZf1k2Fql2T41JV5xhuxvd3AXSpeAozllHSO4fxjRB5m7Af5mod11tIT61bfiiYGg hgdJxep1dlrYD9I+HjB/0w9VfcUaV2treEOKGxMBU4XmPTbaoLR3DZiSdQopOw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1655109804; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PHjuPIMbgdG2lR+qQVtbOKhjK916xLaRY2n9UJBw2Cs=; b=N6P2/Y+gsKq1Uj2HVSh/ousT7E8uMViHXs1BGeRQOR5mzfW32TXfx+SvyiK5/JtwGN5r6b HzPuQ1MLQM/gVWDg== From: "tip-bot2 for Tianchen Ding" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched: Fix the check of nr_running at queue wakelist Cc: Valentin Schneider , Tianchen Ding , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220608233412.327341-2-dtcccc@linux.alibaba.com> References: <20220608233412.327341-2-dtcccc@linux.alibaba.com> MIME-Version: 1.0 Message-ID: <165510980360.4207.9149154297957353437.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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 The following commit has been merged into the sched/core branch of tip: Commit-ID: 28156108fecb1f808b21d216e8ea8f0d205a530c Gitweb: https://git.kernel.org/tip/28156108fecb1f808b21d216e8ea8f0d205a530c Author: Tianchen Ding AuthorDate: Thu, 09 Jun 2022 07:34:11 +08:00 Committer: Peter Zijlstra CommitterDate: Mon, 13 Jun 2022 10:30:01 +02:00 sched: Fix the check of nr_running at queue wakelist The commit 2ebb17717550 ("sched/core: Offload wakee task activation if it the wakee is descheduling") checked rq->nr_running <= 1 to avoid task stacking when WF_ON_CPU. Per the ordering of writes to p->on_rq and p->on_cpu, observing p->on_cpu (WF_ON_CPU) in ttwu_queue_cond() implies !p->on_rq, IOW p has gone through the deactivate_task() in __schedule(), thus p has been accounted out of rq->nr_running. As such, the task being the only runnable task on the rq implies reading rq->nr_running == 0 at that point. The benchmark result is in [1]. [1] https://lore.kernel.org/all/e34de686-4e85-bde1-9f3c-9bbc86b38627@linux.alibaba.com/ Suggested-by: Valentin Schneider Signed-off-by: Tianchen Ding Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Link: https://lore.kernel.org/r/20220608233412.327341-2-dtcccc@linux.alibaba.com --- kernel/sched/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index bfa7452..294b918 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3829,8 +3829,12 @@ static inline bool ttwu_queue_cond(int cpu, int wake_flags) * CPU then use the wakelist to offload the task activation to * the soon-to-be-idle CPU as the current CPU is likely busy. * nr_running is checked to avoid unnecessary task stacking. + * + * Note that we can only get here with (wakee) p->on_rq=0, + * p->on_cpu can be whatever, we've done the dequeue, so + * the wakee has been accounted out of ->nr_running. */ - if ((wake_flags & WF_ON_CPU) && cpu_rq(cpu)->nr_running <= 1) + if ((wake_flags & WF_ON_CPU) && !cpu_rq(cpu)->nr_running) return true; return false;