Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4A5D606A322 for ; Thu, 3 Dec 2026 17:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=nXGnVyYy Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E03C10E538; Thu, 3 Dec 2026 17:12:45 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id D91E610E0F6; Thu, 3 Dec 2026 17:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796317958; x=1827853958; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=htK7//g2ZkozSf8xMbDa3LWceczaEbtF1FN2VlnWX1A=; b=nXGnVyYyNXXTgGHdq5bEZ14i9fKSi/A9tt0whFaCCBDV+ItrOoLAkXWw j0EjUSkycB9cGfGBvBkICm0DNMqj0zBNYLoerWT2Zj4mCf8jTEu7vlOma p36C7vgk6JqxJux1vDjNFQqJoNTIoNMFEF7hcoSJ1BdVwduzYpweaSCYN yasMtP6ATWVq9NacLfMcygepNP4LgtuY5pb4GgocCjO8n9hjq7iR/5nfe SXoWpn5ZNvOFGSNCVlOqfIYcI828+ljyCd/fK+1px0sAIoYLIPuu3l4d8 7mPgwjW/K54u/RFzG3XSAh5CqesJw4w8Sj+4BfCIr43Y8INZV7Dfr6CtH g==; X-CSE-ConnectionGUID: 7C886uAYQESxnNYobTXaHQ== X-CSE-MsgGUID: tW7IzM8yQh+U1CkEe8WPNw== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5192697" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5192697" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 09:12:36 -0800 X-CSE-ConnectionGUID: M73vb8cFQaOGB1olBntOyw== X-CSE-MsgGUID: xYBA0UxFTeCj5rWjVdbNWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="13990011" Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24]) by fmviesa008.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 09:12:36 -0800 Received: from ORSMSX902.amr.corp.intel.com (10.22.229.24) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 09:12:35 -0800 Received: from ORSEDG901.ED.cps.intel.com (10.7.248.11) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 09:12:35 -0800 Received: from PH8PR06CU001.outbound.protection.outlook.com (40.107.209.67) by edgegateway.intel.com (134.134.137.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 09:12:34 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OQnRq6Cv0SI+UswUA4LAtZ6ZCfdyCHk4O3+ocpm4PFSX6u+53WSdibla+xmmB21GA3s0WA4LrknrzxwMBY5tlRTZAS1EwJ4KF3H0m8DguSyuL/Bx/Y4bHVbqcX8+oOO/NK6LIDWFOgAeKA/R3uID2aljz5YgHb6dq/WuYnmxyLMM4853R7+zXR4AHuOEP8soU5AJNstgxq+0In4fHgGuqDyW4vebgrOBkDJTVmmeaLyS3c50cWr4vg3pkgjiTKyzQG4urvE9geSt85QkFOcmT8zZN2vjQRBx8DDEIOpAWSB6umEMTHabizA/GhCkbVdNtM2u5UoypaqYkw4XrocN1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fy2JQGNS0gxFJDgzV2jas1K3RQneiHJYzIZ5jzIBsSM=; b=t9vjR3f3hSrJH/Lf3LIFHyCb2PDMwmXHUtliQPimm9srUwP7/Yx5QJEBeMWcnpDNwbw4+s0PRJ6xdQ6HclA5HKNvMej/smH+h2n2oBS6dZI106ibGV5BfE8oAWQReVmkCFYZLIcf3P7GQXBGf3Hc6yQx6OXeQ1DqaQcq7IV7hQy3PwUSuOPoJRm2FrUQWzeR9VErk21NmwFagDAVAB+cmp6gSjQfnkZG8PzJTH4Pq5DHM64vsJr8+3YlQ6/Ut5Y5R7fxpuEz49ZhBuH0KVDeLEMYD8eZ8VgfR3pKKBKWRNsPnak3chLNInIsPtUmhkSwkaYuwlErztFYnWtAtNHzbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MW3PR11MB4684.namprd11.prod.outlook.com (2603:10b6:303:5d::14) by PH3PPF9E162731D.namprd11.prod.outlook.com (2603:10b6:518:1::d3c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Thu, 3 Dec 2026 17:12:20 +0000 Received: from MW3PR11MB4684.namprd11.prod.outlook.com ([fe80::2f5a:96ce:f7e4:c315]) by MW3PR11MB4684.namprd11.prod.outlook.com ([fe80::2f5a:96ce:f7e4:c315%7]) with mapi id 15.21.0688.011; Thu, 3 Dec 2026 17:12:19 +0000 Date: Thu, 3 Dec 2026 09:12:17 -0800 From: Niranjana Vishwanathapura To: Matthew Brost CC: , , Carlos Santa , Ryan Neph , Matthew Auld , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Natalie Vock , "Arun Pravin" Subject: Re: [PATCH v5 36/36] drm/xe: Make BO defrag tunables configurable via sysfs Message-ID: References: <20261202233323.3743190-1-matthew.brost@intel.com> <20261202233323.3743190-37-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261202233323.3743190-37-matthew.brost@intel.com> X-ClientProxiedBy: PH8PR07CA0025.namprd07.prod.outlook.com (2603:10b6:510:2cf::13) To MW3PR11MB4684.namprd11.prod.outlook.com (2603:10b6:303:5d::14) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MW3PR11MB4684:EE_|PH3PPF9E162731D:EE_ X-MS-Office365-Filtering-Correlation-Id: 40706648-160f-4587-0956-08df516096a8 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|23010399003|261022075727099003|261102123227099003|56012099006|261022105027099003|10067099003|261028144727099003|261021123027099003|261026121527099003|261026140227099003|261021121427099003|261009223027099003|261009221227099003|261009221727099003|261009220027099003|261009223327099003|22082099003|5023799004|11063799006|4143699003|6133799003|18002099003; X-Microsoft-Antispam-Message-Info: gsxKWvPkF8PyCwFDgIbDs4tDnbasUnyF76zjAQElJEP0ihFRVpydMwTdEXL6LYFU1KEnQW/iWyu6dToAR0DLvO7Apn4dOExs8hJCG0q1/dwgNLXyVhk6X9DlTOx9tREb9oiPHUbIGZ3vFg9OQ1JGNsEQs+csSTYKPCY1XUvDV+mc0s21k7yRwMyTKgs3L9J3c0MZPvWtJaMNq1TMtRYPpOEu/+atNIPqk6sGf69Zn/d1b2cymhKqkgPfWmLmpFdVtV5YaGtUELeuXHOno2Qc+dpFmy7Tur4RzRInfmfBlKaEpXhqW6wvIdag6Jo/G7X0/mWhtb/k9L2eMW8BG2Xj/Kse/IegHWkrK9e9aApv9+n1vJHX34nIrKpGL3gNuNE0VZVXWO501t/L84YN+D4Me1WytDlRX0yxJ5Gb0ihkhzsLh1Gl0y7PGPAfGrmVS3FYDQGmP6/Fb0PEQ2LU+WT9AVgBUwE+mUUYiShR5xOzJu4MuZptFWbn9LrswfyUwRKGefirai1kjjp5cR2w6v/9edmU59aOQu08m8D9+QDosV8GXem48zsuPwt4hfYoFHJm17PTnolkOkqkE5Euq5ZTsA/PNN9Y5/XZOIJ4Kag7Dnl6B+tVaUYOsfu/DIDwMgkvhVT0J7Bg65zDQjpwq1bWYdCkqaXeOlYDm/4dzW38Pnw= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MW3PR11MB4684.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014)(23010399003)(261022075727099003)(261102123227099003)(56012099006)(261022105027099003)(10067099003)(261028144727099003)(261021123027099003)(261026121527099003)(261026140227099003)(261021121427099003)(261009223027099003)(261009221227099003)(261009221727099003)(261009220027099003)(261009223327099003)(22082099003)(5023799004)(11063799006)(4143699003)(6133799003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859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FB1Ny1slrgcDcAkYpiiwct9L7vdYoLfpO0kIYFcJdDYpCq37J3?= =?iso-8859-1?Q?e363OtA94QUmhokaqqHE8Bhv0sssIuJx6daxDD1Mw9d8mSvmGkxl?= X-Exchange-RoutingPolicyChecked: NNhTFEpOZA9pqWCWbuSoZsGvwGh/4XvFqzZHpOKRFMD8pdQm7OOICQFXo0amzR0yTKoNA8XcyeN+9WmxossXWBGtzTRR95E913Bqf2GEUqnvRUTlyFypy93LJMGwG6S9VkMTxlLvGY4tii/QcpiEumElq9ybXzF4EtH6YEYjO00EgHCW05BynfCzJ8tdUaB92OzD/gFVlyAl/IPClYF51e7TDNbMkfrv/5chJDjXsUmiNWpN0I8lEJ0pRnC19CFzyOYQuHwfB9CZkIqbGQkgJPH+wAGLpDBzGU7EUJ1NhkSzDul7+KNCqUllil2idYpqlQFWlZmLWMmi+tSNDJFTiA== X-MS-Exchange-CrossTenant-Network-Message-Id: 40706648-160f-4587-0956-08df516096a8 X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4684.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 17:12:19.8265 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yzMi5nAPSG5HMV0EB0mYQMQ3bh4aLXMGhMdPBIXibq7sk3+LpxBgzCkK585CRp0nisbyDMKqGwxNbs/xnTApWd5TFzJkjNRVYqr6uvk71GK85vmQ8Sfnx3O5MtCqBTYf X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH3PPF9E162731D X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Dec 02, 2026 at 03:33:23PM -0800, Matthew Brost wrote: >The BO defrag per-run size limit, default worker interval and maximum >backed off worker interval are currently fixed at build time via >Kconfig. Tuning them requires a rebuild, which makes experimenting with >defrag behaviour on a running system painful. > >Add defrag_size_limit, defrag_interval_ms and defrag_interval_max_ms >device sysfs attributes, defaulting to the Kconfig values. Writes are >validated against the Kconfig ranges, the size limit must be 2M aligned, >and the default interval may not exceed the maximum interval. Lowering >the size limit below 2M (disabling defrag) remains a build time only >decision, so the attributes are only exposed when defrag is supported. >Report the runtime values in the bo_defrag debugfs entry. > >Cc: Carlos Santa >Cc: Ryan Neph >Cc: Matthew Auld >Cc: Thomas Hellström >Cc: Natalie Vock >Cc: Arun Pravin >Signed-off-by: Matthew Brost >--- > drivers/gpu/drm/xe/Kconfig.profile | 9 +- > drivers/gpu/drm/xe/xe_bo.c | 131 +++++++++++++++++++++++---- > drivers/gpu/drm/xe/xe_bo.h | 5 + > drivers/gpu/drm/xe/xe_device_sysfs.c | 122 +++++++++++++++++++++++++ > drivers/gpu/drm/xe/xe_device_types.h | 24 ++++- > 5 files changed, 269 insertions(+), 22 deletions(-) > >diff --git a/drivers/gpu/drm/xe/Kconfig.profile b/drivers/gpu/drm/xe/Kconfig.profile >index 32bc358e6968..ea46e34e3957 100644 >--- a/drivers/gpu/drm/xe/Kconfig.profile >+++ b/drivers/gpu/drm/xe/Kconfig.profile >@@ -115,7 +115,9 @@ config DRM_XE_BO_DEFRAG_SIZE_LIMIT > number of BOs become eligible at once, processing them all in one > worker run would hold things up for a long, unbounded stretch. > Instead, cap the work done per run and requeue, spreading the defrag >- effort out over time. >+ effort out over time. This is the default; when defrag is enabled it >+ can be changed at runtime (2M to 1G) via the defrag_size_limit >+ device sysfs attribute. > > config DRM_XE_BO_DEFRAG_INTERVAL_MS > int "Default delay before defrag worker run (ms)" >@@ -123,6 +125,8 @@ config DRM_XE_BO_DEFRAG_INTERVAL_MS > range 1 1000 > help > Default delay before (re)running the defrag worker, in milliseconds. >+ Can be changed at runtime via the defrag_interval_ms device sysfs >+ attribute. > > config DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS > int "Upper bound for defrag worker interval (ms)" >@@ -131,4 +135,5 @@ config DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS > help > Upper bound for the (exponentially backed off) defrag worker interval, > in milliseconds, so repeated failures don't push the retry arbitrarily >- far out. 15000 ms = 15 seconds. >+ far out. 15000 ms = 15 seconds. Can be changed at runtime via the >+ defrag_interval_max_ms device sysfs attribute. >diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c >index 85552da80bf5..321e74e03e3c 100644 >--- a/drivers/gpu/drm/xe/xe_bo.c >+++ b/drivers/gpu/drm/xe/xe_bo.c >@@ -93,6 +93,12 @@ > #define XE_BO_DEFRAG_INTERVAL_MAX_MS 15000 /* 15 seconds */ > #endif > >+/* Bounds for the values tunable at runtime via sysfs. */ >+#define XE_BO_DEFRAG_SIZE_LIMIT_MAX SZ_1G >+#define XE_BO_DEFRAG_INTERVAL_MS_MAX 1000 >+#define XE_BO_DEFRAG_INTERVAL_MAX_MS_MIN 100 >+#define XE_BO_DEFRAG_INTERVAL_MAX_MS_MAX 1000000 >+ NIT...these definitions should match the range of Kconfig items. May be document that here and in Kconfig so that anyone touching it later would know? In anycase, Reviewed-by: Niranjana Vishwanathapura > static void xe_bo_defrag_worker(struct work_struct *w); > static void xe_place_from_ttm_type(u32 mem_type, struct ttm_place *place); > >@@ -1698,8 +1704,6 @@ static struct ttm_tt *xe_ttm_tt_create(struct ttm_buffer_object *ttm_bo, > return tt; > } > >-static bool xe_bo_defrag_supported(struct xe_device *xe); >- > static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt, > struct ttm_operation_ctx *ctx) > { >@@ -2240,6 +2244,9 @@ int xe_bo_defrag_init_early(struct xe_device *xe) > > spin_lock_init(&xe->mem.defrag.lock); > INIT_LIST_HEAD(&xe->mem.defrag.list); >+ xe->mem.defrag.size_limit = XE_BO_DEFRAG_SIZE_LIMIT; >+ xe->mem.defrag.interval_default_ms = XE_BO_DEFRAG_INTERVAL_MS; >+ xe->mem.defrag.interval_max_ms = XE_BO_DEFRAG_INTERVAL_MAX_MS; > xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS; > INIT_DELAYED_WORK(&xe->mem.defrag.worker, xe_bo_defrag_worker); > >@@ -2310,7 +2317,7 @@ static void xe_bo_defrag_kick_locked(struct xe_device *xe) > if (list_empty(&xe->mem.defrag.list)) > return; > >- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS; >+ xe->mem.defrag.interval_ms = xe->mem.defrag.interval_default_ms; > xe_bo_defrag_schedule_locked(xe, true); > } > >@@ -2364,11 +2371,14 @@ void xe_bo_defrag_kick(struct xe_device *xe) > xe_bo_defrag_kick_locked(xe); > } > >-/* >+/** > * xe_bo_defrag_supported() - Whether background defragmentation is usable > * @xe: xe device instance > * >- * Defragmentation is not supported if XE_BO_DEFRAG_SIZE_LIMIT is less than 2M. >+ * Defragmentation is not supported if the default size limit >+ * (CONFIG_DRM_XE_BO_DEFRAG_SIZE_LIMIT) is less than 2M. The runtime size limit >+ * can't be lowered below 2M, so it can't change whether defragmentation is >+ * supported. > * > * Defragmentation forces TTM moves that reallocate a BO's backing. On a VF > * platform that requires CCS save/restore this interacts badly with CCS >@@ -2377,12 +2387,91 @@ void xe_bo_defrag_kick(struct xe_device *xe) > * backoff that assumes a later in-place upgrade. This is a static platform > * check so the answer can't change during probe, after BOs have been > * allocated or tracked. >+ * >+ * Return: true if background defragmentation is supported, false otherwise. > */ >-static bool xe_bo_defrag_supported(struct xe_device *xe) >+bool xe_bo_defrag_supported(struct xe_device *xe) > { > return XE_BO_DEFRAG_SIZE_LIMIT >= SZ_2M && !IS_VF_CCS_NEEDED(xe); > } > >+/** >+ * xe_bo_defrag_set_size_limit() - Set the defrag worker per-run byte budget >+ * @xe: xe device instance >+ * @size_limit: New maximum number of bytes to defrag per worker run >+ * >+ * Takes effect from the next worker run. >+ * >+ * Return: 0 on success, -EINVAL if @size_limit is out of range or not 2M >+ * aligned. >+ */ >+int xe_bo_defrag_set_size_limit(struct xe_device *xe, u64 size_limit) >+{ >+ if (size_limit < SZ_2M || size_limit > XE_BO_DEFRAG_SIZE_LIMIT_MAX || >+ !IS_ALIGNED(size_limit, SZ_2M)) >+ return -EINVAL; >+ >+ WRITE_ONCE(xe->mem.defrag.size_limit, size_limit); >+ >+ return 0; >+} >+ >+/** >+ * xe_bo_defrag_set_interval_ms() - Set the default defrag worker interval >+ * @xe: xe device instance >+ * @interval_ms: New default delay before (re)running the defrag worker >+ * >+ * The new value is used the next time the worker interval is reset, i.e. on >+ * forward progress or when the defrag list transitions to non-empty. >+ * >+ * Return: 0 on success, -EINVAL if @interval_ms is out of range or exceeds >+ * the maximum interval. >+ */ >+int xe_bo_defrag_set_interval_ms(struct xe_device *xe, unsigned int interval_ms) >+{ >+ if (!interval_ms || interval_ms > XE_BO_DEFRAG_INTERVAL_MS_MAX) >+ return -EINVAL; >+ >+ guard(spinlock)(&xe->mem.defrag.lock); >+ >+ if (interval_ms > xe->mem.defrag.interval_max_ms) >+ return -EINVAL; >+ >+ WRITE_ONCE(xe->mem.defrag.interval_default_ms, interval_ms); >+ >+ return 0; >+} >+ >+/** >+ * xe_bo_defrag_set_interval_max_ms() - Set the maximum defrag worker interval >+ * @xe: xe device instance >+ * @interval_max_ms: New upper bound for the backed off worker interval >+ * >+ * The current interval is clamped to the new maximum, taking effect the next >+ * time the worker is scheduled. >+ * >+ * Return: 0 on success, -EINVAL if @interval_max_ms is out of range or is >+ * less than the default interval. >+ */ >+int xe_bo_defrag_set_interval_max_ms(struct xe_device *xe, >+ unsigned int interval_max_ms) >+{ >+ if (interval_max_ms < XE_BO_DEFRAG_INTERVAL_MAX_MS_MIN || >+ interval_max_ms > XE_BO_DEFRAG_INTERVAL_MAX_MS_MAX) >+ return -EINVAL; >+ >+ guard(spinlock)(&xe->mem.defrag.lock); >+ >+ if (interval_max_ms < xe->mem.defrag.interval_default_ms) >+ return -EINVAL; >+ >+ WRITE_ONCE(xe->mem.defrag.interval_max_ms, interval_max_ms); >+ xe->mem.defrag.interval_ms = min(xe->mem.defrag.interval_ms, >+ interval_max_ms); >+ >+ return 0; >+} >+ > static bool xe_bo_needs_defrag(struct xe_bo *bo) > { > struct ttm_buffer_object *ttm_bo = &bo->ttm; >@@ -2494,7 +2583,7 @@ int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p) > struct delayed_work *dwork = &xe->mem.defrag.worker; > u64 total_size = 0, total_subopt = 0; > unsigned int count = 0, nr = 0, i; >- unsigned int interval_ms; >+ unsigned int interval_ms, interval_default_ms, interval_max_ms; > struct xe_bo **bos, *bo; > int err = 0; > >@@ -2505,15 +2594,18 @@ int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p) > > scoped_guard(spinlock, &xe->mem.defrag.lock) { > interval_ms = xe->mem.defrag.interval_ms; >+ interval_default_ms = xe->mem.defrag.interval_default_ms; >+ interval_max_ms = xe->mem.defrag.interval_max_ms; > list_for_each_entry(bo, &xe->mem.defrag.list, defrag_link) > count++; > } > > drm_printf(p, "beneficial_order: %u\n", > ttm_pool_prealloc_order(&xe->ttm.pool)); >- drm_printf(p, "size_limit: %llu\n", (u64)XE_BO_DEFRAG_SIZE_LIMIT); >+ drm_printf(p, "size_limit: %llu\n", >+ READ_ONCE(xe->mem.defrag.size_limit)); > drm_printf(p, "interval_ms: %u (default %u, max %u)\n", interval_ms, >- XE_BO_DEFRAG_INTERVAL_MS, XE_BO_DEFRAG_INTERVAL_MAX_MS); >+ interval_default_ms, interval_max_ms); > if (delayed_work_pending(dwork)) { > long delay = (long)(READ_ONCE(dwork->timer.expires) - jiffies); > >@@ -2739,6 +2831,7 @@ static void xe_bo_defrag_worker(struct work_struct *w) > struct delayed_work *dwork = to_delayed_work(w); > struct xe_device *xe = > container_of(dwork, struct xe_device, mem.defrag.worker); >+ u64 size_limit = READ_ONCE(xe->mem.defrag.size_limit); > u64 defrag_bytes = 0; > bool requeue = false; > int idx; >@@ -2761,7 +2854,7 @@ static void xe_bo_defrag_worker(struct work_struct *w) > trace_xe_bo_defrag_worker(xe, 0, true); > > /* >- * Process at most XE_BO_DEFRAG_SIZE_LIMIT bytes of newly (re)allocated >+ * Process at most @mem.defrag.size_limit bytes of newly (re)allocated > * backing per run rather than draining the whole list in one go. Only > * the pages a move actually reallocates are charged - pages harvested > * (borrowed) from the old backing are free and do not count - so the >@@ -2772,7 +2865,7 @@ static void xe_bo_defrag_worker(struct work_struct *w) > * active work make progress; any remaining work is handled by a > * follow-up run scheduled below. > */ >- while (defrag_bytes < XE_BO_DEFRAG_SIZE_LIMIT) { >+ while (defrag_bytes < size_limit) { > struct xe_bo *first, *bo; > u64 consumed = 0; > bool needs_more = false; >@@ -2783,7 +2876,8 @@ static void xe_bo_defrag_worker(struct work_struct *w) > > /* Progress, reset interval */ > if (defrag_bytes) >- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS; >+ xe->mem.defrag.interval_ms = >+ xe->mem.defrag.interval_default_ms; > > do { > first = list_first_entry_or_null(&xe->mem.defrag.list, >@@ -2806,7 +2900,7 @@ static void xe_bo_defrag_worker(struct work_struct *w) > * beneficial harvests, so each run only spends budget on new > * forward progress. > */ >- ret = xe_bo_defrag_one(xe, bo, XE_BO_DEFRAG_SIZE_LIMIT - defrag_bytes, >+ ret = xe_bo_defrag_one(xe, bo, size_limit - defrag_bytes, > &consumed, &needs_more); > defrag_bytes += consumed; > >@@ -2820,10 +2914,11 @@ static void xe_bo_defrag_worker(struct work_struct *w) > */ > xe->mem.defrag.interval_ms = > min(xe->mem.defrag.interval_ms * 2, >- (unsigned int)XE_BO_DEFRAG_INTERVAL_MAX_MS); >+ xe->mem.defrag.interval_max_ms); > else > /* Progress, reset interval */ >- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS; >+ xe->mem.defrag.interval_ms = >+ xe->mem.defrag.interval_default_ms; > } > > xe_bo_put(bo); >@@ -2838,7 +2933,7 @@ static void xe_bo_defrag_worker(struct work_struct *w) > * Decide whether to reschedule: > * > * - The loop hit its per-run limit (defrag_bytes >= >- * XE_BO_DEFRAG_SIZE_LIMIT): we stopped early to spread the work out, >+ * size_limit): we stopped early to spread the work out, > * so requeue at the default interval (reset here since this run made > * progress) whenever the list still has entries. > * >@@ -2848,10 +2943,10 @@ static void xe_bo_defrag_worker(struct work_struct *w) > * - The loop drained the list (broke on the empty list): nothing left to > * do, so stop scheduling. A fresh enqueue will kick the worker again. > */ >- if (defrag_bytes >= XE_BO_DEFRAG_SIZE_LIMIT) { >+ if (defrag_bytes >= size_limit) { > guard(spinlock)(&xe->mem.defrag.lock); > >- xe->mem.defrag.interval_ms = XE_BO_DEFRAG_INTERVAL_MS; >+ xe->mem.defrag.interval_ms = xe->mem.defrag.interval_default_ms; > if (!list_empty(&xe->mem.defrag.list)) > xe_bo_defrag_schedule_locked(xe, false); > } else if (requeue) { >diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h >index 28325341b4d1..281a863c1702 100644 >--- a/drivers/gpu/drm/xe/xe_bo.h >+++ b/drivers/gpu/drm/xe/xe_bo.h >@@ -241,6 +241,11 @@ int xe_bo_defrag_init(struct xe_device *xe); > void xe_bo_defrag_suspend(struct xe_device *xe); > void xe_bo_defrag_resume(struct xe_device *xe); > void xe_bo_defrag_kick(struct xe_device *xe); >+bool xe_bo_defrag_supported(struct xe_device *xe); >+int xe_bo_defrag_set_size_limit(struct xe_device *xe, u64 size_limit); >+int xe_bo_defrag_set_interval_ms(struct xe_device *xe, unsigned int interval_ms); >+int xe_bo_defrag_set_interval_max_ms(struct xe_device *xe, >+ unsigned int interval_max_ms); > int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p); > int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict, > struct drm_exec *exec); >diff --git a/drivers/gpu/drm/xe/xe_device_sysfs.c b/drivers/gpu/drm/xe/xe_device_sysfs.c >index 9b734aeefd33..c94592576408 100644 >--- a/drivers/gpu/drm/xe/xe_device_sysfs.c >+++ b/drivers/gpu/drm/xe/xe_device_sysfs.c >@@ -11,6 +11,7 @@ > #include > > #include "regs/xe_regs.h" >+#include "xe_bo.h" > #include "xe_device.h" > #include "xe_device_sysfs.h" > #include "xe_mmio.h" >@@ -56,6 +57,24 @@ > * back it up. BOs evicted to system memory are never protected. Defaults to > * CONFIG_DRM_XE_SHRINKER_MIN_AGE_MS, 0 disables. This applies at every > * reclaim priority, so a non-zero value can lead to OOM. >+ * >+ * defrag_size_limit - Report/change the maximum number of bytes the BO >+ * defragmentation worker reallocates per run. Valid values are 2M aligned, >+ * 2M to 1G. >+ * Defaults to CONFIG_DRM_XE_BO_DEFRAG_SIZE_LIMIT. Exposed only if BO >+ * defragmentation is supported. >+ * >+ * defrag_interval_ms - Report/change the default delay, in milliseconds, >+ * before (re)running the BO defragmentation worker. Valid values are 1 to >+ * 1000 and must not exceed defrag_interval_max_ms. Defaults to >+ * CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MS. Exposed only if BO defragmentation is >+ * supported. >+ * >+ * defrag_interval_max_ms - Report/change the upper bound, in milliseconds, of >+ * the exponentially backed off BO defragmentation worker interval. Valid >+ * values are 100 to 1000000 and must not be less than defrag_interval_ms. >+ * Defaults to CONFIG_DRM_XE_BO_DEFRAG_INTERVAL_MAX_MS. Exposed only if BO >+ * defragmentation is supported. > */ > > static ssize_t >@@ -428,6 +447,103 @@ static const struct attribute_group userptr_attr_group = { > .attrs = userptr_attrs, > }; > >+static ssize_t >+defrag_size_limit_show(struct device *dev, struct device_attribute *attr, >+ char *buf) >+{ >+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev)); >+ >+ return sysfs_emit(buf, "%llu\n", READ_ONCE(xe->mem.defrag.size_limit)); >+} >+ >+static ssize_t >+defrag_size_limit_store(struct device *dev, struct device_attribute *attr, >+ const char *buf, size_t count) >+{ >+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev)); >+ u64 size_limit; >+ int ret; >+ >+ ret = kstrtou64(buf, 0, &size_limit); >+ if (ret) >+ return ret; >+ >+ ret = xe_bo_defrag_set_size_limit(xe, size_limit); >+ >+ return ret ?: count; >+} >+ >+static DEVICE_ATTR_RW(defrag_size_limit); >+ >+static ssize_t >+defrag_interval_ms_show(struct device *dev, struct device_attribute *attr, >+ char *buf) >+{ >+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev)); >+ >+ return sysfs_emit(buf, "%u\n", >+ READ_ONCE(xe->mem.defrag.interval_default_ms)); >+} >+ >+static ssize_t >+defrag_interval_ms_store(struct device *dev, struct device_attribute *attr, >+ const char *buf, size_t count) >+{ >+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev)); >+ unsigned int interval_ms; >+ int ret; >+ >+ ret = kstrtouint(buf, 0, &interval_ms); >+ if (ret) >+ return ret; >+ >+ ret = xe_bo_defrag_set_interval_ms(xe, interval_ms); >+ >+ return ret ?: count; >+} >+ >+static DEVICE_ATTR_RW(defrag_interval_ms); >+ >+static ssize_t >+defrag_interval_max_ms_show(struct device *dev, struct device_attribute *attr, >+ char *buf) >+{ >+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev)); >+ >+ return sysfs_emit(buf, "%u\n", >+ READ_ONCE(xe->mem.defrag.interval_max_ms)); >+} >+ >+static ssize_t >+defrag_interval_max_ms_store(struct device *dev, struct device_attribute *attr, >+ const char *buf, size_t count) >+{ >+ struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev)); >+ unsigned int interval_max_ms; >+ int ret; >+ >+ ret = kstrtouint(buf, 0, &interval_max_ms); >+ if (ret) >+ return ret; >+ >+ ret = xe_bo_defrag_set_interval_max_ms(xe, interval_max_ms); >+ >+ return ret ?: count; >+} >+ >+static DEVICE_ATTR_RW(defrag_interval_max_ms); >+ >+static struct attribute *defrag_attrs[] = { >+ &dev_attr_defrag_size_limit.attr, >+ &dev_attr_defrag_interval_ms.attr, >+ &dev_attr_defrag_interval_max_ms.attr, >+ NULL >+}; >+ >+static const struct attribute_group defrag_attr_group = { >+ .attrs = defrag_attrs, >+}; >+ > int xe_device_sysfs_init(struct xe_device *xe) > { > struct device *dev = xe->drm.dev; >@@ -441,6 +557,12 @@ int xe_device_sysfs_init(struct xe_device *xe) > if (ret) > return ret; > >+ if (xe_bo_defrag_supported(xe)) { >+ ret = devm_device_add_group(dev, &defrag_attr_group); >+ if (ret) >+ return ret; >+ } >+ > if (xe->d3cold.capable) { > ret = devm_device_add_group(dev, &vram_attr_group); > if (ret) >diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h >index 423a868d4605..051e29a6f00c 100644 >--- a/drivers/gpu/drm/xe/xe_device_types.h >+++ b/drivers/gpu/drm/xe/xe_device_types.h >@@ -345,10 +345,30 @@ struct xe_device { > */ > struct delayed_work worker; > /** >- * @mem.defrag.interval_ms: Reschedule interval for >- * @mem.defrag.worker, in milliseconds. >+ * @mem.defrag.interval_ms: Current (possibly backed off) >+ * reschedule interval for @mem.defrag.worker, in >+ * milliseconds. Protected by @mem.defrag.lock. > */ > unsigned int interval_ms; >+ /** >+ * @mem.defrag.interval_default_ms: Interval that >+ * @mem.defrag.interval_ms is reset to on forward progress, >+ * in milliseconds. Tunable via sysfs. Written under >+ * @mem.defrag.lock. >+ */ >+ unsigned int interval_default_ms; >+ /** >+ * @mem.defrag.interval_max_ms: Upper bound for the >+ * backed off @mem.defrag.interval_ms, in milliseconds. >+ * Tunable via sysfs. Written under @mem.defrag.lock. >+ */ >+ unsigned int interval_max_ms; >+ /** >+ * @mem.defrag.size_limit: Maximum number of newly >+ * (re)allocated bytes the worker defrags per run. >+ * Tunable via sysfs. >+ */ >+ u64 size_limit; > /** > * @mem.defrag.suspended: The device is suspending, > * suspended or undergoing FLR; @mem.defrag.worker must >-- >2.34.1 >