Message ID | 20230419172101.78638-1-gankulkarni@os.amperecomputing.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp562924vqo; Wed, 19 Apr 2023 10:47:59 -0700 (PDT) X-Google-Smtp-Source: AKy350ZQ3GrJnA5Mh40MAlfwT6UXMUtLj4BeDP6vc3R3yE+5H0tafRym9oDchuJIltwvjcsr/5mf X-Received: by 2002:a05:6a20:9f4a:b0:ef:7d7b:433b with SMTP id ml10-20020a056a209f4a00b000ef7d7b433bmr3977215pzb.41.1681926479666; Wed, 19 Apr 2023 10:47:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681926479; cv=pass; d=google.com; s=arc-20160816; b=gKxzqUMO1nQJrIOXc22/xb0nxZIE7/SuKU/8L3/eeLDIqs8UewbRXWzPXvxlK/DJp6 onNj/OLBw0tmGARu/ClwGrHQmziodglGT2O3Z1hdcZgEVUD9VUBtbhXth3ZlZ6wntT/i vGrN5S7Uibf+JRrvNBnQdtfBJ2x15vRe2Kyvbg24vuhL3N/DB8ry0uZ5kXkQWQILn3rc F8PwSViEGSl353TvtmQIKP1PJQw6uA4KnYVjDYFNrSWnG6UvjUgxELHRfjgWKUGqogxd 3Nk4IYN2jCj7qteu/S7fxx2c+GxZOo1AOlVsadMl7DVFKCY2j2PW0F/qehUv4n2wjbxQ ++ww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=wJgEWTkc/GZAhBSEt2/g7wf6XL3jy88yCeiMYuP1Cn4=; b=yTdoJ8UwGxUDxGQFnXQWAdfFLhmy03TC4NkG/yiCIhenyXfqZUBnc/F3E2bhUWLgao MjtR5SVHGt/v9gGsL9j7Kdqh95ycDKK7AJNllWxpSmMgexMiX6bvwXkvMfF9D2Xrufuq MPw4uraLwJPkYntTRChsKbDic1YRSkh7t+awKQ+cBkoRE7wKDjO+XmbQJ2O6QuncMV+z kAo0OWdBWfJSUZhC9+T5HRmxB+Re450Nqf/ydM7afCdeP1JB/QrVpaL1jNSofRzXEmXi XyzzDpq1uDUVHRb1k+4Oj9IKzn3hQasKWjl1Cskf2crRdBNB/Y/YJqsLMwgS5t+j8+FJ 7Dxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=lVNJ5ZUu; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a6566c5000000b00520384a7d16si2763231pgw.725.2023.04.19.10.47.45; Wed, 19 Apr 2023 10:47:59 -0700 (PDT) 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; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=lVNJ5ZUu; arc=pass (i=1 spf=pass spfdomain=os.amperecomputing.com dkim=pass dkdomain=os.amperecomputing.com dmarc=pass fromdomain=os.amperecomputing.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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amperecomputing.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbjDSRV2 (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Wed, 19 Apr 2023 13:21:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjDSRVZ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 19 Apr 2023 13:21:25 -0400 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2130.outbound.protection.outlook.com [40.107.102.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B7765B5 for <linux-kernel@vger.kernel.org>; Wed, 19 Apr 2023 10:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CHC0jwtUAsam3/24ioTTUD60CDUqOo5vuSHw1gJmAtJl7ZxMj9lfku4VtNdbzcPy+QfppBwk+3GIauE4gE71knWgEnzA+vjKDuvSs2sPMPswlmIBuwP8r3JJp4VDqyaFT4FjINOewlPKB8dmZoTxrkjM8XSCyP8CM4qZx3RcztBiAAW7jjkzejUzFeK07KQwPbo2uIkpv7MDNGmV21VMRioldQoPlRCRd0aIC36e4cDs/gs7A5iiy5uqeQp9cQRIO0fDq+i2Lnp4+gnUPXrX9by9lY3e6hYy5A4oflEQQ4SxFy9bA0fOGRhsLF938SX4a6O5ZPSNDT359lARQZkHeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wJgEWTkc/GZAhBSEt2/g7wf6XL3jy88yCeiMYuP1Cn4=; b=aXigXJPK1S95vE3O0BfB3M9IbU2m1UlIIlNh6UxylZ4MRaRATt2p63WudbVgTZ2FX21R7n7Ex3mwFH8qN7L7I59F0R0RE7mnVfHSy56E0SN2NeQWZUTEy8C9EL2VMggJWiMjRu9cRSMHxX+9qvm65sp4GW0GpQVeezzNn73QgAeKQVog7lPlCECaeGlEJKvs0d55Pq/Woka3iPq1End+HDDNz7pcgSewKwiAEjbtkWYNkhi8OPnfj2CoXjguYdKOMKYotV5vfO89hi4SEjFyYdp+PZy98YNfxQoDhls/b7SGhTJrSJbFnQ6u+EariLqXpTo7U5d5uCwyLgkefSEt3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wJgEWTkc/GZAhBSEt2/g7wf6XL3jy88yCeiMYuP1Cn4=; b=lVNJ5ZUuZpZe0SYdGQHlLmWADVyKo/gEoCc5fxqm/tgfycoRV3zKWh5J8D1ATVjBrAtnHODCE0y/jq8nK7v9wT0qVggl4eAGMwsxSPPO9liuBTgjVq7QBXjg2074jCiU5g4MzyzxeyNUwkvbKGvuXoDrpoSwZvSz+/C/gR/lQIQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) by BYAPR01MB4358.prod.exchangelabs.com (2603:10b6:a03:a5::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.20; Wed, 19 Apr 2023 17:21:17 +0000 Received: from DM8PR01MB6824.prod.exchangelabs.com ([fe80::5cf:2baf:f5ab:ac87]) by DM8PR01MB6824.prod.exchangelabs.com ([fe80::5cf:2baf:f5ab:ac87%5]) with mapi id 15.20.6319.022; Wed, 19 Apr 2023 17:21:17 +0000 From: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> To: linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, mike.leach@linaro.org, suzuki.poulose@arm.com Cc: mathieu.poirier@linaro.org, acme@kernel.org, darren@os.amperecomputing.com, scott@os.amperecomputing.com, scclevenger@os.amperecomputing.com, gankulkarni@os.amperecomputing.com Subject: [PATCH] perf cs-etm: Add support for coresight trace for any range of CPUs Date: Wed, 19 Apr 2023 10:21:01 -0700 Message-Id: <20230419172101.78638-1-gankulkarni@os.amperecomputing.com> X-Mailer: git-send-email 2.38.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: CH2PR20CA0015.namprd20.prod.outlook.com (2603:10b6:610:58::25) To DM8PR01MB6824.prod.exchangelabs.com (2603:10b6:8:23::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM8PR01MB6824:EE_|BYAPR01MB4358:EE_ X-MS-Office365-Filtering-Correlation-Id: b9b03fc4-9ea3-4359-b522-08db40fa7c15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: apFa3RohvaAn4+6Z9o3cKYuWr8u554Wl5BZTAEnLI2KLjj0BiksjltqZlyPFTJ8irfVI5UTQz3mNZTESfoofLp9mLnADl+yysKMqNqcjGK2RjNKo91p/tJel61nfQmeXCCIm8UFJLo4p6MvM0RH6mbmg1wmyvIRDqg2dKFPREqesfAInRgCVHjE+XWnsoVeRHm5Khjh9xn1bhE8sH+ddYfjtqDeoov9w/iJF0bQLpUria7J3HU5FeeBpyABZ16jymp3gk7qJUbFPgi4MtacgnuqFUSEX4RXCYpJolKJJdffzLskbdanv+rlr+oAnG8X4HUDpj6CCBgWJ7UHTi6GQTFOb736JqBKWCoqt6ccf7NuVFzbamXBZSj8aVowqT6ro5gVwMC20iPlcFjXwrkNGKBD6Z5bUnp9C7daJUt2MQ00O4pD5dZWHz9DFSmr3mwmZYDz0aHrnHRPlcY4qvHb6jPnlFHpjQPZBI+QKXX4nnU6DfTakZT3LYiyy1jMLX7Wq/CINAyZpYurlfsiN0hGs/EAiDvyCNI7HKKU6RtqUxBA3yL23q8qXxcXbbk8Q4tTOaQKoOpi4hDQcs1+Y0kTeHTSBJr4W7jI69nnopfKq7iHJnQKKTkN4UbbpQkWOVVRX X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM8PR01MB6824.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(136003)(346002)(396003)(39850400004)(451199021)(4326008)(38350700002)(8936002)(8676002)(38100700002)(316002)(66946007)(66556008)(66476007)(2906002)(478600001)(6486002)(6666004)(52116002)(1076003)(26005)(6512007)(6506007)(86362001)(83380400001)(5660300002)(41300700001)(107886003)(2616005)(186003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JzXUACAYtgXsqesSP4yV+FlmcWJqWVjO/F7CAbRYpYUGqq9Jn4T6nNAeXe64RWB3iDOi6zxBN2/eij79c45GmXBlmyk+EjUjbZibrwqtR0q54TMBe3jV8BLRw4a5xndUycHZy7hTtpTI15BcBZOea9TJRsrDjiSJQiuUfOtbXGTsNy7NdNv9fRjX1+iSgPeMgmUxx5K9d0KWefWzsxjM95hK+ZeOEDvMo8yGz8Oh0g64s5fJh3OYF058GhhUHjtDm+n2euiXnmwF4JlBv47CJw40T/DGNOblcTYvRpBk6fezbkPid7A04dDy96qC8bm9Cz3foi77LZ+6uTEbJ2VVoB1s0pvHUHRdT/swHf10NAlkzwC1r7n1hYcmT1pS6rPfsxALp3y1xwRqnM1ZYNPelsgdV9B1YyS+x+/b/eEtvC6Wi40bKU/jQxR1XHon9TUDS0O2txOsEPoXKkNRRGFCq1ADg6Rg4ecYYpw05AUnY4Hj4V/zYc8MYAF4cU4qJiV/eSYMn2MXlUVvbaasmHyI9cISF0TJjBqx5ynGuzuH/WpvJ8xMSY48HJBKsBkMssQ7axUOpndgerqXzumUR1ZXLd0vfSq3/qiMKJRxvgjh8hae15ZLxapXEFJI1sE1Euh/Rhqj3M/iE7EuyZ3i3TCoxLCe9qRMKVQTPPfUhCZATIRgsvDyd6kYVpAu6384xlhgByTn4JAzdLDOpanLB/OABCok58B1CTn50s5Cln3TMh6YS0WstlBNQDfSDGGBd1vBrTMdpWbUZl60ZCOgFVd4ux+NzfE/YhLmoXROr7Fh+zfYhDlbfrkQlQzJ0XT6VOcCd2LhPZy40vOdKtkYd3JnNfZ29+5X0NrXMDRFpMX1VpIsg+nI+A82BaYfmqdk+t/qj+c/L5WO5FcIZGMzInv3aII9FH2lLW7wsFLUPXvmdST/Yd+695q24vbNPesKH2rZolwFoBZZVLsDKBrAozBcNSfP97lLyjwOKZFdSu0TBhK5uAJQhC4p044LHkQeRDD3oAYxZ+IGOyL5T1RkvUlFOij9k8HnMxpA+K2qAF50MqOkUnRZlbCKA0OFwG1Nf2En/f4qAUV+OLJYUOry9RuwyT5H7QvsNYCa5iLCCmwXh2EvRQoi1AwuJnANiQa16xczcS+BaKbtmsFEIonQC7qlqwQOWNVPjUyc+iJQb3jO24madd9lcilPF95HBtSHD739XeQX86fout2/l2Ei5CppDGbwFlU2XZgt/DRkk7iVhlfBB50KSbTtU5qI0O7iLneK6YCQGS373/NWk5yiIqnICox3pnNHBxzkCzXxtb0q12juS/Ujjwm5UF4xTkX24s37kIynbmu8KaiO4T+CR7xWkE0Y3bGehtGHn5iCfKa2L3lVj0DLgqlWk7AglJw+U8tvHs4p5r/assBq/mIOYNOo1Y8Oxzcx53kcKYDSs8zwnqeTxYb0ZOp7aBOaMON4duQqn2mEKx+A+WPNFs184ljyjDk6JeP3viyIFkQdk7qzaAyNH/m5zUftC+jx6KZ+gcQoSW9a0gSRieJAKq7KmtlI/spJrCnHHGF6kGTK6cd0pO9J08Po9tS/VUZupm8XDyCSeSNNuosRAjqDAt1CY1EPBGR2jMgameb8d8Zx5QZTR4c= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9b03fc4-9ea3-4359-b522-08db40fa7c15 X-MS-Exchange-CrossTenant-AuthSource: DM8PR01MB6824.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 17:21:17.2690 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: deQ+A2QSsr3ll0cFBgyxHmjcAXs0ttzfY9APZhtG2CVaTPMb8tQ5U6f2Pl/WyFzhGER+RhadSzfYPRsipzHSGpZGyRU7WecIQTnnVf3/eCpvzR/DZZYtKOBgvcu7mOql X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR01MB4358 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763627740150921377?= X-GMAIL-MSGID: =?utf-8?q?1763627740150921377?= |
Series |
perf cs-etm: Add support for coresight trace for any range of CPUs
|
|
Commit Message
Ganapatrao Kulkarni
April 19, 2023, 5:21 p.m. UTC
The current implementation supports coresight trace for a range of
CPUs, if the first CPU is CPU0.
Adding changes to enable coresight trace for any range of CPUs by
decoding the first CPU also from the header.
Later, first CPU id is used instead of CPU0 across the decoder functions.
Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>
---
.../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +-
.../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +-
tools/perf/util/cs-etm.c | 62 ++++++++++++-------
3 files changed, 42 insertions(+), 27 deletions(-)
Comments
On 19/04/2023 18:21, Ganapatrao Kulkarni wrote: > The current implementation supports coresight trace for a range of > CPUs, if the first CPU is CPU0. > > Adding changes to enable coresight trace for any range of CPUs by > decoding the first CPU also from the header. > Later, first CPU id is used instead of CPU0 across the decoder functions. > > Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> > --- > .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- > .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- > tools/perf/util/cs-etm.c | 62 ++++++++++++------- > 3 files changed, 42 insertions(+), 27 deletions(-) > > diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > index 82a27ab90c8b..41ab299b643b 100644 > --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c > @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, > } > > struct cs_etm_decoder * > -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, > +cs_etm_decoder__new(int first_decoder, int decoders, struct cs_etm_decoder_params *d_params, > struct cs_etm_trace_params t_params[]) > { > struct cs_etm_decoder *decoder; > @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, > /* init raw frame logging if required */ > cs_etm_decoder__init_raw_frame_logging(d_params, decoder); > > - for (i = 0; i < decoders; i++) { > + for (i = first_decoder; i < decoders; i++) { > ret = cs_etm_decoder__create_etm_decoder(d_params, > &t_params[i], > decoder); > diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h > index 92a855fbe5b8..b06193fc75b4 100644 > --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h > +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h > @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, > size_t len, size_t *consumed); > > struct cs_etm_decoder * > -cs_etm_decoder__new(int num_cpu, > +cs_etm_decoder__new(int first_decoder, > + int decoders, > struct cs_etm_decoder_params *d_params, > struct cs_etm_trace_params t_params[]); > > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c > index 94e2d02009eb..2619513ae088 100644 > --- a/tools/perf/util/cs-etm.c > +++ b/tools/perf/util/cs-etm.c > @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { > u8 has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */ > > int num_cpu; > + int first_cpu; > + int last_cpu; > u64 latest_kernel_timestamp; > u32 auxtrace_type; > u64 branches_sample_type; > @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct cs_etm_trace_params *t_params, > } > > static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params, > - struct cs_etm_auxtrace *etm, > - int decoders) > + struct cs_etm_auxtrace *etm) > { > int i; > u32 etmidr; > u64 architecture; > > - for (i = 0; i < decoders; i++) { > + for (i = etm->first_cpu; i < etm->last_cpu; i++) { > architecture = etm->metadata[i][CS_ETM_MAGIC]; > > switch (architecture) { > @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session *session) > /* Then the RB tree itself */ > intlist__delete(traceid_list); > > - for (i = 0; i < aux->num_cpu; i++) > + for (i = aux->first_cpu; i < aux->last_cpu; i++) > zfree(&aux->metadata[i]); > > thread__zput(aux->unknown_thread); > @@ -921,7 +922,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, > * Each queue can only contain data from one CPU when unformatted, so only one decoder is > * needed. > */ > - int decoders = formatted ? etm->num_cpu : 1; > + int first_decoder = formatted ? etm->first_cpu : 0; > + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); > > etmq = zalloc(sizeof(*etmq)); > if (!etmq) > @@ -937,7 +939,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, > if (!t_params) > goto out_free; > > - if (cs_etm__init_trace_params(t_params, etm, decoders)) > + if (cs_etm__init_trace_params(t_params, etm)) > goto out_free; > > /* Set decoder parameters to decode trace packets */ > @@ -947,8 +949,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, > formatted)) > goto out_free; > > - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, > - t_params); > + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, &d_params, t_params); > > if (!etmq->decoder) > goto out_free; > @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct perf_session *session) > * Loop through the ETMs and complain if we find at least one where ts_source != 1 (virtual > * timestamps). > */ > -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) > +static bool cs_etm__has_virtual_ts(u64 **metadata, struct cs_etm_auxtrace *etm) > { > int j; > > - for (j = 0; j < num_cpu; j++) { > + for (j = etm->first_cpu; j < etm->last_cpu; j++) { > switch (metadata[j][CS_ETM_MAGIC]) { > case __perf_cs_etmv4_magic: > if (HAS_PARAM(j, ETMV4, TS_SOURCE) || metadata[j][CS_ETMV4_TS_SOURCE] != 1) > @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) > } > > /* map trace ids to correct metadata block, from information in metadata */ > -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) > +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm) > { > u64 cs_etm_magic; > + u64 **metadata = etm->metadata; > u8 trace_chan_id; > int i, err; > > - for (i = 0; i < num_cpu; i++) { > + for (i = etm->first_cpu; i < etm->last_cpu; i++) { > cs_etm_magic = metadata[i][CS_ETM_MAGIC]; > switch (cs_etm_magic) { > case __perf_cs_etmv3_magic: > @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) > * If we found AUX_HW_ID packets, then set any metadata marked as unused to the > * unused value to reduce the number of unneeded decoders created. > */ > -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **metadata) > +static int cs_etm__clear_unused_trace_ids_metadata(struct cs_etm_auxtrace *etm) > { > u64 cs_etm_magic; > + u64 **metadata = etm->metadata; > int i; > > - for (i = 0; i < num_cpu; i++) { > + for (i = etm->first_cpu; i < etm->last_cpu; i++) { > cs_etm_magic = metadata[i][CS_ETM_MAGIC]; > switch (cs_etm_magic) { > case __perf_cs_etmv3_magic: > @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, > int event_header_size = sizeof(struct perf_event_header); > int total_size = auxtrace_info->header.size; > int priv_size = 0; > - int num_cpu; > + int num_cpu, first_cpu = 0, last_cpu; > int err = 0; > int aux_hw_id_found; > int i, j; > @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, > /* First the global part */ > ptr = (u64 *) auxtrace_info->priv; > num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; > - metadata = zalloc(sizeof(*metadata) * num_cpu); > + > + /* Start parsing after the common part of the header */ > + i = CS_HEADER_VERSION_MAX; > + > + /*Get CPU id of first event */ > + first_cpu = ptr[i + CS_ETM_CPU]; > + last_cpu = first_cpu + num_cpu; > + > + if (first_cpu > cpu__max_cpu().cpu || > + last_cpu > cpu__max_cpu().cpu) > + return -EINVAL; > + > + metadata = zalloc(sizeof(*metadata) * last_cpu); Hi Ganapatrao, I think I see what the problem is, but I'm wondering if a better fix would be to further decouple the CPU ID from the index in the array. With your change it's not clear what happens with sparse recordings, for example 'perf record -e cs_etm// -C 1,3,5'. And it seems like there is some wastage in the zalloc here for example if only CPU 256 is traced then we'd still make 256 decoders but 255 of them would be unused? I tried to test sparse recordings, but your change doesn't apply to the latest coresight/next branch. I did notice that 'perf report -D' doesn't work with them on coresight/next (it just quits), but I couldn't see if that's fixed with your change. Would a better fix not be to keep the metadata loops from 0-N and instead save the CPU ID in cs_etm_decoder_params or the decoder. That way it would support both sparse and not starting from 0 cases? I think the code would be better if it's worded like "i < recorded_cpus" rather than "i < cpu" to make it clear that i isn't actually the CPU ID it's just an index. Also a new test for this scenario would probably be a good idea. Thanks James
On 20/04/2023 10:43, James Clark wrote: > > > On 19/04/2023 18:21, Ganapatrao Kulkarni wrote: >> The current implementation supports coresight trace for a range of >> CPUs, if the first CPU is CPU0. >> >> Adding changes to enable coresight trace for any range of CPUs by >> decoding the first CPU also from the header. >> Later, first CPU id is used instead of CPU0 across the decoder functions. >> >> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> >> --- >> .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- >> .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- >> tools/perf/util/cs-etm.c | 62 ++++++++++++------- >> 3 files changed, 42 insertions(+), 27 deletions(-) >> >> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >> index 82a27ab90c8b..41ab299b643b 100644 >> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >> @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, >> } >> >> struct cs_etm_decoder * >> -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, >> +cs_etm_decoder__new(int first_decoder, int decoders, struct cs_etm_decoder_params *d_params, >> struct cs_etm_trace_params t_params[]) >> { >> struct cs_etm_decoder *decoder; >> @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, >> /* init raw frame logging if required */ >> cs_etm_decoder__init_raw_frame_logging(d_params, decoder); >> >> - for (i = 0; i < decoders; i++) { >> + for (i = first_decoder; i < decoders; i++) { >> ret = cs_etm_decoder__create_etm_decoder(d_params, >> &t_params[i], >> decoder); >> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >> index 92a855fbe5b8..b06193fc75b4 100644 >> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >> @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, >> size_t len, size_t *consumed); >> >> struct cs_etm_decoder * >> -cs_etm_decoder__new(int num_cpu, >> +cs_etm_decoder__new(int first_decoder, >> + int decoders, >> struct cs_etm_decoder_params *d_params, >> struct cs_etm_trace_params t_params[]); >> >> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c >> index 94e2d02009eb..2619513ae088 100644 >> --- a/tools/perf/util/cs-etm.c >> +++ b/tools/perf/util/cs-etm.c >> @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { >> u8 has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */ >> >> int num_cpu; >> + int first_cpu; >> + int last_cpu; >> u64 latest_kernel_timestamp; >> u32 auxtrace_type; >> u64 branches_sample_type; >> @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct cs_etm_trace_params *t_params, >> } >> >> static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params, >> - struct cs_etm_auxtrace *etm, >> - int decoders) >> + struct cs_etm_auxtrace *etm) >> { >> int i; >> u32 etmidr; >> u64 architecture; >> >> - for (i = 0; i < decoders; i++) { >> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >> architecture = etm->metadata[i][CS_ETM_MAGIC]; >> >> switch (architecture) { >> @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session *session) >> /* Then the RB tree itself */ >> intlist__delete(traceid_list); >> >> - for (i = 0; i < aux->num_cpu; i++) >> + for (i = aux->first_cpu; i < aux->last_cpu; i++) >> zfree(&aux->metadata[i]); >> >> thread__zput(aux->unknown_thread); >> @@ -921,7 +922,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >> * Each queue can only contain data from one CPU when unformatted, so only one decoder is >> * needed. >> */ >> - int decoders = formatted ? etm->num_cpu : 1; >> + int first_decoder = formatted ? etm->first_cpu : 0; >> + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); >> >> etmq = zalloc(sizeof(*etmq)); >> if (!etmq) >> @@ -937,7 +939,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >> if (!t_params) >> goto out_free; >> >> - if (cs_etm__init_trace_params(t_params, etm, decoders)) >> + if (cs_etm__init_trace_params(t_params, etm)) >> goto out_free; >> >> /* Set decoder parameters to decode trace packets */ >> @@ -947,8 +949,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >> formatted)) >> goto out_free; >> >> - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, >> - t_params); >> + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, &d_params, t_params); >> >> if (!etmq->decoder) >> goto out_free; >> @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct perf_session *session) >> * Loop through the ETMs and complain if we find at least one where ts_source != 1 (virtual >> * timestamps). >> */ >> -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >> +static bool cs_etm__has_virtual_ts(u64 **metadata, struct cs_etm_auxtrace *etm) >> { >> int j; >> >> - for (j = 0; j < num_cpu; j++) { >> + for (j = etm->first_cpu; j < etm->last_cpu; j++) { >> switch (metadata[j][CS_ETM_MAGIC]) { >> case __perf_cs_etmv4_magic: >> if (HAS_PARAM(j, ETMV4, TS_SOURCE) || metadata[j][CS_ETMV4_TS_SOURCE] != 1) >> @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >> } >> >> /* map trace ids to correct metadata block, from information in metadata */ >> -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) >> +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm) >> { >> u64 cs_etm_magic; >> + u64 **metadata = etm->metadata; >> u8 trace_chan_id; >> int i, err; >> >> - for (i = 0; i < num_cpu; i++) { >> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >> switch (cs_etm_magic) { >> case __perf_cs_etmv3_magic: >> @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) >> * If we found AUX_HW_ID packets, then set any metadata marked as unused to the >> * unused value to reduce the number of unneeded decoders created. >> */ >> -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **metadata) >> +static int cs_etm__clear_unused_trace_ids_metadata(struct cs_etm_auxtrace *etm) >> { >> u64 cs_etm_magic; >> + u64 **metadata = etm->metadata; >> int i; >> >> - for (i = 0; i < num_cpu; i++) { >> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >> switch (cs_etm_magic) { >> case __perf_cs_etmv3_magic: >> @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, >> int event_header_size = sizeof(struct perf_event_header); >> int total_size = auxtrace_info->header.size; >> int priv_size = 0; >> - int num_cpu; >> + int num_cpu, first_cpu = 0, last_cpu; >> int err = 0; >> int aux_hw_id_found; >> int i, j; >> @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, >> /* First the global part */ >> ptr = (u64 *) auxtrace_info->priv; >> num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; >> - metadata = zalloc(sizeof(*metadata) * num_cpu); >> + >> + /* Start parsing after the common part of the header */ >> + i = CS_HEADER_VERSION_MAX; >> + >> + /*Get CPU id of first event */ >> + first_cpu = ptr[i + CS_ETM_CPU]; >> + last_cpu = first_cpu + num_cpu; >> + >> + if (first_cpu > cpu__max_cpu().cpu || >> + last_cpu > cpu__max_cpu().cpu) >> + return -EINVAL; >> + >> + metadata = zalloc(sizeof(*metadata) * last_cpu); > > Hi Ganapatrao, > > I think I see what the problem is, but I'm wondering if a better fix > would be to further decouple the CPU ID from the index in the array. > > With your change it's not clear what happens with sparse recordings, for > example 'perf record -e cs_etm// -C 1,3,5'. And it seems like there is > some wastage in the zalloc here for example if only CPU 256 is traced > then we'd still make 256 decoders but 255 of them would be unused? > > I tried to test sparse recordings, but your change doesn't apply to the > latest coresight/next branch. I did notice that 'perf report -D' doesn't > work with them on coresight/next (it just quits), but I couldn't see if > that's fixed with your change. > > Would a better fix not be to keep the metadata loops from 0-N and > instead save the CPU ID in cs_etm_decoder_params or the decoder. That > way it would support both sparse and not starting from 0 cases? I think > the code would be better if it's worded like "i < recorded_cpus" rather > than "i < cpu" to make it clear that i isn't actually the CPU ID it's > just an index. > > Also a new test for this scenario would probably be a good idea. > > Thanks > James > BTW for the test, I'm currently working on something where I've added something like this to test_arm_coresight.sh: arm_cs_etm_basic_test() { echo "Recording trace with $@" perf record -o ${perfdata} "$@" -- ls > /dev/null 2>&1 perf_script_branch_samples ls && perf_report_branch_samples ls && perf_report_instruction_samples ls err=$? arm_cs_report "CoreSight basic testing with %@" $err } # Test all combinations of per-thread, system-wide and normal mode with # and without timestamps arm_cs_etm_basic_test -e cs_etm/timestamp=0/ --per-thread arm_cs_etm_basic_test -e cs_etm/timestamp=1/ --per-thread arm_cs_etm_basic_test -e cs_etm/timestamp=0/ -a arm_cs_etm_basic_test -e cs_etm/timestamp=1/ -a arm_cs_etm_basic_test -e cs_etm/timestamp=0/ arm_cs_etm_basic_test -e cs_etm/timestamp=1/ I think you should be able to add this to cover your cases as well: # Test non-zero indexed and sparse CPU lists arm_cs_etm_basic_test -e cs_etm// -C 1,2 arm_cs_etm_basic_test -e cs_etm// -C 0,2
Hi James, On 20-04-2023 03:13 pm, James Clark wrote: > > > On 19/04/2023 18:21, Ganapatrao Kulkarni wrote: >> The current implementation supports coresight trace for a range of >> CPUs, if the first CPU is CPU0. >> >> Adding changes to enable coresight trace for any range of CPUs by >> decoding the first CPU also from the header. >> Later, first CPU id is used instead of CPU0 across the decoder functions. >> >> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> >> --- >> .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- >> .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- >> tools/perf/util/cs-etm.c | 62 ++++++++++++------- >> 3 files changed, 42 insertions(+), 27 deletions(-) >> >> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >> index 82a27ab90c8b..41ab299b643b 100644 >> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >> @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, >> } >> >> struct cs_etm_decoder * >> -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, >> +cs_etm_decoder__new(int first_decoder, int decoders, struct cs_etm_decoder_params *d_params, >> struct cs_etm_trace_params t_params[]) >> { >> struct cs_etm_decoder *decoder; >> @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, >> /* init raw frame logging if required */ >> cs_etm_decoder__init_raw_frame_logging(d_params, decoder); >> >> - for (i = 0; i < decoders; i++) { >> + for (i = first_decoder; i < decoders; i++) { >> ret = cs_etm_decoder__create_etm_decoder(d_params, >> &t_params[i], >> decoder); >> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >> index 92a855fbe5b8..b06193fc75b4 100644 >> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >> @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, >> size_t len, size_t *consumed); >> >> struct cs_etm_decoder * >> -cs_etm_decoder__new(int num_cpu, >> +cs_etm_decoder__new(int first_decoder, >> + int decoders, >> struct cs_etm_decoder_params *d_params, >> struct cs_etm_trace_params t_params[]); >> >> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c >> index 94e2d02009eb..2619513ae088 100644 >> --- a/tools/perf/util/cs-etm.c >> +++ b/tools/perf/util/cs-etm.c >> @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { >> u8 has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */ >> >> int num_cpu; >> + int first_cpu; >> + int last_cpu; >> u64 latest_kernel_timestamp; >> u32 auxtrace_type; >> u64 branches_sample_type; >> @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct cs_etm_trace_params *t_params, >> } >> >> static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params, >> - struct cs_etm_auxtrace *etm, >> - int decoders) >> + struct cs_etm_auxtrace *etm) >> { >> int i; >> u32 etmidr; >> u64 architecture; >> >> - for (i = 0; i < decoders; i++) { >> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >> architecture = etm->metadata[i][CS_ETM_MAGIC]; >> >> switch (architecture) { >> @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session *session) >> /* Then the RB tree itself */ >> intlist__delete(traceid_list); >> >> - for (i = 0; i < aux->num_cpu; i++) >> + for (i = aux->first_cpu; i < aux->last_cpu; i++) >> zfree(&aux->metadata[i]); >> >> thread__zput(aux->unknown_thread); >> @@ -921,7 +922,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >> * Each queue can only contain data from one CPU when unformatted, so only one decoder is >> * needed. >> */ >> - int decoders = formatted ? etm->num_cpu : 1; >> + int first_decoder = formatted ? etm->first_cpu : 0; >> + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); >> >> etmq = zalloc(sizeof(*etmq)); >> if (!etmq) >> @@ -937,7 +939,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >> if (!t_params) >> goto out_free; >> >> - if (cs_etm__init_trace_params(t_params, etm, decoders)) >> + if (cs_etm__init_trace_params(t_params, etm)) >> goto out_free; >> >> /* Set decoder parameters to decode trace packets */ >> @@ -947,8 +949,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >> formatted)) >> goto out_free; >> >> - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, >> - t_params); >> + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, &d_params, t_params); >> >> if (!etmq->decoder) >> goto out_free; >> @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct perf_session *session) >> * Loop through the ETMs and complain if we find at least one where ts_source != 1 (virtual >> * timestamps). >> */ >> -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >> +static bool cs_etm__has_virtual_ts(u64 **metadata, struct cs_etm_auxtrace *etm) >> { >> int j; >> >> - for (j = 0; j < num_cpu; j++) { >> + for (j = etm->first_cpu; j < etm->last_cpu; j++) { >> switch (metadata[j][CS_ETM_MAGIC]) { >> case __perf_cs_etmv4_magic: >> if (HAS_PARAM(j, ETMV4, TS_SOURCE) || metadata[j][CS_ETMV4_TS_SOURCE] != 1) >> @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >> } >> >> /* map trace ids to correct metadata block, from information in metadata */ >> -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) >> +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm) >> { >> u64 cs_etm_magic; >> + u64 **metadata = etm->metadata; >> u8 trace_chan_id; >> int i, err; >> >> - for (i = 0; i < num_cpu; i++) { >> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >> switch (cs_etm_magic) { >> case __perf_cs_etmv3_magic: >> @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) >> * If we found AUX_HW_ID packets, then set any metadata marked as unused to the >> * unused value to reduce the number of unneeded decoders created. >> */ >> -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **metadata) >> +static int cs_etm__clear_unused_trace_ids_metadata(struct cs_etm_auxtrace *etm) >> { >> u64 cs_etm_magic; >> + u64 **metadata = etm->metadata; >> int i; >> >> - for (i = 0; i < num_cpu; i++) { >> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >> switch (cs_etm_magic) { >> case __perf_cs_etmv3_magic: >> @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, >> int event_header_size = sizeof(struct perf_event_header); >> int total_size = auxtrace_info->header.size; >> int priv_size = 0; >> - int num_cpu; >> + int num_cpu, first_cpu = 0, last_cpu; >> int err = 0; >> int aux_hw_id_found; >> int i, j; >> @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, >> /* First the global part */ >> ptr = (u64 *) auxtrace_info->priv; >> num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; >> - metadata = zalloc(sizeof(*metadata) * num_cpu); >> + >> + /* Start parsing after the common part of the header */ >> + i = CS_HEADER_VERSION_MAX; >> + >> + /*Get CPU id of first event */ >> + first_cpu = ptr[i + CS_ETM_CPU]; >> + last_cpu = first_cpu + num_cpu; >> + >> + if (first_cpu > cpu__max_cpu().cpu || >> + last_cpu > cpu__max_cpu().cpu) >> + return -EINVAL; >> + >> + metadata = zalloc(sizeof(*metadata) * last_cpu); > > Hi Ganapatrao, > > I think I see what the problem is, but I'm wondering if a better fix > would be to further decouple the CPU ID from the index in the array. > > With your change it's not clear what happens with sparse recordings, for > example 'perf record -e cs_etm// -C 1,3,5'. And it seems like there is This patch fixes for any range of CPUs. Record with sparse list of CPUs will not work with current code still. > some wastage in the zalloc here for example if only CPU 256 is traced > then we'd still make 256 decoders but 255 of them would be unused? > > I tried to test sparse recordings, but your change doesn't apply to the > latest coresight/next branch. I did notice that 'perf report -D' doesn't > work with them on coresight/next (it just quits), but I couldn't see if > that's fixed with your change. My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches related to dynamic id [1] support(queued for 6.4). "perf report -D" works for me. [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html > > Would a better fix not be to keep the metadata loops from 0-N and > instead save the CPU ID in cs_etm_decoder_params or the decoder. That > way it would support both sparse and not starting from 0 cases? I think Yep, I though this initially, it got complicated due to for more for-loops. I will try again and post V2. > the code would be better if it's worded like "i < recorded_cpus" rather > than "i < cpu" to make it clear that i isn't actually the CPU ID it's > just an index. Yes, makes sense to call it "recorded_cpus". > > Also a new test for this scenario would probably be a good idea. > > Thanks > James > Thanks, Ganapat
On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: > > Hi James, > > On 20-04-2023 03:13 pm, James Clark wrote: >> >> >> On 19/04/2023 18:21, Ganapatrao Kulkarni wrote: >>> The current implementation supports coresight trace for a range of >>> CPUs, if the first CPU is CPU0. >>> >>> Adding changes to enable coresight trace for any range of CPUs by >>> decoding the first CPU also from the header. >>> Later, first CPU id is used instead of CPU0 across the decoder >>> functions. >>> >>> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> >>> --- >>> .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- >>> .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- >>> tools/perf/util/cs-etm.c | 62 ++++++++++++------- >>> 3 files changed, 42 insertions(+), 27 deletions(-) >>> >>> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>> b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>> index 82a27ab90c8b..41ab299b643b 100644 >>> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>> @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct >>> cs_etm_decoder_params *d_params, >>> } >>> struct cs_etm_decoder * >>> -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params >>> *d_params, >>> +cs_etm_decoder__new(int first_decoder, int decoders, struct >>> cs_etm_decoder_params *d_params, >>> struct cs_etm_trace_params t_params[]) >>> { >>> struct cs_etm_decoder *decoder; >>> @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct >>> cs_etm_decoder_params *d_params, >>> /* init raw frame logging if required */ >>> cs_etm_decoder__init_raw_frame_logging(d_params, decoder); >>> - for (i = 0; i < decoders; i++) { >>> + for (i = first_decoder; i < decoders; i++) { >>> ret = cs_etm_decoder__create_etm_decoder(d_params, >>> &t_params[i], >>> decoder); >>> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>> b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>> index 92a855fbe5b8..b06193fc75b4 100644 >>> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>> @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct >>> cs_etm_decoder *decoder, >>> size_t len, size_t *consumed); >>> struct cs_etm_decoder * >>> -cs_etm_decoder__new(int num_cpu, >>> +cs_etm_decoder__new(int first_decoder, >>> + int decoders, >>> struct cs_etm_decoder_params *d_params, >>> struct cs_etm_trace_params t_params[]); >>> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c >>> index 94e2d02009eb..2619513ae088 100644 >>> --- a/tools/perf/util/cs-etm.c >>> +++ b/tools/perf/util/cs-etm.c >>> @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { >>> u8 has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */ >>> int num_cpu; >>> + int first_cpu; >>> + int last_cpu; >>> u64 latest_kernel_timestamp; >>> u32 auxtrace_type; >>> u64 branches_sample_type; >>> @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct >>> cs_etm_trace_params *t_params, >>> } >>> static int cs_etm__init_trace_params(struct cs_etm_trace_params >>> *t_params, >>> - struct cs_etm_auxtrace *etm, >>> - int decoders) >>> + struct cs_etm_auxtrace *etm) >>> { >>> int i; >>> u32 etmidr; >>> u64 architecture; >>> - for (i = 0; i < decoders; i++) { >>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>> architecture = etm->metadata[i][CS_ETM_MAGIC]; >>> switch (architecture) { >>> @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session >>> *session) >>> /* Then the RB tree itself */ >>> intlist__delete(traceid_list); >>> - for (i = 0; i < aux->num_cpu; i++) >>> + for (i = aux->first_cpu; i < aux->last_cpu; i++) >>> zfree(&aux->metadata[i]); >>> thread__zput(aux->unknown_thread); >>> @@ -921,7 +922,8 @@ static struct cs_etm_queue >>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>> * Each queue can only contain data from one CPU when >>> unformatted, so only one decoder is >>> * needed. >>> */ >>> - int decoders = formatted ? etm->num_cpu : 1; >>> + int first_decoder = formatted ? etm->first_cpu : 0; >>> + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); >>> etmq = zalloc(sizeof(*etmq)); >>> if (!etmq) >>> @@ -937,7 +939,7 @@ static struct cs_etm_queue >>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>> if (!t_params) >>> goto out_free; >>> - if (cs_etm__init_trace_params(t_params, etm, decoders)) >>> + if (cs_etm__init_trace_params(t_params, etm)) >>> goto out_free; >>> /* Set decoder parameters to decode trace packets */ >>> @@ -947,8 +949,7 @@ static struct cs_etm_queue >>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>> formatted)) >>> goto out_free; >>> - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, >>> - t_params); >>> + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, >>> &d_params, t_params); >>> if (!etmq->decoder) >>> goto out_free; >>> @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct >>> perf_session *session) >>> * Loop through the ETMs and complain if we find at least one where >>> ts_source != 1 (virtual >>> * timestamps). >>> */ >>> -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >>> +static bool cs_etm__has_virtual_ts(u64 **metadata, struct >>> cs_etm_auxtrace *etm) >>> { >>> int j; >>> - for (j = 0; j < num_cpu; j++) { >>> + for (j = etm->first_cpu; j < etm->last_cpu; j++) { >>> switch (metadata[j][CS_ETM_MAGIC]) { >>> case __perf_cs_etmv4_magic: >>> if (HAS_PARAM(j, ETMV4, TS_SOURCE) || >>> metadata[j][CS_ETMV4_TS_SOURCE] != 1) >>> @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 >>> **metadata, int num_cpu) >>> } >>> /* map trace ids to correct metadata block, from information in >>> metadata */ >>> -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) >>> +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm) >>> { >>> u64 cs_etm_magic; >>> + u64 **metadata = etm->metadata; >>> u8 trace_chan_id; >>> int i, err; >>> - for (i = 0; i < num_cpu; i++) { >>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >>> switch (cs_etm_magic) { >>> case __perf_cs_etmv3_magic: >>> @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int >>> num_cpu, u64 **metadata) >>> * If we found AUX_HW_ID packets, then set any metadata marked as >>> unused to the >>> * unused value to reduce the number of unneeded decoders created. >>> */ >>> -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 >>> **metadata) >>> +static int cs_etm__clear_unused_trace_ids_metadata(struct >>> cs_etm_auxtrace *etm) >>> { >>> u64 cs_etm_magic; >>> + u64 **metadata = etm->metadata; >>> int i; >>> - for (i = 0; i < num_cpu; i++) { >>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >>> switch (cs_etm_magic) { >>> case __perf_cs_etmv3_magic: >>> @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union >>> perf_event *event, >>> int event_header_size = sizeof(struct perf_event_header); >>> int total_size = auxtrace_info->header.size; >>> int priv_size = 0; >>> - int num_cpu; >>> + int num_cpu, first_cpu = 0, last_cpu; >>> int err = 0; >>> int aux_hw_id_found; >>> int i, j; >>> @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union >>> perf_event *event, >>> /* First the global part */ >>> ptr = (u64 *) auxtrace_info->priv; >>> num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; >>> - metadata = zalloc(sizeof(*metadata) * num_cpu); >>> + >>> + /* Start parsing after the common part of the header */ >>> + i = CS_HEADER_VERSION_MAX; >>> + >>> + /*Get CPU id of first event */ >>> + first_cpu = ptr[i + CS_ETM_CPU]; >>> + last_cpu = first_cpu + num_cpu; >>> + >>> + if (first_cpu > cpu__max_cpu().cpu || >>> + last_cpu > cpu__max_cpu().cpu) >>> + return -EINVAL; >>> + >>> + metadata = zalloc(sizeof(*metadata) * last_cpu); >> >> Hi Ganapatrao, >> >> I think I see what the problem is, but I'm wondering if a better fix >> would be to further decouple the CPU ID from the index in the array. >> >> With your change it's not clear what happens with sparse recordings, for >> example 'perf record -e cs_etm// -C 1,3,5'. And it seems like there is > > This patch fixes for any range of CPUs. > Record with sparse list of CPUs will not work with current code still. > Is there a major issue that means sparse can't be done? I'm thinking it would be best to fix both issues with one change while we understand this part rather than a half fix that might have do be completely re-understood and re-done later anyway. Unless there is some big blocker but I can't see it? >> some wastage in the zalloc here for example if only CPU 256 is traced >> then we'd still make 256 decoders but 255 of them would be unused? >> >> I tried to test sparse recordings, but your change doesn't apply to the >> latest coresight/next branch. I did notice that 'perf report -D' doesn't >> work with them on coresight/next (it just quits), but I couldn't see if >> that's fixed with your change. > > My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches > related to dynamic id [1] support(queued for 6.4). > > "perf report -D" works for me. I was referring to sparse CPU lists, which I think you mentioned above doesn't work even with this patch. > > [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html > It should be based on the next branch here: git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git >> >> Would a better fix not be to keep the metadata loops from 0-N and >> instead save the CPU ID in cs_etm_decoder_params or the decoder. That >> way it would support both sparse and not starting from 0 cases? I think > > Yep, I though this initially, it got complicated due to for more > for-loops. I will try again and post V2. > I can't imagine it would need any extra for loops off the top of my head. Just saving the CPU ID in a few structs and using it wherever it's needed instead of the loop index. I imagine most of the loops would actually stay the same rather than be changed like you have in V1. >> the code would be better if it's worded like "i < recorded_cpus" rather >> than "i < cpu" to make it clear that i isn't actually the CPU ID it's >> just an index. > > Yes, makes sense to call it "recorded_cpus". > >> >> Also a new test for this scenario would probably be a good idea. >> >> Thanks >> James >> > Thanks, > Ganapat
On 20-04-2023 06:00 pm, James Clark wrote: > > > On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: >> >> Hi James, >> >> On 20-04-2023 03:13 pm, James Clark wrote: >>> >>> >>> On 19/04/2023 18:21, Ganapatrao Kulkarni wrote: >>>> The current implementation supports coresight trace for a range of >>>> CPUs, if the first CPU is CPU0. >>>> >>>> Adding changes to enable coresight trace for any range of CPUs by >>>> decoding the first CPU also from the header. >>>> Later, first CPU id is used instead of CPU0 across the decoder >>>> functions. >>>> >>>> Signed-off-by: Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com> >>>> --- >>>> .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- >>>> .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- >>>> tools/perf/util/cs-etm.c | 62 ++++++++++++------- >>>> 3 files changed, 42 insertions(+), 27 deletions(-) >>>> >>>> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>> b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>> index 82a27ab90c8b..41ab299b643b 100644 >>>> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>> @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct >>>> cs_etm_decoder_params *d_params, >>>> } >>>> struct cs_etm_decoder * >>>> -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params >>>> *d_params, >>>> +cs_etm_decoder__new(int first_decoder, int decoders, struct >>>> cs_etm_decoder_params *d_params, >>>> struct cs_etm_trace_params t_params[]) >>>> { >>>> struct cs_etm_decoder *decoder; >>>> @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct >>>> cs_etm_decoder_params *d_params, >>>> /* init raw frame logging if required */ >>>> cs_etm_decoder__init_raw_frame_logging(d_params, decoder); >>>> - for (i = 0; i < decoders; i++) { >>>> + for (i = first_decoder; i < decoders; i++) { >>>> ret = cs_etm_decoder__create_etm_decoder(d_params, >>>> &t_params[i], >>>> decoder); >>>> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>> b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>> index 92a855fbe5b8..b06193fc75b4 100644 >>>> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>> @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct >>>> cs_etm_decoder *decoder, >>>> size_t len, size_t *consumed); >>>> struct cs_etm_decoder * >>>> -cs_etm_decoder__new(int num_cpu, >>>> +cs_etm_decoder__new(int first_decoder, >>>> + int decoders, >>>> struct cs_etm_decoder_params *d_params, >>>> struct cs_etm_trace_params t_params[]); >>>> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c >>>> index 94e2d02009eb..2619513ae088 100644 >>>> --- a/tools/perf/util/cs-etm.c >>>> +++ b/tools/perf/util/cs-etm.c >>>> @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { >>>> u8 has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */ >>>> int num_cpu; >>>> + int first_cpu; >>>> + int last_cpu; >>>> u64 latest_kernel_timestamp; >>>> u32 auxtrace_type; >>>> u64 branches_sample_type; >>>> @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct >>>> cs_etm_trace_params *t_params, >>>> } >>>> static int cs_etm__init_trace_params(struct cs_etm_trace_params >>>> *t_params, >>>> - struct cs_etm_auxtrace *etm, >>>> - int decoders) >>>> + struct cs_etm_auxtrace *etm) >>>> { >>>> int i; >>>> u32 etmidr; >>>> u64 architecture; >>>> - for (i = 0; i < decoders; i++) { >>>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>>> architecture = etm->metadata[i][CS_ETM_MAGIC]; >>>> switch (architecture) { >>>> @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session >>>> *session) >>>> /* Then the RB tree itself */ >>>> intlist__delete(traceid_list); >>>> - for (i = 0; i < aux->num_cpu; i++) >>>> + for (i = aux->first_cpu; i < aux->last_cpu; i++) >>>> zfree(&aux->metadata[i]); >>>> thread__zput(aux->unknown_thread); >>>> @@ -921,7 +922,8 @@ static struct cs_etm_queue >>>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>>> * Each queue can only contain data from one CPU when >>>> unformatted, so only one decoder is >>>> * needed. >>>> */ >>>> - int decoders = formatted ? etm->num_cpu : 1; >>>> + int first_decoder = formatted ? etm->first_cpu : 0; >>>> + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); >>>> etmq = zalloc(sizeof(*etmq)); >>>> if (!etmq) >>>> @@ -937,7 +939,7 @@ static struct cs_etm_queue >>>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>>> if (!t_params) >>>> goto out_free; >>>> - if (cs_etm__init_trace_params(t_params, etm, decoders)) >>>> + if (cs_etm__init_trace_params(t_params, etm)) >>>> goto out_free; >>>> /* Set decoder parameters to decode trace packets */ >>>> @@ -947,8 +949,7 @@ static struct cs_etm_queue >>>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>>> formatted)) >>>> goto out_free; >>>> - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, >>>> - t_params); >>>> + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, >>>> &d_params, t_params); >>>> if (!etmq->decoder) >>>> goto out_free; >>>> @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct >>>> perf_session *session) >>>> * Loop through the ETMs and complain if we find at least one where >>>> ts_source != 1 (virtual >>>> * timestamps). >>>> */ >>>> -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >>>> +static bool cs_etm__has_virtual_ts(u64 **metadata, struct >>>> cs_etm_auxtrace *etm) >>>> { >>>> int j; >>>> - for (j = 0; j < num_cpu; j++) { >>>> + for (j = etm->first_cpu; j < etm->last_cpu; j++) { >>>> switch (metadata[j][CS_ETM_MAGIC]) { >>>> case __perf_cs_etmv4_magic: >>>> if (HAS_PARAM(j, ETMV4, TS_SOURCE) || >>>> metadata[j][CS_ETMV4_TS_SOURCE] != 1) >>>> @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 >>>> **metadata, int num_cpu) >>>> } >>>> /* map trace ids to correct metadata block, from information in >>>> metadata */ >>>> -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) >>>> +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm) >>>> { >>>> u64 cs_etm_magic; >>>> + u64 **metadata = etm->metadata; >>>> u8 trace_chan_id; >>>> int i, err; >>>> - for (i = 0; i < num_cpu; i++) { >>>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>>> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >>>> switch (cs_etm_magic) { >>>> case __perf_cs_etmv3_magic: >>>> @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int >>>> num_cpu, u64 **metadata) >>>> * If we found AUX_HW_ID packets, then set any metadata marked as >>>> unused to the >>>> * unused value to reduce the number of unneeded decoders created. >>>> */ >>>> -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 >>>> **metadata) >>>> +static int cs_etm__clear_unused_trace_ids_metadata(struct >>>> cs_etm_auxtrace *etm) >>>> { >>>> u64 cs_etm_magic; >>>> + u64 **metadata = etm->metadata; >>>> int i; >>>> - for (i = 0; i < num_cpu; i++) { >>>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>>> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >>>> switch (cs_etm_magic) { >>>> case __perf_cs_etmv3_magic: >>>> @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union >>>> perf_event *event, >>>> int event_header_size = sizeof(struct perf_event_header); >>>> int total_size = auxtrace_info->header.size; >>>> int priv_size = 0; >>>> - int num_cpu; >>>> + int num_cpu, first_cpu = 0, last_cpu; >>>> int err = 0; >>>> int aux_hw_id_found; >>>> int i, j; >>>> @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union >>>> perf_event *event, >>>> /* First the global part */ >>>> ptr = (u64 *) auxtrace_info->priv; >>>> num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; >>>> - metadata = zalloc(sizeof(*metadata) * num_cpu); >>>> + >>>> + /* Start parsing after the common part of the header */ >>>> + i = CS_HEADER_VERSION_MAX; >>>> + >>>> + /*Get CPU id of first event */ >>>> + first_cpu = ptr[i + CS_ETM_CPU]; >>>> + last_cpu = first_cpu + num_cpu; >>>> + >>>> + if (first_cpu > cpu__max_cpu().cpu || >>>> + last_cpu > cpu__max_cpu().cpu) >>>> + return -EINVAL; >>>> + >>>> + metadata = zalloc(sizeof(*metadata) * last_cpu); >>> >>> Hi Ganapatrao, >>> >>> I think I see what the problem is, but I'm wondering if a better fix >>> would be to further decouple the CPU ID from the index in the array. >>> >>> With your change it's not clear what happens with sparse recordings, for >>> example 'perf record -e cs_etm// -C 1,3,5'. And it seems like there is >> >> This patch fixes for any range of CPUs. >> Record with sparse list of CPUs will not work with current code still. >> > > Is there a major issue that means sparse can't be done? I'm thinking it > would be best to fix both issues with one change while we understand > this part rather than a half fix that might have do be completely > re-understood and re-done later anyway. Unless there is some big blocker > but I can't see it? > >>> some wastage in the zalloc here for example if only CPU 256 is traced >>> then we'd still make 256 decoders but 255 of them would be unused? >>> >>> I tried to test sparse recordings, but your change doesn't apply to the >>> latest coresight/next branch. I did notice that 'perf report -D' doesn't >>> work with them on coresight/next (it just quits), but I couldn't see if >>> that's fixed with your change. >> >> My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches >> related to dynamic id [1] support(queued for 6.4). >> >> "perf report -D" works for me. > > I was referring to sparse CPU lists, which I think you mentioned above > doesn't work even with this patch. > >> >> [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html >> > > It should be based on the next branch here: > git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git OK. > >>> >>> Would a better fix not be to keep the metadata loops from 0-N and >>> instead save the CPU ID in cs_etm_decoder_params or the decoder. That >>> way it would support both sparse and not starting from 0 cases? I think >> >> Yep, I though this initially, it got complicated due to for more >> for-loops. I will try again and post V2. >> > > I can't imagine it would need any extra for loops off the top of my > head. Just saving the CPU ID in a few structs and using it wherever it's > needed instead of the loop index. I imagine most of the loops would > actually stay the same rather than be changed like you have in V1. Working on V2, I will post it at the earliest. > >>> the code would be better if it's worded like "i < recorded_cpus" rather >>> than "i < cpu" to make it clear that i isn't actually the CPU ID it's >>> just an index. >> >> Yes, makes sense to call it "recorded_cpus". >> >>> >>> Also a new test for this scenario would probably be a good idea. >>> >>> Thanks >>> James >>> >> Thanks, >> Ganapat Thanks, Ganapat
On 20/04/2023 13:37, Ganapatrao Kulkarni wrote: > > > On 20-04-2023 06:00 pm, James Clark wrote: >> >> >> On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: >>> ... >>> My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches >>> related to dynamic id [1] support(queued for 6.4). >>> >>> "perf report -D" works for me. >> >> I was referring to sparse CPU lists, which I think you mentioned above >> doesn't work even with this patch. >> >>> >>> [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html >>> >> >> It should be based on the next branch here: >> git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git > > OK. It need not be. Since this patch is purely perf tools patch and has nothing to do with the kernel drivers, it should be beased on whatever the tip of the perf tool tree is. Otherwise we risk rebasing to that eventually. Cheers Suzuki
Hi James, On 20-04-2023 06:07 pm, Ganapatrao Kulkarni wrote: > > > On 20-04-2023 06:00 pm, James Clark wrote: >> >> >> On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: >>> >>> Hi James, >>> >>> On 20-04-2023 03:13 pm, James Clark wrote: >>>> >>>> >>>> On 19/04/2023 18:21, Ganapatrao Kulkarni wrote: >>>>> The current implementation supports coresight trace for a range of >>>>> CPUs, if the first CPU is CPU0. >>>>> >>>>> Adding changes to enable coresight trace for any range of CPUs by >>>>> decoding the first CPU also from the header. >>>>> Later, first CPU id is used instead of CPU0 across the decoder >>>>> functions. >>>>> >>>>> Signed-off-by: Ganapatrao Kulkarni >>>>> <gankulkarni@os.amperecomputing.com> >>>>> --- >>>>> .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- >>>>> .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- >>>>> tools/perf/util/cs-etm.c | 62 >>>>> ++++++++++++------- >>>>> 3 files changed, 42 insertions(+), 27 deletions(-) >>>>> >>>>> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>>> b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>>> index 82a27ab90c8b..41ab299b643b 100644 >>>>> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>>> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c >>>>> @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct >>>>> cs_etm_decoder_params *d_params, >>>>> } >>>>> struct cs_etm_decoder * >>>>> -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params >>>>> *d_params, >>>>> +cs_etm_decoder__new(int first_decoder, int decoders, struct >>>>> cs_etm_decoder_params *d_params, >>>>> struct cs_etm_trace_params t_params[]) >>>>> { >>>>> struct cs_etm_decoder *decoder; >>>>> @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct >>>>> cs_etm_decoder_params *d_params, >>>>> /* init raw frame logging if required */ >>>>> cs_etm_decoder__init_raw_frame_logging(d_params, decoder); >>>>> - for (i = 0; i < decoders; i++) { >>>>> + for (i = first_decoder; i < decoders; i++) { >>>>> ret = cs_etm_decoder__create_etm_decoder(d_params, >>>>> &t_params[i], >>>>> decoder); >>>>> diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>>> b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>>> index 92a855fbe5b8..b06193fc75b4 100644 >>>>> --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>>> +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h >>>>> @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct >>>>> cs_etm_decoder *decoder, >>>>> size_t len, size_t *consumed); >>>>> struct cs_etm_decoder * >>>>> -cs_etm_decoder__new(int num_cpu, >>>>> +cs_etm_decoder__new(int first_decoder, >>>>> + int decoders, >>>>> struct cs_etm_decoder_params *d_params, >>>>> struct cs_etm_trace_params t_params[]); >>>>> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c >>>>> index 94e2d02009eb..2619513ae088 100644 >>>>> --- a/tools/perf/util/cs-etm.c >>>>> +++ b/tools/perf/util/cs-etm.c >>>>> @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { >>>>> u8 has_virtual_ts; /* Virtual/Kernel timestamps in the >>>>> trace. */ >>>>> int num_cpu; >>>>> + int first_cpu; >>>>> + int last_cpu; >>>>> u64 latest_kernel_timestamp; >>>>> u32 auxtrace_type; >>>>> u64 branches_sample_type; >>>>> @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct >>>>> cs_etm_trace_params *t_params, >>>>> } >>>>> static int cs_etm__init_trace_params(struct cs_etm_trace_params >>>>> *t_params, >>>>> - struct cs_etm_auxtrace *etm, >>>>> - int decoders) >>>>> + struct cs_etm_auxtrace *etm) >>>>> { >>>>> int i; >>>>> u32 etmidr; >>>>> u64 architecture; >>>>> - for (i = 0; i < decoders; i++) { >>>>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>>>> architecture = etm->metadata[i][CS_ETM_MAGIC]; >>>>> switch (architecture) { >>>>> @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session >>>>> *session) >>>>> /* Then the RB tree itself */ >>>>> intlist__delete(traceid_list); >>>>> - for (i = 0; i < aux->num_cpu; i++) >>>>> + for (i = aux->first_cpu; i < aux->last_cpu; i++) >>>>> zfree(&aux->metadata[i]); >>>>> thread__zput(aux->unknown_thread); >>>>> @@ -921,7 +922,8 @@ static struct cs_etm_queue >>>>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>>>> * Each queue can only contain data from one CPU when >>>>> unformatted, so only one decoder is >>>>> * needed. >>>>> */ >>>>> - int decoders = formatted ? etm->num_cpu : 1; >>>>> + int first_decoder = formatted ? etm->first_cpu : 0; >>>>> + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); >>>>> etmq = zalloc(sizeof(*etmq)); >>>>> if (!etmq) >>>>> @@ -937,7 +939,7 @@ static struct cs_etm_queue >>>>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>>>> if (!t_params) >>>>> goto out_free; >>>>> - if (cs_etm__init_trace_params(t_params, etm, decoders)) >>>>> + if (cs_etm__init_trace_params(t_params, etm)) >>>>> goto out_free; >>>>> /* Set decoder parameters to decode trace packets */ >>>>> @@ -947,8 +949,7 @@ static struct cs_etm_queue >>>>> *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, >>>>> formatted)) >>>>> goto out_free; >>>>> - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, >>>>> - t_params); >>>>> + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, >>>>> &d_params, t_params); >>>>> if (!etmq->decoder) >>>>> goto out_free; >>>>> @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct >>>>> perf_session *session) >>>>> * Loop through the ETMs and complain if we find at least one where >>>>> ts_source != 1 (virtual >>>>> * timestamps). >>>>> */ >>>>> -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) >>>>> +static bool cs_etm__has_virtual_ts(u64 **metadata, struct >>>>> cs_etm_auxtrace *etm) >>>>> { >>>>> int j; >>>>> - for (j = 0; j < num_cpu; j++) { >>>>> + for (j = etm->first_cpu; j < etm->last_cpu; j++) { >>>>> switch (metadata[j][CS_ETM_MAGIC]) { >>>>> case __perf_cs_etmv4_magic: >>>>> if (HAS_PARAM(j, ETMV4, TS_SOURCE) || >>>>> metadata[j][CS_ETMV4_TS_SOURCE] != 1) >>>>> @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 >>>>> **metadata, int num_cpu) >>>>> } >>>>> /* map trace ids to correct metadata block, from information in >>>>> metadata */ >>>>> -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 >>>>> **metadata) >>>>> +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace >>>>> *etm) >>>>> { >>>>> u64 cs_etm_magic; >>>>> + u64 **metadata = etm->metadata; >>>>> u8 trace_chan_id; >>>>> int i, err; >>>>> - for (i = 0; i < num_cpu; i++) { >>>>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>>>> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >>>>> switch (cs_etm_magic) { >>>>> case __perf_cs_etmv3_magic: >>>>> @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int >>>>> num_cpu, u64 **metadata) >>>>> * If we found AUX_HW_ID packets, then set any metadata marked as >>>>> unused to the >>>>> * unused value to reduce the number of unneeded decoders created. >>>>> */ >>>>> -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 >>>>> **metadata) >>>>> +static int cs_etm__clear_unused_trace_ids_metadata(struct >>>>> cs_etm_auxtrace *etm) >>>>> { >>>>> u64 cs_etm_magic; >>>>> + u64 **metadata = etm->metadata; >>>>> int i; >>>>> - for (i = 0; i < num_cpu; i++) { >>>>> + for (i = etm->first_cpu; i < etm->last_cpu; i++) { >>>>> cs_etm_magic = metadata[i][CS_ETM_MAGIC]; >>>>> switch (cs_etm_magic) { >>>>> case __perf_cs_etmv3_magic: >>>>> @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union >>>>> perf_event *event, >>>>> int event_header_size = sizeof(struct perf_event_header); >>>>> int total_size = auxtrace_info->header.size; >>>>> int priv_size = 0; >>>>> - int num_cpu; >>>>> + int num_cpu, first_cpu = 0, last_cpu; >>>>> int err = 0; >>>>> int aux_hw_id_found; >>>>> int i, j; >>>>> @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union >>>>> perf_event *event, >>>>> /* First the global part */ >>>>> ptr = (u64 *) auxtrace_info->priv; >>>>> num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; >>>>> - metadata = zalloc(sizeof(*metadata) * num_cpu); >>>>> + >>>>> + /* Start parsing after the common part of the header */ >>>>> + i = CS_HEADER_VERSION_MAX; >>>>> + >>>>> + /*Get CPU id of first event */ >>>>> + first_cpu = ptr[i + CS_ETM_CPU]; >>>>> + last_cpu = first_cpu + num_cpu; >>>>> + >>>>> + if (first_cpu > cpu__max_cpu().cpu || >>>>> + last_cpu > cpu__max_cpu().cpu) >>>>> + return -EINVAL; >>>>> + >>>>> + metadata = zalloc(sizeof(*metadata) * last_cpu); >>>> >>>> Hi Ganapatrao, >>>> >>>> I think I see what the problem is, but I'm wondering if a better fix >>>> would be to further decouple the CPU ID from the index in the array. >>>> >>>> With your change it's not clear what happens with sparse recordings, >>>> for >>>> example 'perf record -e cs_etm// -C 1,3,5'. And it seems like there is >>> >>> This patch fixes for any range of CPUs. >>> Record with sparse list of CPUs will not work with current code still. >>> >> >> Is there a major issue that means sparse can't be done? I'm thinking it >> would be best to fix both issues with one change while we understand >> this part rather than a half fix that might have do be completely >> re-understood and re-done later anyway. Unless there is some big blocker >> but I can't see it? >> >>>> some wastage in the zalloc here for example if only CPU 256 is traced >>>> then we'd still make 256 decoders but 255 of them would be unused? >>>> >>>> I tried to test sparse recordings, but your change doesn't apply to the >>>> latest coresight/next branch. I did notice that 'perf report -D' >>>> doesn't >>>> work with them on coresight/next (it just quits), but I couldn't see if >>>> that's fixed with your change. >>> >>> My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches >>> related to dynamic id [1] support(queued for 6.4). >>> >>> "perf report -D" works for me. >> >> I was referring to sparse CPU lists, which I think you mentioned above >> doesn't work even with this patch. >> >>> >>> [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html >>> >> >> It should be based on the next branch here: >> git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git > > OK. >> >>>> >>>> Would a better fix not be to keep the metadata loops from 0-N and >>>> instead save the CPU ID in cs_etm_decoder_params or the decoder. That >>>> way it would support both sparse and not starting from 0 cases? I think >>> >>> Yep, I though this initially, it got complicated due to for more >>> for-loops. I will try again and post V2. >>> >> >> I can't imagine it would need any extra for loops off the top of my >> head. Just saving the CPU ID in a few structs and using it wherever it's >> needed instead of the loop index. I imagine most of the loops would >> actually stay the same rather than be changed like you have in V1. > > Working on V2, I will post it at the earliest. My codebase is "6.3-RC7 + Mike's patche[1] + Anshuman/Suzuki patches[3]" and below diff works for any CPU range and sparse list as well. I will send the V2 ASAP. [root@B0-213 perf]# git diff diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 94e2d02009eb..bfed0bb8be98 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -274,6 +274,22 @@ static int cs_etm__metadata_set_trace_id(u8 trace_chan_id, u64 *cpu_metadata) (typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \ }) + +static u64 *get_cpu_data(struct cs_etm_auxtrace *etm, int cpu) +{ + int i; + u64 *metadata = NULL; + + for (i = 0; i < etm->num_cpu; i++) { + if (etm->metadata[i][CS_ETM_CPU] == (u64)cpu) { + metadata = etm->metadata[i]; + break; + } + } + + return metadata; +} + /* * Handle the PERF_RECORD_AUX_OUTPUT_HW_ID event. * @@ -344,7 +360,7 @@ static int cs_etm__process_aux_output_hw_id(struct perf_session *session, } /* not one we've seen before - lets map it */ - cpu_data = etm->metadata[cpu]; + cpu_data = get_cpu_data(etm, cpu); err = cs_etm__map_trace_id(trace_chan_id, cpu_data); if (err) return err; I tried below commands and works well with this diff. timeout 8s ./perf record -e cs_etm// -C 0 dd if=/dev/zero of=/dev/null timeout 8s ./perf record -e cs_etm// -C 1 dd if=/dev/zero of=/dev/null timeout 8s ./perf record -e cs_etm// -C 1,3,5 dd if=/dev/zero of=/dev/null timeout 8s ./perf record -e cs_etm// -C 10,3,12 dd if=/dev/zero of=/dev/null timeout 8s ./perf record -e cs_etm//u -C 0-10 dd if=/dev/zero of=/dev/null timeout 8s ./perf record -e cs_etm//u -C 10-20 dd if=/dev/zero of=/dev/nu However I could not be able to apply to next branch of coresight repo git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git Then I looked at the code, it does not have Mike's dynamic ID patches[1] which are merged to perf/next. It seems the code is not the latest or it is next for coresight driver only. I think either patch should be rebased to most-recent kernel RC1/RCx(which I did) or perf-tools-next of [2] for perf tool. [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html [2] git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git [3] https://www.spinics.net/lists/arm-kernel/msg1059012.html >> >>>> the code would be better if it's worded like "i < recorded_cpus" rather >>>> than "i < cpu" to make it clear that i isn't actually the CPU ID it's >>>> just an index. >>> >>> Yes, makes sense to call it "recorded_cpus". >>> >>>> >>>> Also a new test for this scenario would probably be a good idea. >>>> >>>> Thanks >>>> James >>>> >>> Thanks, >>> Ganapat > > Thanks, > Ganapat Thanks, Ganapat
On 20/04/2023 14:03, Suzuki K Poulose wrote: > On 20/04/2023 13:37, Ganapatrao Kulkarni wrote: >> >> >> On 20-04-2023 06:00 pm, James Clark wrote: >>> >>> >>> On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: >>>> > > ... > >>>> My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches >>>> related to dynamic id [1] support(queued for 6.4). >>>> >>>> "perf report -D" works for me. >>> >>> I was referring to sparse CPU lists, which I think you mentioned above >>> doesn't work even with this patch. >>> >>>> >>>> [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html >>>> >>> >>> It should be based on the next branch here: >>> git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git >> >> OK. > > It need not be. Since this patch is purely perf tools patch and has > nothing to do with the kernel drivers, it should be beased on whatever > the tip of the perf tool tree is. Otherwise we risk rebasing to that > eventually. > > Cheers > Suzuki > Good point, sorry for the confusion! I wonder if we could have some kind of new staging branch that has both up to date perf and coresight changes at the same time? Either that would make things like this easier, or more complicated. I'm not sure. I suppose I can DIY it quite easily but then everyone would have to as well. James
Em Thu, Apr 20, 2023 at 04:44:21PM +0100, James Clark escreveu: > On 20/04/2023 14:03, Suzuki K Poulose wrote: > > On 20/04/2023 13:37, Ganapatrao Kulkarni wrote: > >> On 20-04-2023 06:00 pm, James Clark wrote: > >>> On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: > >>>> My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches > >>>> related to dynamic id [1] support(queued for 6.4). > >>>> "perf report -D" works for me. > >>> I was referring to sparse CPU lists, which I think you mentioned above > >>> doesn't work even with this patch. > >>>> [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html > >>> It should be based on the next branch here: > >>> git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git > >> OK. > > It need not be. Since this patch is purely perf tools patch and has > > nothing to do with the kernel drivers, it should be beased on whatever > > the tip of the perf tool tree is. Otherwise we risk rebasing to that > > eventually. > Good point, sorry for the confusion! > I wonder if we could have some kind of new staging branch that has both > up to date perf and coresight changes at the same time? Either that > would make things like this easier, or more complicated. I'm not sure. > I suppose I can DIY it quite easily but then everyone would have to as well. My two cents: It this was available together with a CI that would run 'perf test' + 'make -C tools/perf build-test' and any other set of tests, that would be great. But not having it also has an advantage: no lockstep development, tooling should gracefully work with whatever is available. I say this because it is a really common theme, even Debian had a packaging scheme that shoehorned (forcefully fused?) perf's and the kernel's version :-\ - Arnaldo
On 20/04/2023 16:44, James Clark wrote: > > > On 20/04/2023 14:03, Suzuki K Poulose wrote: >> On 20/04/2023 13:37, Ganapatrao Kulkarni wrote: >>> >>> >>> On 20-04-2023 06:00 pm, James Clark wrote: >>>> >>>> >>>> On 20/04/2023 12:47, Ganapatrao Kulkarni wrote: >>>>> >> >> ... >> >>>>> My patch is rebased on 6.3-RC7 codebase with Mike's 3 perf patches >>>>> related to dynamic id [1] support(queued for 6.4). >>>>> >>>>> "perf report -D" works for me. >>>> >>>> I was referring to sparse CPU lists, which I think you mentioned above >>>> doesn't work even with this patch. >>>> >>>>> >>>>> [1] https://www.spinics.net/lists/linux-perf-users/msg27452.html >>>>> >>>> >>>> It should be based on the next branch here: >>>> git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux.git >>> >>> OK. >> >> It need not be. Since this patch is purely perf tools patch and has >> nothing to do with the kernel drivers, it should be beased on whatever >> the tip of the perf tool tree is. Otherwise we risk rebasing to that >> eventually. >> >> Cheers >> Suzuki >> > > Good point, sorry for the confusion! > > I wonder if we could have some kind of new staging branch that has both > up to date perf and coresight changes at the same time? Either that > would make things like this easier, or more complicated. I'm not sure. I agree that it is complicated. :-( We could do something about this if a situation arises in the future, where the kernel and perf patches are out of sync w.r.t merging. As, such the dependency on Anshuman's series is for ACPI support which Ampere system needs. I would let this one pass, given the merge window is too close. Thanks Suzuki
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 82a27ab90c8b..41ab299b643b 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -724,7 +724,7 @@ cs_etm_decoder__create_etm_decoder(struct cs_etm_decoder_params *d_params, } struct cs_etm_decoder * -cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, +cs_etm_decoder__new(int first_decoder, int decoders, struct cs_etm_decoder_params *d_params, struct cs_etm_trace_params t_params[]) { struct cs_etm_decoder *decoder; @@ -769,7 +769,7 @@ cs_etm_decoder__new(int decoders, struct cs_etm_decoder_params *d_params, /* init raw frame logging if required */ cs_etm_decoder__init_raw_frame_logging(d_params, decoder); - for (i = 0; i < decoders; i++) { + for (i = first_decoder; i < decoders; i++) { ret = cs_etm_decoder__create_etm_decoder(d_params, &t_params[i], decoder); diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index 92a855fbe5b8..b06193fc75b4 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -90,7 +90,8 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, size_t len, size_t *consumed); struct cs_etm_decoder * -cs_etm_decoder__new(int num_cpu, +cs_etm_decoder__new(int first_decoder, + int decoders, struct cs_etm_decoder_params *d_params, struct cs_etm_trace_params t_params[]); diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 94e2d02009eb..2619513ae088 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -55,6 +55,8 @@ struct cs_etm_auxtrace { u8 has_virtual_ts; /* Virtual/Kernel timestamps in the trace. */ int num_cpu; + int first_cpu; + int last_cpu; u64 latest_kernel_timestamp; u32 auxtrace_type; u64 branches_sample_type; @@ -638,14 +640,13 @@ static void cs_etm__set_trace_param_ete(struct cs_etm_trace_params *t_params, } static int cs_etm__init_trace_params(struct cs_etm_trace_params *t_params, - struct cs_etm_auxtrace *etm, - int decoders) + struct cs_etm_auxtrace *etm) { int i; u32 etmidr; u64 architecture; - for (i = 0; i < decoders; i++) { + for (i = etm->first_cpu; i < etm->last_cpu; i++) { architecture = etm->metadata[i][CS_ETM_MAGIC]; switch (architecture) { @@ -817,7 +818,7 @@ static void cs_etm__free(struct perf_session *session) /* Then the RB tree itself */ intlist__delete(traceid_list); - for (i = 0; i < aux->num_cpu; i++) + for (i = aux->first_cpu; i < aux->last_cpu; i++) zfree(&aux->metadata[i]); thread__zput(aux->unknown_thread); @@ -921,7 +922,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, * Each queue can only contain data from one CPU when unformatted, so only one decoder is * needed. */ - int decoders = formatted ? etm->num_cpu : 1; + int first_decoder = formatted ? etm->first_cpu : 0; + int decoders = first_decoder + (formatted ? etm->num_cpu : 1); etmq = zalloc(sizeof(*etmq)); if (!etmq) @@ -937,7 +939,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, if (!t_params) goto out_free; - if (cs_etm__init_trace_params(t_params, etm, decoders)) + if (cs_etm__init_trace_params(t_params, etm)) goto out_free; /* Set decoder parameters to decode trace packets */ @@ -947,8 +949,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, formatted)) goto out_free; - etmq->decoder = cs_etm_decoder__new(decoders, &d_params, - t_params); + etmq->decoder = cs_etm_decoder__new(first_decoder, decoders, &d_params, t_params); if (!etmq->decoder) goto out_free; @@ -2959,11 +2960,11 @@ static int cs_etm__queue_aux_records(struct perf_session *session) * Loop through the ETMs and complain if we find at least one where ts_source != 1 (virtual * timestamps). */ -static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) +static bool cs_etm__has_virtual_ts(u64 **metadata, struct cs_etm_auxtrace *etm) { int j; - for (j = 0; j < num_cpu; j++) { + for (j = etm->first_cpu; j < etm->last_cpu; j++) { switch (metadata[j][CS_ETM_MAGIC]) { case __perf_cs_etmv4_magic: if (HAS_PARAM(j, ETMV4, TS_SOURCE) || metadata[j][CS_ETMV4_TS_SOURCE] != 1) @@ -2982,13 +2983,14 @@ static bool cs_etm__has_virtual_ts(u64 **metadata, int num_cpu) } /* map trace ids to correct metadata block, from information in metadata */ -static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) +static int cs_etm__map_trace_ids_metadata(struct cs_etm_auxtrace *etm) { u64 cs_etm_magic; + u64 **metadata = etm->metadata; u8 trace_chan_id; int i, err; - for (i = 0; i < num_cpu; i++) { + for (i = etm->first_cpu; i < etm->last_cpu; i++) { cs_etm_magic = metadata[i][CS_ETM_MAGIC]; switch (cs_etm_magic) { case __perf_cs_etmv3_magic: @@ -3015,12 +3017,13 @@ static int cs_etm__map_trace_ids_metadata(int num_cpu, u64 **metadata) * If we found AUX_HW_ID packets, then set any metadata marked as unused to the * unused value to reduce the number of unneeded decoders created. */ -static int cs_etm__clear_unused_trace_ids_metadata(int num_cpu, u64 **metadata) +static int cs_etm__clear_unused_trace_ids_metadata(struct cs_etm_auxtrace *etm) { u64 cs_etm_magic; + u64 **metadata = etm->metadata; int i; - for (i = 0; i < num_cpu; i++) { + for (i = etm->first_cpu; i < etm->last_cpu; i++) { cs_etm_magic = metadata[i][CS_ETM_MAGIC]; switch (cs_etm_magic) { case __perf_cs_etmv3_magic: @@ -3049,7 +3052,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, int event_header_size = sizeof(struct perf_event_header); int total_size = auxtrace_info->header.size; int priv_size = 0; - int num_cpu; + int num_cpu, first_cpu = 0, last_cpu; int err = 0; int aux_hw_id_found; int i, j; @@ -3068,22 +3071,31 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, /* First the global part */ ptr = (u64 *) auxtrace_info->priv; num_cpu = ptr[CS_PMU_TYPE_CPUS] & 0xffffffff; - metadata = zalloc(sizeof(*metadata) * num_cpu); + + /* Start parsing after the common part of the header */ + i = CS_HEADER_VERSION_MAX; + + /*Get CPU id of first event */ + first_cpu = ptr[i + CS_ETM_CPU]; + last_cpu = first_cpu + num_cpu; + + if (first_cpu > cpu__max_cpu().cpu || + last_cpu > cpu__max_cpu().cpu) + return -EINVAL; + + metadata = zalloc(sizeof(*metadata) * last_cpu); if (!metadata) { err = -ENOMEM; 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 * required by the trace decoder to properly decode the trace due * to its highly compressed nature. */ - for (j = 0; j < num_cpu; j++) { + for (j = first_cpu; j < last_cpu; j++) { if (ptr[i] == __perf_cs_etmv3_magic) { metadata[j] = cs_etm__create_meta_blk(ptr, &i, @@ -3145,6 +3157,8 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, etm->machine = &session->machines.host; etm->num_cpu = num_cpu; + etm->first_cpu = first_cpu; + etm->last_cpu = last_cpu; etm->pmu_type = (unsigned int) ((ptr[CS_PMU_TYPE_CPUS] >> 32) & 0xffffffff); etm->snapshot_mode = (ptr[CS_ETM_SNAPSHOT] != 0); etm->metadata = metadata; @@ -3152,7 +3166,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, etm->timeless_decoding = cs_etm__is_timeless_decoding(etm); /* Use virtual timestamps if all ETMs report ts_source = 1 */ - etm->has_virtual_ts = cs_etm__has_virtual_ts(metadata, num_cpu); + etm->has_virtual_ts = cs_etm__has_virtual_ts(metadata, etm); if (!etm->has_virtual_ts) ui__warning("Virtual timestamps are not enabled, or not supported by the traced system.\n" @@ -3232,10 +3246,10 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, /* if HW ID found then clear any unused metadata ID values */ if (aux_hw_id_found) - err = cs_etm__clear_unused_trace_ids_metadata(num_cpu, metadata); + err = cs_etm__clear_unused_trace_ids_metadata(etm); /* otherwise, this is a file with metadata values only, map from metadata */ else - err = cs_etm__map_trace_ids_metadata(num_cpu, metadata); + err = cs_etm__map_trace_ids_metadata(etm); if (err) goto err_delete_thread; @@ -3256,7 +3270,7 @@ int cs_etm__process_auxtrace_info_full(union perf_event *event, zfree(&etm); err_free_metadata: /* No need to check @metadata[j], free(NULL) is supported */ - for (j = 0; j < num_cpu; j++) + for (j = first_cpu; j < last_cpu; j++) zfree(&metadata[j]); zfree(&metadata); err_free_traceid_list: