riscv: cancel the limitation that NR_CPUS is less than or equal to 32
PATCH v2 1/1 riscv: cancel the limitation that NR_CPUS is less than or equal to 32
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.
Test on sifive unmatched.
---
Changes since v1:
* When NR_CPUS is very large, the value of GD_AVAILABLE_HARTS will overflow the immediate range of ld/lw. This patch fixes this problem
arch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++----- arch/riscv/include/asm/global_data.h | 4 +++- arch/riscv/lib/smp.c | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-)
arch/riscv/Kconfig +2 -2
@@ -220,8 +220,8 @@ config SPL_SMP all, single processor machines. config NR_CPUS - int "Maximum number of CPUs (2-32)" - range 2 32 + int "Maximum number of CPUs (2-4095)" + range 2 4095 depends on SMP || SPL_SMP default 8 help
arch/riscv/cpu/start.S +16 -5
@@ -166,11 +166,22 @@ wait_for_gd_init: mv gp, s0 /* register available harts in the available_harts mask */ - li t1, 1 - sll t1, t1, tp - LREG t2, GD_AVAILABLE_HARTS(gp) - or t2, t2, t1 - SREG t2, GD_AVAILABLE_HARTS(gp) + li t1, GD_AVAILABLE_HARTS + add t1, t1, gp + LREG t1, 0(t1) +#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2 +#endif + add t1, t1, t2 + LREG t2, 0(t1) + li t3, 1 + sll t3, t3, tp + or t2, t2, t3 + SREG t2, 0(t1) amoswap.w.rl zero, zero, 0(t0)
arch/riscv/include/asm/global_data.h +3 -1
@@ -10,9 +10,11 @@#ifndef __ASM_GBL_DATA_H#define __ASM_GBL_DATA_H +#include <config.h> #include <asm/smp.h> #include <asm/u-boot.h> #include <compiler.h> +#include <linux/bitops.h> /* Architecture-specific global data */ struct arch_global_data {
@@ -28,7 +30,7 @@ struct arch_global_data {struct ipi_data ipi[CONFIG_NR_CPUS ];#endif #ifndef CONFIG_XIP -ulong available_harts; +ulong available_harts[BITS_TO_LONGS (CONFIG_NR_CPUS )];#endif };
arch/riscv/lib/smp.c +1 -1
@@ -47,7 +47,7 @@ static int send_ipi_many(struct ipi_data *ipi, int wait)#ifndef CONFIG_XIP /* skip if hart is not available */ -if (!(gd->arch.available_harts & (1 << reg))) +if (!test_bit (reg, gd->arch.available_harts))continue ;#endif
Signature · 1 line
2.30.2
Hi Xiang,
Quoted 40 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemarch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++----- arch/riscv/include/asm/global_data.h | 4 +++- arch/riscv/lib/smp.c | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-)arch/riscv/cpu/start.S +4
-5@@ -166,11 +166,22 @@ wait_for_gd_init: mv gp, s0 /* register available harts in the available_harts mask */ - li t1, 1 - sll t1, t1, tp - LREG t2, GD_AVAILABLE_HARTS(gp) - or t2, t2, t1 - SREG t2, GD_AVAILABLE_HARTS(gp) + li t1, GD_AVAILABLE_HARTS + add t1, t1, gp + LREG t1, 0(t1) +#if defined(CONFIG_ARCH_RV64I)
arch/riscv/cpu/start.S wait_for_gd_init: · line 182
Quoted 10 lines
arch/riscv/cpu/start.S +10
-0+ srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2 +#endif + add t1, t1, t2 + LREG t2, 0(t1) + li t3, 1 + sll t3, t3, tp
This seems incorrect.
Shouldn't we have "$tp % sizeof(ulong)" instead of "$tp / sizeof(ulong)" ?
arch/riscv/cpu/start.S wait_for_gd_init: · line 186
Quoted 4 lines
arch/riscv/cpu/start.S +2
-0+ or t2, t2, t3 + SREG t2, 0(t1) amoswap.w.rl zero, zero, 0(t0)
Best regards,
Leo
Quoted 47 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 45 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemarch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++-----
arch/riscv/include/asm/global_data.h| 4 +++- arch/riscv/lib/smp.c | 2 +-4 files changed, 22 insertions(+), 9 deletions(-)arch/riscv/cpu/start.S +0
-0@@ -166,11 +166,22 @@ wait_for_gd_init:mv gp, s0
/* register available harts in theavailable_hartsmask */ - li t1, 1
- sll t1, t1, tp
- LREG t2,GD_AVAILABLE_HARTS(gp)
- or t2, t2, t1
- SREG t2,GD_AVAILABLE_HARTS(gp)
+ li t1,GD_AVAILABLE_HARTS
+ add t1, t1, gp
+ LREG t1, 0(t1)arch/riscv/cpu/start.S +6
-0+#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2
Quoted 8 lines
Quoted 5 lines
+#endif
+ add t1, t1, t2
+ LREG t2, 0(t1)
+ li t3, 1
+ sll t3, t3, tpThis seems incorrect.
Shouldn't we have "$tp % sizeof(ulong)" instead of "$tp / sizeof(ulong)" ?
Do you meening: "$tp % sizeof(ulong)" instead of "$tp" ?
There is such a description in the riscv specification:
SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.
SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in register rs2. In RV64I, only the low 6 bits of rs2 are considered for the shift amount.
So we don’t need to perform the remainder operation.
regards,
Xiang W
Quoted 6 lines
Quoted 4 lines
+ or t2, t2, t3
+ SREG t2, 0(t1)
amoswap.w.rl zero, zero, 0(t0)Best regards,
Leo
Leo Liang
Reviewed-byQuoted 65 lines · Xiang W
Quoted 47 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 45 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemarch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++-----
arch/riscv/include/asm/global_data.h| 4 +++- arch/riscv/lib/smp.c | 2 +-4 files changed, 22 insertions(+), 9 deletions(-)arch/riscv/cpu/start.S +0
-0@@ -166,11 +166,22 @@ wait_for_gd_init:mv gp, s0
/* register available harts in theavailable_hartsmask */ - li t1, 1
- sll t1, t1, tp
- LREG t2,GD_AVAILABLE_HARTS(gp)
- or t2, t2, t1
- SREG t2,GD_AVAILABLE_HARTS(gp)
+ li t1,GD_AVAILABLE_HARTS
+ add t1, t1, gp
+ LREG t1, 0(t1)arch/riscv/cpu/start.S +6
-0+#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2Quoted 8 lines
Quoted 5 lines
+#endif
+ add t1, t1, t2
+ LREG t2, 0(t1)
+ li t3, 1
+ sll t3, t3, tpThis seems incorrect.
Shouldn't we have "$tp % sizeof(ulong)" instead of "$tp / sizeof(ulong)" ?Do you meening: "$tp % sizeof(ulong)" instead of "$tp" ?
There is such a description in the riscv specification:
SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.
Quoted 6 lines
SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in register rs2. In RV64I, only the low 6 bits of rs2 are considered for the shift amount.
So we don’t need to perform the remainder operation.
Got it! Thanks for the explanation.
LGTM,
Best regards,
Leo
Quoted 11 lines
regards,
Xiang WQuoted 6 lines
Quoted 4 lines
+ or t2, t2, t3
+ SREG t2, 0(t1)
amoswap.w.rl zero, zero, 0(t0)Best regards,
Leo
Quoted 72 lines · Leo Liang
Quoted 70 lines · Xiang W
Quoted 47 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 45 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemarch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++----- arch/riscv/include/asm/global_data.h | 4 +++- arch/riscv/lib/smp.c | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-)arch/riscv/cpu/start.S +9
-5@@ -166,11 +166,22 @@ wait_for_gd_init: mv gp, s0 /* register available harts in the available_harts mask */ - li t1, 1 - sll t1, t1, tp - LREG t2, GD_AVAILABLE_HARTS(gp) - or t2, t2, t1 - SREG t2, GD_AVAILABLE_HARTS(gp) + li t1, GD_AVAILABLE_HARTS + add t1, t1, gp + LREG t1, 0(t1) +#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2Quoted 8 lines
arch/riscv/cpu/start.S wait_for_gd_init: · line 182
Quoted 5 lines
arch/riscv/cpu/start.S +5
-0+#endif + add t1, t1, t2 + LREG t2, 0(t1) + li t3, 1 + sll t3, t3, tpThis seems incorrect.
Shouldn't we have "$tp % sizeof(ulong)" instead of "$tp / sizeof(ulong)" ?Do you meening: "$tp % sizeof(ulong)" instead of "$tp" ?
There is such a description in the riscv specification:
SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.
SLL, SRL, and SRA perform logical left, logical right, and arithmetic right shifts on the value in register rs1 by the shift amount held in register rs2. In RV64I, only the low 6 bits of rs2 are considered for the shift amount.
Quoted 6 lines
Quoted 1 line
So we don’t need to perform the remainder operation.
Got it! Thanks for the explanation.
LGTM,
Reviewed-by Leo Yu-Chi Liang <[email protected]>
I noticed that this has never landed in U-Boot. Was this forgotten or dropped for some reason (couldn't find anything)?
The current limit on the Linux kernel side is 512. The default on 64-bit (riscv64) is 64.
david
Quoted 14 lines
Best regards,
LeoQuoted 11 lines
regards,
Xiang WQuoted 6 lines
arch/riscv/cpu/start.S wait_for_gd_init: · line 186
Quoted 4 lines
arch/riscv/cpu/start.S +2
-0+ or t2, t2, t3 + SREG t2, 0(t1) amoswap.w.rl zero, zero, 0(t0)Best regards,
Leo
Hi David,
Quoted 13 lines · David Abdurachmanov
Quoted 12 lines · Leo Liang
Quoted 10 lines · Xiang W
Quoted 9 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 7 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>I noticed that this has never landed in U-Boot. Was this forgotten or dropped for some reason (couldn't find anything)?
Sorry, This patch is forgotten.
I will make sure this gets applied as soon as possible if there is no other error or concerns.
Thanks for the reminder!
Best regards,
Leo
Quoted 4 lines
The current limit on the Linux kernel side is 512. The default on 64-bit (riscv64) is 64.
david
Hi Xiang,
Quoted 30 lines · David Abdurachmanov
Quoted 22 lines · Leo Liang
Quoted 20 lines · Xiang W
Quoted 19 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 17 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++----- arch/riscv/include/asm/global_data.h | 4 +++- arch/riscv/lib/smp.c | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-)
Quoted 7 lines
I noticed that this has never landed in U-Boot. Was this forgotten or dropped for some reason (couldn't find anything)?
The current limit on the Linux kernel side is 512. The default on 64-bit (riscv64) is 64.
david
The patch seems to cause some CI error (timeout on QEMU).
(https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/15076)
Could you take a look at it if you have time?
Best regards,
Leo
Quoted 39 lines · 在 2023-02-10星期五的 07:25 +0000,Leo Liang写道:
Hi Xiang,
Quoted 36 lines · David Abdurachmanov
Quoted 22 lines · Leo Liang
Quoted 20 lines · Xiang W
Quoted 19 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 17 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++-----
arch/riscv/include/asm/global_data.h| 4 +++- arch/riscv/lib/smp.c | 2 +-4 files changed, 22 insertions(+), 9 deletions(-)I noticed that this has never landed in U-Boot. Was this forgotten or dropped for some reason (couldn't find anything)?
The current limit on the Linux kernel side is 512. The default on 64-bit (riscv64) is 64.
Quoted 8 lines
Quoted 1 line
david
The patch seems to cause some CI error (timeout on QEMU).
(https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/15076)
Could you take a look at it if you have time?Best regards,
Leo
sorry! I missing a bug. There is an error in calculating the starting address of available_harts. The patch for start.S needs to be updated.
arch/riscv/cpu/start.S +15 -5
@@ -166,11 +166,22 @@ wait_for_gd_init: mv gp, s0 /* register available harts in the available_harts mask */ - li t1, 1 - sll t1, t1, tp - LREG t2, GD_AVAILABLE_HARTS(gp) - or t2, t2, t1 - SREG t2, GD_AVAILABLE_HARTS(gp) + li t1, GD_AVAILABLE_HARTS + add t1, t1, gp +#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2 +#endif + add t1, t1, t2 + LREG t2, 0(t1) + li t3, 1 + sll t3, t3, tp + or t2, t2, t3 + SREG t2, 0(t1) amoswap.w.rl zero, zero, 0(t0)
The mailing list cannot receive my mail, please help to update
Hi Xiang,
Quoted 83 lines · Xiang W
Quoted 39 lines · 在 2023-02-10星期五的 07:25 +0000,Leo Liang写道:
Hi Xiang,
Quoted 36 lines · David Abdurachmanov
Quoted 22 lines · Leo Liang
Quoted 20 lines · Xiang W
Quoted 19 lines · 在 2021-12-29星期三的 17:23 +0800,Leo Liang写道:
Hi Xiang,
Quoted 17 lines · Xiang W
Various specifications of riscv allow the number of hart to be greater than 32. The limit of 32 is determined by
gd->arch.available_harts. We can eliminate this limitation through bitmaps. Currently, the number of hart is limited to 4095, and 4095 is the limit of the RISC-V Advanced Core Local Interruptor Specification.Test on sifive unmatched.
Signed-off-by Xiang W <[email protected]>---
Changes since v1:* When
NR_CPUSis very large, the value ofGD_AVAILABLE_HARTSwill overflow the immediate range of ld/lw. This patch fixes this problemQuoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 21 ++++++++++++++++-----
arch/riscv/include/asm/global_data.h| 4 +++- arch/riscv/lib/smp.c | 2 +-4 files changed, 22 insertions(+), 9 deletions(-)I noticed that this has never landed in U-Boot. Was this forgotten or dropped for some reason (couldn't find anything)?
The current limit on the Linux kernel side is 512. The default on 64-bit (riscv64) is 64.
Quoted 8 lines
Quoted 1 line
david
The patch seems to cause some CI error (timeout on QEMU).
(https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/15076)
Could you take a look at it if you have time?Best regards,
Leosorry! I missing a bug. There is an error in calculating the starting address of
available_harts. The patch forstart.Sneeds to be updated.arch/riscv/cpu/start.S +15
-5@@ -166,11 +166,22 @@ wait_for_gd_init: mv gp, s0 /* register available harts in the available_harts mask */ - li t1, 1 - sll t1, t1, tp - LREG t2, GD_AVAILABLE_HARTS(gp) - or t2, t2, t1 - SREG t2, GD_AVAILABLE_HARTS(gp) + li t1, GD_AVAILABLE_HARTS + add t1, t1, gp +#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2 +#endif + add t1, t1, t2 + LREG t2, 0(t1) + li t3, 1 + sll t3, t3, tp + or t2, t2, t3 + SREG t2, 0(t1) amoswap.w.rl zero, zero, 0(t0)
Quoted 2 lines
The mailing list cannot receive my mail, please help to update
I have updated the patch.
(https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/)
Could you take a look to see if there is any issue?
Best regards,
Leo