Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp898432ybc; Tue, 19 Nov 2019 11:06:13 -0800 (PST) X-Google-Smtp-Source: APXvYqyA3M/GBpdk92zlmTkrUM+tZKAoWSu/fhUoSmSWjQCrsE9xpkLGZ44o6jXdRbSwSFFkSDhG X-Received: by 2002:a17:906:194a:: with SMTP id b10mr37226624eje.123.1574190373336; Tue, 19 Nov 2019 11:06:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574190373; cv=none; d=google.com; s=arc-20160816; b=gJ8u8kJA9aWc20rRmtYGtU3c1natD1MjDQhxp5A+Qyf1e7qCA6tJSdRBCIKGWzxkGx QyabIUrucjAT368zBHa2d2V+ejfo/PAZxspnnFhYWuaAczfET2KDyupBFtBgwATupdS9 hcEWw7/AM0Z//rXxSH89uC0+UUlchPqJ61mDgyKLCJgeuXTH4jJyAMXfJyPpEc9W/QdV e2LU6JqtkTpYvn1BPxQsp7lnPs1bLWTKb/THmiiDnPNq4Hld58uphYlZwJ374eZiv3GB KkiiHLdFGQj4ocZlFu8ZUwqUMrQYp9Z83irFiheiVW5vtvXlJCnoRMk2ewG2/eG4PTZ5 kqZg== 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=N5IXEqqYz7IFwy+gEurJhn05Az2pV/jf6zB5Y5rRxrU=; b=wpYQYnWURsAYDoKJCHLiGRtA9xC3mSWLR7s7M+6c/og6B2tdZMOW8NFrk2eod3otYu k1STS7KrmBIjgHk89JoCPhw3UelanQfMQszdT1o0oJvfR8ZSpJdI6DvDLLkq3xTKz2Iw KV5LNs8ryRxxowXxwgsJM9kgwH04/iVAjUGhMQbAnQcWIJfvHBm7WMgnrOlo/dG2CaUG z9hPEzaQFoa0q2/sQsJoQq/ly73Nz7212bySOYlOAHKfmvblJ0QFYQy7pmZQhRonWn4I 02sisjW1zelFTvXAig2Z2H707TtH0y+y87ZRD0OA/k5WZFfwLd+Zl384QaWIx/8AbZHx OQmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EuzDHzZz; 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 a4si13923862ejy.439.2019.11.19.11.05.48; Tue, 19 Nov 2019 11:06:13 -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=EuzDHzZz; 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 S1727295AbfKSTCY (ORCPT + 99 others); Tue, 19 Nov 2019 14:02:24 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:33879 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726711AbfKSTCX (ORCPT ); Tue, 19 Nov 2019 14:02:23 -0500 Received: by mail-il1-f195.google.com with SMTP id p6so20732267ilp.1 for ; Tue, 19 Nov 2019 11:02:22 -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=N5IXEqqYz7IFwy+gEurJhn05Az2pV/jf6zB5Y5rRxrU=; b=EuzDHzZzwMf9YDBFrVfiFws0Iew/P7Ki1TvB06d1mxqNSPP7AgdCaHL370iKwv5YqT WmQ21HBtq+tEcd3X0LqhBHsgbeEvhKBTTkxQr06rBrmfG8JAbP5drJoaDAkudj53TB0F LP2o9b77UViL6qR6tMqNrKVIOJ1vQcQdGbVaAYYiWScCLm0HiRSWDdslLQgyUEiVT/8Q 0mwIuGZVfTUn3aSbi3XteKRPQEGqRU2YKYSaPHpp/Azv0l+FFbFFIbxP3ioYiTFn9sHe 71x1IpjIIg8IUllPT/X5eLWETggefEdx74zEhMqWp7FhOZv1+g0V9x/lgJ3AZT7XFROL ogGg== 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=N5IXEqqYz7IFwy+gEurJhn05Az2pV/jf6zB5Y5rRxrU=; b=GsRD8E9sf1S7kE+zWfNx+gpRck8qTQjknvrv9GCDIugcbPyp6+cVeJJe+fLYkHyS1N 2qtYfJtqW2bScgcrwMfx9BiqqOBa0xCm50s/LM7982BaZZgwgLZcr4CrrdTX5AaT/O3A +cpBgAoBMAQN1p6w8FtWHpREeuT92Bf78I2bx84/gDlB95+BUF55gXowvLPKbUl7kKgN xJXHituKfkWMEfKxeoybc+PfBvAgwbHRD0GhCKqO+2FfnHbnh4itC9ifpbc3WEVEHmF9 nFyPbfn19oVba+Nent5DPIefnxC5Cqi1Ua25BMEVVcf7zDnomygcHJsT3+oIWzif2008 TqVA== X-Gm-Message-State: APjAAAVfQ7UR4z6t8G5jWaQc7iDA5C3Cc+0CeFhWWvvQO3lRJHLksM5Q fMHqpnynwK6fHEli77yq3eyxtRSW8kROxmbMhXusxUua X-Received: by 2002:a92:dd8e:: with SMTP id g14mr22948154iln.129.1574190141871; Tue, 19 Nov 2019 11:02:21 -0800 (PST) MIME-Version: 1.0 References: <20191119143411.3482-1-kan.liang@linux.intel.com> <20191119143411.3482-2-kan.liang@linux.intel.com> In-Reply-To: <20191119143411.3482-2-kan.liang@linux.intel.com> From: Stephane Eranian Date: Tue, 19 Nov 2019 11:02:10 -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 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]. > diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h > index bb7b271397a6..c2da61c9ace7 100644 > --- a/include/uapi/linux/perf_event.h > +++ b/include/uapi/linux/perf_event.h > @@ -180,7 +180,10 @@ enum perf_branch_sample_type_shift { > > PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT = 16, /* save branch type */ > > - PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ > + PERF_SAMPLE_BRANCH_MAX_SHIFT = 17, /* non-ABI */ > + > + /* PMU specific */ > + PERF_SAMPLE_BRANCH_LBR_TOS_SHIFT = 63, /* save LBR TOS */ > }; > > enum perf_branch_sample_type { > @@ -208,8 +211,13 @@ enum perf_branch_sample_type { > 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT, > > PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, > + > + PERF_SAMPLE_BRANCH_LBR_TOS = 1ULL << PERF_SAMPLE_BRANCH_LBR_TOS_SHIFT, > }; > > +#define PERF_SAMPLE_BRANCH_MASK ((PERF_SAMPLE_BRANCH_MAX - 1) |\ > + PERF_SAMPLE_BRANCH_LBR_TOS) > + > /* > * Common flow change classification > */ > @@ -849,7 +857,11 @@ enum perf_event_type { > * char data[size];}&& PERF_SAMPLE_RAW > * > * { u64 nr; > - * { u64 from, to, flags } lbr[nr];} && PERF_SAMPLE_BRANCH_STACK > + * { u64 from, to, flags } lbr[nr]; > + * > + * # only available if PERF_SAMPLE_BRANCH_LBR_TOS is set > + * u64 tos; > + * } && PERF_SAMPLE_BRANCH_STACK > * > * { u64 abi; # enum perf_sample_regs_abi > * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER > diff --git a/kernel/events/core.c b/kernel/events/core.c > index cfd89b4a02d8..8aff3aad43b5 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -6391,6 +6391,11 @@ static void perf_output_read(struct perf_output_handle *handle, > perf_output_read_one(handle, event, enabled, running); > } > > +static inline bool perf_sample_save_lbr_tos(struct perf_event *event) > +{ > + return event->attr.branch_sample_type & PERF_SAMPLE_BRANCH_LBR_TOS; > +} > + > void perf_output_sample(struct perf_output_handle *handle, > struct perf_event_header *header, > struct perf_sample_data *data, > @@ -6480,6 +6485,8 @@ void perf_output_sample(struct perf_output_handle *handle, > > perf_output_put(handle, data->br_stack->nr); > perf_output_copy(handle, data->br_stack->entries, size); > + if (perf_sample_save_lbr_tos(event)) > + perf_output_put(handle, data->br_stack->tos); > } else { > /* > * we always store at least the value of nr > @@ -6667,7 +6674,11 @@ void perf_prepare_sample(struct perf_event_header *header, > if (data->br_stack) { > size += data->br_stack->nr > * sizeof(struct perf_branch_entry); > + > + if (perf_sample_save_lbr_tos(event)) > + size += sizeof(u64); > } > + > header->size += size; > } > > @@ -10731,7 +10742,7 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr, > u64 mask = attr->branch_sample_type; > > /* only using defined bits */ > - if (mask & ~(PERF_SAMPLE_BRANCH_MAX-1)) > + if (mask & ~PERF_SAMPLE_BRANCH_MASK) > return -EINVAL; > > /* at least one branch bit must be set */ > -- > 2.17.1 >