drm/amdgpu: make devcoredump reading fast
Subsystems (2)
PATCH 1/7 drm/amdgpu: make devcoredump reading fast
Update the way drm_coredump_printer is used based on its documentation and Xe's code: the main idea is to generate the final version in one go and then use memcpy to return the chunks requested by the caller of amdgpu_devcoredump_read.
This cuts the time to copy the dump from 40s to ~0s on my machine.
--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 43 +++++++++++++++++-- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 7 +++ 2 files changed, 46 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +39 -4
@@ -34,6 +34,8 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, }#else +#define AMDGPU_CORE_DUMP_SIZE_MAX (256 * 1024 * 1024) +const char *hw_ip_names[MAX_HWIP ] = { [GC_HWIP ] ="GC" , [HDP_HWIP] = "HDP",
@@ -196,11 +198,9 @@ static void amdgpu_devcoredump_fw_info(struct amdgpu_device *adev, }static ssize_t -amdgpu_devcoredump_read (char *buffer,loff_t offset,size_t count, -void *data,size_t datalen) +__amdgpu_devcoredump_read (char *buffer,size_t count,struct amdgpu_coredump_info *coredump) {struct drm_printer p; -struct amdgpu_coredump_info *coredump = data;struct drm_print_iterator iter;struct amdgpu_vm_fault_info *fault_info;struct amdgpu_ip_block *ip_block;
@@ -208,7 +208,6 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count, iter.data = buffer; iter.offset =0 ; - iter.start = offset; iter.remain = count; p =drm_coredump_printer (&iter);
@@ -321,8 +320,44 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count,return count - iter.remain; } +static ssize_t +amdgpu_devcoredump_read (char *buffer,loff_t offset,size_t count, +void *data,size_t datalen) +{ +struct amdgpu_coredump_info *coredump = data; +ssize_t byte_copied; + +if (!coredump) +return -ENODEV ; + +if (!coredump->read.buffer) { +/* Do a one-time preparation of the coredump output because +* repeatingly calling drm_coredump_printer is very slow. +*/ + coredump->read.size = +__amdgpu_devcoredump_read (NULL ,AMDGPU_CORE_DUMP_SIZE_MAX , coredump); + coredump->read.buffer =kvmalloc (coredump->read.size,GFP_USER ); +if (!coredump->read.buffer) +return -ENODEV ; + +__amdgpu_devcoredump_read (coredump->read.buffer, coredump->read.size, coredump); + } + +if (offset >= coredump->read.size) +return 0 ; + + byte_copied = count < coredump->read.size - offset ? count : + coredump->read.size - offset; +memcpy (buffer, coredump->read.buffer + offset, byte_copied); + +return byte_copied; +} +static void amdgpu_devcoredump_free (void *data) { +struct amdgpu_coredump_info *coredump = data; + +kvfree (coredump->read.buffer);kfree (data); }
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +7 -0
@@ -38,6 +38,13 @@ struct amdgpu_coredump_info {bool skip_vram_check;bool reset_vram_lost;struct amdgpu_ring *ring; +/* Readable form of coredevdump, generate once to speed up +* reading it (see drm_coredump_printer's documentation). +*/ +struct { +ssize_t size; +char *buffer; + } read; };#endif
Signature · 1 line
2.43.0
PATCH 2/7 drm/amdgpu: don't report stale vm_fault info in devcoredump
The coredump needs to contain accurate data and reporting a page fault from a previous issue is incorrect.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 13 ++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +8 -5
@@ -273,11 +273,13 @@ __amdgpu_devcoredump_read(char *buffer, size_t count, struct amdgpu_coredump_inf }/* Add page fault information */ - fault_info = &coredump->adev->vm_manager.fault_info; -drm_printf (&p,"\n[%s] Page fault observed\n" , - fault_info->vmhub ?"mmhub" :"gfxhub" ); -drm_printf (&p,"Faulty page starting at address: 0x%016llx\n" , fault_info->addr); -drm_printf (&p,"Protection fault status register: 0x%x\n\n" , fault_info->status); + fault_info = &coredump->fault_info; +if (fault_info->status !=0 ) { +drm_printf (&p,"\n[%s] Page fault observed\n" , + fault_info->vmhub ?"mmhub" :"gfxhub" ); +drm_printf (&p,"Faulty page starting at address: 0x%016llx\n" , fault_info->addr); +drm_printf (&p,"Protection fault status register: 0x%x\n\n" , fault_info->status); + }/* dump the ip state for each ip */ drm_printf (&p,"IP Dump\n" );
@@ -377,6 +379,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->skip_vram_check = skip_vram_check; coredump->reset_vram_lost = vram_lost; + coredump->fault_info = adev->vm_manager.fault_info;if (job && job->pasid) {struct amdgpu_task_info *ti;
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +1 -0
@@ -37,6 +37,7 @@ struct amdgpu_coredump_info {struct timespec64 reset_time;bool skip_vram_check;bool reset_vram_lost; +struct amdgpu_vm_fault_info fault_info;struct amdgpu_ring *ring;/* Readable form of coredevdump, generate once to speed up * reading it (see drm_coredump_printer's documentation).
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5 -0
@@ -199,6 +199,11 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) exit:drm_dev_exit (idx); + +/* Clear fault info to avoid reporting the same fault. */ + adev->vm_manager.fault_info.status =0 ; + adev->vm_manager.fault_info.addr =0 ; +return DRM_GPU_SCHED_STAT_NOMINAL ; }
Signature · 1 line
2.43.0
Christian König
maintainerRe: [PATCH v1 2/7] drm/amdgpu: don't report stale vm_fault info in devcoredump
Quoted 58 lines · Pierre-Eric Pelloux-Prayer
The coredump needs to contain accurate data and reporting a page fault from a previous issue is incorrect.
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 13 ++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +8
-5@@ -273,11 +273,13 @@ __amdgpu_devcoredump_read(char *buffer, size_t count, struct amdgpu_coredump_inf }/* Add page fault information */ - fault_info = &coredump->adev->vm_manager.fault_info; -drm_printf (&p,"\n[%s] Page fault observed\n" , - fault_info->vmhub ?"mmhub" :"gfxhub" ); -drm_printf (&p,"Faulty page starting at address: 0x%016llx\n" , fault_info->addr); -drm_printf (&p,"Protection fault status register: 0x%x\n\n" , fault_info->status); + fault_info = &coredump->fault_info; +if (fault_info->status !=0 ) { +drm_printf (&p,"\n[%s] Page fault observed\n" , + fault_info->vmhub ?"mmhub" :"gfxhub" ); +drm_printf (&p,"Faulty page starting at address: 0x%016llx\n" , fault_info->addr); +drm_printf (&p,"Protection fault status register: 0x%x\n\n" , fault_info->status); + }/* dump the ip state for each ip */ drm_printf (&p,"IP Dump\n" );@@ -377,6 +379,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->skip_vram_check = skip_vram_check; coredump->reset_vram_lost = vram_lost; + coredump->fault_info = adev->vm_manager.fault_info;if (job && job->pasid) {struct amdgpu_task_info *ti;drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +1
-0@@ -37,6 +37,7 @@ struct amdgpu_coredump_info {struct timespec64 reset_time;bool skip_vram_check;bool reset_vram_lost; +struct amdgpu_vm_fault_info fault_info;struct amdgpu_ring *ring;/* Readable form of coredevdump, generate once to speed up * reading it (see drm_coredump_printer's documentation). drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) · line 206
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +5
-0@@ -199,6 +199,11 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job) exit:drm_dev_exit (idx); + +/* Clear fault info to avoid reporting the same fault. */ + adev->vm_manager.fault_info.status =0 ; + adev->vm_manager.fault_info.addr =0 ; +
That needs to come much earlier and prefereable while holding a lock.
Apart from that looks good to me.
Christian.
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +0
-0return DRM_GPU_SCHED_STAT_NOMINAL ; }
PATCH 3/7 drm/amdgpu: always keep the latest coredump
In reply to Pierre-Eric Pelloux-PrayerCoredumps are automatically removed after 5 minutes, but if a new one is created while one exists already, the new one is discarded silently.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +5 -0
@@ -400,6 +400,11 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,ktime_get_ts64 (&coredump->reset_time); +/* Delete the previous coredump if any, otherwise dev_coredumpm will fail silently +* and the older one will be kept. +*/ +dev_coredump_put (dev->dev); +dev_coredumpm (dev->dev,THIS_MODULE , coredump,0 ,GFP_NOWAIT , amdgpu_devcoredump_read, amdgpu_devcoredump_free);
Signature · 1 line
2.43.0
PATCH 4/7 Revert "drm/amdgpu: add the evf attached gem obj resv dump"
In reply to Pierre-Eric Pelloux-PrayerThis reverts commit b75818d0d28f1e06ca396cc2b8a38601b44c4788.
dma_resv_describe outputs new lines so it breaks the "one line per BO" formatting.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -5
@@ -1645,11 +1645,7 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)amdgpu_bo_print_flag (m, bo,VRAM_CONTIGUOUS );amdgpu_bo_print_flag (m, bo,VM_ALWAYS_VALID );amdgpu_bo_print_flag (m, bo,EXPLICIT_SYNC ); -/* Add the gem obj resv fence dump*/ -if (dma_resv_trylock (bo->tbo.base.resv)) { -dma_resv_describe (bo->tbo.base.resv, m); -dma_resv_unlock (bo->tbo.base.resv); - } +seq_puts (m,"\n" );return size;
Signature · 1 line
2.43.0
PATCH 5/7 drm/amdgpu: port some debugfs function to drm_printer
In reply to Pierre-Eric Pelloux-PrayerUsing the drm_printer interface will allow us to use these functions when generating the coredump.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 38 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 42 ++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 5 +-- 6 files changed, 52 insertions(+), 48 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +4 -1
@@ -1773,12 +1773,15 @@ static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused)struct amdgpu_device *adev = m->private;struct drm_device *dev =adev_to_drm (adev);struct drm_file *file; +struct drm_printer p;int r; r =mutex_lock_interruptible (&dev->filelist_mutex);if (r)return r; + p =drm_seq_file_printer (m); +list_for_each_entry (file, &dev->filelist, lhead) {struct amdgpu_fpriv *fpriv = file->driver_priv;struct amdgpu_vm *vm = &fpriv->vm;
@@ -1793,7 +1796,7 @@ static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused) r =amdgpu_bo_reserve (vm->root.bo, true);if (r)break ; -amdgpu_debugfs_vm_bo_info (vm, m); +amdgpu_debugfs_vm_bo_info (vm, &p);amdgpu_bo_unreserve (vm->root.bo); }
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4 -1
@@ -1141,12 +1141,15 @@ static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)struct amdgpu_device *adev = m->private;struct drm_device *dev =adev_to_drm (adev);struct drm_file *file; +struct drm_printer p;int r; r =mutex_lock_interruptible (&dev->filelist_mutex);if (r)return r; + p =drm_seq_file_printer (m); +list_for_each_entry (file, &dev->filelist, lhead) {struct task_struct *task;struct drm_gem_object *gobj;
@@ -1170,7 +1173,7 @@ static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)idr_for_each_entry (&file->object_idr, gobj, id) {struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); -amdgpu_bo_print_info (id, bo, m); +amdgpu_bo_print_info (id, bo, &p); }spin_unlock (&file->table_lock); }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +18 -20
@@ -1553,27 +1553,26 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,return domain; } -#if defined(CONFIG_DEBUG_FS ) -#define amdgpu_bo_print_flag (m, bo, flag) \ +#define amdgpu_bo_print_flag (p, bo, flag) \ do { \ if (bo->flags & (AMDGPU_GEM_CREATE_ ## flag)) { \ - seq_printf((m), " " #flag); \ + drm_printf((p), " " #flag); \ } \ } while (0)/** -* amdgpu_bo_print_info - print BO info in debugfs file +* amdgpu_bo_print_info - print BO info in printer * * @id: Index or Id of the BO * @bo: Requested BO for printing info -* @m: debugfs file +* @p: drm_printer to use * * Print BO information in debugfs file * * Returns: * Size of the BO in bytes. */ -u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct seq_file *m) +u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct drm_printer *p) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct dma_buf_attachment *attachment;
@@ -1623,31 +1622,30 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m) } size =amdgpu_bo_size (bo); -seq_printf (m,"\t\t0x%08x: %12lld byte %s" , - id, size, placement); +drm_printf (p,"\t\t0x%08x: %12lld byte %s" , + id, size, placement); pin_count =READ_ONCE (bo->tbo.pin_count);if (pin_count) -seq_printf (m," pin count %d" , pin_count); +drm_printf (p," pin count %d" , pin_count); dma_buf =READ_ONCE (bo->tbo.base.dma_buf); attachment =READ_ONCE (bo->tbo.base.import_attach);if (attachment) -seq_printf (m," imported from ino:%lu" ,file_inode (dma_buf->file)->i_ino); +drm_printf (p," imported from ino:%lu" ,file_inode (dma_buf->file)->i_ino);else if (dma_buf) -seq_printf (m," exported as ino:%lu" ,file_inode (dma_buf->file)->i_ino); +drm_printf (p," exported as ino:%lu" ,file_inode (dma_buf->file)->i_ino); -amdgpu_bo_print_flag (m, bo,CPU_ACCESS_REQUIRED ); -amdgpu_bo_print_flag (m, bo,NO_CPU_ACCESS ); -amdgpu_bo_print_flag (m, bo,CPU_GTT_USWC ); -amdgpu_bo_print_flag (m, bo,VRAM_CLEARED ); -amdgpu_bo_print_flag (m, bo,VRAM_CONTIGUOUS ); -amdgpu_bo_print_flag (m, bo,VM_ALWAYS_VALID ); -amdgpu_bo_print_flag (m, bo,EXPLICIT_SYNC ); +amdgpu_bo_print_flag (p, bo,CPU_ACCESS_REQUIRED ); +amdgpu_bo_print_flag (p, bo,NO_CPU_ACCESS ); +amdgpu_bo_print_flag (p, bo,CPU_GTT_USWC ); +amdgpu_bo_print_flag (p, bo,VRAM_CLEARED ); +amdgpu_bo_print_flag (p, bo,VRAM_CONTIGUOUS ); +amdgpu_bo_print_flag (p, bo,VM_ALWAYS_VALID ); +amdgpu_bo_print_flag (p, bo,EXPLICIT_SYNC ); -seq_puts (m,"\n" ); +drm_puts (p,"\n" );return size; } -#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +4 -1
@@ -139,6 +139,8 @@ struct amdgpu_bo_vm {struct amdgpu_vm_bo_base entries[]; }; +struct drm_printer ; +static inline struct amdgpu_bo *ttm_to_amdgpu_bo (struct ttm_buffer_object *tbo) { return container_of(tbo, struct amdgpu_bo, tbo);
@@ -345,8 +347,9 @@ void amdgpu_sa_bo_free(struct drm_suballoc **sa_bo,#if defined(CONFIG_DEBUG_FS )void amdgpu_sa_bo_dump_debug_info (struct amdgpu_sa_manager *sa_manager,struct seq_file *m); -u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct seq_file *m);#endif +u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct drm_printer *p); +void amdgpu_debugfs_sa_init (struct amdgpu_device *adev);bool amdgpu_bo_support_uswc (u64 bo_flags);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +20 -22
110 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -3
@@ -43,6 +43,7 @@ struct amdgpu_bo_va;struct amdgpu_job ;struct amdgpu_bo_list_entry ;struct amdgpu_bo_vm ; +struct drm_printer ;/* * GPUVM handling
@@ -598,9 +599,7 @@ void amdgpu_vm_pt_free_work(struct work_struct *work);void amdgpu_vm_pt_free_list (struct amdgpu_device *adev,struct amdgpu_vm_update_params *params); -#if defined(CONFIG_DEBUG_FS ) -void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct seq_file *m); -#endif +void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct drm_printer *p);int amdgpu_vm_pt_map_tables (struct amdgpu_device *adev,struct amdgpu_vm *vm);
Signature · 1 line
2.43.0
Christian König
maintainerRe: [PATCH v1 5/7] drm/amdgpu: port some debugfs function to drm_printer
Quoted 2 lines · Pierre-Eric Pelloux-Prayer
Using the
drm_printerinterface will allow us to use these functions when generating the coredump.
This change in general is harmless, but you must be extremely careful to not grab locks in the core dump which somebody could hold while waiting for a reset to complete.
For example any BO lock is an absolute no-go.
Regards,
Christian.
Quoted 314 lines
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 38 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 42 ++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 5 +-- 6 files changed, 52 insertions(+), 48 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +4
-1@@ -1773,12 +1773,15 @@ static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused)struct amdgpu_device *adev = m->private;struct drm_device *dev =adev_to_drm (adev);struct drm_file *file; +struct drm_printer p;int r; r =mutex_lock_interruptible (&dev->filelist_mutex);if (r)return r; + p =drm_seq_file_printer (m); +list_for_each_entry (file, &dev->filelist, lhead) {struct amdgpu_fpriv *fpriv = file->driver_priv;struct amdgpu_vm *vm = &fpriv->vm;@@ -1793,7 +1796,7 @@ static int amdgpu_debugfs_vm_info_show(struct seq_file *m, void *unused) r =amdgpu_bo_reserve (vm->root.bo, true);if (r)break ; -amdgpu_debugfs_vm_bo_info (vm, m); +amdgpu_debugfs_vm_bo_info (vm, &p);amdgpu_bo_unreserve (vm->root.bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4
-1@@ -1141,12 +1141,15 @@ static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)struct amdgpu_device *adev = m->private;struct drm_device *dev =adev_to_drm (adev);struct drm_file *file; +struct drm_printer p;int r; r =mutex_lock_interruptible (&dev->filelist_mutex);if (r)return r; + p =drm_seq_file_printer (m); +list_for_each_entry (file, &dev->filelist, lhead) {struct task_struct *task;struct drm_gem_object *gobj;@@ -1170,7 +1173,7 @@ static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)idr_for_each_entry (&file->object_idr, gobj, id) {struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); -amdgpu_bo_print_info (id, bo, m); +amdgpu_bo_print_info (id, bo, &p); }spin_unlock (&file->table_lock); }drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +18
-20@@ -1553,27 +1553,26 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,return domain; } -#if defined(CONFIG_DEBUG_FS ) -#define amdgpu_bo_print_flag (m, bo, flag) \ +#define amdgpu_bo_print_flag (p, bo, flag) \ do { \ if (bo->flags & (AMDGPU_GEM_CREATE_ ## flag)) { \ - seq_printf((m), " " #flag); \ + drm_printf((p), " " #flag); \ } \ } while (0)/** -* amdgpu_bo_print_info - print BO info in debugfs file +* amdgpu_bo_print_info - print BO info in printer * * @id: Index or Id of the BO * @bo: Requested BO for printing info -* @m: debugfs file +* @p: drm_printer to use * * Print BO information in debugfs file * * Returns: * Size of the BO in bytes. */ -u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct seq_file *m) +u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct drm_printer *p) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct dma_buf_attachment *attachment;@@ -1623,31 +1622,30 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m) } size =amdgpu_bo_size (bo); -seq_printf (m,"\t\t0x%08x: %12lld byte %s" , - id, size, placement); +drm_printf (p,"\t\t0x%08x: %12lld byte %s" , + id, size, placement); pin_count =READ_ONCE (bo->tbo.pin_count);if (pin_count) -seq_printf (m," pin count %d" , pin_count); +drm_printf (p," pin count %d" , pin_count); dma_buf =READ_ONCE (bo->tbo.base.dma_buf); attachment =READ_ONCE (bo->tbo.base.import_attach);if (attachment) -seq_printf (m," imported from ino:%lu" ,file_inode (dma_buf->file)->i_ino); +drm_printf (p," imported from ino:%lu" ,file_inode (dma_buf->file)->i_ino);else if (dma_buf) -seq_printf (m," exported as ino:%lu" ,file_inode (dma_buf->file)->i_ino); +drm_printf (p," exported as ino:%lu" ,file_inode (dma_buf->file)->i_ino); -amdgpu_bo_print_flag (m, bo,CPU_ACCESS_REQUIRED ); -amdgpu_bo_print_flag (m, bo,NO_CPU_ACCESS ); -amdgpu_bo_print_flag (m, bo,CPU_GTT_USWC ); -amdgpu_bo_print_flag (m, bo,VRAM_CLEARED ); -amdgpu_bo_print_flag (m, bo,VRAM_CONTIGUOUS ); -amdgpu_bo_print_flag (m, bo,VM_ALWAYS_VALID ); -amdgpu_bo_print_flag (m, bo,EXPLICIT_SYNC ); +amdgpu_bo_print_flag (p, bo,CPU_ACCESS_REQUIRED ); +amdgpu_bo_print_flag (p, bo,NO_CPU_ACCESS ); +amdgpu_bo_print_flag (p, bo,CPU_GTT_USWC ); +amdgpu_bo_print_flag (p, bo,VRAM_CLEARED ); +amdgpu_bo_print_flag (p, bo,VRAM_CONTIGUOUS ); +amdgpu_bo_print_flag (p, bo,VM_ALWAYS_VALID ); +amdgpu_bo_print_flag (p, bo,EXPLICIT_SYNC ); -seq_puts (m,"\n" ); +drm_puts (p,"\n" );return size; } -#endif drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +4
-1@@ -139,6 +139,8 @@ struct amdgpu_bo_vm {struct amdgpu_vm_bo_base entries[]; }; +struct drm_printer ; +static inline struct amdgpu_bo *ttm_to_amdgpu_bo (struct ttm_buffer_object *tbo) { return container_of(tbo, struct amdgpu_bo, tbo);@@ -345,8 +347,9 @@ void amdgpu_sa_bo_free(struct drm_suballoc **sa_bo,#if defined(CONFIG_DEBUG_FS )void amdgpu_sa_bo_dump_debug_info (struct amdgpu_sa_manager *sa_manager,struct seq_file *m); -u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct seq_file *m);#endif +u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct drm_printer *p); +void amdgpu_debugfs_sa_init (struct amdgpu_device *adev);bool amdgpu_bo_support_uswc (u64 bo_flags);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +20
-22@@ -2990,16 +2990,15 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,return false; } -#if defined(CONFIG_DEBUG_FS )/** * amdgpu_debugfs_vm_bo_info - print BO info for the VM * * @vm: Requested VM for printing BO info -* @m: debugfs file +* @p: the drm_printer to use * * Print BO information in debugfs file for the VM */ -void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct seq_file *m) +void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct drm_printer *p) {struct amdgpu_bo_va *bo_va, *tmp;u64 total_idle =0 ;@@ -3017,74 +3016,73 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m)unsigned int id =0 ;spin_lock (&vm->status_lock); -seq_puts (m,"\tIdle BOs:\n" ); +drm_puts (p,"\tIdle BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->idle, base.vm_status) {if (!bo_va->base.bo)continue ; - total_idle +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); + total_idle +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); } total_idle_objs = id; id =0 ; -seq_puts (m,"\tEvicted BOs:\n" ); +drm_puts (p,"\tEvicted BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->evicted, base.vm_status) {if (!bo_va->base.bo)continue ; - total_evicted +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); + total_evicted +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); } total_evicted_objs = id; id =0 ; -seq_puts (m,"\tRelocated BOs:\n" ); +drm_puts (p,"\tRelocated BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->relocated, base.vm_status) {if (!bo_va->base.bo)continue ; - total_relocated +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); + total_relocated +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); } total_relocated_objs = id; id =0 ; -seq_puts (m,"\tMoved BOs:\n" ); +drm_puts (p,"\tMoved BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->moved, base.vm_status) {if (!bo_va->base.bo)continue ; - total_moved +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); + total_moved +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); } total_moved_objs = id; id =0 ; -seq_puts (m,"\tInvalidated BOs:\n" ); +drm_puts (p,"\tInvalidated BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ; - total_invalidated +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); + total_invalidated +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); } total_invalidated_objs = id; id =0 ; -seq_puts (m,"\tDone BOs:\n" ); +drm_puts (p,"\tDone BOs:\n" );list_for_each_entry_safe (bo_va, tmp, &vm->done, base.vm_status) {if (!bo_va->base.bo)continue ; - total_done +=amdgpu_bo_print_info (id++, bo_va->base.bo, m); + total_done +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); }spin_unlock (&vm->status_lock); total_done_objs = id; -seq_printf (m,"\tTotal idle size: %12lld\tobjs:\t%d\n" , total_idle, +drm_printf (p,"\tTotal idle size: %12lld\tobjs:\t%d\n" , total_idle, total_idle_objs); -seq_printf (m,"\tTotal evicted size: %12lld\tobjs:\t%d\n" , total_evicted, +drm_printf (p,"\tTotal evicted size: %12lld\tobjs:\t%d\n" , total_evicted, total_evicted_objs); -seq_printf (m,"\tTotal relocated size: %12lld\tobjs:\t%d\n" , total_relocated, +drm_printf (p,"\tTotal relocated size: %12lld\tobjs:\t%d\n" , total_relocated, total_relocated_objs); -seq_printf (m,"\tTotal moved size: %12lld\tobjs:\t%d\n" , total_moved, +drm_printf (p,"\tTotal moved size: %12lld\tobjs:\t%d\n" , total_moved, total_moved_objs); -seq_printf (m,"\tTotal invalidated size: %12lld\tobjs:\t%d\n" , total_invalidated, +drm_printf (p,"\tTotal invalidated size: %12lld\tobjs:\t%d\n" , total_invalidated, total_invalidated_objs); -seq_printf (m,"\tTotal done size: %12lld\tobjs:\t%d\n" , total_done, +drm_printf (p,"\tTotal done size: %12lld\tobjs:\t%d\n" , total_done, total_done_objs); } -#endif /** * amdgpu_vm_update_fault_cache - update cached fault into. drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2
-3@@ -43,6 +43,7 @@ struct amdgpu_bo_va;struct amdgpu_job ;struct amdgpu_bo_list_entry ;struct amdgpu_bo_vm ; +struct drm_printer ;/* * GPUVM handling @@ -598,9 +599,7 @@ void amdgpu_vm_pt_free_work(struct work_struct *work);void amdgpu_vm_pt_free_list (struct amdgpu_device *adev,struct amdgpu_vm_update_params *params); -#if defined(CONFIG_DEBUG_FS ) -void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct seq_file *m); -#endif +void amdgpu_debugfs_vm_bo_info (struct amdgpu_vm *vm,struct drm_printer *p);int amdgpu_vm_pt_map_tables (struct amdgpu_device *adev,struct amdgpu_vm *vm);
PATCH 6/7 drm/amdgpu: add VA ranges to amdgpu_bo_print_info output
In reply to Pierre-Eric Pelloux-PrayerThis information is useful when investigating page faults.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 25 +++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 12 +++++------ 4 files changed, 33 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -1
@@ -1173,7 +1173,7 @@ static int amdgpu_debugfs_gem_info_show(struct seq_file *m, void *unused)idr_for_each_entry (&file->object_idr, gobj, id) {struct amdgpu_bo *bo =gem_to_amdgpu_bo (gobj); -amdgpu_bo_print_info (id, bo, &p); +amdgpu_bo_print_info (id, bo,NULL , &p); }spin_unlock (&file->table_lock); }
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +24 -1
@@ -1565,6 +1565,7 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,* * @id: Index or Id of the BO * @bo: Requested BO for printing info +* @bo_va: optional VA allocations for the BO * @p: drm_printer to use * * Print BO information in debugfs file
@@ -1572,7 +1573,8 @@ uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,* Returns: * Size of the BO in bytes. */ -u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct drm_printer *p) +u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct amdgpu_bo_va *bo_va, +struct drm_printer *p) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct dma_buf_attachment *attachment;
@@ -1645,6 +1647,27 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct drm_printer *p)amdgpu_bo_print_flag (p, bo,VM_ALWAYS_VALID );amdgpu_bo_print_flag (p, bo,EXPLICIT_SYNC ); +if (dma_resv_trylock (bo->tbo.base.resv)) { +if (bo_va) { +struct amdgpu_bo_va_mapping *mapping; + +drm_puts (p," VA:[ " ); +list_for_each_entry (mapping, &bo_va->valids, list) { +drm_printf (p,"0x%llx-0x%llx " , + mapping->start *AMDGPU_GPU_PAGE_SIZE , + (mapping->last +1 ) *AMDGPU_GPU_PAGE_SIZE -1 ); + } +list_for_each_entry (mapping, &bo_va->invalids, list) { +drm_printf (p,"0x%llx-0x%llx! " , + mapping->start *AMDGPU_GPU_PAGE_SIZE , + (mapping->last +1 ) *AMDGPU_GPU_PAGE_SIZE -1 ); + } +drm_puts (p,"]" ); + } + +dma_resv_unlock (bo->tbo.base.resv); + } +drm_puts (p,"\n" );return size;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -1
@@ -348,7 +348,8 @@ void amdgpu_sa_bo_free(struct drm_suballoc **sa_bo,void amdgpu_sa_bo_dump_debug_info (struct amdgpu_sa_manager *sa_manager,struct seq_file *m);#endif -u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct drm_printer *p); +u64 amdgpu_bo_print_info (int id,struct amdgpu_bo *bo,struct amdgpu_bo_va *bo_va, +struct drm_printer *p);void amdgpu_debugfs_sa_init (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6 -6
@@ -3020,7 +3020,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct drm_printer *p)list_for_each_entry_safe (bo_va, tmp, &vm->idle, base.vm_status) {if (!bo_va->base.bo)continue ; - total_idle +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); + total_idle +=amdgpu_bo_print_info (id++, bo_va->base.bo, bo_va, p); } total_idle_objs = id; id =0 ;
@@ -3029,7 +3029,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct drm_printer *p)list_for_each_entry_safe (bo_va, tmp, &vm->evicted, base.vm_status) {if (!bo_va->base.bo)continue ; - total_evicted +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); + total_evicted +=amdgpu_bo_print_info (id++, bo_va->base.bo, bo_va, p); } total_evicted_objs = id; id =0 ;
@@ -3038,7 +3038,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct drm_printer *p)list_for_each_entry_safe (bo_va, tmp, &vm->relocated, base.vm_status) {if (!bo_va->base.bo)continue ; - total_relocated +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); + total_relocated +=amdgpu_bo_print_info (id++, bo_va->base.bo, bo_va, p); } total_relocated_objs = id; id =0 ;
@@ -3047,7 +3047,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct drm_printer *p)list_for_each_entry_safe (bo_va, tmp, &vm->moved, base.vm_status) {if (!bo_va->base.bo)continue ; - total_moved +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); + total_moved +=amdgpu_bo_print_info (id++, bo_va->base.bo, bo_va, p); } total_moved_objs = id; id =0 ;
@@ -3056,7 +3056,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct drm_printer *p)list_for_each_entry_safe (bo_va, tmp, &vm->invalidated, base.vm_status) {if (!bo_va->base.bo)continue ; - total_invalidated +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); + total_invalidated +=amdgpu_bo_print_info (id++, bo_va->base.bo, bo_va, p); } total_invalidated_objs = id; id =0 ;
@@ -3065,7 +3065,7 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct drm_printer *p)list_for_each_entry_safe (bo_va, tmp, &vm->done, base.vm_status) {if (!bo_va->base.bo)continue ; - total_done +=amdgpu_bo_print_info (id++, bo_va->base.bo, p); + total_done +=amdgpu_bo_print_info (id++, bo_va->base.bo, bo_va, p); }spin_unlock (&vm->status_lock); total_done_objs = id;
Signature · 1 line
2.43.0
PATCH 7/7 drm/amdgpu: include BO dump into coredump
In reply to Pierre-Eric Pelloux-PrayerIt can be useful when getting a page fault.
--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 36 +++++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 1 + 2 files changed, 37 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +36 -0
@@ -319,6 +319,11 @@ __amdgpu_devcoredump_read(char *buffer, size_t count, struct amdgpu_coredump_infelse if (coredump->reset_vram_lost)drm_printf (&p,"VRAM is lost due to GPU reset!\n" ); +if (coredump->vm_dump) { +drm_puts (&p,"\nVM Dump\n" ); +drm_puts (&p, coredump->vm_dump); + } +return count - iter.remain; }
@@ -360,6 +365,7 @@ static void amdgpu_devcoredump_free(void *data)struct amdgpu_coredump_info *coredump = data;kvfree (coredump->read.buffer); +kvfree (coredump->vm_dump);kfree (data); }
@@ -383,12 +389,42 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,if (job && job->pasid) {struct amdgpu_task_info *ti; +struct amdgpu_vm *vm; +unsigned long flags; ti =amdgpu_vm_get_task_info_pasid (adev, job->pasid);if (ti) { coredump->reset_task_info = *ti;amdgpu_vm_put_task_info (ti); } + +xa_lock_irqsave (&adev->vm_manager.pasids, flags); + vm =xa_load (&adev->vm_manager.pasids, job->pasid); +xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); + +if (vm &&amdgpu_bo_reserve (vm->root.bo, true) ==0 ) { +struct drm_printer p; +struct drm_print_iterator iter; +ssize_t vm_dump_size; + + iter.data =NULL ; + iter.offset =0 ; + iter.remain =AMDGPU_CORE_DUMP_SIZE_MAX ; + + p =drm_coredump_printer (&iter); +amdgpu_debugfs_vm_bo_info (vm, &p); + + vm_dump_size =AMDGPU_CORE_DUMP_SIZE_MAX - iter.remain; + coredump->vm_dump =kvmalloc (vm_dump_size,GFP_USER ); +if (coredump->vm_dump) { + iter.remain = vm_dump_size; + iter.data = coredump->vm_dump; + p =drm_coredump_printer (&iter); +amdgpu_debugfs_vm_bo_info (vm, &p); + } + +amdgpu_bo_unreserve (vm->root.bo); + } }if (job) {
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +1 -0
@@ -39,6 +39,7 @@ struct amdgpu_coredump_info {bool reset_vram_lost;struct amdgpu_vm_fault_info fault_info;struct amdgpu_ring *ring; +char *vm_dump;/* Readable form of coredevdump, generate once to speed up * reading it (see drm_coredump_printer's documentation). */
Signature · 1 line
2.43.0
Christian König
maintainerQuoted 6 lines · Pierre-Eric Pelloux-Prayer
Update the way
drm_coredump_printeris used based on its documentation and Xe's code: the main idea is to generate the final version in one go and then use memcpy to return the chunks requested by the caller ofamdgpu_devcoredump_read.This cuts the time to copy the dump from 40s to ~0s on my machine.
Well that indeed strongly sounds like something is going wrong, but I'm pretty sure that copying things into a temporary buffer is not the right solution.
My educated guess is that userspace reads the core dump in chunks of pages (or similar). So we end up generating the same dump over and over again and then returning only like 4k of it at a time.
How do you copy the core dump on your box?
Regards,
Christian.
Quoted 103 lines
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 43 +++++++++++++++++-- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 7 +++ 2 files changed, 46 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +39
-4@@ -34,6 +34,8 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, }#else +#define AMDGPU_CORE_DUMP_SIZE_MAX (256 * 1024 * 1024) +const char *hw_ip_names[MAX_HWIP ] = { [GC_HWIP ] ="GC" , [HDP_HWIP] = "HDP",@@ -196,11 +198,9 @@ static void amdgpu_devcoredump_fw_info(struct amdgpu_device *adev, }static ssize_t -amdgpu_devcoredump_read (char *buffer,loff_t offset,size_t count, -void *data,size_t datalen) +__amdgpu_devcoredump_read (char *buffer,size_t count,struct amdgpu_coredump_info *coredump) {struct drm_printer p; -struct amdgpu_coredump_info *coredump = data;struct drm_print_iterator iter;struct amdgpu_vm_fault_info *fault_info;struct amdgpu_ip_block *ip_block;@@ -208,7 +208,6 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count, iter.data = buffer; iter.offset =0 ; - iter.start = offset; iter.remain = count; p =drm_coredump_printer (&iter);@@ -321,8 +320,44 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count,return count - iter.remain; } +static ssize_t +amdgpu_devcoredump_read (char *buffer,loff_t offset,size_t count, +void *data,size_t datalen) +{ +struct amdgpu_coredump_info *coredump = data; +ssize_t byte_copied; + +if (!coredump) +return -ENODEV ; + +if (!coredump->read.buffer) { +/* Do a one-time preparation of the coredump output because +* repeatingly calling drm_coredump_printer is very slow. +*/ + coredump->read.size = +__amdgpu_devcoredump_read (NULL ,AMDGPU_CORE_DUMP_SIZE_MAX , coredump); + coredump->read.buffer =kvmalloc (coredump->read.size,GFP_USER ); +if (!coredump->read.buffer) +return -ENODEV ; + +__amdgpu_devcoredump_read (coredump->read.buffer, coredump->read.size, coredump); + } + +if (offset >= coredump->read.size) +return 0 ; + + byte_copied = count < coredump->read.size - offset ? count : + coredump->read.size - offset; +memcpy (buffer, coredump->read.buffer + offset, byte_copied); + +return byte_copied; +} +static void amdgpu_devcoredump_free (void *data) { +struct amdgpu_coredump_info *coredump = data; + +kvfree (coredump->read.buffer);kfree (data); }drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +7
-0@@ -38,6 +38,13 @@ struct amdgpu_coredump_info {bool skip_vram_check;bool reset_vram_lost;struct amdgpu_ring *ring; +/* Readable form of coredevdump, generate once to speed up +* reading it (see drm_coredump_printer's documentation). +*/ +struct { +ssize_t size; +char *buffer; + } read; };#endif