From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: kan.liang@linux.intel.com
Cc: jolsa@redhat.com, peterz@infradead.org, mingo@redhat.com,
linux-kernel@vger.kernel.org, namhyung@kernel.org,
adrian.hunter@intel.com, mathieu.poirier@linaro.org,
ravi.bangoria@linux.ibm.com, alexey.budankov@linux.intel.com,
vitaly.slobodskoy@intel.com, pavel.gerasimov@intel.com,
mpe@ellerman.id.au, eranian@google.com, ak@linux.intel.com
Subject: Re: [PATCH V4 10/17] perf tools: Save previous sample for LBR stitching approach
Date: Fri, 17 Apr 2020 12:02:40 -0300 [thread overview]
Message-ID: <20200417150240.GC17973@kernel.org> (raw)
In-Reply-To: <20200319202517.23423-11-kan.liang@linux.intel.com>
Em Thu, Mar 19, 2020 at 01:25:10PM -0700, kan.liang@linux.intel.com escreveu:
> From: Kan Liang <kan.liang@linux.intel.com>
>
> To retrieve the overwritten LBRs from previous sample for LBR stitching
> approach, perf has to save the previous sample.
>
> Only allocate the struct lbr_stitch once, when LBR stitching approach
> is enabled and kernel supports hw_idx.
Applied + this one on top:
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 59778f5aec2a..a54ca09a1d00 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2297,7 +2297,7 @@ static bool alloc_lbr_stitch(struct thread *thread)
if (thread->lbr_stitch)
return true;
- thread->lbr_stitch = calloc(1, sizeof(struct lbr_stitch));
+ thread->lbr_stitch = zalloc(sizeof(*thread->lbr_stitch));
if (!thread->lbr_stitch)
goto err;
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index f65a84a25f93..34eb61cee6a4 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -5,6 +5,7 @@
#include <linux/refcount.h>
#include <linux/rbtree.h>
#include <linux/list.h>
+#include <linux/zalloc.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
@@ -153,7 +154,7 @@ static inline bool thread__is_filtered(struct thread *thread)
static inline void thread__free_stitch_list(struct thread *thread)
{
- free(thread->lbr_stitch);
+ zfree(&thread->lbr_stitch);
}
#endif /* __PERF_THREAD_H */
> Reviewed-by: Andi Kleen <ak@linux.intel.com>
> Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
> ---
> tools/perf/util/machine.c | 23 +++++++++++++++++++++++
> tools/perf/util/thread.c | 1 +
> tools/perf/util/thread.h | 11 +++++++++++
> 3 files changed, 35 insertions(+)
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index f1661dd3ca69..d91e11bfc8ca 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2261,6 +2261,21 @@ static int lbr_callchain_add_lbr_ip(struct thread *thread,
> return 0;
> }
>
> +static bool alloc_lbr_stitch(struct thread *thread)
> +{
> + if (thread->lbr_stitch)
> + return true;
> +
> + thread->lbr_stitch = calloc(1, sizeof(struct lbr_stitch));
> + if (!thread->lbr_stitch)
> + goto err;
> +
> +err:
> + pr_warning("Failed to allocate space for stitched LBRs. Disable LBR stitch\n");
> + thread->lbr_stitch_enable = false;
> + return false;
> +}
> +
> /*
> * Recolve LBR callstack chain sample
> * Return:
> @@ -2277,6 +2292,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
> {
> struct ip_callchain *chain = sample->callchain;
> int chain_nr = min(max_stack, (int)chain->nr), i;
> + struct lbr_stitch *lbr_stitch;
> u64 branch_from = 0;
> int err;
>
> @@ -2289,6 +2305,13 @@ static int resolve_lbr_callchain_sample(struct thread *thread,
> if (i == chain_nr)
> return 0;
>
> + if (thread->lbr_stitch_enable && !sample->no_hw_idx &&
> + alloc_lbr_stitch(thread)) {
> + lbr_stitch = thread->lbr_stitch;
> +
> + memcpy(&lbr_stitch->prev_sample, sample, sizeof(*sample));
> + }
> +
> if (callchain_param.order == ORDER_CALLEE) {
> /* Add kernel ip */
> err = lbr_callchain_add_kernel_ip(thread, cursor, sample,
> diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> index 1f080db23615..8d0da260c84c 100644
> --- a/tools/perf/util/thread.c
> +++ b/tools/perf/util/thread.c
> @@ -111,6 +111,7 @@ void thread__delete(struct thread *thread)
>
> exit_rwsem(&thread->namespaces_lock);
> exit_rwsem(&thread->comm_lock);
> + thread__free_stitch_list(thread);
> free(thread);
> }
>
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index 95294050cff2..f65a84a25f93 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -13,6 +13,7 @@
> #include <strlist.h>
> #include <intlist.h>
> #include "rwsem.h"
> +#include "event.h"
>
> struct addr_location;
> struct map;
> @@ -20,6 +21,10 @@ struct perf_record_namespaces;
> struct thread_stack;
> struct unwind_libunwind_ops;
>
> +struct lbr_stitch {
> + struct perf_sample prev_sample;
> +};
> +
> struct thread {
> union {
> struct rb_node rb_node;
> @@ -49,6 +54,7 @@ struct thread {
>
> /* LBR call stack stitch */
> bool lbr_stitch_enable;
> + struct lbr_stitch *lbr_stitch;
> };
>
> struct machine;
> @@ -145,4 +151,9 @@ static inline bool thread__is_filtered(struct thread *thread)
> return false;
> }
>
> +static inline void thread__free_stitch_list(struct thread *thread)
> +{
> + free(thread->lbr_stitch);
> +}
> +
> #endif /* __PERF_THREAD_H */
> --
> 2.17.1
>
--
- Arnaldo
next prev parent reply other threads:[~2020-04-17 15:02 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-19 20:25 [PATCH V4 00/17] Stitch LBR call stack (Perf Tools) kan.liang
2020-03-19 20:25 ` [PATCH V4 01/17] perf pmu: Add support for PMU capabilities kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 02/17] perf header: Support CPU " kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 03/17] perf record: Clear HEADER_CPU_PMU_CAPS for non LBR call stack mode kan.liang
2020-04-17 14:42 ` Arnaldo Carvalho de Melo
2020-03-19 20:25 ` [PATCH V4 04/17] perf stat: Clear HEADER_CPU_PMU_CAPS kan.liang
2020-04-17 14:42 ` Arnaldo Carvalho de Melo
2020-03-19 20:25 ` [PATCH V4 05/17] perf machine: Remove the indent in resolve_lbr_callchain_sample kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 06/17] perf machine: Refine the function for LBR call stack reconstruction kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 07/17] perf machine: Factor out lbr_callchain_add_kernel_ip() kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 08/17] perf machine: Factor out lbr_callchain_add_lbr_ip() kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 09/17] perf thread: Add a knob for LBR stitch approach kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 10/17] perf tools: Save previous sample for LBR stitching approach kan.liang
2020-04-17 15:02 ` Arnaldo Carvalho de Melo [this message]
2020-04-22 12:17 ` [tip: perf/core] perf thread: " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 11/17] perf tools: Save previous cursor nodes " kan.liang
2020-04-17 16:53 ` Arnaldo Carvalho de Melo
2020-04-22 12:17 ` [tip: perf/core] perf callchain: " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 12/17] perf tools: Stitch LBR call stack kan.liang
2020-04-22 12:17 ` [tip: perf/core] perf callchain: " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 13/17] perf report: Add option to enable the LBR stitching approach kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 14/17] perf script: " kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 15/17] perf top: " kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 16/17] perf c2c: " kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-19 20:25 ` [PATCH V4 17/17] perf hist: Add fast path for duplicate entries check kan.liang
2020-04-22 12:17 ` [tip: perf/core] " tip-bot2 for Kan Liang
2020-03-23 11:13 ` [PATCH V4 00/17] Stitch LBR call stack (Perf Tools) Jiri Olsa
2020-04-02 15:34 ` Liang, Kan
2020-04-02 16:00 ` Arnaldo Carvalho de Melo
2020-04-02 17:02 ` Liang, Kan
2020-04-17 17:48 ` Arnaldo Carvalho de Melo
2020-04-17 21:47 ` Liang, Kan
2020-04-17 21:54 ` Arnaldo Carvalho de Melo
2020-04-17 21:55 ` Arnaldo Carvalho de Melo
2020-04-17 21:55 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200417150240.GC17973@kernel.org \
--to=arnaldo.melo@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=namhyung@kernel.org \
--cc=pavel.gerasimov@intel.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@linux.ibm.com \
--cc=vitaly.slobodskoy@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.