Re: [PATCH v3] of: cache phandle nodes to reduce cost of of_find_node_by_phandle()
From: Frank Rowand
Date: Wed Feb 28 2018 - 13:22:47 EST
On 02/28/18 05:27, Chintan Pandya wrote:
>
>
> On 2/15/2018 6:22 AM, frowand.list@xxxxxxxxx wrote:
>
>> +static void of_populate_phandle_cache(void)
>> +{
>> +ÂÂÂ unsigned long flags;
>> +ÂÂÂ u32 cache_entries;
>> +ÂÂÂ struct device_node *np;
>> +ÂÂÂ u32 phandles = 0;
>> +
>> +ÂÂÂ raw_spin_lock_irqsave(&devtree_lock, flags);
>> +
>> +ÂÂÂ kfree(phandle_cache);
>> +ÂÂÂ phandle_cache = NULL;
>> +
>> +ÂÂÂ for_each_of_allnodes(np)
>> +ÂÂÂÂÂÂÂ if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL)
>> +ÂÂÂÂÂÂÂÂÂÂÂ phandles++;
>> +
>> +ÂÂÂ cache_entries = roundup_pow_of_two(phandles);
>> +ÂÂÂ phandle_cache_mask = cache_entries - 1;
>> +
>> +ÂÂÂ phandle_cache = kcalloc(cache_entries, sizeof(*phandle_cache),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_ATOMIC);
>> +
>
> NULL check of phandle_cache would be good to have.
Thanks for catching that.
>> +ÂÂÂ for_each_of_allnodes(np)
>> +ÂÂÂÂÂÂÂ if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL)
>> +ÂÂÂÂÂÂÂÂÂÂÂ phandle_cache[np->phandle & phandle_cache_mask] = np;
>> +
>> +ÂÂÂ raw_spin_unlock_irqrestore(&devtree_lock, flags);
>> +}
>
>
> Chintan