Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2528144rdb; Wed, 15 Nov 2023 03:34:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IER/Dn+Fves2L6MW14nlTIa5l6k3+A2AtPGsxSk/oIA74xu8DVXFrX36S8VbsigzDZKFLx8 X-Received: by 2002:a05:6a00:8d82:b0:6c3:468c:6caa with SMTP id im2-20020a056a008d8200b006c3468c6caamr8093295pfb.6.1700048061986; Wed, 15 Nov 2023 03:34:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700048061; cv=none; d=google.com; s=arc-20160816; b=s94nLWCS6DfGD58o8MAtPNtI8H2CxWWOM0lbLf8ixazQETzF7SQtymYVa333d/U0DO XKRfeD5ipM0nmhKXoh21DRNV6v05+Rh7aCI4YiznzdtiUHKJp7Hjj13DbkcYrxHBHXXG R3riMgyrKWYNiRMP09MuUXUQtvIHbgv9cp+xVRruhK/BtX2yvt0K3Qm/LRr7yjhXeC/K XkMgOLX8mOQf3WxBKeXhWXqa2YdQoTtIMXS1KpvdFY9zfDIhOY/RHo2mtUFiJYfa2N6h nz4kSn/55NjrkV1WUczjgUqTCg85P9xUbtzo5A2xZ2seMVgM4gX3XGjpowT2Qwdij4ir 1wUw== 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 :message-id:date:subject:cc:to:from; bh=Lk9nxR1+tPNpbHnDbEc0soLCyhir+WCzlzWR8FAvJmo=; fh=QlmRtWuTYJDhaxF0GCu0nvK7RUqeTMNKD6hMg0kv7eo=; b=vQa4yYoY7g88d0B+zTjxrM6xle332Hud7wDI9l5XZkNiYMR54dJ5rFv5iCSwaSOyqh vY39hRzXwv7CN+Ip7Kpayc1EJV+9uFUVXHsqd48eLk9DCDlN2M9WMl8hiskQigun3zOx o+bUFTWMKZY1oB7iQ+jxoizW1n5ZnIVrSV33kyLUgYJ0JEnw4Mfd+w2RvyPVudFPoNal WlO2MCTJzo0hwj4oiJde/Kzq9+pfKRePx3rq0bzYG3adADW4ISl3sRBJSuKaBGppwxjh zafvQA2Mb/aM+WY4h7czcyj78rogSOOvW0aKLYZ6vFCrP1tGaH6bxtQpZWG/YNkdDmyX 0OXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s36-20020a056a0017a400b006c3535bfc77si9997449pfg.82.2023.11.15.03.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 03:34:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 0E2B7802646A; Wed, 15 Nov 2023 03:34:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234923AbjKOLd7 (ORCPT + 99 others); Wed, 15 Nov 2023 06:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234114AbjKOLd5 (ORCPT ); Wed, 15 Nov 2023 06:33:57 -0500 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5107C109 for ; Wed, 15 Nov 2023 03:33:53 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VwSxxJq_1700048021; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwSxxJq_1700048021) by smtp.aliyun-inc.com; Wed, 15 Nov 2023 19:33:50 +0800 From: Cruz Zhao To: mingo@redhat.com, peterz@infradead.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, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 0/4] sched/core: fix cfs_prio_less Date: Wed, 15 Nov 2023 19:33:37 +0800 Message-Id: <20231115113341.13261-1-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 03:34:13 -0800 (PST) The update of vruntime snapshot will cause unfair sched, especially when tasks enqueue/dequeue frequently. Consider the following case: - Task A1 and A2 share a cookie, and task B has another cookie. - A1 is a short task, waking up frequently but running short everytime. - A2 and B are long tasks. - A1 and B runs on ht0 and A2 runs on ht1. ht0 ht1 fi_before fi update switch to A1 switch to A2 0 0 1 A1 sleeps switch to B A2 force idle 0 1 1 A1 wakes up switch to A1 switch to A1 1 0 1 A1 sleeps switch to B A2 force idle 0 1 1 In this case, cfs_rq->min_vruntime_fi will update every schedule, and prio of B and A2 will be pulled to the same level, no matter how long A2 and B have run before, which is not fair enough. Extramely, we observed that the latency of a task became several minutes due to this reason, which should be 100ms. To fix this problem, a possible approach is to maintain another vruntime relative to the core, called core_vruntime, and we compare the priority of ses using core_vruntime directly, instead of vruntime snapshot. To achieve this goal, we need to introduce cfs_rq->core, similarity to rq->core, and record core_min_vruntime in cfs_rq->core. Cruz Zhao (4): sched/core: Introduce core_id sched: Introduce cfs_rq->core sched: introduce core_vruntime and core_min_vruntime fix vruntime snapshot include/linux/sched.h | 3 ++ kernel/sched/core.c | 37 +++++++--------- kernel/sched/fair.c | 98 ++++++++++++++++++++++++++----------------- kernel/sched/sched.h | 5 ++- 4 files changed, 81 insertions(+), 62 deletions(-) -- 2.39.3