Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2112331ybt; Fri, 3 Jul 2020 00:48:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIhomBhAxLpraFO9mj907i3gJQkUB4xfatS1CJxI99VLOY6/7FpdkCmm1tmUjC/NmV9dtW X-Received: by 2002:a17:906:1db1:: with SMTP id u17mr24790634ejh.72.1593762537078; Fri, 03 Jul 2020 00:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593762537; cv=none; d=google.com; s=arc-20160816; b=QqG+KtytarhjJ+fRXhzaNWVr1eyr6czUmZZeX2y4dNS7gjfMY1OYiBUCc/+N2jz6Z9 dUVoR6TgSIoejsQ1rvj1hPHVFmeH0zQi8e6F1VoRaQRSaalhGb6lK8kf+TSCK9TRR+Ve 2LQcKH3QBi0V1mx1T0SeoyIYxlgibROYsvzwEM0J7wkTyNkuUbJj1hPJUn+MCTD9E8mj iC1/Q9fg9rb2RY5K7TF+ihU36Z986e/8uiNUyaHPeCidtL7qA94qMy4L39+1DiRQzJUy fGnHgOfFxrK5Y0g05z8PJ2jQRACnDhC1KqgyRSx6aWDyrvkorH1WKj/IDzIJyjlkMsio EOGg== 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=GbV4XyCT8H1QtCdBEeJ8CRgdEAJoTgDN1OPvhc5HmRA=; b=BlmueRJ7ewdDN9/apwHngGgE7FT13rYCGO1owk1mp+CYB0WYBuGBYwM94jSF7U856D WPoSApGLhygjyRaGMGPS4n6HsQAI3TU7AZ1y7dWq9fqVkClBTZ45KImhpziZpp157PSP FlkIwXPQyCW0pXpdC+u8Pe62SCHK0Wd5OdFGJ10zwMgFvIl0hQBYVuI0hHOHcF2IcFCs sopi+vN1nTjlyaBmQ2Xci2up57h27Row22M/4P9dg7Ig/2WCiQiVUecBLhAWxplUz1Cy ZC9e9CbRHNXuFZlEhVRtr6k2QIHGoWdzFKYIchw9w7/hz+3y+GzcusubjULMGlV5O45T BH3A== 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 v20si7493086ejx.754.2020.07.03.00.48.34; Fri, 03 Jul 2020 00:48:57 -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 S1726098AbgGCHr3 (ORCPT + 99 others); Fri, 3 Jul 2020 03:47:29 -0400 Received: from mga09.intel.com ([134.134.136.24]:42659 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725779AbgGCHr3 (ORCPT ); Fri, 3 Jul 2020 03:47:29 -0400 IronPort-SDR: fbcj0PsgF7t/rv0XDyqzjtOJJbfd+BzAGS+ZQ2eU7RG67yGkUwDRYiuXPrB+qJvzXdKtiEgQX3 YEaeAzU+vplw== X-IronPort-AV: E=McAfee;i="6000,8403,9670"; a="148636483" X-IronPort-AV: E=Sophos;i="5.75,307,1589266800"; d="scan'208";a="148636483" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2020 00:47:28 -0700 IronPort-SDR: c/zT7KvmQnd/G2QfimUB57y2tckCernOCsvapCdbds5gCl2pwp6+FNqoeFTH+FcXMakvHWnA8W x9gJSwixYphg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,307,1589266800"; d="scan'208";a="296143768" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP; 03 Jul 2020 00:47:28 -0700 Received: from [10.249.231.67] (abudanko-mobl.ccr.corp.intel.com [10.249.231.67]) by linux.intel.com (Postfix) with ESMTP id 5D1BD580781; Fri, 3 Jul 2020 00:47:23 -0700 (PDT) Subject: [PATCH v9 11/15] perf stat: implement control commands handling From: Alexey Budankov To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: Organization: Intel Corp. Message-ID: <21669f5a-6220-df0a-09f1-b73b32487f23@linux.intel.com> Date: Fri, 3 Jul 2020 10:47:22 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: 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 Implement handling of 'enable' and 'disable' control commands coming from control file descriptor. process_evlist() function checks for events on control fds and makes required operations. If poll event splits initiated timeout interval then the reminder is calculated and still waited in the following poll() syscall. Signed-off-by: Alexey Budankov --- tools/perf/builtin-stat.c | 75 ++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 9e4288ecf2b8..5021f7286422 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -485,6 +485,31 @@ static bool handle_interval(unsigned int interval, int *times) return false; } +static bool process_evlist(struct evlist *evlist, unsigned int interval, int *times) +{ + bool stop = false; + enum evlist_ctl_cmd cmd = EVLIST_CTL_CMD_UNSUPPORTED; + + if (evlist__ctlfd_process(evlist, &cmd) > 0) { + switch (cmd) { + case EVLIST_CTL_CMD_ENABLE: + pr_info(EVLIST_ENABLED_MSG); + stop = handle_interval(interval, times); + break; + case EVLIST_CTL_CMD_DISABLE: + stop = handle_interval(interval, times); + pr_info(EVLIST_DISABLED_MSG); + break; + case EVLIST_CTL_CMD_ACK: + case EVLIST_CTL_CMD_UNSUPPORTED: + default: + break; + } + } + + return stop; +} + static void enable_counters(void) { if (stat_config.initial_delay < 0) { @@ -560,10 +585,21 @@ static bool is_target_alive(struct target *_target, return false; } -static int dispatch_events(bool forks, int timeout, int interval, int *times, struct timespec *ts) +static int dispatch_events(bool forks, int timeout, int interval, int *times) { bool stop = false; int child_exited = 0, status = 0; + int time_to_sleep, sleep_time; + struct timespec time_start, time_stop, time_diff; + + if (interval) + sleep_time = interval; + else if (timeout) + sleep_time = timeout; + else + sleep_time = 1000; + + time_to_sleep = sleep_time; while (1) { if (forks) @@ -574,11 +610,22 @@ static int dispatch_events(bool forks, int timeout, int interval, int *times, st if (done || stop || child_exited) break; - nanosleep(ts, NULL); - if (timeout) - stop = true; - else - stop = handle_interval(interval, times); + clock_gettime(CLOCK_MONOTONIC, &time_start); + if (!(evlist__poll(evsel_list, time_to_sleep) > 0)) { /* poll timeout or EINTR */ + if (timeout) + stop = true; + else + stop = handle_interval(interval, times); + time_to_sleep = sleep_time; + } else { /* fd revent */ + stop = process_evlist(evsel_list, interval, times); + clock_gettime(CLOCK_MONOTONIC, &time_stop); + diff_timespec(&time_diff, &time_stop, &time_start); + time_to_sleep -= time_diff.tv_sec * MSEC_PER_SEC + + time_diff.tv_nsec / NSEC_PER_MSEC; + if (time_to_sleep < 0) + time_to_sleep = 0; + } } return status; @@ -647,7 +694,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) char msg[BUFSIZ]; unsigned long long t0, t1; struct evsel *counter; - struct timespec ts; size_t l; int status = 0; const bool forks = (argc > 0); @@ -656,17 +702,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) int i, cpu; bool second_pass = false; - if (interval) { - ts.tv_sec = interval / USEC_PER_MSEC; - ts.tv_nsec = (interval % USEC_PER_MSEC) * NSEC_PER_MSEC; - } else if (timeout) { - ts.tv_sec = timeout / USEC_PER_MSEC; - ts.tv_nsec = (timeout % USEC_PER_MSEC) * NSEC_PER_MSEC; - } else { - ts.tv_sec = 1; - ts.tv_nsec = 0; - } - if (forks) { if (perf_evlist__prepare_workload(evsel_list, &target, argv, is_pipe, workload_exec_failed_signal) < 0) { @@ -824,7 +859,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) enable_counters(); if (interval || timeout) - status = dispatch_events(forks, timeout, interval, ×, &ts); + status = dispatch_events(forks, timeout, interval, ×); if (child_pid != -1) { if (timeout) kill(child_pid, SIGTERM); @@ -841,7 +876,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) psignal(WTERMSIG(status), argv[0]); } else { enable_counters(); - status = dispatch_events(forks, timeout, interval, ×, &ts); + status = dispatch_events(forks, timeout, interval, ×); } disable_counters(); -- 2.24.1