From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752612AbcF2Grq (ORCPT ); Wed, 29 Jun 2016 02:47:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60106 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751953AbcF2Grp (ORCPT ); Wed, 29 Jun 2016 02:47:45 -0400 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: ravi.bangoria@linux.vnet.ibm.com Subject: Re: [PATCH 3/4] perf annotate: add powerpc support To: David Laight , "linux-kernel@vger.kernel.org" , "acme@kernel.org" , "linuxppc-dev@lists.ozlabs.org" References: <1467113807-29571-1-git-send-email-ravi.bangoria@linux.vnet.ibm.com> <1467113807-29571-4-git-send-email-ravi.bangoria@linux.vnet.ibm.com> <063D6719AE5E284EB5DD2968C1650D6D5F4E67FA@AcuExch.aculab.com> Cc: "ananth@in.ibm.com" , "naveen.n.rao@linux.vnet.ibm.com" , "dja@axtens.net" From: Ravi Bangoria Date: Wed, 29 Jun 2016 12:17:29 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D5F4E67FA@AcuExch.aculab.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16062906-8235-0000-0000-000008B136BF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16062906-8236-0000-0000-000032AA11D2 Message-Id: <57736F01.1010308@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-06-29_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1606290062 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> Signed-off-by: Ravi Bangoria >> --- >> 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 >