Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1615146rdb; Tue, 20 Feb 2024 01:23:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdOnEMU+2EivY8JVPkcE276iMOVaz1BBlaLEpXNh0EMgjWAAHvC3zTblCCbajWYF/WazUhwJM9Gg7HkA06pLXXa2AsCw2XQHjzxY0/Ng== X-Google-Smtp-Source: AGHT+IFaVFgRSBDcw6DSY1O471hEHDelg/DvVqCFfZiX9JHvxXS7vkySL/y12wb6BeiSsi7yBBdl X-Received: by 2002:a05:6a00:91:b0:6e0:a305:aae5 with SMTP id c17-20020a056a00009100b006e0a305aae5mr11033455pfj.28.1708421023436; Tue, 20 Feb 2024 01:23:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708421023; cv=pass; d=google.com; s=arc-20160816; b=rPgf+3cgsIl21Zk+jMes7vozfRXtU7LeW1lI63i63A/+6Eq6+lgaRmPPeRgzKhcXW3 W1HMhAFB+cUNmC97aM7FvFGRRbGS47nZH3Mx0wzTOvHw9w6qgVSa0Mf+joBYN5FApyaO N0Sy9AHqws3uVVsk6S7hA6xD4RVqq9fDouXWBRobRgiY/0y3Xbxk0Ng9vZBQPfxktUgV ZQls9FyffQx3zj1IOothWUuvG6gFP3x7t1ly8DHZoN98kjuWtHU9RGDcLOBRvzy8PN1F 0ZysKGRvO7D5AmKqcuU/9B+LsgOPFsfYywH4377MgHOLvXdoFSjav+uww/rOFd1Lyg8v O46Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yqtS9OdSkKTkmUyYkJaIlBJaviSDyIFjBjSZbNBn07E=; fh=dLxbI+Zi8gXrEdRSzkhp02yOT5tAQrjMGJ/OdYFDC04=; b=RKh0smpqnQq9HDXbILSH+HKIwM0PPTXooWXO2/m2ZoP8D4DDJ02eQNfP5ZxPfJ6tFy FFBY7YsMgOSj/PpIALD8g4vCRQQvwqGXud+VoMStbWPd/uMCB35IK0OeadpjU+B0Q0sF Pqj7HUqaS1yim27ektBvlExbHkVeCRqwSf870hx4aP8Hc3WUPJnYOMbz4iNjHLZlYRgG DOb7iIfctRxYZ+t4PzCF2GQtdqfupq295eb9xhDdhInxdlAZ6OZACdI7ElpjXj1/JaDa VkBn0EbeAatES0tp9V3UTOA2Umv+nLVcSD5AWtzZ7/qBiHJu/ATSE09C9W+gRo3w/opH qJhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@natalenko.name header.s=dkim-20170712 header.b=rKWXKsfJ; arc=pass (i=1 spf=pass spfdomain=natalenko.name dkim=pass dkdomain=natalenko.name dmarc=pass fromdomain=natalenko.name); spf=pass (google.com: domain of linux-kernel+bounces-72640-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72640-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=natalenko.name Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x24-20020a056a000bd800b006e3427bb92csi5032289pfu.84.2024.02.20.01.23.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 01:23:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72640-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=@natalenko.name header.s=dkim-20170712 header.b=rKWXKsfJ; arc=pass (i=1 spf=pass spfdomain=natalenko.name dkim=pass dkdomain=natalenko.name dmarc=pass fromdomain=natalenko.name); spf=pass (google.com: domain of linux-kernel+bounces-72640-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72640-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=natalenko.name 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 05953B21D1E for ; Tue, 20 Feb 2024 09:04:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FE4B6088A; Tue, 20 Feb 2024 09:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=natalenko.name header.i=@natalenko.name header.b="rKWXKsfJ" Received: from prime.voidband.net (prime.voidband.net [199.247.17.104]) (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 410745C8E9; Tue, 20 Feb 2024 09:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.247.17.104 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708419794; cv=none; b=Fjq7aGPWiFhdFHNM3n49Zhf7b+SJTKh6gSlvn3bx5CAXHO5pov7JxSB5QjNjuKkuw9acav8itiFT3E+7s+7fqbIaQzLF9dVoenZIyoEGyMLt37Xlr1uRT2W/CG4TejkN+4NbNFeIizRpo7jK8uy4Q4WoNM63Ow4lFn00frtoAQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708419794; c=relaxed/simple; bh=JceG0EdglJthXyZekPMBQ1UrnXqMgMpzZET8QvST5k0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nuxhyBJflhToNLG1nug+m4a7ywuBBZ9rSvd2Vi385mkr7npd7ZE0P1idihuRWlMssDjKQsRyR4FA1+t9s70iYuQXmMARZiT6yobTOPaSivFD66AWzSPI8O031W40kA3oUx8mIyMuptOCKJpHvQWlVEpI02bUQs7D6zmaX2YeS0Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=natalenko.name; spf=pass smtp.mailfrom=natalenko.name; dkim=pass (1024-bit key) header.d=natalenko.name header.i=@natalenko.name header.b=rKWXKsfJ; arc=none smtp.client-ip=199.247.17.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=natalenko.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=natalenko.name Received: from spock.localnet (unknown [94.142.239.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by prime.voidband.net (Postfix) with ESMTPSA id BFA16635B056; Tue, 20 Feb 2024 10:03:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=natalenko.name; s=dkim-20170712; t=1708419782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yqtS9OdSkKTkmUyYkJaIlBJaviSDyIFjBjSZbNBn07E=; b=rKWXKsfJ8o3lefY6RKvN3UuSJvK4ybWAncvyjvNfyyN3kLsGnjZ83xEQS73j9psgeqrgkK od6Es83fuZI/nffi5iSKfYGZbM42qtRvc/g0R8KJeyxuZwXXpBG9u1Vz/Ltlnl3PwWw6gK KMNOqhDkuF3LM6aMFmWKNtuiOeAlwTs= From: Oleksandr Natalenko To: rafael@kernel.org, Lucas Lee Jing Yi 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, 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: Re: [PATCH] [PATCH] amd_pstate: fix erroneous highest_perf value on some CPUs Date: Tue, 20 Feb 2024 10:02:48 +0100 Message-ID: <3868832.mvXUDI8C0e@natalenko.name> In-Reply-To: <20240218161435.38312-2-lucasleeeeeeeee@gmail.com> References: <20240218161435.38312-1-lucasleeeeeeeee@gmail.com> <20240218161435.38312-2-lucasleeeeeeeee@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart13532597.O9o76ZdvQC"; micalg="pgp-sha256"; protocol="application/pgp-signature" --nextPart13532597.O9o76ZdvQC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8"; protected-headers="v1" From: Oleksandr Natalenko To: rafael@kernel.org, Lucas Lee Jing Yi Date: Tue, 20 Feb 2024 10:02:48 +0100 Message-ID: <3868832.mvXUDI8C0e@natalenko.name> In-Reply-To: <20240218161435.38312-2-lucasleeeeeeeee@gmail.com> MIME-Version: 1.0 Hello. On ned=C4=9Ble 18. =C3=BAnora 2024 17:10:31 CET Lucas Lee Jing Yi wrote: > 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 o= f 5.14ghz , leading to a large degradation in performance. >=20 > Fix the broken assumption and revert back to the old logic for getting hi= ghest_perf. >=20 > TEST: > Geekbench 6 Before Patch: > Single Core: 2325 (-22%)! > Multi Core: 11335 (-10%) >=20 > Geekbench 6 AFTER Patch: > Single Core: 2635 > Multi Core: 12487 >=20 > Signed-off-by: Lucas Lee Jing Yi > --- > drivers/cpufreq/amd-pstate.c | 22 ++++++++++------------ > 1 file changed, 10 insertions(+), 12 deletions(-) >=20 > 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 @@ > =20 > #define AMD_PSTATE_TRANSITION_LATENCY 20000 > #define AMD_PSTATE_TRANSITION_DELAY 1000 > -#define AMD_PSTATE_PREFCORE_THRESHOLD 166 > =20 > /* > * TODO: We need more time to fine tune processors with shared memory so= lution > @@ -299,15 +298,12 @@ static int pstate_init_perf(struct amd_cpudata *cpu= data) > &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. > +=20 > + /* Some CPUs have different highest_perf from others, it is safer=20 > + * to read it than to assume some erroneous value, leading to performan= ce issues. > */ > - if (cpudata->hw_prefcore) > - highest_perf =3D AMD_PSTATE_PREFCORE_THRESHOLD; > - else > + highest_perf =3D amd_get_highest_perf(); > + if(highest_perf > AMD_CPPC_HIGHEST_PERF(cap1)) > highest_perf =3D AMD_CPPC_HIGHEST_PERF(cap1); > =20 > WRITE_ONCE(cpudata->highest_perf, highest_perf); > @@ -329,9 +325,11 @@ static int cppc_init_perf(struct amd_cpudata *cpudat= a) > if (ret) > return ret; > =20 > - if (cpudata->hw_prefcore) > - highest_perf =3D AMD_PSTATE_PREFCORE_THRESHOLD; > - else > + /* Some CPUs have different highest_perf from others, it is safer=20 > + * to read it than to assume some erroneous value, leading to performan= ce issues. > + */ > + highest_perf =3D amd_get_highest_perf(); > + if(highest_perf > cppc_perf.highest_perf) > highest_perf =3D cppc_perf.highest_perf; > =20 > WRITE_ONCE(cpudata->highest_perf, highest_perf); >=20 Please pay attention to trailing whitespaces, adding whitespaces to blank l= ines, and whitespaces between `if` and opening `(`. `scripts/checkpatch.pl` may help you with that. Thank you. =2D-=20 Oleksandr Natalenko (post-factum) --nextPart13532597.O9o76ZdvQC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZUOOw5ESFLHZZtOKil/iNcg8M0sFAmXUargACgkQil/iNcg8 M0uKvBAA75ErCLUkoBjqYUXvYnxdCiWChCP3YbRF+TZpge2SRBrdHkP37tb0h5xj /YidBER2zYHcqz5PKoflu54fCIQod0VkX33TQ8HkXjm4tytT75WKs6invTYQOMOD wrZmWRw5AvsjKNxUGuhtg2sp3CJjigzk7E8JUdeE2L07Wo5//npN2T4uNZAzI3wA MX6ACRYwwh8yY4iIRTv2PJZfZATo69iRnNbo7UlLAgKqQA+GOsF+jwio2d41O+ZE 5xUfZQDx8DV7Bg/nbhTR0gg0Il3SwsxBg5lIeeLxJch7Rex6tI/Qhj6M0QCPViEA w+ZyB9yMNhwy5yHH0t3KiSBB3ONy7CI0Umw+xriblr0iWRhlDCktI4/PkGhu6QfB CLNk2Xrh8zYVUuZ91YBkxE0HEWxRBlI8c5RdMvS2qYqjdBgvdR8n1ZRVfDioIUHc GCrQSI3/bkfvZDgHJIqFJAQTwS2o4SLUHiNgbrB0V66V9RRvqTlWbqIdztXgWhKi egIAdiyKMEckiymU9Cqh8Q34Voaf2+o7mOE3Hj1l5s2NCBxk4fWoYJP1uRRF+wZm FRQ/DuT2EgDDynHHLybnLl5Fy2LAEFh5cdWdZum8aOuCmruEsG06srI6j8qJ1FLk NjH/oCDfkMemqkVHUFmOO4W9MgY89I4UVQuZGaYDAg2vTDY8+0E= =MiiV -----END PGP SIGNATURE----- --nextPart13532597.O9o76ZdvQC--