From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796062607; b=e4mBNwBR0flNYNvi5hvn7kH20z+TnZMm0Z7v4fvO5TrEnEzOtD2Vyf7L13NgsYzCRRiO Jem0AyCM4V0jMmtyyLCo/0j4yIqVA58DIcXkfbhFxnFpl357fGvCb0HksB+twVJZQMFFS ZSC1+dOk25YdrtxMBwo7cECjpmc0IqArMCLYiXdQeERuBSeA/ujKS/79bvL6KRZ1Kxdr+ Ntdj1XUS8KbDJnHaya4BF7WVkS0+LbV1SFDMXnHp52heNgOYfcj9geX09spfUZr5TMMGP K/t5M2tlURHB7OOdyQRqUyf6q+JMAlIonQ048ZiF4bAqHc4KoUjEPPgRoZtLzGZGTqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796062607; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=50YdDMIUbLDq2T74wVTm0cCLnyGoKtEPRQ9K/cADVcc=; b=TuhhCvnvpn8TTIhy8B0T2VmGZODL8Vf3HpKCMNGELNewXjxiQ0G4YbvP9l2zrwOG9POf 5HhcovWSSzO46+xBgUwqgxNBXlxwU1YTm5h25jk1Tuu1G4eF0z6AeQsjtmcV+9+ltMtfZ AVc+kYHWQBpKKxonEC6TI2NtlGcPfahcrN/f07xHtcosPhJ7AnriRLfct8UjHTL+qtGoh +gr8AU3jPvpYSOsEbLVWED87Z8JWELTwmutbKP8BN4VP2oA6vdbHfaj+dQQjHMD8mxdyu 6lKwgswcdZEgaKaT09gQGg+BurLlzKmcyLcajid8x1KdRJ1Hi8P99QAWrXy92ZAccfg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ymD5KePG; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8848A606A32A for ; Mon, 30 Nov 2026 18:16:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8848A606A32A 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ymD5KePG Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4a3517554f7so97875265e9.2 for ; Mon, 30 Nov 2026 10:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796062606; x=1796667406; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=50YdDMIUbLDq2T74wVTm0cCLnyGoKtEPRQ9K/cADVcc=; b=ymD5KePGlAUZw+zNhSmfjrThGvqYl5Z1+jmYyNCGbXsh5KwyWZ4ACeJtXqHjqE02l4 ACEu1S38x7ZdMiuxEhLfVoW5f4Cz360kqhM2E40PwuVebJrESCEV4QDGxS0muERW3CwJ oJC+K4sSlvTpzStPs7X9tt9AIzInU3HXr72IbBYcA2xgiumZOj+EpCZw6lz4WgYn2KQu gA4e5gZYqUYHuUegUsxd65VMLK+CMjPwHYQKv7nuEjgu3PcBUD6fYRrqvwsVoZJ5LdJL 8EsM01BznnOOjxG8xkBFNtItGqqQsZeg3QoAfbMAqgt51TSl9/SNHPZKNDctGwDpxZje P2hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796062606; x=1796667406; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=50YdDMIUbLDq2T74wVTm0cCLnyGoKtEPRQ9K/cADVcc=; b=HU2dZgucGT039xx0HWxkY7MeYojlCHYlIx6UCGvQbeiEesKMjAGzhOaSurXwUcZ/Fb yM9BZaedjEBQ6aVfOiaihywd+w7ixTKrDExE31d1/RAVSAwZ0kBRQI+Rs8QVS//G/jEu w864Y4hGT/vVLviZenSDe/kYAaHVJtTpPtFerXybTq4a5A+uyzy+Bm5q/cwzKSJliBdV xUWIcfAEVgPQkYxYkrVonOhZpdNn7fxv9b6RZDsz4J0ymHqyfsBF4uXWF/J0MaR/mj0j 3DdzYWnNo22jZPvypBU2kZ40NgValyKe8dR5sBEsTl9y4B5VvnXVVddTNl5MdT8e0MLR bMag== X-Forwarded-Encrypted: i=1; AL+hErE23I16oAiJ2ojKTsHaY821ugo1yM/UUUVvc8DxcCkYnb8OOTI2NkClWIZGXFOkY3KiVDRgNmc=@vger.kernel.org X-Gm-Message-State: APuU4Z+OPvHw5uqTplrne5XdFSX6kRtN5M2aMEPvl4dbOXRvxa5fqD2X xUGJi0l005a4QMokQ28/PylitTkflI+oEWG/kcgnuIBBS1wdypSAo639 X-Gm-Gg: AZFdTZe6X4KPbwtlwk+5Ur1vPVuY5ddSVJz9Qu4CSbEjN6D+sTBEU8hn2IRQqEjwieg WJDQe/RA3xBGLiyWlJPr6ImQe3/1pdVtcisycRsV9An6xYEPrQ9XHdMiuumDDwgvdC5ew+nlo4R mAe4i9lKn58vjWIxYDPFkFr8o0E9ZtbBnyrKIscjT7OWBImxctoro3vzfCN12BTVgDLdXMJbQR8 +Ze8bjHSWVz9jd/iwmrq74ewedC8r/jsBQkZCm1opGQPGLznJc4wl/liZFfmbHmNyDEfn5mCvq5 6GKS1qOcTmxZPLM181M+jo62m31ir3HpfgJLDQyHyz4ckLzlhmwwvbYm8o8JZK6/w2ESpcpjjRI e/dz/SV26BrVn6gJfCDLSQqOfzjeaEbFwynt07Yt+kAw4gAUeO/evxgnINFgQMRPeAn/V8bvpaf gCU8OyCI8k9RfRnh2iQtMBhe8HNfNLEmni1YLpEcZo36CC6YcPEHJP5ebFJR5styJObDDGxcDTV HzU6dTOkD8Dn6FXGcNoDyQCZWnEy9n2QcDOKDg/19ko6ZfrJw2Ijj1bhQLIq1Fw8tvdhHXdG+4R pWMtMbCgYONegjr6+zOd9/Gf1XNSAw86t711CXEeftzKrvj3P1yIezNSrFDx13kIUg== X-Received: by 2002:a05:600c:1c08:b0:4bb:7757:fe6d with SMTP id 5b1f17b1804b1-4bb88804c5fmr859245005e9.11.1796062605660; Mon, 30 Nov 2026 10:16:45 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88f148aasm383984005e9.0.2026.11.30.10.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 10:16:45 -0800 (PST) Date: Mon, 30 Nov 2026 18:16:42 +0000 From: David Laight To: Mathieu Desnoyers Cc: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org, tglx@kernel.org, will@kernel.org, boqun@kernel.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, luca.abeni@santannapisa.it, tommaso.cucinotta@gmail.com, mathieu.poirier@linaro.org, longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, shuah@kernel.org, bigeasy@linutronix.de, clrkwllms@kernel.org, parri.andrea@gmail.com, m.szyprowski@samsung.com, kayracizmeci@gmail.com, weihengqiuu@gmail.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev, stable@vger.kernel.org Subject: Re: [PATCH v12 20/43] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Message-ID: <20261130181642.23d46e0a@pumpkin> In-Reply-To: <777f6ac1-d7e2-43cf-b9c0-19cd5bebf8a6@efficios.com> References: <3300daac81b2483e451bca006dfaa2da5b21fced.1795771148.git.mathieu.desnoyers@efficios.com> <20261130141225.1e78e5f2@pumpkin> <777f6ac1-d7e2-43cf-b9c0-19cd5bebf8a6@efficios.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Mon, 30 Nov 2026 10:26:19 -0500 Mathieu Desnoyers wrote: > On 2026-11-30 09:12, David Laight wrote: > > It looks like the casts were added to avoid an expensive 64bit divide. > > So I'm not at all sure it is sensible to remove them. =20 >=20 > The divide runs rarely, so I do not think its cost matters here. > __dl_add() and __dl_sub() run only when deadline bandwidth is > admitted, released, or moved to another root domain: > - sched_setattr() and sched_setaffinity(); > - a cpuset attach, CPU hotplug and a rebuild of the root domains; > - a write to the parameters of a deadline server in debugfs; > - the load or the unload of a sched_ext scheduler; > - a task that leaves the deadline class or exits; > - a task that wakes up or migrates into a root domain that does not > count its bandwidth. Patch 14 of this series adds this case. >=20 > Each caller first counts the active CPUs of the root domain, with > dl_bw_cpus(). =46rom the above it seems like that is 'almost constant' so doesn't need recalculating all the time. > __dl_update() then writes the extra_bw of each of them. > Next to these two loops, one divide costs little. div_u64() is one > divide instruction on 64-bit, and one or two divl on 32-bit x86. >=20 > > Changing to (u32) is enough to stop the sign being flipped and requires > > 4096 CPU before there is any overflow. =20 >=20 > Two problems with (u32): > - In __dl_add(), -((u32)tsk_bw / cpus) is an unsigned int. The s64 > argument of __dl_update() then gets a large positive value. Nope, the unsigned int is converted to u64 before being converted to s64. The existing code is doing a signed divide so can generate 'very large positive values'; just changing 'int cpus' to 'unsigned int cpus' would also have the same effect. > So > extra_bw would grow instead of shrinking. > - x86 with MAXSMP allows 8192 CPUs. A sum of bandwidths can then still > pass U32_MAX. That probably means that a lot of the '<< 20' should be '<< 19'. >=20 > > If this code runs every time a deadline process suspends it could > > get very expensive even without the divide. =20 >=20 > No. A deadline task that blocks or wakes up changes only running_bw > and this_bw of its runqueue. At a wakeup, only the last case of the > list above calls __dl_sub() and __dl_add(). It does so once, when the > task changes root domain. >=20 > > The code seems to have loops across all the cpu - so I'm not sure how > > well it actually scales for large systems. =20 >=20 > Those loops are already in v7.4-rc2, and this patch does not change > them. They run only on the paths listed above. Indeed - that doesn't mean it is a good idea... There is nothing in the commit I read that added this code that mentioned anything about performance. > > I'm also not sure of the locking for the 'rq->dl_extra_bw +=3D bw' in > > __dl_update(). =20 >=20 > Good point. __dl_update() writes extra_bw under the dl_bw lock of the > root domain. Are you saying that either there is only one rd->span, or that they are all disjoint. Otherwise there can be two updates of the field under different locks. David > grub_reclaim() reads it under the lock of its own > runqueue only, and reads it twice. A write between the two reads could > make u_act wrap around. A 32-bit kernel could also read a torn value. > init_dl_rq_bw_ratio() also writes extra_bw without the dl_bw lock, from > the handler of the sched_rt_runtime_us and sched_rt_period_us sysctls. > It sets extra_bw back to max_bw, which forgets the bandwidth already > admitted. All of this is already in v7.4-rc2. I have only checked it by > reading. I would rather fix it in a separate patch. >=20 > Thanks, >=20 > Mathieu >=20 >=20