Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp333841lqt; Thu, 6 Jun 2024 05:17:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGz6r/XzT4jaexzbOcwKOiCv3sTpvytsSML3Uc4rr0QOBib9hd7+emlUOWaUK2RNrbLxNVBdzv6X/ROMs5FZJJWUFHAvVrYtjh4Ps/cA== X-Google-Smtp-Source: AGHT+IE+0+Jjw/jvj7sz/fZK+xhzT2zUII6ICHcQdZ5GF/vKiCmOdZs+eGwVuBh/dsh65QXqEszb X-Received: by 2002:a05:6e02:1847:b0:374:9c31:1206 with SMTP id e9e14a558f8ab-374b1f0cb58mr60780695ab.17.1717676237911; Thu, 06 Jun 2024 05:17:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717676237; cv=pass; d=google.com; s=arc-20160816; b=LsgSOqOUpHOMFJ7hZ+r1VI+RqK+y85ctoMpF8Ywvji6OSMYvWXQWFkD+DQCZARVndr nF0SchLqKnWcVtcjKz5vneUnEpE9myc/DjAz+61Due0Ff3YlYxxY3LEm9RVLK02zDfoR Xb+SAgC7ijpNvSdaBWV2V3sZKGPlA5DxBifQUM1I71vuzUL8mK+uYf/qvzW7OUalNV1M W9NMoLfloD2+h+Gc/gpkf2vD/JUwu5Q22BXRVXH9LAzsusz5+4CZoDEPYlWg8Icsle88 bb43SBe04Z1EsRDM/FYaLKt/aoRBw8q820fJDp9N7HhTht1BAgH7fJc/ETHCrHlPb9Rl l5hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=Ux3c4GrH0j+qzqsRoY6/yNW16+IpBpBK4wDcWMtCATU=; fh=7izcEXAdPngrOUFCaBplH9kUZiD2omwYlL0l3u8HGT0=; b=NfR+uGnkDkbUPPlbJE5eD/5B7MZ4m74yRuf9xv9cbbQt1eBoIeHQLvFOwj4tyXSIFE twK4YLRH2Oiu4MsP+AZMUvFT1InVREii3M1iPvRaShc7ik1NgsM1qb3fImkL/kXW6GfK FXXMAUsufKsBtwUqqjpKaAxjiEyo8XAPDRDcGlYgWQvDIHnRLjY3BuSVZlizJ/ruNdOy oHM7kzxpG6i51/bAGWXRMIgLWrTwCa3HwRjWMvRpGcZXCF2YdixBkcNVQmtGKi95/DUf MTgu2Zd8CeMCbjoMLOvHzT5RWrgm2dbeP802P//5iB08u6FpCEw/naieklilUrBWlxI7 E/kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-204257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de2073c4afsi1069301a12.45.2024.06.06.05.17.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 05:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-204257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 90B822866A5 for ; Thu, 6 Jun 2024 12:16:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C047713BC26; Thu, 6 Jun 2024 12:13:32 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C89641667E3 for ; Thu, 6 Jun 2024 12:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717676012; cv=none; b=Sq21LrnPBoWoyuueqUFbHfCQMgc/XuWe94z8KJsMZEANTLl58ZRS39rQ5wv/H0XVQ9HrwxNEdr01DLsA8rFj4UxdLggy6XIWpJlwW4vRCrzddNkT411yafx8E1dxAgm77X/T+PBH9MCFtSeLT2jls05MwT0Djlr4wcUyp1912e0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717676012; c=relaxed/simple; bh=tPvfH57TFgOP+d7fqdIVp6YeHGR7Kb6r3bxVdfQgS8Q=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=TRqmGJdJxPrZIV+YZv+8D0ZtnI/rWGyhp4pYqLuTYYVKTm7u54BJ7kXUVpNhlCKSz7XM8x4l5g6cHNBugQLnk04jlXKlvdO1sUkcdWJ3NaIUqqsy72xLSKVn4C+711OeK6ToDgfOg5EovwHqs2mCQ83yYf1AZTH/6zPYJ3F9eB0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Vw36B5K6yzwPF4; Thu, 6 Jun 2024 20:09:22 +0800 (CST) Received: from canpemm500001.china.huawei.com (unknown [7.192.104.163]) by mail.maildlp.com (Postfix) with ESMTPS id C048818006D; Thu, 6 Jun 2024 20:13:20 +0800 (CST) Received: from huawei.com (10.67.174.191) by canpemm500001.china.huawei.com (7.192.104.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 6 Jun 2024 20:13:20 +0800 From: Zhang Qiao To: , , , , , , , , , CC: , Zhang Qiao Subject: [PATCH] sched: Initialize the vruntime of a new task when it is first enqueued Date: Thu, 6 Jun 2024 20:11:33 +0800 Message-ID: <20240606121133.2218723-1-zhangqiao22@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500001.china.huawei.com (7.192.104.163) When create a new task, we initialize vruntime of the new task at sched_cgroup_fork(). However, the timing of executing this action is too early and may not be accurate. Because it use current cpu to init the vruntime, but the new task actually runs on the cpu which be assigned at wake_up_new_task(). To optimize this case, we pass ENQUEUE_INITIAL flag to activate_task() in wake_up_new_task(), in this way, when place_entity is called in enqueue_entity(), the vruntime of the new task will be initialized. At the same time, place_entity in task_fork_fair() is useless, remove it. Signed-off-by: Zhang Qiao --- kernel/sched/core.c | 2 +- kernel/sched/fair.c | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index bcf2c4cc0522..b4ff595a2dc8 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4897,7 +4897,7 @@ void wake_up_new_task(struct task_struct *p) update_rq_clock(rq); post_init_entity_util_avg(p); - activate_task(rq, p, ENQUEUE_NOCLOCK); + activate_task(rq, p, ENQUEUE_NOCLOCK | ENQUEUE_INITIAL); trace_sched_wakeup_new(p); wakeup_preempt(rq, p, WF_FORK); #ifdef CONFIG_SMP diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index efce2d36a783..bb5f376fd51e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12702,23 +12702,7 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) */ static void task_fork_fair(struct task_struct *p) { - struct sched_entity *se = &p->se, *curr; - struct cfs_rq *cfs_rq; - struct rq *rq = this_rq(); - struct rq_flags rf; - - rq_lock(rq, &rf); - set_task_max_allowed_capacity(p); - - cfs_rq = task_cfs_rq(current); - curr = cfs_rq->curr; - if (curr) { - update_rq_clock(rq); - update_curr(cfs_rq); - } - place_entity(cfs_rq, se, ENQUEUE_INITIAL); - rq_unlock(rq, &rf); } /* -- 2.18.0.huawei.25