From nobody Sun Dec 14 21:43:37 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2089.outbound.protection.outlook.com [40.107.223.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44A93221D93; Wed, 5 Feb 2025 06:06:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735592; cv=fail; b=d6CVXMa23XtgbGTwxuxghi2bLaEWgTlxiLjLNX81P6yCVVSRaKh7MqlW1QiooCJhOd9qmC9+6XM/3EmfrW89+NV0eMoSBfJVsW+ZngJtGHHX3L8hxB2gX94kgCMLwnUkT3h45CreQBvBLuwb3JsVEZsPhtBRelfwfD/R3xqLAkY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735592; c=relaxed/simple; bh=KgB+lZb1ZEG/7T8t190CsMT8rxeZUx7Nb/0JhKbjqbM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mol5V3i0Jny3dWkKUlG7PLv8vrkxPiQfjqUCvArowqzEnWIVTHW9HLzj1cvBYa8qr7FoA/3TXShvk8KfhfRrCVZDpeyHlmFprqsAgAKT2isYfcOoVUn49f7DWlAxfm0wy/9MHITS6kqEu84KaPEiNvQ6cyzjEGrfuD8/Pme8O90= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Deg6bSEt; arc=fail smtp.client-ip=40.107.223.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Deg6bSEt" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iUc1qPz2cW5fuSB+MdLUYYvT1ywd1hXHT+GPEMCYpvX9bDo7rfpeaP6xRM+6+GyH65paMbyH/5eBSqPGjvx4SWy7PzjpiD6kjdkbBVBE4HJvLvendRnF4io33JIQPrApE7kv5DW32b3GBIpkY7eug7ZaOlCEjLZth6Bu+5mrQkFqRqZsN1hG1RdIfP+cW7cCW3QWJjW6XG0qShlx2cVEYdqXBU0vF4HUSUFZc2RoPCoZlYxOfG+hU31rI/Kkz0AdKupucWo0HbRkpIyni446bv4JnKK5DzmTSH2aloufRRPWP3NSLp/zeCIr3NLP3jGHoO+wYrB4pY1QWYpRh04ugQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=PyXUenj8QFLgdXV+8Dp16hCZ8yrWRR5njw2NQ8PGBdo=; b=GrrANCBcr16EFLiVLqlVW8IuZtlktjeJOa2WMi8SLGzndS+x9MRe0vM7GCVELevS3o+gDqyTvRGMZp4fUU/5cFIVDD3liQzlhxh7ntuoWJ18UevpEKl0HUXps+WM2SudGJRvmlxuzszQu1MgPX6oW4l1SHRwNGivyr3o33fl0YfLUqs/gdHLgdF57GbJkLp7n7QXuqRXFBPWGacC+LapcfV63M2toGrWeFSIaR82n2Q4cK0YCuxoWAth095g9PcE/UMJifGv/MMDVEAw8SOYnJBps7G72DZtmF9WNHY23eE8PdcOEGMVqp6NwKMbERy6mal8HYAwX1vwNQpxCsAxHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PyXUenj8QFLgdXV+8Dp16hCZ8yrWRR5njw2NQ8PGBdo=; b=Deg6bSEtmknWalggo4bQX3hkVWCduL9j18HfyFW1frPswkaAbigdQa67Uav5lkiu7R1f2T9K/Uk2plAz6/glzwFV6fGk2sbic+swa6DXsAyn5vlFFdz8O88ERB3Z7QDpqWzuFRqUA3CBAn2vXKLHVwu9ccYcO0zEQhtFsse2ihI= Received: from SJ0PR13CA0168.namprd13.prod.outlook.com (2603:10b6:a03:2c7::23) by DM4PR12MB5796.namprd12.prod.outlook.com (2603:10b6:8:63::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8422.10; Wed, 5 Feb 2025 06:06:24 +0000 Received: from CO1PEPF000075F2.namprd03.prod.outlook.com (2603:10b6:a03:2c7:cafe::e4) by SJ0PR13CA0168.outlook.office365.com (2603:10b6:a03:2c7::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.26 via Frontend Transport; Wed, 5 Feb 2025 06:06:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075F2.mail.protection.outlook.com (10.167.249.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:23 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:18 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 1/7] perf/amd/ibs: Add support for OP Load Latency Filtering Date: Wed, 5 Feb 2025 06:05:41 +0000 Message-ID: <20250205060547.1337-2-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075F2:EE_|DM4PR12MB5796:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e3a738b-ed1d-43b0-83fa-08dd45ab37fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7U+AMlBQQl1P2if2NUeMtjglUkifSlkDjS3EWLwNDnqJpoTIDLzQHZ/JAfvH?= =?us-ascii?Q?TUJcqdU441hOL5xawSxi2tZUzLQqA1Hkuyi9Tpz3iuFB0F0MNntYyL34VECl?= =?us-ascii?Q?7IPMuKHub3u7zb2p605BUVZp+tHvpJJQtCdxzc8V7exRSCHYvu9eNnPek4vG?= =?us-ascii?Q?QvHFhE3mk8kE0sZbeKhh0ZR6ddwtLF/DYPbKAp+Xqzojr9VQt7aFVmAlnBQW?= =?us-ascii?Q?8Tpaq3yNaNwMREu2A9vqW9Z3HCfHNop3+DXCstXa2ATz2iBBtb7dWHIMzN4k?= =?us-ascii?Q?SGpbvGeKmyLtAasJArtM3OwQulFdh1wgebjjsfdwT2blr4pNuj6ixGOLt/bY?= =?us-ascii?Q?NKzNqqF82kZ3UkoU+1kCGvZoug6WjZqFS02ickTHNUAL/9cGDqZICdmdNsyW?= =?us-ascii?Q?U5BW7A6SpxXrA6YGVuXcMkBW5cMEZSjokCT3e5tI7NmnZsyRyhmaf65AKoHH?= =?us-ascii?Q?Ib/I6S/sRh0Nc8y9d9QwUItwiPiHteLRCRz9T/o3nQ+mUjOdBIb3kS6Pa0Bv?= =?us-ascii?Q?bL6qOaNXvx7HH1IiGZR2yH8DMqNs37Y1IA/sJ4ZHD63NVji6hqKGa+5Mqrjo?= =?us-ascii?Q?BdVJKezzoTNHI2Ko/56oigDCZ7ClGawO76LRjeaHWynRrt2Y0RZm4aNPUCAf?= =?us-ascii?Q?HYc0gnymIrhtc1IO+sZ5+dhC6mRuVO/dEEGTP9Xi6uPxwrSvWJHf2+u4TDpD?= =?us-ascii?Q?Fe+uPMt+DCSlng+72IeFrpPVJSx8bjd662IC67JUc24JAmcuNk3L9j6anL49?= =?us-ascii?Q?QxI2sKqPMo4XoCN8mAsiXiKObAvAYMzrNtLDYe0N9FMNdPCB4M3bZ8tgB4xT?= =?us-ascii?Q?bZ1+b3zA0uy+EoLzwb9nwTwaGIj5D0SpQO/bP8fo4OukyjsCWH0PwTQeN6Ji?= =?us-ascii?Q?hHt8Au4ZZLXeIaKa48T23umQtU/kCRZNGKtQjEKcm3nwCpFP/kIcTUcH9J0M?= =?us-ascii?Q?ulxI3xnC341dE5looqVGNh9fIUC1cH8STN3VTAv73UCjTbiFTl9Byfq++c+3?= =?us-ascii?Q?ZG9Tt0hXGkerZDPKUEsQKmNk9tv8NzoEIj12ygkwDLbNUbfBfvXDDcOazhoR?= =?us-ascii?Q?BGMv5vHTJz8+SJ7wBJJxOXKKoQ0WbF8hcHHT+nf8cY+8m6+VM4bBWgm3WKSC?= =?us-ascii?Q?jvcS3sCuYcKgb7Y2SWEqa4MyuBB+RQN3rChJwHIg0Hmeb2okE9i1q8xBoJbW?= =?us-ascii?Q?WoVbwzF6HiRTKFuRXoOzuW0BrF1JF2U+u3kMzB/+kPot3Ntnvlaw38t7kRyu?= =?us-ascii?Q?152ZAEmpdjQYSXxbTq/pSZPbQjhMC+3OTlepKSvh4HbPAoSMlO/tB4KL/aqW?= =?us-ascii?Q?7wv/C3Y7VIVivCNIaMrPHlf23OEbqsdZ1mLI138cDGVkj6NPdjO5ivOvbv/0?= =?us-ascii?Q?oobKS8GjVmCnU6btdnDfNHC7yaGua2Rlv+4g3Cl61lzBals0rQAedWtOjyYJ?= =?us-ascii?Q?YopR/2Kc6OIqxxSDqCH0YkhBhL7869aWchM4bgbIuYbSdDlHLCxJYzjKTvuf?= =?us-ascii?Q?wHM4K9pxm3o+vFg=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:23.5935 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e3a738b-ed1d-43b0-83fa-08dd45ab37fc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5796 Content-Type: text/plain; charset="utf-8" IBS Op PMU on Zen5 uarch added new Load Latency filtering capability. It's advertised by CPUID_Fn8000001B_EAX bit 12. When enabled, IBS HW will raise interrupt only for sample that had an IbsDcMissLat value greater than N cycles, where N is a programmable value defined as multiples of 128 (i.e. 128, 256, 384 etc.) from 128-2048 cycles. Similar to L3MissOnly, IBS HW internally drops the sample and restarts if the sample does not meet the filtering criteria. Add support for LdLat filtering in IBS Op PMU. Since hardware supports threshold in multiple of 128, add a software filter on top to support latency threshold with the granularity of 1 cycle between [128-2048]. Example usage: # perf record -a -e ibs_op/ldlat=3D128/ -- sleep 5 Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 93 ++++++++++++++++++++++++++++--- arch/x86/include/asm/amd-ibs.h | 3 +- arch/x86/include/asm/perf_event.h | 3 + 3 files changed, 90 insertions(+), 9 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 7978d7910adc..85b29b3f305b 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -268,6 +268,14 @@ static int validate_group(struct perf_event *event) return 0; } =20 +static bool perf_ibs_ldlat_event(struct perf_ibs *perf_ibs, + struct perf_event *event) +{ + return perf_ibs =3D=3D &perf_ibs_op && + (ibs_caps & IBS_CAPS_OPLDLAT) && + (event->attr.config1 & 0xFFF); +} + static int perf_ibs_init(struct perf_event *event) { struct hw_perf_event *hwc =3D &event->hw; @@ -339,6 +347,17 @@ static int perf_ibs_init(struct perf_event *event) return -EINVAL; } =20 + if (perf_ibs_ldlat_event(perf_ibs, event)) { + u64 ldlat =3D event->attr.config1 & 0xFFF; + + if (ldlat < 128 || ldlat > 2048) + return -EINVAL; + ldlat >>=3D 7; + + config |=3D (ldlat - 1) << 59; + config |=3D IBS_OP_L3MISSONLY | IBS_OP_LDLAT_EN; + } + /* * If we modify hwc->sample_period, we also need to update * hwc->last_period and hwc->period_left. @@ -607,7 +626,9 @@ PMU_FORMAT_ATTR(cnt_ctl, "config:19"); PMU_FORMAT_ATTR(swfilt, "config2:0"); PMU_EVENT_ATTR_STRING(l3missonly, fetch_l3missonly, "config:59"); PMU_EVENT_ATTR_STRING(l3missonly, op_l3missonly, "config:16"); +PMU_EVENT_ATTR_STRING(ldlat, ibs_op_ldlat_format, "config1:0-11"); PMU_EVENT_ATTR_STRING(zen4_ibs_extensions, zen4_ibs_extensions, "1"); +PMU_EVENT_ATTR_STRING(ldlat, ibs_op_ldlat_cap, "1"); =20 static umode_t zen4_ibs_extensions_is_visible(struct kobject *kobj, struct attribute *att= r, int i) @@ -615,6 +636,12 @@ zen4_ibs_extensions_is_visible(struct kobject *kobj, s= truct attribute *attr, int return ibs_caps & IBS_CAPS_ZEN4 ? attr->mode : 0; } =20 +static umode_t +ibs_op_ldlat_is_visible(struct kobject *kobj, struct attribute *attr, int = i) +{ + return ibs_caps & IBS_CAPS_OPLDLAT ? attr->mode : 0; +} + static struct attribute *fetch_attrs[] =3D { &format_attr_rand_en.attr, &format_attr_swfilt.attr, @@ -631,6 +658,11 @@ static struct attribute *zen4_ibs_extensions_attrs[] = =3D { NULL, }; =20 +static struct attribute *ibs_op_ldlat_cap_attrs[] =3D { + &ibs_op_ldlat_cap.attr.attr, + NULL, +}; + static struct attribute_group group_fetch_formats =3D { .name =3D "format", .attrs =3D fetch_attrs, @@ -648,6 +680,12 @@ static struct attribute_group group_zen4_ibs_extension= s =3D { .is_visible =3D zen4_ibs_extensions_is_visible, }; =20 +static struct attribute_group group_ibs_op_ldlat_cap =3D { + .name =3D "caps", + .attrs =3D ibs_op_ldlat_cap_attrs, + .is_visible =3D ibs_op_ldlat_is_visible, +}; + static const struct attribute_group *fetch_attr_groups[] =3D { &group_fetch_formats, &empty_caps_group, @@ -686,6 +724,11 @@ static struct attribute_group group_op_formats =3D { .attrs =3D op_attrs, }; =20 +static struct attribute *ibs_op_ldlat_format_attrs[] =3D { + &ibs_op_ldlat_format.attr.attr, + NULL, +}; + static struct attribute_group group_cnt_ctl =3D { .name =3D "format", .attrs =3D cnt_ctl_attrs, @@ -704,10 +747,18 @@ static const struct attribute_group *op_attr_groups[]= =3D { NULL, }; =20 +static struct attribute_group group_ibs_op_ldlat_format =3D { + .name =3D "format", + .attrs =3D ibs_op_ldlat_format_attrs, + .is_visible =3D ibs_op_ldlat_is_visible, +}; + static const struct attribute_group *op_attr_update[] =3D { &group_cnt_ctl, &group_op_l3missonly, &group_zen4_ibs_extensions, + &group_ibs_op_ldlat_cap, + &group_ibs_op_ldlat_format, NULL, }; =20 @@ -1060,15 +1111,25 @@ static void perf_ibs_parse_ld_st_data(__u64 sample_= type, } } =20 -static int perf_ibs_get_offset_max(struct perf_ibs *perf_ibs, u64 sample_t= ype, +static bool perf_ibs_is_mem_sample_type(struct perf_ibs *perf_ibs, + struct perf_event *event) +{ + u64 sample_type =3D event->attr.sample_type; + + return perf_ibs =3D=3D &perf_ibs_op && + sample_type & (PERF_SAMPLE_DATA_SRC | + PERF_SAMPLE_WEIGHT_TYPE | + PERF_SAMPLE_ADDR | + PERF_SAMPLE_PHYS_ADDR); +} + +static int perf_ibs_get_offset_max(struct perf_ibs *perf_ibs, + struct perf_event *event, int check_rip) { - if (sample_type & PERF_SAMPLE_RAW || - (perf_ibs =3D=3D &perf_ibs_op && - (sample_type & PERF_SAMPLE_DATA_SRC || - sample_type & PERF_SAMPLE_WEIGHT_TYPE || - sample_type & PERF_SAMPLE_ADDR || - sample_type & PERF_SAMPLE_PHYS_ADDR))) + if (event->attr.sample_type & PERF_SAMPLE_RAW || + perf_ibs_is_mem_sample_type(perf_ibs, event) || + perf_ibs_ldlat_event(perf_ibs, event)) return perf_ibs->offset_max; else if (check_rip) return 3; @@ -1123,7 +1184,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_= ibs, struct pt_regs *iregs) offset =3D 1; check_rip =3D (perf_ibs =3D=3D &perf_ibs_op && (ibs_caps & IBS_CAPS_RIPIN= VALIDCHK)); =20 - offset_max =3D perf_ibs_get_offset_max(perf_ibs, event->attr.sample_type,= check_rip); + offset_max =3D perf_ibs_get_offset_max(perf_ibs, event, check_rip); =20 do { rdmsrl(msr + offset, *buf++); @@ -1132,6 +1193,22 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf= _ibs, struct pt_regs *iregs) perf_ibs->offset_max, offset + 1); } while (offset < offset_max); + + if (perf_ibs_ldlat_event(perf_ibs, event)) { + union ibs_op_data3 op_data3; + + op_data3.val =3D ibs_data.regs[ibs_op_msr_idx(MSR_AMD64_IBSOPDATA3)]; + /* + * Opening event is errored out if load latency threshold is + * outside of [128, 2048] range. Since the event has reached + * interrupt handler, we can safely assume the threshold is + * within [128, 2048] range. + */ + if (!op_data3.ld_op || !op_data3.dc_miss || + op_data3.dc_miss_lat <=3D (event->attr.config1 & 0xFFF)) + goto out; + } + /* * Read IbsBrTarget, IbsOpData4, and IbsExtdCtl separately * depending on their availability. diff --git a/arch/x86/include/asm/amd-ibs.h b/arch/x86/include/asm/amd-ibs.h index cb2a5e113daa..77f3a589a99a 100644 --- a/arch/x86/include/asm/amd-ibs.h +++ b/arch/x86/include/asm/amd-ibs.h @@ -64,7 +64,8 @@ union ibs_op_ctl { opmaxcnt_ext:7, /* 20-26: upper 7 bits of periodic op maximum count */ reserved0:5, /* 27-31: reserved */ opcurcnt:27, /* 32-58: periodic op counter current count */ - reserved1:5; /* 59-63: reserved */ + ldlat_thrsh:4, /* 59-62: Load Latency threshold */ + ldlat_en:1; /* 63: Load Latency enabled */ }; }; =20 diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 73b104049f8c..a60efe47498d 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -502,6 +502,7 @@ struct pebs_cntr_header { #define IBS_CAPS_FETCHCTLEXTD (1U<<9) #define IBS_CAPS_OPDATA4 (1U<<10) #define IBS_CAPS_ZEN4 (1U<<11) +#define IBS_CAPS_OPLDLAT (1U<<12) =20 #define IBS_CAPS_DEFAULT (IBS_CAPS_AVAIL \ | IBS_CAPS_FETCHSAM \ @@ -527,6 +528,8 @@ struct pebs_cntr_header { * The lower 7 bits of the current count are random bits * preloaded by hardware and ignored in software */ +#define IBS_OP_LDLAT_EN (1ULL<<63) +#define IBS_OP_LDLAT_THRSH (0xFULL<<59) #define IBS_OP_CUR_CNT (0xFFF80ULL<<32) #define IBS_OP_CUR_CNT_RAND (0x0007FULL<<32) #define IBS_OP_CUR_CNT_EXT_MASK (0x7FULL<<52) --=20 2.43.0 From nobody Sun Dec 14 21:43:37 2025 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2041.outbound.protection.outlook.com [40.107.94.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FA7C223309; Wed, 5 Feb 2025 06:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735593; cv=fail; b=cgxWd6BVZLUW2yKX4E6V9JevFh8kykaAw6foxNdMKX/BC/+M8P//vg19Y+0Fi+MB75//FLOFGwl3TKUmKBhk4aUqU/Qf0x0BkEnnpazSOYLgPPW9aKD3Sy66yf+ZrrKeI/FK11n2sDAm/IZWbeHylGevDBTq7ZILz5ebEoye5IU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735593; c=relaxed/simple; bh=qJ6PhnnzUh1ytS27TjA1bmCBG45DN90b7gRg94u5OyY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VhT2tx65l6Cxdsw63xsiU5J63Hhn5BpYul8PnMSS5ak6Wo0zla5pjnM1h8IeT3awsuvRcsxsawHFEuuLM3m7MTUbsJZUyBmPxq2y5pSvM1cIN0QRF0USslHeQW9UKWdydNIg7PfzUYm1sBhtLSzS5Qux8BJaIpoMwlDLadreuXk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=uxwLswzl; arc=fail smtp.client-ip=40.107.94.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="uxwLswzl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZYUYY4Moz1WjEjIIb64Vcrl7Ijk7xSyRdjzoTUqS6CUnXwxywbXCLkMeqyW1YsWpUNFy5vnpbr18XQXMz9dPFFJ0EHFWWG6+v4Nv1GXO/oHnu87qUVUFqeyFfYUfUxvVvzxERpkHxYDOCMSkrP6Ecanp/APvN63fmx5dpc4oUggIQ7V6OSMecOPi+driEm3B5UDewAfLoYSywoYGGHD2AcM5yJunOVbeE84EkRALVyKwnJXfiaeP4Dy6KfS8k3a5gTzHu8ziWTw2CxKAZ+7ik2X+mHDGVsYoIKGEppQ77P6Wa2JtosqwWCD2SyKlqwSzEn5SHy+v7Q9buHvHn0t+Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=L/5uAiudxFABk6KiijS4q6dXRq7jOnWjQFZ3mYlTDDE=; b=orphik0wLRJgh4U7zEiGQH0Z+w7CRDzcnSEzaZnn/0AaWkgZuXLVeLt9xu+M0OuTUlNKuCZGKT3iWyDYaun8nllVhAGYpw1Ha1Vu8IUtQwapi6FTs8Ajnmz6kq3O+EQiae0HFtewxqZfGJDAWREyi3rJ9XxlcsjZq4wftdSr+EBMaWqMN71IUKCHlKSrPWfT7iX8T6LkEazLJvoDLUyCqcFkX7AWRsi8Sr+SceOxjeCig01Zw7nzXG8hMKwxLdGv4PnmnJQU3werIcMmjPdQhJpipKYG49piraMNSzISfYBDLU+AEIgMXZTBrGYZkRbAv5qENYe7SMK6/Gah/0L4FA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L/5uAiudxFABk6KiijS4q6dXRq7jOnWjQFZ3mYlTDDE=; b=uxwLswzlyXdK2koRg7p03R2Kxo1Vydam16wLj9iJO+AHV8vsOqEmFYCwFNBJrXqDmoNkSLnk4C1fez0SWZ7CMDqghgqYSXgU0EEQgBjC8WKtO2cTm2m0FzWHVfF/xqllpdZnsDL0xuZrZQxZfwUNyfUXarsY1+edu8ptVgz85y8= Received: from MW4PR03CA0279.namprd03.prod.outlook.com (2603:10b6:303:b5::14) by MW6PR12MB8707.namprd12.prod.outlook.com (2603:10b6:303:241::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.25; Wed, 5 Feb 2025 06:06:29 +0000 Received: from CO1PEPF000075EE.namprd03.prod.outlook.com (2603:10b6:303:b5:cafe::ac) by MW4PR03CA0279.outlook.office365.com (2603:10b6:303:b5::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.27 via Frontend Transport; Wed, 5 Feb 2025 06:06:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075EE.mail.protection.outlook.com (10.167.249.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:28 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:23 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 2/7] perf/amd/ibs: Update DTLB/PageSize decode logic Date: Wed, 5 Feb 2025 06:05:42 +0000 Message-ID: <20250205060547.1337-3-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075EE:EE_|MW6PR12MB8707:EE_ X-MS-Office365-Filtering-Correlation-Id: 4079422b-6f46-4aa6-bfd6-08dd45ab3b02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|7416014|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?wKUX6KXlLnJA7nArOuFuejHaEDjenUPYpHMXk/tcqdubxVgBUFN5p4wZAdRp?= =?us-ascii?Q?wH/xR63+9SdjBNKAS7D7cWKdQxViX/38sPcsCp14bCsHlidaln/RxCV2Vyr+?= =?us-ascii?Q?2DD4eyF8Xo+kAFkNheHMxeP5O9biq2nV1w8aob13AID8wVM8vg022pVDmYKa?= =?us-ascii?Q?KdmtuKNflahuT4pnhz8ieDHNXOmnUUG5otS88OGlheeWGnPdTaxD83A2HBiB?= =?us-ascii?Q?6qzZVb1tj2y5Pi98zA7Y9spHziTVEYBZ3m2S91+zh5L61+GQjrmKMba+yUbL?= =?us-ascii?Q?Tt4/C3E5uQcLimViAXy0GY60pzd+wz+kMt6/LSJUQyUA0ja7aQxOA6nqe4g0?= =?us-ascii?Q?6dKQrWRjEV9SY7IKH9RWeSFZBSwev7R3fi6YGIp1KHKZEWQTRbYcVjd9wL09?= =?us-ascii?Q?JK5zSeWSbI1vsPGcuS0dMHwHGl6+QBbcODGI0/lTmQH61SxSaJGFMVolyFAI?= =?us-ascii?Q?CkhcoBUPiLGVHz3N1T5AynzU1Bd+3k0LlT9BKCpueqKKh+t9rYJPw3/SOnbT?= =?us-ascii?Q?An/LuIz0ED3KR7ewStKEYfzlV+VSQPnP5PuGDtqqcOuUypEkAZMU91QxaF+S?= =?us-ascii?Q?WmdLPW+ncOKOgXEr/J4Dni9SYOVbcrgguArzfR1sQHBmnbiLiK9F3SIj24qw?= =?us-ascii?Q?ExAKokfJceAa596p9WH2Xq21lyyTJam08iJYOT4U1ex2I2rR2uRHyfNGNJFK?= =?us-ascii?Q?NhaSLg8W7IA0i1VI0TBMn0T9Mkmjbr8ELNmXegSqD+lH+0cz5hwhuLfntRm5?= =?us-ascii?Q?WzwrJv0x38Y2ER6HX/P8dXJ5EfUXBissK6tYfzrchWZZxEe+BPVbHY27OCLM?= =?us-ascii?Q?ZNv+Ja1Dotztczd6y1VIb61xiSLv/X+wkp/r1mvsW62spxB6pA5y5H47yOq5?= =?us-ascii?Q?QC9Rj+CdtbOwf8glwrmoc3I4SJQxJxD9oLkDW7qD/YRWdWir4ABVsmmxaG67?= =?us-ascii?Q?/u80G6NZFneD0kSwg8smw02Sg70rTxkAXUF5+jcuCsAfEXRC68xLPuyoO75p?= =?us-ascii?Q?hpJW2aEOiB5hJvmK+vDoSgQPsEqcJSaCHQ2Hq+vhZcC+DfktT/1/c4qOQdYf?= =?us-ascii?Q?rYC6aE6VKv4GW3HWrj010qZbP2PDCYzwoKDSmZjzrTlwZlzrYhmqLh0wnmbO?= =?us-ascii?Q?guGFWEGnrwr+lyrsgGeLWca1a7xqag3Q1xT7RcLhY0B/+FqDvbx2FtS/WN+9?= =?us-ascii?Q?76D1R1eHjxbDf6GZhmPssFuF7mwOC7+v8j2wDHqiefd5lEElMn7i2jlhfQrN?= =?us-ascii?Q?HhCodK5x4V9YoHjbyJuOV+4KCKy++DTFaSXt9blLeCafw1KJbYUnaM/dtzop?= =?us-ascii?Q?RIneyJHtr+rjS8wj7Sb16LyRKkqOZZ+VoLQV7lnKxW5daVsynBHmdo09Gyj8?= =?us-ascii?Q?gOPRLen7MxbYUOuVod9k32EUUrkspJ1jkPJyC1U2LPEDaDggwmgS17inWJmE?= =?us-ascii?Q?W2K6XPeuktpPp8gVUIxUAUx12IzrBWWVJ54YVxUGWgM4iy0AuJPtj/Iq9Kl5?= =?us-ascii?Q?LUv3lB5EwwxE5Nk=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:28.6676 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4079422b-6f46-4aa6-bfd6-08dd45ab3b02 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075EE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8707 Content-Type: text/plain; charset="utf-8" IBS Op PMU on Zen5 reports DTLB and page size information differently compared to prior generation. The change is enumerated by CPUID_Fn8000001B_EAX[19]. IBS_OP_DATA3 Zen3/4 Zen5 ---------------------------------------------------------------- 19 IbsDcL2TlbHit1G Reserved ---------------------------------------------------------------- 6 IbsDcL2tlbHit2M Reserved ---------------------------------------------------------------- 5 IbsDcL1TlbHit1G PageSize: 4 IbsDcL1TlbHit2M 0 - 4K 1 - 2M 2 - 1G 3 - Reserved Valid only if IbsDcPhyAddrValid =3D 1 ---------------------------------------------------------------- 3 IbsDcL2TlbMiss IbsDcL2TlbMiss Valid only if IbsDcPhyAddrValid =3D 1 ---------------------------------------------------------------- 2 IbsDcL1tlbMiss IbsDcL1tlbMiss Valid only if IbsDcPhyAddrValid =3D 1 ---------------------------------------------------------------- o Currently, only bit 2 and 3 are interpreted by IBS NMI handler for PERF_SAMPLE_DATA_SRC. Add dependency on IbsDcPhyAddrValid for those bits. o Introduce new IBS Op PMU capability and expose it to userspace via PMU's sysfs directory. Signed-off-by: Ravi Bangoria --- arch/x86/events/amd/ibs.c | 23 +++++++++++++++++++++++ arch/x86/include/asm/perf_event.h | 1 + 2 files changed, 24 insertions(+) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 85b29b3f305b..7b52b8e3a185 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -629,6 +629,7 @@ PMU_EVENT_ATTR_STRING(l3missonly, op_l3missonly, "confi= g:16"); PMU_EVENT_ATTR_STRING(ldlat, ibs_op_ldlat_format, "config1:0-11"); PMU_EVENT_ATTR_STRING(zen4_ibs_extensions, zen4_ibs_extensions, "1"); PMU_EVENT_ATTR_STRING(ldlat, ibs_op_ldlat_cap, "1"); +PMU_EVENT_ATTR_STRING(dtlb_pgsize, ibs_op_dtlb_pgsize_cap, "1"); =20 static umode_t zen4_ibs_extensions_is_visible(struct kobject *kobj, struct attribute *att= r, int i) @@ -642,6 +643,12 @@ ibs_op_ldlat_is_visible(struct kobject *kobj, struct a= ttribute *attr, int i) return ibs_caps & IBS_CAPS_OPLDLAT ? attr->mode : 0; } =20 +static umode_t +ibs_op_dtlb_pgsize_is_visible(struct kobject *kobj, struct attribute *attr= , int i) +{ + return ibs_caps & IBS_CAPS_OPDTLBPGSIZE ? attr->mode : 0; +} + static struct attribute *fetch_attrs[] =3D { &format_attr_rand_en.attr, &format_attr_swfilt.attr, @@ -663,6 +670,11 @@ static struct attribute *ibs_op_ldlat_cap_attrs[] =3D { NULL, }; =20 +static struct attribute *ibs_op_dtlb_pgsize_cap_attrs[] =3D { + &ibs_op_dtlb_pgsize_cap.attr.attr, + NULL, +}; + static struct attribute_group group_fetch_formats =3D { .name =3D "format", .attrs =3D fetch_attrs, @@ -686,6 +698,12 @@ static struct attribute_group group_ibs_op_ldlat_cap = =3D { .is_visible =3D ibs_op_ldlat_is_visible, }; =20 +static struct attribute_group group_ibs_op_dtlb_pgsize_cap =3D { + .name =3D "caps", + .attrs =3D ibs_op_dtlb_pgsize_cap_attrs, + .is_visible =3D ibs_op_dtlb_pgsize_is_visible, +}; + static const struct attribute_group *fetch_attr_groups[] =3D { &group_fetch_formats, &empty_caps_group, @@ -759,6 +777,7 @@ static const struct attribute_group *op_attr_update[] = =3D { &group_zen4_ibs_extensions, &group_ibs_op_ldlat_cap, &group_ibs_op_ldlat_format, + &group_ibs_op_dtlb_pgsize_cap, NULL, }; =20 @@ -1007,6 +1026,10 @@ static void perf_ibs_get_tlb_lvl(union ibs_op_data3 = *op_data3, if (!op_data3->dc_lin_addr_valid) return; =20 + if ((ibs_caps & IBS_CAPS_OPDTLBPGSIZE) && + !op_data3->dc_phy_addr_valid) + return; + if (!op_data3->dc_l1tlb_miss) { data_src->mem_dtlb =3D PERF_MEM_TLB_L1 | PERF_MEM_TLB_HIT; return; diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index a60efe47498d..43b17b7b6ac0 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -503,6 +503,7 @@ struct pebs_cntr_header { #define IBS_CAPS_OPDATA4 (1U<<10) #define IBS_CAPS_ZEN4 (1U<<11) #define IBS_CAPS_OPLDLAT (1U<<12) +#define IBS_CAPS_OPDTLBPGSIZE (1U<<19) =20 #define IBS_CAPS_DEFAULT (IBS_CAPS_AVAIL \ | IBS_CAPS_FETCHSAM \ --=20 2.43.0 From nobody Sun Dec 14 21:43:37 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2083.outbound.protection.outlook.com [40.107.93.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B092C221D87; Wed, 5 Feb 2025 06:06:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735598; cv=fail; b=iev+TjUb1xWs+fiKWIsfGVgsayngZcdcxGBLh+PRtGqZtdLZ305N8Fw5nCbRHOqaXQU8XWb3+XDuCI+tfYHjCp0Z7u90XnkYJ951WiI21Ncb92c+5WM5CNR5w/DpcgvVFb0mtlPbCluMsCQAws/us4FKigxXmyJe7aX7Ir5ZlRE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735598; c=relaxed/simple; bh=+VjtZVc0lZftn8rygY1z2AsE+iSg3suYjUAiojvr8mw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bv9O7D/Zhazuzre8VWvpA8a0h11cqMFLJdgt8OGqZRdi5EvljZ5zPgMSFXWZTVRVoBA9dIaQrTVXPLaeFvHL/65AfjcFBa4S3bMwx9Z1nKF18A53AR1R8Glej4FpkiwT/1yUw5kL9dyPISPVbAVB3UHrJKW5Hf7Vu3mdkAd+FYk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=I50wCODS; arc=fail smtp.client-ip=40.107.93.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="I50wCODS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KTjcQXlloG5/jy3roUzu2xgFBZUji87mGy1kVU/goM3tyBJr8I4oQAd4w0J6gz8sUi7P3MPQAZEZmSfEzomy3OtL2EcR4ERhXL03mamkSVAvDyI+n941YavKt+bLRX+Ue2UJGFth9Y+vEijnSNADAQOXeOwfVHnrHLoQbgrELE9Be7LVE2cTKREt8C67eaUgsSIHOrpmCpHcg9vh/zg+SaaJEItNrYQ9bamSbgp7eanbVAYrW0mciXBTOIO+qZPGcdNVabkX34sJa1y5LcJEfs/YX2sAHICU0dnSGrJhYHqMGWqZjWXIb944/SWlB+vvkmW7lfrk5qggaJ6ODkfw3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=QmwvAg8UxCNiKkZk2vTiQafUWT/8fxaOyCkOZh8Wdnc=; b=m3OPBraQ3rHFH94mz+54+WloTUivNEt+f0rChplVGWkLDM1up0bpEOV8L1f8hNfK07Uu8lnZktmYV9a3ShDSogxtRLVYq/Umuyo8m9IIjNBoccoVH3XPaIc+xf+ODJY8DbjHWnLK9AhN3UK5a/1AVOylAcE0PUJLuGi381HR1njIAjiVluzgDdrJLqdGdreBy22lT3yLbwsAiG9Z3iy/m3Z9FSYMiO+lLAbP5++4O8fNP1lcdISV8isjnHzsBniVH/JtjplScC6FK5AxKt3uKlLz0nzT/MqXlzu+YAJPyLSQwcDS+3cf8t//TpMTmDWw0uJoR0XB3tmwd+YSa9jErQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QmwvAg8UxCNiKkZk2vTiQafUWT/8fxaOyCkOZh8Wdnc=; b=I50wCODSpwnJV+HZza3y5EOWE7pArijqmdhWrITyOkketQGkS5yaxFaX7zXPTMWLD16kW5NGVIdxPGT/FtJnMXVuBE6pIz51K9PK9MdB8OgI1yHqRk9TXd0nwMSTNhmJv4/eIkFSNifcV0OAznqjSKcD6EaKorhlsiM8GV50hCg= Received: from BYAPR01CA0015.prod.exchangelabs.com (2603:10b6:a02:80::28) by MW4PR12MB6974.namprd12.prod.outlook.com (2603:10b6:303:207::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8422.11; Wed, 5 Feb 2025 06:06:34 +0000 Received: from CO1PEPF000075F1.namprd03.prod.outlook.com (2603:10b6:a02:80:cafe::94) by BYAPR01CA0015.outlook.office365.com (2603:10b6:a02:80::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.20 via Frontend Transport; Wed, 5 Feb 2025 06:06:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075F1.mail.protection.outlook.com (10.167.249.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:33 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:28 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 3/7] perf amd ibs: Sync arch/x86/include/asm/amd-ibs.h header with the kernel Date: Wed, 5 Feb 2025 06:05:43 +0000 Message-ID: <20250205060547.1337-4-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075F1:EE_|MW4PR12MB6974:EE_ X-MS-Office365-Filtering-Correlation-Id: 677e4025-9841-42aa-364c-08dd45ab3de9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?iFZTboKPzRHUu0wLn7pbpBys1YHT3mFegKVYOvx6vEznEk7q/qxp+I2nFsGj?= =?us-ascii?Q?GKIntVnTdm+DzzPpMIBE2WwcjZwoMxSH6eNFVmLOGIKLXqWyE+A3o7Qa1niN?= =?us-ascii?Q?grLxXDGVvBWs9DHGEllUgKWNMdoRAqiTOPSncEHKTWOHYhaKZY2ln9n1DFt4?= =?us-ascii?Q?G/2HvWS6vMtZLn1Au9OjADCHy9lQn0nXJEU7NIM2lL8ahPEiQ/JVIdT891TE?= =?us-ascii?Q?64lZOAGsLtDdO+fp0XmI2IlGmCCn4lTXydidGumJYXv72ir9XA8U99nVcZZS?= =?us-ascii?Q?6fQgATnLWvwQEOFf7d/FSaRHPqw79bsXZKpqebl1a2/KKJkj0Aigj+MtoAjT?= =?us-ascii?Q?3URqeRVbhtOpRnZqAlEsPMGyunqcYdqxZytLYDJ+Kb7Imw/qNgPBbUdvY6h4?= =?us-ascii?Q?X9qEkz00L4E2YrPvmq9MMVSqhZ8gRvjFTqaQUm42+9/NREBaAysnm1oRChhx?= =?us-ascii?Q?uN5tEHwu6oDFFuZy3GyUEsQcYAzX/UUGP1bNPFO3BCd2U/KbAWnVCOmtmjXP?= =?us-ascii?Q?RBtuChGNcXDAiSXfO7gKC3WpEs1XN8Jm9m5PLtABfSHfjyN4/MPePgPRVaIQ?= =?us-ascii?Q?KsfDeJLW5N71Th+Y0qybmRoDTuWKtTNmeBeUwQUlWsag/zMb8f6mlmVIOrXe?= =?us-ascii?Q?YHKiYoDBdm8YgzsqfM6JWi1BbAkijV6SD2gCX/1JrE18N11Y3FheDpw37Uww?= =?us-ascii?Q?KI0tVQNV85XUqd824H/HH5loF8e4g1sM2Lw3/aKn1Z5babsstGaX2aZq5m5F?= =?us-ascii?Q?uaDSZ13kvt8z/I+LbxMj15CpPWPlXKuHbq4u8z1ZzVTGlEO+PPKAzvC2KOe/?= =?us-ascii?Q?3svU4SvxivWztQlyUqPtIbTfVUtSpJgp+mHlKWIi5QpGfrkIgnLPGh5im6hA?= =?us-ascii?Q?StrdprynHwftpknyPDt+RhajTBlamXSGy8KlH32G5UisO7dBemqsXQnJOJeq?= =?us-ascii?Q?8SBsRmVS72Jkd/GRUJbWeXAb+SQyJZr++jPSO2QoGHzbg2hfR/AXPCZaH8m1?= =?us-ascii?Q?tdnh3bfKnvOoPeAoj27ABV9BaprkgPxPeApywrjhWcYqhcbRief/fZGjmAqH?= =?us-ascii?Q?BecynI69+ykciFRPPJe9a04W0iK3AHE1brKdmcKhaTddmJwumzJsr+1FBmKx?= =?us-ascii?Q?Ciyk8+9YJrk1Hd1p0R5NZJmIyAjJVdDJKe2pp9vnc7h1W6EHdDupJ8+Wi3jF?= =?us-ascii?Q?zNXAvG9TLYBY+CmWLzMEaY6WzlLLU7PbZ4zx5tgTesVL9lMKtFWvHR0xyjvm?= =?us-ascii?Q?IRXD318YJxfPXlVd0uJzIzkM8XM+Y+1N9B9cdO4STWEL4DshDrDW9mKns1+g?= =?us-ascii?Q?msGkIeP60HY2XrlYdWGVFj1W7IYjolkx5vHIzFI+q5DoNxhsejGAoiCmkGxi?= =?us-ascii?Q?2CD/hc8G4CixHXvFwoWbfZHjSW/S6c3VtYD+cZp0opbicB8Nd+fXw39uNC0T?= =?us-ascii?Q?K2IMHgpBfFZu2ZNWGWJlvolLBSYHfAAT7i4Fp+430laHORT+81I1NQ=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:33.5177 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 677e4025-9841-42aa-364c-08dd45ab3de9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6974 Content-Type: text/plain; charset="utf-8" Sync load latency related bit fields into the tool's header copy Signed-off-by: Ravi Bangoria --- tools/arch/x86/include/asm/amd-ibs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/arch/x86/include/asm/amd-ibs.h b/tools/arch/x86/include/= asm/amd-ibs.h index 93807b437e4d..cb1740bc3da2 100644 --- a/tools/arch/x86/include/asm/amd-ibs.h +++ b/tools/arch/x86/include/asm/amd-ibs.h @@ -64,7 +64,8 @@ union ibs_op_ctl { opmaxcnt_ext:7, /* 20-26: upper 7 bits of periodic op maximum count */ reserved0:5, /* 27-31: reserved */ opcurcnt:27, /* 32-58: periodic op counter current count */ - reserved1:5; /* 59-63: reserved */ + ldlat_thrsh:4, /* 59-62: Load Latency threshold */ + ldlat_en:1; /* 63: Load Latency enabled */ }; }; =20 --=20 2.43.0 From nobody Sun Dec 14 21:43:37 2025 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2D6B223339; Wed, 5 Feb 2025 06:06:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735606; cv=fail; b=tfHAA1DCqLiCP2wjRIeFhc9bOO/XkqQ/LmH3oDjPM1ltbL18Di72izWYE5yASVnJKBW9C4T523zHaNMmNixZnIG1jXUAJyemoiLayqLMh1G7YPUGJi5eFHiOfO+WMeVG4XetnqZ/8StnNvjBuSMlpdXOza+JckU8VKGu1/S+vuE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735606; c=relaxed/simple; bh=Glp+NTrVrjz69E7ID8NKNOhdRLnwqMvd7kGsouV6spA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zs8DahM26EA5bUdW5OcuLXc8yQmXISyMA/l+8+dBtjLUchvYYpEHxeHnJKo4dMA6ybqs2JzykbeENKIrgv5J2Lr7quciHCWTIRriFTrqeGkSrYsOMK+ruy3BWJQpxq/79aFO4qVI3uTfHH11II70NiiPAoSSHl6Xqx/pMGU4ksQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=pE+L4BLQ; arc=fail smtp.client-ip=40.107.223.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="pE+L4BLQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gB92HSa7GmpYsmKRexPwbydcDUPrcUKbCOA6i6CFRrWEDa9/LEbwnxPNL/8H20KO+QLmXlcP5mUIBEgsyV9XyaeKLHpozMU+FyzebTZ82N+kK6rmNbo61eHl4kCfkzTsIqDwcYKtBFjDoBJYKwe/injnxgo558ApXRVarz9O/lV5L5wiXplxld3jpOoxl2N2bkOoJYOHCkrhYokxUDb7VhQSXqVwdVeGw5YD5Dp6HYcBkn2GyJGJmX8ASOHMYShTqLhPbwN5EKm26yTk8rIervK1XvpNz0WxQavruv4woKzWMgnC7EyrPdUiFr7Cth5Xad9HhtFUQMcm05xvy/Jw5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=ZZJKQdzsXhc4h5/H42TwHke+LKvW80blz8uLEdZiC4U=; b=rPQXhYforDgX4jEPY2RuVust2LRcfaN9ho6VCuda7RQraAbD2uWLvFwedjOdC+4ZD6GJ2izNhOVni6oy6IxQS6tPxPXrK2+oxad6YDwN1aOfCXNLWorXRtQhuH7p+uoqMejjTwl8UeBf7gVNOjqRWzF16mPYUv6hv7L1BkZIUphEHERCIjQEMM2LSnjXT8rlMWi6FIUHXHw+Xy368/7dlOaOeKu0WybJnYCtyFwYAR+YvD+SW6g0IFim9Il8Wi9q4XXjVL3HGqg2lI6vslqNYFc4eBQtxiBct5DZ88rFJMvi9LNcyrCiNpPSvstS6w1EJpe63pnC7vRAUOdNJ+j71g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZZJKQdzsXhc4h5/H42TwHke+LKvW80blz8uLEdZiC4U=; b=pE+L4BLQUBT9z/LhIc5UVdb8X8ulUe1Ub2oMy+ryhiVSqey+sZ4Visuh39ovMF0gthEvmCwo1uA2NaYyqFrc6i5VfhuBw0mZHDc8nQoq2GFa9nfDelrLSR4keZC+LTBlvG+kuoSI8m0JpbXKnrx2ixkkB4H673q1SI0M436Bl0s= Received: from BYAPR01CA0021.prod.exchangelabs.com (2603:10b6:a02:80::34) by SN7PR12MB7451.namprd12.prod.outlook.com (2603:10b6:806:29b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.25; Wed, 5 Feb 2025 06:06:41 +0000 Received: from CO1PEPF000075F1.namprd03.prod.outlook.com (2603:10b6:a02:80:cafe::ec) by BYAPR01CA0021.outlook.office365.com (2603:10b6:a02:80::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.27 via Frontend Transport; Wed, 5 Feb 2025 06:06:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075F1.mail.protection.outlook.com (10.167.249.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:38 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:32 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 4/7] perf amd ibs: Add Load Latency bits in raw dump Date: Wed, 5 Feb 2025 06:05:44 +0000 Message-ID: <20250205060547.1337-5-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075F1:EE_|SN7PR12MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: c10d880d-0f75-4082-6488-08dd45ab40c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EaaXK4OZuJ4azzLwFhaE8tJuVGqomuAikNUmnN1amxu1/TGYlHhdvKgUSMHI?= =?us-ascii?Q?g0c2g3wE4Ks/vNBsdhuWv0r6905vmBzeu5l5NmFvmzVO2QDHXgqLeQiZ2Ffu?= =?us-ascii?Q?w7Gy/Egcgwf2vZLKiRdKHrht2vVrGz76hlWdH46bf1j6yzZmoSIMJgRU3Arw?= =?us-ascii?Q?U0dgpz4nfVndHLx/u3ZtZn4IXFbkgiwnLL4sBJKqCX0p7XZEVBsXc2iE5TWC?= =?us-ascii?Q?Ct8qosOb+wxuQITz+F47g0WnK4LbDrVfl1WSQa+KfTSOYslbjh2A9MnISAVv?= =?us-ascii?Q?3v+I0UE6yw4ffUF5S9sdNMy/NnmOz+PaUWA/pvUTWiEUsKCELRvLHL4eob4o?= =?us-ascii?Q?Gr1vWEoGAlIqza7fu0WrtrbBjyR7gMjgpUHAiD/T9J6dJHIhfMxcix0D6ztV?= =?us-ascii?Q?Sxd/ScykIk2mojwOLOwtPMlfHK1vemB8IXDMwAo+yEksOBhfaJUiuK/ssOlq?= =?us-ascii?Q?tOtrkGyTwibvkE1VcU9UiXQxNRQYj7ull4bSrBrfFH44+0MuixenjJUAut96?= =?us-ascii?Q?RYeoBXEDRjENIKvfwy4y2FVZ6vxBNrdWekuq87sFvNP1Z7Q7OdvBy2orwNlP?= =?us-ascii?Q?Wli+4z6m/lNITNyOCP6kSK6HedjaBwlegBbYe36/hH8LlVYUWNKiLPdMp72z?= =?us-ascii?Q?6tO9B6Jg7ISik37SdafjkLtvQOr7gnqP7bL5XZs2FoQPGXyrPKj6cIL4aMM7?= =?us-ascii?Q?lAxx3XsZ8S26mn+gLNi+eWKYakGjTfZ94Uk/h0rGsKSJOZvI5p1ofap8mEb5?= =?us-ascii?Q?n0/7PYJqaQrN/ElR1cPGxBBVm/ujyMf8YPzbr4UxtPRbzLPPUmq4lR/V0KsH?= =?us-ascii?Q?L2hdc1pcj5txg9I+KkcTg0AHDi6BNyjKgjcIh/WSmFXepcYLPuvVEvFAd4un?= =?us-ascii?Q?+9B87py0fP64RDfuRWUKFYiKpH1RTarF8d9krf4yynjUy9JlfckrNRjBDOgl?= =?us-ascii?Q?pOagG7lLOoDlhku7xRKK641RCdnrLPWyEI5hSDkrPT95HiJ6xKbr6Vb9vZ55?= =?us-ascii?Q?5SXJE3FwvdVzuZnidxHGhBG42C5CFF9GwZ4rcdSAVdxvNKSyUpUsR9gS2cW/?= =?us-ascii?Q?q0pSoMsECB5tactA2zow3LMcS0lZ+3h+zQe5J6NQJFSIHeHbkX7TNFBAg+Pf?= =?us-ascii?Q?V4z95szZRp4ayZdBwLf4ACXF76+rHZ6j01ddz2S5hIIG8wPwFInEnOuRI7NS?= =?us-ascii?Q?/q+6UfrJe7xqo02VqwsTPT2F9vxxLyz2bL5RHAbxLNXJ4+CY4LuQRHN/6yti?= =?us-ascii?Q?w1YS97IIgl01bCPLSkY8Bua3tfd/QVeqcB3aVcOx/aMrtHZZtu0BqCdaFv7D?= =?us-ascii?Q?gX4opZLRpqHMbvkkQIuhzeS/hCZvwxFCr21pHdbMAKFEWRXmEQVP/C7woOf7?= =?us-ascii?Q?HFHyzqbG9v1YqXBxPXNLJ023YTSP44bPhXZJuTW8dKeV6kg91UGMDXL9UNzS?= =?us-ascii?Q?XWOCoAumG3c9Dfv6qQdNZmlE9JQIPQwuXfoANzDgWg8V+iAxNj9X30A/Ty/T?= =?us-ascii?Q?oWVc/qfkquceEK8=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:38.2990 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c10d880d-0f75-4082-6488-08dd45ab40c0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7451 Content-Type: text/plain; charset="utf-8" IBS OP PMU on Zen5 supports Load Latency filtering. Decode and dump Load Latency filtering related bits into perf script raw dump. Also add oneliner example in the perf-amd-ibs man page. Signed-off-by: Ravi Bangoria --- tools/perf/Documentation/perf-amd-ibs.txt | 9 +++++++++ tools/perf/util/amd-sample-raw.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-amd-ibs.txt b/tools/perf/Documen= tation/perf-amd-ibs.txt index 2fd31d9d7b71..55f80beae037 100644 --- a/tools/perf/Documentation/perf-amd-ibs.txt +++ b/tools/perf/Documentation/perf-amd-ibs.txt @@ -85,6 +85,15 @@ System-wide profile, uOps event, sampling period: 100000= , L3MissOnly (Zen4 onwar =20 # perf record -e ibs_op/cnt_ctl=3D1,l3missonly=3D1/ -c 100000 -a =20 +System-wide profile, cycles event, sampling period: 100000, LdLat filterin= g (Zen5 +onward) + + # perf record -e ibs_op/ldlat=3D128/ -c 100000 -a + + Supported load latency threshold values are 128 to 2048 (both inclusive). + Latency value which is a multiple of 128 incurs a little less profiling + overhead compared to other values. + Per process(upstream v6.2 onward), uOps event, sampling period: 100000 =20 # perf record -e ibs_op/cnt_ctl=3D1/ -c 100000 -p 1234 diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-= raw.c index 9d0ce88e90e4..ac34b18ccc0c 100644 --- a/tools/perf/util/amd-sample-raw.c +++ b/tools/perf/util/amd-sample-raw.c @@ -19,6 +19,7 @@ =20 static u32 cpu_family, cpu_model, ibs_fetch_type, ibs_op_type; static bool zen4_ibs_extensions; +static bool ldlat_cap; =20 static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg) { @@ -78,14 +79,20 @@ static void pr_ic_ibs_extd_ctl(union ic_ibs_extd_ctl re= g) static void pr_ibs_op_ctl(union ibs_op_ctl reg) { char l3_miss_only[sizeof(" L3MissOnly _")] =3D ""; + char ldlat[sizeof(" LdLatThrsh __ LdLatEn _")] =3D ""; =20 if (zen4_ibs_extensions) snprintf(l3_miss_only, sizeof(l3_miss_only), " L3MissOnly %d", reg.l3_mi= ss_only); =20 - printf("ibs_op_ctl:\t%016llx MaxCnt %9d%s En %d Val %d CntCtl %d=3D%s Cur= Cnt %9d\n", + if (ldlat_cap) { + snprintf(ldlat, sizeof(ldlat), " LdLatThrsh %2d LdLatEn %d", + reg.ldlat_thrsh, reg.ldlat_en); + } + + printf("ibs_op_ctl:\t%016llx MaxCnt %9d%s En %d Val %d CntCtl %d=3D%s Cur= Cnt %9d%s\n", reg.val, ((reg.opmaxcnt_ext << 16) | reg.opmaxcnt) << 4, l3_miss_only, reg.op_en, reg.op_val, reg.cnt_ctl, - reg.cnt_ctl ? "uOps" : "cycles", reg.opcurcnt); + reg.cnt_ctl ? "uOps" : "cycles", reg.opcurcnt, ldlat); } =20 static void pr_ibs_op_data(union ibs_op_data reg) @@ -331,6 +338,9 @@ bool evlist__has_amd_ibs(struct evlist *evlist) if (perf_env__find_pmu_cap(env, "ibs_op", "zen4_ibs_extensions")) zen4_ibs_extensions =3D 1; =20 + if (perf_env__find_pmu_cap(env, "ibs_op", "ldlat")) + ldlat_cap =3D 1; + if (ibs_fetch_type || ibs_op_type) { if (!cpu_family) parse_cpuid(env); --=20 2.43.0 From nobody Sun Dec 14 21:43:37 2025 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2073.outbound.protection.outlook.com [40.107.244.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FE85227B9C; Wed, 5 Feb 2025 06:06:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735608; cv=fail; b=XkXLhBrf8Thh6Ang2W3diQEFccNkF6eHjZFPxMhECVs/icg2sBoRKrNHiL7Y66boXXeQSpgTKNYJNqBXiT4+M3MPgowmSnCuNiC/mydE98RCyzLluqTwBHanlThiJ6ARWEVZiOeHslW3jlG7mOFfnGebnzn1aV2GMuM84NIADk8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735608; c=relaxed/simple; bh=F6vK+qcbBQeun0lC5nxK3lTZv6uP5jfhpfJa+wgZRKY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qppqNb+YR2Ya8mNjwOk5ffdv2iSUp0boOh1un0/Dsjw4bqlYvlzbCAGk86THlYa63rmjzwbuDyGLQ+FohiadOPm1VbrvMt+NpktspxryLq/R4NKmqcjqWvv55vr3ErNOMK+6dQXa6oQtIOPXLmG+p7/6IsU+owmRE1DstciE1Q0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=itUltLw3; arc=fail smtp.client-ip=40.107.244.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="itUltLw3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pgSYxOu7FqEnsAPNPaRACtxuUnbGHda0qIO6xgb6rm1dHr66jUTcpF40q4rOk+yebgFQ/jn3NOYe8sRLyRBWzVSCX1WUXwwj1ofytxfw7PZOLKiAI0qN8atD6NuaZGeUFdYSHcTfkCU5XO9TZDv/qXh6TweZmH7oIHo6drLf8XJnpJucdfWE8EH6N1pHWfdnEHeEYIKxIGB6milXlB1DdYqXWDiJc+ZNUwcFtaf8oG1xliqpxb2UZ2Ly4jxSDquLoEjwdhtxEptQuzw6sCcEIRP8jWEi2DdSE4Nh+3YZbkVUj4sXmmBpO5ULoHZijYkBXTVmoHRmgDLFenKMqHJ83A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=K4oVkcgJIs/QHr643puiUL3vz6lXlqqMLffc8P3XfkY=; b=YO+fVU0Ewo0fXlS9bs152k6JN3W/yWFAsk1YFY/cZszsrLpa9u2dI7J6MBEQvOkYXrUIKUeoEdfXEgXlR2VwyDpWgL8OnkvgzU6B/tCzy2/cTjXPiknCgrd0Zeixrl6d1A34PlQs5EyhlWH1B79r8zSim9EcaZjNP+0Eg+y2uSezIsE+oyz6jqaLFjQnJSyQehDsqiFpe3RqLey7ubbzk1MswPV+tYw7sOmnazJpyMejpDv5d9u7+gswSmaEGFC8XyUPi5bNzZTFdyie+GYiePlT/pkVkEkCjHZDEidf+g0eNbl8DiJa4wBZ/2xPQzsAib2HgBhFdj7yJyjDoQ8UNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K4oVkcgJIs/QHr643puiUL3vz6lXlqqMLffc8P3XfkY=; b=itUltLw3oVhHFBD6O2xbnnmVs4PpShes+bnZi8LB273YFhmv+vCbnrzEzH8UB8hOFViybe7l2yczyGmNeBx11up67tcNFEO+Hr6Zeo+ioiGznrz0Zaie16b/fWQrHRE4Ee569WZ9QURaCjGKcu7rnifp6upQum1+JGnf+YIgTUs= Received: from SJ0PR05CA0191.namprd05.prod.outlook.com (2603:10b6:a03:330::16) by PH7PR12MB6420.namprd12.prod.outlook.com (2603:10b6:510:1fc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8422.10; Wed, 5 Feb 2025 06:06:43 +0000 Received: from CO1PEPF000075F3.namprd03.prod.outlook.com (2603:10b6:a03:330:cafe::8e) by SJ0PR05CA0191.outlook.office365.com (2603:10b6:a03:330::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.24 via Frontend Transport; Wed, 5 Feb 2025 06:06:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075F3.mail.protection.outlook.com (10.167.249.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:43 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:37 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 5/7] perf amd ibs: Incorporate Zen5 DTLB and PageSize information Date: Wed, 5 Feb 2025 06:05:45 +0000 Message-ID: <20250205060547.1337-6-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075F3:EE_|PH7PR12MB6420:EE_ X-MS-Office365-Filtering-Correlation-Id: ac3cc907-4b43-46e7-ea31-08dd45ab4391 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Sol1H2RdboUpBcUsqj619T9HyI/YpwICA9fB49YnGizA3LRVrncPth5znnq1?= =?us-ascii?Q?BI4Xpdi6quOYNvswFWM5+awKiPeg7ZbiiGpUQ34C1T5N/dGFZ1GrTEOsftuR?= =?us-ascii?Q?rgPSL1bvYNKsGsy2VkIkohaTUHNg+598Skua3gsfJAJhLePa8GOx/AKhdhiv?= =?us-ascii?Q?shz/1rgk4HwjlSc5BmvHmJ88cP1In+ktHeRE20D0p42nSMSeiMVGPqDgsGrD?= =?us-ascii?Q?TvBUvKn8D119M+FmojVE7PrRWVcrH0tHj2ikktVI22vNlW+kiMl+iE9VBTuA?= =?us-ascii?Q?PMr5f4BBLf4SEu4gQ0B8ElWiI4r0Zv5xY4TiT4EuVT4+ZeEdj4GW2clNwnZt?= =?us-ascii?Q?2n7eNhrmlgunaI99kuHaCLtiF68c8HE3WpD7018MVyAc2VZoNgIFUfi4CTYU?= =?us-ascii?Q?6PVczfsd1VHCPnd/hvXep3XZUY46e9kiNNPBIcxvKbxWAmuQj8VTUhpmpeVi?= =?us-ascii?Q?m/nYP7T2kApdV7bu8UrVweiQubhe5CCaosuKvHpzZ9hq98VDRnaTwYIfs3C0?= =?us-ascii?Q?kkpfgNMbit1RFZaFK1JPfpMCSdVibUEpEAZQvKyz+PaXPCetgv/bLk75VYTy?= =?us-ascii?Q?CXUHrhMAyCxXabTb2MgYPErEGwmOK78Z62Am5U/U8GFclJVNF/A02w4kqldA?= =?us-ascii?Q?DeVsURiY8EygsGVprxKG0E3r755YdWcESzvFupM1ShvvLnLUD/TKvJQcLett?= =?us-ascii?Q?+asz1GF7ik/v98oEKVFVhml5gQQXgMw41O9BF2PTJK//T8+JlZOPwQcDFURy?= =?us-ascii?Q?ntcBzLSD9o5gFD7p+Yy8hRvr6UvnfGSonU14PqZRGITZMLbFnyMlXhx0NZwb?= =?us-ascii?Q?V5QHyxGMRFKjFBdg6qLr4+7JUKXN/815Tr0r2QnWoLPQkd68KeNsmnCFAjsY?= =?us-ascii?Q?1chj6lJ8duffxpnKCefCa+dash2mrxzIk9MKqjiFNpAGs/QdHAsdkxG/cctW?= =?us-ascii?Q?q/PqU/P1VSS7/TwY349zihFy9Dy/1UeAmE/ycCTrxhKplqfOuMvvt0QafcbT?= =?us-ascii?Q?5NHKemax4ONmQpiaAxJQ/xBN1ExGjGknicHNdNddQo87kk5SIUMhARywOvh9?= =?us-ascii?Q?ffIj+Hl31SzYorsU2LF5NZ/8Ne+XuP8xMfCbYkWTVevtdMrUG2qCpe2V7GMD?= =?us-ascii?Q?RaTDs8yFluyqwWdHKwTcT2M+Q/ogsdXNRU/FpOfn3ZoKV3s/21DRxZWMLCvY?= =?us-ascii?Q?gQw3zN8c9j6Y2+hF0PbUHoaDraXV3hU3GIi5iTRGx59AbLUoC0rafp81hV7H?= =?us-ascii?Q?3Ju9yHFCpLv3bL833ei2MxEbyLlmDK9WTv2/s4T7oApHn5hlE9hSn1u7rFqK?= =?us-ascii?Q?UyrjrKv4cH4whizNE6dVkYP1a/ylHNujG4E3e18bF5ezsE0IfItIJ03ft/OI?= =?us-ascii?Q?2VOc8LDFXwK/0hpmM0/Z8w/1BtpNp4/63gdMlt3IeL5T1Fmt5JVIOLtoZ44I?= =?us-ascii?Q?9L0uKCqk2oJXa/Odn5EO6qZVyYy3bW5dikd5FBf/5s+kYaj0++CUdfA/Me9a?= =?us-ascii?Q?f/TOfOwSV/aBCpM=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:43.0276 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac3cc907-4b43-46e7-ea31-08dd45ab4391 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6420 Content-Type: text/plain; charset="utf-8" IBS Op PMU on Zen5 reports DTLB and page size information differently compared to prior generation. IBS_OP_DATA3 Zen3/4 Zen5 ---------------------------------------------------------------- 19 IbsDcL2TlbHit1G Reserved ---------------------------------------------------------------- 6 IbsDcL2tlbHit2M Reserved ---------------------------------------------------------------- 5 IbsDcL1TlbHit1G PageSize: 4 IbsDcL1TlbHit2M 0 - 4K 1 - 2M 2 - 1G 3 - Reserved Valid only if IbsDcPhyAddrValid =3D 1 ---------------------------------------------------------------- 3 IbsDcL2TlbMiss IbsDcL2TlbMiss Valid only if IbsDcPhyAddrValid =3D 1 ---------------------------------------------------------------- 2 IbsDcL1tlbMiss IbsDcL1tlbMiss Valid only if IbsDcPhyAddrValid =3D 1 ---------------------------------------------------------------- Kernel expose this change as "dtlb_pgsize" capability in PMU sysfs. Change IBS register raw-dump logic according to new bit definitions. Signed-off-by: Ravi Bangoria --- tools/perf/util/amd-sample-raw.c | 63 ++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-= raw.c index ac34b18ccc0c..022c9eb39509 100644 --- a/tools/perf/util/amd-sample-raw.c +++ b/tools/perf/util/amd-sample-raw.c @@ -20,6 +20,7 @@ static u32 cpu_family, cpu_model, ibs_fetch_type, ibs_op_type; static bool zen4_ibs_extensions; static bool ldlat_cap; +static bool dtlb_pgsize_cap; =20 static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg) { @@ -161,9 +162,20 @@ static void pr_ibs_op_data2(union ibs_op_data2 reg) =20 static void pr_ibs_op_data3(union ibs_op_data3 reg) { - char l2_miss_str[sizeof(" L2Miss _")] =3D ""; - char op_mem_width_str[sizeof(" OpMemWidth _____ bytes")] =3D ""; + static const char * const dc_page_sizes[] =3D { + " 4K", + " 2M", + " 1G", + " ??", + }; char op_dc_miss_open_mem_reqs_str[sizeof(" OpDcMissOpenMemReqs __")] =3D = ""; + char dc_l1_l2tlb_miss_str[sizeof(" DcL1TlbMiss _ DcL2TlbMiss _")] =3D ""; + char dc_l1tlb_hit_str[sizeof(" DcL1TlbHit2M _ DcL1TlbHit1G _")] =3D ""; + char op_mem_width_str[sizeof(" OpMemWidth _____ bytes")] =3D ""; + char dc_l2tlb_hit_2m_str[sizeof(" DcL2TlbHit2M _")] =3D ""; + char dc_l2tlb_hit_1g_str[sizeof(" DcL2TlbHit1G _")] =3D ""; + char dc_page_size_str[sizeof(" DcPageSize ____")] =3D ""; + char l2_miss_str[sizeof(" L2Miss _")] =3D ""; =20 /* * Erratum #1293 @@ -179,16 +191,40 @@ static void pr_ibs_op_data3(union ibs_op_data3 reg) snprintf(op_mem_width_str, sizeof(op_mem_width_str), " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1)); =20 - printf("ibs_op_data3:\t%016llx LdOp %d StOp %d DcL1TlbMiss %d DcL2TlbMiss= %d " - "DcL1TlbHit2M %d DcL1TlbHit1G %d DcL2TlbHit2M %d DcMiss %d DcMisAcc %d " - "DcWcMemAcc %d DcUcMemAcc %d DcLockedOp %d DcMissNoMabAlloc %d DcLinAddr= Valid %d " - "DcPhyAddrValid %d DcL2TlbHit1G %d%s SwPf %d%s%s DcMissLat %5d TlbRefill= Lat %5d\n", - reg.val, reg.ld_op, reg.st_op, reg.dc_l1tlb_miss, reg.dc_l2tlb_miss, - reg.dc_l1tlb_hit_2m, reg.dc_l1tlb_hit_1g, reg.dc_l2tlb_hit_2m, reg.dc_mi= ss, - reg.dc_mis_acc, reg.dc_wc_mem_acc, reg.dc_uc_mem_acc, reg.dc_locked_op, - reg.dc_miss_no_mab_alloc, reg.dc_lin_addr_valid, reg.dc_phy_addr_valid, - reg.dc_l2_tlb_hit_1g, l2_miss_str, reg.sw_pf, op_mem_width_str, - op_dc_miss_open_mem_reqs_str, reg.dc_miss_lat, reg.tlb_refill_lat); + if (dtlb_pgsize_cap) { + if (reg.dc_phy_addr_valid) { + int idx =3D (reg.dc_l1tlb_hit_1g << 1) | reg.dc_l1tlb_hit_2m; + + snprintf(dc_l1_l2tlb_miss_str, sizeof(dc_l1_l2tlb_miss_str), + " DcL1TlbMiss %d DcL2TlbMiss %d", + reg.dc_l1tlb_miss, reg.dc_l2tlb_miss); + snprintf(dc_page_size_str, sizeof(dc_page_size_str), + " DcPageSize %4s", dc_page_sizes[idx]); + } + } else { + snprintf(dc_l1_l2tlb_miss_str, sizeof(dc_l1_l2tlb_miss_str), + " DcL1TlbMiss %d DcL2TlbMiss %d", + reg.dc_l1tlb_miss, reg.dc_l2tlb_miss); + snprintf(dc_l1tlb_hit_str, sizeof(dc_l1tlb_hit_str), + " DcL1TlbHit2M %d DcL1TlbHit1G %d", + reg.dc_l1tlb_hit_2m, reg.dc_l1tlb_hit_1g); + snprintf(dc_l2tlb_hit_2m_str, sizeof(dc_l2tlb_hit_2m_str), + " DcL2TlbHit2M %d", reg.dc_l2tlb_hit_2m); + snprintf(dc_l2tlb_hit_1g_str, sizeof(dc_l2tlb_hit_1g_str), + " DcL2TlbHit1G %d", reg.dc_l2_tlb_hit_1g); + } + + printf("ibs_op_data3:\t%016llx LdOp %d StOp %d%s%s%s DcMiss %d DcMisAcc %= d " + "DcWcMemAcc %d DcUcMemAcc %d DcLockedOp %d DcMissNoMabAlloc %d " + "DcLinAddrValid %d DcPhyAddrValid %d%s%s SwPf %d%s%s " + "DcMissLat %5d TlbRefillLat %5d\n", + reg.val, reg.ld_op, reg.st_op, dc_l1_l2tlb_miss_str, + dtlb_pgsize_cap ? dc_page_size_str : dc_l1tlb_hit_str, + dc_l2tlb_hit_2m_str, reg.dc_miss, reg.dc_mis_acc, reg.dc_wc_mem_acc, + reg.dc_uc_mem_acc, reg.dc_locked_op, reg.dc_miss_no_mab_alloc, + reg.dc_lin_addr_valid, reg.dc_phy_addr_valid, dc_l2tlb_hit_1g_str, + l2_miss_str, reg.sw_pf, op_mem_width_str, op_dc_miss_open_mem_reqs_str, + reg.dc_miss_lat, reg.tlb_refill_lat); } =20 /* @@ -341,6 +377,9 @@ bool evlist__has_amd_ibs(struct evlist *evlist) if (perf_env__find_pmu_cap(env, "ibs_op", "ldlat")) ldlat_cap =3D 1; =20 + if (perf_env__find_pmu_cap(env, "ibs_op", "dtlb_pgsize")) + dtlb_pgsize_cap =3D 1; + if (ibs_fetch_type || ibs_op_type) { if (!cpu_family) parse_cpuid(env); --=20 2.43.0 From nobody Sun Dec 14 21:43:37 2025 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2084.outbound.protection.outlook.com [40.107.93.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9DE4227BB2; Wed, 5 Feb 2025 06:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735612; cv=fail; b=eOp+t0DqHSPGXVSOSSlhKaHvOfkzJAhBGfWMAt2LOjzpJ/lCMFHArES/8qsiGHf4xXsiYKIunJB85p5DI2F3GVPzCuPliiTytVXOVrbTHg7wSG0cRAnbANLyWJmq4LjF0i7rXIyhWRzVUaBEOsB0KA0riFOPhRtB6VPlrQw1+kA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735612; c=relaxed/simple; bh=xkm9Si+Y1gc3vIB4wzXq5Xl5HE6FLnIiL46VMZ8JL9Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Slsy+Q5DbjNA9iXJ1RzVyo3Vw6NRVT6UYYBvc+dJldQBcnmFM23zbJUBn7ARufGRv7nHpqSyrzj9ryYnn7qtADW09/K/THp1vdGkd9lu8E7udN9c3HXeYTe8kLR4zj9GFRWhyitHMxuzIKtP5/deKoAG0Ec2I66DWFlKBs78YeM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=2PBElOx/; arc=fail smtp.client-ip=40.107.93.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="2PBElOx/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i3YEdvrMhJbeLsW0QHJ73IKsMpcSfZUedPEqbzri0yJYRTKsktVin+un6icAHyEgBnvcAKxkRLbsDNnW/A8OPCagc2g0xpdTPk50e+7h1vdyRd+aarNG8jIqJ5JdXHxPi4IJl2c18i5DcFGoR9saHAU0xCNt00RV0Fkn01mnxKfBrWhidDNE0zjL5snsQ4fpm/1Hlc0op0hKntqEwfpO1KaACwivWNIME5sy9CAqswNPAmFYsFGo99byY9+ibyi86m2hXQOq0nnqhumtY5lIq7SWdz5XnuQicCMu6rRIQdWRR/v3PnGkjYmM5cCO18KE6rlrAjKxL1YWfiNjHNeuJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Vt6nSEDoYcS8AgOjkyGNNb2pAqoT3+kTYbeMgj2WNw4=; b=ZmFnKgT3frl0nt3NYK9x3q2qOReQPZftPIY06Zyh4SOgLNnOOgD/hgAE+RjaXnkXRQTX7cE1ZpRN/5nO8Z8fg8SzNYfr3toenUg26p3lutV5Us7I7WIkjn6v/gSBPTE81W5Keqjh5br/0VjXLmso4asf2n2GTYIP13VWFFzybhQgwtjemg+jYPCFZPpTugWjsV9NBBPcDljJKKj4DhFXe0kbbnlu7BvlLJko+txLSsxDkc6zAEZx5+444oUUx+Xt7Es+oEEzvR1A2+5Eo3uhq78WoFCj6FEruUeYnfBukcCCOTab5AFRE00z3tWz4/fai29ubcG432jozpIlBOlsHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vt6nSEDoYcS8AgOjkyGNNb2pAqoT3+kTYbeMgj2WNw4=; b=2PBElOx/bFhdwR97pEqapEJxzZ+uE58utReFdbyd4wDp2BZl2ESuWjkAzrIgC6uFInakQmlxGrJeEikoL2ifjt/ewez4CbhaJMeK+07vPGfqH6bKv2gocGXckL9n5LebBSfLUiKetNz0CWctp6VDpGMWXm0AnxrzySqis8jw77o= Received: from SJ0PR05CA0208.namprd05.prod.outlook.com (2603:10b6:a03:330::33) by CH2PR12MB4181.namprd12.prod.outlook.com (2603:10b6:610:a8::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8422.10; Wed, 5 Feb 2025 06:06:48 +0000 Received: from CO1PEPF000075F3.namprd03.prod.outlook.com (2603:10b6:a03:330:cafe::33) by SJ0PR05CA0208.outlook.office365.com (2603:10b6:a03:330::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.26 via Frontend Transport; Wed, 5 Feb 2025 06:06:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075F3.mail.protection.outlook.com (10.167.249.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:48 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:42 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 6/7] perf mem/c2c amd: Add ldlat support Date: Wed, 5 Feb 2025 06:05:46 +0000 Message-ID: <20250205060547.1337-7-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075F3:EE_|CH2PR12MB4181:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e83fb41-a769-4da3-a0cb-08dd45ab4691 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?1lQSnTxu2YoyJPtaMfconUCF7LFVxfuatdP7/RY40vNKxlSDBN0sbGjNQ7Mn?= =?us-ascii?Q?u5CrJgCj9UxUil7lVEhPNHzeLMhGl5BgjLWHOYCsPEo8jF7MZ3LMvm3CIkB2?= =?us-ascii?Q?Vj4jdpGqwSovTOq6oAV3L7RVvU8Yb1zQ5tpylci79S01wZM0/MFTbRltLF0A?= =?us-ascii?Q?QN4RopjofjcXicmRyLyfeqEUop+0fpeaXby+LqJU3euV+kvQ7cwpm03Lh3o7?= =?us-ascii?Q?IbHWy63qP/0CggPONGYUuumeCMKIXAzcMYof3TXs5z0hrcfQI0hFKv+Uo+ZD?= =?us-ascii?Q?12BjdTPvzCt+A/ta2+9A1paT4lBvLXlHENGCZx0lxQdZ3+3uZ1Pj1NxJ3wdq?= =?us-ascii?Q?Hd6eYk0wwl8mYhu9yeSZLFmi6acoYAIvoAYDBdzjUGu4PMF69eOwWiuz2ArH?= =?us-ascii?Q?DU12aBnveYoBZEl5fLGOH0YR6uTnJltKhJgjQaV7WYaRlbHnt/BMFiS+f1Ov?= =?us-ascii?Q?5l8sXkxNsLKsWgM4O07gzrzGf7JoTgsdeOthQclUXR1jZ3itPxS7JaVj+hMo?= =?us-ascii?Q?nw3dY7MUBF56HdJxVLju6S+A3sRGLL2AmVx6kC2vtsNzFTna1is8BpxYZyDw?= =?us-ascii?Q?OzokAyXUnFF/AyYq5zFndqdotc3NZCcdiKmjjwq/CuMq+AZtxoFqsR7CMGK0?= =?us-ascii?Q?Sy8JmstAJu9vKWj0DVjLDJIvKjla4KpPfZyFXfzbSPdyJKMq5NEYo+oFsS4d?= =?us-ascii?Q?UJ2f20ZBLwbGA7v7h6+2+Rrhy7Y98c9KRSc7T8w3+dWsluW1NfggcI9kCSMA?= =?us-ascii?Q?So/ZQCAfcTTMriW6aiC8X+5zbUPMkwYYkIBuoBl3V4A9k5OLXmE+e8u1eCiv?= =?us-ascii?Q?JKEPQ1R46ZZYjGobwq2z9DlyNL/vDg6lgv3wKDfNKdgFco0nCOHBZMrKRaJE?= =?us-ascii?Q?7Z8zZO365WCzbMS23gSNY1xn4/xKVehDqddaU/AdEgpZQDsVuYsgn9C1D8EB?= =?us-ascii?Q?1gGEdwRd6fPotSyBkvIWsQwPDmIMtkD87uTTrg5AEuupy9RPpZljFhGcwe9x?= =?us-ascii?Q?SwGXXuqYl9PosG0KP+sfF6m6iI6zdWehY8fqQp6xj1tT4wRQ4DDSJyQe7TuZ?= =?us-ascii?Q?IgLFkBa7AtKq3Ctv3tQKorC47puvTbKolnwS2wzvlx6BMz86qXz0BcjsDrmv?= =?us-ascii?Q?ljuPm0neEErI/tVOQNeo9RcuGXEjaUt8H4wGKaLIjN55Rbti+N5GVEH734oo?= =?us-ascii?Q?3rX5sko9/UWXkXSV1aiiuJEzmrzcLmOJBwrqHu3BdDMrVrhiq5NILHMDlktF?= =?us-ascii?Q?gksadrlQxc38De90PYDzIAkDw4oNFixmXImP8nj6gstXdGkyPZ4UBxlzYhuw?= =?us-ascii?Q?llKKlv4hB8pAjPg1ZZokIqZnT6Z8Hxnpne1R+RcgJlHvyTgdxXOmPYXNwoXF?= =?us-ascii?Q?R0Yr73p1XjtI06cHmcccOJQOZGBEPhyuT1jOm99ZhHtS450AphuCIqguXhtK?= =?us-ascii?Q?aaGvq/7yfA+XsBtE7uJniXYACVW3mZOUhgJ57+O5i43Fis1ezFQrolXX6Jjz?= =?us-ascii?Q?UoJoHwzZ+abTqoA=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:48.0589 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e83fb41-a769-4da3-a0cb-08dd45ab4691 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075F3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4181 Content-Type: text/plain; charset="utf-8" Perf mem and c2c uses IBS Op PMU on AMD platforms. IBS Op PMU on Zen5 uarch has added support for Load Latency filtering. Implement perf mem/ c2c --ldlat using IBS Op Load Latency filtering capability. Some subtle differences between AMD and other arch: o --ldlat is disabled by default on AMD o Supported values are 128 to 2048. Signed-off-by: Ravi Bangoria --- tools/perf/Documentation/perf-c2c.txt | 10 ++++++-- tools/perf/Documentation/perf-mem.txt | 12 +++++++-- tools/perf/arch/x86/util/mem-events.c | 6 +++++ tools/perf/arch/x86/util/mem-events.h | 1 + tools/perf/arch/x86/util/pmu.c | 20 ++++++++++++--- tools/perf/tests/shell/test_data_symbol.sh | 29 +++++++++++++++++++--- tools/perf/util/pmu.c | 11 ++++++++ tools/perf/util/pmu.h | 2 ++ 8 files changed, 81 insertions(+), 10 deletions(-) diff --git a/tools/perf/Documentation/perf-c2c.txt b/tools/perf/Documentati= on/perf-c2c.txt index 856f0dfb8e5a..3e2f690f127a 100644 --- a/tools/perf/Documentation/perf-c2c.txt +++ b/tools/perf/Documentation/perf-c2c.txt @@ -54,8 +54,14 @@ RECORD OPTIONS =20 -l:: --ldlat:: - Configure mem-loads latency. Supported on Intel and Arm64 processors - only. Ignored on other archs. + Configure mem-loads latency. Supported on Intel, Arm64 and some variants + of AMD platforms. Ignored on other archs. + + On supported AMD platforms: + - Supported latency values are 128 to 2048 (both inclusive). + - Latency value which is a multiple of 128 incurs a little less profiling + overhead compared to other values. + - Load latency filtering is disabled by default. =20 -k:: --all-kernel:: diff --git a/tools/perf/Documentation/perf-mem.txt b/tools/perf/Documentati= on/perf-mem.txt index 8a1bd9ff0f86..f28837d6b783 100644 --- a/tools/perf/Documentation/perf-mem.txt +++ b/tools/perf/Documentation/perf-mem.txt @@ -28,6 +28,8 @@ and kernel support is required. See linkperf:perf-arm-spe= [1] for a setup guide. Due to the statistical nature of SPE sampling, not every memory operation = will be sampled. =20 +On AMD this use IBS Op PMU to sample load-store operations. + COMMON OPTIONS -------------- -f:: @@ -67,8 +69,14 @@ RECORD OPTIONS Configure all used events to run in user space. =20 --ldlat :: - Specify desired latency for loads event. Supported on Intel and Arm64 - processors only. Ignored on other archs. + Specify desired latency for loads event. Supported on Intel, Arm64 and + some variants of AMD platforms. Ignored on other archs. + + On supported AMD platforms: + - Supported latency values are 128 to 2048 (both inclusive). + - Latency value which is a multiple of 128 incurs a little less profiling + overhead compared to other values. + - Load latency filtering is disabled by default. =20 REPORT OPTIONS -------------- diff --git a/tools/perf/arch/x86/util/mem-events.c b/tools/perf/arch/x86/ut= il/mem-events.c index 62df03e91c7e..b38f519020ff 100644 --- a/tools/perf/arch/x86/util/mem-events.c +++ b/tools/perf/arch/x86/util/mem-events.c @@ -26,3 +26,9 @@ struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS= __MAX] =3D { E(NULL, NULL, NULL, false, 0), E("mem-ldst", "%s//", NULL, false, 0), }; + +struct perf_mem_event perf_mem_events_amd_ldlat[PERF_MEM_EVENTS__MAX] =3D { + E(NULL, NULL, NULL, false, 0), + E(NULL, NULL, NULL, false, 0), + E("mem-ldst", "%s/ldlat=3D%u/", NULL, true, 0), +}; diff --git a/tools/perf/arch/x86/util/mem-events.h b/tools/perf/arch/x86/ut= il/mem-events.h index f55c8d3b7d59..11e09a256f5b 100644 --- a/tools/perf/arch/x86/util/mem-events.h +++ b/tools/perf/arch/x86/util/mem-events.h @@ -6,5 +6,6 @@ extern struct perf_mem_event perf_mem_events_intel[PERF_MEM= _EVENTS__MAX]; extern struct perf_mem_event perf_mem_events_intel_aux[PERF_MEM_EVENTS__MA= X]; =20 extern struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX]; +extern struct perf_mem_event perf_mem_events_amd_ldlat[PERF_MEM_EVENTS__MA= X]; =20 #endif /* _X86_MEM_EVENTS_H */ diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c index e0060dac2a9f..8712cbbbc712 100644 --- a/tools/perf/arch/x86/util/pmu.c +++ b/tools/perf/arch/x86/util/pmu.c @@ -18,8 +18,10 @@ #include "mem-events.h" #include "util/env.h" =20 -void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_unused) +void perf_pmu__arch_init(struct perf_pmu *pmu) { + struct perf_pmu_caps *ldlat_cap; + #ifdef HAVE_AUXTRACE_SUPPORT if (!strcmp(pmu->name, INTEL_PT_PMU_NAME)) { pmu->auxtrace =3D true; @@ -33,8 +35,20 @@ void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_un= used) #endif =20 if (x86__is_amd_cpu()) { - if (!strcmp(pmu->name, "ibs_op")) - pmu->mem_events =3D perf_mem_events_amd; + if (strcmp(pmu->name, "ibs_op")) + return; + + pmu->mem_events =3D perf_mem_events_amd; + + if (!perf_pmu__caps_parse(pmu)) + return; + + ldlat_cap =3D perf_pmu__get_cap(pmu, "ldlat"); + if (!ldlat_cap || strcmp(ldlat_cap->value, "1")) + return; + + perf_mem_events__loads_ldlat =3D 0; + pmu->mem_events =3D perf_mem_events_amd_ldlat; } else if (pmu->is_core) { if (perf_pmu__have_event(pmu, "mem-loads-aux")) pmu->mem_events =3D perf_mem_events_intel_aux; diff --git a/tools/perf/tests/shell/test_data_symbol.sh b/tools/perf/tests/= shell/test_data_symbol.sh index c86da0235059..747f5dc9d679 100755 --- a/tools/perf/tests/shell/test_data_symbol.sh +++ b/tools/perf/tests/shell/test_data_symbol.sh @@ -55,11 +55,34 @@ trap cleanup_files exit term int =20 echo "Recording workload..." =20 -# perf mem/c2c internally uses IBS PMU on AMD CPU which doesn't support -# user/kernel filtering and per-process monitoring, spin program on -# specific CPU and test in per-CPU mode. is_amd=3D$(grep -E -c 'vendor_id.*AuthenticAMD' /proc/cpuinfo) if (($is_amd >=3D 1)); then + mem_events=3D"$(perf mem record -v -e list 2>&1)" + if ! [[ "$mem_events" =3D~ ^mem\-ldst.*ibs_op/(.*)/.*available ]]; then + echo "ERROR: mem-ldst event is not matching" + exit 1 + fi + + # --ldlat on AMD: + # o Zen4 and earlier uarch does not support ldlat + # o Even on supported platforms, it's disabled (--ldlat=3D0) by default. + ldlat=3D${BASH_REMATCH[1]} + if [[ -n $ldlat ]]; then + if ! [[ "$ldlat" =3D~ ldlat=3D0 ]]; then + echo "ERROR: ldlat not initialized to 0?" + exit 1 + fi + + mem_events=3D"$(perf mem record -v --ldlat=3D150 -e list 2>&1)" + if ! [[ "$mem_events" =3D~ ^mem-ldst.*ibs_op/ldlat=3D150/.*available ]];= then + echo "ERROR: --ldlat not honored?" + exit 1 + fi + fi + + # perf mem/c2c internally uses IBS PMU on AMD CPU which doesn't + # support user/kernel filtering and per-process monitoring on older + # kernels, spin program on specific CPU and test in per-CPU mode. perf mem record -vvv -o ${PERF_DATA} -C 0 -- taskset -c 0 $TEST_PROGRAM 2= >"${ERR_FILE}" & else perf mem record -vvv --all-user -o ${PERF_DATA} -- $TEST_PROGRAM 2>"${ERR= _FILE}" & diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 6206c8fe2bf9..7053a59083a8 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -2114,6 +2114,17 @@ static void perf_pmu__del_caps(struct perf_pmu *pmu) } } =20 +struct perf_pmu_caps *perf_pmu__get_cap(struct perf_pmu *pmu, const char *= name) +{ + struct perf_pmu_caps *caps; + + list_for_each_entry(caps, &pmu->caps, list) { + if (!strcmp(caps->name, name)) + return caps; + } + return NULL; +} + /* * Reading/parsing the given pmu capabilities, which should be located at: * /sys/bus/event_source/devices//caps as sysfs group attributes. diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index dbed6c243a5e..b3d4d7c5b92d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -266,6 +266,8 @@ bool pmu_uncore_identifier_match(const char *compat, co= nst char *id); =20 int perf_pmu__convert_scale(const char *scale, char **end, double *sval); =20 +struct perf_pmu_caps *perf_pmu__get_cap(struct perf_pmu *pmu, const char *= name); + int perf_pmu__caps_parse(struct perf_pmu *pmu); =20 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, --=20 2.43.0 From nobody Sun Dec 14 21:43:37 2025 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2070.outbound.protection.outlook.com [40.107.212.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8556D22837C; Wed, 5 Feb 2025 06:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.212.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735625; cv=fail; b=CvLQRYfvmmU7Z9j+PYzPzKlkY/xR/HuknfYmChoKn9Sb6qprwbNnhszxj1feBGrrduHAZX3oZHmTkGxlTJK7woxo5RvbKjmbEzkT1QVOMxXty4Yyd2d/wbzIxzKvozv0IS1F01JVGhan7Q+TlczgvoGa3rjISe9cfLtXGRw8T60= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738735625; c=relaxed/simple; bh=24BVGdgTZp4fSaGmcL9xVfTddlhyMGByMyF3WHwbdnA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q+V0O6nbUK+VUm9UGmWNMrqsySttt2JjslnOZ93jFaXEjsnaFRGKA5Bc+EgALRmGVvoRdu//Z8XvEmqrPCwxAC5uB1R0IbXp52vQoRAOlYGig1L7HXIQejF0FZrq9bhV6npY6r/QuT6O31GjBIo0huk07hdBkpGY/hJi2pHD9Rg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ipm9Saa1; arc=fail smtp.client-ip=40.107.212.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ipm9Saa1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fzoema6Nrefi1s2kM1R6BQCBC82uXd0yH8TTLQhRSwffmnzl4zIISb1V2IKo2u2BuCBTp9Mbvjd1QNJWCZfDa6mNQHHO4kV0pKwNIQcVSyjezK6pL1gKoWABVc/Iq8imKs34OGdCa2UDl/MNMUOD+z4+0+noQwDc96uxnbhoOR2mWobmncADDRjSFRLa2/1BZok4KIYrR/3CubAEK3xpluivUAt26geLzctls7UebzowfY7aAXXrXStnVxxq7SglVGlu0UrlpyiL53UfZVJiJoAkHEi7PruTky93z5BKef/+EUVqw553ysN8P2tGhxQFVG2h+qjOc6hnoYV536xOfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=TSxqc4Gbe4BrFwNvfEw3XdkZxpULw3REtw5mbYe/+n8=; b=JEpy8h/c9ClVb4UAgVh4Dl4YE0DtTVbPu4C0XnCSfx7cZ2dUkEE2fNFbr2MoC7WHV82eySjjACk9Bzje4EQHJYmltysDEAot4yVb5rviHAkYPMXwoY2DnIDxH60vTI9/vq4sTLdk5TpW4KeJOrI1E7BSNy7G//djkTkdnsZb74boKOhPu8ZGTR5rKhJtytILZ16aeJ82cRNe9vNkIbs5xz3PdLqjkQ6KRV9/Zb3bEzPfFVKWRXY9CLMH7Xcyd2z/Yy7BJhrsbXbXJ9s/A2zVX6UhAnP/QFk3wYj9zNir8lbnxJDY9dN+DMhxErTQAU0qrw40a1DBh5MskqGcf9RjPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TSxqc4Gbe4BrFwNvfEw3XdkZxpULw3REtw5mbYe/+n8=; b=ipm9Saa1u+bWKble7fbs1O/VpAs8h5a3rvNDU6kRYY4Ed2+Lgxvn+G+l6930+4fH7DatCCavtD8c38nXPwSsQDfGJZ7y867I9aOrhYlANo+xk/JLa9w7/9qCL7NDxo0VA0zIA23DiVjvakH+AiScdaKQpnpOLlVpsq5zAocU+Kw= Received: from BYAPR02CA0022.namprd02.prod.outlook.com (2603:10b6:a02:ee::35) by PH7PR12MB6489.namprd12.prod.outlook.com (2603:10b6:510:1f7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.24; Wed, 5 Feb 2025 06:06:53 +0000 Received: from CO1PEPF000075ED.namprd03.prod.outlook.com (2603:10b6:a02:ee:cafe::fa) by BYAPR02CA0022.outlook.office365.com (2603:10b6:a02:ee::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.26 via Frontend Transport; Wed, 5 Feb 2025 06:06:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000075ED.mail.protection.outlook.com (10.167.249.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8398.14 via Frontend Transport; Wed, 5 Feb 2025 06:06:53 +0000 Received: from BLR-L-RBANGORI.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 5 Feb 2025 00:06:47 -0600 From: Ravi Bangoria To: , , CC: , , , , , , , , , , , Subject: [PATCH v3 7/7] perf test amd ibs: Add sample period unit test Date: Wed, 5 Feb 2025 06:05:47 +0000 Message-ID: <20250205060547.1337-8-ravi.bangoria@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250205060547.1337-1-ravi.bangoria@amd.com> References: <20250205060547.1337-1-ravi.bangoria@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000075ED:EE_|PH7PR12MB6489:EE_ X-MS-Office365-Filtering-Correlation-Id: fe38923e-bd35-4911-78ae-08dd45ab4989 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?XVspV3qM8WFW/k+mW2pR6xq1GWxnFouh4ClMVZi4kJkuZeaUR3QN5+yK9S3J?= =?us-ascii?Q?TfVEiM3d3Uxzs+fOr/T1bA49sd5fHzOohRs30FiIzH2R4y9yMnQ/7r58WYpl?= =?us-ascii?Q?PO5iOkvg+5Mfe1XC4iY27XD4pKG8YHEpJ7huagl0vd7SwBW+QQlTwTdmsB/R?= =?us-ascii?Q?nqAeMJdRJzYjLOsm6Cugi6/9ihEVoUTXYm5hS7AeuFpk9FAUfGT7GIuK9vHN?= =?us-ascii?Q?6xgUQH5dRKhAj63K34Pt/Vt4JKl0tflzWGJTElOFyJ0jhLRgs4TWTvZ9fXOl?= =?us-ascii?Q?sIRm7qbpvH00hiAZ1sv7wIFEyTR2lDksFMvar9qhPnuNUyjmJGf4RjoiKa+o?= =?us-ascii?Q?fxjt+G31dnK9lmLu4f3qiFOUZ58BhmBD4l4zlSFW7FMG/YDS5pJlcfx+etFz?= =?us-ascii?Q?BDhZucGhI6/L2JvLa8OAPnXUCYlaz7ng4pIXD5ciiHeOLrkAzYzHSuFzVCaV?= =?us-ascii?Q?oseoiEd/Vrd7iioQFrjDBwpzlw38HaMWmIyn32LrKK/YvkSg83Ox1cnjnatC?= =?us-ascii?Q?UPgTzkC5fzh++NGiHtQw2AvzyfbwLXIpIKRziRYNzoYCE7N3Z38jxD2QNBKC?= =?us-ascii?Q?Ndz5lnbTDp1HTA/HXu03yn/8nbYvnBLLuV7DAW9TuMoNs4mJNk2xEZM47MNH?= =?us-ascii?Q?GLNNViTgihx//BXJUa2FWa9iFIuDS4zpactjhpwkaJSaarfLHdjg+EuozPuj?= =?us-ascii?Q?pencC0s15KgOdO+1oOZ11u/qvNc7vJMFnDinkiSiC+awVe14Xz5/89BC8gCZ?= =?us-ascii?Q?ytkDQg35xhD9ZxyhUkvR+XlQpmCqW9kge1gkrf+FDdTc6DoerH1Zz0dxesWs?= =?us-ascii?Q?GRvdbWM4DNeoPK1aZEi3pjWCPzfV9fqJig3ocrEbUJHmQO5M2yyFe54WWQCj?= =?us-ascii?Q?Y8jVS5Vp8lubyqVMdqyUWHktbDw728mvbVIIQUJNNntAt9VVvlD5yYb+SBgE?= =?us-ascii?Q?tkvf/0lEIIcHbqDBodtgQsyZ9H51dqsznGeeVdDmXLqhUcz9MKjbHmiRfvXu?= =?us-ascii?Q?c3V2TfFvWDoakItVAamKKIQ6B9WjCM+ZKWAGxVhwqR7OegabRlxlp0LjZIch?= =?us-ascii?Q?p5/sd3YmQgr/bAWwMXUaVkRGwcOUORmZQh9L7hXtmeBl9sVktdxajwoasPSp?= =?us-ascii?Q?znV/1+SRG6lT4wUZbMquV+1Xnhqtuiv3CKPmV1+fLTBCepiIgXdky7Uyyr8j?= =?us-ascii?Q?CR93eUUHpqQyzbj5kAY/XGnok8a/cXDnmKBYbdu7S0rU13Czp2fxqqvlzLXW?= =?us-ascii?Q?KjdX3e8QfUWwLUxLWXDqSN/cgDcbdFWmpKJm/7zsfjX5SxcPOadaGbzbPu2F?= =?us-ascii?Q?a+Kmd638pPjzjRmbpOrtVRePsNE7XDqyIN6omOjTP2LLVoerWdOcslMWyRmJ?= =?us-ascii?Q?Idnf05vRZC/rlO+qe8T+2eEi3XbvzfwdSvhR+ay2IRjpqOHHktVp2el1g35S?= =?us-ascii?Q?pBgMQVgMnb522Mqz6aEPjiwSZRu0mdlZ+OiDf5VGw5JwX60UM7mED1yMRj9v?= =?us-ascii?Q?SD4cZb5xnI721fA=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 06:06:53.0386 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe38923e-bd35-4911-78ae-08dd45ab4989 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000075ED.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6489 Content-Type: text/plain; charset="utf-8" IBS Fetch and IBS Op PMUs has various constraints on supported sample periods. Add perf unit tests to test those. Running it in parallel with other tests causes intermittent failures. Mark it exclusive to force it to run sequentially. Sample output on a Zen5 machine: Without kernel fixes: $ sudo ./perf test -vv 112 112: AMD IBS sample period: --- start --- test child forked, pid 8774 Using CPUID AuthenticAMD-26-2-1 IBS config tests: ----------------- Fetch PMU tests: 0xffff : Ok (nr samples: 1078) 0x1000 : Ok (nr samples: 17030) 0xff : Ok (nr samples: 41068) 0x1 : Ok (nr samples: 40543) 0x0 : Ok 0x10000 : Ok Op PMU tests: 0x0 : Ok 0x1 : Fail 0x8 : Fail 0x9 : Ok (nr samples: 40543) 0xf : Ok (nr samples: 40543) 0x1000 : Ok (nr samples: 18736) 0xffff : Ok (nr samples: 1168) 0x10000 : Ok 0x100000 : Fail (nr samples: 14) 0xf00000 : Fail (nr samples: 1) 0xf0ffff : Fail (nr samples: 1) 0x1f0ffff : Fail (nr samples: 1) 0x7f0ffff : Fail (nr samples: 0) 0x8f0ffff : Ok 0x17f0ffff : Ok IBS sample period constraint tests: ----------------------------------- Fetch PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Fail freq 0, sample_freq 15: Fail freq 0, sample_freq 16: Ok (nr samples: 1604) freq 0, sample_freq 17: Ok (nr samples: 1604) freq 0, sample_freq 143: Ok (nr samples: 1604) freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1604) freq 0, sample_freq 1234: Ok (nr samples: 1566) freq 0, sample_freq 4103: Ok (nr samples: 1119) freq 0, sample_freq 65520: Ok (nr samples: 2264) freq 0, sample_freq 65535: Ok (nr samples: 2263) freq 0, sample_freq 65552: Ok (nr samples: 1166) freq 0, sample_freq 8388607: Ok (nr samples: 268) freq 0, sample_freq 268435455: Ok (nr samples: 8) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Ok (nr samples: 4) freq 1, sample_freq 15: Ok (nr samples: 4) freq 1, sample_freq 16: Ok (nr samples: 4) freq 1, sample_freq 17: Ok (nr samples: 4) freq 1, sample_freq 143: Ok (nr samples: 5) freq 1, sample_freq 144: Ok (nr samples: 5) freq 1, sample_freq 145: Ok (nr samples: 5) freq 1, sample_freq 1234: Ok (nr samples: 7) freq 1, sample_freq 4103: Ok (nr samples: 35) freq 1, sample_freq 65520: Ok (nr samples: 642) freq 1, sample_freq 65535: Ok (nr samples: 636) freq 1, sample_freq 65552: Ok (nr samples: 651) freq 1, sample_freq 8388607: Ok Op PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Fail freq 0, sample_freq 15: Fail freq 0, sample_freq 16: Fail freq 0, sample_freq 17: Fail freq 0, sample_freq 143: Fail freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1604) freq 0, sample_freq 1234: Ok (nr samples: 1604) freq 0, sample_freq 4103: Ok (nr samples: 1604) freq 0, sample_freq 65520: Ok (nr samples: 2227) freq 0, sample_freq 65535: Ok (nr samples: 2296) freq 0, sample_freq 65552: Ok (nr samples: 2213) freq 0, sample_freq 8388607: Ok (nr samples: 250) freq 0, sample_freq 268435455: Ok (nr samples: 8) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Fail (nr samples: 4) freq 1, sample_freq 15: Fail (nr samples: 4) freq 1, sample_freq 16: Fail (nr samples: 4) freq 1, sample_freq 17: Fail (nr samples: 4) freq 1, sample_freq 143: Fail (nr samples: 5) freq 1, sample_freq 144: Fail (nr samples: 5) freq 1, sample_freq 145: Fail (nr samples: 5) freq 1, sample_freq 1234: Fail (nr samples: 8) freq 1, sample_freq 4103: Fail (nr samples: 33) freq 1, sample_freq 65520: Fail (nr samples: 546) freq 1, sample_freq 65535: Fail (nr samples: 544) freq 1, sample_freq 65552: Fail (nr samples: 555) freq 1, sample_freq 8388607: Ok IBS ioctl() tests: ------------------ Fetch PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Fail ioctl(period =3D 0xf ): Fail ioctl(period =3D 0x10 ): Ok ioctl(period =3D 0x11 ): Fail ioctl(period =3D 0x1f ): Fail ioctl(period =3D 0x20 ): Ok ioctl(period =3D 0x80 ): Ok ioctl(period =3D 0x8f ): Fail ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Fail ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Fail ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Fail ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok Op PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Fail ioctl(period =3D 0xf ): Fail ioctl(period =3D 0x10 ): Fail ioctl(period =3D 0x11 ): Fail ioctl(period =3D 0x1f ): Fail ioctl(period =3D 0x20 ): Fail ioctl(period =3D 0x80 ): Fail ioctl(period =3D 0x8f ): Fail ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Fail ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Fail ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Fail ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok IBS freq (negative) tests: -------------------------- freq 1, sample_freq 200000: Fail IBS L3MissOnly test: (takes a while) -------------------- Fetch L3MissOnly: Fail (nr_samples: 1213) Op L3MissOnly: Ok (nr_samples: 1193) ---- end(-1) ---- 112: AMD IBS sample period : FA= ILED! With kernel fixes: $ sudo ./perf test -vv 112 112: AMD IBS sample period: --- start --- test child forked, pid 6939 Using CPUID AuthenticAMD-26-2-1 IBS config tests: ----------------- Fetch PMU tests: 0xffff : Ok (nr samples: 969) 0x1000 : Ok (nr samples: 15540) 0xff : Ok (nr samples: 40555) 0x1 : Ok (nr samples: 40543) 0x0 : Ok 0x10000 : Ok Op PMU tests: 0x0 : Ok 0x1 : Ok 0x8 : Ok 0x9 : Ok (nr samples: 40543) 0xf : Ok (nr samples: 40543) 0x1000 : Ok (nr samples: 19156) 0xffff : Ok (nr samples: 1169) 0x10000 : Ok 0x100000 : Ok (nr samples: 1151) 0xf00000 : Ok (nr samples: 76) 0xf0ffff : Ok (nr samples: 73) 0x1f0ffff : Ok (nr samples: 33) 0x7f0ffff : Ok (nr samples: 10) 0x8f0ffff : Ok 0x17f0ffff : Ok IBS sample period constraint tests: ----------------------------------- Fetch PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Ok freq 0, sample_freq 15: Ok freq 0, sample_freq 16: Ok (nr samples: 1203) freq 0, sample_freq 17: Ok (nr samples: 1604) freq 0, sample_freq 143: Ok (nr samples: 1604) freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1604) freq 0, sample_freq 1234: Ok (nr samples: 1604) freq 0, sample_freq 4103: Ok (nr samples: 1343) freq 0, sample_freq 65520: Ok (nr samples: 2254) freq 0, sample_freq 65535: Ok (nr samples: 2136) freq 0, sample_freq 65552: Ok (nr samples: 1158) freq 0, sample_freq 8388607: Ok (nr samples: 257) freq 0, sample_freq 268435455: Ok (nr samples: 8) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Ok (nr samples: 4) freq 1, sample_freq 15: Ok (nr samples: 4) freq 1, sample_freq 16: Ok (nr samples: 4) freq 1, sample_freq 17: Ok (nr samples: 4) freq 1, sample_freq 143: Ok (nr samples: 5) freq 1, sample_freq 144: Ok (nr samples: 5) freq 1, sample_freq 145: Ok (nr samples: 5) freq 1, sample_freq 1234: Ok (nr samples: 8) freq 1, sample_freq 4103: Ok (nr samples: 34) freq 1, sample_freq 65520: Ok (nr samples: 458) freq 1, sample_freq 65535: Ok (nr samples: 628) freq 1, sample_freq 65552: Ok (nr samples: 396) freq 1, sample_freq 8388607: Ok Op PMU test: freq 0, sample_freq 0: Ok freq 0, sample_freq 1: Ok freq 0, sample_freq 15: Ok freq 0, sample_freq 16: Ok freq 0, sample_freq 17: Ok freq 0, sample_freq 143: Ok freq 0, sample_freq 144: Ok (nr samples: 1604) freq 0, sample_freq 145: Ok (nr samples: 1604) freq 0, sample_freq 1234: Ok (nr samples: 1604) freq 0, sample_freq 4103: Ok (nr samples: 1604) freq 0, sample_freq 65520: Ok (nr samples: 2250) freq 0, sample_freq 65535: Ok (nr samples: 2158) freq 0, sample_freq 65552: Ok (nr samples: 2296) freq 0, sample_freq 8388607: Ok (nr samples: 243) freq 0, sample_freq 268435455: Ok (nr samples: 6) freq 1, sample_freq 0: Ok freq 1, sample_freq 1: Ok (nr samples: 4) freq 1, sample_freq 15: Ok (nr samples: 4) freq 1, sample_freq 16: Ok (nr samples: 4) freq 1, sample_freq 17: Ok (nr samples: 4) freq 1, sample_freq 143: Ok (nr samples: 4) freq 1, sample_freq 144: Ok (nr samples: 5) freq 1, sample_freq 145: Ok (nr samples: 4) freq 1, sample_freq 1234: Ok (nr samples: 6) freq 1, sample_freq 4103: Ok (nr samples: 27) freq 1, sample_freq 65520: Ok (nr samples: 542) freq 1, sample_freq 65535: Ok (nr samples: 550) freq 1, sample_freq 65552: Ok (nr samples: 552) freq 1, sample_freq 8388607: Ok IBS ioctl() tests: ------------------ Fetch PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Ok ioctl(period =3D 0xf ): Ok ioctl(period =3D 0x10 ): Ok ioctl(period =3D 0x11 ): Ok ioctl(period =3D 0x1f ): Ok ioctl(period =3D 0x20 ): Ok ioctl(period =3D 0x80 ): Ok ioctl(period =3D 0x8f ): Ok ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Ok ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Ok ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Ok ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok Op PMU tests ioctl(period =3D 0x0 ): Ok ioctl(period =3D 0x1 ): Ok ioctl(period =3D 0xf ): Ok ioctl(period =3D 0x10 ): Ok ioctl(period =3D 0x11 ): Ok ioctl(period =3D 0x1f ): Ok ioctl(period =3D 0x20 ): Ok ioctl(period =3D 0x80 ): Ok ioctl(period =3D 0x8f ): Ok ioctl(period =3D 0x90 ): Ok ioctl(period =3D 0x91 ): Ok ioctl(period =3D 0x100 ): Ok ioctl(period =3D 0xfff0 ): Ok ioctl(period =3D 0xffff ): Ok ioctl(period =3D 0x10000 ): Ok ioctl(period =3D 0x1fff0 ): Ok ioctl(period =3D 0x1fff5 ): Ok ioctl(freq =3D 0x0 ): Ok ioctl(freq =3D 0x1 ): Ok ioctl(freq =3D 0xf ): Ok ioctl(freq =3D 0x10 ): Ok ioctl(freq =3D 0x11 ): Ok ioctl(freq =3D 0x1f ): Ok ioctl(freq =3D 0x20 ): Ok ioctl(freq =3D 0x80 ): Ok ioctl(freq =3D 0x8f ): Ok ioctl(freq =3D 0x90 ): Ok ioctl(freq =3D 0x91 ): Ok ioctl(freq =3D 0x100 ): Ok IBS freq (negative) tests: -------------------------- freq 1, sample_freq 200000: Ok IBS L3MissOnly test: (takes a while) -------------------- Fetch L3MissOnly: Ok (nr_samples: 1301) Op L3MissOnly: Ok (nr_samples: 1590) ---- end(0) ---- 112: AMD IBS sample period : Ok Signed-off-by: Ravi Bangoria --- tools/perf/arch/x86/include/arch-tests.h | 1 + tools/perf/arch/x86/tests/Build | 1 + tools/perf/arch/x86/tests/amd-ibs-period.c | 951 +++++++++++++++++++++ tools/perf/arch/x86/tests/arch-tests.c | 2 + 4 files changed, 955 insertions(+) create mode 100644 tools/perf/arch/x86/tests/amd-ibs-period.c diff --git a/tools/perf/arch/x86/include/arch-tests.h b/tools/perf/arch/x86= /include/arch-tests.h index c0421a26b875..4fd425157d7d 100644 --- a/tools/perf/arch/x86/include/arch-tests.h +++ b/tools/perf/arch/x86/include/arch-tests.h @@ -14,6 +14,7 @@ int test__intel_pt_hybrid_compat(struct test_suite *test,= int subtest); int test__bp_modify(struct test_suite *test, int subtest); int test__x86_sample_parsing(struct test_suite *test, int subtest); int test__amd_ibs_via_core_pmu(struct test_suite *test, int subtest); +int test__amd_ibs_period(struct test_suite *test, int subtest); int test__hybrid(struct test_suite *test, int subtest); =20 extern struct test_suite *arch_tests[]; diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Bu= ild index 3227053f3355..db4b7945fc40 100644 --- a/tools/perf/arch/x86/tests/Build +++ b/tools/perf/arch/x86/tests/Build @@ -10,6 +10,7 @@ perf-test-$(CONFIG_AUXTRACE) +=3D insn-x86.o endif perf-test-$(CONFIG_X86_64) +=3D bp-modify.o perf-test-y +=3D amd-ibs-via-core-pmu.o +perf-test-y +=3D amd-ibs-period.o =20 ifdef SHELLCHECK SHELL_TESTS :=3D gen-insn-x86-dat.sh diff --git a/tools/perf/arch/x86/tests/amd-ibs-period.c b/tools/perf/arch/x= 86/tests/amd-ibs-period.c new file mode 100644 index 000000000000..6d491c036551 --- /dev/null +++ b/tools/perf/arch/x86/tests/amd-ibs-period.c @@ -0,0 +1,951 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + +#include "arch-tests.h" +#include "linux/perf_event.h" +#include "linux/zalloc.h" +#include "tests/tests.h" +#include "../perf-sys.h" +#include "pmu.h" +#include "pmus.h" +#include "debug.h" +#include "util.h" +#include "strbuf.h" +#include "../util/env.h" + +#define PAGE_SIZE sysconf(_SC_PAGESIZE) + +#define PERF_MMAP_DATA_PAGES 32L +#define PERF_MMAP_DATA_SIZE (PERF_MMAP_DATA_PAGES * PAGE_SIZE) +#define PERF_MMAP_DATA_MASK (PERF_MMAP_DATA_SIZE - 1) +#define PERF_MMAP_TOTAL_PAGES (PERF_MMAP_DATA_PAGES + 1) +#define PERF_MMAP_TOTAL_SIZE (PERF_MMAP_TOTAL_PAGES * PAGE_SIZE) + +#define rmb() asm volatile("lfence":::"memory") + +enum { + FD_ERROR, + FD_SUCCESS, +}; + +enum { + IBS_FETCH, + IBS_OP, +}; + +struct perf_pmu *fetch_pmu; +struct perf_pmu *op_pmu; +unsigned int perf_event_max_sample_rate; + +/* Dummy workload to generate IBS samples. */ +static int dummy_workload_1(unsigned long count) +{ + int (*func)(void); + int ret =3D 0; + char *p; + char insn1[] =3D { + 0xb8, 0x01, 0x00, 0x00, 0x00, /* mov 1,%eax */ + 0xc3, /* ret */ + 0xcc, /* int 3 */ + }; + + char insn2[] =3D { + 0xb8, 0x02, 0x00, 0x00, 0x00, /* mov 2,%eax */ + 0xc3, /* ret */ + 0xcc, /* int 3 */ + }; + + p =3D zalloc(2 * PAGE_SIZE); + if (!p) { + printf("malloc() failed. %m"); + return 1; + } + + func =3D (void *)((unsigned long)(p + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)); + + ret =3D mprotect(func, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC); + if (ret) { + printf("mprotect() failed. %m"); + goto out; + } + + if (count < 100000) + count =3D 100000; + else if (count > 10000000) + count =3D 10000000; + while (count--) { + memcpy(func, insn1, sizeof(insn1)); + if (func() !=3D 1) { + pr_debug("ERROR insn1\n"); + ret =3D -1; + goto out; + } + memcpy(func, insn2, sizeof(insn2)); + if (func() !=3D 2) { + pr_debug("ERROR insn2\n"); + ret =3D -1; + goto out; + } + } + +out: + free(p); + return ret; +} + +/* Another dummy workload to generate IBS samples. */ +static void dummy_workload_2(char *perf) +{ + char bench[] =3D " bench sched messaging -g 10 -l 5000 > /dev/null 2>&1"; + char taskset[] =3D "taskset -c 0 "; + int ret __maybe_unused; + struct strbuf sb; + char *cmd; + + strbuf_init(&sb, 0); + strbuf_add(&sb, taskset, strlen(taskset)); + strbuf_add(&sb, perf, strlen(perf)); + strbuf_add(&sb, bench, strlen(bench)); + cmd =3D strbuf_detach(&sb, NULL); + ret =3D system(cmd); + free(cmd); +} + +static int sched_affine(int cpu) +{ + cpu_set_t set; + + CPU_ZERO(&set); + CPU_SET(cpu, &set); + if (sched_setaffinity(getpid(), sizeof(set), &set) =3D=3D -1) { + pr_debug("sched_setaffinity() failed. [%m]"); + return -1; + } + return 0; +} + +static void +copy_sample_data(void *src, unsigned long offset, void *dest, size_t size) +{ + size_t chunk1_size, chunk2_size; + + if ((offset + size) < (size_t)PERF_MMAP_DATA_SIZE) { + memcpy(dest, src + offset, size); + } else { + chunk1_size =3D PERF_MMAP_DATA_SIZE - offset; + chunk2_size =3D size - chunk1_size; + + memcpy(dest, src + offset, chunk1_size); + memcpy(dest + chunk1_size, src, chunk2_size); + } +} + +static int rb_read(struct perf_event_mmap_page *rb, void *dest, size_t siz= e) +{ + void *base; + unsigned long data_tail, data_head; + + /* Casting to (void *) is needed. */ + base =3D (void *)rb + PAGE_SIZE; + + data_head =3D rb->data_head; + rmb(); + data_tail =3D rb->data_tail; + + if ((data_head - data_tail) < size) + return -1; + + data_tail &=3D PERF_MMAP_DATA_MASK; + copy_sample_data(base, data_tail, dest, size); + rb->data_tail +=3D size; + return 0; +} + +static void rb_skip(struct perf_event_mmap_page *rb, size_t size) +{ + size_t data_head =3D rb->data_head; + + rmb(); + + if ((rb->data_tail + size) > data_head) + rb->data_tail =3D data_head; + else + rb->data_tail +=3D size; +} + +/* Sample period value taken from perf sample must match with expected val= ue. */ +static int period_equal(unsigned long exp_period, unsigned long act_period) +{ + return exp_period =3D=3D act_period ? 0 : -1; +} + +/* + * Sample period value taken from perf sample must be >=3D minimum sample = period + * supported by IBS HW. + */ +static int period_higher(unsigned long min_period, unsigned long act_perio= d) +{ + return min_period <=3D act_period ? 0 : -1; +} + +static int rb_drain_samples(struct perf_event_mmap_page *rb, + unsigned long exp_period, + int *nr_samples, + int (*callback)(unsigned long, unsigned long)) +{ + struct perf_event_header hdr; + unsigned long period; + int ret =3D 0; + + /* + * PERF_RECORD_SAMPLE: + * struct { + * struct perf_event_header hdr; + * { u64 period; } && PERF_SAMPLE_PERIOD + * }; + */ + while (1) { + if (rb_read(rb, &hdr, sizeof(hdr))) + return ret; + + if (hdr.type =3D=3D PERF_RECORD_SAMPLE) { + (*nr_samples)++; + period =3D 0; + if (rb_read(rb, &period, sizeof(period))) + pr_debug("rb_read(period) error. [%m]"); + ret |=3D callback(exp_period, period); + } else { + rb_skip(rb, hdr.size - sizeof(hdr)); + } + } + return ret; +} + +static long perf_event_open(struct perf_event_attr *attr, pid_t pid, + int cpu, int group_fd, unsigned long flags) +{ + return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); +} + +static void fetch_prepare_attr(struct perf_event_attr *attr, + unsigned long long config, int freq, + unsigned long sample_period) +{ + memset(attr, 0, sizeof(struct perf_event_attr)); + + attr->type =3D fetch_pmu->type; + attr->size =3D sizeof(struct perf_event_attr); + attr->config =3D config; + attr->disabled =3D 1; + attr->sample_type =3D PERF_SAMPLE_PERIOD; + attr->freq =3D freq; + attr->sample_period =3D sample_period; /* =3D ->sample_freq */ +} + +static void op_prepare_attr(struct perf_event_attr *attr, + unsigned long config, int freq, + unsigned long sample_period) +{ + memset(attr, 0, sizeof(struct perf_event_attr)); + + attr->type =3D op_pmu->type; + attr->size =3D sizeof(struct perf_event_attr); + attr->config =3D config; + attr->disabled =3D 1; + attr->sample_type =3D PERF_SAMPLE_PERIOD; + attr->freq =3D freq; + attr->sample_period =3D sample_period; /* =3D ->sample_freq */ +} + +struct ibs_configs { + /* Input */ + unsigned long config; + + /* Expected output */ + unsigned long period; + int fd; +}; + +/* + * Somehow first Fetch event with sample period =3D 0x10 causes 0 + * samples. So start with large period and decrease it gradually. + */ +struct ibs_configs fetch_configs[] =3D { + { .config =3D 0xffff, .period =3D 0xffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1000, .period =3D 0x10000, .fd =3D FD_SUCCESS }, + { .config =3D 0xff, .period =3D 0xff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1, .period =3D 0x10, .fd =3D FD_SUCCESS }, + { .config =3D 0x0, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x10000, .period =3D -1, .fd =3D FD_ERROR }, +}; + +struct ibs_configs op_configs[] =3D { + { .config =3D 0x0, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x1, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x8, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x9, .period =3D 0x90, .fd =3D FD_SUCCESS }, + { .config =3D 0xf, .period =3D 0xf0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1000, .period =3D 0x10000, .fd =3D FD_SUCCESS }, + { .config =3D 0xffff, .period =3D 0xffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x10000, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x100000, .period =3D 0x100000, .fd =3D FD_SUCCESS }, + { .config =3D 0xf00000, .period =3D 0xf00000, .fd =3D FD_SUCCESS }, + { .config =3D 0xf0ffff, .period =3D 0xfffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x1f0ffff, .period =3D 0x1fffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x7f0ffff, .period =3D 0x7fffff0, .fd =3D FD_SUCCESS }, + { .config =3D 0x8f0ffff, .period =3D -1, .fd =3D FD_ERROR }, + { .config =3D 0x17f0ffff, .period =3D -1, .fd =3D FD_ERROR }, +}; + +static int __ibs_config_test(int ibs_type, struct ibs_configs *config, int= *nr_samples) +{ + struct perf_event_attr attr; + int fd, i; + void *rb; + int ret =3D 0; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, config->config, 0, 0); + else + op_prepare_attr(&attr, config->config, 0, 0); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (config->fd =3D=3D FD_ERROR) { + if (fd !=3D -1) { + close(fd); + return -1; + } + return 0; + } + if (fd <=3D -1) + return -1; + + rb =3D mmap(NULL, PERF_MMAP_TOTAL_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (rb =3D=3D MAP_FAILED) { + pr_debug("mmap() failed. [%m]\n"); + return -1; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + + i =3D 5; + while (i--) { + dummy_workload_1(1000000); + + ret =3D rb_drain_samples(rb, config->period, nr_samples, + period_equal); + if (ret) + break; + } + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + munmap(rb, PERF_MMAP_TOTAL_SIZE); + close(fd); + return ret; +} + +static int ibs_config_test(void) +{ + int nr_samples =3D 0; + unsigned long i; + int ret =3D 0; + int r; + + pr_debug("\nIBS config tests:\n"); + pr_debug("-----------------\n"); + + pr_debug("Fetch PMU tests:\n"); + for (i =3D 0; i < ARRAY_SIZE(fetch_configs); i++) { + nr_samples =3D 0; + r =3D __ibs_config_test(IBS_FETCH, &(fetch_configs[i]), &nr_samples); + + if (fetch_configs[i].fd =3D=3D FD_ERROR) { + pr_debug("0x%-16lx: %-4s\n", fetch_configs[i].config, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("0x%-16lx: %-4s (nr samples: %d)\n", fetch_configs[i].config, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + + ret |=3D r; + } + + pr_debug("Op PMU tests:\n"); + for (i =3D 0; i < ARRAY_SIZE(op_configs); i++) { + nr_samples =3D 0; + r =3D __ibs_config_test(IBS_OP, &(op_configs[i]), &nr_samples); + + if (op_configs[i].fd =3D=3D FD_ERROR) { + pr_debug("0x%-16lx: %-4s\n", op_configs[i].config, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("0x%-16lx: %-4s (nr samples: %d)\n", op_configs[i].config, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + + ret |=3D r; + } + + return ret; +} + +struct ibs_period { + /* Input */ + int freq; + unsigned long sample_freq; + + /* Output */ + int ret; + unsigned long period; +}; + +struct ibs_period fetch_period[] =3D { + { .freq =3D 0, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 1, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0xf, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x10, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 0, .sample_freq =3D 0x11, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 0, .sample_freq =3D 0x8f, .ret =3D FD_SUCCESS, .period = =3D 0x80 }, + { .freq =3D 0, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x4d0 }, + { .freq =3D 0, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x1000 }, + { .freq =3D 0, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x10010 }, + { .freq =3D 0, .sample_freq =3D 0x7fffff, .ret =3D FD_SUCCESS, .period = =3D 0x7ffff0 }, + { .freq =3D 0, .sample_freq =3D 0xfffffff, .ret =3D FD_SUCCESS, .period = =3D 0xffffff0 }, + { .freq =3D 1, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 1, .sample_freq =3D 1, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0xf, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x10, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x11, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x8f, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + { .freq =3D 1, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x10 }, + /* ret=3DFD_ERROR because freq > default perf_event_max_sample_rate (1000= 00) */ + { .freq =3D 1, .sample_freq =3D 0x7fffff, .ret =3D FD_ERROR, .period = =3D -1 }, +}; + +struct ibs_period op_period[] =3D { + { .freq =3D 0, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 1, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0xf, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x10, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x11, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x8f, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 0, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 0, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x4d0 }, + { .freq =3D 0, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x1000 }, + { .freq =3D 0, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0xfff0 }, + { .freq =3D 0, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x10010 }, + { .freq =3D 0, .sample_freq =3D 0x7fffff, .ret =3D FD_SUCCESS, .period = =3D 0x7ffff0 }, + { .freq =3D 0, .sample_freq =3D 0xfffffff, .ret =3D FD_SUCCESS, .period = =3D 0xffffff0 }, + { .freq =3D 1, .sample_freq =3D 0, .ret =3D FD_ERROR, .period = =3D -1 }, + { .freq =3D 1, .sample_freq =3D 1, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0xf, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x10, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x11, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x8f, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x90, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x91, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x4d2, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x1007, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0xfff0, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0xffff, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + { .freq =3D 1, .sample_freq =3D 0x10010, .ret =3D FD_SUCCESS, .period = =3D 0x90 }, + /* ret=3DFD_ERROR because freq > default perf_event_max_sample_rate (1000= 00) */ + { .freq =3D 1, .sample_freq =3D 0x7fffff, .ret =3D FD_ERROR, .period = =3D -1 }, +}; + +static int __ibs_period_constraint_test(int ibs_type, struct ibs_period *p= eriod, + int *nr_samples) +{ + struct perf_event_attr attr; + int ret =3D 0; + void *rb; + int fd; + + if (period->freq && period->sample_freq >=3D perf_event_max_sample_rate) + period->ret =3D FD_ERROR; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, 0, period->freq, period->sample_freq); + else + op_prepare_attr(&attr, 0, period->freq, period->sample_freq); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (period->ret =3D=3D FD_ERROR) { + if (fd !=3D -1) { + close(fd); + return -1; + } + return 0; + } + if (fd <=3D -1) + return -1; + + rb =3D mmap(NULL, PERF_MMAP_TOTAL_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (rb =3D=3D MAP_FAILED) { + pr_debug("mmap() failed. [%m]\n"); + close(fd); + return -1; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + + if (period->freq) { + dummy_workload_1(100000); + ret =3D rb_drain_samples(rb, period->period, nr_samples, + period_higher); + } else { + dummy_workload_1(period->sample_freq * 10); + ret =3D rb_drain_samples(rb, period->period, nr_samples, + period_equal); + } + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + munmap(rb, PERF_MMAP_TOTAL_SIZE); + close(fd); + return ret; +} + +static int ibs_period_constraint_test(void) +{ + unsigned long i; + int nr_samples; + int ret =3D 0; + int r; + + pr_debug("\nIBS sample period constraint tests:\n"); + pr_debug("-----------------------------------\n"); + + pr_debug("Fetch PMU test:\n"); + for (i =3D 0; i < ARRAY_SIZE(fetch_period); i++) { + nr_samples =3D 0; + r =3D __ibs_period_constraint_test(IBS_FETCH, &fetch_period[i], + &nr_samples); + + if (fetch_period[i].ret =3D=3D FD_ERROR) { + pr_debug("freq %d, sample_freq %9ld: %-4s\n", + fetch_period[i].freq, fetch_period[i].sample_freq, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("freq %d, sample_freq %9ld: %-4s (nr samples: %d)\n", + fetch_period[i].freq, fetch_period[i].sample_freq, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + ret |=3D r; + } + + pr_debug("Op PMU test:\n"); + for (i =3D 0; i < ARRAY_SIZE(op_period); i++) { + nr_samples =3D 0; + r =3D __ibs_period_constraint_test(IBS_OP, &op_period[i], + &nr_samples); + + if (op_period[i].ret =3D=3D FD_ERROR) { + pr_debug("freq %d, sample_freq %9ld: %-4s\n", + op_period[i].freq, op_period[i].sample_freq, + !r ? "Ok" : "Fail"); + } else { + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("freq %d, sample_freq %9ld: %-4s (nr samples: %d)\n", + op_period[i].freq, op_period[i].sample_freq, + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + } + ret |=3D r; + } + + return ret; +} + +struct ibs_ioctl { + /* Input */ + int freq; + unsigned long period; + + /* Expected output */ + int ret; +}; + +struct ibs_ioctl fetch_ioctl[] =3D { + { .freq =3D 0, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0xf, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x11, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x20, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x80, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x8f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x91, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x100, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xfff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xffff, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10000, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff5, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x1, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0xf, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x10, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x11, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x1f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x20, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x80, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x8f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x91, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x100, .ret =3D FD_SUCCESS }, +}; + +struct ibs_ioctl op_ioctl[] =3D { + { .freq =3D 0, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0xf, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x11, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x1f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x20, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x80, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x8f, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x91, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x100, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xfff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0xffff, .ret =3D FD_ERROR }, + { .freq =3D 0, .period =3D 0x10000, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff0, .ret =3D FD_SUCCESS }, + { .freq =3D 0, .period =3D 0x1fff5, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x0, .ret =3D FD_ERROR }, + { .freq =3D 1, .period =3D 0x1, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0xf, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x10, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x11, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x1f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x20, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x80, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x8f, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x90, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x91, .ret =3D FD_SUCCESS }, + { .freq =3D 1, .period =3D 0x100, .ret =3D FD_SUCCESS }, +}; + +static int __ibs_ioctl_test(int ibs_type, struct ibs_ioctl *ibs_ioctl) +{ + struct perf_event_attr attr; + int ret =3D 0; + int fd; + int r; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, 0, ibs_ioctl->freq, 1000); + else + op_prepare_attr(&attr, 0, ibs_ioctl->freq, 1000); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (fd <=3D -1) { + pr_debug("event_open() Failed\n"); + return -1; + } + + r =3D ioctl(fd, PERF_EVENT_IOC_PERIOD, &ibs_ioctl->period); + if ((ibs_ioctl->ret =3D=3D FD_SUCCESS && r <=3D -1) || + (ibs_ioctl->ret =3D=3D FD_ERROR && r >=3D 0)) { + ret =3D -1; + } + + close(fd); + return ret; +} + +static int ibs_ioctl_test(void) +{ + unsigned long i; + int ret =3D 0; + int r; + + pr_debug("\nIBS ioctl() tests:\n"); + pr_debug("------------------\n"); + + pr_debug("Fetch PMU tests\n"); + for (i =3D 0; i < ARRAY_SIZE(fetch_ioctl); i++) { + r =3D __ibs_ioctl_test(IBS_FETCH, &fetch_ioctl[i]); + + pr_debug("ioctl(%s =3D 0x%-7lx): %s\n", + fetch_ioctl[i].freq ? "freq " : "period", + fetch_ioctl[i].period, r ? "Fail" : "Ok"); + ret |=3D r; + } + + pr_debug("Op PMU tests\n"); + for (i =3D 0; i < ARRAY_SIZE(op_ioctl); i++) { + r =3D __ibs_ioctl_test(IBS_OP, &op_ioctl[i]); + + pr_debug("ioctl(%s =3D 0x%-7lx): %s\n", + op_ioctl[i].freq ? "freq " : "period", + op_ioctl[i].period, r ? "Fail" : "Ok"); + ret |=3D r; + } + + return ret; +} + +static int ibs_freq_neg_test(void) +{ + struct perf_event_attr attr; + int fd; + + pr_debug("\nIBS freq (negative) tests:\n"); + pr_debug("--------------------------\n"); + + /* + * Assuming perf_event_max_sample_rate <=3D 100000, + * config: 0x300D40 =3D=3D> MaxCnt: 200000 + */ + op_prepare_attr(&attr, 0x300D40, 1, 0); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (fd !=3D -1) { + pr_debug("freq 1, sample_freq 200000: Fail\n"); + close(fd); + return -1; + } + + pr_debug("freq 1, sample_freq 200000: Ok\n"); + + return 0; +} + +static int __ibs_l3missonly_test(char *perf, int ibs_type, int *nr_samples= , int min_period) +{ + struct perf_event_attr attr; + int ret =3D 0; + void *rb; + int fd; + + if (ibs_type =3D=3D IBS_FETCH) + fetch_prepare_attr(&attr, 0x800000000000000UL, 1, 10000); + else + op_prepare_attr(&attr, 0x10000, 1, 10000); + + /* CPU0, All processes */ + fd =3D perf_event_open(&attr, -1, 0, -1, 0); + if (fd =3D=3D -1) { + pr_debug("perf_event_open() failed. [%m]\n"); + return -1; + } + + rb =3D mmap(NULL, PERF_MMAP_TOTAL_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (rb =3D=3D MAP_FAILED) { + pr_debug("mmap() failed. [%m]\n"); + close(fd); + return -1; + } + + ioctl(fd, PERF_EVENT_IOC_RESET, 0); + ioctl(fd, PERF_EVENT_IOC_ENABLE, 0); + + dummy_workload_2(perf); + + ioctl(fd, PERF_EVENT_IOC_DISABLE, 0); + + ret =3D rb_drain_samples(rb, min_period, nr_samples, period_higher); + + munmap(rb, PERF_MMAP_TOTAL_SIZE); + close(fd); + return ret; +} + +static int ibs_l3missonly_test(char *perf) +{ + int nr_samples =3D 0; + int ret =3D 0; + int r =3D 0; + + pr_debug("\nIBS L3MissOnly test: (takes a while)\n"); + pr_debug("--------------------\n"); + + if (perf_pmu__has_format(fetch_pmu, "l3missonly")) { + nr_samples =3D 0; + r =3D __ibs_l3missonly_test(perf, IBS_FETCH, &nr_samples, 0x10); + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("Fetch L3MissOnly: %-4s (nr_samples: %d)\n", + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + ret |=3D r; + } + + if (perf_pmu__has_format(op_pmu, "l3missonly")) { + nr_samples =3D 0; + r =3D __ibs_l3missonly_test(perf, IBS_OP, &nr_samples, 0x90); + /* + * Although nr_samples =3D=3D 0 is reported as Fail here, + * the failure status is not cascaded up because, we + * can not decide whether test really failed or not + * without actual samples. + */ + pr_debug("Op L3MissOnly: %-4s (nr_samples: %d)\n", + (!r && nr_samples !=3D 0) ? "Ok" : "Fail", nr_samples); + ret |=3D r; + } + + return ret; +} + +static unsigned int get_perf_event_max_sample_rate(void) +{ + unsigned int max_sample_rate =3D 100000; + FILE *fp; + int ret; + + fp =3D fopen("/proc/sys/kernel/perf_event_max_sample_rate", "r"); + if (!fp) { + pr_debug("Can't open perf_event_max_sample_rate. Asssuming %d\n", + max_sample_rate); + goto out; + } + + ret =3D fscanf(fp, "%d", &max_sample_rate); + if (ret =3D=3D EOF) { + pr_debug("Can't read perf_event_max_sample_rate. Assuming 100000\n"); + max_sample_rate =3D 100000; + } + fclose(fp); + +out: + return max_sample_rate; +} + +int test__amd_ibs_period(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + char perf[PATH_MAX] =3D {'\0'}; + int ret =3D TEST_OK; + + perf_event_max_sample_rate =3D get_perf_event_max_sample_rate(); + fetch_pmu =3D perf_pmus__find("ibs_fetch"); + op_pmu =3D perf_pmus__find("ibs_op"); + + if (!x86__is_amd_cpu() || !fetch_pmu || !op_pmu) + return TEST_SKIP; + + perf_exe(perf, sizeof(perf)); + + if (sched_affine(0)) + return TEST_FAIL; + + /* + * Perf event can be opened in two modes: + * 1 Freq mode + * perf_event_attr->freq =3D 1, ->sample_freq =3D + * 2 Sample period mode + * perf_event_attr->freq =3D 0, ->sample_period =3D + * + * Instead of using above interface, IBS event in 'sample period mode' + * can also be opened by passing value directly in a MaxCnt + * bitfields of perf_event_attr->config. Test this IBS specific special + * interface. + */ + if (ibs_config_test()) + ret =3D TEST_FAIL; + + /* + * IBS Fetch and Op PMUs have HW constraints on minimum sample period. + * Also, sample period value must be in multiple of 0x10. Test that IBS + * driver honors HW constraints for various possible values in Freq as + * well as Sample Period mode IBS events. + */ + if (ibs_period_constraint_test()) + ret =3D TEST_FAIL; + + /* + * Test ioctl() with various sample period values for IBS event. + */ + if (ibs_ioctl_test()) + ret =3D TEST_FAIL; + + /* + * Test that opening of freq mode IBS event fails when the freq value + * is passed through ->config, not explicitly in ->sample_freq. Also + * use high freq value (beyond perf_event_max_sample_rate) to test IBS + * driver do not bypass perf_event_max_sample_rate checks. + */ + if (ibs_freq_neg_test()) + ret =3D TEST_FAIL; + + /* + * L3MissOnly is a post-processing filter, i.e. IBS HW checks for L3 + * Miss at the completion of the tagged uOp. The sample is discarded + * if the tagged uOp did not cause L3Miss. Also, IBS HW internally + * resets CurCnt to a small pseudo-random value and resumes counting. + * A new uOp is tagged once CurCnt reaches to MaxCnt. But the process + * repeats until the tagged uOp causes an L3 Miss. + * + * With the freq mode event, the next sample period is calculated by + * generic kernel on every sample to achieve desired freq of samples. + * + * Since the number of times HW internally reset CurCnt and the pseudo- + * random value of CurCnt for all those occurrences are not known to SW, + * the sample period adjustment by kernel goes for a toes for freq mode + * IBS events. Kernel will set very small period for the next sample if + * the window between current sample and prev sample is too high due to + * multiple samples being rejected by IBS internally. + * + * Test that IBS sample period constraints are honored when L3MissOnly + * is ON. + */ + if (ibs_l3missonly_test(perf)) + ret =3D TEST_FAIL; + + return ret; +} diff --git a/tools/perf/arch/x86/tests/arch-tests.c b/tools/perf/arch/x86/t= ests/arch-tests.c index a216a5d172ed..bfee2432515b 100644 --- a/tools/perf/arch/x86/tests/arch-tests.c +++ b/tools/perf/arch/x86/tests/arch-tests.c @@ -25,6 +25,7 @@ DEFINE_SUITE("x86 bp modify", bp_modify); #endif DEFINE_SUITE("x86 Sample parsing", x86_sample_parsing); DEFINE_SUITE("AMD IBS via core pmu", amd_ibs_via_core_pmu); +DEFINE_SUITE_EXCLUSIVE("AMD IBS sample period", amd_ibs_period); static struct test_case hybrid_tests[] =3D { TEST_CASE_REASON("x86 hybrid event parsing", hybrid, "not hybrid"), { .name =3D NULL, } @@ -50,6 +51,7 @@ struct test_suite *arch_tests[] =3D { #endif &suite__x86_sample_parsing, &suite__amd_ibs_via_core_pmu, + &suite__amd_ibs_period, &suite__hybrid, NULL, }; --=20 2.43.0