Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3666657ybt; Tue, 23 Jun 2020 07:59:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZcMBnvTbWu854SS1001eXjE3YUfKeFgSEw3Civ3h4HBLmUWV42Nq+32xwYa1OKzpiyb7e X-Received: by 2002:aa7:d388:: with SMTP id x8mr22840468edq.380.1592924343245; Tue, 23 Jun 2020 07:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592924343; cv=none; d=google.com; s=arc-20160816; b=W1LVMFsYYaA6BdSdVaoj6LLmn9JLICJFLom7pCNI60BxHZxjMYe0jBnnJG4nYewimR 7NsN3Zn6TBsp+JIM7x75wsRFgCLbN5YG4niPko/EmEwZY/m940YdHi0+7gG5YtSNHxYm xqrbGfcYtVjSr9kYZajJFf3JabH86ANaLOjm+q/WmZxZUN+9xOwROQ95zwPU1Im98/F5 uY8BcvBnNU2xNV/zaoKDz4PWlrCMkW8F9UWeYu18PdzvMo1rlWAUh0NvxOg+2UynBQE2 9CHKKwFO8MjRz1qC4iG866s5Z0wivUnbptWFj/vcFVvJ53lwj7F7dgAd6wtfPQBj1ewJ /4/w== 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=hIIVI2IVwxufkOdRkONfj/5M92J90slWUkJGgrwHoh4=; b=DiJ/OPFeCMZxmyMb26bLX+cZL6R0yHMDWnY91R3y1NdzjN3g1sT5JeCnHGTF7RcW7R xRrz/jE8v9Q1GpvKq3XMsPx58xYz5s2Cj1VUi4JhzEUE2uLFVrl+g4ypxe4vfOyqUa4q sjEds4Xu5lY6qeCNxyAIuzbE7HojitBNLTkbwjdrRwqjFO1u8K9N2HsJhJVtDJmJjso2 LZPT983u8M2feoRf+ekcMnh0mwkkeZ55oJptxSr6xzONHYg+cob6ks/5ZefCaIrKnqXO RGOpSI740+04fZqBdXTYlvoRCmvEcXUUnPmw2T7nP6zvaMH+9+Bws0oGl2GqjB59IHyl ELkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D3RcxQYT; 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 jz21si11778127ejb.635.2020.06.23.07.58.40; Tue, 23 Jun 2020 07:59:03 -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=D3RcxQYT; 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 S1732969AbgFWO4c (ORCPT + 99 others); Tue, 23 Jun 2020 10:56:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:21245 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732961AbgFWO4b (ORCPT ); Tue, 23 Jun 2020 10:56:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592924190; 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=hIIVI2IVwxufkOdRkONfj/5M92J90slWUkJGgrwHoh4=; b=D3RcxQYTrjobIlXAJLnRDQV0+mRP18QWUGjpf/phu0bRXUHEKaTOFLD3iy87i73en4cSf7 9DIyFvbKVknwyc1gp1aigCvCYKB9NJ6v4wC0jZ6D7RzoPzRwaOoUk1rqiwT1SLkXBn/1on seYDGFVYHAMH6M5TBUD9mB/zpzIE2Rs= 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-207-xnFlv3hTPIWa_ocKGfuBxA-1; Tue, 23 Jun 2020 10:56:27 -0400 X-MC-Unique: xnFlv3hTPIWa_ocKGfuBxA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A23D0A0C0B; Tue, 23 Jun 2020 14:56:25 +0000 (UTC) Received: from krava (unknown [10.40.192.77]) by smtp.corp.redhat.com (Postfix) with SMTP id 9186E512FE; Tue, 23 Jun 2020 14:56:23 +0000 (UTC) Date: Tue, 23 Jun 2020 16:56:22 +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 v8 07/13] perf stat: factor out event handling loop into dispatch_events() Message-ID: <20200623145622.GJ2619137@krava> References: <0781a077-aa82-5b4a-273e-c17372a72b93@linux.intel.com> <4d90938c-429a-586c-0cc7-767f804c6bce@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4d90938c-429a-586c-0cc7-767f804c6bce@linux.intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 17, 2020 at 11:40:03AM +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 | 35 ++++++++++++++++++++++++----------- > 1 file changed, 24 insertions(+), 11 deletions(-) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 3bc538576607..39749c290508 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -557,6 +557,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) > +{ > + bool stop = false; > + int child = 0, status = 0; > + > + while (1) { > + if (forks) > + child = waitpid(child_pid, &status, WNOHANG); > + else > + child = !is_target_alive(&target, evsel_list->core.threads) ? 1 : 0; please renme child to something more accurate, so the condition below makes more sense, like child_stoped or such jirka > + > + if (done || stop || child) > + break; > + > + nanosleep(ts, NULL); > + stop = process_timeout(timeout, interval, times); > + } > + > + return status; > +} > + SNIP