public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf sort: Segmentation fault of basic block cycles sort dimension
@ 2017-03-13  8:31 changbin.du
  2017-03-13 14:41 ` Arnaldo Carvalho de Melo
  2017-03-15 18:37 ` [tip:perf/core] perf sort: Fix segfault with basic block 'cycles' " tip-bot for Changbin Du
  0 siblings, 2 replies; 3+ messages in thread
From: changbin.du @ 2017-03-13  8:31 UTC (permalink / raw)
  To: peterz, mingo, acme; +Cc: linux-kernel, Changbin Du

From: Changbin Du <changbin.du@intel.com>

Skip the sample which doesn't have branch_info to avoid segmentation
fault occurrence.

The fault can be reproduced by:
perf record -a
perf report -F cycles

Signed-off-by: Changbin Du <changbin.du@intel.com>
---
 tools/perf/util/sort.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 0ff6222..b6db140 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
 static int64_t
 sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 {
+	if (!left->branch_info || !right->branch_info)
+		return cmp_null(left->branch_info, right->branch_info);
+
 	return left->branch_info->flags.cycles -
 		right->branch_info->flags.cycles;
 }
@@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
 				    size_t size, unsigned int width)
 {
+	if (!he->branch_info)
+		return scnprintf(bf, size, "%-.*s", width, "N/A");
 	if (he->branch_info->flags.cycles == 0)
 		return repsep_snprintf(bf, size, "%-*s", width, "-");
 	return repsep_snprintf(bf, size, "%-*hd", width,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf sort: Segmentation fault of basic block cycles sort dimension
  2017-03-13  8:31 [PATCH] perf sort: Segmentation fault of basic block cycles sort dimension changbin.du
@ 2017-03-13 14:41 ` Arnaldo Carvalho de Melo
  2017-03-15 18:37 ` [tip:perf/core] perf sort: Fix segfault with basic block 'cycles' " tip-bot for Changbin Du
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-03-13 14:41 UTC (permalink / raw)
  To: changbin.du; +Cc: peterz, mingo, linux-kernel

Em Mon, Mar 13, 2017 at 04:31:48PM +0800, changbin.du@intel.com escreveu:
> From: Changbin Du <changbin.du@intel.com>
> 
> Skip the sample which doesn't have branch_info to avoid segmentation
> fault occurrence.
> 
> The fault can be reproduced by:
> perf record -a
> perf report -F cycles

Thanks, applied.

- Arnaldo
 
> Signed-off-by: Changbin Du <changbin.du@intel.com>
> ---
>  tools/perf/util/sort.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index 0ff6222..b6db140 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
>  static int64_t
>  sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
>  {
> +	if (!left->branch_info || !right->branch_info)
> +		return cmp_null(left->branch_info, right->branch_info);
> +
>  	return left->branch_info->flags.cycles -
>  		right->branch_info->flags.cycles;
>  }
> @@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
>  static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
>  				    size_t size, unsigned int width)
>  {
> +	if (!he->branch_info)
> +		return scnprintf(bf, size, "%-.*s", width, "N/A");
>  	if (he->branch_info->flags.cycles == 0)
>  		return repsep_snprintf(bf, size, "%-*s", width, "-");
>  	return repsep_snprintf(bf, size, "%-*hd", width,
> -- 
> 2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:perf/core] perf sort: Fix segfault with basic block 'cycles' sort dimension
  2017-03-13  8:31 [PATCH] perf sort: Segmentation fault of basic block cycles sort dimension changbin.du
  2017-03-13 14:41 ` Arnaldo Carvalho de Melo
@ 2017-03-15 18:37 ` tip-bot for Changbin Du
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Changbin Du @ 2017-03-15 18:37 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ak, tglx, acme, hpa, changbin.du, peterz, mingo, linux-kernel

Commit-ID:  4b0b3aa6a2756e6115fdf275c521e4552a7082f3
Gitweb:     http://git.kernel.org/tip/4b0b3aa6a2756e6115fdf275c521e4552a7082f3
Author:     Changbin Du <changbin.du@intel.com>
AuthorDate: Mon, 13 Mar 2017 16:31:48 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 13 Mar 2017 11:41:20 -0300

perf sort: Fix segfault with basic block 'cycles' sort dimension

Skip the sample which doesn't have branch_info to avoid segmentation
fault:

The fault can be reproduced by:

  perf record -a
  perf report -F cycles

Signed-off-by: Changbin Du <changbin.du@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Fixes: 0e332f033a82 ("perf tools: Add support for cycles, weight branch_info field")
Link: http://lkml.kernel.org/r/20170313083148.23568-1-changbin.du@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/sort.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index f8f16c0..93f755a 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
 static int64_t
 sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 {
+	if (!left->branch_info || !right->branch_info)
+		return cmp_null(left->branch_info, right->branch_info);
+
 	return left->branch_info->flags.cycles -
 		right->branch_info->flags.cycles;
 }
@@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
 				    size_t size, unsigned int width)
 {
+	if (!he->branch_info)
+		return scnprintf(bf, size, "%-.*s", width, "N/A");
 	if (he->branch_info->flags.cycles == 0)
 		return repsep_snprintf(bf, size, "%-*s", width, "-");
 	return repsep_snprintf(bf, size, "%-*hd", width,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-15 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-13  8:31 [PATCH] perf sort: Segmentation fault of basic block cycles sort dimension changbin.du
2017-03-13 14:41 ` Arnaldo Carvalho de Melo
2017-03-15 18:37 ` [tip:perf/core] perf sort: Fix segfault with basic block 'cycles' " tip-bot for Changbin Du

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox