From patchwork Mon Mar 24 13:29:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027321 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 9DE98C3600B for ; Mon, 24 Mar 2025 13:30:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0CBCC10E3F5; Mon, 24 Mar 2025 13:30:29 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="ltvVPOEd"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id D6F1410E3F4; Mon, 24 Mar 2025 13:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823028; x=1774359028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wIM7Ap2NLCw1fDjMv7PtrN70hMcsqq8VoScA0EKr67o=; b=ltvVPOEdifk93A9p2aNtqZGfyoteVJBtZUuCQ4Yz/EBpzYwFVoiOIKB/ F4wrfQvDHBJd1pZnjHo/kkBhGPegBWGpwpRPRZrIn7OrbT0u8Kug6NMYw 7Wlfv3SNlJnU75yTMGYPqcXAvkj83m4It3XtqwyJIjIRecRTVzeti1PAf 8PVrRLPL2InYUcrXSncaBURFT7eOyfWmbAbV7a0JF2d54LfPJk9aNiJiR ydsD5gbscS+tsmvEtCdGanPV85GKKcTzh4SP4pJdoueqIM8FseTbJ7COT aE+hyC0rmM3APgQrNRAeqzt9IT27HRGvjXv5fE/NIiXVHvSaYOUe5jT43 A==; X-CSE-ConnectionGUID: XxjeSVQDRdKZ3FqFAy0A1A== X-CSE-MsgGUID: fi60PrFaRUmeZylQ8Ox8kg== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="47682968" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="47682968" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:27 -0700 X-CSE-ConnectionGUID: OzoZbyt6SrqiW2FAd4BoyQ== X-CSE-MsgGUID: 92HnHGpXTmGPPN2r32lqgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124061692" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:24 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 01/15] drm/i915/gt: Avoid using masked workaround for CCS_MODE setting Date: Mon, 24 Mar 2025 14:29:37 +0100 Message-ID: <20250324132952.1075209-2-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" When setting the CCS mode, we mistakenly used wa_masked_en() to apply the workaround, which reads from the register and masks the existing value with the new one. Our intention was to write the value directly, without masking it. So far, this hasn't caused issues because we've been using a register value that only enables a single CCS engine, typically with an ID of '0'. However, in upcoming patches, we will be utilizing multiple engines, and it's crucial that we write the new value directly without any masking. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_workarounds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gt/intel_workarounds.c b/drivers/gpu/drm/i915/gt/intel_workarounds.c index 116683ebe074..b3dd8a077660 100644 --- a/drivers/gpu/drm/i915/gt/intel_workarounds.c +++ b/drivers/gpu/drm/i915/gt/intel_workarounds.c @@ -2760,7 +2760,7 @@ static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_li * assign all slices to a single CCS. We will call it CCS mode 1 */ mode = intel_gt_apply_ccs_mode(gt); - wa_masked_en(wal, XEHP_CCS_MODE, mode); + wa_add(wal, XEHP_CCS_MODE, 0, mode, mode, false); } /* From patchwork Mon Mar 24 13:29:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027322 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 19440C3600C for ; Mon, 24 Mar 2025 13:30:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74CF010E3F4; Mon, 24 Mar 2025 13:30:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="cAN2QcAH"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 31DB710E3F3; Mon, 24 Mar 2025 13:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823035; x=1774359035; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6p4CMRy1NHVUMv8FMMCIzMThsBHsmA9L3MRtNO76Q/k=; b=cAN2QcAH/VWwRrl2cJbMeMcasxhLmUg1rzJs3ZYoxDJQ2u/STYTYr3tE 9HCWDITTS3XeoSUm4KWICBJf4wg2++12tyLRNWDJhMIwVf+sbS/uteSxU MOyURVrMK4i5HngW/kHB2KVsWs/JJb20A7sCnXo5S40VLLJGDeYWYF4n/ hgrflTjxVzU3MtTYMGBo7Py+Yk9BQkXdT5Mwt8ruVkdbcgOOvNHgA4uZP bTKIrp/3X1jFCQfXUi7m0Eud0hj6tvPwOj0LQr2aYVS81lJR5Wdw6sXdg SarVNB6+6i84BNyv4E5Npwu8udpgl8OCqyZJv5k8p9jktYu2P9ODROECM w==; X-CSE-ConnectionGUID: sPSXU8G6Sn+abRM6pHwKkQ== X-CSE-MsgGUID: HaqcZC0iQlmeLaivNT/oTA== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="47683011" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="47683011" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:35 -0700 X-CSE-ConnectionGUID: vceYKWPhTyKVp5fGv7M8CA== X-CSE-MsgGUID: pMAie4wqSwyoCA7TMUWstQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124061727" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:31 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 02/15] drm/i915/gt: Move the CCS mode variable to a global position Date: Mon, 24 Mar 2025 14:29:38 +0100 Message-ID: <20250324132952.1075209-3-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Store the CCS mode value in the intel_gt->ccs structure to make it available for future instances that may need to change its value. Name it mode_reg_val because it holds the value that will be written into the CCS_MODE register, determining the CCS balancing and, consequently, the number of engines generated. No functional changes intended. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt.c | 3 +++ drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 16 +++++++++++----- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h | 2 +- drivers/gpu/drm/i915/gt/intel_gt_types.h | 11 +++++++++++ drivers/gpu/drm/i915/gt/intel_workarounds.c | 6 ++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt.c b/drivers/gpu/drm/i915/gt/intel_gt.c index 3d3b1ba76e2b..bf09297f92c1 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt.c +++ b/drivers/gpu/drm/i915/gt/intel_gt.c @@ -18,6 +18,7 @@ #include "intel_ggtt_gmch.h" #include "intel_gt.h" #include "intel_gt_buffer_pool.h" +#include "intel_gt_ccs_mode.h" #include "intel_gt_clock_utils.h" #include "intel_gt_debugfs.h" #include "intel_gt_mcr.h" @@ -136,6 +137,8 @@ int intel_gt_init_mmio(struct intel_gt *gt) intel_sseu_info_init(gt); intel_gt_mcr_init(gt); + intel_gt_ccs_mode_init(gt); + return intel_engines_init_mmio(gt); } diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index 3c62a44e9106..fcd07eb4728b 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -8,15 +8,12 @@ #include "intel_gt_ccs_mode.h" #include "intel_gt_regs.h" -unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt) +static void intel_gt_apply_ccs_mode(struct intel_gt *gt) { int cslice; u32 mode = 0; int first_ccs = __ffs(CCS_MASK(gt)); - if (!IS_DG2(gt->i915)) - return 0; - /* Build the value for the fixed CCS load balancing */ for (cslice = 0; cslice < I915_MAX_CCS; cslice++) { if (gt->ccs.cslices & BIT(cslice)) @@ -35,5 +32,14 @@ unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt) XEHP_CCS_MODE_CSLICE_MASK); } - return mode; + gt->ccs.mode_reg_val = mode; +} + +void intel_gt_ccs_mode_init(struct intel_gt *gt) +{ + if (!IS_DG2(gt->i915)) + return; + + /* Initialize the CCS mode setting */ + intel_gt_apply_ccs_mode(gt); } diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h index 55547f2ff426..0f2506586a41 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h @@ -8,6 +8,6 @@ struct intel_gt; -unsigned int intel_gt_apply_ccs_mode(struct intel_gt *gt); +void intel_gt_ccs_mode_init(struct intel_gt *gt); #endif /* __INTEL_GT_CCS_MODE_H__ */ diff --git a/drivers/gpu/drm/i915/gt/intel_gt_types.h b/drivers/gpu/drm/i915/gt/intel_gt_types.h index bcee084b1f27..9e257f34d05b 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_types.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_types.h @@ -207,12 +207,23 @@ struct intel_gt { [MAX_ENGINE_INSTANCE + 1]; enum intel_submission_method submission_method; + /* + * Track fixed mapping between CCS engines and compute slices. + * + * In order to w/a HW that has the inability to dynamically load + * balance between CCS engines and EU in the compute slices, we have to + * reconfigure a static mapping on the fly. + * + * The mode variable is set by the user and sets the balancing mode, + * i.e. how the CCS streams are distributed amongs the slices. + */ struct { /* * Mask of the non fused CCS slices * to be used for the load balancing */ intel_engine_mask_t cslices; + u32 mode_reg_val; } ccs; /* diff --git a/drivers/gpu/drm/i915/gt/intel_workarounds.c b/drivers/gpu/drm/i915/gt/intel_workarounds.c index b3dd8a077660..bec70294fc5c 100644 --- a/drivers/gpu/drm/i915/gt/intel_workarounds.c +++ b/drivers/gpu/drm/i915/gt/intel_workarounds.c @@ -2742,7 +2742,7 @@ add_render_compute_tuning_settings(struct intel_gt *gt, static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_list *wal) { struct intel_gt *gt = engine->gt; - u32 mode; + u32 mode = gt->ccs.mode_reg_val; if (!IS_DG2(gt->i915)) return; @@ -2758,8 +2758,10 @@ static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_li /* * After having disabled automatic load balancing we need to * assign all slices to a single CCS. We will call it CCS mode 1 + * + * The gt->ccs.mode_reg_val has already been set previously during + * initialization. */ - mode = intel_gt_apply_ccs_mode(gt); wa_add(wal, XEHP_CCS_MODE, 0, mode, mode, false); } From patchwork Mon Mar 24 13:29:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027323 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 CBCB4C3600B for ; Mon, 24 Mar 2025 13:30:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2153610E3FA; Mon, 24 Mar 2025 13:30:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="P2kBSQmq"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id DCBE510E3FA; Mon, 24 Mar 2025 13:30:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823042; x=1774359042; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hSIAYqsJrH/ialZ89ugO5jmuLNQyH1/tyx8P5WFoZIw=; b=P2kBSQmqoZPbcHJDMJ4jEUnqTJQfSPxyn8iGWjMmpuXAshxOeh+WU9Ym C7Py+aaEClw5sl3e5zos3A6hg57XiJTfkFSOrGw4FyRPjFaJPLpWZIWTK VcOlUtseNTTutn6KuKklriPmIY6CvWh6vkIho8n4vYnYd5ZBsq7Zqyu/M tQqTUqYOuXroRvgjliQazSXIYga+FzQkcnfSwyQjiyHskOb1bHsBR5fQa Q4BzedW70UswqiytiM0cv6d3eX8ZZ414xy7fXBnUMRE8kFRVcsKLurf/k ETKhKKgy7ezFXYMgbaka96HmnbLpo/mIIiyrHjDmKjJZEWuiydn8/+vYh g==; X-CSE-ConnectionGUID: xFR4HF2TRPmk4+poSSKNLw== X-CSE-MsgGUID: FhOhQiqgQdyV6sjNHlzIkA== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="44133967" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="44133967" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:41 -0700 X-CSE-ConnectionGUID: qBEBqokTST+lGiBCYyDEdg== X-CSE-MsgGUID: qLozwjL7Q2Sg9VVg/ymCUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124209210" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:38 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 03/15] drm/i915/gt: Allow the creation of multi-mode CCS masks Date: Mon, 24 Mar 2025 14:29:39 +0100 Message-ID: <20250324132952.1075209-4-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Until now, we have only set CCS mode balancing to 1, which means that only one compute engine is exposed to the user. The stream of compute commands submitted to that engine is then shared among all the dedicated execution units. This is done by calling the 'intel_gt_apply_ccs_mode(); function. With this change, the aforementioned function takes an additional parameter called 'mode' that specifies the desired mode to be set for the CCS engines balancing. The mode parameter can have the following values: - mode = 0: CCS load balancing mode 1 (1 CCS engine exposed) - mode = 1: CCS load balancing mode 2 (2 CCS engines exposed) - mode = 3: CCS load balancing mode 4 (4 CCS engines exposed) This allows us to generate the appropriate register value to be written to CCS_MODE, configuring how the exposed engine streams will be submitted to the execution units. No functional changes are intended yet, as no mode higher than '0' is currently being set. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 85 +++++++++++++++++---- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h | 2 +- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index fcd07eb4728b..a6c33b471567 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -4,35 +4,92 @@ */ #include "i915_drv.h" -#include "intel_gt.h" #include "intel_gt_ccs_mode.h" #include "intel_gt_regs.h" static void intel_gt_apply_ccs_mode(struct intel_gt *gt) { + unsigned long cslices_mask = gt->ccs.cslices; + u32 mode_val = 0; + /* CCS engine id, i.e. the engines position in the engine's bitmask */ + int engine; int cslice; - u32 mode = 0; - int first_ccs = __ffs(CCS_MASK(gt)); - /* Build the value for the fixed CCS load balancing */ + /* + * The mode has two bit dedicated for each engine + * that will be used for the CCS balancing algorithm: + * + * BIT | CCS slice + * ------------------ + * 0 | CCS slice + * 1 | 0 + * ------------------ + * 2 | CCS slice + * 3 | 1 + * ------------------ + * 4 | CCS slice + * 5 | 2 + * ------------------ + * 6 | CCS slice + * 7 | 3 + * ------------------ + * + * When a CCS slice is not available, then we will write 0x7, + * oterwise we will write the user engine id which load will + * be forwarded to that slice. + * + * The possible configurations are: + * + * 1 engine (ccs0): + * slice 0, 1, 2, 3: ccs0 + * + * 2 engines (ccs0, ccs1): + * slice 0, 2: ccs0 + * slice 1, 3: ccs1 + * + * 4 engines (ccs0, ccs1, ccs2, ccs3): + * slice 0: ccs0 + * slice 1: ccs1 + * slice 2: ccs2 + * slice 3: ccs3 + */ + engine = __ffs(cslices_mask); + for (cslice = 0; cslice < I915_MAX_CCS; cslice++) { - if (gt->ccs.cslices & BIT(cslice)) + if (!(cslices_mask & BIT(cslice))) { /* - * If available, assign the cslice - * to the first available engine... + * If not available, mark the slice as unavailable + * and no task will be dispatched here. */ - mode |= XEHP_CCS_MODE_CSLICE(cslice, first_ccs); + mode_val |= XEHP_CCS_MODE_CSLICE(cslice, + XEHP_CCS_MODE_CSLICE_MASK); + continue; + } - else + mode_val |= XEHP_CCS_MODE_CSLICE(cslice, engine); + + engine = find_next_bit(&cslices_mask, I915_MAX_CCS, engine + 1); + /* + * If "engine" has reached the I915_MAX_CCS value it means that + * we have gone through all the unfused engines and now we need + * to reset its value to the first engine. + * + * From the find_next_bit() description: + * + * "Returns the bit number for the next set bit + * If no bits are set, returns @size." + */ + if (engine == I915_MAX_CCS) { /* - * ... otherwise, mark the cslice as - * unavailable if no CCS dispatches here + * CCS mode, will be used later to + * reset to a flexible value */ - mode |= XEHP_CCS_MODE_CSLICE(cslice, - XEHP_CCS_MODE_CSLICE_MASK); + engine = __ffs(cslices_mask); + continue; + } } - gt->ccs.mode_reg_val = mode; + gt->ccs.mode_reg_val = mode_val; } void intel_gt_ccs_mode_init(struct intel_gt *gt) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h index 0f2506586a41..4a6763b95a78 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h @@ -6,7 +6,7 @@ #ifndef __INTEL_GT_CCS_MODE_H__ #define __INTEL_GT_CCS_MODE_H__ -struct intel_gt; +#include "intel_gt.h" void intel_gt_ccs_mode_init(struct intel_gt *gt); From patchwork Mon Mar 24 13:29:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027324 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 6549CC36002 for ; Mon, 24 Mar 2025 13:30:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C01EF10E3FD; Mon, 24 Mar 2025 13:30:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="DR95mpnS"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 58D9F10E3FB; Mon, 24 Mar 2025 13:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823048; x=1774359048; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PPr1duwMkRcKDYxMWWJ/kZemhhAGp5BzUkTLLCgGJkQ=; b=DR95mpnSovztmMJDyb6uwQ+gOZYig8Tx8Q05BP2HwxY88dUz8boXl3j2 7y67X9+lYjzSzFEgCuYOAsgzL1YZoV3vQ5JNdNFem74eaAnwWqVEjyH60 OAtg6h8dq5hdqame7hsXKhKUyF4iXcJWqfM01xVI0NeDXByP9wtgB06bv ET6hXv0BkHPBjyozCspFUz7ai6rbbTR9z8+EHfXEanCK+knOePQiHrmm3 PuovOuchhLyZZLH78t2zleEKfosDpaunDziUzm3lQ2MJyJVvwB275bTxr GAaimQJO/LsUn1htprRRRt2pGLQUD+WA0F8KCQg434cSOpMQs8z/OO1Fz w==; X-CSE-ConnectionGUID: l1VkMij2TYWXmnwg1YNx8Q== X-CSE-MsgGUID: Imxl78sLQX6BrHXezFRGVA== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="44133980" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="44133980" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:48 -0700 X-CSE-ConnectionGUID: ujrSekMkRH22fddlly4Odw== X-CSE-MsgGUID: hq0gnTdAQN2OqcrtldIxZA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124209221" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:44 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti , Tvrtko Ursulin Subject: [PATCH v4 04/15] drm/i915/gt: Refactor uabi engine class/instance list creation Date: Mon, 24 Mar 2025 14:29:40 +0100 Message-ID: <20250324132952.1075209-5-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" For the upcoming changes we need a cleaner way to build the list of uabi engines. Suggested-by: Tvrtko Ursulin Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_engine_user.c | 29 ++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_user.c b/drivers/gpu/drm/i915/gt/intel_engine_user.c index 833987015b8b..11cc06c0c785 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_user.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_user.c @@ -203,7 +203,7 @@ static void engine_rename(struct intel_engine_cs *engine, const char *name, u16 void intel_engines_driver_register(struct drm_i915_private *i915) { - u16 name_instance, other_instance = 0; + u16 class_instance[I915_LAST_UABI_ENGINE_CLASS + 2] = { }; struct legacy_ring ring = {}; struct list_head *it, *next; struct rb_node **p, *prev; @@ -214,6 +214,8 @@ void intel_engines_driver_register(struct drm_i915_private *i915) prev = NULL; p = &i915->uabi_engines.rb_node; list_for_each_safe(it, next, &engines) { + u16 uabi_class; + struct intel_engine_cs *engine = container_of(it, typeof(*engine), uabi_list); @@ -222,15 +224,14 @@ void intel_engines_driver_register(struct drm_i915_private *i915) GEM_BUG_ON(engine->class >= ARRAY_SIZE(uabi_classes)); engine->uabi_class = uabi_classes[engine->class]; - if (engine->uabi_class == I915_NO_UABI_CLASS) { - name_instance = other_instance++; - } else { - GEM_BUG_ON(engine->uabi_class >= - ARRAY_SIZE(i915->engine_uabi_class_count)); - name_instance = - i915->engine_uabi_class_count[engine->uabi_class]++; - } - engine->uabi_instance = name_instance; + + if (engine->uabi_class == I915_NO_UABI_CLASS) + uabi_class = I915_LAST_UABI_ENGINE_CLASS + 1; + else + uabi_class = engine->uabi_class; + + GEM_BUG_ON(uabi_class >= ARRAY_SIZE(class_instance)); + engine->uabi_instance = class_instance[uabi_class]++; /* * Replace the internal name with the final user and log facing @@ -238,11 +239,15 @@ void intel_engines_driver_register(struct drm_i915_private *i915) */ engine_rename(engine, intel_engine_class_repr(engine->class), - name_instance); + engine->uabi_instance); - if (engine->uabi_class == I915_NO_UABI_CLASS) + if (uabi_class > I915_LAST_UABI_ENGINE_CLASS) continue; + GEM_BUG_ON(uabi_class >= + ARRAY_SIZE(i915->engine_uabi_class_count)); + i915->engine_uabi_class_count[uabi_class]++; + rb_link_node(&engine->uabi_node, prev, p); rb_insert_color(&engine->uabi_node, &i915->uabi_engines); From patchwork Mon Mar 24 13:29:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027325 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 00A33C36002 for ; Mon, 24 Mar 2025 13:30:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 641CD10E3FB; Mon, 24 Mar 2025 13:30:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="f2kTrwr0"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B98410E3FB; Mon, 24 Mar 2025 13:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823054; x=1774359054; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lpwNkHlIqkg1GJGVRPhIXkpFAk3MWeFOqvNleve+cLQ=; b=f2kTrwr0525X56eXpSCRwlueL395dm1dpCL6zI7IAZ41KO1I/P//8o6j 7KDLFnoFDI9+P1IYRfb2a/Vv/vgqrUkfee1eR4/m5Tutev0nveu6SVOXZ kpiayQahtrsEYyAcseETQg5LKpydaRxwei55qAzZH0tGwQMsYOhjhdJKG xIGCLiGgBTu2G7FM+l5k8pKB05GhVrvOk6Kzba0MNJtIEgi/VBy50TZbo LIgEb3gPXpW1+h27nCTivKkASHXG8vY1GQdGrjLsfMAen/CNAdANed1IP YOXWz2DojrmHHFv8hUl8UuKpc0JdbA7uX4/auJ8GWPC4k36yBsZGM9+NK w==; X-CSE-ConnectionGUID: VIcVCRKHQ5ylIlRUUb7oUg== X-CSE-MsgGUID: 7yYEa8Z0SmKt4AIDAxIiwQ== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="44133991" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="44133991" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:54 -0700 X-CSE-ConnectionGUID: c6WuyvfQTge6FRNsZM6OqQ== X-CSE-MsgGUID: 5MMW1gFXRXmxpa9EDds12g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124209237" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:50 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 05/15] drm/i915/gem: Mark and verify UABI engine validity Date: Mon, 24 Mar 2025 14:29:41 +0100 Message-ID: <20250324132952.1075209-6-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Mark engines as invalid when they are not added to the UABI list to prevent accidental assignment of batch buffers. Currently, this change is mostly precautionary with minimal impact. However, in the future, when CCS engines will be dynamically added and removed by the user, this mechanism will be used for determining engine validity. Signed-off-by: Andi Shyti --- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 28 +++++++++++++++++-- drivers/gpu/drm/i915/gt/intel_engine_user.c | 9 ++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 7796c4119ef5..a6448f6c8f6a 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -2680,6 +2680,22 @@ eb_select_legacy_ring(struct i915_execbuffer *eb) return user_ring_map[user_ring_id]; } +static bool engine_valid(struct intel_context *ce) +{ + if (!intel_engine_is_virtual(ce->engine)) + return !RB_EMPTY_NODE(&ce->engine->uabi_node); + + /* + * TODO: check virtual sibilings; we need to walk through all the + * virtual engines and ask whether the physical engine where it is based + * is still valid. For each of them we need to check with + * RB_EMPTY_NODE(...) + * + * This can be a placed in a new ce_ops. + */ + return true; +} + static int eb_select_engine(struct i915_execbuffer *eb) { @@ -2710,8 +2726,6 @@ eb_select_engine(struct i915_execbuffer *eb) eb->num_batches = ce->parallel.number_children + 1; gt = ce->engine->gt; - for_each_child(ce, child) - intel_context_get(child); eb->wakeref = intel_gt_pm_get(ce->engine->gt); /* * Keep GT0 active on MTL so that i915_vma_parked() doesn't @@ -2720,6 +2734,16 @@ eb_select_engine(struct i915_execbuffer *eb) if (gt->info.id) eb->wakeref_gt0 = intel_gt_pm_get(to_gt(gt->i915)); + /* We need to hold the wakeref to stabilize i915->uabi_engines */ + if (!engine_valid(ce)) { + intel_context_put(ce); + err = -ENODEV; + goto err; + } + + for_each_child(ce, child) + intel_context_get(child); + if (!test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) { err = intel_context_alloc_state(ce); if (err) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_user.c b/drivers/gpu/drm/i915/gt/intel_engine_user.c index 11cc06c0c785..cd7662b1ad59 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_user.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_user.c @@ -220,7 +220,7 @@ void intel_engines_driver_register(struct drm_i915_private *i915) container_of(it, typeof(*engine), uabi_list); if (intel_gt_has_unrecoverable_error(engine->gt)) - continue; /* ignore incomplete engines */ + goto clear_node_continue; /* ignore incomplete engines */ GEM_BUG_ON(engine->class >= ARRAY_SIZE(uabi_classes)); engine->uabi_class = uabi_classes[engine->class]; @@ -242,7 +242,7 @@ void intel_engines_driver_register(struct drm_i915_private *i915) engine->uabi_instance); if (uabi_class > I915_LAST_UABI_ENGINE_CLASS) - continue; + goto clear_node_continue; GEM_BUG_ON(uabi_class >= ARRAY_SIZE(i915->engine_uabi_class_count)); @@ -260,6 +260,11 @@ void intel_engines_driver_register(struct drm_i915_private *i915) prev = &engine->uabi_node; p = &prev->rb_right; + + continue; + +clear_node_continue: + RB_CLEAR_NODE(&engine->uabi_node); } if (IS_ENABLED(CONFIG_DRM_I915_SELFTESTS) && From patchwork Mon Mar 24 13:29:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027326 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 648C6C36002 for ; Mon, 24 Mar 2025 13:31:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C1C1B10E402; Mon, 24 Mar 2025 13:31:01 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="emRxP14S"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 33D9010E402; Mon, 24 Mar 2025 13:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823061; x=1774359061; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AJK6ea4Xsjf2ytS2pyg23oNywyBBHMaSfUDKO3MljCc=; b=emRxP14Sk/xeYmmhhiyOh94q0p+QY8+B+p3uN4rTW1YpD6UFPmobPILL qMS9mvfE03c5EkgFodZYRfMkLFrCm3xSNIbYujJJFSgo7mjn3cJiipTw9 EzQf5z18p1yEzGU/J41SbogNZZVia9FCD65EdaEOX0al1B3H3N+EYlqbR L+pX8sb6Kpl82h2LURhMYlvOmxIQz00EtxuOMuKAJVLjMuC4F1GISHFNq ZQXre7opvsT1/ozUdejDtKxP0hAWDy7OCCpuyToGQBzbJa8khMTJEtTqZ BVlEpWm+EIMvZ319hHsM8PWT1yLdTauR7iEsYT3cfwmcb6aR0LW5CBYVw Q==; X-CSE-ConnectionGUID: mDwtd34uRxSHJHgoSLoNfw== X-CSE-MsgGUID: U7YJJywBTQ+5S8wfdLbfBg== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="44134005" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="44134005" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:01 -0700 X-CSE-ConnectionGUID: gbsC7mv7TxymVrF3xJ6BAw== X-CSE-MsgGUID: 6DGmxlLeTvqPGi/vOaQpqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124209254" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:30:56 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 06/15] drm/i915/gt: Introduce for_each_enabled_engine() and apply it in selftests Date: Mon, 24 Mar 2025 14:29:42 +0100 Message-ID: <20250324132952.1075209-7-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Selftests should run only on enabled engines, as disabled engines are not intended for use. A practical example is when, on DG2 machines, the user chooses to utilize only one CCS stream instead of all four. To address this, introduce the for_each_enabled_engine() loop, which will skip engines when they are marked as RB_EMPTY. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt.h | 12 +++++ drivers/gpu/drm/i915/gt/selftest_context.c | 6 +-- drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 4 +- .../drm/i915/gt/selftest_engine_heartbeat.c | 6 +-- drivers/gpu/drm/i915/gt/selftest_engine_pm.c | 6 +-- drivers/gpu/drm/i915/gt/selftest_execlists.c | 52 +++++++++---------- drivers/gpu/drm/i915/gt/selftest_gt_pm.c | 2 +- drivers/gpu/drm/i915/gt/selftest_hangcheck.c | 22 ++++---- drivers/gpu/drm/i915/gt/selftest_lrc.c | 18 +++---- drivers/gpu/drm/i915/gt/selftest_mocs.c | 6 +-- drivers/gpu/drm/i915/gt/selftest_rc6.c | 4 +- drivers/gpu/drm/i915/gt/selftest_reset.c | 8 +-- .../drm/i915/gt/selftest_ring_submission.c | 2 +- drivers/gpu/drm/i915/gt/selftest_rps.c | 14 ++--- drivers/gpu/drm/i915/gt/selftest_timeline.c | 14 ++--- drivers/gpu/drm/i915/gt/selftest_tlb.c | 2 +- .../gpu/drm/i915/gt/selftest_workarounds.c | 14 ++--- 17 files changed, 102 insertions(+), 90 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt.h b/drivers/gpu/drm/i915/gt/intel_gt.h index 998ca029b73a..1c9d861241ad 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt.h +++ b/drivers/gpu/drm/i915/gt/intel_gt.h @@ -188,6 +188,18 @@ int intel_gt_tiles_init(struct drm_i915_private *i915); (id__)++) \ for_each_if ((engine__) = (gt__)->engine[(id__)]) +/* + * Iterator over all initialized and enabled engines. Some engines, like CCS, + * may be "disabled" (i.e., not exposed to the user). Disabling is indicated + * by marking the rb_node as empty. + */ +#define for_each_enabled_engine(engine__, gt__, id__) \ + for ((id__) = 0; \ + (id__) < I915_NUM_ENGINES; \ + (id__)++) \ + for_each_if (((engine__) = (gt__)->engine[(id__)]) && \ + (!RB_EMPTY_NODE(&(engine__)->uabi_node))) + /* Iterator over subset of engines selected by mask */ #define for_each_engine_masked(engine__, gt__, mask__, tmp__) \ for ((tmp__) = (mask__) & (gt__)->info.engine_mask; \ diff --git a/drivers/gpu/drm/i915/gt/selftest_context.c b/drivers/gpu/drm/i915/gt/selftest_context.c index 5eb46700dc4e..9976e231248d 100644 --- a/drivers/gpu/drm/i915/gt/selftest_context.c +++ b/drivers/gpu/drm/i915/gt/selftest_context.c @@ -157,7 +157,7 @@ static int live_context_size(void *arg) * HW tries to write past the end of one. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct file *saved; if (!engine->context_size) @@ -311,7 +311,7 @@ static int live_active_context(void *arg) enum intel_engine_id id; int err = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = __live_active_context(engine); if (err) break; @@ -424,7 +424,7 @@ static int live_remote_context(void *arg) enum intel_engine_id id; int err = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = __live_remote_context(engine); if (err) break; diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_cs.c b/drivers/gpu/drm/i915/gt/selftest_engine_cs.c index 5ffa5e30f419..038723a401df 100644 --- a/drivers/gpu/drm/i915/gt/selftest_engine_cs.c +++ b/drivers/gpu/drm/i915/gt/selftest_engine_cs.c @@ -142,7 +142,7 @@ static int perf_mi_bb_start(void *arg) return 0; wakeref = perf_begin(gt); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce = engine->kernel_context; struct i915_vma *batch; u32 cycles[COUNT]; @@ -270,7 +270,7 @@ static int perf_mi_noop(void *arg) return 0; wakeref = perf_begin(gt); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce = engine->kernel_context; struct i915_vma *base, *nop; u32 cycles[COUNT]; diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c b/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c index 9e4f0e417b3b..74d4c2dc69cf 100644 --- a/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c +++ b/drivers/gpu/drm/i915/gt/selftest_engine_heartbeat.c @@ -160,7 +160,7 @@ static int live_idle_flush(void *arg) /* Check that we can flush the idle barriers */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { st_engine_heartbeat_disable(engine); err = __live_idle_pulse(engine, intel_engine_flush_barriers); st_engine_heartbeat_enable(engine); @@ -180,7 +180,7 @@ static int live_idle_pulse(void *arg) /* Check that heartbeat pulses flush the idle barriers */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { st_engine_heartbeat_disable(engine); err = __live_idle_pulse(engine, intel_engine_pulse); st_engine_heartbeat_enable(engine); @@ -246,7 +246,7 @@ static int live_heartbeat_off(void *arg) if (!CONFIG_DRM_I915_HEARTBEAT_INTERVAL) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { if (!intel_engine_has_preemption(engine)) continue; diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_pm.c b/drivers/gpu/drm/i915/gt/selftest_engine_pm.c index 10e556a7eac4..1da3bddbf02e 100644 --- a/drivers/gpu/drm/i915/gt/selftest_engine_pm.c +++ b/drivers/gpu/drm/i915/gt/selftest_engine_pm.c @@ -203,7 +203,7 @@ static int live_engine_timestamps(void *arg) if (GRAPHICS_VER(gt->i915) < 8) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { int err; st_engine_heartbeat_disable(engine); @@ -257,7 +257,7 @@ static int live_engine_busy_stats(void *arg) return -ENOMEM; GEM_BUG_ON(intel_gt_pm_is_awake(gt)); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; ktime_t busyness, dummy; ktime_t de, dt; @@ -363,7 +363,7 @@ static int live_engine_pm(void *arg) } GEM_BUG_ON(intel_gt_pm_is_awake(gt)); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { const typeof(*igt_atomic_phases) *p; for (p = igt_atomic_phases; p->name; p++) { diff --git a/drivers/gpu/drm/i915/gt/selftest_execlists.c b/drivers/gpu/drm/i915/gt/selftest_execlists.c index d7717de17ecc..e47411c05b31 100644 --- a/drivers/gpu/drm/i915/gt/selftest_execlists.c +++ b/drivers/gpu/drm/i915/gt/selftest_execlists.c @@ -120,7 +120,7 @@ static int live_sanitycheck(void *arg) if (igt_spinner_init(&spin, gt)) return -ENOMEM; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; struct i915_request *rq; @@ -177,7 +177,7 @@ static int live_unlite_restore(struct intel_gt *gt, int prio) return err; err = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce[2] = {}; struct i915_request *rq[2]; struct igt_live_test t; @@ -339,7 +339,7 @@ static int live_unlite_ring(void *arg) if (igt_spinner_init(&spin, gt)) return -ENOMEM; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce[2] = {}; struct i915_request *rq; struct igt_live_test t; @@ -488,7 +488,7 @@ static int live_pin_rewind(void *arg) * To simulate this, let's apply a bit of deliberate sabotague. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; struct i915_request *rq; struct intel_ring *ring; @@ -596,7 +596,7 @@ static int live_hold_reset(void *arg) if (igt_spinner_init(&spin, gt)) return -ENOMEM; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; struct i915_request *rq; @@ -703,7 +703,7 @@ static int live_error_interrupt(void *arg) if (!intel_has_reset_engine(gt)) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { const struct error_phase *p; int err = 0; @@ -938,7 +938,7 @@ slice_semaphore_queue(struct intel_engine_cs *outer, if (IS_ERR(head)) return PTR_ERR(head); - for_each_engine(engine, outer->gt, id) { + for_each_enabled_engine(engine, outer->gt, id) { if (!intel_engine_has_preemption(engine)) continue; @@ -1018,7 +1018,7 @@ static int live_timeslice_preempt(void *arg) if (err) goto err_pin; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { if (!intel_engine_has_preemption(engine)) continue; @@ -1124,7 +1124,7 @@ static int live_timeslice_rewind(void *arg) if (!CONFIG_DRM_I915_TIMESLICE_DURATION) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { enum { A1, A2, B1 }; enum { X = 1, Z, Y }; struct i915_request *rq[3] = {}; @@ -1325,7 +1325,7 @@ static int live_timeslice_queue(void *arg) if (err) goto err_pin; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_sched_attr attr = { .priority = I915_PRIORITY_MAX }; struct i915_request *rq, *nop; @@ -1425,7 +1425,7 @@ static int live_timeslice_nopreempt(void *arg) if (igt_spinner_init(&spin, gt)) return -ENOMEM; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; struct i915_request *rq; unsigned long timeslice; @@ -1578,7 +1578,7 @@ static int live_busywait_preempt(void *arg) if (err) goto err_vma; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *lo, *hi; struct igt_live_test t; u32 *cs; @@ -1754,7 +1754,7 @@ static int live_preempt(void *arg) if (igt_spinner_init(&spin_lo, gt)) goto err_spin_hi; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct igt_live_test t; struct i915_request *rq; @@ -1847,7 +1847,7 @@ static int live_late_preempt(void *arg) /* Make sure ctx_lo stays before ctx_hi until we trigger preemption. */ ctx_lo->sched.priority = 1; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct igt_live_test t; struct i915_request *rq; @@ -1969,7 +1969,7 @@ static int live_nopreempt(void *arg) goto err_client_a; b.ctx->sched.priority = I915_PRIORITY_MAX; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq_a, *rq_b; if (!intel_engine_has_preemption(engine)) @@ -2396,7 +2396,7 @@ static int live_preempt_cancel(void *arg) if (preempt_client_init(gt, &data.b)) goto err_client_a; - for_each_engine(data.engine, gt, id) { + for_each_enabled_engine(data.engine, gt, id) { if (!intel_engine_has_preemption(data.engine)) continue; @@ -2463,7 +2463,7 @@ static int live_suppress_self_preempt(void *arg) if (preempt_client_init(gt, &b)) goto err_client_a; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq_a, *rq_b; int depth; @@ -2570,7 +2570,7 @@ static int live_chain_preempt(void *arg) if (preempt_client_init(gt, &lo)) goto err_client_hi; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_sched_attr attr = { .priority = I915_PRIORITY_MAX }; struct igt_live_test t; struct i915_request *rq; @@ -2928,7 +2928,7 @@ static int live_preempt_ring(void *arg) if (igt_spinner_init(&spin, gt)) return -ENOMEM; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { int n; if (!intel_engine_has_preemption(engine)) @@ -2971,7 +2971,7 @@ static int live_preempt_gang(void *arg) * high priority levels into execution order. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq = NULL; struct igt_live_test t; IGT_TIMEOUT(end_time); @@ -3277,7 +3277,7 @@ static int live_preempt_user(void *arg) return PTR_ERR(result); } - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *client[3] = {}; struct igt_live_test t; int i; @@ -3393,7 +3393,7 @@ static int live_preempt_timeout(void *arg) if (igt_spinner_init(&spin_lo, gt)) goto err_ctx_lo; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { unsigned long saved_timeout; struct i915_request *rq; @@ -3567,7 +3567,7 @@ static int smoke_crescendo(struct preempt_smoke *smoke, unsigned int flags) memset(arg, 0, I915_NUM_ENGINES * sizeof(*arg)); - for_each_engine(engine, smoke->gt, id) { + for_each_enabled_engine(engine, smoke->gt, id) { arg[id] = *smoke; arg[id].engine = engine; if (!(flags & BATCH)) @@ -3585,7 +3585,7 @@ static int smoke_crescendo(struct preempt_smoke *smoke, unsigned int flags) } count = 0; - for_each_engine(engine, smoke->gt, id) { + for_each_enabled_engine(engine, smoke->gt, id) { if (IS_ERR_OR_NULL(worker[id])) continue; @@ -3613,7 +3613,7 @@ static int smoke_random(struct preempt_smoke *smoke, unsigned int flags) count = 0; do { - for_each_engine(smoke->engine, smoke->gt, id) { + for_each_enabled_engine(smoke->engine, smoke->gt, id) { struct i915_gem_context *ctx = smoke_context(smoke); int err; @@ -3876,7 +3876,7 @@ static int live_virtual_engine(void *arg) if (intel_uc_uses_guc_submission(>->uc)) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = nop_virtual_engine(gt, &engine, 1, 1, 0); if (err) { pr_err("Failed to wrap engine %s: err=%d\n", diff --git a/drivers/gpu/drm/i915/gt/selftest_gt_pm.c b/drivers/gpu/drm/i915/gt/selftest_gt_pm.c index 33351deeea4f..ddc4b5623f19 100644 --- a/drivers/gpu/drm/i915/gt/selftest_gt_pm.c +++ b/drivers/gpu/drm/i915/gt/selftest_gt_pm.c @@ -95,7 +95,7 @@ static int live_gt_clocks(void *arg) wakeref = intel_gt_pm_get(gt); intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { u32 cycles; u32 expected; u64 time; diff --git a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c index f057c16410e7..7a486a650e3e 100644 --- a/drivers/gpu/drm/i915/gt/selftest_hangcheck.c +++ b/drivers/gpu/drm/i915/gt/selftest_hangcheck.c @@ -296,7 +296,7 @@ static int igt_hang_sanitycheck(void *arg) if (err) return err; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_wedge_me w; long timeout; @@ -360,7 +360,7 @@ static int igt_reset_nop(void *arg) reset_count = i915_reset_count(global); count = 0; do { - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; int i; @@ -433,7 +433,7 @@ static int igt_reset_nop_engine(void *arg) if (!intel_has_reset_engine(gt)) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { unsigned int reset_count, reset_engine_count, count; struct intel_context *ce; IGT_TIMEOUT(end_time); @@ -553,7 +553,7 @@ static int igt_reset_fail_engine(void *arg) if (!intel_has_reset_engine(gt)) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { unsigned int count; struct intel_context *ce; IGT_TIMEOUT(end_time); @@ -700,7 +700,7 @@ static int __igt_reset_engine(struct intel_gt *gt, bool active) return err; } - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { unsigned int reset_count, reset_engine_count; unsigned long count; bool using_guc = intel_engine_uses_guc(engine); @@ -990,7 +990,7 @@ static int __igt_reset_engines(struct intel_gt *gt, if (!threads) return -ENOMEM; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { unsigned long device = i915_reset_count(global); unsigned long count = 0, reported; bool using_guc = intel_engine_uses_guc(engine); @@ -1010,7 +1010,7 @@ static int __igt_reset_engines(struct intel_gt *gt, } memset(threads, 0, sizeof(*threads) * I915_NUM_ENGINES); - for_each_engine(other, gt, tmp) { + for_each_enabled_engine(other, gt, tmp) { struct kthread_worker *worker; threads[tmp].resets = @@ -1185,7 +1185,7 @@ static int __igt_reset_engines(struct intel_gt *gt, } unwind: - for_each_engine(other, gt, tmp) { + for_each_enabled_engine(other, gt, tmp) { int ret; if (!threads[tmp].worker) @@ -1621,7 +1621,7 @@ static int wait_for_others(struct intel_gt *gt, struct intel_engine_cs *engine; enum intel_engine_id id; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { if (engine == exclude) continue; @@ -1649,7 +1649,7 @@ static int igt_reset_queue(void *arg) if (err) goto unlock; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_selftest_saved_policy saved; struct i915_request *prev; IGT_TIMEOUT(end_time); @@ -1982,7 +1982,7 @@ static int igt_reset_engines_atomic(void *arg) struct intel_engine_cs *engine; enum intel_engine_id id; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = igt_atomic_reset_engine(engine, p); if (err) goto out; diff --git a/drivers/gpu/drm/i915/gt/selftest_lrc.c b/drivers/gpu/drm/i915/gt/selftest_lrc.c index 23f04f6f8fba..8c18e3f11991 100644 --- a/drivers/gpu/drm/i915/gt/selftest_lrc.c +++ b/drivers/gpu/drm/i915/gt/selftest_lrc.c @@ -172,7 +172,7 @@ static int live_lrc_layout(void *arg) GEM_BUG_ON(offset_in_page(lrc)); err = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { u32 *hw; int dw; @@ -295,7 +295,7 @@ static int live_lrc_fixed(void *arg) * the context image. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { const struct { u32 reg; u32 offset; @@ -517,7 +517,7 @@ static int live_lrc_state(void *arg) if (IS_ERR(scratch)) return PTR_ERR(scratch); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = __live_lrc_state(engine, scratch); if (err) break; @@ -711,7 +711,7 @@ static int live_lrc_gpr(void *arg) if (IS_ERR(scratch)) return PTR_ERR(scratch); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { st_engine_heartbeat_disable(engine); err = __live_lrc_gpr(engine, scratch, false); @@ -876,7 +876,7 @@ static int live_lrc_timestamp(void *arg) * with a second request (carrying more poison into the timestamp). */ - for_each_engine(data.engine, gt, id) { + for_each_enabled_engine(data.engine, gt, id) { int i, err = 0; st_engine_heartbeat_disable(data.engine); @@ -1534,7 +1534,7 @@ static int live_lrc_isolation(void *arg) * context image and attempt to modify that list from a remote context. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { int i; /* Just don't even ask */ @@ -1722,7 +1722,7 @@ static int lrc_wabb_ctx(void *arg, bool per_ctx) enum intel_engine_id id; int err = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { intel_engine_pm_get(engine); err = __lrc_wabb_ctx(engine, per_ctx); intel_engine_pm_put(engine); @@ -1858,7 +1858,7 @@ static int live_lrc_garbage(void *arg) if (!IS_ENABLED(CONFIG_DRM_I915_SELFTEST_BROKEN)) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { I915_RND_STATE(prng); int err = 0, i; @@ -1960,7 +1960,7 @@ static int live_pphwsp_runtime(void *arg) * is monotonic. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = __live_pphwsp_runtime(engine); if (err) break; diff --git a/drivers/gpu/drm/i915/gt/selftest_mocs.c b/drivers/gpu/drm/i915/gt/selftest_mocs.c index d73e438fb85f..6fd9fb0cd9f6 100644 --- a/drivers/gpu/drm/i915/gt/selftest_mocs.c +++ b/drivers/gpu/drm/i915/gt/selftest_mocs.c @@ -271,7 +271,7 @@ static int live_mocs_kernel(void *arg) if (err) return err; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { intel_engine_pm_get(engine); err = check_mocs_engine(&mocs, engine->kernel_context); intel_engine_pm_put(engine); @@ -297,7 +297,7 @@ static int live_mocs_clean(void *arg) if (err) return err; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; ce = mocs_context_create(engine); @@ -400,7 +400,7 @@ static int live_mocs_reset(void *arg) return err; igt_global_reset_lock(gt); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { bool using_guc = intel_engine_uses_guc(engine); struct intel_selftest_saved_policy saved; struct intel_context *ce; diff --git a/drivers/gpu/drm/i915/gt/selftest_rc6.c b/drivers/gpu/drm/i915/gt/selftest_rc6.c index 99de5d85a096..805942864100 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rc6.c +++ b/drivers/gpu/drm/i915/gt/selftest_rc6.c @@ -177,7 +177,7 @@ randomised_engines(struct intel_gt *gt, int n; n = 0; - for_each_engine(engine, gt, id) + for_each_enabled_engine(engine, gt, id) n++; if (!n) return NULL; @@ -187,7 +187,7 @@ randomised_engines(struct intel_gt *gt, return NULL; n = 0; - for_each_engine(engine, gt, id) + for_each_enabled_engine(engine, gt, id) engines[n++] = engine; i915_prandom_shuffle(engines, sizeof(*engines), n, prng); diff --git a/drivers/gpu/drm/i915/gt/selftest_reset.c b/drivers/gpu/drm/i915/gt/selftest_reset.c index 2cfc23c58e90..548e00ec47bd 100644 --- a/drivers/gpu/drm/i915/gt/selftest_reset.c +++ b/drivers/gpu/drm/i915/gt/selftest_reset.c @@ -55,7 +55,7 @@ __igt_reset_stolen(struct intel_gt *gt, if (err) goto err_lock; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; struct i915_request *rq; @@ -113,7 +113,7 @@ __igt_reset_stolen(struct intel_gt *gt, if (mask == ALL_ENGINES) { intel_gt_reset(gt, mask, NULL); } else { - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { if (mask & engine->mask) intel_engine_reset(engine, NULL); } @@ -197,7 +197,7 @@ static int igt_reset_engines_stolen(void *arg) if (!intel_has_reset_engine(gt)) return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { err = __igt_reset_stolen(gt, engine->mask, engine->name); if (err) return err; @@ -326,7 +326,7 @@ static int igt_atomic_engine_reset(void *arg) if (!igt_force_reset(gt)) goto out_unlock; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct tasklet_struct *t = &engine->sched_engine->tasklet; if (t->func) diff --git a/drivers/gpu/drm/i915/gt/selftest_ring_submission.c b/drivers/gpu/drm/i915/gt/selftest_ring_submission.c index 87ceb0f374b6..a447fec027e1 100644 --- a/drivers/gpu/drm/i915/gt/selftest_ring_submission.c +++ b/drivers/gpu/drm/i915/gt/selftest_ring_submission.c @@ -259,7 +259,7 @@ static int live_ctx_switch_wa(void *arg) * and equally important it was wasn't run when we don't! */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_vma *saved_wa; int err; diff --git a/drivers/gpu/drm/i915/gt/selftest_rps.c b/drivers/gpu/drm/i915/gt/selftest_rps.c index 73bc91c6ea07..d77a95acb400 100644 --- a/drivers/gpu/drm/i915/gt/selftest_rps.c +++ b/drivers/gpu/drm/i915/gt/selftest_rps.c @@ -242,7 +242,7 @@ int live_rps_clock_interval(void *arg) intel_gt_check_clock_frequency(gt); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; u32 cycles; u64 dt; @@ -401,7 +401,7 @@ int live_rps_control(void *arg) rps->work.func = dummy_rps_work; wakeref = intel_gt_pm_get(gt); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; ktime_t min_dt, max_dt; int f, limit; @@ -630,7 +630,7 @@ int live_rps_frequency_cs(void *arg) saved_work = rps->work.func; rps->work.func = dummy_rps_work; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; struct i915_vma *vma; u32 *cancel, *cntr; @@ -769,7 +769,7 @@ int live_rps_frequency_srm(void *arg) saved_work = rps->work.func; rps->work.func = dummy_rps_work; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; struct i915_vma *vma; u32 *cancel, *cntr; @@ -1052,7 +1052,7 @@ int live_rps_interrupt(void *arg) saved_work = rps->work.func; rps->work.func = dummy_rps_work; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { /* Keep the engine busy with a spinner; expect an UP! */ if (pm_events & GEN6_PM_RP_UP_THRESHOLD) { intel_gt_pm_wait_for_idle(engine->gt); @@ -1159,7 +1159,7 @@ int live_rps_power(void *arg) saved_work = rps->work.func; rps->work.func = dummy_rps_work; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; struct { u64 power; @@ -1261,7 +1261,7 @@ int live_rps_dynamic(void *arg) if (intel_rps_uses_timer(rps)) pr_info("RPS has timer support\n"); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq; struct { ktime_t dt; diff --git a/drivers/gpu/drm/i915/gt/selftest_timeline.c b/drivers/gpu/drm/i915/gt/selftest_timeline.c index fa36cf920bde..47d6f02808ba 100644 --- a/drivers/gpu/drm/i915/gt/selftest_timeline.c +++ b/drivers/gpu/drm/i915/gt/selftest_timeline.c @@ -543,7 +543,7 @@ static int live_hwsp_engine(void *arg) return -ENOMEM; count = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { if (!intel_engine_can_store_dword(engine)) continue; @@ -619,7 +619,7 @@ static int live_hwsp_alternate(void *arg) count = 0; for (n = 0; n < NUM_TIMELINES; n++) { - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_timeline *tl; struct i915_request *rq; @@ -691,7 +691,7 @@ static int live_hwsp_wrap(void *arg) if (err) goto out_free; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { const u32 *hwsp_seqno[2]; struct i915_request *rq; u32 seqno[2]; @@ -1016,7 +1016,7 @@ static int live_hwsp_read(void *arg) goto out; } - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; unsigned long count = 0; IGT_TIMEOUT(end_time); @@ -1188,7 +1188,7 @@ static int live_hwsp_rollover_kernel(void *arg) * see a seqno rollover. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce = engine->kernel_context; struct intel_timeline *tl = ce->timeline; struct i915_request *rq[3] = {}; @@ -1266,7 +1266,7 @@ static int live_hwsp_rollover_user(void *arg) * on the user's timeline. */ - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_request *rq[3] = {}; struct intel_timeline *tl; struct intel_context *ce; @@ -1357,7 +1357,7 @@ static int live_hwsp_recycle(void *arg) */ count = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { IGT_TIMEOUT(end_time); if (!intel_engine_can_store_dword(engine)) diff --git a/drivers/gpu/drm/i915/gt/selftest_tlb.c b/drivers/gpu/drm/i915/gt/selftest_tlb.c index 69ed946a39e5..12526d17177f 100644 --- a/drivers/gpu/drm/i915/gt/selftest_tlb.c +++ b/drivers/gpu/drm/i915/gt/selftest_tlb.c @@ -293,7 +293,7 @@ mem_tlbinv(struct intel_gt *gt, } err = 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_gem_ww_ctx ww; struct intel_context *ce; int bit; diff --git a/drivers/gpu/drm/i915/gt/selftest_workarounds.c b/drivers/gpu/drm/i915/gt/selftest_workarounds.c index 14a8b25b6204..55f9f5c556c3 100644 --- a/drivers/gpu/drm/i915/gt/selftest_workarounds.c +++ b/drivers/gpu/drm/i915/gt/selftest_workarounds.c @@ -70,7 +70,7 @@ reference_lists_init(struct intel_gt *gt, struct wa_lists *lists) gt_init_workarounds(gt, &lists->gt_wa_list); wa_init_finish(&lists->gt_wa_list); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct i915_wa_list *wal = &lists->engine[id].wa_list; wa_init_start(wal, gt, "REF", engine->name); @@ -89,7 +89,7 @@ reference_lists_fini(struct intel_gt *gt, struct wa_lists *lists) struct intel_engine_cs *engine; enum intel_engine_id id; - for_each_engine(engine, gt, id) + for_each_enabled_engine(engine, gt, id) intel_wa_list_free(&lists->engine[id].wa_list); intel_wa_list_free(&lists->gt_wa_list); @@ -764,7 +764,7 @@ static int live_dirty_whitelist(void *arg) if (GRAPHICS_VER(gt->i915) < 7) /* minimum requirement for LRI, SRM, LRM */ return 0; - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; int err; @@ -794,7 +794,7 @@ static int live_reset_whitelist(void *arg) /* If we reset the gpu, we should not lose the RING_NONPRIV */ igt_global_reset_lock(gt); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { if (engine->whitelist.count == 0) continue; @@ -1089,7 +1089,7 @@ static int live_isolated_whitelist(void *arg) } } - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce[2]; if (!engine->kernel_context->vm) @@ -1172,7 +1172,7 @@ verify_wa_lists(struct intel_gt *gt, struct wa_lists *lists, ok &= wa_list_verify(gt, &lists->gt_wa_list, str); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_context *ce; ce = intel_context_create(engine); @@ -1257,7 +1257,7 @@ live_engine_reset_workarounds(void *arg) reference_lists_init(gt, lists); - for_each_engine(engine, gt, id) { + for_each_enabled_engine(engine, gt, id) { struct intel_selftest_saved_policy saved; bool using_guc = intel_engine_uses_guc(engine); bool ok; From patchwork Mon Mar 24 13:29:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027327 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 D69E7C3600C for ; Mon, 24 Mar 2025 13:31:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4643C10E407; Mon, 24 Mar 2025 13:31:09 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="EqelBRNy"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A46310E401; Mon, 24 Mar 2025 13:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823068; x=1774359068; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JQLpubuA/Xc4YFAb6kRQlIkOagPzvUMOtL3/QfRI6YU=; b=EqelBRNyXEXyL5KeUmITmsoM40O79PGtbIPkQ+4Z0Cw/Fd+FyUq0qYLD CNE4p2aCP/YuxEHzRXSN0keyycP12xECXpQ7IZOppNO3BfTnrgwPsP8oi mFHWszMhqbHFpFYA62w4HYTgbltun89AU0ZoJzJtFsoUtWA4KvXttPIdo Uw6JKyLkpSNDZ/lchQIFCD5dBNxeUriyidsgfLDASQNdPaAH46Zu1ZEL+ +pHZFD3szYpEHpCvOVf4itnvqWFxKy3QV6KZl1fUJoOOxXz9RG79n6sPx lLGUYpS2Ysw3AMEimguw71Khshbo56uD6XrVvk8ifAtQWuhScxB6s5yPk A==; X-CSE-ConnectionGUID: lqVj20yjTkaZqBLlZTM2yw== X-CSE-MsgGUID: v27H2rkeQAuxeMxDLR8CwA== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="44134028" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="44134028" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:08 -0700 X-CSE-ConnectionGUID: mUM/HjmjTQyXFsvBs7ksZA== X-CSE-MsgGUID: +451tkBFTXyAKJ3KlTXLCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="124209282" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:03 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 07/15] drm/i915/gt: Manage CCS engine creation within UABI exposure Date: Mon, 24 Mar 2025 14:29:43 +0100 Message-ID: <20250324132952.1075209-8-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" In commit ea315f98e5d6 ("drm/i915/gt: Do not generate the command streamer for all the CCS"), we restricted the creation of physical CCS engines to only one stream. This allowed the user to submit a single compute workload, with all CCS slices sharing the workload from that stream. This patch removes that limitation but still exposes only one stream to the user. The physical memory for each engine remains allocated but unused, however the user will only see one engine exposed. Do this by adding only one engine to the UABI list, ensuring that only one engine is visible to the user. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_engine_cs.c | 23 --------------------- drivers/gpu/drm/i915/gt/intel_engine_user.c | 17 ++++++++++++--- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/drivers/gpu/drm/i915/gt/intel_engine_cs.c index b721bbd23356..d2e2461e09d1 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c @@ -875,29 +875,6 @@ static intel_engine_mask_t init_engine_mask(struct intel_gt *gt) info->engine_mask &= ~BIT(GSC0); } - /* - * Do not create the command streamer for CCS slices beyond the first. - * All the workload submitted to the first engine will be shared among - * all the slices. - * - * Once the user will be allowed to customize the CCS mode, then this - * check needs to be removed. - */ - if (IS_DG2(gt->i915)) { - u8 first_ccs = __ffs(CCS_MASK(gt)); - - /* - * Store the number of active cslices before - * changing the CCS engine configuration - */ - gt->ccs.cslices = CCS_MASK(gt); - - /* Mask off all the CCS engine */ - info->engine_mask &= ~GENMASK(CCS3, CCS0); - /* Put back in the first CCS engine */ - info->engine_mask |= BIT(_CCS(first_ccs)); - } - return info->engine_mask; } diff --git a/drivers/gpu/drm/i915/gt/intel_engine_user.c b/drivers/gpu/drm/i915/gt/intel_engine_user.c index cd7662b1ad59..8e5284af8335 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_user.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_user.c @@ -246,6 +246,20 @@ void intel_engines_driver_register(struct drm_i915_private *i915) GEM_BUG_ON(uabi_class >= ARRAY_SIZE(i915->engine_uabi_class_count)); + + /* Fix up the mapping to match default execbuf::user_map[] */ + add_legacy_ring(&ring, engine); + + /* + * Do not create the command streamer for CCS slices beyond the + * first. All the workload submitted to the first engine will be + * shared among all the slices. + */ + if (IS_DG2(i915) && + uabi_class == I915_ENGINE_CLASS_COMPUTE && + engine->uabi_instance) + goto clear_node_continue; + i915->engine_uabi_class_count[uabi_class]++; rb_link_node(&engine->uabi_node, prev, p); @@ -255,9 +269,6 @@ void intel_engines_driver_register(struct drm_i915_private *i915) engine->uabi_class, engine->uabi_instance) != engine); - /* Fix up the mapping to match default execbuf::user_map[] */ - add_legacy_ring(&ring, engine); - prev = &engine->uabi_node; p = &prev->rb_right; From patchwork Mon Mar 24 13:29:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027328 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 7B2C0C3600B for ; Mon, 24 Mar 2025 13:31:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC91E10E405; Mon, 24 Mar 2025 13:31:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="SVX+3UkJ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 38EB910E405; Mon, 24 Mar 2025 13:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823075; x=1774359075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ec4keQkax8q652yYyRWcqB084B5FwldDIKKQW0gvYXc=; b=SVX+3UkJHlrsptGyFCv+FR61vXypnb0ZNhI+e0Fq9AfdjCjZpFxg4jYa w4DdZYylE5rwB333BnvlWCFtslha2CVfYOTmjPhTJeSAjPEcnzHdSmaTV TpXLsjlH0k7v+oBpXK+DSvg71guuncRWwQXrJ9Siv0nN9AkFpGmGqIwh7 toy0Ai7dSi5WYmMHDXk4MyG2hqe1Ye3Qt6tCGN61hKcDGfhMGzdGY58+P NjvnZEDTzOnrtfqvwNFeg83cULcBPLvtkuF8Nh0MYqEFFC00DiQZPiggh 2g5P4JsAATiOaNuhPSw6+W9c/5Op5Jve430HJhv/Tas5AH97VzuMwVKSo w==; X-CSE-ConnectionGUID: TVseiJblTHmR/nNZ+aTv7w== X-CSE-MsgGUID: Su1w+tIoQ8GUtZcyt0HuDA== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="55024697" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="55024697" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:15 -0700 X-CSE-ConnectionGUID: n9X/B3GjRBqflKxyrwws2A== X-CSE-MsgGUID: L+Orx1lzTcmxFa/AK+6V2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="155060061" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:11 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 08/15] drm/i915/gt: Remove cslices mask value from the CCS structure Date: Mon, 24 Mar 2025 14:29:44 +0100 Message-ID: <20250324132952.1075209-9-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Following the decision to manage CCS engine creation within UABI engines, the "cslices" variable in the "ccs" structure in the "gt" is no longer needed. Remove it is now redundant. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 2 +- drivers/gpu/drm/i915/gt/intel_gt_types.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index a6c33b471567..fc8a23fc28b6 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -9,7 +9,7 @@ static void intel_gt_apply_ccs_mode(struct intel_gt *gt) { - unsigned long cslices_mask = gt->ccs.cslices; + unsigned long cslices_mask = CCS_MASK(gt); u32 mode_val = 0; /* CCS engine id, i.e. the engines position in the engine's bitmask */ int engine; diff --git a/drivers/gpu/drm/i915/gt/intel_gt_types.h b/drivers/gpu/drm/i915/gt/intel_gt_types.h index 9e257f34d05b..71e43071da0b 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_types.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_types.h @@ -218,11 +218,6 @@ struct intel_gt { * i.e. how the CCS streams are distributed amongs the slices. */ struct { - /* - * Mask of the non fused CCS slices - * to be used for the load balancing - */ - intel_engine_mask_t cslices; u32 mode_reg_val; } ccs; From patchwork Mon Mar 24 13:29:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027329 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 6BD28C3600C for ; Mon, 24 Mar 2025 13:31:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF54110E40B; Mon, 24 Mar 2025 13:31:22 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="emVZDmYe"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7DEBB10E408; Mon, 24 Mar 2025 13:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823081; x=1774359081; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P6obomOq1G54LndOsjqHUJjRv+uJYxQbnF88ybgHZm4=; b=emVZDmYedn7IV/n6T8dUSDS5OrTwXNimhvNkyRODgCad2XcBZ//CwShy ehu9g9zZqG93N9t9is2lMCHJhvmAi5zCcwbT/qvstDai+1lmZrAFFKlhv 87BnltOEWuwxpCQKJCL9PY7XTPEacLD4My2W3VbPuTWsK5NdlNbe68d/o 6SwwkyeiXdKoe5d1Vfxb17ppDYr5ru8AD68lIvLx3IfH8a+vhiew7dy9m oIifj97MAZ1wpII8FiGyqG3YQ3NSxTsAOocrDBE2f8yKTy7Mp9f79pNz0 t90Qw8GflcJQfd4HMv7e8kKng84aHydYezBomwmFe5x+GFElZ9WdwTu07 g==; X-CSE-ConnectionGUID: SZoOqmuPQsqCCtBCQZuQxg== X-CSE-MsgGUID: TCyOQW3GSJeA+b0lB/oX6Q== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="55024708" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="55024708" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:21 -0700 X-CSE-ConnectionGUID: rwpgbpgLSAWZQIHeD0aBPA== X-CSE-MsgGUID: /9OC9LZWSvyLWK0RubOLkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="155060079" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:17 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 09/15] drm/i915/gt: Expose the number of total CCS slices Date: Mon, 24 Mar 2025 14:29:45 +0100 Message-ID: <20250324132952.1075209-10-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Implement a sysfs interface to show the number of available CCS slices. The displayed number does not take into account the CCS balancing mode. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 21 +++++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h | 1 + drivers/gpu/drm/i915/gt/intel_gt_sysfs.c | 2 ++ 3 files changed, 24 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index fc8a23fc28b6..edb6a4b63826 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -5,7 +5,9 @@ #include "i915_drv.h" #include "intel_gt_ccs_mode.h" +#include "intel_gt_print.h" #include "intel_gt_regs.h" +#include "intel_gt_sysfs.h" static void intel_gt_apply_ccs_mode(struct intel_gt *gt) { @@ -100,3 +102,22 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt) /* Initialize the CCS mode setting */ intel_gt_apply_ccs_mode(gt); } + +static ssize_t num_cslices_show(struct device *dev, + struct device_attribute *attr, + char *buff) +{ + struct intel_gt *gt = kobj_to_gt(&dev->kobj); + u32 num_slices; + + num_slices = hweight32(CCS_MASK(gt)); + + return sysfs_emit(buff, "%u\n", num_slices); +} +static DEVICE_ATTR_RO(num_cslices); + +void intel_gt_sysfs_ccs_init(struct intel_gt *gt) +{ + if (sysfs_create_file(>->sysfs_gt, &dev_attr_num_cslices.attr)) + gt_warn(gt, "Failed to create sysfs num_cslices files\n"); +} diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h index 4a6763b95a78..9696cc9017f6 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.h @@ -9,5 +9,6 @@ #include "intel_gt.h" void intel_gt_ccs_mode_init(struct intel_gt *gt); +void intel_gt_sysfs_ccs_init(struct intel_gt *gt); #endif /* __INTEL_GT_CCS_MODE_H__ */ diff --git a/drivers/gpu/drm/i915/gt/intel_gt_sysfs.c b/drivers/gpu/drm/i915/gt/intel_gt_sysfs.c index 33cba406b569..895eedc402ae 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_sysfs.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_sysfs.c @@ -12,6 +12,7 @@ #include "i915_drv.h" #include "i915_sysfs.h" #include "intel_gt.h" +#include "intel_gt_ccs_mode.h" #include "intel_gt_print.h" #include "intel_gt_sysfs.h" #include "intel_gt_sysfs_pm.h" @@ -101,6 +102,7 @@ void intel_gt_sysfs_register(struct intel_gt *gt) goto exit_fail; intel_gt_sysfs_pm_init(gt, >->sysfs_gt); + intel_gt_sysfs_ccs_init(gt); return; From patchwork Mon Mar 24 13:29:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027330 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 336ECC3600B for ; Mon, 24 Mar 2025 13:31:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A153310E401; Mon, 24 Mar 2025 13:31:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="J6755M92"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9D55110E401; Mon, 24 Mar 2025 13:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823088; x=1774359088; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5dZ7i6KdiiglMR3Z15YUXNXvlJx0fpT6bB4NJxyP8hc=; b=J6755M92DPMWVcZJ8dKGHxdIxEFbq8jLB+LGJZBweixCpR3d+VPJsvCl Rpeyzcblf1SbmHtisemCodo6hI+sBT5U3qHQgyt3l/RcmftboVrvOmKmr Ho3/M4G9xqNxqcnUES/9h0Hc+ONuEcTm/jgKdzbTX4i9OjyuWOR+oyhR5 u/NR1DEGKJLtJzZqR/Z9/IEfrPJ5lS9GCCmwYrgeyVuuFg8icdCc1G/Hv oTUL6NrZWcRplgPiME3Yy1EYa0oSTxcORn5oWg9+EgiKNkO3X4Msa8q61 fzUuCiN/q6Cd0GXMfKALW14n/HHQf0OSmY5Zt+PzwXXTHzkdD2N6nRYA/ Q==; X-CSE-ConnectionGUID: Nn7JFTYZRUemA0oNNaDUag== X-CSE-MsgGUID: +wXerguBRwmqR/SKkb3OLg== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="55024724" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="55024724" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:27 -0700 X-CSE-ConnectionGUID: OGo991j7TcSNaQLJHUwMkA== X-CSE-MsgGUID: 6iE5unEZTVWgoi/NWRltug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="155060104" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:23 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 10/15] drm/i915/gt: Store engine-related sysfs kobjects Date: Mon, 24 Mar 2025 14:29:46 +0100 Message-ID: <20250324132952.1075209-11-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Upcoming commits will need to access engine-related kobjects to enable the creation and destruction of sysfs interfaces at runtime. For this, store the "engine" directory (i915->sysfs_engine), the engine files (gt->kobj), and the default data (gt->kobj_defaults). Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_engine_types.h | 2 ++ drivers/gpu/drm/i915/gt/sysfs_engines.c | 4 ++++ drivers/gpu/drm/i915/i915_drv.h | 1 + 3 files changed, 7 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_engine_types.h b/drivers/gpu/drm/i915/gt/intel_engine_types.h index 155b6255a63e..be8f1eb77b29 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_types.h +++ b/drivers/gpu/drm/i915/gt/intel_engine_types.h @@ -393,6 +393,8 @@ struct intel_engine_cs { u32 context_size; u32 mmio_base; + struct kobject *kobj; + struct intel_engine_tlb_inv tlb_inv; /* diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c index aab2759067d2..f70f0a2983f1 100644 --- a/drivers/gpu/drm/i915/gt/sysfs_engines.c +++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c @@ -506,6 +506,8 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915) if (!dir) return; + i915->sysfs_engine = dir; + for_each_uabi_engine(engine, i915) { struct kobject *kobj; @@ -526,6 +528,8 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915) add_defaults(container_of(kobj, struct kobj_engine, base)); + engine->kobj = kobj; + if (0) { err_object: kobject_put(kobj); diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index ffc346379cc2..97806e44429c 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -319,6 +319,7 @@ struct drm_i915_private { struct intel_gt *gt[I915_MAX_GT]; struct kobject *sysfs_gt; + struct kobject *sysfs_engine; /* Quick lookup of media GT (current platforms only have one) */ struct intel_gt *media_gt; From patchwork Mon Mar 24 13:29:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027331 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 032C9C3600C for ; Mon, 24 Mar 2025 13:31:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 615BD10E40D; Mon, 24 Mar 2025 13:31:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="WtpKV+pq"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 560F810E40D; Mon, 24 Mar 2025 13:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823094; x=1774359094; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LSvA/nYeQYQDFfLKkSLmeL1x6jSmZ45+uQHxVbxVrZg=; b=WtpKV+pqB7yRXoFrDHPn5OOxLZVtNZLmNnTmFMu5jX//u19S6zKoU2su BSnP+w+jx4hAjNPakK5lVzXzllWoxBe+I0dnBEjCP2ECdpG/XnRNCkofc 28uLGwsRgWxu4z+0g9b9k+Rg/Ng6dKzxBcHOaDpYPAyKKfmFVtlSGWMQ2 TK8aiW8n65xuY+ZNerkYzuqgjLp5zpZTSevroB6STiTrX8AUh1+UA/WSv VzChDt+OkScU8/FuAFr6gkTPpZxAsDwhRGzgG99wzS8/eh6UTD9EAX9p/ zHRguH4EXjfADaux3FSvtdD1/gcv3wL83EHjmC3tIe8+zmkm9fdexHBOk w==; X-CSE-ConnectionGUID: GFZD3scKT9Sj9Bb2v5viJQ== X-CSE-MsgGUID: S6BJP5SCSMyJn7dPoDQIWQ== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="55024726" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="55024726" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:34 -0700 X-CSE-ConnectionGUID: 9AWnqDW/Rd2a76ZaRwjOUQ== X-CSE-MsgGUID: rY0IKRb5T9eYBcxhteUS6g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="155060126" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:30 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 11/15] drm/i915/gt: Store active CCS mask Date: Mon, 24 Mar 2025 14:29:47 +0100 Message-ID: <20250324132952.1075209-12-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" To support upcoming patches, we need to store the current mask for active CCS engines. Active engines refer to those exposed to userspace via the UABI engine list. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 41 +++++++++++++++++++-- drivers/gpu/drm/i915/gt/intel_gt_types.h | 7 ++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index edb6a4b63826..5eead7b18f57 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -12,6 +12,7 @@ static void intel_gt_apply_ccs_mode(struct intel_gt *gt) { unsigned long cslices_mask = CCS_MASK(gt); + unsigned long ccs_mask = gt->ccs.id_mask; u32 mode_val = 0; /* CCS engine id, i.e. the engines position in the engine's bitmask */ int engine; @@ -55,7 +56,7 @@ static void intel_gt_apply_ccs_mode(struct intel_gt *gt) * slice 2: ccs2 * slice 3: ccs3 */ - engine = __ffs(cslices_mask); + engine = __ffs(ccs_mask); for (cslice = 0; cslice < I915_MAX_CCS; cslice++) { if (!(cslices_mask & BIT(cslice))) { @@ -86,7 +87,7 @@ static void intel_gt_apply_ccs_mode(struct intel_gt *gt) * CCS mode, will be used later to * reset to a flexible value */ - engine = __ffs(cslices_mask); + engine = __ffs(ccs_mask); continue; } } @@ -94,13 +95,45 @@ static void intel_gt_apply_ccs_mode(struct intel_gt *gt) gt->ccs.mode_reg_val = mode_val; } +static void __update_ccs_mask(struct intel_gt *gt, u32 ccs_mode) +{ + unsigned long cslices_mask = CCS_MASK(gt); + int i; + + /* Mask off all the CCS engines */ + gt->ccs.id_mask = 0; + + for_each_set_bit(i, &cslices_mask, I915_MAX_CCS) { + gt->ccs.id_mask |= BIT(i); + + ccs_mode--; + if (!ccs_mode) + break; + } + + /* + * It's impossible for 'ccs_mode' to be zero at this point. + * This scenario would only occur if the 'ccs_mode' provided by + * the caller exceeded the total number of CCS engines, a condition + * we check before calling the 'update_ccs_mask()' function. + */ + GEM_BUG_ON(ccs_mode); + + /* Initialize the CCS mode setting */ + intel_gt_apply_ccs_mode(gt); +} + void intel_gt_ccs_mode_init(struct intel_gt *gt) { if (!IS_DG2(gt->i915)) return; - /* Initialize the CCS mode setting */ - intel_gt_apply_ccs_mode(gt); + /* + * Set CCS balance mode 1 in the ccs_mask. + * + * During init the workaround are not set up yet. + */ + __update_ccs_mask(gt, 1); } static ssize_t num_cslices_show(struct device *dev, diff --git a/drivers/gpu/drm/i915/gt/intel_gt_types.h b/drivers/gpu/drm/i915/gt/intel_gt_types.h index 71e43071da0b..641be69016e1 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_types.h +++ b/drivers/gpu/drm/i915/gt/intel_gt_types.h @@ -219,6 +219,13 @@ struct intel_gt { */ struct { u32 mode_reg_val; + + /* + * CCS id_mask is the command streamer instance + * exposed to the user. While the CCS_MASK(gt) + * is the available unfused compute slices. + */ + intel_engine_mask_t id_mask; } ccs; /* From patchwork Mon Mar 24 13:29:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027332 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 272B2C36002 for ; Mon, 24 Mar 2025 13:31:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8DD4810E414; Mon, 24 Mar 2025 13:31:42 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="LR6DTRO9"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 38A9610E414; Mon, 24 Mar 2025 13:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823101; x=1774359101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7cKHASeBoHHNkyDBIKSIt+yIk6xplt4fCE4ZNa/kqiU=; b=LR6DTRO9mS7ZZTCdpxQ6h6j8P9NHSFVW08ANztCyNXs1QowfsejvDpEk SwUjCaHjdTyjRaVZy5d0H+lhghj8C/nYXS0j9zR1E8ZW73YC0zaDKmkkD NiQHc+P6MoPIutffWHwg0UidHfsKz3OVd1QO28vv9cA4IoiWze1DRiWEh VXmComsaBM79XD5Fn/E816WGea124WWEs8UYwWMwkMQ21PSZ9qNrD2RGc ii8sYha6D1im4+VHKpnh9hz+7RO+jHK1JQRGrtAr+Q6bWO1Jr/agoH831 skBhmH/r3xNUmRBEc1bgvhZHvjNSEAq2tZxncNaCttvJJe6ppeU48OZp3 A==; X-CSE-ConnectionGUID: ysiYXK95TSWMD5pAQ+G6BA== X-CSE-MsgGUID: GJG8V2U1SNa3nrAQ6+HG6g== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="55024735" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="55024735" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:41 -0700 X-CSE-ConnectionGUID: I/FWvvwJQseDDTqyUnDjiw== X-CSE-MsgGUID: BJaLx1rJSB2NxANFYfuENg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="155060153" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:37 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 12/15] drm/i915: Protect access to the UABI engines list with a mutex Date: Mon, 24 Mar 2025 14:29:48 +0100 Message-ID: <20250324132952.1075209-13-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Until now, the UABI engines list has been accessed in read-only mode, as it was created once during boot and destroyed upon module unload. In upcoming commits, we will be modifying this list by changing the CCS mode, allowing compute engines to be dynamically added and removed at runtime based on user whims. To ensure thread safety and prevent race conditions, we need to protect the engine list with a mutex, thereby serializing access to it. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 3 +++ drivers/gpu/drm/i915/gt/intel_engine_user.c | 7 +++++++ drivers/gpu/drm/i915/gt/sysfs_engines.c | 5 +++++ drivers/gpu/drm/i915/i915_cmd_parser.c | 2 ++ drivers/gpu/drm/i915/i915_debugfs.c | 4 ++++ drivers/gpu/drm/i915/i915_drv.h | 4 ++++ drivers/gpu/drm/i915/i915_gem.c | 4 ++++ drivers/gpu/drm/i915/i915_perf.c | 8 +++++--- drivers/gpu/drm/i915/i915_pmu.c | 11 +++++++++-- drivers/gpu/drm/i915/i915_query.c | 21 ++++++++++++++++----- 10 files changed, 59 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index ab1af978911b..4263d3eb2557 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1124,6 +1124,7 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx, if (!e) return ERR_PTR(-ENOMEM); + mutex_lock(&ctx->i915->uabi_engines_mutex); for_each_uabi_engine(engine, ctx->i915) { struct intel_context *ce; struct intel_sseu sseu = {}; @@ -1155,9 +1156,11 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx, } + mutex_unlock(&ctx->i915->uabi_engines_mutex); return e; free_engines: + mutex_unlock(&ctx->i915->uabi_engines_mutex); free_engines(e); return err; } diff --git a/drivers/gpu/drm/i915/gt/intel_engine_user.c b/drivers/gpu/drm/i915/gt/intel_engine_user.c index 8e5284af8335..209d5badbd3d 100644 --- a/drivers/gpu/drm/i915/gt/intel_engine_user.c +++ b/drivers/gpu/drm/i915/gt/intel_engine_user.c @@ -210,6 +210,13 @@ void intel_engines_driver_register(struct drm_i915_private *i915) LIST_HEAD(engines); sort_engines(i915, &engines); + mutex_init(&i915->uabi_engines_mutex); + + /* + * We are still booting i915 and we are sure we are running + * single-threaded. We don't need at this point to protect the + * uabi_engines access list with the mutex. + */ prev = NULL; p = &i915->uabi_engines.rb_node; diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c index f70f0a2983f1..d3d3c67edf34 100644 --- a/drivers/gpu/drm/i915/gt/sysfs_engines.c +++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c @@ -508,6 +508,11 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915) i915->sysfs_engine = dir; + /* + * We are still booting i915 and we are sure we are running + * single-threaded. We don't need at this point to protect the + * uabi_engines access list with the mutex. + */ for_each_uabi_engine(engine, i915) { struct kobject *kobj; diff --git a/drivers/gpu/drm/i915/i915_cmd_parser.c b/drivers/gpu/drm/i915/i915_cmd_parser.c index 2905df83e180..12987ece6f8e 100644 --- a/drivers/gpu/drm/i915/i915_cmd_parser.c +++ b/drivers/gpu/drm/i915/i915_cmd_parser.c @@ -1592,12 +1592,14 @@ int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv) bool active = false; /* If the command parser is not enabled, report 0 - unsupported */ + mutex_lock(&dev_priv->uabi_engines_mutex); for_each_uabi_engine(engine, dev_priv) { if (intel_engine_using_cmd_parser(engine)) { active = true; break; } } + mutex_unlock(&dev_priv->uabi_engines_mutex); if (!active) return 0; diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index 0d9e263913ff..f2957435b529 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -451,8 +451,10 @@ static int i915_engine_info(struct seq_file *m, void *unused) to_gt(i915)->clock_period_ns); p = drm_seq_file_printer(m); + mutex_lock(&i915->uabi_engines_mutex); for_each_uabi_engine(engine, i915) intel_engine_dump(engine, &p, "%s\n", engine->name); + mutex_unlock(&i915->uabi_engines_mutex); intel_gt_show_timelines(to_gt(i915), &p, i915_request_show_with_schedule); @@ -466,6 +468,7 @@ static int i915_wa_registers(struct seq_file *m, void *unused) struct drm_i915_private *i915 = node_to_i915(m->private); struct intel_engine_cs *engine; + mutex_lock(&i915->uabi_engines_mutex); for_each_uabi_engine(engine, i915) { const struct i915_wa_list *wal = &engine->ctx_wa_list; const struct i915_wa *wa; @@ -485,6 +488,7 @@ static int i915_wa_registers(struct seq_file *m, void *unused) seq_printf(m, "\n"); } + mutex_unlock(&i915->uabi_engines_mutex); return 0; } diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 97806e44429c..fcfab2ad2908 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -223,6 +223,10 @@ struct drm_i915_private { struct rb_root uabi_engines; }; unsigned int engine_uabi_class_count[I915_LAST_UABI_ENGINE_CLASS + 1]; + /* + * Protect access to the uabi_engines list. + */ + struct mutex uabi_engines_mutex; /* protects the irq masks */ spinlock_t irq_lock; diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 8c8d43451f35..56b796c0e06b 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1261,7 +1261,11 @@ void i915_gem_driver_remove(struct drm_i915_private *dev_priv) i915_gem_suspend_late(dev_priv); for_each_gt(gt, dev_priv, i) intel_gt_driver_remove(gt); + + /* Let's make sure no one is using the uabi_engines list */ + mutex_lock(&dev_priv->uabi_engines_mutex); dev_priv->uabi_engines = RB_ROOT; + mutex_unlock(&dev_priv->uabi_engines_mutex); /* Flush any outstanding unpin_work. */ i915_gem_drain_workqueue(dev_priv); diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index bec164e884ae..7c8dc42a3623 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -2691,7 +2691,7 @@ oa_configure_all_contexts(struct i915_perf_stream *stream, struct intel_engine_cs *engine; struct intel_gt *gt = stream->engine->gt; struct i915_gem_context *ctx, *cn; - int err; + int err = 0; lockdep_assert_held(>->perf.lock); @@ -2735,6 +2735,7 @@ oa_configure_all_contexts(struct i915_perf_stream *stream, * If we don't modify the kernel_context, we do not get events while * idle. */ + mutex_lock(&i915->uabi_engines_mutex); for_each_uabi_engine(engine, i915) { struct intel_context *ce = engine->kernel_context; @@ -2745,10 +2746,11 @@ oa_configure_all_contexts(struct i915_perf_stream *stream, err = gen8_modify_self(ce, regs, num_regs, active); if (err) - return err; + break; } + mutex_unlock(&i915->uabi_engines_mutex); - return 0; + return err; } static int diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index 69a109d02116..047588aba524 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -1017,6 +1017,7 @@ create_event_attributes(struct i915_pmu *pmu) } } + mutex_lock(&i915->uabi_engines_mutex); for_each_uabi_engine(engine, i915) { for (i = 0; i < ARRAY_SIZE(engine_events); i++) { if (!engine_event_status(engine, @@ -1024,6 +1025,7 @@ create_event_attributes(struct i915_pmu *pmu) count++; } } + mutex_unlock(&i915->uabi_engines_mutex); /* Allocate attribute objects and table. */ i915_attr = kcalloc(count, sizeof(*i915_attr), GFP_KERNEL); @@ -1081,6 +1083,7 @@ create_event_attributes(struct i915_pmu *pmu) } /* Initialize supported engine counters. */ + mutex_lock(&i915->uabi_engines_mutex); for_each_uabi_engine(engine, i915) { for (i = 0; i < ARRAY_SIZE(engine_events); i++) { char *str; @@ -1092,7 +1095,7 @@ create_event_attributes(struct i915_pmu *pmu) str = kasprintf(GFP_KERNEL, "%s-%s", engine->name, engine_events[i].name); if (!str) - goto err; + goto err_unlock; *attr_iter++ = &i915_iter->attr.attr; i915_iter = @@ -1104,18 +1107,22 @@ create_event_attributes(struct i915_pmu *pmu) str = kasprintf(GFP_KERNEL, "%s-%s.unit", engine->name, engine_events[i].name); if (!str) - goto err; + goto err_unlock; *attr_iter++ = &pmu_iter->attr.attr; pmu_iter = add_pmu_attr(pmu_iter, str, "ns"); } } + mutex_unlock(&i915->uabi_engines_mutex); pmu->i915_attr = i915_attr; pmu->pmu_attr = pmu_attr; return attr; +err_unlock: + mutex_unlock(&i915->uabi_engines_mutex); + err:; for (attr_iter = attr; *attr_iter; attr_iter++) kfree((*attr_iter)->name); diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c index 14d9ec0ed777..7c6669cc4c96 100644 --- a/drivers/gpu/drm/i915/i915_query.c +++ b/drivers/gpu/drm/i915/i915_query.c @@ -140,6 +140,7 @@ query_engine_info(struct drm_i915_private *i915, if (query_item->flags) return -EINVAL; + mutex_lock(&i915->uabi_engines_mutex); for_each_uabi_engine(engine, i915) num_uabi_engines++; @@ -147,11 +148,13 @@ query_engine_info(struct drm_i915_private *i915, ret = copy_query_item(&query, sizeof(query), len, query_item); if (ret != 0) - return ret; + goto err; if (query.num_engines || query.rsvd[0] || query.rsvd[1] || - query.rsvd[2]) - return -EINVAL; + query.rsvd[2]) { + ret = -EINVAL; + goto err; + } info_ptr = &query_ptr->engines[0]; @@ -162,17 +165,25 @@ query_engine_info(struct drm_i915_private *i915, info.capabilities = engine->uabi_capabilities; info.logical_instance = ilog2(engine->logical_mask); - if (copy_to_user(info_ptr, &info, sizeof(info))) - return -EFAULT; + if (copy_to_user(info_ptr, &info, sizeof(info))) { + ret = -EFAULT; + goto err; + } query.num_engines++; info_ptr++; } + mutex_unlock(&i915->uabi_engines_mutex); if (copy_to_user(query_ptr, &query, sizeof(query))) return -EFAULT; return len; + +err: + mutex_unlock(&i915->uabi_engines_mutex); + + return ret; } static int can_copy_perf_config_registers_or_number(u32 user_n_regs, From patchwork Mon Mar 24 13:29:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027333 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 44F81C3600B for ; Mon, 24 Mar 2025 13:31:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AEBED10E418; Mon, 24 Mar 2025 13:31:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="G/67rIR6"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C91910E417; Mon, 24 Mar 2025 13:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823109; x=1774359109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oeLz/XchHAbw0hNN6fJDVTMPfBUgq6Y9ga9vEaBEsVs=; b=G/67rIR6Fhn7NEY6M/4NNS7vZ002Euv+z28eQHbRIovUayzPxniChht8 JIWxlS9691B0fQc3P1MrUc0WO8xLoTbwrJRn9Z5jVP2T3SY5MBS9e0d+j nu4H7wwBoVvZfv5B2RxaGfiSoLbKSu8j3kCANIB9TDZGMiChv8Y5Q/GK7 fkDtTKkm9B8SZM1cVMdBJB3t7QS46RgeJvt3EQAEK+N5BeA4vNGi603bS LLTFxjT3X9jyVy3bYnnltQ8CipjK+cGS3DovD9Vai6dEIix9SBz5Kg0X/ rV2067ZbJ+48Mnxi3GKfcohQFBRQXJ5bp3ixtAoxS9ynLGM8C9Txd/SAc Q==; X-CSE-ConnectionGUID: a2f3SlL/RAGytUstH2A3xw== X-CSE-MsgGUID: 4adrt1qFSeuxbOsaaX8bTA== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="66493452" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="66493452" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:48 -0700 X-CSE-ConnectionGUID: R9teW9FSRNukGDiQvkGV2w== X-CSE-MsgGUID: sjY5y0Y1SLq3jeE+0pwDiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="123847260" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:44 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 13/15] drm/i915/gt: Isolate single sysfs engine file creation Date: Mon, 24 Mar 2025 14:29:49 +0100 Message-ID: <20250324132952.1075209-14-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" In preparation for upcoming patches, we need the ability to create and remove individual sysfs files. To facilitate this, extract from the intel_engines_add_sysfs() function the creation of individual files. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/sysfs_engines.c | 75 ++++++++++++++++--------- drivers/gpu/drm/i915/gt/sysfs_engines.h | 2 + 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c index d3d3c67edf34..ef2eda72ac7f 100644 --- a/drivers/gpu/drm/i915/gt/sysfs_engines.c +++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c @@ -9,6 +9,7 @@ #include "i915_drv.h" #include "intel_engine.h" #include "intel_engine_heartbeat.h" +#include "intel_gt_print.h" #include "sysfs_engines.h" struct kobj_engine { @@ -481,7 +482,7 @@ static void add_defaults(struct kobj_engine *parent) return; } -void intel_engines_add_sysfs(struct drm_i915_private *i915) +int intel_engine_add_single_sysfs(struct intel_engine_cs *engine) { static const struct attribute * const files[] = { &name_attr.attr, @@ -497,7 +498,48 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915) #endif NULL }; + struct kobject *dir = engine->i915->sysfs_engine; + struct kobject *kobj = engine->kobj; + int err; + + kobj = kobj_engine(dir, engine); + if (!kobj) { + err = -EFAULT; + goto err_engine; + } + + err = sysfs_create_files(kobj, files); + if (err) + goto err_object; + + if (intel_engine_has_timeslices(engine)) { + err = sysfs_create_file(kobj, ×lice_duration_attr.attr); + if (err) + goto err_object; + } + if (intel_engine_has_preempt_reset(engine)) { + err = sysfs_create_file(kobj, &preempt_timeout_attr.attr); + if (err) + goto err_object; + } + + add_defaults(container_of(kobj, struct kobj_engine, base)); + + engine->kobj = kobj; + + return 0; + +err_object: + kobject_put(kobj); +err_engine: + gt_warn(engine->gt, "Failed to add sysfs engine '%s'\n", engine->name); + + return err; +} + +void intel_engines_add_sysfs(struct drm_i915_private *i915) +{ struct device *kdev = i915->drm.primary->kdev; struct intel_engine_cs *engine; struct kobject *dir; @@ -514,33 +556,10 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915) * uabi_engines access list with the mutex. */ for_each_uabi_engine(engine, i915) { - struct kobject *kobj; - - kobj = kobj_engine(dir, engine); - if (!kobj) - goto err_engine; - - if (sysfs_create_files(kobj, files)) - goto err_object; + int err; - if (intel_engine_has_timeslices(engine) && - sysfs_create_file(kobj, ×lice_duration_attr.attr)) - goto err_engine; - - if (intel_engine_has_preempt_reset(engine) && - sysfs_create_file(kobj, &preempt_timeout_attr.attr)) - goto err_engine; - - add_defaults(container_of(kobj, struct kobj_engine, base)); - - engine->kobj = kobj; - - if (0) { -err_object: - kobject_put(kobj); -err_engine: - dev_warn(kdev, "Failed to add sysfs engine '%s'\n", - engine->name); - } + err = intel_engine_add_single_sysfs(engine); + if (err) + break; } } diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.h b/drivers/gpu/drm/i915/gt/sysfs_engines.h index 9546fffe03a7..2e3ec2df14a9 100644 --- a/drivers/gpu/drm/i915/gt/sysfs_engines.h +++ b/drivers/gpu/drm/i915/gt/sysfs_engines.h @@ -7,7 +7,9 @@ #define INTEL_ENGINE_SYSFS_H struct drm_i915_private; +struct intel_engine_cs; void intel_engines_add_sysfs(struct drm_i915_private *i915); +int intel_engine_add_single_sysfs(struct intel_engine_cs *engine); #endif /* INTEL_ENGINE_SYSFS_H */ From patchwork Mon Mar 24 13:29:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027334 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 35B0AC3600C for ; Mon, 24 Mar 2025 13:31:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 97BA110E3FC; Mon, 24 Mar 2025 13:31:56 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="bbJxo6HZ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4ADCF10E3FC; Mon, 24 Mar 2025 13:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823115; x=1774359115; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/HZ8eHUvNEiY8vUppqka4NSpBBozp2cWl54+iDYTNw8=; b=bbJxo6HZHoTFiVWZS6z8CqzYXQhow+M55yc2Z3k6Yz5tqyKZYux6BTFp UbiHMpG+u3UD9KVjJXEfHKVum59BDQGRz7klfJRIzP38/NcDd5x7BCIBA WAVOnJDc1aZwuTrVkg25OI12GSw7UHfSD2jieo8O9A9WVL+qXoyD1WWM0 7wmMrR8DLResxR9AVL4TOGDVAX5A0I2WOZEXc2L7Qh5gbIltW+h/y3435 hYAbHBX0ixjsgrMgFJSxFJNs9NN6wNQ8ECiLgcqiPChGvFdoBzuufWRim Ky0CKv1x5h+MBdxPcGPE2OIwtaCd3ITCCH+DG8LaWeu5qN40Uk6BOAnX6 g==; X-CSE-ConnectionGUID: hE9Odj/rS0ettiwZr/7LIQ== X-CSE-MsgGUID: paGDQAnyS+2g8tktazNX8Q== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="66493462" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="66493462" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:55 -0700 X-CSE-ConnectionGUID: 1nz1nQRHTmWTlS3+N1fi4Q== X-CSE-MsgGUID: rtbJkxTZTg6yOmAF3/aTgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="123847272" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:51 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 14/15] drm/i915/gt: Implement creation and removal routines for CCS engines Date: Mon, 24 Mar 2025 14:29:50 +0100 Message-ID: <20250324132952.1075209-15-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" In preparation for upcoming patches, we need routines to dynamically create and destroy CCS engines based on the CCS mode that the user wants to set. The process begins by calculating the engine mask for the engines that need to be added or removed. We then update the UABI list of exposed engines and create or destroy the corresponding sysfs interfaces accordingly. These functions are not yet in use, so no functional changes are intended at this stage. Mark the functions 'add_uabi_ccs_engines()' and 'remove_uabi_ccs_engines()' as '__maybe_unused' to ensure successful compilation and maintain bisectability. This annotation will be removed in subsequent commits. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 128 ++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index 5eead7b18f57..cbabeb503d3b 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -4,10 +4,12 @@ */ #include "i915_drv.h" +#include "intel_engine_user.h" #include "intel_gt_ccs_mode.h" #include "intel_gt_print.h" #include "intel_gt_regs.h" #include "intel_gt_sysfs.h" +#include "sysfs_engines.h" static void intel_gt_apply_ccs_mode(struct intel_gt *gt) { @@ -123,6 +125,29 @@ static void __update_ccs_mask(struct intel_gt *gt, u32 ccs_mode) intel_gt_apply_ccs_mode(gt); } +static void update_ccs_mask(struct intel_gt *gt, u32 ccs_mode) +{ + struct intel_engine_cs *engine; + intel_engine_mask_t tmp; + + __update_ccs_mask(gt, ccs_mode); + + /* Update workaround values */ + for_each_engine_masked(engine, gt, gt->ccs.id_mask, tmp) { + struct i915_wa_list *wal = &engine->wa_list; + struct i915_wa *wa; + int i; + + for (i = 0, wa = wal->list; i < wal->count; i++, wa++) { + if (!i915_mmio_reg_equal(wa->reg, XEHP_CCS_MODE)) + continue; + + wa->set = gt->ccs.mode_reg_val; + wa->read = gt->ccs.mode_reg_val; + } + } +} + void intel_gt_ccs_mode_init(struct intel_gt *gt) { if (!IS_DG2(gt->i915)) @@ -136,6 +161,109 @@ void intel_gt_ccs_mode_init(struct intel_gt *gt) __update_ccs_mask(gt, 1); } +static int rb_engine_cmp(struct rb_node *rb_new, const struct rb_node *rb_old) +{ + struct intel_engine_cs *new = rb_to_uabi_engine(rb_new); + struct intel_engine_cs *old = rb_to_uabi_engine(rb_old); + + if (new->uabi_class - old->uabi_class == 0) + return new->uabi_instance - old->uabi_instance; + + return new->uabi_class - old->uabi_class; +} + +static void __maybe_unused add_uabi_ccs_engines(struct intel_gt *gt, u32 ccs_mode) +{ + struct drm_i915_private *i915 = gt->i915; + intel_engine_mask_t new_ccs_mask, tmp; + struct intel_engine_cs *e; + + /* Store the current ccs mask */ + new_ccs_mask = gt->ccs.id_mask; + update_ccs_mask(gt, ccs_mode); + + /* + * Store only the mask of the CCS engines that need to be added by + * removing from the new mask the engines that are already active + */ + new_ccs_mask = gt->ccs.id_mask & ~new_ccs_mask; + new_ccs_mask <<= CCS0; + + mutex_lock(&i915->uabi_engines_mutex); + for_each_engine_masked(e, gt, new_ccs_mask, tmp) { + int err; + struct rb_node *n; + struct intel_engine_cs *__e; + + i915->engine_uabi_class_count[I915_ENGINE_CLASS_COMPUTE]++; + + /* + * The engine is now inserted and marked as valid. + * + * rb_find_add() should always return NULL. If it returns a + * pointer to an rb_node it means that it found the engine we + * are trying to insert which means that something is really + * wrong. + */ + n = rb_find_add(&e->uabi_node, + &i915->uabi_engines, rb_engine_cmp); + GEM_BUG_ON(n); + + /* We inserted the engine, let's check if now we can find it */ + __e = intel_engine_lookup_user(i915, e->uabi_class, + e->uabi_instance) != e; + GEM_BUG_ON(__e != e); + + /* + * If the engine has never been used before (e.g. we are moving + * for the first time from CCS mode 1 to CCS mode 2 or 4), then + * also its sysfs entry has never been created. In this case its + * value will be null and we need to allocate it. + */ + if (!e->kobj) + err = intel_engine_add_single_sysfs(e); + else + err = kobject_add(e->kobj, + i915->sysfs_engine, "%s", e->name); + + if (err) + gt_warn(gt, + "Unable to create sysfs entries for %s engine", + e->name); + } + mutex_unlock(&i915->uabi_engines_mutex); +} + +static void __maybe_unused remove_uabi_ccs_engines(struct intel_gt *gt, u8 ccs_mode) +{ + struct drm_i915_private *i915 = gt->i915; + intel_engine_mask_t new_ccs_mask, tmp; + struct intel_engine_cs *e; + + /* Store the current ccs mask */ + new_ccs_mask = gt->ccs.id_mask; + update_ccs_mask(gt, ccs_mode); + + /* + * Store only the mask of the CCS engines that need to be removed by + * unmasking them from the new mask the engines that are already active + */ + new_ccs_mask = new_ccs_mask & ~gt->ccs.id_mask; + new_ccs_mask <<= CCS0; + + mutex_lock(&i915->uabi_engines_mutex); + for_each_engine_masked(e, gt, new_ccs_mask, tmp) { + i915->engine_uabi_class_count[I915_ENGINE_CLASS_COMPUTE]--; + + rb_erase(&e->uabi_node, &i915->uabi_engines); + RB_CLEAR_NODE(&e->uabi_node); + + /* Remove sysfs entries */ + kobject_del(e->kobj); + } + mutex_unlock(&i915->uabi_engines_mutex); +} + static ssize_t num_cslices_show(struct device *dev, struct device_attribute *attr, char *buff) From patchwork Mon Mar 24 13:29:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Shyti X-Patchwork-Id: 14027335 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 09A9EC36002 for ; Mon, 24 Mar 2025 13:32:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 71F2210E40E; Mon, 24 Mar 2025 13:32:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="lLpDr9p6"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7FD8D10E40E; Mon, 24 Mar 2025 13:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1742823122; x=1774359122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=92l6FArlYG7KWJ7HEUNaMMrZ2E5B106tBpHBnZs79uU=; b=lLpDr9p6FNHczF1v0BlGzW9DlbTPYwGuo5oR2C5gaEFyt5CXXV0kEs3o E/MQuCXEkJnEC2X8f1N2V6kbiHgb84MfupKPypIDDGJS/QWu+On04uSJR bkUxN+cmWHpA2GDjHOFGEZyJEE//IIyisXSLHA5sgijunDfkYf1zMUaLc uEHP9v6Hzzwr1eOpnFD3RqFkV8FEiwamQgsEE3z4rjnZ6TBntKagaCg5E DNmUwnLk+x24V3GJcMS8rQsSecokIQHcViEPLS+fx77W6EGuwZyijr4en gCnrL6Hj3Fypx6so08IrXf74o9GdVv6svifizyrP0Svk654BGwTMCMR3E w==; X-CSE-ConnectionGUID: 93+RGvJKSiin4YeDmLn+Hg== X-CSE-MsgGUID: MXog9HOARhqghltVHZG6hQ== X-IronPort-AV: E=McAfee;i="6700,10204,11383"; a="66493475" X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="66493475" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:32:01 -0700 X-CSE-ConnectionGUID: D0UQ/YLqSCuLac1K6jBGEQ== X-CSE-MsgGUID: Jfb1NZdxRvWy1VN2i7580A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,272,1736841600"; d="scan'208";a="123847292" Received: from slindbla-desk.ger.corp.intel.com (HELO localhost) ([10.245.246.252]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2025 06:31:57 -0700 From: Andi Shyti To: intel-gfx , dri-devel Cc: Tvrtko Ursulin , Joonas Lahtinen , Chris Wilson , Simona Vetter , Arshad Mehmood , Michal Mrozek , Andi Shyti , Andi Shyti Subject: [PATCH v4 15/15] drm/i915/gt: Allow the user to change the CCS mode through sysfs Date: Mon, 24 Mar 2025 14:29:51 +0100 Message-ID: <20250324132952.1075209-16-andi.shyti@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250324132952.1075209-1-andi.shyti@linux.intel.com> References: <20250324132952.1075209-1-andi.shyti@linux.intel.com> MIME-Version: 1.0 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" Create the 'ccs_mode' file under /sys/class/drm/cardX/gt/gt0/ccs_mode This file allows the user to read and set the current CCS mode. - Reading: The user can read the current CCS mode, which can be 1, 2, or 4. This value is derived from the current engine mask. - Writing: The user can set the CCS mode to 1, 2, or 4, depending on the desired number of exposed engines and the required load balancing. The interface will return -EBUSY if other clients are connected to i915, or -EINVAL if an invalid value is set. Signed-off-by: Andi Shyti --- drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c | 82 ++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c index cbabeb503d3b..8364523f2730 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_ccs_mode.c @@ -6,6 +6,7 @@ #include "i915_drv.h" #include "intel_engine_user.h" #include "intel_gt_ccs_mode.h" +#include "intel_gt_pm.h" #include "intel_gt_print.h" #include "intel_gt_regs.h" #include "intel_gt_sysfs.h" @@ -172,7 +173,7 @@ static int rb_engine_cmp(struct rb_node *rb_new, const struct rb_node *rb_old) return new->uabi_class - old->uabi_class; } -static void __maybe_unused add_uabi_ccs_engines(struct intel_gt *gt, u32 ccs_mode) +static void add_uabi_ccs_engines(struct intel_gt *gt, u32 ccs_mode) { struct drm_i915_private *i915 = gt->i915; intel_engine_mask_t new_ccs_mask, tmp; @@ -234,7 +235,7 @@ static void __maybe_unused add_uabi_ccs_engines(struct intel_gt *gt, u32 ccs_mod mutex_unlock(&i915->uabi_engines_mutex); } -static void __maybe_unused remove_uabi_ccs_engines(struct intel_gt *gt, u8 ccs_mode) +static void remove_uabi_ccs_engines(struct intel_gt *gt, u8 ccs_mode) { struct drm_i915_private *i915 = gt->i915; intel_engine_mask_t new_ccs_mask, tmp; @@ -277,8 +278,85 @@ static ssize_t num_cslices_show(struct device *dev, } static DEVICE_ATTR_RO(num_cslices); +static ssize_t ccs_mode_show(struct device *dev, + struct device_attribute *attr, char *buff) +{ + struct intel_gt *gt = kobj_to_gt(&dev->kobj); + u32 ccs_mode; + + ccs_mode = hweight32(gt->ccs.id_mask); + + return sysfs_emit(buff, "%u\n", ccs_mode); +} + +static ssize_t ccs_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buff, size_t count) +{ + struct intel_gt *gt = kobj_to_gt(&dev->kobj); + int num_cslices = hweight32(CCS_MASK(gt)); + int ccs_mode = hweight32(gt->ccs.id_mask); + ssize_t ret; + u32 val; + + ret = kstrtou32(buff, 0, &val); + if (ret) + return ret; + + /* + * As of now possible values to be set are 1, 2, 4, + * up to the maximum number of available slices + */ + if (!val || val > num_cslices || (num_cslices % val)) + return -EINVAL; + + /* Let's wait until the GT is no longer in use */ + ret = intel_gt_pm_wait_for_idle(gt); + if (ret) + return ret; + + mutex_lock(>->wakeref.mutex); + + /* + * Let's check again that the GT is idle, + * we don't want to change the CCS mode + * while someone is using the GT + */ + if (intel_gt_pm_is_awake(gt)) { + ret = -EBUSY; + goto out; + } + + /* + * Nothing to do if the requested setting + * is the same as the current one + */ + if (val == ccs_mode) + goto out; + else if (val > ccs_mode) + add_uabi_ccs_engines(gt, val); + else + remove_uabi_ccs_engines(gt, val); + +out: + mutex_unlock(>->wakeref.mutex); + + return ret ?: count; +} +static DEVICE_ATTR_RW(ccs_mode); + void intel_gt_sysfs_ccs_init(struct intel_gt *gt) { if (sysfs_create_file(>->sysfs_gt, &dev_attr_num_cslices.attr)) gt_warn(gt, "Failed to create sysfs num_cslices files\n"); + + /* + * Do not create the ccs_mode file for non DG2 platforms + * because they don't need it as they have only one CCS engine + */ + if (!IS_DG2(gt->i915)) + return; + + if (sysfs_create_file(>->sysfs_gt, &dev_attr_ccs_mode.attr)) + gt_warn(gt, "Failed to create sysfs ccs_mode files\n"); }