Skip to content

Commit bc7b0be

Browse files
Changbin Duzhenyw
authored andcommitted
drm/i915/gvt: Add basic debugfs infrastructure
We need debugfs entry to expose some debug information of gvt and vGPUs. The first tool will be added is mmio-diff, which help to find the difference values of host and vGPU mmio. It's useful for platform enabling. This patch just add a basic debugfs infrastructure, each vGPU has its own sub-folder. Two simple attributes are created as a template. . ├── num_tracked_mmio ├── vgpu1 | └── active └── vgpu2 └── active Signed-off-by: Changbin Du <changbin.du@intel.com> Reviewed-by: Zhi Wang <zhi.a.wang@intel.com> Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
1 parent 6aa23ce commit bc7b0be

File tree

6 files changed

+121
-4
lines changed

6 files changed

+121
-4
lines changed

drivers/gpu/drm/i915/gvt/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GVT_DIR := gvt
22
GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o firmware.o \
33
interrupt.o gtt.o cfg_space.o opregion.o mmio.o display.o edid.o \
4-
execlist.o scheduler.o sched_policy.o render.o cmd_parser.o
4+
execlist.o scheduler.o sched_policy.o render.o cmd_parser.o debugfs.o
55

66
ccflags-y += -I$(src) -I$(src)/$(GVT_DIR)
77
i915-y += $(addprefix $(GVT_DIR)/, $(GVT_SOURCE))

drivers/gpu/drm/i915/gvt/debugfs.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright(c) 2011-2017 Intel Corporation. All rights reserved.
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 (including the next
12+
* paragraph) shall be included in all copies or substantial portions of the
13+
* Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
#include <linux/debugfs.h>
24+
#include "i915_drv.h"
25+
#include "gvt.h"
26+
27+
28+
/**
29+
* intel_gvt_debugfs_add_vgpu - register debugfs entries for a vGPU
30+
* @vgpu: a vGPU
31+
*
32+
* Returns:
33+
* Zero on success, negative error code if failed.
34+
*/
35+
int intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
36+
{
37+
struct dentry *ent;
38+
char name[10] = "";
39+
40+
sprintf(name, "vgpu%d", vgpu->id);
41+
vgpu->debugfs = debugfs_create_dir(name, vgpu->gvt->debugfs_root);
42+
if (!vgpu->debugfs)
43+
return -ENOMEM;
44+
45+
ent = debugfs_create_bool("active", 0444, vgpu->debugfs,
46+
&vgpu->active);
47+
if (!ent)
48+
return -ENOMEM;
49+
50+
return 0;
51+
}
52+
53+
/**
54+
* intel_gvt_debugfs_remove_vgpu - remove debugfs entries of a vGPU
55+
* @vgpu: a vGPU
56+
*/
57+
void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu)
58+
{
59+
debugfs_remove_recursive(vgpu->debugfs);
60+
vgpu->debugfs = NULL;
61+
}
62+
63+
/**
64+
* intel_gvt_debugfs_init - register gvt debugfs root entry
65+
* @gvt: GVT device
66+
*
67+
* Returns:
68+
* zero on success, negative if failed.
69+
*/
70+
int intel_gvt_debugfs_init(struct intel_gvt *gvt)
71+
{
72+
struct drm_minor *minor = gvt->dev_priv->drm.primary;
73+
struct dentry *ent;
74+
75+
gvt->debugfs_root = debugfs_create_dir("gvt", minor->debugfs_root);
76+
if (!gvt->debugfs_root) {
77+
gvt_err("Cannot create debugfs dir\n");
78+
return -ENOMEM;
79+
}
80+
81+
ent = debugfs_create_ulong("num_tracked_mmio", 0444, gvt->debugfs_root,
82+
&gvt->mmio.num_tracked_mmio);
83+
if (!ent)
84+
return -ENOMEM;
85+
86+
return 0;
87+
}
88+
89+
/**
90+
* intel_gvt_debugfs_clean - remove debugfs entries
91+
* @gvt: GVT device
92+
*/
93+
void intel_gvt_debugfs_clean(struct intel_gvt *gvt)
94+
{
95+
debugfs_remove_recursive(gvt->debugfs_root);
96+
gvt->debugfs_root = NULL;
97+
}

drivers/gpu/drm/i915/gvt/gvt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
318318
if (WARN_ON(!gvt))
319319
return;
320320

321+
intel_gvt_debugfs_clean(gvt);
321322
clean_service_thread(gvt);
322323
intel_gvt_clean_cmd_parser(gvt);
323324
intel_gvt_clean_sched_policy(gvt);
@@ -441,6 +442,10 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
441442
}
442443
gvt->idle_vgpu = vgpu;
443444

445+
ret = intel_gvt_debugfs_init(gvt);
446+
if (ret)
447+
gvt_err("debugfs registeration failed, go on.\n");
448+
444449
gvt_dbg_core("gvt device initialization is done\n");
445450
dev_priv->gvt = gvt;
446451
return 0;

drivers/gpu/drm/i915/gvt/gvt.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ struct intel_vgpu {
190190
struct intel_vgpu_display display;
191191
struct intel_vgpu_submission submission;
192192

193+
struct dentry *debugfs;
194+
193195
#if IS_ENABLED(CONFIG_DRM_I915_GVT_KVMGT)
194196
struct {
195197
struct mdev_device *mdev;
@@ -253,7 +255,7 @@ struct intel_gvt_mmio {
253255
unsigned int num_mmio_block;
254256

255257
DECLARE_HASHTABLE(mmio_info_table, INTEL_GVT_MMIO_HASH_BITS);
256-
unsigned int num_tracked_mmio;
258+
unsigned long num_tracked_mmio;
257259
};
258260

259261
struct intel_gvt_firmware {
@@ -301,6 +303,8 @@ struct intel_gvt {
301303
struct task_struct *service_thread;
302304
wait_queue_head_t service_thread_wq;
303305
unsigned long service_request;
306+
307+
struct dentry *debugfs_root;
304308
};
305309

306310
static inline struct intel_gvt *to_gvt(struct drm_i915_private *i915)
@@ -619,6 +623,12 @@ static inline bool intel_gvt_mmio_has_mode_mask(
619623
return gvt->mmio.mmio_attribute[offset >> 2] & F_MODE_MASK;
620624
}
621625

626+
int intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu);
627+
void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu);
628+
int intel_gvt_debugfs_init(struct intel_gvt *gvt);
629+
void intel_gvt_debugfs_clean(struct intel_gvt *gvt);
630+
631+
622632
#include "trace.h"
623633
#include "mpt.h"
624634

drivers/gpu/drm/i915/gvt/handlers.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,8 +2928,6 @@ int intel_gvt_setup_mmio_info(struct intel_gvt *gvt)
29282928
gvt->mmio.mmio_block = mmio_blocks;
29292929
gvt->mmio.num_mmio_block = ARRAY_SIZE(mmio_blocks);
29302930

2931-
gvt_dbg_mmio("traced %u virtual mmio registers\n",
2932-
gvt->mmio.num_tracked_mmio);
29332931
return 0;
29342932
err:
29352933
intel_gvt_clean_mmio_info(gvt);

drivers/gpu/drm/i915/gvt/vgpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu)
252252

253253
WARN(vgpu->active, "vGPU is still active!\n");
254254

255+
intel_gvt_debugfs_remove_vgpu(vgpu);
255256
idr_remove(&gvt->vgpu_idr, vgpu->id);
256257
intel_vgpu_clean_sched_policy(vgpu);
257258
intel_vgpu_clean_submission(vgpu);
@@ -378,10 +379,16 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
378379
if (ret)
379380
goto out_clean_submission;
380381

382+
ret = intel_gvt_debugfs_add_vgpu(vgpu);
383+
if (ret)
384+
goto out_clean_sched_policy;
385+
381386
mutex_unlock(&gvt->lock);
382387

383388
return vgpu;
384389

390+
out_clean_sched_policy:
391+
intel_vgpu_clean_sched_policy(vgpu);
385392
out_clean_submission:
386393
intel_vgpu_clean_submission(vgpu);
387394
out_clean_display:

0 commit comments

Comments
 (0)