Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp941440lqt; Fri, 7 Jun 2024 03:31:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXfOLF+QvfQetCjcyA4zrxstVQmF7rq/4SFG/Oqw6mKVJ7WBrsYofwq1BS9rt0mUbqUj2xFaLaGVJwSjJQjRXMsASLjgc6KHSroamHjaw== X-Google-Smtp-Source: AGHT+IHUPVgN6bextZSVP1WXnUfzeEmKRKcenC5lU7vzfKSTdCpy/oDiig8fuf3IRuOQG7uSszmN X-Received: by 2002:a17:906:1d08:b0:a68:e4ec:6ed2 with SMTP id a640c23a62f3a-a6cd675cdb2mr140169166b.31.1717756269322; Fri, 07 Jun 2024 03:31:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717756269; cv=pass; d=google.com; s=arc-20160816; b=InA7mbL3dTotL59aL3HPUomGU5OFXCP+XJE/OddDCcuXmspEXDhPommvGMzgHP7lsA ht7kubEJC/M8NSpolXhLUMq6IS9GD1tWEqBdXYly4Co1aY4znaCsClrIABwNk+teuQt6 qcSl0a3tSP+SfClN0nDRS4WZuERuSaOs7f0Hi7+GuJgOapjVcqx52Vef1SN+h68fmL7l 7cvPaq9ft7T0b/0bdV1JBll+kHsVilqQnPDXwB4DTgffVKdDqihyewRIIP0SIdNTvrcQ mLMn3fO0Ijr7Z7CR1I5s7dp/QcOdRTJM7oxtyhn1MI+Vcf/aWIiEEC2+fn1IJGB96ysl 9sCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uyoBt0JfhrDyTzN3Vspe+/CrH6yaV6pDIoW5yTEXKos=; fh=lU/S4w+hqsXKJTNiZXSgcSuwXiotxal1fY/OA16lxXU=; b=SI5xPMZHokI2ZJdEx4OYlM3GAnCb2LbFP7AUn5VONw6IbDda3yXy8WH/UigacXDPuq wzH9iZ3zNj+WHUWdm15oMoCOTkzMbuy6kQ9C3vQ3/bwnC2uWKJRw8sJilCL5XkP8N7gX 8mIYbNsjxKoP8RxXSS8hjdB8U3As+5RuBxRFBTJvGsIez17RVYk4VzpQqDaVXVtYzCR7 0jru8TqwlsEEWZjSNQ8QKQtihY68Zodiv2Y70L71UxoBDwDsOIjXdAgxShcvGmSL6FkJ gTdTGoml6sZRNSsfUbLogdruRWixf9NhL7Oi5VElAXmdazck4FjCFLIsgRC3yGfGXQCJ x9iA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k6K3EGki; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-205823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205823-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c8074936fsi169845666b.1014.2024.06.07.03.31.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 03:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=k6K3EGki; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-205823-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205823-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id D85FD1F255E5 for ; Fri, 7 Jun 2024 10:31:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BC5E15B13C; Fri, 7 Jun 2024 10:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="k6K3EGki" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2F00B2F2B for ; Fri, 7 Jun 2024 10:30:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717756262; cv=none; b=p4OsNZjWBlEpmBuCDilYtvARO9DQ3ZuaMQWWzLIviWFjHcJyuPREIsIugh1xWb8m/mTHmXMvrgcZcFLYrSMQo5WSerJkUfcunghzHCj/h8nyhzUkN1Rzm8gyg3qL5IM3pYTpepOrP/Jm7UwMRyjd+tWMAlU6GdufaSobvBTF9aI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717756262; c=relaxed/simple; bh=TH4cscibZLSNy4YsDvEPmdXH2rRNMmDbYIaDLwboVUY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BArEq6yKmxkjm6FqxWT17qWsRdDFgjIJ+CxBUk8YOL69M9WNO70cTME5i7dL0dqdfi36RXa8RMB2eoE45+IR3vpGs22DFf8noNfuxMqGZQURZbCv7XJh5ErkUS+tdC9N6fcye34Lxwr0YhVaESeCzHppGHdvlihrfUth7N4Z1lk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=k6K3EGki; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=uyoBt0JfhrDyTzN3Vspe+/CrH6yaV6pDIoW5yTEXKos=; b=k6K3EGkiBF4XVnPjzFLdokzTJv ebb7u0invf9NHAcVPNjyfvZAjYjzyquHcuwO6ixuUQL24xR7iSMTXigMypLm3h5f54/q+NuiRhnnt xdeIZrT0Mh0KXGaeL1rPLIJXP3+3SE2SNZ3GOC06WOJnvmQQGTuc9FBWswRXk8AJ/al3v9V9cr6/E R29g+tPKXTqmYBvYNSxksz0Wu/0Sx6pMmH/YS/wO5NvWv/YZh9b6zq0hNbG+4cVfK7Okx03OO9U4P 7PJYWIU4plys4X0v5DrvOLXCwWmNxoFTZVMoBNgTY82eUvTW0bOvtqAvCIy10wuL3mf46oMraPgOP xCSSyjVw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sFWru-00000005IK2-0Ewb; Fri, 07 Jun 2024 10:30:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id E470D30047C; Fri, 7 Jun 2024 12:30:43 +0200 (CEST) Date: Fri, 7 Jun 2024 12:30:43 +0200 From: Peter Zijlstra To: Zhang Qiao Cc: mingo@redhat.com, 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, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched: Initialize the vruntime of a new task when it is first enqueued Message-ID: <20240607103043.GO8774@noisy.programming.kicks-ass.net> References: <20240606121133.2218723-1-zhangqiao22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240606121133.2218723-1-zhangqiao22@huawei.com> On Thu, Jun 06, 2024 at 08:11:33PM +0800, Zhang Qiao wrote: > 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. The better argument would've looked at history to see why the code was the way it is and then verify those reasons are no longer valid. Specifically, I think these are remains of child_runs_first, and that is now gone. Can you verify and update accordingly? > 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 >