Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp117005ybt; Mon, 6 Jul 2020 05:30:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyks5Vkj/K2cMcVh1IQ+FlbI1hqJir0fOEEWhSHCQ1nBweU52ydblrZhb7jM9/G3ykHC6Bd X-Received: by 2002:a17:906:240d:: with SMTP id z13mr40613949eja.346.1594038642786; Mon, 06 Jul 2020 05:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594038642; cv=none; d=google.com; s=arc-20160816; b=ej77jveqNfsV+uQ5A7nosTcXi/BP4MPLC2Jx4RDz/qHlAb1x8ql27GM9wbzXL7AP0z iE51wxnXVkV6avLdXF78jXXhvoNe4BB2Up4ZCnOI3vuSSiiwdpiNnJAySRrfqd6YjOvz GdwaSF0LKKyVVUYsGD/Ot0vdNaDvd5aXmqKSSRoZBFKPhVEoqpPIaGTujWbeh60VxjXJ 4eDFjc56iz70FCs2dDtYzJUP7AJQ0tqlauMchsz+IxUirN+hRdIYDzlRBwHRds4rp/0Y Vj2zBurifDqzVUMRJb4fgZaNdPFXqK0TcrZZaTz/l694pKxFYmASNL0bw7PGCc9mW3EG w42g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=WPXvApqxqLDntBlzk8IwXZWQao6uBNHUfWsS3vG9Elo=; b=uB9YV0anMOtZrYkaDokvHzflYG3v/sRGd45aTVFRHQSFwP9tsnq9/jC9nGDAuIMCSN g/loMF64r6TpcmXi9Cc+JSlB9tsEtxRq2RUwrTvom1/Qvz5BLUu0OwBNu8NTW/Uf7dxU PRLEBbMGGkyPnPItrq8GAkyV7ALoAYU1kCZYe7Hh++kSmoMeI8RzAeYb62Zq1H67uyC8 M3ignHefb3ds9+Y+Do+Z2w5PD8cLpfVzQEPrjJT22MH9H86e7SRSDqy8EW4+4zpDal2c RFl+VddVWcvp0Uv12qMs3qaS4oiQLGJy9wQC3oJS3amxJUbeq1CTh7UcXR+kjGP40SZY 6sRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hrFauHm6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d23si12778426edz.176.2020.07.06.05.30.19; Mon, 06 Jul 2020 05:30:42 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hrFauHm6; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729110AbgGFM10 (ORCPT + 99 others); Mon, 6 Jul 2020 08:27:26 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:37286 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729051AbgGFM10 (ORCPT ); Mon, 6 Jul 2020 08:27:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594038445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WPXvApqxqLDntBlzk8IwXZWQao6uBNHUfWsS3vG9Elo=; b=hrFauHm6jgAwA1c64O6HFCdbv+1wTUG8dqMg5uwqiwl1umDOqnnaqHMeW26i1Z4HGJdnY3 0CMCOFym+fV0KKlsb1Wt0wvNwHSxHIIlW1nHd4aaVC69/HDFxOmjXVCpaVj9NkdzC6icqU p2RZaty/I8Zy+2u+OM2dhSuq++E5w7g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-345-NGyHy7JrNNmXy0KXnq_DCg-1; Mon, 06 Jul 2020 08:27:21 -0400 X-MC-Unique: NGyHy7JrNNmXy0KXnq_DCg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D157A18FE871; Mon, 6 Jul 2020 12:27:19 +0000 (UTC) Received: from krava (unknown [10.40.193.8]) by smtp.corp.redhat.com (Postfix) with SMTP id 156727B410; Mon, 6 Jul 2020 12:27:17 +0000 (UTC) Date: Mon, 6 Jul 2020 14:27:17 +0200 From: Jiri Olsa To: Alexey Budankov Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , Andi Kleen , linux-kernel Subject: Re: [PATCH v9 09/15] perf stat: factor out event handling loop into dispatch_events() Message-ID: <20200706122717.GC3401866@krava> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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..? thanks, jirka > + } > + > + return status; > +} > + SNIP