From nobody Tue Jun 23 13:03:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 477A6C433EF for ; Fri, 4 Mar 2022 06:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238250AbiCDGKK (ORCPT ); Fri, 4 Mar 2022 01:10:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229962AbiCDGKG (ORCPT ); Fri, 4 Mar 2022 01:10:06 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2080.outbound.protection.outlook.com [40.107.223.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B02B13D0F; Thu, 3 Mar 2022 22:09:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Os9GBHywhLpa0es5Rav8hcd3Fu6ZDCyK5qV7VwUj4QKwmW9EWGUpI8cMzjS7Urd3OYr2tKtgo/HjAxo1n7XhDohsHCc3jwCXGZNEuRbdRcDeveV0CxeZ38d0dsxo31X+KtJDO2xm7gfAKnH/9QiShFd8W9eAPGmSf2KQoEdzPu18BxdSyst9SZG2Zj4/z9+Kz/beMrYjHVohMWbWXiVhX2SRJv12A7+gVvq0QuDEfDiQZk3KHmSG6PI7aXZwtvSb0i92wLQa9OjeWsBGoQ+MWQ0RqHFtYv2yATJ05+X9wcLw86/X3STVBT12/2Hf3YyjhnmYOYBA2AI1QPic3lrQgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LGweuggBnk3AQ02wK6JgGU6yJIbat/nGe/F8Ny3eduE=; b=XCAa+xydyFqNBVUQUdKHaf83kyLYwKHJZC2gkpAwPBGGBripdi0HV7ZjvAVE7S8lGjzAlTwRmdwjWbQppn/GDtzcoVVsNhQSt8T0BqlKdTcJaoQONV/8iWV6g0YmzK7nq70lgSAG1ig2zPK2a2UdHRgWK81r25njPODeGWKAIl1S+9hKza2YZ1cYFzJsXZsiF/pWVkVE4KS0GWh4wdI3JFfOPEgsre1eiSV2ln0L16XoxrmClj2qMeyjLKUE83XbuiX4ogOnnD1pWfkV8m1yVFNI2Jo/I/kdrdxlOTypH4Ij4+L3btmRCrx7jRqjtnYuF/WA2xM6N/OV/XOXbo4/rQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=rjwysocki.net 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 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=LGweuggBnk3AQ02wK6JgGU6yJIbat/nGe/F8Ny3eduE=; b=Yea0/UmuTNy02DOglph9gcUZfliHUjjORTQEOf3MUX6+UnO+KOZnM5XvrXYb/58o4osbM2HXDlQ/eANVW3Q62qjGMZNyEdPsHDN4i0fTqsaLLqZudv2p3FVdBurNUDJaOc6fkpWcuQtb5rDAhzJqtVarS8vfU3MXcXSnd2BWjas= Received: from BN9PR03CA0300.namprd03.prod.outlook.com (2603:10b6:408:f5::35) by MN2PR12MB3983.namprd12.prod.outlook.com (2603:10b6:208:169::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Fri, 4 Mar 2022 06:09:17 +0000 Received: from BN8NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::3b) by BN9PR03CA0300.outlook.office365.com (2603:10b6:408:f5::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:17 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT031.mail.protection.outlook.com (10.13.177.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:16 +0000 Received: from jinzhosu-System-Product-Name.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.2375.18; Fri, 4 Mar 2022 00:09:12 -0600 From: Jinzhou Su To: , , , CC: , , , , , , , , , , Jinzhou Su Subject: [PATCH V2 1/4] cpufreq: amd-pstate: Add more tracepoint for AMD P-State module Date: Fri, 4 Mar 2022 14:07:21 +0800 Message-ID: <20220304060724.314582-2-Jinzhou.Su@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220304060724.314582-1-Jinzhou.Su@amd.com> References: <20220304060724.314582-1-Jinzhou.Su@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 087784d6-3e72-4b0d-2785-08d9fda583aa X-MS-TrafficTypeDiagnostic: MN2PR12MB3983:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CwwBkPYWqp5iDiiiR7ShzceboDeJxpoJSiv2Diyt60KR/YLtnuUdeiZZD/d8klQgIxOZKttizT7E8KUAeJCCnYZix/hejotIVG8El8h4j01g/AF6qKg3qaFG+0/maqqSFPf9ROguu6GqmoqhvYiTkYwu3Wk0HjUjCEc2OhlxCLuCnF7IAwOl6GfKL0W1FJFaCuLkhQ+yR2Rog5EwgFzTwNhMOjbuROMVHA1De98mtpG+FOgKKO4KZpA9SuwAKRSHP16D6noSLhz458XwnNgizdbntUYEvYp3nImcU38PR1YGBHLFZG0luoIpsPYhN9qtcxKdG+6SL+4FyGPEKaE0QwVeEDgJUkNxwOoTuWZ1vb3/gpfteEHYIV2pcvX/K0kU6/oYT/6R6mHO6bRpzbb1PP/3RfeEGckkaAE+OV+Iq0wrEuaIllXzHxGv3+N0yIVwWjGh5ErcKoX5SrwcY6poqfaT+oh+6Ax3AjZlZR12X1VmmoN8RmfuGMG5MYd8LN37PAAp3X7b6LVVboYBNTKfDs5Y0iZ+4BYTAILygJy2WFBLwlsPkVcKBBtf0M7OPm7IWLMcOwJnrKiW6ibs7sY1LDdxMdq62LDOa+Jq7B5km7/oZWpvBmbjxV+vjmdYHOIQAdGBVGyt0xQNVWbza8Bml66wQK0NAYl732OLBR3ZZPZQ4VfaPsJZPoWLhhr9Po4atUwZTvk68YJ2cN6HymTZmw== 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:(13230001)(4636009)(46966006)(40470700004)(36840700001)(36860700001)(5660300002)(6666004)(83380400001)(36756003)(110136005)(54906003)(1076003)(186003)(26005)(47076005)(16526019)(336012)(7696005)(426003)(2616005)(2906002)(8936002)(316002)(508600001)(82310400004)(8676002)(356005)(4326008)(86362001)(81166007)(70206006)(70586007)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2022 06:09:16.9252 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 087784d6-3e72-4b0d-2785-08d9fda583aa 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: BN8NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3983 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add frequency, mperf, aperf and tsc in the trace. This can be used to debug and tune the performance of AMD P-state driver. Use the time difference between amd_pstate_update to calculate CPU frequency. There could be sleep in arch_freq_get_on_cpu, so do not use it here. Signed-off-by: Jinzhou Su Co-developed-by: Huang Rui Signed-off-by: Huang Rui --- drivers/cpufreq/amd-pstate-trace.h | 22 ++++++++++- drivers/cpufreq/amd-pstate.c | 59 +++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/amd-pstate-trace.h b/drivers/cpufreq/amd-pstat= e-trace.h index 647505957d4f..35f38ae67fb1 100644 --- a/drivers/cpufreq/amd-pstate-trace.h +++ b/drivers/cpufreq/amd-pstate-trace.h @@ -27,6 +27,10 @@ TRACE_EVENT(amd_pstate_perf, TP_PROTO(unsigned long min_perf, unsigned long target_perf, unsigned long capacity, + u64 freq, + u64 mperf, + u64 aperf, + u64 tsc, unsigned int cpu_id, bool changed, bool fast_switch @@ -35,6 +39,10 @@ TRACE_EVENT(amd_pstate_perf, TP_ARGS(min_perf, target_perf, capacity, + freq, + mperf, + aperf, + tsc, cpu_id, changed, fast_switch @@ -44,6 +52,10 @@ TRACE_EVENT(amd_pstate_perf, __field(unsigned long, min_perf) __field(unsigned long, target_perf) __field(unsigned long, capacity) + __field(unsigned long long, freq) + __field(unsigned long long, mperf) + __field(unsigned long long, aperf) + __field(unsigned long long, tsc) __field(unsigned int, cpu_id) __field(bool, changed) __field(bool, fast_switch) @@ -53,15 +65,23 @@ TRACE_EVENT(amd_pstate_perf, __entry->min_perf =3D min_perf; __entry->target_perf =3D target_perf; __entry->capacity =3D capacity; + __entry->freq =3D freq; + __entry->mperf =3D mperf; + __entry->aperf =3D aperf; + __entry->tsc =3D tsc; __entry->cpu_id =3D cpu_id; __entry->changed =3D changed; __entry->fast_switch =3D fast_switch; ), =20 - TP_printk("amd_min_perf=3D%lu amd_des_perf=3D%lu amd_max_perf=3D%lu cpu_i= d=3D%u changed=3D%s fast_switch=3D%s", + TP_printk("amd_min_perf=3D%lu amd_des_perf=3D%lu amd_max_perf=3D%lu freq= =3D%llu mperf=3D%llu aperf=3D%llu tsc=3D%llu cpu_id=3D%u changed=3D%s fast_= switch=3D%s", (unsigned long)__entry->min_perf, (unsigned long)__entry->target_perf, (unsigned long)__entry->capacity, + (unsigned long long)__entry->freq, + (unsigned long long)__entry->mperf, + (unsigned long long)__entry->aperf, + (unsigned long long)__entry->tsc, (unsigned int)__entry->cpu_id, (__entry->changed) ? "true" : "false", (__entry->fast_switch) ? "true" : "false" diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 9ce75ed11f8e..7be38bc6a673 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -65,6 +65,18 @@ MODULE_PARM_DESC(shared_mem, =20 static struct cpufreq_driver amd_pstate_driver; =20 +/** + * struct amd_aperf_mperf + * @aperf: actual performance frequency clock count + * @mperf: maximum performance frequency clock count + * @tsc: time stamp counter + */ +struct amd_aperf_mperf { + u64 aperf; + u64 mperf; + u64 tsc; +}; + /** * struct amd_cpudata - private CPU data for AMD P-State * @cpu: CPU number @@ -81,6 +93,9 @@ static struct cpufreq_driver amd_pstate_driver; * @min_freq: the frequency that mapped to lowest_perf * @nominal_freq: the frequency that mapped to nominal_perf * @lowest_nonlinear_freq: the frequency that mapped to lowest_nonlinear_p= erf + * @cur: Difference of Aperf/Mperf/tsc count between last and current samp= le + * @prev: Last Aperf/Mperf/tsc count value read from register + * @freq: current cpu frequency value * @boost_supported: check whether the Processor or SBIOS supports boost m= ode * * The amd_cpudata is key private data for each CPU thread in AMD P-State,= and @@ -102,6 +117,10 @@ struct amd_cpudata { u32 nominal_freq; u32 lowest_nonlinear_freq; =20 + struct amd_aperf_mperf cur; + struct amd_aperf_mperf prev; + + u64 freq; bool boost_supported; }; =20 @@ -211,6 +230,39 @@ static inline void amd_pstate_update_perf(struct amd_c= pudata *cpudata, max_perf, fast_switch); } =20 +static inline bool amd_pstate_sample(struct amd_cpudata *cpudata) +{ + u64 aperf, mperf, tsc; + unsigned long flags; + + local_irq_save(flags); + rdmsrl(MSR_IA32_APERF, aperf); + rdmsrl(MSR_IA32_MPERF, mperf); + tsc =3D rdtsc(); + + if (cpudata->prev.mperf =3D=3D mperf || cpudata->prev.tsc =3D=3D tsc) { + local_irq_restore(flags); + return false; + } + + local_irq_restore(flags); + + cpudata->cur.aperf =3D aperf; + cpudata->cur.mperf =3D mperf; + cpudata->cur.tsc =3D tsc; + cpudata->cur.aperf -=3D cpudata->prev.aperf; + cpudata->cur.mperf -=3D cpudata->prev.mperf; + cpudata->cur.tsc -=3D cpudata->prev.tsc; + + cpudata->prev.aperf =3D aperf; + cpudata->prev.mperf =3D mperf; + cpudata->prev.tsc =3D tsc; + + cpudata->freq =3D div64_u64((cpudata->cur.aperf * cpu_khz), cpudata->cur.= mperf); + + return true; +} + static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf, u32 des_perf, u32 max_perf, bool fast_switch) { @@ -226,8 +278,11 @@ static void amd_pstate_update(struct amd_cpudata *cpud= ata, u32 min_perf, value &=3D ~AMD_CPPC_MAX_PERF(~0L); value |=3D AMD_CPPC_MAX_PERF(max_perf); =20 - trace_amd_pstate_perf(min_perf, des_perf, max_perf, - cpudata->cpu, (value !=3D prev), fast_switch); + if (trace_amd_pstate_perf_enabled() && amd_pstate_sample(cpudata)) { + trace_amd_pstate_perf(min_perf, des_perf, max_perf, cpudata->freq, + cpudata->cur.mperf, cpudata->cur.aperf, cpudata->cur.tsc, + cpudata->cpu, (value !=3D prev), fast_switch); + } =20 if (value =3D=3D prev) return; --=20 2.27.0 From nobody Tue Jun 23 13:03:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE18BC433F5 for ; Fri, 4 Mar 2022 06:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiCDGKZ (ORCPT ); Fri, 4 Mar 2022 01:10:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238276AbiCDGKR (ORCPT ); Fri, 4 Mar 2022 01:10:17 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2047.outbound.protection.outlook.com [40.107.100.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C92EF45ACF; Thu, 3 Mar 2022 22:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sy8g511V63Up9oHsM/3XSPWjPZWRUQzWYDadkAEavv6faz8Kix/PDLp63zICDOY//uosprpGBaQjBXFeYuKoF6Dh/Xru1yD709zTONbU0SLgol7q836E2J35S8y4zoKxsFXgRsJJ5uaLccvNJSHHL9ck+4zd1vmva5/yKb32jyyBu8IZCbhqOvyWMb68bm4KJvpgLx2XJ2M0MWx3LRgfIgjAWqlXbaro65C0j88+eC6KtzdvxJzEICSEblrWRWg/boE22iXFGNDLto8LNpE6fOGmySJ152J/Xd1/xZ+ksEZF2aJte6BY4rW5OeMHKHqtegw2kvTVPbtWZq6Ikz5eOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vBlX5wVO9ovhQ6dNKrl9JGe6dARvGKz/HIvt+uXaxE4=; b=ktkSDNNJ8LbHZVbHTo0lM6+B/cPCJr3cKQt/R93DHeGopdAXDNyHKVGP48cwujvsSXfbqCZO99Mn5ToiVbQj7IeUi1v//3nbsWOb5pU3OQoB0QkFAY4iSLn1/0T0zMedZG0dZHjNaREk3IibQdSCJB5hQMDYZBvVDkwjor5Myy1ZJq6gM7KxVITksbUQgRcT7SB8RBK5TrSKlb4o/vDL2SY9W4atokaJdSkHBVmEqAJigOQsc9e8m/hJDoUiRRen//UeOngU0BKeX6QyLdi5OEUCw5bf+EnAKlc2YI6K7XE8PLdM+jaLsJY580luSh8RDLhGo5Z0MaPfaKpAKgLpVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=rjwysocki.net 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 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=vBlX5wVO9ovhQ6dNKrl9JGe6dARvGKz/HIvt+uXaxE4=; b=0L0PaePHhrL71jzOMyxBiqcn7E12ceDCxGZ5BVCOPkww19g3ld8q68Zs8qf1lhun6vRtvsckcG8pTTlqE994FiUP7ZT7lh6G7EDxGsFE0gYkNVu/lw96FfFDUM7WGbBchvx4Y7TNri5QWChK58tudWJrJJrvx1cycviXwoNT7uw= Received: from BN6PR2001CA0039.namprd20.prod.outlook.com (2603:10b6:405:16::25) by BL0PR12MB2548.namprd12.prod.outlook.com (2603:10b6:207:41::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.13; Fri, 4 Mar 2022 06:09:27 +0000 Received: from BN8NAM11FT005.eop-nam11.prod.protection.outlook.com (2603:10b6:405:16:cafe::50) by BN6PR2001CA0039.outlook.office365.com (2603:10b6:405:16::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:27 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT005.mail.protection.outlook.com (10.13.176.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:27 +0000 Received: from jinzhosu-System-Product-Name.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.2375.18; Fri, 4 Mar 2022 00:09:22 -0600 From: Jinzhou Su To: , , , CC: , , , , , , , , , , Jinzhou Su Subject: [PATCH V2 2/4] tools/power/x86/intel_pstate_tracer: make tracer as a module Date: Fri, 4 Mar 2022 14:07:22 +0800 Message-ID: <20220304060724.314582-3-Jinzhou.Su@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220304060724.314582-1-Jinzhou.Su@amd.com> References: <20220304060724.314582-1-Jinzhou.Su@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd3888ce-7e06-4b7c-3223-08d9fda589c8 X-MS-TrafficTypeDiagnostic: BL0PR12MB2548:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MfL5jd+ZDb50++T7fk6PQ+HYex56X5g6aG4ZYr//5lI6bc27g2w3PXCUrU6rXU7KhzM9UUoywSbpYHzNp4LjZ4KZNctqiMDbvJOVMRd5flBoKRhtG4JkLg8AFL/htMsNZPcDscwtahSrl70c93EIxWxUU8tgZiLAP5nN09+lLs06E/rwoAW7vVSZneoGbaWt3Ex3npNWZiwHIu04c5jdwaAJvDv3x5CQlzC/K4wT+1WJnwafsR/6Y1UA/Mkzpc6ntw1UeaolgVnJZnAUV+DlOEnj+dATEleZ90lNLePiIXpgRsBoOKuZ46ZjAziDqLNjlLQb/6OgyFKm4+uOMh3+XRnznAa8wWzjNUu7dNvygBuQ3TTRvTbbIfNlvmNMoxnzf5LlT12oJkH4zVxNzCQcIqUFaS/RbbPjC8CcLEElmfQ43jq9KGopQl3z9mo7C8+i7bt4Q9lJpkb2hUBYDX+Ul6XQFWyGefILmgcID5rXkjjqpIG3lUpviQNRX6YoI27ZuBF7r7E3613jENXuec1KzC8yFqckTVuDTttPPcoFojsnPoYCPtlSjELBL4JwaeUeZo4saQayWJkeh7wqzx8Zol0J6mvKUmgVt4UE7kTvNtiDEi74YX2XOMnP0hHiDWv8VkWyPMiN0nwI5Q3Dn5K+nBSn1t54HAGnaMvAnuFicZThA/lyXf5xyfSTl1V3rEE8EMDMIDOGgicTwmDWfHkq2Q== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(36860700001)(508600001)(47076005)(70586007)(86362001)(83380400001)(40460700003)(16526019)(2906002)(36756003)(26005)(426003)(336012)(1076003)(186003)(7696005)(81166007)(316002)(30864003)(2616005)(5660300002)(4326008)(8936002)(82310400004)(110136005)(8676002)(70206006)(356005)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2022 06:09:27.1884 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd3888ce-7e06-4b7c-3223-08d9fda589c8 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: BN8NAM11FT005.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2548 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make intel_pstate_tracer as a module. Other trace event can import this module to analyze their trace data. Signed-off-by: Jinzhou Su Acked-by: Doug Smythies --- .../intel_pstate_tracer.py | 260 +++++++++--------- 1 file changed, 129 insertions(+), 131 deletions(-) diff --git a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py b/t= ools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py index e15e20696d17..b46e9eb8f5aa 100755 --- a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py +++ b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py @@ -63,7 +63,7 @@ C_USEC =3D 3 C_SEC =3D 2 C_CPU =3D 1 =20 -global sample_num, last_sec_cpu, last_usec_cpu, start_time, testname +global sample_num, last_sec_cpu, last_usec_cpu, start_time, testname, trac= e_file =20 # 11 digits covers uptime to 115 days getcontext().prec =3D 11 @@ -72,17 +72,17 @@ sample_num =3D0 last_sec_cpu =3D [0] * MAX_CPUS last_usec_cpu =3D [0] * MAX_CPUS =20 -def print_help(): - print('intel_pstate_tracer.py:') +def print_help(driver_name): + print('%s_tracer.py:'%driver_name) print(' Usage:') print(' If the trace file is available, then to simply parse and pl= ot, use (sudo not required):') - print(' ./intel_pstate_tracer.py [-c cpus] -t -n ') + print(' ./%s_tracer.py [-c cpus] -t -n '%= driver_name) print(' Or') - print(' ./intel_pstate_tracer.py [--cpu cpus] ---trace_file --name ') + print(' ./%s_tracer.py [--cpu cpus] ---trace_file --= name '%driver_name) print(' To generate trace file, parse and plot, use (sudo required)= :') - print(' sudo ./intel_pstate_tracer.py [-c cpus] -i -n = -m ') + print(' sudo ./%s_tracer.py [-c cpus] -i -n -m '%driver_name) print(' Or') - print(' sudo ./intel_pstate_tracer.py [--cpu cpus] --interval --name --memory ') + print(' sudo ./%s_tracer.py [--cpu cpus] --interval --= name --memory '%driver_name) print(' Optional argument:') print(' cpus: comma separated list of CPUs') print(' kbytes: Kilo bytes of memory per CPU to allocate to the t= race buffer. Default: 10240') @@ -323,7 +323,7 @@ def set_4_plot_linestyles(g_plot): g_plot('set style line 3 linetype 1 linecolor rgb "purple" pointtype -= 1') g_plot('set style line 4 linetype 1 linecolor rgb "blue" pointtype -1') =20 -def store_csv(cpu_int, time_pre_dec, time_post_dec, core_busy, scaled, _fr= om, _to, mperf, aperf, tsc, freq_ghz, io_boost, common_comm, load, duration= _ms, sample_num, elapsed_time, tsc_ghz): +def store_csv(cpu_int, time_pre_dec, time_post_dec, core_busy, scaled, _fr= om, _to, mperf, aperf, tsc, freq_ghz, io_boost, common_comm, load, duration= _ms, sample_num, elapsed_time, tsc_ghz, cpu_mask): """ Store master csv file information """ =20 global graph_data_present @@ -342,11 +342,9 @@ def store_csv(cpu_int, time_pre_dec, time_post_dec, co= re_busy, scaled, _from, _t =20 graph_data_present =3D True; =20 -def split_csv(): +def split_csv(current_max_cpu, cpu_mask): """ seperate the all csv file into per CPU csv files. """ =20 - global current_max_cpu - if os.path.exists('cpu.csv'): for index in range(0, current_max_cpu + 1): if cpu_mask[int(index)] !=3D 0: @@ -381,27 +379,25 @@ def clear_trace_file(): print('IO error clearing trace file ') sys.exit(2) =20 -def enable_trace(): +def enable_trace(trace_file): """ Enable trace """ =20 try: - open('/sys/kernel/debug/tracing/events/power/pstate_sample/enable' - , 'w').write("1") + open(trace_file,'w').write("1") except: print('IO error enabling trace ') sys.exit(2) =20 -def disable_trace(): +def disable_trace(trace_file): """ Disable trace """ =20 try: - open('/sys/kernel/debug/tracing/events/power/pstate_sample/enable' - , 'w').write("0") + open(trace_file, 'w').write("0") except: print('IO error disabling trace ') sys.exit(2) =20 -def set_trace_buffer_size(): +def set_trace_buffer_size(memory): """ Set trace buffer size """ =20 try: @@ -421,7 +417,7 @@ def free_trace_buffer(): print('IO error freeing trace buffer ') sys.exit(2) =20 -def read_trace_data(filename): +def read_trace_data(filename, cpu_mask): """ Read and parse trace data """ =20 global current_max_cpu @@ -481,135 +477,137 @@ def read_trace_data(filename): tsc_ghz =3D Decimal(0) if duration_ms !=3D Decimal(0) : tsc_ghz =3D Decimal(tsc)/duration_ms/Decimal(1000000) - store_csv(cpu_int, time_pre_dec, time_post_dec, core_busy,= scaled, _from, _to, mperf, aperf, tsc, freq_ghz, io_boost, common_comm, lo= ad, duration_ms, sample_num, elapsed_time, tsc_ghz) + store_csv(cpu_int, time_pre_dec, time_post_dec, core_busy,= scaled, _from, _to, mperf, aperf, tsc, freq_ghz, io_boost, common_comm, lo= ad, duration_ms, sample_num, elapsed_time, tsc_ghz, cpu_mask) =20 if cpu_int > current_max_cpu: current_max_cpu =3D cpu_int # End of for each trace line loop # Now seperate the main overall csv file into per CPU csv files. - split_csv() + split_csv(current_max_cpu, cpu_mask) =20 def signal_handler(signal, frame): print(' SIGINT: Forcing cleanup before exit.') if interval: - disable_trace() + disable_trace(trace_file) clear_trace_file() # Free the memory free_trace_buffer() sys.exit(0) =20 -signal.signal(signal.SIGINT, signal_handler) +if __name__ =3D=3D "__main__": + trace_file =3D "/sys/kernel/debug/tracing/events/power/pstate_sample/e= nable" + signal.signal(signal.SIGINT, signal_handler) =20 -interval =3D "" -filename =3D "" -cpu_list =3D "" -testname =3D "" -memory =3D "10240" -graph_data_present =3D False; + interval =3D "" + filename =3D "" + cpu_list =3D "" + testname =3D "" + memory =3D "10240" + graph_data_present =3D False; =20 -valid1 =3D False -valid2 =3D False + valid1 =3D False + valid2 =3D False =20 -cpu_mask =3D zeros((MAX_CPUS,), dtype=3Dint) + cpu_mask =3D zeros((MAX_CPUS,), dtype=3Dint) =20 -try: - opts, args =3D getopt.getopt(sys.argv[1:],"ht:i:c:n:m:",["help","trace= _file=3D","interval=3D","cpu=3D","name=3D","memory=3D"]) -except getopt.GetoptError: - print_help() - sys.exit(2) -for opt, arg in opts: - if opt =3D=3D '-h': - print() + try: + opts, args =3D getopt.getopt(sys.argv[1:],"ht:i:c:n:m:",["help","t= race_file=3D","interval=3D","cpu=3D","name=3D","memory=3D"]) + except getopt.GetoptError: + print_help('intel_pstate') + sys.exit(2) + for opt, arg in opts: + if opt =3D=3D '-h': + print_help('intel_pstate') + sys.exit() + elif opt in ("-t", "--trace_file"): + valid1 =3D True + location =3D os.path.realpath(os.path.join(os.getcwd(), os.pat= h.dirname(__file__))) + filename =3D os.path.join(location, arg) + elif opt in ("-i", "--interval"): + valid1 =3D True + interval =3D arg + elif opt in ("-c", "--cpu"): + cpu_list =3D arg + elif opt in ("-n", "--name"): + valid2 =3D True + testname =3D arg + elif opt in ("-m", "--memory"): + memory =3D arg + + if not (valid1 and valid2): + print_help('intel_pstate') sys.exit() - elif opt in ("-t", "--trace_file"): - valid1 =3D True - location =3D os.path.realpath(os.path.join(os.getcwd(), os.path.di= rname(__file__))) - filename =3D os.path.join(location, arg) - elif opt in ("-i", "--interval"): - valid1 =3D True - interval =3D arg - elif opt in ("-c", "--cpu"): - cpu_list =3D arg - elif opt in ("-n", "--name"): - valid2 =3D True - testname =3D arg - elif opt in ("-m", "--memory"): - memory =3D arg - -if not (valid1 and valid2): - print_help() - sys.exit() - -if cpu_list: - for p in re.split("[,]", cpu_list): - if int(p) < MAX_CPUS : - cpu_mask[int(p)] =3D 1 -else: - for i in range (0, MAX_CPUS): - cpu_mask[i] =3D 1 - -if not os.path.exists('results'): - os.mkdir('results') + + if cpu_list: + for p in re.split("[,]", cpu_list): + if int(p) < MAX_CPUS : + cpu_mask[int(p)] =3D 1 + else: + for i in range (0, MAX_CPUS): + cpu_mask[i] =3D 1 + + if not os.path.exists('results'): + os.mkdir('results') + # The regular user needs to own the directory, not root. + fix_ownership('results') + + os.chdir('results') + if os.path.exists(testname): + print('The test name directory already exists. Please provide a un= ique test name. Test re-run not supported, yet.') + sys.exit() + os.mkdir(testname) # The regular user needs to own the directory, not root. - fix_ownership('results') - -os.chdir('results') -if os.path.exists(testname): - print('The test name directory already exists. Please provide a unique= test name. Test re-run not supported, yet.') - sys.exit() -os.mkdir(testname) -# The regular user needs to own the directory, not root. -fix_ownership(testname) -os.chdir(testname) - -# Temporary (or perhaps not) -cur_version =3D sys.version_info -print('python version (should be >=3D 2.7):') -print(cur_version) - -# Left as "cleanup" for potential future re-run ability. -cleanup_data_files() - -if interval: - filename =3D "/sys/kernel/debug/tracing/trace" - clear_trace_file() - set_trace_buffer_size() - enable_trace() - print('Sleeping for ', interval, 'seconds') - time.sleep(int(interval)) - disable_trace() - -current_max_cpu =3D 0 - -read_trace_data(filename) - -if interval: - clear_trace_file() - # Free the memory - free_trace_buffer() - -if graph_data_present =3D=3D False: - print('No valid data to plot') - sys.exit(2) - -for cpu_no in range(0, current_max_cpu + 1): - plot_perf_busy_with_sample(cpu_no) - plot_perf_busy(cpu_no) - plot_durations(cpu_no) - plot_loads(cpu_no) - -plot_pstate_cpu_with_sample() -plot_pstate_cpu() -plot_load_cpu() -plot_frequency_cpu() -plot_duration_cpu() -plot_scaled_cpu() -plot_boost_cpu() -plot_ghz_cpu() - -# It is preferrable, but not necessary, that the regular user owns the fil= es, not root. -for root, dirs, files in os.walk('.'): - for f in files: - fix_ownership(f) - -os.chdir('../../') + fix_ownership(testname) + os.chdir(testname) + + # Temporary (or perhaps not) + cur_version =3D sys.version_info + print('python version (should be >=3D 2.7):') + print(cur_version) + + # Left as "cleanup" for potential future re-run ability. + cleanup_data_files() + + if interval: + filename =3D "/sys/kernel/debug/tracing/trace" + clear_trace_file() + set_trace_buffer_size(memory) + enable_trace(trace_file) + print('Sleeping for ', interval, 'seconds') + time.sleep(int(interval)) + disable_trace(trace_file) + + current_max_cpu =3D 0 + + read_trace_data(filename, cpu_mask) + + if interval: + clear_trace_file() + # Free the memory + free_trace_buffer() + + if graph_data_present =3D=3D False: + print('No valid data to plot') + sys.exit(2) + + for cpu_no in range(0, current_max_cpu + 1): + plot_perf_busy_with_sample(cpu_no) + plot_perf_busy(cpu_no) + plot_durations(cpu_no) + plot_loads(cpu_no) + + plot_pstate_cpu_with_sample() + plot_pstate_cpu() + plot_load_cpu() + plot_frequency_cpu() + plot_duration_cpu() + plot_scaled_cpu() + plot_boost_cpu() + plot_ghz_cpu() + + # It is preferrable, but not necessary, that the regular user owns the= files, not root. + for root, dirs, files in os.walk('.'): + for f in files: + fix_ownership(f) + + os.chdir('../../') --=20 2.27.0 From nobody Tue Jun 23 13:03:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A17FC433F5 for ; Fri, 4 Mar 2022 06:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238313AbiCDGKo (ORCPT ); Fri, 4 Mar 2022 01:10:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238276AbiCDGKa (ORCPT ); Fri, 4 Mar 2022 01:10:30 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2055.outbound.protection.outlook.com [40.107.93.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4770045783; Thu, 3 Mar 2022 22:09:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ENulLYmPo4ktPCRD+OzkmVEscnHpfEoYNYctOEwJQAfYehaoKIH71bUW/hzyiTHz1j0OMvNGhwO2djvEKOvVDTzxTwWDq+XMWGCWTBPAqX+E1LlHxIyEW4Fz3cOSejl3g4pqU33bLqajqkac6MCOWjAaKxELYMfWT/T32gF+x5aamWnru+GzpDKJQVvXqWcqj3xXWL0XmlRub4Bbj5Wb14p2UFzWHiBNyTejqFEI5iEQEmOAzZusn4Bz1pnH0FUwxzyjfN3/GSdZeCdQuqqM/xFJdXTX+515BxY8T67njLpLkk9zSSxcjZDcws3dBUtBjFg9LEQqop7REpFsjhj1CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BOhhYLSoe02Mi1TojJfX9Jlw16ZIn2kImVhO5DfId3g=; b=OCo/ayOmAgiXWYnIbyb5JLHYKNrS4h+0Rd5WiLdV9P+VfLgDyELePkdpWezV9+II/DssyzwesHKAgqWOSG9Ue6I3K/teED1EYRXSi/SUOlqbQ59ztZtICVh9TNqLkfI6p0s677L7K7//vcc+E9GVjT3n9VJSgdoa6rlBxGQRHsWNega6L8km97Xp/mSXJ/qKYA61b31CX9q3UGT6IJzzxxKEgw8jTiLCdtXGIkH6BQkPNexrsXJb2fvrwYtRW7fqlpfafDtZ7XwcAill7umf/MKtMORx0DcfqgSL49nUAd5gkGmp41aqZ+MaWyUmZ6lfyRnyXTDxqDCrFJA3mYcLOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=rjwysocki.net 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 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=BOhhYLSoe02Mi1TojJfX9Jlw16ZIn2kImVhO5DfId3g=; b=VQ0XLddOfPqGjURdq1qbtosfKcrF2c05oAV7e3yU3JTA87cD9bZ0eVq7DIsilFMujbUi9jbWPG98EfqEq69wHM6BkjFx4/B9a9IaO5JXT8ZeFOG53nuMOwpaJavnXVKzrEB3He/eh7H80g3rSiat/dpjzagUprodCnbSANe3vhA= Received: from BN0PR04CA0075.namprd04.prod.outlook.com (2603:10b6:408:ea::20) by MN2PR12MB3328.namprd12.prod.outlook.com (2603:10b6:208:c2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.26; Fri, 4 Mar 2022 06:09:35 +0000 Received: from BN8NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ea:cafe::2c) by BN0PR04CA0075.outlook.office365.com (2603:10b6:408:ea::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.13 via Frontend Transport; Fri, 4 Mar 2022 06:09:35 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT055.mail.protection.outlook.com (10.13.177.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:34 +0000 Received: from jinzhosu-System-Product-Name.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.2375.18; Fri, 4 Mar 2022 00:09:30 -0600 From: Jinzhou Su To: , , , CC: , , , , , , , , , , Jinzhou Su Subject: [PATCH V2 3/4] tools/power/x86/amd_pstate_tracer: Add tracer tool for AMD P-state Date: Fri, 4 Mar 2022 14:07:23 +0800 Message-ID: <20220304060724.314582-4-Jinzhou.Su@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220304060724.314582-1-Jinzhou.Su@amd.com> References: <20220304060724.314582-1-Jinzhou.Su@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8ce5189-bb85-4b55-7664-08d9fda58e6b X-MS-TrafficTypeDiagnostic: MN2PR12MB3328:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NbI6xv+BWv74R6QEsQsQS1lihNOb1xmoPy+em7d0vdPo01JbKkx9PwnsfXZHTCSnhIDuo3uM8qzFC8jn6xuO4d7yIaVeiBax0uM6acfXdltFC0LgUtDjo3R3tfa1eiL43voGpRaQik/KIJhOmPculqsz5pgZLUH+OcKer9lFMxlDCLbABQ1jywCedpVONE2OVcLGa9MlD+1bNW3jMKFD3fHsLWUCZnOFK6SkcJH//ZrBCDHYa3eNdaUd3QHaOczwolG7sRYEZqt5o+RkDGXpvPYw6pGiehYr8pMcfj3M8krzoawDTLSruVJ05xsB0nhY3HbAHmGQ2/DGOufNFb848ELtTTUZZTbJt/vpg9L1bSVM9Ha7IpgDDiRIo1XIZmBL2pNxOoqfOOrG6dlva/PgvpBu3S0Jc28rqN/Lzp8tMpl5jaAfyXgGRrCe74Yp5SRgEk8oG+cqsscY1NW8FJot5BM6bYS1lPVRkLRTwhJ9M8Yv8611c2Ky+0/2aq3XaMaPFujKfcuBgS1tp8N7kOAviiYRSVbqol3iKE7M8/uvXrQ+mHvMjEuYkfx3btmxQENHFrZxWKDgP/5R47mzq7TwCm0SvoyLiFOf8OLfadXtouP8C41WIO7hLPNGHHZ6FGTL/wCRueMKmqyGm0DxcA6rIEQN0BXWzSwDvYQSzAq0rEvtKHx/5TXd1iteYldyJiGNuQWa7U1FKK0tMsStteOBqg== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(1076003)(5660300002)(2616005)(7696005)(336012)(426003)(86362001)(8936002)(316002)(82310400004)(70206006)(70586007)(8676002)(30864003)(26005)(16526019)(186003)(2906002)(36756003)(81166007)(356005)(6666004)(508600001)(83380400001)(54906003)(110136005)(36860700001)(47076005)(4326008)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2022 06:09:34.9849 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8ce5189-bb85-4b55-7664-08d9fda58e6b 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: BN8NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3328 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Intel P-state tracer is a useful tool to tune and debug Intel P-state driver. AMD P-state tracer import intel pstate tracer. This tool can be used to analyze the performance of AMD P-state tracer. Now CPU frequency, load and desired perf can be traced. Signed-off-by: Jinzhou Su Reviewed-by: Huang Rui --- MAINTAINERS | 1 + .../x86/amd_pstate_tracer/amd_pstate_trace.py | 354 ++++++++++++++++++ 2 files changed, 355 insertions(+) create mode 100755 tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py diff --git a/MAINTAINERS b/MAINTAINERS index 4f9acc183cdc..01ac42504dcd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1002,6 +1002,7 @@ L: linux-pm@vger.kernel.org S: Supported F: Documentation/admin-guide/pm/amd-pstate.rst F: drivers/cpufreq/amd-pstate* +F: tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py =20 AMD PTDMA DRIVER M: Sanjay R Mehta diff --git a/tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py b/tools/= power/x86/amd_pstate_tracer/amd_pstate_trace.py new file mode 100755 index 000000000000..2dea4032ac56 --- /dev/null +++ b/tools/power/x86/amd_pstate_tracer/amd_pstate_trace.py @@ -0,0 +1,354 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +# -*- coding: utf-8 -*- +# +""" This utility can be used to debug and tune the performance of the +AMD P-State driver. It imports intel_pstate_tracer to analyze AMD P-State +trace event. + +Prerequisites: + Python version 2.7.x or higher + gnuplot 5.0 or higher + gnuplot-py 1.8 or higher + (Most of the distributions have these required packages. They may be c= alled + gnuplot-py, phython-gnuplot or phython3-gnuplot, gnuplot-nox, ... ) + + Kernel config for Linux trace is enabled + + see print_help(): for Usage and Output details + +""" +from __future__ import print_function +from datetime import datetime +import subprocess +import os +import time +import re +import signal +import sys +import getopt +import Gnuplot +from numpy import * +from decimal import * +sys.path.append('../intel_pstate_tracer') +#import intel_pstate_tracer +import intel_pstate_tracer as ipt + +__license__ =3D "GPL version 2" + +MAX_CPUS =3D 256 +# Define the csv file columns +C_COMM =3D 15 +C_ELAPSED =3D 14 +C_SAMPLE =3D 13 +C_DURATION =3D 12 +C_LOAD =3D 11 +C_TSC =3D 10 +C_APERF =3D 9 +C_MPERF =3D 8 +C_FREQ =3D 7 +C_MAX_PERF =3D 6 +C_DES_PERF =3D 5 +C_MIN_PERF =3D 4 +C_USEC =3D 3 +C_SEC =3D 2 +C_CPU =3D 1 + +global sample_num, last_sec_cpu, last_usec_cpu, start_time, test_name, tra= ce_file + +getcontext().prec =3D 11 + +sample_num =3D0 +last_sec_cpu =3D [0] * MAX_CPUS +last_usec_cpu =3D [0] * MAX_CPUS + +def plot_per_cpu_freq(cpu_index): + """ Plot per cpu frequency """ + + file_name =3D 'cpu{:0>3}.csv'.format(cpu_index) + if os.path.exists(file_name): + output_png =3D "cpu%03d_frequency.png" % cpu_index + g_plot =3D ipt.common_gnuplot_settings() + g_plot('set output "' + output_png + '"') + g_plot('set yrange [0:7]') + g_plot('set ytics 0, 1') + g_plot('set ylabel "CPU Frequency (GHz)"') + g_plot('set title "{} : frequency : CPU {:0>3} : {:%F %H:%M}"'.for= mat(test_name, cpu_index, datetime.now())) + g_plot('set ylabel "CPU frequency"') + g_plot('set key off') + ipt.set_4_plot_linestyles(g_plot) + g_plot('plot "' + file_name + '" using {:d}:{:d} with linespoints = linestyle 1 axis x1y1'.format(C_ELAPSED, C_FREQ)) + +def plot_per_cpu_des_perf(cpu_index): + """ Plot per cpu desired perf """ + + file_name =3D 'cpu{:0>3}.csv'.format(cpu_index) + if os.path.exists(file_name): + output_png =3D "cpu%03d_des_perf.png" % cpu_index + g_plot =3D ipt.common_gnuplot_settings() + g_plot('set output "' + output_png + '"') + g_plot('set yrange [0:255]') + g_plot('set ylabel "des perf"') + g_plot('set title "{} : cpu des perf : CPU {:0>3} : {:%F %H:%M}"'.= format(test_name, cpu_index, datetime.now())) + g_plot('set key off') + ipt.set_4_plot_linestyles(g_plot) + g_plot('plot "' + file_name + '" using {:d}:{:d} with linespoints = linestyle 1 axis x1y1'.format(C_ELAPSED, C_DES_PERF)) + +def plot_per_cpu_load(cpu_index): + """ Plot per cpu load """ + + file_name =3D 'cpu{:0>3}.csv'.format(cpu_index) + if os.path.exists(file_name): + output_png =3D "cpu%03d_load.png" % cpu_index + g_plot =3D ipt.common_gnuplot_settings() + g_plot('set output "' + output_png + '"') + g_plot('set yrange [0:100]') + g_plot('set ytics 0, 10') + g_plot('set ylabel "CPU load (percent)"') + g_plot('set title "{} : cpu load : CPU {:0>3} : {:%F %H:%M}"'.form= at(test_name, cpu_index, datetime.now())) + g_plot('set key off') + ipt.set_4_plot_linestyles(g_plot) + g_plot('plot "' + file_name + '" using {:d}:{:d} with linespoints = linestyle 1 axis x1y1'.format(C_ELAPSED, C_LOAD)) + +def plot_all_cpu_frequency(): + """ Plot all cpu frequencies """ + + output_png =3D 'all_cpu_frequencies.png' + g_plot =3D ipt.common_gnuplot_settings() + g_plot('set output "' + output_png + '"') + g_plot('set ylabel "CPU Frequency (GHz)"') + g_plot('set title "{} : cpu frequencies : {:%F %H:%M}"'.format(test_na= me, datetime.now())) + + title_list =3D subprocess.check_output('ls cpu???.csv | sed -e \'s/.cs= v//\'',shell=3DTrue).decode('utf-8').replace('\n', ' ') + plot_str =3D "plot for [i in title_list] i.'.csv' using {:d}:{:d} pt 7= ps 1 title i".format(C_ELAPSED, C_FREQ) + g_plot('title_list =3D "{}"'.format(title_list)) + g_plot(plot_str) + +def plot_all_cpu_des_perf(): + """ Plot all cpu desired perf """ + + output_png =3D 'all_cpu_des_perf.png' + g_plot =3D ipt.common_gnuplot_settings() + g_plot('set output "' + output_png + '"') + g_plot('set ylabel "des perf"') + g_plot('set title "{} : cpu des perf : {:%F %H:%M}"'.format(test_name,= datetime.now())) + + title_list =3D subprocess.check_output('ls cpu???.csv | sed -e \'s/.cs= v//\'',shell=3DTrue).decode('utf-8').replace('\n', ' ') + plot_str =3D "plot for [i in title_list] i.'.csv' using {:d}:{:d} pt 2= 55 ps 1 title i".format(C_ELAPSED, C_DES_PERF) + g_plot('title_list =3D "{}"'.format(title_list)) + g_plot(plot_str) + +def plot_all_cpu_load(): + """ Plot all cpu load """ + + output_png =3D 'all_cpu_load.png' + g_plot =3D ipt.common_gnuplot_settings() + g_plot('set output "' + output_png + '"') + g_plot('set yrange [0:100]') + g_plot('set ylabel "CPU load (percent)"') + g_plot('set title "{} : cpu load : {:%F %H:%M}"'.format(test_name, dat= etime.now())) + + title_list =3D subprocess.check_output('ls cpu???.csv | sed -e \'s/.cs= v//\'',shell=3DTrue).decode('utf-8').replace('\n', ' ') + plot_str =3D "plot for [i in title_list] i.'.csv' using {:d}:{:d} pt 2= 55 ps 1 title i".format(C_ELAPSED, C_LOAD) + g_plot('title_list =3D "{}"'.format(title_list)) + g_plot(plot_str) + +def store_csv(cpu_int, time_pre_dec, time_post_dec, min_perf, des_perf, ma= x_perf, freq_ghz, mperf, aperf, tsc, common_comm, load, duration_ms, sample= _num, elapsed_time, cpu_mask): + """ Store master csv file information """ + + global graph_data_present + + if cpu_mask[cpu_int] =3D=3D 0: + return + + try: + f_handle =3D open('cpu.csv', 'a') + string_buffer =3D "CPU_%03u, %05u, %06u, %u, %u, %u, %.4f, %u, %u,= %u, %.2f, %.3f, %u, %.3f, %s\n" % (cpu_int, int(time_pre_dec), int(time_po= st_dec), int(min_perf), int(des_perf), int(max_perf), freq_ghz, int(mperf),= int(aperf), int(tsc), load, duration_ms, sample_num, elapsed_time, common_= comm) + f_handle.write(string_buffer) + f_handle.close() + except: + print('IO error cpu.csv') + return + + graph_data_present =3D True; + + +def cleanup_data_files(): + """ clean up existing data files """ + + if os.path.exists('cpu.csv'): + os.remove('cpu.csv') + f_handle =3D open('cpu.csv', 'a') + f_handle.write('common_cpu, common_secs, common_usecs, min_perf, des_p= erf, max_perf, freq, mperf, aperf, tsc, load, duration_ms, sample_num, elap= sed_time, common_comm') + f_handle.write('\n') + f_handle.close() + +def read_trace_data(file_name, cpu_mask): + """ Read and parse trace data """ + + global current_max_cpu + global sample_num, last_sec_cpu, last_usec_cpu, start_time + + try: + data =3D open(file_name, 'r').read() + except: + print('Error opening ', file_name) + sys.exit(2) + + for line in data.splitlines(): + search_obj =3D \ + re.search(r'(^(.*?)\[)((\d+)[^\]])(.*?)(\d+)([.])(\d+)(.*?amd_= min_perf=3D)(\d+)(.*?amd_des_perf=3D)(\d+)(.*?amd_max_perf=3D)(\d+)(.*?freq= =3D)(\d+)(.*?mperf=3D)(\d+)(.*?aperf=3D)(\d+)(.*?tsc=3D)(\d+)' + , line) + + if search_obj: + cpu =3D search_obj.group(3) + cpu_int =3D int(cpu) + cpu =3D str(cpu_int) + + time_pre_dec =3D search_obj.group(6) + time_post_dec =3D search_obj.group(8) + min_perf =3D search_obj.group(10) + des_perf =3D search_obj.group(12) + max_perf =3D search_obj.group(14) + freq =3D search_obj.group(16) + mperf =3D search_obj.group(18) + aperf =3D search_obj.group(20) + tsc =3D search_obj.group(22) + + common_comm =3D search_obj.group(2).replace(' ', '') + + if sample_num =3D=3D 0 : + start_time =3D Decimal(time_pre_dec) + Decimal(time_post_d= ec) / Decimal(1000000) + sample_num +=3D 1 + + if last_sec_cpu[cpu_int] =3D=3D 0 : + last_sec_cpu[cpu_int] =3D time_pre_dec + last_usec_cpu[cpu_int] =3D time_post_dec + else : + duration_us =3D (int(time_pre_dec) - int(last_sec_cpu[cpu_= int])) * 1000000 + (int(time_post_dec) - int(last_usec_cpu[cpu_int])) + duration_ms =3D Decimal(duration_us) / Decimal(1000) + last_sec_cpu[cpu_int] =3D time_pre_dec + last_usec_cpu[cpu_int] =3D time_post_dec + elapsed_time =3D Decimal(time_pre_dec) + Decimal(time_post= _dec) / Decimal(1000000) - start_time + load =3D Decimal(int(mperf)*100)/ Decimal(tsc) + freq_ghz =3D Decimal(freq)/Decimal(1000000) + store_csv(cpu_int, time_pre_dec, time_post_dec, min_perf, = des_perf, max_perf, freq_ghz, mperf, aperf, tsc, common_comm, load, duratio= n_ms, sample_num, elapsed_time, cpu_mask) + + if cpu_int > current_max_cpu: + current_max_cpu =3D cpu_int +# Now separate the main overall csv file into per CPU csv files. + ipt.split_csv(current_max_cpu, cpu_mask) + + +def signal_handler(signal, frame): + print(' SIGINT: Forcing cleanup before exit.') + if interval: + ipt.disable_trace(trace_file) + ipt.clear_trace_file() + ipt.free_trace_buffer() + sys.exit(0) + +trace_file =3D "/sys/kernel/debug/tracing/events/amd_cpu/enable" +signal.signal(signal.SIGINT, signal_handler) + +interval =3D "" +file_name =3D "" +cpu_list =3D "" +test_name =3D "" +memory =3D "10240" +graph_data_present =3D False; + +valid1 =3D False +valid2 =3D False + +cpu_mask =3D zeros((MAX_CPUS,), dtype=3Dint) + + +try: + opts, args =3D getopt.getopt(sys.argv[1:],"ht:i:c:n:m:",["help","trace= _file=3D","interval=3D","cpu=3D","name=3D","memory=3D"]) +except getopt.GetoptError: + ipt.print_help('amd_pstate') + sys.exit(2) +for opt, arg in opts: + if opt =3D=3D '-h': + print() + sys.exit() + elif opt in ("-t", "--trace_file"): + valid1 =3D True + location =3D os.path.realpath(os.path.join(os.getcwd(), os.path.di= rname(__file__))) + file_name =3D os.path.join(location, arg) + elif opt in ("-i", "--interval"): + valid1 =3D True + interval =3D arg + elif opt in ("-c", "--cpu"): + cpu_list =3D arg + elif opt in ("-n", "--name"): + valid2 =3D True + test_name =3D arg + elif opt in ("-m", "--memory"): + memory =3D arg + +if not (valid1 and valid2): + ipt.print_help('amd_pstate') + sys.exit() + +if cpu_list: + for p in re.split("[,]", cpu_list): + if int(p) < MAX_CPUS : + cpu_mask[int(p)] =3D 1 +else: + for i in range (0, MAX_CPUS): + cpu_mask[i] =3D 1 + +if not os.path.exists('results'): + os.mkdir('results') + ipt.fix_ownership('results') + +os.chdir('results') +if os.path.exists(test_name): + print('The test name directory already exists. Please provide a unique= test name. Test re-run not supported, yet.') + sys.exit() +os.mkdir(test_name) +ipt.fix_ownership(test_name) +os.chdir(test_name) + +cur_version =3D sys.version_info +print('python version (should be >=3D 2.7):') +print(cur_version) + +cleanup_data_files() + +if interval: + file_name =3D "/sys/kernel/debug/tracing/trace" + ipt.clear_trace_file() + ipt.set_trace_buffer_size(memory) + ipt.enable_trace(trace_file) + time.sleep(int(interval)) + ipt.disable_trace(trace_file) + +current_max_cpu =3D 0 + +read_trace_data(file_name, cpu_mask) + +if interval: + ipt.clear_trace_file() + ipt.free_trace_buffer() + +if graph_data_present =3D=3D False: + print('No valid data to plot') + sys.exit(2) + +for cpu_no in range(0, current_max_cpu + 1): + plot_per_cpu_freq(cpu_no) + plot_per_cpu_des_perf(cpu_no) + plot_per_cpu_load(cpu_no) + +plot_all_cpu_des_perf() +plot_all_cpu_frequency() +plot_all_cpu_load() + +for root, dirs, files in os.walk('.'): + for f in files: + ipt.fix_ownership(f) + +os.chdir('../../') --=20 2.27.0 From nobody Tue Jun 23 13:03:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE267C433F5 for ; Fri, 4 Mar 2022 06:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238330AbiCDGKs (ORCPT ); Fri, 4 Mar 2022 01:10:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238290AbiCDGKe (ORCPT ); Fri, 4 Mar 2022 01:10:34 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2049.outbound.protection.outlook.com [40.107.100.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 450C547AFE; Thu, 3 Mar 2022 22:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A3aRqQW3dwj7w1kLOks0dNf1HIOtrBY8t+tec/Mc00yn26NlTPEPjCVwDADPJVg6cbHrxp5jtM+ef1UPmfljzW+07HKsTiCiQHU2jD2wIfyASow9Xi+AwdoG+wkl+Ho8/WEVN3wsYgypfb+brN6wDR03D4asUdXRj2TGSgqBipmzXZ5zAtA4mgBKKz7XHhPgYn9D0+xLIH2F0Sx7xoIkk87pMq/hz2Z3s/WQXxUI9Zaf9vYC7pf8dzfY4vuutJGBCSEIWzqH7JuG5yjK+pKL2POnAVf/1k40JG9/hUFDSuqcMqWFRS3IOehArm5vVRv5nSPj4tHY1MZAi0NYXamXBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rQSb8aXFwzJmaujcSCOmzQP9FuKfdMzEyXLIAc7XpV0=; b=be1SbxMfUYwGRLs7Y8nrzMz70t1ja3LGKKRtojR3SB49gZUlJLoIsGSdNhDfJ1M+OOTcUcZwZs0wTZJOt0tEXqjT4HoFlRBQHZhwks4wdIKWx86k1ZoT7dWf/ZxyHwxxXZaSQD7evws8Bv0ctJt6cNQ+KgRlunackMykd5D5plXUlOIvXBPRTVpMjnVz6+9TtyaT6LzrfFpIO6g0FstZVzwoH5ywz26nKIHZ8TEzENP96TKaOvnPJ3DnYQKzZfqwtH08mmPmNBaSxb/x3xyn3IVpn9YLqB8fqP5JRtzuEvMAxyct+0lrQ0vqCnVY6AmY7MoBsjWV0+6EOha+Z0ebkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=rjwysocki.net 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 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=rQSb8aXFwzJmaujcSCOmzQP9FuKfdMzEyXLIAc7XpV0=; b=BQAdBX/2CX1BT3h2pGfhgJRfYyMkAzdl9qSzrtj/9KyO3p4zWN/g+duLDU3gGiBCteQfCE2utDU9FkAqFbUbaeyQv0T5vi5WxtBQtgaFOp+yHhYVGY2QQVfqlJFgkg0fakXrYStkGRLzDo+bVvxOIKnq92iClfXydRy3MKz1GC8= Received: from BN9PR03CA0937.namprd03.prod.outlook.com (2603:10b6:408:108::12) by DM4PR12MB5326.namprd12.prod.outlook.com (2603:10b6:5:39f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.15; Fri, 4 Mar 2022 06:09:43 +0000 Received: from BN8NAM11FT057.eop-nam11.prod.protection.outlook.com (2603:10b6:408:108:cafe::31) by BN9PR03CA0937.outlook.office365.com (2603:10b6:408:108::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:42 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT057.mail.protection.outlook.com (10.13.177.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Fri, 4 Mar 2022 06:09:42 +0000 Received: from jinzhosu-System-Product-Name.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.2375.18; Fri, 4 Mar 2022 00:09:36 -0600 From: Jinzhou Su To: , , , CC: , , , , , , , , , , Jinzhou Su Subject: [PATCH V2 4/4] Documentation: amd-pstate: add tracer tool introduction Date: Fri, 4 Mar 2022 14:07:24 +0800 Message-ID: <20220304060724.314582-5-Jinzhou.Su@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220304060724.314582-1-Jinzhou.Su@amd.com> References: <20220304060724.314582-1-Jinzhou.Su@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fb6b7e3-b999-48dd-139f-08d9fda592c5 X-MS-TrafficTypeDiagnostic: DM4PR12MB5326:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6GxDl/LJ/yFzWT1+TY7cwUht9DF90jLkNuLemqy8kVoRVAa8oz81bNatTvTI5YKmUookYDuqctTJ1OACfMY38Z8WdDh8a50/4d2QSy2nt9DYmzTGP14ZPAsCOwAOJ4vHoiy2lgbLHxdj206td8L3TSne9M/N1eyk0kpiZslZp6Btv2ShI0ggr9I3KMi+oJQgc7YH+qqyMNO4nzMvW73AyDPYiZmBpvNDc/1Wk3/IM2FBiN1OUKcfzsrtqYLlgPerm5pwr8YUCw6lkFWHGqvsC1I6r+v1S1tnjZqnx5BqTBaOcTpZcLRvvp9OVb4Qw3bOQ8Dx0QhFJV8g9qGxlrymtcW+HYzk1x+442ZNF2cYjkn/5Tl0kv6ydIK/IcKefj1f4CmDHNsRTGQU5UUBEVpdqp+Gxh3W35kPzG2jCrmYllCB9g5xAspD7U2phALVmpdIx2lA3Z6I7h8JDwthRrguefDWddmMSTrdccnC/69fcR3TLGYysXQSNO0iZKKePitUsansHTZE2PnqiCUmG6N65sqc4BRwLhm8c2h0uxikkod0vAygRaKXap08GYyNTjOxr1Hvut/leUJdKKOf+nhFeM/VO4ddZxusIcHZl/v+WroVV6n1jyAV0pccrFC093r7YSDZNAzYeFwVrZC25rOnSFdIRJB9nXl/CEy4Gtfu+i6cdwIDjz7LMIaLvtjoJX2ky59SjgbBM8AExHXgZN7rxw== 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(316002)(82310400004)(8676002)(4326008)(2616005)(70206006)(508600001)(70586007)(86362001)(110136005)(6666004)(54906003)(36860700001)(47076005)(40460700003)(26005)(81166007)(186003)(1076003)(16526019)(426003)(356005)(336012)(83380400001)(7696005)(2906002)(8936002)(5660300002)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Mar 2022 06:09:42.2674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2fb6b7e3-b999-48dd-139f-08d9fda592c5 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: BN8NAM11FT057.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5326 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add amd pstate tracer tool introduction Signed-off-by: Jinzhou Su --- Documentation/admin-guide/pm/amd-pstate.rst | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/ad= min-guide/pm/amd-pstate.rst index 2f066df4ee9c..17dd7396e8fc 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -369,6 +369,32 @@ governor (for the policies it is attached to), or by t= he ``CPUFreq`` core (for t policies with other scaling governors). =20 =20 +Tracer Tool +------------- + +``amd_pstate_tracer.py`` can record and parse amd-pstate trace log, then +generate performance plots. This utility can be used to debug and tune the +performance of the amd-pstate driver. The tracer tool needs to import intel +pstate tracer. + +Tracer tool located in linux/tools/power/x86/amd_pstate_tracer. It can be +used in two ways. If trace file is available, then directly parse the file +with command :: + + ./amd_pstate_trace.py [-c cpus] -t -n + +Or generate trace file with root privilege, then parse and plot with comma= nd :: + + sudo ./amd_pstate_trace.py [-c cpus] -n -i [-m kby= tes] + +The test result can be found in ``results/test_name``. Following is the ex= ample +about part of the output. :: + + common_cpu common_secs common_usecs min_perf des_perf max_perf freq= mperf apef tsc load duration_ms sample_num elapsed_time = common_comm + CPU_005 712 116384 39 49 166 0.75= 65 9645075 2214891 38431470 25.1 11.646 469 2.496 = kworker/5:0-40 + CPU_006 712 116408 39 49 166 0.67= 69 8950227 1839034 37192089 24.06 11.272 470 2.496 = kworker/6:0-1264 + + Reference =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.27.0