From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0762EC07E9E for ; Wed, 7 Jul 2021 14:04:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD59761CA8 for ; Wed, 7 Jul 2021 14:04:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232002AbhGGOHf (ORCPT ); Wed, 7 Jul 2021 10:07:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:44036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbhGGOHc (ORCPT ); Wed, 7 Jul 2021 10:07:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C810C61C92; Wed, 7 Jul 2021 14:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625666692; bh=X05+giyFKsVT+sh0hnEHJ5D9wx29IQi/oJ6RZCCiYdc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jw9QDbboQVZmhJTdpYKUBDl5Urg8AOtcJ1QcxY+8FidTj0Qsdc6Ya7EXPDznObwfU jkeLZzQ7OE4HyTFk4vUuIEDUv757Vf7BcEpdhCI3EjpWwzCn0pzJUrLGqrXFDhGjNs OvAOFNolWWTIED7BlLP4MI+QgazZICx1UIirNIRa4P1lKUq+pcEFJxQgX89jqu3ovQ Fd5zgVv6ROfuCjczgWuRMLt5STOmLgPBSeEnZTpT34aFunQlzZd6lCPJT5UA321LxL jJijpFNGL2n4xTOvo/UPFmqQGRPFYOjkGn1lWbzOzPU2FFLzOYkBP9w1fc+FMddedL rJIcTENISNdOg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 1A48F40B1A; Wed, 7 Jul 2021 11:04:49 -0300 (-03) Date: Wed, 7 Jul 2021 11:04:49 -0300 From: Arnaldo Carvalho de Melo To: kajoljain Cc: Jiri Olsa , maddy@linux.vnet.ibm.com, atrajeev@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, ravi.bangoria@linux.ibm.com, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, rnsastry@linux.ibm.com, "Paul A. Clarke" Subject: Re: [PATCH] perf script python: Fix buffer size to report iregs in perf script Message-ID: References: <20210628062341.155839-1-kjain@linux.ibm.com> <20210628144937.GE142768@li-24c3614c-2adc-11b2-a85c-85f334518bdb.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Jul 07, 2021 at 11:16:20AM +0530, kajoljain escreveu: > On 7/7/21 12:45 AM, Arnaldo Carvalho de Melo wrote: > > Em Tue, Jul 06, 2021 at 05:26:12PM +0530, kajoljain escreveu: > >> On 6/29/21 12:39 PM, kajoljain wrote: > >>> On 6/28/21 8:19 PM, Paul A. Clarke wrote: > >>>> On Mon, Jun 28, 2021 at 11:53:41AM +0530, Kajol Jain wrote: > >>>>> @@ -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]; > >>>> I propose using a template rather than a magic number here. Something like: > >>>> const char reg_name_tmpl[] = "10 chars "; > >>>> const char reg_value_tmpl[] = "0x0123456789abcdef"; > >>>> const int size = __sw_hweight64(attr->sample_regs_intr) + > >>>> sizeof reg_name_tmpl + sizeof reg_value_tmpl; > >>> Thanks for reviewing the patch. Yes these are > >>> some standardization we can do by creating macros for different > >>> fields. > >>> The basic idea is, we want to provide significant buffer size > >>> based on number of registers present in sample_regs_intr to accommodate > >>> all data. > >> Is the approach used in this patch looks fine to you? > > Yeah, and the comment you provide right above it explains it, so I think > > that is enough, ok? > Thanks for reviewing it. As you said added comment already explains > why we are taking size constant as 28, should we skip adding macros part? > Can you pull this patch. Sure. - Arnaldo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D421EC07E95 for ; Wed, 7 Jul 2021 14:05:26 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5975E61C92 for ; Wed, 7 Jul 2021 14:05:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5975E61C92 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GKh5c70wgz3035 for ; Thu, 8 Jul 2021 00:05:24 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jw9QDbbo; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=198.145.29.99; helo=mail.kernel.org; envelope-from=acme@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jw9QDbbo; dkim-atps=neutral Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GKh543q8Dz300b for ; Thu, 8 Jul 2021 00:04:56 +1000 (AEST) Received: by mail.kernel.org (Postfix) with ESMTPSA id C810C61C92; Wed, 7 Jul 2021 14:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625666692; bh=X05+giyFKsVT+sh0hnEHJ5D9wx29IQi/oJ6RZCCiYdc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jw9QDbboQVZmhJTdpYKUBDl5Urg8AOtcJ1QcxY+8FidTj0Qsdc6Ya7EXPDznObwfU jkeLZzQ7OE4HyTFk4vUuIEDUv757Vf7BcEpdhCI3EjpWwzCn0pzJUrLGqrXFDhGjNs OvAOFNolWWTIED7BlLP4MI+QgazZICx1UIirNIRa4P1lKUq+pcEFJxQgX89jqu3ovQ Fd5zgVv6ROfuCjczgWuRMLt5STOmLgPBSeEnZTpT34aFunQlzZd6lCPJT5UA321LxL jJijpFNGL2n4xTOvo/UPFmqQGRPFYOjkGn1lWbzOzPU2FFLzOYkBP9w1fc+FMddedL rJIcTENISNdOg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 1A48F40B1A; Wed, 7 Jul 2021 11:04:49 -0300 (-03) Date: Wed, 7 Jul 2021 11:04:49 -0300 From: Arnaldo Carvalho de Melo To: kajoljain Subject: Re: [PATCH] perf script python: Fix buffer size to report iregs in perf script Message-ID: References: <20210628062341.155839-1-kjain@linux.ibm.com> <20210628144937.GE142768@li-24c3614c-2adc-11b2-a85c-85f334518bdb.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ravi.bangoria@linux.ibm.com, atrajeev@linux.vnet.ibm.com, rnsastry@linux.ibm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, maddy@linux.vnet.ibm.com, "Paul A. Clarke" , Jiri Olsa Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Em Wed, Jul 07, 2021 at 11:16:20AM +0530, kajoljain escreveu: > On 7/7/21 12:45 AM, Arnaldo Carvalho de Melo wrote: > > Em Tue, Jul 06, 2021 at 05:26:12PM +0530, kajoljain escreveu: > >> On 6/29/21 12:39 PM, kajoljain wrote: > >>> On 6/28/21 8:19 PM, Paul A. Clarke wrote: > >>>> On Mon, Jun 28, 2021 at 11:53:41AM +0530, Kajol Jain wrote: > >>>>> @@ -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]; > >>>> I propose using a template rather than a magic number here. Something like: > >>>> const char reg_name_tmpl[] = "10 chars "; > >>>> const char reg_value_tmpl[] = "0x0123456789abcdef"; > >>>> const int size = __sw_hweight64(attr->sample_regs_intr) + > >>>> sizeof reg_name_tmpl + sizeof reg_value_tmpl; > >>> Thanks for reviewing the patch. Yes these are > >>> some standardization we can do by creating macros for different > >>> fields. > >>> The basic idea is, we want to provide significant buffer size > >>> based on number of registers present in sample_regs_intr to accommodate > >>> all data. > >> Is the approach used in this patch looks fine to you? > > Yeah, and the comment you provide right above it explains it, so I think > > that is enough, ok? > Thanks for reviewing it. As you said added comment already explains > why we are taking size constant as 28, should we skip adding macros part? > Can you pull this patch. Sure. - Arnaldo