diff options
author | Anup Patel <anup.patel@wdc.com> | 2020-09-25 07:38:24 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2020-10-20 11:30:06 +0300 |
commit | 530e95bd63f60337140ffa55de335e9acc3811b4 (patch) | |
tree | 2d8c030e74a7781299b05c64c9139ed7aed2c352 /lib | |
parent | 3a30d2c34d9c287f49419b44c768ffb70764325c (diff) | |
download | opensbi-530e95bd63f60337140ffa55de335e9acc3811b4.tar.xz |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbi/sbi_hsm.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 8121efb..e1b2b2c 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -57,20 +57,27 @@ int sbi_hsm_hart_state_to_status(int state) 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_scratch *scratch; scratch = sbi_hartid_to_scratch(hartid); - if (!scratch || !sbi_domain_is_assigned_hart(dom, hartid)) + if (!scratch) return SBI_HART_UNKNOWN; hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); - 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) { 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, ulong hbase, ulong *out_hmask) { - ulong i; - ulong hcount = sbi_scratch_last_hartid() + 1; + ulong i, hmask, dmask; + ulong hend = sbi_scratch_last_hartid() + 1; *out_hmask = 0; - if (hcount <= hbase) + if (hend <= hbase) return SBI_EINVAL; - if (BITS_PER_LONG < (hcount - hbase)) - hcount = BITS_PER_LONG; - - for (i = hbase; i < hcount; i++) { - if (sbi_hsm_hart_get_state(dom, i) == SBI_HART_STARTED) - *out_hmask |= 1UL << (i - hbase); + if (BITS_PER_LONG < (hend - hbase)) + hend = hbase + BITS_PER_LONG; + + dmask = sbi_domain_get_assigned_hartmask(dom, hbase); + for (i = hbase; i < hend; i++) { + hmask = 1UL << (i - hbase); + if ((dmask & hmask) && + (__sbi_hsm_hart_get_state(i) == SBI_HART_STARTED)) + *out_hmask |= hmask; } return 0; |