Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2439180imm; Thu, 7 Jun 2018 10:34:50 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL6nviw0Lcjw9V92qat5fkqM7R3NnWaUNXURgOtcDAXn52V2AGdpfwdPCua+4skmiCt66/l X-Received: by 2002:a17:902:7688:: with SMTP id m8-v6mr3063817pll.54.1528392890751; Thu, 07 Jun 2018 10:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528392890; cv=none; d=google.com; s=arc-20160816; b=rh3qnis72cSf91ql7B4fCEFq24o7Jua7a1T23gai5SeEBe6OrIY+H5nm5YsNowKNFg X92joNx8vuANyyyMduflq4NDpPAnasV/ewd58wQhDbkrnNiKatBvJ3GFzrl2fKVmUxXp fIO2Cl3bCVOpLhhsX81/dkar2LxgAcqy5E4xgohCdwk3ZY9+5kAVi1YqeceM7/PkzPXq 1/KP344dOPByPaIYDAQ8YZfLyrkMeEQgx8c14HxTzfR0+sdb/qupV5XcpQHsPWSBqJu4 sWWjDUK3bXEpe5Uo89uLUr47ekz5RtBl1SexsVBIt64cW6DE3RYd4MvOYLEENsGoMZ4p 8sbQ== 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:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=DxEs0quU9P2lndA+i79qTlVs88ohmloYYGKvLU/Yuaw=; b=XwZ0/KUIRTWfqdBpZsOJE6TzWjaBjb3mFks01Ckue+Mzrb0xwfHVRCbUW1abpyRP80 4E6xMs0+UhsQT6ln3NftzHt4EpYPKqK3qShQQob3Uz6C4PPTdjiEUzhZ1tVkvtbWIzX7 W9uh0sftLKlXPxZdRhcHH7R8tw8CEhSz/1w27fRz2hs5B7cBYOcFOnGLA75yCYB+mZO3 7dy3qAMBCZVTWktoQYvYRMJ/fbSLTe8Lcr9u3uIDiY9uZ+uTYzIFddRBpmGWVNMiJQpK aCE+WeV74Asaa/xBHNRY4Cjn6Ax2LkQ4fPUcVkND2kisuyN25rq/gdv9Qq+MDVxmbIEz jGqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z73-v6si28277640pgd.122.2018.06.07.10.34.35; Thu, 07 Jun 2018 10:34:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934481AbeFGOkb (ORCPT + 99 others); Thu, 7 Jun 2018 10:40:31 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40549 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932912AbeFGOk1 (ORCPT ); Thu, 7 Jun 2018 10:40:27 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbv-0005Zm-BL; Thu, 07 Jun 2018 15:09:55 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvaz-0002lQ-QQ; Thu, 07 Jun 2018 15:08:57 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Arnaldo Carvalho de Melo" , "Adrian Hunter" , "Wang Nan" , "David Ahern" , "Jiri Olsa" , "Namhyung Kim" , "Bram Stolk" , "Andi Kleen" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 066/410] perf record: Generate PERF_RECORD_{MMAP,COMM,EXEC} with --delay In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo commit d3dbf43c56f9176be325ce1cc72a44c8d3c210dc upstream. When we use an initial delay, e.g.: 'perf record --delay 1000', we do not enable the events until that delay has passed after we started the workload, including the tracking event, i.e. the one for which we have attr.mmap, etc, enabled to ask the kernel to generate the PERF_RECORD_{MMAP,COMM,EXEC} metadata events that will then allow us to resolve addresses in samples to the map, dso and symbol. There will be a shadow that even synthesizing samples won't cover, i.e. the workload that we start and other processes forking while we wait for the initial delay to expire. So use a dummy event to be the tracking one and make it be enabled on exec. Before: # perf record --delay 1000 stress --cpu 1 --timeout 5 stress: info: [9029] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd stress: info: [9029] successful run completed in 5s [ perf record: Woken up 3 times to write data ] [ perf record: Captured and wrote 0.624 MB perf.data (15908 samples) ] # perf script | head :9031 9031 32001.826888: 1 cycles:ppp: ffffffff831aa30d event_function (/lib/modules/4.14.0-rc6+/build/vmlinux) :9031 9031 32001.826893: 1 cycles:ppp: ffffffff8300d1a0 intel_bts_enable_local (/lib/modules/4.14.0-rc6+/build/vmlinux) :9031 9031 32001.826895: 7 cycles:ppp: ffffffff83023870 sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux) :9031 9031 32001.826897: 103 cycles:ppp: ffffffff8300c331 intel_pmu_handle_irq (/lib/modules/4.14.0-rc6+/build/vmlinux) :9031 9031 32001.826899: 1615 cycles:ppp: ffffffff830231f8 native_sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux) :9031 9031 32001.826902: 26724 cycles:ppp: ffffffff8384c6a7 native_irq_return_iret (/lib/modules/4.14.0-rc6+/build/vmlinux) :9031 9031 32001.826913: 329739 cycles:ppp: 7fb2a5410932 [unknown] ([unknown]) :9031 9031 32001.827033: 1225451 cycles:ppp: 7fb2a5410930 [unknown] ([unknown]) :9031 9031 32001.827474: 1391725 cycles:ppp: 7fb2a5410930 [unknown] ([unknown]) :9031 9031 32001.827978: 1233697 cycles:ppp: 7fb2a5410928 [unknown] ([unknown]) # After: # perf record --delay 1000 stress --cpu 1 --timeout 5 stress: info: [9741] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd stress: info: [9741] successful run completed in 5s [ perf record: Woken up 3 times to write data ] [ perf record: Captured and wrote 0.751 MB perf.data (15976 samples) ] # perf script | head stress 9742 32110.959106: 1 cycles:ppp: ffffffff831b26f6 __perf_event_task_sched_in (/lib/modules/4.14.0-rc6+/build/vmlinux) stress 9742 32110.959110: 1 cycles:ppp: ffffffff8300c2e9 intel_pmu_handle_irq (/lib/modules/4.14.0-rc6+/build/vmlinux) stress 9742 32110.959112: 7 cycles:ppp: ffffffff830231e0 native_sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux) stress 9742 32110.959115: 101 cycles:ppp: ffffffff83023870 sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux) stress 9742 32110.959117: 1533 cycles:ppp: ffffffff830231f8 native_sched_clock (/lib/modules/4.14.0-rc6+/build/vmlinux) stress 9742 32110.959119: 23992 cycles:ppp: ffffffff831b0900 ctx_sched_in (/lib/modules/4.14.0-rc6+/build/vmlinux) stress 9742 32110.959129: 329406 cycles:ppp: 7f4b1b661930 __random_r (/usr/lib64/libc-2.25.so) stress 9742 32110.959249: 1288322 cycles:ppp: 5566e1e7cbc9 hogcpu (/usr/bin/stress) stress 9742 32110.959712: 1464046 cycles:ppp: 7f4b1b66179e __random (/usr/lib64/libc-2.25.so) stress 9742 32110.960241: 1266918 cycles:ppp: 7f4b1b66195b __random_r (/usr/lib64/libc-2.25.so) # Reported-by: Bram Stolk Tested-by: Bram Stolk Cc: Adrian Hunter Cc: Andi Kleen Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Fixes: 6619a53ef757 ("perf record: Add --initial-delay option") Link: http://lkml.kernel.org/n/tip-nrdfchshqxf7diszhxcecqb9@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo [bwh: Backported to 3.16: - Don't set perf_evsel::tracking fields - Adjust context] Signed-off-by: Ben Hutchings --- --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -140,6 +140,19 @@ static int record__open(struct record *r struct record_opts *opts = &rec->opts; int rc = 0; + /* + * For initial_delay we need to add a dummy event so that we can track + * PERF_RECORD_MMAP while we wait for the initial delay to enable the + * real events, the ones asked by the user. + */ + if (opts->initial_delay) { + if (perf_evlist__add_dummy(evlist)) + return -ENOMEM; + + pos = perf_evlist__last(evlist); + pos->attr.enable_on_exec = 1; + } + perf_evlist__config(evlist, opts); evlist__for_each(evlist, pos) {