Skip to contentSkip to conversation

drm/xe: Make p2pdma distance check verbose via dynamic debug

PATCH Superseded Thomas Hellström 3 participants 4 messages Sep 14

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Thomas Hellström

author maintainer
#0 lore raw

PATCH 1/1 drm/xe: Make p2pdma distance check verbose via dynamic debug

pci_p2pdma_distance() can optionally print details about how it computed the ACS/PCIe topology distance between the two devices, but xe_dma_buf_attach() always called it with verbose set to false, silently hiding useful diagnostics whenever a dma-buf attach unset attach->peer2peer.

Tie the verbose argument to a dedicated dynamic-debug callsite tagged "xe dma-buf p2p debug" (in addition to keeping the existing DRM_UT_DRIVER category as a default), so the extra p2pdma distance logging can be switched on without a recompile in any of the following ways:

- Enable the whole DRIVER category for xe via drm.debug, which is already used elsewhere in the driver:

     # echo 0x10 > /sys/module/drm/parameters/debug

- Enable dynamic debug for the whole file:

     # echo 'file xe_dma_buf.c +p' > \
             /sys/kernel/debug/dynamic_debug/control

- Enable dynamic debug for just this callsite by function name:

     # echo 'func xe_dma_buf_attach +p' > \
             /sys/kernel/debug/dynamic_debug/control

- Enable dynamic debug by matching the format string used to register the callsite:

     # echo 'format "xe dma-buf p2p debug" +p' > \
             /sys/kernel/debug/dynamic_debug/control

- Enable it at boot via the dyndbg= kernel command line parameter:

dyndbg="func xe_dma_buf_attach +p"

Any of the above flips verbose_p2p_dist to true for that attach call, causing pci_p2pdma_distance() to log its distance calculation without requiring the whole DRM_UT_DRIVER category to be enabled.

Cc Matthew Brost <[email protected]>
Cc Matthew Auld <[email protected]>
Assisted-by LLM
---
 drivers/gpu/drm/xe/xe_dma_buf.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_dma_buf.c +9 -1
index 5d9f1cd24b7f..b63fd70fb4de 100644
@@ -22,13 +22,21 @@
 
 MODULE_IMPORT_NS("DMA_BUF");
 
+static void xe_ddebug_flip_bool(const struct _ddebug *desc, bool *flag)
+{
+	*flag = true;
+}
+
 static int xe_dma_buf_attach(struct dma_buf *dmabuf,
 			     struct dma_buf_attachment *attach)
 {
 	struct drm_gem_object *obj = attach->dmabuf->priv;
+	bool verbose_p2p_dist = drm_debug_enabled(DRM_UT_DRIVER);
+
+	_dynamic_func_call("xe dma-buf p2p debug", xe_ddebug_flip_bool, &verbose_p2p_dist);
 
 	if (attach->peer2peer &&
-	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, false) < 0)
+	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, verbose_p2p_dist) < 0)
 		attach->peer2peer = false;
 
 	if (!attach->peer2peer && !xe_bo_can_migrate(gem_to_xe_bo(obj), XE_PL_TT))
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Unconditional use of the internal `_dynamic_func_call` macro causes a build failure when…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Unconditional use of the internal _dynamic_func_call macro causes a build failure when CONFIG_DYNAMIC_DEBUG is disabled. --

commit 6e70a101effbf7ae91a2873e2642ceaadc4900a3
Author: Thomas Hellström <[email protected]>

drm/xe: Make p2pdma distance check verbose via dynamic debug

pci_p2pdma_distance() can optionally print details about how it computed the ACS/PCIe topology distance between the two devices. Tie the verbose argument to a dedicated dynamic-debug callsite tagged "xe dma-buf p2p debug" so the extra p2pdma distance logging can be switched on without a recompile.

Quoted 10 lines
drivers/gpu/drm/xe/xe_dma_buf.c +2 -0
index 5d9f1cd24b7f3..b63fd70fb4de9 100644
@@ -22,13 +22,21 @@
 
 MODULE_IMPORT_NS("DMA_BUF");
 
+static void xe_ddebug_flip_bool(const struct _ddebug *desc, bool *flag)
+{

drivers/gpu/drm/xe/xe_dma_buf.c line 36

Quoted 10 lines
drivers/gpu/drm/xe/xe_dma_buf.c +6 -0
+	*flag = true;
+}
+
 static int xe_dma_buf_attach(struct dma_buf *dmabuf,
 			     struct dma_buf_attachment *attach)
 {
 	struct drm_gem_object *obj = attach->dmabuf->priv;
+	bool verbose_p2p_dist = drm_debug_enabled(DRM_UT_DRIVER);
+
+	_dynamic_func_call("xe dma-buf p2p debug", xe_ddebug_flip_bool, &verbose_p2p_dist);
        ^^^^^^^^^^^^^^^^^^

[Severity: Low]
Does this unconditional use of the internal _dynamic_func_call macro cause a build failure when CONFIG_DYNAMIC_DEBUG is disabled?

Since _dynamic_func_call has no stub definition in the #else block of include/linux/dynamic_debug.h, compiling the xe driver with CONFIG_DRM_XE enabled but CONFIG_DYNAMIC_DEBUG disabled results in an implicit function declaration error.

If the macro call is guarded by an ifdef, does xe_ddebug_flip_bool() also need an ifdef guard or __maybe_unused to avoid a -Wunused-function warning?

Quoted 5 lines
drivers/gpu/drm/xe/xe_dma_buf.c +1 -1
 	if (attach->peer2peer &&
-	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, false) < 0)
+	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, verbose_p2p_dist) < 0)
 		attach->peer2peer = false;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Thomas Hellström
Quoted 33 lines · Thomas Hellström

pci_p2pdma_distance() can optionally print details about how it computed the ACS/PCIe topology distance between the two devices, but xe_dma_buf_attach() always called it with verbose set to false, silently hiding useful diagnostics whenever a dma-buf attach unset attach->peer2peer.

Tie the verbose argument to a dedicated dynamic-debug callsite tagged "xe dma-buf p2p debug" (in addition to keeping the existing DRM_UT_DRIVER category as a default), so the extra p2pdma distance logging can be switched on without a recompile in any of the following ways:

- Enable the whole DRIVER category for xe via drm.debug, which is already used elsewhere in the driver:

# echo 0x10 > /sys/module/drm/parameters/debug

- Enable dynamic debug for the whole file:

      # echo 'file xe_dma_buf.c +p' > \
              /sys/kernel/debug/dynamic_debug/control

- Enable dynamic debug for just this callsite by function name:

      # echo 'func xe_dma_buf_attach +p' > \
              /sys/kernel/debug/dynamic_debug/control

- Enable dynamic debug by matching the format string used to register the callsite:

# echo 'format "xe dma-buf p2p debug" +p' > \
/sys/kernel/debug/dynamic_debug/control

Quoted 7 lines

- Enable it at boot via the dyndbg= kernel command line parameter:

dyndbg="func xe_dma_buf_attach +p"

Any of the above flips verbose_p2p_dist to true for that attach call, causing pci_p2pdma_distance() to log its distance calculation without requiring the whole DRM_UT_DRIVER category to be enabled.

Is drm.debug not enough here for typical usescases? If you are interested in this you would maybe toggle that anyway, in case there is other interesting stuff? Or do you think the dynamic debug will be useful?

Quoted 5 lines
Cc Matthew Brost <[email protected]>
Cc Matthew Auld <[email protected]>
Assisted-by LLM

Either way,

(With the ifdef guard or so)

Quoted 31 lines
---
  drivers/gpu/drm/xe/xe_dma_buf.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_dma_buf.c +9 -1
index 5d9f1cd24b7f..b63fd70fb4de 100644
@@ -22,13 +22,21 @@
 
  MODULE_IMPORT_NS("DMA_BUF");
 
+static void xe_ddebug_flip_bool(const struct _ddebug *desc, bool *flag)
+{
+	*flag = true;
+}
+
  static int xe_dma_buf_attach(struct dma_buf *dmabuf,
  			     struct dma_buf_attachment *attach)
  {
  	struct drm_gem_object *obj = attach->dmabuf->priv;
+	bool verbose_p2p_dist = drm_debug_enabled(DRM_UT_DRIVER);
+
+	_dynamic_func_call("xe dma-buf p2p debug", xe_ddebug_flip_bool, &verbose_p2p_dist);
 
  	if (attach->peer2peer &&
-	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, false) < 0)
+	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach->dev, verbose_p2p_dist) < 0)
  		attach->peer2peer = false;
 
  	if (!attach->peer2peer && !xe_bo_can_migrate(gem_to_xe_bo(obj), XE_PL_TT))
author maintainer
#3 lore raw
Quoted 48 lines · Matthew Auld
Quoted 39 lines · Thomas Hellström

pci_p2pdma_distance() can optionally print details about how it computed the ACS/PCIe topology distance between the two devices, but
xe_dma_buf_attach() always called it with verbose set to false, silently hiding useful diagnostics whenever a dma-buf attach unset attach->peer2peer.

Tie the verbose argument to a dedicated dynamic-debug callsite tagged
"xe dma-buf p2p debug" (in addition to keeping the existing DRM_UT_DRIVER category as a default), so the extra p2pdma distance logging can be switched on without a recompile in any of the following
ways:

  - Enable the whole DRIVER category for xe via drm.debug, which is already used elsewhere in the driver:

      # echo 0x10 > /sys/module/drm/parameters/debug

  - Enable dynamic debug for the whole file:

      # echo 'file xe_dma_buf.c +p' > \
              /sys/kernel/debug/dynamic_debug/control

  - Enable dynamic debug for just this callsite by function name:

      # echo 'func xe_dma_buf_attach +p' > \
              /sys/kernel/debug/dynamic_debug/control

  - Enable dynamic debug by matching the format string used to register the callsite:

      # echo 'format "xe dma-buf p2p debug" +p' > \
              /sys/kernel/debug/dynamic_debug/control

  - Enable it at boot via the dyndbg= kernel command line parameter:

Quoted 7 lines

      dyndbg="func xe_dma_buf_attach +p"

Any of the above flips verbose_p2p_dist to true for that attach call,
causing pci_p2pdma_distance() to log its distance calculation without
requiring the whole DRM_UT_DRIVER category to be enabled.

Quoted 5 lines

Is drm.debug not enough here for typical usescases?  If you are interested in this you would maybe toggle that anyway, in case there is
other interesting stuff? Or do you think the dynamic debug will be useful?

There are cases where we just want to check just if p2p is enabled. And normally IIRC you can do this by targeting a separate pr_debug or drm_debug using dynamic debug. But since this one triggers printouts in the p2pdma code, it seems like this construct is neecessary.

Quoted 9 lines
Quoted 6 lines
Cc Matthew Brost <[email protected]>
Cc Matthew Auld <[email protected]>
Assisted-by LLM

Either way,

Thanks,
Thomas

Quoted 40 lines

(With the ifdef guard or so)

Quoted 37 lines

---
  drivers/gpu/drm/xe/xe_dma_buf.c | 10 +++++++++-

  1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_dma_buf.c +0 -0
index 5d9f1cd24b7f..b63fd70fb4de 100644
@@ -22,13 +22,21 @@


  MODULE_IMPORT_NS("DMA_BUF");

+static void xe_ddebug_flip_bool(const struct _ddebug *desc, bool *flag)

drivers/gpu/drm/xe/xe_dma_buf.c +4 -0
+{
+	*flag = true;
+}
+

  static int xe_dma_buf_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) {
   struct drm_gem_object *obj = attach->dmabuf->priv;

drivers/gpu/drm/xe/xe_dma_buf.c +3 -0
+	bool verbose_p2p_dist = drm_debug_enabled(DRM_UT_DRIVER);
+
+	_dynamic_func_call("xe dma-buf p2p debug",

xe_ddebug_flip_bool, &verbose_p2p_dist);

   if (attach->peer2peer &&

drivers/gpu/drm/xe/xe_dma_buf.c +0 -1
-	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach-
Quoted 1 line

dev, false) < 0)

drivers/gpu/drm/xe/xe_dma_buf.c +1 -0
+	    pci_p2pdma_distance(to_pci_dev(obj->dev->dev), attach-
Quoted 1 line

dev, verbose_p2p_dist) < 0)

   attach->peer2peer = false;

   if (!attach->peer2peer &&
!xe_bo_can_migrate(gem_to_xe_bo(obj), XE_PL_TT))