AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kenny Ho <Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
To: y2kenny-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	Kenny.Ho-5C7GfCeVMHo@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH RFC 4/5] drm/amdgpu: Add accounting of command submission via DRM cgroup
Date: Tue, 20 Nov 2018 13:58:13 -0500	[thread overview]
Message-ID: <20181120185814.13362-5-Kenny.Ho@amd.com> (raw)
In-Reply-To: <20181120185814.13362-1-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>

Account for the number of command submitted to amdgpu by type on a per
cgroup basis, for the purpose of profiling/monitoring applications.

x prefix in the control file name x.cmd_submitted.amd.stat signify
experimental.

Change-Id: Ibc22e5bda600f54fe820fe0af5400ca348691550
Signed-off-by: Kenny Ho <Kenny.Ho@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c      |  5 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c | 54 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h |  5 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c    | 15 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h    |  5 +-
 5 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 663043c8f0f5..b448160aed89 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -33,6 +33,7 @@
 #include "amdgpu_trace.h"
 #include "amdgpu_gmc.h"
 #include "amdgpu_gem.h"
+#include "amdgpu_drmcgrp.h"
 
 static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,
 				      struct drm_amdgpu_cs_chunk_fence *data,
@@ -1275,6 +1276,7 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	union drm_amdgpu_cs *cs = data;
 	struct amdgpu_cs_parser parser = {};
 	bool reserved_buffers = false;
+	struct amdgpu_ring *ring;
 	int i, r;
 
 	if (!adev->accel_working)
@@ -1317,6 +1319,9 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	if (r)
 		goto out;
 
+	ring = to_amdgpu_ring(parser.entity->rq->sched);
+	amdgpu_drmcgrp_count_cs(current, dev, ring->funcs->type);
+
 	r = amdgpu_cs_submit(&parser, cs);
 
 out:
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c
index ed8aac17769c..853b77532428 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.c
@@ -1,11 +1,65 @@
 // SPDX-License-Identifier: MIT
 // Copyright 2018 Advanced Micro Devices, Inc.
 #include <linux/slab.h>
+#include <linux/mutex.h>
 #include <linux/cgroup_drm.h>
 #include <drm/drm_device.h>
+#include "amdgpu_ring.h"
 #include "amdgpu_drmcgrp.h"
 
+void amdgpu_drmcgrp_count_cs(struct task_struct *task, struct drm_device *dev,
+		enum amdgpu_ring_type r_type)
+{
+	struct drmcgrp *drmcgrp = get_drmcgrp(task);
+	struct drmcgrp_device_resource *ddr;
+	struct drmcgrp *p;
+	struct amd_drmcgrp_dev_resource *a_ddr;
+
+	if (drmcgrp == NULL)
+		return;
+
+	ddr = drmcgrp->dev_resources[dev->primary->index];
+
+	mutex_lock(&ddr->ddev->mutex);
+	for (p = drmcgrp; p != NULL; p = parent_drmcgrp(drmcgrp)) {
+		a_ddr = ddr_amdddr(p->dev_resources[dev->primary->index]);
+
+		a_ddr->cs_count[r_type]++;
+	}
+	mutex_unlock(&ddr->ddev->mutex);
+}
+
+int amd_drmcgrp_cmd_submit_accounting_read(struct seq_file *sf, void *v)
+{
+	struct drmcgrp *drmcgrp = css_drmcgrp(seq_css(sf));
+	struct drmcgrp_device_resource *ddr = NULL;
+	struct amd_drmcgrp_dev_resource *a_ddr = NULL;
+	int i, j;
+
+	seq_puts(sf, "---\n");
+	for (i = 0; i < MAX_DRM_DEV; i++) {
+		ddr = drmcgrp->dev_resources[i];
+
+		if (ddr == NULL || ddr->ddev->vid != amd_drmcgrp_vendor_id)
+			continue;
+
+		a_ddr = ddr_amdddr(ddr);
+
+		seq_printf(sf, "card%d:\n", i);
+		for (j = 0; j < __MAX_AMDGPU_RING_TYPE; j++)
+			seq_printf(sf, "  %s: %llu\n", amdgpu_ring_names[j], a_ddr->cs_count[j]);
+	}
+
+	return 0;
+}
+
+
 struct cftype files[] = {
+	{
+		.name = "x.cmd_submitted.amd.stat",
+		.seq_show = amd_drmcgrp_cmd_submit_accounting_read,
+		.flags = CFTYPE_NOT_ON_ROOT,
+	},
 	{ } /* terminate */
 };
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h
index e2934b7a49f5..f894a9a1059f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drmcgrp.h
@@ -5,12 +5,17 @@
 #define _AMDGPU_DRMCGRP_H
 
 #include <linux/cgroup_drm.h>
+#include "amdgpu_ring.h"
 
 /* for AMD specific DRM resources */
 struct amd_drmcgrp_dev_resource {
 	struct drmcgrp_device_resource ddr;
+	u64 cs_count[__MAX_AMDGPU_RING_TYPE];
 };
 
+void amdgpu_drmcgrp_count_cs(struct task_struct *task, struct drm_device *dev,
+		enum amdgpu_ring_type r_type);
+
 static inline struct amd_drmcgrp_dev_resource *ddr_amdddr(struct drmcgrp_device_resource *ddr)
 {
 	return ddr ? container_of(ddr, struct amd_drmcgrp_dev_resource, ddr) : NULL;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index b70e85ec147d..1606f84d2334 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -34,6 +34,21 @@
 #include "amdgpu.h"
 #include "atom.h"
 
+char const *amdgpu_ring_names[] = {
+	[AMDGPU_RING_TYPE_GFX]		= "gfx",
+	[AMDGPU_RING_TYPE_COMPUTE]	= "compute",
+	[AMDGPU_RING_TYPE_SDMA]		= "sdma",
+	[AMDGPU_RING_TYPE_UVD]		= "uvd",
+	[AMDGPU_RING_TYPE_VCE]		= "vce",
+	[AMDGPU_RING_TYPE_KIQ]		= "kiq",
+	[AMDGPU_RING_TYPE_UVD_ENC]	= "uvd_enc",
+	[AMDGPU_RING_TYPE_VCN_DEC]	= "vcn_dec",
+	[AMDGPU_RING_TYPE_VCN_ENC]	= "vcn_enc",
+	[AMDGPU_RING_TYPE_VCN_JPEG]	= "vcn_jpeg",
+	[__MAX_AMDGPU_RING_TYPE]	= "_max"
+
+};
+
 /*
  * Rings
  * Most engines on the GPU are fed via ring buffers.  Ring
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
index 4caa301ce454..e292b7e89c6a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
@@ -56,9 +56,12 @@ enum amdgpu_ring_type {
 	AMDGPU_RING_TYPE_UVD_ENC,
 	AMDGPU_RING_TYPE_VCN_DEC,
 	AMDGPU_RING_TYPE_VCN_ENC,
-	AMDGPU_RING_TYPE_VCN_JPEG
+	AMDGPU_RING_TYPE_VCN_JPEG,
+	__MAX_AMDGPU_RING_TYPE
 };
 
+extern char const *amdgpu_ring_names[];
+
 struct amdgpu_device;
 struct amdgpu_ring;
 struct amdgpu_ib;
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2018-11-20 18:58 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20 18:58 [PATCH RFC 0/5] DRM cgroup controller Kenny Ho
2018-11-20 18:58 ` [PATCH RFC 1/5] cgroup: Introduce cgroup for drm subsystem Kenny Ho
     [not found] ` <20181120185814.13362-1-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2018-11-20 18:58   ` [PATCH RFC 2/5] cgroup: Add mechanism to register vendor specific DRM devices Kenny Ho
     [not found]     ` <20181120185814.13362-3-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2018-11-20 20:21       ` Tejun Heo
     [not found]         ` <20181120202141.GA2509588-LpCCV3molIbIZ9tKgghJQw2O0Ztt9esIQQ4Iyu8u01E@public.gmane.org>
2018-11-20 22:21           ` Ho, Kenny
     [not found]             ` <DM5PR12MB1226E972538A45325114ADF683D90-2J9CzHegvk+lTFawYev2gQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-11-20 22:30               ` Tejun Heo
     [not found]                 ` <20181120223018.GB2509588-LpCCV3molIbIZ9tKgghJQw2O0Ztt9esIQQ4Iyu8u01E@public.gmane.org>
2018-11-21 22:07                   ` Ho, Kenny
2018-11-21 22:12                   ` Ho, Kenny
2018-11-26 20:59                   ` Kasiviswanathan, Harish
2018-11-27  9:38                     ` Koenig, Christian
2018-11-27  9:46                     ` [Intel-gfx] " Joonas Lahtinen
2018-11-27 15:41                       ` Ho, Kenny
2018-11-28  9:14                         ` Joonas Lahtinen
2018-11-28 19:46                           ` Ho, Kenny
2018-11-30 22:22                             ` Matt Roper
     [not found]                               ` <20181130222228.GE31345-b/RNqDZ/lqH1fpGqjiHozbKMmGWinSIL2HeeBUIffwg@public.gmane.org>
2018-12-03  6:46                                 ` [Intel-gfx] " Ho, Kenny
2018-12-03 18:58                                   ` Matt Roper
     [not found]                           ` <154339645444.5339.6291298808444340104-zzJjBcU1GAT9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
2018-12-03 20:55                             ` Kuehling, Felix
     [not found]                               ` <219f8754-3e14-05ad-07a3-6cddb8bb74aa-5C7GfCeVMHo@public.gmane.org>
2018-12-05 14:20                                 ` Joonas Lahtinen
2018-11-21  9:53       ` Christian König
2018-11-20 18:58   ` [PATCH RFC 3/5] drm/amdgpu: Add DRM cgroup support for AMD devices Kenny Ho
     [not found]     ` <20181120185814.13362-4-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2018-11-21  9:55       ` Christian König
2018-11-20 18:58   ` Kenny Ho [this message]
2018-11-20 20:57     ` [PATCH RFC 4/5] drm/amdgpu: Add accounting of command submission via DRM cgroup Eric Anholt
     [not found]       ` <87r2ff79he.fsf-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
2018-11-21 10:03         ` Christian König
2018-11-23 17:36           ` Eric Anholt
     [not found]             ` <871s7b7l2b.fsf-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>
2018-11-23 18:13               ` Koenig, Christian
     [not found]                 ` <095e010c-e3b8-ec79-c87b-a05ce1d95e10-5C7GfCeVMHo@public.gmane.org>
2018-11-23 19:09                   ` Ho, Kenny
2018-11-21  9:58     ` Christian König
2018-11-20 18:58 ` [PATCH RFC 5/5] drm/amdgpu: Add accounting of buffer object creation request " Kenny Ho
     [not found]   ` <20181120185814.13362-6-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2018-11-20 20:56     ` Eric Anholt
2018-11-21 10:00     ` Christian König
2018-11-27 18:15       ` Kenny Ho
     [not found]         ` <CAOWid-fMFUvT_XQijRd34+cUOxM=zbbf+HwWv_NbqO-rBo2d_A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-11-27 20:31           ` Christian König
     [not found]             ` <3299d9d6-e272-0459-8f63-0c81d11cde1e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-11-27 20:36               ` Kenny Ho
2019-05-09 21:04 ` [RFC PATCH v2 0/5] new cgroup controller for gpu/drm subsystem Kenny Ho
     [not found]   ` <20190509210410.5471-1-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2019-05-09 21:04     ` [RFC PATCH v2 1/5] cgroup: Introduce cgroup for drm subsystem Kenny Ho
2019-05-09 21:04     ` [RFC PATCH v2 2/5] cgroup: Add mechanism to register DRM devices Kenny Ho
2019-05-09 21:04     ` [RFC PATCH v2 5/5] drm, cgroup: Add peak GEM buffer allocation limit Kenny Ho
     [not found]       ` <20190509210410.5471-6-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2019-05-10 12:29         ` Christian König
2019-05-10 12:31     ` [RFC PATCH v2 0/5] new cgroup controller for gpu/drm subsystem Christian König
2019-05-10 15:07       ` Kenny Ho
     [not found]         ` <CAOWid-dJZrnAifFYByh4p9x-jA1o_5YWkoNVAVbdRUaxzdPbGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-10 17:46           ` Koenig, Christian
2019-05-09 21:04   ` [RFC PATCH v2 3/5] drm/amdgpu: Register AMD devices for DRM cgroup Kenny Ho
2019-05-09 21:04   ` [RFC PATCH v2 4/5] drm, cgroup: Add total GEM buffer allocation limit Kenny Ho
     [not found]     ` <20190509210410.5471-5-Kenny.Ho-5C7GfCeVMHo@public.gmane.org>
2019-05-10 12:28       ` Christian König
     [not found]         ` <f63c8d6b-92a4-2977-d062-7e0b7036834e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-05-10 14:57           ` Kenny Ho
2019-05-10 15:08             ` Koenig, Christian
     [not found]               ` <1ca1363e-b39c-c299-1d24-098b1059f7ff-5C7GfCeVMHo@public.gmane.org>
2019-05-10 15:25                 ` Kenny Ho
2019-05-10 17:48                   ` Koenig, Christian
2019-05-10 18:50                     ` Kenny Ho
     [not found]                       ` <CAOWid-es+C_iStQUkM52mO3TeP8eS9MX+emZDQNH2PyZCf=RHQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-13 15:10                         ` Daniel Vetter
2019-05-15 21:26     ` Welty, Brian
     [not found]       ` <d81e8f55-9602-818e-0f9c-1d9d150133b1-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2019-05-16  2:29         ` Kenny Ho
     [not found]           ` <CAOWid-ftUrVVWPu9KuS8xpWKNQT6_FtxB8gEyEAn9nLD6qxb5Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-16  7:16             ` Koenig, Christian
2019-05-16  7:25               ` Christian König
     [not found]                 ` <6e124f5e-f83f-5ca1-4616-92538f202653-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-05-16 12:28                   ` Daniel Vetter
2019-05-16 14:08                     ` Koenig, Christian
2019-05-16 14:03                   ` Kenny Ho
     [not found]                     ` <CAOWid-fQgah16ycz-V-ymsm7yKUnFTeTSBaW4MK=2mqUHhCcmw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-16 14:12                       ` Christian König
2019-05-16 14:28                         ` Kenny Ho
2019-05-16 14:10             ` Tejun Heo
2019-05-16 14:58               ` Kenny Ho

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181120185814.13362-5-Kenny.Ho@amd.com \
    --to=kenny.ho-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=y2kenny-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox