public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Graeme Russ <graeme.russ@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC][Timer API] Revised Specification -	Implementation details
Date: Wed, 15 Jun 2011 23:17:20 +1000	[thread overview]
Message-ID: <4DF8B0E0.2080006@gmail.com> (raw)
In-Reply-To: <20110530105704.0C83F14EBCB@gemini.denx.de>

Hi Wolfgang,

Since discussion seems to have died down, I have assumed pseudo consensus
and have started hitting the timer cleanup in earnest. All I can say is:

Wow! What a mess ;)

> We could also design a more complicated API like this one, but I doubt
> this is needed:

Well, it is needed if you are measuring how long something has taken (say
erasing a Flash, performing an I/O operation, profiling boot-up etc)

> 
> 	/*
> 	 * round - used to control rounding:
> 	 * <0 : round down, return time that has passed AT LEAST
> 	 * =0 : don't round, provide raw time difference
> 	 * >0 : round up, return time that has passed AT MOST
> 	 */
> 	 u32 delta_timer(u32 from, u32 to, int round)
> 	 {

[snip]

> 	}

I decided to implement three separate functions:

u32 time_ms_delta_min(u32 from, u32 to)
u32 time_ms_delta_max(u32 from, u32 to)
u32 time_ms_delta_raw(u32 from, u32 to)

So if you only use one, the rest get stripped out of the binary

The ms_ part allows for:

u32 time_us_delta_min(u32 from, u32 to)
u32 time_us_delta_max(u32 from, u32 to)
u32 time_us_delta_raw(u32 from, u32 to)

I intend to let the time_us_delta* functions drop to ms resolution of the
underlying tick counter is not sub-millisecond. Where the tick counter is
microsecond (or better), then arch-specific udelay becomes a trivial
implementation of a loop using time_us_now() and time_us_delta_min() -
Actually, we can make this a weak default and have arches with a non
microsecond tick counter override it.

> So our timeout from case 1) above would now be written like this:
> 
>    	u32 start,now;
> 	u32 timeout = 5 * CONFIG_SYS_HZ; /* timeout after 5 seconds */
> 
>    	start = get_timer(0);

I now have:
	start = time_ms_now();

> 
> 	while (test_for_event() == 0) {
> 		now = get_timer(0);
> 
> 		if (delta_timer(start, now) > timeout)
> 			handle_timeout();
> 
> 		udelay(100);
> 	}
> 
> and would be guaranteed never to terminate early.
> 
> 
> 
> Comments?

With the 'time_ms_' prefix, it's starting to get rather long, and I'm
pushing a lot of timeout checks beyond 80 columns - especially when
existing code has variables like 'start_time_tx' - I'm starting to consider
dropping the time_ prefix (all time functions will still have a ms_ or us_
prefix anyway) and rename a lot of variables

Thoughts?

Regards,

Graeme

  parent reply	other threads:[~2011-06-15 13:17 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26 13:27 [U-Boot] [RFC][Timer API] Revised Specification - Implementation details Graeme Russ
2011-05-26 15:57 ` Simon Glass
2011-05-26 17:28   ` Wolfgang Denk
2011-05-26 22:44     ` Graeme Russ
2011-05-27  5:23       ` Simon Glass
2011-05-27  7:40         ` Wolfgang Denk
2011-05-27 14:46           ` Simon Glass
2011-05-26 16:56 ` J. William Campbell
2011-05-26 17:53   ` Wolfgang Denk
2011-05-26 18:52     ` J. William Campbell
2011-05-26 19:16       ` Wolfgang Denk
2011-05-26 19:54         ` J. William Campbell
2011-05-26 20:27           ` Wolfgang Denk
2011-05-26 20:39             ` J. William Campbell
2011-05-26 22:59       ` Graeme Russ
2011-05-26 23:28   ` Graeme Russ
2011-05-27  1:26     ` J. William Campbell
2011-05-27  1:51       ` Graeme Russ
2011-05-27  3:54         ` J. William Campbell
2011-05-27  4:33           ` Graeme Russ
2011-05-27  6:33             ` J. William Campbell
2011-05-27  6:54               ` Graeme Russ
2011-05-27 15:49                 ` J. William Campbell
2011-05-28  0:32                   ` Graeme Russ
2011-05-27  7:33           ` Wolfgang Denk
2011-05-27 14:16             ` J. William Campbell
2011-05-27  7:28       ` Wolfgang Denk
2011-05-27 14:04         ` J. William Campbell
2011-05-27  7:13     ` Wolfgang Denk
2011-05-27  7:35       ` Graeme Russ
2011-05-27  7:48         ` Wolfgang Denk
2011-05-27  7:57           ` Graeme Russ
2011-05-27  8:01             ` Graeme Russ
2011-05-27 11:27               ` Wolfgang Denk
2011-05-27 12:43                 ` Graeme Russ
2011-05-27 13:07                   ` Scott McNutt
2011-05-27 15:00                     ` J. William Campbell
2011-05-27 15:13                       ` Simon Glass
2011-05-27 17:11                         ` J. William Campbell
2011-05-27 15:44                       ` Scott McNutt
2011-05-27 15:59                         ` J. William Campbell
2011-05-29 15:55                     ` Wolfgang Denk
2011-05-29 19:12                       ` Simon Glass
2011-05-30 10:57                         ` Wolfgang Denk
2011-05-30 11:47                           ` Graeme Russ
2011-05-30 12:31                             ` Wolfgang Denk
2011-05-30 12:46                               ` Graeme Russ
2011-05-30 18:57                           ` Reinhard Meyer
2011-05-31  0:24                             ` Graeme Russ
2011-05-31  4:07                               ` Reinhard Meyer
2011-05-31  4:24                                 ` Graeme Russ
2011-05-31  4:36                                   ` Reinhard Meyer
2011-05-31  4:53                                     ` Graeme Russ
2011-05-31  5:56                                     ` Wolfgang Denk
2011-05-31  4:45                               ` Simon Glass
2011-05-31  4:53                                 ` Reinhard Meyer
2011-05-31  5:03                                   ` Graeme Russ
2011-05-31  5:16                                     ` Reinhard Meyer
2011-05-31  6:03                                     ` Wolfgang Denk
2011-05-31  6:23                                       ` Graeme Russ
2011-05-31  5:18                                   ` Wolfgang Denk
2011-05-31  5:37                                     ` Reinhard Meyer
2011-05-31  6:10                                       ` Wolfgang Denk
2011-05-31  4:56                           ` Simon Glass
2011-05-31  5:49                             ` Wolfgang Denk
2011-05-31  6:28                               ` Graeme Russ
2011-05-31  6:29                                 ` Graeme Russ
2011-06-15 13:17                           ` Graeme Russ [this message]
2011-06-15 16:03                             ` Simon Glass
2011-06-15 20:38                               ` Graeme Russ
2011-06-15 21:58                                 ` Simon Glass
2011-06-15 23:09                                   ` Graeme Russ
2011-06-16  5:53                                     ` Simon Glass
2011-06-16  6:27                                       ` Graeme Russ
2011-06-16 13:58                                         ` Simon Glass
2011-05-27 11:26             ` Wolfgang Denk
2011-05-27 14:23         ` J. William Campbell
2011-05-28  5:53           ` Graeme Russ
2011-05-28  6:18             ` Reinhard Meyer
2011-05-28  8:59               ` Graeme Russ
2011-05-29  1:41             ` J. William Campbell
2011-05-26 17:49 ` Wolfgang Denk
2011-05-26 22:51   ` Graeme Russ
2011-05-27  7:17     ` Wolfgang Denk
2011-05-27  7:33       ` Graeme Russ
2011-05-27  7:45         ` Wolfgang Denk
2011-05-27 14:58           ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DF8B0E0.2080006@gmail.com \
    --to=graeme.russ@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox