Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp344763ybt; Wed, 8 Jul 2020 01:09:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkGLJdiQjam6EqWIQzpfCSWSP9+pZgx0qfSU7vnmN6xXtFN4luMQVGoB94kP3oi3e2f+7v X-Received: by 2002:a05:6402:3048:: with SMTP id bu8mr67655417edb.367.1594195745783; Wed, 08 Jul 2020 01:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594195745; cv=none; d=google.com; s=arc-20160816; b=v6BS3szQeiatCnnxyK3eMvWBYljQUROWaqjDzpBCmIGZ9BfatlII9ydku6BD5fVcns lIWCU/Y5a3wyGZgQLS+9YWUtLL+CpzeyurXnmr7i0rvyWDt9I9i/Uvex29JwgFMe2Wi5 Dfa9aeUQZwv4F8gfp5FdPhKXdt9vHJ85cQ4qZtZWaS16x5sq+ixWdHpChsFedMmOhRuO lQvUqWjaCqDyyhaTbVP4H7NfBfdmNaZu4wHX5cS/WYa77yEXjlYALBW/5x9EtgyDqk6D tuFaEnYlGEImXJCG6eZp1pUARX+oVmfnUfdpnVe7NFxw95ro1dpHtPDwP0NlEg8GS8xe 2HgQ== 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=QINWb8tW8bP+lbQEFfg1wIygDyLQYKxRyHC1BAq3JMNF7Ub73nh79PQqe/AFWtCjCk 1SWV9E7mfzelxxM4LOiU+oNpJ2x34zxt4uAz+ZPehZkIKPDoWI9UsIJqF9/1Lx1M2flz CS4gHpK55x5i6hLZW9j3Ps00wT69L7jlsTIiANGEO8m57Vq6yxNRDtiAFYCPZwXoeHWJ v78kwN67YclJEvAIwQ8UwzVlpYuTrPHfluRUeYCsCoPAzaH0ZwWNtjE7A91oxBUCWQv/ fdR+hIJ+ls4/O9MHUSEGeDOiyX3gtOTxzLn0evvpoYPoTakXt6k4KIPDokMJN2OCUhcZ xCZw== 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 b15si16998464edx.0.2020.07.08.01.08.41; Wed, 08 Jul 2020 01:09:05 -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 S1727905AbgGHHwd (ORCPT + 99 others); Wed, 8 Jul 2020 03:52:33 -0400 Received: from mga14.intel.com ([192.55.52.115]:7504 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726211AbgGHHwd (ORCPT ); Wed, 8 Jul 2020 03:52:33 -0400 IronPort-SDR: B5sB9e6B2ZryaOtmiamDm8xA0UKZA6Y4UvMYLPb6feOviZezkmToOI0i6mI5qfHM//A/xTaY9r YlD9JYr3QOyw== X-IronPort-AV: E=McAfee;i="6000,8403,9675"; a="146824742" X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="146824742" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2020 00:52:31 -0700 IronPort-SDR: PJTHRv1C00VQiPOHbM3BNfja4AH8KikS1rFp0wuJNmBOAZZz7wXAWOAOXrequPGqb/5V2AFhGj AqZoKieiQq3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="358030767" Received: from linux.intel.com ([10.54.29.200]) by orsmga001.jf.intel.com with ESMTP; 08 Jul 2020 00:52:31 -0700 Received: from [10.249.226.44] (abudanko-mobl.ccr.corp.intel.com [10.249.226.44]) by linux.intel.com (Postfix) with ESMTP id 47F8A5807FC; Wed, 8 Jul 2020 00:52:29 -0700 (PDT) Subject: [PATCH v10 09/15] perf stat: factor out event handling loop into dispatch_events() From: Alexey Budankov To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <4af50c95-36f6-7a61-5a22-2949970fe7a5@linux.intel.com> Organization: Intel Corp. Message-ID: Date: Wed, 8 Jul 2020 10:52:28 +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: <4af50c95-36f6-7a61-5a22-2949970fe7a5@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