linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: roman.sudarikov@linux.intel.com
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org,
	linux-kernel@vger.kernel.org, eranian@google.com,
	bgregg@netflix.com, ak@linux.intel.com,
	kan.liang@linux.intel.com
Cc: alexander.antonov@intel.com, roman.sudarikov@linux.intel.com
Subject: [PATCH 2/6] perf tools: Helper functions to enumerate and probe PCI devices
Date: Tue, 26 Nov 2019 19:36:26 +0300	[thread overview]
Message-ID: <20191126163630.17300-3-roman.sudarikov@linux.intel.com> (raw)
In-Reply-To: <20191126163630.17300-2-roman.sudarikov@linux.intel.com>

From: Roman Sudarikov <roman.sudarikov@linux.intel.com>

This makes aggregation of performance data per I/O device
available in the perf user tools.

Signed-off-by: Roman Sudarikov <roman.sudarikov@linux.intel.com>
Co-developed-by: Alexander Antonov <alexander.antonov@intel.com>
Signed-off-by: Alexander Antonov <alexander.antonov@intel.com>
---
 tools/perf/util/Build |  1 +
 tools/perf/util/pci.c | 53 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/pci.h | 23 +++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 tools/perf/util/pci.c
 create mode 100644 tools/perf/util/pci.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8dcfca1a882f..02b699f8a10a 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -23,6 +23,7 @@ perf-y += memswap.o
 perf-y += parse-events.o
 perf-y += perf_regs.o
 perf-y += path.o
+perf-y += pci.o
 perf-y += print_binary.o
 perf-y += rlimit.o
 perf-y += argv_split.o
diff --git a/tools/perf/util/pci.c b/tools/perf/util/pci.c
new file mode 100644
index 000000000000..ba1a48e9d0cc
--- /dev/null
+++ b/tools/perf/util/pci.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Helper functions to access PCI CFG space.
+ *
+ * Copyright (C) 2019, Intel Corporation
+ *
+ * Authors: Roman Sudarikov <roman.sudarikov@intel.com>
+ *	    Alexander Antonov <alexander.antonov@intel.com>
+ */
+#include "pci.h"
+#include <api/fs/fs.h>
+#include <linux/kernel.h>
+#include <string.h>
+#include <unistd.h>
+
+#define PCI_DEVICE_PATH_TEMPLATE "bus/pci/devices/0000:%02x:%02x.0"
+#define PCI_DEVICE_FILE_TEMPLATE PCI_DEVICE_PATH_TEMPLATE"/%s"
+
+static bool directory_exists(const char * const path)
+{
+	return (access(path, F_OK) == 0);
+}
+
+bool pci_device_probe(struct bdf bdf)
+{
+	char path[PATH_MAX];
+
+	scnprintf(path, PATH_MAX, "%s/"PCI_DEVICE_PATH_TEMPLATE,
+		  sysfs__mountpoint(), bdf.busno, bdf.devno);
+	return directory_exists(path);
+}
+
+bool is_pci_device_root_port(struct bdf bdf, u8 *secondary, u8 *subordinate)
+{
+	char path[PATH_MAX];
+	int secondary_interim;
+	int subordinate_interim;
+
+	scnprintf(path, PATH_MAX, PCI_DEVICE_FILE_TEMPLATE,
+		  bdf.busno, bdf.devno, "secondary_bus_number");
+	if (!sysfs__read_int(path, &secondary_interim)) {
+		scnprintf(path, PATH_MAX, PCI_DEVICE_FILE_TEMPLATE,
+			  bdf.busno, bdf.devno, "subordinate_bus_number");
+		if (!sysfs__read_int(path, &subordinate_interim)) {
+			if (secondary)
+				*secondary = (u8)secondary_interim;
+			if (subordinate)
+				*subordinate = (u8)subordinate_interim;
+			return true;
+		}
+	}
+	return false;
+}
diff --git a/tools/perf/util/pci.h b/tools/perf/util/pci.h
new file mode 100644
index 000000000000..e963b12e10e7
--- /dev/null
+++ b/tools/perf/util/pci.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0*/
+/*
+ *
+ * Copyright (C) 2019, Intel Corporation
+ *
+ * Authors: Roman Sudarikov <roman.sudarikov@intel.com>
+ *	    Alexander Antonov <alexander.antonov@intel.com>
+ */
+#ifndef _PCI_H
+#define _PCI_H
+
+#include <linux/types.h>
+
+struct bdf {
+	u8 busno;
+	u8 devno;
+	u8 funcno;
+};
+
+bool pci_device_probe(struct bdf bdf);
+bool is_pci_device_root_port(struct bdf bdf, u8 *secondary, u8 *subordinate);
+
+#endif /* _PCI_H */
-- 
2.19.1


  reply	other threads:[~2019-11-26 16:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26 16:36 [PATCH 0/6] perf x86: Exposing IO stack to IO PMON mapping through sysfs roman.sudarikov
2019-11-26 16:36 ` [PATCH 1/6] perf x86: Infrastructure for exposing an Uncore unit to PMON mapping roman.sudarikov
2019-11-26 16:36   ` roman.sudarikov [this message]
2019-11-26 16:36     ` [PATCH 3/6] perf stat: Helper functions for list of IIO devices roman.sudarikov
2019-11-26 16:36       ` [PATCH 4/6] perf stat: New --iiostat mode to provide I/O performance metrics roman.sudarikov
2019-11-26 16:36         ` [PATCH 5/6] perf tools: Add feature check for libpci roman.sudarikov
2019-11-26 16:36           ` [PATCH 6/6] perf stat: Add PCI device name to --iiostat output roman.sudarikov
2019-12-02 14:00   ` [PATCH 1/6] perf x86: Infrastructure for exposing an Uncore unit to PMON mapping Peter Zijlstra
2019-12-02 19:47   ` Stephane Eranian
2019-12-03  3:00     ` Andi Kleen
2019-12-04 18:48     ` Sudarikov, Roman
2019-12-05 18:02       ` Stephane Eranian
2019-12-05 22:28         ` Andi Kleen
2019-12-06 16:08         ` Sudarikov, Roman

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=20191126163630.17300-3-roman.sudarikov@linux.intel.com \
    --to=roman.sudarikov@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.antonov@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bgregg@netflix.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).