Skip to content

Commit 7a7a933

Browse files
Martin Krastevzackr
authored andcommitted
drm/vmwgfx: Introduce VMware mks-guest-stats
VMware mks-guest-stats mechanism allows the collection of performance stats from guest userland GL contexts, as well as from vmwgfx kernelspace, via a set of sw- defined performance counters. The userspace performance counters are (de)registerd with vmware-vmx-stats hypervisor via new iocts. The vmwgfx kernelspace counters are controlled at build-time via a new config DRM_VMWGFX_MKSSTATS. * Add vmw_mksstat_{add|remove|reset}_ioctl controlling the tracking of mks-guest-stats in guest winsys contexts * Add DRM_VMWGFX_MKSSTATS config to drivers/gpu/drm/vmwgfx/Kconfig controlling the instrumentation of vmwgfx for kernelspace mks-guest-stats counters * Instrument vmwgfx vmw_execbuf_ioctl to collect mks-guest-stats according to DRM_VMWGFX_MKSSTATS Signed-off-by: Martin Krastev <krastevm@vmware.com> Reviewed-by: Zack Rusin <zackr@vmware.com> Signed-off-by: Zack Rusin <zackr@vmware.com> Link: https://patchwork.freedesktop.org/patch/msgid/20210609172307.131929-3-zackr@vmware.com
1 parent d92223e commit 7a7a933

9 files changed

Lines changed: 919 additions & 27 deletions

File tree

‎drivers/gpu/drm/vmwgfx/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ config DRM_VMWGFX_FBCON
2222
Choose this option if you are shipping a new vmwgfx
2323
userspace driver that supports using the kernel driver.
2424

25+
config DRM_VMWGFX_MKSSTATS
26+
bool "Enable mksGuestStats instrumentation of vmwgfx by default"
27+
depends on DRM_VMWGFX
28+
default n
29+
help
30+
Choose this option to instrument the kernel driver for mksGuestStats.
31+

‎drivers/gpu/drm/vmwgfx/device_include/svga_types.h‎

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
* SOFTWARE.
2424
*
2525
**********************************************************/
26-
#ifndef _VM_BASIC_TYPES_H_
27-
#define _VM_BASIC_TYPES_H_
26+
#ifndef _SVGA_TYPES_H_
27+
#define _SVGA_TYPES_H_
2828
#include <linux/kernel.h>
29+
#include <linux/mm.h>
30+
#include <asm/page.h>
2931

3032
typedef u32 uint32;
3133
typedef s32 int32;
@@ -48,4 +50,90 @@ typedef bool Bool;
4850

4951
#define CONST64U(x) x##ULL
5052

53+
/*
54+
* MKS Guest Stats types
55+
*/
56+
57+
typedef struct MKSGuestStatCounter {
58+
atomic64_t count;
59+
} MKSGuestStatCounter;
60+
61+
typedef struct MKSGuestStatCounterTime {
62+
MKSGuestStatCounter counter;
63+
atomic64_t selfCycles;
64+
atomic64_t totalCycles;
65+
} MKSGuestStatCounterTime;
66+
67+
/*
68+
* Flags for MKSGuestStatInfoEntry::flags below
69+
*/
70+
71+
#define MKS_GUEST_STAT_FLAG_NONE 0
72+
#define MKS_GUEST_STAT_FLAG_TIME (1U << 0)
73+
74+
typedef __attribute__((aligned(32))) struct MKSGuestStatInfoEntry {
75+
union {
76+
const char *s;
77+
uint64 u;
78+
} name;
79+
union {
80+
const char *s;
81+
uint64 u;
82+
} description;
83+
uint64 flags;
84+
union {
85+
MKSGuestStatCounter *counter;
86+
MKSGuestStatCounterTime *counterTime;
87+
uint64 u;
88+
} stat;
89+
} MKSGuestStatInfoEntry;
90+
91+
#define INVALID_PPN64 ((PPN64)0x000fffffffffffffULL)
92+
#define vmw_num_pages(size) (PAGE_ALIGN(size) >> PAGE_SHIFT)
93+
94+
#define MKS_GUEST_STAT_INSTANCE_DESC_LENGTH 1024
95+
#define MKS_GUEST_STAT_INSTANCE_MAX_STATS 4096
96+
#define MKS_GUEST_STAT_INSTANCE_MAX_STAT_PPNS \
97+
(vmw_num_pages(MKS_GUEST_STAT_INSTANCE_MAX_STATS * \
98+
sizeof(MKSGuestStatCounterTime)))
99+
#define MKS_GUEST_STAT_INSTANCE_MAX_INFO_PPNS \
100+
(vmw_num_pages(MKS_GUEST_STAT_INSTANCE_MAX_STATS * \
101+
sizeof(MKSGuestStatInfoEntry)))
102+
#define MKS_GUEST_STAT_AVERAGE_NAME_LENGTH 40
103+
#define MKS_GUEST_STAT_INSTANCE_MAX_STRS_PPNS \
104+
(vmw_num_pages(MKS_GUEST_STAT_INSTANCE_MAX_STATS * \
105+
MKS_GUEST_STAT_AVERAGE_NAME_LENGTH))
106+
107+
/*
108+
* The MKSGuestStatInstanceDescriptor is used as main interface to
109+
* communicate guest stats back to the host code. The guest must
110+
* allocate an instance of this structure at the start of a page and
111+
* provide the physical address to the host. From there the host code
112+
* can walk this structure to find other (pinned) pages containing the
113+
* stats data.
114+
*
115+
* Since the MKSGuestStatInfoEntry structures contain userlevel
116+
* pointers, the InstanceDescriptor also contains pointers to the
117+
* begining of these sections allowing the host side code to correctly
118+
* interpret the pointers.
119+
*
120+
* Because the host side code never acknowledges anything back to the
121+
* guest there is no strict requirement to maintain compatability
122+
* across releases. If the interface changes the host might not be
123+
* able to log stats, but the guest will continue to run normally.
124+
*/
125+
126+
typedef struct MKSGuestStatInstanceDescriptor {
127+
uint64 reservedMBZ; /* must be zero for now. */
128+
uint64 statStartVA; /* VA of the start of the stats section. */
129+
uint64 strsStartVA; /* VA of the start of the strings section. */
130+
uint64 statLength; /* length of the stats section in bytes. */
131+
uint64 infoLength; /* length of the info entry section in bytes. */
132+
uint64 strsLength; /* length of the strings section in bytes. */
133+
PPN64 statPPNs[MKS_GUEST_STAT_INSTANCE_MAX_STAT_PPNS]; /* stat counters */
134+
PPN64 infoPPNs[MKS_GUEST_STAT_INSTANCE_MAX_INFO_PPNS]; /* stat info */
135+
PPN64 strsPPNs[MKS_GUEST_STAT_INSTANCE_MAX_STRS_PPNS]; /* strings */
136+
char description[MKS_GUEST_STAT_INSTANCE_DESC_LENGTH];
137+
} MKSGuestStatInstanceDescriptor;
138+
51139
#endif

‎drivers/gpu/drm/vmwgfx/device_include/vm_basic_types.h‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎drivers/gpu/drm/vmwgfx/vmwgfx_drv.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "vmwgfx_binding.h"
4444
#include "vmwgfx_devcaps.h"
4545
#include "vmwgfx_drv.h"
46+
#include "vmwgfx_mksstat.h"
4647

4748
#define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
4849

@@ -148,6 +149,14 @@
148149
#define DRM_IOCTL_VMW_MSG \
149150
DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_MSG, \
150151
struct drm_vmw_msg_arg)
152+
#define DRM_IOCTL_VMW_MKSSTAT_RESET \
153+
DRM_IO(DRM_COMMAND_BASE + DRM_VMW_MKSSTAT_RESET)
154+
#define DRM_IOCTL_VMW_MKSSTAT_ADD \
155+
DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_MKSSTAT_ADD, \
156+
struct drm_vmw_mksstat_add_arg)
157+
#define DRM_IOCTL_VMW_MKSSTAT_REMOVE \
158+
DRM_IOW(DRM_COMMAND_BASE + DRM_VMW_MKSSTAT_REMOVE, \
159+
struct drm_vmw_mksstat_remove_arg)
151160

152161
/*
153162
* The core DRM version of this macro doesn't account for
@@ -244,6 +253,15 @@ static const struct drm_ioctl_desc vmw_ioctls[] = {
244253
VMW_IOCTL_DEF(VMW_MSG,
245254
vmw_msg_ioctl,
246255
DRM_RENDER_ALLOW),
256+
VMW_IOCTL_DEF(VMW_MKSSTAT_RESET,
257+
vmw_mksstat_reset_ioctl,
258+
DRM_RENDER_ALLOW),
259+
VMW_IOCTL_DEF(VMW_MKSSTAT_ADD,
260+
vmw_mksstat_add_ioctl,
261+
DRM_RENDER_ALLOW),
262+
VMW_IOCTL_DEF(VMW_MKSSTAT_REMOVE,
263+
vmw_mksstat_remove_ioctl,
264+
DRM_RENDER_ALLOW),
247265
};
248266

249267
static const struct pci_device_id vmw_pci_id_list[] = {
@@ -1137,6 +1155,8 @@ static void vmw_driver_unload(struct drm_device *dev)
11371155
for (i = vmw_res_context; i < vmw_res_max; ++i)
11381156
idr_destroy(&dev_priv->res_idr[i]);
11391157

1158+
vmw_mksstat_remove_all(dev_priv);
1159+
11401160
pci_release_regions(pdev);
11411161
}
11421162

‎drivers/gpu/drm/vmwgfx/vmwgfx_drv.h‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
22
/**************************************************************************
33
*
4-
* Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
4+
* Copyright 2009-2021 VMware, Inc., Palo Alto, CA., USA
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a
77
* copy of this software and associated documentation files (the
@@ -91,6 +91,9 @@
9191
#define VMW_RES_FENCE ttm_driver_type3
9292
#define VMW_RES_SHADER ttm_driver_type4
9393

94+
#define MKSSTAT_CAPACITY_LOG2 5U
95+
#define MKSSTAT_CAPACITY (1U << MKSSTAT_CAPACITY_LOG2)
96+
9497
struct vmw_fpriv {
9598
struct ttm_object_file *tfile;
9699
bool gb_aware; /* user-space is guest-backed aware */
@@ -630,6 +633,18 @@ struct vmw_private {
630633
struct vmw_validation_mem vvm;
631634

632635
uint32 *devcaps;
636+
637+
/*
638+
* mksGuestStat instance-descriptor and pid arrays
639+
*/
640+
struct page *mksstat_user_pages[MKSSTAT_CAPACITY];
641+
atomic_t mksstat_user_pids[MKSSTAT_CAPACITY];
642+
643+
#if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS)
644+
struct page *mksstat_kern_pages[MKSSTAT_CAPACITY];
645+
u8 mksstat_kern_top_timer[MKSSTAT_CAPACITY];
646+
atomic_t mksstat_kern_pids[MKSSTAT_CAPACITY];
647+
#endif
633648
};
634649

635650
static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
@@ -1503,6 +1518,17 @@ __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
15031518
int vmw_msg_ioctl(struct drm_device *dev, void *data,
15041519
struct drm_file *file_priv);
15051520

1521+
/* Host mksGuestStats -vmwgfx_msg.c: */
1522+
int vmw_mksstat_get_kern_slot(pid_t pid, struct vmw_private *dev_priv);
1523+
1524+
int vmw_mksstat_reset_ioctl(struct drm_device *dev, void *data,
1525+
struct drm_file *file_priv);
1526+
int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
1527+
struct drm_file *file_priv);
1528+
int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
1529+
struct drm_file *file_priv);
1530+
int vmw_mksstat_remove_all(struct vmw_private *dev_priv);
1531+
15061532
/* VMW logging */
15071533

15081534
/**

‎drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <drm/ttm/ttm_placement.h>
3333
#include "vmwgfx_so.h"
3434
#include "vmwgfx_binding.h"
35+
#include "vmwgfx_mksstat.h"
3536

3637
#define VMW_RES_HT_ORDER 12
3738

@@ -4406,6 +4407,9 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
44064407
int ret;
44074408
struct dma_fence *in_fence = NULL;
44084409

4410+
MKS_STAT_TIME_DECL(MKSSTAT_KERN_EXECBUF);
4411+
MKS_STAT_TIME_PUSH(MKSSTAT_KERN_EXECBUF);
4412+
44094413
/*
44104414
* Extend the ioctl argument while maintaining backwards compatibility:
44114415
* We take different code paths depending on the value of arg->version.
@@ -4415,7 +4419,8 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
44154419
if (unlikely(arg->version > DRM_VMW_EXECBUF_VERSION ||
44164420
arg->version == 0)) {
44174421
VMW_DEBUG_USER("Incorrect execbuf version.\n");
4418-
return -EINVAL;
4422+
ret = -EINVAL;
4423+
goto mksstats_out;
44194424
}
44204425

44214426
switch (arg->version) {
@@ -4435,7 +4440,8 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
44354440

44364441
if (!in_fence) {
44374442
VMW_DEBUG_USER("Cannot get imported fence\n");
4438-
return -EINVAL;
4443+
ret = -EINVAL;
4444+
goto mksstats_out;
44394445
}
44404446

44414447
ret = vmw_wait_dma_fence(dev_priv->fman, in_fence);
@@ -4458,5 +4464,8 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
44584464
out:
44594465
if (in_fence)
44604466
dma_fence_put(in_fence);
4467+
4468+
mksstats_out:
4469+
MKS_STAT_TIME_POP(MKSSTAT_KERN_EXECBUF);
44614470
return ret;
44624471
}

0 commit comments

Comments
 (0)