Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4AE3C43458 for ; Thu, 2 Jul 2026 14:38:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36ED910E4F6; Thu, 2 Jul 2026 14:38:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="NWYcVbT/"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2287F10E4F9 for ; Thu, 2 Jul 2026 14:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=bfxub8wI9wJW5oTaWjRFJziLCVjOdHIxtiFdmUYYo0I=; b=NWYcVbT/b5MxFX5zKbyNKwAI+u TKFZpstHMH0sPcAnFPZRh2DQY9Y/1ltEQmQchwTyzrnMfwo1QIMgXSZSMvxdNt8j0ffUsIvAmok+N 00GDLWbsqWKbT7213AFagt4/2FWIa7IXOCOU2WAZQD6BG6xLqf2TC/tN6wU42GA5PAkjTj9uBpCAA 1zA0expg2ZsX9k14eCMSNmyhIt7/RZY1JWwIvmP4h3weAMJZ7iLCHvjlN6BolO7oiN2/mk5QZHatz qKKoQqJe790ocDQLI/PS7qTWJzCZ25Q4FAnZHpXN/Zt34N4M/n6HgINs/BNb7xIlpO1wTkzimY7Rh z7FNZ91g==; Received: from [90.240.106.137] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wfIYB-0084XN-3M; Thu, 02 Jul 2026 16:37:59 +0200 From: Tvrtko Ursulin To: dri-devel@lists.freedesktop.org Cc: Boris Brezillon , Steven Price , Liviu Dudau , Chia-I Wu , Danilo Krummrich , Matthew Brost , Philipp Stanner , kernel-dev@igalia.com, Tvrtko Ursulin Subject: [RFC 2/8] drm/panthor: Use separate workqueue for DRM scheduler Date: Thu, 2 Jul 2026 15:37:39 +0100 Message-ID: <20260702143745.79293-3-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260702143745.79293-1-tvrtko.ursulin@igalia.com> References: <20260702143745.79293-1-tvrtko.ursulin@igalia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently an unordered workqueue is used for the DRM scheduler which means its concurrency is externally managed, and given there is one scheduler instance per userspace queue, that means workqueue management logic is within its rights to spawn many kernel threads to submit their respective jobs. Problem there is that all run job callbacks are serialized on the device global mutex, making the potential thread storm just causing lock contention. If we add a separate ordered workqueue for the DRM scheduler integration we can avoid this problem, since the ordered property directly expresses the nature of the submission backend implementation. And considering the other user of this workqueue, the free job callback, which is not globally serialized in this manner so could be thought to potentially regress with this change, it should not be the case since commit a58f317c1ca0 ("drm/sched: Free all finished jobs at once") made the DRM scheduler handle the cleanup of finished jobs more promptly. Signed-off-by: Tvrtko Ursulin Cc: Boris Brezillon Cc: Liviu Dudau Cc: Steven Price --- v2: * Actually create an unordered wq. * Put back WQ_MEM_RECLAIM to sched->wq. --- drivers/gpu/drm/panthor/panthor_sched.c | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c index 2bee1c92fb9e..f4dfd82ad8a8 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -147,13 +147,11 @@ struct panthor_scheduler { struct panthor_device *ptdev; /** - * @wq: Workqueue used by our internal scheduler logic and - * drm_gpu_scheduler. + * @wq: Workqueue used by our internal scheduler logic. * * Used for the scheduler tick, group update or other kind of FW * event processing that can't be handled in the threaded interrupt - * path. Also passed to the drm_gpu_scheduler instances embedded - * in panthor_queue. + * path. */ struct workqueue_struct *wq; @@ -166,6 +164,14 @@ struct panthor_scheduler { */ struct workqueue_struct *heap_alloc_wq; + /** + * @sched_wq: Workqueue used for the DRM scheduler. + * + * Workqueue used for drm_gpu_scheduler instances embedded in + * panthor_queue. + */ + struct workqueue_struct *sched_wq; + /** @tick_work: Work executed on a scheduling tick. */ struct delayed_work tick_work; @@ -3488,7 +3494,7 @@ group_create_queue(struct panthor_group *group, { struct drm_sched_init_args sched_args = { .ops = &panthor_queue_sched_ops, - .submit_wq = group->ptdev->scheduler->wq, + .submit_wq = group->ptdev->scheduler->sched_wq, /* * The credit limit argument tells us the total number of * instructions across all CS slots in the ringbuffer, with @@ -4078,6 +4084,9 @@ static void panthor_sched_fini(struct drm_device *ddev, void *res) if (sched->heap_alloc_wq) destroy_workqueue(sched->heap_alloc_wq); + if (sched->sched_wq) + destroy_workqueue(sched->sched_wq); + for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) { drm_WARN_ON(ddev, !list_empty(&sched->groups.runnable[prio])); drm_WARN_ON(ddev, !list_empty(&sched->groups.idle[prio])); @@ -4168,12 +4177,13 @@ int panthor_sched_init(struct panthor_device *ptdev) * allocate memory, and fail the tiling job if none of these * countermeasures worked. * - * Set WQ_MEM_RECLAIM on sched->wq to unblock the situation when the - * system is running out of memory. + * Set WQ_MEM_RECLAIM on sched->wq and wq->sched_wq to unblock the + * situation when the system is running out of memory. */ sched->heap_alloc_wq = alloc_workqueue("panthor-heap-alloc", WQ_UNBOUND, 0); sched->wq = alloc_workqueue("panthor-csf-sched", WQ_MEM_RECLAIM | WQ_UNBOUND, 0); - if (!sched->wq || !sched->heap_alloc_wq) { + sched->sched_wq = alloc_ordered_workqueue("panthor-drm-sched", WQ_MEM_RECLAIM); + if (!sched->wq || !sched->heap_alloc_wq || !sched->sched_wq) { panthor_sched_fini(&ptdev->base, sched); drm_err(&ptdev->base, "Failed to allocate the workqueues"); return -ENOMEM; -- 2.54.0