Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1432894 > unrolled thread

[PATCH 3/4] perf annotate: add powerpc support

Started byRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
First post2016-06-28 13:40 +0200
Last post2016-06-29 08:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 3/4] perf annotate: add powerpc support Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-28 13:40 +0200
    RE: [PATCH 3/4] perf annotate: add powerpc support David Laight <David.Laight@ACULAB.COM> - 2016-06-28 18:10 +0200
      Re: [PATCH 3/4] perf annotate: add powerpc support Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> - 2016-06-29 08:50 +0200

#1432894 — [PATCH 3/4] perf annotate: add powerpc support

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-06-28 13:40 +0200
Subject[PATCH 3/4] perf annotate: add powerpc support
Message-ID<rOZwZ-6qc-15@gated-at.bofh.it>
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>

Powerpc has long list of branch instructions and hardcoding them in table
appears to be error-prone. So, add new function to find instruction
instead of creating table.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
---
 tools/perf/util/annotate.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 36a5825..96c6610 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -476,6 +476,68 @@ static int ins__cmp(const void *a, const void *b)
 	return strcmp(ia->name, ib->name);
 }
 
+static struct ins *ins__find_powerpc(const char *name)
+{
+	int i;
+	struct ins *ins;
+
+	ins = zalloc(sizeof(struct ins));
+	if (!ins)
+		return NULL;
+
+	ins->name = strdup(name);
+	if (!ins->name)
+		return NULL;
+
+	if (name[0] == 'b') {
+		/* branch instructions */
+		ins->ops = &jump_ops;
+
+		/*
+		 * - Few start with 'b', but aren't branch instructions.
+		 * - Let's also ignore instructions involving 'ctr' and
+		 *   'tar' since target branch addresses for those can't
+		 *   be determined statically.
+		 */
+		if (!strncmp(name, "bcd", 3)   ||
+		    !strncmp(name, "brinc", 5) ||
+		    !strncmp(name, "bper", 4)  ||
+		    strstr(name, "ctr")        ||
+		    strstr(name, "tar"))
+			return NULL;
+
+		i = strlen(name) - 1;
+		if (i < 0)
+			return NULL;
+
+		/* ignore optional hints at the end of the instructions */
+		if (name[i] == '+' || name[i] == '-')
+			i--;
+
+		if (name[i] == 'l' || (name[i] == 'a' && name[i-1] == 'l')) {
+			/*
+			 * if the instruction ends up with 'l' or 'la', then
+			 * those are considered 'calls' since they update LR.
+			 * ... except for 'bnl' which is branch if not less than
+			 * and the absolute form of the same.
+			 */
+			if (strcmp(name, "bnl") && strcmp(name, "bnl+") &&
+			    strcmp(name, "bnl-") && strcmp(name, "bnla") &&
+			    strcmp(name, "bnla+") && strcmp(name, "bnla-"))
+				ins->ops = &call_ops;
+		}
+		if (name[i] == 'r' && name[i-1] == 'l')
+			/*
+			 * instructions ending with 'lr' are considered to be
+			 * return instructions
+			 */
+			ins->ops = &ret_ops;
+
+		return ins;
+	}
+	return NULL;
+}
+
 static void ins__sort(struct ins *instructions, int nmemb)
 {
 	qsort(instructions, nmemb, sizeof(struct ins), ins__cmp);
@@ -511,6 +573,8 @@ static struct ins *ins__find(const char *name, const char *norm_arch)
 	} else if (!strcmp(norm_arch, "arm")) {
 		instructions = instructions_arm;
 		nmemb = ARRAY_SIZE(instructions_arm);
+	} else if (!strcmp(norm_arch, "powerpc")) {
+		return ins__find_powerpc(name);
 	} else {
 		pr_err("perf annotate not supported by %s arch\n", norm_arch);
 		return NULL;
-- 
2.5.5

[toc] | [next] | [standalone]


#1433087

FromDavid Laight <David.Laight@ACULAB.COM>
Date2016-06-28 18:10 +0200
Message-ID<rP3Kh-Rj-11@gated-at.bofh.it>
In reply to#1432894
From: Ravi Bangoria
> Sent: 28 June 2016 12:37
> 
> Powerpc has long list of branch instructions and hardcoding them in table
> appears to be error-prone. So, add new function to find instruction
> instead of creating table.
> 
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
> ---
>  tools/perf/util/annotate.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 64 insertions(+)
> 
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 36a5825..96c6610 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -476,6 +476,68 @@ static int ins__cmp(const void *a, const void *b)
>  	return strcmp(ia->name, ib->name);
>  }
> 
> +static struct ins *ins__find_powerpc(const char *name)

It would be better if the function name include 'branch'.

> +{
> +	int i;
> +	struct ins *ins;
> +
> +	ins = zalloc(sizeof(struct ins));
> +	if (!ins)
> +		return NULL;
> +
> +	ins->name = strdup(name);
> +	if (!ins->name)
> +		return NULL;

	You leak 'ins' here.

> +
> +	if (name[0] == 'b') {
> +		/* branch instructions */
> +		ins->ops = &jump_ops;
> +
> +		/*
> +		 * - Few start with 'b', but aren't branch instructions.
> +		 * - Let's also ignore instructions involving 'ctr' and
> +		 *   'tar' since target branch addresses for those can't
> +		 *   be determined statically.
> +		 */
> +		if (!strncmp(name, "bcd", 3)   ||
> +		    !strncmp(name, "brinc", 5) ||
> +		    !strncmp(name, "bper", 4)  ||
> +		    strstr(name, "ctr")        ||
> +		    strstr(name, "tar"))
> +			return NULL;

	More importantly you leak 'ins' and 'ins->name' here.
	And on other paths below.

...

	David

[toc] | [prev] | [next] | [standalone]


#1433482

FromRavi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Date2016-06-29 08:50 +0200
Message-ID<rPhtT-NA-3@gated-at.bofh.it>
In reply to#1433087
Thanks David.

On Tuesday 28 June 2016 09:37 PM, David Laight wrote:
> From: Ravi Bangoria
>> Sent: 28 June 2016 12:37
>>
>> Powerpc has long list of branch instructions and hardcoding them in table
>> appears to be error-prone. So, add new function to find instruction
>> instead of creating table.
>>
>> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
>> Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
>> ---
>>   tools/perf/util/annotate.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 64 insertions(+)
>>
>> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
>> index 36a5825..96c6610 100644
>> --- a/tools/perf/util/annotate.c
>> +++ b/tools/perf/util/annotate.c
>> @@ -476,6 +476,68 @@ static int ins__cmp(const void *a, const void *b)
>>   	return strcmp(ia->name, ib->name);
>>   }
>>
>> +static struct ins *ins__find_powerpc(const char *name)
> It would be better if the function name include 'branch'.
>
>> +{
>> +	int i;
>> +	struct ins *ins;
>> +
>> +	ins = zalloc(sizeof(struct ins));
>> +	if (!ins)
>> +		return NULL;
>> +
>> +	ins->name = strdup(name);
>> +	if (!ins->name)
>> +		return NULL;
> 	You leak 'ins' here.
>
>> +
>> +	if (name[0] == 'b') {
>> +		/* branch instructions */
>> +		ins->ops = &jump_ops;
>> +
>> +		/*
>> +		 * - Few start with 'b', but aren't branch instructions.
>> +		 * - Let's also ignore instructions involving 'ctr' and
>> +		 *   'tar' since target branch addresses for those can't
>> +		 *   be determined statically.
>> +		 */
>> +		if (!strncmp(name, "bcd", 3)   ||
>> +		    !strncmp(name, "brinc", 5) ||
>> +		    !strncmp(name, "bper", 4)  ||
>> +		    strstr(name, "ctr")        ||
>> +		    strstr(name, "tar"))
>> +			return NULL;
> 	More importantly you leak 'ins' and 'ins->name' here.
> 	And on other paths below.

Yes. Fair points.

I can create linked list that maintain allocated instructions and
lookup it every time before allocating memory. But for this,
I need to free memory at the end and it's becoming complicated.

I can go back to normal approach of creating table for powerpc.
This is simplest. But only problem is powerpc has around 400 branch
instructions(which includes call and ret as well). And list them all is
bit error-prone.

Suggestions?

- Ravi

> ...
>
> 	David
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web