[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: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Wed, 20 Mar 2024 14:53:52 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=hCrHcLBUoBzKyfc/QzlK3Dv+hNOybDPb78n0FUH4GQ8=; b=IqoJZWiTIhv9z9iOCIroJ0IIj2aRlct0+SfjCvrENolGsDx0ASR97+tve5KtYNGccbOEO/RujxNHX/TDrwMShi0DhI/HuIcJlX0GxXUt8FB4cN1EuyLx3XtRPunCcbfMziWXGoUDzshh3RsP24sq3NlSBGcrsJWkVQmcQJPBLRUqE0YAqVJIfO8rjxsyHz1ZJpP0CowTAkpEHvTEUHzh0OMDbOPYZ6MGGHrwNu8H452XXbh2vn3u6c6JRsaD2EtfhexrPEgEaq1uZhW7kB7qXY7AqNUg0apxqevwQI//Tpd9md99y9QOnLtoYLo3sq9/Lo6todXFa1qp5cgVzZYk7w==
  • 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=hCrHcLBUoBzKyfc/QzlK3Dv+hNOybDPb78n0FUH4GQ8=; b=KLdtc+VjU8qryW2bhqsv8Nq4PvkabqjP7nQEkYbSf/O+iPwV+ehox0s23vdy4ky34YIqoieDSNZBHdFhpfk1UOQMdGhivNYjns2EcXz3uKfyP2VjrLnU7fk9QSKUryRtZSrUtXmkrYbTih/oZx7CEKZpAqrMUPEOsubZYIf5ofwuBkrA76D/S0Gf6JHSMkJt4hHcXwFOqyAkMy6LtuKQ9vH0qLcrieG6obN0deCUeQfTllTZXMXZEf3/z3x6m9kLy06xRDdK1MSXAG5vFsdHFTSbk/1yLp8fMcLEiVV/CzDmLqJ/2LvBN23O5gXv75xIk3celFW+/pXJXhFCgi9w3g==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Glh/jMTCwEsf9H8bvSa+7EISz4zxzUIIFuXNf82WaTjrVOupZdRgnoT1N0b5gw/C6JG4VYl/ZaVWAhjOKaRfe70axPYV5DU80TyzCGxrDgVDCGtcTYt1oyTwEjCb9XT1Qty+HhHKyqZRilVC0nunGl3az6YIapFzgNsil93qfezFMAYeJef8GkVYN3VwheHgH6Zn+8oBMM+/74QYBOv1f2WT16oOmf+huZKGehu/uK989ORHt1KYzvwAv2bYewr3GO57V9LnAP/5uMBP+KoZA7/nt4eZ0toxv1RtXQjI7HFhcCm+YnBw2TqE7fagacu2whtDpk0u8aTLVVg3M/tZ8A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iYgCk/sHmlQQC0Nn4XmWDFSO7NIwZB3zH/jltDSBskBCVrxuoW0RhzbrtubpLgdIMUSmSLp3fu8DkmWZJl2x1Xj/iPtzgCMEaasTlttM8F8nXRcId9xjy0tT4t6uJ03IjB1DswqoWBIXbLNAE8lArowoPzd7wMvB1zfo4jVlD5px3kUlghd7maPus6QEevJopE7y1rEw5L9/tMP+l41KIeId43rV7ohXcocgSroEEEQ+v1t1ayYFBn4cQKXb0HNKfA4Gx1QViIyaXKppbHKOG/KXVVP5o3UjCvte1yzHOr4KiTiz6EyosYM1jBrSmvUaRVPNzdQHNuI/Xa12EjCfbQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • 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: Wed, 20 Mar 2024 14:54:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHadH3Zl0JABPg3OE+1Nn9HTjmokLFAgeKAgABB7YA=
  • Thread-topic: [PATCH 06/11] xen/arm: Avoid code duplication in find_unallocated_memory


> 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

Cheers,
Luca


> 
> ~Michal


 


Rackspace

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