Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp712482rdb; Sun, 18 Feb 2024 08:15:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVPOFxxSjjabbmAFMKEiJEBwLHqH3JdpL/IY6P3tIHUg/4fBtJZzV+9S92zeKgGrbDAfx4emgrMzM1tsUDgoCyRLiacMZM7w4jR4VYoUA== X-Google-Smtp-Source: AGHT+IEi9M9W9eKNJy1j1aMHWgFa2b8Krj5qnN7AyPkmy45GfHyhNu+Xl1h/T7NIaC7xQHKx32tn X-Received: by 2002:a05:6870:2c97:b0:21e:854d:e846 with SMTP id oh23-20020a0568702c9700b0021e854de846mr5514464oab.30.1708272926406; Sun, 18 Feb 2024 08:15:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708272926; cv=pass; d=google.com; s=arc-20160816; b=EQI+zZ5lGsUZ7hu2QBJKgYw/IJ0xGzlKUYzIpKLr10+aNqrPl1bgdDFT0TcggMpZkR YtoaKRZHSw+PeuSx3YEepPuqBh6+MHexXXwXsdg2mnJwjCHTJCREhiGz3O5kFOMVGlXS 7qHqZNllZBGtm3tjQsAMHAdR9GRZbeEMjvAJSqlf4AuOpMDd+3mc1OV2uhzWMkjKNKqb uZ/cKghUpKgd8f5Jaza+XY7jX1s1hV+2L+bBVAre2w7d9VvgiuGq6xzklAcCZxR/7sW7 71dU6QgROe3jwTXtIjmnoGUT7Pf045APZqj5aZ5Acbh0LHUCoLwokjabc7/J/WQU0yb1 vCpQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70440-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q4-20020a656a84000000b005dc4190c756si3097003pgu.866.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:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70440-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70440-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id DB8D6B20DF4 for ; Sun, 18 Feb 2024 16:15:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE1786D1D3; Sun, 18 Feb 2024 16:15:09 +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 Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.43.2