From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 554C723D2A3; Wed, 3 Sep 2025 15:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756913023; cv=none; b=SxkxuHdeU//qUSdXTyKZGNr5lgWTGXX9p0+IjozlhOcB9cQt3dTNhBPlA113LCCLHxGTO8beCNoRJ9vvKUMXfa6fwH+Vdg2mPzcFSefdT7uNkEN1VBUCu+WCKEOgVfN2Dgdd/UDjBaDrKCytT5EjOilzbRIvjDKqEbIhQiLvBWk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756913023; c=relaxed/simple; bh=S7LL4MsdJW47Z42rWP9UsxSK5ppKd9sdOI8JWXD9/Y4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b8rg18NXUfu7ttQskX5T61LizEIOGNNsIjAk/niIjCRy5CxQ3aoMQvByttjKil9NMRP0WL1nFPbKjedLEwP2Oq7Ok19Zkhbw5sxqfUcXU5lvMSzU+deGDq4B8W5f5tqf6caS4BBw1B63959imRxpkHQWnPWp1YONCwg7JRxWKSg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=o0KQ4wAp; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="o0KQ4wAp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: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=WDZAXCHyQdJR+rAVGAYAjbO7fmwjjI1leEUOLfsbfz0=; b=o0KQ4wApMOHz/TjSZuytgjgVSu z4HpFYc6l/0le662KfurUN+k/pKNnyqOtfeJ4bfVsBKl0P22wXvmA8mwasW2UbkcPGwMkqUkuPEZM YLEas96zIzAnWyNMpaoJygxg/cvi/0lDg/I7uHkOrSSUlzndSThFVe38aY9JtbaCRg5+9r5Y1A66e 0bAVWedBYvg13N/kri0CCN1XIeXyZAMMT7DV2/eTKPG/uZJZGdXlPkzpDdvcunpQbENJs4nmsg2nQ iNyiKIM2aVZTiPI8c1VI28dLrLWb/wpql0JwRRFsd3AU+5EiWrOBk3orJQvOmwwuZtMHcCYqLUqMy 8zWhMAZQ==; Received: from [84.66.36.92] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1utpKi-006GZ9-Vj; Wed, 03 Sep 2025 17:23:37 +0200 From: Tvrtko Ursulin To: dri-devel@lists.freedesktop.org Cc: amd-gfx@lists.freedesktop.org, kernel-dev@igalia.com, intel-xe@lists.freedesktop.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Tvrtko Ursulin , =?UTF-8?q?Christian=20K=C3=B6nig?= , Danilo Krummrich , Matthew Brost , Philipp Stanner Subject: [RFC 08/21] drm/sched: Remove idle entity from tree Date: Wed, 3 Sep 2025 16:23:14 +0100 Message-ID: <20250903152327.66002-9-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250903152327.66002-1-tvrtko.ursulin@igalia.com> References: <20250903152327.66002-1-tvrtko.ursulin@igalia.com> Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need to keep entities with no jobs in the tree so lets remove it once the last job is consumed. This keeps the tree smaller which is nicer and more efficient as entities are removed and re-added on every popped job. Apart from that, the upcoming fair scheduling algorithm will rely on the tree only containing runnable entities. Signed-off-by: Tvrtko Ursulin Cc: Christian König Cc: Danilo Krummrich Cc: Matthew Brost Cc: Philipp Stanner --- drivers/gpu/drm/scheduler/sched_rq.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_rq.c b/drivers/gpu/drm/scheduler/sched_rq.c index 16d57461765e..67804815ca0d 100644 --- a/drivers/gpu/drm/scheduler/sched_rq.c +++ b/drivers/gpu/drm/scheduler/sched_rq.c @@ -19,6 +19,9 @@ drm_sched_entity_compare_before(struct rb_node *a, const struct rb_node *b) static void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *entity, struct drm_sched_rq *rq) { + lockdep_assert_held(&entity->lock); + lockdep_assert_held(&rq->lock); + if (!RB_EMPTY_NODE(&entity->rb_tree_node)) { rb_erase_cached(&entity->rb_tree_node, &rq->rb_tree_root); RB_CLEAR_NODE(&entity->rb_tree_node); @@ -158,24 +161,27 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity) { struct drm_sched_job *next_job; struct drm_sched_rq *rq; - ktime_t ts; /* * Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ + spin_lock(&entity->lock); + rq = entity->rq; + spin_lock(&rq->lock); next_job = drm_sched_entity_queue_peek(entity); - if (!next_job) - return; + if (next_job) { + ktime_t ts; - spin_lock(&entity->lock); - rq = entity->rq; - spin_lock(&rq->lock); - if (drm_sched_policy == DRM_SCHED_POLICY_FIFO) - ts = next_job->submit_ts; - else - ts = drm_sched_rq_get_rr_ts(rq, entity); - drm_sched_rq_update_fifo_locked(entity, rq, ts); + if (drm_sched_policy == DRM_SCHED_POLICY_FIFO) + ts = next_job->submit_ts; + else + ts = drm_sched_rq_get_rr_ts(rq, entity); + + drm_sched_rq_update_fifo_locked(entity, rq, ts); + } else { + drm_sched_rq_remove_fifo_locked(entity, rq); + } spin_unlock(&rq->lock); spin_unlock(&entity->lock); } -- 2.48.0