Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp634935rdg; Wed, 11 Oct 2023 00:31:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4PYa49Qfd8l7r+9S9zAceiwQa1xYYaCKs8tyQpHPyFe2QWIgGHgiGFIIYUbpxAoMJMBVP X-Received: by 2002:a05:6830:4a:b0:6be:e1d6:821b with SMTP id d10-20020a056830004a00b006bee1d6821bmr19786158otp.31.1697009483012; Wed, 11 Oct 2023 00:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697009482; cv=none; d=google.com; s=arc-20160816; b=KED+gZmTVv3RMyzP5hS5fFh5RfwzpPMFCLhaH62gv1JHqQqBz1+As/HA43SqomJzcS fqyn5f9BqOuW2/Zzw64ZBHXYJ17qzuluKVlJMwjIuM2gXVDlqCDJOL7PvBnPivXG1Fdp a9mSdSswUpqkShhG+NM01+HQihTV6VGHQzsl5ER+XLayJHXACMT9uMdvN2BAQthJ5foy ZUVEcIH31OraaFDY3rfsaCxaXbgL7aDGmH11OXKHRXluV158PxRbhrV7rexMWIKlO4eB xiNbV5amaLvPuzeRCxVirzGja3K9/v0jdOjYKJSAendB5sPWq53jxhQ/2ZTx+4oB5UWP QZVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XxvTBcvRjfLauUJMvX0rv6rXasZpfykJyoESqp8dDTY=; fh=XpiPn/MVFfhC5CRzn5cT5q5iGdWPmFDEHOvC4FluDcY=; b=0/vjdAxF+mLEwUZQHtkosgMzf0VOAOxKT0KXlGqccYLLh76xDq/MmIpAW5pjIfqF86 oFOlu6s5RTa70NDRpu9vmGKtkk2D3oOY6OXUI33IfdMrvHZLFfdh62QAwGQ189OknJp1 bRbSPBoApuBTMJsLgBi8WgxCwhAOjNlVJyvqfHGf2gx8qbAzyHV001quoPZeNDI5L/KC fGLKCs9KtIi22g+FyvPLJgWlI3+DoNwjqhZ3RoCt+/57paFOFUWw3rA28abj4I4NF5PM qc9QAbO4GuFZdJ9WE6wXs2GP/YKX9CF6vzFEOAUB4pdahK2S/a+z/vlGHElKyDuVeTLW GMGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HWpoIUdW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id e26-20020a65679a000000b0057cbd803b30si14188490pgr.654.2023.10.11.00.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 00:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=HWpoIUdW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4870E80DB71D; Wed, 11 Oct 2023 00:31:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344944AbjJKHas (ORCPT + 99 others); Wed, 11 Oct 2023 03:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344731AbjJKHar (ORCPT ); Wed, 11 Oct 2023 03:30:47 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE978D3 for ; Wed, 11 Oct 2023 00:30:45 -0700 (PDT) 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=XxvTBcvRjfLauUJMvX0rv6rXasZpfykJyoESqp8dDTY=; b=HWpoIUdWoiOW3zB5+n1nuu7tfB 0Yv45lVixCmLgcjJW4kkzqyGxvhZDz+rg9tKfBxXs2UR89i8p4rGfhLC6z5Xo6DKeGUtKZHmfdual CfqFjlxAl4VY/tPeRjppEMaA8j7RHk75xj3ZJP1W2ySs7nnFg6hk8jgefLn7wxjqjbHGvx2ChBV7Y 7G36nr/T5qyG8a82SeU34sLFo6t1ErYdWyARkdURBEmc1Yy8Tn/vgf77EGLQd0Zp6n4yWOXh7nbAs 05sTp2YqizhkSJMV9va6jZZ1MdlRHfqTQlqfnIUQUkSpBEpHSFgMQ1doygn255zapu9P/d73WVZcl KqQMAHlw==; 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.94.2 #2 (Red Hat Linux)) id 1qqTfN-009S2G-OE; Wed, 11 Oct 2023 07:30:01 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6877730026F; Wed, 11 Oct 2023 09:30:01 +0200 (CEST) Date: Wed, 11 Oct 2023 09:30:01 +0200 From: Peter Zijlstra To: Abel Wu Cc: mingo@kernel.org, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, corbet@lwn.net, qyousef@layalina.io, chris.hyser@oracle.com, patrick.bellasi@matbug.net, pjt@google.com, pavel@ucw.cz, qperret@google.com, tim.c.chen@linux.intel.com, joshdon@google.com, timj@gnu.org, kprateek.nayak@amd.com, yu.c.chen@intel.com, youssefesmat@chromium.org, joel@joelfernandes.org, efault@gmx.de, tglx@linutronix.de Subject: Re: [PATCH 01/15] sched/fair: Add avg_vruntime Message-ID: <20231011073001.GI14330@noisy.programming.kicks-ass.net> References: <20230531115839.089944915@infradead.org> <20230531124603.654144274@infradead.org> <75adcb1a-c02f-4d7c-bd9c-ab4f403af3e8@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <75adcb1a-c02f-4d7c-bd9c-ab4f403af3e8@bytedance.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Wed, 11 Oct 2023 00:31:20 -0700 (PDT) X-Spam-Level: ** On Wed, Oct 11, 2023 at 12:15:28PM +0800, Abel Wu wrote: > On 5/31/23 7:58 PM, Peter Zijlstra wrote: > > +/* > > + * Compute virtual time from the per-task service numbers: > > + * > > + * Fair schedulers conserve lag: > > + * > > + * \Sum lag_i = 0 > > + * > > + * Where lag_i is given by: > > + * > > + * lag_i = S - s_i = w_i * (V - v_i) > > Since the ideal service time S is task-specific, should this be: > > lag_i = S_i - s_i = w_i * (V - v_i) It is not, S is the same for all tasks. Remember, the base form is a differential equation and all tasks progress at the same time at dt/w_i while S progresses at dt/W. Infinitesimals are awesome, just not feasible in a discrete system like a time-sharing computer. > > + * > > + * Where S is the ideal service time and V is it's virtual time counterpart. > > + * Therefore: > > + * > > + * \Sum lag_i = 0 > > + * \Sum w_i * (V - v_i) = 0 > > + * \Sum w_i * V - w_i * v_i = 0 > > + * > > + * From which we can solve an expression for V in v_i (which we have in > > + * se->vruntime): > > + * > > + * \Sum v_i * w_i \Sum v_i * w_i > > + * V = -------------- = -------------- > > + * \Sum w_i W > > + * > > + * Specifically, this is the weighted average of all entity virtual runtimes. > > + * > > + * [[ NOTE: this is only equal to the ideal scheduler under the condition > > + * that join/leave operations happen at lag_i = 0, otherwise the > > + * virtual time has non-continguous motion equivalent to: > > + * > > + * V +-= lag_i / W > > + * > > + * Also see the comment in place_entity() that deals with this. ]] > > + * > > + * However, since v_i is u64, and the multiplcation could easily overflow > > + * transform it into a relative form that uses smaller quantities: > > + * > > + * Substitute: v_i == (v_i - v0) + v0 > > + * > > + * \Sum ((v_i - v0) + v0) * w_i \Sum (v_i - v0) * w_i > > + * V = ---------------------------- = --------------------- + v0 > > + * W W > > + * > > + * Which we track using: > > + * > > + * v0 := cfs_rq->min_vruntime > > + * \Sum (v_i - v0) * w_i := cfs_rq->avg_vruntime > > IMHO 'sum_runtime' would be more appropriate? Since it actually is > the summed real time rather than virtual time. And also 'sum_load' > instead of 'avg_load'. Given we subtract v0 (min_vruntime) and play games with fixed point math, I don't think it makes sense to change this name. The purpose is to compute the weighted average of things, lets keep the current name.