Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp114287ybj; Wed, 6 May 2020 12:53:52 -0700 (PDT) X-Google-Smtp-Source: APiQypLntuwrWxucGyZYWlHVtHlrYKKwaASEgaySa+ZHWvSPbL/xh8Mpppb0j1a9bQFGMX8BjhLI X-Received: by 2002:a17:906:4e02:: with SMTP id z2mr8803862eju.212.1588794832725; Wed, 06 May 2020 12:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588794832; cv=none; d=google.com; s=arc-20160816; b=nyIfZpy5wUzGWUf1kUbfbTTThGUFxnw4/5PFG6LLz2odKvYXmtQ+CofHAXtPGlChLW Msb9g7xAPIUrh9Nt3e8dpsh+De0XzyDrlJj6MCfqYNXxkFL9LsKv9Qp9OUAKvGGjtsU4 zdmjoBeAD3tawjNKpKn0yfcen/6LRmAWhj4K7Lux9ucJwWNQdajNvh9I6zNQRUM+CKqi JcsI4HAKorY2YMk3CxR2sLp7kHxR17ftM3/NLR/23CP6RBxp7AasMxLcccyEE1ILqQ/o ccdsxl1HampCVgulrY6js2itm+a/G/JpgDiGco+dyn7ie/3d12lPDGncsHrI9nS0Ag1z Ljiw== 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=j7AN4K9IWXxQxgTRS7qS45eJWJ/qmU90clc19qVHx90=; b=KlyMMllHZy1oaagWZDkxiqJ6fQqxSlvcfUeFj++gCEMWWfPUD5ju2jIIUeTipv0+G4 m0KVk4XXAAd+BxMITvFF8MlMug0qzSRV6//H05W2l4NGsqgpo0XhULuXHOMhzdhCB8ko V8+1yGLH1n5FRPsCT51UUp8KuTCaShMEx3Mkb1yA9QkJrFgsxFuxLaAj+itsS+hpWSiC SKPsB2Qj84BdW1mPCaSAPpIsupMAf22zsf7av3pXz5bGxLzWDFfl0ee40k7xGY44iDt4 KoEXjWV9zTFiAR012ZAA4Hr9yEKXHLO2zXtGLPcDw9f0xZh2M1qLgr9kUTkJUAUDSBOl t18A== 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 qp6si1720631ejb.16.2020.05.06.12.53.29; Wed, 06 May 2020 12:53:52 -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 S1730336AbgEFSVn (ORCPT + 99 others); Wed, 6 May 2020 14:21:43 -0400 Received: from mga17.intel.com ([192.55.52.151]:56390 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729400AbgEFSVm (ORCPT ); Wed, 6 May 2020 14:21:42 -0400 IronPort-SDR: 38ljqtNl8YGGVtX/xV6P9HFB0rVnbYVmm7kbImdj0G8hwCxL/DUDLqsLT86xea+ATsty3+xteW 3EzhtGzFKObQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2020 11:21:42 -0700 IronPort-SDR: RZtmxoYDaetrORtlBxehACVYcdmoUialPKZPfj8H8qSK9vhyV9LHG4sZGvgurHPWSXVIOuN3AQ +aUvkaqA8o2g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,360,1583222400"; d="scan'208";a="249002355" Received: from linux.intel.com ([10.54.29.200]) by orsmga007.jf.intel.com with ESMTP; 06 May 2020 11:21:42 -0700 Received: from [10.249.228.227] (abudanko-mobl.ccr.corp.intel.com [10.249.228.227]) by linux.intel.com (Postfix) with ESMTP id DA5E858043A; Wed, 6 May 2020 11:21:39 -0700 (PDT) Subject: [PATCH v2 05/11] 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: <24164c07-c16c-b970-6d97-63ce383fc238@linux.intel.com> Date: Wed, 6 May 2020 21:21:38 +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 bda777ca0420..5aab3ff1bbea 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 = 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 (perf_evlist__ctlfd_process(evsel_list, &cmd) > 0) { + switch (cmd) { + case CTL_CMD_ENABLE: + pr_info(PERF_EVLIST__ENABLED_MSG); + stop = print_interval_and_stop(config, ×); + break; + case CTL_CMD_DISABLE: + stop = print_interval_and_stop(config, ×); + pr_info(PERF_EVLIST__DISABLED_MSG); + break; + case CTL_CMD_ACK: + case 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