Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp871660ybm; Wed, 27 May 2020 09:59:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhb6at0ObkoVunVHpEM7+Xgc5L6vTvBKuiBOaS3iOiWwoWa0hs5iNFG/mqzTHPzAEkchT0 X-Received: by 2002:a50:e606:: with SMTP id y6mr16473944edm.63.1590598790089; Wed, 27 May 2020 09:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590598790; cv=none; d=google.com; s=arc-20160816; b=SKjhMyq8cRfVDu7hUrbRBGX7H1lRNXyLp2akWkt+OCbSE9IoT3cNlBZ+YbKkLVszcm 0JC8hZFIKPR9s6sVKfj9TewEkMCxEh/v3B5E7mVjBSSY/FN+KxCvIEFfxCd6Cql8dx8B YgidciwW9gBT3ijLYTVEvM9jA33rxL8/JvDJxutbFIQnBsbGu+CB8h/pS261kq+IXtrl MqKPUHSSxQzj54IcZ9lj0ztdDhLTpaY0BFWNsLKlFxb0xyAAswDQR7qEsURt/e6Ddh2i IjJ01KK9G0NZwB5xnUI57ToDDrjHE3Kbux6On7yxwFtrUpkej/Adc1rHKITY+jWAmF+7 hsjw== 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=LDX7Cf4DSenOi4PrUGZgz3waJjkFEH91S4KR/ua5GIU=; b=lD33kdDS1b59xODOlww6SrqYXZVCJ2eUnBttmzQXDL3XkUX2YKQEuqwLNNquOOaooT vBhX2gWpojzB3GLYIiWLUQvgkj+OdQtYk8+0OU4HxCYRdic7PUA5jTcr5GnTkSSkSqlg iXAxA8KI37ZBaKz9sNfaVdtKAg+Kz82BHpLU6sINlCPkfjgj74MWXdRXtaLMREtHf+WX RPuCN+xH/JkZtX3E+AJDNatFnVRN5FRgY6pe3dpQfBErr3NDZAgS5VpPZN7JbZQf/RkA fwjWQtAzLngTBzs2Yg7LpWm2nHKWSVlyzyirIKGpnIWrPS753NDzZ79LciTrPKKGUmC5 nIag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TyvwiovL; 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 se23si2204869ejb.247.2020.05.27.09.59.26; Wed, 27 May 2020 09:59:50 -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=TyvwiovL; 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 S2387982AbgE0KaK (ORCPT + 99 others); Wed, 27 May 2020 06:30:10 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:41835 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387584AbgE0KaG (ORCPT ); Wed, 27 May 2020 06:30:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590575403; 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=LDX7Cf4DSenOi4PrUGZgz3waJjkFEH91S4KR/ua5GIU=; b=TyvwiovLQBwJzmCHfF7A+2B8LLd+E9ezX6NNRfA0tY5Z+i9VA3slIix+UE78EGelO+YeCQ +ATiobrPPalO/eocTsuUDBRk7oY+LYbmg4UPnkckNjze6uFnW+b6DkZYLz0iyp2AtSgwS2 Zn+AMQryLMWEL4MxnO9VXx2tE2eSNxo= 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-315-YmF9KXT-MoeFzubiNG3Fzw-1; Wed, 27 May 2020 06:29:54 -0400 X-MC-Unique: YmF9KXT-MoeFzubiNG3Fzw-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 34B34461; Wed, 27 May 2020 10:29:53 +0000 (UTC) Received: from krava (unknown [10.40.195.83]) by smtp.corp.redhat.com (Postfix) with SMTP id 70725648D7; Wed, 27 May 2020 10:29:51 +0000 (UTC) Date: Wed, 27 May 2020 12:29:50 +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 v4 00/10] perf: support enable and disable commands in stat and record modes Message-ID: <20200527102950.GB420698@krava> References: <653fe5f3-c986-a841-1ed8-0a7d2fa24c00@linux.intel.com> <5e09c991-ebd0-df3d-dab8-d6fe7197c20c@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5e09c991-ebd0-df3d-dab8-d6fe7197c20c@linux.intel.com> 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 Wed, May 27, 2020 at 12:27:31PM +0300, Alexey Budankov wrote: > > Making sure it is not sneaked out of your attention. yep, I know about it, will get to it this week jirka > > Thanks, > Alexey > > On 25.05.2020 17:11, Alexey Budankov wrote: > > > > Changes in v4: > > - made checking of ctlfd state unconditional in record trace streaming loop > > - introduced static poll fds to keep evlist__filter_pollfd() unaffected > > - handled ret code of evlist__initialize_ctlfd() where need > > - renamed and structured handle_events() function > > - applied anonymous structs where needed > > > > v3: https://lore.kernel.org/lkml/eb38e9e5-754f-d410-1d9b-e26b702d51b7@linux.intel.com/ > > > > Changes in v3: > > - renamed functions and types from perf_evlist_ to evlist_ to avoid > > clash with libperf code; > > - extended commands to be strings of variable length consisting of > > command name and also possibly including command specific data; > > - merged docs update with the code changes; > > - updated docs for -D,--delay=-1 option for stat and record modes; > > > > v2: https://lore.kernel.org/lkml/d582cc3d-2302-c7e2-70d3-bc7ab6f628c3@linux.intel.com/ > > > > Changes in v2: > > - renamed resume and pause commands to enable and disable ones, renamed > > CTL_CMD_RESUME and CTL_CMD_PAUSE to CTL_CMD_ENABLE and CTL_CMD_DISABLE > > to fit to the appropriate ioctls and avoid mixing up with PAUSE_OUTPUT > > ioctl; > > - factored out event handling loop into a handle_events() for stat mode; > > - separated -D,--delay=-1 into separate patches for stat and record modes; > > > > v1: https://lore.kernel.org/lkml/825a5132-b58d-c0b6-b050-5a6040386ec7@linux.intel.com/ > > > > repo: tip of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core > > > > The patch set implements handling of 'start disabled', 'enable' and 'disable' > > external control commands which can be provided for stat and record modes > > of the tool from an external controlling process. 'start disabled' command > > can be used to postpone enabling of events in the beginning of a monitoring > > session. 'enable' and 'disable' commands can be used to enable and disable > > events correspondingly any time after the start of the session. > > > > The 'start disabled', 'enable' and 'disable' external control commands can be > > used to focus measurement on specially selected time intervals of workload > > execution. Focused measurement reduces tool intrusion and influence on > > workload behavior, reduces distortion and amount of collected and stored > > data, mitigates data accuracy loss because measurement and data capturing > > happen only during intervals of interest. > > > > A controlling process can be a bash shell script [1], native executable or > > any other language program that can directly work with file descriptors, > > e.g. pipes [2], and spawn a process, specially the tool one. > > > > -D,--delay option is extended with -1 value to skip events enabling > > in the beginning of a monitoring session ('start disabled' command). > > --ctl-fd and --ctl-fd-ack command line options are introduced to provide the > > tool with a pair of file descriptors to listen to control commands and reply > > to the controlling process on the completion of received commands. > > > > The tool reads control command message from ctl-fd descriptor, handles the > > command and optionally replies acknowledgement message to fd-ack descriptor, > > if it is specified on the command line. 'enable' command is recognized as > > 'enable' string message and 'disable' command is recognized as 'disable' > > string message both received from ctl-fd descriptor. Completion message is > > 'ack\n' and sent to fd-ack descriptor. > > > > Example bash script demonstrating simple use case follows: > > > > #!/bin/bash > > > > ctl_dir=/tmp/ > > > > ctl_fifo=${ctl_dir}perf_ctl.fifo > > test -p ${ctl_fifo} && unlink ${ctl_fifo} > > mkfifo ${ctl_fifo} && exec {ctl_fd}<>${ctl_fifo} > > > > ctl_ack_fifo=${ctl_dir}perf_ctl_ack.fifo > > test -p ${ctl_ack_fifo} && unlink ${ctl_ack_fifo} > > mkfifo ${ctl_ack_fifo} && exec {ctl_fd_ack}<>${ctl_ack_fifo} > > > > perf stat -D -1 -e cpu-cycles -a -I 1000 \ > > --ctl-fd ${ctl_fd} --ctl-fd-ack ${ctl_fd_ack} \ > > -- sleep 40 & > > perf_pid=$! > > > > sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e1 && echo "enabled(${e1})" > > sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d1 && echo "disabled(${d1})" > > sleep 5 && echo 'enable' >&${ctl_fd} && read -u ${ctl_fd_ack} e2 && echo "enabled(${e2})" > > sleep 10 && echo 'disable' >&${ctl_fd} && read -u ${ctl_fd_ack} d2 && echo "disabled(${d2})" > > > > exec {ctl_fd_ack}>&- && unlink ${ctl_ack_fifo} > > exec {ctl_fd}>&- && unlink ${ctl_fifo} > > > > wait -n ${perf_pid} > > exit $? > > > > > > Script output: > > > > [root@host dir] example > > Events disabled > > # time counts unit events > > 1.001101062 cpu-cycles > > 2.002994944 cpu-cycles > > 3.004864340 cpu-cycles > > 4.006727177 cpu-cycles > > Events enabled > > enabled(ack) > > 4.993808464 3,124,246 cpu-cycles > > 5.008597004 3,325,624 cpu-cycles > > 6.010387483 83,472,992 cpu-cycles > > 7.012266598 55,877,621 cpu-cycles > > 8.014175695 97,892,729 cpu-cycles > > 9.016056093 68,461,242 cpu-cycles > > 10.017937507 55,449,643 cpu-cycles > > 11.019830154 68,938,167 cpu-cycles > > 12.021719952 55,164,101 cpu-cycles > > 13.023627550 70,535,720 cpu-cycles > > 14.025580995 53,240,125 cpu-cycles > > disabled(ack) > > 14.997518260 53,558,068 cpu-cycles > > Events disabled > > 15.027216416 cpu-cycles > > 16.029052729 cpu-cycles > > 17.030904762 cpu-cycles > > 18.032073424 cpu-cycles > > 19.033805074 cpu-cycles > > Events enabled > > enabled(ack) > > 20.001279097 3,021,022 cpu-cycles > > 20.035044381 6,434,367 cpu-cycles > > 21.036923813 89,358,251 cpu-cycles > > 22.038825169 72,516,351 cpu-cycles > > # time counts unit events > > 23.040715596 55,046,157 cpu-cycles > > 24.042643757 78,128,649 cpu-cycles > > 25.044558535 61,052,428 cpu-cycles > > 26.046452785 62,142,806 cpu-cycles > > 27.048353021 74,477,971 cpu-cycles > > 28.050241286 61,001,623 cpu-cycles > > 29.052149961 61,653,502 cpu-cycles > > disabled(ack) > > 30.004980264 82,729,640 cpu-cycles > > Events disabled > > 30.053516176 cpu-cycles > > 31.055348366 cpu-cycles > > 32.057202097 cpu-cycles > > 33.059040702 cpu-cycles > > 34.060843288 cpu-cycles > > 35.000888624 cpu-cycles > > [root@host dir]# > > > > [1] http://man7.org/linux/man-pages/man1/bash.1.html > > [2] http://man7.org/linux/man-pages/man2/pipe.2.html > > > > --- > > Alexey Budankov (10): > > tools/libperf: introduce static poll file descriptors > > perf evlist: introduce control file descriptors > > perf evlist: implement control command handling functions > > perf stat: factor out event handling loop into a function > > perf stat: extend -D,--delay option with -1 value > > perf stat: implement control commands handling > > perf stat: introduce --ctl-fd[-ack] options > > perf record: extend -D,--delay option with -1 value > > perf record: implement control commands handling > > perf record: introduce --ctl-fd[-ack] options > > > > tools/lib/api/fd/array.c | 42 +++++- > > tools/lib/api/fd/array.h | 7 + > > tools/lib/perf/evlist.c | 11 ++ > > tools/lib/perf/include/internal/evlist.h | 2 + > > tools/perf/Documentation/perf-record.txt | 44 ++++++- > > tools/perf/Documentation/perf-stat.txt | 45 ++++++- > > tools/perf/builtin-record.c | 38 +++++- > > tools/perf/builtin-stat.c | 155 +++++++++++++++++------ > > tools/perf/builtin-trace.c | 2 +- > > tools/perf/util/evlist.c | 131 +++++++++++++++++++ > > tools/perf/util/evlist.h | 25 ++++ > > tools/perf/util/record.h | 4 +- > > tools/perf/util/stat.h | 4 +- > > 13 files changed, 459 insertions(+), 51 deletions(-) > > >