linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Mario Limonciello <mario.limonciello@amd.com>
Cc: Borislav Petkov <bp@alien8.de>,
	Hans de Goede <hdegoede@redhat.com>,
	 x86@kernel.org, "Gautham R . Shenoy" <gautham.shenoy@amd.com>,
	 Perry Yuan <perry.yuan@amd.com>,
	LKML <linux-kernel@vger.kernel.org>,
	 linux-doc@vger.kernel.org, linux-pm@vger.kernel.org,
	 platform-driver-x86@vger.kernel.org,
	 Shyam Sundar S K <Shyam-sundar.S-k@amd.com>,
	 Perry Yuan <Perry.Yuan@amd.com>
Subject: Re: [PATCH v2 08/13] platform/x86: hfi: add online and offline callback support
Date: Mon, 14 Oct 2024 13:27:51 +0300 (EEST)	[thread overview]
Message-ID: <55ddb80c-abfa-f3e2-442a-65f270dadbf2@linux.intel.com> (raw)
In-Reply-To: <20241010193705.10362-9-mario.limonciello@amd.com>

On Thu, 10 Oct 2024, 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.
> 
> 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>
> ---
> v2:
>  * Rebase
> ---
>  drivers/platform/x86/amd/hfi/hfi.c | 90 +++++++++++++++++++++++++++++-
>  1 file changed, 89 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index c0065ba0ed18..c969ee7ea5ee 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -244,6 +244,89 @@ 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
> + *
> + * 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;
> +
> +	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);

CPU

Should wct too be capitalized?

Is it okay to return 0 when this error occurs?

> +
> +	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.
> + *
> + * 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;
> +
> +	mutex_lock(&hfi_cpuinfo_lock);

guard or scoped_guard.

> +
> +	/* Disable the workload classification interface */
> +	ret = amd_hfi_set_state(cpu, false);
> +	if (ret)
> +		pr_err("wct disable failed for cpu %d\n", cpu);
> +
> +	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;
> @@ -362,8 +445,13 @@ static int amd_hfi_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto out;
>  
> +	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/amd_hfi:online",
> +				amd_hfi_online, amd_hfi_offline);
> +	if (ret < 0)
> +		goto out;

return ret;

> +
>  out:
> -	return ret;
> +	return ret < 0 ? ret : 0;
>  }
>  
>  static struct platform_driver amd_hfi_driver = {
> 

-- 
 i.


  reply	other threads:[~2024-10-14 10:27 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 19:36 [PATCH v2 00/13] Add support for AMD hardware feedback interface Mario Limonciello
2024-10-10 19:36 ` [PATCH v2 01/13] Documentation: x86: Add AMD Hardware Feedback Interface documentation Mario Limonciello
2024-10-12  3:53   ` Bagas Sanjaya
2024-10-10 19:36 ` [PATCH v2 02/13] MAINTAINERS: Add maintainer entry for AMD Hardware Feedback Driver Mario Limonciello
2024-10-10 19:36 ` [PATCH v2 03/13] x86/cpufeatures: add X86_FEATURE_WORKLOAD_CLASS feature bit Mario Limonciello
2024-10-10 19:36 ` [PATCH v2 04/13] x86/msr-index: define AMD heterogeneous CPU related MSR Mario Limonciello
2024-10-10 19:36 ` [PATCH v2 05/13] platform/x86: hfi: Introduce AMD Hardware Feedback Interface Driver Mario Limonciello
2024-10-14  9:10   ` Ilpo Järvinen
2024-10-14 19:46     ` Mario Limonciello
2024-10-14  9:20   ` Ilpo Järvinen
2024-10-15  3:52   ` Ricardo Neri
2024-10-15 18:09     ` Mario Limonciello
2024-10-17 23:33       ` Ricardo Neri
2024-10-18 13:46         ` Mario Limonciello
2024-10-16  9:36   ` Uwe Kleine-König
2024-10-16  9:59     ` Hans de Goede
2024-10-16 16:06       ` Mario Limonciello
2024-10-10 19:36 ` [PATCH v2 06/13] platform/x86: hfi: parse CPU core ranking data from shared memory Mario Limonciello
2024-10-14 10:14   ` Ilpo Järvinen
2024-10-14 20:09     ` Mario Limonciello
2024-10-10 19:36 ` [PATCH v2 07/13] platform/x86: hfi: init per-cpu scores for each class Mario Limonciello
2024-10-14 10:15   ` Ilpo Järvinen
2024-10-10 19:37 ` [PATCH v2 08/13] platform/x86: hfi: add online and offline callback support Mario Limonciello
2024-10-14 10:27   ` Ilpo Järvinen [this message]
2024-10-10 19:37 ` [PATCH v2 09/13] platform/x86: hfi: add power management callback Mario Limonciello
2024-10-14 10:29   ` Ilpo Järvinen
2024-10-10 19:37 ` [PATCH v2 10/13] x86/cpu: Enable SD_ASYM_PACKING for DIE Domain on AMD Processors Mario Limonciello
2024-10-10 19:37 ` [PATCH v2 11/13] x86/process: Clear hardware feedback history for AMD processors Mario Limonciello
2024-10-10 19:37 ` [PATCH v2 12/13] cpufreq/amd-pstate: Disable preferred cores on designs with workload classification Mario Limonciello
2024-10-10 19:37 ` [PATCH v2 13/13] platform/x86/amd: hfi: Set ITMT priority from ranking data Mario Limonciello
2024-10-11  0:54 ` [PATCH v2 00/13] Add support for AMD hardware feedback interface Bagas Sanjaya
2024-10-11  1:29   ` Mario Limonciello
2024-10-12  2:21     ` Bagas Sanjaya

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=55ddb80c-abfa-f3e2-442a-65f270dadbf2@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=bp@alien8.de \
    --cc=gautham.shenoy@amd.com \
    --cc=hdegoede@redhat.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=perry.yuan@amd.com \
    --cc=platform-driver-x86@vger.kernel.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).