Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1327548ybs; Mon, 25 May 2020 13:04:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz41Jycm+uoknB/vLnDz1nXjqFrFZMOb6ws+Fnl8SRlnEvM4crJT/KqkLROSEk7EBD15AQK X-Received: by 2002:a17:906:a843:: with SMTP id dx3mr19024230ejb.396.1590437074843; Mon, 25 May 2020 13:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590437074; cv=none; d=google.com; s=arc-20160816; b=Vfxvsj5/rFg+0ALiRmTmotc+WJZFKOmtJbIAi+alk/ayU3aohQInkQxTR0sbwja6Ms fDnyntCXaOIicgFzDZtzcK45NIVToamyKQIOE/oYp5z2Z6B2rw8xcVC/zGuOktpU1MiH ZDx2FskujQwFfFWb55YOeW2vUd60AuLX3ldM2W5MnXAN2ggrjhg1iXxOVa34RTQnKsUG LeYF3Puys3GyAvUFyVMBryhO12a/eTPR38eSCElWbCM5QhL6qIiGdC4Y4zNl8rwT4mUI RwIcjLnQ8Zz7a+s5NZztHFlHlwncDTa9LQgsgJrdJ9nYqabrBVwfgz/tdQUF2NnsEBMh kPPQ== 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=T87F+Tvtie7VcfAYNk3Y7ARwyw853kcJCYnJW/5jLeY=; b=clkj/brYJSsli37Yje7AEIQCx3oIV4NZsV7OvAOI2ukdjMlJvA+1YIwnxiVsKhxfNE PyQguF78/ICTVkPJ9n+c8GPc0bZJG9eJ2+rZj6ilgwkObHq6NDDv2GzNqqkmD7HUlYcb bGBcazdXu56dT9jn1oQlPCWsRTDDO+E8oTplT9hn+Cj95qEcXaVS0jjCGtVoEwxPJeE5 2dbqM/NlX6AaPcz5xxdNehaDRAeJ30gumtWjikDaROcP1Aj0UnlDQ2XR+lhG+kbOXIxV y4q39yG1TLt3m9QAnVLdvUs1vz6fz7DXmzkrt1NpZiBATNqEpzynt52lOaujXOm17/7S U3Ew== 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 o16si9677031ejx.200.2020.05.25.13.04.11; Mon, 25 May 2020 13:04:34 -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 S2403927AbgEYOWF (ORCPT + 99 others); Mon, 25 May 2020 10:22:05 -0400 Received: from mga12.intel.com ([192.55.52.136]:11431 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403901AbgEYOWE (ORCPT ); Mon, 25 May 2020 10:22:04 -0400 IronPort-SDR: 1V10DtNLCC721KP7oaOKHwFUmvC+I+N5fdzSsAGgc2Hd4WEecM5Upty/Zc338E5TY7BoTNMQvF 7AB+xnGOGO7g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2020 07:22:03 -0700 IronPort-SDR: QeUxyEsN8Iwb7+4/tM3BhY/guOL4G5vo6//qPJh6xT2xFMySn+QqTCuOeKxjjeHzbhvVgxv8n7 cle/rfaNofrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,433,1583222400"; d="scan'208";a="468064232" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 25 May 2020 07:22:03 -0700 Received: from [10.249.227.191] (abudanko-mobl.ccr.corp.intel.com [10.249.227.191]) by linux.intel.com (Postfix) with ESMTP id 1B376580101; Mon, 25 May 2020 07:22:00 -0700 (PDT) Subject: [PATCH v4 07/10] 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: <653fe5f3-c986-a841-1ed8-0a7d2fa24c00@linux.intel.com> Organization: Intel Corp. Message-ID: <1acee82c-5a75-2e14-c7d7-004872771aae@linux.intel.com> Date: Mon, 25 May 2020 17:21:59 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <653fe5f3-c986-a841-1ed8-0a7d2fa24c00@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 b4d2434584f5..4b15373af800 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -164,6 +164,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). Optionally send control command completion ('ack') 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 c06c2b701a15..69b0e4f498c6 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -187,6 +187,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 inline void diff_timespec(struct timespec *r, struct timespec *a, @@ -1065,6 +1067,10 @@ static struct option stat_options[] = { "Use with 'percore' event qualifier to show the event " "counts of one hardware thread by sum up total hardware " "threads of same physical core"), + 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() }; @@ -2232,6 +2238,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) @@ -2251,6 +2260,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 b00d64f0ca26..65f42a04d9ef 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -131,6 +131,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 update_stats(struct stats *stats, u64 val); -- 2.24.1