[PATCH 1/3] riscv: Add timer_get_us() for tracing

Rick Chen rickchen36 at gmail.com
Wed Oct 21 05:28:19 CEST 2020


Hi Pragnesh

> From: Bin Meng [mailto:bmeng.cn at gmail.com]
> Sent: Friday, September 11, 2020 2:48 PM
> To: Pragnesh Patel
> Cc: U-Boot Mailing List; Atish Patra; Anup Patel; Sagar Kadam; Rick Jian-Zhi Chen(陳建志); Paul Walmsley; Bin Meng; Lukas Auer; Sean Anderson
> Subject: Re: [PATCH 1/3] riscv: Add timer_get_us() for tracing
>
> Hi Pragnesh,
>
> On Mon, Aug 24, 2020 at 10:45 PM Pragnesh Patel
> <pragnesh.patel at sifive.com> wrote:
> >
> > timer_get_us() will use timer_ops->get_count() function for timer counter.
> > For S-mode U-Boot, CSR_TIMEH and CSR_TIME will provide a timer counter and
> > For M-mode U-Boot, mtime register will provide the same.
> >
> > Signed-off-by: Pragnesh Patel <pragnesh.patel at sifive.com>
> > ---
> >  arch/riscv/lib/Makefile |  1 +
> >  arch/riscv/lib/timer.c  | 50 +++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 51 insertions(+)
> >  create mode 100644 arch/riscv/lib/timer.c
> >
> > diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
> > index 10ac5b06d3..fbb68e583b 100644
> > --- a/arch/riscv/lib/Makefile
> > +++ b/arch/riscv/lib/Makefile
> > @@ -26,6 +26,7 @@ obj-y   += setjmp.o
> >  obj-$(CONFIG_$(SPL_)SMP) += smp.o
> >  obj-$(CONFIG_SPL_BUILD)        += spl.o
> >  obj-y   += fdt_fixup.o
> > +obj-$(CONFIG_TIMER) += timer.o
> >
> >  # For building EFI apps
> >  CFLAGS_$(EFI_CRT0) := $(CFLAGS_EFI)
> > diff --git a/arch/riscv/lib/timer.c b/arch/riscv/lib/timer.c
> > new file mode 100644
> > index 0000000000..3e423f2805
> > --- /dev/null
> > +++ b/arch/riscv/lib/timer.c
> > @@ -0,0 +1,50 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2020 SiFive, Inc
> > + *
> > + * Authors:
> > + *   Pragnesh Patel <pragnesh.patel at sifive.com>
> > + */
> > +
> > +#include <common.h>
> > +#include <dm.h>
> > +#include <timer.h>
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +static struct udevice *timer;
> > +
> > +ulong notrace timer_get_us(void)
>
> Does the weak one in lib/time.c not work on RISC-V?

Do you have any comments about Bin's reply ?

Thanks,
Rick

>
> > +{
> > +       u64 count;
> > +       ulong rate;
> > +       int ret;
> > +
> > +       /**
> > +        * gd->timer will become NULL in initr_dm(), so assign gd->timer
> > +        * to other static global timer, so that timer_get_us() can use it.
> > +        */
> > +       if (!timer && gd->timer)
> > +               timer = (struct udevice *)gd->timer;
> > +
> > +       if (timer) {
> > +               ret = timer_get_count(timer, &count);
> > +               if (ret)
> > +                       return ret;
> > +
> > +               rate = timer_get_rate(timer);
> > +       }
> > +
> > +       return (ulong)count / rate;
> > +}
> > +
> > +int timer_init(void)
>
> Why is this function necessary?
>
> > +{
> > +       int ret;
> > +
> > +       ret = dm_timer_init();
>
> Does enabling CONFIG_TIMER_EARLY help?
>
> > +       if (ret)
> > +               return ret;
> > +
> > +       return 0;
> > +}
>
> Regards,
> Bin


More information about the U-Boot mailing list