Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7195264rdb; Wed, 3 Jan 2024 07:38:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVrcjOas+vnQ6DjRYaFpRZ6jE/E4S5tIzelOEXOgP+109OGdgoG558FinA41KjXGLKchiv X-Received: by 2002:ad4:5749:0:b0:680:d1db:6c75 with SMTP id q9-20020ad45749000000b00680d1db6c75mr661035qvx.49.1704296280577; Wed, 03 Jan 2024 07:38:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704296280; cv=none; d=google.com; s=arc-20160816; b=xOb2TxuILuGQ25QOrLcSm7GpQu5+0KRRNOjN/zoQQUR/pCXKDxslea8jAEEGrtSQIB Ga0bq6Ef6Tji+wv/o8mF5qBclA5HbIP5TQPr7ucFLpDr0iTBd9muNjD4/HwSSli+5Q07 pvdwpRjP0rZfFD0xTplkHnLsh6Q8SdzU+k3m8iyOnsjnx+TP+ttCj1ITqWSY2eoPZBkD 9oJe35JkyCALYO07yDxfSTH7dPyNoHoxJGfs1OULcpavBXJYHnjt3kXgCg16QKmUIkxo 0OF2x1VGu5YaGz8E5cqA5Oe7/J4/EBCcGTsktQccV+e4SXk1BpipoRwmTdBHcKUDXCPc hUbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=40j+IqysrfYQAUt1SJO3JpRmqTkW8BeHGoeDA+iZloI=; fh=WELCJYDS7MOcRg8jHsGCXCqyhdalNsqD1wiXyEk1oh8=; b=Db/cNipTTSkAzMUfkVPSMXjwUiSw+OziP60CyAwoNVUDlaYCKP4rEmhtDm7VP5//Wb N+AeT89NYFX8/i/QNj/1Yjvhc7LQ4dwQbuVwn85+0bT/uXkAl8G0MbA1957WMkPXubHr oULE7PzxFY8ZRig83rtgRqxjxvze0/UceKgbGZeCqPAC2c7MpMSJxfs+lXtHPxU77wrq VMjDX2jxUSDJH+wQx+GRZFjuJ5ZrZfi1XQ1QlZ9ntAVh9shW9cM1sI4+Za5VbeHMC5s0 j14GnP5sf4XqIqQammAxQ0iOiqCNK+crIyKIHDJPYN3f9Sd4UFyDQmQyq1GdoIHcVQJN fF5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i23-20020a0cab57000000b0067f584b65besi28895984qvb.263.2024.01.03.07.38.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 07:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-15708-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15708-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 53C571C236D8 for ; Wed, 3 Jan 2024 15:38:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D3741B280; Wed, 3 Jan 2024 15:37:50 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21C371B267; Wed, 3 Jan 2024 15:37:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-595ffa2e6a2so164913eaf.0; Wed, 03 Jan 2024 07:37:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704296266; x=1704901066; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=40j+IqysrfYQAUt1SJO3JpRmqTkW8BeHGoeDA+iZloI=; b=OoMLNn83L1QCMLgwVxFhxrcH9l0Y3nKZ7K8xTz8Kj9CYYO78NoVsqngB4f7rGeouZ6 OGAdDK1nLxmHxJYmzFGH8dBMOR7DTvpha8xPV9p7fnMuaPPW2sIi2jZHNAD/fbP0wwdr uneEZLMnvJnfyocfMUgEx3tuZfN4TuVgp99P2nME/0qGO0Wj7RCNfxTdvcpye1ClXKda d3IwKVtMAW43hX6xrPHiB11hAkabITWwyrqHJuXHiyLkd4VrJcY8nIANOKpfcWDVcCwU bB0i7Tpw9pcRjXk1AVMy7iOTlJb1bTUGFOnGSXWVyHEiVcqrb3gbBd9B3tvqEivChZAh VuKg== X-Gm-Message-State: AOJu0YzOs+YGVoUqxhki/LDr8FVQ2uikLtVdgVkqa6OoeRETQUPkvGHB jMJUslxVIoM7cgbPIHx0xo08Yxp9zHSEEDWTJZk= X-Received: by 2002:a4a:b38c:0:b0:595:6024:c4f8 with SMTP id p12-20020a4ab38c000000b005956024c4f8mr8288888ooo.1.1704296266137; Wed, 03 Jan 2024 07:37:46 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231228075705.26652-1-TonyWWang-oc@zhaoxin.com> <20231228075705.26652-4-TonyWWang-oc@zhaoxin.com> In-Reply-To: <20231228075705.26652-4-TonyWWang-oc@zhaoxin.com> From: "Rafael J. Wysocki" Date: Wed, 3 Jan 2024 16:37:35 +0100 Message-ID: Subject: Re: [PATCH 3/3] ACPI: cpufreq: Add ITMT support when CPPC enabled for Zhaoxin CPUs To: Tony W Wang-oc Cc: rafael@kernel.org, lenb@kernel.org, robert.moore@intel.com, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, mcgrof@kernel.org, peterz@infradead.org, j.granados@samsung.com, ricardo.neri-calderon@linux.intel.com, viresh.kumar@linaro.org, linux-pm@vger.kernel.org, CobeChen@zhaoxin.com, TimGuo@zhaoxin.com, LeoLiu-oc@zhaoxin.com, LindaChai@zhaoxin.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Dec 28, 2023 at 8:57=E2=80=AFAM Tony W Wang-oc wrote: > > 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 specificall= y, > 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-cpufre= q.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 =3D 0, min_highest_perf =3D U64_MAX; > + int ret; > + > + ret =3D 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 <=3D min_highest_perf) { > + if (highest_perf > max_highest_perf) > + max_highest_perf =3D highest_perf; > + > + if (highest_perf < min_highest_perf) > + min_highest_perf =3D highest_perf; > + > + if (max_highest_perf > min_highest_perf) { > + /* > + * This code can be run during CPU online under t= he > + * CPU hotplug locks, so sched_set_itmt_support() > + * cannot be called from here. Queue up a work i= tem > + * to invoke it. > + */ > + cppc_highest_perf_diff =3D 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_polic= y *policy) > unsigned int valid_states =3D 0; > unsigned int result =3D 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_poli= cy *policy) > } > #endif > > + if (c->x86_vendor =3D=3D X86_VENDOR_CENTAUR || c->x86_vendor =3D= =3D X86_VENDOR_ZHAOXIN) { > + for_each_cpu(j, policy->cpus) { > + set_itmt_prio(j); > + } > + } > + > /* capability check */ > if (perf->state_count <=3D 1) { > pr_debug("No P-States\n"); > -- Have you considered using the CPPC cpufreq driver on those platforms?