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 X-Patchwork-Id: 159497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2017458vqb; Sun, 29 Oct 2023 23:36:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGl8WomZb4KNXKkoT1GQJKzNemoOSjI5CgA03JYorsGEmS1VEiXd3LY7LApRbhPYRniTgxy X-Received: by 2002:a17:903:5c4:b0:1cc:51d6:fafe with SMTP id kf4-20020a17090305c400b001cc51d6fafemr666724plb.5.1698647769349; Sun, 29 Oct 2023 23:36:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698647769; cv=pass; d=google.com; s=arc-20160816; b=kRecCZoApGtRroI4h0YlxI23EJJVccu+pKc/5AE2hA3jrWHLefCX8yCyszLvjzMTbi Jx+BdN8mhyuPFFJLX5zaqExvR21wuSWQfwDgGBURE4CsNJft+3cLqVH0Ydnx2l7B2MX7 6eMgi09sVTLo08vlePSofcqreAzx/U0SPZxlu+7t+zW7fUFSvGVSJ0Bs0yOToGybqTaw H8r0MEFhb7zCQC7XWiYWf4npfC6HKtTz5rdClk0mPJ7VJ7zCEPaMTO0rKiS3D6VVlXgA yqLvDTA8yV11gzSJ/hoTbiVxjbKQiLogGnPX9RfYx/iIo1sCg7iJ+PU/S7wGnsmO5gtu C0rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=q5HrsKpt0YVryXU4IZ+7QmZbfZmeatUSthRHzkrESZA=; fh=px4bRiBuq3I9SXanjlkRNLIg6oMFdG8uo3HGDz2F7II=; b=EOmnn41CzSxXWGxqPfadYqkZNd1x1Afbj8R3dbR0at8Xj9xvGnTp+ZQQCoRHkaEoVJ Cj+R84yxOQ9PEn9z7+Xm7wuLSqPaSqEZtEw44dLieoBrb5QmuoBS7QxDTY3tsQxL+ZIy 2OHu/QxAGz56woiJCARieCr9W9saKvHUnbm4CRnxPLpscajbfiFlyLQzM49OVqFbFd9j a3MlHK4RZaThfRvlPfz+EVTfem/wKyP9upUXkukEiRoQamKWK98OVYNqQMEDToUT67Id vi+LilLOXjEv3/EZZz7hKJskxekU+hGEkLTYIjkTEVdeWxk2cZSab9QfjfZ9uT4gHsYO fSUQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=fC8H9XvG; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n18-20020a170903111200b001c9fb2acff5si4728043plh.526.2023.10.29.23.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 23:36:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=fC8H9XvG; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 434B88038F37; Sun, 29 Oct 2023 23:36:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231615AbjJ3Gf4 (ORCPT + 32 others); Mon, 30 Oct 2023 02:35:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbjJ3Gft (ORCPT ); Mon, 30 Oct 2023 02:35:49 -0400 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> 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 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 29 Oct 2023 23:36:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781161283347776143 X-GMAIL-MSGID: 1781161283347776143 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;