From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796062607; b=4Iflz4fpcJkVwmOQ6krF/hTw90fb3EguAj4nAjXVr9ijlnY95/GU0V+AFi/TF08AAKDu 3OlC5IdP+qR0pLmne0YDdm1qhXP177JW/O6+IHLkC8UFRHePC1I6BdA1LG252Tma/KVsX rTQZTCbsrBA7Jp2Q+blr4GVNBXQDFGXUVkk6G6aoqy09iQsDbbinPWJ+d5NrSRTgl5x+v OfAFmGdZy9Uzj3smGWs0+NadAiWBWOQd0jBZpKNIUEVpF9MOv3ZV30TZAn9s9Wm5+/1wc XJ91PKL8Dk4RTN8l9oTELtDx6GKiU7oB2tJQYF1XmAkKH0aKp7z/5hKSQMOnTO7lOLg== 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=Efj27yFkrV38rUnLHKxZWpFtU5zuEocz9qwqI9KGHc1EsrWyCyB02HDc9sLRFkSiG2lB iar76vfEjTQxwB1GmWLxGZKtwCx9Yj0FZ0qI+W6gtbSt/reJVQwgktzZ7fozGLMMkz5pZ VNWHTR2iaPLCE5V0yQfvkESFsPK1eZVFFwGLQHvlf58kp++aqWNnWYF+EH6Y1MaMo4k9L QnvprDRphtr33+WNaIbfgN+CLCieyjRg13HgNKVvxpLUe+Og36J9e1Y0/6+deNFDDi7ET d6eO0LRNWmGJYuS2B3T/3ChiJXGTGzlxiLiYpV4iYA4UB0Fr9qZaJiMjcDKUcWUVOfg== 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.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 8801E606A327 for ; Mon, 30 Nov 2026 18:16:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8801E606A327 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-f42.google.com with SMTP id 5b1f17b1804b1-4bb6c7b6dbdso99925235e9.0 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=GAgEMueCXTeqvOngfWrd6WY7S3aBFmibNVA/h8zwaq5dRyoTcQSMbg5c/BgM9O+8Dh 2/K3D08EgxSEYPEVRsbu9qxFRRil7uF/+RsIA4f/NTZH9eJL4uEvM+Glxr67wODXffdJ CXKdD6JszwRxu7c0ibfHN1ETjCfcvQbHTQGwGa1d3eHDNA8ESotUGPGKC7+SiBVQD1dN 7BolG9ZUDmEIbg800Udjqs0ThLs9qfAlPtuq/IjCCZnDZRQlYRIVYr5SndVYksO8/Bi5 U4BmfBIBlpB3knj8Ut0XJX98+UoY8bXrRoZ8V39eD+eWiLP+5cYfpGOZbSugMQ1gSGzd aO3w== X-Forwarded-Encrypted: i=1; AL+hErFR7/7fY4P7NKraKlXV+G+i9jfrHQoOQn/obwsTffIpAL+He/MLBTa5epUgTnOyxhO1EHSZGdZyh8h+mVtIJ7w=@vger.kernel.org X-Gm-Message-State: APuU4Z9MQvoXSpcX4BURf/bYz5/yNp8T1VCiSHkeE4H//VbMmmF9U7JT HYr7D0+zkV0NfMTurPxEA+EwG3ibRCNiIef/wxBuIvB30ScCJXsQ3XC2 X-Gm-Gg: AZFdTZdGa/xgDU3O8BJKpsU1oLg/fcO2sZEd5wWSkYg9KTRm0ByT/VURTMgFiobMjfw fIUUzJdMA/VHr7jWAQ4pfNlpihz+t2tf9LLJ98sxXpVGyT0RKMRdCeSwUsqUyNyDOkCOV/NHRhR 1SI66ppL0qiqJkXpJClPgzquKclCQRUIWLiGUrdmgbaPNP/Y6TVvCj3QYD2oukLJvrQZEe+BCYc goFY3CF7lFU8KgmcwFdtMFhl51J3SYORPlD6Af3dl/NGMWmi68enOVAOY5g8zuya/OLRFQ0cho/ T0a4PLhsv3kTdiF6+z4LCng9YknoU4BCdMCpk8yavOOGKs30hL/x0vS8xqjzH35HNvDP9zCWayK i9QtyTlDIOxjMbi2Ud16azYJl99FRMsA2tT47lZqHoTZqH4n1cmZwUj8Krl4DAyJsj8kAl0L0gW 2YQvIMcbpo3Zti00VGM5c0J7guz4m/48GhFUOfOMYU2FkkJX/NBVFoHp/eDV3dwS+bx+oaJFTTR VZBpBrf2tmLV7Tas7sKC1XSgBIwv1DyKoPuLsrq1jFZvUdGx+50H+2GIUxBttJQGI80mMWFlFS4 azcmNqnhSLL0OBcUURnqeEW3JMKLSMmBQphjW/lCxdS11/2DcGo29pL+JCf1v6MvNg== 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-kselftest@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