From patchwork Tue Feb 12 17:16:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 158167 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4089105jaa; Tue, 12 Feb 2019 09:16:45 -0800 (PST) X-Google-Smtp-Source: AHgI3IZCvAscDmo0gg4H3H4bZYLAGDPPVjAEl0EAY5wk7r/kxoTzM/ihTcBrx/HHgqXQNgB7+cal X-Received: by 2002:a63:2882:: with SMTP id o124mr4578667pgo.446.1549991805113; Tue, 12 Feb 2019 09:16:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549991805; cv=none; d=google.com; s=arc-20160816; b=017u/AuYhB8aY9QDMirlvE9ah5LNqGkRpsjF5wzIJLzvDY3s4xnNCrzUMJ7j34W2gv +0+4YhnB2nvbRAGCwKGX9ELxQnCNE2d1baSiq+TOfpP3ZgkURzeNBqQV7hScIyIdSYNX +FEFWPw1HdjJ0hwGjBoOGfCUKg8UkM7LdRPcZ+FzcRR4TreS74WpAGshDaawZjf4FSjk vHN0f7HgZ1fbr/4OOFdATWshhAyqPOFJrIKcV3VBxdFYcraPu9jVj+nJBenC5i3duteE 6DjJitLb3eZKRP6JotY/bqopQ/W4aKa4qRrbdLh81kOkAXQqphysqw0DtyLU1YtwTFr8 k8EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=fPu8+x56+bPaqE+Kt7QPAly49dZ2m5zcnSswTAaxNxU=; b=ly6+zd3Y1136w+Zqh5MYjN2ayWMn8mvhd5F+9Hb9LFyyoWwI0g4HcVgvi9tOMFdakU kjGNiVmFGEPMAf2gZwSbtPxRQirSib8mZtHgzn0ke09f6vYt4TSaNdd4SDOtqe+bgYjt 7W5R0fhVIIvRgiespiMkhn5vYNG3/3m8f30Sz7GslXLH2eg+NyNBglak/004rb/hPr5t 7znXlYJzpkESPkva93s7fjfWzKJZVRdu/OUtPUAhIv+2zzmRnHJEuvc8W4AUoqBboY3u VR6+h6wgvstIEBj4ChqnV9Yx+pohBidfYK76e1Y+QCSRdbtZlqzWLfRmjfeXjTimIQFH JGXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wmd0f4y5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y129si5007421pgy.175.2019.02.12.09.16.44; Tue, 12 Feb 2019 09:16:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wmd0f4y5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731827AbfBLRQg (ORCPT + 31 others); Tue, 12 Feb 2019 12:16:36 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43210 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731813AbfBLRQe (ORCPT ); Tue, 12 Feb 2019 12:16:34 -0500 Received: by mail-pl1-f196.google.com with SMTP id f90so1596881plb.10 for ; Tue, 12 Feb 2019 09:16:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fPu8+x56+bPaqE+Kt7QPAly49dZ2m5zcnSswTAaxNxU=; b=Wmd0f4y5WvxofS4IIk+dxekor1GLWA5HfI5d997lyaW20uM6gGnPRhTpEjUcN2xYhr XfdDxPEaxyvelxa9DuAKy+wIo/vZZXq5kpL1aYRyrWfV2R2NLEnU3R0f8BYjGKjBalFu U5tjNeJbUVnHwuZ1O1gYT6Bam1FmRP7Njaye9A9CZ/Rjqv4k1fuxD4afpTgcz4afOgIp 1VV9aLv2+tEQQS8my2EHZp70eY4gYPJ1GF55AQUfHhVMlknG0upE1pWRsv0dR5dvfsun 0NEmlUObt9WSKKmJRsZdNnT0y0Xqp+Cr/DgtU8QISnCP01VYvzOs5iBYceEop0GQfqIh WTNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fPu8+x56+bPaqE+Kt7QPAly49dZ2m5zcnSswTAaxNxU=; b=hp4BTPfDfq37IQlxmou/GOpaUSrjrjLfr7ZRpj3+NAj05WB7YfPDxZBwmfCBbc1g5Q 6znbl2hMfPGt7GBIV9pc7fM+NtkPBZWGgEQJDS0ZSvCBY0MzIRZOHi7LPvyKJSAqqaAk SnfWVM8qV3Fz+tnAwUu3n+dLFeOhBRug/l9r7umeC6Hx38h/iO53q/aJE2aEQKUsFXxj oM9qLlMqDURIc7AQKvmYwwnn3SFC6SejfRlyrXfQxIztsfvlNgA0Dtt53sAiT5nACuvb ZV5Rd2zGJ9D4FinPPA53cz1aGA1qCWITP536Ph3sijzhewcfQ6CJlSCsZGq4qiYnQxwg kg+w== X-Gm-Message-State: AHQUAubpouddESiJJYfhpaBC96pDCG+81K0KxL5ie7FUGYUps4Vkn0eh lPHpLjvshqT56Z9paolozyuDxA== X-Received: by 2002:a17:902:b581:: with SMTP id a1mr4999975pls.36.1549991794044; Tue, 12 Feb 2019 09:16:34 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id z4sm8659231pgu.10.2019.02.12.09.16.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 09:16:33 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org Cc: suzuki.poulose@arm.com, mingo@redhat.com, peterz@infradead.org, jolsa@redhat.com, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 12/13] perf tools: Modularize main packet processing loop Date: Tue, 12 Feb 2019 10:16:17 -0700 Message-Id: <20190212171618.25355-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212171618.25355-1-mathieu.poirier@linaro.org> References: <20190212171618.25355-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Making the main packet processing loop modular so that it can be called from different decoding context (timeless vs. non-timless), avoiding to repeat code. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 129 ++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 57 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index cfa686fe223e..f607bc58bd03 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1519,6 +1519,72 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq) return ret; } +static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) +{ + int ret; + + /* Process each packet in this chunk */ + while (1) { + ret = cs_etm_decoder__get_packet(etmq->decoder, + etmq->packet); + if (ret <= 0) + /* + * Stop processing this chunk on + * end of data or error + */ + break; + + /* + * Since packet addresses are swapped in packet + * handling within below switch() statements, + * thus setting sample flags must be called + * prior to switch() statement to use address + * information before packets swapping. + */ + ret = cs_etm__set_sample_flags(etmq); + if (ret < 0) + break; + + switch (etmq->packet->sample_type) { + case CS_ETM_RANGE: + /* + * If the packet contains an instruction + * range, generate instruction sequence + * events. + */ + cs_etm__sample(etmq); + break; + case CS_ETM_EXCEPTION: + case CS_ETM_EXCEPTION_RET: + /* + * If the exception packet is coming, + * make sure the previous instruction + * range packet to be handled properly. + */ + cs_etm__exception(etmq); + break; + case CS_ETM_DISCONTINUITY: + /* + * Discontinuity in trace, flush + * previous branch stack + */ + cs_etm__flush(etmq); + break; + case CS_ETM_EMPTY: + /* + * Should not receive empty packet, + * report error. + */ + pr_err("CS ETM Trace: empty packet\n"); + return -EINVAL; + default: + break; + } + } + + return ret; +} + static int cs_etm__run_decoder(struct cs_etm_queue *etmq) { int err = 0; @@ -1544,64 +1610,13 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) if (err) return err; - /* Process each packet in this chunk */ - while (1) { - err = cs_etm_decoder__get_packet(etmq->decoder, - etmq->packet); - if (err <= 0) - /* - * Stop processing this chunk on - * end of data or error - */ - break; + /* + * Process each packet in this chunk, nothing to do if + * an error occurs other than hoping the next one will + * be better. + */ + err = cs_etm__process_decoder_queue(etmq); - /* - * Since packet addresses are swapped in packet - * handling within below switch() statements, - * thus setting sample flags must be called - * prior to switch() statement to use address - * information before packets swapping. - */ - err = cs_etm__set_sample_flags(etmq); - if (err < 0) - break; - - switch (etmq->packet->sample_type) { - case CS_ETM_RANGE: - /* - * If the packet contains an instruction - * range, generate instruction sequence - * events. - */ - cs_etm__sample(etmq); - break; - case CS_ETM_EXCEPTION: - case CS_ETM_EXCEPTION_RET: - /* - * If the exception packet is coming, - * make sure the previous instruction - * range packet to be handled properly. - */ - cs_etm__exception(etmq); - break; - case CS_ETM_DISCONTINUITY: - /* - * Discontinuity in trace, flush - * previous branch stack - */ - cs_etm__flush(etmq); - break; - case CS_ETM_EMPTY: - /* - * Should not receive empty packet, - * report error. - */ - pr_err("CS ETM Trace: empty packet\n"); - return -EINVAL; - default: - break; - } - } } while (etmq->buf_len); if (err == 0)