Convert hartid to hart index to get scratch.
PATCH 1/1 Convert hartid to hart index to get scratch.
Hartid may not be sequential, so we need to use index to get scratch.
--- lib/utils/ipi/aclint_mswi.c | 2 +- lib/utils/timer/aclint_mtimer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
lib/utils/ipi/aclint_mswi.c +1 -1
@@ -87,7 +87,7 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)/* Update MSWI pointer in scratch space */ for (i =0 ; i < mswi->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mswi->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mswi->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled
lib/utils/timer/aclint_mtimer.c +1 -1
@@ -206,7 +206,7 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,/* Update MTIMER pointer in scratch space */ for (i =0 ; i < mt->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mt->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mt->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled
Signature · 1 line
2.47.1
PATCH 1/1 Convert hartid to hart index to get scratch.
Quoted 34 lines · On Thu, Jan 9, 2025 at 4:07?PM Chao-ying Fu <[email protected]> wrote:
Hartid may not be sequential, so we need to use index to get scratch.
--- lib/utils/ipi/aclint_mswi.c | 2 +- lib/utils/timer/aclint_mtimer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)lib/utils/ipi/aclint_mswi.c +1
-1@@ -87,7 +87,7 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)/* Update MSWI pointer in scratch space */ for (i =0 ; i < mswi->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mswi->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mswi->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled lib/utils/timer/aclint_mtimer.c +1
-2@@ -206,7 +206,7 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,/* Update MTIMER pointer in scratch space */ for (i =0 ; i < mt->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mt->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mt->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled --
Quoted 2 lines
2.47.1
Any feedback about this patch?
Without this patch, OpenSBI may use a wrong hartid that doesn't exist in a platform.
Thanks!
PATCH 1/1 Convert hartid to hart index to get scratch.
In reply to Chao-ying FuAny feedback on this patch?
The hartid's may not be sequential. We need to use the index to get the scratch.
Raj
Quoted 36 lines · On Thu, Jan 9, 2025 at 4:07?PM Chao-ying Fu <[email protected]> wrote:
Hartid may not be sequential, so we need to use index to get scratch.
--- lib/utils/ipi/aclint_mswi.c | 2 +- lib/utils/timer/aclint_mtimer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)lib/utils/ipi/aclint_mswi.c +1
-1@@ -87,7 +87,7 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)/* Update MSWI pointer in scratch space */ for (i =0 ; i < mswi->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mswi->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mswi->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled lib/utils/timer/aclint_mtimer.c +1
-2@@ -206,7 +206,7 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,/* Update MTIMER pointer in scratch space */ for (i =0 ; i < mt->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mt->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mt->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled -- 2.47.1
Signature · 1 line
2.43.0
PATCH 1/1 Convert hartid to hart index to get scratch.
Quoted 2 lines · Raj Vishwanathan
Any feedback on this patch?
The hartid's may not be sequential. We need to use the index to get the scratch.
Yes, it is true that the harts associated with an ACLINT MSWI need not have sequential hartids. The ACLINT spec explicitly calls this out. However, there is also no guarantee that they will have sequential OpenSBI hart indexes, either. The allocation of hart indexes within OpenSBI should be considered entirely arbitrary. Consider what happens if you randomly select a non-boot-hart CPU node in the DT and mark it as status = "disabled"; this should not cause any erroneous behavior.
Fundamentally, the "first_hartid" and "hart_count" members in aclint_mswi_data are insufficient to cover an ACLINT MSWI with a non-sequential hart mapping. So more refactoring is needed to handle your case robustly.
Regards,
Samuel
Quoted 38 lines · On Thu, Jan 9, 2025 at 4:07?PM Chao-ying Fu <[email protected]> wrote:
Quoted 36 lines
Hartid may not be sequential, so we need to use index to get scratch.
--- lib/utils/ipi/aclint_mswi.c | 2 +- lib/utils/timer/aclint_mtimer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)lib/utils/ipi/aclint_mswi.c +1
-1@@ -87,7 +87,7 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)/* Update MSWI pointer in scratch space */ for (i =0 ; i < mswi->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mswi->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mswi->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled lib/utils/timer/aclint_mtimer.c +1
-2@@ -206,7 +206,7 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,/* Update MTIMER pointer in scratch space */ for (i =0 ; i < mt->hart_count; i++) { - scratch =sbi_hartid_to_scratch (mt->first_hartid + i); + scratch =sbi_hartindex_to_scratch (sbi_hartid_to_hartindex (mt->first_hartid) + i);/* * We don't need to fail if scratch pointer is not available * because we might be dealing with hartid of a HART disabled -- 2.47.1