From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Perry Yuan <perry.yuan@amd.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
Mario.Limonciello@amd.com, Borislav.Petkov@amd.com,
kprateek.nayak@amd.com, Alexander.Deucher@amd.com,
Xinmei.Huang@amd.com, bharathprabhu.perdoor@amd.com,
poonam.aggrwal@amd.com, Li.Meng@amd.com,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
Xiaojian.Du@amd.com
Subject: Re: [PATCH 08/11] platform/x86/: hfi: add online and offline callback support
Date: Tue, 27 Aug 2024 13:53:34 +0300 (EEST) [thread overview]
Message-ID: <0242c3fa-74b8-63d5-dc2d-ae2f2519a281@linux.intel.com> (raw)
In-Reply-To: <2661e74beceb9198d0baefe1f145080ef2b812cb.1724748733.git.perry.yuan@amd.com>
On Tue, 27 Aug 2024, Perry Yuan 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.
>
> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
> ---
> drivers/platform/x86/amd/hfi/hfi.c | 90 ++++++++++++++++++++++++++++++
> 1 file changed, 90 insertions(+)
>
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index cd5f2b708ebf..57b642c4c522 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -154,6 +154,7 @@ static int __percpu *amd_hfi_ipcc_scores;
>
> static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *info, int cpu);
> static int update_hfi_ipcc_scores(struct amd_hfi_data *amd_hfi_data);
> +static int amd_hfi_set_state(unsigned int cpu, bool state);
Unnecessary.
> static int find_cpu_index_by_apicid(unsigned int target_apicid)
> {
> @@ -318,6 +319,87 @@ 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);
> + 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
> + *
> + */
> +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))
Can this ever trigger??
> + return -EINVAL;
Definitely wrong error code to return since this has nothing to do with
user input being invalid.
> + if (!zalloc_cpumask_var(&hfi_info->cpus, GFP_KERNEL))
> + return -ENOMEM;
> +
> + mutex_lock(&hfi_cpuinfo_lock);
Use guard().
> + cpumask_set_cpu(cpu, hfi_info->cpus);
> +
> + /*
> + * Check if @cpu as an associated, initialized and ranking data must be filled
> + */
> + hfi_classes = hfi_info->amd_hfi_classes;
> + if (!hfi_classes)
> + goto unlock;
> +
> + /* Enable the workload classification interface */
> + ret = amd_hfi_set_state(cpu, true);
> + if (ret)
> + pr_err("wct enable failed for cpu %d\n", cpu);
Use %u for unsigned int.
> +
> + mutex_unlock(&hfi_cpuinfo_lock);
> + return 0;
> +
> +unlock:
> + free_cpumask_var(hfi_info->cpus);
> + mutex_unlock(&hfi_cpuinfo_lock);
> + 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.
> + *
> + */
> +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;
> +
> + mutex_lock(&hfi_cpuinfo_lock);
> +
> + /* Disable the workload classification interface */
> + ret = amd_hfi_set_state(cpu, false);
> + if (ret)
> + pr_err("wct disable failed for cpu %d\n", cpu);
%u
> +
> + mutex_unlock(&hfi_cpuinfo_lock);
> +
> + free_cpumask_var(hfi_info->cpus);
> +
> + return 0;
> +}
> +
> static int update_hfi_ipcc_scores(struct amd_hfi_data *amd_hfi_data)
> {
> int cpu;
> @@ -467,6 +549,14 @@ static int amd_hfi_probe(struct platform_device *pdev)
> if (ret)
> goto err_exit;
>
> + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/amd_hfi:online",
> + amd_hfi_online,
> + amd_hfi_offline);
> + if (ret < 0) {
> + pr_warn("failed to setup cpuhp state! (%d)\n", ret);
> + return ret;
> + }
> +
> dev_dbg(&pdev->dev, "%s driver registered.\n", pdev->name);
>
> return 0;
>
--
i.
next prev parent reply other threads:[~2024-08-27 10:53 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 9:36 [PATCH 00/11] Introduce New AMD Heterogeneous Core Driver Perry Yuan
2024-08-27 9:36 ` [PATCH 01/11] Documentation: x86: Add AMD Hardware Feedback Interface documentation Perry Yuan
2024-08-27 17:20 ` Mario Limonciello
2024-08-27 9:36 ` [PATCH 02/11] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver Perry Yuan
2024-08-27 17:21 ` Mario Limonciello
2024-08-27 9:36 ` [PATCH 03/11] x86/cpufeatures: add X86_FEATURE_WORKLOAD_CLASS feature bit Perry Yuan
2024-08-27 9:36 ` [PATCH 04/11] x86/msr-index: define AMD heterogeneous CPU related MSR Perry Yuan
2024-08-27 9:36 ` [PATCH 05/11] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Perry Yuan
2024-08-27 17:32 ` Mario Limonciello
2024-08-27 9:36 ` [PATCH 06/11] platform/x86/: hfi: parse CPU core ranking data from shared memory Perry Yuan
2024-08-27 10:19 ` Ilpo Järvinen
2024-08-27 9:36 ` [PATCH 07/11] platform/x86/: hfi: init per-cpu scores for each class Perry Yuan
2024-08-27 10:32 ` Ilpo Järvinen
2024-08-27 9:36 ` [PATCH 08/11] platform/x86/: hfi: add online and offline callback support Perry Yuan
2024-08-27 10:53 ` Ilpo Järvinen [this message]
2024-08-27 9:36 ` [PATCH 09/11] platform/x86/: hfi: add power management callback Perry Yuan
2024-08-27 17:23 ` Mario Limonciello
2024-08-27 9:36 ` [PATCH 10/11] x86/process: Clear hardware feedback history for AMD processors Perry Yuan
2024-08-27 9:36 ` [PATCH 11/11] x86/cpu: Enable SD_ASYM_PACKING for DIE Domain on AMD Processors Perry Yuan
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=0242c3fa-74b8-63d5-dc2d-ae2f2519a281@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Alexander.Deucher@amd.com \
--cc=Borislav.Petkov@amd.com \
--cc=Li.Meng@amd.com \
--cc=Mario.Limonciello@amd.com \
--cc=Xiaojian.Du@amd.com \
--cc=Xinmei.Huang@amd.com \
--cc=bharathprabhu.perdoor@amd.com \
--cc=hdegoede@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perry.yuan@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=poonam.aggrwal@amd.com \
/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