From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75B03C43331 for ; Fri, 27 Mar 2020 08:47:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BC3720716 for ; Fri, 27 Mar 2020 08:47:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726758AbgC0Iro (ORCPT ); Fri, 27 Mar 2020 04:47:44 -0400 Received: from mga04.intel.com ([192.55.52.120]:4766 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725946AbgC0Irn (ORCPT ); Fri, 27 Mar 2020 04:47:43 -0400 IronPort-SDR: TAantA/ZZCbTAbBu9uPuykj6nb4rFkW0l2seloxQzcbzzaggFc6U4PVo9jpdmMGjGFQ4HTvoxQ khqBl9SFBPnw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2020 01:47:43 -0700 IronPort-SDR: a0G6jkWI6RPL3Wlgf0lWKqyVd5UQS4Bt/Cg+13vdWsFlD/35y1LKYKW6Gvra/eGw7m1AZwshQy A0wqcksTyZHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,311,1580803200"; d="scan'208";a="251080347" Received: from linux.intel.com ([10.54.29.200]) by orsmga006.jf.intel.com with ESMTP; 27 Mar 2020 01:47:43 -0700 Received: from [10.249.36.56] (abudanko-mobl.ccr.corp.intel.com [10.249.36.56]) by linux.intel.com (Postfix) with ESMTP id 3C631580479; Fri, 27 Mar 2020 01:47:41 -0700 (PDT) Subject: [PATCH v1 3/8] perf stat: introduce control descriptors and --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: <825a5132-b58d-c0b6-b050-5a6040386ec7@linux.intel.com> Organization: Intel Corp. Message-ID: <98dfb3ce-dab9-3747-8748-fbf2777f69ba@linux.intel.com> Date: Fri, 27 Mar 2020 11:47:40 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <825a5132-b58d-c0b6-b050-5a6040386ec7@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 control file descriptors and --ctl-fd[-ack] options to pass control descriptors from command line. Extend --delay option with -1 value to start collection in paused mode to be resumed later by resume command provided via control file descriptor. Signed-off-by: Alexey Budankov --- tools/perf/builtin-stat.c | 28 ++++++++++++++++++++++++---- tools/perf/util/evlist.h | 3 +++ tools/perf/util/stat.h | 4 +++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ec053dc1e35c..0a1b79fd3f48 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, @@ -373,16 +375,26 @@ static void process_interval(void) static void enable_counters(void) { - if (stat_config.initial_delay) + if (stat_config.initial_delay < 0) { + pr_info(PERF_EVLIST__PAUSED_MSG); + return; + } + + if (stat_config.initial_delay > 0) { + pr_info(PERF_EVLIST__PAUSED_MSG); usleep(stat_config.initial_delay * USEC_PER_MSEC); + } /* * We need to enable counters only if: * - we don't have tracee (attaching to task or cpu) * - we have initial delay configured */ - if (!target__none(&target) || stat_config.initial_delay) + if (!target__none(&target) || stat_config.initial_delay) { evlist__enable(evsel_list); + if (stat_config.initial_delay > 0) + pr_info(PERF_EVLIST__RESUMED_MSG); + } } static void disable_counters(void) @@ -912,8 +924,8 @@ static struct option stat_options[] = { "aggregate counts per thread", AGGR_THREAD), OPT_SET_UINT(0, "per-node", &stat_config.aggr_mode, "aggregate counts per numa node", AGGR_NODE), - OPT_UINTEGER('D', "delay", &stat_config.initial_delay, - "ms to wait before starting measurement after program start"), + OPT_INTEGER('D', "delay", &stat_config.initial_delay, + "ms to wait before starting measurement after program start (-1: start paused"), OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL, "Only print computed metrics. No raw values", enable_metric_only), OPT_BOOLEAN(0, "topdown", &topdown_run, @@ -933,6 +945,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 ('r': resume, 'p': pause)"), + OPT_INTEGER(0, "ctl-fd-ack", &stat_config.ctl_fd_ack, + "Send control command completion ('a') to fd ack descriptor"), OPT_END() }; @@ -2129,6 +2145,8 @@ int cmd_stat(int argc, const char **argv) signal(SIGALRM, skip_signal); signal(SIGABRT, skip_signal); + perf_evlist__initialize_ctlfd(evsel_list, stat_config.ctl_fd, stat_config.ctl_fd_ack); + status = 0; for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) { if (stat_config.run_count != 1 && verbose > 0) @@ -2148,6 +2166,8 @@ int cmd_stat(int argc, const char **argv) if (!forever && status != -1 && !interval) print_counters(NULL, argc, argv); + perf_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/evlist.h b/tools/perf/util/evlist.h index a94b2993fafc..c91368483074 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -369,6 +369,9 @@ enum evlist_ctl_cmd { CTL_CMD_ACK = 'a' }; +#define PERF_EVLIST__RESUMED_MSG "Monitoring resumed\n" +#define PERF_EVLIST__PAUSED_MSG "Monitoring paused\n" + int perf_evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack); int perf_evlist__finalize_ctlfd(struct evlist *evlist); int perf_evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd); diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index b4fdfaa7f2c0..0b0fa3a2cde2 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -113,7 +113,7 @@ struct perf_stat_config { FILE *output; unsigned int interval; unsigned int timeout; - unsigned int initial_delay; + int initial_delay; unsigned int unit_width; unsigned int metric_only_len; int times; @@ -130,6 +130,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