Re: [PATCHv7 2/4] powerpc/setup: Loosen the mapping between cpu logical id and its seq in dt

2023-09-29 Thread Christophe Leroy


Le 28/09/2023 à 22:36, Wen Xiong a écrit :
> Hi Pingfan,
> 
> +   avail = intserv_node->avail;
> +   nthreads = intserv_node->len / sizeof(int);
> +   for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) {
>  set_cpu_present(cpu, avail);
>  set_cpu_possible(cpu, true);
> -   cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]);
> +   cpu_to_phys_id[cpu] = 
> be32_to_cpu(intserv_node->intserv[j]);
> +   DBG("thread %d -> cpu %d (hard id %d)\n",
> +   j, cpu, be32_to_cpu(intserv[j]));
> 
> Intserv is not defined. Should "be32_to_cpu(intserv_node->intserv[j])?
>  cpu++;
>  }
> +   }

Please don't top-post , see 
https://docs.kernel.org/process/submitting-patches.html#use-trimmed-interleaved-replies-in-email-discussions

Make comments inside the patch directly, making sure that your mail 
client is properly configured to add the standard > in front of all 
lines of the quoted mail.

Christophe

> 
> -Original Message-
> From: Pingfan Liu 
> Sent: Monday, September 25, 2023 2:54 AM
> To: linuxppc-...@lists.ozlabs.org
> Cc: Pingfan Liu ; Michael Ellerman ; 
> Nicholas Piggin ; Christophe Leroy 
> ; Mahesh Salgaonkar ; Wen 
> Xiong ; Baoquan He ; Ming Lei 
> ; kexec@lists.infradead.org
> Subject: [EXTERNAL] [PATCHv7 2/4] powerpc/setup: Loosen the mapping between 
> cpu logical id and its seq in dt
> 
> *** Idea ***
> For kexec -p, the boot cpu can be not the cpu0, this causes the problem of 
> allocating memory for paca_ptrs[]. However, in theory, there is no 
> requirement to assign cpu's logical id as its present sequence in the device 
> tree. But there is something like cpu_first_thread_sibling(), which makes 
> assumption on the mapping inside a core. Hence partially loosening the 
> mapping, i.e. unbind the mapping of core while keep the mapping inside a core.
> 
> *** Implement ***
> At this early stage, there are plenty of memory to utilize. Hence, this patch 
> allocates interim memory to link the cpu info on a list, then reorder cpus by 
> changing the list head. As a result, there is a rotate shift between the 
> sequence number in dt and the cpu logical number.
> 
> *** Result ***
> After this patch, a boot-cpu's logical id will always be mapped into the 
> range [0,threads_per_core).
> 
> Besides this, at this phase, all threads in the boot core are forced to be 
> onlined. This restriction will be lifted in a later patch with extra effort.
> 
> Signed-off-by: Pingfan Liu 
> Cc: Michael Ellerman 
> Cc: Nicholas Piggin 
> Cc: Christophe Leroy 
> Cc: Mahesh Salgaonkar 
> Cc: Wen Xiong 
> Cc: Baoquan He 
> Cc: Ming Lei 
> Cc: kexec@lists.infradead.org
> To: linuxppc-...@lists.ozlabs.org
> ---
>   arch/powerpc/kernel/prom.c | 25 +
>   arch/powerpc/kernel/setup-common.c | 87 +++---
>   2 files changed, 85 insertions(+), 27 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 
> ec82f5bda908..87272a2d8c10 100644
> --- a/arch/powerpc/kernel/prom.c
> +++ b/arch/powerpc/kernel/prom.c
> @@ -76,7 +76,9 @@ u64 ppc64_rma_size;
>   unsigned int boot_cpu_node_count __ro_after_init;  #endif  static 
> phys_addr_t first_memblock_size;
> +#ifdef CONFIG_SMP
>   static int __initdata boot_cpu_count;
> +#endif
> 
>   static int __init early_parse_mem(char *p)  { @@ -331,8 +333,7 @@ static 
> int __init early_init_dt_scan_cpus(unsigned long node,
>  const __be32 *intserv;
>  int i, nthreads;
>  int len;
> -   int found = -1;
> -   int found_thread = 0;
> +   bool found = false;
> 
>  /* We are scanning "cpu" nodes only */
>  if (type == NULL || strcmp(type, "cpu") != 0) @@ -355,8 +356,15 @@ 
> static int __init early_init_dt_scan_cpus(unsigned long node,
>  for (i = 0; i < nthreads; i++) {
>  if (be32_to_cpu(intserv[i]) ==
>  fdt_boot_cpuid_phys(initial_boot_params)) {
> -   found = boot_cpu_count;
> -   found_thread = i;
> +   /*
> +* always map the boot-cpu logical id into the
> +* range of [0, thread_per_core)
> +*/
> +   boot_cpuid = i;
> +   found = true;
> +   /* This works around the hole in paca_ptrs[]. */
> +   if (nr_cpu_ids < nthreads)
> +   set_nr_cpu_ids(nthreads);
>  }
>   #ifdef CONFIG_SMP
>  /* logical cpu id is always 0 on UP kernels */ @@ -365,14 
> +373,13 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
>  }
> 
>  /* Not the boot CPU */
> -   if (found < 0)
> +   if (!found)
>  return 0;
> 

Re: [PATCHv7 2/4] powerpc/setup: Loosen the mapping between cpu logical id and its seq in dt

2023-09-28 Thread Pingfan Liu
On Fri, Sep 29, 2023 at 4:36 AM Wen Xiong  wrote:
>
> Hi Pingfan,
>
> +   avail = intserv_node->avail;
> +   nthreads = intserv_node->len / sizeof(int);
> +   for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) {
> set_cpu_present(cpu, avail);
> set_cpu_possible(cpu, true);
> -   cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]);
> +   cpu_to_phys_id[cpu] = 
> be32_to_cpu(intserv_node->intserv[j]);
> +   DBG("thread %d -> cpu %d (hard id %d)\n",
> +   j, cpu, be32_to_cpu(intserv[j]));
>
> Intserv is not defined. Should "be32_to_cpu(intserv_node->intserv[j])?

Yes, thanks. Sorry that I did not turn on the DBG macro and not catch this bug.

Thanks,

Pingfan
> cpu++;
> }
> +   }
>
> -Original Message-
> From: Pingfan Liu 
> Sent: Monday, September 25, 2023 2:54 AM
> To: linuxppc-...@lists.ozlabs.org
> Cc: Pingfan Liu ; Michael Ellerman ; 
> Nicholas Piggin ; Christophe Leroy 
> ; Mahesh Salgaonkar ; Wen 
> Xiong ; Baoquan He ; Ming Lei 
> ; kexec@lists.infradead.org
> Subject: [EXTERNAL] [PATCHv7 2/4] powerpc/setup: Loosen the mapping between 
> cpu logical id and its seq in dt
>
> *** Idea ***
> For kexec -p, the boot cpu can be not the cpu0, this causes the problem of 
> allocating memory for paca_ptrs[]. However, in theory, there is no 
> requirement to assign cpu's logical id as its present sequence in the device 
> tree. But there is something like cpu_first_thread_sibling(), which makes 
> assumption on the mapping inside a core. Hence partially loosening the 
> mapping, i.e. unbind the mapping of core while keep the mapping inside a core.
>
> *** Implement ***
> At this early stage, there are plenty of memory to utilize. Hence, this patch 
> allocates interim memory to link the cpu info on a list, then reorder cpus by 
> changing the list head. As a result, there is a rotate shift between the 
> sequence number in dt and the cpu logical number.
>
> *** Result ***
> After this patch, a boot-cpu's logical id will always be mapped into the 
> range [0,threads_per_core).
>
> Besides this, at this phase, all threads in the boot core are forced to be 
> onlined. This restriction will be lifted in a later patch with extra effort.
>
> Signed-off-by: Pingfan Liu 
> Cc: Michael Ellerman 
> Cc: Nicholas Piggin 
> Cc: Christophe Leroy 
> Cc: Mahesh Salgaonkar 
> Cc: Wen Xiong 
> Cc: Baoquan He 
> Cc: Ming Lei 
> Cc: kexec@lists.infradead.org
> To: linuxppc-...@lists.ozlabs.org
> ---
>  arch/powerpc/kernel/prom.c | 25 +
>  arch/powerpc/kernel/setup-common.c | 87 +++---
>  2 files changed, 85 insertions(+), 27 deletions(-)
>
> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 
> ec82f5bda908..87272a2d8c10 100644
> --- a/arch/powerpc/kernel/prom.c
> +++ b/arch/powerpc/kernel/prom.c
> @@ -76,7 +76,9 @@ u64 ppc64_rma_size;
>  unsigned int boot_cpu_node_count __ro_after_init;  #endif  static 
> phys_addr_t first_memblock_size;
> +#ifdef CONFIG_SMP
>  static int __initdata boot_cpu_count;
> +#endif
>
>  static int __init early_parse_mem(char *p)  { @@ -331,8 +333,7 @@ static int 
> __init early_init_dt_scan_cpus(unsigned long node,
> const __be32 *intserv;
> int i, nthreads;
> int len;
> -   int found = -1;
> -   int found_thread = 0;
> +   bool found = false;
>
> /* We are scanning "cpu" nodes only */
> if (type == NULL || strcmp(type, "cpu") != 0) @@ -355,8 +356,15 @@ 
> static int __init early_init_dt_scan_cpus(unsigned long node,
> for (i = 0; i < nthreads; i++) {
> if (be32_to_cpu(intserv[i]) ==
> fdt_boot_cpuid_phys(initial_boot_params)) {
> -   found = boot_cpu_count;
> -   found_thread = i;
> +   /*
> +* always map the boot-cpu logical id into the
> +* range of [0, thread_per_core)
> +*/
> +   boot_cpuid = i;
> +   found = true;
> +   /* This works around the hole in paca_ptrs[]. */
> +   if (nr_cpu_ids < nthreads)
> +   set_nr_cpu_ids(nthreads);
> }
>  #ifdef CONFIG_SMP
> /* logical cpu id is always 0 on UP kernels */ @@ -365,14 
> +373,13 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
> }
>
> /* Not the boot CPU */
> -   if (found < 0)
> +   if (!found)
> return 0;
>
> -   DBG("boot cpu: logical %d physical %d\n", found,
> -   be32_to_cpu(intserv[found_thread]));
> -   boot_cpuid = found;
> +   DBG("boot cpu: logical %d physical %d\n", boot_cpuid,
> +   

RE: [PATCHv7 2/4] powerpc/setup: Loosen the mapping between cpu logical id and its seq in dt

2023-09-28 Thread Wen Xiong
Hi Pingfan,

+   avail = intserv_node->avail;
+   nthreads = intserv_node->len / sizeof(int);
+   for (j = 0; j < nthreads && cpu < nr_cpu_ids; j++) {
set_cpu_present(cpu, avail);
set_cpu_possible(cpu, true);
-   cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]);
+   cpu_to_phys_id[cpu] = 
be32_to_cpu(intserv_node->intserv[j]);
+   DBG("thread %d -> cpu %d (hard id %d)\n",
+   j, cpu, be32_to_cpu(intserv[j]));

Intserv is not defined. Should "be32_to_cpu(intserv_node->intserv[j])?
cpu++;
}
+   }

-Original Message-
From: Pingfan Liu  
Sent: Monday, September 25, 2023 2:54 AM
To: linuxppc-...@lists.ozlabs.org
Cc: Pingfan Liu ; Michael Ellerman ; 
Nicholas Piggin ; Christophe Leroy 
; Mahesh Salgaonkar ; Wen 
Xiong ; Baoquan He ; Ming Lei 
; kexec@lists.infradead.org
Subject: [EXTERNAL] [PATCHv7 2/4] powerpc/setup: Loosen the mapping between cpu 
logical id and its seq in dt

*** Idea ***
For kexec -p, the boot cpu can be not the cpu0, this causes the problem of 
allocating memory for paca_ptrs[]. However, in theory, there is no requirement 
to assign cpu's logical id as its present sequence in the device tree. But 
there is something like cpu_first_thread_sibling(), which makes assumption on 
the mapping inside a core. Hence partially loosening the mapping, i.e. unbind 
the mapping of core while keep the mapping inside a core.

*** Implement ***
At this early stage, there are plenty of memory to utilize. Hence, this patch 
allocates interim memory to link the cpu info on a list, then reorder cpus by 
changing the list head. As a result, there is a rotate shift between the 
sequence number in dt and the cpu logical number.

*** Result ***
After this patch, a boot-cpu's logical id will always be mapped into the range 
[0,threads_per_core).

Besides this, at this phase, all threads in the boot core are forced to be 
onlined. This restriction will be lifted in a later patch with extra effort.

Signed-off-by: Pingfan Liu 
Cc: Michael Ellerman 
Cc: Nicholas Piggin 
Cc: Christophe Leroy 
Cc: Mahesh Salgaonkar 
Cc: Wen Xiong 
Cc: Baoquan He 
Cc: Ming Lei 
Cc: kexec@lists.infradead.org
To: linuxppc-...@lists.ozlabs.org
---
 arch/powerpc/kernel/prom.c | 25 +
 arch/powerpc/kernel/setup-common.c | 87 +++---
 2 files changed, 85 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 
ec82f5bda908..87272a2d8c10 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -76,7 +76,9 @@ u64 ppc64_rma_size;
 unsigned int boot_cpu_node_count __ro_after_init;  #endif  static phys_addr_t 
first_memblock_size;
+#ifdef CONFIG_SMP
 static int __initdata boot_cpu_count;
+#endif
 
 static int __init early_parse_mem(char *p)  { @@ -331,8 +333,7 @@ static int 
__init early_init_dt_scan_cpus(unsigned long node,
const __be32 *intserv;
int i, nthreads;
int len;
-   int found = -1;
-   int found_thread = 0;
+   bool found = false;
 
/* We are scanning "cpu" nodes only */
if (type == NULL || strcmp(type, "cpu") != 0) @@ -355,8 +356,15 @@ 
static int __init early_init_dt_scan_cpus(unsigned long node,
for (i = 0; i < nthreads; i++) {
if (be32_to_cpu(intserv[i]) ==
fdt_boot_cpuid_phys(initial_boot_params)) {
-   found = boot_cpu_count;
-   found_thread = i;
+   /*
+* always map the boot-cpu logical id into the
+* range of [0, thread_per_core)
+*/
+   boot_cpuid = i;
+   found = true;
+   /* This works around the hole in paca_ptrs[]. */
+   if (nr_cpu_ids < nthreads)
+   set_nr_cpu_ids(nthreads);
}
 #ifdef CONFIG_SMP
/* logical cpu id is always 0 on UP kernels */ @@ -365,14 
+373,13 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
}
 
/* Not the boot CPU */
-   if (found < 0)
+   if (!found)
return 0;
 
-   DBG("boot cpu: logical %d physical %d\n", found,
-   be32_to_cpu(intserv[found_thread]));
-   boot_cpuid = found;
+   DBG("boot cpu: logical %d physical %d\n", boot_cpuid,
+   be32_to_cpu(intserv[boot_cpuid]));
 
-   boot_cpu_hwid = be32_to_cpu(intserv[found_thread]);
+   boot_cpu_hwid = be32_to_cpu(intserv[boot_cpuid]);
 
/*
 * PAPR defines "logical" PVR values for cpus that diff --git 
a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index 1b19a9815672..f6d32324b5a5 100644
--- a/arch/powerpc/kernel/setup-common.c
+++