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=1796141698; b=ru6c4JsuKnKiAi6Ofvo+nPpso9Ia67pJODVRkn6ltCvW57Q3LZFxtoBP4hi0pA77sp3Q XuSfwHya4Ci+/SwXmwKk/d6yfssfZ2ou46S7mhSQhC6CSfxbV594QmD8Fri5n4tKH1xCY ZsdXsOVfCAVK9UVzfS0Lbt74r8vvWj9SqN8+w3kaw59wqze3vdUodg04RYwC01mjmdbn3 noMANvYQ8pKBh3e3liCF1VnhB15KtSkH1vxTpCWqDix9tF84eaY5kJ0CnbOq5NtSa8BY1 foe9sdiu8iKkO4dGMG5i/F6KzPi6S3rvY6fJri0QQDI3dK/FsXDXWQPnpf47iXo5oEw== 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=QG7zPnEX6VvOBVWxSxtIQxsEGRXgZImVOFMZ9ybTvFjzECFsDhcROHNaFm5Ph1HgBkfk +g3SJZXD6CYCjtqVOInIJQXhaSfvusEpZBhLluDAshavSWEdvvAy0PRcuqCUyF/fbblCm XSjxkB6yRnEsWdb52wC189mnHg7o/+nBmCLyNl51+uc87HNODjfIkjq9hgBFbA2vqe7qB QwgDKO4yeeEy54Yzrwkxa9MefuMQ8uoBSjLKf6u/JoWjhixMQfddzhF+zqEFM5UcO+Dxr fvAEEhLFt4VHG/gNTz/fyYknPOKacD0gMF/1+/hJu6Hfjnjj55XN/rHc+J9h2f6qxxw== 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.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 F0506606A320 for ; Tue, 1 Dec 2026 16:14:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0506606A320 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-f42.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so123554955e9.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=nas/Blcd1SuPAVPExyjtOEkYjqBOUk0GH/F5xrBzGTxQum0MMB/tdD2VxbnHQSDLHJ O3aeN/ulgtKsJekalviDBZHMsZTVGdiKn0LDPZBCmjHBEv2uKBDRos22qSEoZuUv7HHH cN+Wzh57ws7MN8i6L0B3Jp6D4qUO5ytvPJzAXwgzaVdY4Mcg/0E5a6x12h34JYFpKO8F dzsp5u8x2VAVnr6ctxuq/4826pLmk/LnBs4Iqcmr3XKPUmPGJS/+kP6sqBxa1K+P8MKf 1kIv5MdGU082gtkrL2pJ/4P1hFBd/3FYqPkaaQdnBtclX+sXOHbAQbj9qb6R+eaf2wn7 I3Rw== X-Forwarded-Encrypted: i=1; AL+hErELZhYY3GEwrZr12VBQXilMVPanVLHgon4ttZ4pbFcoXNNWkyeBunKcYjgPbVt2xT1y5mOKCeRN@vger.kernel.org X-Gm-Message-State: APuU4Z8X1cdZWX+0sf6indavKAl0cXR+uLubj2yJfsx2A0RJ2SWjb/ot OAAood2iNpprKVCFFR2+yNVV9r9DGmReWl2bcNharvXjpcbrSaPNlCc4 X-Gm-Gg: AZFdTZcqm7wNxEXaHdn/deLkhyWokYx2k95+q9v+aNg1+IgbccUgpvwGfPFDejJ7Le0 eMRK6bUqiCmjrmzn814Xm8ky6ipDwsp206q4XF8SKwrZRUc4vz6HG4/+mQAOApiK4keghk7C3AM ivNjKtoRT8Pmqvxx27YGomxoSvd00zUc86hJVl6luGy8fDLb5n61yUKQPGfwLtsy92PhvkJ0cgC wxgjjKbk1XTSSJpbB3DlhLyfQ47fIRXBtef/nidecSz7ij8XJMqhM7IoY6XdvRydQBpBEMtRcQM VlekRcyhEQGsJdpz5Dkf0gnY1ER4308yu8LZRVMlLWGo9PqbAN9oS746q9QO2fWoChC9VygYLNp jrRHHJ6DlAqHVJLKbHOjThX7P1j8+Pxy1qBtkxF0tToRNnoue28yf230E90Ty2ehjwgKuYiYPqf paksZR3+dSYtHJJFED52E3VjAyRJssi1P3+tXSLUtCan1szWLEMdlD2afdJNZVgOUOIWrLFnfd7 9MBW9hBWEJOOPaWw7AG4pUUy+lmznw8usFT2rtaUUR+EwPAMnTV3W6Ik5FdEeI4jSNs3Tn8oUpg U8AYgExiroN+ssQe1K8642o/GlbZnxoavatyZJcb9o5ArayTX683e+KasCWGRHYW 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: 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: 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 >