From alsa-devel-owner@alsa.jcu.cz  Sun Feb 21 16:07:37 1999
Received: from entry.jcu.cz (IDENT:perex@entry.jcu.cz [160.217.1.111])
	by marvin.jcu.cz (8.9.1a/8.9.1) with SMTP id QAA20415;
	Sun, 21 Feb 1999 16:06:06 +0100
Date: Sun, 21 Feb 1999 16:06:06 +0100 (CET)
From: Jaroslav Kysela <perex@jcu.cz>
To: Steve Ratcliffe <steve@parabola.demon.co.uk>
cc: alsa-devel@alsa.jcu.cz
Subject: Re: Timers
In-Reply-To: <199902211303.NAA03165@ariel.sr.home>
Message-ID: <Pine.LNX.3.96.990221155259.30166F-100000@entry.jcu.cz>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

On Sun, 21 Feb 1999, Steve Ratcliffe wrote:

> 
> A few questions about the timer code.
> 
> 1. I'm not sure what global_timer_ticks is being used for in seq_timer.c.
> It looks like it is being used for two different purposes, first as
> a count of ticks to initialise the timer with on open and as a scaling
> factor for resolution.  I don't understand the second use and suggest
> the following patch:
> 
> --- kernel/seq/seq_timer.c.orig	Sun Feb 21 00:52:29 1999
> +++ kernel/seq/seq_timer.c	Sun Feb 21 00:53:39 1999
> @@ -104,7 +104,7 @@
>  	queue_t *q;
>  	timer_t *tmr;
>  
> -	resolution = snd_timer_resolution(timer) * global_timer_ticks;
> +	resolution = snd_timer_resolution(timer);
>  	period.tv_sec = 0;
>  	period.tv_nsec = resolution % 1000000000;
>  
> @@ -312,7 +312,7 @@
>  	snd_mutex_down_static(global_timer);
>  	snd_iprintf(buffer, "Timer       : %s\n", global_timer ? global_timer->name : "None");
>  	if (global_timer) {
> -		resolution = snd_timer_resolution(global_timer) * global_timer_ticks;
> +		resolution = snd_timer_resolution(global_timer);
>  		snd_iprintf(buffer, "Period time : %d.%09d\n", resolution / 1000000000, resolution % 1000000000);
>   	}
>  	snd_mutex_up_static(global_timer);

It is the wrong code. The current timer interface supports only timers
with the FIXED resolution and variable ticks.

snd_timer_resolution() returns time between two ticks
snd_timer_start() sets the number of ticks with given resolution

The global_timer_ticks variable contains ticks needed for the 
frequency in the global_timer_resolution resolution variable.

If you want the sequencer interrupt code to work on the same frequency as
timer, you must change the global_timer_resolution variable, too.

> 2. Is the purpose of snd_timer_open to find a timer with a resolution
> that is as good as or better than that requested?  If so a test is the

Yes, this means we must find the resolution (in 1.0E-9sec) less or equal
than requested.

> wrong way round.  The code should also use snd_timer_resolution() to cope
> with the case that hw.c_resolution() is being used and not hw.resolution.

The hw.c_resolution() callbacks can be used after hw.open() :-((

> 3. How should timers work that are not specific to an audio card?
> Should they just pass in a NULL card_t when registering?  If so there
> are a couple of places where timer->card should be tested before use.

Fixed. Thanks.

						Jaroslav

-----
Jaroslav Kysela <perex@jcu.cz>
Academic Computer Centre, University of South Bohemia
Branisovska 31, C. Budejovice, CZ-370 05 Czech Republic


