From patchwork Mon Oct 30 06:34:01 2023
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: "Meng, Li \(Jassmine\)"
X-Patchwork-Id: 739314
Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net
[23.128.96.19])
(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 B365B15D5
for ; Mon, 30 Oct 2023 06:35:39 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com
header.b="fC8H9XvG"
Received: from NAM12-MW2-obe.outbound.protection.outlook.com
(mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62])
by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2186CF5;
Sun, 29 Oct 2023 23:35:37 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=jdrn7DUtfHgLneepxQo3sm+Pz0ToBP+1zNHMp4QgUXrUfhaNoWELBoe1nr5ZGUtEGIobY+8dN3vWpXKOHUjx8plCLpCUh+nfEKsUvZgGCa7o4WYSgLVxnfFgUhXu+MFRsRvhjn2GmFWtAJNACSrrWP7/2dxg3dpZRf87NAVb8VjmJJapeakSanGMeUjOaKVyFG4SEo6jN418W3IfaPPYw79bOIUMrROHT1Z/2Lh0rNACd7/MlldbLhnW4SZfJ3SKWSJks8gFYBXUEk09FpstBmb9UeIKnd9fCIDi7HVwtX95Js9zcDPty1rNVt308/ZN4PwmzosfnWD2e5j7UDMucA==
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=q5HrsKpt0YVryXU4IZ+7QmZbfZmeatUSthRHzkrESZA=;
b=faMxPVVjzaUj545dQ81bguJfkCMTcMrNvb5uqKw9ZAv6MqeoO7Bd+U7W/VE2ZfA1w1/CRRw4w17WyyfBrVbHhvqlT2EAH1FaeowW3+XocOa7w+WlURiVAQxsejNe9ZtfoMPKQZitWbp4H1fTR+cXuULbNVWhmyOKg76LmhsaMM8edf0UcmQRWs84qrbwXLRb/ihdgohbx/YbG2iBfCakd3s7Gpnvnf9s0nhHIAaUda7dLXID2MKvdftVWasHpgjOZubZlwsOP5vkr0pIygAQ4EMtEYnzShvmE4OFmHX50GBCsrIJr+29QvZGbV+aAe8R4yTROeGdOdvSzzKnnxakfg==
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=q5HrsKpt0YVryXU4IZ+7QmZbfZmeatUSthRHzkrESZA=;
b=fC8H9XvG73f3WQ3crt+V7dp6tRG630fneSx4rjIeCyjYbQtTemfAtoMu67RNAvcsn1TJn6E9HGfx230EV/Bwy8zOj/Bxz9U2HzjehRJAcO9ts6n6MMAo9uogFYj9/K6BtK0K3mv6vkv2vWteUnF+p174JE161bKBzMT1Sm7cExs=
Received: from BL1PR13CA0076.namprd13.prod.outlook.com (2603:10b6:208:2b8::21)
by IA1PR12MB8079.namprd12.prod.outlook.com (2603:10b6:208:3fb::5)
with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Mon, 30 Oct
2023 06:35:34 +0000
Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com
(2603:10b6:208:2b8:cafe::bb) by BL1PR13CA0076.outlook.office365.com
(2603:10b6:208:2b8::21) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.15 via Frontend
Transport; Mon, 30 Oct 2023 06:35:34 +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
BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft
SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
15.20.6933.15 via Frontend Transport; Mon, 30 Oct 2023 06:35:33 +0000
Received: from jasmine-meng.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.32; Mon, 30 Oct
2023 01:35:28 -0500
From: Meng Li
To: "Rafael J . Wysocki" , Huang Rui
CC: , ,
, , Shuah Khan
, , "Nathan
Fontenot" , Deepak Sharma ,
Alex Deucher , Mario Limonciello
, Shimmer Huang , "Perry
Yuan" , Xiaojian Du , Viresh Kumar
, Borislav Petkov , "Oleksandr
Natalenko" , Meng Li , Wyes Karny
Subject: [PATCH V10 5/7] cpufreq: amd-pstate: Update amd-pstate preferred core
ranking dynamically
Date: Mon, 30 Oct 2023 14:34:01 +0800
Message-ID: <20231030063403.3502816-6-li.meng@amd.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20231030063403.3502816-1-li.meng@amd.com>
References: <20231030063403.3502816-1-li.meng@amd.com>
Precedence: bulk
X-Mailing-List: linux-acpi@vger.kernel.org
List-Id:
List-Subscribe:
List-Unsubscribe:
MIME-Version: 1.0
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-TrafficTypeDiagnostic: BL6PEPF0001AB78:EE_|IA1PR12MB8079:EE_
X-MS-Office365-Filtering-Correlation-Id: 83848946-3249-4772-2799-08dbd9126b61
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: 0mRw208Z0nxomr0ZMyYtSBUdTQyLqvFUEuJBCTXsSt52dmeH6EN4dqb5WgVPrVKkVS7B/jfxwDemMJ5Q3oK4SHnnTx1/ZaAN0Wkle1aSSob20BOY3Txtnc1GjTsWlNSWjCFVsGq+rDzq1k9fpv4i3rYOajD6ehE9e7R7gB5E3FtVq1RsbSAKwC6CAPHUlmjvB5GJrrFw6hb5cRA3KCVRamgIU4xozNiLvaZQwMJvX9Y1Q+CXsV1vSyHc1+5knauCslIkY7qrUiiymMwZhF0knFtEz/Q4Xvh27fFd+Hdel0jX81g/LiretjG89t1vnf481jTGmsvEKJ4C2XCbfvrkzctq74rolLbFIQwafmz9M7QA3vrd4n4/YAiwrheLlkDs2KeLRGB6Q2SoRdoi39k8XwjgMs8oR3zdqwUtas/clUuxFjHTvFtQlSLz15eLgXmiqLi3DD8XdU3keZ6ZUdvJeQOCQ8RCXZKLTKOPvhOPjjNtksJUCWT1mZQX9YRQk9zWhceSO9IGBrIKklItpNTP4fOjV2Dbaltl/3wdldlc0h/i4XIf5mFqFGY5fjRXtL0LLmHqHlj2EEv67kuM+inpdOemjT9kR6tUAzWpltNGGBke9vQgj2VzmKAZUas0iBhX5mH4RnsnaPR3HbtbNL1G0s7Mh1soA4klxqNP0WSl2r7q84M/OcWAq/lByHMNOBi1vQXIMbtv2Lis8b52+ZEC+y/feHDa/8L1E1wBCZ/Lx36H5e76PDyjBzs2Tlkuk4NcGMogfeEEnuV1WhH7sizLcQ==
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)(4636009)(39860400002)(396003)(376002)(136003)(346002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(82310400011)(36840700001)(40470700004)(46966006)(2906002)(86362001)(66899024)(41300700001)(8676002)(4326008)(8936002)(7416002)(5660300002)(15650500001)(40460700003)(36756003)(478600001)(40480700001)(47076005)(7696005)(6666004)(1076003)(81166007)(6636002)(316002)(54906003)(16526019)(110136005)(26005)(70206006)(426003)(336012)(70586007)(82740400003)(83380400001)(36860700001)(2616005)(356005)(36900700001);
DIR:OUT; SFP:1101;
X-OriginatorOrg: amd.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2023 06:35:33.6756 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 83848946-3249-4772-2799-08dbd9126b61
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: BL6PEPF0001AB78.namprd02.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8079
Preferred core rankings can be changed dynamically by the
platform based on the workload and platform conditions and
accounting for thermals and aging.
When this occurs, cpu priority need to be set.
Tested-by: Oleksandr Natalenko
Reviewed-by: Mario Limonciello
Reviewed-by: Wyes Karny
Reviewed-by: Huang Rui
Signed-off-by: Meng Li
---
drivers/cpufreq/amd-pstate.c | 46 ++++++++++++++++++++++++++++++++++++
include/linux/amd-pstate.h | 6 +++++
2 files changed, 52 insertions(+)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 2033e5e70017..1be33f926678 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -312,6 +312,7 @@ static int pstate_init_perf(struct amd_cpudata *cpudata)
WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1));
WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1));
WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1));
+ WRITE_ONCE(cpudata->prefcore_ranking, AMD_CPPC_HIGHEST_PERF(cap1));
return 0;
}
@@ -333,6 +334,7 @@ static int cppc_init_perf(struct amd_cpudata *cpudata)
WRITE_ONCE(cpudata->lowest_nonlinear_perf,
cppc_perf.lowest_nonlinear_perf);
WRITE_ONCE(cpudata->lowest_perf, cppc_perf.lowest_perf);
+ WRITE_ONCE(cpudata->prefcore_ranking, cppc_perf.highest_perf);
if (cppc_state == AMD_PSTATE_ACTIVE)
return 0;
@@ -749,6 +751,34 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
schedule_work(&sched_prefcore_work);
}
+static void amd_pstate_update_highest_perf(unsigned int cpu)
+{
+ struct cpufreq_policy *policy;
+ struct amd_cpudata *cpudata;
+ u32 prev_high = 0, cur_high = 0;
+ int ret;
+
+ if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore))
+ return;
+
+ ret = amd_pstate_get_highest_perf(cpu, &cur_high);
+ if (ret)
+ return;
+
+ policy = cpufreq_cpu_get(cpu);
+ cpudata = policy->driver_data;
+ prev_high = READ_ONCE(cpudata->prefcore_ranking);
+
+ if (prev_high != cur_high) {
+ WRITE_ONCE(cpudata->prefcore_ranking, cur_high);
+
+ if (cur_high < CPPC_MAX_PERF)
+ sched_set_itmt_core_prio((int)cur_high, cpu);
+ }
+
+ cpufreq_cpu_put(policy);
+}
+
static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
{
int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
@@ -920,6 +950,17 @@ static ssize_t show_amd_pstate_highest_perf(struct cpufreq_policy *policy,
return sysfs_emit(buf, "%u\n", perf);
}
+static ssize_t show_amd_pstate_prefcore_ranking(struct cpufreq_policy *policy,
+ char *buf)
+{
+ u32 perf;
+ struct amd_cpudata *cpudata = policy->driver_data;
+
+ perf = READ_ONCE(cpudata->prefcore_ranking);
+
+ return sysfs_emit(buf, "%u\n", perf);
+}
+
static ssize_t show_amd_pstate_hw_prefcore(struct cpufreq_policy *policy,
char *buf)
{
@@ -1133,6 +1174,7 @@ cpufreq_freq_attr_ro(amd_pstate_max_freq);
cpufreq_freq_attr_ro(amd_pstate_lowest_nonlinear_freq);
cpufreq_freq_attr_ro(amd_pstate_highest_perf);
+cpufreq_freq_attr_ro(amd_pstate_prefcore_ranking);
cpufreq_freq_attr_ro(amd_pstate_hw_prefcore);
cpufreq_freq_attr_rw(energy_performance_preference);
cpufreq_freq_attr_ro(energy_performance_available_preferences);
@@ -1143,6 +1185,7 @@ static struct freq_attr *amd_pstate_attr[] = {
&amd_pstate_max_freq,
&amd_pstate_lowest_nonlinear_freq,
&amd_pstate_highest_perf,
+ &amd_pstate_prefcore_ranking,
&amd_pstate_hw_prefcore,
NULL,
};
@@ -1151,6 +1194,7 @@ static struct freq_attr *amd_pstate_epp_attr[] = {
&amd_pstate_max_freq,
&amd_pstate_lowest_nonlinear_freq,
&amd_pstate_highest_perf,
+ &amd_pstate_prefcore_ranking,
&amd_pstate_hw_prefcore,
&energy_performance_preference,
&energy_performance_available_preferences,
@@ -1491,6 +1535,7 @@ static struct cpufreq_driver amd_pstate_driver = {
.suspend = amd_pstate_cpu_suspend,
.resume = amd_pstate_cpu_resume,
.set_boost = amd_pstate_set_boost,
+ .update_highest_perf = amd_pstate_update_highest_perf,
.name = "amd-pstate",
.attr = amd_pstate_attr,
};
@@ -1505,6 +1550,7 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
.online = amd_pstate_epp_cpu_online,
.suspend = amd_pstate_epp_suspend,
.resume = amd_pstate_epp_resume,
+ .update_highest_perf = amd_pstate_update_highest_perf,
.name = "amd-pstate-epp",
.attr = amd_pstate_epp_attr,
};
diff --git a/include/linux/amd-pstate.h b/include/linux/amd-pstate.h
index 87e140e9e6db..426822612373 100644
--- a/include/linux/amd-pstate.h
+++ b/include/linux/amd-pstate.h
@@ -39,11 +39,16 @@ struct amd_aperf_mperf {
* @cppc_req_cached: cached performance request hints
* @highest_perf: the maximum performance an individual processor may reach,
* assuming ideal conditions
+ * 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 fixed value as the highest_perf.
* @nominal_perf: the maximum sustained performance level of the processor,
* assuming ideal operating conditions
* @lowest_nonlinear_perf: the lowest performance level at which nonlinear power
* savings are achieved
* @lowest_perf: the absolute lowest performance level of the processor
+ * @prefcore_ranking: the preferred core ranking, the higher value indicates a higher
+ * priority.
* @max_freq: the frequency that mapped to highest_perf
* @min_freq: the frequency that mapped to lowest_perf
* @nominal_freq: the frequency that mapped to nominal_perf
@@ -73,6 +78,7 @@ struct amd_cpudata {
u32 nominal_perf;
u32 lowest_nonlinear_perf;
u32 lowest_perf;
+ u32 prefcore_ranking;
u32 max_freq;
u32 min_freq;