xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c (revision c1e01cdbe0312d95b8c1542abd67fe786b534f57)
187444254SRoy Sun // SPDX-License-Identifier: MIT
287444254SRoy Sun /* Copyright 2021 Advanced Micro Devices, Inc.
387444254SRoy Sun  *
487444254SRoy Sun  * Permission is hereby granted, free of charge, to any person obtaining a
587444254SRoy Sun  * copy of this software and associated documentation files (the "Software"),
687444254SRoy Sun  * to deal in the Software without restriction, including without limitation
787444254SRoy Sun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
887444254SRoy Sun  * and/or sell copies of the Software, and to permit persons to whom the
987444254SRoy Sun  * Software is furnished to do so, subject to the following conditions:
1087444254SRoy Sun  *
1187444254SRoy Sun  * The above copyright notice and this permission notice shall be included in
1287444254SRoy Sun  * all copies or substantial portions of the Software.
1387444254SRoy Sun  *
1487444254SRoy Sun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1587444254SRoy Sun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1687444254SRoy Sun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1787444254SRoy Sun  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1887444254SRoy Sun  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1987444254SRoy Sun  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2087444254SRoy Sun  * OTHER DEALINGS IN THE SOFTWARE.
2187444254SRoy Sun  *
2287444254SRoy Sun  * Authors: David Nieto
2387444254SRoy Sun  *          Roy Sun
2487444254SRoy Sun  */
2587444254SRoy Sun 
2687444254SRoy Sun #include <linux/debugfs.h>
2787444254SRoy Sun #include <linux/list.h>
2887444254SRoy Sun #include <linux/module.h>
2987444254SRoy Sun #include <linux/uaccess.h>
3087444254SRoy Sun #include <linux/reboot.h>
3187444254SRoy Sun #include <linux/syscalls.h>
3287444254SRoy Sun 
3387444254SRoy Sun #include <drm/amdgpu_drm.h>
3487444254SRoy Sun #include <drm/drm_debugfs.h>
35af0b5416SChristian König #include <drm/drm_drv.h>
3687444254SRoy Sun 
3787444254SRoy Sun #include "amdgpu.h"
3887444254SRoy Sun #include "amdgpu_vm.h"
3987444254SRoy Sun #include "amdgpu_gem.h"
4087444254SRoy Sun #include "amdgpu_ctx.h"
4187444254SRoy Sun #include "amdgpu_fdinfo.h"
4287444254SRoy Sun 
4387444254SRoy Sun 
4487444254SRoy Sun static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = {
4587444254SRoy Sun 	[AMDGPU_HW_IP_GFX]	=	"gfx",
4687444254SRoy Sun 	[AMDGPU_HW_IP_COMPUTE]	=	"compute",
4787444254SRoy Sun 	[AMDGPU_HW_IP_DMA]	=	"dma",
4887444254SRoy Sun 	[AMDGPU_HW_IP_UVD]	=	"dec",
4987444254SRoy Sun 	[AMDGPU_HW_IP_VCE]	=	"enc",
5087444254SRoy Sun 	[AMDGPU_HW_IP_UVD_ENC]	=	"enc_1",
5187444254SRoy Sun 	[AMDGPU_HW_IP_VCN_DEC]	=	"dec",
5287444254SRoy Sun 	[AMDGPU_HW_IP_VCN_ENC]	=	"enc",
5387444254SRoy Sun 	[AMDGPU_HW_IP_VCN_JPEG]	=	"jpeg",
5487444254SRoy Sun };
5587444254SRoy Sun 
amdgpu_show_fdinfo(struct drm_printer * p,struct drm_file * file)56376c25f8SRob Clark void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
5787444254SRoy Sun {
5887444254SRoy Sun 	struct amdgpu_device *adev = drm_to_adev(file->minor->dev);
59af0b5416SChristian König 	struct amdgpu_fpriv *fpriv = file->driver_priv;
609bdc1992SChristian König 	struct amdgpu_vm *vm = &fpriv->vm;
61af0b5416SChristian König 
62d6530c33SMarek Olšák 	struct amdgpu_mem_stats stats;
63af0b5416SChristian König 	ktime_t usage[AMDGPU_HW_IP_NUM];
64af0b5416SChristian König 	uint32_t bus, dev, fn, domain;
65af0b5416SChristian König 	unsigned int hw_ip;
6687444254SRoy Sun 	int ret;
6787444254SRoy Sun 
68d6530c33SMarek Olšák 	memset(&stats, 0, sizeof(stats));
6987444254SRoy Sun 	bus = adev->pdev->bus->number;
7087444254SRoy Sun 	domain = pci_domain_nr(adev->pdev->bus);
7187444254SRoy Sun 	dev = PCI_SLOT(adev->pdev->devfn);
7287444254SRoy Sun 	fn = PCI_FUNC(adev->pdev->devfn);
7387444254SRoy Sun 
749bdc1992SChristian König 	ret = amdgpu_bo_reserve(vm->root.bo, false);
759bdc1992SChristian König 	if (ret)
7687444254SRoy Sun 		return;
779bdc1992SChristian König 
78d6530c33SMarek Olšák 	amdgpu_vm_get_memory(vm, &stats);
799bdc1992SChristian König 	amdgpu_bo_unreserve(vm->root.bo);
80d7eff46cSPhilip Yang 
81af0b5416SChristian König 	amdgpu_ctx_mgr_usage(&fpriv->ctx_mgr, usage);
8287444254SRoy Sun 
83af0b5416SChristian König 	/*
84af0b5416SChristian König 	 * ******************************************************************
85af0b5416SChristian König 	 * For text output format description please see drm-usage-stats.rst!
86af0b5416SChristian König 	 * ******************************************************************
87af0b5416SChristian König 	 */
88af0b5416SChristian König 
89376c25f8SRob Clark 	drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid);
90376c25f8SRob Clark 	drm_printf(p, "drm-driver:\t%s\n", file->minor->dev->driver->name);
91376c25f8SRob Clark 	drm_printf(p, "drm-pdev:\t%04x:%02x:%02x.%d\n", domain, bus, dev, fn);
923dc6d835SSrinivasan Shanmugam 	drm_printf(p, "drm-client-id:\t%llu\n", vm->immediate.fence_context);
93376c25f8SRob Clark 	drm_printf(p, "drm-memory-vram:\t%llu KiB\n", stats.vram/1024UL);
94376c25f8SRob Clark 	drm_printf(p, "drm-memory-gtt: \t%llu KiB\n", stats.gtt/1024UL);
95376c25f8SRob Clark 	drm_printf(p, "drm-memory-cpu: \t%llu KiB\n", stats.cpu/1024UL);
96376c25f8SRob Clark 	drm_printf(p, "amd-memory-visible-vram:\t%llu KiB\n",
97d6530c33SMarek Olšák 		   stats.visible_vram/1024UL);
98376c25f8SRob Clark 	drm_printf(p, "amd-evicted-vram:\t%llu KiB\n",
99d6530c33SMarek Olšák 		   stats.evicted_vram/1024UL);
100376c25f8SRob Clark 	drm_printf(p, "amd-evicted-visible-vram:\t%llu KiB\n",
101d6530c33SMarek Olšák 		   stats.evicted_visible_vram/1024UL);
102376c25f8SRob Clark 	drm_printf(p, "amd-requested-vram:\t%llu KiB\n",
103d6530c33SMarek Olšák 		   stats.requested_vram/1024UL);
104376c25f8SRob Clark 	drm_printf(p, "amd-requested-visible-vram:\t%llu KiB\n",
105d6530c33SMarek Olšák 		   stats.requested_visible_vram/1024UL);
106376c25f8SRob Clark 	drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
107d6530c33SMarek Olšák 		   stats.requested_gtt/1024UL);
108*f85a55fbSAlex Deucher 	drm_printf(p, "drm-shared-vram:\t%llu KiB\n", stats.vram_shared/1024UL);
109*f85a55fbSAlex Deucher 	drm_printf(p, "drm-shared-gtt:\t%llu KiB\n", stats.gtt_shared/1024UL);
110*f85a55fbSAlex Deucher 	drm_printf(p, "drm-shared-cpu:\t%llu KiB\n", stats.cpu_shared/1024UL);
111*f85a55fbSAlex Deucher 
112af0b5416SChristian König 	for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
113af0b5416SChristian König 		if (!usage[hw_ip])
11487444254SRoy Sun 			continue;
11587444254SRoy Sun 
1163dc6d835SSrinivasan Shanmugam 		drm_printf(p, "drm-engine-%s:\t%lld ns\n", amdgpu_ip_name[hw_ip],
117af0b5416SChristian König 			   ktime_to_ns(usage[hw_ip]));
11887444254SRoy Sun 	}
11987444254SRoy Sun }
120