Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1542351ybj; Fri, 8 May 2020 03:54:00 -0700 (PDT) X-Google-Smtp-Source: APiQypLLL0l/raQjUUsHxvq+rHlBhMhkShtqgAGnRjJ7KCXtB+wsLo+cKBqCkkhjcRvo3P71Gu1h X-Received: by 2002:a17:906:52d6:: with SMTP id w22mr1268895ejn.353.1588935240426; Fri, 08 May 2020 03:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588935240; cv=none; d=google.com; s=arc-20160816; b=COxoK5caNPmrfGRP2z+oa58IfNK3Dj46hG5Q3h2mTzXm58B3ez6tC58NHOTasSbuHq uD47PRTTfyPFlbQNnJ9DjBHv77eLBn4Rwf83gXQnWRIJksebed+4AyCxaefpTnZB3mqm RffM+05b89ZKfWlhOEcR8P6j1AZjUBumnVBkknbjQOyiceFLkIalkU8jK5wosyz035Y2 IfpWQJAE05liYLMty/C6siCv4tXnEK6myREbOA8GFeWxDCE3I6GGGAtKfnykFAmS85NB 5Kv2iYQEHuyCDlJcFzg077nzOpWFxoHdL0sDvX8BcFsXR4XK140O60dWS85WDV+YlVsM aPsg== 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=vB8PRFW+HTpjxOBHXnptZ/DvH1f6dVfJghA9zG4o40UBIXMP3g696JINzpFZ/wVnsu F11WGlrF4P6zH6MJJrLQ0+dd9p+LiQfOx1F7jFEdctdUouzNao/gg8QmNbj3CVGb4lnt PqldEqqe6F7hA4QO5U5fl+1xrcrR3//fOjC1LRdVQdmall8rL6BaEYf9VUUa06osud+7 GFaeCPZnA9gjgputTiO1xN60Kh8N8koJcX6sQCYCYHRD0O8cyiJCkxD+hSQkFwEmYJZ6 9A+aR5wPklKONRRRU571sPjbKPKvLat5joxr+cCfGRjV3Z/kn/XG7U/k0fJY1Eb3CGng jMxw== 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 f4si720357ejd.83.2020.05.08.03.53.24; Fri, 08 May 2020 03:54:00 -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 S1727795AbgEHKuo (ORCPT + 99 others); Fri, 8 May 2020 06:50:44 -0400 Received: from mga07.intel.com ([134.134.136.100]:46619 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726922AbgEHKun (ORCPT ); Fri, 8 May 2020 06:50:43 -0400 IronPort-SDR: QljuPMLafHHZ8E4r8H7w6f63uFfFi6AzH3vySEFR2iwHegRCIRX0NnULdpX4hYABpY7e3M8aDM HobM/TqEfLkA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2020 03:50:32 -0700 IronPort-SDR: 4fgqyW9pueXVJT8zDgpVZKYOYS6VDnvvkTw7P+0pNXtnCObO0kUkIeoLSvKnvWUg8XgEpq2pLj 76I2y8XjgYEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,367,1583222400"; d="scan'208";a="435643885" Received: from linux.intel.com ([10.54.29.200]) by orsmga005.jf.intel.com with ESMTP; 08 May 2020 03:50:32 -0700 Received: from [10.249.224.104] (abudanko-mobl.ccr.corp.intel.com [10.249.224.104]) by linux.intel.com (Postfix) with ESMTP id A9FA95805B4; Fri, 8 May 2020 03:50:30 -0700 (PDT) Subject: [PATCH v3 5/9] 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: <0b63e751-5c45-3311-d930-15f1ebe72601@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Fri, 8 May 2020 13:50:29 +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: <0b63e751-5c45-3311-d930-15f1ebe72601@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 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