Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5431052ybp; Mon, 14 Oct 2019 22:37:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRkKypw4GuPmTZoF3QMgiXkZqOnhcwBMOGguLZUQ09aU1uuQrYBsjRBx9s7C/qhjSxkrKF X-Received: by 2002:a05:6402:323:: with SMTP id q3mr4970801edw.166.1571117833849; Mon, 14 Oct 2019 22:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571117833; cv=none; d=google.com; s=arc-20160816; b=J0LFqtF5sH4xvDsX12rv698beDJ/tqKpj6UsaXFkyuGXyenGI+d4dAKOHB5lnRJ8xy bicYDznPJrlTqHaPWLhHdlihmoVO63j4K798IXUAY7NRXBNW3crEr8ASOk7TtjQCz373 IqSwoRsjX+5BiR20mRCAv4uzuFlyFn19M7Nr+5MW6LZ1eliwf7F+6F+f+R0DXWh7DyV6 Oy+x4C+4Zoa3rFx++NW661Jzy5DuUa/eEx68XO8NcVu9KB3uxa7ee8Zvt9+A3uyA7R0K HuzctdTQk+uEiQvMHROVb3gDSdu3sMpcQTBQi6/soAo9cYXQYq4J0uzCU7Y/sR/oeKBe A/BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=voz4i+v+frHsSQ8PRqlMxILgaKVhYjtinkOnPqt0d44=; b=lNEgTNdZ3RRpDqDDeFQzWdiY0M+5PQMTfZeWAlt4UEfJeIX+ZZRZvWM9m980dI61i7 +MQo9x66lg9CD+Ut4cwcUOlQFnoaZQuSkb6eT6kP8m+9fwoDpgp428rGAHeM7mjM+Ez9 9g5Qt6qJIRbZFrpyQqHazFG5mK+7Z8CvVp8Z2IO4GOFfuOSe9QuPkHBkltAvLFUk2xzy x5aHmVY3jSGD5LYvJe0OkW0VNCklgMk4y8vMIr3CIcLciGTD++/NOJnhS5seso/QwIlF ZgMvHkDbeiyK7F/bymVxC5Zl4uqsR1rFdQYpEOYcuUbpbeHeg78n8/wlLFHSgplu3Kgd XVrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wXk34FGC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si12401946ejp.103.2019.10.14.22.36.50; Mon, 14 Oct 2019 22:37:13 -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; dkim=pass header.i=@linaro.org header.s=google header.b=wXk34FGC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727864AbfJODoK (ORCPT + 99 others); Mon, 14 Oct 2019 23:44:10 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:35987 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727092AbfJODoK (ORCPT ); Mon, 14 Oct 2019 23:44:10 -0400 Received: by mail-qk1-f195.google.com with SMTP id y189so17932471qkc.3 for ; Mon, 14 Oct 2019 20:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=voz4i+v+frHsSQ8PRqlMxILgaKVhYjtinkOnPqt0d44=; b=wXk34FGCnDMKI8b3FXI7D9xaCgxD/y6Q9rbb36RCr0LZKiYrzCuPXbqv2Bv6VGoRuU bTe3ibnOMobN28LsH8Edn1hWcSPokpkncM7Dfgp1cAHTl7lYafygzCv7MlgbicKd/89a 8fFFaCKGPceBmTMcYN/tocdizAYPV1VH1Cff0XEMQxaBspzTFgl9KHg0KoWB9nWhOod3 tixOZVKvgzY3bMsxjury0RRAHv27CTPbiJI5//IXsThoIofDeEaMSWOuLhBsPnkzIk1s E3L8BRiamiDUaBRL9UP8ZcNv5CQJvGstxAO05J1za86dfWVGFd+OVPPWaEHkq0HAPnqi 1vIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=voz4i+v+frHsSQ8PRqlMxILgaKVhYjtinkOnPqt0d44=; b=mSf9NY1LtdjYyKQnLDu3y70NPbfL4NANqJ+mV5BUvbrOtJjWB3BZuGwA0+QJ1Fx/SW rnhBAgzSlGCGi6jY02YF62JtPSbErRhwwuxVDItIuUibsKnTAzx1zSpY+MRs01Uqa6tP FSy2X4nb8b9rSheLCJ2oidWx8sAS5VhXvgjGGScKjLZMDnbZoZpZHnTzeGwK8nz1Qca2 APkMx2vPxnEhe2Nnp9l21weOj865jCoGw7iAfoVTcSlfFzXUqv/YMWO+rKrOzSvoxUm9 mo/B21q5bV+7mlhqHCSmczEyyMkmBN15xrgqajQoGnbgFEK5V/NbGQ0oLPo58eVj2B1C gN9w== X-Gm-Message-State: APjAAAX7MIAYQDZ6XDkgRVdmW69XizB/bhdmD7KceGNqfxDNKIqo7skP pWXJjJqwnsmFSKO45dsRJVq0LQ== X-Received: by 2002:ae9:f50a:: with SMTP id o10mr33521733qkg.372.1571111048572; Mon, 14 Oct 2019 20:44:08 -0700 (PDT) Received: from leoy-ThinkPad-X240s (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id g194sm9801676qke.46.2019.10.14.20.44.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 20:44:07 -0700 (PDT) Date: Tue, 15 Oct 2019 11:44:00 +0800 From: Leo Yan To: Mathieu Poirier Cc: Arnaldo Carvalho de Melo , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Subject: Re: [PATCH v3 6/6] perf cs-etm: Synchronize instruction sample with the thread stack Message-ID: <20191015034400.GC6336@leoy-ThinkPad-X240s> References: <20191005091614.11635-1-leo.yan@linaro.org> <20191005091614.11635-7-leo.yan@linaro.org> <20191011201750.GD13688@xps15> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191011201750.GD13688@xps15> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 11, 2019 at 02:17:50PM -0600, Mathieu Poirier wrote: > On Sat, Oct 05, 2019 at 05:16:14PM +0800, Leo Yan wrote: > > The synthesized flow use 'tidq->packet' for instruction samples; on the > > other hand, 'tidp->prev_packet' is used to generate the thread stack and > > the branch samples, this results in the instruction samples using one > > packet ahead than thread stack and branch samples ('tidp->prev_packet' > > vs 'tidq->packet'). > > > > This leads to an instruction's callchain error as shows in below > > example: > > > > main 1579 100 instructions: > > ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) > > ffff000010214850 perf_event_update_userpage+0x48 ([kernel.kallsyms]) > > ffff000010219360 perf_swevent_add+0x88 ([kernel.kallsyms]) > > ffff0000102135f4 event_sched_in.isra.57+0xbc ([kernel.kallsyms]) > > ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) > > ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) > > ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) > > > > In the callchain log, for the two continuous lines the up line contains > > one child function info and the followed line contains the caller > > function info, and so forth. So the first two lines are: > > > > perf_event_update_userpage+0x4c => the sampled instruction > > perf_event_update_userpage+0x48 => the parent function's calling > > > > The child function and parent function both are the same function > > perf_event_update_userpage(), but this isn't a recursive function, thus > > the sequence for perf_event_update_userpage() calling itself shouldn't > > never happen. This callchain error is caused by the instruction sample > > using an ahead packet than the thread stack, the thread stack is deferred > > to process the new packet and misses to pop stack if it is just a return > > packet. > > > > To fix this issue, we can simply change to use 'tidq->prev_packet' to > > generate the instruction samples, this allows the thread stack to push > > and pop synchronously with instruction sample. Finally, the callchain > > can be displayed correctly as below: > > > > main 1579 100 instructions: > > ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) > > ffff000010219360 perf_swevent_add+0x88 ([kernel.kallsyms]) > > ffff0000102135f4 event_sched_in.isra.57+0xbc ([kernel.kallsyms]) > > ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) > > ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) > > ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) > > > > Signed-off-by: Leo Yan > > --- > > tools/perf/util/cs-etm.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c > > index 56e501cd2f5f..fa969dcb45d2 100644 > > --- a/tools/perf/util/cs-etm.c > > +++ b/tools/perf/util/cs-etm.c > > @@ -1419,7 +1419,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, > > struct cs_etm_packet *tmp; > > int ret; > > u8 trace_chan_id = tidq->trace_chan_id; > > - u64 instrs_executed = tidq->packet->instr_count; > > + u64 instrs_executed = tidq->prev_packet->instr_count; > > > > tidq->period_instructions += instrs_executed; > > > > @@ -1450,7 +1450,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, > > */ > > s64 offset = (instrs_executed - instrs_over - 1); > > u64 addr = cs_etm__instr_addr(etmq, trace_chan_id, > > - tidq->packet, offset); > > + tidq->prev_packet, offset); > > I have tested this set in --per-thread mode and things are working as > advertised. Did you see how things look like in CPU-wide scenarios? I am not sure I checked the callchain for CPU-wide scenarios, but I didn't pay attention for the case when the trace data is switching between CPUs, especially if connect with your comment in patch 03, with wrong buffer ID it might cause the wrong callchain for CPU-wide scenarios. Will do more testing for CPU-wide scenarios in next spin. Thanks for the suggestions. Leo Yan > Thanks, > Mathieu > > > > > ret = cs_etm__synth_instruction_sample( > > etmq, tidq, addr, etm->instructions_sample_period); > > -- > > 2.17.1 > >