Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4697774pxu; Thu, 10 Dec 2020 03:19:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxW7EmFkev9sc7s/CQz1vmZ6ggtqBk8tnJhzw3CmdD4EklDgvXOL4rLcr5SIC/QqISTi7rA X-Received: by 2002:a17:906:4944:: with SMTP id f4mr6068443ejt.231.1607599160523; Thu, 10 Dec 2020 03:19:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607599160; cv=none; d=google.com; s=arc-20160816; b=tbcRCo9/qnlS7vCRaeHYsACFtByl18HaG0bYXRhAqxM4A1eZ7fVrnDclmKxUsnATPW DyK+k1vmcavFaifkJOSQZzcns1T+YBDaHAjJ/RUJfthwxCQwC4LR0OBddhRMgsJBvAzb 3/7+iKN1IuX64+zhqllROYdO7AlrKr5ij14yPu6g5PTIWll8k3lOFcL5yqBAP3YjFUUe 0c0bIa6yKhGIl2qwK/II+22xr4W3m7FqTXvUGZyrOJ3yNmG+HRyzN0tgMfYR/GQGqfdu KOE6F4lPBAPZVHu7R1YsuYWHxan4o3O2yXMU4uyybo3GdUC1TyyRrpoxc3XFDVv19Y2i p82Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=pWVBRBWPvzP2QG23cFNO0pVRn7twxfqPeDoOLCCGmjk=; b=cDhOgW4t8qs4cLi354equPYLOUI+2zDOu/Szl0tQIsOg5IMxzSndFXFS7zkysU9HIS tFrqGSDVSPKF5z+dUL10SZr/c9VmV/tLrsTN3gYrxiVlmJ9y5HjlYYNv3LBLA3QnnuBT +KGmT2H0L6xIDEzlJ5KILQT9yTmJwgc4NxTkMhoLDrTCxeoGnuCHUHZamuhomkPW6MfB vr3TfxSlraYua6vqWkp9Hvg/QbEM3f2bmEnKnSjaLhjKzucuFhFE6j8qYMyrBzrUWCXx wrknM5zaY3hkBYvY0SdKHfn3ZjvNUapZWqq6CZGwQhvI4AwdTlqx1khiwM9yVgxtXrCY 0fXQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si2353395eje.347.2020.12.10.03.18.57; Thu, 10 Dec 2020 03:19:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729094AbgLJJG4 (ORCPT + 99 others); Thu, 10 Dec 2020 04:06:56 -0500 Received: from mga11.intel.com ([192.55.52.93]:6071 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726278AbgLJJGz (ORCPT ); Thu, 10 Dec 2020 04:06:55 -0500 IronPort-SDR: EKiwKmg2mDQ7gRW7q5Ropfaqjx7cgm0OmkuI5IpwUz9VAQqJaBO6JgfYHmNNqlU1K1KGhDIQGR Uqx1yMSbgFeg== X-IronPort-AV: E=McAfee;i="6000,8403,9830"; a="170712751" X-IronPort-AV: E=Sophos;i="5.78,408,1599548400"; d="scan'208";a="170712751" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2020 01:03:56 -0800 IronPort-SDR: m2ZtIuTECe+SCyaATm0Tla8UKJ5CBxw6h81N+qPVlstJABxZ0mPBAhzsz+Mj9RK/p4BNqSsssv ruDUww7wE4hA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,408,1599548400"; d="scan'208";a="408450130" Received: from nntpdsd52-183.inn.intel.com ([10.125.52.183]) by orsmga001.jf.intel.com with ESMTP; 10 Dec 2020 01:03:53 -0800 From: Alexander Antonov To: acme@kernel.org Cc: linux-kernel@vger.kernel.org, jolsa@redhat.com, alexander.shishkin@linux.intel.com, mark.rutland@arm.com, namhyung@kernel.org, mingo@redhat.com, peterz@infradead.org, ak@linux.intel.com, alexander.antonov@linux.intel.com Subject: [PATCH 3/5] perf stat: Basic support for iiostat in perf stat Date: Thu, 10 Dec 2020 12:03:38 +0300 Message-Id: <20201210090340.14358-4-alexander.antonov@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20201210090340.14358-1-alexander.antonov@linux.intel.com> References: <20201210090340.14358-1-alexander.antonov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add basic flow for a new --iiostat mode in perf stat. 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. Signed-off-by: Alexander Antonov --- 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 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index e3ff55de4f7a..c8168cfe202b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -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 @@ -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) diff --git a/tools/perf/util/iiostat.h b/tools/perf/util/iiostat.h new file mode 100644 index 000000000000..6a905b2b40b9 --- /dev/null +++ b/tools/perf/util/iiostat.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * perf stat --iiostat + * + * Copyright (C) 2020, Intel Corporation + * + * Authors: Alexander Antonov + */ + +#ifndef _IIOSTAT_H +#define _IIOSTAT_H + +#include +#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 */ diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 3bfcdb80443a..9eb8484e8b90 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -17,6 +17,7 @@ #include "cgroup.h" #include #include "util.h" +#include "iiostat.h" #define CNTR_NOT_SUPPORTED "" #define CNTR_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: diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 901265127e36..c5851ceb4c6b 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -9,6 +9,7 @@ #include "expr.h" #include "metricgroup.h" #include +#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) { diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index d053ebd44ae3..a072dfe3dbbf 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -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; -- 2.19.1