From patchwork Mon Aug 26 07:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joakim Zhang X-Patchwork-Id: 11114191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E83F914DB for ; Mon, 26 Aug 2019 07:34:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF9A22087E for ; Mon, 26 Aug 2019 07:34:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EDN3JnWo"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="bkwOryGN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF9A22087E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To: References:Message-ID:Date:Subject:To:From:Reply-To:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qVuqE/42on/fFItDEzWClHs7BxeY9N44sJKUR79nZYE=; b=EDN3JnWoDYIVR7 p4iDmsUd0XNmhb7cypoiiwZw12POrAlcdQ9dWVdBVFovRjIsV8Spn398SSzmyiZQgZN6Pk8khj5mI /GmZxwSGESfV8hlNYZU1+KqvI0huW1o8vSGMGW8uOyOiQkd0maG40TE9m5k8RMTQHAWUBD44atFKR 7Ogkm5SO7J/d4uldBZFn51PmEBBrwHMyucUmePelMGJFAOIUnKhKBrAZr8Hv7hKCjP8K+aae8rYaB BEahkogTytiCOdvgUER177Wp/QnpnLjj/XSvOTuLG00SUcGYDvI/d30I5BD/PuKExnuIoVhXiZgRl tijylFN6lsY/lfM9LdIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i29WL-0007Yw-Td; Mon, 26 Aug 2019 07:34:34 +0000 Received: from mail-eopbgr20081.outbound.protection.outlook.com ([40.107.2.81] helo=EUR02-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i29W8-0007Jp-6d for linux-arm-kernel@lists.infradead.org; Mon, 26 Aug 2019 07:34:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PDH8e6haj2p7uDvO15wa1pzdfInC/OBsf3bTtNU4FnUpZ0mL2y1TlztsGt3WhRzXaJdaVaQ0d4OsrQlvl43fVv/FFwwsBhF93yQykf+oHylSgO4LKTDdPmH5LWHV5cQDfVl2WCU8PJ28gAm9TZaEmHMZ3f7xHG2/uzNcrebGvTtMKKo7RRrTOtCCuwHpk0ENxl/uuzBNuD9ZYzlA21I7uVln8KkxFWoa4QF/hbbii0hHxulVNaqAs/IrSeyRbvoQJwNsVmLHHE+r0SEe3WiAdu6gA4sl9XNHKJIDAxOb2j71Jvqiv5gAhfumYBwXBSuzHN3jlIqPkS8L3o21ZD4lng== 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-SenderADCheck; bh=vwGnm0ZY4n+qTU7ZJMZ5yBdjkaXnrIzKpgzUHDpcXh8=; b=Wv+JsrV3PxWwzhkLNmF0QMdYPMQGZ3XMHAwzeEHA6cTq3JpV7jrUJ2VIARG66GMiUFCjEf/O/Iok7Udb6PWzMdniIT2n6gjBtXt5FGt/UZJ4EsYkjkmV1J21c93HMHyywkNEzRxJOkQPHVk1QXrAsD5qi9SxMz6uUmigPXl3i26/sD434umn5CPzEOohUc/nLX2gdj9V28N50hQHZveGHhePouzrO7pSGZtUwjY96DRijBpkQqz7AqFJQjom1Jzp2JHzYC0r1Na2ine0dHbbyuIIam2FmP0mTtsGgxQQwDpn94b1I7EBa8CKw/E4lSTZ1N80hDDAM0/SytE3dqEafA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vwGnm0ZY4n+qTU7ZJMZ5yBdjkaXnrIzKpgzUHDpcXh8=; b=bkwOryGNHT/gGpxldqR8R73qVx4ozb9DIJS3hgigv4Lf0ezMSKtChdiB9HMHrFcDgDxd3MRgscIcgqYZxKpRn00ITYjaZ20qCaOO/ysSd1/xWQWdeUwltCROg6zBSs1buU5v6tCzquXuHu9DHG5FikynKeYfB/8u8Gqu/Klbh7o= Received: from DB7PR04MB4618.eurprd04.prod.outlook.com (52.135.139.151) by DB7PR04MB4122.eurprd04.prod.outlook.com (52.135.130.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Mon, 26 Aug 2019 07:34:16 +0000 Received: from DB7PR04MB4618.eurprd04.prod.outlook.com ([fe80::c8ca:1c9c:6c3:fb6f]) by DB7PR04MB4618.eurprd04.prod.outlook.com ([fe80::c8ca:1c9c:6c3:fb6f%4]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 07:34:16 +0000 From: Joakim Zhang To: "robin.murphy@arm.com" , "will@kernel.org" , "mark.rutland@arm.com" Subject: [PATCH V6 1/3] perf: imx8_ddr_perf: add AXI ID filter support Thread-Topic: [PATCH V6 1/3] perf: imx8_ddr_perf: add AXI ID filter support Thread-Index: AQHVW+Cp+1e907fk80iOj0kPjwFqmA== Date: Mon, 26 Aug 2019 07:34:15 +0000 Message-ID: <20190826073128.10052-2-qiangqing.zhang@nxp.com> References: <20190826073128.10052-1-qiangqing.zhang@nxp.com> In-Reply-To: <20190826073128.10052-1-qiangqing.zhang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SG2PR03CA0087.apcprd03.prod.outlook.com (2603:1096:4:7c::15) To DB7PR04MB4618.eurprd04.prod.outlook.com (2603:10a6:5:38::23) authentication-results: spf=none (sender IP is ) smtp.mailfrom=qiangqing.zhang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.71] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3adba962-2fe2-4dc0-1461-08d729f7cc45 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:DB7PR04MB4122; x-ms-traffictypediagnostic: DB7PR04MB4122: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(376002)(366004)(39860400002)(136003)(346002)(199004)(189003)(54534003)(6486002)(26005)(2501003)(6436002)(2906002)(102836004)(14454004)(6506007)(386003)(316002)(110136005)(256004)(2616005)(50226002)(2201001)(305945005)(14444005)(36756003)(7736002)(66066001)(71200400001)(8676002)(86362001)(478600001)(5660300002)(4326008)(71190400001)(81156014)(81166006)(99286004)(54906003)(486006)(53936002)(3846002)(76176011)(52116002)(6116002)(66446008)(66946007)(66476007)(66556008)(6512007)(186003)(11346002)(1076003)(25786009)(8936002)(446003)(64756008)(476003); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR04MB4122; H:DB7PR04MB4618.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: By8mXzEEMTutdn+Oqzk0LfdXLAE/wm6toPC4zUqwsuaLgFEwUQxnNNF9NHYBv536CoWE+gTOnI8lZuXrBJMrNZ9aOlRkC9QoX5GJu4RXejbyHL2Sw0NDgcCU6Qce18OPBeGL3EwZLsyqmJ0h6BJjfsXnJGCOmoE9lUkk3Uw7yo50b3EGYfLDcJ5JknVGMr0xEfacb5cfie+3lgaaGlfpZ1iY3WLog2iXc6/M6LkSTFGgiwsDYc74+tTbSjNiNwcWTdRD5JyxOhqFA4bDkTOeQnxVtU3Fxl5pNKwUXPw1VVbgcK1FZ0zrQ//FQpPNHpGQHhcNit1+ID50EsBUd0lgp51O+Aj0ZE5VXwc4qlcJq5pYCis3rD3YmCxp8Hl/ZWxJXL8tL4V4fakLvDqVSIsFS+pNKfY2/jEXJlNFQRKjk18= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3adba962-2fe2-4dc0-1461-08d729f7cc45 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 07:34:16.0232 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VWs/aED+qBQSOaeaMotuvvcrC77PDfJUizz8Zk8INZBwLQtb/5Ob8la9alCyp0ga9sTby6NnrbmXnTaZFH5a2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4122 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190826_003420_285740_97E0B864 X-CRM114-Status: GOOD ( 19.79 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.2.81 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Frank Li , dl-linux-imx , "linux-arm-kernel@lists.infradead.org" , Joakim Zhang Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org AXI filtering is used by CSV modes 0x41 and 0x42 to count reads or writes with an ARID or AWID matching filter setting. Granularity is at subsystem level. Implementation does not allow filtring between masters within a subsystem. Filter is defined with 2 configuration parameters. --AXI_ID defines AxID matching value --AXI_MASKING defines which bits of AxID are meaningful for the matching 0:corresponding bit is masked 1: corresponding bit is not masked, i.e. used to do the matching When non-masked bits are matching corresponding AXI_ID bits then counter is incremented. This filter allows counting read or write access from a subsystem or multiple subsystems. Perf counter is incremented if AxID && AXI_MASKING == AXI_ID && AXI_MASKING AXI_ID and AXI_MASKING are mapped on DPCR1 register in performance counter. Read and write AXI ID filter should write same value to DPCR1 if want to specify at the same time as this filter is shared between counters. e.g. perf stat -a -e imx8_ddr0/axid-read,axi_id=0xMMMMDDDD/,imx8_ddr0/axid-write,axi_id=0xMMMMDDDD/ cmd MMMM: AXI_MASKING DDDD: AXI_ID perf stat -a -e imx8_ddr0/axid-read,axi_id=0xffff0001/ cmd, which will monitor ARID=1 ChangeLog: V1 -> V2: * add error log if user specifies read/write AXI ID filter at the same time. * of_device_get_match_data() instead of of_match_device(), and remove the check of return value. V2 -> V3: * move the AXI ID check to event_add(). * add support for same value of axi_id. V3 -> V4: * move the AXI ID check to event_init(). V4 -> V5: * reject event group if AXI ID not consistent in event_init(). V5 -> V6: * change the event name: axi-id-read->axid-read; axi-id-write->axid-write * add another helper: ddr_perf_filters_compatible() * drop the dev_dbg() Signed-off-by: Joakim Zhang --- drivers/perf/fsl_imx8_ddr_perf.c | 65 +++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index 0e3310dbb145..22af01a25d5d 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -42,9 +42,22 @@ static DEFINE_IDA(ddr_ida); +/* DDR Perf hardware feature */ +#define DDR_CAP_AXI_ID_FILTER 0x1 /* support AXI ID filter */ + +struct fsl_ddr_devtype_data { + unsigned int quirks; /* quirks needed for different DDR Perf core */ +}; + +static const struct fsl_ddr_devtype_data imx8_devtype_data; + +static const struct fsl_ddr_devtype_data imx8m_devtype_data = { + .quirks = DDR_CAP_AXI_ID_FILTER, +}; + static const struct of_device_id imx_ddr_pmu_dt_ids[] = { - { .compatible = "fsl,imx8-ddr-pmu",}, - { .compatible = "fsl,imx8m-ddr-pmu",}, + { .compatible = "fsl,imx8-ddr-pmu", .data = &imx8_devtype_data}, + { .compatible = "fsl,imx8m-ddr-pmu", .data = &imx8m_devtype_data}, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, imx_ddr_pmu_dt_ids); @@ -58,6 +71,7 @@ struct ddr_pmu { struct perf_event *events[NUM_COUNTERS]; int active_events; enum cpuhp_state cpuhp_state; + const struct fsl_ddr_devtype_data *devtype_data; int irq; int id; }; @@ -129,6 +143,8 @@ static struct attribute *ddr_perf_events_attrs[] = { IMX8_DDR_PMU_EVENT_ATTR(refresh, 0x37), IMX8_DDR_PMU_EVENT_ATTR(write, 0x38), IMX8_DDR_PMU_EVENT_ATTR(raw-hazard, 0x39), + IMX8_DDR_PMU_EVENT_ATTR(axid-read, 0x41), + IMX8_DDR_PMU_EVENT_ATTR(axid-write, 0x42), NULL, }; @@ -138,9 +154,11 @@ static struct attribute_group ddr_perf_events_attr_group = { }; PMU_FORMAT_ATTR(event, "config:0-7"); +PMU_FORMAT_ATTR(axi_id, "config1:0-31"); static struct attribute *ddr_perf_format_attrs[] = { &format_attr_event.attr, + &format_attr_axi_id.attr, NULL, }; @@ -190,6 +208,26 @@ static u32 ddr_perf_read_counter(struct ddr_pmu *pmu, int counter) return readl_relaxed(pmu->base + COUNTER_READ + counter * 4); } +static bool ddr_perf_is_filtered(struct perf_event *event) +{ + return event->attr.config == 0x41 || event->attr.config == 0x42; +} + +static u32 ddr_perf_filter_val(struct perf_event *event) +{ + return event->attr.config1; +} + +static bool ddr_perf_filters_compatible(struct perf_event *a, + struct perf_event *b) +{ + if (!ddr_perf_is_filtered(a)) + return true; + if (!ddr_perf_is_filtered(b)) + return true; + return ddr_perf_filter_val(a) == ddr_perf_filter_val(b); +} + static int ddr_perf_event_init(struct perf_event *event) { struct ddr_pmu *pmu = to_ddr_pmu(event->pmu); @@ -216,6 +254,15 @@ static int ddr_perf_event_init(struct perf_event *event) !is_software_event(event->group_leader)) return -EINVAL; + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER) { + if (!ddr_perf_filters_compatible(event, event->group_leader)) + return -EINVAL; + for_each_sibling_event(sibling, event->group_leader) { + if (!ddr_perf_filters_compatible(event, sibling)) + return -EINVAL; + } + } + for_each_sibling_event(sibling, event->group_leader) { if (sibling->pmu != event->pmu && !is_software_event(sibling)) @@ -289,6 +336,18 @@ static int ddr_perf_event_add(struct perf_event *event, int flags) int counter; int cfg = event->attr.config; + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER) { + int i; + + for (i = 1; i < NUM_COUNTERS; i++) { + if (pmu->events[i] && + !ddr_perf_filters_compatible(event, pmu->events[i])) + return -EINVAL; + } + + writel(event->attr.config1, pmu->base + COUNTER_DPCR1); + } + counter = ddr_perf_alloc_counter(pmu, cfg); if (counter < 0) { dev_dbg(pmu->dev, "There are not enough counters\n"); @@ -473,6 +532,8 @@ static int ddr_perf_probe(struct platform_device *pdev) if (!name) return -ENOMEM; + pmu->devtype_data = of_device_get_match_data(&pdev->dev); + pmu->cpu = raw_smp_processor_id(); ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, DDR_CPUHP_CB_NAME,