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 0BCBECC6B0F for ; Tue, 13 Oct 2026 22:29:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF2B610E959; Tue, 13 Oct 2026 22:29:01 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 314FA10E15E for ; Tue, 13 Oct 2026 22:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1791930533; x=1823466533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AZjtZ0GS7PCl2/rlhmx4hoHT7V+vIqPTL3nyZsNHB58=; b=MuzhXLtYTxLeYLD4SGSdohyEtS1HO54PEoLe/3Iy3xlf3qtON57ENoX2 BOoBJX2LrQSVr2B3uSygoewO3j+VwKmPfCuQOD5xcia2XLTuGAvJdKFtQ bTsWGJ35r64v9rV3FL3fOQr8F8qVlKf+HDg23n8kC31djfciXp7Icgt/C nTd1RThsJbuIg/6307jRcFJtEZRqUtgIKcnQ4Be/0Pc1jptAwFhCVM/7J BHfYjcOOd21UqlsAoC0tAA6QihU/ycShAZp5eZphEZVs/eycFEhPjJPoO pIbVyO98rGr54+6BBwSJRNcvTLrdE5paKxQfnOOFiBt6Y0g5DF9HhDkxo w==; X-CSE-ConnectionGUID: gAatFuqXR/a4uOqtovaGFw== X-CSE-MsgGUID: Xoo3cMO8SNOxn8yIdRr9xg== X-IronPort-AV: E=McAfee;i="6800,10657,11934"; a="555675" X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="555675" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2026 15:28:49 -0700 X-CSE-ConnectionGUID: odEsOTqdR4CxWj3OMiOvRA== X-CSE-MsgGUID: pC16KbdmRqWrqYV3xMO5bQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,156,1787036400"; d="scan'208";a="1163699" Received: from aalteres-desk1.fm.intel.com ([10.121.64.173]) by orviesa007.jf.intel.com with ESMTP; 13 Oct 2026 15:28:50 -0700 From: Alan Previn To: intel-xe@lists.freedesktop.org Cc: Alan Previn , julia.filipchuk@intel.com, matthew.brost@intel.com, rodrigo.vivi@intel.com, Zhanjun Dong , =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Subject: [PATCH v11 3/3] drm/xe/guc: Add dump_cache to optimize GuC CT/Log compression flow Date: Tue, 13 Oct 2026 15:28:47 -0700 Message-ID: <20261013222846.308259-8-alan.previn.teres.alexis@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261013222846.308259-5-alan.previn.teres.alexis@intel.com> References: <20261013222846.308259-5-alan.previn.teres.alexis@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" During xe_devcoredump preparation, __xe_devcoredump_read is invoked multiple times, the first time just to get the output size. We should avoid time and energy waste of recompressing the GuC-log-event buffer and GuC-CT buffers repeatedly. Thus, add a dump_cache structure into GuC CT and log snapshot structures to attempt and store a first pass at compressing these buffers for reuse on subsequent calls to __xe_devcoredump_read. Also, ensure any failure of the first compression attempt will still fallback to store the raw dump without compression which is also required when CONFIG_DRM_XE_COMPRESS_DUMP is not enabled. Signed-off-by: Alan Previn Assisted-by: LLM --- drivers/gpu/drm/xe/xe_guc_ct.c | 14 +++- drivers/gpu/drm/xe/xe_guc_ct_types.h | 3 + drivers/gpu/drm/xe/xe_guc_log.c | 96 +++++++++++++++++++++------ drivers/gpu/drm/xe/xe_guc_log.h | 4 +- drivers/gpu/drm/xe/xe_guc_log_types.h | 20 ++++++ 5 files changed, 112 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_guc_ct.c b/drivers/gpu/drm/xe/xe_guc_ct.c index 0d2464c72277..e865d50e8b77 100644 --- a/drivers/gpu/drm/xe/xe_guc_ct.c +++ b/drivers/gpu/drm/xe/xe_guc_ct.c @@ -2223,7 +2223,8 @@ void xe_guc_ct_snapshot_print(struct xe_guc_ct_snapshot *snapshot, if (snapshot->ctb) xe_guc_print_blob(gt, p, "[CTB]", "[CTB].data", &snapshot->ctb, 1, - snapshot->ctb_size, snapshot->ctb_size); + snapshot->ctb_size, snapshot->ctb_size, + &snapshot->dump_cache); } else { drm_puts(p, "CT disabled\n"); } @@ -2241,6 +2242,7 @@ void xe_guc_ct_snapshot_free(struct xe_guc_ct_snapshot *snapshot) if (!snapshot) return; + xe_guc_dump_cache_fini(&snapshot->dump_cache); kfree(snapshot->ctb); kfree(snapshot); } @@ -2369,6 +2371,8 @@ static void ct_dead_print(struct xe_dead_ct *dead) static void ct_dead_worker_func(struct work_struct *w) { struct xe_guc_ct *ct = container_of(w, struct xe_guc_ct, dead.worker); + struct xe_guc_log_snapshot *snapshot_log; + struct xe_guc_ct_snapshot *snapshot_ct; if (!ct->dead.reported) { ct->dead.reported = true; @@ -2377,9 +2381,9 @@ static void ct_dead_worker_func(struct work_struct *w) spin_lock_irq(&ct->dead.lock); - xe_guc_log_snapshot_free(ct->dead.snapshot_log); + snapshot_log = ct->dead.snapshot_log; ct->dead.snapshot_log = NULL; - xe_guc_ct_snapshot_free(ct->dead.snapshot_ct); + snapshot_ct = ct->dead.snapshot_ct; ct->dead.snapshot_ct = NULL; if (ct->dead.reason & (1 << CT_DEAD_STATE_REARM)) { @@ -2389,5 +2393,9 @@ static void ct_dead_worker_func(struct work_struct *w) } spin_unlock_irq(&ct->dead.lock); + + /* Printing may have vmalloc'ed a compression cache; vfree() can sleep */ + xe_guc_log_snapshot_free(snapshot_log); + xe_guc_ct_snapshot_free(snapshot_ct); } #endif diff --git a/drivers/gpu/drm/xe/xe_guc_ct_types.h b/drivers/gpu/drm/xe/xe_guc_ct_types.h index f88e588af0d3..5e33f9fd4cb0 100644 --- a/drivers/gpu/drm/xe/xe_guc_ct_types.h +++ b/drivers/gpu/drm/xe/xe_guc_ct_types.h @@ -14,6 +14,7 @@ #include #include "abi/guc_communication_ctb_abi.h" +#include "xe_guc_log_types.h" struct xe_bo; @@ -75,6 +76,8 @@ struct xe_guc_ct_snapshot { size_t ctb_size; /** @ctb: snapshot of the entire CTB */ void *ctb; + /** @dump_cache: compressed copy of @ctb, built on first print */ + struct xe_guc_dump_cache dump_cache; }; /** diff --git a/drivers/gpu/drm/xe/xe_guc_log.c b/drivers/gpu/drm/xe/xe_guc_log.c index 47adaf70d5bf..90aeaccea596 100644 --- a/drivers/gpu/drm/xe/xe_guc_log.c +++ b/drivers/gpu/drm/xe/xe_guc_log.c @@ -178,6 +178,7 @@ void xe_guc_log_snapshot_free(struct xe_guc_log_snapshot *snapshot) kfree(snapshot->copy); } + xe_guc_dump_cache_fini(&snapshot->dump_cache); kfree(snapshot); } @@ -230,10 +231,9 @@ struct xe_guc_log_snapshot *xe_guc_log_snapshot_capture(struct xe_guc_log *log, } #if IS_ENABLED(CONFIG_DRM_XE_COMPRESS_DUMP) -static void xe_guc_print_blob_compressed(struct xe_gt *gt, struct drm_printer *p, - const char *length_label, const char *data_label, - void **chunks, int num_chunks, - size_t chunk_size, size_t total_size) +static void xe_guc_compress_blob(struct xe_gt *gt, struct xe_guc_dump_cache *cache, + void **chunks, int num_chunks, + size_t chunk_size, size_t total_size) { zstd_parameters params; zstd_cstream *cstream; @@ -244,6 +244,9 @@ static void xe_guc_print_blob_compressed(struct xe_gt *gt, struct drm_printer *p char *dst = NULL; int i; + /* One shot only: every later print replays whatever this pass produced. */ + cache->attempted = true; + /* * Pass 0 as estimated_src_size to use zstd level-3 defaults * (windowLog=18, 256KB window). Passing the full total_size would @@ -286,6 +289,17 @@ static void xe_guc_print_blob_compressed(struct xe_gt *gt, struct drm_printer *p zstd_in_buffer inbuf = { .src = chunks[i], .size = size, .pos = 0 }; while (inbuf.pos < inbuf.size) { + /* + * zstd only guarantees forward progress while the output + * buffer has room. zstd_compress_bound() sizes dst so that + * a single frame always fits, but never risk spinning + * forever in an error-dump path. + */ + if (outbuf.pos == outbuf.size) { + xe_gt_err(gt, "zstd output buffer exhausted\n"); + goto err; + } + ret = zstd_compress_stream(cstream, &outbuf, &inbuf); if (ZSTD_isError(ret)) { xe_gt_err(gt, "zstd_compress_stream failed: %s\n", @@ -296,30 +310,48 @@ static void xe_guc_print_blob_compressed(struct xe_gt *gt, struct drm_printer *p remain -= size; } + /* + * zstd_end_stream() must be called until it returns 0, otherwise the + * frame epilogue is missing and no decompressor will accept the result. + * Running out of output before that happens is a hard error, not a + * reason to stop. + */ do { + if (outbuf.pos == outbuf.size) { + xe_gt_err(gt, "zstd output buffer exhausted\n"); + goto err; + } + ret = zstd_end_stream(cstream, &outbuf); if (ZSTD_isError(ret)) { xe_gt_err(gt, "zstd_end_stream failed: %s\n", ZSTD_getErrorName(ret)); goto err; } - } while (ret > 0 && outbuf.pos < outbuf.size); + } while (ret); - drm_printf(p, "%s.length: 0x%zx -> 0x%zx Algo: ZSTD\n", - length_label, total_size, outbuf.pos); - xe_print_blob_ascii85(p, data_label, '\n', dst, 0, - DIV_ROUND_UP(outbuf.pos, sizeof(u32)) * sizeof(u32)); - goto out; + cache->data = dst; + cache->size = outbuf.pos; + kvfree(wksp); + return; err: - drm_printf(p, "%s.length: 0x%zx Algo: ERROR (compression failed)\n", - length_label, total_size); -out: kvfree(dst); kvfree(wksp); } #endif +/** + * xe_guc_dump_cache_fini - release a dump blob's compression cache + * @cache: cache embedded in the snapshot being freed + */ +void xe_guc_dump_cache_fini(struct xe_guc_dump_cache *cache) +{ + kvfree(cache->data); + cache->data = NULL; + cache->size = 0; +} + /** * xe_guc_print_blob - Print binary data (compressed or uncompressed) as ascii85 * @gt: GT structure for error reporting @@ -330,24 +362,46 @@ static void xe_guc_print_blob_compressed(struct xe_gt *gt, struct drm_printer *p * @num_chunks: number of elements in @chunks * @chunk_size: nominal size of each chunk; the last chunk may hold fewer valid bytes * @total_size: total uncompressed byte count across all chunks + * @cache: per-snapshot compression cache, zeroed at capture time * * If CONFIG_DRM_XE_COMPRESS_DUMP is enabled, compresses @total_size bytes using * zstd level-3 streaming compression and prints the result via @p using ascii85 * encoding. Otherwise, directly prints the uncompressed data. - * On failure the function returns without printing the data blob. + * + * The compressed blob is produced once and kept in @cache, because a snapshot + * is printed repeatedly: __xe_devcoredump_read() measures the output before + * emitting it, and re-emits it a chunk at a time. Compressing per pass would + * let the measured size and the emitted bytes disagree. + * + * If compression fails the raw data is printed instead, so the dump is never + * lost. @cache->attempted latches that decision, so every later pass makes the same + * choice and produces byte-identical output. */ void xe_guc_print_blob(struct xe_gt *gt __maybe_unused, struct drm_printer *p, const char *length_label, const char *data_label, void **chunks, int num_chunks, - size_t chunk_size, size_t total_size) + size_t chunk_size, size_t total_size, + struct xe_guc_dump_cache *cache __maybe_unused) { -#if IS_ENABLED(CONFIG_DRM_XE_COMPRESS_DUMP) - xe_guc_print_blob_compressed(gt, p, length_label, data_label, - chunks, num_chunks, chunk_size, total_size); -#else size_t remain; int i; +#if IS_ENABLED(CONFIG_DRM_XE_COMPRESS_DUMP) + if (!cache->attempted) + xe_guc_compress_blob(gt, cache, chunks, num_chunks, + chunk_size, total_size); + + if (cache->data) { + drm_printf(p, "%s.length: 0x%zx -> 0x%zx Algo: ZSTD\n", + length_label, total_size, cache->size); + xe_print_blob_ascii85(p, data_label, '\n', cache->data, 0, + round_up(cache->size, sizeof(u32))); + return; + } + + /* Compression failed - fallback to emit the blob uncompressed. */ +#endif + drm_printf(p, "%s.length: 0x%zx Algo: RAW\n", length_label, total_size); /* @@ -366,7 +420,6 @@ void xe_guc_print_blob(struct xe_gt *gt __maybe_unused, struct drm_printer *p, DIV_ROUND_UP(size, sizeof(u32)) * sizeof(u32)); remain -= size; } -#endif } /** @@ -393,7 +446,8 @@ void xe_guc_log_snapshot_print(struct xe_guc_log_snapshot *snapshot, struct drm_ xe_guc_print_blob(gt, p, "[LOG]", "[LOG].data", snapshot->copy, snapshot->num_chunks, - GUC_LOG_CHUNK_SIZE, snapshot->size); + GUC_LOG_CHUNK_SIZE, snapshot->size, + &snapshot->dump_cache); } static inline void lfd_output_binary(struct drm_printer *p, char *buf, int buf_size) diff --git a/drivers/gpu/drm/xe/xe_guc_log.h b/drivers/gpu/drm/xe/xe_guc_log.h index 3e97647ee8b5..bb6415271e5f 100644 --- a/drivers/gpu/drm/xe/xe_guc_log.h +++ b/drivers/gpu/drm/xe/xe_guc_log.h @@ -63,7 +63,9 @@ struct xe_guc_log_snapshot *xe_guc_log_snapshot_capture(struct xe_guc_log *log, void xe_guc_print_blob(struct xe_gt *gt, struct drm_printer *p, const char *length_label, const char *data_label, void **chunks, int num_chunks, - size_t chunk_size, size_t total_size); + size_t chunk_size, size_t total_size, + struct xe_guc_dump_cache *cache); +void xe_guc_dump_cache_fini(struct xe_guc_dump_cache *cache); void xe_guc_log_snapshot_print(struct xe_guc_log_snapshot *snapshot, struct drm_printer *p, struct xe_gt *gt); diff --git a/drivers/gpu/drm/xe/xe_guc_log_types.h b/drivers/gpu/drm/xe/xe_guc_log_types.h index 02851b924aa4..a38e9619c95d 100644 --- a/drivers/gpu/drm/xe/xe_guc_log_types.h +++ b/drivers/gpu/drm/xe/xe_guc_log_types.h @@ -13,6 +13,24 @@ struct xe_bo; +/** + * struct xe_guc_dump_cache - cached compressed copy of a dump blob + * + * A snapshot is printed more than once: __xe_devcoredump_read() walks it first + * with a NULL buffer to measure the output size, then again - once per chunk - + * to fill the user buffer. Compressing on every pass would be both wasteful and + * unsafe, as any difference between the measured size and the emitted bytes + * corrupts the dump. So compress at most once and replay the result. + */ +struct xe_guc_dump_cache { + /** @data: compressed bytes, allocation padded up to a u32 boundary */ + char *data; + /** @size: number of valid compressed bytes in @data */ + size_t size; + /** @attempted: compression has been attempted; @data is final either way */ + bool attempted; +}; + /** * struct xe_guc_log_snapshot: * Capture of the GuC log plus various state useful for decoding the log @@ -36,6 +54,8 @@ struct xe_guc_log_snapshot { struct xe_uc_fw_version ver_want; /** @path: Path of GuC firmware blob */ const char *path; + /** @dump_cache: compressed copy of @copy, built on first print */ + struct xe_guc_dump_cache dump_cache; }; /** -- 2.43.0