]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c
Merge tag 'bootconfig-fixes-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_fdinfo.c
1 // SPDX-License-Identifier: MIT
2 /* Copyright 2021 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: David Nieto
23  *          Roy Sun
24  */
25
26 #include <linux/debugfs.h>
27 #include <linux/list.h>
28 #include <linux/module.h>
29 #include <linux/uaccess.h>
30 #include <linux/reboot.h>
31 #include <linux/syscalls.h>
32
33 #include <drm/amdgpu_drm.h>
34 #include <drm/drm_debugfs.h>
35 #include <drm/drm_drv.h>
36 #include <drm/drm_file.h>
37
38 #include "amdgpu.h"
39 #include "amdgpu_vm.h"
40 #include "amdgpu_gem.h"
41 #include "amdgpu_ctx.h"
42 #include "amdgpu_fdinfo.h"
43
44
45 static const char *amdgpu_ip_name[AMDGPU_HW_IP_NUM] = {
46         [AMDGPU_HW_IP_GFX]      =       "gfx",
47         [AMDGPU_HW_IP_COMPUTE]  =       "compute",
48         [AMDGPU_HW_IP_DMA]      =       "dma",
49         [AMDGPU_HW_IP_UVD]      =       "dec",
50         [AMDGPU_HW_IP_VCE]      =       "enc",
51         [AMDGPU_HW_IP_UVD_ENC]  =       "enc_1",
52         [AMDGPU_HW_IP_VCN_DEC]  =       "dec",
53         [AMDGPU_HW_IP_VCN_ENC]  =       "enc",
54         [AMDGPU_HW_IP_VCN_JPEG] =       "jpeg",
55         [AMDGPU_HW_IP_VPE]      =       "vpe",
56 };
57
58 void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)
59 {
60         struct amdgpu_fpriv *fpriv = file->driver_priv;
61         struct amdgpu_vm *vm = &fpriv->vm;
62
63         struct amdgpu_mem_stats stats[__AMDGPU_PL_NUM];
64         ktime_t usage[AMDGPU_HW_IP_NUM];
65         const char *pl_name[] = {
66                 [TTM_PL_VRAM] = "vram",
67                 [TTM_PL_TT] = "gtt",
68                 [TTM_PL_SYSTEM] = "cpu",
69                 [AMDGPU_PL_GDS] = "gds",
70                 [AMDGPU_PL_GWS] = "gws",
71                 [AMDGPU_PL_OA] = "oa",
72                 [AMDGPU_PL_DOORBELL] = "doorbell",
73         };
74         unsigned int hw_ip, i;
75
76         amdgpu_vm_get_memory(vm, stats);
77         amdgpu_ctx_mgr_usage(&fpriv->ctx_mgr, usage);
78
79         /*
80          * ******************************************************************
81          * For text output format description please see drm-usage-stats.rst!
82          * ******************************************************************
83          */
84
85         drm_printf(p, "pasid:\t%u\n", fpriv->vm.pasid);
86
87         for (i = 0; i < ARRAY_SIZE(pl_name); i++) {
88                 if (!pl_name[i])
89                         continue;
90
91                 drm_print_memory_stats(p,
92                                        &stats[i].drm,
93                                        DRM_GEM_OBJECT_RESIDENT |
94                                        DRM_GEM_OBJECT_PURGEABLE,
95                                        pl_name[i]);
96         }
97
98         /* Legacy amdgpu keys, alias to drm-resident-memory-: */
99         drm_printf(p, "drm-memory-vram:\t%llu KiB\n",
100                    stats[TTM_PL_VRAM].drm.resident/1024UL);
101         drm_printf(p, "drm-memory-gtt: \t%llu KiB\n",
102                    stats[TTM_PL_TT].drm.resident/1024UL);
103         drm_printf(p, "drm-memory-cpu: \t%llu KiB\n",
104                    stats[TTM_PL_SYSTEM].drm.resident/1024UL);
105
106         /* Amdgpu specific memory accounting keys: */
107         drm_printf(p, "amd-evicted-vram:\t%llu KiB\n",
108                    stats[TTM_PL_VRAM].evicted/1024UL);
109         drm_printf(p, "amd-requested-vram:\t%llu KiB\n",
110                    (stats[TTM_PL_VRAM].drm.shared +
111                     stats[TTM_PL_VRAM].drm.private) / 1024UL);
112         drm_printf(p, "amd-requested-gtt:\t%llu KiB\n",
113                    (stats[TTM_PL_TT].drm.shared +
114                     stats[TTM_PL_TT].drm.private) / 1024UL);
115
116         for (hw_ip = 0; hw_ip < AMDGPU_HW_IP_NUM; ++hw_ip) {
117                 if (!usage[hw_ip])
118                         continue;
119
120                 drm_printf(p, "drm-engine-%s:\t%lld ns\n", amdgpu_ip_name[hw_ip],
121                            ktime_to_ns(usage[hw_ip]));
122         }
123 }
This page took 0.036728 seconds and 4 git commands to generate.