[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>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Wed, 20 Mar 2024 11:57:43 +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=kvdgdCX0JO2OJJqgjVsQE9DtjhL4RhkkK4YxD6xn6yE=; b=Dxp+XqcXyyQxrEx/z4dhb4oYxxZ34aL/PLFYp/E9X76jjyIk4LCWk5bztudsmXfJzWCSUy6iD0KxH7uCs5XlKqZuRLFPAqA7h01w1PAyj9V3KWHrEoU9PCMTDwJMZoB3sACWLVob33docdN0DVFhFxEztwSClA0bZj9CMikL4DXzoZzpfSAgk1zHyROM4MsxDqiN/2B4VCiJOlBXkLboLyb12Ul3V6Zg4uAuyxgH3XvdO2MotIGsW590mzLHacT+/zQL+tYd/8pLsPIuIjyl91+RFLGgjkQmRlKp7ymcLPCWmIErAV6flo4uiScNbAFo6Ap1z+IWOBrWi72DeYIhFA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LLm4BWRzboT0NS9wOsa8S2IepABmjDRzOHQOQNloiKzU+YT7eOmqW3eSPcbuSOE6vUeXkjdH2WeZU7MGop9ujpChmHM/IEm92Vkl1gyWOWTEVZQyrt4CmTfk2zsHbzGIlMGHywP6dCTksqkP77Rs1p5XEVgdtxMZVz8Kf7a/Zu2ZM0cF0vGn+FFy0pG4QSIW2CB9bGpbT/Uy8aSnmN4Vcccj35xGvl+ULtfolVK2LIm02GOtWvTbLyg5H3K0wxsSjCDNt2A5IIoYduDZkOtX+Jufu36+9fdztDvjhhLcNa1TcBvQYpDHSu9yOfbgPssbDBpf3TkUG5P2L4hSKAjDYg==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 20 Mar 2024 10:58:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

~Michal



 


Rackspace

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