Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3286151pxv; Mon, 28 Jun 2021 00:46:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcWQXunikId7nPj2LLPT7hK+fZHMQs0IeKlc3poxLAxnJhrLN/HZQmg8ux7mCfRRldLS2+ X-Received: by 2002:a05:6402:1355:: with SMTP id y21mr31420412edw.136.1624866410051; Mon, 28 Jun 2021 00:46:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624866410; cv=none; d=google.com; s=arc-20160816; b=tMxfhJLrTtUp1JiD3d55zVZSy5za/WX2RakxNnc9LhaMcaQ2StqQS6DVRK7r6n7Lgg Fv6Vy9K7TDW10kjfmnA8tdrcboBBG7GjKnQji4T+YidFW8UKSlw803bElJ+O0xiePY1T suncR7l2BVlNwH32Tg3lUwOLFZIptmW5vxh0vDdGgTNltl3x8wGfkZfkSfztygUdlj8r LrfYSrkxUVoIegdTjHnW04YPreTmPgHSIeMABE5rjPWgdwyT4N1BAkOBJN/8lsKkX1X5 jSesYHaBmOMr93tx2Xz6zTS6Hdi5azKZsrjE0k3YeUQv91EhJgtrEz1hMv2VUkO4dv3e iiXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=r/immuZYVE8Caoc6yGkt0MFN06PO3hMxemxPKVsCOXg=; b=FE2WdnApBVMBpUUgkvkAWVqgKcJKdP4Mg001x+2qncjJkXSFYfOENd20VgRSje1xQ8 l9TYDhnIhhGTkUNUx661nhlm7WKJsXQyGXZQR79FOYdkXS+MWHa6+Ihf6Rq6JNMm7cl5 ddRQaYFcRdUAJxjUzN/Wkmt/Jh8KyFXnpLdwcx0JA5kGHhyG0ZYsuG6iGstcqv2f1KHx 3vpR6jYSbFCdKEF4hB0fg/b8bWTuNYFeNN6g+/kH/SL4GnbL7BkvpZpiNlQ5UT04kutw G0s7i/5LMwOPXVpvVSnIFjp+hkiHRo/CYkUehr/u8RAOPsClQ4h7llNpXwGMtfJAqSzR J0Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PULsJ+fC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m25si12986536ejb.570.2021.06.28.00.46.26; Mon, 28 Jun 2021 00:46:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=PULsJ+fC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232315AbhF1HSR (ORCPT + 99 others); Mon, 28 Jun 2021 03:18:17 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:64246 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229998AbhF1HSR (ORCPT ); Mon, 28 Jun 2021 03:18:17 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15S744tO116374; Mon, 28 Jun 2021 03:15:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=r/immuZYVE8Caoc6yGkt0MFN06PO3hMxemxPKVsCOXg=; b=PULsJ+fCBXwXQpq19YESKYj0NUC1PSmgzSWtwYgrrtUlXkB52ioit+TZ2eR/ACgDEcvH QdE60MHlrGWSM0Accw/n6FFe/VKL31exLwfVqcJnXHauLyHJPW8u/xd+PS6O6AAolGnp 3+unw+UygJRQbHODn98vnrJkJUPGf4kfKEDtQjPL1VfrvTexV70kIGFnYSRS+pA/OgB1 zvVI8rQL/FMObBe1IV3uQkBgWZ7q6UHJvHTqCLozkk+7RxVVtkP9AaR/bSA5lO7U+3P0 yWMQP+jF6FFmQvnC2orEqrJZ5280vlzJ8MwkfOOqoo0j/cJeixSDSCa2/+HNjnbPFLRv eA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 39f77qkfd1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 03:15:46 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 15S75M6n124410; Mon, 28 Jun 2021 03:15:46 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 39f77qkfc9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 03:15:46 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 15S78YCZ030026; Mon, 28 Jun 2021 07:15:44 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 39duv8gmmy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Jun 2021 07:15:44 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 15S7EAK835979730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jun 2021 07:14:11 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 63E09A4166; Mon, 28 Jun 2021 07:15:40 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8345AA4124; Mon, 28 Jun 2021 07:15:38 +0000 (GMT) Received: from Nageswaras-MacBook-Pro-2.local (unknown [9.199.47.223]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 28 Jun 2021 07:15:38 +0000 (GMT) Subject: Re: [PATCH] perf script python: Fix buffer size to report iregs in perf script To: Kajol Jain , acme@kernel.org Cc: maddy@linux.vnet.ibm.com, atrajeev@linux.vnet.ibm.com, pc@us.ibm.com, linux-kernel@vger.kernel.org, jolsa@redhat.com, ravi.bangoria@linux.ibm.com, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: <20210628062341.155839-1-kjain@linux.ibm.com> From: Nageswara Sastry Message-ID: <46ddcac9-e115-6b96-11ec-6208bcd1c98a@linux.ibm.com> Date: Mon, 28 Jun 2021 12:45:36 +0530 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210628062341.155839-1-kjain@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: vyCjQThvpV6iZpLIzekUkfEwUnIT5C78 X-Proofpoint-GUID: -295f2NuuxizaUdLdi4i3_NLvBLXf4i4 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-28_05:2021-06-25,2021-06-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 spamscore=0 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106280049 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tested by creating perf-script.py using perf script and priting the iregs. Seen more values with this patch. Tested-by: Nageswara R Sastry On 28/06/21 11:53 am, Kajol Jain wrote: > Commit 48a1f565261d ("perf script python: Add more PMU fields > to event handler dict") added functionality to report fields like > weight, iregs, uregs etc via perf report. > That commit predefined buffer size to 512 bytes to print those fields. > > But incase of powerpc, since we added extended regs support > in commits: > > Commit 068aeea3773a ("perf powerpc: Support exposing Performance Monitor > Counter SPRs as part of extended regs") > Commit d735599a069f ("powerpc/perf: Add extended regs support for > power10 platform") > > Now iregs can carry more bytes of data and this predefined buffer size > can result to data loss in perf script output. > > Patch resolve this issue by making buffer size dynamic based on number > of registers needed to print. It also changed return type for function > "regs_map" from int to void, as the return value is not being used by > the caller function "set_regs_in_dict". > > Fixes: 068aeea3773a ("perf powerpc: Support exposing Performance Monitor > Counter SPRs as part of extended regs") > Signed-off-by: Kajol Jain > --- > .../util/scripting-engines/trace-event-python.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) > > diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c > index 4e4aa4c97ac5..c8c9706b4643 100644 > --- a/tools/perf/util/scripting-engines/trace-event-python.c > +++ b/tools/perf/util/scripting-engines/trace-event-python.c > @@ -687,7 +687,7 @@ static void set_sample_datasrc_in_dict(PyObject *dict, > _PyUnicode_FromString(decode)); > } > > -static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) > +static void regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) > { > unsigned int i = 0, r; > int printed = 0; > @@ -695,7 +695,7 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) > bf[0] = 0; > > if (!regs || !regs->regs) > - return 0; > + return; > > for_each_set_bit(r, (unsigned long *) &mask, sizeof(mask) * 8) { > u64 val = regs->regs[i++]; > @@ -704,8 +704,6 @@ static int regs_map(struct regs_dump *regs, uint64_t mask, char *bf, int size) > "%5s:0x%" PRIx64 " ", > perf_reg_name(r), val); > } > - > - return printed; > } > > static void set_regs_in_dict(PyObject *dict, > @@ -713,7 +711,16 @@ static void set_regs_in_dict(PyObject *dict, > struct evsel *evsel) > { > struct perf_event_attr *attr = &evsel->core.attr; > - char bf[512]; > + > + /* > + * Here value 28 is a constant size which can be used to print > + * one register value and its corresponds to: > + * 16 chars is to specify 64 bit register in hexadecimal. > + * 2 chars is for appending "0x" to the hexadecimal value and > + * 10 chars is for register name. > + */ > + int size = __sw_hweight64(attr->sample_regs_intr) * 28; > + char bf[size]; > > regs_map(&sample->intr_regs, attr->sample_regs_intr, bf, sizeof(bf)); > > -- Thanks and Regards R.Nageswara Sastry