Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1770303ybh; Fri, 17 Jul 2020 00:04:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUMrCkD26kgthjBwfVlbZK3HoC0bEKGeOjz/Hi3mJvPOikfcIz2ualrdTzplmhlOTDIrTe X-Received: by 2002:a17:906:abc9:: with SMTP id kq9mr7452473ejb.493.1594969478109; Fri, 17 Jul 2020 00:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594969478; cv=none; d=google.com; s=arc-20160816; b=ybSA8gYlahj6Gsi/tRVgjOYcAT3ShogCy7QCaZM60v9X4lBaPly5gusp5VR7lGyT2j Q641/i1zhokpsDh1rTjW06gzDI+C23ECYBVmq8qP0Oe2mb/d70V8hWOBLZkVzUMOBMy7 9bGKoMxlw9BABbAJJugsP1VdmmBKyW001w5UFRkBOKt9IxrapvqCOCfvN5XGWn1/QVCy PE9NOHKDrb0KUOwo/ZMVvKrP8hARYidK0jVSAOP798C+SMP+u4pgrZk/jI7cZhRMlBlJ 27c2BzFByC+TvbRyKLm8iSaYw+qQzmeR387CFKS01hflR6p07VZeu4rs3s5nUB+hcgGl 1IqQ== 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=vhZ0nKoFvMqEjAqspWWysugRvnax17apZbK1SNvw+k8=; b=n4RN0sgos2B/LyDz4Wm2r1wZc9TecTLWBJfBoe803paNLUZIuc8G3uEZOp840eXyRI SRO0bLZf2cMa66sV2C6Ko63Ic4Ywtz1KAyN9LnonBIK7p8cK/KqDGSXAF7uDSUYiBAfl H2oFzV+gWtcVIZpzeWn1XeeZu4QuXH3uz9AYzjHET95GLbyg+b9rjvIq2No3uZMnP+6J dUBoVTnHdPDPZUY9CK7NBESNTQx20qfyM3TsC3U1Mjm3fQFP4RPMnKtiWpgMgliopkZC BXD6AXfeMkQqKG2NNLoHkZZ1j4C3qf9o5dcavUwGkVCtP/5eyxn8v7FtdXW1fFpuWky3 06rw== 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 e17si4483390ejk.740.2020.07.17.00.04.15; Fri, 17 Jul 2020 00:04:38 -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 S1726929AbgGQHEH (ORCPT + 99 others); Fri, 17 Jul 2020 03:04:07 -0400 Received: from mga11.intel.com ([192.55.52.93]:13061 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbgGQHEG (ORCPT ); Fri, 17 Jul 2020 03:04:06 -0400 IronPort-SDR: 9cbr9jACAEqRxDvidda19vc2qC0bZOQCWJ3mNIYWItTGjogFXMGINyA5OlAjd8oVanxWtdkPne N3Nx1H+zmxIA== X-IronPort-AV: E=McAfee;i="6000,8403,9684"; a="147534151" X-IronPort-AV: E=Sophos;i="5.75,362,1589266800"; d="scan'208";a="147534151" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2020 00:04:06 -0700 IronPort-SDR: bq6H5T1C7aZcsaYaaKTHahOA4FWrbhT17HkZonMHIJPdodesUTcAg8erbm+Yn4/T+GLn/M4nG9 uecLJ+l1r+4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,362,1589266800"; d="scan'208";a="325359359" Received: from linux.intel.com ([10.54.29.200]) by FMSMGA003.fm.intel.com with ESMTP; 17 Jul 2020 00:04:06 -0700 Received: from [10.249.224.34] (abudanko-mobl.ccr.corp.intel.com [10.249.224.34]) by linux.intel.com (Postfix) with ESMTP id 9FDA458066D; Fri, 17 Jul 2020 00:04:03 -0700 (PDT) Subject: [PATCH v12 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: <8d91c3a0-3db4-0a7a-ae13-299adb444bd6@linux.intel.com> Organization: Intel Corp. Message-ID: <8a900bd5-200a-9b0f-7154-80a2343bfd1a@linux.intel.com> Date: Fri, 17 Jul 2020 10:04:02 +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: <8d91c3a0-3db4-0a7a-ae13-299adb444bd6@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 Acked-by: Jiri Olsa Acked-by: Namhyung Kim --- 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