Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: MIT
0002 /* Copyright 2021 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: David Nieto
0023  *          Roy Sun
0024  */
0025 
0026 #include <linux/debugfs.h>
0027 #include <linux/list.h>
0028 #include <linux/module.h>
0029 #include <linux/uaccess.h>
0030 #include <linux/reboot.h>
0031 #include <linux/syscalls.h>
0032 
0033 #include <drm/amdgpu_drm.h>
0034 #include <drm/drm_debugfs.h>
0035 #include <drm/drm_drv.h>
0036 
0037 #include "amdgpu.h"
0038 #include "amdgpu_vm.h"
0039 #include "amdgpu_gem.h"
0040 #include "amdgpu_ctx.h"
0041 #include "amdgpu_fdinfo.h"
0042 
0043 
0044 static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = {
0045     [AMDGPU_HW_IP_GFX]  =   "gfx",
0046     [AMDGPU_HW_IP_COMPUTE]  =   "compute",
0047     [AMDGPU_HW_IP_DMA]  =   "dma",
0048     [AMDGPU_HW_IP_UVD]  =   "dec",
0049     [AMDGPU_HW_IP_VCE]  =   "enc",
0050     [AMDGPU_HW_IP_UVD_ENC]  =   "enc_1",
0051     [AMDGPU_HW_IP_VCN_DEC]  =   "dec",
0052     [AMDGPU_HW_IP_VCN_ENC]  =   "enc",
0053     [AMDGPU_HW_IP_VCN_JPEG] =   "jpeg",
0054 };
0055 
0056 void amdgpu_show_fdinfo(struct seq_file *m, struct file *f)
0057 {
0058     struct drm_file *file = f->private_data;
0059     struct amdgpu_device *adev = drm_to_adev(file->minor->dev);
0060     struct amdgpu_fpriv *fpriv = file->driver_priv;
0061     struct amdgpu_vm *vm = &fpriv->vm;
0062 
0063     uint64_t vram_mem = 0, gtt_mem = 0, cpu_mem = 0;
0064     ktime_t usage[AMDGPU_HW_IP_NUM];
0065     uint32_t bus, dev, fn, domain;
0066     unsigned int hw_ip;
0067     int ret;
0068 
0069     bus = adev->pdev->bus->number;
0070     domain = pci_domain_nr(adev->pdev->bus);
0071     dev = PCI_SLOT(adev->pdev->devfn);
0072     fn = PCI_FUNC(adev->pdev->devfn);
0073 
0074     ret = amdgpu_bo_reserve(vm->root.bo, false);
0075     if (ret)
0076         return;
0077 
0078     amdgpu_vm_get_memory(vm, &vram_mem, &gtt_mem, &cpu_mem);
0079     amdgpu_bo_unreserve(vm->root.bo);
0080 
0081     amdgpu_ctx_mgr_usage(&fpriv->ctx_mgr, usage);
0082 
0083     /*
0084      * ******************************************************************
0085      * For text output format description please see drm-usage-stats.rst!
0086      * ******************************************************************
0087      */
0088 
0089     seq_printf(m, "pasid:\t%u\n", fpriv->vm.pasid);
0090     seq_printf(m, "drm-driver:\t%s\n", file->minor->dev->driver->name);
0091     seq_printf(m, "drm-pdev:\t%04x:%02x:%02x.%d\n", domain, bus, dev, fn);
0092     seq_printf(m, "drm-client-id:\t%Lu\n", vm->immediate.fence_context);
0093     seq_printf(m, "drm-memory-vram:\t%llu KiB\n", vram_mem/1024UL);
0094     seq_printf(m, "drm-memory-gtt: \t%llu KiB\n", gtt_mem/1024UL);
0095     seq_printf(m, "drm-memory-cpu: \t%llu KiB\n", cpu_mem/1024UL);
0096     for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
0097         if (!usage[hw_ip])
0098             continue;
0099 
0100         seq_printf(m, "drm-engine-%s:\t%Ld ns\n", amdgpu_ip_name[hw_ip],
0101                ktime_to_ns(usage[hw_ip]));
0102     }
0103 }