Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp357813imi; Thu, 21 Jul 2022 02:16:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vsXWJlDdvMo+dPAN5ltaYAo2hYb8j6mx/4kerccYl2dKEq7S8RDU6knWOrVYYH5i2235fw X-Received: by 2002:a65:6cc8:0:b0:3fe:2b89:cc00 with SMTP id g8-20020a656cc8000000b003fe2b89cc00mr37966255pgw.599.1658394997525; Thu, 21 Jul 2022 02:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658394997; cv=none; d=google.com; s=arc-20160816; b=Y5cFuvPC+Z63hr5VJM1JNZtQpdo4N5jNLj6y8513vCg3KrssCumMHHdmvfB31EIg+i +LvAZBGZML4egdhAIurcC/TzD4sl87hrv2NPHnG5idzz26G/ZjercaIA2E0wCRuKEWKb 0wFTc+W+WcpsX21876ka32XmAA5iQJgH3FFG9QPtC9gQVRqWTrkoBc6N2DKIPtb1i/dZ TbO5sLrYoxBiA0kG6Pq4zwvlHESrv491CaJGrMFrshm9b1y3omwi4lTT+lVW/arPDzPc JvBmaofIxnMdW1nD5e1wWFeAzjk+65Z0I85E/Rs6VCLrPuL0DMx6TiAmlVWTs62CCV/8 GB4Q== 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=FzDtUCBVDarM3BYezObGDuNytmVTRaxqo+H18+2TjpQ=; b=CgsX48J864Lizr/gTuv4jYn5ht67mh69sh4KETWKIIAtT8PP+VNzFcftTznBR55jRS tqw8opeA61jLEn27Ge0tTXSjmK3MpeZkhYa8qMMXAIpDoeReRqtI/3z9ryIUAwq7ems3 1T9biZTw8zS0+Wof0lSgK5E9ciXXeZcLh8Vf9cxdvEpXbYpeNxv6+OQ8D1l/LIL1hKNl GteOsprXdQk77l+7ujahPk99Bj5h67JhZk+TObH/KAuJtmFo5m1KGDLbiCJpefvlT/oD prZvuAs+VL9ydqM4xmw60kpm5ovAweFaK/aRAbn3mVu0a2nGUpuuUzR37Qq6+a6ViqyC yO7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gQqPjCFY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Ylp471lY; 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 u12-20020a170902e80c00b0016d0be7887csi1790660plg.518.2022.07.21.02.16.23; Thu, 21 Jul 2022 02:16:37 -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=gQqPjCFY; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Ylp471lY; 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 S230016AbiGUIoq (ORCPT + 99 others); Thu, 21 Jul 2022 04:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230152AbiGUIon (ORCPT ); Thu, 21 Jul 2022 04:44:43 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 809BC7F50E; Thu, 21 Jul 2022 01:44:42 -0700 (PDT) Date: Thu, 21 Jul 2022 08:44:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1658393081; 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=FzDtUCBVDarM3BYezObGDuNytmVTRaxqo+H18+2TjpQ=; b=gQqPjCFYGtT1ovWOjuM+J80YePf8vp5eCq4IGnLf+m9EocevlXjqsoEhg1wc0+ZYWYRKAO JYlzpDfw0WzicwI3n1kNTzPrck5yXM3hjSeNcr0ZXG30KGcHx2MSSoCTW2Hl+Ip39cjFjH Hg4rFB8H817c+Gwigi+4WyU/cHtq4iw3k48zkpHgHRWLVTCnRBQjRy++FLyTIwD+CB5QYA MtLQj9fVR0+0x/kYoXx5FS6zWDWSGih21BNbi2SATilyESspQ5+TKKOS9XfSazPgMJX8uP oxPlvkFQRacJqZz4KmCt/ODIySUNlXce3f6RBPE3Pw1iHRauylCDSNISv3Xjxg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1658393081; 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=FzDtUCBVDarM3BYezObGDuNytmVTRaxqo+H18+2TjpQ=; b=Ylp471lYWeUzbPZdu/qjfctZCm+rEsgOIBR4IKZ9qDN70SxntuEp8C1A97pmPSGkMzNy6J 6deQeVsHmyOcxrBw== From: "tip-bot2 for Cruz Zhao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/core: Fix the bug that task won't enqueue into core tree when update cookie Cc: Cruz Zhao , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1656403045-100840-2-git-send-email-CruzZhao@linux.alibaba.com> References: <1656403045-100840-2-git-send-email-CruzZhao@linux.alibaba.com> MIME-Version: 1.0 Message-ID: <165839307992.15455.12098942648295607427.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 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: 91caa5ae242465c3ab9fd473e50170faa7e944f4 Gitweb: https://git.kernel.org/tip/91caa5ae242465c3ab9fd473e50170faa7e944f4 Author: Cruz Zhao AuthorDate: Tue, 28 Jun 2022 15:57:23 +08:00 Committer: Peter Zijlstra CommitterDate: Thu, 21 Jul 2022 10:39:39 +02:00 sched/core: Fix the bug that task won't enqueue into core tree when update cookie In function sched_core_update_cookie(), a task will enqueue into the core tree only when it enqueued before, that is, if an uncookied task is cookied, it will not enqueue into the core tree until it enqueue again, which will result in unnecessary force idle. Here follows the scenario: CPU x and CPU y are a pair of SMT siblings. 1. Start task a running on CPU x without sleeping, and task b and task c running on CPU y without sleeping. 2. We create a cookie and share it to task a and task b, and then we create another cookie and share it to task c. 3. Simpling core_forceidle_sum of task a and b from /proc/PID/sched And we will find out that core_forceidle_sum of task a takes 30% time of the sampling period, which shouldn't happen as task a and b have the same cookie. Then we migrate task a to CPU x', migrate task b and c to CPU y', where CPU x' and CPU y' are a pair of SMT siblings, and sampling again, we will found out that core_forceidle_sum of task a and b are almost zero. To solve this problem, we enqueue the task into the core tree if it's on rq. Fixes: 6e33cad0af49("sched: Trivial core scheduling cookie management") Signed-off-by: Cruz Zhao Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/1656403045-100840-2-git-send-email-CruzZhao@linux.alibaba.com --- kernel/sched/core_sched.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c index 5103502..93878cb 100644 --- a/kernel/sched/core_sched.c +++ b/kernel/sched/core_sched.c @@ -56,7 +56,6 @@ static unsigned long sched_core_update_cookie(struct task_struct *p, unsigned long old_cookie; struct rq_flags rf; struct rq *rq; - bool enqueued; rq = task_rq_lock(p, &rf); @@ -68,14 +67,16 @@ static unsigned long sched_core_update_cookie(struct task_struct *p, */ SCHED_WARN_ON((p->core_cookie || cookie) && !sched_core_enabled(rq)); - enqueued = sched_core_enqueued(p); - if (enqueued) + if (sched_core_enqueued(p)) sched_core_dequeue(rq, p, DEQUEUE_SAVE); old_cookie = p->core_cookie; p->core_cookie = cookie; - if (enqueued) + /* + * Consider the cases: !prev_cookie and !cookie. + */ + if (cookie && task_on_rq_queued(p)) sched_core_enqueue(rq, p); /*