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=Cddg/Z/WC20ki9jKJKkfYjcDPxpq7Kvk+7vWeTGI11Pux63lP4T7o0/DzQXy7fjULwJ/ 5Ozq1f+MTDasFvrUqJIlk4fJwNRqVIIqy7JWlKefPDwzpURLDG5s2Dia66fHxHHdOsy6w lCHuH+PTpARRNv7VKLl0J28hfPkY0GWaTt8aICy9wpHVUgdx6wdlHM5Xnu+KxL8Hx9m/P skCj5i+FxrcT0siKAAWHumgC5Ku0nom3w1YQzOz4oV/FrEQAaS3uWcRgBmLPJtA+U06F5 6tNT54e5mxlDme9Al2uP9yLPXtbbG6y5/x3GTKC/VUiobnpuEYtV4NOzVwRyv9CHCtA== 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=niEY1uqf5ENuEaV1wjvi86sYQ9wtnsAF2S6nQvqj93AZOjlog4qeitCxG4dvtlSPOqkt CWLIDmNmMYO1oW5xUgp7+FGf/G+PQ1bzuSlyP1hw0+rZ3tn6SlpPk7tbvQ5VxGMMc7ir2 d93PuvAQpZO8TK5l4JxbUf4rfIU2yWJvUQaUn46SRlYBZ0Du5aGq6wkoFpRmLTdkwG8n0 M/1qafXQz9tHGX3EWWDYUNi7aQi5GV1CzpGNClFFVZyyXs46/pJCRF9xSXdVWJt6QCPIY Q/1uX4AsUTvzxzqyTUR5EUCL5fOFZzdzdR8jv2u23DxU4UXpPgurwoC1O5vgwCTu0UQ== 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=YKlRucgC; 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 883E0606A329 for ; Mon, 30 Nov 2026 18:16:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 883E0606A329 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=YKlRucgC Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4bb61185057so68834145e9.1 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=lists.linux.dev; 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=YKlRucgCMF859mcKQ/4QEu4d78TxMFRmLpYAD60uI0TDH+MJkRrywc1Pxd9z2aHI4S e8n8zJIzfeXA/yiWsHx6H0q3LUY/CCAFRAlAsFZwNLifJi/ScMlcSiC/rbABtI1xCA0V gwfJp+dGFlyddkWYxaIvG2m0mvkWMVWto6UXJifxQF/aQMdfSbNyQGy79wkd9WGiWDM+ tvsyhIwSsmiyqfEqW3GyoinGBFkANvOyjK4yzB9gkvetNP03GyXXpSzkwfnMUgK0Jc+j UI/LZyV5HxFwtoH5RlXrbRRrnvsC2PCl0x6mxQ8LvSV/gIerA46wssIZwhdPWIOt1xD1 pCLw== 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=0OBqln2fEoZ6BTKNGm/5C3KrJpMsZU7AT2UnY05AhyOKzpsMkJYgPLyJ7s/cZ1tVFc wwQ3i5Xghq9AgGHwM3pwJKNoc5Os2urFn8q8lqOvGQS4OrJZh0l3tZCFtRONN0wbv89Q KP2PI8BKlqr/wJQhLfv8CeowuXEwbsjgxbNtSOWhwsxWJhYTVWGWFl0BI1jVolwi6OD4 8XKXrWIxy2ugh1wD2WHCRpbYPKFthadBe/NLRISrz1nHp0dc4wHk6skW1el7VJBFrJb1 cLxqaCZoPeTP2eeAPFS0qtu30RfHQHhrtuBlKhOtGeL0H/jMYwbDMIrxW1txThRBgc// CzLg== X-Forwarded-Encrypted: i=1; AL+hErE5rMw7li2msI6ywHD0Cr2QYkDYFWhfcp340IUR9sD3OM8XE3PMXTWL7lJPIJC+k4FN07Jbi4xEfCdVfY42Gw==@lists.linux.dev X-Gm-Message-State: APuU4Z+vCJ5RebdTta32ChV06wo9Dk3Wk9vlnKkMLe5tJa+whYgqnygI RIzzmJqKN3yqJL6e6fpA2h9mrLM1gHWQ0Yn7KdKF2k/btiquGueMEZIq X-Gm-Gg: AZFdTZcuDU2JdmndkqDLxgr3Sz7DKr/EzsyQA5eDKLS04kGWwKw7rDstM5mxLk+PpUh RZuwPf6gIp4kH1QMeGIvWQR5UgdW4i8bn6TkaKKzX+6eCDTuEc3RZTpo8NorwfU4EVd0UjYs109 qgCKOH9MHcruXb70RwOEpvQpjiGc83CG/lbFDdiww2mFodjIqAVG76s73dIFMMub1khS7lM8yPZ oP3hZfWId2406WiKhlTo/H4dH9K77uvakiJEez8Dv/A/lKPgbEID9CWKaSeK7y0B4GoPaIBI+EV j9nxCofozXcoIZ+PB4cnJiuPyQgH1fvXZHiQxemlBCWH6Xn7wFtCRFCG16dqqJrTzsXvOKBLPQ1 osuq15m2emq3jFITQTsBRrRVBhgp3+oxB/PPY0eBodUoqD6cMPzuUK6PJ7R9tA/GkWa3tgNNqR3 an0/rqoC3ooe5R6WCQnC8jJS7Gt+upV9YSunHODZAwhq+tIxJjw4cHjGPLLvI1Fh2uCrrC5jp3G fWVmHVmzc2tLPLUS7n+xlbQU/z0dSgd0XdVYpd2d7WRliu3gE6JaM2JTSOXGoutuDqpKAYPDxU3 x/fZO/kBSjWPBsULDgiccxU8L5u5TjHrLwqKGRZKvc4qumSH/KWxR0/fzh6Drdk9Ew== 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: linux-rt-devel@lists.linux.dev 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