Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp609400ybg; Wed, 3 Jun 2020 09:02:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6OnItcBnGIUKVoGVCkzODmo7VZAiNwph9UvB4vqf9My0u83WTS4Gy5/F1Ar5WHgRDwLbM X-Received: by 2002:a17:906:2656:: with SMTP id i22mr13959666ejc.397.1591200145352; Wed, 03 Jun 2020 09:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591200145; cv=none; d=google.com; s=arc-20160816; b=mJ72s8nIG2ElsekF4CC2ymJOp5hJCryuOTMJer3mSJ2IW0tJBi9JiS//xUKNYeV+w8 fKOcb1QuQAvzcdnyktCbkLuQWrVhp8PRSwo8ypLHLGM3w8Vg+zk3B9WSdVhz7zupqb8y 6fSzz1GKTG2ZcegMAEmNlx4hr6wPXaaSvgexyWT2IAJJhiNeM0VPmz+dBLkEa0jy4TsE ZKD53f/4eAI48tD9Lyy38k3L5pHY3jJMppvpjGpIhm71VLAHIWC2GgCuHDDyPGnTav2d TEZDkHY4moz9mVtnnq8ZpB6TvKl5G8fUVKwTD1oXIMcXN5eJ71Ro9FjNcDaHqrAtgaEP HRhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject:ironport-sdr :ironport-sdr; bh=cHNi9lQzlgUBC6Uy49+VJaWKvIA2bz8aJB4o3+dQFyE=; b=epXb5nXNXt9BUKO31J2+3lvn25vs/YxabC9DMNOKjdZ9SXL5iDiHrq0tjKaBb3jClK p3mf6/dwBnxlLnccv4g/5fYNUKIFXFQabZ6tmIUjmxkbzBvJ+A1U/kTHjVygjJnlbEWx Rzk9otHlcsTH+1pQBg8SK3xtXxw078n+SsQf1NNafDArDYLsvcyqmVT44lkwd/W7RN2c I+OH7KGIPKsNFLvRbth5u0yCT5RGJXxNxp3t7r0MLiGdHe10/itXeqUU4/CihL3uqCq1 zj0xXBk0KBREMuToTQHaPn5AHVGK+5RCkjMfzya1Rz2q8QHu+Kndyu9sz0ymnu/5msKu J4eQ== 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 r27si1328352edl.187.2020.06.03.09.02.00; Wed, 03 Jun 2020 09:02:25 -0700 (PDT) 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 S1726077AbgFCQAE (ORCPT + 99 others); Wed, 3 Jun 2020 12:00:04 -0400 Received: from mga07.intel.com ([134.134.136.100]:9932 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725920AbgFCQAD (ORCPT ); Wed, 3 Jun 2020 12:00:03 -0400 IronPort-SDR: m28VJlErmi8LqEnrQp//xEqhOxUrYOO0itZERl/26InNxpYahvlhJ9qw8lgmTfYGrhVIJQto2t iIt2x+EGqUwg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2020 09:00:03 -0700 IronPort-SDR: YBEHLJcyoua7ROdjAQ7NG7vaWAiTULmO6E5ropl+1HxDDoSwyhd4Uy/Hnf59eXVrlxRPxVqaiA ABt8oDAaQwfw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,468,1583222400"; d="scan'208";a="258647015" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 03 Jun 2020 09:00:02 -0700 Received: from [10.249.225.188] (abudanko-mobl.ccr.corp.intel.com [10.249.225.188]) by linux.intel.com (Postfix) with ESMTP id 22A6E5800E3; Wed, 3 Jun 2020 08:59:59 -0700 (PDT) Subject: [PATCH v7 10/13] perf stat: introduce --ctl-fd[-ack] options From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <5de4b954-24f0-1e8d-5a0d-7b12783b8218@linux.intel.com> Organization: Intel Corp. Message-ID: <4f0d0d42-8faf-fb9c-26f7-4db8fbc3f052@linux.intel.com> Date: Wed, 3 Jun 2020 18:59:58 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <5de4b954-24f0-1e8d-5a0d-7b12783b8218@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce --ctl-fd[-ack] options to pass open file descriptors numbers from command line. Extend perf-stat.txt file with --ctl-fd[-ack] options description. Document possible usage model introduced by --ctl-fd[-ack] options by providing example bash shell script. Signed-off-by: Alexey Budankov --- tools/perf/Documentation/perf-stat.txt | 40 ++++++++++++++++++++++++++ tools/perf/builtin-stat.c | 11 +++++++ tools/perf/util/stat.h | 2 ++ 3 files changed, 53 insertions(+) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 9f32f6cd558d..029afa009865 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -176,6 +176,46 @@ with it. --append may be used here. Examples: 3>results perf stat --log-fd 3 -- $cmd 3>>results perf stat --log-fd 3 --append -- $cmd +--ctl-fd:: +--ctl-fd-ack:: +Listen on ctl-fd descriptor for command to control measurement ('enable': enable events, +'disable': disable events). Measurements can be started with events disabled using +--delay=-1 option. Optionally send control command completion ('ack\n') to fd-ack descriptor +to synchronize with the controlling process. Example of bash shell script to enable and +disable events during measurements: + +#!/bin/bash + +ctl_dir=/tmp/ + +ctl_fifo=${ctl_dir}perf_ctl.fifo +test -p ${ctl_fifo} && unlink ${ctl_fifo} +mkfifo ${ctl_fifo} +exec {ctl_fd}<>${ctl_fifo} + +ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo +test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo} +mkfifo ${ctl_ack_fifo} +exec {ctl_fd_ack}<>${ctl_ack_fifo} + +perf stat -D -1 -e cpu-cycles -a -I 1000 \ + --ctl-fd ${ctl_fd} --ctl-fd-ack ${ctl_fd_ack} \ + -- sleep 30 & +perf_pid=$! + +sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})" +sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})" + +exec {ctl_fd_ack}>&- +unlink ${ctl_ack_fifo} + +exec {ctl_fd}>&- +unlink ${ctl_fifo} + +wait -n ${perf_pid} +exit $? + + --pre:: --post:: Pre and post measurement hooks, e.g.: diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index cc56d71a3ed5..8d79ba54dbf9 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -188,6 +188,8 @@ static struct perf_stat_config stat_config = { .metric_only_len = METRIC_ONLY_LEN, .walltime_nsecs_stats = &walltime_nsecs_stats, .big_num = true, + .ctl_fd = -1, + .ctl_fd_ack = -1 }; static bool cpus_map_matched(struct evsel *a, struct evsel *b) @@ -1133,6 +1135,10 @@ static struct option stat_options[] = { "libpfm4 event selector. use 'perf list' to list available events", parse_libpfm_events_option), #endif + OPT_INTEGER(0, "ctl-fd", &stat_config.ctl_fd, + "Listen on fd descriptor for command to control measurement ('enable': enable events, 'disable': disable events)"), + OPT_INTEGER(0, "ctl-fd-ack", &stat_config.ctl_fd_ack, + "Send control command completion ('ack') to fd ack descriptor"), OPT_END() }; @@ -2304,6 +2310,9 @@ int cmd_stat(int argc, const char **argv) signal(SIGALRM, skip_signal); signal(SIGABRT, skip_signal); + if (evlist__initialize_ctlfd(evsel_list, stat_config.ctl_fd, stat_config.ctl_fd_ack)) + goto out; + status = 0; for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) { if (stat_config.run_count != 1 && verbose > 0) @@ -2323,6 +2332,8 @@ int cmd_stat(int argc, const char **argv) if (!forever && status != -1 && (!interval || stat_config.summary)) print_counters(NULL, argc, argv); + evlist__finalize_ctlfd(evsel_list); + if (STAT_RECORD) { /* * We synthesize the kernel mmap record just so that older tools diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 626421ef35c2..06f0baabe775 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -133,6 +133,8 @@ struct perf_stat_config { struct perf_cpu_map *cpus_aggr_map; u64 *walltime_run; struct rblist metric_events; + int ctl_fd; + int ctl_fd_ack; }; void perf_stat__set_big_num(int set); -- 2.24.1