Skip to contentSkip to conversation

perf stat: Introduce iiostat mode to provide I/O performance metrics

PATCH Superseded Alexander Antonov 2 participants 19 messages Dec 23, 2020 – Jan 15, 2021 perf events

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover perf stat: Introduce iiostat mode to provide I/O performance metrics

The previous version can be found at:
v1: https://lkml.kernel.org/r/[email protected]

Changes in this revision are:
v1 -> v2:
1. Using 'perf iiostat' subcommand instead of 'perf stat --iiostat':
- Added perf-iiostat.sh script to use short command
- Updated manual pages to get help for 'perf iiostat'
- Added 'perf-iiostat' to perf's gitignore file

Mode is intended to provide four I/O performance metrics in MB per each IIO stack:

 - Inbound Read:   I/O devices below IIO stack read from the host memory
 - Inbound Write:  I/O devices below IIO stack write to the host memory
 - Outbound Read:  CPU reads from I/O devices below IIO stack

- Outbound Write: CPU writes to I/O devices below IIO stack

Each metric requiries only one IIO event which increments at every 4B transfer in corresponding direction. The formulas to compute metrics are generic:

    #EventCount * 4B / (1024 * 1024)

Note: iiostat introduces new perf data aggregation mode - per I/O stack hence -e and -M options are not supported.

Usage examples:

1. List all IIO stacks (example for 2-S platform):

   $ perf iiostat show
   S0-uncore_iio_0<0000:00>
   S1-uncore_iio_0<0000:80>
   S0-uncore_iio_1<0000:17>
   S1-uncore_iio_1<0000:85>
   S0-uncore_iio_2<0000:3a>
   S1-uncore_iio_2<0000:ae>
   S0-uncore_iio_3<0000:5d>
   S1-uncore_iio_3<0000:d7>

2. Collect metrics for all I/O stacks:

   $ perf iiostat -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
   357708+0 records in
   357707+0 records out
   375083606016 bytes (375 GB, 349 GiB) copied, 215.974 s, 1.7 GB/s

Performance counter stats for 'system wide':

port Inbound Read(MB) Inbound Write(MB) Outbound Read(MB) Outbound Write(MB)

   0000:00                    1                    0                    2                    3 
   0000:80                    0                    0                    0                    0 
   0000:17               352552                   43                    0                   21 
   0000:85                    0                    0                    0                    0 
   0000:3a                    3                    0                    0                    0 
   0000:ae                    0                    0                    0                    0 
   0000:5d                    0                    0                    0                    0 
   0000:d7                    0                    0                    0                    0

3. Collect metrics for comma separated list of I/O stacks:

   $ perf iiostat 0000:17,0:3a -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
   357708+0 records in
   357707+0 records out
   375083606016 bytes (375 GB, 349 GiB) copied, 197.08 s, 1.9 GB/s

Performance counter stats for 'system wide':

port Inbound Read(MB) Inbound Write(MB) Outbound Read(MB) Outbound Write(MB)
0000:17 358559 44 0 22
0000:3a 3 2 0 0

        197.081983474 seconds time elapsed

Alexander Antonov (6):
perf stat: Add AGGR_IIO_STACK mode
perf evsel: Introduce an observed performance device perf stat: Basic support for iiostat in perf
perf stat: Helper functions for IIO stacks list in iiostat mode perf stat: Enable iiostat mode for x86 platforms
perf: Update .gitignore file

 tools/perf/.gitignore                         |   1 +
 tools/perf/Documentation/perf-iiostat.txt     |  89 ++++
 tools/perf/Makefile.perf                      |   5 +-
 tools/perf/arch/x86/util/Build                |   1 +
 tools/perf/arch/x86/util/iiostat.c            | 462 ++++++++++++++++++
 tools/perf/builtin-stat.c                     |  40 +-
 tools/perf/command-list.txt                   |   1 +
 tools/perf/perf-iiostat.sh                    |  12 +
 tools/perf/util/evsel.h                       |   1 +
 tools/perf/util/iiostat.h                     |  33 ++
 .../scripting-engines/trace-event-python.c    |   2 +-
 tools/perf/util/stat-display.c                |  51 +-
 tools/perf/util/stat-shadow.c                 |  11 +-
 tools/perf/util/stat.c                        |   3 +-
 tools/perf/util/stat.h                        |   2 +
 15 files changed, 704 insertions(+), 10 deletions(-)
 create mode 100644 tools/perf/Documentation/perf-iiostat.txt
 create mode 100644 tools/perf/arch/x86/util/iiostat.c
 create mode 100644 tools/perf/perf-iiostat.sh
 create mode 100644 tools/perf/util/iiostat.h

base-commit: 644bf4b0f7acde641d3db200b4db66977e96c3bd

Signature · 1 line
2.19.1
#10 lore raw

PATCH v2 4/6 perf stat: Helper functions for IIO stacks list in iiostat mode

Introduce helper functions to control IIO stacks list. These helpers will be used in the follow-up patch.

---
 tools/perf/arch/x86/util/iiostat.c | 125 +++++++++++++++++++++++++++++
 1 file changed, 125 insertions(+)
 create mode 100644 tools/perf/arch/x86/util/iiostat.c
tools/perf/arch/x86/util/iiostat.c new file +125 -0
new file mode 100644
index 000000000000..98b9707b4827
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * perf iiostat
+ *
+ * Copyright (C) 2020, Intel Corporation
+ *
+ * Authors: Alexander Antonov <[email protected]>
+ */
+
+#include <api/fs/fs.h>
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <regex.h>
+#include "util/cpumap.h"
+#include "util/debug.h"
+#include "util/iiostat.h"
+#include "util/counts.h"
+#include "path.h"
+
+struct iio_root_port {
+	u32 domain;
+	u8 bus;
+	u8 die;
+	u8 pmu_idx;
+	int idx;
+};
+
+struct iio_root_ports_list {
+	struct iio_root_port **rps;
+	int nr_entries;
+};
+
+static void iio_root_port_show(FILE *output, const struct iio_root_port * const rp)
+{
+	if (output && rp)
+		fprintf(output, "S%d-uncore_iio_%d<%04x:%02x>\n",
+			rp->die, rp->pmu_idx, rp->domain, rp->bus);
+}
+
+static struct iio_root_port *iio_root_port_new(u32 domain, u8 bus, u8 die, u8 pmu_idx)
+{
+	struct iio_root_port *p = calloc(1, sizeof(*p));
+
+	if (p) {
+		p->domain = domain;
+		p->bus = bus;
+		p->die = die;
+		p->pmu_idx = pmu_idx;
+	}
+	return p;
+}
+
+static struct iio_root_ports_list *iio_root_ports_list_new(void)
+{
+	struct iio_root_ports_list *list = calloc(1, sizeof(*list));
+
+	if (list) {
+		list->rps = calloc(1, sizeof(struct iio_root_port *));
+		if (!list->rps) {
+			free(list);
+			list = NULL;
+		}
+	}
+
+	return list;
+}
+
+static void iio_root_ports_list_free(struct iio_root_ports_list *list)
+{
+	int idx;
+
+	if (list) {
+		for (idx = 0; idx < list->nr_entries; idx++)
+			free(list->rps[idx]);
+		free(list->rps);
+		free(list);
+	}
+}
+
+static
+struct iio_root_port *iio_root_port_find_by_notation(const struct iio_root_ports_list * const list,
+						     u32 domain, u8 bus)
+{
+	int idx;
+	struct iio_root_port *rp;
+
+	if (list) {
+		for (idx = 0; idx < list->nr_entries; idx++) {
+			rp = list->rps[idx];
+			if (rp && rp->domain == domain && rp->bus == bus)
+				return rp;
+		}
+	}
+	return NULL;
+}
+
+static int iio_root_ports_list_insert(struct iio_root_ports_list *list,
+				      struct iio_root_port * const rp)
+{
+	struct iio_root_port **tmp_buf;
+
+	if (list && rp) {
+		rp->idx = list->nr_entries++;
+		/* One more for NULL.*/
+		tmp_buf = realloc(list->rps, (list->nr_entries + 1) * sizeof(*list->rps));
+		if (!tmp_buf) {
+			pr_err("Failed to realloc memory\n");
+			return -ENOMEM;
+		}
+		tmp_buf[rp->idx] = rp;
+		tmp_buf[list->nr_entries] = NULL;
+		list->rps = tmp_buf;
+	}
+	return 0;
+}
Signature · 1 line
2.19.1
#5 lore raw

PATCH v2 3/6 perf stat: Basic support for iiostat in perf

In reply to Alexander Antonov

Add basic flow for a new iiostat mode in perf. Mode is intended to provide four I/O performance metrics per each IIO stack: Inbound Read, Inbound Write, Outbound Read, Outbound Write.

The actual code to compute the metrics and attribute it to evsel::perf_device is in follow-on patches.

---
 tools/perf/builtin-stat.c      | 33 ++++++++++++++++++++++++++++-
 tools/perf/util/iiostat.h      | 33 +++++++++++++++++++++++++++++
 tools/perf/util/stat-display.c | 38 +++++++++++++++++++++++++++++++++-
 tools/perf/util/stat-shadow.c  | 11 +++++++++-
 tools/perf/util/stat.h         |  1 +
 5 files changed, 113 insertions(+), 3 deletions(-)
 create mode 100644 tools/perf/util/iiostat.h
tools/perf/builtin-stat.c +32 -1
index 72f9d0aa3f96..14c3da136927 100644
@@ -67,6 +67,7 @@
 #include "util/top.h"
 #include "util/affinity.h"
 #include "util/pfm.h"
+#include "util/iiostat.h"
 #include "asm/bug.h"
 
 #include <linux/time64.h>
@@ -198,7 +199,8 @@ static struct perf_stat_config stat_config = {
 	.walltime_nsecs_stats	= &walltime_nsecs_stats,
 	.big_num		= true,
 	.ctl_fd			= -1,
-	.ctl_fd_ack		= -1
+	.ctl_fd_ack		= -1,
+	.iiostat_run		= false,
 };
 
 static bool cpus_map_matched(struct evsel *a, struct evsel *b)
@@ -1073,6 +1075,14 @@ static int parse_stat_cgroups(const struct option *opt,
 	return parse_cgroups(opt, str, unset);
 }
 
+__weak int iiostat_parse(const struct option *opt __maybe_unused,
+			 const char *str __maybe_unused,
+			 int unset __maybe_unused)
+{
+	pr_err("iiostat mode is not supported\n");
+	return -1;
+}
+
 static struct option stat_options[] = {
 	OPT_BOOLEAN('T', "transaction", &transaction_run,
 		    "hardware transaction statistics"),
@@ -1185,6 +1195,8 @@ static struct option stat_options[] = {
 		     "\t\t\t  Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n"
 		     "\t\t\t  Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.",
 		      parse_control_option),
+	OPT_CALLBACK_OPTARG(0, "iiostat", &evsel_list, &stat_config, "root port",
+			    "measure PCIe metrics per IIO stack", iiostat_parse),
 	OPT_END()
 };
 
@@ -1509,6 +1521,12 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
 	return 0;
 }
 
+__weak int iiostat_show_root_ports(struct evlist *evlist __maybe_unused,
+				   struct perf_stat_config *config __maybe_unused)
+{
+	return 0;
+}
+
 /*
  * Add default attributes, if there were no attributes specified or
  * if -d/--detailed, -d -d or -d -d -d is used:
@@ -2054,6 +2072,10 @@ static void setup_system_wide(int forks)
 	}
 }
 
+__weak void iiostat_delete_root_ports(struct evlist *evlist __maybe_unused)
+{
+}
+
 int cmd_stat(int argc, const char **argv)
 {
 	const char * const stat_usage[] = {
@@ -2230,6 +2252,12 @@ int cmd_stat(int argc, const char **argv)
 		goto out;
 	}
 
+	if (stat_config.iiostat_run) {
+		status = iiostat_show_root_ports(evsel_list, &stat_config);
+		if (status || !stat_config.iiostat_run)
+			goto out;
+	}
+
 	if (add_default_attributes())
 		goto out;
 
@@ -2406,6 +2434,9 @@ int cmd_stat(int argc, const char **argv)
 	perf_stat__exit_aggr_mode();
 	perf_evlist__free_stats(evsel_list);
 out:
+	if (stat_config.iiostat_run)
+		iiostat_delete_root_ports(evsel_list);
+
 	zfree(&stat_config.walltime_run);
 
 	if (smi_cost && smi_reset)
tools/perf/util/iiostat.h new file +33 -0
new file mode 100644
index 000000000000..8d4226df9975
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * perf iiostat
+ *
+ * Copyright (C) 2020, Intel Corporation
+ *
+ * Authors: Alexander Antonov <[email protected]>
+ */
+
+#ifndef _IIOSTAT_H
+#define _IIOSTAT_H
+
+#include <subcmd/parse-options.h>
+#include "util/stat.h"
+#include "util/parse-events.h"
+#include "util/evlist.h"
+
+struct option;
+struct perf_stat_config;
+struct evlist;
+struct timespec;
+
+int iiostat_parse(const struct option *opt, const char *str,
+		  int unset __maybe_unused);
+void iiostat_prefix(struct perf_stat_config *config, struct evlist *evlist,
+		    char *prefix, struct timespec *ts);
+void iiostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
+			  struct perf_stat_output_ctx *out);
+int iiostat_show_root_ports(struct evlist *evlist,
+			    struct perf_stat_config *config);
+void iiostat_delete_root_ports(struct evlist *evlist);
+
+#endif /* _IIOSTAT_H */
tools/perf/util/stat-display.c +37 -1
index 3bfcdb80443a..9eb8484e8b90 100644
@@ -17,6 +17,7 @@
 #include "cgroup.h"
 #include <api/fs/fs.h>
 #include "util.h"
+#include "iiostat.h"
 
 #define CNTR_NOT_SUPPORTED	"<not supported>"
 #define CNTR_NOT_COUNTED	"<not counted>"
@@ -310,6 +311,12 @@ static void print_metric_header(struct perf_stat_config *config,
 	struct outstate *os = ctx;
 	char tbuf[1024];
 
+	/* In case of iiostat, print metric header for first perf_device only */
+	if (os->evsel->perf_device && os->evsel->evlist->selected->perf_device &&
+	    config->iiostat_run &&
+	    os->evsel->perf_device != os->evsel->evlist->selected->perf_device)
+		return;
+
 	if (!valid_only_metric(unit))
 		return;
 	unit = fixunit(tbuf, os->evsel, unit);
@@ -942,6 +949,8 @@ static void print_metric_headers(struct perf_stat_config *config,
 			fputs("time,", config->output);
 		fputs(aggr_header_csv[config->aggr_mode], config->output);
 	}
+	if (config->iiostat_run && !config->interval && !config->csv_output)
+		fprintf(config->output, "   port         ");
 
 	/* Print metrics headers only */
 	evlist__for_each_entry(evlist, counter) {
@@ -959,6 +968,13 @@ static void print_metric_headers(struct perf_stat_config *config,
 	fputc('\n', config->output);
 }
 
+__weak void iiostat_prefix(struct perf_stat_config *config __maybe_unused,
+			    struct evlist *evlist __maybe_unused,
+			    char *prefix __maybe_unused,
+			    struct timespec *ts __maybe_unused)
+{
+}
+
 static void print_interval(struct perf_stat_config *config,
 			   struct evlist *evlist,
 			   char *prefix, struct timespec *ts)
@@ -971,7 +987,8 @@ static void print_interval(struct perf_stat_config *config,
 	if (config->interval_clear)
 		puts(CONSOLE_CLEAR);
 
-	sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep);
+	if (!config->iiostat_run)
+		sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep);
 
 	if ((num_print_interval == 0 && !config->csv_output) || config->interval_clear) {
 		switch (config->aggr_mode) {
@@ -1205,6 +1222,10 @@ perf_evlist__print_counters(struct evlist *evlist,
 	int interval = config->interval;
 	struct evsel *counter;
 	char buf[64], *prefix = NULL;
+	void *device = NULL;
+
+	if (config->iiostat_run)
+		evlist->selected = evlist__first(evlist);
 
 	if (interval)
 		print_interval(config, evlist, prefix = buf, ts);
@@ -1254,6 +1275,21 @@ perf_evlist__print_counters(struct evlist *evlist,
 		}
 		break;
 	case AGGR_IIO_STACK:
+		counter = evlist__first(evlist);
+		perf_evlist__set_selected(evlist, counter);
+		iiostat_prefix(config, evlist, prefix = buf, ts);
+		fprintf(config->output, "%s", prefix);
+		evlist__for_each_entry(evlist, counter) {
+			device = evlist->selected->perf_device;
+			if (device && device != counter->perf_device) {
+				perf_evlist__set_selected(evlist, counter);
+				iiostat_prefix(config, evlist, prefix, ts);
+				fprintf(config->output, "\n%s", prefix);
+			}
+			print_counter_aggr(config, counter, prefix);
+			if ((counter->idx + 1) == evlist->core.nr_entries)
+				fputc('\n', config->output);
+		}
 		break;
 	case AGGR_UNSET:
 	default:
tools/perf/util/stat-shadow.c +10 -1
index 901265127e36..c5851ceb4c6b 100644
@@ -9,6 +9,7 @@
 #include "expr.h"
 #include "metricgroup.h"
 #include <linux/zalloc.h>
+#include "iiostat.h"
 
 /*
  * AGGR_GLOBAL: Use CPU 0
@@ -919,6 +920,12 @@ double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_sta
 	return ratio;
 }
 
+__weak void iiostat_print_metric(struct perf_stat_config *config __maybe_unused,
+				  struct evsel *evsel __maybe_unused,
+				  struct perf_stat_output_ctx *out __maybe_unused)
+{
+}
+
 void perf_stat__print_shadow_stats(struct perf_stat_config *config,
 				   struct evsel *evsel,
 				   double avg, int cpu,
@@ -934,7 +941,9 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config,
 	struct metric_event *me;
 	int num = 1;
 
-	if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) {
+	if (config->iiostat_run) {
+		iiostat_print_metric(config, evsel, out);
+	} else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) {
 		total = runtime_stat_avg(st, STAT_CYCLES, ctx, cpu);
 
 		if (total) {
tools/perf/util/stat.h +1 -0
index d053ebd44ae3..a072dfe3dbbf 100644
@@ -118,6 +118,7 @@ struct perf_stat_config {
 	bool			 walltime_run_table;
 	bool			 all_kernel;
 	bool			 all_user;
+	bool			 iiostat_run;
 	bool			 percore_show_thread;
 	bool			 summary;
 	bool			 metric_no_group;
Signature · 1 line
2.19.1
#11 lore raw

PATCH v2 5/6 perf stat: Enable iiostat mode for x86 platforms

In reply to Alexander Antonov

This functionality is based on recently introduced sysfs attributes for Intel® Xeon® Scalable processor family (code name Skylake-SP):
Commit bb42b3d39781 ("perf/x86/intel/uncore: Expose an Uncore unit to IIO PMON mapping")

Mode is intended to provide four I/O performance metrics in MB per each IIO stack:
- Inbound Read: I/O devices below IIO stack read from the host memory
- Inbound Write: I/O devices below IIO stack write to the host memory
- Outbound Read: CPU reads from I/O devices below IIO stack
- Outbound Write: CPU writes to I/O devices below IIO stack

Each metric requiries only one IIO event which increments at every 4B transfer in corresponding direction. The formulas to compute metrics are generic:

    #EventCount * 4B / (1024 * 1024)
---
 tools/perf/Documentation/perf-iiostat.txt |  89 ++++++
 tools/perf/Makefile.perf                  |   5 +-
 tools/perf/arch/x86/util/Build            |   1 +
 tools/perf/arch/x86/util/iiostat.c        | 337 ++++++++++++++++++++++
 tools/perf/command-list.txt               |   1 +
 tools/perf/perf-iiostat.sh                |  12 +
 6 files changed, 444 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/Documentation/perf-iiostat.txt
 create mode 100644 tools/perf/perf-iiostat.sh
tools/perf/Documentation/perf-iiostat.txt new file +89 -0
new file mode 100644
index 000000000000..38b5697b0d85
@@ -0,0 +1,89 @@
+perf-iiostat(1)
+===============
+
+NAME
+----
+perf-iiostat - Show I/O performance metrics
+
+SYNOPSIS
+--------
+[verse]
+'perf iiostat' show
+'perf iiostat' <ports> -- <command> [<options>]
+
+DESCRIPTION
+-----------
+Mode is intended to provide four I/O performance metrics per each IIO
+stack (PCIe root port):
+
+- Inbound Read   - I/O devices below IIO stack read from the host memory, in MB
+
+- Inbound Write  - I/O devices below IIO stack write to the host memory, in MB
+
+- Outbound Read  - CPU reads from I/O devices below IIO stack, in MB
+
+- Outbound Write - CPU writes to I/O devices below IIO stack, in MB
+
+OPTIONS
+-------
+<command>...::
+	Any command you can specify in a shell.
+
+show::
+	List all IIO stacks.
+
+<ports>::
+	Select the root ports for monitoring. Comma-separated list is supported.
+
+EXAMPLES
+--------
+
+1. List all IIO stacks (example for 2-S platform):
+
+   $ perf iiostat show
+   S0-uncore_iio_0<0000:00>
+   S1-uncore_iio_0<0000:80>
+   S0-uncore_iio_1<0000:17>
+   S1-uncore_iio_1<0000:85>
+   S0-uncore_iio_2<0000:3a>
+   S1-uncore_iio_2<0000:ae>
+   S0-uncore_iio_3<0000:5d>
+   S1-uncore_iio_3<0000:d7>
+
+2. Collect metrics for all I/O stacks:
+
+   $ perf iiostat -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
+   357708+0 records in
+   357707+0 records out
+   375083606016 bytes (375 GB, 349 GiB) copied, 215.974 s, 1.7 GB/s
+
+    Performance counter stats for 'system wide':
+
+      port             Inbound Read(MB)    Inbound Write(MB)    Outbound Read(MB)   Outbound Write(MB) 
+   0000:00                    1                    0                    2                    3 
+   0000:80                    0                    0                    0                    0 
+   0000:17               352552                   43                    0                   21 
+   0000:85                    0                    0                    0                    0 
+   0000:3a                    3                    0                    0                    0 
+   0000:ae                    0                    0                    0                    0 
+   0000:5d                    0                    0                    0                    0 
+   0000:d7                    0                    0                    0                    0
+
+3. Collect metrics for comma-separated list of I/O stacks:
+
+   $ perf iiostat 0000:17,0:3a -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
+   357708+0 records in
+   357707+0 records out
+   375083606016 bytes (375 GB, 349 GiB) copied, 197.08 s, 1.9 GB/s
+
+    Performance counter stats for 'system wide':
+
+      port             Inbound Read(MB)    Inbound Write(MB)    Outbound Read(MB)   Outbound Write(MB) 
+   0000:17               358559                   44                    0                   22 
+   0000:3a                    3                    2                    0                    0 
+
+        197.081983474 seconds time elapsed
+
+SEE ALSO
+--------
+linkperf:perf-stat[1]
\ No newline at end of file
tools/perf/Makefile.perf +4 -1
index 7ce3f2e8b9c7..c16c14a304a9 100644
@@ -280,6 +280,7 @@ SCRIPT_SH =
 
 SCRIPT_SH += perf-archive.sh
 SCRIPT_SH += perf-with-kcore.sh
+SCRIPT_SH += perf-iiostat.sh
 
 grep-libs = $(filter -l%,$(1))
 strip-libs = $(filter-out -l%,$(1))
@@ -944,6 +945,8 @@ endif
 		$(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 	$(call QUIET_INSTALL, perf-with-kcore) \
 		$(INSTALL) $(OUTPUT)perf-with-kcore -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
+	$(call QUIET_INSTALL, perf-iiostat) \
+		$(INSTALL) $(OUTPUT)perf-iiostat -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 ifndef NO_LIBAUDIT
 	$(call QUIET_INSTALL, strace/groups) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(STRACE_GROUPS_INSTDIR_SQ)'; \
@@ -1009,7 +1012,7 @@ python-clean:
 	$(python-clean)
 
 clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean config-clean fixdep-clean python-clean
-	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
+	$(call QUIET_CLEAN, core-objs)  $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf-iiostat $(LANG_BINDINGS)
 	$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
 	$(Q)$(RM) $(OUTPUT).config-detected
 	$(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)pmu-events/jevents $(OUTPUT)$(LIBJVMTI).so
tools/perf/arch/x86/util/Build +1 -0
index 347c39b960eb..6fa275d3d897 100644
@@ -6,6 +6,7 @@ perf-y += perf_regs.o
 perf-y += topdown.o
 perf-y += machine.o
 perf-y += event.o
+perf-y += iiostat.o
 
 perf-$(CONFIG_DWARF) += dwarf-regs.o
 perf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
tools/perf/arch/x86/util/iiostat.c +337 -0

346 lines not on this page · raw message

tools/perf/command-list.txt +1 -0
index bc6c585f74fc..77e4c9410b0e 100644
@@ -14,6 +14,7 @@ perf-config			mainporcelain common
 perf-evlist			mainporcelain common
 perf-ftrace			mainporcelain common
 perf-inject			mainporcelain common
+perf-iiostat			mainporcelain common
 perf-kallsyms			mainporcelain common
 perf-kmem			mainporcelain common
 perf-kvm			mainporcelain common
tools/perf/perf-iiostat.sh new file +12 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*
\ No newline at end of file
Signature · 1 line
2.19.1
#18 lore raw

PATCH v2 6/6 perf: Update .gitignore file

In reply to Alexander Antonov

After a "make -C tools/perf", git reports the following untracked file:
perf-iiostat

Add this generated file to perf's .gitignore file.

---
 tools/perf/.gitignore | 1 +
 1 file changed, 1 insertion(+)
tools/perf/.gitignore +1 -0
index f3f84781fd74..ab826736e677 100644
@@ -20,6 +20,7 @@ perf.data.old
 output.svg
 perf-archive
 perf-with-kcore
+perf-iiostat
 tags
 TAGS
 cscope*
Signature · 1 line
2.19.1
#1 lore raw

PATCH v2 1/6 perf stat: Add AGGR_IIO_STACK mode

In reply to Alexander Antonov

Adding AGGR_IIO_STACK mode to be able to distinguish aggr_mode for IIO stacks in following patches.

---
 tools/perf/builtin-stat.c                           |  7 +++++--
 .../util/scripting-engines/trace-event-python.c     |  2 +-
 tools/perf/util/stat-display.c                      | 13 +++++++++++--
 tools/perf/util/stat.c                              |  3 ++-
 tools/perf/util/stat.h                              |  1 +
 5 files changed, 20 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +5 -2
index f15b2f8aa14d..72f9d0aa3f96 100644
@@ -913,7 +913,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
 		init_stats(&walltime_nsecs_stats);
 		update_stats(&walltime_nsecs_stats, t1 - t0);
 
-		if (stat_config.aggr_mode == AGGR_GLOBAL)
+		if (stat_config.aggr_mode == AGGR_GLOBAL || stat_config.aggr_mode == AGGR_IIO_STACK)
 			perf_evlist__save_aggr_prev_raw_counts(evsel_list);
 
 		perf_evlist__copy_prev_raw_counts(evsel_list);
@@ -1309,6 +1309,7 @@ static int perf_stat_init_aggr_mode(void)
 		break;
 	case AGGR_GLOBAL:
 	case AGGR_THREAD:
+	case AGGR_IIO_STACK:
 	case AGGR_UNSET:
 	default:
 		break;
@@ -1499,6 +1500,7 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
 	case AGGR_NONE:
 	case AGGR_GLOBAL:
 	case AGGR_THREAD:
+	case AGGR_IIO_STACK:
 	case AGGR_UNSET:
 	default:
 		break;
@@ -2216,7 +2218,8 @@ int cmd_stat(int argc, const char **argv)
 	 * --per-thread is aggregated per thread, we dont mix it with cpu mode
 	 */
 	if (((stat_config.aggr_mode != AGGR_GLOBAL &&
-	      stat_config.aggr_mode != AGGR_THREAD) || nr_cgroups) &&
+	      stat_config.aggr_mode != AGGR_THREAD &&
+	      stat_config.aggr_mode != AGGR_IIO_STACK) || nr_cgroups) &&
 	    !target__has_cpu(&target)) {
 		fprintf(stderr, "both cgroup and no-aggregation "
 			"modes only available in system-wide mode\n");
tools/perf/util/scripting-engines/trace-event-python.c +1 -1
index c83c2c6564e0..e8b472faeae4 100644
@@ -1401,7 +1401,7 @@ static void python_process_stat(struct perf_stat_config *config,
 	struct perf_cpu_map *cpus = counter->core.cpus;
 	int cpu, thread;
 
-	if (config->aggr_mode == AGGR_GLOBAL) {
+	if (config->aggr_mode == AGGR_GLOBAL || config->aggr_mode == AGGR_IIO_STACK) {
 		process_stat(counter, -1, -1, tstamp,
 			     &counter->counts->aggr);
 		return;
tools/perf/util/stat-display.c +11 -2
index 4b57c0c07632..3bfcdb80443a 100644
@@ -133,6 +133,7 @@ static void aggr_printout(struct perf_stat_config *config,
 			config->csv_sep);
 		break;
 	case AGGR_GLOBAL:
+	case AGGR_IIO_STACK:
 	case AGGR_UNSET:
 	default:
 		break;
@@ -330,7 +331,7 @@ static int first_shadow_cpu(struct perf_stat_config *config,
 	if (config->aggr_mode == AGGR_NONE)
 		return id;
 
-	if (config->aggr_mode == AGGR_GLOBAL)
+	if (config->aggr_mode == AGGR_GLOBAL || config->aggr_mode == AGGR_IIO_STACK)
 		return 0;
 
 	for (i = 0; i < evsel__nr_cpus(evsel); i++) {
@@ -424,6 +425,7 @@ static void printout(struct perf_stat_config *config, int id, int nr,
 	if (config->csv_output && !config->metric_only) {
 		static int aggr_fields[] = {
 			[AGGR_GLOBAL] = 0,
+			[AGGR_IIO_STACK] = 0,
 			[AGGR_THREAD] = 1,
 			[AGGR_NONE] = 1,
 			[AGGR_SOCKET] = 2,
@@ -906,6 +908,7 @@ static int aggr_header_lens[] = {
 	[AGGR_NONE] = 6,
 	[AGGR_THREAD] = 24,
 	[AGGR_GLOBAL] = 0,
+	[AGGR_IIO_STACK] = 0,
 };
 
 static const char *aggr_header_csv[] = {
@@ -914,7 +917,8 @@ static const char *aggr_header_csv[] = {
 	[AGGR_SOCKET] 	= 	"socket,cpus",
 	[AGGR_NONE] 	= 	"cpu,",
 	[AGGR_THREAD] 	= 	"comm-pid,",
-	[AGGR_GLOBAL] 	=	""
+	[AGGR_GLOBAL]	=	"",
+	[AGGR_IIO_STACK] =	"port,"
 };
 
 static void print_metric_headers(struct perf_stat_config *config,
@@ -1001,6 +1005,9 @@ static void print_interval(struct perf_stat_config *config,
 			if (!metric_only)
 				fprintf(output, "                  counts %*s events\n", unit_width, "unit");
 			break;
+		case AGGR_IIO_STACK:
+			fprintf(output, "#           time    port        ");
+			break;
 		case AGGR_GLOBAL:
 		default:
 			fprintf(output, "#           time");
@@ -1246,6 +1253,8 @@ perf_evlist__print_counters(struct evlist *evlist,
 			}
 		}
 		break;
+	case AGGR_IIO_STACK:
+		break;
 	case AGGR_UNSET:
 	default:
 		break;
tools/perf/util/stat.c +2 -1
index bd0decd6d753..6a655f909587 100644
@@ -363,6 +363,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
 		}
 		break;
 	case AGGR_GLOBAL:
+	case AGGR_IIO_STACK:
 		aggr->val += count->val;
 		aggr->ena += count->ena;
 		aggr->run += count->run;
@@ -424,7 +425,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,
 	if (ret)
 		return ret;
 
-	if (config->aggr_mode != AGGR_GLOBAL)
+	if (config->aggr_mode != AGGR_GLOBAL && config->aggr_mode != AGGR_IIO_STACK)
 		return 0;
 
 	if (!counter->snapshot)
tools/perf/util/stat.h +1 -0
index 05adf8165025..d053ebd44ae3 100644
@@ -50,6 +50,7 @@ enum aggr_mode {
 	AGGR_DIE,
 	AGGR_CORE,
 	AGGR_THREAD,
+	AGGR_IIO_STACK,
 	AGGR_UNSET,
 	AGGR_NODE,
 };
Signature · 1 line
2.19.1
#2 lore raw

PATCH v2 2/6 perf evsel: Introduce an observed performance device

In reply to Alexander Antonov

Adding evsel::perf_device void pointer.

For performance monitoring purposes, an evsel can have a related device. These changes allow to attribute, for example, I/O performance metrics to IIO stack.

---
 tools/perf/util/evsel.h | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evsel.h +1 -0
index 79a860d8e3ee..c346920f477a 100644
@@ -127,6 +127,7 @@ struct evsel {
 	 * See also evsel__has_callchain().
 	 */
 	__u64			synth_sample_type;
+	void			*perf_device;
 };
 
 struct perf_missing_features {
Signature · 1 line
2.19.1
maintainer
#3 lore raw

Re: [PATCH v2 2/6] perf evsel: Introduce an observed performance device

Hi,

Quoted 17 lines · Alexander Antonov

Adding evsel::perf_device void pointer.

For performance monitoring purposes, an evsel can have a related device. These changes allow to attribute, for example, I/O performance metrics to IIO stack.

---
 tools/perf/util/evsel.h | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evsel.h +0 -0
index 79a860d8e3ee..c346920f477a 100644

tools/perf/util/evsel.h struct evsel { · line 130

Quoted 4 lines
tools/perf/util/evsel.h +1 -0
@@ -127,6 +127,7 @@ struct evsel {
         * See also evsel__has_callchain().
         */
        __u64                   synth_sample_type;
+       void                    *perf_device;

Maybe we can use the existing 'priv' field.

Thanks,
Namhyung

Quoted 6 lines
tools/perf/util/evsel.h +0 -1
 };
 
 struct perf_missing_features {
--

2.19.1

maintainer
#6 lore raw

Re: [PATCH v2 3/6] perf stat: Basic support for iiostat in perf

In reply to Alexander Antonov
Quoted 4 lines · Alexander Antonov

Add basic flow for a new iiostat mode in perf. Mode is intended to provide four I/O performance metrics per each IIO stack: Inbound Read, Inbound Write, Outbound Read, Outbound Write.

It seems like a generic analysis and other archs can extend it later.. Then we can make it a bit more general.. at least, names? :)

Quoted 61 lines

The actual code to compute the metrics and attribute it to evsel::perf_device is in follow-on patches.

---
 tools/perf/builtin-stat.c      | 33 ++++++++++++++++++++++++++++-
 tools/perf/util/iiostat.h      | 33 +++++++++++++++++++++++++++++
 tools/perf/util/stat-display.c | 38 +++++++++++++++++++++++++++++++++-
 tools/perf/util/stat-shadow.c  | 11 +++++++++-
 tools/perf/util/stat.h         |  1 +
 5 files changed, 113 insertions(+), 3 deletions(-)
 create mode 100644 tools/perf/util/iiostat.h
tools/perf/builtin-stat.c +13 -1
index 72f9d0aa3f96..14c3da136927 100644
@@ -67,6 +67,7 @@
 #include "util/top.h"
 #include "util/affinity.h"
 #include "util/pfm.h"
+#include "util/iiostat.h"
 #include "asm/bug.h"
 
 #include <linux/time64.h>
@@ -198,7 +199,8 @@ static struct perf_stat_config stat_config = {
        .walltime_nsecs_stats   = &walltime_nsecs_stats,
        .big_num                = true,
        .ctl_fd                 = -1,
-       .ctl_fd_ack             = -1
+       .ctl_fd_ack             = -1,
+       .iiostat_run            = false,
 };
 
 static bool cpus_map_matched(struct evsel *a, struct evsel *b)
@@ -1073,6 +1075,14 @@ static int parse_stat_cgroups(const struct option *opt,
        return parse_cgroups(opt, str, unset);
 }
 
+__weak int iiostat_parse(const struct option *opt __maybe_unused,
+                        const char *str __maybe_unused,
+                        int unset __maybe_unused)
+{
+       pr_err("iiostat mode is not supported\n");
+       return -1;
+}
+
 static struct option stat_options[] = {
        OPT_BOOLEAN('T', "transaction", &transaction_run,
                    "hardware transaction statistics"),
@@ -1185,6 +1195,8 @@ static struct option stat_options[] = {
                     "\t\t\t  Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n"
                     "\t\t\t  Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.",
                      parse_control_option),
+       OPT_CALLBACK_OPTARG(0, "iiostat", &evsel_list, &stat_config, "root port",
+                           "measure PCIe metrics per IIO stack", iiostat_parse),
        OPT_END()
 };
 

tools/perf/builtin-stat.c static int perf_stat_init_aggr_mode_file(struct perf_stat *st) · line 1528

Quoted 8 lines
tools/perf/builtin-stat.c +5 -0
@@ -1509,6 +1521,12 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
        return 0;
 }
 
+__weak int iiostat_show_root_ports(struct evlist *evlist __maybe_unused,
+                                  struct perf_stat_config *config __maybe_unused)
+{
+       return 0;
+}

I think it's too specific, maybe iiostat_prepare() ?

tools/perf/builtin-stat.c static void setup_system_wide(int forks) · line 2077

Quoted 11 lines
tools/perf/builtin-stat.c +4 -0
+
 /*
  * Add default attributes, if there were no attributes specified or
  * if -d/--detailed, -d -d or -d -d -d is used:
@@ -2054,6 +2072,10 @@ static void setup_system_wide(int forks)
        }
 }
 
+__weak void iiostat_delete_root_ports(struct evlist *evlist __maybe_unused)
+{
+}

Same here..

Quoted 79 lines
tools/perf/builtin-stat.c +10 -0
+
 int cmd_stat(int argc, const char **argv)
 {
        const char * const stat_usage[] = {
@@ -2230,6 +2252,12 @@ int cmd_stat(int argc, const char **argv)
                goto out;
        }
 
+       if (stat_config.iiostat_run) {
+               status = iiostat_show_root_ports(evsel_list, &stat_config);
+               if (status || !stat_config.iiostat_run)
+                       goto out;
+       }
+
        if (add_default_attributes())
                goto out;
 
@@ -2406,6 +2434,9 @@ int cmd_stat(int argc, const char **argv)
        perf_stat__exit_aggr_mode();
        perf_evlist__free_stats(evsel_list);
 out:
+       if (stat_config.iiostat_run)
+               iiostat_delete_root_ports(evsel_list);
+
        zfree(&stat_config.walltime_run);
 
        if (smi_cost && smi_reset)
tools/perf/util/iiostat.h new file +33 -0
new file mode 100644
index 000000000000..8d4226df9975
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * perf iiostat
+ *
+ * Copyright (C) 2020, Intel Corporation
+ *
+ * Authors: Alexander Antonov <[email protected]>
+ */
+
+#ifndef _IIOSTAT_H
+#define _IIOSTAT_H
+
+#include <subcmd/parse-options.h>
+#include "util/stat.h"
+#include "util/parse-events.h"
+#include "util/evlist.h"
+
+struct option;
+struct perf_stat_config;
+struct evlist;
+struct timespec;
+
+int iiostat_parse(const struct option *opt, const char *str,
+                 int unset __maybe_unused);
+void iiostat_prefix(struct perf_stat_config *config, struct evlist *evlist,
+                   char *prefix, struct timespec *ts);
+void iiostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
+                         struct perf_stat_output_ctx *out);
+int iiostat_show_root_ports(struct evlist *evlist,
+                           struct perf_stat_config *config);
+void iiostat_delete_root_ports(struct evlist *evlist);
+
+#endif /* _IIOSTAT_H */
tools/perf/util/stat-display.c +1 -0
index 3bfcdb80443a..9eb8484e8b90 100644
@@ -17,6 +17,7 @@
 #include "cgroup.h"
 #include <api/fs/fs.h>
 #include "util.h"
+#include "iiostat.h"
 
 #define CNTR_NOT_SUPPORTED     "<not supported>"
 #define CNTR_NOT_COUNTED       "<not counted>"

tools/perf/util/stat-display.c static void print_metric_header(struct perf_stat_config *config, · line 316

Quoted 6 lines
tools/perf/util/stat-display.c +3 -0
@@ -310,6 +311,12 @@ static void print_metric_header(struct perf_stat_config *config,
        struct outstate *os = ctx;
        char tbuf[1024];
 
+       /* In case of iiostat, print metric header for first perf_device only */
+       if (os->evsel->perf_device && os->evsel->evlist->selected->perf_device &&
+           config->iiostat_run &&

When is the perf_device set? Is it possible to be NULL in the iiostat mode?

Thanks,
Namhyung

Quoted 6 lines
tools/perf/util/stat-display.c +3 -0
+           os->evsel->perf_device != os->evsel->evlist->selected->perf_device)
+               return;
+
        if (!valid_only_metric(unit))
                return;
        unit = fixunit(tbuf, os->evsel, unit);
maintainer
#12 lore raw

Re: [PATCH v2 5/6] perf stat: Enable iiostat mode for x86 platforms

In reply to Alexander Antonov
Quoted 13 lines · Alexander Antonov

This functionality is based on recently introduced sysfs attributes for Intel® Xeon® Scalable processor family (code name Skylake-SP):
Commit bb42b3d39781 ("perf/x86/intel/uncore: Expose an Uncore unit to IIO PMON mapping")

Mode is intended to provide four I/O performance metrics in MB per each IIO stack:
- Inbound Read: I/O devices below IIO stack read from the host memory
- Inbound Write: I/O devices below IIO stack write to the host memory
- Outbound Read: CPU reads from I/O devices below IIO stack
- Outbound Write: CPU writes to I/O devices below IIO stack

Quoted 4 lines

Each metric requiries only one IIO event which increments at every 4B transfer in corresponding direction. The formulas to compute metrics are generic:

    #EventCount * 4B / (1024 * 1024)

Hmm.. maybe we can do this with JSON metrics, no?

Quoted 42 lines
---
 tools/perf/Documentation/perf-iiostat.txt |  89 ++++++
 tools/perf/Makefile.perf                  |   5 +-
 tools/perf/arch/x86/util/Build            |   1 +
 tools/perf/arch/x86/util/iiostat.c        | 337 ++++++++++++++++++++++
 tools/perf/command-list.txt               |   1 +
 tools/perf/perf-iiostat.sh                |  12 +
 6 files changed, 444 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/Documentation/perf-iiostat.txt
 create mode 100644 tools/perf/perf-iiostat.sh
tools/perf/Documentation/perf-iiostat.txt new file +23 -0
new file mode 100644
index 000000000000..38b5697b0d85
@@ -0,0 +1,89 @@
+perf-iiostat(1)
+===============
+
+NAME
+----
+perf-iiostat - Show I/O performance metrics
+
+SYNOPSIS
+--------
+[verse]
+'perf iiostat' show
+'perf iiostat' <ports> -- <command> [<options>]
+
+DESCRIPTION
+-----------
+Mode is intended to provide four I/O performance metrics per each IIO
+stack (PCIe root port):
+
+- Inbound Read   - I/O devices below IIO stack read from the host memory, in MB
+
+- Inbound Write  - I/O devices below IIO stack write to the host memory, in MB
+
+- Outbound Read  - CPU reads from I/O devices below IIO stack, in MB

tools/perf/Documentation/perf-iiostat.txt line 33

Quoted 10 lines
tools/perf/Documentation/perf-iiostat.txt new file +10 -0
+
+- Outbound Write - CPU writes to I/O devices below IIO stack, in MB
+
+OPTIONS
+-------
+<command>...::
+       Any command you can specify in a shell.
+
+show::
+       List all IIO stacks.

I'd prefer 'list' for this, but not a strong opinion..

Quoted 57 lines
tools/perf/Documentation/perf-iiostat.txt new file +56 -0
+
+<ports>::
+       Select the root ports for monitoring. Comma-separated list is supported.
+
+EXAMPLES
+--------
+
+1. List all IIO stacks (example for 2-S platform):
+
+   $ perf iiostat show
+   S0-uncore_iio_0<0000:00>
+   S1-uncore_iio_0<0000:80>
+   S0-uncore_iio_1<0000:17>
+   S1-uncore_iio_1<0000:85>
+   S0-uncore_iio_2<0000:3a>
+   S1-uncore_iio_2<0000:ae>
+   S0-uncore_iio_3<0000:5d>
+   S1-uncore_iio_3<0000:d7>
+
+2. Collect metrics for all I/O stacks:
+
+   $ perf iiostat -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
+   357708+0 records in
+   357707+0 records out
+   375083606016 bytes (375 GB, 349 GiB) copied, 215.974 s, 1.7 GB/s
+
+    Performance counter stats for 'system wide':
+
+      port             Inbound Read(MB)    Inbound Write(MB)    Outbound Read(MB)   Outbound Write(MB)
+   0000:00                    1                    0                    2                    3
+   0000:80                    0                    0                    0                    0
+   0000:17               352552                   43                    0                   21
+   0000:85                    0                    0                    0                    0
+   0000:3a                    3                    0                    0                    0
+   0000:ae                    0                    0                    0                    0
+   0000:5d                    0                    0                    0                    0
+   0000:d7                    0                    0                    0                    0
+
+3. Collect metrics for comma-separated list of I/O stacks:
+
+   $ perf iiostat 0000:17,0:3a -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
+   357708+0 records in
+   357707+0 records out
+   375083606016 bytes (375 GB, 349 GiB) copied, 197.08 s, 1.9 GB/s
+
+    Performance counter stats for 'system wide':
+
+      port             Inbound Read(MB)    Inbound Write(MB)    Outbound Read(MB)   Outbound Write(MB)
+   0000:17               358559                   44                    0                   22
+   0000:3a                    3                    2                    0                    0
+
+        197.081983474 seconds time elapsed
+
+SEE ALSO
+--------
+linkperf:perf-stat[1]
\ No newline at end of file

[SNIP]

Quoted 8 lines
tools/perf/perf-iiostat.sh new file +2 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

tools/perf/perf-iiostat.sh line 12

Quoted 10 lines
tools/perf/perf-iiostat.sh new file +10 -0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*

Why is this needed?

Thanks,
Namhyung

Quoted 4 lines

\ No newline at end of file
--
2.19.1

#4 lore raw

Re: [PATCH v2 2/6] perf evsel: Introduce an observed performance device

In reply to Namhyung Kim
Quoted 26 lines · Namhyung Kim

Hi,

Quoted 16 lines · Alexander Antonov

Adding evsel::perf_device void pointer.

For performance monitoring purposes, an evsel can have a related device. These changes allow to attribute, for example, I/O performance metrics to IIO stack.

---
  tools/perf/util/evsel.h | 1 +
  1 file changed, 1 insertion(+)
tools/perf/util/evsel.h +0 -0
index 79a860d8e3ee..c346920f477a 100644

tools/perf/util/evsel.h struct evsel { · line 130

Quoted 4 lines
tools/perf/util/evsel.h +1 -0
@@ -127,6 +127,7 @@ struct evsel {
          * See also evsel__has_callchain().
          */
         __u64                   synth_sample_type;
+       void                    *perf_device;

Maybe we can use the existing 'priv' field.

Quoted 2 lines

Thanks,
Namhyung

Hello Namhyung,

Looks like the 'priv' field isn't used in this case. I suppose it can be re-used in iiostat mode.

Thanks,
Alexander

Quoted 7 lines
Quoted 7 lines
tools/perf/util/evsel.h +0 -1
  };
 
  struct perf_missing_features {
--

2.19.1

#7 lore raw

Re: [PATCH v2 3/6] perf stat: Basic support for iiostat in perf

In reply to Namhyung Kim
Quoted 7 lines · Namhyung Kim
Quoted 3 lines · Alexander Antonov

Add basic flow for a new iiostat mode in perf. Mode is intended to provide four I/O performance metrics per each IIO stack: Inbound Read, Inbound Write, Outbound Read, Outbound Write.

It seems like a generic analysis and other archs can extend it later.. Then we can make it a bit more general.. at least, names? :)

I'm not sure that I fully understand you. Do you mean to rename metrics? The mode is intended to provide PCIe metrics which are appliable for other archs as well.
Actually, I suppose we can rename 'iiostat' to 'pciestat' or something like this to make it a bit more general because the name 'IIO' (Integrated I/O stack) is Intel specific and it can be named in different way on other platforms. In this case the code has to be updated in the same way as well.

Quoted 64 lines
Quoted 64 lines

The actual code to compute the metrics and attribute it to evsel::perf_device is in follow-on patches.

---
  tools/perf/builtin-stat.c      | 33 ++++++++++++++++++++++++++++-
  tools/perf/util/iiostat.h      | 33 +++++++++++++++++++++++++++++
  tools/perf/util/stat-display.c | 38 +++++++++++++++++++++++++++++++++-
  tools/perf/util/stat-shadow.c  | 11 +++++++++-
  tools/perf/util/stat.h         |  1 +
  5 files changed, 113 insertions(+), 3 deletions(-)

create mode 100644 tools/perf/util/iiostat.h

tools/perf/builtin-stat.c +13 -1
index 72f9d0aa3f96..14c3da136927 100644
@@ -67,6 +67,7 @@
  #include "util/top.h"
  #include "util/affinity.h"
  #include "util/pfm.h"
+#include "util/iiostat.h"
  #include "asm/bug.h"
 
  #include <linux/time64.h>
@@ -198,7 +199,8 @@ static struct perf_stat_config stat_config = {
         .walltime_nsecs_stats   = &walltime_nsecs_stats,
         .big_num                = true,
         .ctl_fd                 = -1,
-       .ctl_fd_ack             = -1
+       .ctl_fd_ack             = -1,
+       .iiostat_run            = false,
  };
 
  static bool cpus_map_matched(struct evsel *a, struct evsel *b)
@@ -1073,6 +1075,14 @@ static int parse_stat_cgroups(const struct option *opt,
         return parse_cgroups(opt, str, unset);
  }
 
+__weak int iiostat_parse(const struct option *opt __maybe_unused,
+                        const char *str __maybe_unused,
+                        int unset __maybe_unused)
+{
+       pr_err("iiostat mode is not supported\n");
+       return -1;
+}
+
  static struct option stat_options[] = {
         OPT_BOOLEAN('T', "transaction", &transaction_run,
                     "hardware transaction statistics"),
@@ -1185,6 +1195,8 @@ static struct option stat_options[] = {
                      "\t\t\t  Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n"
                      "\t\t\t  Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.",
                       parse_control_option),
+       OPT_CALLBACK_OPTARG(0, "iiostat", &evsel_list, &stat_config, "root port",
+                           "measure PCIe metrics per IIO stack", iiostat_parse),
         OPT_END()
  };
 
@@ -1509,6 +1521,12 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
         return 0;
  }
 
Quoted 6 lines

tools/perf/builtin-stat.c static int perf_stat_init_aggr_mode_file(struct perf_stat *st) · line 1528

Quoted 5 lines
tools/perf/builtin-stat.c +5 -0
+__weak int iiostat_show_root_ports(struct evlist *evlist __maybe_unused,
+                                  struct perf_stat_config *config __maybe_unused)
+{
+       return 0;
+}

I think it's too specific, maybe iiostat_prepare() ?

What do you think about iiostat_show_root_ports() -> iiostat_show()?

Quoted 9 lines
Quoted 9 lines
tools/perf/builtin-stat.c +1 -0
+
  /*
   * Add default attributes, if there were no attributes specified or
   * if -d/--detailed, -d -d or -d -d -d is used:
@@ -2054,6 +2072,10 @@ static void setup_system_wide(int forks)
         }
  }
 
Quoted 4 lines

tools/perf/builtin-stat.c static void setup_system_wide(int forks) · line 2077

Quoted 3 lines
tools/perf/builtin-stat.c +3 -0
+__weak void iiostat_delete_root_ports(struct evlist *evlist __maybe_unused)
+{
+}

Same here..

I suggest to rename iiostat_delete_root_ports() -> iiostat_release(). What do you think?

Quoted 83 lines
Quoted 83 lines
tools/perf/builtin-stat.c +10 -0
+
  int cmd_stat(int argc, const char **argv)
  {
         const char * const stat_usage[] = {
@@ -2230,6 +2252,12 @@ int cmd_stat(int argc, const char **argv)
                 goto out;
         }
 
+       if (stat_config.iiostat_run) {
+               status = iiostat_show_root_ports(evsel_list, &stat_config);
+               if (status || !stat_config.iiostat_run)
+                       goto out;
+       }
+
         if (add_default_attributes())
                 goto out;
 
@@ -2406,6 +2434,9 @@ int cmd_stat(int argc, const char **argv)
         perf_stat__exit_aggr_mode();
         perf_evlist__free_stats(evsel_list);
  out:
+       if (stat_config.iiostat_run)
+               iiostat_delete_root_ports(evsel_list);
+
         zfree(&stat_config.walltime_run);
 
         if (smi_cost && smi_reset)
tools/perf/util/iiostat.h new file +33 -0
new file mode 100644
index 000000000000..8d4226df9975
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * perf iiostat
+ *
+ * Copyright (C) 2020, Intel Corporation
+ *
+ * Authors: Alexander Antonov <[email protected]>
+ */
+
+#ifndef _IIOSTAT_H
+#define _IIOSTAT_H
+
+#include <subcmd/parse-options.h>
+#include "util/stat.h"
+#include "util/parse-events.h"
+#include "util/evlist.h"
+
+struct option;
+struct perf_stat_config;
+struct evlist;
+struct timespec;
+
+int iiostat_parse(const struct option *opt, const char *str,
+                 int unset __maybe_unused);
+void iiostat_prefix(struct perf_stat_config *config, struct evlist *evlist,
+                   char *prefix, struct timespec *ts);
+void iiostat_print_metric(struct perf_stat_config *config, struct evsel *evsel,
+                         struct perf_stat_output_ctx *out);
+int iiostat_show_root_ports(struct evlist *evlist,
+                           struct perf_stat_config *config);
+void iiostat_delete_root_ports(struct evlist *evlist);
+
+#endif /* _IIOSTAT_H */
tools/perf/util/stat-display.c +1 -0
index 3bfcdb80443a..9eb8484e8b90 100644
@@ -17,6 +17,7 @@
  #include "cgroup.h"
  #include <api/fs/fs.h>
  #include "util.h"
+#include "iiostat.h"
 
  #define CNTR_NOT_SUPPORTED     "<not supported>"
  #define CNTR_NOT_COUNTED       "<not counted>"
@@ -310,6 +311,12 @@ static void print_metric_header(struct perf_stat_config *config,
         struct outstate *os = ctx;
         char tbuf[1024];
 
Quoted 8 lines

tools/perf/util/stat-display.c static void print_metric_header(struct perf_stat_config *config, · line 316

Quoted 3 lines
tools/perf/util/stat-display.c +3 -0
+       /* In case of iiostat, print metric header for first perf_device only */
+       if (os->evsel->perf_device && os->evsel->evlist->selected->perf_device &&
+           config->iiostat_run &&

When is the perf_device set? Is it possible to be NULL in the iiostat mode?

Thanks,
Namhyung

The perf_device field is initialized inside iiostat.c::iiostat_event_group() and it cannot be NULL.
The idea is to attribute events to PCIe ports through perf_device field.

Thanks,
Alexander

Quoted 6 lines
Quoted 6 lines
tools/perf/util/stat-display.c +3 -0
+           os->evsel->perf_device != os->evsel->evlist->selected->perf_device)
+               return;
+
         if (!valid_only_metric(unit))
                 return;
         unit = fixunit(tbuf, os->evsel, unit);
#13 lore raw

Re: [PATCH v2 5/6] perf stat: Enable iiostat mode for x86 platforms

In reply to Namhyung Kim
Quoted 14 lines · Namhyung Kim
Quoted 12 lines · Alexander Antonov

This functionality is based on recently introduced sysfs attributes for Intel® Xeon® Scalable processor family (code name Skylake-SP):
Commit bb42b3d39781 ("perf/x86/intel/uncore: Expose an Uncore unit to IIO PMON mapping")

Mode is intended to provide four I/O performance metrics in MB per each IIO stack:
- Inbound Read: I/O devices below IIO stack read from the host memory
- Inbound Write: I/O devices below IIO stack write to the host memory
- Outbound Read: CPU reads from I/O devices below IIO stack
- Outbound Write: CPU writes to I/O devices below IIO stack

Quoted 5 lines
Quoted 4 lines

Each metric requiries only one IIO event which increments at every 4B transfer in corresponding direction. The formulas to compute metrics are generic:

     #EventCount * 4B / (1024 * 1024)

Hmm.. maybe we can do this with JSON metrics, no?

Do you mean to add metrics to *-metrics.json file?
Looks like it's possible but in this case JSON file should be updated for each new enabled platform and calculations will be the same.
I would prefer to leave it as is because perf will work without changing of userspace part once IIO sysfs attributes are added for new platforms.

Quoted 45 lines
Quoted 45 lines
---
  tools/perf/Documentation/perf-iiostat.txt |  89 ++++++
  tools/perf/Makefile.perf                  |   5 +-
  tools/perf/arch/x86/util/Build            |   1 +
  tools/perf/arch/x86/util/iiostat.c        | 337 ++++++++++++++++++++++
  tools/perf/command-list.txt               |   1 +
  tools/perf/perf-iiostat.sh                |  12 +
  6 files changed, 444 insertions(+), 1 deletion(-)

create mode 100644 tools/perf/Documentation/perf-iiostat.txt create mode 100644 tools/perf/perf-iiostat.sh

tools/perf/Documentation/perf-iiostat.txt new file +26 -0
new file mode 100644
index 000000000000..38b5697b0d85
@@ -0,0 +1,89 @@
+perf-iiostat(1)
+===============
+
+NAME
+----
+perf-iiostat - Show I/O performance metrics
+
+SYNOPSIS
+--------
+[verse]
+'perf iiostat' show
+'perf iiostat' <ports> -- <command> [<options>]
+
+DESCRIPTION
+-----------
+Mode is intended to provide four I/O performance metrics per each IIO
+stack (PCIe root port):
+
+- Inbound Read   - I/O devices below IIO stack read from the host memory, in MB
+
+- Inbound Write  - I/O devices below IIO stack write to the host memory, in MB
+
+- Outbound Read  - CPU reads from I/O devices below IIO stack, in MB
+
+- Outbound Write - CPU writes to I/O devices below IIO stack, in MB
+
Quoted 8 lines

tools/perf/Documentation/perf-iiostat.txt line 33

Quoted 7 lines
tools/perf/Documentation/perf-iiostat.txt new file +7 -0
+OPTIONS
+-------
+<command>...::
+       Any command you can specify in a shell.
+
+show::
+       List all IIO stacks.

I'd prefer 'list' for this, but not a strong opinion..

The 'list' is fine for me as well.

Quoted 79 lines
Quoted 58 lines
tools/perf/Documentation/perf-iiostat.txt new file +56 -0
+
+<ports>::
+       Select the root ports for monitoring. Comma-separated list is supported.
+
+EXAMPLES
+--------
+
+1. List all IIO stacks (example for 2-S platform):
+
+   $ perf iiostat show
+   S0-uncore_iio_0<0000:00>
+   S1-uncore_iio_0<0000:80>
+   S0-uncore_iio_1<0000:17>
+   S1-uncore_iio_1<0000:85>
+   S0-uncore_iio_2<0000:3a>
+   S1-uncore_iio_2<0000:ae>
+   S0-uncore_iio_3<0000:5d>
+   S1-uncore_iio_3<0000:d7>
+
+2. Collect metrics for all I/O stacks:
+
+   $ perf iiostat -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
+   357708+0 records in
+   357707+0 records out
+   375083606016 bytes (375 GB, 349 GiB) copied, 215.974 s, 1.7 GB/s
+
+    Performance counter stats for 'system wide':
+
+      port             Inbound Read(MB)    Inbound Write(MB)    Outbound Read(MB)   Outbound Write(MB)
+   0000:00                    1                    0                    2                    3
+   0000:80                    0                    0                    0                    0
+   0000:17               352552                   43                    0                   21
+   0000:85                    0                    0                    0                    0
+   0000:3a                    3                    0                    0                    0
+   0000:ae                    0                    0                    0                    0
+   0000:5d                    0                    0                    0                    0
+   0000:d7                    0                    0                    0                    0
+
+3. Collect metrics for comma-separated list of I/O stacks:
+
+   $ perf iiostat 0000:17,0:3a -- dd if=/dev/zero of=/dev/nvme0n1 bs=1M oflag=direct
+   357708+0 records in
+   357707+0 records out
+   375083606016 bytes (375 GB, 349 GiB) copied, 197.08 s, 1.9 GB/s
+
+    Performance counter stats for 'system wide':
+
+      port             Inbound Read(MB)    Inbound Write(MB)    Outbound Read(MB)   Outbound Write(MB)
+   0000:17               358559                   44                    0                   22
+   0000:3a                    3                    2                    0                    0
+
+        197.081983474 seconds time elapsed
+
+SEE ALSO
+--------
+linkperf:perf-stat[1]
\ No newline at end of file

[SNIP]

Quoted 8 lines
tools/perf/perf-iiostat.sh new file +2 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

tools/perf/perf-iiostat.sh line 12

Quoted 10 lines
tools/perf/perf-iiostat.sh new file +10 -0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*

Why is this needed?

Quoted 2 lines

Thanks,
Namhyung

Arnaldo raised question relates to format of 'perf stat --iiostat' subcommand and explained how it can be changed to 'perf iiostat' through the aliases mechanism in perf.

Thank you,
Alexander

Quoted 5 lines
Quoted 5 lines

\ No newline at end of file
--
2.19.1

maintainer
#8 lore raw

Re: [PATCH v2 3/6] perf stat: Basic support for iiostat in perf

In reply to Alexander Antonov

Hello,

Quoted 10 lines · Alexander Antonov
Quoted 7 lines · Namhyung Kim
Quoted 3 lines · Alexander Antonov

Add basic flow for a new iiostat mode in perf. Mode is intended to provide four I/O performance metrics per each IIO stack: Inbound Read, Inbound Write, Outbound Read, Outbound Write.

It seems like a generic analysis and other archs can extend it later.. Then we can make it a bit more general.. at least, names? :)

Quoted 11 lines

I'm not sure that I fully understand you. Do you mean to rename metrics? The mode is intended to provide PCIe metrics which are appliable for other archs
as well.
Actually, I suppose we can rename 'iiostat' to 'pciestat' or something like this
to make it a bit more general because the name 'IIO' (Integrated I/O stack) is
Intel specific and it can be named in different way on other platforms. In this
case the code has to be updated in the same way as well.

Maybe just 'iostat' ?

Quoted 64 lines
Quoted 64 lines
Quoted 64 lines

The actual code to compute the metrics and attribute it to evsel::perf_device is in follow-on patches.

---
  tools/perf/builtin-stat.c      | 33 ++++++++++++++++++++++++++++-
  tools/perf/util/iiostat.h      | 33 +++++++++++++++++++++++++++++
  tools/perf/util/stat-display.c | 38 +++++++++++++++++++++++++++++++++-
  tools/perf/util/stat-shadow.c  | 11 +++++++++-
  tools/perf/util/stat.h         |  1 +
  5 files changed, 113 insertions(+), 3 deletions(-)

create mode 100644 tools/perf/util/iiostat.h

tools/perf/builtin-stat.c +13 -1
index 72f9d0aa3f96..14c3da136927 100644
@@ -67,6 +67,7 @@
  #include "util/top.h"
  #include "util/affinity.h"
  #include "util/pfm.h"
+#include "util/iiostat.h"
  #include "asm/bug.h"
 
  #include <linux/time64.h>
@@ -198,7 +199,8 @@ static struct perf_stat_config stat_config = {
         .walltime_nsecs_stats   = &walltime_nsecs_stats,
         .big_num                = true,
         .ctl_fd                 = -1,
-       .ctl_fd_ack             = -1
+       .ctl_fd_ack             = -1,
+       .iiostat_run            = false,
  };
 
  static bool cpus_map_matched(struct evsel *a, struct evsel *b)
@@ -1073,6 +1075,14 @@ static int parse_stat_cgroups(const struct option *opt,
         return parse_cgroups(opt, str, unset);
  }
 
+__weak int iiostat_parse(const struct option *opt __maybe_unused,
+                        const char *str __maybe_unused,
+                        int unset __maybe_unused)
+{
+       pr_err("iiostat mode is not supported\n");
+       return -1;
+}
+
  static struct option stat_options[] = {
         OPT_BOOLEAN('T', "transaction", &transaction_run,
                     "hardware transaction statistics"),
@@ -1185,6 +1195,8 @@ static struct option stat_options[] = {
                      "\t\t\t  Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n"
                      "\t\t\t  Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.",
                       parse_control_option),
+       OPT_CALLBACK_OPTARG(0, "iiostat", &evsel_list, &stat_config, "root port",
+                           "measure PCIe metrics per IIO stack", iiostat_parse),
         OPT_END()
  };
 
@@ -1509,6 +1521,12 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
         return 0;
  }
 
Quoted 7 lines
Quoted 6 lines

tools/perf/builtin-stat.c static int perf_stat_init_aggr_mode_file(struct perf_stat *st) · line 1528

Quoted 5 lines
tools/perf/builtin-stat.c +5 -0
+__weak int iiostat_show_root_ports(struct evlist *evlist __maybe_unused,
+                                  struct perf_stat_config *config __maybe_unused)
+{
+       return 0;
+}

I think it's too specific, maybe iiostat_prepare() ?

What do you think about iiostat_show_root_ports() -> iiostat_show()?

I'm ok with it, I thought it needs some initialization work there.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
tools/perf/builtin-stat.c +1 -0
+
  /*
   * Add default attributes, if there were no attributes specified or
   * if -d/--detailed, -d -d or -d -d -d is used:
@@ -2054,6 +2072,10 @@ static void setup_system_wide(int forks)
         }
  }
 
Quoted 6 lines
Quoted 4 lines

tools/perf/builtin-stat.c static void setup_system_wide(int forks) · line 2077

Quoted 3 lines
tools/perf/builtin-stat.c +3 -0
+__weak void iiostat_delete_root_ports(struct evlist *evlist __maybe_unused)
+{
+}

Same here..

I suggest to rename iiostat_delete_root_ports() -> iiostat_release(). What do you think?

Looks good.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
tools/perf/builtin-stat.c +7 -0
+
  int cmd_stat(int argc, const char **argv)
  {
         const char * const stat_usage[] = {
@@ -2230,6 +2252,12 @@ int cmd_stat(int argc, const char **argv)
                 goto out;
         }
 
+       if (stat_config.iiostat_run) {
+               status = iiostat_show_root_ports(evsel_list, &stat_config);
+               if (status || !stat_config.iiostat_run)
+                       goto out;
+       }
+
         if (add_default_attributes())
                 goto out;
 

[SNIP]

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
tools/perf/util/stat-display.c +1 -0
index 3bfcdb80443a..9eb8484e8b90 100644
@@ -17,6 +17,7 @@
  #include "cgroup.h"
  #include <api/fs/fs.h>
  #include "util.h"
+#include "iiostat.h"
 
  #define CNTR_NOT_SUPPORTED     "<not supported>"
  #define CNTR_NOT_COUNTED       "<not counted>"
@@ -310,6 +311,12 @@ static void print_metric_header(struct perf_stat_config *config,
         struct outstate *os = ctx;
         char tbuf[1024];
 
Quoted 9 lines
Quoted 5 lines

tools/perf/util/stat-display.c static void print_metric_header(struct perf_stat_config *config, · line 316

Quoted 3 lines
tools/perf/util/stat-display.c +3 -0
+       /* In case of iiostat, print metric header for first perf_device only */
+       if (os->evsel->perf_device && os->evsel->evlist->selected->perf_device &&
+           config->iiostat_run &&

When is the perf_device set? Is it possible to be NULL in the iiostat mode?

The perf_device field is initialized inside iiostat.c::iiostat_event_group() and it cannot be NULL.
The idea is to attribute events to PCIe ports through perf_device field.

If it's guaranteed non-NULL, we can check config->iiostat_run only and make the condition simpler.

Thanks,
Namhyung

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
tools/perf/util/stat-display.c +3 -0
+           os->evsel->perf_device != os->evsel->evlist->selected->perf_device)
+               return;
+
         if (!valid_only_metric(unit))
                 return;
         unit = fixunit(tbuf, os->evsel, unit);
maintainer
#14 lore raw

Re: [PATCH v2 5/6] perf stat: Enable iiostat mode for x86 platforms

In reply to Alexander Antonov
Quoted 21 lines · Alexander Antonov
Quoted 18 lines · Namhyung Kim
Quoted 16 lines · Alexander Antonov

This functionality is based on recently introduced sysfs attributes for Intel® Xeon® Scalable processor family (code name Skylake-SP):
Commit bb42b3d39781 ("perf/x86/intel/uncore: Expose an Uncore unit to IIO PMON mapping")

Mode is intended to provide four I/O performance metrics in MB per each IIO stack:
- Inbound Read: I/O devices below IIO stack read from the host memory
- Inbound Write: I/O devices below IIO stack write to the host memory
- Outbound Read: CPU reads from I/O devices below IIO stack
- Outbound Write: CPU writes to I/O devices below IIO stack

Each metric requiries only one IIO event which increments at every 4B transfer in corresponding direction. The formulas to compute metrics are generic:

     #EventCount * 4B / (1024 * 1024)
Quoted 7 lines
Quoted 1 line

Hmm.. maybe we can do this with JSON metrics, no?

Do you mean to add metrics to *-metrics.json file?
Looks like it's possible but in this case JSON file should be updated for each
new enabled platform and calculations will be the same.
I would prefer to leave it as is because perf will work without changing of userspace part once IIO sysfs attributes are added for new platforms.

OK.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

---

[SNIP]

Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
tools/perf/perf-iiostat.sh new file +2 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

tools/perf/perf-iiostat.sh line 12

Quoted 10 lines
tools/perf/perf-iiostat.sh new file +10 -0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*

Why is this needed?

Quoted 6 lines
Quoted 2 lines

Thanks,
Namhyung

Arnaldo raised question relates to format of 'perf stat --iiostat' subcommand
and explained how it can be changed to 'perf iiostat' through the aliases mechanism in perf.

Yeah, I know that. What I'm asking is the DELIMITER part.

Thanks,
Namhyung

#9 lore raw

Re: [PATCH v2 3/6] perf stat: Basic support for iiostat in perf

In reply to Namhyung Kim
Quoted 24 lines · Namhyung Kim

Hello,

Quoted 9 lines · Alexander Antonov
Quoted 7 lines · Namhyung Kim
Quoted 3 lines · Alexander Antonov

Add basic flow for a new iiostat mode in perf. Mode is intended to provide four I/O performance metrics per each IIO stack: Inbound Read, Inbound Write, Outbound Read, Outbound Write.

It seems like a generic analysis and other archs can extend it later.. Then we can make it a bit more general.. at least, names? :)

Quoted 11 lines

I'm not sure that I fully understand you. Do you mean to rename metrics? The mode is intended to provide PCIe metrics which are appliable for other archs
as well.
Actually, I suppose we can rename 'iiostat' to 'pciestat' or something like this
to make it a bit more general because the name 'IIO' (Integrated I/O stack) is
Intel specific and it can be named in different way on other platforms. In this
case the code has to be updated in the same way as well.

Quoted 1 line

Maybe just 'iostat' ?

Yeah, it looks better :)

Quoted 132 lines
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines

The actual code to compute the metrics and attribute it to evsel::perf_device is in follow-on patches.

---
   tools/perf/builtin-stat.c      | 33 ++++++++++++++++++++++++++++-
   tools/perf/util/iiostat.h      | 33 +++++++++++++++++++++++++++++
   tools/perf/util/stat-display.c | 38 +++++++++++++++++++++++++++++++++-
   tools/perf/util/stat-shadow.c  | 11 +++++++++-
   tools/perf/util/stat.h         |  1 +
   5 files changed, 113 insertions(+), 3 deletions(-)

create mode 100644 tools/perf/util/iiostat.h

tools/perf/builtin-stat.c +13 -1
index 72f9d0aa3f96..14c3da136927 100644
@@ -67,6 +67,7 @@
   #include "util/top.h"
   #include "util/affinity.h"
   #include "util/pfm.h"
+#include "util/iiostat.h"
   #include "asm/bug.h"
 
   #include <linux/time64.h>
@@ -198,7 +199,8 @@ static struct perf_stat_config stat_config = {
          .walltime_nsecs_stats   = &walltime_nsecs_stats,
          .big_num                = true,
          .ctl_fd                 = -1,
-       .ctl_fd_ack             = -1
+       .ctl_fd_ack             = -1,
+       .iiostat_run            = false,
   };
 
   static bool cpus_map_matched(struct evsel *a, struct evsel *b)
@@ -1073,6 +1075,14 @@ static int parse_stat_cgroups(const struct option *opt,
          return parse_cgroups(opt, str, unset);
   }
 
+__weak int iiostat_parse(const struct option *opt __maybe_unused,
+                        const char *str __maybe_unused,
+                        int unset __maybe_unused)
+{
+       pr_err("iiostat mode is not supported\n");
+       return -1;
+}
+
   static struct option stat_options[] = {
          OPT_BOOLEAN('T', "transaction", &transaction_run,
                      "hardware transaction statistics"),
@@ -1185,6 +1195,8 @@ static struct option stat_options[] = {
                       "\t\t\t  Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n"
                       "\t\t\t  Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.",
                        parse_control_option),
+       OPT_CALLBACK_OPTARG(0, "iiostat", &evsel_list, &stat_config, "root port",
+                           "measure PCIe metrics per IIO stack", iiostat_parse),
          OPT_END()
   };
 
@@ -1509,6 +1521,12 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
          return 0;
   }
 
Quoted 7 lines
Quoted 6 lines

tools/perf/builtin-stat.c static int perf_stat_init_aggr_mode_file(struct perf_stat *st) · line 1528

Quoted 5 lines
tools/perf/builtin-stat.c +5 -0
+__weak int iiostat_show_root_ports(struct evlist *evlist __maybe_unused,
+                                  struct perf_stat_config *config __maybe_unused)
+{
+       return 0;
+}

I think it's too specific, maybe iiostat_prepare() ?

What do you think about iiostat_show_root_ports() -> iiostat_show()?

I'm ok with it, I thought it needs some initialization work there.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/perf/builtin-stat.c +1 -0
+
   /*
    * Add default attributes, if there were no attributes specified or
    * if -d/--detailed, -d -d or -d -d -d is used:
@@ -2054,6 +2072,10 @@ static void setup_system_wide(int forks)
          }
   }
 
Quoted 6 lines
Quoted 4 lines

tools/perf/builtin-stat.c static void setup_system_wide(int forks) · line 2077

Quoted 3 lines
tools/perf/builtin-stat.c +3 -0
+__weak void iiostat_delete_root_ports(struct evlist *evlist __maybe_unused)
+{
+}

Same here..

I suggest to rename iiostat_delete_root_ports() -> iiostat_release(). What do you think?

Looks good.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
tools/perf/builtin-stat.c +7 -0
+
   int cmd_stat(int argc, const char **argv)
   {
          const char * const stat_usage[] = {
@@ -2230,6 +2252,12 @@ int cmd_stat(int argc, const char **argv)
                  goto out;
          }
 
+       if (stat_config.iiostat_run) {
+               status = iiostat_show_root_ports(evsel_list, &stat_config);
+               if (status || !stat_config.iiostat_run)
+                       goto out;
+       }
+
          if (add_default_attributes())
                  goto out;
 

[SNIP]

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
tools/perf/util/stat-display.c +1 -0
index 3bfcdb80443a..9eb8484e8b90 100644
@@ -17,6 +17,7 @@
   #include "cgroup.h"
   #include <api/fs/fs.h>
   #include "util.h"
+#include "iiostat.h"
 
   #define CNTR_NOT_SUPPORTED     "<not supported>"
   #define CNTR_NOT_COUNTED       "<not counted>"
@@ -310,6 +311,12 @@ static void print_metric_header(struct perf_stat_config *config,
          struct outstate *os = ctx;
          char tbuf[1024];
 
Quoted 9 lines
Quoted 5 lines

tools/perf/util/stat-display.c static void print_metric_header(struct perf_stat_config *config, · line 316

Quoted 3 lines
tools/perf/util/stat-display.c +3 -0
+       /* In case of iiostat, print metric header for first perf_device only */
+       if (os->evsel->perf_device && os->evsel->evlist->selected->perf_device &&
+           config->iiostat_run &&

When is the perf_device set? Is it possible to be NULL in the iiostat mode?

The perf_device field is initialized inside iiostat.c::iiostat_event_group() and it cannot be NULL.
The idea is to attribute events to PCIe ports through perf_device field.

Quoted 6 lines

If it's guaranteed non-NULL, we can check config->iiostat_run only and make the condition simpler.

Thanks,
Namhyung

I will update it in the next version of patchset.

Thanks,
Alexander

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
tools/perf/util/stat-display.c +3 -0
+           os->evsel->perf_device != os->evsel->evlist->selected->perf_device)
+               return;
+
          if (!valid_only_metric(unit))
                  return;
          unit = fixunit(tbuf, os->evsel, unit);
#15 lore raw

Re: [PATCH v2 5/6] perf stat: Enable iiostat mode for x86 platforms

In reply to Namhyung Kim
Quoted 56 lines · Namhyung Kim
Quoted 20 lines · Alexander Antonov
Quoted 18 lines · Namhyung Kim
Quoted 16 lines · Alexander Antonov

This functionality is based on recently introduced sysfs attributes for Intel® Xeon® Scalable processor family (code name Skylake-SP):
Commit bb42b3d39781 ("perf/x86/intel/uncore: Expose an Uncore unit to IIO PMON mapping")

Mode is intended to provide four I/O performance metrics in MB per each IIO stack:
- Inbound Read: I/O devices below IIO stack read from the host memory
- Inbound Write: I/O devices below IIO stack write to the host memory
- Outbound Read: CPU reads from I/O devices below IIO stack
- Outbound Write: CPU writes to I/O devices below IIO stack

Each metric requiries only one IIO event which increments at every 4B transfer in corresponding direction. The formulas to compute metrics are generic:

      #EventCount * 4B / (1024 * 1024)
Quoted 7 lines
Quoted 1 line

Hmm.. maybe we can do this with JSON metrics, no?

Do you mean to add metrics to *-metrics.json file?
Looks like it's possible but in this case JSON file should be updated for each
new enabled platform and calculations will be the same.
I would prefer to leave it as is because perf will work without changing of userspace part once IIO sysfs attributes are added for new platforms.

OK.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

---

[SNIP]

Quoted 22 lines
Quoted 22 lines
Quoted 8 lines
tools/perf/perf-iiostat.sh new file +2 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

tools/perf/perf-iiostat.sh line 12

Quoted 10 lines
tools/perf/perf-iiostat.sh new file +10 -0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*

Why is this needed?

Thanks,
Namhyung

Quoted 8 lines
Quoted 4 lines

Arnaldo raised question relates to format of 'perf stat --iiostat' subcommand
and explained how it can be changed to 'perf iiostat' through the aliases mechanism in perf.

Yeah, I know that. What I'm asking is the DELIMITER part.

Thanks,
Namhyung

I'm using DELIMITER to resolve two different cases for format of iiostat command:
The first one is the command with an option for iiostat mode, for example:
'perf iiostat show' which should be converted to 'perf stat --iiostat=show' or 'perf iiostat 0000:ae,0000:5d' to 'perf stat --iiostat=0000:ae,0000:5d'. The second is the command without any option for iiostat: 'perf iiostat -I 1000' should be converted to 'perf stat --iiostat -I 1000'.

Thanks,
Alexander

maintainer
#16 lore raw

Re: [PATCH v2 5/6] perf stat: Enable iiostat mode for x86 platforms

Quoted 36 lines · Alexander Antonov
Quoted 27 lines · Namhyung Kim
Quoted 25 lines · Alexander Antonov
Quoted 23 lines · Namhyung Kim

On Wed, Dec 23, 2020 at 10:03 PM Alexander Antonov

Quoted 8 lines
tools/perf/perf-iiostat.sh new file +2 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

tools/perf/perf-iiostat.sh line 12

Quoted 10 lines
tools/perf/perf-iiostat.sh new file +10 -0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*

Why is this needed?

Thanks,
Namhyung

Quoted 8 lines
Quoted 4 lines

Arnaldo raised question relates to format of 'perf stat --iiostat' subcommand
and explained how it can be changed to 'perf iiostat' through the aliases mechanism in perf.

Yeah, I know that. What I'm asking is the DELIMITER part.

Thanks,
Namhyung

Quoted 9 lines

I'm using DELIMITER to resolve two different cases for format of iiostat command:
The first one is the command with an option for iiostat mode, for example:
'perf iiostat show' which should be converted to 'perf stat --iiostat=show' or
'perf iiostat 0000:ae,0000:5d' to 'perf stat --iiostat=0000:ae,0000:5d'. The second is the command without any option for iiostat: 'perf iiostat -I 1000'
should be converted to 'perf stat --iiostat -I 1000'.

Can't we simply use a whitespace ?

Thanks,
Namhyung

#17 lore raw

Re: [PATCH v2 5/6] perf stat: Enable iiostat mode for x86 platforms

Quoted 46 lines · Namhyung Kim
Quoted 35 lines · Alexander Antonov
Quoted 26 lines · Namhyung Kim
Quoted 24 lines · Alexander Antonov
Quoted 23 lines · Namhyung Kim

On Wed, Dec 23, 2020 at 10:03 PM Alexander Antonov

Quoted 8 lines
tools/perf/perf-iiostat.sh new file +2 -0
new file mode 100644
index 000000000000..2c5168d2550b
@@ -0,0 +1,12 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

tools/perf/perf-iiostat.sh line 12

Quoted 10 lines
tools/perf/perf-iiostat.sh new file +10 -0
+# perf iiostat
+# Alexander Antonov <[email protected]>
+
+if [[ "$1" == "show" ]] || [[ "$1" =~ ([a-f0-9A-F]{1,}):([a-f0-9A-F]{1,2})(,)? ]]; then
+        DELIMITER="="
+else
+        DELIMITER=" "
+fi
+
+perf stat --iiostat$DELIMITER$*

Why is this needed?

Thanks,
Namhyung

Quoted 8 lines
Quoted 4 lines

Arnaldo raised question relates to format of 'perf stat --iiostat' subcommand
and explained how it can be changed to 'perf iiostat' through the aliases mechanism in perf.

Yeah, I know that. What I'm asking is the DELIMITER part.

Thanks,
Namhyung

Quoted 9 lines

I'm using DELIMITER to resolve two different cases for format of iiostat command:
The first one is the command with an option for iiostat mode, for example:
'perf iiostat show' which should be converted to 'perf stat --iiostat=show' or
'perf iiostat 0000:ae,0000:5d' to 'perf stat --iiostat=0000:ae,0000:5d'. The second is the command without any option for iiostat: 'perf iiostat -I 1000'
should be converted to 'perf stat --iiostat -I 1000'.

Quoted 1 line

Can't we simply use a whitespace ?

We need to use the equal sign to pass arguments to iiostat mode.

Thanks,
Alexander