From patchwork Thu Aug 24 02:12:47 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: 13363392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65275EE49BA for ; Thu, 24 Aug 2023 02:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239253AbjHXCOr (ORCPT ); Wed, 23 Aug 2023 22:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239328AbjHXCOh (ORCPT ); Wed, 23 Aug 2023 22:14:37 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4255F10C4; Wed, 23 Aug 2023 19:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FPMt50tdeBB9RvG2l8FYNp904E/S/ik+CJ8yYAj59dZIBEqB1KyLZTm6dPqDNi30OFU5XX+K/jGBbLM5Swi6numdPQ4zJQL/feUjV9CSz/SK56udUQ5LnsSrpbb8U/zqRx/zFqp6gqQoQRqzb14oNHakM3vSy+hyakyPEm/7OlTPfc9vLJKnJDdkFFNTEc33qCLc3YtCU23QcnWIlk+UGb6nIHqznZlboYaGNmV/8hKWXsLFtSy78TjSn1uILs7JFazZxUvCXF0/3szRJ9R0Bkj5/o7+ITx7FggGPwXpwIh1ncR+NWTUcyIoyR4DQNxst/k75/PnoxZdG6H9bb1MGg== 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=R+RQepWEpY82uXKfwKZoS1l72EUVb6pDIlmqk6YuNWs=; b=BZwFwx3tJUf5gwJGTQJp7t8hxQYXLaozc3/clUFlOi2pJ9C5hoN1wqETObHGfmd67RenhgMvOMeuMRvySbl8h9Ik0u0EjE25SB2cOoQtofSN5iAJ7rzCYbfJwVVpPmnDWXwEr/CU0NSDldAVfE7DS21VaueqPSbVFmZegYHqd2QoGTHtrcXCOG5pQ/OR/g8yfaXU9C+15JNG0UuG15OeGDiGV9qXhkWE9auY9+TDOGCtaL4kcNIbLGh+TuE7Rh3pDNZxGuLjxH96VdLfpcaLMlzDcoe5KLKDpqaTcSpF0RdQ2POATsyelKzq3nXyF5e1EClinE2iJOpAr98ywFqNbQ== 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 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=R+RQepWEpY82uXKfwKZoS1l72EUVb6pDIlmqk6YuNWs=; b=4NmNSHIAsLAJxA5uf1QmGHGyu12H/MhopCMO1ssyLMDoLhFF64CG3I0bTBfghTrvvnz1nU3DSKT26TvLD0kPunsCae55Gqzxf3cmr15dzC+COADpP1SNCwc/7p2vx9ybVtAw1Pl5Fh1OkvueqIWZdHAQPCZzm4H3SC6eapJH6GM= Received: from CH0PR03CA0450.namprd03.prod.outlook.com (2603:10b6:610:10e::28) by CH3PR12MB8972.namprd12.prod.outlook.com (2603:10b6:610:169::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Thu, 24 Aug 2023 02:14:31 +0000 Received: from CY4PEPF0000EDD3.namprd03.prod.outlook.com (2603:10b6:610:10e:cafe::59) by CH0PR03CA0450.outlook.office365.com (2603:10b6:610:10e::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27 via Frontend Transport; Thu, 24 Aug 2023 02:14:31 +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 CY4PEPF0000EDD3.mail.protection.outlook.com (10.167.241.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Thu, 24 Aug 2023 02:14:31 +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.27; Wed, 23 Aug 2023 21:14:24 -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 , Meng Li Subject: [PATCH V3 5/7] cpufreq: amd-pstate: Update AMD Pstate Preferred Core ranking dynamically Date: Thu, 24 Aug 2023 10:12:47 +0800 Message-ID: <20230824021249.271946-6-li.meng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230824021249.271946-1-li.meng@amd.com> References: <20230824021249.271946-1-li.meng@amd.com> 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: CY4PEPF0000EDD3:EE_|CH3PR12MB8972:EE_ X-MS-Office365-Filtering-Correlation-Id: a687b481-ba68-4022-bf3e-08dba447da3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GpbpN2MK9Ib5u8PU8ydkysNGBE3vPmwXgenA5qXd86007XxQ2Pf8O87mO15Yn8XGSU8GQ9Osldh06x5J0lG0lsW12aMAHPcYNnieK8PntD+hTaNI+mAmVMGK5FWlN0BiZZGZ+h+XO4wYi0NYWcc2eVQ5e9/1S+sCCS0a0dLsLD8IY63LKZHfy3LRzci/deeFB+D3Rna4ByWzMDoze9EnAeMfWbC/Oaw72VbuLIxyT3UjABhmCDCNaYHjB5n12LcV5PHR1bQ2dsPYJPrMwXo/tuNtSjS4uAEg0j0HdvJZ3X7VLcNGsLcH8tOT7Ye631xXle2zb/UQ9q0FTixnan5fl/1VGE55zW2nVGBXMMOzix7WHL8hs42UCjK/VYffEPKqBJCSn35J3D7+wAoWWsHLUVXdDogtYqhOZBzF/LaBvs+L/B5yU6JYnqJPX505/oNBsovOe4oL3ejPEpyf936mRsP0uUwQolYsy2/eCQiKuIn7LL0HNnA/r/DT8Eh32ogQZAnCbMc+4dXPPHjNSDvNErGY1riISrYEov+I5IygU/kZ38F87Kbfq4FshVyaQBXndStbeIg6xSwTwKw0j92Vv6JEpXdnttAiF7t9aFbTZPOdOZYqgMfNnMV+KjhUZlqDfBt9TCJ0bL8SQilPapXojnRv9+xygz7CxvUj89MXtz6/0LlYq/AU1BsZltGEfTdlHAX2l2VNaJrfP+SSdX6a8ifDf3wDugR7rAvWIlOU8DuXKw0eKbwIdg4y/gcRJhsKsjjOBQuCrI/z0dUZfDWNjg== 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)(396003)(39860400002)(136003)(346002)(376002)(1800799009)(186009)(451199024)(82310400011)(36840700001)(40470700004)(46966006)(54906003)(70586007)(316002)(70206006)(110136005)(6636002)(8676002)(8936002)(2616005)(4326008)(41300700001)(36756003)(40460700003)(1076003)(356005)(82740400003)(81166007)(478600001)(6666004)(15650500001)(40480700001)(83380400001)(2906002)(47076005)(7696005)(36860700001)(86362001)(426003)(336012)(5660300002)(16526019)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2023 02:14:31.2789 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a687b481-ba68-4022-bf3e-08dba447da3b 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: CY4PEPF0000EDD3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8972 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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. Signed-off-by: Meng Li Reviewed-by: Wyes Karny --- drivers/cpufreq/amd-pstate.c | 32 ++++++++++++++++++++++++++++++++ include/linux/amd-pstate.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index d02305675f66..8a8e4ecb1b5c 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -315,6 +315,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_highest_perf, AMD_CPPC_HIGHEST_PERF(cap1)); return 0; } @@ -336,6 +337,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_highest_perf, cppc_perf.highest_perf); if (cppc_state == AMD_PSTATE_ACTIVE) return 0; @@ -744,6 +746,34 @@ static void amd_pstate_init_prefcore(void) 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; + u64 highest_perf; + int ret; + + if (!prefcore) + return; + + ret = amd_pstate_get_highest_perf(cpu, &highest_perf); + if (ret) + return; + + policy = cpufreq_cpu_get(cpu); + cpudata = policy->driver_data; + cur_high = highest_perf; + prev_high = READ_ONCE(cpudata->prefcore_highest_perf); + + if (prev_high != cur_high) { + WRITE_ONCE(cpudata->prefcore_highest_perf, cur_high); + sched_set_itmt_core_prio(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; @@ -1468,6 +1498,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, }; @@ -1482,6 +1513,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 446394f84606..fa86bc953d3e 100644 --- a/include/linux/amd-pstate.h +++ b/include/linux/amd-pstate.h @@ -70,6 +70,7 @@ struct amd_cpudata { u32 nominal_perf; u32 lowest_nonlinear_perf; u32 lowest_perf; + u32 prefcore_highest_perf; u32 max_freq; u32 min_freq;