Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp322996ybt; Wed, 17 Jun 2020 01:42:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg/SMe63gote54/IK4oILZ8azFV2U0oNe7sa4qxoHS0tnKfmAe1iPVqODHicoHhm1cmLeo X-Received: by 2002:aa7:cb4a:: with SMTP id w10mr6063329edt.46.1592383338673; Wed, 17 Jun 2020 01:42:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592383338; cv=none; d=google.com; s=arc-20160816; b=n43HDGWkPpCGOgCephjhMJ+IB8tgVCJU75TibyELANRUQNrKuG6cGKi5ROtomzsky+ 18SaKtmR7H7Ns7cV5V0Uv7CiR7oTp9mQkyZLfl+R0WR24kTNBw1/0/Y2XgSyW5T/TgoR aT1gt9gfLYSCGbndm9BfK92+olKJKIC78MVoQflWr4s3ZLWWIbWRAFolFqJms+N9dyok 3N3udva3HOd+Z0BbgYQ98JjS3e1qibwQXqNgwB3YlI6PZXYRnFQF6yQZfwJPqB/BvQh7 JYdrhsDaMr4ZWc2sHb9Gho5VjrXbmfKh3oGyqcwQheHqL+JYlNKwtVI0d0Yz/MJeMxhn GqnA== 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=oIkMDOJQH5qOQr3gVS2OyiqRz0JzAUtSfoLnvHtJ7MU=; b=U07w/w3qLr7ugnFWEnpqpWZxxgvD1yrkklSJvyxiHYjwkVc/f7LzilxyOdkl7SAPtl fCWy21qy7J/9qNAosUMp5miofhBQASTut4+3HAyzCn3f3JxCkHA77quCLHbSEkChByFA F5uyN7Txb+lCi5to4pmx+e7acqDOg/doFYMDuNGPOhuMAFbxqc/jRdL1pg6g6aknA1J9 6N3LIf1kcmILHR5jRGizr50DjP8a7sKzw/7CJC58gdU1+kCufrCN5ifx73QsMXwrcH4+ 8ITWEL89RcZktsc6ql6PK4ZpyBT+WVByA+zrMH3E8khHyTPSUacepC197X2IDHi9Dnz3 5qMA== 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 z14si12034390eji.192.2020.06.17.01.41.55; Wed, 17 Jun 2020 01:42:18 -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 S1726510AbgFQIkJ (ORCPT + 99 others); Wed, 17 Jun 2020 04:40:09 -0400 Received: from mga14.intel.com ([192.55.52.115]:19781 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725964AbgFQIkH (ORCPT ); Wed, 17 Jun 2020 04:40:07 -0400 IronPort-SDR: UqyG/sIexTxmOAvcc7k58pmSCAvlb7sGmKtHUQKd3E6KjZz6+g5UWhtELO/prkMzu1lxiUNni/ oDM8EoAtKqzg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2020 01:40:06 -0700 IronPort-SDR: kWq66butJxzFD0zp9h1iSEDUpj3DuYl0iFbc57uy4fSBNxjo/VqcyG1NtBfk2/p98ysX/Je8E+ 1Q5uLLRVNtLQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,522,1583222400"; d="scan'208";a="277207732" Received: from linux.intel.com ([10.54.29.200]) by orsmga006.jf.intel.com with ESMTP; 17 Jun 2020 01:40:06 -0700 Received: from [10.249.225.191] (abudanko-mobl.ccr.corp.intel.com [10.249.225.191]) by linux.intel.com (Postfix) with ESMTP id 3C50B58026B; Wed, 17 Jun 2020 01:40:03 -0700 (PDT) Subject: [PATCH v8 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: <0781a077-aa82-5b4a-273e-c17372a72b93@linux.intel.com> Organization: Intel Corp. Message-ID: <4d90938c-429a-586c-0cc7-767f804c6bce@linux.intel.com> Date: Wed, 17 Jun 2020 11:40:03 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <0781a077-aa82-5b4a-273e-c17372a72b93@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 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 3bc538576607..39749c290508 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -557,6 +557,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, @@ -628,7 +649,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; @@ -797,12 +817,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); @@ -819,10 +835,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