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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 0D6CFC56202 for ; Thu, 26 Nov 2020 14:31:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B20F0204FD for ; Thu, 26 Nov 2020 14:31:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KFy53PN8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391116AbgKZObk (ORCPT ); Thu, 26 Nov 2020 09:31:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391090AbgKZObk (ORCPT ); Thu, 26 Nov 2020 09:31:40 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C4BC0613D4 for ; Thu, 26 Nov 2020 06:31:40 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id w16so1871592pga.9 for ; Thu, 26 Nov 2020 06:31:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+ubtj8jLZa0MRBDrFjBps4/mkC6E9QeHa4hph29+zRI=; b=KFy53PN8f75TZ2JTPs4lQuzQSbU3KeDtrqcv/DjMx4Sm5OH980mFrJ+GlwoNIaqFlW OHX2nbSs8lt/fbbrYXvbcZVA3QV7ffQkfmqwIuoyeVtF9JGN67+0DTycFOsJFbMB/2k/ fsNn5BFOj8uSXIt8mQvT4ntJOq9iRrZdszvC8fSknXjEdRJWJU6FQetE9n+IINWBQTL8 mvFEcsnT8a6xMMt7BmAINf542zAzRvKF9s5E+2TToaEY5thQ6HmPeOmRfDtW+pb8Mw0F vP3LlWlkwseaZ1/zNmd87pHU+qpCgygtyoM3mQSfzfmA+ciffV5d03DQ/lVG5M4jMY8V xsiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+ubtj8jLZa0MRBDrFjBps4/mkC6E9QeHa4hph29+zRI=; b=AR1vs5SJOkxtVcRzuiOfKwL5Xsiw3wkAmy/+Hj8PDDlBkxQ6BWzIOTi0ZchJpdxzfK cfKqtPrswfIzLAxszas8EZQQNez+mcWu0p8JQd2xlR069MZuhqolKR84hchW1TTmSnrL uHXLVspP+m3TxKC5WHNJeppDz9ats/5xFp2khURF1xrpy27H8+qsPeqiQSuq5Yt6PrZ2 pM6fyiOySY7gihdJsGiJiMlrJ35JOdd3u+lkxiZRscDKpAR2a9W0ASGHyp4cHKDkcgUc xuJfPlklvOzWlZP0cAnd1Y8JLOUDFRqilbqLMmaDeIHRUEgHK/KjftAYB64htdzYTLwy JuWg== X-Gm-Message-State: AOAM530dcNX0sXeAxFx1azq1qf5bOyUlVcBlji0Sl497ya4OHQ+MHJaM P++0S6p0a+zDuyIWSUP/6y4zmw== X-Google-Smtp-Source: ABdhPJwaq9okUUCJ7FAFdsCBquKjMAadglZa3TEo1eC7grrkTiSW1FMGteOtVNLkqjjyuFAmY/rDZw== X-Received: by 2002:a63:4925:: with SMTP id w37mr2867451pga.64.1606401099707; Thu, 26 Nov 2020 06:31:39 -0800 (PST) Received: from leoy-ThinkPad-X240s ([103.127.239.100]) by smtp.gmail.com with ESMTPSA id x8sm6630415pjr.52.2020.11.26.06.31.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Nov 2020 06:31:39 -0800 (PST) Date: Thu, 26 Nov 2020 22:31:33 +0800 From: Leo Yan To: Arnaldo Carvalho de Melo Cc: Andre Przywara , Dave Martin , James Clark , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Al Grant , Wei Li , John Garry , Will Deacon , Mathieu Poirier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v9 01/16] perf arm-spe: Refactor printing string to buffer Message-ID: <20201126143133.GB27722@leoy-ThinkPad-X240s> References: <20201119152441.6972-1-leo.yan@linaro.org> <20201119152441.6972-2-leo.yan@linaro.org> <20201126121158.GB53384@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201126121158.GB53384@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 26, 2020 at 09:11:58AM -0300, Arnaldo Carvalho de Melo wrote: > Em Thu, Nov 19, 2020 at 11:24:26PM +0800, Leo Yan escreveu: > > When outputs strings to the decoding buffer with function snprintf(), > > SPE decoder needs to detects if any error returns from snprintf() and if > > so needs to directly bail out. If snprintf() returns success, it needs > > to update buffer pointer and reduce the buffer length so can continue to > > output the next string into the consequent memory space. > > > > This complex logics are spreading in the function arm_spe_pkt_desc() so > > there has many duplicate codes for handling error detecting, increment > > buffer pointer and decrement buffer size. > > > > To avoid the duplicate code, this patch introduces a new helper function > > arm_spe_pkt_out_string() which is used to wrap up the complex logics, > > and it's used by the caller arm_spe_pkt_desc(). This patch moves the > > variable 'blen' as the function's local variable so allows to remove > > the unnecessary braces and improve the readability. > > > > This patch simplifies the return value for arm_spe_pkt_desc(): '0' means > > success and other values mean an error has occurred. To realize this, > > it relies on arm_spe_pkt_out_string()'s parameter 'err', the 'err' is a > > cumulative value, returns its final value if printing buffer is called > > for one time or multiple times. Finally, the error is handled in a > > central place, rather than directly bailing out in switch-cases, it > > returns error at the end of arm_spe_pkt_desc(). > > > > This patch changes the caller arm_spe_dump() to respect the updated > > return value semantics of arm_spe_pkt_desc(). > > > > Suggested-by: Dave Martin > > Signed-off-by: Leo Yan > > Reviewed-by: Andre Przywara > > Reviewed-by: Dave Martin > > --- > > .../arm-spe-decoder/arm-spe-pkt-decoder.c | 302 +++++++++--------- > > tools/perf/util/arm-spe.c | 2 +- > > 2 files changed, 151 insertions(+), 153 deletions(-) > > > > diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c > > index 671a4763fb47..fbededc1bcd4 100644 > > --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c > > +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c > > @@ -9,6 +9,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "arm-spe-pkt-decoder.h" > > > > @@ -258,192 +259,189 @@ int arm_spe_get_packet(const unsigned char *buf, size_t len, > > return ret; > > } > > > > +static int arm_spe_pkt_out_string(int *err, char **buf_p, size_t *blen, > > + const char *fmt, ...) > > +{ > > + va_list ap; > > + int ret; > > > Ok, from a quick look this continues confusing, but at least its not > named scnprintf() and then people won't expect the usual semantics. Shame for the confusion :( > Applying. Thanks, 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=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 588BCC56202 for ; Thu, 26 Nov 2020 14:33:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 BFD22221FE for ; Thu, 26 Nov 2020 14:33:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="c9zcGRIf"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="KFy53PN8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BFD22221FE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IWPgx0JtDGV8z39izP+P52zEu/FajtHE47I7oLhmwW8=; b=c9zcGRIflNTC6RtAk3IEc0gXs xC3ePFYBTvjY8VEv4XycnqDPXZUcj5QXNcd9eolnWsWozj8UP3OdGpvCzHJOCplZeOk4fQeA5Yd7p ihS7bFkSnYxFC+gdk8hA5o0RULHfumWhVQF0SswfXkLfW+0oiKAcrni0faS7ZWNfpr4wUQoDLRp1U vyF8RQNKJGlyrI4OIC/kmfacIo+2Sh2JhZYJax3X/ufFefF55P4lSdKjqZ6aO2Sv+rPoqNnL37IdB Oi9nGnx2oZ7P7hQHS6zuKEruMmwhHql9QtVQAIE7iG3M5XG7NiEiFnng7zm7qU3JTM1F43wsmPb9i n/cJD4ERg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiIJG-0003oH-22; Thu, 26 Nov 2020 14:31:46 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiIJC-0003ms-Qc for linux-arm-kernel@lists.infradead.org; Thu, 26 Nov 2020 14:31:44 +0000 Received: by mail-pg1-x542.google.com with SMTP id t3so1867889pgi.11 for ; Thu, 26 Nov 2020 06:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+ubtj8jLZa0MRBDrFjBps4/mkC6E9QeHa4hph29+zRI=; b=KFy53PN8f75TZ2JTPs4lQuzQSbU3KeDtrqcv/DjMx4Sm5OH980mFrJ+GlwoNIaqFlW OHX2nbSs8lt/fbbrYXvbcZVA3QV7ffQkfmqwIuoyeVtF9JGN67+0DTycFOsJFbMB/2k/ fsNn5BFOj8uSXIt8mQvT4ntJOq9iRrZdszvC8fSknXjEdRJWJU6FQetE9n+IINWBQTL8 mvFEcsnT8a6xMMt7BmAINf542zAzRvKF9s5E+2TToaEY5thQ6HmPeOmRfDtW+pb8Mw0F vP3LlWlkwseaZ1/zNmd87pHU+qpCgygtyoM3mQSfzfmA+ciffV5d03DQ/lVG5M4jMY8V xsiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+ubtj8jLZa0MRBDrFjBps4/mkC6E9QeHa4hph29+zRI=; b=nv1DfKRAqwSsjqGROyUo+OdarqFDjPXoSR382HLVazVhetBQmaQtKp10D87utnUlTx PEcEA3I3/EA+CFpmN5dt8Sv3DpFyu7NFBEfWDmWSD/olA6mGmneEoBOyw/kgmt3Gj7+q d8oYIu5Kxn2tiXj/Bi54uCmSZy1kvkkO9/QhcxMOcD2qeiT51druHFCB9An+IK0wlbTK /6jaVMtKTs5ZTqyzGwrzxD5qg0Hm2jAGpzoCjxa1bnGJQgr/5q6Q86pI+jSefxsMtpNC VumQWidvbmn+ieehPU+AYAteL3wcz3pRX6yv4kwKy+Wm2pDc25yPIZRquyfNK39degev ztTA== X-Gm-Message-State: AOAM5334QkYdqU2bpQxDjJWKHaRxLGKxXTE4fUsymoy28qnZjRk9Ccna 8EaJKQ6um8kqJ4vzuF3//U4vkJfDkV2cywrsd78= X-Google-Smtp-Source: ABdhPJwaq9okUUCJ7FAFdsCBquKjMAadglZa3TEo1eC7grrkTiSW1FMGteOtVNLkqjjyuFAmY/rDZw== X-Received: by 2002:a63:4925:: with SMTP id w37mr2867451pga.64.1606401099707; Thu, 26 Nov 2020 06:31:39 -0800 (PST) Received: from leoy-ThinkPad-X240s ([103.127.239.100]) by smtp.gmail.com with ESMTPSA id x8sm6630415pjr.52.2020.11.26.06.31.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Nov 2020 06:31:39 -0800 (PST) Date: Thu, 26 Nov 2020 22:31:33 +0800 From: Leo Yan To: Arnaldo Carvalho de Melo Subject: Re: [PATCH v9 01/16] perf arm-spe: Refactor printing string to buffer Message-ID: <20201126143133.GB27722@leoy-ThinkPad-X240s> References: <20201119152441.6972-1-leo.yan@linaro.org> <20201119152441.6972-2-leo.yan@linaro.org> <20201126121158.GB53384@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201126121158.GB53384@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201126_093142_910578_39D1DDAD X-CRM114-Status: GOOD ( 33.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Al Grant , Mathieu Poirier , Will Deacon , Peter Zijlstra , Andre Przywara , John Garry , linux-kernel@vger.kernel.org, Alexander Shishkin , Ingo Molnar , James Clark , Namhyung Kim , Jiri Olsa , Dave Martin , linux-arm-kernel@lists.infradead.org, Wei Li Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 26, 2020 at 09:11:58AM -0300, Arnaldo Carvalho de Melo wrote: > Em Thu, Nov 19, 2020 at 11:24:26PM +0800, Leo Yan escreveu: > > When outputs strings to the decoding buffer with function snprintf(), > > SPE decoder needs to detects if any error returns from snprintf() and if > > so needs to directly bail out. If snprintf() returns success, it needs > > to update buffer pointer and reduce the buffer length so can continue to > > output the next string into the consequent memory space. > > > > This complex logics are spreading in the function arm_spe_pkt_desc() so > > there has many duplicate codes for handling error detecting, increment > > buffer pointer and decrement buffer size. > > > > To avoid the duplicate code, this patch introduces a new helper function > > arm_spe_pkt_out_string() which is used to wrap up the complex logics, > > and it's used by the caller arm_spe_pkt_desc(). This patch moves the > > variable 'blen' as the function's local variable so allows to remove > > the unnecessary braces and improve the readability. > > > > This patch simplifies the return value for arm_spe_pkt_desc(): '0' means > > success and other values mean an error has occurred. To realize this, > > it relies on arm_spe_pkt_out_string()'s parameter 'err', the 'err' is a > > cumulative value, returns its final value if printing buffer is called > > for one time or multiple times. Finally, the error is handled in a > > central place, rather than directly bailing out in switch-cases, it > > returns error at the end of arm_spe_pkt_desc(). > > > > This patch changes the caller arm_spe_dump() to respect the updated > > return value semantics of arm_spe_pkt_desc(). > > > > Suggested-by: Dave Martin > > Signed-off-by: Leo Yan > > Reviewed-by: Andre Przywara > > Reviewed-by: Dave Martin > > --- > > .../arm-spe-decoder/arm-spe-pkt-decoder.c | 302 +++++++++--------- > > tools/perf/util/arm-spe.c | 2 +- > > 2 files changed, 151 insertions(+), 153 deletions(-) > > > > diff --git a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c > > index 671a4763fb47..fbededc1bcd4 100644 > > --- a/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c > > +++ b/tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c > > @@ -9,6 +9,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "arm-spe-pkt-decoder.h" > > > > @@ -258,192 +259,189 @@ int arm_spe_get_packet(const unsigned char *buf, size_t len, > > return ret; > > } > > > > +static int arm_spe_pkt_out_string(int *err, char **buf_p, size_t *blen, > > + const char *fmt, ...) > > +{ > > + va_list ap; > > + int ret; > > > Ok, from a quick look this continues confusing, but at least its not > named scnprintf() and then people won't expect the usual semantics. Shame for the confusion :( > Applying. Thanks, Arnaldo. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel