Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1347317ybk; Thu, 21 May 2020 04:51:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwte7ZQmujDdgkp3HTPnrSV7X74QT9P2XAPo846pNq6VFtOhViAKmDuKDac5iZYs9uTieSN X-Received: by 2002:a17:906:3d69:: with SMTP id r9mr3024443ejf.20.1590061887027; Thu, 21 May 2020 04:51:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590061887; cv=none; d=google.com; s=arc-20160816; b=nuhbcI6MJMhTKXaTgUPgKuHahLFtA+037k1F57XILlx1M4xbV8WUbrXY3e1VQ+iio1 UP96MTcx86VqziSFahD3UJa6IkOfMF+mP7otvTEDXxTWuQUjbMIq+ZDodiq8zjy46zEU Ii4nF1E02iw9Vzl8qyxGt2KbEEtORDi4ZMWvTtWecJ9cdTk8uJq1GZZf3K9fkw6tPK0y pxGfFD9bKyHVQHMbnmzxkVLEPP2HL80YDqf3qKMWn2mrKEHSaCznm1Xxf6aCVIH01+gb pmXEGyzb40shCbsbUgcQgtXTjFnVOBF1hJw+0WobQ/kqYGXFVHNf7tAkSPxsZ2zqLbBN mJEA== 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=rD9nUKjKetPNgFJJMbeB1cCRB1Q4uLpwzABIKxJBRI4=; b=xSLoycFv6NKqfbvRdwLfc3hFn0trGPZaw8fDwJTaQJKgiotZP31jigPU7Y9+FGlsNF WR4wruWS297P6WWoZuUjXEiZ20sGJSHAqNYzyaW+gWti6XpnbAd8Kii3t+yjYH5zptgs AqBZTdR/EtBZxRdvMsxmhefwQGunbq+HbIUXJm1nOmaoGcz8R75iTpskfbBTKaUfQIp6 piUMd11ij5OojfBpCgPQ1+qEkNWSiOrjfZCe/G1ocxXEbjRlICzXXatpozAthGXNKt2u vVA7GjaaKLk7LXHk35K44Vd1hns7BNTIk7E/y0dgiBOhqC4+/Zf9ey9ZQuJz2f9ElrGy oGsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZzVXBxj9; 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 p21si3062698ejw.285.2020.05.21.04.51.03; Thu, 21 May 2020 04:51:27 -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=ZzVXBxj9; 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 S1729165AbgEULtK (ORCPT + 99 others); Thu, 21 May 2020 07:49:10 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:42853 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729002AbgEULtJ (ORCPT ); Thu, 21 May 2020 07:49:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590061747; 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=rD9nUKjKetPNgFJJMbeB1cCRB1Q4uLpwzABIKxJBRI4=; b=ZzVXBxj95GDlsNsKaCoFaUGjoi4brsXfFHsZ/DiqcQ1wppNKlIAZn4fqCY7bM2NwH3D0NG VsYVh+YWKenzjb29U75oWCoDKbNvYih9he0tBVaGmpIAGiGk2KfB797FWzX7d+qwT/38cV k0ZG/q8BuZpG6bv/j6C33NqdB3lHo2c= 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-466-32XGUhsBM8yfJVKvXScDxA-1; Thu, 21 May 2020 07:49:03 -0400 X-MC-Unique: 32XGUhsBM8yfJVKvXScDxA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8669C80183C; Thu, 21 May 2020 11:49:02 +0000 (UTC) Received: from krava (unknown [10.40.195.217]) by smtp.corp.redhat.com (Postfix) with SMTP id BCCE75C1B0; Thu, 21 May 2020 11:49:00 +0000 (UTC) Date: Thu, 21 May 2020 13:48:59 +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 v3 3/9] perf stat: factor out event handling loop into a function Message-ID: <20200521114859.GU157452@krava> References: <20200520123850.GI157452@krava> 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.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 20, 2020 at 06:17:40PM +0300, Alexey Budankov wrote: SNIP > >> @@ -675,16 +708,9 @@ 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) > >> - break; > >> - process_interval(); > >> - if (interval_count && !(--times)) > >> - break; > >> - } > >> - } > >> + if (interval || timeout) > >> + handle_events(child_pid, &stat_config); > >> + > >> if (child_pid != -1) { > >> if (timeout) > >> kill(child_pid, SIGTERM); > >> @@ -701,18 +727,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) > >> psignal(WTERMSIG(status), argv[0]); > >> } else { > >> enable_counters(); > >> - while (!done) { > >> - nanosleep(&ts, NULL); > >> - if (!is_target_alive(&target, evsel_list->core.threads)) > >> - break; > >> - if (timeout) > >> - break; > >> - if (interval) { > >> - process_interval(); > >> - if (interval_count && !(--times)) > >> - break; > >> - } > >> - } > >> + handle_events(-1, &stat_config); > > > > this makes me worried.. I'm not sure if it's good idea > > to squash these 2 looops into one, because they are already > > complex as they are.. and one of you following patches is > > making it even more complex > > Loops bodies are mostly identical. The only difference is in events > they wait for and API used for that. Adding of more events will > complicate further. The code is duplicated, thus needs refactoring. > If the following patch complicates lets organize the patch it into > several smaller functions. yea, that might help jirka > > > > > wouldn't it be better if you just add single call into > > each of them.. that would poll on your fd and process the > > commands if needed? > > That's of course possible, but doesn't manage existing complexity > at the first place - __run_perf_stat(). > > Let's still have handle_events() as a general dispatcher and implement > handlers for different events as separate functions? > > ~Alexey >