Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp799062ybk; Wed, 13 May 2020 13:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLC3f5vZxlCScj9xyvvVn3610p1GixSaKQxkt54o7A9XHQaQNnqQsZW6767YCWkaO5oQsy X-Received: by 2002:a50:f0ce:: with SMTP id a14mr1279521edm.131.1589401629371; Wed, 13 May 2020 13:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589401629; cv=none; d=google.com; s=arc-20160816; b=g9MY7QF7Zr42m/elWesGlpvDjPZ9zLACCSS/B/SbArgdIUb7FJrUMapRh2EKLwLsOD PxJgV0yqifTsmRrypRcvAP3UHeG5Q3lTbz2uORCTNA0rV34kYVXhQOIw7kujfbF2NWkE 71r88SaBJ7IPOKM1OaIukMI5xUVIFmIbifp9mxJBhx8xVNOyWhns/gXVzLcqUBvqcsVg DgNhD1RSAZ0gHUhG+men9/doG4046eDI7itRMZsBphYGZipA8IefdYzP0wMLV+74ksCo XfGRxfTTrzfhe+VzrdBcgBGN9FQy73uIbih63hfXD9qWHvJoBuFznK+qxpdYnMFxFMzB MBAQ== 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=D0QEUkCgj4uBQcqb2ExKQmlWkeAjmbQWQPAJlldRy4A=; b=fjGQsnr3hRejcAONnRajZssaOkqzD9LFeMaVkm6Li9/RFQxFU2J9PTmZB/AMKZiZcm WdCG+1+g1vHfsoMqoYul0RGaBLQaI0IE10Gin94rr3sIjs8+gLh98MgMeS47IceMoZPt h9GvOFYYn+LztCrTXrBK6k5bMmc3C/Px2qYKZmesuiDCPyA1qikI5In1190Rgr6B3ip6 eVYtWPAmA0rtBJIEK2jQtauDK9L6l7/1XIfwW3dnRwI6tXBartYZ/G+CyPn08n25EwKg qiV2GaBYcKb3LWvhgrp9K33HnYqbFPTG7A6TlcTmt/Q08Qqd8nQfSIXRQIIrldDvSOao yR8g== 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 n9si402657edf.138.2020.05.13.13.26.46; Wed, 13 May 2020 13:27:09 -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 S1730170AbgEMICV (ORCPT + 99 others); Wed, 13 May 2020 04:02:21 -0400 Received: from mga14.intel.com ([192.55.52.115]:23603 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbgEMICU (ORCPT ); Wed, 13 May 2020 04:02:20 -0400 IronPort-SDR: JZ0Svd37T+x416omlfFpFH2W0Aj15T8StQ4savGGi3sosiRxdWRLvk3D91ukOG0JSAzX2WbThh SN46lPjPIfhQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2020 01:02:19 -0700 IronPort-SDR: wztqazqq9liGBQrgBpLa606ACq7Xwi2JmaNJWCNPSqi4PV9Ao0LVSQUxrI/ZkP1WIci4cOWihB 9OHpeluq5+VA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,387,1583222400"; d="scan'208";a="463844038" Received: from linux.intel.com ([10.54.29.200]) by fmsmga005.fm.intel.com with ESMTP; 13 May 2020 01:02:19 -0700 Received: from [10.249.229.18] (abudanko-mobl.ccr.corp.intel.com [10.249.229.18]) by linux.intel.com (Postfix) with ESMTP id 164CC5804B6; Wed, 13 May 2020 01:02:16 -0700 (PDT) Subject: [PATCH v3 5/9] perf stat: implement control commands handling From: Alexey Budankov To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: Organization: Intel Corp. Message-ID: <078a7905-f029-88c4-9bd5-1c6a394d3e82@linux.intel.com> Date: Wed, 13 May 2020 11:02:15 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.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. Signed-off-by: Alexey Budankov --- tools/perf/builtin-stat.c | 48 +++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 73404b723592..abea82a1ba24 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -460,8 +460,9 @@ static int handle_events(pid_t pid, struct perf_stat_config *config) { pid_t child = 0; bool res, stop = false; - struct timespec time_to_sleep; - int sleep_time, status = 0, times = config->times; + int time_to_sleep, sleep_time, status = 0, times = config->times; + enum evlist_ctl_cmd cmd = EVLIST_CTL_CMD_UNSUPPORTED; + struct timespec time_start, time_stop, time_diff; if (config->interval) sleep_time = config->interval; @@ -470,22 +471,45 @@ static int handle_events(pid_t pid, struct perf_stat_config *config) else sleep_time = 1000; - time_to_sleep.tv_sec = sleep_time / MSEC_PER_SEC; - time_to_sleep.tv_nsec = (sleep_time % MSEC_PER_SEC) * NSEC_PER_MSEC; + time_to_sleep = sleep_time; do { if (pid != -1) child = waitpid(pid, &status, WNOHANG); if (child || stop || done) break; - nanosleep(&time_to_sleep, NULL); - if (pid == -1) - stop = !is_target_alive(&target, evsel_list->core.threads); - if (config->timeout) { - stop = !stop ? true : stop; - } else { - res = print_interval_and_stop(config, ×); - stop = !stop ? res : stop; + clock_gettime(CLOCK_MONOTONIC, &time_start); + if (!(evlist__poll(evsel_list, time_to_sleep) > 0)) { /* poll timeout or EINTR */ + if (pid == -1) + stop = !is_target_alive(&target, evsel_list->core.threads); + if (config->timeout) { + stop = !stop ? true : stop; + } else { + res = print_interval_and_stop(config, ×); + stop = !stop ? res : stop; + } + time_to_sleep = sleep_time; + } else { /* fd revent */ + if (evlist__ctlfd_process(evsel_list, &cmd) > 0) { + switch (cmd) { + case EVLIST_CTL_CMD_ENABLE: + pr_info(EVLIST_ENABLED_MSG); + stop = print_interval_and_stop(config, ×); + break; + case EVLIST_CTL_CMD_DISABLE: + stop = print_interval_and_stop(config, ×); + pr_info(EVLIST_DISABLED_MSG); + break; + case EVLIST_CTL_CMD_ACK: + case EVLIST_CTL_CMD_UNSUPPORTED: + default: + break; + } + } + 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; } } while (1); -- 2.24.1