From patchwork Mon Dec 12 15:55:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2325404wrr; Mon, 12 Dec 2022 08:05:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7+bRkDHmjX1xzda0Wa5zl7e29ovX3TcVKBDCffsc71Bbw7NrlSu4IZN1DJYfDtXwgSW6Kk X-Received: by 2002:a17:906:abcd:b0:7ad:2da5:36ec with SMTP id kq13-20020a170906abcd00b007ad2da536ecmr15151193ejb.41.1670861156063; Mon, 12 Dec 2022 08:05:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670861156; cv=none; d=google.com; s=arc-20160816; b=vFKqHP53Uzx6YnaCBFIW621BdfF5RssvF8ylRQekoh+QTJ5TXATEH04gTtU3t2YPjH SqGo4Uvj4TaBEnNmgZJ2YHfxHReR10T7+9dP5f0HnIWX23Q4uGK7HMMDBkRFbh83dUDY TF57pk2ByfqvRP8i9AgsysI0+mmiT4su2eiCXeXwjqStTw+2KUUmqHy+oMOpUoms92UG dj8fgELp9ELgOxIpUkggPVNOYdfXqY+T9Tkx5pQUsQ9e5MeipLjoEeo4Go0IxWWAGNZd gZHY4ovvv+LhXShPpXa8tw4YYVrVZa/VqZ5+4ETTgl9huR2YzctkzKrudunivBaCmsb5 hcTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e9zzCYLtBXw13x2mcYukb9TWHJyvI1Bb5Iv+FhBP1yA=; b=mdUF4NOscohvCGMFV/PWusMY1R2kWD/ZIDlpoV95x65Khxu7bLxlLEg/vOnCGrqjAa YuUh3P7fFWD1E9Sb1hW/CqDNwkmgTqvJC6HAAJlyzpwvz0LTLt1e17clCEHHAV0tcWab +mVwoIRVEic835FIA8zSsPsuJHGdSJX6JTyUQF9wvbzSJMZa1pnjeRkmCk+ulZ3NM+dh KwGXTDnlxPvQvFbmNRSRTMo7QDlOSc/okMZjhVOR4jmXAqnJnLiccppwc2BT1KmfVqie Y1iRkijI63S0GMEuybJaBkRx7HR54yKq3hsadiKRaZe/tB0BxFn7p7JVPLyV2Ia3sUIj nQtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qc6-20020a170906d8a600b007ae5b41855fsi5174185ejb.895.2022.12.12.08.05.31; Mon, 12 Dec 2022 08:05:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232624AbiLLPzp (ORCPT + 99 others); Mon, 12 Dec 2022 10:55:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbiLLPzn (ORCPT ); Mon, 12 Dec 2022 10:55:43 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CC5064FA; Mon, 12 Dec 2022 07:55:43 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D77B2F4; Mon, 12 Dec 2022 07:56:23 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4BBAA3F71E; Mon, 12 Dec 2022 07:55:40 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 1/5] perf: cs-etm: Print unknown header version as an error Date: Mon, 12 Dec 2022 15:55:09 +0000 Message-Id: <20221212155513.2259623-2-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752024907674024472?= X-GMAIL-MSGID: =?utf-8?q?1752024907674024472?= This is an error rather than just for the raw trace dump so always print it as an error. Also remove the duplicate header version check. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 16db965ac995..aeb1e30888db 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2623,14 +2623,7 @@ static void cs_etm__print_auxtrace_info(__u64 *val, int num) { int i, cpu = 0, version, err; - /* bail out early on bad header version */ version = val[0]; - if (version > CS_HEADER_CURRENT_VERSION) { - /* failure.. return */ - fprintf(stdout, " Unknown Header Version = %x, ", version); - fprintf(stdout, "Version supported <= %x\n", CS_HEADER_CURRENT_VERSION); - return; - } for (i = 0; i < CS_HEADER_VERSION_MAX; i++) fprintf(stdout, cs_etm_global_header_fmts[i], val[i]); @@ -2916,9 +2909,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, /* Look for version of the header */ hdr_version = ptr[0]; if (hdr_version > CS_HEADER_CURRENT_VERSION) { - /* print routine will print an error on bad version */ - if (dump_trace) - cs_etm__print_auxtrace_info(auxtrace_info->priv, 0); + pr_err("\nCS ETM Trace: Unknown Header Version = %#" PRIx64, hdr_version); + pr_err(", version supported <= %x\n", CS_HEADER_CURRENT_VERSION); return -EINVAL; } From patchwork Mon Dec 12 15:55:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2325762wrr; Mon, 12 Dec 2022 08:06:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5jngWpg/V8du41iG6qwVeXlY7zB6T7b2s1MEHBQVJwylPOkhNziNe712c22tSOovh7p1dy X-Received: by 2002:a17:906:895:b0:7bd:27af:396e with SMTP id n21-20020a170906089500b007bd27af396emr12784678eje.45.1670861191244; Mon, 12 Dec 2022 08:06:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670861191; cv=none; d=google.com; s=arc-20160816; b=Vw9oMGGigDa8sPS6wgjJSpZ7+6ROBAJpiSlIRi473irAEEXLRxhQcYf2YyFtLWXAfW kfhbvRVm7D2QJlxTp+f9UqMJQmbgUjFxiDJd1fOqEvRbiH97XIpdnNvKhLDOUolNOlOy viG9amMVtkoz6y04FFwV3S+YZp4gZAxJ7n14oRUDR2uAA4ph43oAR3qfJ+I94aKs76R+ hCTQ2rimjB5O6DrJyv6oU8vqbxitJmWorNvC75asRq06VyaQ+Kew7r5DQP4+AxI3ZjDL gp/alYcweGpCDVPUNkoEuk6RvAgjuQbuAkRrt3PBTVYS5r5bt9aOnnlMVs1WawxGVWpH K4sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7j51waBXT/TsfiBWTW7La16md0bd0IliUIeho55WwM0=; b=r7pJ/2kxKdo5Aa8S2Q4oycFoIQ2c5jlWmh06dVnQY8/qezZ3iL0Se4izkw2Nhp5KCS Kkj5+UkjRWiBRE3lZk5QuW2X1sXGpmHA+76TzsEAAc9bNCb1W11u/Kck0iPJdsic2zCo 0OuWY8veOAb5Q6GG7n2phDZzDjBzAWDgcmGbjClApCpM5l7NuOjUu3BmpAsr6pti0zJ6 q/d+bG1N3FSMcw5Lkjsg3dQY8eKis3HKU83ktbp3fxjMClZz9DSsHlH4WlrAMtZpecNK Rd3auSRNKWzT6+AtoIuW/SpR4Vtqgol3FudbdYb2Pwu+eFyt5zfWLo7F4vm1PIw7qrLS bAhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw19-20020a170907a0d300b0078d288ddfc9si5070918ejc.143.2022.12.12.08.06.07; Mon, 12 Dec 2022 08:06:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232560AbiLLPzv (ORCPT + 99 others); Mon, 12 Dec 2022 10:55:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232628AbiLLPzr (ORCPT ); Mon, 12 Dec 2022 10:55:47 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7476364FA; Mon, 12 Dec 2022 07:55:46 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B75FF15BF; Mon, 12 Dec 2022 07:56:26 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B20343F71E; Mon, 12 Dec 2022 07:55:43 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 2/5] perf: cs-etm: Remove unused stub methods Date: Mon, 12 Dec 2022 15:55:10 +0000 Message-Id: <20221212155513.2259623-3-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752024944462025713?= X-GMAIL-MSGID: =?utf-8?q?1752024944462025713?= These aren't used outside of cs-etm so don't need stubs. Leave cs_etm__process_auxtrace_info() which is used externally, and add an error message so that it's obvious to users why it causes errors. Signed-off-by: James Clark --- tools/perf/util/cs-etm.h | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 90c83f932d9a..401f74be98d6 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -7,6 +7,7 @@ #ifndef INCLUDE__UTIL_PERF_CS_ETM_H__ #define INCLUDE__UTIL_PERF_CS_ETM_H__ +#include "debug.h" #include "util/event.h" #include @@ -218,40 +219,9 @@ static inline int cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, struct perf_session *session __maybe_unused) { + pr_err("\nCS ETM Trace: OpenCSD is not linked in, please recompile with CORESIGHT=1\n"); return -1; } - -static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, - int *cpu __maybe_unused) -{ - return -1; -} - -static inline int cs_etm__etmq_set_tid( - struct cs_etm_queue *etmq __maybe_unused, - pid_t tid __maybe_unused, - u8 trace_chan_id __maybe_unused) -{ - return -1; -} - -static inline bool cs_etm__etmq_is_timeless( - struct cs_etm_queue *etmq __maybe_unused) -{ - /* What else to return? */ - return true; -} - -static inline void cs_etm__etmq_set_traceid_queue_timestamp( - struct cs_etm_queue *etmq __maybe_unused, - u8 trace_chan_id __maybe_unused) {} - -static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue( - struct cs_etm_queue *etmq __maybe_unused, - u8 trace_chan_id __maybe_unused) -{ - return NULL; -} #endif #endif From patchwork Mon Dec 12 15:55:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2327978wrr; Mon, 12 Dec 2022 08:10:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf6itcLXZNaFTyPXmUMMoMtNBDhwuRnm4jGXJ8MhTJQLwVC5ahelMFUvmed5iCswGGh3jzAn X-Received: by 2002:a17:906:895:b0:7bd:27af:396e with SMTP id n21-20020a170906089500b007bd27af396emr12797423eje.45.1670861401900; Mon, 12 Dec 2022 08:10:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670861401; cv=none; d=google.com; s=arc-20160816; b=LMxu95AiGeZlB8NhvHv56WT+U19nQ2Sn4NMZ7e+oOwlhSpS40WXgo0ddkLRHuDrOdN UspOdBLohAZKikrqjPtmEP9kMAP0Vro7RknpNSd6Wujr70rvzq0U1fvRkG/D0TcZgOuA V2FR5LqRalGYBNgkyRLhxOlQMx/b2HkmnDdhZz/Ya+xJFGFmdofj1vgcALLrcEZS9RMf ql3JpfDTazn57B/dEQ+r+uJHgxWWdVNvEcXpc6KkrFP82xmJKlx0UfSXCGHZzLvbrf9E fA8Jb89hrZ89dQ/4cZRHRWi9EvUb08JgvmmKzF6ztst/vr5FXCW4ApfASSoPe2gP6WXX nORA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JVkNQ3YX12uA2WHsAHQ9hs2h3AN+JpkxIQbpDDB77y0=; b=ldygRJSoCurweYlJdI46DpuK1va2bO6QHdjZ4sEBvX7ktq6uh/Y4IJWXUlnbx+Ogm8 Bs3vg9e+lbWMAJEqVYGH7zC486af21pVTSH9vFiTbOq34rX0DqsY63WaCW2j1JyP0tVq DcW5CRIenTdm2Zc0rzjMBW1yHywVA7SAyzIRc7XVzj5SZV7q0rk25O4xyVATEJHmgaq/ O2dCZiHQYdaHlWUY/cbBXh3vE6CxzQRcdEnc/NdzuMhTFKOOy5B+osEQaz71i/3Sj2co 5bfKnMkXkXXN+v63yuB0/GSNQuvV1LSikb3PdkLXLNL9QUylz8+a46FSA8vDRys5YLd7 bE5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht18-20020a170907609200b007bdd38a5d5asi6014182ejc.636.2022.12.12.08.09.38; Mon, 12 Dec 2022 08:10:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232677AbiLLPz7 (ORCPT + 99 others); Mon, 12 Dec 2022 10:55:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbiLLPzv (ORCPT ); Mon, 12 Dec 2022 10:55:51 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0006465B5; Mon, 12 Dec 2022 07:55:49 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D5CE15DB; Mon, 12 Dec 2022 07:56:30 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2BCE03F71E; Mon, 12 Dec 2022 07:55:47 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 3/5] perf: cs-etm: Tidy up auxtrace info header printing Date: Mon, 12 Dec 2022 15:55:11 +0000 Message-Id: <20221212155513.2259623-4-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752025165520114430?= X-GMAIL-MSGID: =?utf-8?q?1752025165520114430?= cs_etm__print_auxtrace_info() is called twice in case there is an error somewhere in cs_etm__process_auxtrace_info(), but all the info is already available at the beginning so just print it there instead. Also use u64 and the already cast ptr variable to make it more consistent with the rest of the etm code. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index aeb1e30888db..bf8fbcec2d69 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2541,14 +2541,14 @@ static const char * const cs_etmv4_priv_fmts[] = { }; static const char * const param_unk_fmt = - " Unknown parameter [%d] %llx\n"; + " Unknown parameter [%d] %"PRIx64"\n"; static const char * const magic_unk_fmt = - " Magic number Unknown %llx\n"; + " Magic number Unknown %"PRIx64"\n"; -static int cs_etm__print_cpu_metadata_v0(__u64 *val, int *offset) +static int cs_etm__print_cpu_metadata_v0(u64 *val, int *offset) { int i = *offset, j, nr_params = 0, fmt_offset; - __u64 magic; + u64 magic; /* check magic value */ magic = val[i + CS_ETM_MAGIC]; @@ -2580,10 +2580,10 @@ static int cs_etm__print_cpu_metadata_v0(__u64 *val, int *offset) return 0; } -static int cs_etm__print_cpu_metadata_v1(__u64 *val, int *offset) +static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset) { int i = *offset, j, total_params = 0; - __u64 magic; + u64 magic; magic = val[i + CS_ETM_MAGIC]; /* total params to print is NR_PARAMS + common block size for v1 */ @@ -2619,7 +2619,7 @@ static int cs_etm__print_cpu_metadata_v1(__u64 *val, int *offset) return 0; } -static void cs_etm__print_auxtrace_info(__u64 *val, int num) +static void cs_etm__print_auxtrace_info(u64 *val, int num) { int i, cpu = 0, version, err; @@ -2925,6 +2925,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, pmu_type = (unsigned int) ((hdr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); + if (dump_trace) + cs_etm__print_auxtrace_info(ptr, num_cpu); + /* * Create an RB tree for traceID-metadata tuple. Since the conversion * has to be made for each packet that gets decoded, optimizing access @@ -3074,10 +3077,6 @@ int cs_etm__process_auxtrace_info(union perf_event *event, goto err_delete_thread; } - if (dump_trace) { - cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu); - } - err = cs_etm__synth_events(etm, session); if (err) goto err_delete_thread; @@ -3113,12 +3112,5 @@ int cs_etm__process_auxtrace_info(union perf_event *event, intlist__delete(traceid_list); err_free_hdr: zfree(&hdr); - /* - * At this point, as a minimum we have valid header. Dump the rest of - * the info section - the print routines will error out on structural - * issues. - */ - if (dump_trace) - cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu); return err; } From patchwork Mon Dec 12 15:55:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2327129wrr; Mon, 12 Dec 2022 08:08:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/lIUOqrCVVS4MBTvRwjiTlFOVC38YD1dCarbnXg4yRh636AiZegQ1olZY//tG4OMuhoiM X-Received: by 2002:a05:6402:1ccc:b0:461:8be6:1ac4 with SMTP id ds12-20020a0564021ccc00b004618be61ac4mr15560188edb.20.1670861320192; Mon, 12 Dec 2022 08:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670861320; cv=none; d=google.com; s=arc-20160816; b=H4AYU8zkyQflncYx2TRdDo2aO+mUvNeh2IIHuEPZCgwCoWyAXwOvOqd+NwoIN/7oIn jVF6B4x/aCpjhRMJ5Ny2WDlMmjHJi8SYy4WBfdO9GnZkDxMtR7vGO042PFpEr9BQI4EQ HTUOsltzsmt2++9jX8jz6MI5EDhorBvxs3RPok/rf3cGHQnWEbcvZz2NIH8YedBjqJAK mlCxCQLZOB6Kg95+07sVtoU5KrH6x2AqFAMgCwO48Ws3Mbv5yWv1X2cU0+wJH/YXHeBT R4Y1CGDwAIWiIzEKAWNlLwJoXAL6IBCF6R4Y9vFFr6qzdCCjjTbLZtbWuvaEukrJwKpf vk+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oBdGslY/MXeWJolkGr+JMvEApF++GsEr9E3pzoC6JdY=; b=mSmZtjFeypTRKEpoAliMcoZoTQ8ucJESB7gD08kmOrdC6bjdGps5Da16nfdPbmuV/K OxpBqnhri62LDVe4Nww0SMmu+WWAvGluXxXLEytYZeIwtYRWSd7lN4ZZpYqvIw1xLKeP bxKTFmRozj43crlRqz93m0+08ju8r/c0A/ut1Q1SS1q6drfMjxCaPUvouRn2lgdPHW/F JNRzrNoIjYu4x2gra387aLyKzMM5UTwF5s9A8Ht3NF7Xzppqn+z+IqFHLKBEXG2cNXk3 B4vMeP9yyVZaeY7ZbXmWA0NuZZ0icZ4/DqRRNbUjswhXrNSYisnth60/nWHmSXI5v5Va P7ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i28-20020a0564020f1c00b0046b1abd7884si7331243eda.108.2022.12.12.08.08.11; Mon, 12 Dec 2022 08:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbiLLP4D (ORCPT + 99 others); Mon, 12 Dec 2022 10:56:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232636AbiLLPz5 (ORCPT ); Mon, 12 Dec 2022 10:55:57 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52ED812AE6; Mon, 12 Dec 2022 07:55:53 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 963411FB; Mon, 12 Dec 2022 07:56:33 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 949133F71E; Mon, 12 Dec 2022 07:55:50 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 4/5] perf: cs-etm: Cleanup cs_etm__process_auxtrace_info() Date: Mon, 12 Dec 2022 15:55:12 +0000 Message-Id: <20221212155513.2259623-5-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752025079246987897?= X-GMAIL-MSGID: =?utf-8?q?1752025079246987897?= hdr is a copy of 3 values of ptr and doesn't need to be long lived. So just use ptr instead which means the malloc and the extra error path can be removed to simplify things. Signed-off-by: James Clark --- tools/perf/util/cs-etm.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index bf8fbcec2d69..ab30591a6c6a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2888,7 +2888,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, int num_cpu, trcidr_idx; int err = 0; int i, j; - u64 *ptr, *hdr = NULL; + u64 *ptr = NULL; u64 **metadata = NULL; u64 hdr_version; @@ -2914,15 +2914,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, return -EINVAL; } - hdr = zalloc(sizeof(*hdr) * CS_HEADER_VERSION_MAX); - if (!hdr) - return -ENOMEM; - - /* Extract header information - see cs-etm.h for format */ - for (i = 0; i < CS_HEADER_VERSION_MAX; i++) - hdr[i] = ptr[i]; - num_cpu = hdr[CS_PMU_TYPE_CPUS] & 0xffffffff; - pmu_type = (unsigned int) ((hdr[CS_PMU_TYPE_CPUS] >> 32) & + num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; + pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); if (dump_trace) @@ -2934,10 +2927,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, * in anything other than a sequential array is worth doing. */ traceid_list = intlist__new(NULL); - if (!traceid_list) { - err = -ENOMEM; - goto err_free_hdr; - } + if (!traceid_list) + return -ENOMEM; metadata = zalloc(sizeof(*metadata) * num_cpu); if (!metadata) { @@ -2945,6 +2936,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, goto err_free_traceid_list; } + /* Start parsing after the common part of the header */ + i = CS_HEADER_VERSION_MAX; + /* * The metadata is stored in the auxtrace_info section and encodes * the configuration of the ARM embedded trace macrocell which is @@ -3043,7 +3037,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, etm->num_cpu = num_cpu; etm->pmu_type = pmu_type; - etm->snapshot_mode = (hdr[CS_ETM_SNAPSHOT] != 0); + etm->snapshot_mode = (ptr[CS_ETM_SNAPSHOT] != 0); etm->metadata = metadata; etm->auxtrace_type = auxtrace_info->type; etm->timeless_decoding = cs_etm__is_timeless_decoding(etm); @@ -3110,7 +3104,5 @@ int cs_etm__process_auxtrace_info(union perf_event *event, zfree(&metadata); err_free_traceid_list: intlist__delete(traceid_list); -err_free_hdr: - zfree(&hdr); return err; } From patchwork Mon Dec 12 15:55:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 32433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2329680wrr; Mon, 12 Dec 2022 08:12:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7LgvopzQiVe/AbDLz3jb8FUO+m+6XHxVHhyvdQeCf5iuqL+HkMYxKpC0aqYh9U6gB1XSj0 X-Received: by 2002:a17:906:8543:b0:7c0:d88e:4b37 with SMTP id h3-20020a170906854300b007c0d88e4b37mr12071528ejy.52.1670861568733; Mon, 12 Dec 2022 08:12:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670861568; cv=none; d=google.com; s=arc-20160816; b=emppmljKlWpT3S6+ILLe4JDklJbKw4BHu4SQIHmcrcwje0TV/QFf8An4Ad5rZL8dl5 kMnaKbGa4It01HkXZ87dvL1yTnnYC3ne9nmcDJPL8GF8k5kjB9HerlE0HNUqI2xjOBtn IOAt+6qnvF5oMbj6o8uostSS18NopPPT3RGPIu4b2rGc7dlympzh+0r+Y/kl7m0Xev31 LH2vuDijKDcLHYEBJEXt1Co92FAGe5qt2gX5lYxAVXQHO0i+GEvpPoopahlh8yCyuaZY A5bc8ihN5O+gRTCEFy4oReI29vqbYJKYaG3T+nsTuQ+tYlqz8LuiHOyz/4EKDylBA4gP gWWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yvAX7xPVlBsRcxG3eEGx4FsBQgZP/qzA6gsUaR/GWDY=; b=dHTh1vfiWUPJjUhV3K2NzPzqC2z8ozd3vjKP5CPEQ0braCle3chEZzZKRoTavOz3Or m4AjsjDZrnJJ9P93GfO9QskPHDXW/izFMOjSi36oAucCsElDRn8bK0ERH0uKQyFxpmhZ qQ9EmwMjSFUhe/4NBzCnW9eb64WTlsqc8h8fCYcd02SMMagNtlHG1PGpKGk4gQGt/reh krduq89KQnKPR2rUBBCXl8gw92Z5kW53WfJLgz6oyciYUw7VFx0VBRvi5649GyOtMBCJ grOB//NHXKI+jmO5XEOVO96mAZEJ+0emzUH7irmPBEV5I2mEh3N5mZhEwW94LAbxMj4b KoNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e26-20020a17090681da00b007973c84ba55si5253132ejx.298.2022.12.12.08.12.25; Mon, 12 Dec 2022 08:12:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232741AbiLLP4U (ORCPT + 99 others); Mon, 12 Dec 2022 10:56:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232649AbiLLP4C (ORCPT ); Mon, 12 Dec 2022 10:56:02 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1116213EB1; Mon, 12 Dec 2022 07:55:56 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 407CE15BF; Mon, 12 Dec 2022 07:56:37 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A1C93F71E; Mon, 12 Dec 2022 07:55:53 -0800 (PST) From: James Clark To: linux-perf-users@vger.kernel.org Cc: Al.Grant@arm.com, James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , John Garry , Will Deacon , Mike Leach , Leo Yan , Mathieu Poirier , Suzuki K Poulose , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH 5/5] perf: cs-etm: Print auxtrace info even if OpenCSD isn't linked Date: Mon, 12 Dec 2022 15:55:13 +0000 Message-Id: <20221212155513.2259623-6-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221212155513.2259623-1-james.clark@arm.com> References: <20221212155513.2259623-1-james.clark@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752024908056339783?= X-GMAIL-MSGID: =?utf-8?q?1752025340536563305?= Printing the info doesn't have any dependency on OpenCSD, and neither does recording Coresight data. Because it's sometimes useful to look at the info for debugging, it makes sense to be able to see it on the same platform that the recording was made on. So pull the auxtrace info printing parts into a new file that is always compiled into Perf. Signed-off-by: James Clark --- tools/perf/util/Build | 1 + tools/perf/util/cs-etm-base.c | 174 ++++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.c | 170 ++------------------------------- tools/perf/util/cs-etm.h | 12 ++- 4 files changed, 191 insertions(+), 166 deletions(-) create mode 100644 tools/perf/util/cs-etm-base.c diff --git a/tools/perf/util/Build b/tools/perf/util/Build index ab37f588ee8b..1193b207ef7d 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -125,6 +125,7 @@ ifdef CONFIG_LIBOPENCSD perf-$(CONFIG_AUXTRACE) += cs-etm.o perf-$(CONFIG_AUXTRACE) += cs-etm-decoder/ endif +perf-$(CONFIG_AUXTRACE) += cs-etm-base.o perf-y += parse-branch-options.o perf-y += dump-insn.o diff --git a/tools/perf/util/cs-etm-base.c b/tools/perf/util/cs-etm-base.c new file mode 100644 index 000000000000..597542410854 --- /dev/null +++ b/tools/perf/util/cs-etm-base.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * File for any parts of the Coresight decoding that don't require + * OpenCSD. + */ + +#include +#include + +#include "cs-etm.h" + +static const char * const cs_etm_global_header_fmts[] = { + [CS_HEADER_VERSION] = " Header version %llx\n", + [CS_PMU_TYPE_CPUS] = " PMU type/num cpus %llx\n", + [CS_ETM_SNAPSHOT] = " Snapshot %llx\n", +}; + +static const char * const cs_etm_priv_fmts[] = { + [CS_ETM_MAGIC] = " Magic number %llx\n", + [CS_ETM_CPU] = " CPU %lld\n", + [CS_ETM_NR_TRC_PARAMS] = " NR_TRC_PARAMS %llx\n", + [CS_ETM_ETMCR] = " ETMCR %llx\n", + [CS_ETM_ETMTRACEIDR] = " ETMTRACEIDR %llx\n", + [CS_ETM_ETMCCER] = " ETMCCER %llx\n", + [CS_ETM_ETMIDR] = " ETMIDR %llx\n", +}; + +static const char * const cs_etmv4_priv_fmts[] = { + [CS_ETM_MAGIC] = " Magic number %llx\n", + [CS_ETM_CPU] = " CPU %lld\n", + [CS_ETM_NR_TRC_PARAMS] = " NR_TRC_PARAMS %llx\n", + [CS_ETMV4_TRCCONFIGR] = " TRCCONFIGR %llx\n", + [CS_ETMV4_TRCTRACEIDR] = " TRCTRACEIDR %llx\n", + [CS_ETMV4_TRCIDR0] = " TRCIDR0 %llx\n", + [CS_ETMV4_TRCIDR1] = " TRCIDR1 %llx\n", + [CS_ETMV4_TRCIDR2] = " TRCIDR2 %llx\n", + [CS_ETMV4_TRCIDR8] = " TRCIDR8 %llx\n", + [CS_ETMV4_TRCAUTHSTATUS] = " TRCAUTHSTATUS %llx\n", + [CS_ETE_TRCDEVARCH] = " TRCDEVARCH %llx\n" +}; + +static const char * const param_unk_fmt = + " Unknown parameter [%d] %"PRIx64"\n"; +static const char * const magic_unk_fmt = + " Magic number Unknown %"PRIx64"\n"; + +static int cs_etm__print_cpu_metadata_v0(u64 *val, int *offset) +{ + int i = *offset, j, nr_params = 0, fmt_offset; + u64 magic; + + /* check magic value */ + magic = val[i + CS_ETM_MAGIC]; + if ((magic != __perf_cs_etmv3_magic) && + (magic != __perf_cs_etmv4_magic)) { + /* failure - note bad magic value */ + fprintf(stdout, magic_unk_fmt, magic); + return -EINVAL; + } + + /* print common header block */ + fprintf(stdout, cs_etm_priv_fmts[CS_ETM_MAGIC], val[i++]); + fprintf(stdout, cs_etm_priv_fmts[CS_ETM_CPU], val[i++]); + + if (magic == __perf_cs_etmv3_magic) { + nr_params = CS_ETM_NR_TRC_PARAMS_V0; + fmt_offset = CS_ETM_ETMCR; + /* after common block, offset format index past NR_PARAMS */ + for (j = fmt_offset; j < nr_params + fmt_offset; j++, i++) + fprintf(stdout, cs_etm_priv_fmts[j], val[i]); + } else if (magic == __perf_cs_etmv4_magic) { + nr_params = CS_ETMV4_NR_TRC_PARAMS_V0; + fmt_offset = CS_ETMV4_TRCCONFIGR; + /* after common block, offset format index past NR_PARAMS */ + for (j = fmt_offset; j < nr_params + fmt_offset; j++, i++) + fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); + } + *offset = i; + return 0; +} + +static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset) +{ + int i = *offset, j, total_params = 0; + u64 magic; + + magic = val[i + CS_ETM_MAGIC]; + /* total params to print is NR_PARAMS + common block size for v1 */ + total_params = val[i + CS_ETM_NR_TRC_PARAMS] + CS_ETM_COMMON_BLK_MAX_V1; + + if (magic == __perf_cs_etmv3_magic) { + for (j = 0; j < total_params; j++, i++) { + /* if newer record - could be excess params */ + if (j >= CS_ETM_PRIV_MAX) + fprintf(stdout, param_unk_fmt, j, val[i]); + else + fprintf(stdout, cs_etm_priv_fmts[j], val[i]); + } + } else if (magic == __perf_cs_etmv4_magic || magic == __perf_cs_ete_magic) { + /* + * ETE and ETMv4 can be printed in the same block because the number of parameters + * is saved and they share the list of parameter names. ETE is also only supported + * in V1 files. + */ + for (j = 0; j < total_params; j++, i++) { + /* if newer record - could be excess params */ + if (j >= CS_ETE_PRIV_MAX) + fprintf(stdout, param_unk_fmt, j, val[i]); + else + fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); + } + } else { + /* failure - note bad magic value and error out */ + fprintf(stdout, magic_unk_fmt, magic); + return -EINVAL; + } + *offset = i; + return 0; +} + +static void cs_etm__print_auxtrace_info(u64 *val, int num) +{ + int i, cpu = 0, version, err; + + version = val[0]; + + for (i = 0; i < CS_HEADER_VERSION_MAX; i++) + fprintf(stdout, cs_etm_global_header_fmts[i], val[i]); + + for (i = CS_HEADER_VERSION_MAX; cpu < num; cpu++) { + if (version == 0) + err = cs_etm__print_cpu_metadata_v0(val, &i); + else if (version == 1) + err = cs_etm__print_cpu_metadata_v1(val, &i); + if (err) + return; + } +} + +/* + * Do some basic checks and print the auxtrace info header before calling + * into cs_etm__process_auxtrace_info_full() which requires OpenCSD to be + * linked in. This allows some basic debugging if OpenCSD is missing. + */ +int cs_etm__process_auxtrace_info(union perf_event *event, + struct perf_session *session) +{ + struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; + int event_header_size = sizeof(struct perf_event_header); + int num_cpu; + u64 *ptr = NULL; + u64 hdr_version; + + if (auxtrace_info->header.size < (event_header_size + INFO_HEADER_SIZE)) + return -EINVAL; + + /* First the global part */ + ptr = (u64 *) auxtrace_info->priv; + + /* Look for version of the header */ + hdr_version = ptr[0]; + if (hdr_version > CS_HEADER_CURRENT_VERSION) { + pr_err("\nCS ETM Trace: Unknown Header Version = %#" PRIx64, hdr_version); + pr_err(", version supported <= %x\n", CS_HEADER_CURRENT_VERSION); + return -EINVAL; + } + + if (dump_trace) { + num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; + cs_etm__print_auxtrace_info(ptr, num_cpu); + } + + return cs_etm__process_auxtrace_info_full(event, session); +} diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index ab30591a6c6a..33303d03c2fa 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2510,134 +2510,6 @@ static bool cs_etm__is_timeless_decoding(struct cs_etm_auxtrace *etm) return timeless_decoding; } -static const char * const cs_etm_global_header_fmts[] = { - [CS_HEADER_VERSION] = " Header version %llx\n", - [CS_PMU_TYPE_CPUS] = " PMU type/num cpus %llx\n", - [CS_ETM_SNAPSHOT] = " Snapshot %llx\n", -}; - -static const char * const cs_etm_priv_fmts[] = { - [CS_ETM_MAGIC] = " Magic number %llx\n", - [CS_ETM_CPU] = " CPU %lld\n", - [CS_ETM_NR_TRC_PARAMS] = " NR_TRC_PARAMS %llx\n", - [CS_ETM_ETMCR] = " ETMCR %llx\n", - [CS_ETM_ETMTRACEIDR] = " ETMTRACEIDR %llx\n", - [CS_ETM_ETMCCER] = " ETMCCER %llx\n", - [CS_ETM_ETMIDR] = " ETMIDR %llx\n", -}; - -static const char * const cs_etmv4_priv_fmts[] = { - [CS_ETM_MAGIC] = " Magic number %llx\n", - [CS_ETM_CPU] = " CPU %lld\n", - [CS_ETM_NR_TRC_PARAMS] = " NR_TRC_PARAMS %llx\n", - [CS_ETMV4_TRCCONFIGR] = " TRCCONFIGR %llx\n", - [CS_ETMV4_TRCTRACEIDR] = " TRCTRACEIDR %llx\n", - [CS_ETMV4_TRCIDR0] = " TRCIDR0 %llx\n", - [CS_ETMV4_TRCIDR1] = " TRCIDR1 %llx\n", - [CS_ETMV4_TRCIDR2] = " TRCIDR2 %llx\n", - [CS_ETMV4_TRCIDR8] = " TRCIDR8 %llx\n", - [CS_ETMV4_TRCAUTHSTATUS] = " TRCAUTHSTATUS %llx\n", - [CS_ETE_TRCDEVARCH] = " TRCDEVARCH %llx\n" -}; - -static const char * const param_unk_fmt = - " Unknown parameter [%d] %"PRIx64"\n"; -static const char * const magic_unk_fmt = - " Magic number Unknown %"PRIx64"\n"; - -static int cs_etm__print_cpu_metadata_v0(u64 *val, int *offset) -{ - int i = *offset, j, nr_params = 0, fmt_offset; - u64 magic; - - /* check magic value */ - magic = val[i + CS_ETM_MAGIC]; - if ((magic != __perf_cs_etmv3_magic) && - (magic != __perf_cs_etmv4_magic)) { - /* failure - note bad magic value */ - fprintf(stdout, magic_unk_fmt, magic); - return -EINVAL; - } - - /* print common header block */ - fprintf(stdout, cs_etm_priv_fmts[CS_ETM_MAGIC], val[i++]); - fprintf(stdout, cs_etm_priv_fmts[CS_ETM_CPU], val[i++]); - - if (magic == __perf_cs_etmv3_magic) { - nr_params = CS_ETM_NR_TRC_PARAMS_V0; - fmt_offset = CS_ETM_ETMCR; - /* after common block, offset format index past NR_PARAMS */ - for (j = fmt_offset; j < nr_params + fmt_offset; j++, i++) - fprintf(stdout, cs_etm_priv_fmts[j], val[i]); - } else if (magic == __perf_cs_etmv4_magic) { - nr_params = CS_ETMV4_NR_TRC_PARAMS_V0; - fmt_offset = CS_ETMV4_TRCCONFIGR; - /* after common block, offset format index past NR_PARAMS */ - for (j = fmt_offset; j < nr_params + fmt_offset; j++, i++) - fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); - } - *offset = i; - return 0; -} - -static int cs_etm__print_cpu_metadata_v1(u64 *val, int *offset) -{ - int i = *offset, j, total_params = 0; - u64 magic; - - magic = val[i + CS_ETM_MAGIC]; - /* total params to print is NR_PARAMS + common block size for v1 */ - total_params = val[i + CS_ETM_NR_TRC_PARAMS] + CS_ETM_COMMON_BLK_MAX_V1; - - if (magic == __perf_cs_etmv3_magic) { - for (j = 0; j < total_params; j++, i++) { - /* if newer record - could be excess params */ - if (j >= CS_ETM_PRIV_MAX) - fprintf(stdout, param_unk_fmt, j, val[i]); - else - fprintf(stdout, cs_etm_priv_fmts[j], val[i]); - } - } else if (magic == __perf_cs_etmv4_magic || magic == __perf_cs_ete_magic) { - /* - * ETE and ETMv4 can be printed in the same block because the number of parameters - * is saved and they share the list of parameter names. ETE is also only supported - * in V1 files. - */ - for (j = 0; j < total_params; j++, i++) { - /* if newer record - could be excess params */ - if (j >= CS_ETE_PRIV_MAX) - fprintf(stdout, param_unk_fmt, j, val[i]); - else - fprintf(stdout, cs_etmv4_priv_fmts[j], val[i]); - } - } else { - /* failure - note bad magic value and error out */ - fprintf(stdout, magic_unk_fmt, magic); - return -EINVAL; - } - *offset = i; - return 0; -} - -static void cs_etm__print_auxtrace_info(u64 *val, int num) -{ - int i, cpu = 0, version, err; - - version = val[0]; - - for (i = 0; i < CS_HEADER_VERSION_MAX; i++) - fprintf(stdout, cs_etm_global_header_fmts[i], val[i]); - - for (i = CS_HEADER_VERSION_MAX; cpu < num; cpu++) { - if (version == 0) - err = cs_etm__print_cpu_metadata_v0(val, &i); - else if (version == 1) - err = cs_etm__print_cpu_metadata_v1(val, &i); - if (err) - return; - } -} - /* * Read a single cpu parameter block from the auxtrace_info priv block. * @@ -2874,15 +2746,13 @@ static int cs_etm__queue_aux_records(struct perf_session *session) return 0; } -int cs_etm__process_auxtrace_info(union perf_event *event, - struct perf_session *session) +int cs_etm__process_auxtrace_info_full(union perf_event *event, + struct perf_session *session) { struct perf_record_auxtrace_info *auxtrace_info = &event->auxtrace_info; struct cs_etm_auxtrace *etm = NULL; struct int_node *inode; - unsigned int pmu_type; int event_header_size = sizeof(struct perf_event_header); - int info_header_size; int total_size = auxtrace_info->header.size; int priv_size = 0; int num_cpu, trcidr_idx; @@ -2890,36 +2760,6 @@ int cs_etm__process_auxtrace_info(union perf_event *event, int i, j; u64 *ptr = NULL; u64 **metadata = NULL; - u64 hdr_version; - - /* - * sizeof(auxtrace_info_event::type) + - * sizeof(auxtrace_info_event::reserved) == 8 - */ - info_header_size = 8; - - if (total_size < (event_header_size + info_header_size)) - return -EINVAL; - - priv_size = total_size - event_header_size - info_header_size; - - /* First the global part */ - ptr = (u64 *) auxtrace_info->priv; - - /* Look for version of the header */ - hdr_version = ptr[0]; - if (hdr_version > CS_HEADER_CURRENT_VERSION) { - pr_err("\nCS ETM Trace: Unknown Header Version = %#" PRIx64, hdr_version); - pr_err(", version supported <= %x\n", CS_HEADER_CURRENT_VERSION); - return -EINVAL; - } - - num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; - pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & - 0xffffffff); - - if (dump_trace) - cs_etm__print_auxtrace_info(ptr, num_cpu); /* * Create an RB tree for traceID-metadata tuple. Since the conversion @@ -2930,6 +2770,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, if (!traceid_list) return -ENOMEM; + /* First the global part */ + ptr = (u64 *) auxtrace_info->priv; + num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; metadata = zalloc(sizeof(*metadata) * num_cpu); if (!metadata) { err = -ENOMEM; @@ -3008,6 +2851,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, * The following tests if the correct number of double words was * present in the auxtrace info section. */ + priv_size = total_size - event_header_size - INFO_HEADER_SIZE; if (i * 8 != priv_size) { err = -EINVAL; goto err_free_metadata; @@ -3036,7 +2880,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, etm->machine = &session->machines.host; etm->num_cpu = num_cpu; - etm->pmu_type = pmu_type; + etm->pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); etm->snapshot_mode = (ptr[CS_ETM_SNAPSHOT] != 0); etm->metadata = metadata; etm->auxtrace_type = auxtrace_info->type; diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 401f74be98d6..5da50d5dae6b 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -202,9 +202,13 @@ struct cs_etm_packet_queue { #define CS_ETMV4_PRIV_SIZE (CS_ETMV4_PRIV_MAX * sizeof(u64)) #define CS_ETE_PRIV_SIZE (CS_ETE_PRIV_MAX * sizeof(u64)) -#ifdef HAVE_CSTRACE_SUPPORT +#define INFO_HEADER_SIZE (sizeof(((struct perf_record_auxtrace_info *)0)->type) + \ + sizeof(((struct perf_record_auxtrace_info *)0)->reserved__)) + int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); + +#ifdef HAVE_CSTRACE_SUPPORT int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); int cs_etm__get_pid_fmt(u8 trace_chan_id, u64 *pid_fmt); int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, @@ -214,10 +218,12 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, u8 trace_chan_id); struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id); +int cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused, + struct perf_session *session __maybe_unused); #else static inline int -cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, - struct perf_session *session __maybe_unused) +cs_etm__process_auxtrace_info_full(union perf_event *event __maybe_unused, + struct perf_session *session __maybe_unused) { pr_err("\nCS ETM Trace: OpenCSD is not linked in, please recompile with CORESIGHT=1\n"); return -1;