[PATCH 09/11] lib: sbi: Detect hart features only once for each hart

Anup Patel anup at brainfault.org
Fri May 6 22:04:39 PDT 2022


On Wed, May 4, 2022 at 7:31 AM Atish Patra <atishp at atishpatra.org> wrote:
>
> On Fri, Apr 29, 2022 at 8:52 AM Anup Patel <apatel at ventanamicro.com> wrote:
> >
> > Currently, the hart_detect_features() is called everytime a hart
> > is stopped and started again which is unnecessary work.
> >
> > We update hart_detect_features() to detect hart features only
> > once for each hart.
> >
>
> Great.
>
> > Signed-off-by: Anup Patel <apatel at ventanamicro.com>
> > ---
> >  lib/sbi/sbi_hart.c | 14 +++++++++++---
> >  1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> > index 956d185..28a7e75 100644
> > --- a/lib/sbi/sbi_hart.c
> > +++ b/lib/sbi/sbi_hart.c
> > @@ -28,6 +28,7 @@ extern void __sbi_expected_trap_hext(void);
> >  void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap;
> >
> >  struct hart_features {
> > +       bool detected;
> >         int priv_version;
> >         unsigned long extensions;
> >         unsigned int pmp_count;
> > @@ -510,11 +511,15 @@ static int hart_pmu_get_allowed_bits(void)
> >  static void hart_detect_features(struct sbi_scratch *scratch)
> >  {
> >         struct sbi_trap_info trap = {0};
> > -       struct hart_features *hfeatures;
> > +       struct hart_features *hfeatures =
> > +               sbi_scratch_offset_ptr(scratch, hart_features_offset);
> >         unsigned long val, oldval;
> >
> > -       /* Reset hart features */
> > -       hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset);
> > +       /* If hart features already detected then do nothing */
> > +       if (hfeatures->detected)
> > +               return;
> > +
> > +       /* Clear hart features */
> >         hfeatures->extensions = 0;
> >         hfeatures->pmp_count = 0;
> >         hfeatures->mhpm_count = 0;
> > @@ -642,6 +647,9 @@ __mhpm_skip:
> >                         hfeatures->extensions |= BIT(SBI_HART_EXT_SMSTATEEN);
> >         }
> >
> > +       /* Mark hart feature detection done */
> > +       hfeatures->detected = true;
> > +
> >         return;
> >  }
> >
> > --
> > 2.34.1
> >
>
> Reviewed-by: Atish Patra <atishp at rivosinc.com>

Applied this patch to the riscv/opensbi repo

Regards,
Anup

>
> --
> Regards,
> Atish



More information about the opensbi mailing list