RISC-V tracing support
Subsystems (2)
v3 cover RISC-V tracing support
This series add a support of tracing for RISC-V arch.
This series is also available here [1] for testing.
[1] https://github.com/pragnesh26992/u-boot/tree/trace
How to test this patch:
1) Enable tracing in "configs/sifive_fu540_defconfig" CONFIG_TRACE=y CONFIG_TRACE_BUFFER_SIZE=0x01000000 CONFIG_TRACE_CALL_DEPTH_LIMIT=15 CONFIG_CMD_TRACE=y
2) make FTRACE=1 sifive_fu540_defconfig
3) make FTRACE=1
Changes in v3:
- Added gd->arch.plmt in global data
- For timer_get_us(), use readq() instead of andes_plmt_get_count() and sifive_clint_get_count()
Changes in v2:
- Remove newly added timer file (arch/riscv/lib/timer.c)
- Added timer_get_us() in riscv_timer.c, sifive_clint_timer.c and andes_plmt_timer.c.
Following are the boot messages on FU540 five cores SMP platform:
U-Boot SPL 2021.01-rc1-00244-g88b5af756c-dirty (Nov 11 2020 - 14:57:25 +0530) Trying to boot from MMC1
U-Boot 2021.01-rc1-00244-g88b5af756c-dirty (Nov 11 2020 - 14:57:25 +0530)
CPU: rv64imafdc Model: SiFive HiFive Unleashed A00 DRAM: 8 GiB trace: enabled MMC: spi at 10050000:mmc at 0: 0
*** Warning - bad CRC, using default environment
In: serial at 10010000 Out: serial at 10010000 Err: serial at 10010000
Board serial number should not be 0 !!
Net:
Error: ethernet at 10090000 address not set.
No ethernet found.
Hit any key to stop autoboot: 0
=> trace stats
178,556 function sites
15,443,168 function calls
1 untracked function calls
1,279,056 traced function calls (14135744 dropped due to overflow)
19 maximum observed call depth
15 call depth limit
15,633,052 calls not traced due to depth
=>
Pragnesh Patel (1):
riscv: Add timer_get_us() for tracing
arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Add timer_get_us() which is useful for tracing. For S-mode U-Boot, CSR_TIMEH and CSR_TIME will provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.
---
Changes in v3:
- Added gd->arch.plmt in global data
- For timer_get_us(), use readq() instead of andes_plmt_get_count() and sifive_clint_get_count()
Changes in v2:
- Added timer_get_us() in riscv_timer.c, sifive_clint_timer.c and andes_plmt_timer.c.
arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)
arch/riscv/include/asm/global_data.h +3 -0
@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLIC void __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP )struct ipi_data ipi[CONFIG_NR_CPUS ];#endif
drivers/timer/andes_plmt_timer.c +18 -1
@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) {return readq ((void __iomem *)MTIME_REG (dev->priv)); }
@@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }
drivers/timer/riscv_timer.c +13 -1
@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;
@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);
drivers/timer/sifive_clint_timer.c +18 -1
@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) {return readq ((void __iomem *)MTIME_REG (dev->priv)); }
@@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
Signature · 1 line
2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Quoted 6 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing. For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>
The default implementation of get_timer_us() in lib/time.c calls get_ticks() which calls timer_get_count(). The get_count() operation is implemented in drivers/timer/andes_plmt_timer.c, drivers/timer/sifive_clint_timer.c, drivers/timer/riscv_timer.c.
Why do you need special timer_get_us() implementations? Isn't it enough to supply the get_count() operation in the drivers?
Best regards
Heinrich
Quoted 160 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLIC void __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP )struct ipi_data ipi[CONFIG_NR_CPUS ];#endif drivers/timer/andes_plmt_timer.c +18
-1@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) {return readq ((void __iomem *)MTIME_REG (dev->priv)); }@@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +13
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +18
-1@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) {return readq ((void __iomem *)MTIME_REG (dev->priv)); }@@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Heinrich,
Quoted 20 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>
Quoted 7 lines
The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks() is depend on gd->timer and there are 2 cases
1) if gd->timer== NULL then dm_timer_init() gets called and it will call functions which are not marked with "notrace" so tracing got stuck.
2) if gd->timer is already initialized then still initr_dm() will make gd->timer = NULL;
initr_dm()
{
#ifdef CONFIG_TIMER
gd->timer = NULL;#endif
}
So again dm_timer_init() gets called and tracing got stuck.
So I thought better to implement timer_get_us().
Quoted 153 lines
Best regards
Heinrich
Quoted 148 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.cindexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +18
-1@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +12
-2@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev); diff --git a/drivers/timer/sifive_clint_timer.c
b/drivers/timer/sifive_clint_timer.c
index00ce0f08d6..c341f7789b100644drivers/timer/sifive_clint_timer.c +18
-1@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Quoted 27 lines · Pragnesh Patel
Hi Heinrich,
Quoted 25 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.
Quoted 7 lines
Quoted 2 lines
Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks()is depend ongd->timerand there are 2 cases1) if gd->timer== NULL then
dm_timer_init()gets called and it will call functions which are not marked with "notrace" so tracing got stuck.
Thanks for the background information.
Please, identify the existing functions that lack "notrace" and fix them. This will give us a solution for all existing boards and not for a small selection. Furthermore it will avoid code duplication.
In lib/trace.c consider replacing "__attribute__((no_instrument_function))" by "notrace".
Best regards
Heinrich
Quoted 168 lines
2) if
gd->timeris already initialized then stillinitr_dm()will makegd->timer= NULL;
initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}So again
dm_timer_init()gets called and tracing got stuck.So I thought better to implement
timer_get_us().Quoted 153 lines
Best regards
Heinrich
Quoted 148 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.cindexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +18
-1@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +12
-2@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev); diff --git a/drivers/timer/sifive_clint_timer.c
b/drivers/timer/sifive_clint_timer.c
index00ce0f08d6..c341f7789b100644drivers/timer/sifive_clint_timer.c +18
-1@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Heinrich,
Quoted 49 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 19:18
To: Pragnesh Patel <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>;
rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 34 lines · Pragnesh Patel
Hi Heinrich,
Quoted 22 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>Quoted 7 lines
The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks()is depend ongd->timerand there are 2 cases
Quoted 8 lines
Quoted 2 lines
1) if gd->timer== NULL then
dm_timer_init()gets called and it will call functions which are not marked with "notrace" so tracing got stuck.Thanks for the background information.
Please, identify the existing functions that lack "notrace" and fix them. This will give us a solution for all existing boards and not for a small selection. Furthermore it will avoid code duplication.
I tried but There are so many functions which need "notrace".
Why don?t we consider removing gd->timer=NULL in initr_dm() initr_dm()
{
#ifdef CONFIG_TIMER
gd->timer = NULL;#endif
}
Or I can use TIMER_EARLY and return ticks and rate by adding timer_early_get_count() and timer_early_get_rate() repectively.
Suggestions are welcome
Quoted 180 lines
In
lib/trace.cconsider replacing "__attribute__((no_instrument_function))" by "notrace".Best regards
Heinrich
Quoted 172 lines
2) if
gd->timeris already initialized then stillinitr_dm()will makegd->timer= NULL;
initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}So again
dm_timer_init()gets called and tracing got stuck.So I thought better to implement
timer_get_us().Quoted 156 lines
Best regards
Heinrich
Quoted 151 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +3
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26 ,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = {.get_count = andes_plmt_get_count, };drivers/timer/andes_plmt_timer.c +15
-0+#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +3
-2@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23 ,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = {.get_count = sifive_clint_get_count, };drivers/timer/sifive_clint_timer.c +15
-0+#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Quoted 54 lines · Pragnesh Patel
Hi Heinrich,
Quoted 52 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 19:18
To: Pragnesh Patel <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>;
rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 36 lines · Pragnesh Patel
Hi Heinrich,
Quoted 22 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>Quoted 7 lines
The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks()is depend ongd->timerand there are 2 cases1) if gd->timer== NULL then
dm_timer_init()gets called and it will call functions which are not marked with "notrace" so tracing got stuck.
Quoted 7 lines
Quoted 5 lines
Thanks for the background information.
Please, identify the existing functions that lack "notrace" and fix them. This will give us a solution for all existing boards and not for a small selection. Furthermore it will avoid code duplication.
I tried but There are so many functions which need "notrace".
Let's start with the problem statement:
When tracing functions is enabled this adds calls to __cyg_profile_func_enter() and __cyg_profile_func_exit() to the traced functions.
__cyg_profile_func_exit() and __cyg_profile_func_exit() invoke timer_get_us() to record the entry and exit time.
If timer_get_us() or any function used to implement does not carry __attribute__((no_instrument_function)) this will lead to an indefinite recursion.
We have to change __cyg_profile_func_enter() and __cyg_profile_func_exit() such that during their execution no function is traced. We can do so by temporarily setting trace_enabled to false.
Does this match your observation?
Best regards
Heinrich
Quoted 195 lines
Why don?t we consider removing gd->timer=NULL in
initr_dm()initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}Or I can use
TIMER_EARLYand return ticks and rate by addingtimer_early_get_count()andtimer_early_get_rate()repectively.Suggestions are welcome
Quoted 180 lines
In
lib/trace.cconsider replacing "__attribute__((no_instrument_function))" by "notrace".Best regards
Heinrich
Quoted 172 lines
2) if
gd->timeris already initialized then stillinitr_dm()will makegd->timer= NULL;
initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}So again
dm_timer_init()gets called and tracing got stuck.So I thought better to implement
timer_get_us().Quoted 156 lines
Best regards
Heinrich
Quoted 151 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +3
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26 ,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = {.get_count = andes_plmt_get_count, };drivers/timer/andes_plmt_timer.c +15
-0+#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +3
-2@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23 ,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = {.get_count = sifive_clint_get_count, };drivers/timer/sifive_clint_timer.c +15
-0+#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Quoted 76 lines · Heinrich Schuchardt
Quoted 54 lines · Pragnesh Patel
Hi Heinrich,
Quoted 52 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 19:18
To: Pragnesh Patel <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>;
rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 36 lines · Pragnesh Patel
Hi Heinrich,
Quoted 22 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>Quoted 7 lines
The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks()is depend ongd->timerand there are 2 cases1) if gd->timer== NULL then
dm_timer_init()gets called and it will call functions which are not marked with "notrace" so tracing got stuck.Quoted 7 lines
Quoted 5 lines
Thanks for the background information.
Please, identify the existing functions that lack "notrace" and fix them. This will give us a solution for all existing boards and not for a small selection. Furthermore it will avoid code duplication.
I tried but There are so many functions which need "notrace".
Let's start with the problem statement:
When tracing functions is enabled this adds calls to
__cyg_profile_func_enter()and__cyg_profile_func_exit()to the traced functions.
__cyg_profile_func_exit()and__cyg_profile_func_exit()invoketimer_get_us()to record the entry and exit time.If
timer_get_us()or any function used to implement does not carry __attribute__((no_instrument_function)) this will lead to an indefinite recursion.
Quoted 5 lines
We have to change
__cyg_profile_func_enter()and__cyg_profile_func_exit()such that during their execution no function is traced. We can do so by temporarily settingtrace_enabledto false.Does this match your observation?
I just tried to put this into a patch
[PATCH 1/1] trace: avoid infinite recursion
https://lists.denx.de/pipermail/u-boot/2020-November/432589.html
https://patchwork.ozlabs.org/project/uboot/patch/20201112071411.4202-1-xypron.glpk at gmx.de/
Does this solve you problem?
Best regards
Heinrich
Quoted 197 lines
Quoted 196 lines
Why don?t we consider removing gd->timer=NULL in
initr_dm()initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}Or I can use
TIMER_EARLYand return ticks and rate by addingtimer_early_get_count()andtimer_early_get_rate()repectively.Suggestions are welcome
Quoted 180 lines
In
lib/trace.cconsider replacing "__attribute__((no_instrument_function))" by "notrace".Best regards
Heinrich
Quoted 172 lines
2) if
gd->timeris already initialized then stillinitr_dm()will makegd->timer= NULL;
initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}So again
dm_timer_init()gets called and tracing got stuck.So I thought better to implement
timer_get_us().Quoted 156 lines
Best regards
Heinrich
Quoted 151 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +3
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +3
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26 ,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = {.get_count = andes_plmt_get_count, };drivers/timer/andes_plmt_timer.c +15
-0+#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +3
-2@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23 ,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = {.get_count = sifive_clint_get_count, };drivers/timer/sifive_clint_timer.c +15
-0+#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Heinrich,
Quoted 98 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 12 November 2020 12:49
To: Pragnesh Patel <[email protected]>; Simon Glass <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>;
rick at andestech.com; Sean Anderson <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 52 lines · Heinrich Schuchardt
Quoted 51 lines · Pragnesh Patel
Hi Heinrich,
Quoted 49 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 19:18
To: Pragnesh Patel <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 34 lines · Pragnesh Patel
Hi Heinrich,
Quoted 22 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>Quoted 7 lines
The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks()is depend ongd->timerand there are 2 casesQuoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
1) if gd->timer== NULL then
dm_timer_init()gets called and it will call functions which are not marked with "notrace" so tracing got stuck.Thanks for the background information.
Please, identify the existing functions that lack "notrace" and fix them. This will give us a solution for all existing boards and not for a small
selection.
Quoted 17 lines
Quoted 3 lines
Quoted 1 line
Furthermore it will avoid code duplication.
I tried but There are so many functions which need "notrace".
Let's start with the problem statement:
When tracing functions is enabled this adds calls to
__cyg_profile_func_enter()and__cyg_profile_func_exit()to the traced functions.
__cyg_profile_func_exit()and__cyg_profile_func_exit()invoketimer_get_us()to record the entry and exit time.If
timer_get_us()or any function used to implement does not carry __attribute__((no_instrument_function)) this will lead to an indefinite recursion.Quoted 5 lines
We have to change
__cyg_profile_func_enter()and__cyg_profile_func_exit()such that during their execution no function is traced. We can do so by temporarily settingtrace_enabledto false.Does this match your observation?
Quoted 8 lines
I just tried to put this into a patch
[PATCH 1/1] trace: avoid infinite recursion https://lists.denx.de/pipermail/u-
boot/2020-November/432589.html
https://patchwork.ozlabs.org/project/uboot/patch/20201112071411.4202-1-
xypron.glpk at gmx.de/Does this solve you problem?
Getting error, "Could not initialize timer (err -11)" from get_ticks() function.
Below are my boot logs,
U-Boot 2021.01-rc1-00244-g794c155581-dirty (Nov 12 2020 - 12:56:27 +0530)
CPU: rv64imafdc Model: SiFive HiFive Unleashed A00 DRAM: 8 GiB trace: enabled
Could not initialize timer (err -11)
Could not initialize timer (err -11)
Could not initialize timer (err -11)
Could not initialize timer (err -11)
Quoted 204 lines
Best regards
Heinrich
Quoted 62 lines
Quoted 62 lines
Why don?t we consider removing gd->timer=NULL in
initr_dm()initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}Or I can use
TIMER_EARLYand return ticks and rate by addingtimer_early_get_count()andtimer_early_get_rate()repectively.Suggestions are welcome
Quoted 47 lines
In
lib/trace.cconsider replacing "__attribute__((no_instrument_function))" by "notrace".Best regards
Heinrich
Quoted 39 lines
2) if
gd->timeris already initialized then stillinitr_dm()will makegd->timer= NULL;
initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}So again
dm_timer_init()gets called and tracing got stuck.So I thought better to implement
timer_get_us().Quoted 23 lines
Best regards
Heinrich
Quoted 18 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef
Quoted 6 lines
arch/riscv/include/asm/global_data.h +0
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef
CONFIG_ANDES_PLICQuoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
Quoted 61 lines
arch/riscv/include/asm/global_data.h +3
-0void __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +3
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26 ,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = {.get_count = andes_plmt_get_count, };drivers/timer/andes_plmt_timer.c +15
-0+#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +1
-0@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice
Quoted 6 lines
drivers/timer/riscv_timer.c +1
-1-static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice*dev)
Quoted 63 lines
Quoted 62 lines
Quoted 61 lines
Quoted 61 lines
Quoted 60 lines
Quoted 60 lines
drivers/timer/riscv_timer.c +10
-0return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED(RISCV_SMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +3
-2@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23 ,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = {.get_count = sifive_clint_get_count, };drivers/timer/sifive_clint_timer.c +15
-0+#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Quoted 134 lines
-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Pragnesh Patel
Sent: 12 November 2020 13:06
To: Heinrich Schuchardt <[email protected]>; Simon Glass <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>;
rick at andestech.com; Sean Anderson <[email protected]>
Subject: RE: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingHi Heinrich,
Quoted 12 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 12 November 2020 12:49
To: Pragnesh Patel <[email protected]>; Simon Glass <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingQuoted 58 lines
[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 54 lines · Heinrich Schuchardt
Quoted 53 lines · Pragnesh Patel
Hi Heinrich,
Quoted 51 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 19:18
To: Pragnesh Patel <[email protected]>
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; u-boot at lists.denx.de; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 36 lines · Pragnesh Patel
Hi Heinrich,
Quoted 22 lines
-----Original Message-----
From: Heinrich Schuchardt <[email protected]>
Sent: 11 November 2020 16:51
To: Pragnesh Patel <[email protected]>; u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; Paul Walmsley ( Sifive) <[email protected]>; anup.patel at wdc.com; Sagar Kadam <[email protected]>; rick at andestech.com; Sean Anderson <[email protected]>; Simon Glass <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Quoted 5 lines · Pragnesh Patel
Add
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>Quoted 7 lines
The default implementation of
get_timer_us()inlib/time.ccallsget_ticks()which callstimer_get_count(). Theget_count()operation is implemented indrivers/timer/andes_plmt_timer.c,drivers/timer/sifive_clint_timer.c,drivers/timer/riscv_timer.c.Why do you need special
timer_get_us()implementations? Isn't it enough to supply theget_count()operation in the drivers?
get_ticks()is depend ongd->timerand there are 2 cases1) if gd->timer== NULL then
dm_timer_init()gets called and it will call functions which are not marked with "notrace" so tracing gotstuck.
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Thanks for the background information.
Please, identify the existing functions that lack "notrace" and fix them. This will give us a solution for all existing boards and not for a small
selection.
Quoted 17 lines
Quoted 3 lines
Quoted 1 line
Furthermore it will avoid code duplication.
I tried but There are so many functions which need "notrace".
Let's start with the problem statement:
When tracing functions is enabled this adds calls to
__cyg_profile_func_enter()and__cyg_profile_func_exit()to the traced functions.
__cyg_profile_func_exit()and__cyg_profile_func_exit()invoketimer_get_us()to record the entry and exit time.If
timer_get_us()or any function used to implement does not carry __attribute__((no_instrument_function)) this will lead to an indefinite recursion.Quoted 5 lines
We have to change
__cyg_profile_func_enter()and__cyg_profile_func_exit()such that during their execution no function is traced. We can do so by temporarily settingtrace_enabledto false.Does this match your observation?
I just tried to put this into a patch
Quoted 7 lines
[PATCH 1/1] trace: avoid infinite recursion
https://lists.denx.de/pipermail/u-
boot/2020-November/432589.html
https://patchwork.ozlabs.org/project/uboot/patch/20201112071411.4202-1-
xypron.glpk at gmx.de/Does this solve you problem?
Getting error, "Could not initialize timer (err -11)" from
get_ticks()function.Below are my boot logs,
U-Boot 2021.01-rc1-00244-g794c155581-dirty (Nov 12 2020 - 12:56:27 +0530)
CPU: rv64imafdc Model: SiFive HiFive Unleashed A00 DRAM: 8 GiB trace: enabled
Quoted 7 lines
Could not initialize timer (err -11)
Could not initialize timer (err -11)
Could not initialize timer (err -11)
Could not initialize timer (err -11)
With Further debugging, this is because gd->dm_root is equal to NULL by initr_dm(). dm_timer_init() will fail if gd->dm_root == NULL.
int notrace dm_timer_init(void)
{
if (gd->dm_root == NULL)
return -EAGAIN;
}So the solution is to call initr_dm() before initr_trace() so that gd->dm_root will become available. I will send a patch to do the same.
Quoted 209 lines
Quoted 209 lines
Best regards
Heinrich
Quoted 62 lines
Quoted 62 lines
Why don?t we consider removing gd->timer=NULL in
initr_dm()initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}Or I can use
TIMER_EARLYand return ticks and rate by addingtimer_early_get_count()andtimer_early_get_rate()repectively.Suggestions are welcome
Quoted 47 lines
In
lib/trace.cconsider replacing "__attribute__((no_instrument_function))" by "notrace".Best regards
Heinrich
Quoted 39 lines
2) if
gd->timeris already initialized then stillinitr_dm()will makegd->timer= NULL;
initr_dm()
{#ifdef CONFIG_TIMER gd->timer = NULL;#endif
}So again
dm_timer_init()gets called and tracing got stuck.So I thought better to implement
timer_get_us().Quoted 23 lines
Best regards
Heinrich
Quoted 18 lines
---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef
Quoted 6 lines
arch/riscv/include/asm/global_data.h +0
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef
CONFIG_ANDES_PLICQuoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
arch/riscv/include/asm/global_data.h +3
-0void __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT +void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +3
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26 ,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = {.get_count = andes_plmt_get_count, };drivers/timer/andes_plmt_timer.c +15
-0+#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +1
-0@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/timer/riscv_timer.c +1
-1-static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(structudevice
*dev)
Quoted 64 lines
Quoted 63 lines
Quoted 62 lines
Quoted 62 lines
Quoted 61 lines
Quoted 61 lines
return ((u64)hi << 32) | lo;}
drivers/timer/riscv_timer.c +10
-0+#if CONFIG_IS_ENABLED(RISCV_SMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) { struct timer_dev_priv *uc_priv =
dev_get_uclass_priv(dev); diff --gita/drivers/timer/sifive_clint_timer.cb/drivers/timer/sifive_clint_timer.c
index00ce0f08d6..c341f7789b100644drivers/timer/sifive_clint_timer.c +3
-2@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23 ,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = {.get_count = sifive_clint_get_count, };drivers/timer/sifive_clint_timer.c +15
-0+#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); }
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Pragnesh
Quoted 35 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com; bmeng.cn at gmail.com; paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing. For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0
arch/riscv/include/asm/global_data.h struct arch_global_data { · line 27
Quoted 4 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data {#ifdef CONFIG_ANDES_PLIC void __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT
It shall be CONFIG_ANDES_PLMT, or it will compile fail as below:
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'struct arch_global_data' has no member named 'plmt'; did you mean 'plic'?
if (gd->arch.plmt) {
^~~~
plicdrivers/timer/andes_plmt_timer.c:37:52: error: 'struct arch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks = readq((void __iomem *)MTIME_REG(gd->arch.plmt));
And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/*
Maybe enable TIMER_EARLY and use timer_get_us() of /lib/time.c will be better. I also found that without dm_timer_init() in initf_dm(), andes_plmt_get_count() will be executed ahead of andes_plmt_probe().
Thanks,
Rick
Quoted 134 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP )struct ipi_data ipi[CONFIG_NR_CPUS ];#endif drivers/timer/andes_plmt_timer.c +18
-1@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) {return readq ((void __iomem *)MTIME_REG (dev->priv)); }@@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +13
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +18
-2@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) {return readq ((void __iomem *)MTIME_REG (dev->priv)); }@@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) +{ +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Rick,
Quoted 66 lines
-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 13 November 2020 13:37
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean Anderson <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Hi Pragnesh
Quoted 4 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;bmeng.cn at gmail.com;
Quoted 34 lines
paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef CONFIG_ANDES_PLIC · line 26
Quoted 3 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT It shall be
CONFIG_ANDES_PLMT, or it will compile fail as below:
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
Quoted 6 lines
if (gd->arch.plmt) { ^~~~ plic
drivers/timer/andes_plmt_timer.c:37:52: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks =readq((void __iomem *)MTIME_REG(gd->arch.plmt));
No I did not get this. Why are you getting this error because plmt is already defined ?
Quoted 6 lines
And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/* Maybe enable
TIMER_EARLYand usetimer_get_us()of/lib/time.cwill be better.
I also found that withoutdm_timer_init()ininitf_dm(),andes_plmt_get_count()will be executed ahead ofandes_plmt_probe().
Thanks Rick but me and Heinrich are working on different approach to use existing dm_timer_init() from lib/time.c
https://patchwork.ozlabs.org/project/uboot/patch/20201112071411.4202-1-xypron.glpk at gmx.de/
Quoted 127 lines
Thanks,
RickQuoted 122 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.cindexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +17
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +17
-3@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Pragnesh
Quoted 64 lines
Hi Rick,
Quoted 62 lines
-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 13 November 2020 13:37
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean Anderson <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Hi Pragnesh
Quoted 4 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;bmeng.cn at gmail.com;
Quoted 34 lines
paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef CONFIG_ANDES_PLIC · line 26
Quoted 3 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT It shall be
CONFIG_ANDES_PLMT, or it will compile fail as below:
Sorry, it's shall be CONFIG_ANDES_PLMT_TIMER here // because of obj-$(CONFIG_ANDES_PLMT_TIMER) += andes_plmt_timer.o Or it will have a compiling error.
Quoted 20 lines
Quoted 10 lines
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?if (gd->arch.plmt) { ^~~~ plic
drivers/timer/andes_plmt_timer.c:37:52: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks =readq((void __iomem *)MTIME_REG(gd->arch.plmt));No I did not get this. Why are you getting this error because plmt is already defined ?
Quoted 6 lines
And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/* Maybe enable
TIMER_EARLYand usetimer_get_us()of/lib/time.cwill be better.
I also found that withoutdm_timer_init()ininitf_dm(),andes_plmt_get_count()will be executed ahead ofandes_plmt_probe().
Quoted 3 lines
Thanks Rick but me and Heinrich are working on different approach to use existing
dm_timer_init()fromlib/time.chttps://patchwork.ozlabs.org/project/uboot/patch/20201112071411.4202-1-xypron.glpk at gmx.de/
OK
Thanks,
Rick
Quoted 128 lines
Quoted 128 lines
Thanks,
RickQuoted 122 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.cindexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +17
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +17
-3@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
In reply to Rick ChenHi Rick,
Quoted 69 lines
-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 13 November 2020 13:37
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean Anderson <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Hi Pragnesh
Quoted 4 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;bmeng.cn at gmail.com;
Quoted 34 lines
paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef CONFIG_ANDES_PLIC · line 26
Quoted 3 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT It shall be
CONFIG_ANDES_PLMT, or it will compile fail as below:
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?if (gd->arch.plmt) { ^~~~ plic
Quoted 7 lines
drivers/timer/andes_plmt_timer.c:37:52: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks =readq((void __iomem *)MTIME_REG(gd->arch.plmt));And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/* Maybe enable
TIMER_EARLYand usetimer_get_us()of/lib/time.cwill be better.
I am planning to use TIMER_EARLY for tracing.
With TIMER_EARLY, I need to implement timer_early_get_rate() and timer_early_get_count()
For timer_early_get_count(), I need PLMT or CLINT base address to read mtime register. So I think it's better to save base address in gd->arch.clint or gd->arch.plmt.
Let me know if you have any other idea to save PLM or CLINT base address.
For timer_early_get_rate(), I will add new variable in global data (gd)
Like, gd->arch.clock_rate; /* Clock rate of timer in Hz */
This will return Timer frequency in Hz.
Tracing is only useful in U-Boot not in U-Boot SPL so I am doing this for M mode U-boot and S mode U-Boot.
Quoted 2 lines
I also found that without
dm_timer_init()ininitf_dm(),andes_plmt_get_count()will be executed ahead ofandes_plmt_probe().
If andes_plmt_get_count() executed before andes_plmt_probe() then how did it will get PLMT base address ?
Quoted 127 lines
Thanks,
RickQuoted 122 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.cindexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +17
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +17
-3@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
On Tue, Nov 17, 2020 at 08:30:21AM +0000, Pragnesh Patel wrote:
Hi Pragnesh,
Quoted 75 lines
Hi Rick,
Quoted 73 lines
-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 13 November 2020 13:37
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean Anderson <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Hi Pragnesh
Quoted 4 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;bmeng.cn at gmail.com;
Quoted 34 lines
paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef CONFIG_ANDES_PLIC · line 26
Quoted 3 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT It shall be
CONFIG_ANDES_PLMT, or it will compile fail as below:
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?if (gd->arch.plmt) { ^~~~ plic
drivers/timer/andes_plmt_timer.c:37:52: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks =readq((void __iomem *)MTIME_REG(gd->arch.plmt));
This patch will cause compile error with ae350 defconfig.
${uboot}/drivers/timer/Makefile is articulated in this way, "obj-$(CONFIG_ANDES_PLMT_TIMER) += andes_plmt_timer.o",
so the #ifdef indicator in ${uboot}/arch/riscv/include/asm/global_data.h should use CONFIG_ANDES_PLMT_TIMER.
Best regards,
Leo
Quoted 153 lines
Quoted 3 lines
And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/* Maybe enable
TIMER_EARLYand usetimer_get_us()of/lib/time.cwill be better.I am planning to use
TIMER_EARLYfor tracing.With
TIMER_EARLY, I need to implementtimer_early_get_rate()andtimer_early_get_count()For
timer_early_get_count(), I need PLMT or CLINT base address to read mtime register. So I think it's better to save base address ingd->arch.clintorgd->arch.plmt.Let me know if you have any other idea to save PLM or CLINT base address.
For
timer_early_get_rate(), I will add new variable in global data (gd)
Like,gd->arch.clock_rate; /* Clock rate of timer in Hz */
This will return Timer frequency in Hz.Tracing is only useful in U-Boot not in U-Boot SPL so I am doing this for M mode U-boot and S mode U-Boot.
Quoted 2 lines
I also found that without
dm_timer_init()ininitf_dm(),andes_plmt_get_count()will be executed ahead ofandes_plmt_probe().If
andes_plmt_get_count()executed beforeandes_plmt_probe()then how did it will get PLMT base address ?Quoted 127 lines
Thanks,
RickQuoted 122 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.cindexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +17
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }drivers/timer/riscv_timer.c +12
-1@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> -static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice *dev)return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED (RISCV_SMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +17
-3@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED (RISCV_MMODE ) +unsigned long notrace timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Leo,
Quoted 96 lines
-----Original Message-----
From: Leo Liang <[email protected]>
Sent: 23 November 2020 11:28
To: Pragnesh Patel <[email protected]>
Cc: Rick Chen <[email protected]>; U-Boot Mailing List <u- boot at lists.denx.de>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean Anderson <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
On Tue, Nov 17, 2020 at 08:30:21AM +0000, Pragnesh Patel wrote:
Hi Pragnesh,
Quoted 11 lines
Hi Rick,
Quoted 9 lines
-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 13 November 2020 13:37
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean AndersonQuoted 54 lines
Quoted 54 lines
rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Hi Pragnesh
Quoted 4 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;bmeng.cn at gmail.com;
Quoted 34 lines
paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef CONFIG_ANDES_PLIC · line 26
Quoted 3 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT It shall be
CONFIG_ANDES_PLMT, or it will compile fail as below:Quoted 10 lines
Quoted 10 lines
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?if (gd->arch.plmt) { ^~~~ plic
drivers/timer/andes_plmt_timer.c:37:52: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks =readq((void __iomem *)MTIME_REG(gd->arch.plmt));
Quoted 6 lines
This patch will cause compile error with ae350 defconfig.
${uboot}/drivers/timer/Makefile is articulated in this way, "obj-$(CONFIG_ANDES_PLMT_TIMER) += andes_plmt_timer.o", so the #ifdef indicator in
${uboot}/arch/riscv/include/asm/global_data.hshould useCONFIG_ANDES_PLMT_TIMER.
Thanks Leo but Rick has already informed about this error.
I have discarded this series and added a new patch for Tracing which uses TIMER_EARLY
https://patchwork.ozlabs.org/project/uboot/patch/20201117110508.25819-1-pragnesh.patel at sifive.com/
Quoted 160 lines
Best regards,
LeoQuoted 10 lines
Quoted 3 lines
And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/* Maybe enable
TIMER_EARLYand usetimer_get_us()of/lib/time.cwill be better.I am planning to use
TIMER_EARLYfor tracing.With
TIMER_EARLY, I need to implementtimer_early_get_rate()andtimer_early_get_count()For
timer_early_get_count(), I need PLMT or CLINT base address to read mtimeregister.
Quoted 79 lines
So I think it's better to save base address in
gd->arch.clintorgd->arch.plmt.Let me know if you have any other idea to save PLM or CLINT base address.
For
timer_early_get_rate(), I will add new variable in global data (gd)
Like,gd->arch.clock_rate; /* Clock rate of timer in Hz */
This will return Timer frequency in Hz.Tracing is only useful in U-Boot not in U-Boot SPL so I am doing this for M mode U-boot and S mode U-Boot.
Quoted 2 lines
I also found that without
dm_timer_init()ininitf_dm(),andes_plmt_get_count()will be executed ahead ofandes_plmt_probe().If
andes_plmt_get_count()executed beforeandes_plmt_probe()then how did it will get PLMT base address ?Quoted 62 lines
Thanks,
RickQuoted 57 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +17
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +1
-0@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> Quoted 6 lines
Quoted 6 lines
drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice
Quoted 6 lines
drivers/timer/riscv_timer.c +1
-1-static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice*dev)
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
drivers/timer/riscv_timer.c +10
-0return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED(RISCV_SMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +17
-3@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1
PATCH v3 1/1 riscv: Add timer_get_us() for tracing
Hi Pragnesh,
Quoted 105 lines · Pragnesh Patel
Hi Leo,
Quoted 96 lines
-----Original Message-----
From: Leo Liang <[email protected]>
Sent: 23 November 2020 11:28
To: Pragnesh Patel <[email protected]>
Cc: Rick Chen <[email protected]>; U-Boot Mailing List <u- boot at lists.denx.de>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean Anderson <[email protected]>; rick <[email protected]>; Alan Kao <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
On Tue, Nov 17, 2020 at 08:30:21AM +0000, Pragnesh Patel wrote:
Hi Pragnesh,
Quoted 11 lines
Hi Rick,
Quoted 9 lines
-----Original Message-----
From: Rick Chen <[email protected]>
Sent: 13 November 2020 13:37
To: Pragnesh Patel <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Atish Patra <[email protected]>; palmerdabbelt at google.com; Bin Meng <[email protected]>; Paul Walmsley ( Sifive) <[email protected]>; Anup Patel <[email protected]>; Sagar Kadam <[email protected]>; Sean AndersonQuoted 54 lines
Quoted 54 lines
rick <[email protected]>; Alan Kao <[email protected]>; Leo Liang <[email protected]>
Subject: Re: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracing[External Email] Do not click links or attachments unless you recognize the sender and know the content is safe
Hi Pragnesh
Quoted 4 lines
From: Pragnesh Patel [mailto:pragnesh.patel at sifive.com]
Sent: Wednesday, November 11, 2020 6:15 PM
To: u-boot at lists.denx.de
Cc: atish.patra at wdc.com; palmerdabbelt at google.com;bmeng.cn at gmail.com;
Quoted 34 lines
paul.walmsley at sifive.com; anup.patel at wdc.com; sagar.kadam at sifive.com; Rick Jian-Zhi Chen(???); Pragnesh Patel; Sean Anderson; Heinrich Schuchardt; Simon Glass
Subject: [PATCH v3 1/1] riscv: Addtimer_get_us()for tracingAdd
timer_get_us()which is useful for tracing.
For S-mode U-Boot,CSR_TIMEHandCSR_TIMEwill provide a timer ticks and For M-mode U-Boot, mtime register will provide the same.Signed-off-by Pragnesh Patel <[email protected]>---
Changes in v3:
- Addedgd->arch.plmtin global data
- Fortimer_get_us(), usereadq()instead ofandes_plmt_get_count()andsifive_clint_get_count()Changes in v2:
- Addedtimer_get_us()inriscv_timer.c,sifive_clint_timer.candandes_plmt_timer.c.arch/riscv/include/asm/global_data.h | 3 +++ drivers/timer/andes_plmt_timer.c | 19 ++++++++++++++++++- drivers/timer/riscv_timer.c | 14 +++++++++++++- drivers/timer/sifive_clint_timer.c | 19 ++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-)arch/riscv/include/asm/global_data.h +0
-0arch/riscv/include/asm/global_data.h struct arch_global_data { #ifdef CONFIG_ANDES_PLIC · line 26
Quoted 3 lines
arch/riscv/include/asm/global_data.h +1
-0@@ -24,6 +24,9 @@ struct arch_global_data { #ifdef CONFIG_ANDES_PLICvoid __iomem *plic;/* plic base address */ #endif +#ifdef CONFIG_ANDES_PLMT It shall be
CONFIG_ANDES_PLMT, or it will compile fail as below:Quoted 10 lines
Quoted 10 lines
drivers/timer/andes_plmt_timer.c: In function 'timer_get_us':drivers/timer/andes_plmt_timer.c:36:15: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?if (gd->arch.plmt) { ^~~~ plic
drivers/timer/andes_plmt_timer.c:37:52: error: 'structarch_global_data' has no member named 'plmt'; did you mean 'plic'?
ticks =readq((void __iomem *)MTIME_REG(gd->arch.plmt));Quoted 6 lines
This patch will cause compile error with ae350 defconfig.
${uboot}/drivers/timer/Makefile is articulated in this way, "obj-$(CONFIG_ANDES_PLMT_TIMER) += andes_plmt_timer.o", so the #ifdef indicator in
${uboot}/arch/riscv/include/asm/global_data.hshould useCONFIG_ANDES_PLMT_TIMER.
Quoted 5 lines
Thanks Leo but Rick has already informed about this error.
I have discarded this series and added a new patch for Tracing which uses
TIMER_EARLY
https://patchwork.ozlabs.org/project/uboot/patch/20201117110508.25819-1-pragnesh.patel at sifive.com/
Got it! Thanks for the explanation,
Best regards,
Leo
Quoted 160 lines
Quoted 160 lines
Best regards,
LeoQuoted 10 lines
Quoted 3 lines
And it is not proper to have dependency of data structure between /arch/riscv/include/asm/* and /drivers/timer/* Maybe enable
TIMER_EARLYand usetimer_get_us()of/lib/time.cwill be better.I am planning to use
TIMER_EARLYfor tracing.With
TIMER_EARLY, I need to implementtimer_early_get_rate()andtimer_early_get_count()For
timer_early_get_count(), I need PLMT or CLINT base address to read mtimeregister.
Quoted 79 lines
So I think it's better to save base address in
gd->arch.clintorgd->arch.plmt.Let me know if you have any other idea to save PLM or CLINT base address.
For
timer_early_get_rate(), I will add new variable in global data (gd)
Like,gd->arch.clock_rate; /* Clock rate of timer in Hz */
This will return Timer frequency in Hz.Tracing is only useful in U-Boot not in U-Boot SPL so I am doing this for M mode U-boot and S mode U-Boot.
Quoted 2 lines
I also found that without
dm_timer_init()ininitf_dm(),andes_plmt_get_count()will be executed ahead ofandes_plmt_probe().If
andes_plmt_get_count()executed beforeandes_plmt_probe()then how did it will get PLMT base address ?Quoted 62 lines
Thanks,
RickQuoted 57 lines
arch/riscv/include/asm/global_data.h +2
-0+void __iomem *plmt;/* plmt base address */ +#endif #if CONFIG_IS_ENABLED (SMP ) struct ipi_data ipi[CONFIG_NR_CPUS]; #endif diff --git
a/drivers/timer/andes_plmt_timer.cb/drivers/timer/andes_plmt_timer.c
indexcec86718c7..7c50c46d9e100644drivers/timer/andes_plmt_timer.c +17
-2@@ -13,11 +13,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base)) -static u64 andes_plmt_get_count (struct udevice *dev) +static u64 notrace andes_plmt_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -26,12 +27,28 @@ static const struct timer_ops andes_plmt_ops = { .get_count = andes_plmt_get_count, }; +#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.plmt should contain valid base address */ +if (gd->arch.plmt) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.plmt)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int andes_plmt_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.plmt = dev->priv;return timer_timebase_fallback (dev); }(quoted diff) +0
-0
b/drivers/timer/riscv_timer.cindex21ae184057..7fa8773da3100644drivers/timer/riscv_timer.c +1
-0@@ -15,8 +15,9 @@#include <errno.h> #include <timer.h> #include <asm/csr.h> +#include <div64.h> Quoted 6 lines
Quoted 6 lines
drivers/timer/riscv_timer.c static u64 riscv_timer_get_count(struct udevice
Quoted 6 lines
drivers/timer/riscv_timer.c +1
-1-static u64 riscv_timer_get_count (struct udevice *dev) +static u64 notrace riscv_timer_get_count(struct udevice *dev) {__maybe_unused u32 hi, lo;@@ -31,6 +32,17 @@ static u64 riscv_timer_get_count(struct udevice*dev)
Quoted 59 lines
Quoted 59 lines
Quoted 59 lines
drivers/timer/riscv_timer.c +10
-0return ((u64 )hi <<32 ) | lo; } +#if CONFIG_IS_ENABLED(RISCV_SMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + + ticks =riscv_timer_get_count (NULL ); +do_div (ticks,CONFIG_SYS_HZ ); +return ticks; +} +#endif +static int riscv_timer_probe (struct udevice *dev) {struct timer_dev_priv *uc_priv =dev_get_uclass_priv (dev);drivers/timer/sifive_clint_timer.c +17
-3@@ -10,11 +10,12 @@#include <timer.h> #include <asm/io.h> #include <linux/err.h> +#include <div64.h> /* mtime register */ #define MTIME_REG (base) ((ulong)(base) + 0xbff8) -static u64 sifive_clint_get_count (struct udevice *dev) +static u64 notrace sifive_clint_get_count(struct udevice *dev) { return readq((void __iomem *)MTIME_REG(dev->priv)); } @@ -23,12 +24,28 @@ static const struct timer_ops sifive_clint_ops = { .get_count = sifive_clint_get_count, }; +#if CONFIG_IS_ENABLED(RISCV_MMODE) unsigned long notrace +timer_get_us (void ) { +u64 ticks; + +/* FIXME: gd->arch.clint should contain valid base address */ +if (gd->arch.clint) { + ticks =readq ((void __iomem *)MTIME_REG (gd->arch.clint)); +do_div (ticks,CONFIG_SYS_HZ ); + } + +return ticks; +} +#endif +static int sifive_clint_probe (struct udevice *dev) { dev->priv =dev_read_addr_ptr (dev);if (!dev->priv)return -EINVAL ; + gd->arch.clint = dev->priv;return timer_timebase_fallback (dev); } --2.17.1