From mboxrd@z Thu Jan 1 00:00:00 1970 From: Graeme Russ Date: Wed, 25 May 2011 21:52:21 +1000 Subject: [U-Boot] [RFC] Review of U-Boot timer API In-Reply-To: <20110525113738.E49DFCFB8A4@gemini.denx.de> References: <4DD7B245.5000008@gmail.com> <201105240024.26511.vapier@gentoo.org> <4DDB42B1.2010206@emk-elektronik.de> <4DDBB29D.2050102@psyent.com> <20110524141950.2AB1CCF5DBF@gemini.denx.de> <4DDBE22D.6050806@gmail.com> <20110524191948.401CBCF5DBF@gemini.denx.de> <4DDC6F46.4090809@comcast.net> <20110525052836.11A30CF5DBF@gemini.denx.de> <20110525080837.5925BCF5DBF@gemini.denx.de> <4DDCBFF4.40002@gmail.com> <20110525113738.E49DFCFB8A4@gemini.denx.de> Message-ID: <4DDCED75.8030906@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Wolfgang, On 25/05/11 21:37, Wolfgang Denk wrote: > Dear Graeme Russ, > > In message <4DDCBFF4.40002@gmail.com> you wrote: >> >>> I don't get you. In such a system, the interrupt would be the tick >>> (see the PPC implementation). If you miss interrupts, you miss ticks. >> >> Yes, you miss ticks, but if the hardware is keeping the tick counter >> current in the background (i.e. without software or interrupts) then this >> does not matter - The prescaler takes care of this... > > I think you don't want to understand. > > Look at the PPC implementation. The decrementer causes an interrupt > every millisecond. This is our tick. We never ever actually read the > decrementer register itself. We just use the interrupt. x86 is the same - a 1ms interrupt which increments the timer >> The key is the prescaler takes a 'tick delta' between the last time it was >> called and now, uses the 'tick frequency' to calculate a corresponding >> 'timer delta' which it adds to the current timer > > The "tick frequency" in above example is 1,000 Hz, and determined by > the frequency of the interrupts. There is not any "timer count > register" we are accessing here. > >> This relies on the tick counter wrapping properly. > > The "tick counter" is already in the higher level, i. e. implemented > in software, without any hardware based registers. And in the PPC case - No prescaler and life is easy BUT - I just found something very disturbing in /board/zylonite/flash.c - Interrupts are disables before the timer is used to detect a timeout! Yes, this is in a board specific flash driver which is bad but who knows where else this might (quite unintentionally) occur No if you have: start = get_timer(0) while (hardware_busy) { if (get_timer(start) > TIMEOUT) { /* deal with timeout */ break; } /* Do stuf (poll hardware etc) */ } Now every time get_timer() is called, the prescaler updates the timer from the current tick count - This cannot fail if interrupts are inadvertently disabled. And if you do not care about the timer updating while you are not 'using it' (i.e. checking for a timeout) - it doesn't really matter - You will get a glitch, but this glitch is 'reset' by the call to get_timer() and your timeout check starts a new timer increment afresh Regards, Graeme