mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
lib: sbi: Optimize sbi_hsm_hart_started_mask() implementation
Instead of calling sbi_hsm_hart_get_state() in a loop, we can simply call a new inline __sbi_hsm_hart_get_state() which only takes "hartid" and enforce domain checks using sbi_domain_assigned_hartmask(). This patch optimizes sbi_hsm_hart_started_mask() as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
@@ -57,20 +57,27 @@ int sbi_hsm_hart_state_to_status(int state)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid)
|
static inline int __sbi_hsm_hart_get_state(u32 hartid)
|
||||||
{
|
{
|
||||||
struct sbi_hsm_data *hdata;
|
struct sbi_hsm_data *hdata;
|
||||||
struct sbi_scratch *scratch;
|
struct sbi_scratch *scratch;
|
||||||
|
|
||||||
scratch = sbi_hartid_to_scratch(hartid);
|
scratch = sbi_hartid_to_scratch(hartid);
|
||||||
if (!scratch || !sbi_domain_is_assigned_hart(dom, hartid))
|
if (!scratch)
|
||||||
return SBI_HART_UNKNOWN;
|
return SBI_HART_UNKNOWN;
|
||||||
|
|
||||||
hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset);
|
hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset);
|
||||||
|
|
||||||
return atomic_read(&hdata->state);
|
return atomic_read(&hdata->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid)
|
||||||
|
{
|
||||||
|
if (!sbi_domain_is_assigned_hart(dom, hartid))
|
||||||
|
return SBI_HART_UNKNOWN;
|
||||||
|
|
||||||
|
return __sbi_hsm_hart_get_state(hartid);
|
||||||
|
}
|
||||||
|
|
||||||
static bool sbi_hsm_hart_started(const struct sbi_domain *dom, u32 hartid)
|
static bool sbi_hsm_hart_started(const struct sbi_domain *dom, u32 hartid)
|
||||||
{
|
{
|
||||||
if (sbi_hsm_hart_get_state(dom, hartid) == SBI_HART_STARTED)
|
if (sbi_hsm_hart_get_state(dom, hartid) == SBI_HART_STARTED)
|
||||||
@@ -90,18 +97,21 @@ static bool sbi_hsm_hart_started(const struct sbi_domain *dom, u32 hartid)
|
|||||||
int sbi_hsm_hart_started_mask(const struct sbi_domain *dom,
|
int sbi_hsm_hart_started_mask(const struct sbi_domain *dom,
|
||||||
ulong hbase, ulong *out_hmask)
|
ulong hbase, ulong *out_hmask)
|
||||||
{
|
{
|
||||||
ulong i;
|
ulong i, hmask, dmask;
|
||||||
ulong hcount = sbi_scratch_last_hartid() + 1;
|
ulong hend = sbi_scratch_last_hartid() + 1;
|
||||||
|
|
||||||
*out_hmask = 0;
|
*out_hmask = 0;
|
||||||
if (hcount <= hbase)
|
if (hend <= hbase)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
if (BITS_PER_LONG < (hcount - hbase))
|
if (BITS_PER_LONG < (hend - hbase))
|
||||||
hcount = BITS_PER_LONG;
|
hend = hbase + BITS_PER_LONG;
|
||||||
|
|
||||||
for (i = hbase; i < hcount; i++) {
|
dmask = sbi_domain_get_assigned_hartmask(dom, hbase);
|
||||||
if (sbi_hsm_hart_get_state(dom, i) == SBI_HART_STARTED)
|
for (i = hbase; i < hend; i++) {
|
||||||
*out_hmask |= 1UL << (i - hbase);
|
hmask = 1UL << (i - hbase);
|
||||||
|
if ((dmask & hmask) &&
|
||||||
|
(__sbi_hsm_hart_get_state(i) == SBI_HART_STARTED))
|
||||||
|
*out_hmask |= hmask;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user