Skip to contentSkip to conversation

add ttm trace event support

RFC PATCH In review Kevin Wang 2 participants 6 messages Jan 28, 2021

Subsystems (3)
lore
Share & tools
lore

Kevin Wang

author
#0 lore raw

cover add ttm trace event support

the kernel ftrace can better help analyze the kernel running status. add some trace events to support TTM.

add trace events list:

ttm:ttm_bo_add_mem_to_lru
ttm:ttm_bo_del_from_lru
ttm:ttm_bo_move_mem
ttm:ttm_bo_wait
ttm:ttm_bo_evict
ttm:ttm_bo_swapout
ttm:ttm_bo_device_init
ttm:ttm_bo_device_release
ttm:ttm_bo_init_reserved
ttm:ttm_bo_validate
ttm:ttm_bo_release
ttm:ttm_bo_mmap
ttm:ttm_bo_vm_fault
ttm:ttm_bo_vm_access
ttm:ttm_shrink
ttm:ttm_mem_global_reserve
ttm:ttm_mem_global_free

Kevin Wang (3):
drm/ttm: add ttm bo trace event support
drm/ttm: add ttm vm bo trace event support
drm/ttm: add ttm mem trace event support

 drivers/gpu/drm/ttm/ttm_bo.c     |  23 ++
 drivers/gpu/drm/ttm/ttm_bo_vm.c  |  12 +-
 drivers/gpu/drm/ttm/ttm_memory.c |   7 +
 drivers/gpu/drm/ttm/ttm_module.c |   3 +
 drivers/gpu/drm/ttm/ttm_trace.h  | 469 +++++++++++++++++++++++++++++++
 5 files changed, 512 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/ttm/ttm_trace.h
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

RFC PATCH 1/3 drm/ttm: add ttm bo trace event support

add ttm bo related trace event support

trace events:
ttm:ttm_bo_add_mem_to_lru
ttm:ttm_bo_del_from_lru
ttm:ttm_bo_move_mem
ttm:ttm_bo_wait
ttm:ttm_bo_evict
ttm:ttm_bo_swapout
ttm:ttm_bo_device_init
ttm:ttm_bo_device_release
ttm:ttm_bo_init_reserved
ttm:ttm_bo_validate
ttm:ttm_bo_release

---
 drivers/gpu/drm/ttm/ttm_bo.c     |  23 +++
 drivers/gpu/drm/ttm/ttm_module.c |   3 +
 drivers/gpu/drm/ttm/ttm_trace.h  | 321 +++++++++++++++++++++++++++++++
 3 files changed, 347 insertions(+)
 create mode 100644 drivers/gpu/drm/ttm/ttm_trace.h
drivers/gpu/drm/ttm/ttm_bo.c +23 -0
index e3931e515906..074afd05aaa8 100644
@@ -43,6 +43,8 @@
 #include <linux/atomic.h>
 #include <linux/dma-resv.h>
 
+#include "ttm_trace.h"
+
 static void ttm_bo_global_kobj_release(struct kobject *kobj);
 
 /**
@@ -143,6 +145,8 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
 	if (mem->placement & TTM_PL_FLAG_NO_EVICT)
 		return;
 
+	trace_ttm_bo_add_mem_to_lru(bo, mem);
+
 	man = ttm_manager_type(bdev, mem->mem_type);
 	list_add_tail(&bo->lru, &man->lru[bo->priority]);
 
@@ -167,6 +171,8 @@ static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
 		notify = true;
 	}
 
+	trace_ttm_bo_del_from_lru(bo, notify);
+
 	if (notify && bdev->driver->del_from_lru_notify)
 		bdev->driver->del_from_lru_notify(bo);
 }
@@ -299,6 +305,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 		}
 	}
 
+	trace_ttm_bo_move_mem(bo, mem, evict);
+
 	if (bdev->driver->move_notify)
 		bdev->driver->move_notify(bo, evict, mem);
 
@@ -542,6 +550,8 @@ static void ttm_bo_release(struct kref *kref)
 	size_t acc_size = bo->acc_size;
 	int ret;
 
+	trace_ttm_bo_release(bo);
+
 	if (!bo->deleted) {
 		ret = ttm_bo_individualize_resv(bo);
 		if (ret) {
@@ -668,6 +678,8 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
 		ttm_resource_free(bo, &evict_mem);
 		goto out;
 	}
+
+	trace_ttm_bo_evict(bo, &evict_mem);
 	bo->evicted = true;
 out:
 	return ret;
@@ -1151,6 +1163,8 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 
 	dma_resv_assert_held(bo->base.resv);
 
+	trace_ttm_bo_validate(bo);
+
 	/*
 	 * Remove the backing store if no placement is given.
 	 */
@@ -1263,6 +1277,8 @@ int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
 	}
 	atomic_inc(&ttm_bo_glob.bo_count);
 
+	trace_ttm_bo_init_reserved(bo, size);
+
 	/*
 	 * For ttm_bo_type_device buffers, allocate
 	 * address space from the device.
@@ -1487,6 +1503,8 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 	if (!ret)
 		ttm_bo_global_release();
 
+	trace_ttm_bo_device_release(bdev);
+
 	return ret;
 }
 EXPORT_SYMBOL(ttm_bo_device_release);
@@ -1537,6 +1555,8 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 	list_add_tail(&bdev->device_list, &glob->device_list);
 	mutex_unlock(&ttm_global_mutex);
 
+	trace_ttm_bo_device_init(bdev);
+
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_device_init);
@@ -1580,6 +1600,8 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
 
 	timeout = dma_resv_wait_timeout_rcu(bo->base.resv, true,
 						      interruptible, timeout);
+
+	trace_ttm_bo_wait(bo, interruptible, timeout);
 	if (timeout < 0)
 		return timeout;
 
@@ -1670,6 +1692,7 @@ int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
 	 * anyone tries to access a ttm page.
 	 */
 
+	trace_ttm_bo_swapout(bo, i);
 	if (bo->bdev->driver->swap_notify)
 		bo->bdev->driver->swap_notify(bo);
 
drivers/gpu/drm/ttm/ttm_module.c +3 -0
index 6ff40c041d79..8b70e8aebecb 100644
@@ -35,6 +35,9 @@
 #include <drm/ttm/ttm_module.h>
 #include <drm/drm_sysfs.h>
 
+#define CREATE_TRACE_POINTS
+#include "ttm_trace.h"
+
 static DECLARE_WAIT_QUEUE_HEAD(exit_q);
 static atomic_t device_released;
 
drivers/gpu/drm/ttm/ttm_trace.h new file +321 -0

321 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#2 lore raw

RFC PATCH 2/3 drm/ttm: add ttm vm bo trace event support

In reply to Kevin Wang

add ttm bo VM related trace event support

trace events:
ttm:ttm_bo_mmap
ttm:ttm_bo_vm_fault
ttm:ttm_bo_vm_access

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c | 12 ++++-
 drivers/gpu/drm/ttm/ttm_trace.h | 78 +++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +10 -2
index 01693e8f24b7..aece2024c1fd 100644
@@ -42,6 +42,8 @@
 #include <linux/uaccess.h>
 #include <linux/mem_encrypt.h>
 
+#include "ttm_trace.h"
+
 static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
 				struct vm_fault *vmf)
 {
@@ -429,15 +431,17 @@ vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf)
 
 	ret = ttm_bo_vm_reserve(bo, vmf);
 	if (ret)
-		return ret;
+		goto out;
 
 	prot = vma->vm_page_prot;
 	ret = ttm_bo_vm_fault_reserved(vmf, prot, TTM_BO_VM_NUM_PREFAULT, 1);
 	if (ret == VM_FAULT_RETRY && !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT))
-		return ret;
+		goto out;
 
 	dma_resv_unlock(bo->base.resv);
 
+out:
+	trace_ttm_bo_vm_fault(bo, vmf, ret);
 	return ret;
 }
 EXPORT_SYMBOL(ttm_bo_vm_fault);
@@ -516,6 +520,8 @@ int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
 	if (ret)
 		return ret;
 
+	trace_ttm_bo_vm_access(bo, !!write, offset, len);
+
 	switch (bo->mem.mem_type) {
 	case TTM_PL_SYSTEM:
 		if (unlikely(bo->ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
@@ -618,6 +624,7 @@ int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
 		goto out_unref;
 
 	ttm_bo_mmap_vma_setup(bo, vma);
+	trace_ttm_bo_mmap(bo, vma);
 	return 0;
 out_unref:
 	ttm_bo_put(bo);
@@ -629,6 +636,7 @@ int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
 {
 	ttm_bo_get(bo);
 	ttm_bo_mmap_vma_setup(bo, vma);
+	trace_ttm_bo_mmap(bo, vma);
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_mmap_obj);
drivers/gpu/drm/ttm/ttm_trace.h +78 -0

90 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#3 lore raw

RFC PATCH 3/3 drm/ttm: add ttm mem trace event support

In reply to Kevin Wang

add ttm memory related trace event support

trace events:
ttm:ttm_shrink
ttm:ttm_mem_global_reserve
ttm:ttm_mem_global_free

---
 drivers/gpu/drm/ttm/ttm_memory.c |  7 ++++
 drivers/gpu/drm/ttm/ttm_trace.h  | 70 ++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
drivers/gpu/drm/ttm/ttm_memory.c +7 -0
index acd63b70d814..27470b1f1f13 100644
@@ -39,6 +39,8 @@
 #include <linux/slab.h>
 #include <linux/swap.h>
 
+#include "ttm_trace.h"
+
 #define TTM_MEMORY_ALLOC_RETRIES 4
 
 struct ttm_mem_global ttm_mem_glob;
@@ -272,6 +274,7 @@ static void ttm_shrink(struct ttm_mem_global *glob, bool from_wq,
 	int ret;
 
 	spin_lock(&glob->lock);
+	trace_ttm_shrink(from_wq, extra, ctx);
 
 	while (ttm_zones_above_swap_target(glob, from_wq, extra)) {
 		spin_unlock(&glob->lock);
@@ -518,6 +521,8 @@ static void ttm_mem_global_free_zone(struct ttm_mem_global *glob,
 		zone->used_mem -= amount;
 	}
 	spin_unlock(&glob->lock);
+	trace_ttm_mem_global_free(single_zone->name, amount,
+				  single_zone->used_mem, single_zone->max_mem);
 }
 
 void ttm_mem_global_free(struct ttm_mem_global *glob,
@@ -590,6 +595,8 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,
 	ret = 0;
 out_unlock:
 	spin_unlock(&glob->lock);
+	trace_ttm_mem_global_reserve(single_zone->name, amount,
+			      single_zone->used_mem, single_zone->max_mem);
 	ttm_check_swapping(glob);
 
 	return ret;
drivers/gpu/drm/ttm/ttm_trace.h +70 -0

76 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Kevin Wang

Not a bad start, but that needs quite some more work.

First of all please rebase on top of current drm-misc-next, a whole bunch of the stuff you want to trace here was already removed or is about to be removed.

Then concentrate on the necessary trace points, for example ttm:ttm_bo_device_init/release are overkill.

On the other hand I'm missing important events like pool shrink, tt swapout/swapin (ttm_bo_swapout can be dropped) and especially BO init.

I would separate the patches into one for each trace point. Not a must have, but it could make it easier to review and we can discuss for each one separately.

Thanks,
Christian.

Am 28.01.21 um 08:13 schrieb Kevin Wang:

Quoted 28 lines

the kernel ftrace can better help analyze the kernel running status. add some trace events to support TTM.

add trace events list:

ttm:ttm_bo_add_mem_to_lru
ttm:ttm_bo_del_from_lru
ttm:ttm_bo_move_mem
ttm:ttm_bo_wait
ttm:ttm_bo_evict
ttm:ttm_bo_swapout
ttm:ttm_bo_device_init
ttm:ttm_bo_device_release
ttm:ttm_bo_init_reserved
ttm:ttm_bo_validate
ttm:ttm_bo_release
ttm:ttm_bo_mmap
ttm:ttm_bo_vm_fault
ttm:ttm_bo_vm_access
ttm:ttm_shrink
ttm:ttm_mem_global_reserve
ttm:ttm_mem_global_free

Kevin Wang (3):
drm/ttm: add ttm bo trace event support
drm/ttm: add ttm vm bo trace event support
drm/ttm: add ttm mem trace event support

Quoted 8 lines
  drivers/gpu/drm/ttm/ttm_bo.c     |  23 ++
  drivers/gpu/drm/ttm/ttm_bo_vm.c  |  12 +-
  drivers/gpu/drm/ttm/ttm_memory.c |   7 +
  drivers/gpu/drm/ttm/ttm_module.c |   3 +
  drivers/gpu/drm/ttm/ttm_trace.h  | 469 +++++++++++++++++++++++++++++++
  5 files changed, 512 insertions(+), 2 deletions(-)

create mode 100644 drivers/gpu/drm/ttm/ttm_trace.h

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

[AMD Official Use Only - Internal Distribution Only]

thanks comments.

I will refine these patches, then send out review later.

Best Regards,
Kevin
________________________________
From: Christian König <[email protected]>
Sent: Thursday, January 28, 2021 3:46 PM
To: Wang, Kevin(Yang) <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Cc: Huang, Ray <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [RFC PATCH 0/3] add ttm trace event support

Not a bad start, but that needs quite some more work.

First of all please rebase on top of current drm-misc-next, a whole bunch of the stuff you want to trace here was already removed or is about to be removed.

Then concentrate on the necessary trace points, for example ttm:ttm_bo_device_init/release are overkill.

On the other hand I'm missing important events like pool shrink, tt swapout/swapin (ttm_bo_swapout can be dropped) and especially BO init.

I would separate the patches into one for each trace point. Not a must have, but it could make it easier to review and we can discuss for each one separately.

Thanks,
Christian.

Am 28.01.21 um 08:13 schrieb Kevin Wang:

Quoted 28 lines

the kernel ftrace can better help analyze the kernel running status. add some trace events to support TTM.

add trace events list:

ttm:ttm_bo_add_mem_to_lru
ttm:ttm_bo_del_from_lru
ttm:ttm_bo_move_mem
ttm:ttm_bo_wait
ttm:ttm_bo_evict
ttm:ttm_bo_swapout
ttm:ttm_bo_device_init
ttm:ttm_bo_device_release
ttm:ttm_bo_init_reserved
ttm:ttm_bo_validate
ttm:ttm_bo_release
ttm:ttm_bo_mmap
ttm:ttm_bo_vm_fault
ttm:ttm_bo_vm_access
ttm:ttm_shrink
ttm:ttm_mem_global_reserve
ttm:ttm_mem_global_free

Kevin Wang (3):
drm/ttm: add ttm bo trace event support
drm/ttm: add ttm vm bo trace event support
drm/ttm: add ttm mem trace event support

Quoted 8 lines
  drivers/gpu/drm/ttm/ttm_bo.c     |  23 ++
  drivers/gpu/drm/ttm/ttm_bo_vm.c  |  12 +-
  drivers/gpu/drm/ttm/ttm_memory.c |   7 +
  drivers/gpu/drm/ttm/ttm_module.c |   3 +
  drivers/gpu/drm/ttm/ttm_trace.h  | 469 +++++++++++++++++++++++++++++++
  5 files changed, 512 insertions(+), 2 deletions(-)

create mode 100644 drivers/gpu/drm/ttm/ttm_trace.h

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx