Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2246763ybb; Fri, 27 Mar 2020 01:49:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuMGWUdVAetaoVliHaWWKqnAkoi5oKYtjinf7fuEBTKjD60opRH1/lxbGl4jPvVwtnxncLn X-Received: by 2002:a05:6830:146:: with SMTP id j6mr9272286otp.352.1585298940826; Fri, 27 Mar 2020 01:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585298940; cv=none; d=google.com; s=arc-20160816; b=TGsgLrXezOIixszg8K6iLEbNLUu+eAawoAo3f3O55Gy1UrztQaGLgBcUHnFgKctkxW 9l9XpvMVEFxycUn/Iq/lWWbGCSm87y4LotO0VlyBEiAyWghWKKZqiT7M5FRgM83DvZO0 fetCtJKucIsp+r+xWZJS7nrGvmQY6C0F6Ti9d9lCpjggXpqNzExZgddRobW9FeereQTE xJMyHK38wYGYUSit0K+CDSOndhSu+HEfloxqLOvTscVQrw+738iUSp7GtBGFAxTSPW5d jc4dbH8G+uxuAgXKKUG3rrYljiMBrHxuucgngjIuOXhxkzoORbgka/UZRuSyuuH3ntYm XvRw== 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=2GastX/d4RvdUYLFP3ZPqUZGQPBlLGg2rQb4REhRdnM=; b=IAEcfY/PxX+xNUcqAHvz0+vWVOh7I4BAJuqQFP81cVaA7aAMO7jc3HaFSqgMDDGro1 v/2iEa5AMBpbuDmg1Qi4XzjS6dmLM9DuXa9Sno6zz3u+i8e+xdWjDBlD+qlTqxgIpgV2 /NJwryTTbXvAf8ngjbDhejVqjkMrtpnU+KUq9N9FV6r23giHUwrf3s782rsdKkxXHQ2y vhVByLqSvcxAeEmm5ggr53zWlGSLIB8pqDIwK0BZtIknHlQd/hNbA8/ht8RKzzj+lc8t yCn+NxZLgFeALZcU/Rn4X3gi2ZewL1pdxgL7NwzQnpbAutY/5sQCeKxLdawDPvDa7SQY uw3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id q6si2029129oth.138.2020.03.27.01.48.48; Fri, 27 Mar 2020 01:49:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726333AbgC0Iro (ORCPT + 99 others); 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