Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp607504ybg; Wed, 3 Jun 2020 09:00:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0DOvHQRV+kWBuD3LTqXUkOsQcf+8HlE8KAVfHTxCCJDG2BBXZqIOQj8PgXA3r+lxmkauo X-Received: by 2002:a17:906:6b8e:: with SMTP id l14mr32198ejr.32.1591200011305; Wed, 03 Jun 2020 09:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591200011; cv=none; d=google.com; s=arc-20160816; b=atw69hsbIE1mrUybZQpy5wPjLeZaSFh93Myfh9ugADErPU30d5DY8LFJvIbvvdZkct +LQyr7NVF46LYySbb1tgAkRiv10IWL+aO0dtYcUpSpxe0PA9gu99mxYv/CAJLjgLIh0z bJiz1QNdYrDTvKYniQDzt477vK1zz4EKEoxaMSGVOCUqXYtZF7t7WlFhYpR3d3kF6o8D y9773LZEbF/rRuOdnIdWZqJS3mIs2alJq6tJguI7OZFMyKb4/S0tWSMYZYgNS/jNT/u4 BbyOW8AFJsvcAUWim1pvaR11eXcZOB4Bc+XKD43Kd7hCNzoIsdCbaMCDs0AeTeyJpAvP 9VDw== 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=ylo2p0n4AwGwMAmf4PjWBv7WbKEANdGbE9IM3qg4P+6WahgNuOWwJ+kj5CIT3Wc8j2 1XeRMZQLw5hbryoS+FXe4dfwM6MgsBq1p6987HlgcNepLUrw0dx6/vCMIE494oS9ijc2 XVC3JsZ/JqjFejrnqprL3DmKVgypH5FM8y+p3JnbEK8O0SEflR8TB2/fB9RiZ7vp1BZ9 wzo3EP/pgnkHdW1lthj2+ijDb8hT2MVZ4aOi8Oy2LMqBvNdXsOOFwGVwdufJ3/T/pbgO E1l8DXitQhSkaElZQ+ScyQKaTfUy1OxXuHALrB3Qg9dA5ZtGHobEejrE+MXV2jjwjIId QAkA== 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 n7si1289805edt.65.2020.06.03.08.59.48; Wed, 03 Jun 2020 09:00:11 -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 S1726138AbgFCP57 (ORCPT + 99 others); Wed, 3 Jun 2020 11:57:59 -0400 Received: from mga09.intel.com ([134.134.136.24]:22870 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725867AbgFCP57 (ORCPT ); Wed, 3 Jun 2020 11:57:59 -0400 IronPort-SDR: TRv+kvKIIUfEE20zR1v61EHQcSUa80yaHlBAo3Jj7ou1+95gEajTxFIdh5rXC63XeYBTMRc1v9 FR8ZFYGxibfQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2020 08:57:59 -0700 IronPort-SDR: jSiadUzkHJjISItSbKiUfBF7DWeuYJUh0oXOSZRGccHEHhHgbHTIQChSXZkcPjz6ybXfzNRAPI gZAK4haxFSUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,468,1583222400"; d="scan'208";a="257480601" Received: from linux.intel.com ([10.54.29.200]) by fmsmga007.fm.intel.com with ESMTP; 03 Jun 2020 08:57:57 -0700 Received: from [10.249.225.188] (abudanko-mobl.ccr.corp.intel.com [10.249.225.188]) by linux.intel.com (Postfix) with ESMTP id 858185800E3; Wed, 3 Jun 2020 08:57:55 -0700 (PDT) Subject: [PATCH v7 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: <5de4b954-24f0-1e8d-5a0d-7b12783b8218@linux.intel.com> Organization: Intel Corp. Message-ID: <0ccd1e8b-be2e-492d-a43c-5db4378a3da1@linux.intel.com> Date: Wed, 3 Jun 2020 18:57:54 +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: <5de4b954-24f0-1e8d-5a0d-7b12783b8218@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