Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1664379

Re: [PATCH 2/2] Support perf script -F brstackoff,dso

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Mark Santaniello <marksan@fb.com>
Newsgroups linux.kernel
Subject Re: [PATCH 2/2] Support perf script -F brstackoff,dso
Date Tue, 13 Jun 2017 06:00:01 +0200
Message-ID <tRL9L-2Py-3@gated-at.bofh.it> (permalink)
References <tRGtr-8hX-5@gated-at.bofh.it> <tRGtr-8hX-13@gated-at.bofh.it> <tRH6a-kl-13@gated-at.bofh.it>
X-Original-To Arnaldo Carvalho de Melo <acme@kernel.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=7pqTGJjoaXjTlQXhFQEsmbtDaWAgSpaPocjWhwjrHGA=; b=BQ4pkzbjzLMfQULtBfp+FuPfyoBpVyn0FExECET3LRWeIU5hn+7UJZ1Rj3rZWaOiCsNI f1qvK8ouBETUTn3PD0XmCXbiKweYum1m2KEPQAk8ba0jpe7Y91v2x483G002IFPJVKBS 3fFl6w8aQ0GwHolB6qcJdjcWMfNnSeFW5fQ=
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=7pqTGJjoaXjTlQXhFQEsmbtDaWAgSpaPocjWhwjrHGA=; b=HtmvAa5vjU7WEHgDRe+44nTmfik+bDqvoAdBpGq3zE5advt+YdesFgVQS9mqHkn5G3OyiExYJMpixG2G+k1+LY9AuJ/KWWC70I6OGHgCLaN5RR/JsmfzeRUMRIW0+apBTwSGoa6xhaHkuU3CDoU9enDSNnYLWVs1ro9YfdjSR68=
Thread-Topic [PATCH 2/2] Support perf script -F brstackoff,dso
Thread-Index AQHS4855tIDcoXnIxUC3S+eqdJz/JaIh4ecA///SRYA=
Accept-Language en-US
Content-Language en-US
User-Agent Microsoft-MacOutlook/f.22.0.170515
Authentication-Results kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=fb.com;
X-Originating-IP [2620:10d:c090:180::1:1574]
X-Ms-Publictraffictype Email
X-Microsoft-Exchange-Diagnostics 1;MWHPR15MB1709;7:EXc6Copzml+Rnt2aUhRFsi0yyRc+xfPvN+Uc7sXZEa1xVF2NiQVwwsVc2nSB5hV7OxsGehjq7xHxprVBrooBYUUrje2YCVYoc6a/Ef6ATLvEYdQr4aPCSr2z1EtYK4Re7g8cM7U7BeMLEPiCvVfygMgofEIjrtuDXifAhpj73DpDI7hLejX/vbimyF5laE/R66W2eplDiGbAr0ZKbS4inoW+C1U1ORomDd7s3gyJ6Nvv9c2yNYuRuHApVoCd+95k2ao9comMZIpPXOXLcn4iXdr3L+vkp9okEtMkaB99mLejP6WjKwcjsUYxcCp6YYZjC0jrdmR/zRP5gGrnu5NVIw==;20:ECkXfcdE0DkihSrwP3cib1bm0c7nox7+z85H6W16g6VwVHly8T/GfcEy5MgzLIVF8hMhOcuemdaMjaSaqoVa8GlEjSfloKXGmrFMJzFSfeTCAoRkJJCDReBnVedbLhsFiL1TTCRTuEYGxs9jnhnHDaGTYvhEDsEajNu/x5LignY=
X-Ms-Traffictypediagnostic MWHPR15MB1709:
X-Ms-Office365-Filtering-Correlation-ID 4d06ab20-d92b-4e4e-8209-08d4b20fb49d
X-Microsoft-Antispam UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(201703131423075)(201703031133081)(201702281549075);SRVR:MWHPR15MB1709;
X-Microsoft-Antispam-Prvs <MWHPR15MB17098260E79A52E97F4AB806D8C20@MWHPR15MB1709.namprd15.prod.outlook.com>
X-Exchange-Antispam-Report-Test UriScan:(67672495146484);
X-Exchange-Antispam-Report-Cfa-Test BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(3002001)(10201501046)(93006095)(93001095)(6041248)(20161123562025)(20161123555025)(20161123560025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR15MB1709;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR15MB1709;
X-Forefront-Prvs 0337AFFE9A
X-Forefront-Antispam-Report SFV:NSPM;SFS:(10019020)(6009001)(39850400002)(39840400002)(39450400003)(39410400002)(39400400002)(24454002)(377454003)(33656002)(305945005)(122556002)(7736002)(229853002)(6916009)(2950100002)(3660700001)(102836003)(5660300001)(2906002)(6246003)(3280700002)(110136004)(6486002)(8676002)(81166006)(8936002)(6506006)(6436002)(478600001)(77096006)(14454004)(53936002)(54906002)(25786009)(99286003)(6512007)(82746002)(53546009)(4326008)(2900100001)(189998001)(83716003)(36756003)(54356999)(50986999)(76176999)(86362001)(575784001)(38730400002)(142933001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1709;H:MWHPR15MB1709.namprd15.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en;
Spamdiagnosticoutput 1:99
Spamdiagnosticmetadata NSPM
Content-Type text/plain; charset="utf-8"
Content-ID <3E0D29C237DB4647B3186D7AF2B5CA80@namprd15.prod.outlook.com>
Content-Transfer-Encoding base64
MIME-Version 1.0
X-Ms-Exchange-Crosstenant-Originalarrivaltime 13 Jun 2017 03:53:08.9151 (UTC)
X-Ms-Exchange-Crosstenant-Fromentityheader Hosted
X-Ms-Exchange-Crosstenant-ID 8ae927fe-1255-47a7-a2af-5f3a069daaa2
X-Ms-Exchange-Transport-Crosstenantheadersstamped MWHPR15MB1709
X-Originatororg fb.com
X-Proofpoint-Spam-Reason safe
X-Fb-Internal Safe
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:,, definitions=2017-06-13_02:,, signatures=0
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 126
Organization linux.* mail to news gateway
X-Original-Cc Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
X-Original-Date Tue, 13 Jun 2017 03:53:08 +0000
X-Original-Message-ID <9A775CA0-1DD7-4F08-979B-8C3378AACFAE@fb.com>
X-Original-References <20170612225113.4043842-1-marksan@fb.com> <20170612225113.4043842-2-marksan@fb.com> <20170612233648.GE3017@kernel.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1664379

Show key headers only | View raw


On 6/12/17, 4:36 PM, "Arnaldo Carvalho de Melo" <acme@kernel.org> wrote:

    Em Mon, Jun 12, 2017 at 03:51:13PM -0700, Mark Santaniello escreveu:
    > The idea here is to make AutoFDO easier in cloud environment with ASLR.
    > It's easiest to show how this is useful by example. I built a small test
    > akin to "while(1) { do_nothing(); }" where the do_nothing function is
    > loaded from a dso.  I sampled the execution with perf record -b.
    > 
    > Using the existing "brstack,dso", we get absolute addresses that are
    > affected by ASLR, and could be different on different hosts. The address
    > does not uniquely identify a branch/target in the binary:
    > $ ./perf script -F brstack,dso | sed 's/\/0 /\/0\n/g' \
    > > | grep burncpu | grep dso.so | head -n 1
    > 0x7f967139b6aa(/tmp/burncpu/dso.so)/0x4006b1(/tmp/burncpu/exe)/P/-/-/0
    > 
    > Using the existing "brstacksym,dso" is a little better, because the
    > symbol plus offset and dso name *does* uniquely identify a branch/target
    > in the binary.  Ultimately, however, AutoFDO wants a simple offset into
    > the binary, so we'd have to undo all the work perf did to symbolize in
    > the first place:
    > $ ./perf script -F brstacksym,dso | sed 's/\/0 /\/0\n/g' \
    > > | grep burncpu | grep dso.so | head -n 1
    > do_nothing+0x5(/tmp/burncpu/dso.so)/main+0x44(/tmp/burncpu/exe)/P/-/-/0
    > 
    > With the new "brstackoff,dso" we get what we need: a simple offset into a
    > specific dso/binary that uniquely identifies a branch/target:
    > $ ./perf script -F brstackoff,dso | sed 's/\/0 /\/0\n/g' \
    > > | grep burncpu | grep dso.so | head -n 1
    > 0x6aa(/tmp/burncpu/dso.so)/0x4006b1(/tmp/burncpu/exe)/P/-/-/0
    > 
    > Note this patch depends on commit 9d0ec0748cd9.
    
    Are you refererring to patch 1/2 in this series?
    
    [acme@jouet linux]$ git show 9d0ec0748cd9
    fatal: ambiguous argument '9d0ec0748cd9': unknown revision or path not in the working tree.
    [acme@jouet linux]$
    
    Can you please provide the test proggie source code?
    
    Seems simple enough, but to save time for people trying to test your
    patch, it would be good to have it available.
    
    - Arnaldo

Hi Arnaldo,

Sorry for the missteps – I’m new to this process.  I am indeed referring to patch 1/2 in this series.
I didn’t realize the revision hash was only meaningful locally.

Below is the little program I am using to test this.

Thanks,
Mark


~/src/burncpu$ cat burncpu.cpp
#include <dlfcn.h>

int main() {
  void* handle = dlopen("./dso.so", RTLD_LAZY);
  if (!handle) return -1;

  typedef void (*fp)();
  fp do_nothing = (fp) dlsym(handle, "do_nothing");

  while(1) {
    do_nothing();
  }
}

~/src/burncpu$ cat dso.cpp
extern "C" void do_nothing() {}

~/src/burncpu$ cat build.sh
#!/bin/bash
g++ -shared dso.cpp -o dso.so
g++ burncpu.cpp -o burncpu -ldl



     
    > Signed-off-by: Mark Santaniello <marksan@fb.com>
    > ---
    >  tools/perf/builtin-script.c | 56 +++++++++++++++++++++++++++++++++++++++++----
    >  1 file changed, 52 insertions(+), 4 deletions(-)
    > 
    > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
    > index 6a7033b..1effc64 100644
    > --- a/tools/perf/builtin-script.c
    > +++ b/tools/perf/builtin-script.c
    > @@ -85,6 +85,7 @@ enum perf_output_field {
    >  	PERF_OUTPUT_INSN	    = 1U << 21,
    >  	PERF_OUTPUT_INSNLEN	    = 1U << 22,
    >  	PERF_OUTPUT_BRSTACKINSN	    = 1U << 23,
    > +	PERF_OUTPUT_BRSTACKOFF	    = 1U << 24,
    >  };
    >  
    >  struct output_option {
    > @@ -115,6 +116,7 @@ struct output_option {
    >  	{.str = "insn", .field = PERF_OUTPUT_INSN},
    >  	{.str = "insnlen", .field = PERF_OUTPUT_INSNLEN},
    >  	{.str = "brstackinsn", .field = PERF_OUTPUT_BRSTACKINSN},
    > +	{.str = "brstackoff", .field = PERF_OUTPUT_BRSTACKOFF},
    >  };
    >  
    >  /* default set to maintain compatibility with current format */
    > @@ -299,10 +301,9 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
    >  		return -EINVAL;
    >  	}
    >  	if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR) &&
    > -	    !PRINT_FIELD(BRSTACK) && !PRINT_FIELD(BRSTACKSYM)) {
    > -		pr_err("Display of DSO requested but none of sample IP, sample address, "
    > -		       "brstack\nor brstacksym are selected. Hence, no addresses to "
    > -		       "convert to DSO.\n");
    > +	    !PRINT_FIELD(BRSTACK) && !PRINT_FIELD(BRSTACKSYM) && !PRINT_FIELD(BRSTACKOFF)) {
    > +		pr_err("Display of DSO requested but no address to convert.  Select\n"
    > +		       "sample IP, sample address, brstack, brstacksym, or brstackoff.\n");
    >  		return -EINVAL;
    >  	}
    >  	if (PRINT_FIELD(SRCLINE) && !PRINT_FIELD(IP)) {
    > @@ -606,6 +607,51 @@ static void print_sample_brstacksym(struct perf_sample *sample,
    >  	}
    >  }
    >  
    > +static void print_sample_brstackoff(struct perf_sample *sample,
    > +				    struct thread *thread,
    > +				    struct perf_event_attr *attr)
    > +{
    > +	struct branch_stack *br = sample->branch_stack;
    > +	struct addr_location alf, alt;
    > +	u64 i, from, to;
    > +
    > +	if (!(br && br->nr))
    > +		return;
    > +
    > +	for (i = 0; i < br->nr; i++) {
    > +
    > +		memset(&alf, 0, sizeof(alf));
    > +		memset(&alt, 0, sizeof(alt));
    > +		from = br->entries[i].from;
    > +		to   = br->entries[i].to;
    > +
    > +		thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf);
    > +		if (alf.map && !alf.map->dso->adjust_symbols)
    > +			from = map__map_ip(alf.map, from);
    > +
    > +		thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
    > +		if (alt.map && !alt.map->dso->adjust_symbols)
    > +			to = map__map_ip(alt.map, to);
    > +
    > +		printf("0x%"PRIx64, from);
    > +		if (PRINT_FIELD(DSO)) {
    > +			printf("(");
    > +			map__fprintf_dsoname(alf.map, stdout);
    > +			printf(")");
    > +		}
    > +		printf("/0x%"PRIx64, to);
    > +		if (PRINT_FIELD(DSO)) {
    > +			printf("(");
    > +			map__fprintf_dsoname(alt.map, stdout);
    > +			printf(")");
    > +		}
    > +		printf("/%c/%c/%c/%d ",
    > +			mispred_str(br->entries + i),
    > +			br->entries[i].flags.in_tx ? 'X' : '-',
    > +			br->entries[i].flags.abort ? 'A' : '-',
    > +			br->entries[i].flags.cycles);
    > +	}
    > +}
    >  #define MAXBB 16384UL
    >  
    >  static int grab_bb(u8 *buffer, u64 start, u64 end,
    > @@ -1227,6 +1273,8 @@ static void process_event(struct perf_script *script,
    >  		print_sample_brstack(sample, thread, attr);
    >  	else if (PRINT_FIELD(BRSTACKSYM))
    >  		print_sample_brstacksym(sample, thread, attr);
    > +	else if (PRINT_FIELD(BRSTACKOFF))
    > +		print_sample_brstackoff(sample, thread, attr);
    >  
    >  	if (perf_evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT))
    >  		print_sample_bpf_output(sample);
    > -- 
    > 2.9.3
    

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] Support perf script -F brstack,dso and brstacksym,dso Mark Santaniello <marksan@fb.com> - 2017-06-13 01:00 +0200
  [PATCH 2/2] Support perf script -F brstackoff,dso Mark Santaniello <marksan@fb.com> - 2017-06-13 01:00 +0200
    Re: [PATCH 2/2] Support perf script -F brstackoff,dso Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-06-13 01:40 +0200
      Re: [PATCH 2/2] Support perf script -F brstackoff,dso Mark Santaniello <marksan@fb.com> - 2017-06-13 06:00 +0200

csiph-web