From: David Gibson <david@gibson.dropbear.id.au>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Nathan Lynch <nathanl@linux.ibm.com>,
Daniel Henrique Barboza <danielhb413@gmail.com>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v7 6/6] powerpc/pseries: Consolidate form1 distance initialization into a helper
Date: Tue, 10 Aug 2021 12:44:42 +1000 [thread overview]
Message-ID: <YRHoGta/GPp1PF/x@yekko> (raw)
In-Reply-To: <20210809052434.53978-7-aneesh.kumar@linux.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 7676 bytes --]
On Mon, Aug 09, 2021 at 10:54:34AM +0530, Aneesh Kumar K.V wrote:
> Currently, we duplicate parsing code for ibm,associativity and
> ibm,associativity-lookup-arrays in the kernel. The associativity array provided
> by these device tree properties are very similar and hence can use
> a helper to parse the node id and numa distance details.
>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Though I'd prefer to see these fixes folded in with the earlier patch.
> ---
> arch/powerpc/mm/numa.c | 104 +++++++++++++++++++++++------------------
> 1 file changed, 58 insertions(+), 46 deletions(-)
>
> diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
> index fffb3c40f595..e6d47fcba335 100644
> --- a/arch/powerpc/mm/numa.c
> +++ b/arch/powerpc/mm/numa.c
> @@ -171,26 +171,36 @@ static void unmap_cpu_from_node(unsigned long cpu)
> }
> #endif /* CONFIG_HOTPLUG_CPU || CONFIG_PPC_SPLPAR */
>
> -/*
> - * Returns nid in the range [0..nr_node_ids], or -1 if no useful NUMA
> - * info is found.
> - */
> -static int associativity_to_nid(const __be32 *associativity)
> +static int __associativity_to_nid(const __be32 *associativity,
> + int max_array_sz)
> {
> - int nid = NUMA_NO_NODE;
> + int nid;
> + /*
> + * primary_domain_index is 1 based array index.
> + */
> + int index = primary_domain_index - 1;
>
> - if (!numa_enabled)
> - goto out;
> + if (!numa_enabled || index >= max_array_sz)
> + return NUMA_NO_NODE;
>
> - if (of_read_number(associativity, 1) >= primary_domain_index)
> - nid = of_read_number(&associativity[primary_domain_index], 1);
> + nid = of_read_number(&associativity[index], 1);
>
> /* POWER4 LPAR uses 0xffff as invalid node */
> if (nid == 0xffff || nid >= nr_node_ids)
> nid = NUMA_NO_NODE;
> -out:
> return nid;
> }
> +/*
> + * Returns nid in the range [0..nr_node_ids], or -1 if no useful NUMA
> + * info is found.
> + */
> +static int associativity_to_nid(const __be32 *associativity)
> +{
> + int array_sz = of_read_number(associativity, 1);
> +
> + /* Skip the first element in the associativity array */
> + return __associativity_to_nid((associativity + 1), array_sz);
> +}
>
> static int __cpu_form2_relative_distance(__be32 *cpu1_assoc, __be32 *cpu2_assoc)
> {
> @@ -295,33 +305,39 @@ int of_node_to_nid(struct device_node *device)
> }
> EXPORT_SYMBOL(of_node_to_nid);
>
> -static void __initialize_form1_numa_distance(const __be32 *associativity)
> +static void __initialize_form1_numa_distance(const __be32 *associativity,
> + int max_array_sz)
> {
> int i, nid;
>
> if (affinity_form != FORM1_AFFINITY)
> return;
>
> - nid = associativity_to_nid(associativity);
> + nid = __associativity_to_nid(associativity, max_array_sz);
> if (nid != NUMA_NO_NODE) {
> for (i = 0; i < distance_ref_points_depth; i++) {
> const __be32 *entry;
> + int index = be32_to_cpu(distance_ref_points[i]) - 1;
> +
> + /*
> + * broken hierarchy, return with broken distance table
> + */
> + if (WARN(index >= max_array_sz, "Broken ibm,associativity property"))
> + return;
>
> - entry = &associativity[be32_to_cpu(distance_ref_points[i])];
> + entry = &associativity[index];
> distance_lookup_table[nid][i] = of_read_number(entry, 1);
> }
> }
> }
>
> -static void initialize_form1_numa_distance(struct device_node *node)
> +static void initialize_form1_numa_distance(const __be32 *associativity)
> {
> - const __be32 *associativity;
> -
> - associativity = of_get_associativity(node);
> - if (!associativity)
> - return;
> + int array_sz;
>
> - __initialize_form1_numa_distance(associativity);
> + array_sz = of_read_number(associativity, 1);
> + /* Skip the first element in the associativity array */
> + __initialize_form1_numa_distance(associativity + 1, array_sz);
> }
>
> /*
> @@ -334,7 +350,13 @@ void update_numa_distance(struct device_node *node)
> if (affinity_form == FORM0_AFFINITY)
> return;
> else if (affinity_form == FORM1_AFFINITY) {
> - initialize_form1_numa_distance(node);
> + const __be32 *associativity;
> +
> + associativity = of_get_associativity(node);
> + if (!associativity)
> + return;
> +
> + initialize_form1_numa_distance(associativity);
> return;
> }
>
> @@ -586,27 +608,17 @@ static int get_nid_and_numa_distance(struct drmem_lmb *lmb)
>
> if (primary_domain_index <= aa.array_sz &&
> !(lmb->flags & DRCONF_MEM_AI_INVALID) && lmb->aa_index < aa.n_arrays) {
> - index = lmb->aa_index * aa.array_sz + primary_domain_index - 1;
> - nid = of_read_number(&aa.arrays[index], 1);
> + const __be32 *associativity;
>
> - if (nid == 0xffff || nid >= nr_node_ids)
> - nid = default_nid;
> + index = lmb->aa_index * aa.array_sz;
> + associativity = &aa.arrays[index];
> + nid = __associativity_to_nid(associativity, aa.array_sz);
> if (nid > 0 && affinity_form == FORM1_AFFINITY) {
> - int i;
> - const __be32 *associativity;
> -
> - index = lmb->aa_index * aa.array_sz;
> - associativity = &aa.arrays[index];
> /*
> - * lookup array associativity entries have different format
> - * There is no length of the array as the first element.
> + * lookup array associativity entries have
> + * no length of the array as the first element.
> */
> - for (i = 0; i < distance_ref_points_depth; i++) {
> - const __be32 *entry;
> -
> - entry = &associativity[be32_to_cpu(distance_ref_points[i]) - 1];
> - distance_lookup_table[nid][i] = of_read_number(entry, 1);
> - }
> + __initialize_form1_numa_distance(associativity, aa.array_sz);
> }
> }
> return nid;
> @@ -632,11 +644,11 @@ int of_drconf_to_nid_single(struct drmem_lmb *lmb)
>
> if (primary_domain_index <= aa.array_sz &&
> !(lmb->flags & DRCONF_MEM_AI_INVALID) && lmb->aa_index < aa.n_arrays) {
> - index = lmb->aa_index * aa.array_sz + primary_domain_index - 1;
> - nid = of_read_number(&aa.arrays[index], 1);
> + const __be32 *associativity;
>
> - if (nid == 0xffff || nid >= nr_node_ids)
> - nid = default_nid;
> + index = lmb->aa_index * aa.array_sz;
> + associativity = &aa.arrays[index];
> + nid = __associativity_to_nid(associativity, aa.array_sz);
> }
> return nid;
> }
> @@ -939,7 +951,7 @@ static int __init parse_numa_properties(void)
>
> if (__vphn_get_associativity(i, vphn_assoc) == 0) {
> nid = associativity_to_nid(vphn_assoc);
> - __initialize_form1_numa_distance(vphn_assoc);
> + initialize_form1_numa_distance(vphn_assoc);
> } else {
>
> /*
> @@ -953,7 +965,7 @@ static int __init parse_numa_properties(void)
> associativity = of_get_associativity(cpu);
> if (associativity) {
> nid = associativity_to_nid(associativity);
> - __initialize_form1_numa_distance(associativity);
> + initialize_form1_numa_distance(associativity);
> }
> of_node_put(cpu);
> }
> @@ -993,7 +1005,7 @@ static int __init parse_numa_properties(void)
> associativity = of_get_associativity(memory);
> if (associativity) {
> nid = associativity_to_nid(associativity);
> - __initialize_form1_numa_distance(associativity);
> + initialize_form1_numa_distance(associativity);
> } else
> nid = default_nid;
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-08-10 4:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 5:24 [PATCH v7 0/6] Add support for FORM2 associativity Aneesh Kumar K.V
2021-08-09 5:24 ` [PATCH v7 1/6] powerpc/pseries: rename min_common_depth to primary_domain_index Aneesh Kumar K.V
2021-08-09 5:24 ` [PATCH v7 2/6] powerpc/pseries: Rename TYPE1_AFFINITY to FORM1_AFFINITY Aneesh Kumar K.V
2021-08-09 5:24 ` [PATCH v7 3/6] powerpc/pseries: Consolidate different NUMA distance update code paths Aneesh Kumar K.V
2021-08-10 2:40 ` David Gibson
2021-08-09 5:24 ` [PATCH v7 4/6] powerpc/pseries: Add a helper for form1 cpu distance Aneesh Kumar K.V
2021-08-09 5:24 ` [PATCH v7 5/6] powerpc/pseries: Add support for FORM2 associativity Aneesh Kumar K.V
2021-08-10 3:02 ` David Gibson
2021-08-11 4:09 ` Aneesh Kumar K.V
2021-08-12 1:41 ` David Gibson
2021-08-12 3:36 ` Aneesh Kumar K.V
2021-08-09 5:24 ` [PATCH v7 6/6] powerpc/pseries: Consolidate form1 distance initialization into a helper Aneesh Kumar K.V
2021-08-10 2:44 ` David Gibson [this message]
2021-08-09 20:56 ` [PATCH v7 0/6] Add support for FORM2 associativity Daniel Henrique Barboza
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=YRHoGta/GPp1PF/x@yekko \
--to=david@gibson.dropbear.id.au \
--cc=aneesh.kumar@linux.ibm.com \
--cc=danielhb413@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=nathanl@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).