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 07/11] platform/x86/: hfi: init per-cpu scores for each class
Date: Tue, 27 Aug 2024 13:32:53 +0300 (EEST) [thread overview]
Message-ID: <2c1a18c9-6ceb-e135-876f-f832f5696124@linux.intel.com> (raw)
In-Reply-To: <b913765989396d62f5184d32932250ee434cd0da.1724748733.git.perry.yuan@amd.com>
On Tue, 27 Aug 2024, Perry Yuan wrote:
> From: Perry Yuan <Perry.Yuan@amd.com>
>
> Initialize per cpu score `amd_hfi_ipcc_scores` which store energy score
> and performance score data for each class.
>
> `Classic core` and `Dense core` are ranked according to those values as
> energy efficiency capability or performance capability.
> OS scheduler will pick cores from the ranking list on each class ID for
> the thread which provide the class id got from hardware feedback
> interface.
>
> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com>
> ---
> drivers/platform/x86/amd/hfi/hfi.c | 65 ++++++++++++++++++++++++++++++
> 1 file changed, 65 insertions(+)
>
> diff --git a/drivers/platform/x86/amd/hfi/hfi.c b/drivers/platform/x86/amd/hfi/hfi.c
> index 50f6ca9c148a..cd5f2b708ebf 100644
> --- a/drivers/platform/x86/amd/hfi/hfi.c
> +++ b/drivers/platform/x86/amd/hfi/hfi.c
> @@ -111,6 +111,7 @@ struct amd_hfi_data {
> raw_spinlock_t table_lock;
> struct acpi_subtable_header *pcct_entry;
> struct amd_hfi_metadata *hfi_meta;
> + raw_spinlock_t hfi_data_lock;
> };
>
> /**
> @@ -130,6 +131,7 @@ struct amd_hfi_classes {
> * struct amd_hfi_cpuinfo - HFI workload class info per CPU
> * @cpu: cpu index
> * @cpus: cpu mask of cpus
> + * @apic_id: apic id of the current cpu
> * @class_index: workload class ID index
> * @nr_classa: max number of workload class supported
> * @amd_hfi_classes: current cpu workload class ranking data
> @@ -139,6 +141,7 @@ struct amd_hfi_classes {
> struct amd_hfi_cpuinfo {
> int cpu;
> cpumask_var_t cpus;
> + u32 apic_id;
> s16 class_index;
> u8 nr_class;
> struct amd_hfi_classes *amd_hfi_classes;
> @@ -146,6 +149,12 @@ struct amd_hfi_cpuinfo {
>
> static DEFINE_PER_CPU(struct amd_hfi_cpuinfo, amd_hfi_cpuinfo) = {.class_index = -1};
>
> +static DEFINE_MUTEX(hfi_cpuinfo_lock);
> +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);
Looks unnecessary forward declarations. In general, we try to arrange code
so that forward declarations are not required.
> +
> static int find_cpu_index_by_apicid(unsigned int target_apicid)
> {
> int cpu_index;
> @@ -293,6 +302,40 @@ static void amd_hfi_remove(struct platform_device *pdev)
>
> mutex_destroy(&dev->lock);
> }
> +
> +static int amd_set_hfi_ipcc_score(struct amd_hfi_cpuinfo *hfi_cpuinfo, int cpu)
> +{
> + int i, *hfi_scores;
> + u8 nr_classes = hfi_cpuinfo->nr_class;
Reverse xmas tree order.
> +
> + hfi_scores = per_cpu_ptr(amd_hfi_ipcc_scores, cpu);
> + if (!hfi_scores)
> + return -ENODEV;
> +
> + for (i = 0; i < nr_classes; i++)
Extra space.
> + WRITE_ONCE(hfi_scores[i], hfi_cpuinfo->amd_hfi_classes[i].perf);
> +
> + return 0;
> +}
> +
> +static int update_hfi_ipcc_scores(struct amd_hfi_data *amd_hfi_data)
> +{
> + int cpu;
> + int ret;
> +
> + raw_spin_lock_irq(&amd_hfi_data->hfi_data_lock);
Again, this is called from .probe so why you need a raw spinlock???
> + for_each_online_cpu(cpu) {
> + struct amd_hfi_cpuinfo *hfi_cpuinfo = per_cpu_ptr(&amd_hfi_cpuinfo, cpu);
> +
> + ret = amd_set_hfi_ipcc_score(hfi_cpuinfo, cpu);
> + if (ret)
> + return ret;
> + }
> + raw_spin_unlock_irq(&amd_hfi_data->hfi_data_lock);
> +
> + return 0;
> +}
> +
> static int amd_hfi_metadata_parser(struct platform_device *pdev,
> struct amd_hfi_data *amd_hfi_data)
> {
> @@ -344,6 +387,19 @@ static int amd_hfi_metadata_parser(struct platform_device *pdev,
> return ret;
> }
>
> +static int alloc_amd_hfi_ipcc_scores(struct amd_hfi_data *amd_hfi_data)
> +{
> + struct amd_hfi_metadata *hfi_meta = amd_hfi_data->hfi_meta;
> +
> + amd_hfi_ipcc_scores = __alloc_percpu(sizeof(*amd_hfi_ipcc_scores) *
> + hfi_meta->n_classes,
> + sizeof(*amd_hfi_ipcc_scores));
Align these continuation lines better.
--
i.
> + if (WARN_ON(!amd_hfi_ipcc_scores))
> + return -ENOMEM;
> +
> + return 0;
> +}
> +
> static const struct acpi_device_id amd_hfi_platform_match[] = {
> { "AMDI0104", 0},
> { }
> @@ -385,6 +441,7 @@ static int amd_hfi_probe(struct platform_device *pdev)
> amd_hfi_data->dhandle = dhandle;
>
> raw_spin_lock_init(&amd_hfi_data->table_lock);
> + raw_spin_lock_init(&amd_hfi_data->hfi_data_lock);
> mutex_init(&amd_hfi_data->lock);
>
> platform_set_drvdata(pdev, amd_hfi_data);
> @@ -402,6 +459,14 @@ static int amd_hfi_probe(struct platform_device *pdev)
>
> amd_hfi_data->hfi_meta->dynamic_rank_feature =
> cpuid_ebx(AMD_HETERO_CPUID_27) & 0xF;
> +
> + if (alloc_amd_hfi_ipcc_scores(amd_hfi_data))
> + goto err_exit;
> +
> + ret = update_hfi_ipcc_scores(amd_hfi_data);
> + if (ret)
> + goto err_exit;
> +
> dev_dbg(&pdev->dev, "%s driver registered.\n", pdev->name);
>
> return 0;
>
next prev parent reply other threads:[~2024-08-27 10:33 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 [this message]
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
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=2c1a18c9-6ceb-e135-876f-f832f5696124@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
all inboxes | Powered by JetHome®