From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Mario Limonciello <superm1@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
Mario Limonciello <mario.limonciello@amd.com>,
Perry Yuan <perry.yuan@amd.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<x86@kernel.org>, "H . Peter Anvin" <hpa@zytor.com>,
Jonathan Corbet <corbet@lwn.net>, Huang Rui <ray.huang@amd.com>,
"Gautham R . Shenoy" <gautham.shenoy@amd.com>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
"open list:AMD HETERO CORE HARDWARE FEEDBACK DRIVER"
<platform-driver-x86@vger.kernel.org>,
"open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<linux-kernel@vger.kernel.org>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
"open list:AMD PSTATE DRIVER" <linux-pm@vger.kernel.org>,
Perry Yuan <Perry.Yuan@amd.com>
Subject: Re: [PATCH v8 07/13] platform/x86: hfi: add online and offline callback support
Date: Wed, 19 Mar 2025 16:04:40 +0200 (EET) [thread overview]
Message-ID: <529e9c45-df4f-440e-3232-106cbec12faf@linux.intel.com> (raw)
In-Reply-To: <20250218190822.1039982-8-superm1@kernel.org>
On Tue, 18 Feb 2025, Mario Limonciello wrote:
> From: Perry Yuan <Perry.Yuan@amd.com>
>
> There are some firmware parameters that need to be configured
> when a CPU core is brought online or offline.
>
> when CPU is online, it will initialize the workload classification
> parameters to CPU firmware which will trigger the workload class ID
> updating function.
>
> Once the CPU is going to offline, it will need to disable the workload
> classification function and clear the history.
>
> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
> Co-developed-by: Mario Limonciello <mario.limonciello@amd.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v8:
> * Move cpus member to this patch
> * Add comment about online
> v7:
> * move mutex to this patch
> ---
> drivers/platform/x86/amd/hfi/hfi.c | 87 ++++++++++++++++++++++++++++++
> 1 file changed, 87 insertions(+)
>
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index e1550f4463275..90b57175ccd97 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -93,6 +93,7 @@ struct amd_hfi_classes {
> * struct amd_hfi_cpuinfo - HFI workload class info per CPU
> * @cpu: cpu index
> * @apic_id: apic id of the current cpu
> + * @cpus: mask of cpus associated with amd_hfi_cpuinfo
> * @class_index: workload class ID index
> * @nr_class: max number of workload class supported
> * @ipcc_scores: ipcc scores for each class
> @@ -103,6 +104,7 @@ struct amd_hfi_classes {
> struct amd_hfi_cpuinfo {
> int cpu;
> u32 apic_id;
> + cpumask_var_t cpus;
> s16 class_index;
> u8 nr_class;
> int *ipcc_scores;
> @@ -111,6 +113,8 @@ struct amd_hfi_cpuinfo {
>
> static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
>
> +static DEFINE_MUTEX(hfi_cpuinfo_lock);
Please mention what this protects.
> +
> static int find_cpu_index_by_apicid(unsigned int target_apicid)
> {
> int cpu_index;
> @@ -234,6 +238,80 @@ static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
> return 0;
> }
>
> +static int amd_hfi_set_state(unsigned int cpu, bool state)
> +{
> + int ret;
> +
> + ret = wrmsrl_on_cpu(cpu, AMD_WORKLOAD_CLASS_CONFIG, state);
I'd prefer bool -> u64 conversion be done explicitly, eg. ,with ?:
operator.
> + if (ret)
> + return ret;
> +
> + return wrmsrl_on_cpu(cpu, AMD_WORKLOAD_HRST, 0x1);
> +}
> +
> +/**
> + * amd_hfi_online() - Enable workload classification on @cpu
> + * @cpu: CPU in which the workload classification will be enabled
> + *
> + * Return: 0 on success, negative error code on failure
> + */
> +static int amd_hfi_online(unsigned int cpu)
> +{
> + struct amd_hfi_cpuinfo *hfi_info = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
> + struct amd_hfi_classes *hfi_classes;
> + int ret;
> +
> + if (WARN_ON_ONCE(!hfi_info))
> + return -EINVAL;
> +
> + /*
> + * Check if @cpu as an associated, initialized and ranking data must be filled
Please fold to 80 characters.
> + */
> + hfi_classes = hfi_info->amd_hfi_classes;
> + if (!hfi_classes)
> + return -EINVAL;
> +
> + guard(mutex)(&hfi_cpuinfo_lock);
> +
> + if (!zalloc_cpumask_var(&hfi_info->cpus, GFP_KERNEL))
> + return -ENOMEM;
> +
> + cpumask_set_cpu(cpu, hfi_info->cpus);
> +
> + ret = amd_hfi_set_state(cpu, true);
> + if (ret)
> + pr_err("WCT enable failed for CPU %d\n", cpu);
%u
> +
> + return ret;
> +}
> +
> +/**
> + * amd_hfi_offline() - Disable workload classification on @cpu
> + * @cpu: CPU in which the workload classification will be disabled
> + *
> + * Remove @cpu from those covered by its HFI instance.
> + *
> + * Return: 0 on success, negative error code on failure
> + */
> +static int amd_hfi_offline(unsigned int cpu)
> +{
> + struct amd_hfi_cpuinfo *hfi_info = &per_cpu(amd_hfi_cpuinfo, cpu);
> + int ret;
> +
> + if (WARN_ON_ONCE(!hfi_info))
> + return -EINVAL;
> +
> + guard(mutex)(&hfi_cpuinfo_lock);
> +
> + ret = amd_hfi_set_state(cpu, false);
> + if (ret)
> + pr_err("WCT disable failed for CPU %d\n", cpu);
%u
> +
> + free_cpumask_var(hfi_info->cpus);
> +
> + return ret;
> +}
> +
> static int update_hfi_ipcc_scores(void)
> {
> int cpu;
> @@ -339,6 +417,15 @@ static int amd_hfi_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + /*
> + * Tasks will already be running at the time this happens. This is
> + * OK because rankings will be adjusted by the callbacks.
> + */
> + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/amd_hfi:online",
> + amd_hfi_online, amd_hfi_offline);
> + if (ret < 0)
> + return ret;
> +
> return 0;
> }
>
>
--
i.
next prev parent reply other threads:[~2025-03-19 14:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-18 19:08 [PATCH v8 00/13] Add support for AMD hardware feedback interface Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 01/13] Documentation: x86: Add AMD Hardware Feedback Interface documentation Mario Limonciello
2025-03-19 14:01 ` Ilpo Järvinen
2025-03-20 16:41 ` Mario Limonciello
2025-03-21 13:58 ` Ilpo Järvinen
2025-03-21 14:41 ` Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 02/13] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 03/13] x86/msr-index: define AMD heterogeneous CPU related MSR Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 04/13] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Mario Limonciello
2025-03-19 14:03 ` Ilpo Järvinen
2025-03-20 16:46 ` Mario Limonciello
2025-03-21 14:01 ` Ilpo Järvinen
2025-02-18 19:08 ` [PATCH v8 05/13] platform/x86: hfi: parse CPU core ranking data from shared memory Mario Limonciello
2025-03-19 14:04 ` Ilpo Järvinen
2025-02-18 19:08 ` [PATCH v8 06/13] platform/x86: hfi: init per-cpu scores for each class Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 07/13] platform/x86: hfi: add online and offline callback support Mario Limonciello
2025-03-19 14:04 ` Ilpo Järvinen [this message]
2025-02-18 19:08 ` [PATCH v8 08/13] platform/x86: hfi: add power management callback Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 09/13] x86/process: Clear hardware feedback history for AMD processors Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 10/13] cpufreq/amd-pstate: Disable preferred cores on designs with workload classification Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 11/13] platform/x86/amd: hfi: Set ITMT priority from ranking data Mario Limonciello
2025-02-18 19:08 ` [PATCH v8 12/13] platform/x86/amd: hfi: Add debugfs support Mario Limonciello
2025-03-19 14:05 ` Ilpo Järvinen
2025-02-18 19:08 ` [PATCH v8 13/13] x86/itmt: Add debugfs file to show core priorities Mario Limonciello
2025-03-20 22:42 ` [PATCH v8 00/13] Add support for AMD hardware feedback interface Christian Loehle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=529e9c45-df4f-440e-3232-106cbec12faf@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=gautham.shenoy@amd.com \
--cc=hdegoede@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=mingo@redhat.com \
--cc=perry.yuan@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=superm1@kernel.org \
--cc=tglx@linutronix.de \
--cc=viresh.kumar@linaro.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).