From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796141698; b=4TNJHL9d0/Nlsgt0FJqEnB4ANeyJkhQybqq5yE0/tZdODy2FjmFPgzeCT8q8c02Ya3rs TfX9ifnqQK1wN38SOUUsYJwMb2zU8V1kJR07ShIKHxLONPU3uwbO3fwcI1v6RiykZqYlL 71Qh1PQwRgzeLrg9UkK0zCfNiIHxSVEqy3CDprL5cwfHhOGmWblQm61zjeJWv1bHyCNuw SLCoSWfTrD8pvK5ni5zM2tu2HeXDnS3G00X6KLvDM7IyD9p3y+0Ck4wphOyq9OwVANjwr OoecXNljMEA/E4ZdK0a2O+YxTHxHGHeE/XP4gtfSYGTjTY+BV6vTqPAnGEM4mWEATEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796141698; 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=u+ENqAyHEppXrns/sI8EjtGmPCZCfoJwjT3RgAOS3jY=; b=eKuCWIRFjHw4hfrWvmTAXvhcVpSe0+W74drsyl9owtVcLt567CroDbttNPvO5j1VXYsZ 4xP36tMPdwfCG3RYRlaXLG/oSIjHyudCozHohLhRnB0qaTuAG8a4L7P0gZiju/19yK2la B/Q9po0jTr8cpDqXPDjPaP6esXX8NoynU2NHx2C7daGrr2fa+m3htBn7zCOSQyPf2KPIN 1h356LlbL9omUZZjf5PMvKX6wnfhFR9i88KZGpTf5gSSGiWQQrrtT9h5epnge0GqWZG94 t4TxvxE+zmJ1tcz5moRH5eIeimvgeWl7z7/Q6p2z88X+Ryypu7oD4Axs8Dh/eIgArKA== 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=v2Yu2d1B; arc=none smtp.remote-ip=209.85.128.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 01C86606A322 for ; Tue, 1 Dec 2026 16:14:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 01C86606A322 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=v2Yu2d1B Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so123554975e9.2 for ; Tue, 01 Dec 2026 08:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796141696; x=1796746496; 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=u+ENqAyHEppXrns/sI8EjtGmPCZCfoJwjT3RgAOS3jY=; b=v2Yu2d1B2lgcUZ0wA0Gyjb+7cANchCfM582KcnXzxqFiXbsB8iTk5AGKnZQdrwHB4F WutknwOTCB4Wh5FcFH2922wHeJJ2hAfiH38AfcptbtrMvYuEHX54Q7KFE62njK3BvbXS V8y03GH47fz6hKTsI9U1bagNdx+DYwzK7S3rziy7yfOfODw3qdcr3kuq81kka+LFRnSw kYOplFBx7AYpvLOdSOodmkWCqiEajIeC5HA1o3XbXqyGYdB/3O+S0n6b5m1mEv+bSrus 9TdQmWIuiSZ4zeE/VavzXs7+E8oIiwRodUk+8UtoGeyDQ8wrpJ7rpBJSrCTs31xhAG38 GerQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796141696; x=1796746496; 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=u+ENqAyHEppXrns/sI8EjtGmPCZCfoJwjT3RgAOS3jY=; b=M+IeD8Rw61qTt9DUn+hEK2lvOPFlvvkDRJWHS+pKjoNHy1MQ4er0yizPdLcMlNHZyY QflRERMMdfE+j0Lr5COtYdx4ubXAQCVCB4mXBLKVWILvCXWp7NaiuWhbi0xCDSA08GVi PYvW1YXBehfHMkNwvd2rMHtqOM/b/7Ut6TYm9xPyPDkylI14jEyLN6VF07peHrANp6kH fcM8y5RHVSYa5Wxt/xImr5TLB92vtKn+45h+oiHDQwS6uBqwAjI3wMNPnPUXDYCv/HXM /QyNO31+o7oCpmeLmeoyWMtmJww5j/j8rA/5ejzbB7V1Q7u1VHoBwOWQCL7yNfT8e+Zx uLFg== X-Forwarded-Encrypted: i=1; AL+hErEpqXMxIA1QGtS54TcPbivz1i7zSByuF6C7faKM8W4iVvzFTon4+szRSzgUYl/nmckNxa0A0LnLnPdorqFLcHo=@vger.kernel.org X-Gm-Message-State: APuU4Z9BBwvZlKrFKnYJ4heNgl0Gfw4Gh5y5NWixJB969CGWGz0DYEK1 njjCZpfw4kGGRsv/w2B7mDm/Pf4yCdT+WOA4KRkzP1Xh0mDvhpgcrDuL X-Gm-Gg: AZFdTZenPxxXKdMRC3kPJt7kuYHAfH1+f1x4GNqO4RxGurgc/ng/lS9tlliEL6GhbKp YbHaPiOh32EZxAArGm1wWf6nmTTPg+yrCgFt2ARYImDQAvuixMjICLodF8FDaqNDWinvVDYTEVj NI7w0tF1ZuRVvJF8fVOZ/tyoLZ7iOBbIuVmCIG6zuGga4AX+VWapuyaXbvlWeYM1tVOO2iUB/0R svOT2NDDNB86sjxlPE/DgbEtmjND5zzakqZME5zSG9ZYosgxHIps28PZF2A+R6+YmNkyxiW+Zd7 ZmhrqJ3QSBcRhyAaRmMpgJ/H/WMqiMPyesVaz20ILY1cauhmdx103L6l2mn1gzh60OCMYPTZK0a B1EuqMj12Hcf3nuKCcl+7Wrw744GtrL68XjCxOPGHOIixSNFg7K2tRwyzrmdFGPnO3xnKOvXwR8 0PoToK9qp5iwLLk53jygZlgPp4qNYf0kTs5NkrfzyOEd7TTctTxRqND6/OeXmH7kBKh2SLjD+1r Wluo4T0CHf7/B7Dv2+YjAy8WMjfAbhE/waf3jL1HeGh3hRbinfwqPC1aGORVR/YZ9Kn5CNwmU1+ 9U5+vUcGlgrudBVYYHl5Pg+3foEgIynfQxQA4hcv+m5CDvRvvftGbPLWbqFPz8Fy X-Received: by 2002:a05:600c:1d8c:b0:4a1:c5eb:b445 with SMTP id 5b1f17b1804b1-4bb88820436mr765830105e9.35.1796141696128; Tue, 01 Dec 2026 08:14:56 -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-4bb853a12acsm1039192855e9.8.2026.12.01.08.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 08:14:55 -0800 (PST) Date: Tue, 1 Dec 2026 16:14:54 +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: <20261201161454.61083505@pumpkin> In-Reply-To: References: <3300daac81b2483e451bca006dfaa2da5b21fced.1795771148.git.mathieu.desnoyers@efficios.com> <20261130141225.1e78e5f2@pumpkin> <777f6ac1-d7e2-43cf-b9c0-19cd5bebf8a6@efficios.com> <20261130181642.23d46e0a@pumpkin> 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: 7bit On Tue, 1 Dec 2026 10:11:14 -0500 Mathieu Desnoyers wrote: > On 2026-11-30 13:16, David Laight wrote: > >> 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 u64 step does not change the result. The negation is done on 32 > bits: -(u32)x is 2^32 - x, a positive unsigned int. Its conversion to > s64 keeps that value. Take a task with 10% of a CPU (104857), in a root > domain of 4 active CPUs. __dl_update() gets 4294941082 instead of > -26214. I checked this with a small user-space program. You need to get the casts in the right order. The quotient needs zero extending to 64bits before being negated. eg -(s64)((u32)task_by / cpus) or 0LL - (u32)task_bw / cpus. Although that is still only right for 4096 cpu. > > > 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. > > Not quite. Once the sum passes S32_MAX, the existing code flips the > sign of the value, as the changelog says. It does not make the value > large. That is the bug this patch fixes. With an unsigned cpus, the > division and the negation would be unsigned, as with (u32). So > __dl_add() would pass 2^32 minus the quotient to __dl_update() for > every bandwidth, even that of one small task. > > > That probably means that a lot of the '<< 20' should be '<< 19'. > > BW_SHIFT sets the precision of every bandwidth ratio. With a 64-bit > divide, a sum needs no smaller shift. I would rather not change it in > a fix. > > >> Each caller first counts the active CPUs of the root domain, with > >> dl_bw_cpus(). > > > > From the above it seems like that is 'almost constant' so doesn't > > need recalculating all the time. > > Right. It changes only at CPU hotplug and at a rebuild of the root > domains. The root domain could keep it. > > >> 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... > > Agreed. They are worth a look on large machines. That is outside this > series. > > > 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. > > Yes, they are disjoint. Each CPU is in one span only, the span of its > rq->rd. But partition_sched_domains() moves CPUs between root domains. > Through cpu_attach_domain(), it calls rq_attach_root(), which moves a > CPU under its rq lock only. > > rq_attach_root() clears the CPU in the old span, then sets it in the > new one. The callers of __dl_update() hold the dl_bw lock of their > root domain, not the rq lock. So two updates can see the moving CPU: > - task_non_contending(), on another CPU of the old root domain, > releases the bandwidth of a task that leaves the class. It read the > old span before the clear. > - rq_attach_root() itself adds the bandwidth of the fair server to the > new root domain, with __dl_server_attach_root(). > Both then write the extra_bw of that CPU under different locks, and one > update could be lost. At its end, partition_sched_domains() rebuilds > the accounting. dl_clear_root_domain() then sets extra_bw again. So > the loss lasts only until the end of the rebuild. There is also the RCU_LOCKDEP check. rcu is usually used lists (or similar) that are followed often but relatively rarely modified. I've not even tried to see what that is about. If this code is only executed when cpu 'move' then I'd have thought there would be minimal contention from a single global lock. This code would then hold the lock. David > This is also in v7.4-rc2, and I have only checked it by reading. v13 > does not fix it. > > Thanks, > > Mathieu >