Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp481845lqt; Fri, 19 Apr 2024 01:25:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9y7YNonlBhTj6wclnNGL03ZoNcKVBaIs/YdaOE+t+fdEghIdXNGBnTzQSjz54bnHJs7D2IJ+SzBNfe+CcvvMStR7CL1Ct7rpPodohvg== X-Google-Smtp-Source: AGHT+IHvsqetWgDzF2I0ll9HyigmRxei7eD4KJ6omhJSpZu9Ec8OlQFYELzcNdj3Q1RjMju9aQEm X-Received: by 2002:a17:90a:7c48:b0:2a5:3c66:25a8 with SMTP id e8-20020a17090a7c4800b002a53c6625a8mr7120679pjl.15.1713515104912; Fri, 19 Apr 2024 01:25:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713515104; cv=pass; d=google.com; s=arc-20160816; b=TgObh6p0hQvVkoEcJx5ma/rZJw3O93/a3qI/YaU37CZFvypkQJryBbnOe5iB+xbn/+ hT2dsVnfOj+Cn+3Gf1yqMkVBkewMFI1LxZR2gyMPsjQeDqQhK/tmz9ypXio0A0b8ezMS L9PDNH1hEQOrCxI2QJj30CjFu3tfQT73NlTdcYLvF9zAKShS4cq9jIpGbahzvDh5L35X FrnxYxrQFKToYhTHgVa+Vw0RdxYdq/9voHtt7R0h9QSxyMIhz3x6pjsS8NHhg0a86Lsj P/2SPTJ32I8hBzk1VdiHgToHC6r7mg2m8OGJDl1tAfIaiePu2WL4ahHWiFuNAIjNEUHh DAsQ== 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=hWwmKuXcipLwwNOWyBLW6snZ40xHGiVaXCKs4svZ0Ng=; fh=ghHzLRQKhbkwxRqv+1lB2fTjYC0fi9XZ47dKClRFPBQ=; b=CijzEUnhAeSXQfjBS/UBrfpZ+Nw4nmVcCTgpFALxBG41AHicN5lhCrNz3vTeuhXeaw DetVdnyB58kYW+Y9o1I3wk/doEV74lO4s9QKi4cRTZT49cjuy6rms147+cHU5bA+Zs1c KSu+z+QDR6/+DBZUgzLx1RRgUC3+RgrgbmvrwEt/8vjeerGBanMwkPkCjj9YanaZXvfb 2aAsO/zSpv+6oIYq0vkrb+VAVRF6moJkl6RYAyuohiKDsmjfQOwCh4zexfb8+1cDt7jf AZrVXc5ooDPTxC/uxtt5dftqXkzoKs+DxE8HgMVv2BVALFx/OlHYVZ88qU6Ro58ex4JF Eamw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KmVmXHmN; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-151159-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151159-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id pi5-20020a17090b1e4500b002a5bccc1b7csi3154261pjb.176.2024.04.19.01.25.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 01:25:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151159-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KmVmXHmN; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-151159-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151159-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8D78F28239F for ; Fri, 19 Apr 2024 08:25:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F241752F85; Fri, 19 Apr 2024 08:24:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KmVmXHmN" 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 D9E1E3EA8C for ; Fri, 19 Apr 2024 08:24:55 +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=1713515099; cv=none; b=g9ztNbIARQsZPenwcXSz/fMKcSuDhwfl+yYct2uQ8eNQgxDvRFMbzGcBJvGvSfHAfjydKWC0iCEfD6RPBJwBCMZJZIO3r1t1oEkyfPQ23pK/OWeaQRwD44ojXg2JxJ6I+aUBiGMkJFEUeqd3tNnDkqRkkkHaw3Nfp6d2lkv9KI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515099; c=relaxed/simple; bh=uGJ6gQhF4xtaVh8DkoSSMEyowEiQyVEblcOoCU+SWmU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pULV/8pRXOX0dxVSKCkeO6uhRBvh3qtI3fO7JL+zJmZzYwkkSexetEbOWM/gcUBPgOPw0n9dRMU+pEeA5ik7mF/KZ+CY6S5FtilXS4gyneB2Cf38zri3nW8RIic2iADb41NtQQvJ2md2kBGMDM9p+BP4q1Xc0XrhkzMi6QaT5Bs= 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=KmVmXHmN; 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=hWwmKuXcipLwwNOWyBLW6snZ40xHGiVaXCKs4svZ0Ng=; b=KmVmXHmNDe9L0zzayfyNQaGwFa uKdI8HtxzIx+osADnb0urrkc0NzUnlS8O1c4WL/uRCr2vulhP1BpsvTDrC5dZaaCsYEMJm97rj8AL ZY5R+lKfPOXhgnx537Y7lBXBxzXiyx2noLnS9Xmtu1Oz0pgs+aQ6FFT5S6fo4urklTWvtZTCrXBus ygNqV9Pc7irh4+8PT3I8Apl/uEnWRNzagUlNU6SNSjkHvROo2CzL89lUAMsDE5VbnTpdQBzg+WYvf 1Thdyt9t63z1ux9RDZgFm65JwqBNBsH4dKt7wJ/IE8gg4MW+Jhfil0ELp0NLqwON1BK80AexUfiIE 7+R+Qo9Q==; 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 1rxjY0-00000007G8h-2Egm; Fri, 19 Apr 2024 08:24:40 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 33D093005AA; Fri, 19 Apr 2024 10:24:40 +0200 (CEST) Date: Fri, 19 Apr 2024 10:24:40 +0200 From: Peter Zijlstra To: Chen Yu Cc: Xuewen Yan , Abel Wu , Ingo Molnar , Vincent Guittot , Juri Lelli , Tim Chen , Tiwei Bie , Honglei Wang , Aaron Lu , Chen Yu , Yujie Liu , linux-kernel@vger.kernel.org, kernel test robot , Tianchen Ding Subject: Re: [RFC PATCH] sched/eevdf: Return leftmost entity in pick_eevdf() if no eligible entity is found Message-ID: <20240419082440.GB6345@noisy.programming.kicks-ass.net> References: <20240226082349.302363-1-yu.c.chen@intel.com> <758ebf4e-ee84-414b-99ec-182537bcc168@bytedance.com> <20240408115833.GF21904@noisy.programming.kicks-ass.net> <20240409092104.GA2665@noisy.programming.kicks-ass.net> 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: On Thu, Apr 18, 2024 at 09:03:36PM +0800, Chen Yu wrote: > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 31bca05c3612..9f203012e8f5 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -696,15 +696,23 @@ u64 avg_vruntime(struct cfs_rq *cfs_rq) > * > * XXX could add max_slice to the augmented data to track this. > */ > + > +static s64 limit_entity_lag(struct sched_entity *se, s64 lag) > +{ > + s64 limit; > + > + limit = calc_delta_fair(max_t(u64, 2*se->slice, TICK_NSEC), se); > + return clamp(lag, -limit, limit); > +} Right, helper makes sense. > @@ -3721,6 +3729,7 @@ static void reweight_eevdf(struct cfs_rq *cfs_rq, struct sched_entity *se, > if (avruntime != se->vruntime) { > vlag = (s64)(avruntime - se->vruntime); > vlag = div_s64(vlag * old_weight, weight); > + vlag = limit_entity_lag(se, vlag); > se->vruntime = avruntime - vlag; So the !on_rq case has clamping in update_entity_lag() which is before scaling. And that makes more sense to me, because putting a limit on vlag before the multiplication *should* ensure the multiplication itself doesn't overflow. But now you allow it to compute garbage and then clip the garbage. > } > > @@ -3768,6 +3777,9 @@ static void reweight_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, > > update_load_set(&se->load, weight); > > + if (!se->on_rq) > + se->vlag = limit_entity_lag(se, se->vlag); > + Except you now add clamping after scaling too, but in a really weird place. Should this not go right after the div_s64() that scales? Unlike the reweight_eevdf() case, there might be an argument for doing it after scaling in this case. Namely, you can have multiple reweights stacking their scale ops. Also, could you put a few words in on how often these clips are hit? I suspect it's fairly rare (but crucial when it does).