[PATCH 3/3] powerpc/smp: Cache CPU to chip lookup
David Gibson
david at gibson.dropbear.id.au
Mon Apr 19 11:19:38 AEST 2021
On Fri, Apr 16, 2021 at 09:27:48PM +0530, Gautham R Shenoy wrote:
> On Thu, Apr 15, 2021 at 11:21:10PM +0530, Srikar Dronamraju wrote:
> > * Gautham R Shenoy <ego at linux.vnet.ibm.com> [2021-04-15 22:49:21]:
> >
> > > >
> > > > +int *chip_id_lookup_table;
> > > > +
> > > > #ifdef CONFIG_PPC64
> > > > int __initdata iommu_is_off;
> > > > int __initdata iommu_force_on;
> > > > @@ -914,13 +916,22 @@ EXPORT_SYMBOL(of_get_ibm_chip_id);
> > > > int cpu_to_chip_id(int cpu)
> > > > {
> > > > struct device_node *np;
> > > > + int ret = -1, idx;
> > > > +
> > > > + idx = cpu / threads_per_core;
> > > > + if (chip_id_lookup_table && chip_id_lookup_table[idx] != -1)
> > >
> >
> > > The value -1 is ambiguous since we won't be able to determine if
> > > it is because we haven't yet made a of_get_ibm_chip_id() call
> > > or if of_get_ibm_chip_id() call was made and it returned a -1.
> > >
> >
> > We don't allocate chip_id_lookup_table unless cpu_to_chip_id() return
> > !-1 value for the boot-cpuid. So this ensures that we dont
> > unnecessarily allocate chip_id_lookup_table. Also I check for
> > chip_id_lookup_table before calling cpu_to_chip_id() for other CPUs.
> > So this avoids overhead of calling cpu_to_chip_id() for platforms that
> > dont support it. Also its most likely that if the
> > chip_id_lookup_table is initialized then of_get_ibm_chip_id() call
> > would return a valid value.
> >
> > + Below we are only populating the lookup table, only when the
> > of_get_cpu_node is valid.
> >
> > So I dont see any drawbacks of initializing it to -1. Do you see
> any?
>
>
> Only if other callers of cpu_to_chip_id() don't check for whether the
> chip_id_lookup_table() has been allocated or not. From a code
> readability point of view, it is easier to have that check this inside
> cpu_to_chip_id() instead of requiring all its callers to make that
> check.
Even if they do, and the bad invalid value should never be read, I
think it's worth initializing that way. If means if there's a mistake
and we do accidentally read the value, then the error is likely to be
much clearer. Likewise if someone looks at this value from a
debugger, it will be clearer what's going on.
>
> >
> > > Thus, perhaps we can initialize chip_id_lookup_table[idx] with a
> > > different unique negative value. How about S32_MIN ? and check
> > > chip_id_lookup_table[idx] is different here ?
> > >
> >
> > I had initially initialized to -2, But then I thought we adding in
> > more confusion than necessary and it was not solving any issues.
> >
> >
>
--
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20210419/669b7dd9/attachment.sig>
More information about the Linuxppc-dev
mailing list