Received: by 2002:a05:7208:1509:b0:82:bbfa:f723 with SMTP id o9csp218452rbf; Tue, 23 Apr 2024 23:56:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBu60gDfgGbUeXp71g+5lG5RwDPqNlyZZn8nV8SDKYKIlD++lijMt8nqNNoYTR5Q5quhBQKsupC3KFbHTp7SlzFP2mNQbbF1ekIYzIWQ== X-Google-Smtp-Source: AGHT+IGMIuTRLbUd43o7iC9zFOXFhco7V+DyDvbMsPldnkeC9RzYYbVtzPQGmoIEzI9yC/yI+ZlA X-Received: by 2002:a17:906:5394:b0:a55:b2f4:908b with SMTP id g20-20020a170906539400b00a55b2f4908bmr888341ejo.18.1713941794535; Tue, 23 Apr 2024 23:56:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713941794; cv=pass; d=google.com; s=arc-20160816; b=vjAq+mnhYDvS8cLrdQmOTI6LZNbpT8zsKVdqWKunWR2YXTiN8JenCN+PiBPsXkENJp yLm1Uooljz1xWe2rwc6kUSi8QiSkBz+oQ+hdK4C1qJpUwaAVercpVoyKQXKcmBcyElNe P/aJ9alybji2iQr4isBjs109BU3c2sg8fzNk6VS9q+v1ZlZrqd/AS4gbmYge7h8htQ8L rDfJkTxxu117CexAAnL+xdWkrztRe/Yaaht1utQxQn4dhOi8MYYEDOznEZVxDJKdPQ87 xUTt9UiP1Fnfhg7/xPIBcpqesy8sg5k4nIRw+A0jKkR1UJn++7axGZcXYk8LLsEdzohE U4xw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=XgR49zR6ty/YN6URwbI1ia4am21R9HACnCsXNHHFEdE=; fh=6MX2t/gitbB0GDq8WiLvJnkGsbZEgaePNliIc1BLmMw=; b=NLVLqWTq1qDeKn/vvZPsCgVg6KxQiVJ6pvNwQ2wvhzfYct4vz5U1Rh8ZKdgFK632IY CoD7kDslNBhxFAzxcu+fXLrnlIdhuvdBvzkI7FgY3uzooJ9XEJIQRqSj3Hsmo9RYM1+6 dVh7Ww/xHyRMvCZzR0VKENpZYUdum+N+b+1ez71OHn8XkbOBvwNfXvjykFdjYU9iALG8 AVYtrxkmWUuhM+5bdAi6BHjJAHMAhqHoQSPrv4Js41M3FcwkoEZCJSYUhpRqeogLMtqQ P1wN7Yd5QWcgWVKXy7Dv0Zo17y/GKFi6ot50XWPMbSVZPfzAfHY3xr9iI0zO0Tlv7Cby tYvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N4cAqKB5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-156419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id wr12-20020a170907700c00b00a5201d75f4csi7940058ejb.611.2024.04.23.23.56.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 23:56:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156419-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=@gmail.com header.s=20230601 header.b=N4cAqKB5; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-156419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 23B4E1F23C7F for ; Wed, 24 Apr 2024 06:56:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 839AE157A47; Wed, 24 Apr 2024 06:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N4cAqKB5" Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3F7115667D for ; Wed, 24 Apr 2024 06:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713941653; cv=none; b=sLoxFdSswl5+rhsAtsH1OPtQhTF09vsdkmiYN1E29tubesOihzePNdQLsAHTkNx0P7tM73RLiapERyn+3TjBa/DJUIvkaf4oVjFOKPEnC50I8v5JLBmgTmch7807fgSVoJctVodfDHf8grqrWisWAbcbHyAa8/lerO6C3E1cZH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713941653; c=relaxed/simple; bh=tN3xGdvpOebKvhqjyvdHhJXLe8z4Riqv3R95vxxSXpI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=QmBHQf2TnhQNx/GOQullQo9GQshzGaJQoVXFsfUccX/Aeb+FtJM5OUedz+JNbkY4bswod6XnByvU7R1l6RBfUN1Fychf3LBRIDTY8xK2O73cv/piywI7yl1jiR4iQqgcqcOKdtnBAFWsPaVr3ikDpMcne1AGpuIQS/HnDj2+cxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N4cAqKB5; arc=none smtp.client-ip=209.85.210.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6ea2ac4607aso3057548a34.3 for ; Tue, 23 Apr 2024 23:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713941651; x=1714546451; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XgR49zR6ty/YN6URwbI1ia4am21R9HACnCsXNHHFEdE=; b=N4cAqKB5r9+ZtIzJ0CvAuUTs48ZWGhgsmnQ4+0P/UqKu10FWieWvSmm75HcAV4qcVb q9/2bSXXZJIDKmafp+MUYdyEWwRu4WpiIAz+zDilXoUZm22gOXgIukdp83EZbGupQABt 2BuWbaT+jY79IYENyOgo+zbx90/YVTzFwoHMzKVosshZkS3lXk19ID7ERJyMXSKTVPIW jbe5WdEObx+NZyJm8pzTJtj+iRqPCBfj9hSUdB2Vm77NjFdUlcwmZvL2PhU5Fjde440c rgdoP2WrPkvs/Dj9ugi208VZeTXZ1KmEipCUIHFY5uD7H9dx8w98nrEDVV1aeHP69sbK J1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713941651; x=1714546451; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XgR49zR6ty/YN6URwbI1ia4am21R9HACnCsXNHHFEdE=; b=DZUUYji55ynPiIEP7OYIgSCXh/LhwIrbLakedXyb64wb5gByvUzSvwbefbp4W5WRRR q4DZSH0Yfhw9ZFi+BeDho3rt5ILVKaj1yOe535qoL/8MsvlZLvjhQBNiZ8MSwN7TbWED fNcHlVIy6fPTaVJWtty7oNdfASaXbOIFBLLEG92va67LwpJ7juWixJTsQMHMNTwhq821 v57RHViG4jtFi2T8waKmM7QF4hmi6UC6XsUUY0RElQoF4cLZVMrUa8Gqn4AW03+wOcvh xqom4UoBrOU5ntUdZdowWEiVikivzAD+00sHy0+1RxaWDHU0Rr1Cg+uZb26CgQd3DLKa q6lQ== X-Forwarded-Encrypted: i=1; AJvYcCWkiRpOpOGd3IsgyPmSmdkkq2DQNd2FrO8ZlrccjL8LbikzQJf0/OMwAp6JtgMJf29W2id58kBPomQdXvRim6mv00f3n0/zDqyBIO/d X-Gm-Message-State: AOJu0YzpCIzOvzpJKZfplLPhUYjaXp/BbIaIK0tyOePdV6nNw0uramkL h8G2ms1yhThQywo9WUnM5vrt6W/ZvB8nLCCpaNdGBzVX4JjrpQwq35Qqk+BxVsAStn1ELl4XjoQ 676ST3rDouG4X6lp+1i0FQnphERw= X-Received: by 2002:a05:6870:3853:b0:235:489d:cea2 with SMTP id z19-20020a056870385300b00235489dcea2mr1634250oal.7.1713941650584; Tue, 23 Apr 2024 23:54:10 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240422082238.5784-1-xuewen.yan@unisoc.com> <20240422094157.GA34453@noisy.programming.kicks-ass.net> <20240422111744.GO30852@noisy.programming.kicks-ass.net> <20240422155937.GP30852@noisy.programming.kicks-ass.net> <20240423114836.GA24704@noisy.programming.kicks-ass.net> In-Reply-To: <20240423114836.GA24704@noisy.programming.kicks-ass.net> From: Xuewen Yan Date: Wed, 24 Apr 2024 14:53:59 +0800 Message-ID: Subject: Re: [PATCH v2] sched/eevdf: Prevent vlag from going out of bounds when reweight_eevdf To: Peter Zijlstra Cc: Xuewen Yan , 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, yu.c.chen@intel.com, ke.wang@unisoc.com, di.shen@unisoc.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 23, 2024 at 7:48=E2=80=AFPM Peter Zijlstra wrote: > > On Tue, Apr 23, 2024 at 11:05:20AM +0800, Xuewen Yan wrote: > > On Mon, Apr 22, 2024 at 11:59=E2=80=AFPM Peter Zijlstra wrote: > > > > > > On Mon, Apr 22, 2024 at 09:12:12PM +0800, Xuewen Yan wrote: > > > > > > > By adding a log to observe weight changes in reweight_entity, I fou= nd > > > > that calc_group_shares() often causes new_weight to become very sma= ll: > > > > > > Yes, cgroups do that. But over-all that should not matter no? > > > > > > Specifically, the whole re-weight thing turns into a series like: > > > > > > w_0 w_1 w_n-1 w_0 > > > S =3D --- * --- * ... * ----- =3D --- > > > w_1 w_2 w_n w_n > > > > > > Where S is our ultimate scale factor. > > > > > > So even if w_m (0 < m < n) is 2, it completely disappears. But yes, i= t > > > will create a big term, which is why the initial vlag should be limit= ed. > > > > Okay, I understand what you mean. Even if the weight during dequeue is > > very small, the weight will be eliminated during enqueue. > > In this case, the necessity of the !on_rq case does not seem to be > > very important. > > > > On the other hand, the following case: > > place_entity() > > { > > ... > > 5244 load =3D cfs_rq->avg_load; > > 5245 if (curr && curr->on_rq) > > 5246 load +=3D scale_load_down(curr->load.weig= ht); > > 5247 > > 5248 lag *=3D load + scale_load_down(se->load.weight); > > 5249 if (WARN_ON_ONCE(!load)) > > 5250 load =3D 1; > > 5251 lag =3D div_s64(lag, load);<<<< > > ... > > } > > So this plays games with scale_load_down() because this is W, the sum of > all w, which can indeed grow quite large and cause overflow. > > > reweight_eevdf() > > { > > ... > > if (avruntime !=3D se->vruntime) { > > 3770 vlag =3D entity_lag(avruntime, se); > > 3771 vlag =3D div_s64(vlag * old_weight, weight); <<<< > > 3772 se->vruntime =3D avruntime - vlag; > > 3773 } > > ..... > > } > > While here we're talking about a single w, which is much more limited in > scope. And per the above, what we're trying to do is: > > vlag =3D lag/w > lag/w * w/w' =3D lag/w' > > That is, move vlag from one w to another. > > > There is no need to clamp the above two positions because these two > > calculations will not theoretically cause s64 overflow? > > Well, supposedly, if I didn't get it wrong etc.. (I do tend to get > things wrong from time to time :-). > > I would think limited vlag would stay below 1 second or about 30 bits > this leaves another 30 bits for w which *should* be enough. > > Anyway, if you're unsure, sprinkle some check_mul_overflow() and see if > you can tickle it. Okay, Thank you for your patient answer:) BR --- xuewen