All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>,
	Ashok Raj <ashok.raj@intel.com>,
	Aditya Srivastava <yashsri421@gmail.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	YueHaibing <yuehaibing@huawei.com>,
	"Gustavo A . R . Silva" <gustavoars@kernel.org>,
	iommu@lists.linux-foundation.org,
	Colin Ian King <colin.king@canonical.com>,
	Will Deacon <will@kernel.org>
Subject: [PATCH 14/23] iommu/vt-d: Expose latency monitor data through debugfs
Date: Thu, 10 Jun 2021 10:01:06 +0800	[thread overview]
Message-ID: <20210610020115.1637656-15-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20210610020115.1637656-1-baolu.lu@linux.intel.com>

A debugfs interface /sys/kernel/debug/iommu/intel/dmar_perf_latency is
created to control and show counts of execution time ranges for various
types per DMAR. The interface may help debug any potential performance
issue.

By default, the interface is disabled.

Possible write value of /sys/kernel/debug/iommu/intel/dmar_perf_latency
  0 - disable sampling all latency data
  1 - enable sampling IOTLB invalidation latency data
  2 - enable sampling devTLB invalidation latency data
  3 - enable sampling intr entry cache invalidation latency data
  4 - enable sampling prq handling latency data

Read /sys/kernel/debug/iommu/intel/dmar_perf_latency gives a snapshot
of sampling result of all enabled monitors.

Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210520031531.712333-1-baolu.lu@linux.intel.com
---
 drivers/iommu/intel/debugfs.c | 111 ++++++++++++++++++++++++++++++++++
 drivers/iommu/intel/Kconfig   |   1 +
 2 files changed, 112 insertions(+)

diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c
index efea7f02abd9..62e23ff3c987 100644
--- a/drivers/iommu/intel/debugfs.c
+++ b/drivers/iommu/intel/debugfs.c
@@ -16,6 +16,7 @@
 #include <asm/irq_remapping.h>
 
 #include "pasid.h"
+#include "perf.h"
 
 struct tbl_walk {
 	u16 bus;
@@ -31,6 +32,9 @@ struct iommu_regset {
 	const char *regs;
 };
 
+#define DEBUG_BUFFER_SIZE	1024
+static char debug_buf[DEBUG_BUFFER_SIZE];
+
 #define IOMMU_REGSET_ENTRY(_reg_)					\
 	{ DMAR_##_reg_##_REG, __stringify(_reg_) }
 
@@ -538,6 +542,111 @@ static int ir_translation_struct_show(struct seq_file *m, void *unused)
 DEFINE_SHOW_ATTRIBUTE(ir_translation_struct);
 #endif
 
+static void latency_show_one(struct seq_file *m, struct intel_iommu *iommu,
+			     struct dmar_drhd_unit *drhd)
+{
+	int ret;
+
+	seq_printf(m, "IOMMU: %s Register Base Address: %llx\n",
+		   iommu->name, drhd->reg_base_addr);
+
+	ret = dmar_latency_snapshot(iommu, debug_buf, DEBUG_BUFFER_SIZE);
+	if (ret < 0)
+		seq_puts(m, "Failed to get latency snapshot");
+	else
+		seq_puts(m, debug_buf);
+	seq_puts(m, "\n");
+}
+
+static int latency_show(struct seq_file *m, void *v)
+{
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+
+	rcu_read_lock();
+	for_each_active_iommu(iommu, drhd)
+		latency_show_one(m, iommu, drhd);
+	rcu_read_unlock();
+
+	return 0;
+}
+
+static int dmar_perf_latency_open(struct inode *inode, struct file *filp)
+{
+	return single_open(filp, latency_show, NULL);
+}
+
+static ssize_t dmar_perf_latency_write(struct file *filp,
+				       const char __user *ubuf,
+				       size_t cnt, loff_t *ppos)
+{
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+	int counting;
+	char buf[64];
+
+	if (cnt > 63)
+		cnt = 63;
+
+	if (copy_from_user(&buf, ubuf, cnt))
+		return -EFAULT;
+
+	buf[cnt] = 0;
+
+	if (kstrtoint(buf, 0, &counting))
+		return -EINVAL;
+
+	switch (counting) {
+	case 0:
+		rcu_read_lock();
+		for_each_active_iommu(iommu, drhd) {
+			dmar_latency_disable(iommu, DMAR_LATENCY_INV_IOTLB);
+			dmar_latency_disable(iommu, DMAR_LATENCY_INV_DEVTLB);
+			dmar_latency_disable(iommu, DMAR_LATENCY_INV_IEC);
+			dmar_latency_disable(iommu, DMAR_LATENCY_PRQ);
+		}
+		rcu_read_unlock();
+		break;
+	case 1:
+		rcu_read_lock();
+		for_each_active_iommu(iommu, drhd)
+			dmar_latency_enable(iommu, DMAR_LATENCY_INV_IOTLB);
+		rcu_read_unlock();
+		break;
+	case 2:
+		rcu_read_lock();
+		for_each_active_iommu(iommu, drhd)
+			dmar_latency_enable(iommu, DMAR_LATENCY_INV_DEVTLB);
+		rcu_read_unlock();
+		break;
+	case 3:
+		rcu_read_lock();
+		for_each_active_iommu(iommu, drhd)
+			dmar_latency_enable(iommu, DMAR_LATENCY_INV_IEC);
+		rcu_read_unlock();
+		break;
+	case 4:
+		rcu_read_lock();
+		for_each_active_iommu(iommu, drhd)
+			dmar_latency_enable(iommu, DMAR_LATENCY_PRQ);
+		rcu_read_unlock();
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	*ppos += cnt;
+	return cnt;
+}
+
+static const struct file_operations dmar_perf_latency_fops = {
+	.open		= dmar_perf_latency_open,
+	.write		= dmar_perf_latency_write,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 void __init intel_iommu_debugfs_init(void)
 {
 	struct dentry *intel_iommu_debug = debugfs_create_dir("intel",
@@ -556,4 +665,6 @@ void __init intel_iommu_debugfs_init(void)
 	debugfs_create_file("ir_translation_struct", 0444, intel_iommu_debug,
 			    NULL, &ir_translation_struct_fops);
 #endif
+	debugfs_create_file("dmar_perf_latency", 0644, intel_iommu_debug,
+			    NULL, &dmar_perf_latency_fops);
 }
diff --git a/drivers/iommu/intel/Kconfig b/drivers/iommu/intel/Kconfig
index 59be5447b775..43ebd8af11c5 100644
--- a/drivers/iommu/intel/Kconfig
+++ b/drivers/iommu/intel/Kconfig
@@ -28,6 +28,7 @@ config INTEL_IOMMU
 config INTEL_IOMMU_DEBUGFS
 	bool "Export Intel IOMMU internals in Debugfs"
 	depends on INTEL_IOMMU && IOMMU_DEBUGFS
+	select DMAR_PERF
 	help
 	  !!!WARNING!!!
 
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  parent reply	other threads:[~2021-06-10  2:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10  2:00 [PATCH 00/23] [PULL REQUEST] Intel IOMMU Updates for Linux v5.14 Lu Baolu
2021-06-10  2:00 ` [PATCH 01/23] iommu/vt-d: Remove redundant assignment to variable agaw Lu Baolu
2021-06-10  2:00 ` [PATCH 02/23] iommu/vt-d: Fix kernel-doc syntax in file header Lu Baolu
2021-06-10  2:00 ` [PATCH 03/23] iommu/vt-d: Tweak the description of a DMA fault Lu Baolu
2021-06-10  2:00 ` [PATCH 04/23] iommu/vt-d: Select PCI_ATS explicitly Lu Baolu
2021-06-10  2:00 ` [PATCH 05/23] iommu/vt-d: Support asynchronous IOMMU nested capabilities Lu Baolu
2021-06-10  2:00 ` [PATCH 06/23] iommu/vt-d: Add pasid private data helpers Lu Baolu
2021-06-10  2:00 ` [PATCH 07/23] iommu/vt-d: Use iommu_sva_alloc(free)_pasid() helpers Lu Baolu
2021-06-10  2:01 ` [PATCH 08/23] iommu/vt-d: Use common helper to lookup svm devices Lu Baolu
2021-06-10  2:01 ` [PATCH 09/23] iommu/vt-d: Refactor prq_event_thread() Lu Baolu
2021-06-10  2:01 ` [PATCH 10/23] iommu/vt-d: Allocate/register iopf queue for sva devices Lu Baolu
2021-06-10  2:01 ` [PATCH 11/23] iommu/vt-d: Report prq to io-pgfault framework Lu Baolu
2021-06-10  2:01 ` [PATCH 12/23] iommu/vt-d: Add prq_report trace event Lu Baolu
2021-06-10  2:01 ` [PATCH 13/23] iommu/vt-d: Add common code for dmar latency performance monitors Lu Baolu
2021-06-10  2:01 ` Lu Baolu [this message]
2021-06-10  2:01 ` [PATCH 15/23] iommu/vt-d: Add cache invalidation latency sampling Lu Baolu
2021-06-10  2:01 ` [PATCH 16/23] iommu/vt-d: Add PRQ handling " Lu Baolu
2021-06-10  2:01 ` [PATCH 17/23] iommu/vt-d: Fix out-bounds-warning in intel/svm.c Lu Baolu
2021-06-10  2:01 ` [PATCH 18/23] iommu/vt-d: Use DEVICE_ATTR_RO macro Lu Baolu
2021-06-10  2:01 ` [PATCH 19/23] iommu/vt-d: Use bitfields for DMAR capabilities Lu Baolu
2021-06-10  2:01 ` [PATCH 20/23] iommu/vt-d: Removed unused iommu_count in dmar domain Lu Baolu
2021-06-10  2:01 ` [PATCH 21/23] iommu/vt-d: Remove unnecessary braces Lu Baolu
2021-06-10  2:01 ` [PATCH 22/23] iommu/vt-d: Define counter explicitly as unsigned int Lu Baolu
2021-06-10  2:01 ` [PATCH 23/23] iommu/vt-d: No need to typecast Lu Baolu
2021-06-10  7:13 ` [PATCH 00/23] [PULL REQUEST] Intel IOMMU Updates for Linux v5.14 Joerg Roedel

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=20210610020115.1637656-15-baolu.lu@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=ashok.raj@intel.com \
    --cc=colin.king@canonical.com \
    --cc=fenghua.yu@intel.com \
    --cc=gustavoars@kernel.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=rdunlap@infradead.org \
    --cc=will@kernel.org \
    --cc=yashsri421@gmail.com \
    --cc=yuehaibing@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.