[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 06/11] xen/arm: Avoid code duplication in find_unallocated_memory


  • To: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Thu, 21 Mar 2024 10:02:30 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aYrAFQWW78PjnbM8VlrzHlBGUVcsNSReRu4Aft2X2aY=; b=iFyXPAai/6ZVWlfuAxtNgSh36x21KtMMFE3YHVBXKS7OVNO9papMazfr9tV+LuFBiysIN1tNAnP3U69nZi1K9HEBmNq5z+CT4Liz/hS2NxvuBZj+nBSbB9xo9v8P+if0lPM6VrX2OT5+HbzQ/Dd6i0CNVX5DhNzw+syu6dBKkDRSmIgmNdHDOM3qtG1bp12R6Vw6IQAWlHGx3uSAKhMsr4r8aiAPTMHHbLytWSH2wWg5JxOQMcR3gOGoTsFQK7EyyqeYeizNHPbtCoWYNYGXo6qpogHHL2877Gw/YHccR45SRFMcurXPTlL4n7nVMQdIrjxJWzwzjquHLvGbaWkrcA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D96gxX9HCXLRXxAh4xnlSEY8JcIdwzmHbl4QITlWHM1jTdwFkHFBweFvt+cqKyWEYa9bOiBgcwxvt1we115KlKL39Agoe/j4NCNJ46DnnLJokDEPAn4Qg22ZnWd8wBLibd/NIV71QjYPa6Vl9fisRw9/w3pl/1nsmTPWXbC/nF77zOFKkbW2Hxreu4cR0GpjxyLYrqe1AnyNeIBTpk1mqAe9kYADQKHMsftafCmHKUJFeldmz2bvjVTpvhUN/JCicQKCm64yWBfjRlIrx/9aX6favxvR7c+2vxOMd7wfil2bnvkCZ+XoXx2bFvE8Dihn1FA3G7azrbb4Q4Ly5gU7fw==
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 21 Mar 2024 09:02:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Luca,

On 20/03/2024 15:53, Luca Fancellu wrote:
> 
> 
>> On 20 Mar 2024, at 10:57, Michal Orzel <michal.orzel@xxxxxxx> wrote:
>>
>> Hi Luca,
>>
>> On 12/03/2024 14:03, Luca Fancellu wrote:
>>>
>>>
>>> The function find_unallocated_memory is using the same code to
>>> loop through 3 structure of the same type, in order to avoid
>>> code duplication, rework the code to have only one loop that
>>> goes through all the structures.
>>>
>>> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
>>> ---
>>> xen/arch/arm/domain_build.c | 62 ++++++++++---------------------------
>>> 1 file changed, 17 insertions(+), 45 deletions(-)
>>>
>>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>>> index b254f252e7cb..d0f2ac6060eb 100644
>>> --- a/xen/arch/arm/domain_build.c
>>> +++ b/xen/arch/arm/domain_build.c
>>> @@ -869,12 +869,14 @@ static int __init add_ext_regions(unsigned long 
>>> s_gfn, unsigned long e_gfn,
>>> static int __init find_unallocated_memory(const struct kernel_info *kinfo,
>>>                                           struct membanks *ext_regions)
>>> {
>>> -    const struct membanks *kinfo_mem = kernel_info_get_mem(kinfo);
>>> -    const struct membanks *mem = bootinfo_get_mem();
>>> -    const struct membanks *reserved_mem = bootinfo_get_reserved_mem();
>>> +    const struct membanks *mem_banks[] = {
>>> +        bootinfo_get_mem(),
>>> +        kernel_info_get_mem(kinfo),
>>> +        bootinfo_get_reserved_mem(),
>>> +    };
>>>     struct rangeset *unalloc_mem;
>>>     paddr_t start, end;
>>> -    unsigned int i;
>>> +    unsigned int i, j;
>>>     int res;
>>>
>>>     dt_dprintk("Find unallocated memory for extended regions\n");
>>> @@ -883,50 +885,20 @@ static int __init find_unallocated_memory(const 
>>> struct kernel_info *kinfo,
>>>     if ( !unalloc_mem )
>>>         return -ENOMEM;
>>>
>>> -    /* Start with all available RAM */
>>> -    for ( i = 0; i < mem->nr_banks; i++ )
>>> -    {
>>> -        start = mem->bank[i].start;
>>> -        end = mem->bank[i].start + mem->bank[i].size;
>>> -        res = rangeset_add_range(unalloc_mem, PFN_DOWN(start),
>>> -                                 PFN_DOWN(end - 1));
>>> -        if ( res )
>>> -        {
>>> -            printk(XENLOG_ERR "Failed to add: 
>>> %#"PRIpaddr"->%#"PRIpaddr"\n",
>>> -                   start, end);
>>> -            goto out;
>>> -        }
>>> -    }
>>> -
>>> -    /* Remove RAM assigned to Dom0 */
>>> -    for ( i = 0; i < kinfo_mem->nr_banks; i++ )
>>> -    {
>>> -        start = kinfo_mem->bank[i].start;
>>> -        end = kinfo_mem->bank[i].start + kinfo_mem->bank[i].size;
>>> -        res = rangeset_remove_range(unalloc_mem, PFN_DOWN(start),
>>> -                                    PFN_DOWN(end - 1));
>>> -        if ( res )
>>> +    for ( i = 0; i < ARRAY_SIZE(mem_banks); i++ )
>>> +        for ( j = 0; j < mem_banks[i]->nr_banks; j++ )
>> It might be a matter of personal opinion, but I would actually prefer the 
>> current code
>> that looks simpler/neater (the steps are clear) to me. I'd like to know 
>> other maintainers opinion.
> 
> Ok, I’ll wait the other maintainers then, I’m going to use this construct in 
> other part
> of the code to simplify and remove duplication so it would be important to 
> know if
> It’s desirable or not.
> 
> Maybe your opinion could change with a proper comment on top of the structure 
> and the loop,
> listing the operation performed in order?
> 
> 1) Start with all available RAM
> 2) Remove RAM assigned to Dom0
> 3) Remove reserved mem
> <later>
> 4) Remove static shared memory regions
Yes, that would help with the overall readability.

~Michal



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.