From patchwork Sun Feb 18 16:10:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Lee Jing Yi X-Patchwork-Id: 202808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp849530dyc; Sun, 18 Feb 2024 08:15:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV4AyPRtN/0L36W8nakFeQzXNN/lgJd54XO2q07BwvOpAt7YDqaGEPyIYpjCNOIs9R+7KbWm2DQQWnlslYwuBmQ6WN2rA== X-Google-Smtp-Source: AGHT+IGu2nAXVoYLUZ37HE0Xkjy6TXPGBM0L4v7CyPs5+WZeK+4pGDvNM4qqTadaK+2ATbQtZlhA X-Received: by 2002:a05:6402:202e:b0:564:17dd:d7e4 with SMTP id ay14-20020a056402202e00b0056417ddd7e4mr2864404edb.33.1708272925521; Sun, 18 Feb 2024 08:15:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708272925; cv=pass; d=google.com; s=arc-20160816; b=VIe4chxVcih/7QNuu5WmxTyQ91SO6Odb/NhMfLq30wabdAYZBe/ONlgcEOf6kaYQaq td6Y6kUjE2W4jOKWpTmtI09u+XQ4rVSApOId2ht3IAr4ERejyQYiD89xdirtKtchxQlh ZYteYC/Nd0IhaySGPwsshXIJIWq9P69qtq5SO9AxVJK+LTrNX3/GrnwkZi/JVspO9V9k SMMuRj4llVpSkG4VUtiX+w9DtFCUbjxvsULQ3U7m0KvSWzRC0tzbFZXWUr7oF8ZwThSv irshkYp/EcDX8Gsclsaz/oEuy8KiMJvWX0FC22KuxRDi4p2sz0v+AoNyujrW04vm/kaB PejA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jBEJEQMmiSyOiBfdxdCLolpOwFxsaEhAkf01EcWWZrk=; fh=TeapZNyTYd21fCy4uZOssWzmS+Oms4PbHEz7COeJn+U=; b=ng/V46waX0cj996+vY+jSaWOduQYkNea92rgkSU+oT39voiGj+CDJY+C/1svYkU3Hh jVEB9oDfbIsIqs9LqvsAW395TtZvsrEEbhlmZptr+KBrjt3wjObJ8KA+jOXSfbWBcbId gQlGREDDTtvF0weriiGle8gleRLZp6/Tw1b9vFnP5M78WvcHcYEylOM2OM+W1Dj4tMyh mHkTDBhiEiNscCGJ7THynZ8Fx8gEQtGtFA+pFU0gpAkjymgd7lt1TzFxCxnbICaqyY8d 9IujayQS/DHBwSXp5LnRfNOz1dfNcGN9tkkMu6j83TrK6kaLpFQB4+exy9eI0fUkOtfJ TBpA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iPQCIfzf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-70440-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70440-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r7-20020a056402234700b0055fea2e2bccsi1742369eda.403.2024.02.18.08.15.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 08:15:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70440-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iPQCIfzf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-70440-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70440-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F18CB1F213D7 for ; Sun, 18 Feb 2024 16:15:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F03EC6DCE0; Sun, 18 Feb 2024 16:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iPQCIfzf" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A17FE6D1B7; Sun, 18 Feb 2024 16:15:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708272909; cv=none; b=HUPcLOnPmpBNYxtDD5dScxHupa+Ibjz2J4pC/zx+b1PlImRdF4Gq4JWpazIcYOFHTXcgTLD5ctQeFCqEh2QbDHkTdPg7HQW2ohP/NZCJZHz/wcgPVOCe6NpdmyRVxYlU9RsvFGfn1KCcO+ANCVNQNf2lmWwXTUP+waThY5Z8vNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708272909; c=relaxed/simple; bh=crYDsTu/Q8z/SY44ZdcbWRzwpyUgHxlte4VZaTnPqNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WgpDXp9bFypaRfk83phGnYVa02EDE385UvON4CJI8ECBt+g44liwfCyRiWq+OG8Sffinp1Ff3LeiolryuKfIY4sUd5A8u83fC6X3iJFy1K9UkFG8MoEP0Dcv7A6cXckAftTBJa8lCzNo7DZ7T6yV+0aAqxcBnXQTjLa1g/+lbeo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iPQCIfzf; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d7393de183so28258685ad.3; Sun, 18 Feb 2024 08:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708272907; x=1708877707; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jBEJEQMmiSyOiBfdxdCLolpOwFxsaEhAkf01EcWWZrk=; b=iPQCIfzfexzl3xlBouQKCaBQisZOMcXvBAmxYwSvfEOTRTeZe7LdIIfjiQUB5KIxc2 xfS++ZgLTVKA4kNk/82bMSyZfXm5GBg7gEt9J7jHgvMBoNw+/Ynt6f5htYuXPGp8c4gJ 2apNm9H2V65kO9j8L5V2Kf5VWAnVEo0fzSM3B63kQ0KKH7hRWWHjykP0c50ZVu6HAbAK D59F0+HPbHooc9vP0HB6OT1p8wmI4i/obyHAb1hHG5v/D4FhgP7kD5Et+JClXw70dM7+ TRTXtJg0wGJcMIIEYplbRlAdIVMpChN0uiFuft027zvgZjnou1dLT/RbxcpI4aK1zYav Yg5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708272907; x=1708877707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jBEJEQMmiSyOiBfdxdCLolpOwFxsaEhAkf01EcWWZrk=; b=BWKBIdGgjEEwJGU3Ef2blr1ofNnB+BXEadkEa0oljjyq033jdSPR/sOt/kPYoU6rUv 6/3Kg3kiTLGHvK5131jhKhw9+Yj0yvEncSZfbnoqt9Mz1PNPSXxLJ2pJSqQHGogn7siG wbzQNHfYW54O1Jw7RM1SC87+XRoragR+T9pn7mJyKFiReiBkzX7dHTTU8SilFaleQpPR 1BnN0RgHnWLJJk4seUIRH0s6uNxuc/OCAkTc8Inypo2oUGHiobGlggJSOXVpaLkNSKha kYUDUyLXGcFrbGui8BnLhj9V45kCeQe8eBV+ScvBtyFJqhtPZPSpGLYTruQs82T9jvP9 H5Aw== X-Forwarded-Encrypted: i=1; AJvYcCWoRbflmZMA7gOxYlXDIz74inoiyOZURtqDQVc91kPCfia6vGn11AOHezZU2M8TeTbp6x/ur+roZho/cPqP9w66CI/dBthphp0AVnFFGdDTLfr2FNTb/fcOXYWSUTdmCEibxv1T3rsP3Miq0g4FruUB2fqhMSbCfZh6cCLcx7l/kwjgZ7wH9qFr8xYIzcMR3GYQa5eAIE1ZivTaMrBzrV4FEpUB X-Gm-Message-State: AOJu0YxMp5Uce6cguR25qGtzXtzs5IAm4O37FBpnKN6tVOIQJTUoz3wX cUClf8jnzc3zzaJ59lhexw5osTtiYGBrR4YRL4DtPb/W5Zz9hqxo3oxmKv9piVQKqA== X-Received: by 2002:a17:902:ea0e:b0:1db:f371:dca3 with SMTP id s14-20020a170902ea0e00b001dbf371dca3mr496043plg.48.1708272906869; Sun, 18 Feb 2024 08:15:06 -0800 (PST) Received: from localhost.localdomain ([2406:3003:2000:500f:a246:8a16:bee7:140f]) by smtp.gmail.com with ESMTPSA id je20-20020a170903265400b001db4caef8d6sm2849500plb.161.2024.02.18.08.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 08:15:06 -0800 (PST) From: Lucas Lee Jing Yi To: rafael@kernel.org Cc: Perry.Yuan@amd.com, Xiaojian.Du@amd.com, alexander.deucher@amd.com, bp@alien8.de, deepak.sharma@amd.com, li.meng@amd.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pm@vger.kernel.org, mario.limonciello@amd.com, nathan.fontenot@amd.com, oleksandr@natalenko.name, rafael.j.wysocki@intel.com, ray.huang@amd.com, shimmer.huang@amd.com, skhan@linuxfoundation.org, viresh.kumar@linaro.org, x86@kernel.org, Lucas Lee Jing Yi Subject: [PATCH] [PATCH] amd_pstate: fix erroneous highest_perf value on some CPUs Date: Mon, 19 Feb 2024 00:10:31 +0800 Message-ID: <20240218161435.38312-2-lucasleeeeeeeee@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240218161435.38312-1-lucasleeeeeeeee@gmail.com> References: <20240218161435.38312-1-lucasleeeeeeeee@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791253990945828841 X-GMAIL-MSGID: 1791253990945828841 On a Ryzen 7840HS the highest_perf value is 196, not 166 as AMD assumed. This leads to the advertised max clock speed to only be 4.35ghz instead of 5.14ghz , leading to a large degradation in performance. Fix the broken assumption and revert back to the old logic for getting highest_perf. TEST: Geekbench 6 Before Patch: Single Core: 2325 (-22%)! Multi Core: 11335 (-10%) Geekbench 6 AFTER Patch: Single Core: 2635 Multi Core: 12487 Signed-off-by: Lucas Lee Jing Yi Reviewed-by: Li Meng < li.meng@amd.com> --- drivers/cpufreq/amd-pstate.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 08e112444c27..54df68773620 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -50,7 +50,6 @@ #define AMD_PSTATE_TRANSITION_LATENCY 20000 #define AMD_PSTATE_TRANSITION_DELAY 1000 -#define AMD_PSTATE_PREFCORE_THRESHOLD 166 /* * TODO: We need more time to fine tune processors with shared memory solution @@ -299,15 +298,12 @@ static int pstate_init_perf(struct amd_cpudata *cpudata) &cap1); if (ret) return ret; - - /* For platforms that do not support the preferred core feature, the - * highest_pef may be configured with 166 or 255, to avoid max frequency - * calculated wrongly. we take the AMD_CPPC_HIGHEST_PERF(cap1) value as - * the default max perf. + + /* Some CPUs have different highest_perf from others, it is safer + * to read it than to assume some erroneous value, leading to performance issues. */ - if (cpudata->hw_prefcore) - highest_perf = AMD_PSTATE_PREFCORE_THRESHOLD; - else + highest_perf = amd_get_highest_perf(); + if(highest_perf > AMD_CPPC_HIGHEST_PERF(cap1)) highest_perf = AMD_CPPC_HIGHEST_PERF(cap1); WRITE_ONCE(cpudata->highest_perf, highest_perf); @@ -329,9 +325,11 @@ static int cppc_init_perf(struct amd_cpudata *cpudata) if (ret) return ret; - if (cpudata->hw_prefcore) - highest_perf = AMD_PSTATE_PREFCORE_THRESHOLD; - else + /* Some CPUs have different highest_perf from others, it is safer + * to read it than to assume some erroneous value, leading to performance issues. + */ + highest_perf = amd_get_highest_perf(); + if(highest_perf > cppc_perf.highest_perf) highest_perf = cppc_perf.highest_perf; WRITE_ONCE(cpudata->highest_perf, highest_perf);