From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796062607; b=KIwOXGw8Gi0qFC3WF7NTknfvZ2Y2MfL7JveGG1DQk01u/l1EMwgxoI7+fDVHkFyJl+fc 9W+RmkCgfvAZDYjp7xKulO6F9uJw6oXVOwGkqznlVFL2UVKATAq/vb+d5DK7kbBrRimE6 4iLNlKhZDOveMfS33yxEcb+c4DYpGn2n3aqeK8bwf42BDMYYwmtsuO40gFkmSVtYek2Ms nIVAmt7peo9CIFnZuBi43Z1An5fb/2yFXHiYPto2Uz4MOOZR4bQ0CPCUz4YDFhDyF/IC/ 3GXyyBdE5WIBLUoxmj/SUzMqbKsiyqkcA23hr07d3KH/8alE0RZuPlRdg+AXkGQk+yA== 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=4CfCuSPGasfvFjJF2u8rI+8Wq5eXs/7rvInPHML+9eEzaxdHzZDqkGOpOjZf5DNDnBf2 rbU+9PjbX+6rdkBKhRPQ+GhnrHFjnl4BHDWtCuIGZ4R8yFNNI+J3wcYUN+PziwbQjMktM hknOycbw4cC/SH2XjN0z1RB6AF5OLb3135M4vzazTV9YVdCHTrxD2cIS+op4dgH+St58X uDrbBOQdT/lZWla9kKzdD/BlruKifpW0Amj2IJrThIqGQ5OnDhhzn7daBCGTgTGW/quC4 9+GC75puzWzLIU8CUXATWdsE1tVa2e6/Lcz1379xer3kfAPfALjNrBpJvcI9GPVdXiQ== 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.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 81C70606A325 for ; Mon, 30 Nov 2026 18:16:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 81C70606A325 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-f52.google.com with SMTP id 5b1f17b1804b1-4a3517554f7so97875275e9.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=VMxwCzrowksVxnjYs2y27VZziaUQwSqCI+9O+HrOgWkxJLQ0e+SHhK88XSKLEbkhmh PmYojAYrIa/AtpUiJl20Cpu9i2ZbiMBUwfLfjupDqzxxU8ANW8z4PJARdryiqJ3OHRkv ZdnVDn2C0SyPGvepZLnPyN2RNi/mPvTds1UwV9j7PTZNOBIlAP2Jlbc002Z9ni3B+3GV 7igldXqpfEu71pA5wBDZHDgPg71cLu5zPBujIpsJ1LuZqx8t4j+b5JJGBvNUzgajOK7a SUsKxeJFaZHFxrFiTr+0ZEOWCHc+Hf5QI63NXbbV0JF85RfhKlR3CbcMjiiVhMtprj/I VAOg== X-Forwarded-Encrypted: i=1; AL+hErG6FH2mnXSvHaG70v4Fs9PI/NmuDSuLIJO8C4ewlJCFrQS4XQ3AUXu68xkLv1vPYwNG02kfr9H/@vger.kernel.org X-Gm-Message-State: APuU4Z/xbjj6dSYq5Kklbpec9gsVvNB8QaluOP5ZNH8gZrCjeQ2CgmSf 2Hn7O624s0X/QMpkF/siVk9n9CrCQtLzCmBrMMyDd4MAPvdTCFjo2U5e X-Gm-Gg: AZFdTZdH67XmtVOv+A7YYT4vO7Zaa7N4Jsuu3PjsOV8f+XzQyDhMWhqkNC4QyPdJx+N QTORt0ii6OUFSwf4Hd5lJVA88zwyVnm7YV2GM8gn9UDXV6eG7QCrlNaMSu72CbO2LlSqfkCNuqC roXqpl87iUshJmHLLnvj/dIS2Kzumg4jOR6umXRrCLolKcjnY6ZbnJghw5s45S1jfzchciDxKN5 8FwEy9qgwvOJqc1vMdwdmM0Yoe6rDBZPuAW5xA2Ra/8/fXaC81zzJv1zV1o/uiCwMZUq5Ju+b7T a93Iqx9/qVqxVdlWyTZ6k4vJgHYRgXXLS48CW0h8cpRs/Knzk3DUOS1hxdO/8aVk5jYeSE6bA+N WsuUbQiOHdp+VSkOVsK/fnbcVOz6K7GUzoTcZvN52n3rDPUK9Z4ImkLeKenMC/u49NORI79ZSiH o58/bTOJCMG1IcKx9rH1BT+V5vkv7TgjG8OYpyJjdOf00J8dDKGxIShsDwgCxwcK8mtibmGgAAc 7vAtsVdMBbZp4J7AWp6PKRb0VCFTB7vHghYGwU84KFjXRYI3CP0YEwfrsISaEiBWEHgG9ljc+IQ f4thELVg2S+VITuPiOSvtuEy8JdNyCeFnxdxPecIFBctoN6wdi6leEvyKON/iLsdIw== 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: cgroups@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