Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp742482ybg; Mon, 1 Jun 2020 13:13:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl7UO9pVkgYxWCwSXrBdFpXaLbpbdcp3jmVjH5BOdADjJ9tcThKADzFvwmLYVfduWsoESN X-Received: by 2002:a17:906:f745:: with SMTP id jp5mr21813544ejb.440.1591042399766; Mon, 01 Jun 2020 13:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591042399; cv=none; d=google.com; s=arc-20160816; b=vuMJKgbbtcLQOLkavU77pntczacuplr6jbs/i+pub1H8NnKfMEQmrWdyHp8J4X7O+H 1MumEHFa0y09TPkkT1mPPM0nS+lJLhATSdOeZj11ZzsAKKYB/zBPjK/HVcgwAsbyA/FA CBB3NdwxVvLCgM0XMhIjF2RWMPCMgM3qeysQ6mIcwoPYmE2PKSLPnZkR1KbhugmYgPaR fN8fuXA/+jrIAYjFmbpSi9ZmcfzSbaA+iYE7MProggrKrpM4VAEYS60SdptH7HzRrbh9 Rr7zuqivkUT1P4TPtN+yU1/XCK9tzDhqmk0AaaKkfAULfXdEzXCfIsIAhSxL7vKnUQRA b0aQ== 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=WS7X8X1cRtjibm3GzKd7tlu/YLUAfuJ81kv1FvNlaZc=; b=qzSCcRs5/gFx3uGvDoaWzHV2Rl0tvI51HccArgkU7uV704kiTWuI/Pkm651pApohIt hdPTxy2k3xeYm2M9l1hXKjy/RzP9Zm0oYVa6XPbA2RsXM5bqJ4P1pwZ7QgCrIrGDzQEO 2aaa0Mb7THYuo4HNUmwpV6Vo0EsvhybNT9DaWk3syY6I/kXVP8kfaq9JxLY4e4mJyleg Tpr196Ud6bGc/BW+QVpMSNPhsEejbtKtX+M1i6ZuIU7O0i3S7xr+t/HWCQSGyrPkNxA4 3veP+KK3WXe01r94ILknt53iDlL4Pl3lQgBuUGJfAOz91ws2Yyy7qVBrdRSqdJu9wbpv KIRQ== 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 l3si255237edi.536.2020.06.01.13.12.56; Mon, 01 Jun 2020 13:13:19 -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 S1728214AbgFAULK (ORCPT + 99 others); Mon, 1 Jun 2020 16:11:10 -0400 Received: from mga03.intel.com ([134.134.136.65]:29189 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726944AbgFAULJ (ORCPT ); Mon, 1 Jun 2020 16:11:09 -0400 IronPort-SDR: Jx/XerwECVMKwCx79BiBwye7nntkM6KBYYMuZDCPJ9ZwnL/7cr7Rj+GACsIfn723sRP2H4UVLD RKxsxrK2wimw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2020 13:11:01 -0700 IronPort-SDR: yZm866xRDzF3MvFte67+ga53cBccLZhWyCN793MaPqJ+riRnoUs7B+Sw4sLQVV5Sx5FlZPVRZD Upb0/aM7T0Tw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,462,1583222400"; d="scan'208";a="347156535" Received: from linux.intel.com ([10.54.29.200]) by orsmga001.jf.intel.com with ESMTP; 01 Jun 2020 13:11:01 -0700 Received: from [10.249.230.65] (abudanko-mobl.ccr.corp.intel.com [10.249.230.65]) by linux.intel.com (Postfix) with ESMTP id 6CB5158010E; Mon, 1 Jun 2020 13:10:59 -0700 (PDT) Subject: [PATCH v6 07/13] perf stat: factor out event handling loop into dispatch_events() 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: Date: Mon, 1 Jun 2020 23:10:58 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 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 Consolidate event dispatching loops for fork, attach and system wide monitoring use cases into common dispatch_events() function. Signed-off-by: Alexey Budankov --- tools/perf/builtin-stat.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index edd6fdcd1c72..f2d1b8c1481d 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -504,6 +504,27 @@ 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) +{ + bool stop = false; + int child = 0, status = 0; + + while (1) { + if (forks) + child = waitpid(child_pid, &status, WNOHANG); + else + child = !is_target_alive(&target, evsel_list->core.threads) ? 1 : 0; + + if (done || stop || child) + break; + + nanosleep(ts, NULL); + stop = process_timeout(timeout, interval, times); + } + + return status; +} + enum counter_recovery { COUNTER_SKIP, COUNTER_RETRY, @@ -575,7 +596,6 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) struct affinity affinity; int i, cpu; bool second_pass = false; - bool stop = false; if (interval) { ts.tv_sec = interval / USEC_PER_MSEC; @@ -744,12 +764,8 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) perf_evlist__start_workload(evsel_list); enable_counters(); - if (interval || timeout) { - while (!stop && !waitpid(child_pid, &status, WNOHANG)) { - nanosleep(&ts, NULL); - stop = process_timeout(timeout, interval, ×); - } - } + if (interval || timeout) + status = dispatch_events(forks, timeout, interval, ×, &ts); if (child_pid != -1) { if (timeout) kill(child_pid, SIGTERM); @@ -766,10 +782,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) psignal(WTERMSIG(status), argv[0]); } else { enable_counters(); - while (!done && !stop && is_target_alive(&target, evsel_list->core.threads)) { - nanosleep(&ts, NULL); - stop = process_timeout(timeout, interval, ×); - } + dispatch_events(forks, timeout, interval, ×, &ts); } disable_counters(); -- 2.24.1