Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-xe] [RFC] drm/xe: Introduce xe_ASSERT macros
@ 2023-07-28 19:25 Michal Wajdeczko
  2023-07-28 19:47 ` [Intel-xe] ✓ CI.Patch_applied: success for " Patchwork
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: Michal Wajdeczko @ 2023-07-28 19:25 UTC (permalink / raw)
  To: intel-xe; +Cc: Francois Dugast, Rodrigo Vivi

As we are moving away from the controversial XE_BUG_ON macro,
relying just on WARN_ON or drm_err does not cover the cases
where we want to annotate functions with additional detailed
debug checks to assert that all prerequisites are satisfied,
without paying footprint or performance penalty on non-debug
builds, where all misuses introduced during code integration
were already fixed.

Introduce family of xe_ASSERT macros that try to follow classic
assert() utility and can be compiled out on non-debug builds.

Macros are based on drm_WARN, but unlikely to origin, disallow
use in expressions since we will compile that code out.

As we are operating on the xe pointers, we can print additional
information about the device, like tile or GT identifier, that
is not available from generic WARN report:

[ ] xe 0000:00:02.0: [drm] Assertion `false` failed!
    graphics: Xe_LP 12.0 media: Xe_M 12.0 GT0
[ ] WARNING: CPU: 4 PID: 8442 at drivers/gpu/drm/xe/xe_device.c:280 xe_device_probe+0x2f5/0x4a0 [xe]
[ ] RIP: 0010:xe_device_probe+0x2f5/0x4a0 [xe]

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Francois Dugast <francois.dugast@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/xe/xe_assert.h | 47 ++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/xe_assert.h

diff --git a/drivers/gpu/drm/xe/xe_assert.h b/drivers/gpu/drm/xe/xe_assert.h
new file mode 100644
index 000000000000..65306768d637
--- /dev/null
+++ b/drivers/gpu/drm/xe/xe_assert.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#ifndef __XE_ASSERT_H__
+#define __XE_ASSERT_H__
+
+#if IS_ENABLED(CONFIG_DRM_XE_DEBUG)
+
+#define xe_ASSERT_MSG(xe, condition, fmt, arg...) ({						\
+	struct xe_device *__xe = (xe);								\
+	int __passed = !!(condition);								\
+	drm_WARN(&__xe->drm, !__passed, "[" DRM_NAME "] Assertion `%s` failed!\n"		\
+		 "graphics: %s %u.%u media: %s %u.%u " fmt,					\
+		 __stringify(condition),							\
+		 __xe->info.graphics_name,							\
+		 __xe->info.graphics_verx100 / 100, __xe->info.graphics_verx100 % 100,		\
+		 __xe->info.media_name,								\
+		 __xe->info.media_verx100 / 100, __xe->info.media_verx100 % 100,		\
+		 ## arg);									\
+	(void)(__passed);									\
+})
+
+#else
+
+#define xe_ASSERT_MSG(xe, condition, fmt, arg...) ({						\
+	typecheck(struct xe_device *, xe);							\
+	BUILD_BUG_ON_INVALID(condition);							\
+})
+
+#endif
+
+#define xe_ASSERT(xe, condition) \
+	xe_ASSERT_MSG((xe), condition, "")
+
+#define xe_tile_ASSERT(tile, condition) ({							\
+	struct xe_tile *__tile = (tile);							\
+	xe_ASSERT_MSG(tile_to_xe(__tile), condition, "tile%u ", __tile->id);			\
+})
+
+#define xe_gt_ASSERT(gt, condition) ({								\
+	struct xe_gt *__gt = (gt);								\
+	xe_ASSERT_MSG(gt_to_xe(__gt), condition, "GT%u ", __gt->info.id);			\
+})
+
+#endif /* __XE_ASSERT_H__ */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-08-04 20:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-28 19:25 [Intel-xe] [RFC] drm/xe: Introduce xe_ASSERT macros Michal Wajdeczko
2023-07-28 19:47 ` [Intel-xe] ✓ CI.Patch_applied: success for " Patchwork
2023-07-28 19:47 ` [Intel-xe] ✗ CI.checkpatch: warning " Patchwork
2023-07-28 19:47 ` [Intel-xe] [RFC] " Vivi, Rodrigo
2023-07-28 20:33   ` Michal Wajdeczko
2023-08-01  8:19     ` Jani Nikula
2023-08-04 20:47       ` Rodrigo Vivi
2023-07-28 19:48 ` [Intel-xe] ✓ CI.KUnit: success for " Patchwork
2023-07-28 19:52 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-07-28 19:52 ` [Intel-xe] ✓ CI.Hooks: " Patchwork
2023-07-28 19:53 ` [Intel-xe] ✓ CI.checksparse: " Patchwork
2023-07-28 20:26 ` [Intel-xe] ○ CI.BAT: info " Patchwork
2023-08-04  3:58 ` [Intel-xe] [RFC] " Matthew Brost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox