Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp144165ybt; Mon, 6 Jul 2020 06:09:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0y3fO/ou68oo4k2TopmYJXluUWdEjE+R0UAwg7mQwi1aNJRJ2/77eVcSkhKqkqcPsuWK6 X-Received: by 2002:a05:6402:228d:: with SMTP id cw13mr56484609edb.343.1594040972283; Mon, 06 Jul 2020 06:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594040972; cv=none; d=google.com; s=arc-20160816; b=aOPtdySQVy0JREtlVJ7VdgA2D40CQF/5e2pkTZMoRh2bLaC3wqwoZQsyfCswLD4T43 cc04Ad1hRC28yPjmrwU+fsMEA74dmTYqY3hbS5907Tzyo5XACK/StO/3vugY0w0gYbch cVPLc9MY2a3aWQbRus8hNHJoJ97pcEwe6FhMPKmqy/mOD8d84Z1jq5KDQVFLB7JZmE1v B2sYQxiHkRVnOn7HWPka2aZJTtGcTCUURJF7frsASVuQW0LakRl9R1aLyGhbdjknuZIj h8qMpUMeaVug6DG4fnkZ7mbxKgj8PMqhRn9hwnh4T9t2LbxlsmksECb01fD6P/Pd7QHH IDWw== 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:from:references:cc:to:subject:ironport-sdr :ironport-sdr; bh=vkU/Zh3tLsan7Iz7sqXsoe33041Um8q4Nvbr3yBJtE0=; b=kSVQ9qwYRD6faMDfkdSh3L1ITk+r9moCVFOXLZ9XORczTgN9Vyo7wUQ6JCmXDjbe9x pwEXnATQzpO03Y9fVMssUvetvvJoyHnhh2Z/oaoF3t1KKGpJ45BAgRGMxEYpYdkKCH/P zxQHTK9HcWs6qmVs0eaNdA4Ax5iAewFDhC3zcFbHK4SWmg9XhnoN4wOBzv31mnGw/N1q 6yhYybS96wqiSy//jmoZO1dL4WCK5MSgkVi6Dlnk7yXPPjDCv5+Y8F898RCdKcZoEgxl y9heT3ch7oSVDuX3jSeNKacd4PRXTWR7viRwseE1MooiMaXL93mSct8kRNkmJWNKpFE5 Gn3w== 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 v9si12865766eja.482.2020.07.06.06.09.09; Mon, 06 Jul 2020 06:09:32 -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 S1729146AbgGFNIB (ORCPT + 99 others); Mon, 6 Jul 2020 09:08:01 -0400 Received: from mga09.intel.com ([134.134.136.24]:60362 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728940AbgGFNIA (ORCPT ); Mon, 6 Jul 2020 09:08:00 -0400 IronPort-SDR: PAUZQ4jXmiTfEPef6XXj32r3N08D+GF9xHWioZtT4ElwZNhDKnTx8BkDqe2OJLi0bJnhoEvV/v grjTFT3OZE/g== X-IronPort-AV: E=McAfee;i="6000,8403,9673"; a="148907933" X-IronPort-AV: E=Sophos;i="5.75,320,1589266800"; d="scan'208";a="148907933" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2020 06:08:00 -0700 IronPort-SDR: d6CGC1Xspusv/7UecsX08VdaFWTPpZODBPwIKLGeYXPYQVon6+IBZqHzJBbQTN0r3P+5+2I0SK xpkv3X2yCcww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,320,1589266800"; d="scan'208";a="305291735" Received: from linux.intel.com ([10.54.29.200]) by fmsmga004.fm.intel.com with ESMTP; 06 Jul 2020 06:07:59 -0700 Received: from [10.249.225.12] (abudanko-mobl.ccr.corp.intel.com [10.249.225.12]) by linux.intel.com (Postfix) with ESMTP id 67800580378; Mon, 6 Jul 2020 06:07:56 -0700 (PDT) Subject: Re: [PATCH v9 09/15] perf stat: factor out event handling loop into dispatch_events() To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel References: <20200706122717.GC3401866@krava> From: Alexey Budankov Organization: Intel Corp. Message-ID: <6af18510-0a01-f2a6-bc5c-27ee3283f3ad@linux.intel.com> Date: Mon, 6 Jul 2020 16:07:54 +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: <20200706122717.GC3401866@krava> 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 On 06.07.2020 15:27, Jiri Olsa wrote: > On Fri, Jul 03, 2020 at 10:46:15AM +0300, Alexey Budankov wrote: >> >> 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 | 42 +++++++++++++++++++++++++-------------- >> 1 file changed, 27 insertions(+), 15 deletions(-) >> >> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c >> index 3e11f854ffc8..723f1fe27d63 100644 >> --- a/tools/perf/builtin-stat.c >> +++ b/tools/perf/builtin-stat.c >> @@ -550,6 +550,30 @@ 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_exited = 0, status = 0; >> + >> + while (1) { >> + if (forks) >> + child_exited = waitpid(child_pid, &status, WNOHANG); >> + else >> + child_exited = !is_target_alive(&target, evsel_list->core.threads) ? 1 : 0; >> + >> + if (done || stop || child_exited) >> + break; > > can (done || stop) be in the while condition and > we'd check just child_exited in here? > >> + >> + nanosleep(ts, NULL); >> + if (timeout) >> + stop = true; > > can we just break out in here? like the original code? > I don't think we need the extra iteration > >> + else >> + stop = handle_interval(interval, times); > > same here..? Accepted. In v10. Alexey