Re: [RFC PATCH] arm64: topology: Map PPTT node offset to logic physical package id

From: Yang, Shunyong
Date: Thu Jun 28 2018 - 11:47:39 EST


Hi, All

> On Jun 28, 2018, at 22:51, Andrew Jones <drjones@xxxxxxxxxx> wrote:
>
>> On Thu, Jun 28, 2018 at 03:09:19PM +0100, Sudeep Holla wrote:
>>
>>
>>> On 28/06/18 14:19, Jeremy Linton wrote:
>>> Hi,
>>>
>>> On 06/28/2018 07:12 AM, Sudeep Holla wrote:
>>
>> [...]
>>
>>>>
>>>> OK sure. I liked the approach in Shunyong's patch. I was thinking if we
>>>> can avoid the list and dynamic allocation on each addition and make it
>>>> more simpler.
>>>>
>>>
>>> This one reads simpler, but yes I agree we should try to avoid the
>>> dynamic allocation.
>>>
>>> OTOH, I think that dropping the dynamic allocation leads to an algorithm
>>> that picks a value and replaces all the matches. Which of course is
>>> Andrew's patch, although I did have to read it a couple times to get a
>>> grasp how it works. I'm guessing that is due to the fact that he seems
>>> to have optimized 3 double loops into a single loop with two individual
>>> nested loops. AKA its probably more efficient than the naive
>>> implementation, but readability seems to have suffered a bit in the
>>> initial version he posted. I'm not sure the optimization is worth it,
>>> but I'm guessing there is a middle ground which makes it more readable.
>>>
>>
>> Completely agree. RFC from Andrew is not so readable and easy to understand.
>
> Middle ground coming up. At the expense of a triple-nested loop (which
> will never be N^3 iterations due to conditions at the start of each loop),
> we can avoid dynamic allocations and list iterations and still gain
> readability.
>
> Thanks,
> drew

I have a new approach. As we've already got the offset of the node with physical package bit set, which is the parent of the cpu we are querying. We can iterate from the begining of PPTT to count the nodes with physical package bit set till we reach the offset we've got. Then, the count value is the package id. This avoid list and dynamic allocation. And PPTT provides length for each node, iteration should be easy.
I think this may implemented in pptt.c.
I am writing this mail on my phone. Maybe I should try to write a patch to test in office tomorrow if you think it's feasible.

Thanks.
Shunyong.