From patchwork Tue Apr 23 07:58:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Perry Yuan X-Patchwork-Id: 791398 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2040.outbound.protection.outlook.com [40.107.237.40]) (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 84A4854BFE; Tue, 23 Apr 2024 07:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713859152; cv=fail; b=J9ZR5gaAw439E7e2FruL+YXj615cgm1vPUEytmQR4ay8AGy2M14fFyLYeiDDwg6a5GOeLS6bao5OWzUGQ35pXI1Ufo3iC/4JQ0Hk510EJHO9DZXV89+6uw20XqzCmYofRauaSkOZxd94Gb+bD+4JZc1BVp06GxFX51auyQggndA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713859152; c=relaxed/simple; bh=ckwcOBVNDuF40QHvqaELwzXzB6I9pFsprYsdpq4lBWI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l3zv44bcsucsCmEEa4OVvQJsKvpdkRbi/qSYYeJi44z6Vx7FWQBlKNkjFxWbn27qezKCJeQcz6/CHKEYcBznhxSi0PwnDfuzGR1Cx+W/yic3AO/+3TOohGfDyM0AYpmkCf49aY3aIlzeKma2HBULqEn98fZtqwn2a2pkOFL1prQ= 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=Zi7E/0Z+; arc=fail smtp.client-ip=40.107.237.40 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="Zi7E/0Z+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QrQuXYi4hw+C7o8UdutHPI5jAf1ublzUgkm0tAWm9714oKjZO0Hp5GDRf2L7AGmMuNku5eqLibVLue260K9VyeTAoYq3VvASgPK+MCeLF73vex6qID45O6oi1w3I38eMdQAecmIaXTDWGs4sO1dyIPKdzRjaUYIGLwOlzzo7tdmLZntjbuXw9/pNtnx8kukPvm5A1pU2tkLBi5PusLiuWRU87Rp58FDiJRlWDYqDsRQXxz/jQwo6qdIo754nLLvtYxByv14r/uZcTLiQxI/88XudVx0jiUZ45T9rnNe2JD5h3wM2z+/rUc2L2O/xtr+o8PcZcNx1kKyuwMhjBjvGrQ== 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=m7Nnj+wrL8I671SDCrz9Xga9ZXP4NJdoC+h1QNGeU94=; b=nYKqyKz5s2ilW37RNMKtZIDdertcVP+CscU/TeG4FJ5PZUYoJPFHAy4XnrBRC1RIZz3Vi2xr3ASwGEM1G8zRXx2ca/4F3CIUEaNh/UaiDqeYbk0/qKPolocyBsaCqhecPFK4XMakmkJrXL58dSVVZuKx1qiED38FXdUvhJr8SbwgfofLT9UGDohyzX1rFaUCFotGLrIbIadCbwi9QuScMa/N9aLcRdVou2J0fQZPaJG5/AShplD8BFxVq3+0XGJJ11SR5Vfv0FEqeUob0K6lHOYJj638luftxKv57Fbnt2W55lzq9rgGskRNHXpV5ENbE+WyF54Dyr3cVyyUQKHynw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=m7Nnj+wrL8I671SDCrz9Xga9ZXP4NJdoC+h1QNGeU94=; b=Zi7E/0Z+MtFMCr6T+UmhTxvjWpTj6ROURFIWzHu/zz+Rv4grE54n4Payi1QJE4lHxy/j4i4eKaeUGAw9uOgsYVd6R7PC05xP51mkvbMam+KE7Mcruo9cgOQgSZsNnmUb7yAn0D7w5bvj+rOWR4o7B6Dnl7iIa6BXydnkFkBHnyU= Received: from CH2PR03CA0026.namprd03.prod.outlook.com (2603:10b6:610:59::36) by IA0PR12MB8695.namprd12.prod.outlook.com (2603:10b6:208:485::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Tue, 23 Apr 2024 07:59:06 +0000 Received: from CH2PEPF0000013E.namprd02.prod.outlook.com (2603:10b6:610:59:cafe::5c) by CH2PR03CA0026.outlook.office365.com (2603:10b6:610:59::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.35 via Frontend Transport; Tue, 23 Apr 2024 07:59:06 +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 CH2PEPF0000013E.mail.protection.outlook.com (10.167.244.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7519.19 via Frontend Transport; Tue, 23 Apr 2024 07:59:05 +0000 Received: from pyuan-Chachani-VN.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.35; Tue, 23 Apr 2024 02:58:59 -0500 From: Perry Yuan To: , , , , , , CC: , , , , , Subject: [PATCH v11 6/8] cpufreq: amd-pstate: get transition delay and latency value from ACPI tables Date: Tue, 23 Apr 2024 15:58:22 +0800 Message-ID: <81aafa46533637984cc9c80f90faf5498a7308c9.1713858800.git.perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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-TrafficTypeDiagnostic: CH2PEPF0000013E:EE_|IA0PR12MB8695:EE_ X-MS-Office365-Filtering-Correlation-Id: 39172584-af73-49d4-6adf-08dc636b3fa8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gPrEsdNZkaMZPQOBAcNXOcd23dfEOg0IQXNyHPV28+isDh95eTQsWC3ukCOiBZQzQmtmyaC8SkLZySeQJZ6c5zXeE3Vw84zypv8UzKPwxkbr9xVecD08hOSq9bAamQYJjigPwSok39jQdj5mhsIQjNmwumH4jOWTgQaoN6CKvBJlJVmfcLKBf0a8yReee13evptusfkUSjb+YG8dVP9O1jXF2P0Zmqqn5vbwk55WQULoZMBeL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mT8ro4tZW5m31MYB7SvD5Gi7EARKNh/KSZnbpoxtTWuhGOQrLl4M7CGojBvpF0= 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:(13230031)(1800799015)(82310400014)(376005)(36860700004); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2024 07:59:05.9795 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 39172584-af73-49d4-6adf-08dc636b3fa8 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: CH2PEPF0000013E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8695 Make pstate driver initially retrieve the P-state transition delay and latency values from the BIOS ACPI tables which has more reasonable delay and latency values according to the platform design and requirements. Previously there values were hardcoded at specific value which may have conflicted with platform and it might not reflect the most accurate or optimized setting for the processor. [054h 0084 8] Preserve Mask : FFFFFFFF00000000 [05Ch 0092 8] Write Mask : 0000000000000001 [064h 0100 4] Command Latency : 00000FA0 [068h 0104 4] Maximum Access Rate : 0000EA60 [06Ch 0108 2] Minimum Turnaround Time : 0000 Reviewed-by: Gautham R. Shenoy Reviewed-by: Mario Limonciello Tested-by: Dhananjay Ugwekar Signed-off-by: Perry Yuan Acked-by: Huang Rui --- drivers/cpufreq/amd-pstate.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 960fead0b83e..510b5aec42ea 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -756,6 +756,36 @@ static void amd_pstate_update_limits(unsigned int cpu) mutex_unlock(&amd_pstate_driver_lock); } +/** + * Get pstate transition delay time from ACPI tables that firmware set + * instead of using hardcode value directly. + */ +static u32 amd_pstate_get_transition_delay_us(unsigned int cpu) +{ + u32 transition_delay_ns; + + transition_delay_ns = cppc_get_transition_latency(cpu); + if (transition_delay_ns == CPUFREQ_ETERNAL) + return AMD_PSTATE_TRANSITION_DELAY; + + return transition_delay_ns / NSEC_PER_USEC; +} + +/** + * Get pstate transition latency value from ACPI tables that firmware + * set instead of using hardcode value directly. + */ +static u32 amd_pstate_get_transition_latency(unsigned int cpu) +{ + u32 transition_latency; + + transition_latency = cppc_get_transition_latency(cpu); + if (transition_latency == CPUFREQ_ETERNAL) + return AMD_PSTATE_TRANSITION_LATENCY; + + return transition_latency; +} + /** * amd_pstate_init_freq: Initialize the max_freq, min_freq, * nominal_freq and lowest_nonlinear_freq for @@ -848,8 +878,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy) goto free_cpudata1; } - policy->cpuinfo.transition_latency = AMD_PSTATE_TRANSITION_LATENCY; - policy->transition_delay_us = AMD_PSTATE_TRANSITION_DELAY; + policy->cpuinfo.transition_latency = amd_pstate_get_transition_latency(policy->cpu); + policy->transition_delay_us = amd_pstate_get_transition_delay_us(policy->cpu); policy->min = min_freq; policy->max = max_freq;