[PATCH 1/5] lib: sbi_tlb: Reduce size of struct sbi_tlb_info

Anup Patel apatel at ventanamicro.com
Tue Dec 12 00:58:54 PST 2023


On Mon, Dec 11, 2023 at 11:46 PM Samuel Holland
<samuel.holland at sifive.com> wrote:
>
> Hi Anup,
>
> On 2023-12-11 12:07 PM, Anup Patel wrote:
> > Let us reduce the size of struct sbi_tlb_info by doing the
> > following:
> > 1) Change the data type of asid and vmid fields to uint16_t
> > 2) Replace local_fn() function pointer with an enum
> >
> > Based on the above, the size of struct sbi_tlb_info is reduced
> > by 16 bytes on RV64 and 4 bytes on RV32.
>
> Nice improvement!
>
> > Signed-off-by: Anup Patel <apatel at ventanamicro.com>
> > ---
> >  include/sbi/sbi_tlb.h      | 29 +++++++------
> >  lib/sbi/sbi_ecall_legacy.c |  8 ++--
> >  lib/sbi/sbi_ecall_rfence.c | 16 +++----
> >  lib/sbi/sbi_tlb.c          | 89 ++++++++++++++++++++++++++++----------
> >  4 files changed, 92 insertions(+), 50 deletions(-)
> >
> > diff --git a/include/sbi/sbi_tlb.h b/include/sbi/sbi_tlb.h
> > index 55dcab0..2c50fe8 100644
> > --- a/include/sbi/sbi_tlb.h
> > +++ b/include/sbi/sbi_tlb.h
> > [...]
> >  static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data)
> >  {
> >       if (unlikely(!data))
> >               return;
> >
> > -     if (data->local_fn == sbi_tlb_local_fence_i)
> > +     switch (data->type) {
> > +     case SBI_TLB_FENCE_I:
> >               sbi_pmu_ctr_incr_fw(SBI_PMU_FW_FENCE_I_SENT);
> > -     else if (data->local_fn == sbi_tlb_local_sfence_vma)
> > +             break;
> > +     case SBI_TLB_SFENCE_VMA:
> >               sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_SENT);
> > -     else if (data->local_fn == sbi_tlb_local_sfence_vma_asid)
> > +             break;
> > +     case SBI_TLB_SFENCE_VMA_ASID:
> >               sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_ASID_SENT);
> > -     else if (data->local_fn == sbi_tlb_local_hfence_gvma)
> > -             sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_SENT);
> > -     else if (data->local_fn == sbi_tlb_local_hfence_gvma_vmid)
> > +             break;
> > +     case SBI_TLB_HFENCE_GVMA_VMID:
> >               sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_VMID_SENT);
> > -     else if (data->local_fn == sbi_tlb_local_hfence_vvma)
> > -             sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_SENT);
> > -     else if (data->local_fn == sbi_tlb_local_hfence_vvma_asid)
> > +             break;
> > +     case SBI_TLB_HFENCE_GVMA:
> > +             sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_SENT);
> > +             break;
> > +     case SBI_TLB_HFENCE_VVMA_ASID:
> >               sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT);
> > +             break;
> > +     case SBI_TLB_HFENCE_VVMA:
> > +             sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_SENT);
> > +             break;
>
> These switch cases are all practically the same. Can this be simplified by using
> a lookup table for the PMU event?

Ahh, yes. We can use a lookup table over here. I will update in the
next revision.

Thanks,
Anup



More information about the opensbi mailing list