Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3583102rdh; Thu, 28 Sep 2023 16:54:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmXkd9Uhx/ghTBP4MR4+CVjROsvRm7/yxpcxxHrqsAkNU20oVgKvoParXOvVpyQdiacllu X-Received: by 2002:a17:90a:c70d:b0:274:4b04:392f with SMTP id o13-20020a17090ac70d00b002744b04392fmr2396172pjt.24.1695945246805; Thu, 28 Sep 2023 16:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695945246; cv=none; d=google.com; s=arc-20160816; b=nYlxtmJ6dwm4SGKLtiu7gDHv/CGomqJdeW/ftMM6sN2NjWqBDlAA8IMSzzeC8pzEGN TV4ctXHl8i6e2CifGYG3uJIqrmNgLe5NV7LUjfrDn2q3R2C4KeOYYOgN5XS1JEVfT4ph oXadJC4s6v5foezM+AXUj1YkTQUwALTZOa2MS2/79AsRu0UJrvWWFi0ueutiZp+HDs+J j1n6is7qKfrfB0A3ryDCpWp0aJm3Kg6ja4KbtMME4Y0CbI9J2ORjQN/ZIELVgOtQpMSb OFrIgPFfFAVQdzAXTzb2IWjvmOJiRRJSgBVxCUkea6a2E0/haUbxIzUKhazzPesKdq8f DncQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=buH2beu+1Ws2gtJzuAfQ9RAY+d9wiGvBqdO+4vM4sj0=; fh=UAnO7KNCZLbahMImboDnVUUrbm5jo6jHWgeLGZsE3lc=; b=v4faqXK8IiSZBW7b0pdyZ+kVgJLe9wu6h7nPQQZi6kIdpMv9vkYA2Uj6zMNaIJaGEx 9Tu7P2Bp54GvthW4Faxo+OWcQdl+KcS08dBiI5EfumiyklvJUrOKU78ZyFHRbYxMat5L l4hdme6Y5pMFAq8zX/Iv1nLRsSsnV/Nrm2g8I70dW2zqeZQGrOpIllxANeOcrranOVMr /uG3lo7g5R+1YQvfO+31X8IHGzSlGDendgfdaJY/Q8NywSdDzXrEXVoOhOzo66JNyD4j UloD4f7ekfsswe89jt0vagnwkRRMXhAS9uNl37SIeKRIOg2sjvutU0nqpb6tsnRfZfiL O1Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jTfmVn4G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j5-20020a17090a318500b002774e4d6e7dsi268594pjb.147.2023.09.28.16.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 16:54:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jTfmVn4G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 02D12831DBD3; Thu, 28 Sep 2023 09:27:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbjI1Q1G (ORCPT + 99 others); Thu, 28 Sep 2023 12:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbjI1Q1E (ORCPT ); Thu, 28 Sep 2023 12:27:04 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D478EB for ; Thu, 28 Sep 2023 09:27:02 -0700 (PDT) Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id A668A66071F8; Thu, 28 Sep 2023 17:27:00 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695918421; bh=7iFYQrUTq7idgt18OEix94cfK90qh9UDM4zHDUrw1bU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jTfmVn4GINVymXF6QWC/4KNIYnq/Gw84MXNaPWsWD8XltylpTnLga/Kxga61Ho12D qs2QDRz2Q8TcHRwArRQiHNFVz3hYpnLaUn5xLmSODbewBK0PAus+wCeizBbE4FALpE drrGeK59ad7wG3briZ+C/aXhKrShRsfuKNRU5OZqLe0Vy9pw286QzgRnNJObYP2dj2 nuA8dGJvv/1hL2YY7etpljqMSvNw9v2yZ1+LN8yNg+b+E9K8G4mrbU4a9uhfHACNqL vxffiFHWp7zDw97ZDrW322TjbC2wo6fXbht+G63B6jEWdN/ARngwjwAzaFi7lTyb+L d1AQJIvbY6orQ== Date: Thu, 28 Sep 2023 18:26:57 +0200 From: Boris Brezillon To: Luben Tuikov Cc: Christian =?UTF-8?B?S8O2bmln?= , Danilo Krummrich , airlied@gmail.com, daniel@ffwll.ch, matthew.brost@intel.com, faith.ekstrand@collabora.com, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Donald Robson , Frank Binns , Sarah Walker Subject: Re: [PATCH drm-misc-next 1/3] drm/sched: implement dynamic job flow control Message-ID: <20230928182657.4e663e7c@collabora.com> In-Reply-To: <1c0b9e1d-c990-437c-a8ba-5bb58e5872a0@amd.com> References: <20230924224555.15595-1-dakr@redhat.com> <20230925145513.49abcc52@collabora.com> <20230926091129.2d7d7472@collabora.com> <390db8af-1510-580b-133c-dacf5adc56d1@amd.com> <20230928100209.37df66f3@collabora.com> <1c0b9e1d-c990-437c-a8ba-5bb58e5872a0@amd.com> Organization: Collabora X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 09:27:09 -0700 (PDT) On Thu, 28 Sep 2023 10:44:47 -0400 Luben Tuikov wrote: > >> > >> What we can do is the follow: > >> 1. The scheduler has some initial credits it can use to push jobs. > >> 2. Each scheduler fence (and *not* the job) has a credits field of how > >> much it will use. > > > > When are the credits assigned to the scheduler fence? As said earlier, > > on PowerVR, we might start with N credits when the job is queued, and > > (N - M) when it gets submitted, so we need a hook to force a > > recalculation every time the scheduler is considering the job for > > submission. > > "Credits" is something the firmware/hardware engineers tell you. It's a > known fixed quantity at ASIC boot. It changes only as you submit jobs > into the hardware/firmware. > > No hook, but rather a peek. You'd peek at the hardware to figure out > how many credits you have available to submit new jobs, or you'd keep > a running count of this quantity--depending on how the ASIC works. Knowing how many 'credits' are available is not really a problem, and I don't need a hook for that. I need a hook to know how many 'credits' a job will consume, because that's the part being dynamic in PowerVR (signaled fences get evicted from the list of commands to issue when the job is pushed to the ring buffer). > > When a job completes, you add it's credits to the available credit > count (or you may ask the hardware how many are available now), > and add/reset that amount to the available count kept in the scheduler > struct (for instance). Again, I have no problem with the available_credits tracking. It's the 'how many credits do I need for this job?' that's dynamic. > Then, if the next job to be pushed--which has been > known from the outset as we use a job-FIFO--is using less than or equal > number of credits than the available ones, then you push the job, and > subtract from the availability count (or, again, peek at the hardware > for that count). > > > > >> 3. After letting a a job run the credits of it's fence are subtracted > >> from the available credits of the scheduler. > > > > Uh, what happens if the job you picked make the scheduler > > available credits pass under zero? I guess that's relying on the > > fact you only expose half of the ring buffer capacity, thus enforcing > > that a job is never bigger than half the ring buffer. The latter is > > acceptable, but the fact your utilization is then half the maximum > > capacity is not great IMHO. > > The credit count you keep should never go negative from the action of pushing > jobs to the hardware. If it did, it tells you the software design is not > consistent. AFAICT, that's what Christian suggested: exposing half the ring buffer capacity so that any job can be queued even it means making the sched->available_credits value negative. In order to submit new jobs, we need to wait for sched->available_credits to become positive again. > > Hardware/firmware engineers will not appreciate the fact that only 1/2 credits > are being exposed due to poor software design principles, nor would > the sales team. Exactly, and again, that's not something I suggested doing, I was replying to Christian's suggestion. Maybe I just misunderstood what he was suggesting. > > (See also message-id: 61c0d884-b8d4-4109-be75-23927b61cb52@amd.com.) > > > > >> 4. The scheduler can keep running jobs as long as it has a positive > >> credit count. > > > > Why not just check that 'next_job_credits < available_credits', and > > Yes, see message-id: 61c0d884-b8d4-4109-be75-23927b61cb52@amd.com. > > > force the scheduler to go to sleep if that's not the case. When it's > > woken up because the parent fence of some previous job is signaled, we > > "pending job" > > > re-evaluate the condition, and go back to sleep if we still don't have > > enough credits. In the PowerVR case, I'd need a wait to recalculate the > > number of credits every time the condition is re-evaluated, but that's > > just a matter of adding an optional hook to force the re-calculation. > > Right. > > > > >> 5. When the credit count becomes negative it goes to sleep until a > >> scheduler fence signals and the count becomes positive again. > >> > >> This way jobs are handled equally, you can still push jobs up to at > >> least halve your ring buffer size > > > > I think that's the aspect I'm not fond of. I don't see why we'd want to > > keep half of the ring buffer unused. I mean, there might be good > > We don't. We absolutely don't. Hardware engineers would absolutely > not appreciate this, and you shouldn't write the code to do that. Again, that's my understanding of Christian's suggestion. > > > reasons to do so, if, for instance, the same ring buffer is used for > > some high-priority commands sent by the kernel or something like that. > > Ideally, you'd want a separate ring with its own credits for high-priority > jobs, since a high-priority job can be as large as the credit capacity, > which would force the code to insert it at the head of the FIFO. Anyway, > I digress. Exactly. > > > But it looks like a driver-specific decision to not fully use the ring > > buffer. > > The full potential of the hardware should be utilized at any point in time. > > > > >> and you should be able to handle your > >> PowerVR case by calculating the credits you actually used in your > >> run_job() callback. > > > > Hm, ideally the credits adjustment should happen every time the > > scheduler is considering a job for submission (every time it got > > unblocked because available credits got increased), otherwise you might > > wait longer than strictly needed if some native fences got signaled in > > the meantime. > > Ideally, at the time you're considering whether you can push a job to the hardware, > you should have the credit capacity ready I'm not after recalculating sched->available_credits here, but rather job->required_credits. I could recalculate job->required_credits when ->prepare_job() is called (AKA, your job is almost ready for submission), but this value might be slightly bigger than what needed when the job finally gets submitted (see below). > --i.e. you should just read it > off a variable/register/etc., possibly atomically. "Calculating" anything > might induce delays, and future temptation to add more code to do more things > there, thus degrading design. Evicting signaled fences is not something we can do without a trigger, so reading a variable won't help. I can recalculate the number of credits needed for a job in the ->prepare_job() hook, but that means credits will only be recalculated the first time the job is considered for submission, not when the scheduler is woken up to re-evaluate jobs waiting for ringbuf space. Given we're adding new infra to support dynamic job sizes, I thought it'd okay to add an optional hook to query the job required_credits value (the only overhead for other drivers is the 'if (hook_present)' test).