Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1116476ybc; Tue, 19 Nov 2019 14:55:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyTRRGdi2wytqYu8oV7Yx6gIdvJMEBTYy1vgd5an8kX8TzpndUz1O8F7IMXpaIopwAOpYXh X-Received: by 2002:a17:906:f154:: with SMTP id gw20mr193021ejb.279.1574204154845; Tue, 19 Nov 2019 14:55:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574204154; cv=none; d=google.com; s=arc-20160816; b=PDbqDNwxSWdaeE3Ubih/8/mSk0HmZsTltkuO/9Wb6MIoeOG3PoyPOtPfSX5c0TRgkX mqzygcMRZ2wRS0kTUKlh6iyVmODs44g2IndzImkD3khPXFbSw9bg9qAHrWM3IbdV1J9k GXLZ9OBR2bjZNLHVpm8gbj4yY4ddSpLMriNAaUgRUt9AYB2K0IIumZs13cVFXswp6MFd HsnUF1f/HpyHi0UdlGAPMSAwka/Uvjgi/aaRTb4/qTJf3MalJQa9agz6eEPhmDeGWM+y 5Z+v/ARsTZR07TU6dQsh8Jm7Q1DCGkbcxCtsbttzn37pl/HMZbXXkwwuku5oHfWKTamx Hgjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JRjxm3LKiDcxqNBGS6tcDgWeqEqzYMXc7gZaYJw28cE=; b=GyPXGDRZwvyCz7mKUEXv/VCkBjcmuadM6C5l4pqEX8kjOYlahqVr0iOqDdHMZAOzwl swnpi6svFn4YMfmEQ+Z+iHNG1pow+HIEpg61ONClhzG7drP/ng4iHGUDEeyK2keRYXr4 AA3uGdQ9RcuE8HFRi49ID1ny66ToVjV+XM5Vtyj7Wqx7EJDky4IFrOmuZYxKsKD9Fvpe v33qVVrKiaRrjDoPyYxOivKbPDKulj9G7C/TlZySXnITGtToTCw9oub1JRS7oZKZmBkD /VXtWVI9X6a/9frrTV8IVnu4VoUKQPtu51PCKwpkymTatHroaE8OEha519Q3K6tJTr8S 1sFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EZbGZyCU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k21si14758447ejc.148.2019.11.19.14.55.30; Tue, 19 Nov 2019 14:55:54 -0800 (PST) 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=@google.com header.s=20161025 header.b=EZbGZyCU; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727508AbfKSWvm (ORCPT + 99 others); Tue, 19 Nov 2019 17:51:42 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:43559 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726196AbfKSWvm (ORCPT ); Tue, 19 Nov 2019 17:51:42 -0500 Received: by mail-io1-f66.google.com with SMTP id r2so20141290iot.10 for ; Tue, 19 Nov 2019 14:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JRjxm3LKiDcxqNBGS6tcDgWeqEqzYMXc7gZaYJw28cE=; b=EZbGZyCUrBD+SQI2cbw2k4yScOLaMBfyt+4IKBB2yNoVUd3Jl5BRcqQW+xB24cwWpe TDrtEBz4g0q+g0Fbr6Zw3z7OmjrTqd1HvlWWpWlysEkoXCeP97k3mRIvYxmaAVjglnv4 45CXrhWle/DbQmTvCbyO4hkImxsm7rWtsBlCFuFTqbohzVA18fjvwJ5LcFNsw0s/X82W S3TAnWNojntdX9GI4qkVCPY/oVL0WAzf69o6oaDxA3j5FsRcsrfBYNobajLeuF2rnpLj R5aOvPMeTj/KUQENMCIpWJ/SFnIKkJih0Z1NiUqNgtuC/UUoM8GG4yeQZLAU6Ga/wz6k XLjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JRjxm3LKiDcxqNBGS6tcDgWeqEqzYMXc7gZaYJw28cE=; b=IBADVM9EPmYNgqGjjj6LSCGDrKhLDPpg4gLyKao4lReGyI7PzR6tRiMsitdbB7Eykq AYqH2KzbKoV6GDNbK2OoZcIwQUBFSuQTeU+tmdEO1eqEwByeKF50H6ubzJ9+Bj6G82qi w85Zk7/S5Nlmn3dIm9/2AHrtgMuRdyW1k6x+LPyHxiJgIzGnc/VN/nmjneL4M9IhXEAc 6l07yM+pVE3w+sHowgyhsX7936QR9FxzApu2hY5lBrlI6iojJHwpSMmFCG/PwP89X+wA pqVMMa4K5nHscAdA3TB74m+bWQDA7uJCTH4kZ7yrx8FCpRFN+PgVukpHRH7UXeqxX+RI p9GA== X-Gm-Message-State: APjAAAW9nmdSUK60r2EG6+/ZzNwV9KIJOqgaD7A8Wrl5hxzxSRtCQk5F knqOmRzjR4Wu3dbzH3jlJ7l/BS7tNofmPphd2pH77g== X-Received: by 2002:a6b:2d4:: with SMTP id 203mr12923784ioc.193.1574203900831; Tue, 19 Nov 2019 14:51:40 -0800 (PST) MIME-Version: 1.0 References: <20191119143411.3482-1-kan.liang@linux.intel.com> <20191119143411.3482-2-kan.liang@linux.intel.com> <6c233145-fb30-b629-2290-8595e192ba82@linux.intel.com> In-Reply-To: <6c233145-fb30-b629-2290-8595e192ba82@linux.intel.com> From: Stephane Eranian Date: Tue, 19 Nov 2019 14:51:29 -0800 Message-ID: Subject: Re: [PATCH V4 01/13] perf/core: Add new branch sample type for LBR TOS To: "Liang, Kan" Cc: Peter Zijlstra , Arnaldo Carvalho de Melo , Ingo Molnar , LKML , Jiri Olsa , Namhyung Kim , vitaly.slobodskoy@intel.com, pavel.gerasimov@intel.com, Andi Kleen , Michael Ellerman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 19, 2019 at 2:25 PM Liang, Kan wrote: > > > > On 11/19/2019 2:02 PM, Stephane Eranian wrote: > > On Tue, Nov 19, 2019 at 6:35 AM wrote: > >> From: Kan Liang > >> > >> In LBR call stack mode, the depth of reconstructed LBR call stack limits > >> to the number of LBR registers. With LBR Top-of-Stack (TOS) information, > >> perf tool may stitch the stacks of two samples. The reconstructed LBR > >> call stack can break the HW limitation. > >> > >> Add a new branch sample type to retrieve LBR TOS. The new type is PMU > >> specific. Add it at the end of enum perf_branch_sample_type. > >> Add a macro to retrieve defined bits of branch sample type. > >> Update perf_copy_attr() to handle the new bit. > >> > >> Only when the new branch sample type is set, the TOS information is > >> dumped into the PERF_SAMPLE_BRANCH_STACK output. > >> Perf tool should check the attr.branch_sample_type, and apply the > >> corresponding format for PERF_SAMPLE_BRANCH_STACK samples. > >> Otherwise, some user case may be broken. For example, users may parse a > >> perf.data, which include the new branch sample type, with an old version > >> perf tool (without the check). Users probably get incorrect information > >> without any warning. > >> > >> Signed-off-by: Kan Liang > >> --- > >> include/linux/perf_event.h | 2 ++ > >> include/uapi/linux/perf_event.h | 16 ++++++++++++++-- > >> kernel/events/core.c | 13 ++++++++++++- > >> 3 files changed, 28 insertions(+), 3 deletions(-) > >> > >> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > >> index 011dcbdbccc2..761021c7ee8a 100644 > >> --- a/include/linux/perf_event.h > >> +++ b/include/linux/perf_event.h > >> @@ -93,6 +93,7 @@ struct perf_raw_record { > >> /* > >> * branch stack layout: > >> * nr: number of taken branches stored in entries[] > >> + * tos: Top-of-Stack (TOS) information. PMU specific data. > >> * > >> * Note that nr can vary from sample to sample > >> * branches (to, from) are stored from most recent > >> @@ -101,6 +102,7 @@ struct perf_raw_record { > >> */ > >> struct perf_branch_stack { > >> __u64 nr; > >> + __u64 tos; /* PMU specific data */ > >> struct perf_branch_entry entries[0]; > >> }; > >> > > Same remark as with the other patch. You need to abstract this. > > The TOS and PMU specific data should be limited to x86/event/intel/*.[ch]. > > > > If we change tos to a generic name, e.g. pmu_specific_data, can we still > keep it here? > It's not just about the name, it is about what it points to? What value does it return when the hw does not have a TOS? I added the PERF_SAMPLE_BRANCH_*. I did not just expose the raw LBR. There is an abstraction layer, so it is easier to map to other architectures, like IBM Power, for instance. You cannot just add a TOS and say it is PMU specific. If you do that for all architectures, then it becomes very messy and hard to understand and use especially for tools. This is an interface you are trying to define. This needs to be specified precisely so that tools can make the right assumptions across hw platforms. Note that the entries[] array is normally already sorted by most recent to least recent. So exporting a TOS there is bizarre. The TOS is likely always pointing to the most recent entry. The TOS you want is exposing a low level index which does not map to the abstracted branch stack. And that's a problem. You need to reconcile your definition of TOS with the branch_sample_entry [] abstraction. > If not, I think the only way is to introduce a new method, e.g. > output_br_pmu_data(), at struct pmu. > When outputting the sample data, the generic code will call > event->pmu->output_br_pmu_data() to retrieve the TOS in Intel code. > I think it's too complicated. > > Thanks, > Kan > > > >