Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1601083ybh; Tue, 14 Jul 2020 02:09:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhjiPk3xMWvDY7uBv5qlAKgKVC+b+i09w+SkW827wBMJRZKgpa42jKq8plsj5OfuBU87PQ X-Received: by 2002:a17:906:57c5:: with SMTP id u5mr3430491ejr.311.1594717767397; Tue, 14 Jul 2020 02:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594717767; cv=none; d=google.com; s=arc-20160816; b=eTL4Lc0cR9vwu76SsEHgAxOqCWVdZB7WFEgWjbzuXOEJi684ZhN/099pmvKVJ68FyS rQDgb4Ort2Dhg72/pGAmSJaoZ05WbdlpIoXmarv5Xc672n8qlfdY85HAoNZYDCMKWdGl uyhIceKnsaW/XS+Yio4J/pRnW9L0v2biS+/GArwbKRILP8/o71syjXGJNCc3E2nliPdb XUNI0E0MQ1kWmzrqIZZ5TQO238OCEeI5OObRWyiv5Ov+hRRjHzWk1vYb4c0al+HcWF4k 1N1WtkV//lIJ1zem3RMkdLm8oI+QX/Y3t8ndrbCkpH483iyDXQ04NP2CxZkk9H0crdKS WMgA== 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=GL2pTSHYUQzQj0m7tSZgxqTckEi5I3hjxjrJAqA/SKQ=; b=wY1DDvOF8yQGmSzrJwhS0L0zPyGIWBod3G/e5GM9wuTAsaS/X9fG/5f/uhsiMTJBxZ vsCbok8iuiOHlgSSY6RIqL65svMelb4qI8kqMfci9l2T1PzsHUbC8oPxzAJuCGPAG5PF hRtM3exEJoT7geWJeJfVN5qKOAlgkcxCWL6rTF3GT1ddKpVBAtZk8dbQx0AS+4tWOjnH ggqzCtiOfiMP1wAqeb2++swI4e9B0Ag+wTMk5Lx1xIdME8iGIOo760M6I3pRHrEGVhsL vk08J4iYwOuubN5w+8Hq2T8mLuvVdJL8ft2dJvs8v0Noe0KWNJNL1TLjNUld/iQ7oWyW Hweg== 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 l1si11212111edv.381.2020.07.14.02.09.04; Tue, 14 Jul 2020 02:09:27 -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 S1726414AbgGNJIr (ORCPT + 99 others); Tue, 14 Jul 2020 05:08:47 -0400 Received: from mga03.intel.com ([134.134.136.65]:21713 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725833AbgGNJIr (ORCPT ); Tue, 14 Jul 2020 05:08:47 -0400 IronPort-SDR: PDDTS5OyHBZD58eivpUzWGl/m9dCx+gnKhkw+UU0HvEQphtKQD/qAmZTp66SHMzzOfv8leafAy ig2gHcGVzO0g== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="148852610" X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="148852610" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 02:08:47 -0700 IronPort-SDR: FCzcrsedL9GXAenx1SjyUUuZPS/1vwVJM66n05jONn6vQE7gfSSxUWcc2OSZVnlJfN4fZ/RT1y 8+bUjqOqGh7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="325784384" Received: from linux.intel.com ([10.54.29.200]) by orsmga007.jf.intel.com with ESMTP; 14 Jul 2020 02:08:47 -0700 Received: from [10.249.230.149] (abudanko-mobl.ccr.corp.intel.com [10.249.230.149]) by linux.intel.com (Postfix) with ESMTP id 2B488580814; Tue, 14 Jul 2020 02:08:44 -0700 (PDT) Subject: [PATCH v11 09/15] 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: <037d737f-0ada-a9f0-9686-f7521ca6fbc3@linux.intel.com> Organization: Intel Corp. Message-ID: <04567b7e-2216-4546-b5f8-9af7cb0c0d1b@linux.intel.com> Date: Tue, 14 Jul 2020 12:08:44 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <037d737f-0ada-a9f0-9686-f7521ca6fbc3@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 | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 91f31518948e..a5a0f4841003 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -550,6 +550,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) +{ + int child_exited = 0, status = 0; + + while (!done) { + if (forks) + child_exited = waitpid(child_pid, &status, WNOHANG); + else + child_exited = !is_target_alive(&target, evsel_list->core.threads) ? 1 : 0; + + if (child_exited) + break; + + nanosleep(ts, NULL); + if (timeout || handle_interval(interval, times)) + break; + } + + return status; +} + enum counter_recovery { COUNTER_SKIP, COUNTER_RETRY, @@ -789,13 +810,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 (!waitpid(child_pid, &status, WNOHANG)) { - nanosleep(&ts, NULL); - if (timeout || handle_interval(interval, ×)) - break; - } - } + if (interval || timeout) + status = dispatch_events(forks, timeout, interval, ×, &ts); if (child_pid != -1) { if (timeout) kill(child_pid, SIGTERM); @@ -812,11 +828,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) psignal(WTERMSIG(status), argv[0]); } else { enable_counters(); - while (!done && is_target_alive(&target, evsel_list->core.threads)) { - nanosleep(&ts, NULL); - if (timeout || handle_interval(interval, ×)) - break; - } + status = dispatch_events(forks, timeout, interval, ×, &ts); } disable_counters(); -- 2.24.1