diff mbox

[U-Boot,v1,(WIP),08/16,Timer] Create new userland timer API

Message ID 1309261269-4363-9-git-send-email-graeme.russ@gmail.com
State RFC
Headers show

Commit Message

Graeme Russ June 28, 2011, 11:41 a.m. UTC
Signed-off-by: Graeme Russ <graeme.russ@gmail.com>
---
 include/common.h |   36 ++++++++++++++++++++----------------
 lib/time.c       |   26 ++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 16 deletions(-)

Comments

Simon Glass June 29, 2011, 4:31 a.m. UTC | #1
Hi Graeme,

What a mammoth effort and what a fantastic clean up.

I'm a bit unsure of this patch which seems to have two prototypes for
the since functions:

On Tue, Jun 28, 2011 at 4:41 AM, Graeme Russ <graeme.russ@gmail.com> wrote:
>
> Signed-off-by: Graeme Russ <graeme.russ@gmail.com>
> ---
>  include/common.h |   36 ++++++++++++++++++++----------------
>  lib/time.c       |   26 ++++++++++++++++++++++++++
>  2 files changed, 46 insertions(+), 16 deletions(-)
>
> diff --git a/include/common.h b/include/common.h
> index 340e585..9735d47 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -584,11 +584,29 @@ void      timer_interrupt    (struct pt_regs *);
>  void   external_interrupt (struct pt_regs *);
>  void   irq_install_handler(int, interrupt_handler_t *, void *);
>  void   irq_free_handler   (int);
> -void   reset_timer        (void);
> -ulong  get_timer          (ulong base);
>  void   enable_interrupts  (void);
>  int    disable_interrupts (void);
>
> +/*
> + * Timer API
> + */
> +void reset_timer (void);
> +ulong get_timer (ulong base);
> +u64 get_ticks(void);
> +void wait_ticks(unsigned long);
> +void __udelay(unsigned long);
> +ulong usec2ticks(unsigned long usec);
> +ulong ticks2usec(unsigned long ticks);
> +int init_timebase(void);
> +
> +/* lib/time.c */
> +void udelay(unsigned long);
> +
> +u32 time_now_ms(void);
> +u32 time_since_ms(u32 from, u32 to);
> +u32 time_max_since_ms(u32 from, u32 to);

Here they have two parameters

> +u32 time_resolution_ms(void);
> +
>  /* $(CPU)/.../commproc.c */
>  int    dpram_init (void);
>  uint   dpram_base(void);
> @@ -616,17 +634,6 @@ void       flush_cache   (unsigned long, unsigned long);
>  void   flush_dcache_range(unsigned long start, unsigned long stop);
>  void   invalidate_dcache_range(unsigned long start, unsigned long stop);
>
> -
> -/* arch/$(ARCH)/lib/ticks.S */
> -unsigned long long get_ticks(void);
> -void   wait_ticks    (unsigned long);
> -
> -/* arch/$(ARCH)/lib/time.c */
> -void   __udelay      (unsigned long);
> -ulong  usec2ticks    (unsigned long usec);
> -ulong  ticks2usec    (unsigned long ticks);
> -int    init_timebase (void);
> -
>  /* lib/gunzip.c */
>  int gunzip(void *, int, unsigned char *, unsigned long *);
>  int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
> @@ -644,9 +651,6 @@ void qsort(void *base, size_t nmemb, size_t size,
>           int(*compar)(const void *, const void *));
>  int strcmp_compar(const void *, const void *);
>
> -/* lib/time.c */
> -void   udelay        (unsigned long);
> -
>  /* lib/vsprintf.c */
>  ulong  simple_strtoul(const char *cp,char **endp,unsigned int base);
>  int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
> diff --git a/lib/time.c b/lib/time.c
> index a309c26..1563507 100644
> --- a/lib/time.c
> +++ b/lib/time.c
> @@ -41,3 +41,29 @@ void udelay(unsigned long usec)
>                usec -= kv;
>        } while(usec);
>  }
> +
> +u32 time_since_ms(u32 from)

and here only one (which is what I expect).

Can you please explain what I am missing?

Thanks,
Simon

> +{
> +       u32 delta = time_now_ms() - from;
> +
> +       /* round down */
> +       if (delta < time_ms_resolution())
> +               return 0;
> +
> +       return delta - time_resolution_ms();
> +}
> +
> +u32 time_max_since_ms(u32 from)
> +{
> +       u32 delta = time_now_ms() - from;
> +
> +       return delta + time_resolution_ms();
> +}
> +
> +__attribute__((weak))
> +u32 time_resolution_ms(void) {return 1;}
> +
> +u32 time_now_ms(void)
> +{
> +       return get_timer(0);
> +}
> --
> 1.7.5.2.317.g391b14
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>
Graeme Russ June 29, 2011, 4:36 a.m. UTC | #2
Hi Simon,

On Wed, Jun 29, 2011 at 2:31 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi Graeme,
>
> What a mammoth effort and what a fantastic clean up.
>
> I'm a bit unsure of this patch which seems to have two prototypes for
> the since functions:
>

[snip]

>> +u32 time_now_ms(void);
>> +u32 time_since_ms(u32 from, u32 to);
>> +u32 time_max_since_ms(u32 from, u32 to);
>
> Here they have two parameters
>

[snip]

>> +
>> +u32 time_since_ms(u32 from)
>
> and here only one (which is what I expect).
>
> Can you please explain what I am missing?

The fact I haven't tried to build it yet ;)

I'll add that to the list of fixes for v2 - Thanks

Regards,

Graeme
Simon Glass June 29, 2011, 4:48 a.m. UTC | #3
Hi Graeme,

On Tue, Jun 28, 2011 at 9:36 PM, Graeme Russ <graeme.russ@gmail.com> wrote:
> Hi Simon,
>> Can you please explain what I am missing?
>
> The fact I haven't tried to build it yet ;)

Oh, OK. That explains the mystery :-) I haven't built it yet either
but it certainly looks good.

Regards,
Simon

>
> I'll add that to the list of fixes for v2 - Thanks
>
> Regards,
>
> Graeme
>
Wolfgang Denk July 11, 2011, 10:05 p.m. UTC | #4
Dear Graeme Russ,

In message <1309261269-4363-9-git-send-email-graeme.russ@gmail.com> you wrote:
> 
> Signed-off-by: Graeme Russ <graeme.russ@gmail.com>

Please define "userland" in U-Boot context ?

> +u32 time_now_ms(void);
> +u32 time_since_ms(u32 from, u32 to);
> +u32 time_max_since_ms(u32 from, u32 to);
> +u32 time_resolution_ms(void);

I'm unhappy about these.  Sorry, but I don't want to have that.  See
previous message(s).

Best regards,

Wolfgang Denk
Graeme Russ July 11, 2011, 10:32 p.m. UTC | #5
Hi Wolfgang,

On 12/07/11 08:05, Wolfgang Denk wrote:
> Dear Graeme Russ,
> 
> In message <1309261269-4363-9-git-send-email-graeme.russ@gmail.com> you wrote:
>>
>> Signed-off-by: Graeme Russ <graeme.russ@gmail.com>
> 
> Please define "userland" in U-Boot context ?

Used outside of /arch (i.e. in board or driver code). Anything in arch/
binds the architecture specific implementation to lib/

>> +u32 time_now_ms(void);
>> +u32 time_since_ms(u32 from, u32 to);
>> +u32 time_max_since_ms(u32 from, u32 to);
>> +u32 time_resolution_ms(void);
> 
> I'm unhappy about these.  Sorry, but I don't want to have that.  See
> previous message(s).

Will do

Thanks,

Graeme
diff mbox

Patch

diff --git a/include/common.h b/include/common.h
index 340e585..9735d47 100644
--- a/include/common.h
+++ b/include/common.h
@@ -584,11 +584,29 @@  void	timer_interrupt	   (struct pt_regs *);
 void	external_interrupt (struct pt_regs *);
 void	irq_install_handler(int, interrupt_handler_t *, void *);
 void	irq_free_handler   (int);
-void	reset_timer	   (void);
-ulong	get_timer	   (ulong base);
 void	enable_interrupts  (void);
 int	disable_interrupts (void);
 
+/*
+ * Timer API
+ */
+void reset_timer (void);
+ulong get_timer (ulong base);
+u64 get_ticks(void);
+void wait_ticks(unsigned long);
+void __udelay(unsigned long);
+ulong usec2ticks(unsigned long usec);
+ulong ticks2usec(unsigned long ticks);
+int init_timebase(void);
+
+/* lib/time.c */
+void udelay(unsigned long);
+
+u32 time_now_ms(void);
+u32 time_since_ms(u32 from, u32 to);
+u32 time_max_since_ms(u32 from, u32 to);
+u32 time_resolution_ms(void);
+
 /* $(CPU)/.../commproc.c */
 int	dpram_init (void);
 uint	dpram_base(void);
@@ -616,17 +634,6 @@  void	flush_cache   (unsigned long, unsigned long);
 void	flush_dcache_range(unsigned long start, unsigned long stop);
 void	invalidate_dcache_range(unsigned long start, unsigned long stop);
 
-
-/* arch/$(ARCH)/lib/ticks.S */
-unsigned long long get_ticks(void);
-void	wait_ticks    (unsigned long);
-
-/* arch/$(ARCH)/lib/time.c */
-void	__udelay      (unsigned long);
-ulong	usec2ticks    (unsigned long usec);
-ulong	ticks2usec    (unsigned long ticks);
-int	init_timebase (void);
-
 /* lib/gunzip.c */
 int gunzip(void *, int, unsigned char *, unsigned long *);
 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
@@ -644,9 +651,6 @@  void qsort(void *base, size_t nmemb, size_t size,
 	   int(*compar)(const void *, const void *));
 int strcmp_compar(const void *, const void *);
 
-/* lib/time.c */
-void	udelay        (unsigned long);
-
 /* lib/vsprintf.c */
 ulong	simple_strtoul(const char *cp,char **endp,unsigned int base);
 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
diff --git a/lib/time.c b/lib/time.c
index a309c26..1563507 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -41,3 +41,29 @@  void udelay(unsigned long usec)
 		usec -= kv;
 	} while(usec);
 }
+
+u32 time_since_ms(u32 from)
+{
+	u32 delta = time_now_ms() - from;
+
+	/* round down */
+	if (delta < time_ms_resolution())
+		return 0;
+
+	return delta - time_resolution_ms();
+}
+
+u32 time_max_since_ms(u32 from)
+{
+	u32 delta = time_now_ms() - from;
+
+	return delta + time_resolution_ms();
+}
+
+__attribute__((weak))
+u32 time_resolution_ms(void) {return 1;}
+
+u32 time_now_ms(void)
+{
+	return get_timer(0);
+}