Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3807552rdb; Wed, 27 Dec 2023 23:58:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCTxQssfSKNthLtjq/cNnhjMH5kgqnwDqUVGajVaw5vrfqh+3MSngt/yntsOHOBqJQmdfo X-Received: by 2002:a05:6e02:18ce:b0:35f:e864:f95 with SMTP id s14-20020a056e0218ce00b0035fe8640f95mr8611154ilu.78.1703750306198; Wed, 27 Dec 2023 23:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703750306; cv=none; d=google.com; s=arc-20160816; b=wkOOkT9i1OknnfsmesXrIYVHqQ14bm6BmuxVZx//fhQFf3HEpVJp1cd2QXRqc1KNYq Obn7UYFgQnltRtLCxpjn3n1rOlqWYwyz4/2jGQMmAJpUr/tM5HGcVBekcaynKlvjwaFI XkuLFGhCc8VXZT2+DhxORLzoCKOUm3NzjkY6+73/NjEJsF+MjmIKZb84m2T7nT0zGqdd 2uELcDWMr/85dbv/1EVe92RRxAys+3Io5gc/ypFuxpYtN0V0rqr3y6CCwwVPJrPvJgm+ ghgqcUpG/1tl459CyqojcxcMejMdbP54DChV4GYAU0RHmQv1J/fbsT6Rf0SrfOYA8vXS OaZg== ARC-Message-Signature: i=1; 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; bh=dxyH3iV7a0eAtX8KRSRnbP5cDoG85jg2/sU4Jpd2JLs=; fh=aRZZFfYpFsbONXxr7ZI6QaRKfYRbAmgYyJx4zno9nrw=; b=mVDqJ83C3ZhnXhA6kjPc3tdb0UcOBhR6FD9dHmnU8aTZLa+PEjcYd1KATpYOaVdLik epNQ2L4DEryWqdw9Kcep2jHBFOSAH6OmwA1DMJCfUoL/qjM4yEkcdWV55ql298JPIkT5 5Qvhey7HdDeQz0jl8Ni8lMWd0kcqBaxpP+vdHars0Bm2q8O9vnk+2IsUJU2HEq7m/a8h rLxRRb5iNojXsGO7vFiMcPOuly9rHuMxxO4DdM3AOmqP5o6icPnZ+S1jtCFHVINGGQlP z78soeJgaYP3dbXgokR3eHO5xyg4o0rNB/MeepDrdYjmf7GKC0D3IFuWS+PGR4rJxBzv RZyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12502-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12502-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m14-20020a6562ce000000b005b8f61fcba6si12116401pgv.452.2023.12.27.23.58.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 23:58:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12502-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12502-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12502-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D1828283B8B for ; Thu, 28 Dec 2023 07:58:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9DEE7466; Thu, 28 Dec 2023 07:57:30 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mx1.zhaoxin.com (MX1.ZHAOXIN.COM [210.0.225.12]) (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 924E76FC7 for ; Thu, 28 Dec 2023 07:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1703750236-086e230f2709020001-xx1T2L Received: from ZXSHMBX1.zhaoxin.com (ZXSHMBX1.zhaoxin.com [10.28.252.163]) by mx1.zhaoxin.com with ESMTP id sBOAnftlcQh0sFp9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 28 Dec 2023 15:57:16 +0800 (CST) X-Barracuda-Envelope-From: TonyWWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 28 Dec 2023 15:57:16 +0800 Received: from tony.zhaoxin.com (10.32.65.162) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 28 Dec 2023 15:57:13 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 From: Tony W Wang-oc X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: , , , , , , , , , , , , , , , , , , CC: , , , Subject: [PATCH 3/3] ACPI: cpufreq: Add ITMT support when CPPC enabled for Zhaoxin CPUs Date: Thu, 28 Dec 2023 15:57:05 +0800 X-ASG-Orig-Subj: [PATCH 3/3] ACPI: cpufreq: Add ITMT support when CPPC enabled for Zhaoxin CPUs Message-ID: <20231228075705.26652-4-TonyWWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231228075705.26652-1-TonyWWang-oc@zhaoxin.com> References: <20231228075705.26652-1-TonyWWang-oc@zhaoxin.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 Content-Type: text/plain X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX1.zhaoxin.com[10.28.252.163] X-Barracuda-Start-Time: 1703750236 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.35:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 3579 X-Barracuda-BRTS-Status: 0 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.118664 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- For Zhaoxin CPUs, the cores' highest frequencies may be different, which means that cores may run at different max frequencies, According to ACPI-spec6 chapter 8.4.7, the per-core highest frequency value can be obtained via cppc. The core with the higher frequency have better performance, which can be called as preferred core. And better performance can be achieved by making the scheduler to run tasks on these preferred cores. The cpufreq driver can use the highest frequency value as the prioriy of core to make the scheduler try to get better performace. More specifically, in the acpi-cpufreq driver use cppc_get_highest_perf() to get highest frequency value of each core, use sched_set_itmt_core_prio() to set highest frequency value as core priority, and use sched_set_itmt_support() provided by ITMT to tell the scheduler to favor on the preferred cores. Signed-off-by: Tony W Wang-oc --- drivers/cpufreq/acpi-cpufreq.c | 56 +++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index 37f1cdf46d29..f4c1ff9e4bb0 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -663,8 +663,56 @@ static u64 get_max_boost_ratio(unsigned int cpu) return div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf); } + +/* The work item is needed to avoid CPU hotplug locking issues */ +static void sched_itmt_work_fn(struct work_struct *work) +{ + sched_set_itmt_support(); +} + +static DECLARE_WORK(sched_itmt_work, sched_itmt_work_fn); + +static void set_itmt_prio(int cpu) +{ + static bool cppc_highest_perf_diff; + static struct cpumask core_prior_mask; + u64 highest_perf; + static u64 max_highest_perf = 0, min_highest_perf = U64_MAX; + int ret; + + ret = cppc_get_highest_perf(cpu, &highest_perf); + if (ret) + return; + + sched_set_itmt_core_prio(highest_perf, cpu); + cpumask_set_cpu(cpu, &core_prior_mask); + + if (max_highest_perf <= min_highest_perf) { + if (highest_perf > max_highest_perf) + max_highest_perf = highest_perf; + + if (highest_perf < min_highest_perf) + min_highest_perf = highest_perf; + + if (max_highest_perf > min_highest_perf) { + /* + * This code can be run during CPU online under the + * CPU hotplug locks, so sched_set_itmt_support() + * cannot be called from here. Queue up a work item + * to invoke it. + */ + cppc_highest_perf_diff = true; + } + } + + if (cppc_highest_perf_diff && cpumask_equal(&core_prior_mask, cpu_online_mask)) { + pr_debug("queue a work to set itmt enabled\n"); + schedule_work(&sched_itmt_work); + } +} #else static inline u64 get_max_boost_ratio(unsigned int cpu) { return 0; } +static void set_itmt_prio(int cpu) { } #endif static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) @@ -677,7 +725,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) unsigned int valid_states = 0; unsigned int result = 0; u64 max_boost_ratio; - unsigned int i; + unsigned int i, j; #ifdef CONFIG_SMP static int blacklisted; #endif @@ -742,6 +790,12 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) } #endif + if (c->x86_vendor == X86_VENDOR_CENTAUR || c->x86_vendor == X86_VENDOR_ZHAOXIN) { + for_each_cpu(j, policy->cpus) { + set_itmt_prio(j); + } + } + /* capability check */ if (perf->state_count <= 1) { pr_debug("No P-States\n"); -- 2.25.1