Skip to contentSkip to conversation

riscv: cpu: Skip unavailable hart in the get_count() op

PATCH New Bin Meng 3 participants 7 messages Aug 8, 2019 – Aug 12, 2019 2 messages not in the archive RISC-V

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

---

 drivers/cpu/riscv_cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/cpu/riscv_cpu.c +4 -0
index f77c126..28ad0aa 100644
@@ -46,6 +46,10 @@ static int riscv_cpu_get_count(struct udevice *dev)
 	ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
 		const char *device_type;
 
+		/* skip if hart is marked as not available in the device tree */
+		if (!ofnode_is_available(node))
+			continue;
+
 		device_type = ofnode_read_string(node, "device_type");
 		if (!device_type)
 			continue;
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

Quoted 22 lines
Quoted 22 lines

From: Bin Meng [mailto:bmeng.cn at gmail.com]
Sent: Thursday, August 08, 2019 3:52 PM
To: Lukas Auer; Rick Jian-Zhi Chen(陳建志); U-Boot Mailing List
Subject: [PATCH] riscv: cpu: Skip unavailable hart in the get_count() op

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

---

 drivers/cpu/riscv_cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/cpu/riscv_cpu.c index renamed from drivers/cpu/riscv_cpu.c +0 -0

f77c126..28ad0aa 100644

drivers/cpu/riscv_cpu.c +0 -0
@@ -46,6 +46,10 @@ static int riscv_cpu_get_count(struct udevice *dev)
      ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
              const char *device_type;
 
Quoted 10 lines
Quoted 9 lines
drivers/cpu/riscv_cpu.c +4 -1
+             /* skip if hart is marked as not available in the device tree */
+             if (!ofnode_is_available(node))
+                     continue;
+
              device_type = ofnode_read_string(node, "device_type");
              if (!device_type)
                      continue;
--

2.7.4

#3 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

In reply to Bin Meng

Hi Bin,

Quoted 3 lines · Bin Meng

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

I think it might make sense to also exclude harts that are not listed as available in the available_harts mask. So the same logic as in arch/riscv/lib/smp.c. In this case, the bind function should probably check the mask as well.

Looks good otherwise!

Thanks,
Lukas

Quoted 21 lines

---

 drivers/cpu/riscv_cpu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/cpu/riscv_cpu.c +4 -0
index f77c126..28ad0aa 100644
@@ -46,6 +46,10 @@ static int riscv_cpu_get_count(struct udevice *dev)
 	ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
 		const char *device_type;
 
+		/* skip if hart is marked as not available in the device tree */
+		if (!ofnode_is_available(node))
+			continue;
+
 		device_type = ofnode_read_string(node, "device_type");
 		if (!device_type)
 			continue;
author
#4 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

Hi Lukas,

Quoted 4 lines · Lukas

Hi Bin,

On Thu, 2019-08-08 at 00:52 -0700, Bin Meng wrote:

Quoted 9 lines
Quoted 3 lines

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

I think it might make sense to also exclude harts that are not listed as available in the available_harts mask. So the same logic as in arch/riscv/lib/smp.c. In this case, the bind function should probably check the mask as well.

Yes, the check to available_harts mask can be added in riscv_cpu_get_count(). I will do that.

However, I doubt we could do available_harts mask check in the bind function. If it returns error for non-available harts, the whole initialization process fails.

Quoted 4 lines

Looks good otherwise!

Regards,
Bin

#5 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

Hi Bin,

Quoted 17 lines · Bin Meng

Hi Lukas,

Quoted 12 lines · Lukas

Hi Bin,

Quoted 3 lines · Bin Meng

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

I think it might make sense to also exclude harts that are not listed as available in the available_harts mask. So the same logic as in arch/riscv/lib/smp.c. In this case, the bind function should probably check the mask as well.

Quoted 7 lines

Yes, the check to available_harts mask can be added in riscv_cpu_get_count(). I will do that.

However, I doubt we could do available_harts mask check in the bind function. If it returns error for non-available harts, the whole initialization process fails.

You are right, I did not think about that. Perhaps it's best to ignore the available_harts mask in the count function as well then.

It just checked where cpu_get_count() is used. The Andes PLIC driver (lib/andes_plic.c) uses it in a way that the patch might break the driver. It iterates over all harts, assuming the first hart is 0 and the last hart the result of cpu_get_count(). If any of the harts is set to disabled, this will no longer be true. It's probably best to update the driver to use the ofnode_for_each_subnode() macro to iterate over all harts. Rick, can you update the driver?

Thanks,
Lukas

Quoted 7 lines
Quoted 4 lines

Looks good otherwise!

Regards,
Bin

author
#6 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

Hi Lukas,

Quoted 24 lines · Lukas

Hi Bin,

Quoted 20 lines · Bin Meng

Hi Lukas,

Quoted 12 lines · Lukas

Hi Bin,

Quoted 3 lines · Bin Meng

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

I think it might make sense to also exclude harts that are not listed as available in the available_harts mask. So the same logic as in arch/riscv/lib/smp.c. In this case, the bind function should probably check the mask as well.

Yes, the check to available_harts mask can be added in riscv_cpu_get_count(). I will do that.

Quoted 8 lines
Quoted 4 lines

However, I doubt we could do available_harts mask check in the bind function. If it returns error for non-available harts, the whole initialization process fails.

You are right, I did not think about that. Perhaps it's best to ignore the available_harts mask in the count function as well then.

Agreed. I will leave this patch as it is.

Quoted 8 lines

It just checked where cpu_get_count() is used. The Andes PLIC driver (lib/andes_plic.c) uses it in a way that the patch might break the driver. It iterates over all harts, assuming the first hart is 0 and the last hart the result of cpu_get_count(). If any of the harts is set to disabled, this will no longer be true. It's probably best to update the driver to use the ofnode_for_each_subnode() macro to iterate over all harts. Rick, can you update the driver?

Good catch!

Regards,
Bin

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

PATCH 1/1 riscv: cpu: Skip unavailable hart in the get_count() op

Hi Lukas

Quoted 37 lines
Quoted 37 lines

From: Auer, Lukas [mailto:lukas.auer at aisec.fraunhofer.de]
Sent: Thursday, August 08, 2019 10:04 PM
To: bmeng.cn at gmail.com
Cc: Rick Jian-Zhi Chen(陳建志); u-boot at lists.denx.de
Subject: Re: [PATCH] riscv: cpu: Skip unavailable hart in the get_count() op

Hi Bin,

Quoted 17 lines · Bin Meng

Hi Lukas,

Quoted 12 lines · Lukas

Hi Bin,

Quoted 3 lines · Bin Meng

We should not count in hart that is marked as not available in the device tree in riscv_cpu_get_count().

I think it might make sense to also exclude harts that are not listed as available in the available_harts mask. So the same logic as in arch/riscv/lib/smp.c. In this case, the bind function should probably check the mask as well.

Quoted 7 lines

Yes, the check to available_harts mask can be added in riscv_cpu_get_count(). I will do that.

However, I doubt we could do available_harts mask check in the bind function. If it returns error for non-available harts, the whole initialization process fails.

You are right, I did not think about that. Perhaps it's best to ignore the available_harts mask in the count function as well then.

Quoted 7 lines
Quoted 7 lines

It just checked where cpu_get_count() is used. The Andes PLIC driver (lib/andes_plic.c) uses it in a way that the patch might break the driver. It iterates over all harts, assuming the first hart is 0 and the last hart the result of cpu_get_count(). If any of the harts is set to disabled, this will no longer be true. It's probably best to update the driver to use the ofnode_for_each_subnode() macro to iterate over all harts. Rick, can you update the driver?

Yes, I will prepare a patch to update it.
Thanks for your catch and reminding.

Regards,
Rick

Quoted 11 lines
Quoted 11 lines

Thanks,
Lukas

Quoted 7 lines
Quoted 4 lines

Looks good otherwise!

Regards,
Bin